Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-6994 feat(cli): add --fields to issue list JSON output (#7946)

Eduardo Matos8c4e0d298535
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.md
index fcf0ecf79a..64b960d865 100644
--- a/CLI_AND_DAEMON.md
+++ b/CLI_AND_DAEMON.md
@@ -503,10 +503,13 @@ multica issue list --full-id
multica issue list --limit 20 --output json
multica issue list --status todo --sort position # board order (the default)
multica issue list --sort created_at --direction desc # newest first
+multica issue list --output json --fields=id,title,status,priority # narrow the JSON payload
```
Table output shows a routable issue `KEY` such as `MUL-123`; copy that key into follow-up commands like `issue get`, `issue comment list`, `issue status`, or `--parent`. Add `--full-id` when you need canonical UUIDs. Available filters: `--status`, `--priority`, `--assignee` / `--assignee-id`, `--project`, `--metadata`, `--property`, `--limit`. Use `--assignee-id <uuid>` for unambiguous filtering when names overlap.
+`--fields` (JSON output only) whitelists which top-level issue keys come back — pass a comma-separated list such as `--fields=id,title,status,priority`. Omit it for the full issue object, unchanged from before this flag existed. Filtering happens client-side after the CLI fetches the full response, so this shrinks CLI output size and agent context cost — not network transfer or server-side work. Field names are the real API keys, not table-display labels — assignee is `assignee_type`/`assignee_id` rather than a single `assignee` field. An unknown name is rejected up front with the valid list rather than silently dropped. Has no effect on `--output table`.
+
Results come back in board order (`position`, ascending) by default. Pass `--sort` to change the column (`position`, `title`, `created_at`, `start_date`, `due_date`, `priority`, or `property:<name-or-id>` for a custom property — select properties order by option order, and issues without the property sort last) and `--direction asc|desc` to flip the order. `position` is always ascending (it is the manual drag order), so `--direction` is rejected when `--sort` is `position` or omitted — use it only with `title`, `created_at`, `start_date`, `due_date`, `priority`, or a `property:` sort.
Use `--metadata key=value` (repeatable; combined with AND) to filter by per-issue metadata. The value is JSON-parsed: `true`/`false` become bool, numbers become numbers, anything else is a string. Wrap as `'"42"'` to force a string when the value would otherwise sniff as a number:
diff --git a/server/cmd/multica/cmd_issue.go b/server/cmd/multica/cmd_issue.go
index 9ca09d7a6f..a38df82f30 100644
--- a/server/cmd/multica/cmd_issue.go
+++ b/server/cmd/multica/cmd_issue.go
@@ -405,6 +405,23 @@ var validIssueSortColumns = []string{
"position", "title", "created_at", "start_date", "due_date", "priority",
}
+// validIssueFields are the top-level keys /api/issues actually emits for
+// `issue list` — i.e. the JSON tags of handler.IssueResponse
+// (server/internal/handler/issue.go), minus reactions/attachments/
+// source_context, which are omitempty and never set by the list endpoint
+// (detail-only). TestValidIssueFieldsMatchListEndpointShape guards this
+// against drifting from that struct. There is no plain "assignee" field —
+// it is split into assignee_type/assignee_id — so that name is rejected
+// rather than silently ignored.
+var validIssueFields = []string{
+ "id", "workspace_id", "number", "identifier", "title", "description",
+ "status", "status_category", "status_name", "priority", "assignee_type",
+ "assignee_id", "creator_type", "creator_id", "parent_issue_id",
+ "project_id", "position", "stage", "start_date", "due_date", "created_at",
+ "updated_at", "revision", "last_activity_at", "metadata", "properties",
+ "labels",
+}
+
// directionalIssueSortColumns are the sort keys for which --direction is
// meaningful: every valid column except "position". Derived from
// validIssueSortColumns so the two stay in sync.
@@ -499,6 +516,7 @@ func init() {
issueListCmd.Flags().Int("offset", 0, "Number of issues to skip (for pagination)")
issueListCmd.Flags().String("sort", "", "Sort column: position (default, manual board order), title, created_at, start_date, due_date, priority, or property:<name-or-id> to sort by a custom property (select properties sort by option order)")
issueListCmd.Flags().String("direction", "", "Sort direction (asc or desc); requires --sort to be a non-position column or a property sort (position is always ascending)")
+ issueListCmd.Flags().String("fields", "", "JSON output only: comma-separated list of issue fields to include (e.g. id,title,status,priority). Filtering happens client-side after the full response is fetched, so this shrinks CLI output size and agent context cost, not network/server-side cost. Omit for the full issue object (default, unchanged). Valid fields: "+strings.Join(validIssueFields, ", "))
// issue get
issueGetCmd.Flags().String("output", "json", "Output format: table or json")
@@ -733,6 +751,21 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
params.Set("direction", d)
}
+ var fields []string
+ if v, _ := cmd.Flags().GetString("fields"); v != "" {
+ valid := make(map[string]bool, len(validIssueFields))
+ for _, f := range validIssueFields {
+ valid[f] = true
+ }
+ for _, f := range strings.Split(v, ",") {
+ f = strings.TrimSpace(f)
+ if !valid[f] {
+ return fmt.Errorf("invalid --fields value %q; valid values: %s", f, strings.Join(validIssueFields, ", "))
+ }
+ fields = append(fields, f)
+ }
+ }
+
path := "/api/issues"
if len(params) > 0 {
path += "?" + params.Encode()
@@ -747,6 +780,9 @@ func runIssueList(cmd *cobra.Command, _ []string) error {
output, _ := cmd.Flags().GetString("output")
if output == "json" {
+ if len(fields) > 0 {
+ filterIssueFields(issuesRaw, fields)
+ }
total, _ := result["total"].(float64)
limit, _ := cmd.Flags().GetInt("limit")
offset, _ := cmd.Flags().GetInt("offset")
@@ -2961,6 +2997,27 @@ func formatAssignee(issue map[string]any, actors actorDisplayLookup) string {
return actors.actor(aType, aID)
}
+// filterIssueFields keeps only the requested top-level keys on each issue,
+// dropping everything else — including description, which makes up most of
+// a typical issue payload. Opt-in via --fields on JSON output only.
+func filterIssueFields(issuesRaw []any, fields []string) {
+ keep := make(map[string]bool, len(fields))
+ for _, f := range fields {
+ keep[f] = true
+ }
+ for _, raw := range issuesRaw {
+ issue, ok := raw.(map[string]any)
+ if !ok {
+ continue
+ }
+ for k := range issue {
+ if !keep[k] {
+ delete(issue, k)
+ }
+ }
+ }
+}
+
func truncateID(id string) string {
if utf8.RuneCountInString(id) > 8 {
runes := []rune(id)
diff --git a/server/cmd/multica/cmd_issue_test.go b/server/cmd/multica/cmd_issue_test.go
index 9deae1cadc..cfe7c72c8a 100644
--- a/server/cmd/multica/cmd_issue_test.go
+++ b/server/cmd/multica/cmd_issue_test.go
@@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"
"github.com/multica-ai/multica/server/internal/cli"
+ "github.com/multica-ai/multica/server/internal/handler"
)
// stderrCapture redirects os.Stderr through a pipe so a test can assert on
@@ -2928,6 +2929,7 @@ func newIssueListTestCmd() *cobra.Command {
cmd.Flags().Int("offset", 0, "")
cmd.Flags().String("sort", "", "")
cmd.Flags().String("direction", "", "")
+ cmd.Flags().String("fields", "", "")
return cmd
}
@@ -3267,6 +3269,254 @@ func TestRunIssueListRejectsDirectionWithoutDirectionalSort(t *testing.T) {
}
}
+// sampleIssueResponse returns a handler.IssueResponse populated the way the
+// /api/issues list endpoint actually populates one (ListIssues in
+// server/internal/handler/issue.go) — every field a real "issue list
+// --output json" row carries. Reactions, Attachments, and SourceContext are
+// left zero-valued on purpose: they are `omitempty` and ListIssues never
+// sets them (detail-only), so a real list payload never carries those keys.
+// This is the single source of truth for both fullTestIssue (the --fields
+// filtering fixture) and the drift guard below, so the two can't diverge
+// from each other the way the whitelist once diverged from the real API.
+func sampleIssueResponse() handler.IssueResponse {
+ desc := "a very long description"
+ assigneeType := "member"
+ assigneeID := "user-1"
+ parentID := "parent-1"
+ projectID := "proj-1"
+ stage := int32(1)
+ startDate := "2024-01-01"
+ dueDate := "2024-01-02"
+ lastActivity := "2024-01-01T00:00:00Z"
+ labels := []handler.LabelResponse{}
+
+ return handler.IssueResponse{
+ ID: "iss-1",
+ WorkspaceID: "ws-1",
+ Number: 42,
+ Identifier: "MUL-42",
+ Title: "Test issue",
+ Description: &desc,
+ Status: "in_progress",
+ StatusCategory: "active",
+ StatusName: "In Progress",
+ Priority: "high",
+ AssigneeType: &assigneeType,
+ AssigneeID: &assigneeID,
+ CreatorType: "member",
+ CreatorID: "user-2",
+ ParentIssueID: &parentID,
+ ProjectID: &projectID,
+ Position: 1,
+ Stage: &stage,
+ StartDate: &startDate,
+ DueDate: &dueDate,
+ CreatedAt: "2024-01-01T00:00:00Z",
+ UpdatedAt: "2024-01-01T00:00:00Z",
+ Revision: 1,
+ LastActivityAt: &lastActivity,
+ Metadata: map[string]any{},
+ Properties: map[string]any{},
+ Labels: &labels,
+ }
+}
+
+// fullTestIssue returns a JSON-decoded issue map carrying every field a real
+// "issue list --output json" row exposes (see sampleIssueResponse), so
+// --fields tests can assert on a realistic full payload rather than a
+// hand-picked subset.
+func fullTestIssue(t *testing.T) map[string]any {
+ t.Helper()
+ return issueResponseJSONMap(t, sampleIssueResponse())
+}
+
+func keysOf(m map[string]any) []string {
+ keys := make([]string, 0, len(m))
+ for k := range m {
+ keys = append(keys, k)
+ }
+ return keys
+}
+
+func issueResponseJSONMap(t *testing.T, resp handler.IssueResponse) map[string]any {
+ t.Helper()
+ b, err := json.Marshal(resp)
+ if err != nil {
+ t.Fatalf("marshal handler.IssueResponse: %v", err)
+ }
+ var m map[string]any
+ if err := json.Unmarshal(b, &m); err != nil {
+ t.Fatalf("unmarshal handler.IssueResponse: %v", err)
+ }
+ return m
+}
+
+// TestValidIssueFieldsMatchListEndpointShape guards validIssueFields (the
+// --fields whitelist) against drifting from what /api/issues actually
+// returns for `issue list`. It caught a real bug: the whitelist was modeled
+// on publicapi/v1.Issue, which the list endpoint never serializes — the real
+// response is handler.IssueResponse, which also emits status_name and
+// labels that the whitelist rejected as invalid field names.
+func TestValidIssueFieldsMatchListEndpointShape(t *testing.T) {
+ realKeys := keysOf(fullTestIssue(t))
+
+ valid := make(map[string]bool, len(validIssueFields))
+ for _, f := range validIssueFields {
+ valid[f] = true
+ }
+ real := make(map[string]bool, len(realKeys))
+ for _, k := range realKeys {
+ real[k] = true
+ }
+
+ for _, k := range realKeys {
+ if !valid[k] {
+ t.Errorf("validIssueFields is missing %q, which a real issue list JSON response emits", k)
+ }
+ }
+ for _, f := range validIssueFields {
+ if !real[f] {
+ t.Errorf("validIssueFields has %q, which a real issue list JSON response never emits", f)
+ }
+ }
+}
+
+// TestRunIssueListFieldsFiltersJSONOutput guards that --fields whitelists
+// exactly the requested top-level keys on each returned issue, so an agent
+// asking for id/title/status/priority never pays for the description field
+// that makes up most of a typical issue payload.
+func TestRunIssueListFieldsFiltersJSONOutput(t *testing.T) {
+ issue := fullTestIssue(t)
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{"issues": []any{issue}, "total": 1})
+ }))
+ defer srv.Close()
+
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cases := []struct {
+ name string
+ fields string
+ want []string
+ }{
+ {"id, title, status, priority", "id,title,status,priority", []string{"id", "title", "status", "priority"}},
+ {"assignee pair", "assignee_type,assignee_id", []string{"assignee_type", "assignee_id"}},
+ {"single field", "identifier", []string{"identifier"}},
+ {"description explicitly requested", "id,description", []string{"id", "description"}},
+ {"whitespace around names", " id , title ", []string{"id", "title"}},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ _ = cmd.Flags().Set("fields", tc.fields)
+
+ out, err := captureStdout(t, func() error { return runIssueList(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+
+ var resp struct {
+ Issues []map[string]any `json:"issues"`
+ }
+ if err := json.Unmarshal([]byte(out), &resp); err != nil {
+ t.Fatalf("unmarshal output: %v\noutput: %s", err, out)
+ }
+ if len(resp.Issues) != 1 {
+ t.Fatalf("issues = %d, want 1", len(resp.Issues))
+ }
+ got := resp.Issues[0]
+ if len(got) != len(tc.want) {
+ t.Fatalf("issue keys = %v, want exactly %v", keysOf(got), tc.want)
+ }
+ for _, f := range tc.want {
+ if _, ok := got[f]; !ok {
+ t.Fatalf("issue missing field %q; got keys %v", f, keysOf(got))
+ }
+ }
+ })
+ }
+}
+
+// TestRunIssueListDefaultKeepsFullIssueUnchanged guards backward
+// compatibility: omitting --fields must return the full issue object,
+// description included, exactly as before this flag existed.
+func TestRunIssueListDefaultKeepsFullIssueUnchanged(t *testing.T) {
+ issue := fullTestIssue(t)
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{"issues": []any{issue}, "total": 1})
+ }))
+ defer srv.Close()
+
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+
+ out, err := captureStdout(t, func() error { return runIssueList(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+ var resp struct {
+ Issues []map[string]any `json:"issues"`
+ }
+ if err := json.Unmarshal([]byte(out), &resp); err != nil {
+ t.Fatalf("unmarshal output: %v", err)
+ }
+ got := resp.Issues[0]
+ if len(got) != len(issue) {
+ t.Fatalf("issue keys = %v, want all %d original fields", keysOf(got), len(issue))
+ }
+ if _, ok := got["description"]; !ok {
+ t.Fatalf("expected description to remain in default (no --fields) output, got %v", got)
+ }
+}
+
+// TestRunIssueListRejectsInvalidFields guards that a typo'd or non-existent
+// field name fails fast with the valid list, instead of silently returning
+// an issue object missing the field the caller expected.
+func TestRunIssueListRejectsInvalidFields(t *testing.T) {
+ t.Setenv("MULTICA_SERVER_URL", "http://127.0.0.1:0")
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("output", "json")
+ _ = cmd.Flags().Set("fields", "id,bogus_field")
+ err := runIssueList(cmd, nil)
+ if err == nil {
+ t.Fatal("runIssueList: expected error for invalid --fields")
+ }
+ if !strings.Contains(err.Error(), `invalid --fields value "bogus_field"`) {
+ t.Fatalf("error = %q, want it to mention the invalid field name", err)
+ }
+}
+
+// TestRunIssueListIgnoresFieldsWithTableOutput guards that --output table
+// (the default) is completely unaffected by --fields, matching how
+// issue comment list's --compact/--summary are JSON-only no-ops for table.
+func TestRunIssueListIgnoresFieldsWithTableOutput(t *testing.T) {
+ issue := fullTestIssue(t)
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{"issues": []any{issue}, "total": 1})
+ }))
+ defer srv.Close()
+
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "test-token")
+
+ cmd := newIssueListTestCmd()
+ _ = cmd.Flags().Set("fields", "id") // table output; --fields must not error or change behavior
+ if err := runIssueList(cmd, nil); err != nil {
+ t.Fatalf("runIssueList: %v", err)
+ }
+}
+
func TestComputeReorderPosition(t *testing.T) {
positions := map[string]float64{"a": 10, "b": 20, "x": 99}
tests := []struct {