fix(daemon): remove opencode stdin dash sentinel (#1365)

This commit is contained in:
PerishFire 2026-05-12 14:15:46 +08:00 committed by GitHub
parent 1ce7d6e8c5
commit 93865f71e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 4 deletions

View file

@ -22,8 +22,10 @@ export const opencodeAgentDef = {
{ id: 'openai/gpt-5', label: 'openai/gpt-5' },
{ id: 'google/gemini-2.5-pro', label: 'google/gemini-2.5-pro' },
],
// Prompt delivered via stdin (`opencode run -`) to avoid Windows
// `spawn ENAMETOOLONG` while preserving OpenCode's structured stream.
// Prompt delivered via stdin (`opencode run` with no message argv) to
// avoid Windows `spawn ENAMETOOLONG` while preserving OpenCode's
// structured stream. A literal `-` is parsed as a positional message by
// OpenCode 1.14.x and can surface as "Session not found".
buildArgs: (_prompt, _imagePaths, _extra, options = {}) => {
const args = [
'run',
@ -34,7 +36,6 @@ export const opencodeAgentDef = {
if (options.model && options.model !== 'default') {
args.push('--model', options.model);
}
args.push('-');
return args;
},
promptViaStdin: true,

View file

@ -1,6 +1,6 @@
import { test } from 'vitest';
import {
assert, claude, codex, copilot, cursorAgent, deepseek, devin, detectAgents, gemini, join, kilo, kiro, mkdtempSync, pi, qoder, rmSync, spawnEnvForAgent, tmpdir, vibe, writeFileSync, chmodSync,
assert, claude, codex, copilot, cursorAgent, deepseek, devin, detectAgents, gemini, join, kilo, kiro, mkdtempSync, opencode, pi, qoder, rmSync, spawnEnvForAgent, tmpdir, vibe, writeFileSync, chmodSync,
} from './helpers/test-helpers.js';
import type { TestAgentDef } from './helpers/test-helpers.js';
@ -25,6 +25,35 @@ test('cursor-agent args deliver prompts via stdin without passing a literal dash
]);
});
test('opencode args deliver prompts via stdin without passing a literal dash prompt', () => {
const prompt = 'design a dashboard';
const baseArgs = opencode.buildArgs(prompt, [], [], {});
assert.equal(opencode.promptViaStdin, true);
assert.equal(baseArgs.includes('-'), false);
assert.equal(baseArgs.includes(prompt), false);
assert.deepEqual(baseArgs, [
'run',
'--format',
'json',
'--dangerously-skip-permissions',
]);
const withModel = opencode.buildArgs(
prompt,
[],
[],
{ model: 'anthropic/claude-sonnet-4-5' },
);
assert.deepEqual(withModel, [
'run',
'--format',
'json',
'--dangerously-skip-permissions',
'--model',
'anthropic/claude-sonnet-4-5',
]);
});
// Copilot reads the prompt from stdin when `-p` is omitted entirely
// (upstream copilot-cli issue #1046, confirmed working as
// `echo "..." | copilot --model <id>`). The earlier `-p -` attempt