Skip to content

Commit 68e41a1

Browse files
authored
fix: pass arguments to commands without explicit placeholders (#9606)
1 parent 5622c53 commit 68e41a1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,22 @@ export function Prompt(props: PromptProps) {
546546
} else if (
547547
inputText.startsWith("/") &&
548548
iife(() => {
549-
const command = inputText.split(" ")[0].slice(1)
550-
console.log(command)
549+
const firstLine = inputText.split("\n")[0]
550+
const command = firstLine.split(" ")[0].slice(1)
551551
return sync.data.command.some((x) => x.name === command)
552552
})
553553
) {
554-
let [command, ...args] = inputText.split(" ")
554+
// Parse command from first line, preserve multi-line content in arguments
555+
const firstLineEnd = inputText.indexOf("\n")
556+
const firstLine = firstLineEnd === -1 ? inputText : inputText.slice(0, firstLineEnd)
557+
const [command, ...firstLineArgs] = firstLine.split(" ")
558+
const restOfInput = firstLineEnd === -1 ? "" : inputText.slice(firstLineEnd + 1)
559+
const args = firstLineArgs.join(" ") + (restOfInput ? "\n" + restOfInput : "")
560+
555561
sdk.client.session.command({
556562
sessionID,
557563
command: command.slice(1),
558-
arguments: args.join(" "),
564+
arguments: args,
559565
agent: local.agent.current().name,
560566
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
561567
messageID,

packages/opencode/src/session/prompt.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,15 @@ NOTE: At any point in time through this workflow you should feel free to ask the
16271627
if (position === last) return args.slice(argIndex).join(" ")
16281628
return args[argIndex]
16291629
})
1630+
const usesArgumentsPlaceholder = templateCommand.includes("$ARGUMENTS")
16301631
let template = withArgs.replaceAll("$ARGUMENTS", input.arguments)
16311632

1633+
// If command doesn't explicitly handle arguments (no $N or $ARGUMENTS placeholders)
1634+
// but user provided arguments, append them to the template
1635+
if (placeholders.length === 0 && !usesArgumentsPlaceholder && input.arguments.trim()) {
1636+
template = template + "\n\n" + input.arguments
1637+
}
1638+
16321639
const shell = ConfigMarkdown.shell(template)
16331640
if (shell.length > 0) {
16341641
const results = await Promise.all(

0 commit comments

Comments
 (0)