返回 html-video
opencode.ts
根目录 / packages / runtime / src / defs / opencode.ts
1 import type { AgentDef } from '../types.js';
2
3 /**
4 * OpenCode def (`opencode`, by SST — sst/opencode, npm `opencode-ai`).
5 *
6 * Unlike the `--print`-style CLIs, OpenCode's non-interactive entry is the
7 * `run` SUBCOMMAND, not a flag. `opencode run` takes the message as a
8 * positional arg or on stdin (non-TTY stdin is prepended to the prompt), runs
9 * the session, and exits when idle. We pipe the prompt via stdin.
10 *
11 * Output: default stdout is an event-stream of text (not JSON unless you pass
12 * `--format json`), so plain mode captures it and the extractor reads the
13 * fenced ```html``` block.
14 *
15 * Note: in non-interactive mode OpenCode tightens permissions by default
16 * (question/plan: deny). Our chat-to-HTML flow only needs the model to emit
17 * text + an html block — no file edits — so the default is fine. If a future
18 * mode needs the agent to write files, add `--dangerously-skip-permissions`.
19 */
20 export const opencode: AgentDef = {
21 id: 'opencode',
22 name: 'OpenCode',
23 bin: 'opencode',
24 versionArgs: ['--version'],
25 buildArgs(_prompt, _ctx) {
26 // `run` is the headless subcommand; prompt arrives via stdin.
27 return ['run'];
28 },
29 streamFormat: 'plain',
30 promptViaStdin: true,
31 installUrl: 'https://opencode.ai/docs',
32 };
33
33 lines TYPESCRIPT