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
4 changes: 3 additions & 1 deletion src/adapters/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ export class CodexAdapter implements AgentAdapter {
promptFilePath = await writePromptFile(opts.prompt);
promptFd = await openPromptFd(promptFilePath);
} else {
args.push(opts.prompt);
// Use -- separator to prevent prompts starting with dashes (e.g. YAML
// frontmatter "---") from being interpreted as CLI options by codex.
args.push("--", opts.prompt);
}

const env = buildSpawnEnv(undefined, opts.env);
Expand Down
26 changes: 24 additions & 2 deletions src/adapters/opencode-launch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ describe("OpenCodeAdapter launch", () => {
const modelIdx = args.indexOf("--model");
const promptIdx = args.indexOf("fix the bug");
expect(modelIdx).toBeLessThan(promptIdx);
expect(args).toEqual(["run", "--model", "deepseek-r1", "fix the bug"]);
expect(args).toEqual([
"run",
"--model",
"deepseek-r1",
"--",
"fix the bug",
]);
});

it("omits --model flag when opts.model is not set", async () => {
Expand All @@ -87,6 +93,22 @@ describe("OpenCodeAdapter launch", () => {
expect(spawnCalls).toHaveLength(1);
const args = spawnCalls[0].args;
expect(args).not.toContain("--model");
expect(args).toEqual(["run", "fix the bug"]);
expect(args).toEqual(["run", "--", "fix the bug"]);
});

it("inserts -- before prompts that start with dashes (e.g. YAML frontmatter)", async () => {
const dashPrompt = "---\ntitle: My Spec\n---\nBuild this.";
await adapter.launch({
adapter: "opencode",
prompt: dashPrompt,
cwd: tmpDir,
});

expect(spawnCalls).toHaveLength(1);
const args = spawnCalls[0].args;
// -- must appear immediately before the prompt positional
const separatorIdx = args.indexOf("--");
expect(separatorIdx).toBeGreaterThan(-1);
expect(args[separatorIdx + 1]).toBe(dashPrompt);
});
});
4 changes: 3 additions & 1 deletion src/adapters/opencode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ export class OpenCodeAdapter implements AgentAdapter {
promptFilePath = await writePromptFile(opts.prompt);
promptFd = await openPromptFd(promptFilePath);
} else {
args.push(opts.prompt);
// Use -- separator to prevent prompts starting with dashes (e.g. YAML
// frontmatter "---") from being interpreted as CLI options by opencode.
args.push("--", opts.prompt);
}

const env = buildSpawnEnv(undefined, opts.env);
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/pi-rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ export class PiRustAdapter implements AgentAdapter {

const args = useTempFile
? ["--print", "--mode", "json"]
: ["--print", "--mode", "json", opts.prompt];
: // Use -- separator to prevent prompts starting with dashes from being
// interpreted as CLI options by pi-rust.
["--print", "--mode", "json", "--", opts.prompt];

if (useTempFile) {
promptFilePath = await writePromptFile(opts.prompt);
Expand Down