Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(daemon): stage-2 — Mentions and Comment Formatting judgment rewrite (MUL-5442) (#6453)
Bohan Jiang62a2d70afd43
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.goindex 0bdbaba7d4..6e6a5bfb31 100644--- a/server/internal/daemon/execenv/execenv_test.go+++ b/server/internal/daemon/execenv/execenv_test.go@@ -2048,17 +2048,31 @@ func TestInjectRuntimeConfigLinuxCommentFormattingEmphasizesFile(t *testing.T) {}s := string(data)+ // Assert inside the section slice: "#4182" also appears in+ // Available Commands, so a whole-file Contains would stay green+ // with the HEREDOC ban deleted here (review catch on #6453).+ // Match the HEADING at line start — Available Commands references+ // "## Comment Formatting" inline earlier in the file.+ cfStart := strings.Index(s, "\n## Comment Formatting\n")+ if cfStart < 0 {+ t.Fatalf("%s missing ## Comment Formatting section\n---\n%s", fileName, s)+ }+ cf := s[cfStart+1:]+ if next := strings.Index(cf[3:], "\n## "); next >= 0 {+ cf = cf[:next+3]+ }for _, want := range []string{- "## Comment Formatting","always write the comment body to a UTF-8 file with your file-write tool first, then post it with `--content-file <path>`",- "#4182","Never use inline `--content` for agent-authored comments",+ "never use `--content-stdin` HEREDOCs alongside other flags",+ "#4182",+ "never `/tmp` or shared paths","Keep the same `--parent` value","rm ./reply.md","do not rely on `\\n` escapes",} {- if !strings.Contains(s, want) {- t.Errorf("%s missing comment-formatting guidance %q\n---\n%s", fileName, want, s)+ if !strings.Contains(cf, want) {+ t.Errorf("%s Comment Formatting section missing %q\n---\n%s", fileName, want, cf)}}@@ -2101,7 +2115,7 @@ func TestInjectRuntimeConfigCodexWindowsUsesContentFile(t *testing.T) {"On Windows, **always write the comment body to a UTF-8 file","$OutputEncoding","--content-file",- "silently dropping non-ASCII characters as `?`",+ "may replace non-ASCII characters with `?`",} {if !strings.Contains(s, want) {t.Errorf("AGENTS.md missing Codex/Windows file-first guidance %q\n---\n%s", want, s)@@ -4951,8 +4965,17 @@ func TestInjectRuntimeConfigMentionLoopHardening(t *testing.T) {for _, want := range []string{"side-effecting actions","enqueues a new run for that agent",- "When NOT to use a mention link",- "When a mention IS appropriate",+ // MUL-5442 judgment rewrite: the two H3 subsections merged into one+ // paragraph — pin the policy anchors, not the retired headings.+ "Default: NO mention",+ // Each warranted-case scope qualifier pinned separately — "not yet+ // involved" and "for the first time" ARE the anti-repeat-notify+ // scope, not decoration (review catch on #6453).+ "restarts an agent-to-agent loop and costs the user money",+ "Mention only when escalating to a human owner",+ "not yet involved",+ "for the first time",+ "explicitly asks to loop someone in","end with no mention at all","Silence ends conversations",} {diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 2dfd0edd68..c05a4a07af 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -300,15 +300,18 @@ func writeIssueBodyFormatting(b *strings.Builder) {}// writeCommentFormatting emits the cross-platform file-first guardrail.-// Windows branch carries the `$OutputEncoding` rationale because Windows-// PowerShell silently drops non-ASCII through stdin.+// The Windows branch carries the `$OutputEncoding` rationale: Windows+// PowerShell 5.1 defaults $OutputEncoding to ASCII and may replace+// non-ASCII with `?` when piping to native commands; PowerShell 6++// defaults to utf8NoBOM, but the file-first rule stays version-agnostic+// because agents cannot rely on which shell services the pipe.func writeCommentFormatting(b *strings.Builder) {b.WriteString("## Comment Formatting\n\n")if runtimeGOOS == "windows" {- b.WriteString("On Windows, **always write the comment body to a UTF-8 file with your file-write tool first, then post it with `--content-file <path>`** — do NOT pipe via `--content-stdin` (PowerShell 5.1's `$OutputEncoding` defaults to ASCIIEncoding when piping to a native command, silently dropping non-ASCII characters as `?`). Never use inline `--content` for agent-authored comments. Write the file inside your working directory, never `/tmp` or shared paths (MUL-4252). Keep the same `--parent` value from the trigger comment when replying. Delete the temp file (`Remove-Item ./reply.md`) after posting; do not rely on `\\n` escapes.\n\n")+ b.WriteString("On Windows, **always write the comment body to a UTF-8 file with your file-write tool first, then post it with `--content-file <path>`** — do NOT pipe via `--content-stdin` (Windows PowerShell 5.1's `$OutputEncoding` may replace non-ASCII characters with `?`). Never use inline `--content` for agent-authored comments. Write the file inside your working directory, never `/tmp` or shared paths (MUL-4252). Keep the same `--parent` value from the trigger comment when replying. Delete the temp file (`Remove-Item ./reply.md`) after posting; do not rely on `\\n` escapes.\n\n")return}- b.WriteString("For issue comments, **always write the comment body to a UTF-8 file with your file-write tool first, then post it with `--content-file <path>`**. Never use inline `--content` for agent-authored comments — the shell rewrites the body (MUL-2904); never use `--content-stdin` HEREDOCs alongside other flags — flags get silently swallowed (#4182). Write the file inside your working directory, never `/tmp` or shared paths (MUL-4252). Keep the same `--parent` value from the trigger comment when replying; delete the temp file (`rm ./reply.md`) after posting; do not rely on `\\n` escapes.\n\n")+ b.WriteString("For issue comments, **always write the comment body to a UTF-8 file with your file-write tool first, then post it with `--content-file <path>`**. Never use inline `--content` for agent-authored comments (MUL-2904); never use `--content-stdin` HEREDOCs alongside other flags (#4182). Write the file inside your working directory, never `/tmp` or shared paths (MUL-4252). Keep the same `--parent` value from the trigger comment when replying; delete the temp file (`rm ./reply.md`) after posting; do not rely on `\\n` escapes.\n\n")}// writeRepositories emits the Repositories section when at least one repo@@ -641,10 +644,7 @@ func writeMentions(b *strings.Builder) {b.WriteString("- `[Project Name](mention://project/<project-id>)` — clickable link (no side effect)\n")b.WriteString("- `[@Name](mention://member/<user-id>)` — **notifies a human**\n")b.WriteString("- `[@Name](mention://agent/<agent-id>)` — **enqueues a new run for that agent**\n\n")- b.WriteString("### When NOT to use a mention link\n\n")- b.WriteString("Default: NO mention. Never @mention the agent you are replying to as a thank-you or sign-off — when replying to an agent that just spoke to you, or thanking / acknowledging / signing off, **end with no mention at all**. An accidental `@mention` restarts an agent-to-agent loop and costs the user money.\n\n")- b.WriteString("### When a mention IS appropriate\n\n")- b.WriteString("Escalating to a human owner not yet involved; delegating a concrete new sub-task to another agent for the first time; or when the user explicitly asks to loop someone in. Otherwise **don't mention**. Silence ends conversations.\n\n")+ b.WriteString("Default: NO mention — an accidental `@mention` restarts an agent-to-agent loop and costs the user money. Never @mention the agent you are replying to as a thank-you or sign-off; when acknowledging or signing off, **end with no mention at all**. Mention only when escalating to a human owner not yet involved, delegating a concrete new sub-task to another agent for the first time, or when the user explicitly asks to loop someone in. Silence ends conversations.\n\n")}// writeAttachments emits the Attachments pointer.