Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(runner): pass the task to opencode, pi and omp the way each CLI reads it (#629)

Croff38596efec80a
diff --git a/docs/runner.md b/docs/runner.md
index 5261c4e0..e2f28b15 100644
--- a/docs/runner.md
+++ b/docs/runner.md
@@ -241,7 +241,8 @@ The extension reads `.mcp.json` from the working directory:
- The preset passes `-p --mode json`. The stream gives the chat answer word by word, the
tool calls, and the session id on the first line. `--session-id` resumes that session.
-- `--append-system-prompt` gives Pi the context of the run.
+- The preset sends the task on stdin. `--append-system-prompt` gives Pi the context of
+ the run.
- Print mode does not wait for tool approval. `--approve` is only project-trust for
`.pi/settings.json`, not tool permission.
- Sign in once with `pi` interactively so a provider is available.
diff --git a/packages/runner/src/__tests__/presets.test.ts b/packages/runner/src/__tests__/presets.test.ts
index aff2b865..21be73a1 100644
--- a/packages/runner/src/__tests__/presets.test.ts
+++ b/packages/runner/src/__tests__/presets.test.ts
@@ -27,10 +27,10 @@ describe('preset arguments', () => {
expect(resumed.indexOf('--model')).toBeLessThan(resumed.length - 1);
});
- it('gives opencode the task as the last argument, after the session flag', () => {
+ it('gives opencode the task as the last argument, behind --, after the session flag', () => {
const argv = presetArgv(PRESETS.opencode, 'ses_1', '', [], 'do it');
expect(argv).toContain('--session');
- expect(argv.at(-1)).toBe('do it');
+ expect(argv.slice(-2)).toEqual(['--', 'do it']);
});
it('resumes an Antigravity conversation and keeps the task behind -p', () => {
@@ -52,22 +52,22 @@ describe('preset arguments', () => {
expect(resumed.slice(-4)).toEqual(['--session-id', 'c66bf000', '-p', 'do it']);
});
- it('prints through pi json mode and resumes by session id, task last', () => {
+ it('prints through pi json mode and resumes by session id, task on stdin', () => {
const fresh = presetArgv(PRESETS.pi, null, 'context', [], 'do it');
expect(fresh.slice(0, 3)).toEqual(['-p', '--mode', 'json']);
expect(fresh).not.toContain('--session-id');
expect(fresh).toContain('--append-system-prompt');
- expect(fresh.at(-1)).toBe('do it');
+ expect(fresh).not.toContain('do it');
const resumed = presetArgv(PRESETS.pi, 'sess-9', '', [], 'do it');
- expect(resumed).toEqual(['-p', '--mode', 'json', '--session-id', 'sess-9', 'do it']);
+ expect(resumed).toEqual(['-p', '--mode', 'json', '--session-id', 'sess-9']);
});
it('prints through omp json mode unattended and resumes with --resume', () => {
const fresh = presetArgv(PRESETS.omp, null, '', [], 'do it');
expect(fresh).toContain('--auto-approve');
expect(fresh).not.toContain('--resume');
- expect(fresh.at(-1)).toBe('do it');
+ expect(fresh.slice(-2)).toEqual(['--', 'do it']);
const resumed = presetArgv(PRESETS.omp, '01a0c317', 'context', [], 'do it');
expect(resumed.slice(0, 6)).toEqual([
@@ -79,7 +79,18 @@ describe('preset arguments', () => {
'01a0c317',
]);
expect(resumed).toContain('--append-system-prompt');
- expect(resumed.at(-1)).toBe('do it');
+ expect(resumed.slice(-2)).toEqual(['--', 'do it']);
+ });
+
+ // A member's message reaches the CLI on stdin or behind what keeps it from being read as
+ // an option, so one beginning with a hyphen stays the task.
+ it('never leaves a message where the CLI reads it as an option', () => {
+ const message = '--version';
+ for (const preset of Object.values(PRESETS)) {
+ const argv = presetArgv(preset, 'sess', '', [], message);
+ if (preset.promptVia === 'stdin') expect(argv).not.toContain(message);
+ else expect(['--', '-p']).toContain(argv.at(-2) ?? '');
+ }
});
it("appends the operator's arguments after the preset's, so a repeated flag wins", () => {
diff --git a/packages/runner/src/presets.ts b/packages/runner/src/presets.ts
index ad102e97..c2fe64e7 100644
--- a/packages/runner/src/presets.ts
+++ b/packages/runner/src/presets.ts
@@ -22,7 +22,9 @@ export interface Preset {
systemPromptFlag?: string;
// The arguments before the operator's own, given null for a fresh session.
head: (sessionId: string | null) => string[];
- // The arguments after the operator's own: a stdin marker, or the flag the prompt follows.
+ // The arguments after the operator's own, framing the prompt: a stdin marker, the flag
+ // the prompt follows, or `--` so a prompt beginning with a hyphen is read as the task
+ // and not as an option.
tail: string[];
}
@@ -76,7 +78,7 @@ export const PRESETS: Record<PresetName, Preset> = {
'json',
...(sessionId ? ['--session', sessionId] : []),
],
- tail: [],
+ tail: ['--'],
},
// --conversation resumes the conversation the stream names. --print-timeout is raised
@@ -116,11 +118,12 @@ export const PRESETS: Record<PresetName, Preset> = {
},
// --mode json writes one event per line. The opening `session` line names the id that
- // --session-id resumes. Print mode does not wait for tool approval.
+ // --session-id resumes. Print mode does not wait for tool approval. The task goes on
+ // stdin: pi reads every argument that begins with a hyphen as an option, `--` included.
pi: {
bin: 'pi',
outputFormat: 'pi-json',
- promptVia: 'arg',
+ promptVia: 'stdin',
systemPromptFlag: '--append-system-prompt',
head: (sessionId) => [
'-p',
@@ -145,7 +148,7 @@ export const PRESETS: Record<PresetName, Preset> = {
'--auto-approve',
...(sessionId ? ['--resume', sessionId] : []),
],
- tail: [],
+ tail: ['--'],
},
};