Repository navigation
feat(agents): add OpenCode 2 beta support - #21418
Conversation
9d26f3d to
db00f47
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds OpenCode 2 as a supported agent. It updates agent configuration, labels, selection, resume handling, telemetry, commit-message commands, and hook routing. It adds separate OpenCode 2 hook plugins and relay overlays. It adds v2 channel-scoped SQLite discovery and parsing for AI Vault sessions. Tests cover agent behavior, hook events, overlay isolation, and SQLite session handling. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to OpenCode 2 can show stale working state while awaiting input, lose resumable session metadata, and omit prompt handling in supported flows. Schema variations can also reduce session discovery. Resolve these before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
opencodeDiscoveries emits an undefined discovery entry on any host that has no OpenCode 2 beta database, and the scanner then throws TypeError: Cannot read properties of undefined (reading 'files') in sessionCandidatesFromDiscoveries. The AI Vault session scan breaks for every existing user who does not have the beta installed — this is the common path, not an edge case. The same root cause already fails two existing tests.
Reviewed changes
- OpenCode 2 agent identity — added
opencode2across the TUI agent registry, renderer catalog, telemetry schemas, resume commands, skills keys, commit-message AI, terminal-title detection, and mobile agent metadata. - Daemon status ingestion — new
src/main/opencode2/service discovery, SSE consumer, event translator, and hook service, registered/cleared with the local PTY lifecycle and feeding the shared agent-status store. - AI Vault OpenCode 2 history — new
session_v2/session_messageSQLite reader and list leg, routed through the existing worker with anagentdiscriminator, plusopencode*.dbname classification. - TUI transcript catchup teardown fix — unrelated to OpenCode 2: catchup now owns an abort controller, returns its signal, and settles cancellation; handoff/restart paths handle
StructuredTuiCatchupStoppedError; new audit evidence underdocs/audits/tui-transcript-acquisition/. - Worktree identity migration coverage — unrelated to OpenCode 2:
migrateWorktreeIdentitynow repointsclosedTerminalTabTombstonesByTabIdandclientHostedBrowserCloseIntentsByEnvironmentrows, with a cross-version downgrade test. - Mobile web bundle compatibility wall — unrelated to OpenCode 2:
evaluateMobileWebBundleCompatplus new blocked-verdict copy inProtocolBlockScreen.
⚠️ This PR ships three workstreams unrelated to its title
The description frames the PR as OpenCode 2 support, but the diff also contains the TUI transcript catchup teardown rewrite, the worktree-identity migration coverage, and a new mobile web-bundle compatibility wall. Each is substantial on its own and none is mentioned in the PR body, so a reviewer approving "OpenCode 2" is also approving all of them, and a revert of the feature reverts them too. Please either split these into separate PRs or call each one out explicitly in the description with its own before/after so it gets a targeted review.
Technical details
# Unrelated workstreams bundled into a feature PR
## Affected sites
- `src/main/native-chat/agent-session-wire/structured-tui-transcript-catchup.ts` and the handoff/restart/teardown files — transcript catchup ownership change, documented by `docs/audits/tui-transcript-acquisition/`.
- `src/main/persistence/tracking-repos/worktree-identity-migration.ts` and `src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-state.ts` — worktree rename row coverage, with `tests/e2e/cross-version-wire/cross-version-worktree-identity-downgrade.unit.test.ts`.
- `mobile/src/transport/mobile-web-bundle-compat.ts` and `mobile/src/components/ProtocolBlockScreen.tsx` — a new mobile update wall.
## Required outcome
- Each unrelated workstream is either split out or described in the PR body with its user-visible before/after and mechanism, so it is reviewable and independently revertible.
## Open questions for the human
- Are the catchup and worktree-identity changes prerequisites for OpenCode 2, or incidental commits picked up on this branch?ℹ️ Nitpicks
src/shared/tui-agent-config.ts:132,src/main/opencode2/service-discovery.ts:8, andsrc/main/opencode2/hook-service.ts:25referencedocs/adr/0001-opencode2-separate-tui-agent.mdanddocs/adr/0002-opencode2-hooks-via-service-event-stream.md, but nodocs/adr/directory exists in the repo. Either add the ADRs (with the.gitignoreallow-list entries) or drop the references.- In
src/main/opencode2/event-translator.ts, everysession.next.tool.*entry inTOOL_EVENTSis also inWORKING_EVENTS, and theWORKING_EVENTScheck runs first, so those entries are unreachable; the two branches also build an identical payload.TOOL_EVENTSis effectively dead for thenextevents.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 16
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Recognize OpenCode 2 explicit prompts. · provider-event-routing.ts:96
src/shared/agent-hook-listener/provider-event-routing.ts:96
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRecognize OpenCode 2 explicit prompts.
The OpenCode 2 translator emits user prompts as
MessagePartwithrole_user_text. This condition accepts that shape foropencodeandmimo-code, but notopencode2.Add
source === 'opencode2'. Otherwise prompt telemetry and prompt-bound permission behavior omit OpenCode 2 turns.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: e6cae4e3-12a5-4694-8312-5ac4198962f7
📥 Commits
Reviewing files that changed from the base of the PR and between 1e7a697 and db00f474d90449edf6a5b72512d25c63cc03e2e4.
📒 Files selected for processing (77)
.github/workflows/pr.ymlREADME.mddocs/audits/tui-transcript-acquisition/README.mddocs/audits/tui-transcript-acquisition/fix.patchdocs/audits/tui-transcript-acquisition/reproduce.mjsdocs/audits/tui-transcript-acquisition/results.jsonmobile/src/components/ProtocolBlockScreen.test.tsmobile/src/components/ProtocolBlockScreen.tsxmobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsxmobile/src/tasks/mobile-tui-agents.tsmobile/src/transport/mobile-web-bundle-compat.test.tsmobile/src/transport/mobile-web-bundle-compat.tsmobile/src/transport/mobile-web-bundle-reply-schemas.test.tsmobile/src/transport/mobile-web-bundle-reply-schemas.tssrc/main/agent-hooks/server-retired-pane-new-turn.test.tssrc/main/agent-hooks/server/server-ingest-terminal.tssrc/main/ai-vault/session-scanner-agent-parser.tssrc/main/ai-vault/session-scanner-opencode-sources.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-client.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-entry.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-protocol.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-spawn.tssrc/main/ai-vault/session-scanner-opencode2-sqlite-list.tssrc/main/ai-vault/session-scanner-opencode2-sqlite.test.tssrc/main/ai-vault/session-scanner-opencode2-sqlite.tssrc/main/ai-vault/session-scanner-parse-cache.tssrc/main/ai-vault/session-scanner-test-fixtures.tssrc/main/ai-vault/session-scanner.test.tssrc/main/ipc/pty/provider/local-configure.tssrc/main/ipc/pty/provider/state-cleanup.tssrc/main/native-chat/agent-session-wire/structured-agent-session-handoff-forward.tssrc/main/native-chat/agent-session-wire/structured-agent-session-handoff-restart-tui.tssrc/main/native-chat/agent-session-wire/structured-agent-session-handoff-restart.tssrc/main/native-chat/agent-session-wire/structured-agent-session-handoff-types.tssrc/main/native-chat/agent-session-wire/structured-agent-session-handoff.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-teardown-handoff-drain.test.tssrc/main/native-chat/agent-session-wire/structured-tui-transcript-catchup.tssrc/main/native-chat/agent-session-wire/structured-tui-transcript-ownership.test.tssrc/main/native-chat/agent-session-wire/structured-tui-transcript-teardown-test-fixture.tssrc/main/native-chat/agent-session-wire/structured-tui-transcript-teardown.test.tssrc/main/opencode2/event-translator.tssrc/main/opencode2/hook-service.test.tssrc/main/opencode2/hook-service.tssrc/main/opencode2/service-discovery.test.tssrc/main/opencode2/service-discovery.tssrc/main/opencode2/sse-consumer.tssrc/main/persistence/tracking-repos/worktree-identity-migration-field-coverage.test.tssrc/main/persistence/tracking-repos/worktree-identity-migration.tssrc/main/providers/local-pty-provider-types.tssrc/main/providers/local-pty-spawn-environment.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/lib/agent-catalog.tsxsrc/renderer/src/lib/agent-status.tssrc/renderer/src/store/slices/worktrees/session/worktree-identity-rename-row-worktree-ids.test.tssrc/renderer/src/store/slices/worktrees/session/worktree-identity-rename-state.tssrc/shared/agent-hook-listener/provider-dispatch.tssrc/shared/agent-hook-listener/provider-event-routing.tssrc/shared/agent-hook-listener/providers/opencode-family-events.tssrc/shared/agent-hook-relay.tssrc/shared/agent-kind.tssrc/shared/agent-name-token-match.tssrc/shared/agent-session-resume.tssrc/shared/agent-type-label.tssrc/shared/ai-vault-resume-command.tssrc/shared/ai-vault-types.tssrc/shared/commit-message-agent-spec.test.tssrc/shared/commit-message-agent-specs-primary.tssrc/shared/opencode-database-name.tssrc/shared/skills-cli-agent-keys.tssrc/shared/source-control-ai-action-recipes.test.tssrc/shared/telemetry-property-schemas.tssrc/shared/terminal-title-agent-type.tssrc/shared/tui-agent-config.tssrc/shared/tui-agent-display-names.tssrc/shared/tui-agent-selection.tssrc/shared/tui-agent.tstests/e2e/cross-version-wire/cross-version-worktree-identity-downgrade.unit.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| import { tmpdir } from 'node:os' | ||
| import { join, resolve } from 'node:path' | ||
| import { fileURLToPath, pathToFileURL } from 'node:url' | ||
| import { applyPatch, parsePatch, reversePatch } from 'diff' |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Declare the direct diff dependency.
Line 7 imports diff, but package.json does not declare it. The documented command can fail after a clean install when no dependency hoists this package.
Add diff to devDependencies.
| const manifestSchema = z | ||
| .looseObject({ | ||
| schemaVersion: z.literal(MOBILE_WEB_BUNDLE_SCHEMA_VERSION), | ||
| schemaVersion: z.number().int(), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Parse unsupported schemas as an envelope before validating the current schema.
schemaVersion now accepts a future version, but manifestSchema still requires the current protocol-window and manifest fields. If a valid future schema changes or removes one of those fields, mobileWebBundleManifestRead rejects the reply before evaluateMobileWebBundleCompat can return bundle-shell-too-old. The user then gets a transport error instead of the update block.
Parse schemaVersion first. Validate the full current shape only for supported versions. Add a future-schema fixture that omits a current-only field.
Based on learnings: validate only fields guaranteed across schema versions, and treat later-version fields as optional.
Source: Learnings
| @@ -137,6 +139,7 @@ export abstract class AgentHookServerIngestTerminal extends AgentHookServerInges | |||
| tabId, | |||
| worktreeId, | |||
| connectionId, | |||
| ...(event.providerSession ? { providerSession: event.providerSession } : {}), | |||
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Give the reported provider session precedence.
preservedProviderSession is spread after event.providerSession, so the previous session overwrites a newly reported session. A pane that replaces an active OpenCode 2 session can retain the old resume ID.
Use event.providerSession ?? preservedProviderSession, or spread the reported value last.
| } | ||
| return results | ||
| })() | ||
| return [discovery.then((results) => results[0]!), discovery.then((results) => results[1]!).catch(() => emptyOpenCode2Discovery(storageDir))] |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Return an empty OpenCode 2 discovery when no v2 database exists.
When v2Paths is empty, results contains only the v1 discovery. The second promise then fulfills with undefined; .catch() does not run. This violates the declared SessionFileDiscovery result contract and can make the scanner fail when it reads the discovery.
Proposed fix
if (v2Paths.length > 0) {
results.push(await discoverOpenCode2Sessions(storageDir, v2Paths, limit, issues))
+ } else {
+ results.push(emptyOpenCode2Discovery(storageDir))
}| await cancelUnreadResponseBody(response) | ||
| throw new Error(`opencode2 service event stream failed: ${response.status}`) | ||
| } | ||
| this.controller = controller |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Track the stream before awaiting fetch.
this.controller remains null while fetch is pending. Another terminal registration can start a second stream, and teardown cannot abort the pending request.
Assign the controller before fetch. Clear it only when the same request fails or closes.
| if (event === 'session.text.delta') { | ||
| const lastIngest = this.lastTextIngestAtByPaneKey.get(paneKey) ?? 0 | ||
| const now = Date.now() | ||
| if (now - lastIngest < TEXT_INGEST_THROTTLE_MS) { | ||
| return | ||
| } | ||
| this.lastTextIngestAtByPaneKey.set(paneKey, now) | ||
| } else if (event === 'session.text.ended') { |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Throttle current OpenCode text events.
The checks cover only session.text.delta and session.text.ended. Current session.next.text.delta events bypass the throttle and ingest every fragment.
Match both event families, for example with .endsWith('.text.delta') and .endsWith('.text.ended').
|
|
||
| private findTerminalByDirectory(directory: string): OpenCode2TerminalRegistration | null { | ||
| for (const registration of this.terminals.values()) { | ||
| if (isSessionDirectoryInCwd(registration.cwd, directory)) { |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not attribute sessions by the first directory match.
If two OpenCode 2 panes use the same cwd, every session matches both registrations and this loop selects the oldest terminal. Prompts, status, and providerSession can then attach to the wrong pane.
Maintain a stable session-to-pane association. Also select the most specific path when nested working directories match.
| while (true) { | ||
| const { done, value } = await reader.read() | ||
| if (done) { | ||
| break | ||
| } | ||
| buffer += decoder.decode(value, { stream: true }) | ||
| let lineEnd = buffer.indexOf('\n') | ||
| while (lineEnd !== -1) { | ||
| const line = buffer.slice(0, lineEnd).replace(/\r$/, '') | ||
| buffer = buffer.slice(lineEnd + 1) | ||
| if (line.startsWith('data:')) { | ||
| dataLines.push(line.slice(5).trimStart()) | ||
| } else if (line.length === 0 && dataLines.length > 0) { | ||
| const payload = dataLines.join('\n') | ||
| dataLines = [] | ||
| onEnvelope(payload) | ||
| } | ||
| lineEnd = buffer.indexOf('\n') | ||
| } | ||
| } | ||
| } catch { | ||
| // stream died; onClose handles the reconnect |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,120p' src/main/opencode2/sse-consumer.ts
rg -n "consumeOpenCode2EventStream|parseOpenCode2SseEnvelope" src/main/opencode2Repository: stablyai/orca
Length of output: 3635
Bound SSE line and event sizes in consumeOpenCode2EventStream. The consumer appends decoded daemon chunks to buffer until a newline arrives. It also stores every data: line in dataLines until a blank line arrives. A reachable malformed or oversized /api/event stream can therefore grow process memory without bound before onEnvelope runs. Enforce limits on the current line and the complete SSE event, and close or discard the stream when a limit is exceeded.
This limit belongs in src/main/opencode2/sse-consumer.ts. The event translator's per-message accumulator runs only after the consumer emits an envelope, so it cannot bound an unterminated SSE line or event.
| const nextClosedTombstones = repointRowRecord( | ||
| session.closedTerminalTabTombstonesByTabId, | ||
| oldWorktreeId, | ||
| newWorktreeId | ||
| ) | ||
| if (nextClosedTombstones) { | ||
| session.closedTerminalTabTombstonesByTabId = nextClosedTombstones | ||
| sessionChanged = true | ||
| } | ||
| const nextCloseIntents = repointRowArrays( | ||
| session.clientHostedBrowserCloseIntentsByEnvironment, | ||
| oldWorktreeId, | ||
| newWorktreeId |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Repair rows that use prior worktree identities.
The new row migration only matches the immediate oldWorktreeId. The cross-version test proves that an older build can strand these rows under a prior ID. A later current-build rename leaves them stale, so closed terminal tabs or browser pages can return.
src/main/persistence/tracking-repos/worktree-identity-migration.ts#L257-L269: Include applicablepriorWorktreeIds, or add a load-time repair for stranded rows.src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-state.ts#L206-L210: Pass prior IDs to the renderer rename path, or consume already-repaired persisted state.tests/e2e/cross-version-wire/cross-version-worktree-identity-downgrade.unit.test.ts#L169-L180: After the repair, expect both rows to useTHIRD_IDinstead of acceptingOLD_ID.
📍 Affects 3 files
src/main/persistence/tracking-repos/worktree-identity-migration.ts#L257-L269(this comment)src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-state.ts#L206-L210tests/e2e/cross-version-wire/cross-version-worktree-identity-downgrade.unit.test.ts#L169-L180
There was a problem hiding this comment.
ℹ️ The new commit removes only the stray root
CONTEXT.md; no code changed. The critical finding from the prior review is still open.
Reviewed changes
- Removed stray
CONTEXT.md— the repo root now holds onlyAGENTS.md/CLAUDE.md/README.mdagain; this was a scratch file and its removal is correct.
The blocker from the previous review is unchanged at src/main/ai-vault/session-scanner-opencode-sources.ts:64: opencodeDiscoveries still resolves an undefined discovery on a host with no OpenCode 2 beta database, which crashes sessionCandidatesFromDiscoveries. That needs the ?? emptyOpenCode2Discovery(storageDir) fix (and the session-scanner-opencode-sources-wsl-stall.test.ts count update) before this can merge.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
db00f47 to
04d99d8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f5d2b044-d3a7-4607-bdcb-c57064605af1
📥 Commits
Reviewing files that changed from the base of the PR and between db00f474d90449edf6a5b72512d25c63cc03e2e4 and 04d99d8.
📒 Files selected for processing (5)
src/main/ai-vault/session-scanner-every-agent-fixture.tssrc/main/ai-vault/session-scanner-opencode-sources.tssrc/main/ai-vault/session-scanner-opencode2-sqlite.tssrc/main/ai-vault/session-scanner-source-discovery.tssrc/renderer/src/runtime/agent-resume-host-authority-capability.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| gemini: undefined, | ||
| antigravity: undefined, | ||
| opencode: undefined, | ||
| opencode2: undefined, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,120p' src/renderer/src/runtime/agent-resume-host-authority-capability.ts
sed -n '1,240p' src/renderer/src/runtime/remote-agent-session-launch.ts
rg -n "agent-session\.host-authority\.v1|opencode2|ensureAgentSession|invalid_argument" src testsRepository: stablyai/orca
Length of output: 50371
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- capability mapping ---'
cat -n src/renderer/src/runtime/agent-resume-host-authority-capability.ts | sed -n '1,60p'
printf '%s\n' '--- launch path ---'
cat -n src/renderer/src/runtime/remote-agent-session-launch.ts | sed -n '1,110p'
printf '%s\n' '--- protocol capabilities ---'
cat -n src/shared/protocol-version.ts | sed -n '130,230p'
printf '%s\n' '--- resume agent list ---'
cat -n src/shared/agent-session-resume.ts | sed -n '1,40p'
printf '%s\n' '--- ensure-session contract ---'
cat -n src/shared/rpc-contract/agent-session-params.ts | sed -n '100,175p'
printf '%s\n' '--- host-authority declaration ---'
cat -n src/shared/agent-session-host-authority.ts | sed -n '1,180p'
printf '%s\n' '--- focused tests and bindings ---'
rg -n -g '*.ts' -g '*.tsx' -g '*.test.ts' -g '*.spec.ts' \
'ensureAgentSession|agent-session\.host-authority\.v1|RESUME_HOST_AUTHORITY_CAPABILITY_BY_AGENT|opencode2' \
src/main src/renderer/src/runtime src/shared | head -n 240
printf '%s\n' '--- relevant commit summary ---'
git show --stat --oneline 04d99d8f80
printf '%s\n' '--- relevant commit diff ---'
git show --format= --no-ext-diff 04d99d8f80 -- \
src/renderer/src/runtime/agent-resume-host-authority-capability.ts \
src/shared/agent-session-resume.ts \
src/shared/protocol-version.ts \
src/shared/rpc-contract/agent-session-params.ts \
src/renderer/src/runtime/agent-resume-host-authority-capability.test.tsRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- focused host-authority test: old-host simulation ---'
cat -n src/renderer/src/runtime/web-runtime-session-terminal-host-authority.test.ts | sed -n '110,245p'
printf '%s\n' '--- focused host-authority test: capability cases ---'
cat -n src/renderer/src/runtime/web-runtime-session-terminal-host-authority.test.ts | sed -n '245,330p'
printf '%s\n' '--- focused integration test references ---'
cat -n src/main/runtime/remote-agent-session-host-authority.integration.test.ts | sed -n '140,220p'
printf '%s\n' '--- mapping test ---'
cat -n src/renderer/src/runtime/agent-resume-host-authority-capability.test.ts | sed -n '1,220p'Repository: stablyai/orca
Length of output: 15178
Gate opencode2 resumes behind a dedicated capability. agent-session.host-authority.v1 predates opencode2, but ExplicitEnsure validates agent with z.enum(RESUMABLE_TUI_AGENTS). A host that advertises the generic capability but lacks the newer enum member rejects the resume request with invalid_argument. runRemoteAgentSessionLaunch falls back only for agent_session_legacy_required and method_not_found, so the resume fails instead of using the legacy path. Add a dedicated opencode2 capability and map it here.
There was a problem hiding this comment.
Important
Two things to address before merge: the new opencode2 resume mapping reintroduces a host-version-skew failure this module exists to prevent, and the every-agent capture guard test is currently red.
Reviewed changes
- Fixed the v2 discovery crash —
opencodeDiscoveriesnow yields only v1 discoveries, and a newopencode2Discoveriesreturns an empty discovery when a storage dir has no v2 database, so noundefinedentry reachessessionCandidatesFromDiscoveries. - Extended the every-agent fixture —
writeEveryAgentVaultnow writes anopencode-next.dbv2 fixture. - Declared the
opencode2resume gate — addedopencode2toRESUME_HOST_AUTHORITY_CAPABILITY_BY_AGENTasundefined. - Added a rename coverage test —
worktree-identity-rename-row-worktree-ids.test.tspins the value-owned worktree rows. - Lint suppressions —
SAFETY:justifications on three casts in the OpenCode 2 SQLite reader.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
04d99d8 to
e21adc4
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Clean up OpenCode 2 overlays. · plugin-overlay.ts:361
src/relay/plugin-overlay.ts:361
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winClean up OpenCode 2 overlays.
In the SSH relay path,
buildPluginEnvironmentmaterializes an OpenCode 2 overlay underopencode2RootusingpaneKey ?? id. PTY exit then callsclearOverlaywith the same identifier, but this loop omitsopencode2Root. Distinct exited panes can therefore accumulate mirrored configuration and plugin files under the relay home.Proposed fix
- for (const root of [this.opencodeRoot, ...Object.values(this.piRoots)]) { + for (const root of [ + this.opencodeRoot, + this.opencode2Root, + ...Object.values(this.piRoots) + ]) {This fixes the per-PTY SSH overlay path. The WSL handler uses a single instance-scoped cached overlay, not one overlay per PTY.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ead0cdc4-4e74-4abd-bbc8-eac6fe468163
📒 Files selected for processing (18)
src/main/agent-hooks/wsl-guest-plugin-install.tssrc/main/agent-hooks/wsl-hook-relay-deps.tssrc/main/agent-hooks/wsl-hook-relay-guest-install.tssrc/main/agent-hooks/wsl-hook-relay-manager.test.tssrc/main/agent-hooks/wsl-hook-relay-manager.tssrc/main/ipc/pty/host-env/assembly.tssrc/main/opencode/hook-plugin-module-contract.test.tssrc/main/opencode/hook-service.test.tssrc/main/opencode/hook-service.tssrc/main/opencode/status-plugin-factory-source.tssrc/main/opencode2/hook-service.tssrc/relay/plugin-overlay.test.tssrc/relay/plugin-overlay.tssrc/relay/relay-agent-hook-runtime.tssrc/relay/wsl-install-plugins-handler.test.tssrc/relay/wsl-install-plugins-handler.tssrc/shared/agent-hook-listener-transport.test.tssrc/shared/agent-hook-listener/source-routing.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| return [ | ||
| ...(options.emitNextEvents | ||
| ? [ | ||
| 'const nextTextByMessageID = new Map();', |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,190p' src/main/opencode/status-plugin-factory-source.ts
rg -n 'nextTextByMessageID|session.next.text|dispose|OrcaOpenCodeStatusPlugin' src/main/opencodeRepository: stablyai/orca
Length of output: 18749
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- source 190-320 ---'
sed -n '190,320p' src/main/opencode/status-plugin-factory-source.ts
printf '%s\n' '--- cap helpers and next-event tests ---'
rg -n -C 4 'capMessagePartText|session\\.next\\.text|nextTextByMessageID|emitNextEvents|dispose' src/main/opencode --glob '*.ts'
printf '%s\n' '--- generated source consumers ---'
rg -n -C 3 'getStatusPluginFactorySource|emitNextEvents|status-plugin-factory-source' src/main/opencode --glob '*.ts'Repository: stablyai/orca
Length of output: 46161
Keep nextTextByMessageID per factory and bound both dimensions.
nextTextByMessageID has module scope, but dispose does not clear it. An interrupted stream, or an ended event that returns before deletion, can retain entries after factory disposal. session.next.text.started also inserts without enforcing the 128-entry limit, and delta handling stores unbounded accumulated text.
Move the map inside OrcaOpenCodeStatusPlugin. Enforce the entry limit after both started and delta insertions. Cap each accumulated preview before storing it. Clear the map during disposal.
There was a problem hiding this comment.
Important
The rewrite routes OpenCode 2 through the relay plugin-overlay path, but the SSH sender never ships the OpenCode 2 plugin source, so opencode2 panes on SSH hosts silently get no status. The WSL path ships it; SSH does not.
Reviewed changes
- Replaced the OpenCode 2 service/SSE integration with a generated status plugin —
src/main/opencode2/{event-translator,sse-consumer,service-discovery}.tsand their tests are deleted, andgetOpenCodeFamilyPluginSourcenow takesemitNextEvents, mappingsession.next.*,permission.v2.*, andquestion.v2.*into the existing lifecycle and preview posts. - Parameterized
OpenCodeHookServiceby variant — a second instance usesopencode2-config-overlays,opencode2-hooks, andorca-opencode2-status.js, selected inbuildPtyHostEnvwhenlaunchAgent === 'opencode2'. - Extended the relay plugin-overlay path to a second agent —
PluginOverlayManagertakes anagentdiscriminator, andRelayAgentHookRuntimeplus the WSL guest handler accept and materialize a separateopencode2overlay. - Dropped the deleted service's PTY registration/cleanup from
local-configure.ts/state-cleanup.ts. - Added plugin-contract tests for the v2 permission and prompt/text mappings, plus separate-overlay tests for the WSL and relay paths.
⚠️ OpenCode 2 status never reaches SSH hosts
The new commits add opencode2PluginSource to the WSL relay deps and teach RelayAgentHookRuntime to materialize a separate OpenCode 2 overlay, but the SSH sender still ships only the OpenCode 1 source. On an SSH host PluginOverlayManager.hasOpenCode2Source() stays false, materializeOpenCode(..., 'opencode2') returns null, and no OPENCODE_CONFIG_DIR is injected into the remote PTY — so an opencode2 pane there reports no status at all. This contradicts the PR description's claim that "WSL and SSH relay paths ship and materialize separate OpenCode 2 overlays".
Technical details
# SSH relay never receives the OpenCode 2 plugin source
## Affected sites
- `src/main/ssh/ssh-relay-session.ts:1531-1536` — `installPluginsOnRelay` sends `opencodePluginSource` but not `opencode2PluginSource`.
- `src/relay/relay-agent-hook-runtime.ts:147-166` — reads `params.opencode2PluginSource` (undefined over SSH), so `hasOpenCode2Source()` is false.
- `src/relay/plugin-overlay.ts:110,159-160,229-232,259-265` — `opencode2PluginSource` stays null; `materializeOpenCode(..., 'opencode2')` returns null.
- `src/relay/relay-agent-hook-runtime.ts:80-91` — for `launchAgent === 'opencode2'`, the `hasOpenCodeSource('opencode2')` guard fails and no `OPENCODE_CONFIG_DIR` is injected.
## Required outcome
- An `opencode2` pane launched on an SSH host materializes the OpenCode 2 overlay and reports status, matching the WSL path.
## Suggested approach
- Add `opencode2PluginSource: openCodeInternals.getOpenCode2PluginSource()` to the `installPluginsOnRelay` payload. The relay handler and overlay already support it, so no relay change is needed.
- Consider asserting the install-plugins payload in `src/main/ssh/ssh-relay-session-managed-hooks.test.ts` so a future source omission fails a test.ℹ️ Nitpicks
- No test exercises the
question.v2.asked/replied/rejectedmapping; only the permission and prompt/text paths are covered, so the question-card contract rests on source inspection alone.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
28a83fe to
96ae72a
Compare
|
Rebased and narrowed in Follow-up review fixes now present:
The relay changes are required because SSH/WSL execution has a different filesystem: plugin source must cross the wire, be materialized beside the remote user's config, and be cleaned when the remote PTY exits. Visual proof in the PR body shows the actual OpenCode source checkout running via the |
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
- Shipped the OpenCode 2 plugin source over SSH —
installPluginsOnRelaynow sendsopencode2PluginSource, andssh-relay-session-managed-hooks.test.tsasserts the payload, closing the prior finding thatopencode2panes on SSH hosts silently got no status. - Swept the OpenCode 2 overlay on PTY exit —
PluginOverlayManager.clearOverlaynow includesopencode2Root, so exited panes no longer accumulate mirrored OpenCode 2 config and plugins. - Added a
question.v2lifecycle test — pinsquestion.v2.askedto theAskUserQuestioncard; therejectedhalf is asserted loosely (inline note).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
96ae72a to
19474e6
Compare
|
I re-read the inline comments. The branch now includes the concrete fixes relevant to the current OpenCode 2 implementation:
Several remaining comments refer to files intentionally removed when the PR was narrowed (mobile compatibility, transcript catchup, worktree migration, and the old OpenCode 2 SSE/service implementation); they are stale against the current diff. I also replaced the misleading visual proof with an actual Orca screenshot of the real source checkout launched as |
|
Correction: the previous replacement screenshot still did not make the running TUI legible. This new capture shows the actual OpenCode interactive screen on the left ( |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the three files changed since the prior pullfrog review (5252661170) at 96ae72a; the full 59-file diff was used for context.
- Labeled OpenCode 2 scan issues correctly —
OpenCodeSqliteWorkerClient.listnow pushesagent: args.agent ?? 'opencode'on its unavailable and timeout/crash scan issues instead of hardcodingopencode, so anopencode2history failure is attributed to the right agent. - Scoped the streamed-text accumulator per factory instance —
nextTextByMessageIDmoved from module scope into the factory body, so concurrent plugin instances no longer share one map; the map is also bounded attext.started, deltas arecapMessagePartText-capped, anddisposeclears it. - Removed the unreachable
session.next.text.delta/endedguard — the prior nit is resolved; the branch already returns earlier. - Strengthened the
question.v2.rejectedtest — it now asserts the final post isSessionIdleinstead of asome(AskUserQuestion)check theaskedcase already satisfied. I mutation-tested it: dropping the rejection mapping makes the test fail.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d3505b58-2207-4a89-8b55-9ccb9655e1ac
📥 Commits
Reviewing files that changed from the base of the PR and between 96ae72a7951bdf8f88ddd91e1d19f9838ae1d12d and 19474e64ef9660313ff8165ad2f0baa8e41d8812.
📒 Files selected for processing (3)
src/main/ai-vault/session-scanner-opencode-sqlite-worker-client.tssrc/main/opencode/hook-plugin-module-contract.test.tssrc/main/opencode/status-plugin-factory-source.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
|
Updated the PR body at current head The visual-proof section now leads with the actual interactive OpenCode 2 TUI running inside Orca, plus a second pane showing the live source checkout process. The old help/config-only proof is explicitly replaced. The body also records the latest follow-up tests and clarifies that comments about removed mobile/transcript/worktree/SSE files are stale against the narrowed diff. |
19474e6 to
7f0544e
Compare
|
CI follow-up: the previous run exposed two real integration misses, now fixed in |
7f0544e to
85004f0
Compare
|
CI failure follow-up pushed as |
85004f0 to
7cda04d
Compare
|
CI static-analysis failure fixed in |
There was a problem hiding this comment.
ℹ️ No critical issues — one formatting regression inline.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review (5252759621, at 19474e64); the incremental range-diff since 7f0544e touches two files.
- Fixed the pane-agent inventory ratchet —
titleHasAgentName's expected count forterminal-title-agent-type.tsmoved14→15, matching theopencode2branch this PR adds.pane-agent-identity-inventory.test.tswas failing at the previous head (7f0544e) and now passes. - Re-added a blank element to the generated OpenCode 2 plugin-source string array — cosmetic whitespace in the generated JS only; the plugin contract tests still pass.
- Regressed the formatter output of
getStatusPluginFactorySource's options type —oxfmt --checknow fails on the joined closing brace.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the delta is test-only, with one assertion that does not actually pin the mapping it was added for.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review (5255090192, at 447a288); the net change is limited to the OpenCode 2 setup-bridge test plus base-branch OMP content merged by the rebase.
- Covered the setup bridge's form-created path —
hook-plugin-opencode2-setup.test.tsnow yieldspermission.repliedand assertsAskUserQuestionforform.created. Theform.createdassertion is real (a mutation onquestion.askedfails it), but the companionSessionIdleassertion is satisfied bypermission.repliedand does not coverform.cancelled(inline). - Dropped the unrelated browser-pane fixture edit —
ClientHostedBrowserPagePane.markup.test.tsxis back to its base content and is no longer part of the PR; the prior anti-slop thread is retired. - Absorbed the base OMP commit-message agent —
commit-message-agent-spec.test.tsnow listsompalongside the PR'sopencode2.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
4642d0d restores OMP's config-directory selection but leaves the larger half of the same regression in place: the relay still never exports ORCA_OMP_FRESH_CONFIG, so omp --config "$ORCA_OMP_FRESH_CONFIG" on an SSH/WSL host has no fresh config and src/relay/omp-fresh-launch-environment.test.ts fails.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review (5255298590, at d31c918): one commit, 4642d0d fix(relay): preserve OMP config directory selection.
- Restored OMP config-directory selection in the relay overlay —
getDefaultPiAgentDir(kind, configDirName?)andmaterializePi'sconfigDirNameoption are back, so a custom OMP config dir is honored again on SSH/WSL. - Reformatted
getRelayOpenCodePluginPath,mirrorOpenCodeConfig, andmaterializeOpenCodeacross lines;mirrorOpenCodeConfigstill skips both OpenCode plugin file names. - Left
ORCA_OMP_FRESH_CONFIGdropped — the OMP fresh-launch env var is still absent frombuildPluginEnvironment; see inline.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the delta restores the OMP fresh-launch environment; one ordering nuance inline.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review (5255313220, at 4642d0d). The head commit 6d0dba3 touches four files.
- Restored
ORCA_OMP_FRESH_CONFIGin the relay —buildPluginEnvironmentsets the fresh-launch config again, so an SSH/WSLomplaunch keeps #20622's no-auto-resume behavior andomp-fresh-launch-environment.test.tspasses. The assignment lands after thehasPiSourceearly return, whereorigin/mainplaces it before (inline). - Corrected the OMP resume expectation —
omp-child-session-recovery.unit.test.tsnow expects the session-file path in the resume argv, which is what the OMP transcript resume actually returns. - Awaited the async env augmenter — the fresh-launch test's second
augmentcall is now awaited, so itstoEqual({})assertion evaluates the resolved env rather than a promise. - Reordered the
opencode2resume case — cosmetic; no behavior change.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review (5255468458, at 6d0dba3); the incremental range-diff isolates two files changed by 266e512.
- Moved the relay OMP fresh-config assignment above the
hasPiSourceguard —buildPluginEnvironmentnow setsORCA_OMP_FRESH_CONFIGbefore the early return, so an OMP launch on a relay host that holds no cached Pi sources keeps #20622's no-auto-resume behavior, matchingorigin/main. - Pinned the setup-bridge form resolution to the final post — the
SessionIdleassertion is nowexpect(names.at(-1)).toBe('SessionIdle'); I mutation-verified that dropping theform.cancelledarm now fails the test, wherepermission.repliedpreviously satisfied it.
Verified: pnpm vitest run src/main/opencode/hook-plugin-opencode2-setup.test.ts src/relay/omp-fresh-launch-environment.test.ts src/relay/plugin-overlay.test.ts — 30 tests pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
266e512 to
f5117da
Compare
Co-authored-by: Xiro The Dev <[email protected]>
45b9097 to
331765b
Compare
|
Please refer to this issue #19708 and avoid putting messy hacks in environment variables or hooks. |
looking at it |

ELI5
Orca now treats the OpenCode 2 beta as a first-class agent. Users can discover and launch the side-by-side
opencode2binary, keep its sessions across tab lifetimes, see working/waiting/done status, resume past sessions, and use it for commit-message generation.What changed
opencode2agent identity across desktop, telemetry, skills, resume commands, agent selection, and commit-message AI.server()/event({ event: { id, type, properties } })contract rather than undocumented service files or an SSE side channel.session.next.*,permission.v2.*, andquestion.v2.*) into Orca's existing status, preview, permission, and question lifecycle.Why
OpenCode's default TUI uses an in-process worker and loads server plugins from its config. Its current source defines the event hook and event schemas in
~/projects/opencodeat commit35075bb46692a921ab36715e5e1f4bf7f2def494. The integration therefore injects a plugin through the existing config-overlay path and keeps the existing Orca status pipeline, with fail-open behavior when a user's config or a remote relay cannot be materialized.The relay changes are necessary because an SSH or WSL agent executes on another filesystem. The host must ship the generated plugin source over the relay wire, the guest must materialize it beside the user's config, and PTY exit must remove the matching OpenCode 1 or OpenCode 2 overlay. Local PTYs use the same overlay model directly on the host.
This incorporates useful direction from the reference PR while correcting its stale service/SSE assumptions. Xiro The Dev is credited as co-author in the implementation commit.
Linked issue
Fixes #14025
Visual proof
The prior screenshots were inadequate: they showed help/config output rather than the running agent. This replacement screenshot is from the real OpenCode source checkout launched as
opencode2inside Orca. The Orca tab title isOpenCode, confirming the interactive TUI process is running in the terminal pane:https://github.com/user-attachments/assets/c6042ead-1874-4f12-858e-5a10fe1929d2
The supporting plugin-load proof remains below: OpenCode's own
debug configoutput lists the generatedorca-opencode2-status.jsplugin and its load marker.Testing
SessionIdlecorepack pnpm tc:nodegit diff --check~/projects/opencodeand ran its actual CLI from the source checkout through Orca;debug configshowed the generatedorca-opencode2-status.jsplugin and its load markerpnpm lint,pnpm test, andpnpm buildremain CI workReview notes
Current head:
19474e64ef9. The current diff no longer contains the mobile compatibility, transcript catchup, worktree migration, or removed OpenCode 2 SSE/service files mentioned by older bot comments./hook/opencodeand its original overlay.