Skip to content

refactor(hooks,relay): split agent hook services and relay under the max-lines budget - #14725

Merged
nwparker merged 1 commit into
mainfrom
nwparker/downsize-06-hook-services
Aug 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/downsize-06-hook-services

Conversation

@nwparker

@nwparker nwparker commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 41 +634 −89 +545
Prod 37 +2554 −2322 +232

What

Splits the four agent hook services, the main hooks module, and the two relay modules into focused modules; removes their eslint-disable max-lines suppressions; prunes the seven corresponding ratchet-baseline entries (341 → 334).

No behavior change.

Why

Each file carried a file-level max-lines suppression and ran 365–628 counted lines against a 300-line budget. Per AGENTS.md → "Do Not Disable Max Lines", the fix is to split, not suppress; config/max-lines-baseline.txt is a shrink-only ratchet.

How it was split

Target Was Now Extracted
main/hooks.ts 628 236 per-concern hook modules
hermes/hook-service.ts 495 174 hermes-managed-plugin-source, hermes-config-yaml, hermes-home-filesystem
relay/agent-hook-server.ts 469 289 request routing / payload handling
antigravity/hook-service.ts 403 221 hook-events, hook-script, hooks-json-bundle
amp/hook-service.ts 368 114 agent-status-plugin-source, managed-plugin-install-status
copilot/hook-service.ts 365 201 copilot-managed-script, copilot-managed-hook-definitions, copilot-remote-hook-install
relay/fs-handler.ts 365 217 per-operation fs modules

The per-agent integrations stay independent. copilot, amp, antigravity and hermes each keep their own getManagedScript, and each folder keeps its own one-line isRecord guard. These collide by name only — each emits a different script body for a different agent — so merging them would be a behavior change and would introduce cross-agent coupling the original code does not have.

For antigravity, the removed suppression's stated rationale (local install, Windows wrapper generation, status cleanup, and SSH remote install must share one event list and managed-command matcher so stale-hook cleanup cannot drift by platform) is now enforced structurally instead of by co-location: both install and installRemote call buildInstalledConfig + createAntigravityManagedCommandMatcher over the single ANTIGRAVITY_EVENTS catalog, with the module graph a strict DAG.

Similarly for amp, AMP_PLUGIN_MARKER stays a single exported constant imported by both the emitter and isManagedPlugin, so install and detect cannot diverge.

No barrel exports; every new module owns real logic and importers point at the owner.

Verification

  • npx oxlint (whole repo) — clean
  • pnpm check:max-lines-ratchet — passes; baseline 341 → 334
  • pnpm typecheck (node + cli + web) — clean
  • pnpm test — full suite green; remaining failures are pre-existing load-induced timeouts in files this branch does not touch, each verified passing when re-run serially
  • No new runtime import cycles (type-only edges excluded — erased at compile time)
  • No eslint/oxlint-disable directive added anywhere, confirmed by diff grep

A CLI-build break the test suite could not catch

The full 4906-file unit suite passed 100% green on the first pass, while pnpm typecheck failed with six TS6307 errors. config/tsconfig.cli.json uses a curated include list rather than a glob, so any module extracted from a CLI-visible file must be registered there explicitly. Without it the CLI build breaks while every test still passes.

This PR adds the six missing antigravity/ and copilot/ entries in alphabetical position. Worth knowing for any future split in this area.

Pre-existing issues found and deliberately NOT changed

  • copilot/hook-service.ts: definitionsChanged compares elements by reference identity (definition !== before[index]), so remove() depends on removeManagedCommands returning identical object references for untouched entries. If that helper ever starts cloning, remove() would rewrite hooks/orca.json on every call.
  • antigravity/hooks-json-bundle.ts: detection asymmetry — hasManagedCommand (used by getStatus) inspects only definition.command and definition.hooks[].command, while bundleHasStaleManagedCommand also inspects definition.bash and definition.powershell. A managed command written into a bash/powershell field is counted stale but never counted present, pinning getStatus at partial.
  • antigravity/hooks-json-bundle.ts: buildInstalledConfig prunes managed commands across the whole bundle and then again per event — idempotent, so harmless, but dead work.
  • amp/hook-service.ts: remove() calls unlinkSync unguarded on a managed file, so a concurrent delete would throw out of remove.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 298aadfa-060a-4f98-a93b-34c3f54c33a2

📥 Commits

Reviewing files that changed from the base of the PR and between 9ca84a6f9bec0a9f64cc31e8b1cf6129cef3e7cc and 2e91b9d.

