Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/opencode/src/cli/cmd/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ type ToolProps<T = Tool.Info> = {
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<T = Tool.Info>(part: ToolPart): ToolProps<T> {
const state = part.state
return {
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions packages/opencode/test/cli/cmd/run-message.test.ts
Original file line number Diff line number Diff line change
@@ -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")
})
})
Loading