Skip to content

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

Go

fix(daemon): offer a Git Bash variant of the Windows reply cookbook (MUL-7554) (#8634)

Bohan Jiang624648cc1426
diff --git a/server/internal/daemon/execenv/reply_instructions.go b/server/internal/daemon/execenv/reply_instructions.go
index dfb48a2168..e1ae87c64e 100644
--- a/server/internal/daemon/execenv/reply_instructions.go
+++ b/server/internal/daemon/execenv/reply_instructions.go
@@ -284,17 +284,29 @@ func buildCommentReplyInstructionsSlim(provider, issueID, triggerCommentID strin
// gate also keeps ./reply.md on disk after a failure, so the retry does
// not have to regenerate the body.
if runtimeGOOS == "windows" {
- // PowerShell 5.1 has no `&&` (it landed in PowerShell 7), so the
- // Windows variant checks $LASTEXITCODE — which carries the exit
- // code of the last NATIVE command — and propagates it instead.
+ // The daemon knows the host OS, not the shell behind the agent's
+ // command tool: Codex runs PowerShell on Windows, Claude Code runs
+ // Git Bash for its Bash tool and (by default on claude.ai accounts)
+ // a PowerShell tool the user can turn off with
+ // CLAUDE_CODE_USE_POWERSHELL_TOOL=0 (#8627). A PowerShell-only
+ // cookbook pasted into Git Bash fails at the `if (` line AFTER the
+ // post succeeded, so the agent sees a failure and may re-post. Offer
+ // one variant per shell and let the agent pick.
+ //
+ // PowerShell 5.1 has no `&&` (it landed in PowerShell 7), so that
+ // variant checks $LASTEXITCODE — which carries the exit code of the
+ // last NATIVE command — and propagates it instead.
return fmt.Sprintf(
lead+
"do NOT reuse --parent values from previous turns in this session.\n\n"+
- "Write the body file first — never pipe via `--content-stdin` (PowerShell drops non-ASCII; full rules: ## Comment Formatting above):\n\n"+
- " multica issue comment add %s --parent %s --content-file ./reply.md --output table\n"+
+ "Write the body file first — never pipe via `--content-stdin` (PowerShell drops non-ASCII; full rules: ## Comment Formatting above). Use the variant for the shell your command tool runs:\n\n"+
+ "PowerShell:\n\n"+
+ " multica issue comment add %[1]s --parent %[2]s --content-file ./reply.md --output table\n"+
" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }\n"+
" Remove-Item ./reply.md\n\n"+
- "Do NOT drop the exit-code check: a bare `Remove-Item` after a failed post reports success and deletes the body.\n\n"+
+ "Git Bash:\n\n"+
+ " multica issue comment add %[1]s --parent %[2]s --content-file ./reply.md --output table && rm ./reply.md\n\n"+
+ "Do NOT drop the exit-code check or the `&&`: a bare cleanup after a failed post reports success and deletes the body.\n\n"+
"Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n",
issueID, triggerCommentID,
)
diff --git a/server/internal/daemon/execenv/reply_instructions_shell_test.go b/server/internal/daemon/execenv/reply_instructions_shell_test.go
index 18c13a1ac7..7fdf807bda 100644
--- a/server/internal/daemon/execenv/reply_instructions_shell_test.go
+++ b/server/internal/daemon/execenv/reply_instructions_shell_test.go
@@ -11,20 +11,36 @@ import (
"testing"
)
-// snippetLines returns the indented command block of a rendered reply
-// cookbook — the lines an agent actually pastes into one shell call.
-func snippetLines(t *testing.T, rendered string) []string {
+// snippetBlock returns the indented command block of a rendered reply
+// cookbook that contains marker — the lines an agent actually pastes into one
+// shell call. The Windows cookbook carries one block per shell (PowerShell and
+// Git Bash, #8627), so a caller names the block by a token unique to it.
+func snippetBlock(t *testing.T, rendered, marker string) []string {
t.Helper()
- var out []string
+ var block []string
+ flush := func() []string {
+ for _, line := range block {
+ if strings.Contains(line, marker) {
+ return block
+ }
+ }
+ return nil
+ }
for _, line := range strings.Split(rendered, "\n") {
if strings.HasPrefix(line, " ") && strings.TrimSpace(line) != "" {
- out = append(out, strings.TrimSpace(line))
+ block = append(block, strings.TrimSpace(line))
+ continue
}
+ if found := flush(); found != nil {
+ return found
+ }
+ block = nil
}
- if len(out) == 0 {
- t.Fatalf("reply instructions contain no command block\n---\n%s", rendered)
+ if found := flush(); found != nil {
+ return found
}
- return out
+ t.Fatalf("reply instructions contain no command block with %q\n---\n%s", marker, rendered)
+ return nil
}
// stubMultica puts a fake `multica` on PATH that exits with the given code, so
@@ -95,24 +111,37 @@ func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {
const triggerID = "22222222-2222-2222-2222-222222222222"
for _, tc := range []struct {
- name string
- goos string
- shell string
- wrap func(script string) []string
+ name string
+ goos string
+ shell string
+ marker string
+ wrap func(script string) []string
}{
{
- name: "posix/sh",
- goos: "linux",
- shell: "sh",
- wrap: func(script string) []string { return []string{"-c", script} },
+ name: "posix/sh",
+ goos: "linux",
+ shell: "sh",
+ marker: "&&",
+ wrap: func(script string) []string { return []string{"-c", script} },
},
{
// PowerShell is cross-platform, so this exercises the Windows
// cookbook's $LASTEXITCODE gate wherever pwsh is installed.
- name: "windows/pwsh",
- goos: "windows",
- shell: "pwsh",
- wrap: func(script string) []string { return []string{"-NoProfile", "-Command", script} },
+ name: "windows/pwsh",
+ goos: "windows",
+ shell: "pwsh",
+ marker: "$LASTEXITCODE",
+ wrap: func(script string) []string { return []string{"-NoProfile", "-Command", script} },
+ },
+ {
+ // The Windows cookbook's Git Bash variant (#8627): a Claude Code
+ // agent with the PowerShell tool turned off pastes this one into
+ // bash.exe. Any POSIX sh exercises the same `&&` gate.
+ name: "windows/git-bash",
+ goos: "windows",
+ shell: "sh",
+ marker: "&&",
+ wrap: func(script string) []string { return []string{"-c", script} },
},
} {
t.Run(tc.name, func(t *testing.T) {
@@ -120,7 +149,7 @@ func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {
t.Skipf("%s not available: %v", tc.shell, err)
}
runtimeGOOS = tc.goos
- script := strings.Join(snippetLines(t, BuildCommentReplyInstructions("claude", issueID, triggerID, false)), "\n")
+ script := strings.Join(snippetBlock(t, BuildCommentReplyInstructions("claude", issueID, triggerID, false), tc.marker), "\n")
t.Run("failed post keeps the failure and the body", func(t *testing.T) {
code, bodyKept := runSnippet(t, tc.shell, tc.wrap(script), stubMultica(t, 3))
diff --git a/server/internal/daemon/execenv/reply_instructions_test.go b/server/internal/daemon/execenv/reply_instructions_test.go
index 0a4a2da0ea..6220bcb5d1 100644
--- a/server/internal/daemon/execenv/reply_instructions_test.go
+++ b/server/internal/daemon/execenv/reply_instructions_test.go
@@ -146,6 +146,11 @@ func TestBuildCommentReplyInstructionsWindowsUsesContentFile(t *testing.T) {
// Formatting variant; the per-turn cookbook keeps the ban,
// the one-line consequence, and the pointer.
"if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }",
+ // #8627: the host OS does not fix the agent's shell — Claude
+ // Code with CLAUDE_CODE_USE_POWERSHELL_TOOL=0 runs Git Bash —
+ // so the Windows cookbook carries a `&&` variant too.
+ "Git Bash",
+ "multica issue comment add " + issueID + " --parent " + triggerID + " --content-file ./reply.md --output table && rm ./reply.md",
"Write the body file first",
"never pipe via `--content-stdin`",
"PowerShell drops non-ASCII",
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index 37f6d1389c..c87701a6a9 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -396,7 +396,7 @@ func writeIssueBodyFormatting(b *strings.Builder) {
// shell is a wrong comment), while the receipt mode only decides how much of
// an already-correct comment is echoed back, so it must not displace the
// guardrail from the section lede.
-const commentReceiptRule = "For final-result comments, use `--output table` to confirm success without echoing the body. Use `--output json` instead when you need the returned comment ID, attachment details, or other response fields. Gate the cleanup on the post succeeding (`&&`, or an `$LASTEXITCODE` check on Windows): a cleanup command run unconditionally succeeds after a failed post and makes the whole shell call exit 0, and under `--output table` empty stdout alone does not prove success.\n\n"
+const commentReceiptRule = "For final-result comments, use `--output table` to confirm success without echoing the body. Use `--output json` instead when you need the returned comment ID, attachment details, or other response fields. Gate the cleanup on the post succeeding (`&&` in bash or Git Bash, an `$LASTEXITCODE` check in PowerShell): a cleanup command run unconditionally succeeds after a failed post and makes the whole shell call exit 0, and under `--output table` empty stdout alone does not prove success.\n\n"
// writeCommentFormatting emits the cross-platform file-first guardrail.
// The Windows branch carries the `$OutputEncoding` rationale: Windows
@@ -407,7 +407,7 @@ const commentReceiptRule = "For final-result comments, use `--output table` to c
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` (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`) only after the post succeeded; 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` in PowerShell, `rm ./reply.md` in Git Bash) only after the post succeeded; do not rely on `\\n` escapes.\n\n")
b.WriteString(commentReceiptRule)
return
}