📒 Files selected for processing (12)
  • config/max-lines-baseline.txt
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-detected-scan-cache.test.ts
  • src/main/ipc/worktrees-forget-local.test.ts
  • src/main/ipc/worktrees-local-create-flow.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/fit-override-integration.test.ts
  • src/main/runtime/mobile-presence-lock.test.ts
  • src/main/runtime/mobile-subscribe-integration.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-desktop-driver.test.ts
💤 Files with no reviewable changes (1)
  • config/max-lines-baseline.txt
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/main/ipc/worktrees.ts
  • src/main/runtime/mobile-subscribe-integration.test.ts
  • src/main/ipc/worktrees-forget-local.test.ts
  • src/main/runtime/fit-override-integration.test.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/runtime/remote-desktop-driver.test.ts
  • src/main/ipc/worktrees-detected-scan-cache.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/mobile-presence-lock.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The change extracts hook, runner, configuration, plugin, relay, and filesystem logic into dedicated modules. It adds AMP, Antigravity, Copilot, and Hermes integrations with platform-specific scripts and installation handling. It adds effective hook policies, runtime targeting, issue-command overrides, and worktree runner creation. Relay event processing now uses shared envelopes and retry scheduling. Relay filesystem operations use dedicated metadata, mutation, and fallback modules. Tests and TypeScript project configuration were updated.

Merge Risk: 🟠 High · up to 2e91b

This refactor leaves unresolved risks in hook installation and relay file handling: existing user plugin artifacts may be overwritten, and a stalled git process may block file-listing requests indefinitely. Additional integration concerns could misreport installation status or break WSL/runtime behavior, so the PR is not ready to merge without owner review and fixes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the refactor and verification, but it omits required template sections such as the linked issue, visual proof, review, checklist, and author details. Add the missing required sections, including a linked issue, visual-proof statement, testing checklist, review checklist, and author information.
Docstring Coverage ⚠️ Warning Docstring coverage is 5.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main refactor: splitting hook and relay services to meet the max-lines budget.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/main/amp/managed-plugin-install-status.ts (1)

27-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive the completeness markers from the generated source module.

