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,390 @@
1
+ /**
2
+ * scheduler-guard-verdict-autoresolve.test.cjs — needs_review ladder gap
3
+ * (2026-09-12, PRD 1181 shape).
4
+ *
5
+ * Auto-fix investigations only ever launch for FAILING runs — a job that
6
+ * exits 0 and gets parked by a post-run GUARD verdict (commit-guard
7
+ * 'silent_no_op', shared-tree-guard 'shared_tree_reverted') never has
8
+ * job.autoFixAttempted set, so isExhaustedAutoFix(job) is false forever and
9
+ * the row is invisible to the existing needs_review auto-resolve ladder —
10
+ * it sits in needs_review permanently, blocking every dependsOn row behind
11
+ * it, until a human clears it by hand. PRD 1181 proved it: exit 0, commit
12
+ * aff5607 landed, parked on a guard verdict, needed a human.
13
+ *
14
+ * This file covers the widened entry gate (isGuardParkedWithoutAutoFix /
15
+ * isEligibleForNeedsReviewAutoResolve) that admits these rows to the SAME
16
+ * ladder (selectExhaustedNeedsReviewTargets / applyNeedsReviewAutoResolve)
17
+ * the exhausted-auto-fix path already uses, keyed on landedCommit +
18
+ * looksDone evidence instead of a spent auto-fix attempt — and the closed
19
+ * set of verdicts eligible for this (GUARD_VERDICT_EVIDENCE_ELIGIBLE)
20
+ * excludes 'worktree_integration_failed', whose damage IS a commit (one
21
+ * stranded on an unmerged branch), so a landedCommit there is not evidence
22
+ * against the verdict.
23
+ *
24
+ * scheduler-needs-review-autoresolve.test.cjs's own suite covers the
25
+ * pre-existing exhausted-auto-fix ladder and must keep passing UNCHANGED —
26
+ * this file only adds new coverage for the second door into the same ladder.
27
+ *
28
+ * HOME is overridden to a tmp dir BEFORE requiring scheduler.cjs — same
29
+ * reason as scheduler-needs-review-autoresolve.test.cjs (appendAuditEvent
30
+ * writes under $HOME/.claude/session-manager/audit-log.jsonl).
31
+ *
32
+ * Run: timeout 120 npx vitest run src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs
33
+ */
34
+
35
+ 'use strict';
36
+
37
+ const assert = require('node:assert/strict');
38
+ const fs = require('node:fs');
39
+ const os = require('node:os');
40
+ const path = require('node:path');
41
+
42
+ const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'guard-verdict-autoresolve-test-'));
43
+ process.env.HOME = tmpHome;
44
+
45
+ const { execFileSync } = require('node:child_process');
46
+
47
+ const {
48
+ selectExhaustedNeedsReviewTargets,
49
+ applyNeedsReviewAutoResolve,
50
+ NEEDS_REVIEW_RESOLVE_CAP,
51
+ GUARD_VERDICT_EVIDENCE_ELIGIBLE,
52
+ isGuardParkedWithoutAutoFix,
53
+ isEligibleForNeedsReviewAutoResolve,
54
+ isExhaustedAutoFix,
55
+ reverifyNeedsReview,
56
+ } = require('../scheduler.cjs');
57
+
58
+ const { pickForProject } = require('../lib/schedulerBatch.cjs');
59
+ const { resolvePrdWriteDir } = require('../lib/prdLocations.cjs');
60
+ const { bustCwdCache } = require('../lib/queueStore.cjs');
61
+
62
+ const MIN_MS = 60_000;
63
+ const THRESHOLD_MS = 30 * MIN_MS;
64
+
65
+ function guardParkedJob(overrides = {}) {
66
+ return {
67
+ slug: '1181-guard-parked-row',
68
+ cwd: '/home/user/project',
69
+ status: 'needs_review',
70
+ exitCode: 0,
71
+ verifierVerdict: 'silent_no_op',
72
+ landedCommit: 'aff5607abc123',
73
+ statusHistory: [{ to: 'needs_review', at: new Date(Date.now() - 45 * MIN_MS).toISOString() }],
74
+ ...overrides,
75
+ };
76
+ }
77
+
78
+ // --- enumeration: which guard verdicts are eligible ---
79
+
80
+ test('GUARD_VERDICT_EVIDENCE_ELIGIBLE contains exactly the benign guard verdicts, never worktree_integration_failed', () => {
81
+ assert.ok(GUARD_VERDICT_EVIDENCE_ELIGIBLE.has('silent_no_op'));
82
+ assert.ok(GUARD_VERDICT_EVIDENCE_ELIGIBLE.has('shared_tree_reverted'));
83
+ assert.equal(GUARD_VERDICT_EVIDENCE_ELIGIBLE.has('worktree_integration_failed'), false);
84
+ });
85
+
86
+ // reaperHelpers.resolvePidlessFailureOverride parks a pidless reap on this
87
+ // exact verdict when the row already carries a landedCommit — same shape as
88
+ // silent_no_op/shared_tree_reverted (exit never observed, no autoFixAttempted,
89
+ // real commit evidence), so it must share this ladder too, or a pidless-reap
90
+ // row stalls in needs_review with nothing to spend and nothing to exhaust —
91
+ // the same bug this file's other tests exist to prevent for the other two
92
+ // verdicts.
93
+ test('GUARD_VERDICT_EVIDENCE_ELIGIBLE also contains pidless_reap_with_landed_commit', () => {
94
+ assert.ok(GUARD_VERDICT_EVIDENCE_ELIGIBLE.has('pidless_reap_with_landed_commit'));
95
+ });
96
+
97
+ // --- isGuardParkedWithoutAutoFix / isEligibleForNeedsReviewAutoResolve ---
98
+
99
+ test('a guard-verdict park with no auto-fix history is guard-parked-without-autofix', () => {
100
+ const job = guardParkedJob();
101
+ assert.equal(isGuardParkedWithoutAutoFix(job), true);
102
+ assert.equal(isExhaustedAutoFix(job), false, 'never went through auto-fix — must not double-count as exhausted');
103
+ assert.equal(isEligibleForNeedsReviewAutoResolve(job), true);
104
+ });
105
+
106
+ test('a row that DID get an auto-fix investigation is left to the exhausted-auto-fix door, not this one', () => {
107
+ const job = guardParkedJob({ autoFixAttempted: true, autoFixOutcome: 'no-plan', autoFixRetries: 1 });
108
+ assert.equal(isGuardParkedWithoutAutoFix(job), false);
109
+ assert.equal(isExhaustedAutoFix(job), true);
110
+ assert.equal(isEligibleForNeedsReviewAutoResolve(job), true, 'still eligible overall, via the OTHER door');
111
+ });
112
+
113
+ test('(c) worktree_integration_failed is never guard-parked-without-autofix, whatever evidence it carries', () => {
114
+ const job = guardParkedJob({ verifierVerdict: 'worktree_integration_failed' });
115
+ assert.equal(isGuardParkedWithoutAutoFix(job), false);
116
+ assert.equal(isEligibleForNeedsReviewAutoResolve(job), false);
117
+ });
118
+
119
+ test('a needs_review row with an unrecognized verifierVerdict and no auto-fix history is not eligible', () => {
120
+ const job = guardParkedJob({ verifierVerdict: 'transcript_errors' });
121
+ assert.equal(isGuardParkedWithoutAutoFix(job), false);
122
+ assert.equal(isEligibleForNeedsReviewAutoResolve(job), false);
123
+ });
124
+
125
+ // --- selectExhaustedNeedsReviewTargets: the widened selector ---
126
+
127
+ test('a fresh guard-parked row (under threshold) is not selected', () => {
128
+ const job = guardParkedJob({
129
+ statusHistory: [{ to: 'needs_review', at: new Date(Date.now() - 2 * MIN_MS).toISOString() }],
130
+ });
131
+ assert.equal(selectExhaustedNeedsReviewTargets([job], Date.now(), THRESHOLD_MS).length, 0);
132
+ });
133
+
134
+ test('a guard-parked row past threshold, under the cap, is selected', () => {
135
+ const job = guardParkedJob();
136
+ const found = selectExhaustedNeedsReviewTargets([job], Date.now(), THRESHOLD_MS);
137
+ assert.equal(found.length, 1);
138
+ assert.equal(found[0].slug, '1181-guard-parked-row');
139
+ });
140
+
141
+ test('(c) worktree_integration_failed is never selected, even past threshold with a landedCommit', () => {
142
+ const job = guardParkedJob({ verifierVerdict: 'worktree_integration_failed' });
143
+ assert.equal(selectExhaustedNeedsReviewTargets([job], Date.now(), THRESHOLD_MS).length, 0);
144
+ });
145
+
146
+ // --- applyNeedsReviewAutoResolve: the three-branch policy, entered via the guard door ---
147
+
148
+ test('(a) the 1181 shape — exit 0 + guard verdict + landedCommit + looksDone — auto-completes', () => {
149
+ const job = guardParkedJob({
150
+ looksDone: { commits: ['aff5607'], paths: ['src/main/scheduler.cjs'], detectedAt: new Date().toISOString() },
151
+ });
152
+ const outcome = applyNeedsReviewAutoResolve(job);
153
+ assert.equal(outcome, 'completed');
154
+ assert.equal(job.status, 'completed');
155
+ assert.match(job.statusHistory.at(-1).reason, /silent_no_op/, 'the reason must name the evidence, not just "auto-resolved"');
156
+ });
157
+
158
+ test('(b) the same shape WITHOUT looksDone does not auto-complete on the first pass — bounded requeue instead', () => {
159
+ const job = guardParkedJob({ exhaustedResolveAttempts: 0 });
160
+ assert.equal(job.looksDone, undefined);
161
+ const outcome = applyNeedsReviewAutoResolve(job);
162
+ assert.equal(outcome, 'requeued');
163
+ assert.equal(job.status, 'pending');
164
+ assert.equal(job.exhaustedResolveAttempts, 1);
165
+ assert.match(job.statusHistory.at(-1).reason, /silent_no_op/);
166
+ });
167
+
168
+ test('a guard-parked row with no evidence, cap spent, auto-skips with the guard verdict named in job.error', () => {
169
+ const job = guardParkedJob({ exhaustedResolveAttempts: NEEDS_REVIEW_RESOLVE_CAP });
170
+ const outcome = applyNeedsReviewAutoResolve(job);
171
+ assert.equal(outcome, 'skipped');
172
+ assert.equal(job.status, 'skipped');
173
+ assert.equal(job.needsReviewAutoResolvedSkip, true);
174
+ assert.match(job.error, /silent_no_op/, 'a human reading the queue must see WHY, not a generic auto-resolved label');
175
+ assert.doesNotMatch(job.error, /exhausted auto-fix path/, 'this row never went through auto-fix — must not claim it did');
176
+ });
177
+
178
+ test('(c) worktree_integration_failed never auto-completes on landed-commit + looksDone evidence', () => {
179
+ const job = guardParkedJob({
180
+ verifierVerdict: 'worktree_integration_failed',
181
+ looksDone: { commits: ['aff5607'], paths: ['src/main/scheduler.cjs'], detectedAt: new Date().toISOString() },
182
+ });
183
+ const outcome = applyNeedsReviewAutoResolve(job);
184
+ assert.equal(outcome, null, 'this verdict has no door into this ladder at all');
185
+ assert.equal(job.status, 'needs_review', 'must stay parked — its own mechanical-recovery path owns this verdict, not this ladder');
186
+ });
187
+
188
+ test('the pre-existing exhausted-auto-fix ladder is unaffected: same branch, same cap, same audit shape', () => {
189
+ const job = {
190
+ slug: 'exhausted-row',
191
+ cwd: '/home/user/project',
192
+ status: 'needs_review',
193
+ autoFixAttempted: true,
194
+ autoFixOutcome: 'no-plan',
195
+ autoFixRetries: 1,
196
+ exhaustedResolveAttempts: 1,
197
+ looksDone: { commits: ['abc1234'], paths: ['src/main/scheduler.cjs'], detectedAt: new Date().toISOString() },
198
+ };
199
+ const outcome = applyNeedsReviewAutoResolve(job);
200
+ assert.equal(outcome, 'completed');
201
+ assert.match(job.statusHistory.at(-1).reason, /verifier annotation shows work landed/);
202
+ });
203
+
204
+ // --- (d) chain drain: a downstream dependsOn row becomes eligible once the guard-parked blocker resolves ---
205
+
206
+ test('(d) a dependsOn chain drains once a guard-parked blocker (no auto-fix, no evidence, cap spent) auto-skips', () => {
207
+ const now = Date.now();
208
+ const rowA = { slug: 'a-first', cwd: '/home/user/project', status: 'completed' };
209
+ const rowB = guardParkedJob({
210
+ slug: 'b-middle',
211
+ exhaustedResolveAttempts: NEEDS_REVIEW_RESOLVE_CAP,
212
+ dependsOn: ['a-first'],
213
+ });
214
+ const rowC = { slug: 'c-last', cwd: '/home/user/project', status: 'pending', dependsOn: ['b-middle'] };
215
+ const jobs = [rowA, rowB, rowC];
216
+
217
+ const before = pickForProject(jobs, new Set(), 5);
218
+ assert.equal(before.batch.length, 0, 'C must not be eligible while B still sits in needs_review');
219
+
220
+ const targets = selectExhaustedNeedsReviewTargets(jobs, now, THRESHOLD_MS);
221
+ assert.equal(targets.length, 1);
222
+ assert.equal(targets[0].slug, 'b-middle');
223
+ const outcome = applyNeedsReviewAutoResolve(rowB);
224
+ assert.equal(outcome, 'skipped');
225
+
226
+ const after = pickForProject(jobs, new Set(), 5);
227
+ assert.ok(after.batch.some((j) => j.slug === 'c-last'), 'C must become eligible once B is auto-skipped');
228
+ });
229
+
230
+ // --- end-to-end: reverifyNeedsReview computes looksDone for a guard-parked row ---
231
+
232
+ function git(args, cwd) {
233
+ return execFileSync('git', args, { cwd, encoding: 'utf8' });
234
+ }
235
+
236
+ function initRepo(dir) {
237
+ fs.mkdirSync(dir, { recursive: true });
238
+ git(['init', '-q'], dir);
239
+ git(['config', 'user.email', 'test@example.com'], dir);
240
+ git(['config', 'user.name', 'Test'], dir);
241
+ fs.writeFileSync(path.join(dir, 'README.md'), 'hello\n', 'utf8');
242
+ git(['add', '-A'], dir);
243
+ git(['commit', '-q', '-m', 'initial'], dir);
244
+ }
245
+
246
+ function commitFile(dir, relPath, content, message) {
247
+ const abs = path.join(dir, relPath);
248
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
249
+ fs.writeFileSync(abs, content);
250
+ git(['add', relPath], dir);
251
+ git(['commit', '-q', '-m', message], dir);
252
+ }
253
+
254
+ function registerActiveProject(cwd, slug) {
255
+ const slugDir = path.join(tmpHome, '.claude', 'projects', slug);
256
+ fs.mkdirSync(slugDir, { recursive: true });
257
+ fs.writeFileSync(path.join(slugDir, 'transcript.jsonl'), JSON.stringify({ cwd }) + '\n');
258
+ bustCwdCache();
259
+ }
260
+
261
+ function writeProjectQueue(cwd, jobs) {
262
+ const stateDir = path.join(cwd, 'session-manager-operations', 'scheduler', 'state');
263
+ fs.mkdirSync(stateDir, { recursive: true });
264
+ fs.writeFileSync(path.join(stateDir, 'queue.json'), JSON.stringify({ jobs }, null, 2));
265
+ return path.join(stateDir, 'queue.json');
266
+ }
267
+
268
+ function writePrd(cwd, slug, body) {
269
+ const dir = resolvePrdWriteDir(cwd);
270
+ fs.mkdirSync(dir, { recursive: true });
271
+ const text = `---\ntitle: Test PRD\ncwd: ${cwd}\nestimateMinutes: 30\n---\n${body}\n`;
272
+ fs.writeFileSync(path.join(dir, `${slug}.md`), text);
273
+ }
274
+
275
+ async function wait(ms) {
276
+ await new Promise((r) => setTimeout(r, ms));
277
+ }
278
+
279
+ test('reverifyNeedsReview computes looksDone for a guard-parked (silent_no_op) row with no auto-fix history', async () => {
280
+ const projectCwd = path.join(tmpHome, 'proj-guard-parked');
281
+ initRepo(projectCwd);
282
+ registerActiveProject(projectCwd, 'proj-guard-parked-slug');
283
+ writePrd(projectCwd, '1181-guard-parked', [
284
+ '# Implementation notes',
285
+ 'Edit `src/thing.js`.',
286
+ ].join('\n'));
287
+
288
+ const startedAt = new Date().toISOString();
289
+ const queuePath = writeProjectQueue(projectCwd, [
290
+ {
291
+ slug: '1181-guard-parked',
292
+ status: 'needs_review',
293
+ cwd: projectCwd,
294
+ runId: 'run-1181',
295
+ startedAt,
296
+ finishedAt: new Date().toISOString(),
297
+ exitCode: 0,
298
+ verifierVerdict: 'silent_no_op',
299
+ landedCommit: 'deadbeef',
300
+ error: 'commit-guard: made no commit on an already-clean tree',
301
+ },
302
+ ]);
303
+
304
+ await wait(1100); // git --since has 1s resolution
305
+ // Must be attributable to THIS job (see attributeLandedCommits) — path
306
+ // overlap alone is no longer evidence. The row's own `landedCommit`
307
+ // ('deadbeef') is a stale/unresolvable placeholder, so this falls to the
308
+ // 'slug trailer' rule by naming the job's own slug in the commit message.
309
+ commitFile(projectCwd, 'src/thing.js', 'hello', 'the actual fix for 1181-guard-parked landed');
310
+
311
+ await reverifyNeedsReview();
312
+
313
+ const jobs = JSON.parse(fs.readFileSync(queuePath, 'utf8')).jobs;
314
+ assert.equal(jobs.length, 1);
315
+ assert.equal(jobs[0].status, 'needs_review', 'looksDone alone never auto-completes — only applyNeedsReviewAutoResolve does');
316
+ assert.ok(jobs[0].looksDone, 'expected a looksDone annotation computed for this guard-parked row');
317
+ assert.equal(jobs[0].looksDone.commits.length, 1);
318
+ assert.equal(jobs[0].looksDone.rule, 'slug trailer');
319
+ });
320
+
321
+ test('reverifyNeedsReview never computes looksDone for a worktree_integration_failed row', async () => {
322
+ const projectCwd = path.join(tmpHome, 'proj-stranded-branch');
323
+ initRepo(projectCwd);
324
+ registerActiveProject(projectCwd, 'proj-stranded-branch-slug');
325
+ writePrd(projectCwd, '1181-stranded', [
326
+ '# Implementation notes',
327
+ 'Edit `src/thing.js`.',
328
+ ].join('\n'));
329
+
330
+ const startedAt = new Date().toISOString();
331
+ const queuePath = writeProjectQueue(projectCwd, [
332
+ {
333
+ slug: '1181-stranded',
334
+ status: 'needs_review',
335
+ cwd: projectCwd,
336
+ runId: 'run-stranded',
337
+ startedAt,
338
+ finishedAt: new Date().toISOString(),
339
+ exitCode: 0,
340
+ verifierVerdict: 'worktree_integration_failed',
341
+ landedCommit: 'deadbeef',
342
+ error: 'worktree branch integration failed',
343
+ },
344
+ ]);
345
+
346
+ await wait(1100);
347
+ commitFile(projectCwd, 'src/thing.js', 'hello', 'unrelated later commit');
348
+
349
+ await reverifyNeedsReview();
350
+
351
+ const jobs = JSON.parse(fs.readFileSync(queuePath, 'utf8')).jobs;
352
+ assert.equal(jobs.length, 1);
353
+ assert.equal(jobs[0].looksDone, undefined, 'a stranded-branch verdict must never be treated as evidence-gatherable');
354
+ assert.equal(jobs[0].status, 'needs_review');
355
+ });
356
+
357
+ test('reverifyNeedsReview heals a stale shared_tree_reverted row (autoFixAttempted, no outcome) whose landedCommit is still an ancestor of HEAD', async () => {
358
+ const projectCwd = path.join(tmpHome, 'proj-stale-shared-tree');
359
+ initRepo(projectCwd);
360
+ registerActiveProject(projectCwd, 'proj-stale-shared-tree-slug');
361
+ writePrd(projectCwd, '1229-stale-shared-tree', '# Implementation notes\nEdit `src/thing.js`.');
362
+
363
+ const startedAt = new Date(Date.now() - 5000).toISOString();
364
+ await wait(1100);
365
+ commitFile(projectCwd, 'src/thing.js', 'job work', 'the job own commit');
366
+ const landed = git(['rev-parse', 'HEAD'], projectCwd).trim();
367
+ commitFile(projectCwd, 'docs/unrelated.md', 'human', 'human commit after the job');
368
+
369
+ const queuePath = writeProjectQueue(projectCwd, [
370
+ {
371
+ slug: '1229-stale-shared-tree',
372
+ status: 'needs_review',
373
+ cwd: projectCwd,
374
+ runId: 'run-1229',
375
+ startedAt,
376
+ finishedAt: new Date().toISOString(),
377
+ exitCode: 0,
378
+ verifierVerdict: 'shared_tree_reverted',
379
+ landedCommit: landed,
380
+ autoFixAttempted: true,
381
+ },
382
+ ]);
383
+
384
+ await reverifyNeedsReview();
385
+
386
+ const jobs = JSON.parse(fs.readFileSync(queuePath, 'utf8')).jobs;
387
+ // Healed rows are archived out of the live queue on the same pass.
388
+ const row = jobs.find((j) => j.slug === '1229-stale-shared-tree');
389
+ assert.ok(!row || row.status === 'completed', 'row must no longer be parked in needs_review');
390
+ });
@@ -0,0 +1,80 @@
1
+ /**
2
+ * scheduler-heartbeat-payload.test.cjs — the heartbeat line carries build
3
+ * identity, a subsystem throw yields a `degraded: true` line, and both
4
+ * watchdogHelpers.heartbeatFresh and health.readFreshHeartbeat treat a
5
+ * degraded line as NOT fresh.
6
+ *
7
+ * Run: timeout 120 npx vitest run src/main/__tests__/scheduler-heartbeat-payload.test.cjs
8
+ */
9
+ 'use strict';
10
+
11
+ import { test, expect, beforeEach, vi } from 'vitest';
12
+ const fs = require('node:fs');
13
+ const schedulerPaths = require('../lib/schedulerPaths.cjs');
14
+ const scheduler = require('../scheduler.cjs');
15
+ const { heartbeatFresh } = require('../lib/watchdogHelpers.cjs');
16
+ const { readFreshHeartbeat } = require('../health.cjs');
17
+
18
+ const HB = () => schedulerPaths.heartbeatPath();
19
+ const lastLine = () => JSON.parse(fs.readFileSync(HB(), 'utf8').trim().split('\n').pop());
20
+
21
+ beforeEach(() => {
22
+ fs.mkdirSync(require('node:path').dirname(HB()), { recursive: true });
23
+ fs.rmSync(HB(), { force: true });
24
+ vi.spyOn(console, 'error').mockImplementation(() => {});
25
+ });
26
+
27
+ test('healthy tick writes build {version, codeSha, builtAt} and is fresh', () => {
28
+ const entry = scheduler.heartbeatTick({ readQueueSync: () => ({ jobs: [], unreadable: true, paused: null }) });
29
+ expect(entry.degraded).toBeUndefined();
30
+ const line = lastLine();
31
+ expect(line.build).toEqual(expect.objectContaining({ version: expect.anything() }));
32
+ expect(Object.keys(line.build).sort()).toEqual(['builtAt', 'codeSha', 'version']);
33
+ expect(line.counts).toBeDefined();
34
+ expect(heartbeatFresh(HB())).toBe(true);
35
+ expect(readFreshHeartbeat(HB())).not.toBeNull();
36
+ });
37
+
38
+ test('a throwing queue read writes a degraded line with the error, never a fresh one', () => {
39
+ scheduler.heartbeatTick({ readQueueSync: () => { throw new Error('boom-queue'); } });
40
+ const line = lastLine();
41
+ expect(line.degraded).toBe(true);
42
+ expect(line.errors[0]).toEqual({ subsystem: 'queue-read-starvation-watchdog', error: 'boom-queue' });
43
+ expect(line.build).toBeDefined();
44
+ expect(line.utilization).toBeUndefined();
45
+ expect(heartbeatFresh(HB())).toBe(false);
46
+ expect(readFreshHeartbeat(HB())).toBeNull();
47
+ });
48
+
49
+ test('a throw in the stall detector degrades the line too', () => {
50
+ scheduler.heartbeatTick({ readQueueSync: () => ({ jobs: null, unreadable: true, paused: null }) });
51
+ const line = lastLine();
52
+ expect(line.degraded).toBe(true);
53
+ expect(line.errors.some((e) => e.subsystem === 'stall-detector' || e.subsystem === 'heartbeat-write')).toBe(true);
54
+ expect(heartbeatFresh(HB())).toBe(false);
55
+ });
56
+
57
+ test('watchdogHelpers treats a hand-written degraded line as stale', () => {
58
+ fs.writeFileSync(HB(), JSON.stringify({ ts: Date.now(), degraded: true }) + '\n');
59
+ expect(heartbeatFresh(HB())).toBe(false);
60
+ fs.writeFileSync(HB(), JSON.stringify({ ts: Date.now() }) + '\n');
61
+ expect(heartbeatFresh(HB())).toBe(true);
62
+ });
63
+
64
+ test('healthy tick carries dispatch {..., pendingDispatchable excludes blocked chains}', () => {
65
+ const jobs = [
66
+ { slug: '1-a', cwd: '/p', status: 'failed' },
67
+ { slug: '2-b', cwd: '/p', status: 'pending', dependsOn: ['1-a'] },
68
+ { slug: '3-c', cwd: '/p', status: 'pending' },
69
+ ];
70
+ const entry = scheduler.heartbeatTick({
71
+ readQueueSync: () => ({ jobs, unreadable: true, paused: null, lastRunAt: '2026-01-01T00:00:00.000Z' }),
72
+ });
73
+ expect(entry.dispatch).toEqual(expect.objectContaining({
74
+ lastRunAt: '2026-01-01T00:00:00.000Z', pendingDispatchable: 1, runningCount: 0, paused: false,
75
+ }));
76
+ expect(Object.keys(entry.dispatch).sort()).toEqual(
77
+ ['drain', 'lastDispatchAttemptAt', 'lastRunAt', 'lastTickReason', 'paused', 'pendingDispatchable', 'runningCount'],
78
+ );
79
+ expect(entry.dispatch.drain).toBeNull();
80
+ });
@@ -18,6 +18,7 @@ import { test, expect, beforeAll, afterAll, afterEach } from 'vitest';
18
18
  const fs = require('node:fs');
