Add opencode agent backend - #43
Conversation
Add opencode to the supported agent backends, launching one-shot 'opencode run' in the role worktree with the generated role prompt. Provider/model selection passes through extra CLI args (--model), and SWARMFORGE_MODEL sets a default model for opencode roles when no per-role --model is given. Add launcher tests covering the initial prompt, extra CLI args, the SWARMFORGE_MODEL default, and per-role override precedence.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9eaf90b41c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "copilot" (str "copilot -C " (sq (str role-worktree)) " --name " (sq (str "SwarmForge " display)) " " (extra-args-prefix row) "-i \"$(cat " (sq (str prompt-file)) ")\"") | ||
| "grok" (str "grok --cwd " (sq (str role-worktree)) " " (grok-permission-prefix row) (extra-args-prefix row) "--rules \"$(cat " (sq (str prompt-file)) ")\" --verbatim \"$(cat " (sq (str prompt-file)) ")\""))) | ||
| "grok" (str "grok --cwd " (sq (str role-worktree)) " " (grok-permission-prefix row) (extra-args-prefix row) "--rules \"$(cat " (sq (str prompt-file)) ")\" --verbatim \"$(cat " (sq (str prompt-file)) ")\"") | ||
| "opencode" (str "opencode run --dir " (sq (str role-worktree)) " " (opencode-model-arg row) (extra-args-prefix row) "\"$(cat " (sq (str prompt-file)) ")\""))) |
There was a problem hiding this comment.
Launch opencode in a persistent mode
For configurations where a role uses opencode, this invokes opencode run, which the OpenCode CLI docs describe as the non-interactive scripting mode (opencode run [message..], with --dir as a run flag: https://opencode.ai/docs/cli/#run). SwarmForge depends on the tmux agent process staying alive to receive later handoffs, and the first window appends cleanup immediately after the agent exits; an opencode first role will complete the initial prompt and tear down the swarm, while later opencode roles will simply stop instead of waiting for work. Use the persistent TUI entrypoint with an initial prompt/project directory, or another long-running opencode mode, for swarm roles.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in e268a54: opencode roles now launch the persistent TUI entrypoint (opencode <worktree> --prompt "$(cat <role prompt>)") instead of one-shot opencode run, so the agent process stays alive to receive handoff wake-ups. Added a regression assertion that the launch command does not use opencode run. Verified with bb test (28 tests / 101 assertions).
opencode run is the one-shot scripting mode: the agent completes the initial prompt and exits, which would tear down the first (cleanup) window and leave later roles stopped instead of waiting for work. Launch the persistent TUI entrypoint instead, injecting the role prompt with --prompt so the process stays alive to receive handoff wake-ups, matching the claude and copilot interactive backends.
Summary
Adds
opencodeas a supported agent backend, following the existingcodexlaunch pattern:swarmforge.bb: acceptsopencodein the agent allowlist and launchesopencode run --dir <worktree> <extra args> "$(cat <role prompt>)".--model provider/model-id) or globally viaSWARMFORGE_MODELfor all opencode roles; a per-role--modeltakes precedence.SWARMFORGE_MODELdefault, and per-role override precedence.Validation
bb test: 28 tests / 100 assertions, 0 failures.Scope is deliberately limited to the opencode backend (no other backends, no default model, no auto-approve flags baked in). Related discussion: #39.