isCompleteManagedPlugin matches literal text that getAmpPluginSource emits, including the single-quote style in amp.on('session.start'. The two modules are now separate files, so an edit to the generated source can break detection silently. The result is a partial status with the detail "Managed Amp plugin is missing required handlers" even though the plugin is correct.

Export the required markers from agent-status-plugin-source.ts and consume them here. A test that asserts isCompleteManagedPlugin(getAmpPluginSource()) also closes the gap.

♻️ Proposed refactor

In src/main/amp/agent-status-plugin-source.ts:

+export const AMP_PLUGIN_REQUIRED_MARKERS = [
+  '/hook/amp',
+  "amp.on('session.start'",
+  "amp.on('agent.start'",
+  "amp.on('tool.call'",
+  "amp.on('tool.result'",
+  "amp.on('agent.end'"
+] as const

In src/main/amp/managed-plugin-install-status.ts:

-import { AMP_PLUGIN_FILE, AMP_PLUGIN_MARKER } from './agent-status-plugin-source'
+import {
+  AMP_PLUGIN_FILE,
+  AMP_PLUGIN_MARKER,
+  AMP_PLUGIN_REQUIRED_MARKERS
+} from './agent-status-plugin-source'
@@
 function isCompleteManagedPlugin(content: string): boolean {
-  return (
-    isManagedPlugin(content) &&
-    content.includes('/hook/amp') &&
-    content.includes("amp.on('session.start'") &&
-    content.includes("amp.on('agent.start'") &&
-    content.includes("amp.on('tool.call'") &&
-    content.includes("amp.on('tool.result'") &&
-    content.includes("amp.on('agent.end'")
-  )
+  return (
+    isManagedPlugin(content) &&
+    AMP_PLUGIN_REQUIRED_MARKERS.every((marker) => content.includes(marker))
+  )
 }
src/relay/fs-path-mutation-requests.ts (1)

42-47: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer a static node:path import.

dirname is required on every call, so the dynamic import adds no deferral benefit. Relay code is bundled separately for remote deploy, so a static import of a built-in keeps resolution predictable in the bundle.

Based on learnings, src/relay is bundled separately for remote deploy, so relay modules should keep their dependencies resolvable at bundle time.

♻️ Proposed refactor
 import { writeFile, stat, lstat, mkdir, rename, cp, rm } from 'node:fs/promises'
+import { dirname } from 'node:path'
 import { expandTilde } from './context'
 export async function createRelayFile(params: Record<string, unknown>) {
   const filePath = expandTilde(params.filePath as string)
-  const { dirname } = await import('node:path')
   await mkdir(dirname(filePath), { recursive: true })
   await writeFile(filePath, '', { encoding: 'utf-8', flag: 'wx' })
 }

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 29e8da77-1e2e-4a4f-83bb-e44d60a7ff16

📥 Commits

Reviewing files that changed from the base of the PR and between 5464525 and 16fcabe.

📒 Files selected for processing (48)
  • config/max-lines-baseline.txt
  • config/tsconfig.cli.json
  • src/main/amp/agent-status-plugin-source.ts
  • src/main/amp/hook-service.ts
  • src/main/amp/managed-plugin-install-status.ts
  • src/main/antigravity/hook-events.ts
  • src/main/antigravity/hook-script.ts
  • src/main/antigravity/hook-service.ts
  • src/main/antigravity/hooks-json-bundle.ts
  • src/main/copilot/copilot-managed-hook-definitions.ts
  • src/main/copilot/copilot-managed-script.ts
  • src/main/copilot/copilot-remote-hook-install.ts
  • src/main/copilot/hook-service.ts
  • src/main/effective-hook-config.ts
  • src/main/global-fetch-call-site-audit.test.ts
  • src/main/hermes/hermes-config-yaml.ts
  • src/main/hermes/hermes-home-filesystem.ts
  • src/main/hermes/hermes-managed-plugin-source.ts
  • src/main/hermes/hook-service.ts
  • src/main/hook-runtime-target.ts
  • src/main/hooks-runner.test.ts
  • src/main/hooks.test.ts
  • src/main/hooks.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/issue-command-file.ts
  • src/main/runtime/fit-override-integration.test.ts
  • src/main/runtime/mobile-presence-lock.test.ts
  • src/main/runtime/mobile-subscribe-integration.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-desktop-driver.test.ts
  • src/main/setup-hook-env-vars.ts
  • src/main/setup-runner-script-text.ts
  • src/main/worktree-runner-script.ts
  • src/relay/agent-hook-endpoint-coordinates.ts
  • src/relay/agent-hook-envelope-build.ts
  • src/relay/agent-hook-result-retry-scheduler.ts
  • src/relay/agent-hook-server.test.ts
  • src/relay/agent-hook-server.ts
  • src/relay/fs-handler-ripgrep-fallback.test.ts
  • src/relay/fs-handler.ts
  • src/relay/fs-list-files-fallback-chain.ts
  • src/relay/fs-path-metadata-requests.ts
  • src/relay/fs-path-mutation-requests.ts
  • src/relay/relay.ts
💤 Files with no reviewable changes (1)
  • config/max-lines-baseline.txt

Comment on lines +111 to +114
export function writePluginFiles(pluginDir = getPluginDir()): void {
mkdirSync(pluginDir, { recursive: true })
writeFileSync(getManifestPath(pluginDir), getPluginManifest(), 'utf-8')
writeFileSync(getInitPath(pluginDir), getPluginInitSource(), 'utf-8')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not overwrite unmanaged plugin files.

writePluginFiles overwrites existing plugin.yaml and __init__.py files. getPluginFilesState already identifies unmanaged plugin files, but this write path does not use that result. Reject unmanaged or partial plugin directories before writing. Apply the same ownership check before the remote install path writes these files.

Proposed local guard
 export function writePluginFiles(pluginDir = getPluginDir()): void {
+  const manifestPath = getManifestPath(pluginDir)
+  const initPath = getInitPath(pluginDir)
+  if ((existsSync(manifestPath) || existsSync(initPath)) && !getPluginFilesState(pluginDir).managed) {
+    throw new Error('Refusing to overwrite unmanaged Hermes plugin files')
+  }
   mkdirSync(pluginDir, { recursive: true })
-  writeFileSync(getManifestPath(pluginDir), getPluginManifest(), 'utf-8')
-  writeFileSync(getInitPath(pluginDir), getPluginInitSource(), 'utf-8')
+  writeFileSync(manifestPath, getPluginManifest(), 'utf-8')
+  writeFileSync(initPath, getPluginInitSource(), 'utf-8')
 }

getEffectiveHooks: vi.fn().mockReturnValue(null),
runHook: vi.fn().mockResolvedValue({ success: true, output: '' })
}))
vi.mock('../worktree-runner-script', () => ({ createSetupRunnerScript: vi.fn() }))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# List worktree-runner-script exports, then compare with each runtime test mock factory.
echo "== exports =="
rg -nP '^export (function|const|type) \w+' src/main/worktree-runner-script.ts

