Skip to content

fix(agent-hooks): recognize Orca Codex, Cursor, Copilot, and Kiro hook commands - #50185

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-managed-hook-ownership
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-managed-hook-ownership

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a regression from #49456 (2f8456fad66) where createManagedCommandMatcher failed to recognize Orca's own hook commands, causing repeated hook duplication on every reconcile pass — most visibly appending duplicate Reporting status to Orca entries to ~/.codex/hooks.json while findStaleOrcaApprovals stripped trusted_hash from all earlier copies in ~/.codex/config.toml (triggering Codex's "Hooks need review — N hooks are new or changed" prompt).

Root causes fixed

  • Codex POSIX (posix-condition-clauses.ts): POSIX_ENV_GUARD_CLAUSE only matched [ -n "${ORCA_PANE_KEY|ORCA_AGENT_PANE|HOME-}" ], rejecting [ -n "${ORCA_AGENT_HOOK_ROOT-}" ], [ -z "${ORCA_AGENT_HOOK_ROOT-}" ], and [ -n "${ORCA_AGENT_HOOK_PORT-}" ] emitted by buildCodexHookCommand.
  • Cursor POSIX (posix-condition-clauses.ts): unquoteSinglePosixToken only unescaped '\'', rejecting portable quoteStartupArg fragments ("'" and "\\") used in Cursor's /bin/sh -c '...' wrapper (which caused ~/.cursor/hooks.json to duplicate as well).
  • Codex Windows & Copilot Windows (managed-hook-command-ownership.ts): added isManagedWindowsCmdCommand for cmd.exe --% /d /v:off /c @"<script>" (Codex) and cmd.exe /d /c <script> <event> (Copilot).
  • Cursor Windows & Kiro Windows standalone (managed-hook-command-ownership.ts): accepted the UTF-8 encoding prefix in Cursor's encoded PowerShell command and the leading if defined ORCA_PANE_KEY guard in Kiro's standalone Windows command.

Performance

Improves hook reconciliation and agent hook execution performance by stopping unbounded duplication of ~/.codex/hooks.json and ~/.cursor/hooks.json entries (which otherwise grew on every reconcile pass and forced repeated file rewrites and hook spawns). The ownership check itself runs in linear time over short hook command strings during hook reconciliation only.

Verification

  • Added managed-hook-command-ownership.test.ts covering all real Orca hook builders (Codex, Cursor, Copilot, Kiro, Claude, Antigravity), real-home Codex idempotency/pruning, and negative composite-command checks.
  • Dry-ran planRealHomeCodexHookEntries and removeManagedCommands against live duplicated ~/.codex/hooks.json (34–36 entries/event → pruned to 1 Orca hook + all user hooks; pass 2 settled with changedLabels=0) and ~/.cursor/hooks.json (13–14 entries/event → all 13 Orca duplicates removed, all user hooks preserved).
  • Full hook test suites passed (22 test files, 102 tests passed), plus pnpm oxfmt, pnpm oxlint, and pnpm run typecheck:node.

@nwparker
nwparker merged commit 36dcde4 into main Nov 27, 2026
58 of 60 checks passed
@nwparker
nwparker deleted the nwparker/fix-managed-hook-ownership branch November 27, 2026 00:23
dluxhu pushed a commit to dluxhu/orca that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant