Commit 3633219
authored
feat(dispatcher): add opencode CLI support (#89)
## Summary
Add first-class opencode (`anomalyco/opencode`) support to the
dispatcher's agent abstraction layer. opencode is a provider-agnostic
open-source coding agent CLI that, like codex, mints its own session id
per invocation. Mirrors the pattern established in #88: capture the
CLI-minted id from the JSON stream into a sidecar, feed it back on
resume.
## Why
After #88 fixed the codex branch with a session-id-capture pattern,
opencode's identical wrinkle (CLI mints the id; caller can't pre-mint)
became cheap to address with the same approach. README #87 already lists
opencode as the next CLI to integrate; this closes that follow-up.
## Design
opencode JSON shape (verified against `opencode run --format json --pure
"test"` on v1.14.46):
```json
{"type":"step_start","timestamp":1778415469963,"sessionID":"ses_1ee2d8d...","part":...}
```
Every event carries `"sessionID":"ses_<base62>"` — not gated on a
specific event type. The capture filter records the first occurrence
(which arrives in the very first event), validates the format with
`^ses_[A-Za-z0-9]+$`, and writes it to
`${pid_dir}/opencode-session-${dispatcher_session_id}`.
- `run_agent` opencode case: `opencode run --format json [--title
<session_name>] [PROMPT]` piped through `_opencode_capture_session`.
- `resume_agent` opencode case: reads the captured id via
`_opencode_session_id` and calls `opencode run --session <id> --format
json [PROMPT]`. Falls back to `run_agent` when the sidecar is missing or
malformed (defense-in-depth: even though pid_dir is mode 0700, a
malformed sidecar value would otherwise be passed to `opencode run
--session ...` as raw shell input).
## Test Plan
- [x] **Live verification**: installed opencode v1.14.46 locally, ran
`opencode run --format json --pure "test"`, confirmed JSON shape; ran
resume with the captured id, confirmed it works.
- [x] 31 new cases in `tests/unit/test-lib-agent-opencode.sh`:
- Source-of-truth grep (opencode case present, uses `run --format json`,
resume uses `--session`)
- run_agent argv shape + sessionID capture (stub emits the actual
opencode JSON shape)
- resume_agent uses captured sessionID
- Fallback when sidecar missing (logs diagnostic, calls run_agent shape,
creates fresh sidecar)
- Crash path (opencode exits before any JSON event → no sidecar, exit
code surfaced)
- **Malformed-sidecar regression** (manually planted
`ses_with;injection\`hazard` → regex rejects, fallback triggers, garbage
never reaches `opencode run --session`)
- [x] Codex tests still pass (27/27)
- [x] Full unit suite: 37/37 test files pass
- [x] `bash -n` clean on `lib-agent.sh`
- [x] shellcheck: only SC1091-info for `lib-config.sh` source
- [x] Code-reviewer agent run: zero findings ≥ 80 confidence
- [ ] CI checks pass
## Backwards Compatibility
- `AGENT_CMD=opencode` was previously routed to the generic `<cli> -p
<prompt>` fallback. With this PR it's routed to a first-class branch —
the new behavior is strictly more correct (no `-p` flag misuse).
- `claude` / `codex` / `kiro` branches unchanged.
- Sidecar paths are new files under an already-existing per-user dir
(mode 0700).
## Open follow-ups (not in scope)
- `--dangerously-skip-permissions` flag wiring when
`AGENT_PERMISSION_MODE=bypassPermissions`. The codex branch has the same
gap; would prefer a single PR that addresses both consistently rather
than per-CLI ad-hoc fixes.
## Checklist
- [x] Design described in commit message + this PR body
- [x] Test cases documented (31 cases with thorough behavioral +
regression coverage)
- [x] Build/tests pass
- [x] Code review passed (zero blocking findings)1 parent e1f9383 commit 3633219
4 files changed
Lines changed: 464 additions & 15 deletions
File tree
- skills/autonomous-dispatcher/scripts
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| |||
149 | 156 | | |
150 | 157 | | |
151 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
152 | 227 | | |
153 | 228 | | |
154 | 229 | | |
| |||
214 | 289 | | |
215 | 290 | | |
216 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
217 | 307 | | |
218 | 308 | | |
219 | 309 | | |
| |||
271 | 361 | | |
272 | 362 | | |
273 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
274 | 381 | | |
275 | 382 | | |
276 | 383 | | |
| |||
0 commit comments