echo "== importers under src/main/runtime =="
rg -nPU "(?s)import (type )?\{.*?\} from '\.\./worktree-runner-script'" src/main/runtime

echo "== mock factories =="
rg -nPU -A 6 "vi\.mock\('\.\./worktree-runner-script'" src/main/runtime

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -e
for f in \
  src/main/runtime/fit-override-integration.test.ts \
  src/main/runtime/mobile-presence-lock.test.ts \
  src/main/runtime/mobile-subscribe-integration.test.ts \
  src/main/runtime/orca-runtime.ts \
  src/main/worktree-runner-script.ts
do
  echo "== $f =="
  rg -n -C 3 "worktree-runner-script|createSetupRunnerScript|createIssueCommandRunnerScript|resolveSetupRunnerShell" "$f"
done

Repository: stablyai/orca

Length of output: 2934


🏁 Script executed:

#!/bin/bash
set -e
for f in \
  src/main/runtime/fit-override-integration.test.ts \
  src/main/runtime/mobile-presence-lock.test.ts \
  src/main/runtime/mobile-subscribe-integration.test.ts
do
  echo "== $f: test cases and setup-related fixtures =="
  rg -n -C 2 "describe\(|it\(|test\(|setup|createSetupRunnerScript|resolveSetupRunnerShell|createWorktree|worktree" "$f" | head -n 240
done

echo "== all runtime imports of worktree-runner-script =="
rg -n -U -P "from ['\"]\.\./worktree-runner-script['\"]" src/main/runtime --glob '*.ts' | grep -B 8 -A 2 "worktree-runner-script"

Repository: stablyai/orca

Length of output: 22392


Add resolveSetupRunnerShell to the three ../worktree-runner-script mocks.
orca-runtime.ts imports and calls this function during worktree setup. createIssueCommandRunnerScript is not imported by orca-runtime.ts and does not need to be mocked.

📍 Affects 3 files
  • src/main/runtime/fit-override-integration.test.ts#L26-L26 (this comment)
  • src/main/runtime/mobile-presence-lock.test.ts#L16-L16
  • src/main/runtime/mobile-subscribe-integration.test.ts#L26-L26

