Skip to content

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

Go

fix(cli): make doc write guidance render and stop inviting body resends (#11376)

Bohan Jiangf8602f0452c9
diff --git a/server/cmd/multica/cmd_doc.go b/server/cmd/multica/cmd_doc.go
index 395b518c81..24586a8873 100644
--- a/server/cmd/multica/cmd_doc.go
+++ b/server/cmd/multica/cmd_doc.go
@@ -25,14 +25,6 @@ import (
var docCmd = &cobra.Command{
Use: "doc",
Short: "Work with knowledge base docs",
- Long: "Read and write docs in the workspace knowledge base.\n\n" +
- "People may be editing a doc while you work on it. For targeted changes prefer " +
- "`multica doc edit`: it replaces text you quote and lands wherever that text now is. " +
- "`multica doc update` replaces the whole doc and needs --base-revision, the revision you read " +
- "with `multica doc get`; edits made since then are usually merged in. The update is refused, with nothing " +
- "written, when you and someone else changed the same paragraph, and also when your revision is too old " +
- "to merge from or the live-editing service is unavailable. " +
- "Pass --message to say what changed and why — it shows in the doc's history.",
}
var docListCmd = &cobra.Command{
@@ -80,8 +72,17 @@ var docCreateCmd = &cobra.Command{
var docUpdateCmd = &cobra.Command{
Use: "update <doc-id>",
Short: "Update a doc's title or content",
- Args: exactArgs(1),
- RunE: runDocUpdate,
+ Long: "Replace a doc's title or its whole content.\n\n" +
+ "People may be editing a doc while you work on it. For targeted changes prefer " +
+ "`multica doc edit`: it replaces text you quote and lands wherever that text now is. " +
+ "--base-revision is the revision you read with `multica doc get`; edits made since then are usually merged in. " +
+ "The update is refused, with nothing written, when you and someone else changed the same paragraph, " +
+ "and also when your revision is too old to merge from or the live-editing service is unavailable. " +
+ "On a refusal, run `multica doc get` and redo your change on that content; never resend the same body " +
+ "with the new revision, which would erase their edits. " +
+ "Pass --message to say what changed and why — it shows in the doc's history.",
+ Args: exactArgs(1),
+ RunE: runDocUpdate,
}
var docEditCmd = &cobra.Command{
@@ -91,7 +92,7 @@ var docEditCmd = &cobra.Command{
"--old must match the doc's current Markdown exactly once (copy it from `multica doc get --output content`, " +
"with enough surrounding text to be unique), or at least once with --replace-all. " +
"The edit applies to the live doc, so it is safe while people are editing; " +
- "it fails only when the quoted text is no longer there.",
+ "it fails, with nothing written, only when the quoted text is gone or, without --replace-all, appears more than once.",
Args: exactArgs(1),
RunE: runDocEdit,
}
@@ -123,8 +124,6 @@ var docRestoreCmd = &cobra.Command{
var docCommentCmd = &cobra.Command{
Use: "comment",
Short: "Read the discussion on a doc",
- Long: "Read the comment threads people left on a doc. Writing in doc discussions " +
- "(commenting, replying, resolving) is reserved for people, so there are no write commands.",
}
var docCommentListCmd = &cobra.Command{
@@ -133,7 +132,8 @@ var docCommentListCmd = &cobra.Command{
Long: "List the comment threads on a doc, each root comment followed by its replies. " +
"A root comment's QUOTE (anchor_quote in --output json) is the doc text it was left on.\n\n" +
"Resolved threads are hidden unless you pass --include-resolved. " +
- "The table shortens long comments; --output json has the full text.",
+ "The table shortens long comments; --output json has the full text.\n\n" +
+ "Writing in doc discussions (commenting, replying, resolving) is reserved for people, so there are no write commands.",
Args: exactArgs(1),
RunE: runDocCommentList,
}
@@ -141,9 +141,6 @@ var docCommentListCmd = &cobra.Command{
var docFolderCmd = &cobra.Command{
Use: "folder",
Short: "Manage knowledge base doc folders",
- Long: "List, create, rename, and move folders in the workspace knowledge base.\n\n" +
- "Folder arguments and --parent accept a full folder id or a unique prefix from " +
- "`multica doc list` or `multica doc folder list`.",
}
var docFolderListCmd = &cobra.Command{
@@ -191,7 +188,7 @@ func init() {
docRestoreCmd.Flags().String("output", "json", "Output format: table or json")
docCommentListCmd.Flags().Bool("include-resolved", false, "Include resolved threads")
docCommentListCmd.Flags().String("output", "table", "Output format: table or json")
- docMoveCmd.Flags().String("folder", "", "Destination folder id, or `root` for the top level (required)")
+ docMoveCmd.Flags().String("folder", "", "Destination folder id or unique prefix, or \"root\" for the top level (required)")
docMoveCmd.Flags().String("output", "json", "Output format: table or json")
docListCmd.Flags().String("output", "table", "Output format: table or json")
docSearchCmd.Flags().Int("limit", 20, "Maximum results (at most 50)")
@@ -207,20 +204,20 @@ func init() {
}
docCreateCmd.Flags().String("folder", "", "Folder id (default: root)")
docUpdateCmd.Flags().Int64("base-revision", 0, "Revision from doc get (required)")
- docEditCmd.Flags().String("old", "", "Exact text to replace (required)")
+ docEditCmd.Flags().String("old", "", "Exact text to replace (this or --old-file is required)")
docEditCmd.Flags().String("old-file", "", "Read the text to replace from a UTF-8 file")
- docEditCmd.Flags().String("new", "", "Replacement text")
+ docEditCmd.Flags().String("new", "", "Replacement text; \"\" deletes it (this or --new-file is required)")
docEditCmd.Flags().String("new-file", "", "Read the replacement from a UTF-8 file")
docEditCmd.Flags().Bool("replace-all", false, "Replace every occurrence of --old")
docEditCmd.Flags().String("message", "", "Change summary for history")
docEditCmd.Flags().String("output", "json", "Output format: table or json")
docFolderListCmd.Flags().String("output", "table", "Output format: table or json")
docFolderCreateCmd.Flags().String("title", "", "Folder title (required)")
- docFolderCreateCmd.Flags().String("parent", "", "Parent folder id, or `root` for the top level (default: root)")
+ docFolderCreateCmd.Flags().String("parent", "", "Parent folder id or unique prefix, or \"root\" for the top level (default: root)")
docFolderCreateCmd.Flags().String("output", "json", "Output format: table or json")
docFolderUpdateCmd.Flags().String("title", "", "Folder title (required)")
docFolderUpdateCmd.Flags().String("output", "json", "Output format: table or json")
- docFolderMoveCmd.Flags().String("parent", "", "Destination parent folder id, or `root` for the top level (required)")
+ docFolderMoveCmd.Flags().String("parent", "", "Destination parent folder id or unique prefix, or \"root\" for the top level (required)")
docFolderMoveCmd.Flags().String("output", "json", "Output format: table or json")
}
@@ -288,8 +285,9 @@ func docWriteError(action string, base int64, err error) error {
action, base, httpErr.Body)
case strings.Contains(httpErr.Body, "doc_merge_conflict"):
return fmt.Errorf("%s: someone changed the same paragraphs since revision %d, so nothing was written. "+
- "The conflicts list both versions; run `multica doc get`, then apply your change with `multica doc edit` "+
- "or retry the update from the new revision (%s)", action, base, httpErr.Body)
+ "The conflicts list both versions; run `multica doc get` and redo your change on that content, "+
+ "with `multica doc edit`, or `multica doc update` with the new --base-revision. "+
+ "Do not resend the same body — it would erase their edits (%s)", action, base, httpErr.Body)
case strings.Contains(httpErr.Body, "doc_edit_failed"):
return fmt.Errorf("%s: nothing was written because --old does not match the doc exactly once. "+
"Run `multica doc get --output content`, quote the current text (with more context if it repeats), and retry (%s)",
diff --git a/server/cmd/multica/cmd_doc_test.go b/server/cmd/multica/cmd_doc_test.go
index f7d3464414..751faa0da2 100644
--- a/server/cmd/multica/cmd_doc_test.go
+++ b/server/cmd/multica/cmd_doc_test.go
@@ -61,6 +61,53 @@ func TestDocConflictErrorExplainsRecovery(t *testing.T) {
}
}
+func TestDocMergeConflictErrorForbidsResendingTheBody(t *testing.T) {
+ err := docWriteError("update doc", 3, &cli.HTTPError{StatusCode: http.StatusConflict, Body: `{"code":"doc_merge_conflict"}`})
+ for _, want := range []string{"nothing was written", "redo your change", "Do not resend the same body"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Fatalf("merge conflict error missing %q: %v", want, err)
+ }
+ }
+}
+
+// renderHelp renders cmd's --help the way the CLI prints it. Group commands
+// use subHelpTemplate, which prints only Short, so rules agents need must
+// live on the leaf commands the brief points at.
+func renderHelp(t *testing.T, cmd *cobra.Command) string {
+ t.Helper()
+ var out strings.Builder
+ cmd.SetOut(&out)
+ defer cmd.SetOut(nil)
+ if err := cmd.Help(); err != nil {
+ t.Fatalf("render %s help: %v", cmd.CommandPath(), err)
+ }
+ return out.String()
+}
+
+func TestDocHelpRendersWriteRules(t *testing.T) {
+ tests := []struct {
+ cmd *cobra.Command
+ want []string
+ }{
+ {docUpdateCmd, []string{"--base-revision", "refused, with nothing written", "never resend the same body"}},
+ {docEditCmd, []string{"without --replace-all, appears more than once", "this or --old-file is required", "this or --new-file is required"}},
+ {docCommentListCmd, []string{"reserved for people"}},
+ {docMoveCmd, []string{`--folder string`, `or "root" for the top level`}},
+ {docFolderCreateCmd, []string{`--parent string`, `or "root" for the top level`}},
+ {docFolderMoveCmd, []string{`--parent string`, `or "root" for the top level`}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.cmd.CommandPath(), func(t *testing.T) {
+ help := renderHelp(t, tt.cmd)
+ for _, want := range tt.want {
+ if !strings.Contains(help, want) {
+ t.Fatalf("%s --help missing %q; rendered:\n%s", tt.cmd.CommandPath(), want, help)
+ }
+ }
+ })
+ }
+}
+
func TestRunDocSearchQueriesServerSearch(t *testing.T) {
var gotPath string
var gotQuery url.Values
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index e824277d3d..d49c479f5c 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -295,7 +295,7 @@ func writeAvailableCommands(b *strings.Builder, ctx TaskContextForEnv) {
b.WriteString("- `multica issue wakeup <create|list|get|update|disable|trigger|delete|runs|events>` — persist an event, condition or time wakeup on this issue, then finish the current run. When the platform can check the fact itself, use one `--until-*` condition so no run starts before it holds; check the rule's `last_error` for missing PR links or snapshots, which are retried automatically. Conditions, PR rules and actor filters: `multica issue wakeup create --help` and the multica-platform issues reference.\n")
b.WriteString("- `multica issue children <id> [--output json]` — list a parent's sub-issues grouped by stage.\n")
if ctx.DocsEnabled {
- b.WriteString("- `multica doc list|search|get|create|edit|update|move|history|restore|comment|folder` — workspace docs and folders (`doc folder list|create|update|move`); `doc search <query>` matches titles and content; people may be editing a doc live, so change part of it with `doc edit <id> --old <exact text> --new <text>`; `doc update` rewrites the whole doc and needs `--base-revision` from `multica doc get`; `doc comment list <id>` shows the open review threads on a doc; `doc history` / `doc restore` read and roll back versions (details: `multica doc --help`).\n")
+ b.WriteString("- `multica doc list|search|get|create|edit|update|move|history|restore|comment|folder` — workspace docs and folders (`doc folder list|create|update|move`); `doc search <query>` matches titles and content; people may be editing a doc live, so change part of it with `doc edit <id> --old <exact text> --new <text>` (`--old-file` / `--new-file` for multi-line text or anything with code or quotes); `doc update` rewrites the whole doc and needs `--base-revision` from `multica doc get`; `doc comment list <id>` shows the open review threads on a doc; `doc history` / `doc restore` read and roll back versions (details: `multica doc update --help`, `multica doc edit --help`).\n")
}
b.WriteString("- `multica issue comment add <issue-id> [--content \"...\" | --content-file <path> | --content-stdin] [--parent <comment-id>] [--attachment <path>]` — post a comment. Agent-authored bodies MUST use `--content-file` with a file inside your working directory; full flags: `multica issue comment add --help`.\n")
b.WriteString("- `multica repo checkout <url> [--ref <branch-or-sha>] [--fresh]` — repository checkout on a dedicated branch; re-running it keeps a checkout that has uncommitted or unpushed work, or is already on this task's branch, and only fetches; a clean, fully pushed checkout on another branch starts over on a new branch. `--fresh` discards uncommitted and untracked files for a new branch; commits stay on the old branch, so push any you still need first.\n\n")
diff --git a/server/internal/service/builtin_skills/multica-platform/references/docs.md b/server/internal/service/builtin_skills/multica-platform/references/docs.md
index cb421f79e7..da320be892 100644
--- a/server/internal/service/builtin_skills/multica-platform/references/docs.md
+++ b/server/internal/service/builtin_skills/multica-platform/references/docs.md
@@ -29,8 +29,9 @@ saved snapshot in its history. They are different numbers.
```bash
multica doc edit <doc-id> --old "<exact current text>" --new "<replacement>" --message "why"
+multica doc edit <doc-id> --old-file ./old.md --new-file ./new.md --message "why"
multica doc update <doc-id> --content-file ./doc.md --base-revision <revision> --message "why"
-multica doc create --title "Runbook" --folder <folder-id> --content-file ./doc.md
+multica doc create --title "Runbook" --folder <folder-id> --content-file ./doc.md --message "why"
multica doc move <doc-id> --folder <folder-id|root>
multica doc folder create --title "Ops" --parent <folder-id|root>
```
@@ -38,14 +39,15 @@ multica doc folder create --title "Ops" --parent <folder-id|root>
People may be typing in the doc while you write. Prefer `doc edit` for a
targeted change: it replaces the text you quote wherever it now is, and fails
only when that text is gone or appears more than once (quote more context, or
-pass `--replace-all`). `doc update` replaces the whole doc and needs the
-`--base-revision` you read with `doc get`. Edits made since then are usually
-merged in, and the update is refused with nothing written when you and someone
-else changed the same paragraph. It is also refused, whatever paragraphs
-changed, when your revision is too old to merge from or the live-editing
-service is unavailable. On any refusal, read the doc again and redo your change
-on top of it; never retry the same body with a newer revision, which would
-erase their work.
+pass `--replace-all`). Use `--old-file` / `--new-file` for multi-line text or
+anything with code or quotes, so the shell cannot change it. `doc update`
+replaces the whole doc and needs the `--base-revision` you read with `doc get`.
+Edits made since then are usually merged in, and the update is refused with
+nothing written when you and someone else changed the same paragraph. It is
+also refused, whatever paragraphs changed, when your revision is too old to
+merge from or the live-editing service is unavailable. On any refusal, read the
+doc again and redo your change on top of it; never retry the same body with a
+newer revision, which would erase their work.
Pass `--message` on every `create`, `edit`, `update` and `restore`. It is what
the doc's history shows next to your name, and your run and issue are recorded