Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issue): bind update attachments safely (#8588) (#8766)
mrlonely79b932783770
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex bfaef20cdc..181bb1b80e 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -579,9 +579,11 @@ Flags: `--title` (required), `--description`, `--status`, `--priority`, `--assig```bashmultica issue update <id> --title "New title" --priority urgentmultica issue update <id> --position 4.5+multica issue update <id> --attachment revised.png````--position` sets the raw ordering value within the board column (lower sorts first). For relative moves, `issue reorder` is easier because it works out the value for you.+`--attachment` uploads a local file and appends its Markdown reference to the end of the issue description. Repeat the flag to attach multiple files. To replace an existing image, also use `--description-file` to remove the old reference from the description.### Reorder Issuediff --git a/server/cmd/multica/cmd_issue.go b/server/cmd/multica/cmd_issue.goindex 2922c8528c..98e4c370f7 100644--- a/server/cmd/multica/cmd_issue.go+++ b/server/cmd/multica/cmd_issue.go@@ -635,7 +635,8 @@ func init() {issueUpdateCmd.Flags().String("description", "", "New description (decodes \\n, \\r, \\t, \\\\; pipe via --description-stdin to preserve literal backslashes)")issueUpdateCmd.Flags().Bool("description-stdin", false, "Read new description from stdin (preserves multi-line content verbatim)")issueUpdateCmd.Flags().String("description-file", "", "Read new description from a UTF-8 file (preserves multi-line content verbatim; use this on Windows when stdin piping mangles non-ASCII bytes). The path must be inside the current working directory unless --allow-external-file is set.")- issueUpdateCmd.Flags().Bool("allow-external-file", false, "Allow --description-file to read a path outside the current working directory. Off by default so a stale temp file from another run/environment can't be picked up (MUL-4252).")+ issueUpdateCmd.Flags().Bool("allow-external-file", false, "Allow --description-file / --attachment to read a path outside the current working directory. Off by default so a stale temp file from another run/environment can't be picked up (MUL-4252).")+ issueUpdateCmd.Flags().StringSlice("attachment", nil, "Local file path(s) to attach to the issue description (repeatable); references are appended to the end of the description")issueUpdateCmd.Flags().String("status", "", "New status")issueUpdateCmd.Flags().String("priority", "", "New priority")issueUpdateCmd.Flags().String("assignee", "", "New assignee name (member, agent, or squad; fuzzy match)")@@ -1316,7 +1317,8 @@ type pendingAttachment struct {// returns an error with nothing uploaded. Both `issue create` and// `comment add` share this so an invalid attachment can never leave an earlier// one uploaded as an orphaned issue attachment while the issue/comment is never-// created (which would duplicate on retry).+// created (which would duplicate on retry). `issue update` also uses this+// preflight so an invalid later path cannot leave earlier files uploaded.func collectLocalAttachments(cmd *cobra.Command, attachments []string) ([]pendingAttachment, error) {pending := make([]pendingAttachment, 0, len(attachments))for _, filePath := range attachments {@@ -1640,6 +1642,7 @@ func activeDuplicateIssueCreateMessage(err error) (string, bool) {}func runIssueUpdate(cmd *cobra.Command, args []string) error {+ attachmentPaths, _ := cmd.Flags().GetStringSlice("attachment")noStart, _ := cmd.Flags().GetBool("no-start")statusChanged := cmd.Flags().Changed("status")statusFlag, _ := cmd.Flags().GetString("status")@@ -1661,7 +1664,11 @@ func runIssueUpdate(cmd *cobra.Command, args []string) error {return err}- ctx, cancel := cli.APIContext(context.Background())+ timeout := cli.APITimeout()+ if len(attachmentPaths) > 0 {+ timeout = cli.AtLeastAPITimeout(60 * time.Second)+ }+ ctx, cancel := context.WithTimeout(context.Background(), timeout)defer cancel()issueRef, err := resolveIssueRef(ctx, client, args[0])@@ -1679,11 +1686,8 @@ func runIssueUpdate(cmd *cobra.Command, args []string) error {if err != nil {return err}- // `issue update` has no --attachment flag, so the hint must point at the- // command that does. Telling the agent to "pass --attachment" here would- // name an argument this command rejects.if err := guardLocalPathLinks(desc, "issue description",- "`multica issue update` cannot carry files — deliver the file with `multica issue comment add <issue-id> --attachment <path>` instead, and drop the link."); err != nil {+ "Attach the file with `multica issue update <issue-id> --attachment <path>` and drop the local-path link."); err != nil {return err}body["description"] = desc@@ -1748,15 +1752,54 @@ func runIssueUpdate(cmd *cobra.Command, args []string) error {body["position"] = v}- if len(body) == 0 {+ if len(body) == 0 && len(attachmentPaths) == 0 {return fmt.Errorf("no fields to update; use flags like --title, --status, --priority, --assignee, etc.")}+ // Validate every path before any upload so an invalid later path cannot+ // leave earlier files uploaded and unbound.+ pending, err := collectLocalAttachments(cmd, attachmentPaths)+ if err != nil {+ return err+ }+ if len(body) == 0 && len(pending) == 0 {+ return fmt.Errorf("no local attachments to update; --attachment accepts file paths, not URLs")+ }+ desc, changed := body["description"].(string)+ if len(pending) > 0 && !changed {+ var issue struct {+ Description *string `json:"description"`+ }+ if err := client.GetJSON(ctx, "/api/issues/"+url.PathEscape(issueRef.ID), &issue); err != nil {+ return fmt.Errorf("get issue description before binding attachments: %w", err)+ }+ if issue.Description != nil {+ desc = *issue.Description+ }+ }+ attachmentIDs := make([]string, 0, len(pending))+ attachmentRefs := make([]cli.AttachmentResponse, 0, len(pending))+ for _, att := range pending {+ uploaded, uploadErr := client.UploadIssueAttachment(ctx, att.data, att.path, "")+ if uploadErr != nil {+ return fmt.Errorf("upload attachment %s: %w; already uploaded IDs: %v", att.path, uploadErr, attachmentIDs)+ }+ attachmentIDs = append(attachmentIDs, uploaded.ID)+ attachmentRefs = append(attachmentRefs, uploaded)+ fmt.Fprintf(os.Stderr, "Uploaded %s\n", att.path)+ }+ if len(attachmentRefs) > 0 {+ body["description"] = appendAttachmentReferences(desc, attachmentRefs)+ body["attachment_ids"] = attachmentIDs+ }if noStart {body["suppress_run"] = true}var result map[string]anyif err := client.PutJSON(ctx, "/api/issues/"+issueRef.ID, body, &result); err != nil {+ if len(attachmentIDs) > 0 {+ return fmt.Errorf("update issue (uploaded IDs: %v): %w", attachmentIDs, err)+ }return fmt.Errorf("update issue: %w", err)}diff --git a/server/cmd/multica/cmd_issue_test.go b/server/cmd/multica/cmd_issue_test.goindex 1606126547..dbd8b69d31 100644--- a/server/cmd/multica/cmd_issue_test.go+++ b/server/cmd/multica/cmd_issue_test.go@@ -3737,6 +3737,7 @@ func newIssueUpdateTestCmd() *cobra.Command {cmd.Flags().Bool("description-stdin", false, "")cmd.Flags().String("description-file", "", "")cmd.Flags().Bool("allow-external-file", false, "")+ cmd.Flags().StringSlice("attachment", nil, "")cmd.Flags().String("status", "", "")cmd.Flags().String("priority", "", "")cmd.Flags().String("assignee", "", "")@@ -3752,6 +3753,103 @@ func newIssueUpdateTestCmd() *cobra.Command {return cmd}+func TestRunIssueUpdateAppendsLocalAttachmentToDescription(t *testing.T) {+ t.Chdir(t.TempDir())+ const issueID = "11111111-1111-4111-8111-111111111111"+ const uploadedID = "33333333-3333-4333-8333-333333333333"+ path := writeIssueCreateAttachment(t, "revised.png")+ var calls []string+ var body map[string]any+ uploadIncludedIssueID := false+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ calls = append(calls, r.Method+" "+r.URL.Path)+ switch r.URL.Path {+ case "/api/upload-file":+ if err := r.ParseMultipartForm(1 << 20); err != nil {+ t.Errorf("parse upload: %v", err)+ }+ uploadIncludedIssueID = r.FormValue("issue_id") != ""+ _ = json.NewEncoder(w).Encode(map[string]any{+ "id": uploadedID, "filename": "revised.png", "content_type": "image/png",+ "markdown_url": "https://api.example/api/attachments/" + uploadedID + "/download",+ })+ case "/api/issues/" + issueID:+ if r.Method == http.MethodGet {+ _ = json.NewEncoder(w).Encode(map[string]any{"description": "Existing body"})+ } else {+ if err := json.NewDecoder(r.Body).Decode(&body); err != nil {+ t.Errorf("decode update: %v", err)+ }+ _ = json.NewEncoder(w).Encode(map[string]any{"id": issueID, "title": "Updated"})+ }+ default:+ http.NotFound(w, r)+ }+ }))+ defer srv.Close()+ setCLITestServerEnv(t, srv.URL)+ cmd := newIssueUpdateTestCmd()+ _ = cmd.Flags().Set("attachment", path)+ if err := runIssueUpdate(cmd, []string{issueID}); err != nil {+ t.Fatalf("runIssueUpdate: %v", err)+ }+ if got := body["description"].(string); got != "Existing body\n\n" {+ t.Fatalf("description = %q", got)+ }+ if ids, ok := body["attachment_ids"].([]any); !ok || !reflect.DeepEqual(ids, []any{uploadedID}) {+ t.Fatalf("attachment_ids = %#v", body["attachment_ids"])+ }+ if uploadIncludedIssueID {+ t.Fatal("upload included issue_id; update must bind the unbound upload in the PUT")+ }+ if want := []string{"GET /api/issues/" + issueID, "POST /api/upload-file", "PUT /api/issues/" + issueID}; !slices.Equal(calls, want) {+ t.Fatalf("calls = %v, want %v", calls, want)+ }+}++func TestRunIssueUpdateAttachmentUsesProvidedDescriptionWithoutFetching(t *testing.T) {+ t.Chdir(t.TempDir())+ const issueID = "11111111-1111-4111-8111-111111111111"+ const attachmentID = "22222222-2222-4222-8222-222222222222"+ path := writeIssueCreateAttachment(t, "revised.png")+ var calls []string+ var body map[string]any+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ calls = append(calls, r.Method+" "+r.URL.Path)+ switch r.URL.Path {+ case "/api/upload-file":+ _ = json.NewEncoder(w).Encode(map[string]any{+ "id": attachmentID, "filename": "revised.png", "content_type": "image/png",+ "markdown_url": "https://api.example/api/attachments/" + attachmentID + "/download",+ })+ case "/api/issues/" + issueID:+ if r.Method == http.MethodGet {+ t.Error("description GET must be skipped when --description is provided")+ }+ if err := json.NewDecoder(r.Body).Decode(&body); err != nil {+ t.Errorf("decode update: %v", err)+ }+ _ = json.NewEncoder(w).Encode(map[string]any{"id": issueID, "title": "Updated"})+ default:+ http.NotFound(w, r)+ }+ }))+ defer srv.Close()+ setCLITestServerEnv(t, srv.URL)+ cmd := newIssueUpdateTestCmd()+ _ = cmd.Flags().Set("attachment", path)+ _ = cmd.Flags().Set("description", "Replacement body")+ if err := runIssueUpdate(cmd, []string{issueID}); err != nil {+ t.Fatalf("runIssueUpdate: %v", err)+ }+ if got := body["description"].(string); !strings.HasPrefix(got, "Replacement body\n\n") {+ t.Fatalf("description = %q", got)+ }+ if want := []string{"POST /api/upload-file", "PUT /api/issues/" + issueID}; !slices.Equal(calls, want) {+ t.Fatalf("calls = %v, want %v", calls, want)+ }+}+func newIssueAssignTestCmd() *cobra.Command {cmd := &cobra.Command{Use: "assign"}cmd.Flags().String("to", "", "")diff --git a/server/cmd/multica/local_path_link_lint_test.go b/server/cmd/multica/local_path_link_lint_test.goindex 8529b3a2b7..7222de9ec9 100644--- a/server/cmd/multica/local_path_link_lint_test.go+++ b/server/cmd/multica/local_path_link_lint_test.go@@ -262,9 +262,7 @@ func TestGuardLocalPathLinksOnlyFiresInAgentContext(t *testing.T) {})}-// The per-command fix hint. `issue update` is the trap: it has no --attachment-// flag, so a shared "pass --attachment" message would point the agent at an-// argument the command rejects and turn one failure into two.+// The per-command fix hint should now use `issue update --attachment`.func TestGuardLocalPathLinksHintIsPerCommand(t *testing.T) {workdir := withWorkdir(t)shot := filepath.Join(workdir, "shot.png")@@ -276,19 +274,16 @@ func TestGuardLocalPathLinksHintIsPerCommand(t *testing.T) {err := guardLocalPathLinks("[screenshot]("+shot+")","issue description",- "`multica issue update` cannot carry files — deliver the file with `multica issue comment add <issue-id> --attachment <path>` instead, and drop the link.",+ "Attach the file with `multica issue update <issue-id> --attachment <path>` and drop the local-path link.",)if err == nil {t.Fatal("expected a hard failure")}msg := err.Error()- if !strings.Contains(msg, "`multica issue update` cannot carry files") {+ if !strings.Contains(msg, "multica issue update <issue-id> --attachment <path>") {t.Errorf("update hint missing, got: %v", msg)}- if !strings.Contains(msg, "multica issue comment add <issue-id> --attachment <path>") {- t.Errorf("update hint must redirect to comment add, got: %v", msg)- }- if strings.Contains(msg, "multica issue update --attachment") {- t.Errorf("update hint must never name a flag `issue update` does not have, got: %v", msg)+ if strings.Contains(msg, "multica issue comment add") {+ t.Errorf("update hint must not redirect to comment add, got: %v", msg)}}diff --git a/server/internal/service/builtin_skills/multica-platform/references/issues.md b/server/internal/service/builtin_skills/multica-platform/references/issues.mdindex a1ac4e7e13..bf0b138278 100644--- a/server/internal/service/builtin_skills/multica-platform/references/issues.md+++ b/server/internal/service/builtin_skills/multica-platform/references/issues.md@@ -10,6 +10,8 @@ Product contracts the runtime brief does not fully encode.- [Sub-issues: todo starts work now, backlog parks it](#sub-issues-todo-starts-work-now-backlog-parks-it)- [Incorrect to correct](#incorrect-to-correct)+To attach a local file to an existing issue description, use `multica issue update <id> --attachment <local-path>`. The CLI appends the file's Markdown reference to the end of the description; to replace an image, also use `--description-file` to remove the old reference. Do not put local filesystem paths in the description.+## PR linking and auto-completeA PR is linked to an issue when its **title** or **branch name** contains a