Send OpenCode source-control prompts over stdin (#4859)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-06-07 21:00:20 -07:00
committed by GitHub
co-authored by Orca
parent 4a3db11e16
commit bed394ca11
4 changed files with 197 additions and 8 deletions
@@ -331,6 +331,60 @@ describe('buildArgs (Codex)', () => {
})
})
describe('buildArgs (OpenCode)', () => {
const spec = getCommitMessageAgentSpec('opencode')!
it('runs `opencode run` without passing the prompt via argv', () => {
const prompt = `PROMPT ${'x'.repeat(1024)}`
const args = spec.buildArgs({
prompt,
model: 'opencode/deepseek-v4-flash-free'
})
expect(args).toEqual([
'run',
'--model',
'opencode/deepseek-v4-flash-free',
'--agent',
'build',
'--format',
'default'
])
expect(args).not.toContain(prompt)
expect(args).not.toContain('')
expect(spec.promptDelivery).toBe('stdin')
})
it('emits --variant <level> when thinking level is supplied', () => {
const args = spec.buildArgs({
prompt: 'PROMPT',
model: 'opencode/gpt-5.4-mini',
thinkingLevel: 'high'
})
expect(args).toEqual([
'run',
'--model',
'opencode/gpt-5.4-mini',
'--agent',
'build',
'--format',
'default',
'--variant',
'high'
])
})
it('omits --variant when no thinking level is supplied', () => {
const args = spec.buildArgs({
prompt: 'PROMPT',
model: 'opencode/gpt-5.4-mini'
})
expect(args).not.toContain('--variant')
})
})
describe('buildArgs (Antigravity)', () => {
const spec = getCommitMessageAgentSpec('antigravity')!
+5 -4
View File
@@ -336,8 +336,10 @@ export const COMMIT_MESSAGE_AGENT_SPECS: Partial<Record<TuiAgent, CommitMessageA
id: 'opencode',
label: 'OpenCode',
binary: 'opencode',
promptDelivery: 'argv',
buildArgs: ({ prompt, model, thinkingLevel }) => [
// Why: Source Control AI prompts can include large staged diffs; OpenCode
// accepts the prompt on stdin, which avoids cross-platform argv limits.
promptDelivery: 'stdin',
buildArgs: ({ model, thinkingLevel }) => [
'run',
'--model',
model,
@@ -345,8 +347,7 @@ export const COMMIT_MESSAGE_AGENT_SPECS: Partial<Record<TuiAgent, CommitMessageA
'build',
'--format',
'default',
...(thinkingLevel ? ['--variant', thinkingLevel] : []),
prompt
...(thinkingLevel ? ['--variant', thinkingLevel] : [])
],
modelSource: 'dynamic',
modelDiscovery: { binary: 'opencode', args: ['models'], parse: parseLineModels },
+33 -4
View File
@@ -33,7 +33,7 @@ describe('planCommitMessageGeneration', () => {
})
})
it('plans OpenCode run with prompt in argv and model variant', () => {
it('plans OpenCode run with prompt on stdin and model variant', () => {
const result = planCommitMessageGeneration(
{
agentId: 'opencode',
@@ -56,10 +56,39 @@ describe('planCommitMessageGeneration', () => {
'--format',
'default',
'--variant',
'high',
'PROMPT'
'high'
],
stdinPayload: null,
stdinPayload: 'PROMPT',
label: 'OpenCode'
}
})
})
it('keeps OpenCode preset command overrides while sending the prompt on stdin', () => {
const result = planCommitMessageGeneration(
{
agentId: 'opencode',
model: 'opencode/gpt-5.4-mini',
agentCommandOverride: 'npx opencode'
},
'PROMPT'
)
expect(result).toEqual({
ok: true,
plan: {
binary: 'npx',
args: [
'opencode',
'run',
'--model',
'opencode/gpt-5.4-mini',
'--agent',
'build',
'--format',
'default'
],
stdinPayload: 'PROMPT',
label: 'OpenCode'
}
})