Repository navigation
fix(agent-hooks): install OpenCode status plugin into the WSL guest so status works over WSL - #10328
Conversation
…o status works over WSL OpenCode reports agent status via a JS plugin dropped into OPENCODE_CONFIG_DIR (unlike Claude/Codex, which use managed hooks.json scripts). Over the WSL runtime that plugin was never materialized inside the guest and OPENCODE_CONFIG_DIR never crossed into the guest, so OpenCode status never reached Orca's sidebar (the workspace stayed green). Codex already worked; this was OpenCode-specific. Mirror the SSH plugin-overlay path for WSL: - Guest relay registers AGENT_HOOK_INSTALL_PLUGINS_METHOD, byte-caps the source, and materializes an OpenCode config overlay via PluginOverlayManager (the same electron-free path the SSH relay uses), returning overlayDirs.opencode. - Host manager ships the plugin source over the existing stdio channel after installers run (and on mid-session reinstall) and records the guest overlay dir; -32601 / CONNECTION_LOST / DISPOSED are swallowed like ssh-relay-session. - PTY env points OPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR at the guest overlay; until the relay reports it (first spawn / older guest bundle) it drops those vars rather than crossing the Windows overlay path into WSL — so in-guest OpenCode falls back to its own config (pre-fix behavior, no regression). - WSLENV passes OPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR through (/u for guest paths). SSH is untouched: the same JSON-RPC constant is reused and the guest response merely gains an optional overlayDirs field the SSH host ignores. Runtime repro: native opencode launched in a WSL Orca terminal had ORCA_AGENT_HOOK_PORT/ORCA_PANE_KEY but no OPENCODE_CONFIG_DIR and no Orca plugin in ~/.config/opencode, so agentStatusByPaneKey stayed empty.
|
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:
📝 WalkthroughWalkthroughAdds WSL guest-side OpenCode plugin installation through the agent-hook relay. The relay manager requests and tracks per-distro overlay directories, while PTY environment construction uses those guest paths when available and removes incompatible Windows-side paths otherwise. WSLENV handling now marks OpenCode configuration directories for appropriate path translation. Tests cover guest installation, byte limits, missing handlers, overlay exposure, PTY environment behavior, and WSLENV entries. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/relay/wsl-install-plugins-handler.ts (1)
1-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the new implementation comments. These multi-line comments narrate behavior already expressed by names and control flow; retain only a concise one-line explanation where the cross-process fallback is non-obvious.
src/relay/wsl-install-plugins-handler.ts#L1-L5: reduce the file-header narrative to one short purpose statement.src/relay/wsl-install-plugins-handler.test.ts#L1-L3: reduce the platform rationale to one line.src/relay/wsl-agent-hook-relay.ts#L67-L69: reduce the overlay-registration rationale to one line.src/main/agent-hooks/wsl-hook-relay-manager.ts#L101-L103: shorten the getter documentation to one line.src/main/agent-hooks/wsl-hook-relay-manager.ts#L280-L281: shorten the installer rationale to one line.src/main/agent-hooks/wsl-guest-plugin-install.ts#L1-L5: reduce the file-header narrative to one short purpose statement.src/main/pty/wsl-orca-env.ts#L57-L58: shorten the WSLENV flag rationale to one line.As per coding guidelines, “Keep comments concise and limited to non-obvious context; prefer one line and do not explain obvious behavior or walk through implementation details.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 45298064-73b5-47d6-af83-e30bb3b89083
📒 Files selected for processing (11)
src/main/agent-hooks/wsl-guest-plugin-install.tssrc/main/agent-hooks/wsl-hook-relay-deps.tssrc/main/agent-hooks/wsl-hook-relay-manager.test.tssrc/main/agent-hooks/wsl-hook-relay-manager.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/pty/wsl-orca-env.test.tssrc/main/pty/wsl-orca-env.tssrc/relay/wsl-agent-hook-relay.tssrc/relay/wsl-install-plugins-handler.test.tssrc/relay/wsl-install-plugins-handler.ts
| it('leaves the overlay dir null when the guest bundle lacks the installPlugins handler', async () => { | ||
| const waitForSentinel = vi.fn(async () => guestTransport(false)) | ||
| const { manager, deps } = createManager({ waitForSentinel }) | ||
| manager.ensureForDistro('Ubuntu') | ||
| // Connect still completes (hooks install); the -32601 is swallowed silently. | ||
| await vi.waitFor(() => expect(deps.installHooks).toHaveBeenCalledTimes(1)) | ||
| await new Promise((resolve) => setTimeout(resolve, 20)) | ||
| expect(manager.getOpenCodeOverlayDir('Ubuntu')).toBeNull() | ||
| expect(deps.warn).not.toHaveBeenCalledWith(expect.stringContaining('installPlugins')) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Await a completion signal instead of a fixed delay.
getOpenCodeOverlayDir() starts as null, so this passes if installPlugins hangs; the 20 ms sleep does not prove the -32601 fallback completed. Expose or spy on the relay request and await its completion.
… and churning under running agents Review fixes on top of the WSL OpenCode plugin install: - Never cross a Windows OPENCODE_CONFIG_DIR into the guest. The /p flag was not a defensive default but WSLENV's translate-and-deliver flag, and buildWslRelaySpawnEnv spreads process.env while the daemon merge resurrects keys buildPtyHostEnv only deleted -- so a Windows value reached the guest as /mnt/c/... and was adopted as its OpenCode config root. Register the two vars only when the value is already a guest POSIX path. - Make guest materialization idempotent. The overlay id is instance-scoped, and the host re-ships on every reinstall (60s after connect, and on later pane spawns), so materializeOpenCode's remove-and-rebuild wiped the config root under running agents and raced panes spawning against the path just handed to them. Rebuild only when the shipped source changed or the overlay went missing. - Mirror the guest's default ~/.config/opencode (honouring XDG_CONFIG_HOME) when no explicit dir is discoverable, so pointing OPENCODE_CONFIG_DIR at the overlay no longer silently drops the user's models/agents/skills/mcp. - Carry opencodeOverlayDir across relay relaunch; it is instance-keyed and on the distro's persistent filesystem, so dropping it only blanked status on panes spawned mid-relaunch.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dd3389d7-8d69-46b0-b675-5df09bcb1666
📒 Files selected for processing (7)
src/main/agent-hooks/wsl-guest-plugin-install.tssrc/main/agent-hooks/wsl-hook-relay-manager.tssrc/main/pty/wsl-orca-env.test.tssrc/main/pty/wsl-orca-env.tssrc/relay/wsl-agent-hook-relay.tssrc/relay/wsl-install-plugins-handler.test.tssrc/relay/wsl-install-plugins-handler.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/relay/wsl-agent-hook-relay.ts
- src/main/agent-hooks/wsl-hook-relay-manager.ts
…ailed to rebuild Round-2 review fixes: - materializeOpenCode wipes before rebuilding, and every failure path after the wipe returns null leaving the dir present but plugin-less. The host treated that null the same as "no handler / teardown" and silently kept the previous value, so a pane could be pointed at an empty config root -- worse than the documented fallback of dropping the var. requestGuestOpenCodeOverlayDir now distinguishes 'none' (guest answered, no dir) from 'unavailable', and the manager clears the recorded dir on 'none'. - The handler cache keyed only on plugin source, so a ~/.config/opencode created after the relay connected was never mirrored for the relay's lifetime. Key on the resolved source dir too, and validate the cache by the plugin file rather than the directory -- the directory is exactly what a failed rebuild leaves behind, so checking it alone made the bad state stick.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/agent-hooks/wsl-guest-plugin-install.test.ts (2)
6-10: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the relay method and payload.
fakeMuxcurrently accepts a zero-argument callback, so these tests cannot detect regressions in the JSON-RPC method or plugin-source payload. Capture the request arguments and assert the expected contract in the success case.Suggested test adjustment
function fakeMux( - request: () => Promise<unknown>, + request: (method: string, params?: Record<string, unknown>) => Promise<unknown>, isDisposed = false ): { mux: SshChannelMultiplexer } { return { mux: { request, isDisposed: () => isDisposed } as unknown as SshChannelMultiplexer } } it('reports the guest overlay dir', async () => { - const { mux } = fakeMux(async () => ({ overlayDirs: { opencode: '/home/jin/.orca-relay/x' } })) + const request = vi.fn(async () => ({ overlayDirs: { opencode: '/home/jin/.orca-relay/x' } })) + const { mux } = fakeMux(request) await expect(requestGuestOpenCodeOverlayDir(mux, deps(), 'Ubuntu')).resolves.toEqual({ kind: 'dir', dir: '/home/jin/.orca-relay/x' }) + expect(request).toHaveBeenCalledWith('agent_hook.installPlugins', { + opencodePluginSource: '// src' + }) })
38-49: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the
mux.isDisposed()fallback explicitly.This test only exercises error codes; it does not verify the separate disposed-multiplexer branch at Line 37. Add a case where an ordinary error is thrown while
isDisposedistrue, and assert that no warning is emitted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1339a318-5a52-45c6-86dc-f045d3c6aa1f
📒 Files selected for processing (6)
src/main/agent-hooks/wsl-guest-plugin-install.test.tssrc/main/agent-hooks/wsl-guest-plugin-install.tssrc/main/agent-hooks/wsl-hook-relay-manager.tssrc/relay/plugin-overlay.tssrc/relay/wsl-install-plugins-handler.test.tssrc/relay/wsl-install-plugins-handler.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/relay/wsl-install-plugins-handler.ts
- src/main/agent-hooks/wsl-hook-relay-manager.ts
- src/relay/wsl-install-plugins-handler.test.ts
…he WSL overlay OPENCODE_CONFIG_DIR is APPENDED to OpenCode's config-dir list, not a replacement for it. Verified against the shipped binary: the list is built as [Path.config, ...project .opencode dirs, ...OPENCODE_CONFIG_DIR ? [it] : []], and Path.config is derived independently from XDG_CONFIG_HOME/$HOME/.config. So ~/.config/opencode is read whether or not Orca overrides the var, and the earlier fallback that mirrored it into the overlay made OpenCode load the user's config -- and their plugins -- twice. Resolve only an explicitly-set dir, which is the one case that genuinely leaves the list when Orca overwrites the variable. This also restores parity with the SSH and local paths.
…test framing The per-call source-dir re-resolution comment still described the XDG default branch that 6745eba removed. The relay's env is fixed for its lifetime and the rc scan behind it is memoized, so the sourceDir cache key is defensive rather than live -- say so, and retitle the test that simulates it by mutating the captured env, so neither reads as coverage of a production scenario.
…o status works over WSL (stablyai#10328) * fix(agent-hooks): install OpenCode status plugin into the WSL guest so status works over WSL OpenCode reports agent status via a JS plugin dropped into OPENCODE_CONFIG_DIR (unlike Claude/Codex, which use managed hooks.json scripts). Over the WSL runtime that plugin was never materialized inside the guest and OPENCODE_CONFIG_DIR never crossed into the guest, so OpenCode status never reached Orca's sidebar (the workspace stayed green). Codex already worked; this was OpenCode-specific. Mirror the SSH plugin-overlay path for WSL: - Guest relay registers AGENT_HOOK_INSTALL_PLUGINS_METHOD, byte-caps the source, and materializes an OpenCode config overlay via PluginOverlayManager (the same electron-free path the SSH relay uses), returning overlayDirs.opencode. - Host manager ships the plugin source over the existing stdio channel after installers run (and on mid-session reinstall) and records the guest overlay dir; -32601 / CONNECTION_LOST / DISPOSED are swallowed like ssh-relay-session. - PTY env points OPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR at the guest overlay; until the relay reports it (first spawn / older guest bundle) it drops those vars rather than crossing the Windows overlay path into WSL — so in-guest OpenCode falls back to its own config (pre-fix behavior, no regression). - WSLENV passes OPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR through (/u for guest paths). SSH is untouched: the same JSON-RPC constant is reused and the guest response merely gains an optional overlayDirs field the SSH host ignores. Runtime repro: native opencode launched in a WSL Orca terminal had ORCA_AGENT_HOOK_PORT/ORCA_PANE_KEY but no OPENCODE_CONFIG_DIR and no Orca plugin in ~/.config/opencode, so agentStatusByPaneKey stayed empty. * fix(agent-hooks): stop the WSL OpenCode overlay leaking Windows paths and churning under running agents Review fixes on top of the WSL OpenCode plugin install: - Never cross a Windows OPENCODE_CONFIG_DIR into the guest. The /p flag was not a defensive default but WSLENV's translate-and-deliver flag, and buildWslRelaySpawnEnv spreads process.env while the daemon merge resurrects keys buildPtyHostEnv only deleted -- so a Windows value reached the guest as /mnt/c/... and was adopted as its OpenCode config root. Register the two vars only when the value is already a guest POSIX path. - Make guest materialization idempotent. The overlay id is instance-scoped, and the host re-ships on every reinstall (60s after connect, and on later pane spawns), so materializeOpenCode's remove-and-rebuild wiped the config root under running agents and raced panes spawning against the path just handed to them. Rebuild only when the shipped source changed or the overlay went missing. - Mirror the guest's default ~/.config/opencode (honouring XDG_CONFIG_HOME) when no explicit dir is discoverable, so pointing OPENCODE_CONFIG_DIR at the overlay no longer silently drops the user's models/agents/skills/mcp. - Carry opencodeOverlayDir across relay relaunch; it is instance-keyed and on the distro's persistent filesystem, so dropping it only blanked status on panes spawned mid-relaunch. * fix(agent-hooks): stop advertising a WSL OpenCode overlay the guest failed to rebuild Round-2 review fixes: - materializeOpenCode wipes before rebuilding, and every failure path after the wipe returns null leaving the dir present but plugin-less. The host treated that null the same as "no handler / teardown" and silently kept the previous value, so a pane could be pointed at an empty config root -- worse than the documented fallback of dropping the var. requestGuestOpenCodeOverlayDir now distinguishes 'none' (guest answered, no dir) from 'unavailable', and the manager clears the recorded dir on 'none'. - The handler cache keyed only on plugin source, so a ~/.config/opencode created after the relay connected was never mirrored for the relay's lifetime. Key on the resolved source dir too, and validate the cache by the plugin file rather than the directory -- the directory is exactly what a failed rebuild leaves behind, so checking it alone made the bad state stick. * fix(agent-hooks): don't mirror the XDG default OpenCode config into the WSL overlay OPENCODE_CONFIG_DIR is APPENDED to OpenCode's config-dir list, not a replacement for it. Verified against the shipped binary: the list is built as [Path.config, ...project .opencode dirs, ...OPENCODE_CONFIG_DIR ? [it] : []], and Path.config is derived independently from XDG_CONFIG_HOME/$HOME/.config. So ~/.config/opencode is read whether or not Orca overrides the var, and the earlier fallback that mirrored it into the overlay made OpenCode load the user's config -- and their plugins -- twice. Resolve only an explicitly-set dir, which is the one case that genuinely leaves the list when Orca overwrites the variable. This also restores parity with the SSH and local paths. * docs(agent-hooks): correct the WSL install-plugins cache comment and test framing The per-call source-dir re-resolution comment still described the XDG default branch that 6745eba removed. The relay's env is fixed for its lifetime and the rc scan behind it is memoized, so the sourceDir cache key is defensive rather than live -- say so, and retitle the test that simulates it by mutating the captured env, so neither reads as coverage of a production scenario.
Root cause
When Orca's agent runtime is WSL on Windows, OpenCode agent status (Idle/Working/Done/Permission) never reached Orca's sidebar — the workspace stayed green. Codex worked; OpenCode did not.
OpenCode reports status via a JS plugin dropped into
OPENCODE_CONFIG_DIR(unlike Claude/Codex, which use managedhooks.jsonscripts). On the WSL path that plugin was never materialized inside the guest, andOPENCODE_CONFIG_DIRnever crossed into the guest — so in-guest OpenCode loaded no Orca plugin andagentStatusByPaneKeystayed empty.Runtime repro: native
opencode(from opencode.ai/install) launched in a WSL Orca terminal hadORCA_AGENT_HOOK_PORTandORCA_PANE_KEYbut noOPENCODE_CONFIG_DIR, and no Orca plugin existed in~/.config/opencode. SSH did not have this bug — only WSL.Approach — mirror the SSH plugin-overlay path for WSL
The SSH relay already ships OpenCode's plugin source over the wire and materializes a config overlay in the remote home via
PluginOverlayManager. This PR gives the WSL guest relay the same capability:src/relay/wsl-agent-hook-relay.ts+ newwsl-install-plugins-handler.ts) registersAGENT_HOOK_INSTALL_PLUGINS_METHOD, byte-caps each source, and materializes an OpenCode config overlay viaPluginOverlayManager(electron-free — already bundled with the SSH relay), returningoverlayDirs.opencode.wsl-hook-relay-deps.ts,wsl-hook-relay-manager.ts, newwsl-guest-plugin-install.ts) ship the plugin source over the existing stdio channel after the hook installers run (and again on mid-session reinstall), and record the guest overlay dir.-32601/CONNECTION_LOST/DISPOSEDare swallowed, mirroringssh-relay-session.ts.src/main/ipc/pty.tsWSL branch) pointsOPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIRat the guest overlay when known.src/main/pty/wsl-orca-env.ts) passesOPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIRthrough (/ufor guest POSIX paths).First-spawn graceful degradation
The relay launch is fire-and-forget; on the very first spawn (before the relay connects) or against an older guest bundle (no handler →
-32601swallowed), the overlay dir isnull. In that case the PTY env deletesOPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR/ORCA_OPENCODE_SOURCE_CONFIG_DIRrather than crossing the Windows overlay path into WSL (which would hide the user's real config). Deleting = in-guest OpenCode uses its own default config = today's pre-fix behavior, so there is no regression. Noawaitis added to the synchronous PTY env build.SSH is untouched
The same
AGENT_HOOK_INSTALL_PLUGINS_METHODconstant is reused; the guest response merely gains an optionaloverlayDirsfield the SSH host ignores. Scope is OpenCode only — the payload/response shape stays identical to SSH so Pi/OMP are additive later.Tests
wsl-hook-relay-manager.test.ts: guest dispatcher registers the new method;connect()exposes the guest overlay dir; a-32601(handler absent) case keeps the overlay dir null and still completes connect.wsl-install-plugins-handler.test.ts(POSIX-only): feeds a source, assertsorca-opencode-status.jswritten under the overlay andoverlayDirs.opencodeequals that dir; includes a byte-cap rejection case.wsl-orca-env.test.ts: guest-POSIXOPENCODE_CONFIG_DIR→WSLENVOPENCODE_CONFIG_DIR/u(+ORCA_OPENCODE_CONFIG_DIR/u); absent var → no entry.pty.test.ts: WSL daemon spawn dropsOPENCODE_CONFIG_DIRuntil the overlay is known; points it at the guest overlay (and clears the source pointer) once the relay reports it.ssh-relay-session-agent-hooks.integration.test.tsandagent-hook-relay.test.tsremain green.Typecheck + oxlint + the touched tests all pass.