Repository navigation
fix(agent-hooks): refresh existing Orca launchers when agent CLIs are unavailable - #13378
Conversation
…s no longer detected A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide config invoking Orca's launcher script under ~/.orca/agent-hooks, but the presence gate skips install() with no removal — freezing the script at whatever Orca generated last. Anyone in that state kept the pre-#11568 more.com-leaking .cmd forever, because no launcher script is ever deleted and Windows startup deliberately skips shell PATH hydration. Reconcile before gating: every existing shared launcher/statusline script is rewritten to the current template on each install pass. Creating scripts stays behind the presence gate — an existing file is proof of a prior install; a missing one means the gate did its job. Amp and Hermes are deliberately absent: they write provider-native plugin code with its own install lifecycle, not shared launchers. - refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists) - refreshManagedScripts() on the 11 launcher-writing services (openclaude via the shared Claude class) - reconcile pass in installManagedAgentHooks before presence detection, filtered by the agents option, best-effort per agent - coverage gate: a launcher written to ~/.orca/agent-hooks without a matching refresher entry fails the suite, in both directions
📝 WalkthroughWalkthroughManaged hook services can now refresh existing generated scripts without creating missing files. The refresh utility supports permissions, atomic replacement, Windows write retries, and asynchronous filesystem access. A registry connects supported agents to refresh callbacks. Installation runs selected refreshers before installer selection and CLI detection, logs refresh failures, and continues installation. Tests cover provider coverage, ordering, selection, missing files, platform behavior, permissions, and event-loop responsiveness. 🚥 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f161b0bb-6d35-43e9-87be-8bf6cd14b1b1
📒 Files selected for processing (16)
src/main/agent-hooks/installer-utils.tssrc/main/agent-hooks/managed-agent-hook-controls.test.tssrc/main/agent-hooks/managed-agent-hook-controls.tssrc/main/agent-hooks/managed-agent-hook-registry.tssrc/main/agent-hooks/managed-hook-script-refresh.test.tssrc/main/antigravity/hook-service.tssrc/main/claude/hook-service.tssrc/main/codex/hook-service.tssrc/main/command-code/hook-service.tssrc/main/copilot/hook-service.tssrc/main/cursor/hook-service.tssrc/main/devin/hook-service.tssrc/main/droid/hook-service.tssrc/main/gemini/hook-service.tssrc/main/grok/hook-service.tssrc/main/kimi/hook-service.ts
Windows Electron QA — PASS @
|
| Check | Result |
|---|---|
| Existing stale launcher rewritten to safe template | PASS — SHA CCA2C36E… → 17957A96…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak) |
| Absent managed script not created | PASS — no claude-statusline.cmd |
| Missing agent config not created | PASS — no .claude/settings.json; empty .claude/ dir only (0 files, not a hook install) |
| Renderer console | 0 errors (4 dev-only warnings: CSP/React Grab/tooltip) |
Note: droid-hook.cmd / grok-hook.cmd were created because those CLIs remained on PATH (control agents). Claude path stayed presence-gated.
UI exercised
Empty-home surface + Settings → Agents (Agent status hooks ON).
Screenshots
(uploaded to refs/uploads/pr-13378-windows-qa-screenshots, not in PR diff)
Cleanup
Temp profile/home, CDP/renderer processes from this run will be torn down after comment. PR worktree preserved.
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 95ceaa62-ccce-44e4-8875-ba6cf3622719
📒 Files selected for processing (18)
config/tsconfig.cli.jsonsrc/main/agent-hooks/managed-agent-hook-controls.test.tssrc/main/agent-hooks/managed-agent-hook-controls.tssrc/main/agent-hooks/managed-agent-hook-registry.tssrc/main/agent-hooks/managed-hook-script-refresh-main-thread.test.tssrc/main/agent-hooks/managed-hook-script-refresh.test.tssrc/main/agent-hooks/managed-hook-script-refresh.tssrc/main/antigravity/hook-service.tssrc/main/claude/hook-service.tssrc/main/codex/hook-service.tssrc/main/command-code/hook-service.tssrc/main/copilot/hook-service.tssrc/main/cursor/hook-service.tssrc/main/devin/hook-service.tssrc/main/droid/hook-service.tssrc/main/gemini/hook-service.tssrc/main/grok/hook-service.tssrc/main/kimi/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (13)
- src/main/antigravity/hook-service.ts
- src/main/droid/hook-service.ts
- src/main/command-code/hook-service.ts
- src/main/codex/hook-service.ts
- src/main/agent-hooks/managed-agent-hook-controls.test.ts
- src/main/agent-hooks/managed-agent-hook-registry.ts
- src/main/cursor/hook-service.ts
- src/main/agent-hooks/managed-agent-hook-controls.ts
- src/main/devin/hook-service.ts
- src/main/grok/hook-service.ts
- src/main/kimi/hook-service.ts
- src/main/gemini/hook-service.ts
- src/main/claude/hook-service.ts
Windows Electron QA — PASS @
|
| Check | Result |
|---|---|
| Existing stale launcher rewritten to safe template | PASS — SHA CCA2C36E… → D2C3CAC0…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak) |
| Absent managed statusline not created | PASS — no cursor-statusline.cmd |
| Missing agent config not created | PASS — no ~/.cursor |
| Other absent launchers not created | PASS — no gemini/antigravity/devin/kimi/command-code launchers |
| Renderer console | 0 errors (4 dev-only warnings: CSP/React Grab/tooltip) |
[agent-hooks] Failed to refresh |
0 in main/daemon/stdout/stderr |
PATH-present agents (claude/codex/droid/grok) correctly installed under the isolated home only.
UI exercised
Empty-home surface + Settings → Agents (heading Agents, Default Agent, Agent status hooks ON, Windows runtime).
Screenshots
(uploaded to refs/uploads/pr-13378-async-head-screenshots, not in PR diff; gh image unavailable without browser session token)
Cleanup
QA Electron/CDP/renderer processes and temp profile will be torn down after this comment. Worktree preserved at exact head for coordinator inspection.
Third-party upload audit (prior stopped attempt)
Prior temp orca-pr13378-qa-66c6194a had no image-urls.json and no catbox/0x0 URLs — no third-party upload occurred.
Windows Electron QA — PASS @
|
| Check | Result |
|---|---|
| Existing stale launcher rewritten to safe template | PASS — SHA 508BF34C… → D2C3CAC0…; now has if "%ORCA_AGENT_HOOK_PORT%"=="" exit /b 0 (no empty-port goto leak) |
| Absent managed statusline not created | PASS — no cursor-statusline.cmd |
| Missing agent config not created | PASS — no ~/.cursor |
| Other absent launchers not created | PASS — no gemini/antigravity/devin/kimi/command-code launchers |
| Renderer console (post-reload) | 0 errors (4 dev-only warnings: CSP/React Grab/tooltip) |
[agent-hooks] Failed to refresh |
0 in main stdout/stderr + daemon.log |
PATH-present agents (claude/codex/droid/grok) correctly installed under the isolated home only.
UI exercised
Empty-home surface + Settings → Agents (heading Agents, Default Agent, Agent status hooks ON, Windows runtime).
Screenshots
| Empty home | Settings → Agents |
|---|---|
![]() |
![]() |
Cleanup
QA Electron/CDP/renderer processes and temp profile torn down after this comment. Worktree preserved at exact head for coordinator inspection. No source changes; no merge.
… unavailable (stablyai#13378) * fix(agent-hooks): refresh existing shared hook scripts when the CLI is no longer detected A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide config invoking Orca's launcher script under ~/.orca/agent-hooks, but the presence gate skips install() with no removal — freezing the script at whatever Orca generated last. Anyone in that state kept the pre-stablyai#11568 more.com-leaking .cmd forever, because no launcher script is ever deleted and Windows startup deliberately skips shell PATH hydration. Reconcile before gating: every existing shared launcher/statusline script is rewritten to the current template on each install pass. Creating scripts stays behind the presence gate — an existing file is proof of a prior install; a missing one means the gate did its job. Amp and Hermes are deliberately absent: they write provider-native plugin code with its own install lifecycle, not shared launchers. - refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists) - refreshManagedScripts() on the 11 launcher-writing services (openclaude via the shared Claude class) - reconcile pass in installManagedAgentHooks before presence detection, filtered by the agents option, best-effort per agent - coverage gate: a launcher written to ~/.orca/agent-hooks without a matching refresher entry fails the suite, in both directions * perf(agent-hooks): refresh launchers off the main thread * test(agent-hooks): keep refresh mode assertion POSIX-only






Summary
Follow-up to #11568 / #11549. If an agent CLI falls off PATH (for example, after an npm-prefix or shim relocation), the presence gate skips
install()with no removal, while the agent's user-wide config can keep invoking its existing launcher under~/.orca/agent-hooks. That left the launcher frozen at its previous generated version; on Windows, it could preserve the pre-#11568more.comleak indefinitely.This adds a reconcile pass before presence detection: every already-existing shared launcher/statusline script is rewritten to the current template. Creation remains presence-gated, so an absent script or missing agent config is not created. Amp and Hermes remain excluded because they install provider-native plugin code through a different lifecycle rather than shared launchers.
The refresh path is asynchronous and sequential. It short-circuits identical content, publishes changed content with a same-directory temp file plus rename, preserves POSIX executable mode, and applies the existing Windows ACL recovery behavior without blocking Electron's main thread or fanning work across the thread pool.
User path
Decision rationale
The lifecycle boundary is deliberate: automatically maintain artifacts Orca already owns; require positive CLI detection before creating integrations or mutating agent-owned configuration.
~/.orca/agent-hooksproves Orca previously created that launcher, and the agent's user-wide config may still invoke it while the CLI is temporarily missing from Orca's PATH.cli_not_foundcould therefore break a still-referenced hook target.This makes the refresh pass the narrowest repair that reaches the affected population: it updates only existing Orca-owned launchers, creates nothing for never-configured agents, and leaves agent configuration untouched until the CLI is positively detected.
Screenshots
No product UI changes. Exact-head Windows Electron validation and screenshots: #13378 (comment)
Testing
0646b42075: 53 files, 703 passed, 27 skippedgit diff --checkAI Review Report
Reviewed adversarially from the user-visible failure back through presence detection and installer history. Before #11442, managed-hook reconciliation invoked installers unconditionally, which refreshed launchers; #11442 correctly added CLI-presence gating but thereby froze an existing launcher when a CLI became undetectable. #11568 fixed the leaking Windows template and explicitly left existing-launcher refresh as this follow-up.
Alternatives considered and rejected: deleting on
cli_not_foundturns a false-negative PATH probe into a broken hook target; treating launcher existence as CLI presence would resume mutating agent configuration without proof the CLI is installed; versioned filenames require config rewrites. SSH/relay installers are separate and unchanged, and the local path does not assume a git worktree, so SSH/WSL and folder-workspace behavior are unaffected.Security Audit
Refresh touches only files that already exist under Orca's fixed
~/.orca/agent-hooksnamespace and uses the same trusted in-repo generators as installation. It creates no launcher directories, missing scripts, or agent configuration. Best-effort failures are logged per agent and preserve a complete old script rather than publishing partial content.Notes