Repository navigation
feat(runtime): implement OpenCodeRuntime - #8473
waynesun09 wants to merge 44 commits into
Conversation
|
/fs-fix-stop |
|
Fix agent disabled for this PR. Remove the |
|
🤖 Finished Review · ✅ Success · Started 8:08 PM UTC · Completed 8:29 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $5.48 |
PR Summary by QodoImplement an opt-in OpenCode agent runtime
AI Description
Diagram
High-Level Assessment
Files changed (46)
|
Code Review by Qodo
1.
|
Site previewCommit: |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Risk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history. Previous runRisk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history; incremental update of ~127 lines across 5 files preserves the moderate risk profile. Previous run (2)Risk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history. Previous run (3)Risk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history. Previous run (4)Risk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history. Previous run (5)Risk Assessment: moderate (2/5) DetailsLarge additive runtime implementation touching one protected path (Containerfile) with moderate churn in existing docs and config, mitigated by opt-in configuration safety, solid test coverage, and established author history. |
ReviewFindingsHigh
Medium
Low
Earlier findings
Labels: The PR adds a new opt-in agent runtime, which is a feature. Next steps:
Previous runReviewFindingsHigh
Medium
Low
Earlier findings
Next steps:
Previous run (2)ReviewFindingsHigh
Medium
Low
Earlier findings
Next steps:
Previous run (3)ReviewFindingsHigh
Medium
Low
Earlier findings
Labels: PR adds a new runtime with substantial documentation changes alongside the sandbox/runner code. Next steps:
|
Bootstrap/Run/ExtractTranscripts/ConfigDir for the OpenCode agent runtime,
mirroring the pi runtime pattern. Flip config.ValidRuntimes() to include
"opencode" so org/per-repo/per-agent config can select it.
What lands in this PR
- sandbox.SandboxOpenCodeConfig (/sandbox/opencode-config) — runner-owned
config dir, off the agent-writable workspace. Path convention pinned by
unbound-force#515 (hook adapter also lives here under plugins/).
- opencode.go: ConfigDir → SandboxOpenCodeConfig; EnvExports exports
OPENCODE_CONFIG_DIR (runner-owned dir pointer), OPENCODE_CONFIG_CONTENT
(Vertex provider + permission-deny config, merges last in opencode's config
stack so it wins over any repo config), and GOOGLE_APPLICATION_CREDENTIALS;
implements DebugLogNamer.
- opencode_bootstrap.go: Bootstrap() creates agent/, skills/, plugins/ under
ConfigDir; translates the Claude-style agent .md to OpenCode's
{agent,agents}/**/*.md layout with JSON frontmatter (mode: primary, tools
as {toolID: bool}); uploads harness skills; preflights opencode --version.
No ClaudeHooksBootstrap — hook adapter is unbound-force#515; plugin path
reserved at ConfigDir/plugins/fullsend-hooks.ts with sha256 fail-closed
guard shape (exit 97, before .env) for #515 to populate.
- opencode_run.go: buildOpenCodeRunCommand renders "opencode run --format json
--model <provider/model> --variant <effort> --agent <name> <prompt>
</dev/null"; honors RunParams.Prompt (feedback_mode); shell-escapes all
interpolated values (sh -c boundary); emits InitEvent from RunParams.Model
(wire format carries no model metadata); captures ResultEvent metrics;
overrides exit 0 when the stream reports an error (same as pi).
- opencode_transcript.go: ExtractTranscripts downloads the tee'd output.jsonl
(interim approach; full redesign → unbound-force#513); ParseTranscriptFile
replays ndjson through parseOpenCodeStream for the exit-0 override;
ExtractDebugLog downloads opencode-debug.log.
- config.ValidRuntimes(): adds "opencode"; all call sites that hardcoded
"opencode" as a rejected stub updated to accept it or use "nonexistent"
for the invalid-name coverage.
- docs/contributing/runtime-implementation.md: security matrix OpenCode
column filled in (hooks: not wired / #515; transcripts: interim tee;
host-side scans: runtime-agnostic). docs/runtimes.md: config-key table
OpenCode column added; runtime table entry updated from "Stub" to
"Implemented".
- 44 new tests; patch coverage on new opencode production files ≈ 82%.
What does NOT land (owned by unbound-force#515)
- Hook plugin adapter (tool.execute.before/after) — path reserved.
- SandboxHooksBootstrap type-assert in Bootstrap.
- ContextBridger: omitted — opencode reads AGENTS.md natively.
Phase 0 (opencode headless in sandbox) confirmed via unbound-force#509.
ConfigDir path + sha256 convention pinned per unbound-force#515 comment.
Signed-off-by: Yvonne Devlin <[email protected]>
Signed-off-by: Yvonne Devlin <[email protected]>
… mechanics Address PR #7103 review feedback from @waynesun09 and @qodo-code-review: Security: - Add OPENCODE_DISABLE_PROJECT_CONFIG=true to EnvExports (H1) - Re-pin runner-owned env vars after .env source, mirroring pi/codex (H6) - Migrate tools: to permission: field matching upstream schema (H3/H5) - Fix LS tool mapping from "list" to "read" (H2) - Add agent name validation in Bootstrap to prevent fallback (H7) Run mechanics: - Add clearStrayProcesses to ClearIterationArtifacts (H4) - Move rc file under output/ so it is cleaned between iterations (H8) - Make final exit conditional on prelude success (H8) - Add --print-logs --log-level DEBUG when Debug is set (H9) - Propagate stream parseErr to adjust exit code (B6) Assisted-by: claude-opus Signed-off-by: Yvonne Devlin <[email protected]>
Address PR #7103 review feedback from @waynesun09 and @qodo-code-review: Docs: - Add opencode to architecture.md runtime selection diagram (H11) - Add opencode to layered-config-reference.md valid values (H11) - Tick runtime-implementation.md checklist boxes (H11) - Change "Experimental" to "Planned" callout for deferred features (B2) - Fix "opt-in per org" to "opt-in per repo" per ADR 0044 (H10) - Update tools: references to permission: in opencode.md (H3) Config: - Restore ADR 0044 deprecation guard in TestOrgConfigValidateRuntime (H10) - Add write-agent note to ValidRuntimes doc comment (B14) Image: - Add OpenCode binary to base sandbox Containerfile (B12) Assisted-by: claude-opus Signed-off-by: Yvonne Devlin <[email protected]>
…ap, docs - translateOpenCodeModel now consults RunParams.ModelAliases via mergedOpenCodeModelAliases(), matching pi's per-repo override pattern - Add 'Agent' (current name) to openCodeToolForClaude map alongside legacy 'Task' alias so sub-agent dispatch is not silently dropped - Add stderr warning when BashAllowlist is non-empty, matching codex_bootstrap.go pattern for operator visibility - Remove stale 'list' from doc comment in opencode.go (LS maps to read) - Fix opencode.md debug-log description to reflect --print-logs behavior - Add tests for config alias merging and Agent tool mapping Signed-off-by: Yvonne Devlin <[email protected]>
Add tests targeting uncovered error paths identified by Codecov patch coverage analysis. Coverage now exceeds the 80% threshold for all functions across the three flagged files. Bootstrap tests: - Agent name fallback from frontmatter/path when input name is empty - Body-only agent (no frontmatter fences) - Agent name sanitization failure - Duplicate skill name detection (distinct paths, same basename) - Empty skill path skip Run tests: - Debug mode (--print-logs, --log-level DEBUG) - Fallback models warning - Default handler when OnEvent is nil - Error subtype in empty-message case Transcript tests: - Debug log download when debug is set - ParseTranscriptErrors with non-existent dir - ParseTranscriptErrors skips dirs and non-jsonl - ExtractTranscripts probe exec error - ExtractTranscripts path-traversal rejection Signed-off-by: Yvonne Devlin <[email protected]>
- Permission record: resolve nil-vs-empty doc contradiction — both
produce `"permission": {}` which OpenCode treats as "use defaults";
doc now explains why this is acceptable (harness policy is the
authoritative gate)
- Validated arg: narrow fallback claim for --agent — empty agent name
uses default agent instead of bootstrap-generated one; callers
should treat empty result as error
- InitEvent handler: add forward-compatibility comment explaining the
branch is currently unreachable but guards against future wire-format
revisions
- Debug log test: replace coverage-only `_ =` with real assertions
(require.NoError + file content check)
Signed-off-by: Yvonne Devlin <[email protected]>
…penCode - openCodePermissionRecord now initializes all 12 tool IDs as deny then overwrites allowed tools to allow, closing the widen-only gap (thread 5b) - Run prelude writes runner-owned opencode.json to ConfigDir with config.instructions pointing at workspace AGENTS.md as an absolute path, bypassing OPENCODE_DISABLE_PROJECT_CONFIG discovery gate (thread 11) - Doc comment at opencode.go corrected: re-exported so prelude inherits them, not asserted present (thread 13) - openCodeConfigFile constant and openCodeInstructionsConfig helper added with tests Signed-off-by: Yvonne Devlin <[email protected]>
OpenCode's built-in provider registry names the Vertex-backed Anthropic provider "google-vertex-anthropic", not "anthropic-vertex". The latter is Pi-specific (registered by its vendored pi-anthropic-vertex extension). The OpenCode runtime copied the Pi constant, causing a ProviderModelNotFoundError at startup. Fixes #7103 Signed-off-by: Yvonne Devlin <[email protected]>
Addresses PR #7103 review feedback from @waynesun09 and @rh-hemartin. Assisted-by: gpt-5.6-sol Signed-off-by: Yvonne Devlin <[email protected]>
Addresses review-council findings for PR #7103. Assisted-by: gpt-5.6-sol Signed-off-by: Yvonne Devlin <[email protected]>
|
🤖 Finished Review · ✅ Success · Started 10:50 PM UTC · Completed 11:04 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.22 |
OpenCode matches both the tool and the argument pattern, so with
{"*":"allow","bash":{"rm *":"deny"}} it still allows ls. Copying
only the bash map let the agent's own "*": "deny" reject ls. Give a
declared tool every trusted rule that applies to it, in order.
Assisted-by: Claude
Signed-off-by: Wayne Sun <[email protected]>
|
🤖 Finished Review · ✅ Success · Started 11:14 PM UTC · Completed 11:27 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.29 |
… dirs Go's ordered parse and OpenCode's JSON.parse read a permission object with a repeated key differently, so the translated agent record could widen the trusted policy. Reject duplicate keys in the trusted policy. The runner installs no OpenCode plugins yet, so the per-iteration reset now also clears plugin/, plugins/ and skill/. Only skills/, which holds the runner's skills, stays writable until #7824. Assisted-by: Claude Signed-off-by: Wayne Sun <[email protected]>
|
🤖 Finished Review · ✅ Success · Started 11:38 PM UTC · Completed 11:52 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.32 |
…gent opencode debug agent ran with the previous iteration's agent-writable opencode.json. Clear it with the other overrides; the run prelude writes the runner's copy after the reset. Assisted-by: Claude Signed-off-by: Wayne Sun <[email protected]>
|
🤖 Finished Review · ✅ Success · Started 12:02 AM UTC · Completed 12:14 AM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.99 |
Summary
Adds OpenCode as an opt-in fullsend agent runtime. Claude Code stays the default.
This supersedes #7103 by @yvonnedevlinrh. It contains their 33 commits unchanged, with authorship and sign-off kept, rebased onto current
main. The commits on top close the open review findings. OpenCode is supported for read-only agents only until the sandbox hook adapter lands (#7824, unbound-force/unbound-force#515). The runtime does not enforce this; the docs say so.Related to #1260. Downstream tracker: unbound-force/unbound-force#510.
Changes Made
From #7103 (see that PR for the full description):
provider/modelreferences, and effort through--variant.Fixes on top:
{"read":"allow","*":"deny"}can no longer be widened by the agent.bash: {"gh *": "allow", "*": "deny"}), an agent that declares the tool now gets that pattern map. Before this fix, the agent-level"*": "deny"denied the tool outright.agent/,agents/,mode/,modes/,opencode.jsonc,$HOME/.opencode,$HOME/.config/opencode), re-uploads the translated agent file and re-runsopencode debug agent. An iteration fails when OpenCode printsFalling back to default agent, on stderr or, in debug mode, in the debug log.claude-*-5-5@default, andOPENCODE_DISABLE_MODELS_FETCH=truekeeps the sandbox on that catalog. The runtime's flags, event stream, permission evaluation and agent loading are unchanged from 1.18.30. OpenCode 2.x is a separate rewrite with breaking CLI and config changes and no release tarballs, so it is left for a later migration.opus,sonnetandhaikuresolve to the same 5.5 generation as the other Claude-family runtimes (claude-*-5-5@default). A parity test checks this. OpenCode has no model fallback chain yet (feat(runtime/opencode): fall back along the alias chain when a model is not served #8476), so on a Vertex project that does not serve 5.5, name a model the project serves.uploadHarnessSkillsfrom Forge skills that share a directory basename replace each other: review loses issue-labels #7830, so skills land atskills/<declared SKILL.md name>..env: the run prelude repeats the override reset after sourcing the agent-writable.envand fails (exit 98) if the agent file's SHA-256 changed.model:applies when the harness names none (as on Claude Code and Codex); an exported emptyGOOGLE_CLOUD_LOCATIONis unset; a transcript with malformed lines is reported as an error. The per-iteration reset also clearstool/,tools/,command/,commands/, a cachedmodels.jsonandauth.json.docs/runtimes/opencode.mdis now a short local-run walkthrough with real output, a models table and troubleshooting; the mechanics moved to the runtime implementation guide. Code comments are trimmed.GOOGLE_CLOUD_LOCATIONassertion and covered the empty-region case. The tests that needsha256sumin the pinned utility directories now skip on hosts without it (macOS).Out of scope
The hook adapter (#7824), credential redaction (#7320), Renovate for
OPENCODE_VERSION(#8201), and the Vertex@defaultsuffix handling (#7823).Test plan
go build ./..., andpre-commit run --from-ref origin/main --to-ref HEADinternal/runtime,agentnew,cli,config,repos,scaffold,sandbox,harness,pkg/behaviourtest/...fullsend run triagewithruntime: opencode(OpenCode 1.19.1 sandbox image built from this branch), against the throwaway repononflux/tmp-8473-opencode, with a trusted bash pattern-map policy: agent exit 0, output validation passed. Re-run at the final head after the post-.envreset and agent-file check: exit 0, validation passed. Withclaude-sonnet-5-5@defaultthe id resolves from the 1.19.1 catalog; the Vertex project used for testing does not serve 5.5 (availability is per project), so that run usedclaude-sonnet-4-6@default.e2e/behaviour/features/runtime/opencode.feature, gated on theruntime-opencodecapability. Not run: it needs a published sandbox image that contains OpenCode, which exists only after this merges.Backward Compatibility
This change is additive and opt-in. Existing configurations keep Claude Code unless they select
runtime: opencode.🤖 Generated with Claude Code