1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! OpenCode CLI bindings — pipe mode spawn builder.
//!
//! OpenCode (`sst/opencode`, later `opencode-ai/opencode`) v1.4.0+ provides a
//! structured pipe mode via `opencode run --format json`. It emits NDJSON with
//! a 5-event schema distinct from Claude/Cursor stream-json.
//!
//! # Source documentation
//! - https://opencode.ai/docs/cli/
//! - https://github.com/opencode-ai/opencode
//! - https://deepwiki.com/sst/opencode/6.1-command-line-interface-(cli)
//!
//! # Argv shape (built from docs, not from live capture)
//!
//! Fresh session:
//! ```text
//! opencode run --format json [<extra>...] "<prompt>"
//! ```
//!
//! Resumed session:
//! ```text
//! opencode run --format json --session <ses_XXXX> [<extra>...] "<prompt>"
//! ```
//!
//! Session IDs use the `ses_XXXX` prefix. The `--session` / `-s` flag resumes
//! by exact session ID. `-c` / `--continue` resumes the most recent session, but
//! since gate4agent tracks explicit IDs, we always use `--session`.
//!
//! If real output differs from the assumed shape, reconcile in a future patch.
use crateCliCommandBuilder;
use crateSpawnOptions;
/// Pipe-mode spawn builder for OpenCode.
///
/// Argv produced (fresh session, from docs):
/// ```text
/// opencode run --format json [<extra>...] "<prompt>"
/// ```
///
/// Argv produced (resumed session):
/// ```text
/// opencode run --format json --session <ses_XXXX> [<extra>...] "<prompt>"
/// ```
///
/// # Prompt delivery
///
/// The prompt is appended as the final positional argv token.
/// OpenCode does not use stdin for the one-shot `run` invocation.
///
/// # Field sources
/// All flag names taken from: https://opencode.ai/docs/cli/
/// - `run`: non-interactive run subcommand
/// - `--format json` / `-f json`: NDJSON output mode
/// - `--session <id>` / `-s <id>`: resume specific session by ID
/// - `--continue` / `-c`: resume most recent session (not used here — we need explicit IDs)
;