claude-code-session-manager 0.86.0 → 0.88.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 (335) hide show
  1. package/README.md +26 -53
  2. package/dist/assets/AgentLibrary-BZ6IY2g1.js +3 -0
  3. package/dist/assets/{DataModel-Q4jhl24R.js → DataModel-dAoGAODX.js} +1 -1
  4. package/dist/assets/{History-Cj2FejEo.js → History-CF157HyX.js} +2 -2
  5. package/dist/assets/{Hooks-CaelQI6t.js → Hooks-CCPPipBk.js} +3 -3
  6. package/dist/assets/{HostBilko--v7cMR8I.js → HostBilko-Dlmz2m06.js} +1 -1
  7. package/dist/assets/{Library-DgI9oCCZ.js → Library-BaXcboWX.js} +1 -1
  8. package/dist/assets/{ListDetail-DYUZN-x-.js → ListDetail-CoUCzG5S.js} +1 -1
  9. package/dist/assets/MarkdownEditor-DTg3JlOT.js +1 -0
  10. package/dist/assets/{McpServers-ypCYURh3.js → McpServers-DdjY1sA3.js} +2 -2
  11. package/dist/assets/{Memory-C2qYp-3M.js → Memory-BJ3Jlw0C.js} +4 -4
  12. package/dist/assets/{Panel-Cj2kw-Zv.js → Panel-ygRSgc41.js} +1 -1
  13. package/dist/assets/Permissions-m0KAnccF.js +3 -0
  14. package/dist/assets/{Plugins-C1Vj8_dU.js → Plugins-CJRl6B3Q.js} +2 -2
  15. package/dist/assets/{ProvenanceBadge-DczPNM5U.js → ProvenanceBadge-w8cnlVvW.js} +1 -1
  16. package/dist/assets/{SaveBar-Cd_7U6Gb.js → SaveBar-BpyPcUIk.js} +1 -1
  17. package/dist/assets/Scheduler-D2ppxSfy.js +14 -0
  18. package/dist/assets/{ScopeSwitcher-DVSyI44-.js → ScopeSwitcher-EyuIwt-j.js} +1 -1
  19. package/dist/assets/Settings-BHSGGFEc.js +3 -0
  20. package/dist/assets/{SkillReferenceGraph-CUv1_Q2c.js → SkillReferenceGraph-BNaZ2JCF.js} +1 -1
  21. package/dist/assets/{Skills-C_YHkAy-.js → Skills-Dl3q75QV.js} +2 -2
  22. package/dist/assets/{SystemPrompt-B8R7T9xn.js → SystemPrompt-Bg6F-Cyp.js} +1 -1
  23. package/dist/assets/{TagLibrary-dj9YHWyy.js → TagLibrary-BSutflCy.js} +1 -1
  24. package/dist/assets/{TiptapBody-DnSBUjHE.js → TiptapBody-CXih4xrc.js} +1 -1
  25. package/dist/assets/{Toggle-CjV_BJn6.js → Toggle-2qtUHhA9.js} +1 -1
  26. package/dist/assets/{index-CXFQIPhO.js → index-B3emy2oI.js} +583 -583
  27. package/dist/assets/{index-CDo9xBR9.css → index-BHTX4OTc.css} +1 -1
  28. package/dist/assets/settingsSchema-CdzxaqwM.js +3 -0
  29. package/dist/assets/{whisperWorker-Dbia1OpC.js → whisperWorker-C7ZGQwKg.js} +7 -7
  30. package/dist/index.html +2 -2
  31. package/dist/vad/ort-wasm-simd-threaded.asyncify.mjs +106 -110
  32. package/dist/vad/ort-wasm-simd-threaded.asyncify.wasm +0 -0
  33. package/dist/vad/ort-wasm-simd-threaded.jsep.mjs +98 -98
  34. package/dist/vad/ort-wasm-simd-threaded.jsep.wasm +0 -0
  35. package/dist/vad/ort-wasm-simd-threaded.jspi.mjs +99 -102
  36. package/dist/vad/ort-wasm-simd-threaded.jspi.wasm +0 -0
  37. package/dist/vad/ort-wasm-simd-threaded.mjs +46 -46
  38. package/dist/vad/ort-wasm-simd-threaded.wasm +0 -0
  39. package/package.json +14 -17
  40. package/plugins/CLAUDE.md +61 -0
  41. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  42. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +1 -1
  43. package/plugins/session-manager-dev/skills/ops-sweep/SKILL.md +1 -1
  44. package/scripts/README.md +59 -0
  45. package/scripts/audit-ops-hygiene.cjs +350 -0
  46. package/scripts/hooks/guard-destructive-git.cjs +10 -34
  47. package/scripts/hooks/guard-inline-implementation.cjs +14 -8
  48. package/scripts/hooks/guard-prd-writes.cjs +7 -36
  49. package/scripts/hooks/guard-self-schedule.cjs +175 -0
  50. package/scripts/ops-sweep.cjs +355 -0
  51. package/scripts/scheduler-mcp-server.cjs +35 -71
  52. package/src/main/__tests__/agentModelResolve.test.cjs +100 -9
  53. package/src/main/__tests__/bilkoHost-integration.test.cjs +3 -3
  54. package/src/main/__tests__/broadcastCoalescer.test.cjs +18 -0
  55. package/src/main/__tests__/chat-cancel-terminal.test.cjs +6 -9
  56. package/src/main/__tests__/chat-exit-close-race.test.cjs +3 -3
  57. package/src/main/__tests__/chat-mcp-consent-notice.test.cjs +4 -5
  58. package/src/main/__tests__/chat-queue.test.cjs +2 -2
  59. package/src/main/__tests__/chat-stop-signal.test.cjs +2 -2
  60. package/src/main/__tests__/dep-orphan-archive-health.test.cjs +77 -0
  61. package/src/main/__tests__/dod-batchkey.test.cjs +2 -2
  62. package/src/main/__tests__/dod-drain-hook.test.cjs +2 -2
  63. package/src/main/__tests__/dod-report.test.cjs +2 -2
  64. package/src/main/__tests__/dod-reverify.test.cjs +2 -2
  65. package/src/main/__tests__/epicMint.test.cjs +4 -4
  66. package/src/main/__tests__/exchanges.test.cjs +2 -2
  67. package/src/main/__tests__/extractJson.test.cjs +2 -2
  68. package/src/main/__tests__/files-reject-credentials.test.cjs +1 -1
  69. package/src/main/__tests__/fixtures/1218-fo-01-move-scripts-lib-into-src-main-lib.log +556 -0
  70. package/src/main/__tests__/health-build-freshness.test.cjs +39 -0
  71. package/src/main/__tests__/health-delegation-chain.test.cjs +17 -2
  72. package/src/main/__tests__/health-queue-dispatch.test.cjs +58 -7
  73. package/src/main/__tests__/health-tick-liveness.test.cjs +11 -3
  74. package/src/main/__tests__/health-usage-poller.test.cjs +70 -23
  75. package/src/main/__tests__/historyRollup.test.cjs +2 -2
  76. package/src/main/__tests__/kg-augment.test.cjs +2 -2
  77. package/src/main/__tests__/mcpStatus.test.cjs +2 -2
  78. package/src/main/__tests__/memoryAggregate.test.cjs +1 -1
  79. package/src/main/__tests__/memoryStale.test.cjs +1 -1
  80. package/src/main/__tests__/needsReviewLedger.test.cjs +162 -0
  81. package/src/main/__tests__/opsErrorLogTelemetryTap.test.cjs +28 -4
  82. package/src/main/__tests__/pollLoop-dispatch-on-failure.test.cjs +48 -4
  83. package/src/main/__tests__/prd-group-allocator.test.cjs +2 -2
  84. package/src/main/__tests__/prdAdminRouteParity.test.cjs +2 -0
  85. package/src/main/__tests__/prdAdminRoutes.test.cjs +14 -2
  86. package/src/main/__tests__/prdAuthoringSeed.test.cjs +39 -0
  87. package/src/main/__tests__/prdCreateDisposition.test.cjs +201 -0
  88. package/src/main/__tests__/prdFrontmatterDisposition.test.cjs +125 -0
  89. package/src/main/__tests__/prdLocations.test.cjs +100 -2
  90. package/src/main/__tests__/prdLocationsArchived.test.cjs +50 -1
  91. package/src/main/__tests__/prdSetDisposition.test.cjs +222 -0
  92. package/src/main/__tests__/proc-role-env.test.cjs +125 -0
  93. package/src/main/__tests__/procname-claude-spawn-sites.test.cjs +304 -0
  94. package/src/main/__tests__/procname-sm-processes.test.cjs +127 -0
  95. package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +81 -401
  96. package/src/main/__tests__/projectPages.test.cjs +63 -149
  97. package/src/main/__tests__/queue-health-verdict.test.cjs +170 -0
  98. package/src/main/__tests__/queue-starvation-dispatch-driver.test.cjs +117 -20
  99. package/src/main/__tests__/queue-starvation-per-project.test.cjs +14 -2
  100. package/src/main/__tests__/queueHistory.test.cjs +65 -2
  101. package/src/main/__tests__/rateLimitPollerStreak.test.cjs +38 -3
  102. package/src/main/__tests__/reconcileTiming.test.cjs +135 -0
  103. package/src/main/__tests__/runVerify-landed-commit-outranks.test.cjs +181 -0
  104. package/src/main/__tests__/runVerify.test.cjs +5 -5
  105. package/src/main/__tests__/scheduleJobStatusDrift.test.cjs +3 -3
  106. package/src/main/__tests__/scheduleJobTransitions.test.cjs +103 -3
  107. package/src/main/__tests__/scheduler-adopted-run-supervision.test.cjs +143 -0
  108. package/src/main/__tests__/scheduler-autofix-select.test.cjs +2 -2
  109. package/src/main/__tests__/scheduler-autopromote.test.cjs +2 -2
  110. package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +3 -5
  111. package/src/main/__tests__/scheduler-boot-orphans.test.cjs +79 -98
  112. package/src/main/__tests__/scheduler-broadcast-reconcile.test.cjs +121 -0
  113. package/src/main/__tests__/scheduler-cross-project-batch.test.cjs +43 -0
  114. package/src/main/__tests__/scheduler-default-eligible-heal.test.cjs +161 -0
  115. package/src/main/__tests__/scheduler-dispatch-loop.test.cjs +58 -0
  116. package/src/main/__tests__/scheduler-epic-digest.test.cjs +3 -5
  117. package/src/main/__tests__/scheduler-force-tick-outcome.test.cjs +2 -2
  118. package/src/main/__tests__/scheduler-gate-shadow.test.cjs +119 -0
  119. package/src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs +390 -0
  120. package/src/main/__tests__/scheduler-heartbeat-payload.test.cjs +80 -0
  121. package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +25 -18
  122. package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +4 -4
  123. package/src/main/__tests__/scheduler-job-budget.test.cjs +172 -0
  124. package/src/main/__tests__/scheduler-launch-failure.test.cjs +3 -5
  125. package/src/main/__tests__/scheduler-looks-done.test.cjs +119 -10
  126. package/src/main/__tests__/scheduler-manual-pause.test.cjs +118 -0
  127. package/src/main/__tests__/scheduler-meta-code-sha.test.cjs +26 -3
  128. package/src/main/__tests__/scheduler-porcelain-rename.test.cjs +164 -0
  129. package/src/main/__tests__/scheduler-prd-missing-skip.test.cjs +17 -2
  130. package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +3 -5
  131. package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +41 -6
  132. package/src/main/__tests__/scheduler-rate-limit-pause.test.cjs +62 -6
  133. package/src/main/__tests__/scheduler-rate-limit-spin-guard.test.cjs +3 -5
  134. package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +182 -3
  135. package/src/main/__tests__/scheduler-reaper-helpers-basics.test.cjs +87 -0
  136. package/src/main/__tests__/scheduler-reconcile-cwd-preserve.test.cjs +100 -0
  137. package/src/main/__tests__/scheduler-reconcile-invalid-repair.test.cjs +3 -3
  138. package/src/main/__tests__/scheduler-reconcile-quarantine.test.cjs +4 -4
  139. package/src/main/__tests__/scheduler-shard-quarantine.test.cjs +110 -0
  140. package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +168 -0
  141. package/src/main/__tests__/scheduler-starve-escalation.test.cjs +18 -8
  142. package/src/main/__tests__/scheduler-stranded-autofix-park.test.cjs +245 -0
  143. package/src/main/__tests__/scheduler-supervisor-record.test.cjs +81 -0
  144. package/src/main/__tests__/scheduler-tick-cancel-token.test.cjs +2 -2
  145. package/src/main/__tests__/scheduler-tick-wedge.test.cjs +172 -0
  146. package/src/main/__tests__/scheduler-transient-failure.test.cjs +2 -2
  147. package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +51 -11
  148. package/src/main/__tests__/scheduler-worktree-exec-cwd.test.cjs +3 -5
  149. package/src/main/__tests__/usageSingleFlight.test.cjs +157 -0
  150. package/src/main/__tests__/workTypeLibrary.test.cjs +1 -1
  151. package/src/main/bilkoHost.cjs +16 -7
  152. package/src/main/build-info.json +8 -0
  153. package/src/main/chatRunner.cjs +12 -7
  154. package/src/main/config.cjs +2 -3
  155. package/src/main/docEdit.cjs +4 -2
  156. package/src/main/health.cjs +268 -52
  157. package/src/main/heapSnapshot.cjs +2 -2
  158. package/src/main/historyAggregator.cjs +6 -1
  159. package/src/main/index.cjs +152 -50
  160. package/src/main/ipcSchemas.cjs +53 -17
  161. package/src/main/lib/__tests__/active-sessions.test.cjs +251 -0
  162. package/src/main/lib/__tests__/auditLog.test.cjs +38 -0
  163. package/src/main/lib/__tests__/bootSelfHeal.test.cjs +107 -0
  164. package/src/main/lib/__tests__/buildIdentity.test.cjs +121 -0
  165. package/src/main/lib/__tests__/cwdClassify.test.cjs +111 -0
  166. package/src/main/lib/__tests__/definitionOfDoneSequence.test.cjs +95 -0
  167. package/src/main/lib/__tests__/delegationReadiness.test.cjs +323 -44
  168. package/src/main/lib/__tests__/dispatchLoop.test.cjs +63 -0
  169. package/src/main/lib/__tests__/effectiveModelInfo.test.cjs +239 -0
  170. package/src/main/lib/__tests__/gateFixtures.json +20 -0
  171. package/src/main/lib/__tests__/gitWorktree.test.cjs +97 -1
  172. package/src/main/lib/__tests__/guardShims.test.cjs +151 -0
  173. package/src/main/lib/__tests__/instanceLock.test.cjs +93 -7
  174. package/src/main/lib/__tests__/jobSupervisorRecord.test.cjs +78 -0
  175. package/src/main/lib/__tests__/jobWorktreeBootLive.test.cjs +11 -0
  176. package/src/main/lib/__tests__/localAdminHttp.test.cjs +1 -1
  177. package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +6 -1
  178. package/src/main/lib/__tests__/opsRootAbsoluteCwd.test.cjs +5 -5
  179. package/src/main/lib/__tests__/prdDisposition.test.cjs +224 -0
  180. package/src/main/lib/__tests__/procIdentity.test.cjs +119 -0
  181. package/src/main/lib/__tests__/procName.test.cjs +92 -0
  182. package/src/main/lib/__tests__/queueStoreMachineStateRecovery.test.cjs +67 -0
  183. package/src/main/lib/__tests__/reaperHelpers.test.cjs +179 -1
  184. package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +6 -7
  185. package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +37 -204
  186. package/src/main/lib/__tests__/schedulerPaths.test.cjs +226 -0
  187. package/src/main/lib/__tests__/schedulerPathsWorktree.test.cjs +94 -0
  188. package/src/main/lib/__tests__/schedulerRuntimeState.test.cjs +56 -0
  189. package/src/main/lib/__tests__/sessionSlots.test.cjs +45 -0
  190. package/src/main/lib/__tests__/telemetryBacklog.test.cjs +1 -1
  191. package/src/main/lib/__tests__/upgradeDrain.test.cjs +130 -0
  192. package/src/main/lib/__tests__/usageCircuit.test.cjs +285 -0
  193. package/src/main/lib/__tests__/watchdog-helpers.test.cjs +375 -0
  194. package/src/main/lib/__tests__/watchdog-relaunch.test.cjs +266 -0
  195. package/src/main/lib/activeIndexRebuild.cjs +1 -3
  196. package/{scripts → src/main}/lib/activeSessions.cjs +67 -89
  197. package/src/main/lib/adoptedRunSupervisor.cjs +136 -0
  198. package/src/main/lib/agentModelResolve.cjs +94 -24
  199. package/src/main/lib/agentPersonaSchema.cjs +2 -2
  200. package/src/main/lib/auditLog.cjs +30 -5
  201. package/src/main/lib/bootSelfHeal.cjs +88 -0
  202. package/src/main/lib/buildIdentity.cjs +113 -0
  203. package/src/main/lib/classifyPromptTicket.cjs +3 -2
  204. package/src/main/lib/claudeBin.cjs +37 -2
  205. package/src/main/lib/cleanEnv.cjs +27 -1
  206. package/src/main/lib/credentials.cjs +4 -2
  207. package/src/main/lib/cwdClassify.cjs +185 -0
  208. package/src/main/lib/definitionOfDone.cjs +296 -52
  209. package/src/main/lib/delegationReadiness.cjs +290 -225
  210. package/src/main/lib/dispatchLoop.cjs +40 -0
  211. package/src/main/lib/effectiveModelInfo.cjs +332 -0
  212. package/src/main/lib/ephemeralCwd.cjs +7 -28
  213. package/src/main/lib/epicMint.cjs +3 -3
  214. package/src/main/lib/gitWorktree.cjs +136 -19
  215. package/src/main/lib/guardShims.cjs +156 -0
  216. package/src/main/lib/historyRollup.cjs +6 -7
  217. package/src/main/lib/instanceLock.cjs +32 -5
  218. package/src/main/lib/jobDirtFilter.cjs +7 -2
  219. package/src/main/lib/jobSupervisorRecord.cjs +147 -0
  220. package/src/main/lib/jobWorktreeBootLive.cjs +9 -5
  221. package/src/main/lib/launchFailure.cjs +2 -1
  222. package/src/main/lib/localAdminHttp.cjs +9 -27
  223. package/src/main/lib/mcpToolCatalog.cjs +33 -78
  224. package/src/main/lib/needsReviewLedger.cjs +205 -0
  225. package/src/main/lib/opsErrorLog.cjs +1 -1
  226. package/src/main/lib/opsOwnership.cjs +27 -19
  227. package/src/main/lib/prdAuthoringSeed.cjs +36 -0
  228. package/src/main/lib/prdCreate.cjs +56 -1
  229. package/src/main/lib/prdDisposition.cjs +199 -0
  230. package/src/main/lib/prdFrontmatter.cjs +8 -2
  231. package/src/main/lib/prdLocations.cjs +214 -45
  232. package/src/main/lib/procIdentity.cjs +126 -0
  233. package/src/main/lib/procName.cjs +98 -0
  234. package/src/main/lib/projectHomeAdminRoutes.cjs +56 -327
  235. package/src/main/lib/projectRootResolve.cjs +1 -1
  236. package/src/main/lib/queueHistory.cjs +27 -8
  237. package/src/main/lib/queueStore.cjs +63 -38
  238. package/src/main/lib/quietMachineLease.cjs +19 -2
  239. package/src/main/lib/reaperHelpers.cjs +181 -15
  240. package/src/main/lib/reservationExpiry.cjs +30 -0
  241. package/src/main/lib/runClaudeP.cjs +4 -2
  242. package/src/main/lib/runLogRetention.cjs +3 -2
  243. package/src/main/lib/scheduleJobSchema.cjs +10 -2
  244. package/src/main/lib/scheduleJobTransitions.cjs +60 -0
  245. package/src/main/lib/schedulerBatch.cjs +27 -2
  246. package/src/main/lib/schedulerConfig.cjs +24 -0
  247. package/src/main/lib/schedulerPaths.cjs +175 -0
  248. package/src/main/lib/schedulerRuntimeState.cjs +59 -0
  249. package/src/main/lib/sessionSlots.cjs +47 -9
  250. package/src/main/lib/smProcNames.cjs +51 -0
  251. package/src/main/lib/upgradeDrain.cjs +188 -0
  252. package/src/main/lib/usageCircuit.cjs +206 -0
  253. package/{scripts → src/main}/lib/watchdogHelpers.cjs +71 -38
  254. package/src/main/lib/withTimeout.cjs +33 -0
  255. package/src/main/mcpStatus.cjs +4 -2
  256. package/src/main/pluginInstall.cjs +6 -2
  257. package/src/main/projectPages.cjs +41 -145
  258. package/src/main/pty.cjs +8 -1
  259. package/src/main/queueOps.cjs +10 -10
  260. package/src/main/runVerify.cjs +69 -3
  261. package/src/main/scheduler/prdParser.cjs +13 -0
  262. package/src/main/scheduler.cjs +2841 -482
  263. package/src/main/seedAgentPersonas.cjs +1 -1
  264. package/src/main/seedDevPlugin.cjs +1 -1
  265. package/src/main/seedSchedulerMcp.cjs +7 -6
  266. package/src/main/seedStatus.cjs +1 -1
  267. package/src/main/supervisor.cjs +5 -3
  268. package/src/main/templates/PRD_AUTHORING.md +50 -0
  269. package/src/main/usage.cjs +140 -58
  270. package/src/preload/api.d.ts +110 -65
  271. package/src/preload/index.cjs +12 -4
  272. package/src/seed/agents/project-home-builder.md +31 -48
  273. package/dist/assets/AgentLibrary-DTFL7y8G.js +0 -3
  274. package/dist/assets/MarkdownEditor-DCIubYWf.js +0 -1
  275. package/dist/assets/Permissions-BiYZNGYW.js +0 -3
  276. package/dist/assets/Scheduler-DcLBiJBq.js +0 -14
  277. package/dist/assets/Settings-Cv-pRyms.js +0 -3
  278. package/dist/assets/settingsSchema-BJVciriw.js +0 -3
  279. package/screenshots/.gitkeep +0 -0
  280. package/screenshots/README-screenshots.md +0 -13
  281. package/scripts/project-pages-logic/dist/logic.cjs +0 -4709
  282. package/scripts/render-project-pages/dist/renderer.cjs +0 -18900
  283. package/scripts/render-project-pages.cjs +0 -70
  284. package/scripts/validate-project-pages-summary.cjs +0 -62
  285. package/src/main/lib/projectPageSummarySchema.cjs +0 -181
  286. package/src/main/teams.cjs +0 -95
  287. package/src/main/templates/project-pages-catalog.json +0 -741
  288. package/src/main/templates/project-pages-default-home.html +0 -123
  289. package/src/main/templates/project-pages-pipeline.md +0 -417
  290. package/src/seed/prompts/code-review/ac-coverage-check.md +0 -8
  291. package/src/seed/prompts/code-review/correctness-only.md +0 -8
  292. package/src/seed/prompts/code-review/full-spectrum-high.md +0 -8
  293. package/src/seed/prompts/code-review/hallucination-check.md +0 -8
  294. package/src/seed/prompts/code-review/public-api-compat.md +0 -8
  295. package/src/seed/prompts/code-review/readability-naming.md +0 -8
  296. package/src/seed/prompts/debugging/bug-as-failing-test.md +0 -8
  297. package/src/seed/prompts/debugging/git-bisect-regression.md +0 -8
  298. package/src/seed/prompts/debugging/instrument-intermittent-bug.md +0 -8
  299. package/src/seed/prompts/debugging/localize-pipeline-failure.md +0 -8
  300. package/src/seed/prompts/debugging/reproduce-then-diagnose.md +0 -8
  301. package/src/seed/prompts/documentation/adr-from-change.md +0 -8
  302. package/src/seed/prompts/documentation/module-readme.md +0 -8
  303. package/src/seed/prompts/documentation/onboarding-plan.md +0 -8
  304. package/src/seed/prompts/documentation/refresh-claude-md.md +0 -8
  305. package/src/seed/prompts/documentation/tsdoc-public-exports.md +0 -8
  306. package/src/seed/prompts/git-pr/conventional-commit.md +0 -8
  307. package/src/seed/prompts/git-pr/draft-pr-title-body.md +0 -8
  308. package/src/seed/prompts/git-pr/pre-commit-safety-sweep.md +0 -8
  309. package/src/seed/prompts/git-pr/release-notes-block.md +0 -8
  310. package/src/seed/prompts/git-pr/split-large-pr.md +0 -8
  311. package/src/seed/prompts/performance/bundle-startup-audit.md +0 -8
  312. package/src/seed/prompts/performance/complexity-audit.md +0 -8
  313. package/src/seed/prompts/performance/cpu-profile-hot-path.md +0 -8
  314. package/src/seed/prompts/performance/db-query-plan-review.md +0 -8
  315. package/src/seed/prompts/performance/memory-leak-hunt.md +0 -8
  316. package/src/seed/prompts/qa/api-contract-tests.md +0 -8
  317. package/src/seed/prompts/qa/e2e-critical-path.md +0 -8
  318. package/src/seed/prompts/qa/failing-test-for-bug.md +0 -8
  319. package/src/seed/prompts/qa/find-missing-test-coverage.md +0 -8
  320. package/src/seed/prompts/qa/stabilize-flaky-test.md +0 -8
  321. package/src/seed/prompts/qa/tdd-red-first.md +0 -8
  322. package/src/seed/prompts/qa/visual-regression-review.md +0 -8
  323. package/src/seed/prompts/qa/wcag-axe-scan.md +0 -8
  324. package/src/seed/prompts/refactoring/dead-code-sweep.md +0 -8
  325. package/src/seed/prompts/refactoring/extract-duplicated-pattern.md +0 -8
  326. package/src/seed/prompts/refactoring/modernize-legacy-file.md +0 -8
  327. package/src/seed/prompts/refactoring/reduce-cyclomatic-complexity.md +0 -8
  328. package/src/seed/prompts/refactoring/tighten-module-boundaries.md +0 -8
  329. package/src/seed/prompts/security/authz-audit.md +0 -8
  330. package/src/seed/prompts/security/crypto-correctness.md +0 -8
  331. package/src/seed/prompts/security/cwe-top-25-hunt.md +0 -8
  332. package/src/seed/prompts/security/dependency-audit.md +0 -8
  333. package/src/seed/prompts/security/ipc-boundary-hardening.md +0 -8
  334. package/src/seed/prompts/security/owasp-top-10-staged-diff.md +0 -8
  335. package/src/seed/prompts/security/secret-credential-scan.md +0 -8