Comment on lines +133 to +147
// Why: setup script runs inside WSL bash, so translate the Windows UNC env-var paths to Linux paths.
if (wslWorktree) {
for (const key of Object.keys(envVars)) {
envVars[key] = toLinuxPath(envVars[key])
}
} else if (nativeWindowsWorktree && runnerShell.family === 'posix') {
// Why: a Git Bash runner already receives its own path as /c/..., and the shell exports HOME
// and PWD the same way, so leaving ORCA_* in C:\ form would make them the lone exception.
// Only path-valued keys convert; the workspace name and policy values are not paths.
for (const key of SETUP_RUNNER_PATH_ENV_KEYS) {
const value = envVars[key]
if (value) {
envVars[key] = nativeWindowsPathToPosixShellPath(value)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Restrict WSL conversion to path variables.

Line 135 converts every setup environment value. getSetupRunnerEnvVars also returns ORCA_WORKSPACE_NAME and the credential-guard policy. Pass only SETUP_RUNNER_PATH_ENV_KEYS to toLinuxPath.

Proposed fix
-    for (const key of Object.keys(envVars)) {
-      envVars[key] = toLinuxPath(envVars[key])
+    for (const key of SETUP_RUNNER_PATH_ENV_KEYS) {
+      const value = envVars[key]
+      if (value) {
+        envVars[key] = toLinuxPath(value)
+      }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Why: setup script runs inside WSL bash, so translate the Windows UNC env-var paths to Linux paths.
if (wslWorktree) {
for (const key of Object.keys(envVars)) {
envVars[key] = toLinuxPath(envVars[key])
}
} else if (nativeWindowsWorktree && runnerShell.family === 'posix') {
// Why: a Git Bash runner already receives its own path as /c/..., and the shell exports HOME
// and PWD the same way, so leaving ORCA_* in C:\ form would make them the lone exception.
// Only path-valued keys convert; the workspace name and policy values are not paths.
for (const key of SETUP_RUNNER_PATH_ENV_KEYS) {
const value = envVars[key]
if (value) {
envVars[key] = nativeWindowsPathToPosixShellPath(value)
}
}
// Why: setup script runs inside WSL bash, so translate the Windows UNC env-var paths to Linux paths.
if (wslWorktree) {
for (const key of SETUP_RUNNER_PATH_ENV_KEYS) {
const value = envVars[key]
if (value) {
envVars[key] = toLinuxPath(value)
}
}
} else if (nativeWindowsWorktree && runnerShell.family === 'posix') {
// Why: a Git Bash runner already receives its own path as /c/..., and the shell exports HOME
// and PWD the same way, so leaving ORCA_* in C:\ form would make them the lone exception.
// Only path-valued keys convert; the workspace name and policy values are not paths.
for (const key of SETUP_RUNNER_PATH_ENV_KEYS) {
const value = envVars[key]
if (value) {
envVars[key] = nativeWindowsPathToPosixShellPath(value)
}
}

@nwparker
nwparker force-pushed the nwparker/downsize-06-hook-services branch 2 times, most recently from 3bed660 to 9ca84a6 Compare August 16, 2026 00:50
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 330a515b-b8db-4c7e-a5da-49160f26ee97

📥 Commits

Reviewing files that changed from the base of the PR and between 93ab6e1 and 9ca84a6f9bec0a9f64cc31e8b1cf6129cef3e7cc.

📒 Files selected for processing (78)
  • config/max-lines-baseline.txt
  • config/tsconfig.cli.json
  • src/main/amp/agent-status-plugin-source.ts
  • src/main/amp/hook-service.ts
  • src/main/amp/managed-plugin-install-status.ts
  • src/main/antigravity/hook-events.ts
  • src/main/antigravity/hook-script.ts
  • src/main/antigravity/hook-service.ts
  • src/main/antigravity/hooks-json-bundle.ts
  • src/main/copilot/copilot-managed-hook-definitions.ts
  • src/main/copilot/copilot-managed-script.ts
  • src/main/copilot/copilot-remote-hook-install.ts
  • src/main/copilot/hook-service.ts
  • src/main/effective-hook-config.ts
  • src/main/global-fetch-call-site-audit.test.ts
  • src/main/hermes/hermes-config-yaml.ts
  • src/main/hermes/hermes-home-filesystem.ts
  • src/main/hermes/hermes-managed-plugin-source.ts
  • src/main/hermes/hook-service.ts
  • src/main/hook-runtime-target.ts
  • src/main/hooks-effective-hook-resolution.test.ts
  • src/main/hooks-issue-command.test.ts
  • src/main/hooks-runner.test.ts
  • src/main/hooks-setup-runner-script.test.ts
  • src/main/hooks.test.ts
  • src/main/hooks.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-create-metadata-persistence.test.ts
  • src/main/ipc/worktrees-delete-pty-teardown.test.ts
  • src/main/ipc/worktrees-detected-scan-cache.test.ts
  • src/main/ipc/worktrees-discovery-metadata-backfill.test.ts
  • src/main/ipc/worktrees-existing-branch-checkout.test.ts
  • src/main/ipc/worktrees-forget-local.test.ts
  • src/main/ipc/worktrees-issue-command-overrides.test.ts
  • src/main/ipc/worktrees-lineage-hydration.test.ts
  • src/main/ipc/worktrees-listing-fallback-rows.test.ts
  • src/main/ipc/worktrees-local-base-ref-resolution.test.ts
  • src/main/ipc/worktrees-local-create-flow.test.ts
  • src/main/ipc/worktrees-orphan-directory-cleanup.test.ts
  • src/main/ipc/worktrees-preserved-branch-fork-remote.test.ts
  • src/main/ipc/worktrees-removal-recovery.test.ts
  • src/main/ipc/worktrees-remove-archive-hooks.test.ts
  • src/main/ipc/worktrees-remove-host-disambiguation.test.ts
  • src/main/ipc/worktrees-remove-preflight.test.ts
  • src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts
  • src/main/ipc/worktrees-ssh-base-ref-resolution.test.ts
  • src/main/ipc/worktrees-ssh-branch-conflict-suffixing.test.ts
  • src/main/ipc/worktrees-ssh-create-base-prefetch.test.ts
  • src/main/ipc/worktrees-ssh-local-base-refresh.test.ts
  • src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts
  • src/main/ipc/worktrees-ssh-provider-authority.test.ts
  • src/main/ipc/worktrees-ssh-repo-owner-resolution.test.ts
  • src/main/ipc/worktrees-ssh-setup-launch.test.ts
  • src/main/ipc/worktrees-test-module-mocks.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/ipc/worktrees-wsl-runtime-routing.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/issue-command-file.ts
  • src/main/runtime/fit-override-integration.test.ts
  • src/main/runtime/mobile-presence-lock.test.ts
  • src/main/runtime/mobile-subscribe-integration.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-desktop-driver.test.ts
  • src/main/setup-hook-env-vars.ts
  • src/main/setup-runner-script-text.ts
  • src/main/worktree-runner-script.ts
  • src/relay/agent-hook-endpoint-coordinates.ts
  • src/relay/agent-hook-envelope-build.ts
  • src/relay/agent-hook-result-retry-scheduler.ts
  • src/relay/agent-hook-server.test.ts
  • src/relay/agent-hook-server.ts
  • src/relay/fs-handler-ripgrep-fallback.test.ts
  • src/relay/fs-handler.ts
  • src/relay/fs-list-files-fallback-chain.ts
  • src/relay/fs-path-metadata-requests.ts
  • src/relay/fs-path-mutation-requests.ts
  • src/relay/relay.ts
💤 Files with no reviewable changes (1)
  • config/max-lines-baseline.txt
🚧 Files skipped from review as they are similar to previous changes (43)
  • src/relay/relay.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/runtime/mobile-presence-lock.test.ts
  • src/main/runtime/mobile-subscribe-integration.test.ts
  • src/relay/agent-hook-server.test.ts
  • src/main/global-fetch-call-site-audit.test.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/runtime/remote-desktop-driver.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/hooks.test.ts
  • src/main/setup-hook-env-vars.ts
  • src/main/copilot/copilot-remote-hook-install.ts
  • src/main/hook-runtime-target.ts
  • src/main/antigravity/hook-events.ts
  • src/main/runtime/fit-override-integration.test.ts
  • src/relay/fs-handler.ts
  • src/relay/agent-hook-endpoint-coordinates.ts
  • src/main/hermes/hermes-home-filesystem.ts
  • src/main/copilot/hook-service.ts
  • config/tsconfig.cli.json
  • src/main/amp/managed-plugin-install-status.ts
  • src/main/antigravity/hook-script.ts
  • src/relay/fs-path-mutation-requests.ts
  • src/main/amp/hook-service.ts
  • src/relay/fs-handler-ripgrep-fallback.test.ts
  • src/relay/fs-path-metadata-requests.ts
  • src/main/worktree-runner-script.ts
  • src/relay/agent-hook-envelope-build.ts
  • src/main/effective-hook-config.ts
  • src/main/antigravity/hook-service.ts
  • src/main/hermes/hook-service.ts
  • src/relay/agent-hook-result-retry-scheduler.ts
  • src/main/setup-runner-script-text.ts
  • src/main/copilot/copilot-managed-hook-definitions.ts
  • src/main/antigravity/hooks-json-bundle.ts
  • src/main/copilot/copilot-managed-script.ts
  • src/main/hermes/hermes-managed-plugin-source.ts
  • src/main/issue-command-file.ts
  • src/relay/agent-hook-server.ts
  • src/main/hermes/hermes-config-yaml.ts
  • src/main/amp/agent-status-plugin-source.ts

Comment on lines +34 to +41
const isGitRepo = await new Promise<boolean>((resolve) => {
execFile(
'git',
['rev-parse', '--is-inside-work-tree'],
{ cwd: rootPath, env: buildRelayCommandEnv() },
(err) => resolve(!err)
)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm the execFile options contract and check for an existing probe-timeout convention in the relay bundle.
set -euo pipefail

echo '--- other execFile call sites in src/relay ---'
rg -nP -C4 '\bexecFile\s*\(' src/relay

echo '--- existing timeout constants in src/relay ---'
rg -nP 'timeout' src/relay -g '*.ts' | rg -nP 'TIMEOUT|timeout:'

echo '--- declared Node types version ---'
fd -t f 'package.json' -d 2 --exec rg -n '"`@types/node`"|"node":' {}

Repository: stablyai/orca

Length of output: 6832


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- file outline ---'
ast-grep outline src/relay/fs-list-files-fallback-chain.ts

echo '--- target implementation ---'
cat -n src/relay/fs-list-files-fallback-chain.ts

echo '--- callers and cancellation helpers ---'
rg -n -C4 'runListFilesScan|listFilesWithGit|listFilesWithReaddir|throwIfFileListingCancelled|AbortSignal' src/relay -g '*.ts'

echo '--- relevant tests ---'
rg -n -C5 'fs-list-files-fallback-chain|rev-parse|listFilesWithGit|listFilesWithReaddir|runListFilesScan' src/relay -g '*test.ts'

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- cancellation implementation ---'
cat -n src/shared/file-listing-cancellation.ts

echo '--- focused fallback-chain test section ---'
sed -n '1,180p' src/relay/fs-handler-ripgrep-fallback.test.ts

echo '--- list-files handler call site ---'
rg -n -C8 'runListFilesScan\(' src/relay -g '*.ts' -g '!*.test.ts'

echo '--- walker budget and deadline definitions ---'
rg -n -C6 'createQuickOpenReaddirBudget|deadline|timeout|AbortSignal|signal' \
  src/relay/fs-handler-git-fallback.ts \
  src/relay/fs-handler-readdir-fallback.ts \
  src/shared/quick-open-readdir-walk.ts \
  src/relay/fs-handler-list-files.ts

echo '--- execFile type declarations ---'
rg -n -C8 'function execFile|execFile\(' node_modules/@types/node/child_process.d.ts 2>/dev/null || true

Repository: stablyai/orca

Length of output: 48119


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- quick-open walker entry checks ---'
sed -n '111,180p' src/shared/quick-open-readdir-walk.ts
sed -n '1,90p' src/shared/quick-open-readdir-budget.ts

echo '--- scan coordinator cancellation behavior ---'
rg -n -C8 'class .*Scan|listFilesScans|start\(|abort\(|AbortController' src/relay -g '*scan*.ts' -g '*.ts' | head -240

echo '--- Node execFile timeout and signal behavior ---'
node - <<'JS'
const { execFile } = require('node:child_process');

function probe(options, abortDelay) {
  return new Promise((resolve) => {
    const started = Date.now();
    const controller = options.signal ? new AbortController() : null;
    const finalOptions = controller ? { ...options, signal: controller.signal } : options;
    const child = execFile(
      process.execPath,
      ['-e', 'setTimeout(() => {}, 60_000)'],
      finalOptions,
      (error) => resolve({
        elapsedMs: Date.now() - started,
        errorName: error?.name ?? null,
        killed: child.killed,
        signalCode: child.signalCode
      })
    );
    if (controller) setTimeout(() => controller.abort(), abortDelay);
  });
}

(async () => {
  console.log('timeout', await probe({ timeout: 50 }));
  console.log('abort', await probe({ signal: true }, 50));
})();
JS

Repository: stablyai/orca

Length of output: 23748


Bound and cancel the git rev-parse probe.

Pass a bounded timeout and signal to execFile. Call throwIfFileListingCancelled(signal) after the probe so AbortError cannot enter fallback logic.

🧰 Tools
🪛 ast-grep (0.45.1)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

Source: Linters/SAST tools

…max-lines budget

The four agent hook services, the main hooks module, and the two relay modules
each carried a file-level `eslint-disable max-lines` and ran 365-628 counted
lines against a 300-line budget. AGENTS.md calls for splitting rather than
suppressing, and config/max-lines-baseline.txt is a shrink-only ratchet, so this
removes all seven suppressions and prunes their entries (341 -> 334).

Pure move, no behavior change. Each hook service splits into its managed script
source, its config/bundle serialization, and its remote-install path, keeping the
per-agent integrations independent: copilot, amp, antigravity and hermes each
retain their own getManagedScript rather than sharing one, because each emits a
different script body for a different agent. Merging them by name would have
been a behavior change, not a refactor.

For antigravity the suppression's stated rationale -- that local install, Windows
wrapper generation, status cleanup, and SSH remote install must share one event
list and managed-command matcher so stale-hook cleanup cannot drift by platform
-- is now enforced structurally instead: both install paths call
buildInstalledConfig + createAntigravityManagedCommandMatcher over the single
ANTIGRAVITY_EVENTS catalog, with the graph a strict DAG.

Also registers the six new antigravity/ and copilot/ modules in
config/tsconfig.cli.json. That project uses a curated `include` list rather than
a glob, so an unlisted module fails `tsc -p config/tsconfig.tc.cli.json` with
TS6307 even though the entire unit suite passes.

Verified: oxlint clean, ratchet passes, typecheck clean, full unit suite green
(remaining failures are pre-existing load flakes in untouched files, green when
re-run serially), no new runtime import cycles, and no lint suppression added.
@nwparker
nwparker force-pushed the nwparker/downsize-06-hook-services branch from 9ca84a6 to 2e91b9d Compare August 16, 2026 01:21
@nwparker
nwparker merged commit bc28107 into main Aug 16, 2026
45 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 17, 2026
…max-lines budget (#14725)

The four agent hook services, the main hooks module, and the two relay modules
each carried a file-level `eslint-disable max-lines` and ran 365-628 counted
lines against a 300-line budget. AGENTS.md calls for splitting rather than
suppressing, and config/max-lines-baseline.txt is a shrink-only ratchet, so this
removes all seven suppressions and prunes their entries (341 -> 334).

Pure move, no behavior change. Each hook service splits into its managed script
source, its config/bundle serialization, and its remote-install path, keeping the
per-agent integrations independent: copilot, amp, antigravity and hermes each
retain their own getManagedScript rather than sharing one, because each emits a
different script body for a different agent. Merging them by name would have
been a behavior change, not a refactor.

For antigravity the suppression's stated rationale -- that local install, Windows
wrapper generation, status cleanup, and SSH remote install must share one event
list and managed-command matcher so stale-hook cleanup cannot drift by platform
-- is now enforced structurally instead: both install paths call
buildInstalledConfig + createAntigravityManagedCommandMatcher over the single
ANTIGRAVITY_EVENTS catalog, with the graph a strict DAG.

Also registers the six new antigravity/ and copilot/ modules in
config/tsconfig.cli.json. That project uses a curated `include` list rather than
a glob, so an unlisted module fails `tsc -p config/tsconfig.tc.cli.json` with
TS6307 even though the entire unit suite passes.

Verified: oxlint clean, ratchet passes, typecheck clean, full unit suite green
(remaining failures are pre-existing load flakes in untouched files, green when
re-run serially), no new runtime import cycles, and no lint suppression added.
kunsanglee added a commit to kunsanglee/orca that referenced this pull request Aug 17, 2026
One conflicting file, src/relay/agent-hook-server.ts, and the conflict is
entirely stablyai#14725's split of that file: main moved the endpoint coordinates,
the envelope builder and the assistant-message/codex retry scheduling out
into three modules, so every constant, import and method this branch had
added sat next to something that had left.

Resolved by keeping only what the merged file still reaches: the cwd
attribution imports and FOREIGN_CWD_WARN_PANE_CAP stay, the retry and
endpoint constants go with the code that moved, and the class keeps both
sides' fields.

The one resolution git could not have reached on its own is in a file it
reported as clean. This branch added `sourceCwd` to the envelope inside the
private `forwardEvent`; stablyai#14725 extracted that method into
buildRelayHookEnvelope in agent-hook-envelope-build.ts, before the field
existed, and repointed both the live and replay call sites at it. Taking
either side alone drops the field silently — the method is dead with no
callers, and the builder never carried it. `sourceCwd` now lives in the
builder, which is what both legs go through.

Verified by removing that one line again: 'forwards a parsed Claude
UserPromptSubmit POST as a normalized envelope' fails with
`expected undefined to be '/srv/app'`. relay, shared agent-hook and
main/agent-hooks suites: 197 files, 2010 passing. tsc clean on the node
project, oxlint and oxfmt clean, 85 reliability gates, ratchet at 190.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…max-lines budget (stablyai#14725)

The four agent hook services, the main hooks module, and the two relay modules
each carried a file-level `eslint-disable max-lines` and ran 365-628 counted
lines against a 300-line budget. AGENTS.md calls for splitting rather than
suppressing, and config/max-lines-baseline.txt is a shrink-only ratchet, so this
removes all seven suppressions and prunes their entries (341 -> 334).

Pure move, no behavior change. Each hook service splits into its managed script
source, its config/bundle serialization, and its remote-install path, keeping the
per-agent integrations independent: copilot, amp, antigravity and hermes each
retain their own getManagedScript rather than sharing one, because each emits a
different script body for a different agent. Merging them by name would have
been a behavior change, not a refactor.

For antigravity the suppression's stated rationale -- that local install, Windows
wrapper generation, status cleanup, and SSH remote install must share one event
list and managed-command matcher so stale-hook cleanup cannot drift by platform
-- is now enforced structurally instead: both install paths call
buildInstalledConfig + createAntigravityManagedCommandMatcher over the single
ANTIGRAVITY_EVENTS catalog, with the graph a strict DAG.

Also registers the six new antigravity/ and copilot/ modules in
config/tsconfig.cli.json. That project uses a curated `include` list rather than
a glob, so an unlisted module fails `tsc -p config/tsconfig.tc.cli.json` with
TS6307 even though the entire unit suite passes.

Verified: oxlint clean, ratchet passes, typecheck clean, full unit suite green
(remaining failures are pre-existing load flakes in untouched files, green when
re-run serially), no new runtime import cycles, and no lint suppression added.
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