@schoolai/shipyard 3.10.0 → 3.11.0-nightly.20260610.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.
- package/dist/{auth-GGM253LQ.js → auth-AUY74PMB.js} +3 -3
- package/dist/capability-detector-worker.js +9 -9
- package/dist/{chunk-KRX7OJER.js → chunk-4SYLDZTY.js} +5 -5
- package/dist/{chunk-IJHF4OM4.js → chunk-5W5N5U2S.js} +2 -2
- package/dist/{chunk-4THTCNVI.js → chunk-AAJSB2PQ.js} +4 -4
- package/dist/{chunk-AEUTFH76.js → chunk-EUDESORD.js} +4 -4
- package/dist/chunk-EUDESORD.js.map +1 -0
- package/dist/{chunk-RW2OTTUA.js → chunk-KYLYGFMH.js} +4 -4
- package/dist/{chunk-QJP7JCIS.js → chunk-LRNGLC4V.js} +41 -3
- package/dist/chunk-LRNGLC4V.js.map +1 -0
- package/dist/{chunk-A2UK6TW2.js → chunk-LZSMNUAI.js} +18 -1
- package/dist/{chunk-A2UK6TW2.js.map → chunk-LZSMNUAI.js.map} +1 -1
- package/dist/{chunk-Z37T5W6S.js → chunk-P2HZDIN7.js} +12 -7
- package/dist/chunk-P2HZDIN7.js.map +1 -0
- package/dist/{chunk-4PBXNWJV.js → chunk-RMLQ5DRP.js} +5 -3
- package/dist/chunk-RMLQ5DRP.js.map +1 -0
- package/dist/{chunk-2EQOL57Z.js → chunk-TFRYQDDG.js} +2 -2
- package/dist/{chunk-VKCGK333.js → chunk-U4UFUZSP.js} +66 -3
- package/dist/chunk-U4UFUZSP.js.map +1 -0
- package/dist/{chunk-3WEEGJJN.js → chunk-X5KCX6ZS.js} +2 -2
- package/dist/{chunk-GM6MH4CD.js → chunk-XIEOWUPV.js} +2 -2
- package/dist/{chunk-6LINHACK.js → chunk-Y5UWRARP.js} +47 -24
- package/dist/chunk-Y5UWRARP.js.map +1 -0
- package/dist/{chunk-EI4HMJ54.js → chunk-ZKW4DSN3.js} +50 -13
- package/dist/chunk-ZKW4DSN3.js.map +1 -0
- package/dist/cursor-runner.js +89 -63
- package/dist/cursor-runner.js.map +1 -1
- package/dist/electron-utility.js +5 -5
- package/dist/{git-repo-QNGPCJLI.js → git-repo-CTZJS3ER.js} +6 -4
- package/dist/index.js +8 -8
- package/dist/{logger-2F3CBS3V.js → logger-AN7EUK2B.js} +7 -5
- package/dist/{login-NZKH63H7.js → login-YB34LF4L.js} +7 -7
- package/dist/{logout-HY3MPOY5.js → logout-GUXVSWLZ.js} +5 -5
- package/dist/{mcp-servers-ICHOWXZB.js → mcp-servers-OAPQNDA7.js} +4 -4
- package/dist/{roi-YM5OOWHG.js → roi-NXJHL5X2.js} +3 -3
- package/dist/{serve-HVLR5UQ7.js → serve-I32KKQXL.js} +1349 -715
- package/dist/{serve-HVLR5UQ7.js.map → serve-I32KKQXL.js.map} +1 -1
- package/dist/{skills-W2Y6TWHA.js → skills-2UBVHFQ5.js} +2 -2
- package/dist/{start-YA4H2XFQ.js → start-PWYT7KCX.js} +11 -11
- package/package.json +2 -2
- package/dist/chunk-4PBXNWJV.js.map +0 -1
- package/dist/chunk-6LINHACK.js.map +0 -1
- package/dist/chunk-AEUTFH76.js.map +0 -1
- package/dist/chunk-EI4HMJ54.js.map +0 -1
- package/dist/chunk-QJP7JCIS.js.map +0 -1
- package/dist/chunk-VKCGK333.js.map +0 -1
- package/dist/chunk-Z37T5W6S.js.map +0 -1
- /package/dist/{auth-GGM253LQ.js.map → auth-AUY74PMB.js.map} +0 -0
- /package/dist/{chunk-KRX7OJER.js.map → chunk-4SYLDZTY.js.map} +0 -0
- /package/dist/{chunk-IJHF4OM4.js.map → chunk-5W5N5U2S.js.map} +0 -0
- /package/dist/{chunk-4THTCNVI.js.map → chunk-AAJSB2PQ.js.map} +0 -0
- /package/dist/{chunk-RW2OTTUA.js.map → chunk-KYLYGFMH.js.map} +0 -0
- /package/dist/{chunk-2EQOL57Z.js.map → chunk-TFRYQDDG.js.map} +0 -0
- /package/dist/{chunk-3WEEGJJN.js.map → chunk-X5KCX6ZS.js.map} +0 -0
- /package/dist/{chunk-GM6MH4CD.js.map → chunk-XIEOWUPV.js.map} +0 -0
- /package/dist/{git-repo-QNGPCJLI.js.map → git-repo-CTZJS3ER.js.map} +0 -0
- /package/dist/{logger-2F3CBS3V.js.map → logger-AN7EUK2B.js.map} +0 -0
- /package/dist/{login-NZKH63H7.js.map → login-YB34LF4L.js.map} +0 -0
- /package/dist/{logout-HY3MPOY5.js.map → logout-GUXVSWLZ.js.map} +0 -0
- /package/dist/{mcp-servers-ICHOWXZB.js.map → mcp-servers-OAPQNDA7.js.map} +0 -0
- /package/dist/{roi-YM5OOWHG.js.map → roi-NXJHL5X2.js.map} +0 -0
- /package/dist/{skills-W2Y6TWHA.js.map → skills-2UBVHFQ5.js.map} +0 -0
- /package/dist/{start-YA4H2XFQ.js.map → start-PWYT7KCX.js.map} +0 -0
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
loadAuthToken,
|
|
6
6
|
readConfig,
|
|
7
7
|
writeConfig
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-X5KCX6ZS.js";
|
|
9
|
+
import "./chunk-P2HZDIN7.js";
|
|
10
10
|
import "./chunk-CNR7O5YH.js";
|
|
11
11
|
import "./chunk-2H7UOFLK.js";
|
|
12
12
|
export {
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
readConfig,
|
|
17
17
|
writeConfig
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=auth-
|
|
19
|
+
//# sourceMappingURL=auth-AUY74PMB.js.map
|
|
@@ -3,27 +3,27 @@ import {
|
|
|
3
3
|
detectCapabilities,
|
|
4
4
|
refreshMcpServers,
|
|
5
5
|
registerBuiltInProfiles
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-ZKW4DSN3.js";
|
|
7
|
+
import "./chunk-XIEOWUPV.js";
|
|
8
8
|
import {
|
|
9
9
|
getRepoMetadata
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Y5UWRARP.js";
|
|
11
11
|
import "./chunk-4T2OQAVL.js";
|
|
12
12
|
import {
|
|
13
13
|
MCPTokenStore
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-KYLYGFMH.js";
|
|
15
15
|
import "./chunk-RR6V6SNM.js";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-TFRYQDDG.js";
|
|
17
17
|
import "./chunk-ZFKJAYAN.js";
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-U4UFUZSP.js";
|
|
19
|
+
import "./chunk-RMLQ5DRP.js";
|
|
20
20
|
import "./chunk-EHQITHQX.js";
|
|
21
21
|
import "./chunk-X3MULCV5.js";
|
|
22
22
|
import {
|
|
23
23
|
flushLogger,
|
|
24
24
|
logger
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-LRNGLC4V.js";
|
|
26
|
+
import "./chunk-P2HZDIN7.js";
|
|
27
27
|
import "./chunk-CNR7O5YH.js";
|
|
28
28
|
import "./chunk-2H7UOFLK.js";
|
|
29
29
|
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
import {
|
|
3
3
|
print,
|
|
4
4
|
printError
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-5W5N5U2S.js";
|
|
6
6
|
import {
|
|
7
7
|
getConfigPath,
|
|
8
8
|
loadAuthToken,
|
|
9
9
|
readConfig,
|
|
10
10
|
writeConfig
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-X5KCX6ZS.js";
|
|
12
12
|
import {
|
|
13
13
|
DeviceExchangeCodeResponseSchema,
|
|
14
14
|
DevicePollPendingSchema,
|
|
15
15
|
DevicePollResponseSchema,
|
|
16
16
|
DeviceStartResponseSchema,
|
|
17
17
|
ROUTES
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-RMLQ5DRP.js";
|
|
19
19
|
import {
|
|
20
20
|
isDevMode,
|
|
21
21
|
validateEnv
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-P2HZDIN7.js";
|
|
23
23
|
import {
|
|
24
24
|
external_exports
|
|
25
25
|
} from "./chunk-CNR7O5YH.js";
|
|
@@ -223,4 +223,4 @@ export {
|
|
|
223
223
|
ensureAuthenticated,
|
|
224
224
|
loginCommand
|
|
225
225
|
};
|
|
226
|
-
//# sourceMappingURL=chunk-
|
|
226
|
+
//# sourceMappingURL=chunk-4SYLDZTY.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
getLogFilePath
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LRNGLC4V.js";
|
|
5
5
|
|
|
6
6
|
// src/shared/commands/output.ts
|
|
7
7
|
import { appendFileSync } from "fs";
|
|
@@ -40,4 +40,4 @@ export {
|
|
|
40
40
|
print,
|
|
41
41
|
printError
|
|
42
42
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
43
|
+
//# sourceMappingURL=chunk-5W5N5U2S.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
validateEnv
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-P2HZDIN7.js";
|
|
5
5
|
import {
|
|
6
6
|
external_exports
|
|
7
7
|
} from "./chunk-CNR7O5YH.js";
|
|
@@ -18,8 +18,8 @@ function getDaemonVersion() {
|
|
|
18
18
|
return cached;
|
|
19
19
|
}
|
|
20
20
|
function readDaemonVersion() {
|
|
21
|
-
if ("3.
|
|
22
|
-
return "3.
|
|
21
|
+
if ("3.11.0".length > 0) {
|
|
22
|
+
return "3.11.0";
|
|
23
23
|
}
|
|
24
24
|
try {
|
|
25
25
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -48,4 +48,4 @@ function readDaemonVersion() {
|
|
|
48
48
|
export {
|
|
49
49
|
getDaemonVersion
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
51
|
+
//# sourceMappingURL=chunk-AAJSB2PQ.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
getDaemonVersion
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AAJSB2PQ.js";
|
|
5
5
|
import {
|
|
6
6
|
WorkerCommandCodec,
|
|
7
7
|
WorkerReplyCodec
|
|
8
8
|
} from "./chunk-NACJENDW.js";
|
|
9
9
|
import {
|
|
10
10
|
buildNodeSpawnEnv
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-XIEOWUPV.js";
|
|
12
12
|
import {
|
|
13
13
|
createServiceSupervisor
|
|
14
14
|
} from "./chunk-ZFKJAYAN.js";
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
resolveNodeExecPath,
|
|
20
20
|
validateEnv
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-P2HZDIN7.js";
|
|
22
22
|
|
|
23
23
|
// src/services/metrics/metrics-collector.ts
|
|
24
24
|
var NOOP_METRICS = {
|
|
@@ -1094,4 +1094,4 @@ export {
|
|
|
1094
1094
|
shutdownFileWatcherGuard,
|
|
1095
1095
|
guardedSubscribe
|
|
1096
1096
|
};
|
|
1097
|
-
//# sourceMappingURL=chunk-
|
|
1097
|
+
//# sourceMappingURL=chunk-EUDESORD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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';\nimport { getDaemonVersion } from '../../shared/daemon-version.js';\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). Payload:\n * `{ priorPid, priorHeartbeatAt, ageMs }` always, plus breadcrumb-derived\n * diagnostics when the prior run left a readable breadcrumb whose pid matches:\n * `lastPhase` (the boot/runtime phase it was last in), `lastError` (a\n * captured early-boot exception message, if any), `breadcrumbAgeMs` (age of\n * the last breadcrumb write). Without these the event was unrootcauseable —\n * they turn \"it died\" into \"it died in phase X with error Y\".\n * - `daemon_early_boot_crashed` — an exception escaped the daemon early-boot\n * path before the daemon stabilized (caught by the guard in `serve()` before\n * the entry-point `.catch()` exits the process). Payload: `{ phase, error,\n * stack? }`. The same error is also written to the breadcrumb so the NEXT\n * boot's `daemon_catastrophic_restart` carries it as `lastError`.\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 * - `bootstrap_phase` — per-step timing+outcome emitted by the auto-instrumentation\n * primitive in `shared/bootstrap-phase.ts`. Payload: `{ phase, durationMs, outcome,\n * error? }`. Fires once per wrapped startup step (#3290).\n * - `startup_complete` — aggregate emitted at the end of daemon boot with\n * `{ totalMs, phaseCount, phases[] }`. Pairs with the same-named structured\n * log line for easy post-mortem.\n * - `run_stall_timeout` — Cursor runner silence watchdog fired.\n * - `request_task_state_replay_failed` — peer-requested task-state replay failed.\n * - `loro_recovery_failed` — CRDT recovery failed after a recoverable Loro panic.\n * - `mcp_server_connect_failed` — coordinator moved an MCP server into failed\n * because connect/probe/timeout failed.\n * - `mcp_server_needs_auth` — coordinator moved an MCP server into needs-auth\n * after an auth-class failure.\n * - `mcp_reconnect_failed` — subprocess-side MCP reconnect failed with a\n * transient/unclassified error.\n * - `mcp_reconnect_terminal` — subprocess-side reconnect failed with a\n * terminal reason that needs user action.\n * - `mcp_reconnect_terminal_unsupported` — reconnect hit a calm terminal\n * unsupported-server classification.\n * - `mcp_reauth_failed` — an MCP OAuth re-authentication flow failed, so the\n * user's recovery path for a needs-auth server is itself broken.\n * - `mcp_adopted_set_failed` — coordinator failed to push the resolved MCP set\n * into a newly adopted subprocess.\n * - `mcp_push_failed` — coordinator failed to repush the resolved MCP set into\n * a running subprocess.\n * - `harness_mcp_registration_failed` — an agent init did not report the\n * Shipyard harness MCP server as connected, so Shipyard tools may be absent.\n * - `codex_auth_divergence_detected` — Codex subprocess auth signal disagreed with disk.\n * - `cursor_auth_divergence_detected` — Cursor subprocess auth signal disagreed with Cursor.me().\n * - `event_loop_stall` — discrete event-loop stall above watchdog threshold.\n * - `machine_sleep_artifact` — watchdog lag too large to be actionable as a JS stall.\n * - `squirrel_install_stuck_recovered` — Electron main cleared a wedged Squirrel.Mac\n * staged install on launch so electron-updater can re-download.\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 | 'daemon_early_boot_crashed'\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 | 'bootstrap_phase'\n | 'startup_complete'\n | 'run_stall_timeout'\n | 'request_task_state_replay_failed'\n | 'loro_recovery_failed'\n | 'mcp_server_connect_failed'\n | 'mcp_server_needs_auth'\n | 'mcp_reconnect_failed'\n | 'mcp_reconnect_terminal'\n | 'mcp_reconnect_terminal_unsupported'\n | 'mcp_reauth_failed'\n | 'mcp_adopted_set_failed'\n | 'mcp_push_failed'\n | 'harness_mcp_registration_failed'\n | 'codex_auth_divergence_detected'\n | 'cursor_auth_divergence_detected'\n | 'event_loop_stall'\n | 'machine_sleep_artifact'\n | 'squirrel_install_stuck_recovered';\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\n/**\n * Sink for telemetry-delivery failures. Wired to the daemon logger at WARN so a\n * broken pipeline is always visible regardless of LOG_LEVEL. Without this, `flush()`\n * swallowed every non-2xx/error (`fetch().catch(() => {})`) — which is why a\n * fleet-wide ingest outage went unnoticed for 9 days.\n */\nexport type MetricsLogger = (entry: { event: string; [key: string]: unknown }) => void;\n\nconst NOOP_LOG: MetricsLogger = () => {};\n\n/** Min spacing between failure logs so a persistent outage doesn't itself become log spam. */\nconst FAILURE_LOG_THROTTLE_MS = 600_000;\n\ninterface MetricsCollectorOpts {\n flushIntervalMs?: number;\n maxBatchSize?: number;\n log?: MetricsLogger;\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 /**\n * String OR a getter resolved at flush time. The daemon holds a static\n * boot-time token; a getter lets a long-running daemon pick up a token\n * refreshed in config.json (re-login) without restarting, so its telemetry\n * stops 401-ing on the stale token.\n */\n readonly #authToken: string | (() => string);\n readonly #maxBatchSize: number;\n readonly #log: MetricsLogger;\n /**\n * Resolved once at construction — the version is static for a process, and\n * getDaemonVersion() can throw in a misconfigured packaged build, so we never\n * want to call it per-event. Falls back to 'unknown' rather than failing\n * telemetry capture if resolution throws.\n */\n readonly #daemonVersion: string;\n #buffer: BufferedEvent[] = [];\n #timer: ReturnType<typeof setInterval> | null = null;\n #disposed = false;\n #lastFailureLogMs = 0;\n #suppressedFailures = 0;\n\n constructor(workerUrl: string, authToken: string | (() => string), opts?: MetricsCollectorOpts) {\n this.#workerUrl = workerUrl.replace(/\\/$/, '');\n this.#authToken = authToken;\n this.#maxBatchSize = opts?.maxBatchSize ?? 50;\n this.#log = opts?.log ?? NOOP_LOG;\n this.#daemonVersion = resolveDaemonVersionSafely();\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 /**\n * Every event carries daemonVersion so fleet telemetry can be sliced by\n * version — without it, triage can't distinguish 'fix not deployed' from\n * 'fix ineffective'. Spread last so a stray caller field can't override\n * the authoritative value.\n */\n payload: { ...(properties ?? {}), daemonVersion: this.#daemonVersion },\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 const token = typeof this.#authToken === 'function' ? this.#authToken() : this.#authToken;\n fetch(`${this.#workerUrl}/ingest`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n },\n body: JSON.stringify(body),\n })\n .then((res) => {\n if (res.ok) {\n this.#suppressedFailures = 0;\n return;\n }\n this.#reportFailure({ status: res.status, droppedEvents: events.length });\n })\n .catch((err: unknown) => {\n this.#reportFailure({\n error: err instanceof Error ? err.message : String(err),\n droppedEvents: events.length,\n });\n });\n }\n\n /**\n * Surface a delivery failure at most once per throttle window, carrying the\n * count of failures suppressed since the last log so a persistent outage is\n * visible without flooding the log.\n */\n #reportFailure(detail: Record<string, unknown>): void {\n const now = Date.now();\n if (now - this.#lastFailureLogMs < FAILURE_LOG_THROTTLE_MS) {\n this.#suppressedFailures += 1;\n return;\n }\n this.#log({\n event: 'telemetry_ingest_failed',\n suppressedSinceLastLog: this.#suppressedFailures,\n ...detail,\n });\n this.#lastFailureLogMs = now;\n this.#suppressedFailures = 0;\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\nfunction resolveDaemonVersionSafely(): string {\n try {\n return getDaemonVersion();\n } catch {\n return 'unknown';\n }\n}\n\nexport function createMetricsCollector(\n workerUrl: string | undefined,\n authToken: string | (() => string) | undefined,\n telemetryEnabled: boolean,\n log: MetricsLogger\n): MetricsCapture {\n if (!telemetryEnabled || !workerUrl || !authToken) return NOOP_METRICS;\n return new MetricsCollector(workerUrl, authToken, { log });\n}\n","import { fork as childProcessFork } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { dirname } from 'node:path';\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';\nimport { validateEnv } from './env.js';\nimport { buildNodeSpawnEnv, resolveNodeExecPath } from './spawn-as-node.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;\nexport const MAX_ACTIVE_WATCHERS =\n validateEnv().SHIPYARD_FILE_WATCHER_MAX ?? 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 * In dev mode (`tsx src/index.ts`), `import.meta.url` is the source file\n * (`src/shared/file-watcher-guard.ts`), not `dist/index.js`. `./worker.js`\n * relative to `src/shared/` would point to a non-existent file. Detect the\n * dev path by checking whether the module URL contains `/src/` and resolve\n * to the actual worker source (`src/services/watcher-worker/worker.ts`)\n * instead — tsx handles the `.js` → `.ts` extension rewrite automatically.\n */\n const selfUrl = import.meta.url;\n const isDevMode = selfUrl.endsWith('.ts');\n const workerPath = isDevMode\n ? new URL('../services/watcher-worker/worker.ts', selfUrl).pathname\n : new URL('./worker.js', selfUrl).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) =>\n /**\n * Fork the watcher worker against the resolved Node binary + Electron-node\n * env overlay — NOT the default `process.execPath`. In the packaged Electron\n * utility process the default resolves to a helper executable that may be\n * absent from the bundle (spawn ENOENT) and, even when present, needs\n * `ELECTRON_RUN_AS_NODE=1` to run a JS file instead of booting an Electron\n * app. Same root cause as the cursor-runner crash loop — this path is lazy\n * (first worktree subscription) so it broke file watching rather than boot.\n */\n childProcessFork(modulePath, args, {\n ...options,\n execPath: resolveNodeExecPath(),\n env: buildNodeSpawnEnv(process.env),\n });\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 const parentExists = pathExistsForLog(dirname(path));\n deps.log({\n event: 'file_watcher_subscribe_failed',\n path,\n pathExists: pathExistsForLog(path),\n parentExists,\n err: err instanceof Error ? err.message : String(err),\n /**\n * The expected-ENOENT fallback path (file doesn't exist yet but\n * parent does) is a normal poll cycle, not a failure. Downgrade\n * the log level so log triage doesn't flag 40+ of these per task.\n */\n ...(parentExists ? { level: 'debug' as const } : {}),\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\nfunction pathExistsForLog(path: string): boolean {\n try {\n return existsSync(path);\n } catch {\n return false;\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 {\n createServiceSupervisor,\n type ServiceSupervisor,\n type StdioChildProcessLike,\n} from '@shipyard/local-runtime';\nimport { assertNever } from '../../shared/assert-never.js';\nimport {\n type AttemptState,\n decideAction,\n makeInitialAttemptState,\n} from '../../shared/file-watcher-guard.js';\nimport {\n type WorkerCommand,\n WorkerCommandCodec,\n type WorkerParcelEvent,\n type WorkerReply,\n WorkerReplyCodec,\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 * Process lifecycle (spawn, peer attach, generation tokens, exit dispatch)\n * is delegated to `createServiceSupervisor` from @shipyard/local-runtime.\n * This module retains the watcher-specific concerns:\n * - subscription map + replay-on-respawn\n * - the file-watcher-guard-based half-open circuit (separate from the\n * primitive's simpler deaths-per-window circuit, which is opted out of)\n * - pendingRespawnGeneration accounting tied to subscribe-ack delivery\n * - synthetic 'evicted' eviction across the death gap\n * - SIGTERM → SIGKILL shutdown escalation\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 readonly fork: (\n modulePath: string,\n args: string[],\n options: { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }\n ) => ChildProcess;\n readonly workerPath: string;\n readonly log: SupervisorLogger;\n readonly metrics?: SupervisorMetrics;\n readonly now: () => number;\n readonly setTimeout: (fn: () => void, ms: number) => unknown;\n readonly 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\nexport function createWatcherWorkerSupervisor(\n deps: WatcherWorkerSupervisorDeps\n): WatcherWorkerSupervisor {\n const subscriptions = new Map<string, SubscriptionEntry>();\n let restartState: AttemptState = makeInitialAttemptState();\n let liveGeneration = 0;\n let lastSpawnedAt = 0;\n let lastPid: number | null = null;\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 let nextReplayStartedAt: 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 /**\n * Adapt deps.fork to the primitive's ForkLike shape. ChildProcess\n * structurally satisfies StdioChildProcessLike; we just match the\n * argument signature (readonly args -> string[]).\n */\n const adaptedFork = (\n modulePath: string,\n args: readonly string[],\n options: { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }\n ): StdioChildProcessLike => {\n return deps.fork(modulePath, Array.from(args), options);\n };\n\n const supervisor: ServiceSupervisor<WorkerCommand> = createServiceSupervisor<\n WorkerCommand,\n WorkerReply\n >({\n fork: adaptedFork,\n workerPath: deps.workerPath,\n commandCodec: WorkerCommandCodec,\n replyCodec: WorkerReplyCodec,\n onReply: (reply, fromGeneration) => dispatchReply(reply, fromGeneration),\n onChildSpawned: ({ generation, pid }) => {\n liveGeneration = generation;\n lastPid = pid;\n lastSpawnedAt = deps.now();\n log({ event: 'watcher_worker_started', pid });\n captureMetric('watcher_worker_started', { pid });\n },\n onChildExit: ({ code, signal, generation, uptimeMs }) => {\n handleChildExit(generation, code, signal, uptimeMs);\n },\n onDecodeFailed: ({ line }) => log({ event: 'watcher_worker_decode_failed', line }),\n onStderrLine: (line) => {\n if (!line.trim()) return;\n log({ event: 'watcher_worker_stderr', line });\n },\n onMissingStdout: () => log({ event: 'watcher_worker_no_stdout' }),\n onOverflow: ({ stream, bytes, maxBytes }) =>\n log({ event: 'watcher_worker_stdio_overflow', stream, bytes, maxBytes }),\n onPeerError: (err) => log({ event: 'watcher_worker_error', err: err.message }),\n log,\n now: deps.now,\n /** Watcher uses its own file-watcher-guard circuit; opt out of the primitive's. */\n });\n\n function sendCommand(cmd: WorkerCommand): boolean {\n const sent = supervisor.send(cmd);\n if (!sent && supervisor.getCurrentProcess() !== null) {\n log({\n event: 'watcher_worker_stdin_write_failed',\n err: 'stdio peer send returned false',\n });\n }\n return sent;\n }\n\n function dispatchReply(reply: WorkerReply, fromGeneration: number): void {\n if (fromGeneration !== liveGeneration) {\n log({\n event: 'watcher_worker_stale_reply_dropped',\n replyType: reply.type,\n id: reply.id,\n generation: fromGeneration,\n liveGeneration,\n });\n return;\n }\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 when respawning.\n * Pipe drains can deliver replies from a dead generation after a\n * successor is live, and only the original generation should consume\n * 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 handleChildExit(\n generation: number,\n code: number | null,\n signal: NodeJS.Signals | null,\n uptimeMs: number\n ): void {\n /**\n * The primitive only fires onChildExit for the currently-live generation,\n * so this always matches `liveGeneration`. After this returns, the\n * primitive has set its internal live to null.\n */\n if (pendingRespawnGeneration === generation) {\n pendingRespawnGeneration = null;\n }\n\n const replayCount = subscriptions.size;\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(uptimeMs);\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(uptimeMs: number): 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: uptimeMs,\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. Without this guard both timers fire and the\n * second one runs forkAndReplay while a worker is already alive.\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'.\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 const openedAt = restartState.circuitOpenedAt;\n if (openedAt === null) {\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 attemptRespawn();\n return;\n case 'noop':\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 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 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 */\n type ReplayResult =\n | { kind: 'completed'; replayedCount: number }\n | { kind: 'pipe_failed'; replayedCount: number };\n\n function forkAndReplay(): void {\n const isRespawn = liveGeneration >= 1;\n nextReplayStartedAt = deps.now();\n /**\n * Whether the spawn we're about to perform is a respawn that should\n * close the circuit on its first ack. We snapshot here BEFORE start/\n * restart fires onChildSpawned (which bumps liveGeneration).\n */\n const shouldMarkPendingRespawn = isRespawn && subscriptions.size > 0;\n\n if (liveGeneration === 0) {\n supervisor.start();\n } else {\n supervisor.restart();\n }\n\n if (shouldMarkPendingRespawn) {\n pendingRespawnGeneration = liveGeneration;\n }\n\n const replayResult = replaySubscriptions();\n\n if (replayResult.kind === 'pipe_failed') {\n handleReplayPipeFailure(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(\n replayResult.replayedCount,\n deps.now() - (nextReplayStartedAt ?? deps.now())\n );\n }\n }\n\n function replaySubscriptions(): 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({\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(replayedCount: number): void {\n log({\n event: 'watcher_worker_replay_pipe_failed',\n pid: lastPid,\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 */\n recordRestartFailure(deps.now() - lastSpawnedAt);\n /**\n * Pipe death usually means the worker has already exited or its stdin\n * was closed underneath us. Kill the underlying process so onExit fires\n * and the standard respawn cycle takes over.\n */\n const proc = supervisor.getCurrentProcess();\n if (proc !== null) {\n try {\n proc.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(replayCount: number, replayDurationMs: number): void {\n log({\n event: 'watcher_worker_respawned',\n pid: lastPid,\n replayCount,\n replayDurationMs,\n });\n captureMetric('watcher_worker_respawned', {\n newPid: lastPid,\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 (supervisor.getCurrentProcess() === null) {\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 = sendCommand({ 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 (supervisor.getCurrentProcess() !== 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 (supervisor.getCurrentProcess() === null) {\n await start();\n } else {\n sendCommand({ cmd: 'subscribe', id, path, opts });\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.\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 proc = supervisor.getCurrentProcess();\n supervisor.dispose();\n if (proc === null) return;\n\n sendCommand({ cmd: 'shutdown' });\n\n await escalateShutdown(proc);\n }\n\n function killWithSignal(proc: StdioChildProcessLike, 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 proc.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(proc: StdioChildProcessLike): Promise<void> {\n return new Promise<void>((resolve) => {\n const ctx = { done: false, exited: false };\n const finish = () => {\n if (ctx.done) return;\n ctx.done = true;\n resolve();\n };\n\n proc.once('exit', () => {\n ctx.exited = true;\n finish();\n });\n\n deps.setTimeout(() => onSigtermDeadline(proc, ctx, finish), SHUTDOWN_GRACEFUL_MS);\n });\n }\n\n function onSigtermDeadline(\n proc: StdioChildProcessLike,\n ctx: { done: boolean; exited: boolean },\n finish: () => void\n ): void {\n if (ctx.done || ctx.exited) return;\n killWithSignal(proc, 'SIGTERM');\n deps.setTimeout(() => onSigkillDeadline(proc, ctx, finish), SHUTDOWN_SIGTERM_MS);\n }\n\n function onSigkillDeadline(\n proc: StdioChildProcessLike,\n ctx: { done: boolean; exited: boolean },\n finish: () => void\n ): void {\n if (ctx.done || ctx.exited) return;\n killWithSignal(proc, '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":";;;;;;;;;;;;;;;;;;;;;;;AA0HO,IAAM,eAA+B;AAAA,EAC1C,UAAU;AAAA,EAAC;AAAA,EACX,UAAU;AAAA,EAAC;AACb;AAUA,IAAM,WAA0B,MAAM;AAAC;AAGvC,IAAM,0BAA0B;AAezB,IAAM,mBAAN,MAAuB;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA,EACA;AAAA,EAC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AAA,IACP,MAAM,OAAO;AAAA,IACb,SAAS;AAAA,EACX,CAAC;AACD,OAAK,WAAW,MAAM;AACpB,SAAK,wBAAwB,MAAM;AAAA,EACrC,GAAG,8BAA8B;AACnC;AAEA,eAAe,wBAAwB,QAAoC;AACzE,QAAM,EAAE,KAAK,IAAI;AACjB,MAAI;AACF,UAAM,iBAAiB,OAAO,MAAM,OAAO,kBAAkB,CAAC,GAAG,aAAa,QAAQ;AACtF,SAAK,IAAI,EAAE,OAAO,wCAAwC,MAAM,OAAO,KAAK,CAAC;AAAA,EAC/E,SAAS,KAAK;AACZ,SAAK,IAAI;AAAA,MACP,OAAO;AAAA,MACP,MAAM,OAAO;AAAA,MACb,KAAK,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,IACtD,CAAC;AAAA,EACH;AACF;AAEA,SAAS,YAAY,MAAc,SAA0C;AAC3E,QAAM,EAAE,KAAK,IAAI;AACjB,aAAW,OAAO,SAAS;AACzB,YAAQ,IAAI,MAAM;AAAA,MAChB,KAAK;AACH,aAAK,IAAI,EAAE,OAAO,6BAA6B,KAAK,CAAC;AACrD,oBAAY,aAAa,IAAI,MAAM,KAAK,IAAI,CAAC;AAC7C;AAAA,MACF,KAAK;AACH,aAAK,IAAI,EAAE,OAAO,+BAA+B,KAAK,CAAC;AACvD,oBAAY,aAAa,OAAO,IAAI;AACpC;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":[]}
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
} from "./chunk-RR6V6SNM.js";
|
|
6
6
|
import {
|
|
7
7
|
logger
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LRNGLC4V.js";
|
|
9
9
|
import {
|
|
10
10
|
isClaudeCodeKeychainReadEnabled
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-P2HZDIN7.js";
|
|
12
12
|
import {
|
|
13
13
|
external_exports
|
|
14
14
|
} from "./chunk-CNR7O5YH.js";
|
|
@@ -1391,7 +1391,7 @@ async function detectMCPServers(environments, tokenStore, log, lastKnown, prefer
|
|
|
1391
1391
|
lastKnown
|
|
1392
1392
|
);
|
|
1393
1393
|
} catch (err) {
|
|
1394
|
-
const { logger: logger2 } = await import("./logger-
|
|
1394
|
+
const { logger: logger2 } = await import("./logger-AN7EUK2B.js");
|
|
1395
1395
|
if (lastKnown && lastKnown.length > 0) {
|
|
1396
1396
|
logger2.warn(
|
|
1397
1397
|
{ err, lastKnownCount: lastKnown.length },
|
|
@@ -1589,4 +1589,4 @@ export {
|
|
|
1589
1589
|
detectCodexPluginMcps,
|
|
1590
1590
|
detectMCPServers
|
|
1591
1591
|
};
|
|
1592
|
-
//# sourceMappingURL=chunk-
|
|
1592
|
+
//# sourceMappingURL=chunk-KYLYGFMH.js.map
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getShipyardHome,
|
|
4
4
|
validateEnv
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-P2HZDIN7.js";
|
|
6
6
|
|
|
7
7
|
// src/shared/logger.ts
|
|
8
8
|
import { mkdirSync } from "fs";
|
|
9
|
+
import { readdir, stat, unlink } from "fs/promises";
|
|
9
10
|
import { join } from "path";
|
|
10
11
|
import pino from "pino";
|
|
11
12
|
function shouldAttachFileTransport(env) {
|
|
@@ -17,6 +18,33 @@ function shouldAttachFileTransport(env) {
|
|
|
17
18
|
}
|
|
18
19
|
return true;
|
|
19
20
|
}
|
|
21
|
+
var LOG_RETENTION_DAYS = 7;
|
|
22
|
+
function shouldDeleteLogFile(fileName, mtimeMs, nowMs) {
|
|
23
|
+
if (!/^daemon\.log\.\d+$/.test(fileName)) return false;
|
|
24
|
+
return mtimeMs < nowMs - LOG_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
|
|
25
|
+
}
|
|
26
|
+
async function cleanOldLogs(dir) {
|
|
27
|
+
try {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const files = await readdir(dir);
|
|
30
|
+
const rotated = files.filter((file) => /^daemon\.log\.\d+$/.test(file));
|
|
31
|
+
const indexOf = (file) => Number(file.split(".").at(-1) ?? "0");
|
|
32
|
+
const maxIndex = rotated.reduce((max, file) => Math.max(max, indexOf(file)), 0);
|
|
33
|
+
await Promise.allSettled(
|
|
34
|
+
rotated.filter((file) => indexOf(file) < maxIndex).map(async (file) => {
|
|
35
|
+
try {
|
|
36
|
+
const filePath = join(dir, file);
|
|
37
|
+
const stats = await stat(filePath);
|
|
38
|
+
if (shouldDeleteLogFile(file, stats.mtimeMs, now)) {
|
|
39
|
+
await unlink(filePath);
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
20
48
|
var attachFileTransport = shouldAttachFileTransport({
|
|
21
49
|
VITEST: process.env.VITEST,
|
|
22
50
|
NODE_ENV: process.env.NODE_ENV
|
|
@@ -24,6 +52,7 @@ var attachFileTransport = shouldAttachFileTransport({
|
|
|
24
52
|
var logDir = join(getShipyardHome(), "logs");
|
|
25
53
|
if (attachFileTransport) {
|
|
26
54
|
mkdirSync(logDir, { recursive: true, mode: 448 });
|
|
55
|
+
void cleanOldLogs(logDir);
|
|
27
56
|
}
|
|
28
57
|
var logFilePath = join(logDir, "daemon.log");
|
|
29
58
|
function getLogFilePath() {
|
|
@@ -39,7 +68,15 @@ var transport = pino.transport({
|
|
|
39
68
|
target: "pino-roll",
|
|
40
69
|
options: {
|
|
41
70
|
file: logFilePath,
|
|
42
|
-
|
|
71
|
+
/*
|
|
72
|
+
* Size-based rotation (not frequency-based): pino-roll's daily frequency
|
|
73
|
+
* uses birthtime filtering in detectLastNumber, which causes every daemon
|
|
74
|
+
* restart to re-open daemon.log.1 (old files predate today's midnight).
|
|
75
|
+
* Without a frequency, detectLastNumber has no time filter and correctly
|
|
76
|
+
* identifies the highest-numbered existing file to continue writing there.
|
|
77
|
+
*/
|
|
78
|
+
size: "100m",
|
|
79
|
+
// NOTE: per-session cap only — cross-restart retention is owned by cleanOldLogs above
|
|
43
80
|
limit: { count: 7 },
|
|
44
81
|
mkdir: true
|
|
45
82
|
},
|
|
@@ -68,9 +105,10 @@ function flushLogger(timeoutMs = 2e3) {
|
|
|
68
105
|
|
|
69
106
|
export {
|
|
70
107
|
shouldAttachFileTransport,
|
|
108
|
+
shouldDeleteLogFile,
|
|
71
109
|
getLogFilePath,
|
|
72
110
|
logger,
|
|
73
111
|
createChildLogger,
|
|
74
112
|
flushLogger
|
|
75
113
|
};
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
114
|
+
//# sourceMappingURL=chunk-LRNGLC4V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shared/logger.ts"],"sourcesContent":["import { mkdirSync } from 'node:fs';\nimport { readdir, stat, unlink } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport pino from 'pino';\nimport { getShipyardHome, validateEnv } from './env.js';\n\n/** Whether the rolling file transport should attach (suppressed under vitest / NODE_ENV=test). */\nexport function shouldAttachFileTransport(env: { VITEST?: string; NODE_ENV?: string }): boolean {\n if (env.VITEST !== undefined) {\n return false;\n }\n if (env.NODE_ENV === 'test') {\n return false;\n }\n return true;\n}\n\nconst LOG_RETENTION_DAYS = 7;\n\n/**\n * Pure decision: should a rotated daemon log file be deleted?\n * fileName must be a basename (e.g. \"daemon.log.1\"), not a full path.\n * Exported for testing — no I/O.\n */\nexport function shouldDeleteLogFile(fileName: string, mtimeMs: number, nowMs: number): boolean {\n if (!/^daemon\\.log\\.\\d+$/.test(fileName)) return false;\n return mtimeMs < nowMs - LOG_RETENTION_DAYS * 24 * 60 * 60 * 1000;\n}\n\nasync function cleanOldLogs(dir: string): Promise<void> {\n try {\n const now = Date.now();\n const files = await readdir(dir);\n const rotated = files.filter((file) => /^daemon\\.log\\.\\d+$/.test(file));\n /*\n * Skip the highest-indexed file: pino-roll's transport worker selects it\n * as the continuation target and may have an open fd on it before this\n * sweep completes. Files with lower indices are safe to prune.\n */\n const indexOf = (file: string): number => Number(file.split('.').at(-1) ?? '0');\n const maxIndex = rotated.reduce((max, file) => Math.max(max, indexOf(file)), 0);\n await Promise.allSettled(\n rotated\n .filter((file) => indexOf(file) < maxIndex)\n .map(async (file) => {\n try {\n const filePath = join(dir, file);\n const stats = await stat(filePath);\n if (shouldDeleteLogFile(file, stats.mtimeMs, now)) {\n await unlink(filePath);\n }\n } catch {\n // NOTE: ENOENT/EACCES expected — file may be concurrently deleted or temporarily unreadable\n }\n })\n );\n } catch {\n // NOTE: readdir failure is swallowed so log cleanup never blocks daemon startup\n }\n}\n\nconst attachFileTransport = shouldAttachFileTransport({\n VITEST: process.env.VITEST,\n NODE_ENV: process.env.NODE_ENV,\n});\n\nconst logDir = join(getShipyardHome(), 'logs');\nif (attachFileTransport) {\n mkdirSync(logDir, { recursive: true, mode: 0o700 });\n void cleanOldLogs(logDir);\n}\n\nconst logFilePath = join(logDir, 'daemon.log');\n\n/** Exposed for output.ts to append CLI output to the same log file. */\nexport function getLogFilePath(): string {\n return logFilePath;\n}\n\nconst isDev = process.env.NODE_ENV !== 'production';\nconst level = validateEnv().LOG_LEVEL;\n\nconst transport = pino.transport({\n targets: [\n ...(isDev\n ? [{ target: 'pino-pretty', options: { colorize: true }, level }]\n : [{ target: 'pino/file', options: { destination: 1 }, level }]),\n ...(attachFileTransport\n ? [\n {\n target: 'pino-roll',\n options: {\n file: logFilePath,\n /*\n * Size-based rotation (not frequency-based): pino-roll's daily frequency\n * uses birthtime filtering in detectLastNumber, which causes every daemon\n * restart to re-open daemon.log.1 (old files predate today's midnight).\n * Without a frequency, detectLastNumber has no time filter and correctly\n * identifies the highest-numbered existing file to continue writing there.\n */\n size: '100m',\n // NOTE: per-session cap only — cross-restart retention is owned by cleanOldLogs above\n limit: { count: 7 },\n mkdir: true,\n },\n level,\n },\n ]\n : []),\n ],\n});\n\n/**\n * Pino's error serializer only triggers on the `err` key (not `error`).\n * Always use `{ err: myError }` when logging Error objects.\n * See: https://github.com/pinojs/pino/issues/895\n */\nexport const logger = pino({ level }, transport);\n\nexport function createChildLogger(context: { taskId?: string; sessionId?: string; mode?: string }) {\n return logger.child(context);\n}\n\n/**\n * Flush pino's async transport buffer and wait for it to drain.\n * Must be called before process.exit() to avoid losing buffered log entries.\n * Times out after the given ms to avoid hanging on a stuck transport.\n */\nexport function flushLogger(timeoutMs = 2_000): Promise<void> {\n return new Promise<void>((resolve) => {\n const timer = setTimeout(resolve, timeoutMs);\n logger.flush((err) => {\n clearTimeout(timer);\n if (err) {\n /** Best-effort: if flush fails, we still exit */\n process.stderr.write(`Logger flush error: ${err.message}\\n`);\n }\n resolve();\n });\n });\n}\n"],"mappings":";;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,MAAM,cAAc;AACtC,SAAS,YAAY;AACrB,OAAO,UAAU;AAIV,SAAS,0BAA0B,KAAsD;AAC9F,MAAI,IAAI,WAAW,QAAW;AAC5B,WAAO;AAAA,EACT;AACA,MAAI,IAAI,aAAa,QAAQ;AAC3B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,qBAAqB;AAOpB,SAAS,oBAAoB,UAAkB,SAAiB,OAAwB;AAC7F,MAAI,CAAC,qBAAqB,KAAK,QAAQ,EAAG,QAAO;AACjD,SAAO,UAAU,QAAQ,qBAAqB,KAAK,KAAK,KAAK;AAC/D;AAEA,eAAe,aAAa,KAA4B;AACtD,MAAI;AACF,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,QAAQ,MAAM,QAAQ,GAAG;AAC/B,UAAM,UAAU,MAAM,OAAO,CAAC,SAAS,qBAAqB,KAAK,IAAI,CAAC;AAMtE,UAAM,UAAU,CAAC,SAAyB,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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAQN,MAAM;AAAA;AAAA,UAEN,OAAO,EAAE,OAAO,EAAE;AAAA,UAClB,OAAO;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACF,CAAC;AAOM,IAAM,SAAS,KAAK,EAAE,MAAM,GAAG,SAAS;AAExC,SAAS,kBAAkB,SAAiE;AACjG,SAAO,OAAO,MAAM,OAAO;AAC7B;AAOO,SAAS,YAAY,YAAY,KAAsB;AAC5D,SAAO,IAAI,QAAc,CAAC,YAAY;AACpC,UAAM,QAAQ,WAAW,SAAS,SAAS;AAC3C,WAAO,MAAM,CAAC,QAAQ;AACpB,mBAAa,KAAK;AAClB,UAAI,KAAK;AAEP,gBAAQ,OAAO,MAAM,uBAAuB,IAAI,OAAO;AAAA,CAAI;AAAA,MAC7D;AACA,cAAQ;AAAA,IACV,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -441,6 +441,23 @@ var RunnerToDaemonSchema = external_exports.discriminatedUnion("kind", [
|
|
|
441
441
|
generation: external_exports.number().int().nonnegative(),
|
|
442
442
|
sessionId: external_exports.string()
|
|
443
443
|
}),
|
|
444
|
+
/**
|
|
445
|
+
* Runner→daemon liveness edge for in-flight tool execution. Emitted only
|
|
446
|
+
* on the 0→1 transition (first tool call started, phase `'started'`) and
|
|
447
|
+
* the 1→0 transition (last tool call completed, phase `'settled'`). Drives
|
|
448
|
+
* the daemon's `toolExecutionStallTimeoutMs` window: when a tool is
|
|
449
|
+
* in-flight the stall watchdog uses the extended per-tool budget so a
|
|
450
|
+
* legitimate long-running tool (e.g. `git commit` with a full `pnpm check`
|
|
451
|
+
* pre-commit hook, 3–10 min) is not false-killed. On settle the watchdog
|
|
452
|
+
* reverts to the shorter mid-run window. Stale-generation filtering applies.
|
|
453
|
+
*
|
|
454
|
+
* Daemon↔forked-child IPC only — NOT the browser wire. No PROTOCOL_VERSION bump.
|
|
455
|
+
*/
|
|
456
|
+
external_exports.object({
|
|
457
|
+
kind: external_exports.literal("tool_execution"),
|
|
458
|
+
generation: external_exports.number().int().nonnegative(),
|
|
459
|
+
phase: external_exports.enum(["started", "settled"])
|
|
460
|
+
}),
|
|
444
461
|
/**
|
|
445
462
|
* Warm-pool reinit succeeded (C9). The runner created a fresh Agent for the
|
|
446
463
|
* claimed task on the warm executor. `sessionId` is the new `agent.agentId`
|
|
@@ -486,4 +503,4 @@ export {
|
|
|
486
503
|
parseDaemonToRunner,
|
|
487
504
|
parseRunnerToDaemon
|
|
488
505
|
};
|
|
489
|
-
//# sourceMappingURL=chunk-
|
|
506
|
+
//# sourceMappingURL=chunk-LZSMNUAI.js.map
|