@schoolai/shipyard 3.7.0 → 3.8.0-rc.20260529.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/{auth-SS7LV5XK.js → auth-EXHO3AG5.js} +4 -4
  2. package/dist/capability-detector-worker.js +142 -0
  3. package/dist/capability-detector-worker.js.map +1 -0
  4. package/dist/{chunk-DKMDBOFU.js → chunk-2CNIEBKO.js} +21 -11
  5. package/dist/chunk-2CNIEBKO.js.map +1 -0
  6. package/dist/chunk-4T2OQAVL.js +51 -0
  7. package/dist/chunk-4T2OQAVL.js.map +1 -0
  8. package/dist/chunk-5ER6ZHA2.js +46 -0
  9. package/dist/chunk-5ER6ZHA2.js.map +1 -0
  10. package/dist/chunk-7LSEE26O.js +24227 -0
  11. package/dist/chunk-7LSEE26O.js.map +1 -0
  12. package/dist/{chunk-7AHRFPAL.js → chunk-7YOU7MBN.js} +183 -17
  13. package/dist/chunk-7YOU7MBN.js.map +1 -0
  14. package/dist/chunk-CMGJGK6R.js +382 -0
  15. package/dist/chunk-CMGJGK6R.js.map +1 -0
  16. package/dist/{chunk-VPMN47TL.js → chunk-CNR7O5YH.js} +1 -2
  17. package/dist/{chunk-2J3WSIAF.js → chunk-EF2DAODF.js} +18 -3
  18. package/dist/chunk-EF2DAODF.js.map +1 -0
  19. package/dist/chunk-HQ43PHOH.js +1203 -0
  20. package/dist/chunk-HQ43PHOH.js.map +1 -0
  21. package/dist/chunk-KITSAHTX.js +134 -0
  22. package/dist/chunk-KITSAHTX.js.map +1 -0
  23. package/dist/chunk-LESHN5J5.js +6898 -0
  24. package/dist/chunk-LESHN5J5.js.map +1 -0
  25. package/dist/{chunk-LW2MS4T5.js → chunk-LMJFHKRD.js} +15 -12
  26. package/dist/chunk-LMJFHKRD.js.map +1 -0
  27. package/dist/{chunk-SNYEQHUK.js → chunk-NACJENDW.js} +14 -21
  28. package/dist/chunk-NACJENDW.js.map +1 -0
  29. package/dist/{chunk-IISLTKYY.js → chunk-TU63KZFW.js} +2 -2
  30. package/dist/chunk-TX6DK4PK.js +186 -0
  31. package/dist/chunk-TX6DK4PK.js.map +1 -0
  32. package/dist/chunk-UQVXWOPT.js +48 -0
  33. package/dist/chunk-UQVXWOPT.js.map +1 -0
  34. package/dist/{chunk-3MNPDCO5.js → chunk-WBB4XHLH.js} +139 -140
  35. package/dist/chunk-WBB4XHLH.js.map +1 -0
  36. package/dist/chunk-X3MULCV5.js +11 -0
  37. package/dist/chunk-X3MULCV5.js.map +1 -0
  38. package/dist/chunk-YZ3Z3ZYI.js +787 -0
  39. package/dist/chunk-YZ3Z3ZYI.js.map +1 -0
  40. package/dist/{chunk-2UN5AR7V.js → chunk-ZAOPND5G.js} +2 -2
  41. package/dist/chunk-ZFKJAYAN.js +542 -0
  42. package/dist/chunk-ZFKJAYAN.js.map +1 -0
  43. package/dist/cursor-hook-shim.js +316 -0
  44. package/dist/cursor-hook-shim.js.map +1 -0
  45. package/dist/cursor-runner.js +358 -0
  46. package/dist/cursor-runner.js.map +1 -0
  47. package/dist/electron-utility.js +111 -0
  48. package/dist/electron-utility.js.map +1 -0
  49. package/dist/git-pool-V73Q53NX.js +18 -0
  50. package/dist/{git-repo-VRT57DGC.js → git-repo-TN3VZXQV.js} +9 -6
  51. package/dist/index.js +12 -12
  52. package/dist/index.js.map +1 -1
  53. package/dist/{logger-GQCSLSZH.js → logger-QHPTO22N.js} +4 -4
  54. package/dist/login-Q7SZI7JJ.js +20 -0
  55. package/dist/{logout-VUNCW5B2.js → logout-O4AVMO5S.js} +6 -6
  56. package/dist/mcp-servers-F64M5T4I.js +24 -0
  57. package/dist/{roi-Y3MX5UW4.js → roi-EYDLPOCS.js} +5 -5
  58. package/dist/rss-worker.js +159 -0
  59. package/dist/rss-worker.js.map +1 -0
  60. package/dist/{serve-O53FNK64.js → serve-6A7RJWEF.js} +89862 -102999
  61. package/dist/{serve-O53FNK64.js.map → serve-6A7RJWEF.js.map} +1 -1
  62. package/dist/skills-ZHEPSBHW.js +11 -0
  63. package/dist/{start-IDFDHRD6.js → start-YGYYIK53.js} +229 -27
  64. package/dist/start-YGYYIK53.js.map +1 -0
  65. package/dist/vault-crypto-BKDOA65F.js +13 -0
  66. package/dist/vault-crypto-BKDOA65F.js.map +1 -0
  67. package/dist/worker.js +6 -3
  68. package/dist/worker.js.map +1 -1
  69. package/package.json +17 -10
  70. package/dist/chunk-2J3WSIAF.js.map +0 -1
  71. package/dist/chunk-3MNPDCO5.js.map +0 -1
  72. package/dist/chunk-66OBOZ3X.js +0 -79
  73. package/dist/chunk-66OBOZ3X.js.map +0 -1
  74. package/dist/chunk-7AHRFPAL.js.map +0 -1
  75. package/dist/chunk-DKMDBOFU.js.map +0 -1
  76. package/dist/chunk-L2WQMPWS.js +0 -666
  77. package/dist/chunk-L2WQMPWS.js.map +0 -1
  78. package/dist/chunk-LW2MS4T5.js.map +0 -1
  79. package/dist/chunk-PI77CUEP.js +0 -49
  80. package/dist/chunk-PI77CUEP.js.map +0 -1
  81. package/dist/chunk-RXI4637N.js +0 -395
  82. package/dist/chunk-RXI4637N.js.map +0 -1
  83. package/dist/chunk-SNYEQHUK.js.map +0 -1
  84. package/dist/chunk-VBPHGPBR.js +0 -126
  85. package/dist/chunk-VBPHGPBR.js.map +0 -1
  86. package/dist/index.d.ts +0 -2
  87. package/dist/login-L4BBPUYO.js +0 -20
  88. package/dist/mcp-servers-MXS5VAWI.js +0 -18
  89. package/dist/shell-V36EX2IJ.js +0 -27
  90. package/dist/skills-GPGRNV4R.js +0 -9
  91. package/dist/start-IDFDHRD6.js.map +0 -1
  92. package/dist/worker.d.ts +0 -49
  93. /package/dist/{auth-SS7LV5XK.js.map → auth-EXHO3AG5.js.map} +0 -0
  94. /package/dist/{chunk-VPMN47TL.js.map → chunk-CNR7O5YH.js.map} +0 -0
  95. /package/dist/{chunk-IISLTKYY.js.map → chunk-TU63KZFW.js.map} +0 -0
  96. /package/dist/{chunk-2UN5AR7V.js.map → chunk-ZAOPND5G.js.map} +0 -0
  97. /package/dist/{git-repo-VRT57DGC.js.map → git-pool-V73Q53NX.js.map} +0 -0
  98. /package/dist/{logger-GQCSLSZH.js.map → git-repo-TN3VZXQV.js.map} +0 -0
  99. /package/dist/{login-L4BBPUYO.js.map → logger-QHPTO22N.js.map} +0 -0
  100. /package/dist/{mcp-servers-MXS5VAWI.js.map → login-Q7SZI7JJ.js.map} +0 -0
  101. /package/dist/{logout-VUNCW5B2.js.map → logout-O4AVMO5S.js.map} +0 -0
  102. /package/dist/{shell-V36EX2IJ.js.map → mcp-servers-F64M5T4I.js.map} +0 -0
  103. /package/dist/{roi-Y3MX5UW4.js.map → roi-EYDLPOCS.js.map} +0 -0
  104. /package/dist/{skills-GPGRNV4R.js.map → skills-ZHEPSBHW.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/services/metrics/metrics-collector.ts","../src/shared/file-watcher-guard.ts","../src/services/watcher-worker/worker-supervisor.ts"],"sourcesContent":["import type { MetricsIngestRequest } from '@shipyard/session';\n\n/**\n * Known event types emitted by the daemon. Documented in one place so the\n * grep target is unambiguous when wiring a new emitter or chasing a metric.\n *\n * - `daemon_catastrophic_restart` — boot detected a prior abnormal exit via\n * the heartbeat file (native crash, SIGABRT, SIGKILL).\n * - `file_watcher_circuit_open` — file-watcher-guard tripped its breaker for\n * a path after repeated subscribe failures.\n * - `file_watcher_evicted` — guard evicted a `lazy` watcher to make room.\n * - `file_watcher_essential_evicted` — guard evicted an `essential` watcher\n * (should not happen in practice; warning telemetry).\n * - `file_watcher_subscribe_failed` — single subscribe attempt failed.\n * - `file_watcher_active_count` — periodic gauge of active watchers.\n * - `file_watcher_budget_exceeded` — guard rejected a subscribe because the\n * FSEvents budget would be overrun.\n * - `watcher_worker_started` — worker-supervisor forked the initial watcher\n * subprocess.\n * - `watcher_worker_died` — watcher subprocess exited abnormally\n * (SIGABRT/SIGSEGV/SIGBUS or non-zero code).\n * - `watcher_worker_respawned` — supervisor successfully re-forked the\n * subprocess and replayed its subscription map.\n * - `watcher_worker_circuit_open` — too many subprocess deaths in the\n * circuit window; supervisor opens cooldown before next probe.\n * - `watcher_worker_circuit_closed` — half-open probe succeeded (or a\n * normal subscribe_success closed an open cooldown); cooldown is reset.\n * - `daemon_supervisor_respawned` — outer CLI supervisor re-forked the\n * daemon child after an abnormal exit.\n * - `daemon_supervisor_circuit_open` — outer CLI supervisor gave up after\n * crash-loop and is exiting non-zero.\n *\n * The wire format treats `eventType` as an opaque string — this list exists\n * to give type-aware editors something to autocomplete and to give code\n * review a single grep target. New event types are added here.\n */\nexport type DaemonMetricsEvent =\n | 'daemon_catastrophic_restart'\n | 'file_watcher_circuit_open'\n | 'file_watcher_evicted'\n | 'file_watcher_essential_evicted'\n | 'file_watcher_subscribe_failed'\n | 'file_watcher_active_count'\n | 'file_watcher_budget_exceeded'\n | 'watcher_worker_started'\n | 'watcher_worker_died'\n | 'watcher_worker_respawned'\n | 'watcher_worker_circuit_open'\n | 'watcher_worker_circuit_closed'\n | 'daemon_supervisor_respawned'\n | 'daemon_supervisor_circuit_open';\n\nexport interface MetricsCapture {\n capture(eventType: DaemonMetricsEvent | string, properties?: Record<string, unknown>): void;\n dispose(): void;\n}\n\nexport const NOOP_METRICS: MetricsCapture = {\n capture() {},\n dispose() {},\n};\n\ninterface MetricsCollectorOpts {\n flushIntervalMs?: number;\n maxBatchSize?: number;\n}\n\ninterface BufferedEvent {\n eventType: string;\n taskId?: string;\n payload: Record<string, unknown>;\n clientTimestamp: number;\n}\n\nexport class MetricsCollector {\n readonly #workerUrl: string;\n readonly #authToken: string;\n readonly #maxBatchSize: number;\n #buffer: BufferedEvent[] = [];\n #timer: ReturnType<typeof setInterval> | null = null;\n #disposed = false;\n\n constructor(workerUrl: string, authToken: string, opts?: MetricsCollectorOpts) {\n this.#workerUrl = workerUrl.replace(/\\/$/, '');\n this.#authToken = authToken;\n this.#maxBatchSize = opts?.maxBatchSize ?? 50;\n\n const intervalMs = opts?.flushIntervalMs ?? 30_000;\n this.#timer = setInterval(() => {\n this.flush();\n }, intervalMs);\n this.#timer.unref();\n }\n\n capture(eventType: string, properties?: Record<string, unknown>): void {\n if (this.#disposed) return;\n\n const taskId = typeof properties?.taskId === 'string' ? properties.taskId : undefined;\n\n this.#buffer.push({\n eventType,\n taskId,\n payload: properties ?? {},\n clientTimestamp: Date.now(),\n });\n\n if (this.#buffer.length >= this.#maxBatchSize) {\n this.flush();\n }\n }\n\n flush(): void {\n if (this.#buffer.length === 0) return;\n\n const events = this.#buffer;\n this.#buffer = [];\n\n const body: MetricsIngestRequest = { events };\n\n fetch(`${this.#workerUrl}/ingest`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.#authToken}`,\n },\n body: JSON.stringify(body),\n }).catch(() => {});\n }\n\n dispose(): void {\n this.#disposed = true;\n if (this.#timer) {\n clearInterval(this.#timer);\n this.#timer = null;\n }\n this.flush();\n }\n}\n\nexport function createMetricsCollector(\n workerUrl: string | undefined,\n authToken: string | undefined,\n telemetryEnabled: boolean\n): MetricsCapture {\n if (!telemetryEnabled || !workerUrl || !authToken) return NOOP_METRICS;\n return new MetricsCollector(workerUrl, authToken);\n}\n","import { fork as childProcessFork } from 'node:child_process';\nimport type {\n AsyncSubscription,\n Event as ParcelEvent,\n Options as ParcelOptions,\n} from '@parcel/watcher';\nimport {\n createWatcherWorkerSupervisor,\n type SupervisorMetrics,\n type WatcherWorkerEventLike,\n type WatcherWorkerSupervisor,\n} from '../services/watcher-worker/worker-supervisor.js';\nimport { assertNever } from './assert-never.js';\n\n/**\n * Re-entry safety (AGENTS.md Invariant #11): synthetic 'evicted' dispatch is\n * deferred via queueMicrotask so we never re-enter @parcel/watcher's own\n * dispatch from inside this module.\n */\n\nexport type GuardTier = 'essential' | 'lazy';\nexport type GuardReason = 'initial' | 'escalation' | 'rescan';\n\n/**\n * Wider event shape than @parcel/watcher's. The guard injects synthetic\n * 'evicted' events into a watcher's callback when LRU pressure forces eviction;\n * consumers can react by re-establishing a subscription or doing a readdir\n * catch-up on the next read.\n */\nexport type GuardedEvent = ParcelEvent | { type: 'evicted'; path: string };\n\nexport type GuardedSubscribeCallback = (err: Error | null, events: GuardedEvent[]) => unknown;\n\nexport type GuardedSubscribeOptions = ParcelOptions;\n\nexport type FileWatcherGuardLogger = (entry: { event: string; [key: string]: unknown }) => void;\n\nexport interface FileWatcherGuardDeps {\n /**\n * Underlying watcher implementation. In production this routes through the\n * watcher worker subprocess via `WatcherWorkerSupervisor.subscribe`; the\n * supervisor's synthetic 'evicted' event (fired across worker respawns) is\n * forwarded to the consumer alongside the guard's own LRU-eviction synthetic\n * events. Tests inject a direct fake.\n */\n subscribe: (\n path: string,\n fn: (err: Error | null, events: GuardedEvent[]) => unknown,\n opts?: ParcelOptions\n ) => Promise<AsyncSubscription>;\n log: FileWatcherGuardLogger;\n /** Injected for deterministic testing. */\n now: () => number;\n /** Injected so tests can drive without real timers. */\n setTimeout: (fn: () => void, ms: number) => unknown;\n /** Injected so tests can cancel scheduled timers (e.g. supervisor shutdown). */\n clearTimeout: (timer: unknown) => void;\n}\n\nconst DEFAULT_MAX_ACTIVE_WATCHERS = 450;\nconst ENV_MAX = process.env.SHIPYARD_FILE_WATCHER_MAX;\nconst PARSED_ENV_MAX = ENV_MAX ? Number.parseInt(ENV_MAX, 10) : Number.NaN;\nexport const MAX_ACTIVE_WATCHERS =\n Number.isFinite(PARSED_ENV_MAX) && PARSED_ENV_MAX > 0\n ? PARSED_ENV_MAX\n : DEFAULT_MAX_ACTIVE_WATCHERS;\n\nexport const STARTING_BACKOFF_MS_INITIAL = 250;\nexport const STARTING_BACKOFF_MS_ESCALATION = 1_000;\nexport const MAX_BACKOFF_MS = 30_000;\nexport const BACKOFF_RESET_AFTER_MS = 5 * 60_000;\n\nexport const CIRCUIT_FAILURES = 5;\nexport const CIRCUIT_WINDOW_MS = 60_000;\nexport const CIRCUIT_OPEN_MS = 5 * 60_000;\nexport const CIRCUIT_OPEN_MAX_MS = 30 * 60_000;\n\n/** Delay before the guard attempts to re-subscribe an evicted essential watcher. */\nexport const ESSENTIAL_RESUBSCRIBE_DELAY_MS = 1_000;\n\nexport interface AttemptState {\n /** Monotonic count of consecutive failures since last clean window. */\n failureCount: number;\n /** Current backoff value (next subscribe attempt waits this long). */\n backoffMs: number;\n /** Last failure timestamp, used to compute clean-window decay. */\n lastFailureAt: number;\n /** Set when circuit is open. */\n circuitOpenedAt: number | null;\n /** Cooldown duration for the currently-open circuit (doubles on re-open). */\n circuitCooldownMs: number;\n /** Most recent failure timestamps used to detect rate (5 within window). */\n recentFailures: number[];\n /** When circuit went half-open (one probe permitted). */\n halfOpenAt: number | null;\n}\n\nexport function makeInitialAttemptState(): AttemptState {\n return {\n failureCount: 0,\n backoffMs: 0,\n lastFailureAt: 0,\n circuitOpenedAt: null,\n circuitCooldownMs: CIRCUIT_OPEN_MS,\n recentFailures: [],\n halfOpenAt: null,\n };\n}\n\nfunction isCleanAttemptState(state: AttemptState): boolean {\n return (\n state.circuitOpenedAt === null &&\n state.failureCount === 0 &&\n state.backoffMs === 0 &&\n state.recentFailures.length === 0 &&\n state.halfOpenAt === null\n );\n}\n\nexport type DecisionEvent =\n | { kind: 'request_subscribe'; reason: GuardReason; activeCount: number }\n | { kind: 'subscribe_success' }\n | { kind: 'subscribe_failure' };\n\nexport type DecisionAction =\n | { kind: 'subscribe' }\n | { kind: 'evict_and_subscribe' }\n | { kind: 'wait'; ms: number }\n | { kind: 'reject_stub'; reason: 'circuit_open' }\n | { kind: 'noop' };\n\nexport interface DecisionResult {\n state: AttemptState;\n action: DecisionAction;\n /** Side-effect signals the shell should emit (logs). */\n signals: Array<\n { kind: 'circuit_opened' } | { kind: 'circuit_closed' } | { kind: 'circuit_probe' }\n >;\n}\n\n/**\n * Pure state-machine step. No I/O, deterministic — drives all retry / circuit /\n * backoff behavior. The shell interprets DecisionAction.\n */\nexport function decideAction(\n state: AttemptState,\n event: DecisionEvent,\n now: number\n): DecisionResult {\n switch (event.kind) {\n case 'request_subscribe':\n return decideRequest(state, event, now);\n case 'subscribe_success':\n return decideSuccess(state, now);\n case 'subscribe_failure':\n return decideFailure(state, now);\n default:\n return assertNever(event);\n }\n}\n\nfunction decideRequest(\n state: AttemptState,\n event: { kind: 'request_subscribe'; reason: GuardReason; activeCount: number },\n now: number\n): DecisionResult {\n /** Decay backoff after a long clean window. */\n const decayed = decayBackoff(state, now);\n\n if (decayed.circuitOpenedAt !== null) {\n const cooldownEnd = decayed.circuitOpenedAt + decayed.circuitCooldownMs;\n if (now < cooldownEnd) {\n return {\n state: decayed,\n action: { kind: 'reject_stub', reason: 'circuit_open' },\n signals: [],\n };\n }\n /** Half-open: allow ONE probe through; mark it. */\n return {\n state: { ...decayed, halfOpenAt: now },\n action:\n event.activeCount >= MAX_ACTIVE_WATCHERS\n ? { kind: 'evict_and_subscribe' }\n : { kind: 'subscribe' },\n signals: [{ kind: 'circuit_probe' }],\n };\n }\n\n /**\n * If we have an outstanding backoff window and we're inside it, tell the\n * shell to wait. The shell schedules a retry via setTimeout.\n */\n if (decayed.backoffMs > 0 && now < decayed.lastFailureAt + decayed.backoffMs) {\n const remaining = decayed.lastFailureAt + decayed.backoffMs - now;\n return { state: decayed, action: { kind: 'wait', ms: remaining }, signals: [] };\n }\n\n /**\n * No prior failure but reason='escalation' — start with a higher floor since\n * escalation is by definition retry pressure.\n */\n let nextState = decayed;\n if (decayed.backoffMs === 0 && event.reason === 'escalation') {\n nextState = { ...decayed, backoffMs: STARTING_BACKOFF_MS_ESCALATION };\n }\n\n if (event.activeCount >= MAX_ACTIVE_WATCHERS) {\n return { state: nextState, action: { kind: 'evict_and_subscribe' }, signals: [] };\n }\n return { state: nextState, action: { kind: 'subscribe' }, signals: [] };\n}\n\nfunction decideSuccess(state: AttemptState, _now: number): DecisionResult {\n const wasHalfOpen = state.halfOpenAt !== null;\n const next: AttemptState = {\n failureCount: 0,\n backoffMs: 0,\n lastFailureAt: 0,\n circuitOpenedAt: null,\n circuitCooldownMs: CIRCUIT_OPEN_MS,\n recentFailures: [],\n halfOpenAt: null,\n };\n return {\n state: next,\n action: { kind: 'noop' },\n signals: wasHalfOpen ? [{ kind: 'circuit_closed' }] : [],\n };\n}\n\nfunction decideFailure(state: AttemptState, now: number): DecisionResult {\n const recent = [...state.recentFailures.filter((t) => now - t < CIRCUIT_WINDOW_MS), now];\n const baseBackoff =\n state.backoffMs === 0\n ? STARTING_BACKOFF_MS_INITIAL\n : Math.min(state.backoffMs * 2, MAX_BACKOFF_MS);\n\n /** Already half-open and probe failed: re-open with doubled cooldown. */\n if (state.halfOpenAt !== null) {\n const nextCooldown = Math.min(state.circuitCooldownMs * 2, CIRCUIT_OPEN_MAX_MS);\n return {\n state: {\n ...state,\n failureCount: state.failureCount + 1,\n backoffMs: baseBackoff,\n lastFailureAt: now,\n recentFailures: recent,\n circuitOpenedAt: now,\n circuitCooldownMs: nextCooldown,\n halfOpenAt: null,\n },\n action: { kind: 'noop' },\n signals: [{ kind: 'circuit_opened' }],\n };\n }\n\n /** Newly opening the circuit. */\n if (recent.length >= CIRCUIT_FAILURES && state.circuitOpenedAt === null) {\n return {\n state: {\n ...state,\n failureCount: state.failureCount + 1,\n backoffMs: baseBackoff,\n lastFailureAt: now,\n recentFailures: recent,\n circuitOpenedAt: now,\n circuitCooldownMs: CIRCUIT_OPEN_MS,\n halfOpenAt: null,\n },\n action: { kind: 'noop' },\n signals: [{ kind: 'circuit_opened' }],\n };\n }\n\n return {\n state: {\n ...state,\n failureCount: state.failureCount + 1,\n backoffMs: baseBackoff,\n lastFailureAt: now,\n recentFailures: recent,\n },\n action: { kind: 'noop' },\n signals: [],\n };\n}\n\nfunction decayBackoff(state: AttemptState, now: number): AttemptState {\n if (state.lastFailureAt === 0 || state.backoffMs === 0) return state;\n const sinceLast = now - state.lastFailureAt;\n if (sinceLast >= BACKOFF_RESET_AFTER_MS) {\n return { ...state, backoffMs: 0, failureCount: 0, recentFailures: [] };\n }\n /** Halve every 60s of clean window — mirrors the documented decay. */\n const halvings = Math.floor(sinceLast / 60_000);\n if (halvings === 0) return state;\n const next = Math.max(STARTING_BACKOFF_MS_INITIAL, state.backoffMs >> halvings);\n return { ...state, backoffMs: next };\n}\n\ninterface ActiveEntry {\n path: string;\n tier: GuardTier;\n lastUsedAt: number;\n unsubscribe: () => Promise<void>;\n /** Original consumer callback so we can fire synthetic 'evicted' events. */\n consumerCallback: GuardedSubscribeCallback;\n}\n\n/**\n * A reservation reserves a slot in the budget while a `subscribe` call is\n * in flight. Without this, N concurrent subscribes when active.size == MAX-1\n * all see \"subscribe\" with no eviction and overrun the budget on resolve.\n */\ninterface Reservation {\n path: string;\n tier: GuardTier;\n reservedAt: number;\n}\n\ninterface GuardModuleState {\n active: Set<ActiveEntry>;\n reservations: Set<Reservation>;\n perPath: Map<string, AttemptState>;\n /** Cache of circuit-open log emission so we log only once per opening. */\n loggedOpenAt: Map<string, number>;\n /** Live deps; overridden in tests via _resetGuardForTesting / configureFileWatcherGuard. */\n deps: FileWatcherGuardDeps;\n /**\n * Lazily-instantiated worker supervisor — Commit 2 of the watcher-worker\n * subprocess rollout. Created on first `guardedSubscribe` call so test\n * envs that override `deps.subscribe` never instantiate it.\n */\n supervisor: WatcherWorkerSupervisor | null;\n supervisorMetrics: SupervisorMetrics | null;\n}\n\nlet moduleState: GuardModuleState = makeModuleState();\n\nfunction makeModuleState(): GuardModuleState {\n return {\n active: new Set<ActiveEntry>(),\n reservations: new Set<Reservation>(),\n perPath: new Map<string, AttemptState>(),\n loggedOpenAt: new Map<string, number>(),\n deps: defaultDeps(),\n supervisor: null,\n supervisorMetrics: null,\n };\n}\n\n/**\n * Vitest sets `process.env.VITEST === 'true'`; under that we fall back to\n * the direct `@parcel/watcher` import so existing consumer tests that mock\n * `@parcel/watcher` keep working without each test having to mock the\n * worker-supervisor module. Production code paths set neither, so the\n * supervisor routing is always live in `shipyard start`.\n *\n * WHY THIS FALLBACK STILL EXISTS (Commit 4 audit):\n * - `apps/daemon/src/services/file-watcher.test.ts` mocks `@parcel/watcher`\n * directly via `vi.mock('@parcel/watcher', ...)` and exercises the guard\n * indirectly through `FileWatcherPool`. Migrating it (and any future\n * consumer test that adopts the same pattern) to mock the worker supervisor\n * is a separate refactor — its scope is \"rewrite the FileWatcherPool test\n * harness\" which is independent of the watcher-worker subprocess rollout.\n * - `tests/integration-coverage.test.ts` keeps `file-watcher-guard.ts` in\n * the Invariant #17 allowlist for as long as this fallback exists. Once\n * `file-watcher.test.ts` switches to mocking the supervisor module, this\n * constant + `legacyDirectSubscribe` can both be removed and the allowlist\n * tightened to only `worker.ts` and its tests.\n */\nconst IN_VITEST = process.env.VITEST === 'true' || process.env.NODE_ENV === 'test';\n\nfunction defaultDeps(): FileWatcherGuardDeps {\n return {\n /**\n * Production path: route every subscribe through the watcher worker\n * supervisor (which runs `@parcel/watcher` in a subprocess). The\n * supervisor delivers `WatcherWorkerEventLike[]` whose 'evicted' variant\n * is fired during worker respawns; we widen it to `GuardedEvent[]`\n * (which already accommodates 'evicted' via the LRU eviction path).\n */\n subscribe: (path, fn, opts) => {\n if (IN_VITEST) return legacyDirectSubscribe(path, fn, opts);\n return supervisorSubscribe(path, fn, opts);\n },\n log: () => {},\n now: () => Date.now(),\n setTimeout: (fn, ms) => setTimeout(fn, ms),\n clearTimeout: (timer) => {\n /**\n * `timer` is typed `unknown` in `FileWatcherGuardDeps` so test impls\n * can use numeric handles. The Node runtime accepts both numeric IDs\n * and `Timeout` objects via the same call.\n */\n if (timer === null || timer === undefined) return;\n clearTimeout(timer as never);\n },\n };\n}\n\nconst supervisorSubscribe: FileWatcherGuardDeps['subscribe'] = async (path, fn, opts) => {\n const supervisor = ensureSupervisor();\n const handle = await supervisor.subscribe(\n path,\n (err, events) => {\n fn(err, events.map(toGuardedEvent));\n },\n toSupervisorOpts(opts)\n );\n return { unsubscribe: () => handle.unsubscribe() };\n};\n\nfunction toSupervisorOpts(opts?: ParcelOptions): {\n ignore?: string[];\n backend?: 'default' | 'brute-force' | 'watchman';\n} {\n const out: { ignore?: string[]; backend?: 'default' | 'brute-force' | 'watchman' } = {};\n if (!opts) return out;\n if (opts.ignore) out.ignore = opts.ignore;\n if (opts.backend === 'brute-force' || opts.backend === 'watchman') {\n out.backend = opts.backend;\n }\n return out;\n}\n\nfunction toGuardedEvent(e: WatcherWorkerEventLike): GuardedEvent {\n switch (e.type) {\n case 'evicted':\n return { type: 'evicted', path: e.path };\n case 'create':\n case 'update':\n case 'delete':\n return { type: e.type, path: e.path };\n default:\n return assertNever(e.type);\n }\n}\n\nfunction ensureSupervisor(): WatcherWorkerSupervisor {\n if (moduleState.supervisor) return moduleState.supervisor;\n /**\n * `workerPath` resolves to the bundled worker entry shipped alongside the\n * daemon. tsup is configured (in `apps/daemon/tsup.config.ts`) with two\n * entries that emit at the top level of `dist/`: `src/index.ts` →\n * `dist/index.js` and `src/services/watcher-worker/worker.ts` →\n * `dist/worker.js`. tsup uses the basename of each entry for the output\n * filename and does NOT preserve the source directory structure. At\n * runtime `import.meta.url` is the daemon bundle (the only place that\n * imports this module in production) so `./worker.js` resolves to its\n * sibling. Meta-test \"Daemon Fork Targets Exist\" enforces this.\n */\n const workerPath = new URL('./worker.js', import.meta.url).pathname;\n moduleState.supervisor = createWatcherWorkerSupervisor({\n fork: nodeFork,\n workerPath,\n log: (entry) => moduleState.deps.log(entry),\n metrics: moduleState.supervisorMetrics ?? undefined,\n now: () => moduleState.deps.now(),\n setTimeout: (fn, ms) => moduleState.deps.setTimeout(fn, ms),\n clearTimeout: (timer) => moduleState.deps.clearTimeout(timer),\n });\n return moduleState.supervisor;\n}\n\nconst nodeFork: Parameters<typeof createWatcherWorkerSupervisor>[0]['fork'] = (\n modulePath,\n args,\n options\n) => childProcessFork(modulePath, args, options);\n\n/** Total occupancy = active + outstanding reservations. */\nfunction occupancy(): number {\n return moduleState.active.size + moduleState.reservations.size;\n}\n\n/**\n * Production wiring: replace only the `log` callback (and not `now`/`setTimeout`/\n * `subscribe`) so structured events reach Pino + the metrics collector.\n * Idempotent: callers may invoke this multiple times; later calls win. Optionally\n * accepts a `metrics` capture so the supervisor's restart-class telemetry is\n * routed through the same collector that already receives the guard's events.\n */\nexport function configureFileWatcherGuard(deps: {\n log: FileWatcherGuardLogger;\n metrics?: SupervisorMetrics;\n}): void {\n moduleState.deps = { ...moduleState.deps, log: deps.log };\n if (deps.metrics) {\n moduleState.supervisorMetrics = deps.metrics;\n }\n}\n\n/**\n * Test-only: replace deps and reset internal state. NOT exported as part of\n * the production surface — guarded by underscore convention.\n *\n * Resets to a `subscribe` impl that dynamically imports `@parcel/watcher`\n * (the pre-Commit-2 default), so existing `vi.mock('@parcel/watcher')`\n * patterns in consumer tests continue to work without each test needing to\n * mock the worker supervisor module. Production `defaultDeps()` routes\n * through the supervisor; tests opt into that path explicitly.\n */\nexport function _resetGuardForTesting(deps?: Partial<FileWatcherGuardDeps>): void {\n moduleState = makeModuleState();\n moduleState.deps = {\n ...moduleState.deps,\n subscribe: legacyDirectSubscribe,\n };\n if (deps) moduleState.deps = { ...moduleState.deps, ...deps };\n}\n\n/**\n * Test-only fallback that calls `@parcel/watcher.subscribe` directly. Kept\n * isolated from `defaultDeps()` (which goes through the worker supervisor)\n * so we never accidentally ship the direct-import path into production.\n *\n * The guard's `subscribe` deps callback type accepts `GuardedEvent[]` (a\n * superset of `ParcelEvent[]`), so we adapt the direction by widening each\n * ParcelEvent to a GuardedEvent before forwarding — no type assertion\n * needed because every ParcelEvent is structurally a GuardedEvent.\n */\nconst legacyDirectSubscribe: FileWatcherGuardDeps['subscribe'] = async (path, fn, opts) => {\n const mod = await import('@parcel/watcher');\n return mod.subscribe(\n path,\n (err, events) => {\n const widened: GuardedEvent[] = events.map((e) => ({ type: e.type, path: e.path }));\n fn(err, widened);\n },\n opts\n );\n};\n\n/**\n * Graceful shutdown for the lazily-instantiated supervisor. No-op if the\n * supervisor was never created (test envs that override `deps.subscribe`).\n */\nexport async function shutdownFileWatcherGuard(): Promise<void> {\n const supervisor = moduleState.supervisor;\n if (!supervisor) return;\n moduleState.supervisor = null;\n await supervisor.shutdown();\n}\n\nexport function _getActiveCountForTesting(): number {\n return moduleState.active.size;\n}\n\nexport function _getPerPathSizeForTesting(): number {\n return moduleState.perPath.size;\n}\n\nexport function _getReservationCountForTesting(): number {\n return moduleState.reservations.size;\n}\n\n/**\n * Single chokepoint for every file watcher in the daemon. See AGENTS.md\n * Invariant #17 for the contract and rationale.\n */\nexport async function guardedSubscribe(\n path: string,\n callback: GuardedSubscribeCallback,\n opts: GuardedSubscribeOptions,\n tier: GuardTier,\n reason: GuardReason\n): Promise<AsyncSubscription> {\n const { deps } = moduleState;\n const now = deps.now();\n const priorState = moduleState.perPath.get(path) ?? makeInitialAttemptState();\n const decision = decideAction(\n priorState,\n { kind: 'request_subscribe', reason, activeCount: occupancy() },\n now\n );\n moduleState.perPath.set(path, decision.state);\n emitSignals(path, decision.signals);\n\n switch (decision.action.kind) {\n case 'reject_stub':\n return makeStubSubscription();\n case 'wait': {\n const waitMs = decision.action.ms;\n await new Promise<void>((resolve) => deps.setTimeout(() => resolve(), waitMs));\n return guardedSubscribe(path, callback, opts, tier, 'escalation');\n }\n case 'evict_and_subscribe':\n evictOne(path);\n return performSubscribe(path, callback, opts, tier);\n case 'subscribe':\n return performSubscribe(path, callback, opts, tier);\n case 'noop':\n /** decideRequest never returns 'noop'; satisfy exhaustiveness. */\n throw new Error('guardedSubscribe: unexpected noop on request');\n default:\n return assertNever(decision.action);\n }\n}\n\nasync function performSubscribe(\n path: string,\n consumerCallback: GuardedSubscribeCallback,\n opts: GuardedSubscribeOptions,\n tier: GuardTier\n): Promise<AsyncSubscription> {\n const { deps } = moduleState;\n let entry: ActiveEntry | null = null;\n\n /**\n * Reserve the slot synchronously (TOCTOU fix). Without this, N concurrent\n * subscribes at activeCount = MAX-1 all read \"below budget\" and skip the\n * eviction path; on resolve they all add entries and we silently overrun\n * the FSEvents stream limit.\n */\n const reservation: Reservation = { path, tier, reservedAt: deps.now() };\n moduleState.reservations.add(reservation);\n\n const wrapped = (err: Error | null, events: GuardedEvent[]) => {\n if (entry) entry.lastUsedAt = deps.now();\n consumerCallback(err, events);\n };\n\n try {\n const sub = await deps.subscribe(path, wrapped, opts);\n moduleState.reservations.delete(reservation);\n const now = deps.now();\n /** Mark success in the per-path state (closes any half-open circuit). */\n const priorState = moduleState.perPath.get(path) ?? makeInitialAttemptState();\n const successDecision = decideAction(priorState, { kind: 'subscribe_success' }, now);\n if (isCleanAttemptState(successDecision.state)) {\n moduleState.perPath.delete(path);\n } else {\n moduleState.perPath.set(path, successDecision.state);\n }\n emitSignals(path, successDecision.signals);\n\n entry = {\n path,\n tier,\n lastUsedAt: now,\n unsubscribe: () => sub.unsubscribe(),\n consumerCallback,\n };\n moduleState.active.add(entry);\n deps.log({ event: 'file_watcher_active_count', count: moduleState.active.size });\n\n /** Wrap unsubscribe so guard accounting stays consistent on consumer-driven teardown. */\n return {\n unsubscribe: async () => {\n if (entry && moduleState.active.has(entry)) {\n moduleState.active.delete(entry);\n }\n /**\n * Per-path cleanup (F6): drop the AttemptState entry when the watcher\n * unsubscribes cleanly and no failures have accumulated. Long-running\n * daemon with task churn would otherwise grow this map without bound.\n */\n const current = moduleState.perPath.get(path);\n if (current && isCleanAttemptState(current)) {\n moduleState.perPath.delete(path);\n }\n await sub.unsubscribe();\n },\n };\n } catch (err) {\n moduleState.reservations.delete(reservation);\n const now = deps.now();\n const priorState = moduleState.perPath.get(path) ?? makeInitialAttemptState();\n const failureDecision = decideAction(priorState, { kind: 'subscribe_failure' }, now);\n moduleState.perPath.set(path, failureDecision.state);\n deps.log({\n event: 'file_watcher_subscribe_failed',\n path,\n err: err instanceof Error ? err.message : String(err),\n });\n emitSignals(path, failureDecision.signals);\n\n /** If the failure tipped us into circuit-open, return a stub. Otherwise rethrow so caller can handle. */\n if (failureDecision.state.circuitOpenedAt !== null) {\n return makeStubSubscription();\n }\n throw err;\n }\n}\n\n/**\n * Pick the oldest entry in the given tier (or any tier if `tier` is null).\n * Pure: depends only on `entries`. Returns null if no candidate matches.\n */\nfunction pickOldest(entries: Iterable<ActiveEntry>, tier: 'lazy' | null): ActiveEntry | null {\n let target: ActiveEntry | null = null;\n for (const entry of entries) {\n if (tier !== null && entry.tier !== tier) continue;\n if (target === null || entry.lastUsedAt < target.lastUsedAt) target = entry;\n }\n return target;\n}\n\nfunction selectEvictionVictim(\n entries: Iterable<ActiveEntry>\n): { victim: ActiveEntry; evictingEssential: boolean } | null {\n const lazy = pickOldest(entries, 'lazy');\n if (lazy !== null) return { victim: lazy, evictingEssential: false };\n const any = pickOldest(entries, null);\n if (any !== null) return { victim: any, evictingEssential: true };\n return null;\n}\n\nfunction evictOne(incomingPath: string): void {\n const { deps } = moduleState;\n if (moduleState.active.size === 0) {\n throw new Error('file-watcher-guard: cannot evict — active set is empty (counter is broken)');\n }\n\n const selection = selectEvictionVictim(moduleState.active);\n if (selection === null) {\n throw new Error('file-watcher-guard: eviction selection failed');\n }\n const { victim, evictingEssential } = selection;\n\n moduleState.active.delete(victim);\n deps.log({\n event: evictingEssential ? 'file_watcher_essential_evicted' : 'file_watcher_evicted',\n path: victim.path,\n tier: victim.tier,\n incomingPath,\n });\n\n /**\n * Re-entry safety (Invariant #11): defer the synthetic dispatch via\n * queueMicrotask so a callback that re-enters the guard cannot do so from\n * inside the dispatching frame.\n */\n queueMicrotask(() => {\n victim.consumerCallback(null, [{ type: 'evicted', path: victim.path }]);\n });\n /** Fire-and-forget unsubscribe; we don't block the new subscribe on it. */\n victim.unsubscribe().catch((err) => {\n deps.log({\n event: 'file_watcher_unsubscribe_failed_during_eviction',\n path: victim.path,\n err: err instanceof Error ? err.message : String(err),\n });\n });\n\n /**\n * Self-healing essentials (F4): consumers of essential watchers (capability\n * watcher, plan-file-bridge, published-artifact-store) don't currently\n * re-subscribe on `evicted` — they treat the synthetic event as fatal. The\n * guard schedules a retry on their behalf so an essential watcher that lost\n * its slot to a budget squeeze comes back online once the new arrival\n * settles. Bounded by the circuit breaker — repeated failures will trip it.\n */\n if (evictingEssential) {\n scheduleEssentialResubscribe(victim);\n }\n}\n\nfunction scheduleEssentialResubscribe(victim: ActiveEntry): void {\n const { deps } = moduleState;\n deps.log({\n event: 'file_watcher_essential_re_subscribe_scheduled',\n path: victim.path,\n delayMs: ESSENTIAL_RESUBSCRIBE_DELAY_MS,\n });\n deps.setTimeout(() => {\n void retryEssentialSubscribe(victim);\n }, ESSENTIAL_RESUBSCRIBE_DELAY_MS);\n}\n\nasync function retryEssentialSubscribe(victim: ActiveEntry): Promise<void> {\n const { deps } = moduleState;\n try {\n await guardedSubscribe(victim.path, victim.consumerCallback, {}, 'essential', 'rescan');\n deps.log({ event: 'file_watcher_essential_re_subscribed', path: victim.path });\n } catch (err) {\n deps.log({\n event: 'file_watcher_essential_re_subscribe_failed',\n path: victim.path,\n err: err instanceof Error ? err.message : String(err),\n });\n }\n}\n\nfunction emitSignals(path: string, signals: DecisionResult['signals']): void {\n const { deps } = moduleState;\n for (const sig of signals) {\n switch (sig.kind) {\n case 'circuit_opened':\n deps.log({ event: 'file_watcher_circuit_open', path });\n moduleState.loggedOpenAt.set(path, deps.now());\n break;\n case 'circuit_closed':\n deps.log({ event: 'file_watcher_circuit_closed', path });\n moduleState.loggedOpenAt.delete(path);\n break;\n case 'circuit_probe':\n /** Probe attempts are attempt-level — no log to avoid spam. */\n break;\n default:\n assertNever(sig);\n }\n }\n}\n\nfunction makeStubSubscription(): AsyncSubscription {\n return { unsubscribe: async () => {} };\n}\n","import type { ChildProcess } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport { assertNever } from '../../shared/assert-never.js';\nimport {\n type AttemptState,\n decideAction,\n makeInitialAttemptState,\n} from '../../shared/file-watcher-guard.js';\nimport {\n decodeLine,\n encodeLine,\n type WorkerCommand,\n type WorkerParcelEvent,\n type WorkerReply,\n} from './worker-protocol.js';\n\n/**\n * Parent-side supervisor for the watcher worker subprocess. Owns the\n * Map<id, SubscriptionEntry> source of truth and replays it onto a fresh\n * worker after a crash, firing a synthetic 'evicted' event so consumers\n * can readdir-catch-up across the gap.\n *\n * The supervisor's restart-circuit (5 deaths in 60s -> 5min cooldown) is\n * SEPARATE from `file-watcher-guard.ts`'s per-path subscribe-failure\n * circuit. Both apply: a single bad path won't crash the worker, but a\n * worker that keeps SIGABRTing will eventually trip this layer.\n */\n\nexport interface WatcherWorkerEventLike {\n type: 'create' | 'update' | 'delete' | 'evicted';\n path: string;\n}\n\nexport type WatcherWorkerCallback = (\n err: Error | null,\n events: WatcherWorkerEventLike[]\n) => unknown;\n\nexport interface WatcherWorkerSubscribeOptions {\n ignore?: string[];\n backend?: 'default' | 'brute-force' | 'watchman';\n}\n\nexport interface WatcherWorkerSubscriptionHandle {\n unsubscribe(): Promise<void>;\n}\n\nexport interface WatcherWorkerSupervisor {\n /** Spawn the worker if not yet running. Idempotent. */\n start(): Promise<void>;\n subscribe(\n path: string,\n callback: WatcherWorkerCallback,\n opts: WatcherWorkerSubscribeOptions\n ): Promise<WatcherWorkerSubscriptionHandle>;\n /** Graceful shutdown. Sends shutdown command, escalates SIGTERM, then SIGKILL. */\n shutdown(): Promise<void>;\n}\n\nexport interface SupervisorMetrics {\n capture(eventType: string, properties: Record<string, unknown>): void;\n}\n\nexport type SupervisorLogger = (entry: { event: string; [key: string]: unknown }) => void;\n\nexport interface WatcherWorkerSupervisorDeps {\n fork: (\n modulePath: string,\n args: string[],\n options: { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }\n ) => ChildProcess;\n workerPath: string;\n log: SupervisorLogger;\n metrics?: SupervisorMetrics;\n now: () => number;\n setTimeout: (fn: () => void, ms: number) => unknown;\n clearTimeout: (timer: unknown) => void;\n}\n\n/** Empirically: SIGSEGV -> 139, SIGBUS -> 138, SIGABRT -> 134 on POSIX. */\nconst ABNORMAL_SIGNALS = new Set<NodeJS.Signals>(['SIGABRT', 'SIGSEGV', 'SIGBUS', 'SIGKILL']);\n\nconst SHUTDOWN_GRACEFUL_MS = 2_000;\nconst SHUTDOWN_SIGTERM_MS = 500;\n\ninterface SubscriptionEntry {\n id: string;\n path: string;\n opts: WatcherWorkerSubscribeOptions;\n callback: WatcherWorkerCallback;\n status: 'pending' | 'subscribed' | 'unsubscribing';\n resolveSubscribed?: (handle: WatcherWorkerSubscriptionHandle) => void;\n rejectSubscribed?: (err: Error) => void;\n resolveUnsubscribed?: () => void;\n}\n\ninterface ChildHolder {\n process: ChildProcess;\n spawnedAt: number;\n /** Captured exit listeners can match against this to drop stale events. */\n generation: number;\n exited: boolean;\n}\n\nexport function createWatcherWorkerSupervisor(\n deps: WatcherWorkerSupervisorDeps\n): WatcherWorkerSupervisor {\n const subscriptions = new Map<string, SubscriptionEntry>();\n let child: ChildHolder | null = null;\n let restartState: AttemptState = makeInitialAttemptState();\n let nextGeneration = 1;\n let shutdownInitiated = false;\n let restartTimer: unknown = null;\n /**\n * Tracks the generation of a worker that was forked as a respawn and is\n * still awaiting its first `subscribed` ack. The ack from THAT generation\n * fires decideAction({kind:'subscribe_success'}) to close the cooldown\n * circuit. A boolean would mis-attribute: if worker B (respawn) dies before\n * acking and we respawn worker C, B's stale window would reset on C's first\n * ack — but C's ack should only count for C's own respawn (which it does,\n * because we re-set this on each respawn). More importantly, when B dies\n * before acking we MUST clear the pending generation so a future ack from\n * C is judged on its own respawn fork, not on the abandoned B window.\n */\n let pendingRespawnGeneration: number | null = null;\n\n function log(entry: { event: string; [key: string]: unknown }): void {\n deps.log(entry);\n }\n\n function captureMetric(eventType: string, properties: Record<string, unknown>): void {\n deps.metrics?.capture(eventType, properties);\n }\n\n function sendCommand(holder: ChildHolder, cmd: WorkerCommand): boolean {\n const stdin = holder.process.stdin;\n if (!stdin || stdin.destroyed || holder.exited) return false;\n try {\n /**\n * Ignore the boolean return: `false` signals kernel-pipe backpressure,\n * but Node still queues the data in the user-land Writable buffer and\n * delivers it once the consumer drains. Treating backpressure as\n * failure would force unnecessary respawns under burst load. Real\n * pipe death is caught above (`stdin.destroyed`) or as an EPIPE throw.\n */\n stdin.write(`${encodeLine(cmd)}\\n`);\n return true;\n } catch (err) {\n log({\n event: 'watcher_worker_stdin_write_failed',\n err: err instanceof Error ? err.message : String(err),\n });\n return false;\n }\n }\n\n function dispatchReply(reply: WorkerReply, fromGeneration: number): void {\n switch (reply.type) {\n case 'subscribed':\n handleSubscribedReply(reply.id, fromGeneration);\n return;\n case 'subscribe_failed':\n handleSubscribeFailedReply(reply.id, reply.error);\n return;\n case 'unsubscribed':\n handleUnsubscribedReply(reply.id);\n return;\n case 'events':\n handleEventsReply(reply.id, reply.events);\n return;\n default:\n assertNever(reply);\n }\n }\n\n function handleSubscribedReply(id: string, fromGeneration: number): void {\n const entry = subscriptions.get(id);\n if (!entry) return;\n /**\n * Respawn-ack accounting (F4): the ack that closes the cooldown window\n * must come from the SAME generation we marked pending in forkAndReplay.\n * `fromGeneration` is captured in the attachChildIo closure of the holder\n * that wrote this reply — pipe drains can deliver replies from a dead\n * generation after a successor is live, and only the original generation\n * should consume its own pending-ack window.\n */\n if (pendingRespawnGeneration !== null && fromGeneration === pendingRespawnGeneration) {\n pendingRespawnGeneration = null;\n const successDecision = decideAction(restartState, { kind: 'subscribe_success' }, deps.now());\n restartState = successDecision.state;\n for (const sig of successDecision.signals) {\n if (sig.kind === 'circuit_closed') {\n log({ event: 'watcher_worker_circuit_closed' });\n }\n }\n }\n if (entry.status === 'pending' && entry.resolveSubscribed) {\n entry.status = 'subscribed';\n entry.resolveSubscribed(makeHandle(entry));\n entry.resolveSubscribed = undefined;\n entry.rejectSubscribed = undefined;\n return;\n }\n entry.status = 'subscribed';\n }\n\n function handleSubscribeFailedReply(id: string, error: string): void {\n const entry = subscriptions.get(id);\n if (!entry) return;\n subscriptions.delete(id);\n entry.rejectSubscribed?.(new Error(error));\n }\n\n function handleUnsubscribedReply(id: string): void {\n const entry = subscriptions.get(id);\n if (!entry) return;\n subscriptions.delete(id);\n entry.resolveUnsubscribed?.();\n }\n\n function handleEventsReply(id: string, events: WorkerParcelEvent[]): void {\n const entry = subscriptions.get(id);\n if (!entry || entry.status === 'unsubscribing') return;\n entry.callback(null, toCallbackEvents(events));\n }\n\n function attachChildIo(holder: ChildHolder): void {\n const proc = holder.process;\n const { stdout, stderr } = proc;\n if (!stdout) {\n log({ event: 'watcher_worker_no_stdout' });\n return;\n }\n\n /**\n * Per-holder stdout buffer. Node's 'exit' event fires before stdio\n * drain completes, so a previous worker's residual chunks can arrive\n * after this listener is installed for the successor. Scoping the\n * buffer to the holder closure keeps each generation's partial-line\n * state isolated — generation N's leftover bytes can't corrupt\n * generation N+1's decode. fromGeneration is captured for the same\n * reason: a lagged ack from holder N must be attributed to N's\n * pending-respawn window, not whichever generation is currently live.\n */\n let stdoutBuffer = '';\n const fromGeneration = holder.generation;\n stdout.setEncoding('utf8');\n stdout.on('data', (chunk: string) => {\n stdoutBuffer += chunk;\n let nl = stdoutBuffer.indexOf('\\n');\n while (nl !== -1) {\n const line = stdoutBuffer.slice(0, nl);\n stdoutBuffer = stdoutBuffer.slice(nl + 1);\n nl = stdoutBuffer.indexOf('\\n');\n if (line.length === 0) continue;\n const decoded = decodeLine(line);\n if (decoded === null) {\n log({ event: 'watcher_worker_decode_failed', line });\n continue;\n }\n if (!('type' in decoded)) {\n log({ event: 'watcher_worker_unexpected_command', cmd: decoded.cmd });\n continue;\n }\n dispatchReply(decoded, fromGeneration);\n }\n });\n\n if (stderr) {\n stderr.setEncoding('utf8');\n let stderrBuffer = '';\n stderr.on('data', (chunk: string) => {\n stderrBuffer += chunk;\n let nl = stderrBuffer.indexOf('\\n');\n while (nl !== -1) {\n const line = stderrBuffer.slice(0, nl);\n stderrBuffer = stderrBuffer.slice(nl + 1);\n nl = stderrBuffer.indexOf('\\n');\n if (line.length > 0) {\n log({ event: 'watcher_worker_stderr', line });\n }\n }\n });\n }\n\n proc.on('exit', (code, signal) => {\n handleChildExit(holder, code, signal);\n });\n proc.on('error', (err) => {\n log({ event: 'watcher_worker_error', err: err.message });\n });\n }\n\n function handleChildExit(\n holder: ChildHolder,\n code: number | null,\n signal: NodeJS.Signals | null\n ): void {\n holder.exited = true;\n if (child !== holder) return;\n child = null;\n /**\n * If this child was the respawn we were awaiting an ack for, clear the\n * pending generation so the NEXT respawn is judged on its own window\n * rather than collecting a stale subscribe_success the moment the\n * post-exit successor happens to ack first.\n */\n if (pendingRespawnGeneration === holder.generation) {\n pendingRespawnGeneration = null;\n }\n\n const replayCount = subscriptions.size;\n const uptimeMs = deps.now() - holder.spawnedAt;\n\n if (shutdownInitiated) {\n log({ event: 'watcher_worker_exited_during_shutdown', code, signal, uptimeMs });\n return;\n }\n\n const abnormal = isAbnormalExit(code, signal) || replayCount > 0;\n if (!abnormal) {\n log({ event: 'watcher_worker_exited_clean', code, signal, uptimeMs });\n return;\n }\n\n log({ event: 'watcher_worker_died', code, signal, replayCount, uptimeMs });\n captureMetric('watcher_worker_died', {\n code,\n signal,\n replayCount,\n uptimeMs,\n });\n\n recordRestartFailure(holder);\n\n /** Fire synthetic 'evicted' so consumers know there was a gap. */\n fireSyntheticEvictionToAll();\n\n /** Schedule a respawn unless the circuit is open. */\n scheduleRespawn();\n }\n\n /**\n * Reuse the guard's pure restart core: a 'subscribe_failure' event drives\n * the same backoff/circuit logic per-process. activeCount=0 because the\n * supervisor has its own slot, not a shared FSEvents budget.\n */\n function recordRestartFailure(holder: ChildHolder): void {\n const failureDecision = decideAction(restartState, { kind: 'subscribe_failure' }, deps.now());\n restartState = failureDecision.state;\n for (const sig of failureDecision.signals) {\n if (sig.kind === 'circuit_opened') {\n log({ event: 'watcher_worker_circuit_open' });\n captureMetric('watcher_worker_circuit_open', {\n deathCount: restartState.failureCount,\n windowMs: deps.now() - holder.spawnedAt,\n });\n } else if (sig.kind === 'circuit_closed') {\n log({ event: 'watcher_worker_circuit_closed' });\n }\n }\n }\n\n function dispatchSyntheticEviction(entry: SubscriptionEntry): void {\n if (!subscriptions.has(entry.id)) return;\n try {\n entry.callback(null, [{ type: 'evicted', path: entry.path }]);\n } catch (err) {\n log({\n event: 'watcher_worker_synthetic_dispatch_failed',\n id: entry.id,\n err: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n function fireSyntheticEvictionToAll(): void {\n /**\n * Re-entry safety (Invariant #11): defer dispatch to a fresh microtask\n * so a callback that re-enters supervisor.subscribe() cannot do so from\n * inside the exit-handler frame.\n */\n const snapshot = Array.from(subscriptions.values());\n queueMicrotask(() => {\n for (const entry of snapshot) {\n dispatchSyntheticEviction(entry);\n }\n });\n }\n\n function scheduleRespawn(): void {\n if (shutdownInitiated) return;\n /**\n * Idempotency: pipe-failure and on-exit can both fire scheduleRespawn\n * for the same death (pipe-failure schedules first, kill triggers\n * on-exit which schedules again). Without this guard both timers fire\n * and the second one runs forkAndReplay while a worker is already\n * alive — leaking the original process and replaying subscriptions to\n * the wrong target. The first scheduled timer is sufficient; let it\n * run with whatever restartState accumulated during the dual path.\n */\n if (restartTimer !== null) return;\n\n /**\n * Always route through `decideAction({kind:'request_subscribe'})` so the\n * pure core handles half-open transition: when the cooldown expires,\n * `decideRequest` sets `halfOpenAt = now` and returns 'subscribe'. Without\n * this, `halfOpenAt` stays null forever and `decideFailure`'s doubled-\n * cooldown defense (line 240 of file-watcher-guard.ts) never fires —\n * a SIGABRT loop churns at the base 5min cooldown instead of backing\n * off toward the 30min cap.\n */\n const requestDecision = decideAction(\n restartState,\n { kind: 'request_subscribe', reason: 'rescan', activeCount: 0 },\n deps.now()\n );\n restartState = requestDecision.state;\n\n switch (requestDecision.action.kind) {\n case 'reject_stub': {\n /**\n * Circuit open and cooldown not yet expired. Schedule a wake-up\n * at the cooldown boundary; on wake, scheduleRespawn re-runs and\n * `decideRequest` will then transition to half-open.\n */\n const openedAt = restartState.circuitOpenedAt;\n if (openedAt === null) {\n /** Defensive: should never happen with reject_stub. */\n attemptRespawn();\n return;\n }\n const cooldownEnd = openedAt + restartState.circuitCooldownMs;\n const waitMs = Math.max(0, cooldownEnd - deps.now());\n restartTimer = deps.setTimeout(() => {\n restartTimer = null;\n scheduleRespawn();\n }, waitMs);\n return;\n }\n case 'wait': {\n restartTimer = deps.setTimeout(() => {\n restartTimer = null;\n attemptRespawn();\n }, requestDecision.action.ms);\n return;\n }\n case 'subscribe':\n case 'evict_and_subscribe':\n /** evict_and_subscribe never fires here — activeCount is always 0. */\n attemptRespawn();\n return;\n case 'noop':\n /** decideRequest never returns 'noop'; defensive. */\n attemptRespawn();\n return;\n default:\n assertNever(requestDecision.action);\n }\n }\n\n function attemptRespawn(): void {\n if (shutdownInitiated) return;\n if (restartState.circuitOpenedAt !== null) {\n /**\n * Half-open probe: the pure core flagged this attempt by setting\n * halfOpenAt; if the new worker dies, the circuit re-opens with\n * doubled cooldown.\n */\n log({ event: 'watcher_worker_probe_attempt' });\n }\n try {\n forkAndReplay();\n } catch (err) {\n log({\n event: 'watcher_worker_fork_failed',\n err: err instanceof Error ? err.message : String(err),\n });\n /** Treat fork-time failure same as runtime crash. */\n const failureDecision = decideAction(restartState, { kind: 'subscribe_failure' }, deps.now());\n restartState = failureDecision.state;\n scheduleRespawn();\n }\n }\n\n /**\n * Replay outcome: either we sent every entry (`completed`) or `sendCommand`\n * returned false partway through (`pipe_failed`). The latter means the\n * fresh worker's pipe is already dead; we abandon this generation and\n * trigger another respawn so the next fresh worker gets a clean replay\n * (F2). Without this, entries N+1..M would stay in the map with their\n * original resolve/reject closures and never receive an ack — their\n * `subscribe()` callers would hang forever.\n */\n type ReplayResult =\n | { kind: 'completed'; replayedCount: number }\n | { kind: 'pipe_failed'; replayedCount: number };\n\n function forkAndReplay(): void {\n const isRespawn = nextGeneration > 1;\n const replayStart = deps.now();\n const holder = spawnChildHolder();\n if (isRespawn && subscriptions.size > 0) {\n pendingRespawnGeneration = holder.generation;\n }\n\n const replayResult = replaySubscriptions(holder);\n\n if (replayResult.kind === 'pipe_failed') {\n handleReplayPipeFailure(holder, replayResult.replayedCount);\n return;\n }\n if (replayResult.replayedCount > 0) {\n log({ event: 'watcher_worker_replayed', replayCount: replayResult.replayedCount });\n }\n if (isRespawn) {\n recordRespawnTelemetry(holder, replayResult.replayedCount, deps.now() - replayStart);\n }\n }\n\n function spawnChildHolder(): ChildHolder {\n const proc = deps.fork(deps.workerPath, [], {\n stdio: ['pipe', 'pipe', 'pipe', 'ipc'],\n });\n const holder: ChildHolder = {\n process: proc,\n spawnedAt: deps.now(),\n generation: nextGeneration++,\n exited: false,\n };\n child = holder;\n log({ event: 'watcher_worker_started', pid: proc.pid ?? null });\n captureMetric('watcher_worker_started', { pid: proc.pid ?? null });\n attachChildIo(holder);\n return holder;\n }\n\n function replaySubscriptions(holder: ChildHolder): ReplayResult {\n let replayedCount = 0;\n for (const entry of subscriptions.values()) {\n /**\n * Reset to 'pending' so the new {type:'subscribed'} reply hits the\n * resolution path. In-flight subscribers from before the death keep\n * their resolve/reject closures and resolve when the new worker\n * acknowledges. New subscribers added after replay get appended.\n */\n entry.status = 'pending';\n const ok = sendCommand(holder, {\n cmd: 'subscribe',\n id: entry.id,\n path: entry.path,\n opts: entry.opts,\n });\n if (!ok) {\n return { kind: 'pipe_failed', replayedCount };\n }\n replayedCount++;\n }\n return { kind: 'completed', replayedCount };\n }\n\n function handleReplayPipeFailure(holder: ChildHolder, replayedCount: number): void {\n log({\n event: 'watcher_worker_replay_pipe_failed',\n pid: holder.process.pid ?? null,\n replayedCount,\n pendingCount: subscriptions.size - replayedCount,\n });\n /**\n * Count this as a failure for the restart-circuit. Without it, a\n * pathological environment where every fresh worker's stdin pipe is\n * dead-on-arrival would respawn forever — `failureCount` never\n * increments because the on-exit failure path requires an exit signal\n * we may not see if the worker is alive but the pipe is closed.\n * If on-exit fires later, it records a second failure for the same\n * generation; that's acceptable — failure-count is a circuit-tripping\n * heuristic, not an exact crash count.\n */\n recordRestartFailure(holder);\n /**\n * Pipe death usually means the worker has already exited or its stdin\n * was closed underneath us. The on-exit handler will fire (if it hasn't\n * already) and trigger its own respawn cycle. Schedule one explicitly\n * here too — if the worker survives but the pipe is wedged, we still\n * need to recover, and `scheduleRespawn` is idempotent under the\n * shutdown / circuit-open guards.\n */\n if (!holder.exited) {\n try {\n holder.process.kill('SIGKILL');\n } catch (err) {\n log({\n event: 'watcher_worker_kill_failed',\n signal: 'SIGKILL',\n err: err instanceof Error ? err.message : String(err),\n });\n }\n }\n scheduleRespawn();\n }\n\n function recordRespawnTelemetry(\n holder: ChildHolder,\n replayCount: number,\n replayDurationMs: number\n ): void {\n log({\n event: 'watcher_worker_respawned',\n pid: holder.process.pid ?? null,\n replayCount,\n replayDurationMs,\n });\n captureMetric('watcher_worker_respawned', {\n newPid: holder.process.pid ?? null,\n replayCount,\n replayDurationMs,\n });\n }\n\n function makeHandle(entry: SubscriptionEntry): WatcherWorkerSubscriptionHandle {\n return {\n unsubscribe: () => unsubscribeEntry(entry),\n };\n }\n\n function unsubscribeEntry(entry: SubscriptionEntry): Promise<void> {\n if (!subscriptions.has(entry.id)) return Promise.resolve();\n entry.status = 'unsubscribing';\n if (!child) {\n /** No worker -> just drop the entry; the next worker won't replay it. */\n subscriptions.delete(entry.id);\n return Promise.resolve();\n }\n return new Promise<void>((resolve) => {\n entry.resolveUnsubscribed = resolve;\n const sent = child !== null && sendCommand(child, { cmd: 'unsubscribe', id: entry.id });\n if (!sent) {\n /** Pipe gone — drop the entry so we don't leak. */\n subscriptions.delete(entry.id);\n resolve();\n }\n });\n }\n\n function makeStubHandle(): WatcherWorkerSubscriptionHandle {\n return { unsubscribe: async () => {} };\n }\n\n async function start(): Promise<void> {\n if (child !== null) return;\n if (shutdownInitiated) {\n throw new Error('WatcherWorkerSupervisor: cannot start after shutdown');\n }\n forkAndReplay();\n }\n\n async function subscribe(\n path: string,\n callback: WatcherWorkerCallback,\n opts: WatcherWorkerSubscribeOptions\n ): Promise<WatcherWorkerSubscriptionHandle> {\n if (shutdownInitiated) {\n throw new Error('WatcherWorkerSupervisor: cannot subscribe after shutdown');\n }\n /**\n * Honor the supervisor's own circuit. Stub subscriptions still occupy a\n * slot in the map only briefly — we don't add to subscriptions on the\n * stub path, so a future probe doesn't try to replay them.\n */\n if (restartState.circuitOpenedAt !== null) {\n const cooldownEnd = restartState.circuitOpenedAt + restartState.circuitCooldownMs;\n if (deps.now() < cooldownEnd) {\n log({ event: 'watcher_worker_subscribe_stubbed', path });\n return makeStubHandle();\n }\n }\n\n const id = randomUUID();\n const entry: SubscriptionEntry = {\n id,\n path,\n opts,\n callback,\n status: 'pending',\n };\n const promise = new Promise<WatcherWorkerSubscriptionHandle>((resolve, reject) => {\n entry.resolveSubscribed = resolve;\n entry.rejectSubscribed = reject;\n });\n subscriptions.set(id, entry);\n\n if (child === null) {\n /** First subscribe: forkAndReplay sends the subscribe as part of replay. */\n await start();\n } else {\n sendCommand(child, { cmd: 'subscribe', id, path, opts });\n }\n /**\n * If the worker died while this command was buffered, the exit handler\n * will replay this entry to the next worker; the original promise stays\n * pending until the replay's 'subscribed' arrives.\n */\n return promise;\n }\n\n async function shutdown(): Promise<void> {\n if (shutdownInitiated) return;\n shutdownInitiated = true;\n if (restartTimer !== null) {\n deps.clearTimeout(restartTimer);\n restartTimer = null;\n }\n\n /**\n * Reject in-flight subscribes AND resolve pending unsubscribes (F5).\n * A consumer awaiting `handle.unsubscribe()` at shutdown-time would\n * otherwise hang forever — its resolve closure is captured in the entry\n * and never fired because we don't wait for an `unsubscribed` reply\n * during shutdown. Resolve them so callers awaiting unsubscribe see\n * shutdown as a successful tear-down (the watcher is going away either\n * way; from the consumer's perspective the subscription is gone).\n */\n for (const entry of subscriptions.values()) {\n entry.rejectSubscribed?.(new Error('WatcherWorkerSupervisor: shutdown'));\n entry.rejectSubscribed = undefined;\n entry.resolveSubscribed = undefined;\n entry.resolveUnsubscribed?.();\n entry.resolveUnsubscribed = undefined;\n }\n subscriptions.clear();\n\n const holder = child;\n if (holder === null) return;\n\n sendCommand(holder, { cmd: 'shutdown' });\n\n await escalateShutdown(holder);\n }\n\n function killWithSignal(holder: ChildHolder, signal: 'SIGTERM' | 'SIGKILL'): void {\n log({\n event:\n signal === 'SIGTERM'\n ? 'watcher_worker_shutdown_sigterm'\n : 'watcher_worker_shutdown_sigkill',\n });\n try {\n holder.process.kill(signal);\n } catch (err) {\n log({\n event: 'watcher_worker_kill_failed',\n signal,\n err: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n function escalateShutdown(holder: ChildHolder): Promise<void> {\n return new Promise<void>((resolve) => {\n const ctx = { done: false };\n const finish = () => {\n if (ctx.done) return;\n ctx.done = true;\n resolve();\n };\n\n holder.process.once('exit', finish);\n if (holder.exited) {\n finish();\n return;\n }\n\n deps.setTimeout(() => onSigtermDeadline(holder, ctx, finish), SHUTDOWN_GRACEFUL_MS);\n });\n }\n\n function onSigtermDeadline(\n holder: ChildHolder,\n ctx: { done: boolean },\n finish: () => void\n ): void {\n if (ctx.done || holder.exited) return;\n killWithSignal(holder, 'SIGTERM');\n deps.setTimeout(() => onSigkillDeadline(holder, ctx, finish), SHUTDOWN_SIGTERM_MS);\n }\n\n function onSigkillDeadline(\n holder: ChildHolder,\n ctx: { done: boolean },\n finish: () => void\n ): void {\n if (ctx.done || holder.exited) return;\n killWithSignal(holder, 'SIGKILL');\n finish();\n }\n\n return { start, subscribe, shutdown };\n}\n\nfunction isAbnormalExit(code: number | null, signal: NodeJS.Signals | null): boolean {\n if (signal !== null && ABNORMAL_SIGNALS.has(signal)) return true;\n if (code !== null && code !== 0) return true;\n return false;\n}\n\nfunction toCallbackEvents(events: WorkerParcelEvent[]): WatcherWorkerEventLike[] {\n return events.map((e) => ({ type: e.type, path: e.path }));\n}\n"],"mappings":";;;;;;;;AAyDO,IAAM,eAA+B;AAAA,EAC1C,UAAU;AAAA,EAAC;AAAA,EACX,UAAU;AAAA,EAAC;AACb;AAcO,IAAM,mBAAN,MAAuB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACT,UAA2B,CAAC;AAAA,EAC5B,SAAgD;AAAA,EAChD,YAAY;AAAA,EAEZ,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;AAAA,MACF,KAAK;AAEH;AAAA,MACF;AACE,oBAAY,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,uBAA0C;AACjD,SAAO,EAAE,aAAa,YAAY;AAAA,EAAC,EAAE;AACvC;","names":[]}
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/shared/capabilities/shell.ts
4
- import { execFile } from "child_process";
5
- var TIMEOUT_MS = 5e3;
6
- var AUTH_STATUS_TIMEOUT_MS = 15e3;
7
- var STANDARD_PATHS_BY_PLATFORM = {
8
- darwin: ["/usr/bin", "/usr/local/bin", "/opt/homebrew/bin"],
9
- linux: ["/usr/bin", "/usr/local/bin"]
10
- };
11
- function augmentPath(currentPath, platform) {
12
- const standardPaths = STANDARD_PATHS_BY_PLATFORM[platform];
13
- if (!standardPaths) return currentPath;
14
- const existing = currentPath.length > 0 ? currentPath.split(":") : [];
15
- const existingSet = new Set(existing);
16
- const toPrepend = standardPaths.filter((p) => !existingSet.has(p));
17
- if (toPrepend.length === 0) return currentPath;
18
- return existing.length > 0 ? `${toPrepend.join(":")}:${currentPath}` : toPrepend.join(":");
19
- }
20
- var augmentedPath = augmentPath(process.env.PATH ?? "", process.platform);
21
- if (augmentedPath.length > 0) {
22
- process.env.PATH = augmentedPath;
23
- }
24
- function run(command, args, cwd, timeoutMs = TIMEOUT_MS) {
25
- return new Promise((resolve, reject) => {
26
- execFile(command, args, { timeout: timeoutMs, cwd }, (error, stdout) => {
27
- if (error) {
28
- reject(error);
29
- return;
30
- }
31
- resolve(stdout.trim());
32
- });
33
- });
34
- }
35
- function runWithTimeout(command, args, cwd, timeoutMs) {
36
- return new Promise((resolve, reject) => {
37
- execFile(
38
- command,
39
- args,
40
- { timeout: timeoutMs, cwd, maxBuffer: 10 * 1024 * 1024 },
41
- (error, stdout) => {
42
- if (error) {
43
- reject(error);
44
- return;
45
- }
46
- resolve(stdout.trim());
47
- }
48
- );
49
- });
50
- }
51
- var DIFF_TIMEOUT_MS = 15e3;
52
- var MAX_DIFF_SIZE = 5e5;
53
- function isMaxBufferError(err) {
54
- return err instanceof Error && err.message.includes("maxBuffer");
55
- }
56
- var BUFFER_OVERFLOW_MSG = "... diff too large (exceeded buffer limit) ...\n";
57
- function truncateDiff(result) {
58
- if (result.length <= MAX_DIFF_SIZE) return result;
59
- const boundary = result.lastIndexOf("\ndiff --git ", MAX_DIFF_SIZE);
60
- const cutoff = boundary > 0 ? boundary : MAX_DIFF_SIZE;
61
- return `${result.slice(0, cutoff)}
62
-
63
- ... diff truncated (exceeds 500KB) ...
64
- `;
65
- }
66
-
67
- export {
68
- TIMEOUT_MS,
69
- AUTH_STATUS_TIMEOUT_MS,
70
- augmentPath,
71
- run,
72
- runWithTimeout,
73
- DIFF_TIMEOUT_MS,
74
- MAX_DIFF_SIZE,
75
- isMaxBufferError,
76
- BUFFER_OVERFLOW_MSG,
77
- truncateDiff
78
- };
79
- //# sourceMappingURL=chunk-66OBOZ3X.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared/capabilities/shell.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\n\nexport const TIMEOUT_MS = 5_000;\nexport const AUTH_STATUS_TIMEOUT_MS = 15_000;\n\nconst STANDARD_PATHS_BY_PLATFORM: Partial<Record<NodeJS.Platform, readonly string[]>> = {\n darwin: ['/usr/bin', '/usr/local/bin', '/opt/homebrew/bin'],\n linux: ['/usr/bin', '/usr/local/bin'],\n};\n\n/**\n * Daemons launched from Finder/Spotlight on macOS get a stripped PATH that may\n * omit /usr/bin where git lives. Prepend standard locations idempotently so\n * `execFile('git', ...)` resolves the binary. User-customized PATH entries\n * stay preferred — we only prepend dirs that aren't already present.\n */\nexport function augmentPath(currentPath: string, platform: NodeJS.Platform): string {\n const standardPaths = STANDARD_PATHS_BY_PLATFORM[platform];\n if (!standardPaths) return currentPath;\n\n const existing = currentPath.length > 0 ? currentPath.split(':') : [];\n const existingSet = new Set(existing);\n const toPrepend = standardPaths.filter((p) => !existingSet.has(p));\n if (toPrepend.length === 0) return currentPath;\n return existing.length > 0 ? `${toPrepend.join(':')}:${currentPath}` : toPrepend.join(':');\n}\n\nconst augmentedPath = augmentPath(process.env.PATH ?? '', process.platform);\nif (augmentedPath.length > 0) {\n process.env.PATH = augmentedPath;\n}\n\nexport function run(\n command: string,\n args: string[],\n cwd?: string,\n timeoutMs: number = TIMEOUT_MS\n): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(command, args, { timeout: timeoutMs, cwd }, (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout.trim());\n });\n });\n}\n\nexport function runWithTimeout(\n command: string,\n args: string[],\n cwd: string,\n timeoutMs: number\n): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(\n command,\n args,\n { timeout: timeoutMs, cwd, maxBuffer: 10 * 1024 * 1024 },\n (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout.trim());\n }\n );\n });\n}\n\nexport const DIFF_TIMEOUT_MS = 15_000;\nexport const MAX_DIFF_SIZE = 500_000;\n\nexport function isMaxBufferError(err: unknown): boolean {\n return err instanceof Error && err.message.includes('maxBuffer');\n}\n\nexport const BUFFER_OVERFLOW_MSG = '... diff too large (exceeded buffer limit) ...\\n';\n\nexport function truncateDiff(result: string): string {\n if (result.length <= MAX_DIFF_SIZE) return result;\n const boundary = result.lastIndexOf('\\ndiff --git ', MAX_DIFF_SIZE);\n const cutoff = boundary > 0 ? boundary : MAX_DIFF_SIZE;\n return `${result.slice(0, cutoff)}\\n\\n... diff truncated (exceeds 500KB) ...\\n`;\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AAElB,IAAM,aAAa;AACnB,IAAM,yBAAyB;AAEtC,IAAM,6BAAkF;AAAA,EACtF,QAAQ,CAAC,YAAY,kBAAkB,mBAAmB;AAAA,EAC1D,OAAO,CAAC,YAAY,gBAAgB;AACtC;AAQO,SAAS,YAAY,aAAqB,UAAmC;AAClF,QAAM,gBAAgB,2BAA2B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