@@ -0,0 +1,375 @@
1
+ 'use strict';
2
+
3
+ // Run: timeout 120 npx vitest run src/main/lib/__tests__/watchdog-helpers.test.cjs
4
+
5
+ const assert = require('node:assert/strict');
6
+ const fs = require('node:fs');
7
+ const os = require('node:os');
8
+ const path = require('node:path');
9
+ const {
10
+ heartbeatFresh,
11
+ evaluateDispatchLiveness,
12
+ readLastHeartbeat,
13
+ localDateStr,
14
+ maybeFinalizeHistory,
15
+ tryAcquireLock,
16
+ releaseLock,
17
+ } = require('../watchdogHelpers.cjs');
18
+
19
+ function tmpFile() {
20
+ return path.join(os.tmpdir(), `watchdog-test-${process.pid}-${Math.floor(Math.random() * 1e9)}.log`);
21
+ }
22
+
23
+ function tmpDir() {
24
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'watchdog-history-test-'));
25
+ }
26
+
27
+ function writeLines(p, lines) {
28
+ fs.writeFileSync(p, lines.join('\n') + '\n');
29
+ }
30
+
31
+ test('fresh ts (just now) → true', () => {
32
+ const p = tmpFile();
33
+ try {
34
+ writeLines(p, [JSON.stringify({ ts: Date.now(), counts: {}, paused: null })]);
35
+ assert.equal(heartbeatFresh(p, 180_000), true);
36
+ } finally {
37
+ try { fs.unlinkSync(p); } catch {}
38
+ }
39
+ });
40
+
41
+ test('stale ts (10 min old) → false', () => {
42
+ const p = tmpFile();
43
+ try {
44
+ const staleTs = Date.now() - 10 * 60 * 1000;
45
+ writeLines(p, [JSON.stringify({ ts: staleTs, counts: {}, paused: null })]);
46
+ assert.equal(heartbeatFresh(p, 180_000), false);
47
+ } finally {
48
+ try { fs.unlinkSync(p); } catch {}
49
+ }
50
+ });
51
+
52
+ test('missing file → false', () => {
53
+ const p = path.join(os.tmpdir(), 'watchdog-test-nonexistent-999999.log');
54
+ assert.equal(heartbeatFresh(p, 180_000), false);
55
+ });
56
+
57
+ test('garbage last line → false', () => {
58
+ const p = tmpFile();
59
+ try {
60
+ writeLines(p, ['not json at all!!!']);
61
+ assert.equal(heartbeatFresh(p, 180_000), false);
62
+ } finally {
63
+ try { fs.unlinkSync(p); } catch {}
64
+ }
65
+ });
66
+
67
+ test('last non-empty line wins (fresh after stale)', () => {
68
+ const p = tmpFile();
69
+ try {
70
+ const staleTs = Date.now() - 10 * 60 * 1000;
71
+ writeLines(p, [
72
+ JSON.stringify({ ts: staleTs }),
73
+ JSON.stringify({ ts: Date.now() }),
74
+ ]);
75
+ assert.equal(heartbeatFresh(p, 180_000), true);
76
+ } finally {
77
+ try { fs.unlinkSync(p); } catch {}
78
+ }
79
+ });
80
+
81
+ test('empty file → false', () => {
82
+ const p = tmpFile();
83
+ try {
84
+ fs.writeFileSync(p, '');
85
+ assert.equal(heartbeatFresh(p, 180_000), false);
86
+ } finally {
87
+ try { fs.unlinkSync(p); } catch {}
88
+ }
89
+ });
90
+
91
+ test('JSON line without ts field → false', () => {
92
+ const p = tmpFile();
93
+ try {
94
+ writeLines(p, [JSON.stringify({ counts: {}, paused: null })]);
95
+ assert.equal(heartbeatFresh(p, 180_000), false);
96
+ } finally {
97
+ try { fs.unlinkSync(p); } catch {}
98
+ }
99
+ });
100
+
101
+ // ── readLastHeartbeat ─────────────────────────────────────────────────────────
102
+
103
+ test('readLastHeartbeat: returns full parsed object including pid', () => {
104
+ const p = tmpFile();
105
+ try {
106
+ const entry = { ts: Date.now(), pid: 12345, counts: {}, paused: null };
107
+ writeLines(p, [JSON.stringify(entry)]);
108
+ const result = readLastHeartbeat(p);
109
+ assert.equal(result.ts, entry.ts);
110
+ assert.equal(result.pid, 12345);
111
+ } finally {
112
+ try { fs.unlinkSync(p); } catch {}
113
+ }
114
+ });
115
+
116
+ test('readLastHeartbeat: returns null for missing file', () => {
117
+ const p = path.join(os.tmpdir(), 'watchdog-helpers-test-nonexistent-999999.log');
118
+ assert.equal(readLastHeartbeat(p), null);
119
+ });
120
+
121
+ test('readLastHeartbeat: returns null for empty file', () => {
122
+ const p = tmpFile();
123
+ try {
124
+ fs.writeFileSync(p, '');
125
+ assert.equal(readLastHeartbeat(p), null);
126
+ } finally {
127
+ try { fs.unlinkSync(p); } catch {}
128
+ }
129
+ });
130
+
131
+ test('readLastHeartbeat: returns object without pid for legacy entry', () => {
132
+ const p = tmpFile();
133
+ try {
134
+ const staleTs = Date.now() - 10 * 60 * 1000;
135
+ writeLines(p, [JSON.stringify({ ts: staleTs, counts: {}, paused: null })]);
136
+ const result = readLastHeartbeat(p);
137
+ assert.ok(result !== null);
138
+ assert.equal(result.ts, staleTs);
139
+ assert.equal(result.pid, undefined);
140
+ } finally {
141
+ try { fs.unlinkSync(p); } catch {}
142
+ }
143
+ });
144
+
145
+ // ── maybeFinalizeHistory: stamp gate ─────────────────────────────────────────
146
+
147
+ test('maybeFinalizeHistory: same-day stamp → skip in O(1), finalizeFn never called', async () => {
148
+ const dir = tmpDir();
149
+ try {
150
+ const stampPath = path.join(dir, 'history-rollup.stamp');
151
+ const lockPath = path.join(dir, 'history-rollup.lock');
152
+ fs.writeFileSync(stampPath, localDateStr(), 'utf8');
153
+ let called = false;
154
+ const result = await maybeFinalizeHistory({
155
+ stampPath,
156
+ lockPath,
157
+ finalizeFn: async () => { called = true; return { finalizedDates: [], partial: false }; },
158
+ });
159
+ assert.equal(called, false);
160
+ assert.equal(result.ran, false);
161
+ assert.equal(result.reason, 'already-finalized-today');
162
+ } finally {
163
+ fs.rmSync(dir, { recursive: true, force: true });
164
+ }
165
+ });
166
+
167
+ test('maybeFinalizeHistory: new day (stale/missing stamp) → runs and stamps today', async () => {
168
+ const dir = tmpDir();
169
+ try {
170
+ const stampPath = path.join(dir, 'history-rollup.stamp');
171
+ const lockPath = path.join(dir, 'history-rollup.lock');
172
+ fs.writeFileSync(stampPath, '2000-01-01', 'utf8');
173
+ let called = false;
174
+ const result = await maybeFinalizeHistory({
175
+ stampPath,
176
+ lockPath,
177
+ finalizeFn: async (opts) => { called = true; assert.equal(opts.budgetMs, 60_000); return { finalizedDates: ['2000-01-02'], partial: false }; },
178
+ });
179
+ assert.equal(called, true);
180
+ assert.equal(result.ran, true);
181
+ assert.equal(result.reason, 'finalized');
182
+ assert.equal(fs.readFileSync(stampPath, 'utf8').trim(), localDateStr());
183
+ } finally {
184
+ fs.rmSync(dir, { recursive: true, force: true });
185
+ }
186
+ });
187
+
188
+ test('maybeFinalizeHistory: missing stamp file → treated as new day, runs', async () => {
189
+ const dir = tmpDir();
190
+ try {
191
+ const stampPath = path.join(dir, 'history-rollup.stamp');
192
+ const lockPath = path.join(dir, 'history-rollup.lock');
193
+ const result = await maybeFinalizeHistory({
194
+ stampPath,
195
+ lockPath,
196
+ finalizeFn: async () => ({ finalizedDates: [], partial: false }),
197
+ });
198
+ assert.equal(result.ran, true);
199
+ } finally {
200
+ fs.rmSync(dir, { recursive: true, force: true });
201
+ }
202
+ });
203
+
204
+ // ── maybeFinalizeHistory: lock contention ────────────────────────────────────
205
+
206
+ test('maybeFinalizeHistory: lock already held (fresh) by another caller → skip silently', async () => {
207
+ const dir = tmpDir();
208
+ try {
209
+ const stampPath = path.join(dir, 'history-rollup.stamp');
210
+ const lockPath = path.join(dir, 'history-rollup.lock');
211
+ // Simulate a concurrent holder (e.g. the in-app Electron boot pass).
212
+ assert.equal(tryAcquireLock(lockPath, 10 * 60 * 1000), true);
213
+ let called = false;
214
+ const result = await maybeFinalizeHistory({
215
+ stampPath,
216
+ lockPath,
217
+ finalizeFn: async () => { called = true; return { finalizedDates: [], partial: false }; },
218
+ });
219
+ assert.equal(called, false);
220
+ assert.equal(result.ran, false);
221
+ assert.equal(result.reason, 'lock-contended');
222
+ // The other holder's lock must be untouched by the loser.
223
+ assert.equal(fs.existsSync(lockPath), true);
224
+ } finally {
225
+ releaseLock(path.join(dir, 'history-rollup.lock'));
226
+ fs.rmSync(dir, { recursive: true, force: true });
227
+ }
228
+ });
229
+
230
+ test('maybeFinalizeHistory: stale lock (older than staleLockMs) is reclaimed and runs', async () => {
231
+ const dir = tmpDir();
232
+ try {
233
+ const stampPath = path.join(dir, 'history-rollup.stamp');
234
+ const lockPath = path.join(dir, 'history-rollup.lock');
235
+ fs.writeFileSync(lockPath, '99999', 'utf8');
236
+ const staleTime = new Date(Date.now() - 20 * 60 * 1000);
237
+ fs.utimesSync(lockPath, staleTime, staleTime);
238
+
239
+ let called = false;
240
+ const result = await maybeFinalizeHistory({
241
+ stampPath,
242
+ lockPath,
243
+ staleLockMs: 10 * 60 * 1000,
244
+ finalizeFn: async () => { called = true; return { finalizedDates: [], partial: false }; },
245
+ });
246
+ assert.equal(called, true);
247
+ assert.equal(result.ran, true);
248
+ // Lock is released after the run.
249
+ assert.equal(fs.existsSync(lockPath), false);
250
+ } finally {
251
+ fs.rmSync(dir, { recursive: true, force: true });
252
+ }
253
+ });
254
+
255
+ test('maybeFinalizeHistory: releases the lock even when finalizeFn throws', async () => {
256
+ const dir = tmpDir();
257
+ try {
258
+ const stampPath = path.join(dir, 'history-rollup.stamp');
259
+ const lockPath = path.join(dir, 'history-rollup.lock');
260
+ await assert.rejects(() => maybeFinalizeHistory({
261
+ stampPath,
262
+ lockPath,
263
+ finalizeFn: async () => { throw new Error('boom'); },
264
+ }));
265
+ assert.equal(fs.existsSync(lockPath), false);
266
+ } finally {
267
+ fs.rmSync(dir, { recursive: true, force: true });
268
+ }
269
+ });
270
+
271
+ // ── maybeFinalizeHistory: budget-partial ─────────────────────────────────────
272
+
273
+ test('maybeFinalizeHistory: partial finalize (budget exceeded) does NOT stamp the day complete', async () => {
274
+ const dir = tmpDir();
275
+ try {
276
+ const stampPath = path.join(dir, 'history-rollup.stamp');
277
+ const lockPath = path.join(dir, 'history-rollup.lock');
278
+ const result = await maybeFinalizeHistory({
279
+ stampPath,
280
+ lockPath,
281
+ finalizeFn: async () => ({ finalizedDates: [], partial: true }),
282
+ });
283
+ assert.equal(result.ran, true);
284
+ assert.equal(result.reason, 'partial');
285
+ assert.equal(fs.existsSync(stampPath), false);
286
+ } finally {
287
+ fs.rmSync(dir, { recursive: true, force: true });
288
+ }
289
+ });
290
+
291
+ // ── maybeFinalizeHistory: dry run ────────────────────────────────────────────
292
+
293
+ test('maybeFinalizeHistory: dryRun computes without stamping or requiring a write', async () => {
294
+ const dir = tmpDir();
295
+ try {
296
+ const stampPath = path.join(dir, 'history-rollup.stamp');
297
+ const lockPath = path.join(dir, 'history-rollup.lock');
298
+ let seenDryRun;
299
+ const result = await maybeFinalizeHistory({
300
+ stampPath,
301
+ lockPath,
302
+ dryRun: true,
303
+ finalizeFn: async (opts) => { seenDryRun = opts.dryRun; return { finalizedDates: ['2026-07-01'], partial: false }; },
304
+ });
305
+ assert.equal(seenDryRun, true);
306
+ assert.equal(result.ran, false);
307
+ assert.equal(result.reason, 'dry-run');
308
+ assert.deepEqual(result.finalizedDates, ['2026-07-01']);
309
+ assert.equal(fs.existsSync(stampPath), false);
310
+ } finally {
311
+ fs.rmSync(dir, { recursive: true, force: true });
312
+ }
313
+ });
314
+
315
+ describe('evaluateDispatchLiveness', () => {
316
+ const now = 10_000_000_000;
317
+ const deadMs = 30 * 60_000;
318
+ const base = () => ({
319
+ ts: now - 1_000,
320
+ dispatch: {
321
+ lastDispatchAttemptAt: new Date(now - 1_000).toISOString(),
322
+ lastRunAt: new Date(now - deadMs - 60_000).toISOString(),
323
+ lastTickReason: 'held',
324
+ pendingDispatchable: 3,
325
+ runningCount: 0,
326
+ paused: false,
327
+ },
328
+ });
329
+
330
+ test('all conditions met → dead', () => {
331
+ assert.deepEqual(evaluateDispatchLiveness(base(), now, { deadMs }), { dead: true, reason: 'dispatch-dead' });
332
+ });
333
+
334
+ test('default deadMs is 30 min', () => {
335
+ assert.equal(evaluateDispatchLiveness(base(), now).dead, true);
336
+ const e = base();
337
+ e.dispatch.lastRunAt = new Date(now - 29 * 60_000).toISOString();
338
+ assert.equal(evaluateDispatchLiveness(e, now).dead, false);
339
+ });
340
+
341
+ test('each condition is conjunctive', () => {
342
+ const recent = base(); recent.dispatch.lastRunAt = new Date(now - 60_000).toISOString();
343
+ const none = base(); none.dispatch.pendingDispatchable = 0;
344
+ const running = base(); running.dispatch.runningCount = 1;
345
+ const stale = base(); stale.ts = now - 10 * 60_000;
346
+ for (const e of [recent, none, running, stale]) {
347
+ assert.equal(evaluateDispatchLiveness(e, now, { deadMs }).dead, false);
348
+ }
349
+ });
350
+
351
+ test('never-dispatched (null lastRunAt) counts as older than deadMs', () => {
352
+ const e = base(); e.dispatch.lastRunAt = null;
353
+ assert.equal(evaluateDispatchLiveness(e, now, { deadMs }).dead, true);
354
+ });
355
+
356
+ test('paused suppresses', () => {
357
+ const e = base(); e.dispatch.paused = true;
358
+ assert.deepEqual(evaluateDispatchLiveness(e, now, { deadMs }), { dead: false, reason: 'paused' });
359
+ });
360
+
361
+ test('drained queue (nothing dispatchable) suppresses', () => {
362
+ const e = base(); e.dispatch.pendingDispatchable = 0;
363
+ assert.equal(evaluateDispatchLiveness(e, now, { deadMs }).reason, 'nothing-dispatchable');
364
+ });
365
+
366
+ test('a degraded line is ignored', () => {
367
+ const e = { ...base(), degraded: true, errors: [] };
368
+ assert.equal(evaluateDispatchLiveness(e, now, { deadMs }).dead, false);
369
+ });
370
+
371
+ test('null entry / missing dispatch field → not dead', () => {
372
+ assert.equal(evaluateDispatchLiveness(null, now).dead, false);
373
+ assert.equal(evaluateDispatchLiveness({ ts: now }, now).dead, false);
374
+ });
375
+ });
@@ -0,0 +1,266 @@
1
+ 'use strict';
2
+
3
+ // Run: timeout 120 npx vitest run src/main/lib/__tests__/watchdog-relaunch.test.cjs
4
+
5
+ const assert = require('node:assert/strict');
6
+ const fs = require('node:fs');
7
+ const os = require('node:os');
8
+ const path = require('node:path');
9
+ const { spawnSync } = require('node:child_process');
10
+ const {
11
+ maybeRelaunchApp,
12
+ evaluateDispatchLiveness,
13
+ readLastHeartbeat,
14
+ readRelaunchState,
15
+ DEFAULT_MAX_RELAUNCH_ATTEMPTS,
16
+ } = require('../watchdogHelpers.cjs');
17
+
18
+ function tmpDir() {
19
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'watchdog-relaunch-test-'));
20
+ }
21
+
22
+ function writeHeartbeat(hbPath, tsMs, pid) {
23
+ fs.writeFileSync(hbPath, JSON.stringify({ ts: tsMs, pid }) + '\n');
24
+ }
25
+
26
+ function makeSpawnSpy() {
27
+ const calls = [];
28
+ const fn = (opts) => { calls.push(opts); };
29
+ fn.calls = calls;
30
+ return fn;
31
+ }
32
+
33
+ // heartbeatFresh() reads the real wall clock internally (no injectable `now`),
34
+ // so every heartbeat ts below is anchored to actual Date.now() at test start —
35
+ // only the `now` passed to maybeRelaunchApp (which drives debounce/cap math)
36
+ // is offset from that same anchor.
37
+ //
38
+ // isPidAlive() treats EPERM (pid exists, owned by another user — e.g. pid 1)
39
+ // as alive, so a genuinely-dead pid must actually be gone (ESRCH), not just
40
+ // inaccessible. Spawn a short-lived same-user child and use its exited pid —
41
+ // guaranteed ESRCH under our own uid, unlike a hardcoded low pid number.
42
+ const DEAD_PID = (() => {
43
+ const result = spawnSync(process.execPath, ['-e', 'process.exit(0)']);
44
+ return result.pid;
45
+ })();
46
+
47
+ test('fresh heartbeat → no relaunch, no spawn', () => {
48
+ const dir = tmpDir();
49
+ try {
50
+ const hbPath = path.join(dir, 'heartbeat.log');
51
+ const statePath = path.join(dir, 'state.json');
52
+ const now = Date.now();
53
+ writeHeartbeat(hbPath, now - 1_000, DEAD_PID); // 1s old — fresh
54
+ const spawnFn = makeSpawnSpy();
55
+
56
+ const result = maybeRelaunchApp({
57
+ heartbeatPath: hbPath,
58
+ maxAgeMs: 180_000,
59
+ statePath,
60
+ now,
61
+ spawnFn,
62
+ });
63
+
64
+ assert.equal(result.relaunched, false);
65
+ assert.equal(result.reason, 'alive');
66
+ assert.equal(spawnFn.calls.length, 0);
67
+ } finally {
68
+ fs.rmSync(dir, { recursive: true, force: true });
69
+ }
70
+ });
71
+
72
+ test('stale heartbeat + dead pid → relaunch fires', () => {
73
+ const dir = tmpDir();
74
+ try {
75
+ const hbPath = path.join(dir, 'heartbeat.log');
76
+ const statePath = path.join(dir, 'state.json');
77
+ const now = Date.now();
78
+ writeHeartbeat(hbPath, now - 10 * 60_000, DEAD_PID);
79
+ const spawnFn = makeSpawnSpy();
80
+
81
+ const result = maybeRelaunchApp({
82
+ heartbeatPath: hbPath,
83
+ maxAgeMs: 180_000,
84
+ statePath,
85
+ debounceMs: 90_000,
86
+ now,
87
+ spawnFn,
88
+ });
89
+
90
+ assert.equal(result.relaunched, true);
91
+ assert.equal(result.attemptCount, 1);
92
+ assert.equal(spawnFn.calls.length, 1);
93
+
94
+ const state = readRelaunchState(statePath);
95
+ assert.equal(state.attemptCount, 1);
96
+ assert.equal(state.lastAttemptTs, now);
97
+ } finally {
98
+ fs.rmSync(dir, { recursive: true, force: true });
99
+ }
100
+ });
101
+
102
+ test('stale heartbeat but debounce window not elapsed → no relaunch', () => {
103
+ const dir = tmpDir();
104
+ try {
105
+ const hbPath = path.join(dir, 'heartbeat.log');
106
+ const statePath = path.join(dir, 'state.json');
107
+ const now = Date.now();
108
+ writeHeartbeat(hbPath, now - 10 * 60_000, DEAD_PID);
109
+
110
+ // First tick: relaunch fires.
111
+ const spawnFn1 = makeSpawnSpy();
112
+ const first = maybeRelaunchApp({
113
+ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, debounceMs: 90_000, now, spawnFn: spawnFn1,
114
+ });
115
+ assert.equal(first.relaunched, true);
116
+
117
+ // Second tick 30s later — inside the 90s debounce window.
118
+ const spawnFn2 = makeSpawnSpy();
119
+ const second = maybeRelaunchApp({
120
+ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, debounceMs: 90_000, now: now + 30_000, spawnFn: spawnFn2,
121
+ });
122
+
123
+ assert.equal(second.relaunched, false);
124
+ assert.equal(second.reason, 'debounce');
125
+ assert.equal(spawnFn2.calls.length, 0);
126
+ } finally {
127
+ fs.rmSync(dir, { recursive: true, force: true });
128
+ }
129
+ });
130
+
131
+ test('3 failed attempts → stops attempting and logs, no 4th attempt', () => {
132
+ const dir = tmpDir();
133
+ try {
134
+ const hbPath = path.join(dir, 'heartbeat.log');
135
+ const statePath = path.join(dir, 'state.json');
136
+ const logPath = path.join(dir, 'relaunch.log');
137
+ let now = Date.now();
138
+ writeHeartbeat(hbPath, now - 10 * 60_000, DEAD_PID); // stays stale/dead throughout
139
+
140
+ let lastResult;
141
+ for (let i = 0; i < DEFAULT_MAX_RELAUNCH_ATTEMPTS; i++) {
142
+ const spawnFn = makeSpawnSpy();
143
+ lastResult = maybeRelaunchApp({
144
+ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, logPath, debounceMs: 90_000, now, spawnFn,
145
+ });
146
+ assert.equal(lastResult.relaunched, true, `attempt ${i + 1} should relaunch`);
147
+ assert.equal(spawnFn.calls.length, 1);
148
+ now += 100_000; // past the 90s debounce for the next tick
149
+ }
150
+
151
+ // 4th tick: capped — must NOT spawn again.
152
+ const spawnFn4 = makeSpawnSpy();
153
+ const fourth = maybeRelaunchApp({
154
+ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, logPath, debounceMs: 90_000, now, spawnFn: spawnFn4,
155
+ });
156
+
157
+ assert.equal(fourth.relaunched, false);
158
+ assert.equal(fourth.reason, 'capped');
159
+ assert.equal(spawnFn4.calls.length, 0);
160
+ assert.equal(fourth.attemptCount, DEFAULT_MAX_RELAUNCH_ATTEMPTS);
161
+
162
+ const logContent = fs.readFileSync(logPath, 'utf8');
163
+ assert.match(logContent, /giving up/i);
164
+ } finally {
165
+ fs.rmSync(dir, { recursive: true, force: true });
166
+ }
167
+ });
168
+
169
+ test('attemptCount resets to 0 once a fresh heartbeat is observed', () => {
170
+ const dir = tmpDir();
171
+ try {
172
+ const hbPath = path.join(dir, 'heartbeat.log');
173
+ const statePath = path.join(dir, 'state.json');
174
+ const now = Date.now();
175
+ writeHeartbeat(hbPath, now - 10 * 60_000, DEAD_PID);
176
+
177
+ const spawnFn = makeSpawnSpy();
178
+ maybeRelaunchApp({ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, debounceMs: 90_000, now, spawnFn });
179
+ assert.equal(readRelaunchState(statePath).attemptCount, 1);
180
+
181
+ // App comes back up — fresh heartbeat observed on a later tick, recorded
182
+ // with this test process's own (guaranteed-alive) pid.
183
+ const later = now + 200_000;
184
+ writeHeartbeat(hbPath, later - 1_000, process.pid);
185
+ const result = maybeRelaunchApp({
186
+ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, debounceMs: 90_000, now: later, spawnFn,
187
+ });
188
+
189
+ assert.equal(result.relaunched, false);
190
+ assert.equal(result.reason, 'alive');
191
+ assert.equal(readRelaunchState(statePath).attemptCount, 0);
192
+ } finally {
193
+ fs.rmSync(dir, { recursive: true, force: true });
194
+ }
195
+ });
196
+
197
+ test('dispatch-dead (fresh heartbeat, dead dispatch chain) never relaunches', () => {
198
+ const dir = tmpDir();
199
+ try {
200
+ const hbPath = path.join(dir, 'heartbeat.log');
201
+ const statePath = path.join(dir, 'state.json');
202
+ const now = Date.now();
203
+ fs.writeFileSync(hbPath, JSON.stringify({
204
+ ts: now - 1_000,
205
+ pid: process.pid,
206
+ dispatch: {
207
+ lastDispatchAttemptAt: new Date(now - 1_000).toISOString(),
208
+ lastRunAt: new Date(now - 2 * 60 * 60_000).toISOString(),
209
+ lastTickReason: 'held',
210
+ pendingDispatchable: 5,
211
+ runningCount: 0,
212
+ paused: false,
213
+ },
214
+ }) + '\n');
215
+ assert.equal(evaluateDispatchLiveness(readLastHeartbeat(hbPath), now).dead, true);
216
+
217
+ const spawnFn = makeSpawnSpy();
218
+ const result = maybeRelaunchApp({ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, now, spawnFn });
219
+ assert.equal(result.relaunched, false);
220
+ assert.equal(result.reason, 'alive');
221
+ assert.equal(spawnFn.calls.length, 0);
222
+ } finally {
223
+ fs.rmSync(dir, { recursive: true, force: true });
224
+ }
225
+ });
226
+
227
+ // ── restarting marker (drain-restart exit window) ───────────────────────────
228
+
229
+ test('stale heartbeat + active restarting marker → no relaunch; expired marker → relaunch', () => {
230
+ const dir = tmpDir();
231
+ try {
232
+ const hbPath = path.join(dir, 'heartbeat.log');
233
+ const statePath = path.join(dir, 'state.json');
234
+ const markerPath = path.join(dir, 'restarting.json');
235
+ const now = Date.now();
236
+ writeHeartbeat(hbPath, now - 10 * 60_000, DEAD_PID);
237
+ fs.writeFileSync(markerPath, JSON.stringify({ pid: DEAD_PID, at: now - 1_000, expiresAt: now + 60_000 }));
238
+ const spawnFn = makeSpawnSpy();
239
+
240
+ const held = maybeRelaunchApp({ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, restartingMarkerPath: markerPath, now, spawnFn });
241
+ assert.equal(held.relaunched, false);
242
+ assert.equal(held.reason, 'restarting');
243
+ assert.equal(spawnFn.calls.length, 0);
244
+ assert.equal(fs.existsSync(statePath), false, 'a held relaunch must not burn an attempt');
245
+
246
+ // Bounded lifetime: once the marker expires the watchdog resumes duty.
247
+ const lapsed = maybeRelaunchApp({ heartbeatPath: hbPath, maxAgeMs: 180_000, statePath, restartingMarkerPath: markerPath, now: now + 61_000, spawnFn });
248
+ assert.equal(lapsed.relaunched, true);
249
+ assert.equal(spawnFn.calls.length, 1);
250
+ } finally {
251
+ fs.rmSync(dir, { recursive: true, force: true });
252
+ }
253
+ });
254
+
255
+ test('fresh heartbeat carrying dispatch.drain is not dispatch-dead', () => {
256
+ const now = Date.now();
257
+ const entry = {
258
+ ts: now - 1_000,
259
+ dispatch: {
260
+ lastRunAt: new Date(now - 5 * 60 * 60_000).toISOString(),
261
+ pendingDispatchable: 5, runningCount: 0, paused: false,
262
+ drain: { since: new Date(now - 60_000).toISOString(), requestedAt: new Date(now - 60_000).toISOString() },
263
+ },
264
+ };
265
+ assert.deepEqual(evaluateDispatchLiveness(entry, now), { dead: false, reason: 'draining' });
266
+ });
@@ -48,9 +48,7 @@ function listMirrorFiles(dir) {
48
48
  * `skipped` — file names not turned into a row.
49
49
  * `reasons` — `{ [fileName]: humanReadableReason }`, one entry per skipped
50
50
  * file. A file is never guessed at: no mirrored `status` is a skip, not a
51
- * fabricated 'unknown' row (see scripts/mirror-epic-status.cjs for the
52
- * only place that vocabulary is deliberately introduced, for the
53
- * migration's own back-fill bookkeeping).
51
+ * fabricated 'unknown' row.
54
52
  *
55
53
  * `events` and `tombstones` from the existing on-disk index (if any) are
56
54
  * carried through completely untouched — this function only ever