Repository navigation
Only install agent hooks for installed CLIs - #7474
brennanb2025 wants to merge 6 commits into
Conversation
|
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis change adds shared managed-agent target and executable-token utilities, local and relay-side CLI presence detection, and a manifest-driven hook installation pipeline. Local and remote installers now return structured per-agent statuses with skip reasons and error handling. CLI, IPC, runtime, startup, Codex launch, and SSH relay flows use asynchronous presence-gated installation. Tests cover PATH probing, overrides, timeout cleanup, manifest alignment, status reporting, cancellation, and remote installation behavior. Configuration updates register the new compilation inputs and reliability gate. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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: 5
♻️ Duplicate comments (1)
src/main/agent-hooks/managed-agent-hook-controls.ts (1)
13-19: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDuplicate
ManagedHookInstallertype,errorStatus, andrunManagedHookInstallersvsinstall-telemetry.ts— see linked comment in that file for the functional regression this causes (lost default telemetry on install failure).This file's
runManagedHookInstallers(line 92:onInstallError: InstallOptions['onInstallError'], used asonInstallError?.(agent, error)) does not default torecordManagedHookInstallFailurethe wayinstall-telemetry.ts's version does, so call sites that omitonInstallError(e.g., the CLI offline path viaapplyAgentStatusHooksEnabled) silently skip failure telemetry.Also applies to: 77-109
🧹 Nitpick comments (5)
src/shared/managed-agent-command-token.ts (1)
7-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExplain the platform-dependent backslash-escape rule.
shouldTreatBackslashAsEscapesilently disables backslash-escaping on Windows so that paths likeC:\My Tools\claude.cmdsurvive intact, but nothing states this reasoning inline. A one-line comment would prevent future edits from "fixing" this as an oversight.As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
📝 Suggested comment
const shouldTreatBackslashAsEscape = (options.platform ?? process.platform) !== 'win32' + // Why: Windows paths use `\` as a separator, not an escape char, so backslash + // escaping must be disabled there to preserve literal path segments like `C:\Tools`.Source: Coding guidelines
src/main/agent-hooks/local-agent-cli-presence.ts (1)
44-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a short comment explaining the Windows
X_OKskip.Skipping the executable-bit check on
win32(Windows lacks POSIX execute permission semantics) is a non-obvious platform quirk that isn't documented inline.As per coding guidelines, non-obvious platform-driven behavior should have a short comment explaining why.
📝 Suggested comment
if (platform === 'win32') { + // Why: Windows has no POSIX execute-permission bit; access(X_OK) isn't + // a meaningful executability signal there, so file existence suffices. return true }Source: Coding guidelines
src/main/agent-hooks/managed-agent-hook-controls.test.ts (1)
1-178: 📐 Maintainability & Code Quality | 🔵 TrivialMissing test coverage for the detection-failure (
cli_presence_unknown) skip path.The suite covers found/missing gating,
shouldContinuegating, and theagentsfilter, but doesn't exercisedetectLocalManagedAgentCliPresenceMock.mockRejectedValue(...), which drives thecli_presence_unknownskip branch ininstallManagedAgentHooks(lines 36-46 ofmanaged-agent-hook-controls.ts).✅ Suggested additional test
+ it('skips all agents with cli_presence_unknown when detection throws', async () => { + detectLocalManagedAgentCliPresenceMock.mockRejectedValue(new Error('probe failed')) + + const results = await installManagedAgentHooks({ agentCmdOverrides: {} }) + + expect(installCodex).not.toHaveBeenCalled() + expect(installClaude).not.toHaveBeenCalled() + expect(results).toEqual([ + expect.objectContaining({ agent: 'codex', state: 'skipped', skipReason: 'cli_presence_unknown' }), + expect.objectContaining({ agent: 'claude', state: 'skipped', skipReason: 'cli_presence_unknown' }) + ]) + })src/main/ipc/settings.ts (1)
122-125: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the
shouldHydrateShellPathgate
app.isPackaged && process.platform !== 'win32'is duplicated insrc/main/ipc/settings.tsandsrc/main/index.ts; moving it into a shared helper or constant would keep the hook-install path and runtime wiring aligned.src/main/runtime/orca-runtime.ts (1)
2480-2493: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winConsider guarding against a rapid re-toggle race with
shouldContinue.
updateClientSettingsappliesupdateSettingssynchronously and then awaitsapplyAgentStatusHooksEnabledfor the previous toggle target. If a secondupdateClientSettingscall flips the setting back before the first install/remove finishes, the two async operations can complete out of order and leave hook state inconsistent with the final persisted setting.applyAgentStatusHooksEnabled/installManagedAgentHooksalready support anoptions.shouldContinuecallback for exactly this purpose — it's used at the startup call site insrc/main/index.ts(shouldContinue: () => isAgentStatusHooksEnabled(managedHookStore.getSettings())) but not wired in here.♻️ Suggested fix
try { await applyAgentStatusHooksEnabled( updates.agentStatusHooksEnabled, { agentCmdOverrides: this.store.getSettings().agentCmdOverrides ?? {} }, { shouldHydrateShellPath: this.shouldHydrateShellPathForAgentHooks, - onInstallError: recordManagedHookInstallFailure + onInstallError: recordManagedHookInstallFailure, + shouldContinue: () => + this.store?.getSettings().agentStatusHooksEnabled !== false === + updates.agentStatusHooksEnabled } ) } catch (error) {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 793174eb-83b4-49f6-aa76-802aff72c80d
📒 Files selected for processing (30)
config/reliability-gates.jsoncconfig/tsconfig.cli.jsonsrc/cli/handlers/agent-hooks.test.tssrc/cli/handlers/agent-hooks.tssrc/main/agent-hooks/install-telemetry.tssrc/main/agent-hooks/local-agent-cli-presence.test.tssrc/main/agent-hooks/local-agent-cli-presence.tssrc/main/agent-hooks/managed-agent-hook-controls.test.tssrc/main/agent-hooks/managed-agent-hook-controls.tssrc/main/agent-hooks/managed-agent-hook-manifest.test.tssrc/main/agent-hooks/managed-agent-hook-manifest.tssrc/main/agent-hooks/remote-managed-hook-installers.test.tssrc/main/agent-hooks/remote-managed-hook-installers.tssrc/main/index.tssrc/main/ipc/settings.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/client-ui.tssrc/main/ssh/ssh-relay-session.test.tssrc/main/ssh/ssh-relay-session.tssrc/main/text-generation/commit-message-agent-environment.test.tssrc/main/text-generation/commit-message-agent-environment.tssrc/relay/agent-hook-cli-presence-timeout.test.tssrc/relay/agent-hook-cli-presence.test.tssrc/relay/agent-hook-cli-presence.tssrc/relay/relay.tssrc/renderer/src/components/settings/SourceControlActionRepoOverrideNote.tsxsrc/shared/agent-hook-types.tssrc/shared/managed-agent-command-token.tssrc/shared/managed-agent-hook-targets.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/settings/SourceControlActionRepoOverrideNote.tsx
|
Possibly relevant WSL hook-transport edge case from #7565 / #7091. This PR gates managed hook installation on positive CLI presence. That is useful, but a separate WSL failure mode now looks confirmed: a WSL-spawned agent can have the managed hook/extension installed and launched correctly, but still be unable to report status because the injected hook receiver endpoint points at Windows localhost. Observed with OMP on Windows desktop app + WSL runtime:
So for WSL agent hooks, presence/install success is not enough; the injected endpoint must be reachable from the WSL process. If this PR touches hook launch/env validation, it would be worth adding WSL coverage for endpoint reachability from the actual spawned agent environment. |
Co-authored-by: Orca <[email protected]>
…ixes - Report agents omitted from the remote presence map as remote_presence_unavailable instead of cli_not_found; only a positive 'missing' probe means the CLI is absent. - Re-check shouldContinue after the SFTP open await in installManagedHooksOnRemote so a disposed/replaced session cannot mutate remote agent config. - Treat relative (non-home, non-absolute) command overrides as unknown presence instead of probing them against the main process CWD. Co-authored-by: Orca <[email protected]>
…ax-lines - Update the issue #7253 remote-installer coverage test to the manifest + presence-gated installRemoteManagedAgentHooks signature (droid/copilot now install remotely only with positive CLI presence, preserving the #7253 fix). - Split the remote managed-hook presence gating tests out of ssh-relay-session.test.ts into a focused sibling file so both stay under the 800-line oxlint max-lines limit without any suppression.
…ve-override guard, gate test path - Restore per-launch Codex hook upkeep on the interactive PTY launch path via a shared maintainCodexLaunchHooks() helper (fire-and-forget from the sync spawn path, awaited from commit-message prep). This keeps #7896's runtime /hooks approval promotion + user-hook refresh running on every Codex launch, which the presence-gating refactor had dropped from the interactive path. Enabled installs stay presence-gated. - Relay CLI presence: report 'unknown' for a relative (non-absolute, non-home) override path instead of probing it against the relay process CWD, mirroring the local detector's guard. Adds a regression test. - Repoint the agent-hooks.cli-presence-gating reliability gate at the split-out ssh-relay-session-agent-hook-presence.test.ts where those assertions now live.
08cf843 to
2fae001
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
config/reliability-gates.jsonc (1)
2596-2638: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMap assertionRefs for every contract claimed by the oracle.
The oracle includes config-authoritative status reads and ungated removal, but the assertion references only cover local presence, SSH ordering, and relay timeout cleanup. Add refs for the controls, CLI, IPC, and runtime tests that prove those behaviors, or remove the unreferenced claims.
Based on the reliability-gate validator contract in
config/scripts/check-reliability-gates.mjs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ba821b5b-d412-4be2-bb1a-20e2f2425d26
📒 Files selected for processing (16)
config/reliability-gates.jsoncconfig/tsconfig.cli.jsonsrc/cli/handlers/agent-hooks.test.tssrc/cli/handlers/agent-hooks.tssrc/main/agent-hooks/install-telemetry.tssrc/main/agent-hooks/local-agent-cli-presence.test.tssrc/main/agent-hooks/local-agent-cli-presence.tssrc/main/agent-hooks/managed-agent-hook-controls.test.tssrc/main/agent-hooks/managed-agent-hook-controls.tssrc/main/agent-hooks/managed-agent-hook-manifest.test.tssrc/main/agent-hooks/managed-agent-hook-manifest.tssrc/main/agent-hooks/remote-hook-service-installers.test.tssrc/main/agent-hooks/remote-managed-hook-installers.test.tssrc/main/agent-hooks/remote-managed-hook-installers.tssrc/main/index.tssrc/main/ipc/settings.ts
💤 Files with no reviewable changes (2)
- src/main/ipc/settings.ts
- src/main/index.ts
🚧 Files skipped from review as they are similar to previous changes (12)
- src/main/agent-hooks/managed-agent-hook-controls.test.ts
- config/tsconfig.cli.json
- src/main/agent-hooks/remote-managed-hook-installers.test.ts
- src/main/agent-hooks/local-agent-cli-presence.test.ts
- src/cli/handlers/agent-hooks.ts
- src/main/agent-hooks/local-agent-cli-presence.ts
- src/main/agent-hooks/remote-managed-hook-installers.ts
- src/main/agent-hooks/install-telemetry.ts
- src/main/agent-hooks/managed-agent-hook-manifest.ts
- src/main/agent-hooks/managed-agent-hook-manifest.test.ts
- src/cli/handlers/agent-hooks.test.ts
- src/main/agent-hooks/managed-agent-hook-controls.ts
…ller loop, honest Windows-remote presence - Launch-prep no longer drops #7896 approval promotion when the presence gate skips the managed install (false-'missing' PATH probe or relative command override). Promotion now runs on every Codex launch; only the managed-config write stays presence-gated. Guarded by a new predicate test. - Remove the now-dead duplicated installer loop + errorStatus from install-telemetry (production uses the CLI-safe copy in controls); keep the electron-coupled recorder there and test it directly. Add fail-open loop coverage to controls where the loop actually lives. - Relay Windows presence reports 'unknown' (honest) instead of a false 'missing'; drop the unused 'unsupported_remote_platform' skip reason.
Reconcile presence-gated Codex launch prep with main's #7969 WSL runtime-home status-hook install: - WSL runtime-home installs (installForRuntimeHome/refreshRuntimeUserHooksForRuntimeHome) run unconditionally and synchronously — never presence-gated, since the Windows-side PATH probe cannot see a codex CLI living inside the WSL distro (gating it would regress #7969). - Non-WSL launches keep the presence gate plus the always-run #7896 approval promotion from this branch's review fixes. - Keep both new tsconfig.cli entries and the added imports (getDefaultWslDistro, codexLaunchNeedsDirectApprovalPromotion).
Summary
This changes managed agent hook auto-install so Orca only mutates hook config for an agent when the matching CLI is positively present on that host, or when a configured command override resolves. Disabling hooks still removes Orca-managed hook entries even if the CLI is gone.
This does not add a manual force-install path, and config status reads remain authoritative rather than reporting a skipped install attempt as current config state.
Design Approach
The implementation adds shared managed-hook target descriptors derived from the TUI agent config, then uses a main-process manifest to derive installers, removers, status readers, and remote support. Local installs use a bounded PATH/override presence detector; SSH installs ask the relay to detect remote CLI presence before opening SFTP. Codex source-control launch prep also routes through the same single-agent presence gate so it cannot bypass startup/settings gating.
Design Review
Design review completed clean. The chosen shape is the standard pattern for this class of problem: gate the managed-config write on positive CLI presence, but keep cleanup ungated so stale Orca-managed entries stay removable even after a CLI is uninstalled. Direct config mutation (rather than a launch-time wrapper) is required because Orca's status hooks must already be present for agents launched outside Orca's own spawn path. Presence-gating the write is a deliberate improvement over prior-art managers that mutate agent config unconditionally.
Implementation
Implemented local, Settings, runtime RPC, offline CLI, Codex launch-prep, SSH, and relay presence-gated install paths. Remote hook install is best-effort after provider registration so SSH becomes usable even if relay PATH probing is slow or unavailable. One deviation from the initial design is intentional: SSH provider registration no longer waits for remote hook install because the relay login-shell PATH probe can be slow; tests verify provider registration continues and hook install remains best-effort.
Completeness Verification
Completeness verification first found the offline CLI async regression, which is fixed and covered. A later final review found Codex launch prep could still install hooks directly; that is fixed by routing through
installManagedAgentHooks(..., { agents: ['codex'] }). Final targeted verification reported no blockers.Headline Status
Implemented. Startup, Settings, runtime settings updates, offline CLI, Codex model/commit-message launch prep, and SSH remote setup now avoid installing managed hooks without positive CLI presence. Cleanup remains ungated.
App Consistency
Compared desktop startup, Settings toggle, CLI
orca agent hooks on/off/status, runtime paired-client settings update, Codex source-control generation/model discovery, web fallback/status shape, and SSH startup. The PR fixes the previous mismatch where startup/settings/SSH installed all hook configs regardless of installed CLIs, and preserves config-authoritative status reads plus ungated removal.Risks And Non-Goals
Remaining gaps: no real Windows runner evidence yet; Windows behavior is covered deterministically for PATHEXT and path parsing. Live SSH Linux behavior was validated with Docker. No visible UI behavior changed, so no screenshot evidence is included.
Tradeoffs
/hooksapprovals can never be silently swept by stale-trust cleanup. We accept a possible missed config refresh over risking approval loss.unknown, which never installs and never falsely removes — detection fails safe.Performance
Perf audit passed. Local detection scans deduped PATH entries against deduped executable candidates; Codex launch prep uses a single-agent filtered detector; SSH adds one bounded relay request and avoids SFTP when no remote CLI is found. No polling, timers, listener leaks, per-pane/session fanout, or telemetry cardinality growth were introduced.
Code Review Loop
The review loop found and fixed: offline CLI override propagation, runtime
settings.updateawaiting hook application, startup race handling when hooks are disabled during async detection, CLI typecheck coverage for new hook modules, relay login-shell timeout coverage, and the Codex direct-install sibling path. Final targeted review returned clean.Product Validation
Brennan's PR process validation result: land after fixing full lint. The full lint blocker was an unrelated exhaustive-switch default arm in
SourceControlActionRepoOverrideNote.tsx; it was removed andpnpm run lintnow passes.Live SSH validation was run against a Docker Linux SSH target through Electron. The remote had a fake
codexCLI and no other agent CLIs; backing remote state showed only Codex hook config was installed, and absent agent config dirs remained absent. Offline CLI smoke with a temp user data path and no agent CLIs returned 14/14 skipped statuses withcli_not_found, then persisted hooks disabled onagent hooks off.Checks
pnpm run typecheckpnpm run lintpnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/managed-agent-hook-manifest.test.ts src/main/agent-hooks/local-agent-cli-presence.test.ts src/main/agent-hooks/managed-agent-hook-controls.test.ts src/main/agent-hooks/install-telemetry.test.ts src/main/agent-hooks/remote-managed-hook-installers.test.ts src/main/ssh/ssh-relay-session.test.ts src/relay/agent-hook-cli-presence.test.ts src/relay/agent-hook-cli-presence-timeout.test.ts src/cli/handlers/agent-hooks.test.ts src/main/runtime/rpc/methods/client-ui.test.ts src/main/runtime/orca-runtime.test.ts src/main/text-generation/commit-message-agent-environment.test.tspnpm run check:reliability-gatespnpm build:relaygit diff --checkORCA_USER_DATA_PATHPost-PR Stabilization
Completed. I ran the required quiet wait, checked PR review comments, issue comments, reviews, and checks, then waited again while the pending
verifycheck finished. Required checks pass:verify,native-smoke (ubuntu-22.04),native-smoke (windows-latest), andtrack-community-pr; matrix packaging jobs were skipped by workflow conditions.CodeRabbit later posted five inline comments; all are replied to and resolved. Three were fixed in
08cf8433d: agents omitted from the remote presence map now reportremote_presence_unavailableinstead ofcli_not_found;installManagedHooksOnRemotere-checks cancellation after the SFTP open await before mutating remote config; and relative (non-absolute, non-home) command overrides reportunknownpresence instead of being probed against the main process CWD. Each fix has a regression test. Two were declined with rationale: the offline CLI cannot reuse the main-process telemetry recorder because the telemetry client importselectron, and the manifest invariant assertion stays CI-enforced because the manifest is static and a runtime throw would conflict with fail-open startup.Follow-up Review Fixes
An adversarial re-review landed three fixes (commit
6b2eb9cd0):unknown),install()— and with it the approval promotion — was skipped even though codex was actively launching; the disabled path still promoted, so the asymmetry was backwards. Launch-prep now always runs promotion and only presence-gates the managed-config write. Guarded bysrc/main/codex/codex-launch-hook-upkeep.test.ts.runManagedHookInstallers/errorStatusin bothinstall-telemetry(electron-coupled, no remaining production callers) and the CLI-safemanaged-agent-hook-controls. Deleted the dead copy, kept the single CLI-safe one, repointed the telemetry test atrecordManagedHookInstallFailuredirectly, and added fail-open loop coverage where the loop actually lives.unknown(not a falsemissing) on a Windows relay host, and the unusedunsupported_remote_platformskip reason was removed.Checks re-run:
pnpm run typecheck, targetedvitest(666 passing across the gate suite),pnpm run check:reliability-gates,pnpm run check:max-lines-ratchet, oxlint on changed files,git diff --check.