19
19
  const os = require('node:os');
20
20
  const path = require('node:path');
21
+ const claudeStub = require('../../../tests/helpers/claudeStub.cjs');
21
22
  const { execFileSync } = require('node:child_process');
22
23
 
23
24
  let tmpHome;
@@ -52,6 +53,12 @@ function registerActiveProject(cwd) {
52
53
  fs.writeFileSync(path.join(slugDir, 'transcript.jsonl'), JSON.stringify({ cwd }) + '\n');
53
54
  }
54
55
 
56
+ // Every PRD fixture below lives Epic-scoped, not in the legacy flat prds/
57
+ // dir: the flat dir is retired and swept into prds-archived/ by
58
+ // consolidateFlatPrds the moment a job is no longer pending/running, which
59
+ // would strand a just-completed/failed row the instant reconcile()'s
60
+ // auto-archive-drop path (see scheduler-reconcile-history-backfill.test.cjs)
61
+ // treats the now-missing PRD as "archived on purpose" and drops it.
55
62
  function writeProjectQueue(cwd, jobs) {
56
63
  const stateDir = path.join(cwd, 'session-manager-operations', 'scheduler', 'state');
57
64
  fs.mkdirSync(stateDir, { recursive: true });
@@ -68,16 +75,13 @@ function writeProjectQueue(cwd, jobs) {
68
75
  // which is not the scenario under test here — this must land as a genuine
69
76
  // non-zero exit.
70
77
  function writeKilledClaudeStub() {
71
- const stubPath = path.join(os.tmpdir(), `sm-claude-stub-killed-${process.pid}-${Math.floor(Math.random() * 1e9)}.cjs`);
72
- const body = `
78
+ return claudeStub.writeClaudeStub({ body: `
73
79
  const fs = require('fs');
74
80
  const path = require('path');
75
81
  fs.writeFileSync(path.join(process.cwd(), 'README.md'), 'hello\\nedited by job\\n', 'utf8');
76
82
  fs.writeFileSync(path.join(process.cwd(), 'job-output.txt'), 'work the job produced before dying\\n', 'utf8');
77
83
  process.exit(137);
78
- `;
79
- fs.writeFileSync(stubPath, `#!${process.execPath}\n${body}\n`, { mode: 0o755 });
80
- return stubPath;
84
+ ` });
81
85
  }
82
86
 
83
87
  beforeAll(() => {
@@ -117,7 +121,7 @@ test('an in-place job killed (exit 137) mid-run salvages a delta-scoped patch th
117
121
  fs.appendFileSync(path.join(projectCwd, 'human-wip.txt'), 'more human edits\n', 'utf8');
118
122
 
119
123
  const slug = `1098-test-inplace-killed-${process.pid}-${Math.floor(Math.random() * 1e6)}`;
120
- const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'prds');
124
+ const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'epics', 'test-fixture-epic', 'prds');
121
125
  fs.mkdirSync(prdsDir, { recursive: true });
122
126
  fs.writeFileSync(path.join(prdsDir, `${slug}.md`), 'Do a thing that gets killed mid-run.', 'utf8');
123
127
 
@@ -192,13 +196,10 @@ test('an in-place job killed (exit 137) mid-run salvages a delta-scoped patch th
192
196
  // — a job whose only working-tree dirt is pre-existing human/sibling WIP
193
197
  // present before the run even started.
194
198
  function writeNoopClaudeStub() {
195
- const stubPath = path.join(os.tmpdir(), `sm-claude-stub-noop-${process.pid}-${Math.floor(Math.random() * 1e9)}.cjs`);
196
- const body = `
199
+ return claudeStub.writeClaudeStub({ body: `
197
200
  process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', result: 'nothing to do', is_error: false }) + '\\n');
198
201
  process.exit(0);
199
- `;
200
- fs.writeFileSync(stubPath, `#!${process.execPath}\n${body}\n`, { mode: 0o755 });
201
- return stubPath;
202
+ ` });
202
203
  }
203
204
 
204
205
  // Stub `claude` binary that blocks until a `go` marker file appears in its
@@ -206,11 +207,19 @@ function writeNoopClaudeStub() {
206
207
  // window to read the queue row's intermediate dispatchPhase before the run
207
208
  // finalizes and deletes it.
208
209
  function writeGatedClaudeStub() {
209
- const stubPath = path.join(os.tmpdir(), `sm-claude-stub-gated-${process.pid}-${Math.floor(Math.random() * 1e9)}.cjs`);
210
- const body = `
210
+ return claudeStub.writeClaudeStub({ body: `
211
211
  const fs = require('fs');
212
212
  const path = require('path');
213
213
  const { execFileSync } = require('child_process');
214
+ // spawnJob's dispatch path probes 'claude --version' (claudeBin.cjs)
215
+ // BEFORE the real dispatch — a real claude binary answers that
216
+ // near-instantly regardless of any in-flight work, so the stub must
217
+ // too, or the probe's own 8s exec timeout eats almost this whole test's
218
+ // poll window before the row ever advances past 'running-stamped'.
219
+ if (process.argv.includes('--version')) {
220
+ process.stdout.write('1.0.0 (stub)\\n');
221
+ process.exit(0);
222
+ }
214
223
  const goFile = path.join(process.cwd(), 'go.marker');
215
224
  const deadline = Date.now() + 10_000;
216
225
  while (!fs.existsSync(goFile) && Date.now() < deadline) {
@@ -218,9 +227,7 @@ function writeGatedClaudeStub() {
218
227
  }
219
228
  process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', result: 'ok', is_error: false }) + '\\n');
220
229
  process.exit(0);
221
- `;
222
- fs.writeFileSync(stubPath, `#!${process.execPath}\n${body}\n`, { mode: 0o755 });
223
- return stubPath;
230
+ ` });
224
231
  }
225
232
 
226
233
  test('dispatchPhase breadcrumb advances to "spawned" mid-run and is gone after finalize', async () => {
@@ -229,7 +236,7 @@ test('dispatchPhase breadcrumb advances to "spawned" mid-run and is gone after f
229
236
  registerActiveProject(projectCwd);
230
237
 
231
238
  const slug = `1163-test-dispatchphase-${process.pid}-${Math.floor(Math.random() * 1e6)}`;
232
- const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'prds');
239
+ const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'epics', 'test-fixture-epic', 'prds');
233
240
  fs.mkdirSync(prdsDir, { recursive: true });
234
241
  fs.writeFileSync(path.join(prdsDir, `${slug}.md`), 'Do a thing, gated on a marker file.', 'utf8');
235
242
 
@@ -285,7 +292,7 @@ test('a job whose tree is dirty only from pre-existing baseline WIP (human/sibli
285
292
  fs.writeFileSync(path.join(projectCwd, 'human-wip.txt'), 'human work in progress\n', 'utf8');
286
293
 
287
294
  const slug = `1098-test-inplace-noop-${process.pid}-${Math.floor(Math.random() * 1e6)}`;
288
- const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'prds');
295
+ const prdsDir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'epics', 'test-fixture-epic', 'prds');
289
296
  fs.mkdirSync(prdsDir, { recursive: true });
290
297
  fs.writeFileSync(path.join(prdsDir, `${slug}.md`), 'Do nothing.', 'utf8');
291
298
 
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * scheduler-investigation-prompt.test.cjs — unit tests for buildInvestigationPrompt.
3
3
  *
4
- * Run: timeout 120 node --test src/main/__tests__/scheduler-investigation-prompt.test.cjs
4
+ * Run: timeout 300 npx vitest run src/main/__tests__/scheduler-investigation-prompt.test.cjs
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- const { test } = require('node:test');
9
+ import { test } from 'vitest';
10
10
  const assert = require('node:assert/strict');
11
11
  const fs = require('node:fs');
12
12
  const os = require('node:os');
@@ -93,7 +93,7 @@ test('prompt instructs that cwd must be the git repo root where the fix will lan
93
93
  assert.match(prompt, /needs_review/);
94
94
  });
95
95
 
96
- test('prompt frontmatter block still declares exactly the four expected keys', () => {
96
+ test('prompt frontmatter block still declares exactly the five expected keys', () => {
97
97
  const prompt = buildInvestigationPrompt(makeArgs());
98
98
  const fenceMatch = prompt.match(/```\s*\n\s*---\n([\s\S]*?)\n\s*---\n\s*```/);
99
99
  assert.ok(fenceMatch, 'expected a fenced frontmatter block in the prompt');
@@ -101,7 +101,7 @@ test('prompt frontmatter block still declares exactly the four expected keys', (
101
101
  .split('\n')
102
102
  .filter((line) => line.trim().length > 0)
103
103
  .map((line) => line.split(':')[0].trim());
104
- assert.deepEqual(keys, ['title', 'cwd', 'parallelGroup', 'estimateMinutes']);
104
+ assert.deepEqual(keys, ['title', 'cwd', 'parallelGroup', 'estimateMinutes', 'isFixPlan']);
105
105
  });
106
106
 
107
107
  // ─── isGitRepoSync (scheduler.cjs) ─────────────────────────────────────────────