Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(daemon): stage-1 judgment rewrite — mode router and small guardrail sections (MUL-5442) (#6365)
Bohan Jiang1e661bb04bdd
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.goindex 1464f70a81..3ace68321e 100644--- a/server/internal/daemon/execenv/execenv_test.go+++ b/server/internal/daemon/execenv/execenv_test.go@@ -4993,6 +4993,12 @@ func TestInjectRuntimeConfigMentionLoopHardening(t *testing.T) {// pinning which section carries it.for _, want := range []string{"Decide whether a reply is warranted",+ // Both outcomes pinned individually (MUL-5442 stage-1 review):+ // the work-produced arm and the silent-exit arm must each+ // survive compression, not just the bullet's heading.+ "produced actual work",+ "pure acknowledgment / thanks / sign-off",+ "do NOT reply","Silence is a valid and preferred way","Never @mention the agent you are replying to as a thank-you or sign-off",} {@@ -5662,6 +5668,10 @@ func TestInjectRuntimeConfigIssueMetadataSectionScope(t *testing.T) {filename: "CLAUDE.md",workflowStepPresent: []string{"multica issue metadata list issue-md-1 --output json",+ // Platform failure semantics, not tool mechanics: a failed+ // metadata read must never block the main task (MUL-5442+ // stage-1 review).+ "CLI failures are normal",// Both steps point at the section instead of restating its// rules (MUL-5442); the entry step names what to look for,// the exit step names the write bar.diff --git a/server/internal/daemon/execenv/reply_instructions_test.go b/server/internal/daemon/execenv/reply_instructions_test.goindex f24731f2f0..b53a6241a6 100644--- a/server/internal/daemon/execenv/reply_instructions_test.go+++ b/server/internal/daemon/execenv/reply_instructions_test.go@@ -197,7 +197,19 @@ func TestInjectRuntimeConfigKeepsTriggerCommentOutOfBrief(t *testing.T) {t.Errorf("CLAUDE.md must not carry the trigger comment id (MUL-5377)\n---\n%s", s)}for _, want := range []string{- "Mode router",+ // MUL-5442 stage 1: the mode-router paragraph compressed to a+ // "Turn mode." lead. Pin every routing RULE, not just the markers —+ // a further compression that drops the one-block rule or the+ // no-mode-line fallback must fail here (stage-1 review).+ "**Turn mode.**",+ "Steps 1–6 are shared",+ "apply exactly one mode block",+ "differ on issue status",+ // The full fallback MAPPING, not its halves: "No mode line" and+ // "Reply mode" pinned separately could both pass while the text+ // says "No mode line → Ownership mode" (final-review catch).+ "No mode line → Reply mode",+ "do not change the issue status","`Turn mode: Reply.`","`Turn mode: Ownership.`","Use the `--parent` value the per-turn user message gives you for this turn",diff --git a/server/internal/daemon/execenv/runtime_config_kind_test.go b/server/internal/daemon/execenv/runtime_config_kind_test.goindex cd441aa5de..f0aa15e4ac 100644--- a/server/internal/daemon/execenv/runtime_config_kind_test.go+++ b/server/internal/daemon/execenv/runtime_config_kind_test.go@@ -96,7 +96,10 @@ func TestBuildMetaSkillContentIssueBodyFormatting(t *testing.T) {for _, want := range []string{"## Issue Body Formatting","An issue title already serves as its H1.",- "do not add a Markdown H1 (`# ...`)",+ // The rule covers BOTH surfaces: `description` is the CLI/API+ // field name, `body` the UI term — the alias is a cross-surface+ // mapping, not prose (MUL-5442 stage-1 review).+ "do not add a Markdown H1 (`# ...`) to an issue body or description","start with prose or `##` subheadings","Only add an H1 when the user specifically requests one",} {diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 9121bbec0a..e6a7716487 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -300,7 +300,7 @@ func writeAvailableCommandsQuickCreate(b *strings.Builder) {// surfaces.func writeIssueBodyFormatting(b *strings.Builder) {b.WriteString("## Issue Body Formatting\n\n")- b.WriteString("An issue title already serves as its H1. By default, do not add a Markdown H1 (`# ...`) to an issue body or description; start with prose or `##` subheadings instead. Only add an H1 when the user specifically requests one.\n\n")+ b.WriteString("An issue title already serves as its H1. By default, do not add a Markdown H1 (`# ...`) to an issue body or description; start with prose or `##` subheadings. Only add an H1 when the user specifically requests one.\n\n")}// writeCommentFormatting emits the cross-platform file-first guardrail.@@ -309,10 +309,10 @@ func writeIssueBodyFormatting(b *strings.Builder) {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 `?` before they reach `multica.exe`). Never use inline `--content` for agent-authored comments. Write that file inside your working directory (`./reply.md`), never `/tmp` or shared paths — the CLI rejects a `--content-file` path outside the workdir so another run's stale file can't leak in (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` (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")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 backticks / `$()` / quotes in the body (MUL-2904). Never use `--content-stdin` with a HEREDOC alongside other flags either — the heredoc/flag boundary is fragile and flags get silently swallowed (#4182). Write that file inside your working directory (`./reply.md`), never `/tmp` or shared paths — the CLI rejects a `--content-file` path outside the workdir so another run's stale file can't leak in (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 — 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")}// writeRepositories emits the Repositories section when at least one repo@@ -512,10 +512,7 @@ func writeWorkflowAutopilot(b *strings.Builder, ctx TaskContextForEnv) {// ctx.IsSquadLeader is agent configuration, not per-run state, so branching// on it does not break byte-stability across runs of one session.func writeWorkflowIssue(b *strings.Builder, ctx TaskContextForEnv) {- b.WriteString("**Mode router — read this before acting.** This file is identical on every run, so it cannot tell you what triggered THIS turn. The user message for this turn names its mode on a line of its own:\n\n")- b.WriteString("- `Turn mode: Reply.` → **Reply mode**. That message also carries the triggering comment's id, the exact `--parent` value for your reply, and the comment's content when the platform supplied it.\n")- b.WriteString("- `Turn mode: Ownership.` → **Ownership mode** (an assignment or status change started this run).\n\n")- b.WriteString("Steps 1–6 below are the same in both modes. The mode blocks after them differ, and they differ on issue status in particular — **apply exactly one mode block, the one the user message named. Never apply both.** If neither line is present, treat the turn as Reply mode and do not change the issue status.\n\n")+ b.WriteString("**Turn mode.** The per-turn user message names this run's mode on a line of its own: `Turn mode: Reply.` (respond to the comment that message carries — it brings the triggering comment's id and your `--parent` value) or `Turn mode: Ownership.` (an assignment or status change started this run). Steps 1–6 are shared; then **apply exactly one mode block, the one the user message named** — they differ on issue status. No mode line → Reply mode, do not change the issue status.\n\n")b.WriteString("**Steps 1–6 — both modes**\n\n")fmt.Fprintf(b, "1. Run `multica issue get %s --output json` to understand the issue context\n", ctx.IssueID)@@ -539,8 +536,8 @@ func writeWorkflowIssue(b *strings.Builder, ctx TaskContextForEnv) {fmt.Fprintf(b, "- If blocked, run `multica issue status %s blocked`, and post a comment explaining the blocker unless your Agent Identity forbids issue comments.\n\n", ctx.IssueID)b.WriteString("**Reply mode only — respond to the comment in the user message**\n\n")- b.WriteString("- Your primary job is to respond to THAT specific comment, even if you have handled similar requests before in this session. Do NOT confuse it with previous comments; take its id from the user message, never from this file or from an earlier turn.\n")- b.WriteString("- **Decide whether a reply is warranted.** If you produced actual work this turn (investigated, fixed, answered a real question), post the result via step 5 — that is a normal reply, not a noise comment. If the triggering comment was a pure acknowledgment / thanks / sign-off from another agent AND you produced no work this turn, do NOT post a reply — and do NOT post a comment saying 'No reply needed' or similar. Simply exit with no output. Silence is a valid and preferred way to end agent-to-agent conversations.\n")+ b.WriteString("- Respond to THAT specific comment; take its id from the user message, never from this file or from an earlier turn.\n")+ b.WriteString("- **Decide whether a reply is warranted.** If you produced actual work this turn, post the result via step 5. If the triggering comment was a pure acknowledgment / thanks / sign-off from another agent AND you produced no work, do NOT reply — not even a 'No reply needed' comment; exit with no output. Silence is a valid and preferred way to end agent-to-agent conversations.\n")if ctx.IsSquadLeader {fmt.Fprintf(b, "- **Squad leader rule:** If your evaluation outcome is `no_action`, call `multica squad activity %s no_action --reason \"...\"` and then EXIT IMMEDIATELY. DO NOT post any comment whose only purpose is to announce that you are taking no action, exiting silently, or acknowledging another agent. A comment like \"No action needed\" or \"Exiting silently\" is noise — the `squad activity` call already records your decision in the timeline.\n", ctx.IssueID)}@@ -639,7 +636,7 @@ func writeAttachments(b *strings.Builder) {// (compressed).func writeAlwaysUseCLI(b *strings.Builder) {b.WriteString("## Important: Always Use the `multica` CLI\n\n")- b.WriteString("Access Multica platform resources (issues, comments, attachments, files) only through the `multica` CLI — never `curl` / `wget`. For any operation the CLI doesn't cover, post a comment mentioning the workspace owner rather than working around it.\n\n")+ b.WriteString("Access Multica platform resources only through the `multica` CLI — never `curl` / `wget`. For anything the CLI doesn't cover, post a comment mentioning the workspace owner rather than working around it.\n\n")}// writeDeliveryInvariant emits the always-on delivery contract, shared by every