diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 6766583bad..5c2a26edfd 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -86,6 +86,15 @@ type ToolProps = { part: ToolPart } +// altimate_change start — upstream_fix: run quoted space-containing prompt arguments, which reached the model as literal quotes +export function joinRunMessage(args: string[], command: boolean): string { + if (!command) return args.join(" ") + return args + .map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg)) + .join(" ") +} +// altimate_change end + function props(part: ToolPart): ToolProps { const state = part.state return { @@ -485,9 +494,9 @@ export const RunCommand = cmd({ }) // altimate_change end - let message = [...args.message, ...(args["--"] || [])] - .map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg)) - .join(" ") + // altimate_change start — upstream_fix: run quoted space-containing prompt arguments, which reached the model as literal quotes + let message = joinRunMessage([...args.message, ...(args["--"] || [])], Boolean(args.command)) + // altimate_change end const directory = (() => { if (!args.dir) return undefined diff --git a/packages/opencode/test/cli/cmd/run-message.test.ts b/packages/opencode/test/cli/cmd/run-message.test.ts new file mode 100644 index 0000000000..1f4da32db0 --- /dev/null +++ b/packages/opencode/test/cli/cmd/run-message.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, test } from "bun:test" +import { joinRunMessage } from "../../../src/cli/cmd/run" +import { correctionReason } from "../../../src/altimate/learn/correction" + +describe("run message arguments", () => { + test("preserves spaces and literal quotes in a plain prompt", () => { + expect(joinRunMessage(['Use "to_utc" here.'], false)).toBe('Use "to_utc" here.') + }) + + test("joins multiple plain prompt arguments with a single space", () => { + expect(joinRunMessage(["Please", "use to_utc", "here."], false)).toBe("Please use to_utc here.") + }) + + test("quotes command arguments containing spaces and escapes embedded quotes as before", () => { + expect(joinRunMessage(["first", 'use "to_utc" here', '"last"'], true)).toBe( + 'first "use \\"to_utc\\" here" "last"', + ) + }) + + test("keeps a single-argument correction recognizable by learning capture", () => { + const message = joinRunMessage(["No, use to_utc."], false) + expect(message).toBe("No, use to_utc.") + expect(correctionReason(message)).toBe("user rejected the previous action and gave a direction") + }) +})