Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
9 changes: 6 additions & 3 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
const agentName = cmd.agent ?? input.agent

const raw = input.arguments.match(argsRegex) ?? []
const args = raw.map((arg) => arg.replace(quoteTrimRegex, ""))
const args = parseCommandArguments(input.arguments)
const templateCommand = yield* Effect.promise(async () => cmd.template)

const placeholders = templateCommand.match(placeholderRegex) ?? []
Expand Down Expand Up @@ -2151,7 +2150,11 @@ export function createStructuredOutputTool(input: {
const bashRegex = /!`([^`]+)`/g
// Match [Image N] as single token, quoted strings, or non-space sequences
const argsRegex = /(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi
const placeholderRegex = /\$(\d+)/g
const quoteTrimRegex = /^["']|["']$/g
const placeholderRegex = /\$(\d+)/g

export function parseCommandArguments(input: string) {
return (input.match(argsRegex) ?? []).map((arg) => arg.replace(quoteTrimRegex, ""))
}

export * as SessionPrompt from "./prompt"
14 changes: 14 additions & 0 deletions packages/opencode/test/session/prompt-substitute.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from "bun:test"
import { SessionPrompt } from "../../src/session/prompt"

describe("SessionPrompt.parseCommandArguments", () => {
test("preserves quoted multi-word arguments as a single argument", () => {
const result = SessionPrompt.parseCommandArguments('"sync|Syncing dev with upstream/dev"')
expect(result).toEqual(["sync|Syncing dev with upstream/dev"])
})

test("splits remaining unquoted arguments normally", () => {
const result = SessionPrompt.parseCommandArguments('"sync|Syncing dev with upstream/dev" tail one')
expect(result).toEqual(["sync|Syncing dev with upstream/dev", "tail", "one"])
})
})