Repository navigation
fix(agent-hooks): install Droid & Copilot managed hooks over SSH (#7253) - #7744
Conversation
Droid and Copilot each shipped a working `installRemote` (and, for Copilot, its own remote-install test) but were never registered in `REMOTE_MANAGED_HOOK_INSTALLERS`. Over SSH, `installRemoteManagedAgentHooks` only iterates that list, so neither agent's hook config or managed script ever reached the remote host — the CLI never fired the hook and no agent status row appeared in the task tree. Claude/Hermes/Codex/Amp were registered, which is why they worked over SSH. - Add `DroidHookService.installRemote` (mirrors the grok/command-code sibling pattern; extracts `buildInstalledDroidConfig` so local and remote produce identical Factory settings.json; always emits POSIX script/paths even from a Windows host). - Register `droid` and `copilot` in `REMOTE_MANAGED_HOOK_INSTALLERS`. - Add a class-level invariant test: every locally-managed hook service that implements `installRemote` must be registered in the remote installer. This guards the whole bug class, not just these two agents. Verified end-to-end over a real Docker SSH target: the aggregate install now writes ~/.factory/settings.json + droid-hook.sh, and the managed hook POSTs to /hook/droid with the auth token and payload. Fixes #7253 Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughChangesThis change adds Copilot and Droid to the remote-managed hook installer registry, exporting a new Sequence Diagram(s)Included in hidden artifact. Related Issues: Estimated code review effort: High Suggested labels: area:agent-hooks, droid, testing Suggested reviewers: (none identified) Poem 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (3)
src/main/droid/hook-service.ts (1)
250-269: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the remote script filename to avoid literal drift.
'droid-hook.sh'is hardcoded twice: once embedded inremoteScriptPath(Line 252) and once passed directly tobuildInstalledDroidConfig(Line 265). If either literal is edited without the other,createManagedCommandMatchersilently stops matching managed entries, defeating the sweep/cleanup logic — exactly the kind of quiet drift this PR is meant to prevent.♻️ Proposed fix
async installRemote(sftp: SFTPWrapper, remoteHome: string): Promise<AgentHookInstallStatus> { const home = remoteHome.replace(/\/$/, '') const remoteConfigPath = `${home}/.factory/settings.json` - const remoteScriptPath = `${home}/.orca/agent-hooks/droid-hook.sh` + const REMOTE_SCRIPT_FILE_NAME = 'droid-hook.sh' + const remoteScriptPath = `${home}/.orca/agent-hooks/${REMOTE_SCRIPT_FILE_NAME}` try { const config = await readHooksJsonRemote(sftp, remoteConfigPath) ... - buildInstalledDroidConfig(config, wrapPosixHookCommand(remoteScriptPath), 'droid-hook.sh') + buildInstalledDroidConfig(config, wrapPosixHookCommand(remoteScriptPath), REMOTE_SCRIPT_FILE_NAME)src/main/agent-hooks/remote-hook-service-installers.test.ts (2)
661-663: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate
hooksproperty in type cast.The inline type annotation repeats the identical
hooks: Record<...>member four times. TypeScript accepts identical duplicate members silently, but this is clearly a copy-paste artifact and should be collapsed to a single declaration.🧹 Proposed fix
const config = JSON.parse(fs.files.get('/home/dev/.factory/settings.json')!) as { hooks: Record<string, { matcher?: string; hooks?: { command: string }[] }[]> - hooks: Record<string, { matcher?: string; hooks?: { command: string }[] }[]> - hooks: Record<string, { matcher?: string; hooks?: { command: string }[] }[]> - hooks: Record<string, { matcher?: string; hooks?: { command: string }[] }[]> }
646-708: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a local/remote parity test.
buildInstalledDroidConfig's own doc comment states its purpose is to keepinstall()andinstallRemote()"byte-identical" hook trees, but no test here directly asserts that parity — onlyinstallRemote()'s output is checked. A test comparinginstall()'s andinstallRemote()'s resulting hook structures (normalizing the platform-specific command string) would directly validate the PR's stated invariant and catch future divergence between the two code paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c4d7ff0b-c53b-4183-9e51-554cca06df01
📒 Files selected for processing (3)
src/main/agent-hooks/remote-hook-service-installers.test.tssrc/main/agent-hooks/remote-managed-hook-installers.tssrc/main/droid/hook-service.ts
…blyai#7253) (stablyai#7744) Co-authored-by: Orca <[email protected]>
Summary
Fixes #7253 — Codex, Amp & Droid agent status rows missing in the task tree over SSH (Claude/Hermes work).
Root cause (structural, one bug class, two agents): Agent status over SSH depends on
installRemoteManagedAgentHooksSFTP-ing each agent's hook config + managed script onto the remote host. It only iterates theREMOTE_MANAGED_HOOK_INSTALLERSregistry. Droid had noinstallRemotemethod and wasn't in the registry; Copilot shipped a fullinstallRemote(and its own remote-install test) but was also never added to the registry. So for both agents, no hook config ever reached the remote → the CLI never fired the managed hook → no status row. Claude/Hermes/Codex/Amp were registered, which is why they worked over SSH.Changes
src/main/droid/hook-service.ts— addDroidHookService.installRemote(mirrors the grok/command-code sibling pattern). ExtractbuildInstalledDroidConfigso localinstall()andinstallRemoteproduce byte-identical~/.factory/settings.jsonhook trees.getManagedScript('posix')always emits POSIX script/paths even from a Windows host; local default ('local') preserves existing Windows behavior.src/main/agent-hooks/remote-managed-hook-installers.ts— registerdroidandcopilot; exportREMOTE_MANAGED_HOOK_INSTALLER_AGENTSfor the invariant test.src/main/agent-hooks/remote-hook-service-installers.test.ts— add a class-level invariant test: every locally-managed hook service that implementsinstallRemotemust be registered in the remote installer. This guards the whole bug class, not just these two agents. Plus a Droid config-shape test, a malformed-settings.jsonsafety test, an aggregate droid+copilot install test, and Droid added to the POSIX-from-Windows loop.Testing
demo-projectcloned in): the productioninstallRemoteManagedAgentHooksinstalled hook scripts/configs for claude/codex/amp/hermes + 10 others but wrote nothing for droid — no~/.factory/settings.json, nodroid-hook.sh./hook/droidwith the auth token and URL-encoded payload — confirming the only gap was the missing install.~/.factory/settings.json(all 8 events,if [ -x ]guard,timeout: 10) plus an executabledroid-hook.sh.expected [ 'copilot' ] to deeply equal [].pnpm tsgo(node project) +oxlintclean; 62 tests pass across the touched suites.Cross-platform / scope notes
installManagedHooksOnRemote). Local Windows/macOS/Linux behavior is unchanged.🤖 Generated with Claude Code
Made with Orca 🐋