Skip to content

Commit 350938c

Browse files
anandgupta42claude
andauthored
fix(cli): stop quoting plain run prompt arguments (AltimateAI#1560) (AltimateAI#1561)
Plain `run` prompts are joined with spaces instead of having each space-containing argument wrapped in quotes, which reached the model and hid corrections from learn capture. `--command` keeps its quoting for `$1`/`$2` expansion. Closes AltimateAI#1560 Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3d5a704 commit 350938c

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ type ToolProps<T = Tool.Info> = {
8686
part: ToolPart
8787
}
8888

89+
// altimate_change start — upstream_fix: run quoted space-containing prompt arguments, which reached the model as literal quotes
90+
export function joinRunMessage(args: string[], command: boolean): string {
91+
if (!command) return args.join(" ")
92+
return args
93+
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
94+
.join(" ")
95+
}
96+
// altimate_change end
97+
8998
function props<T = Tool.Info>(part: ToolPart): ToolProps<T> {
9099
const state = part.state
91100
return {
@@ -485,9 +494,9 @@ export const RunCommand = cmd({
485494
})
486495
// altimate_change end
487496

488-
let message = [...args.message, ...(args["--"] || [])]
489-
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
490-
.join(" ")
497+
// altimate_change start — upstream_fix: run quoted space-containing prompt arguments, which reached the model as literal quotes
498+
let message = joinRunMessage([...args.message, ...(args["--"] || [])], Boolean(args.command))
499+
// altimate_change end
491500

492501
const directory = (() => {
493502
if (!args.dir) return undefined
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { joinRunMessage } from "../../../src/cli/cmd/run"
3+
import { correctionReason } from "../../../src/altimate/learn/correction"
4+
5+
describe("run message arguments", () => {
6+
test("preserves spaces and literal quotes in a plain prompt", () => {
7+
expect(joinRunMessage(['Use "to_utc" here.'], false)).toBe('Use "to_utc" here.')
8+
})
9+
10+
test("joins multiple plain prompt arguments with a single space", () => {
11+
expect(joinRunMessage(["Please", "use to_utc", "here."], false)).toBe("Please use to_utc here.")
12+
})
13+
14+
test("quotes command arguments containing spaces and escapes embedded quotes as before", () => {
15+
expect(joinRunMessage(["first", 'use "to_utc" here', '"last"'], true)).toBe(
16+
'first "use \\"to_utc\\" here" "last"',
17+
)
18+
})
19+
20+
test("keeps a single-argument correction recognizable by learning capture", () => {
21+
const message = joinRunMessage(["No, use to_utc."], false)
22+
expect(message).toBe("No, use to_utc.")
23+
expect(correctionReason(message)).toBe("user rejected the previous action and gave a direction")
24+
})
25+
})

0 commit comments

Comments
 (0)