claude-code-session-manager 0.98.0 → 0.101.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 (441) hide show
  1. package/README.md +3 -3
  2. package/bin/cli.cjs +16 -4
  3. package/bin/node-floor.cjs +41 -0
  4. package/dist/assets/DataModel-CXaH2GED.js +1 -0
  5. package/dist/assets/{History-Bfdoywlh.js → History-Cerii-HA.js} +2 -2
  6. package/dist/assets/{Hooks-CKDJjTJV.js → Hooks-aXMb5LDy.js} +3 -3
  7. package/dist/assets/{Library-7akfgy67.js → Library-WrJFKEOJ.js} +1 -1
  8. package/dist/assets/{MarkdownEditor-DDesiqet.js → MarkdownEditor-D1BMCXS7.js} +1 -1
  9. package/dist/assets/{McpServers-D4lZtXof.js → McpServers-Cf0davLd.js} +2 -2
  10. package/dist/assets/{Memory-CeI8G1w5.js → Memory-Dn6NHWPe.js} +6 -6
  11. package/dist/assets/Permissions-CTVuFPjg.js +3 -0
  12. package/dist/assets/{Plugins-P4eCXy_S.js → Plugins-C2TyF8Mn.js} +2 -2
  13. package/dist/assets/ProvenanceBadge-F_jwHSwE.js +1 -0
  14. package/dist/assets/{SaveBar-l9jnEMES.js → SaveBar-DA1KVJST.js} +1 -1
  15. package/dist/assets/Scheduler-Bm6Q_hlu.js +16 -0
  16. package/dist/assets/{ScopeSwitcher-CjJi8ST5.js → ScopeSwitcher-BygZlJca.js} +1 -1
  17. package/dist/assets/Settings-BYCiv5KV.js +3 -0
  18. package/dist/assets/{SkillReferenceGraph-CjbO01Sg.js → SkillReferenceGraph-CcLnl9np.js} +1 -1
  19. package/dist/assets/{Skills-BxZ9_fCR.js → Skills-ChffsdTD.js} +2 -2
  20. package/dist/assets/{SystemPrompt-D8vfFb8b.js → SystemPrompt-dNkfHE_M.js} +1 -1
  21. package/dist/assets/{TagLibrary-2vzUo7YL.js → TagLibrary-jVlEuB0m.js} +1 -1
  22. package/dist/assets/{TiptapBody-B8ZfbK90.js → TiptapBody-6_cdwcP0.js} +1 -1
  23. package/dist/assets/{Toggle-BbW4nGGf.js → Toggle-CVXqGpAP.js} +1 -1
  24. package/dist/assets/ViewTabs-DO1YVbpc.js +1 -0
  25. package/dist/assets/{index-CKH5Uxik.css → index-D89EUizB.css} +1 -1
  26. package/dist/assets/{index-Cd98Q1lD.js → index-DbCQPWWY.js} +747 -752
  27. package/dist/assets/{settingsSchema-IhUfucCF.js → settingsSchema-Wrvn-Yz1.js} +1 -1
  28. package/dist/index.html +2 -2
  29. package/package.json +25 -29
  30. package/plugins/CLAUDE.md +6 -6
  31. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +21 -19
  32. package/plugins/session-manager-dev/skills/builder/SKILL.md +3 -3
  33. package/plugins/session-manager-dev/skills/develop/SKILL.md +254 -510
  34. package/plugins/session-manager-dev/skills/develop/standards.md +17 -22
  35. package/scripts/README.md +3 -11
  36. package/scripts/audit-ops-hygiene.cjs +3 -3
  37. package/scripts/hooks/lib/guard-prd-writes-policy.cjs +1 -1
  38. package/scripts/hooks/lib/guard-self-schedule-policy.cjs +1 -1
  39. package/scripts/mint-epic.cjs +2 -3
  40. package/scripts/scheduler-mcp-server.cjs +64 -7
  41. package/src/main/agentLibrary.cjs +22 -2
  42. package/src/main/build-info.json +4 -4
  43. package/src/main/chatRunner.cjs +4 -3
  44. package/src/main/config.cjs +41 -38
  45. package/src/main/docEdit.cjs +4 -1
  46. package/src/main/files.cjs +2 -5
  47. package/src/main/health.cjs +1 -1
  48. package/src/main/index.cjs +40 -11
  49. package/src/main/ipcSchemas.cjs +35 -34
  50. package/src/main/lib/agentPersonaSchema.cjs +13 -2
  51. package/src/main/lib/atomicFs.cjs +116 -0
  52. package/src/main/lib/branchSweep.cjs +13 -12
  53. package/src/main/lib/buildTarget.cjs +3 -3
  54. package/src/main/lib/builtinMacros.cjs +39 -0
  55. package/src/main/lib/claudeCliCaps.cjs +129 -0
  56. package/src/main/lib/credentials.cjs +2 -4
  57. package/src/main/lib/crossProjectFeedback.cjs +3 -3
  58. package/src/main/lib/cwdClassify.cjs +15 -3
  59. package/src/main/lib/definitionOfDone.cjs +207 -125
  60. package/src/main/lib/dodDrainHook.cjs +11 -5
  61. package/src/main/lib/epicMint.cjs +2 -4
  62. package/src/main/lib/epicStatusMirror.cjs +8 -10
  63. package/src/main/lib/epicWorktreeProjectConfig.cjs +2 -4
  64. package/src/main/lib/gateAuthority.cjs +96 -0
  65. package/src/main/lib/gitExec.cjs +69 -0
  66. package/src/main/lib/gitWorktree.cjs +656 -92
  67. package/src/main/lib/instanceLock.cjs +5 -8
  68. package/src/main/lib/launchFailure.cjs +2 -3
  69. package/src/main/lib/macroLibrary.cjs +480 -0
  70. package/src/main/lib/mcpToolCatalog.cjs +49 -17
  71. package/src/main/lib/needsReviewLedger.cjs +1 -1
  72. package/src/main/lib/opsErrorLog.cjs +11 -1
  73. package/src/main/lib/opsOwnership.cjs +5 -9
  74. package/src/main/lib/pidAlive.cjs +32 -0
  75. package/src/main/lib/prdCreate.cjs +121 -12
  76. package/src/main/lib/prdDisposition.cjs +2 -2
  77. package/src/main/lib/prdGateFiles.cjs +284 -0
  78. package/src/main/lib/prdLocations.cjs +61 -0
  79. package/src/main/lib/prdMigration.cjs +2 -3
  80. package/src/main/lib/prdSizing.cjs +2 -1
  81. package/src/main/lib/projectHomeAdminRoutes.cjs +136 -21
  82. package/src/main/lib/promptSessionSchema.cjs +10 -2
  83. package/src/main/lib/rcaReport.cjs +4 -6
  84. package/src/main/lib/reaperHelpers.cjs +8 -1
  85. package/src/main/lib/reservationExpiry.cjs +6 -1
  86. package/src/main/lib/reviewNotice.cjs +263 -0
  87. package/src/main/lib/runClaudeP.cjs +4 -1
  88. package/src/main/lib/schedulerPaths.cjs +22 -2
  89. package/src/main/lib/sessionSlots.cjs +2 -4
  90. package/src/main/lib/shippedPersonaSeeds.cjs +226 -0
  91. package/src/main/lib/smfileHeaders.cjs +66 -0
  92. package/src/main/lib/timeoutShim.cjs +123 -0
  93. package/src/main/lib/timeoutShimScript.cjs +275 -0
  94. package/src/main/lib/upgradeDrain.cjs +4 -10
  95. package/src/main/lib/watchdogHelpers.cjs +12 -25
  96. package/src/main/lib/workTypeLibrary.cjs +7 -1
  97. package/src/main/projectPages.cjs +43 -13
  98. package/src/main/promptSessionEvents.cjs +37 -13
  99. package/src/main/scheduler.cjs +910 -198
  100. package/src/main/seedAgentPersonas.cjs +279 -24
  101. package/src/main/supervisor.cjs +4 -1
  102. package/src/main/templates/PRD_AUTHORING.md +126 -406
  103. package/src/preload/__tests__/preload-surface.test.cjs +68 -0
  104. package/src/preload/api.d.ts +53 -94
  105. package/src/preload/index.cjs +14 -9
  106. package/src/seed/agents/architect.md +2 -0
  107. package/src/seed/agents/demo-video-builder.md +84 -0
  108. package/src/seed/agents/dev-lead.md +18 -18
  109. package/src/seed/agents/project-home-builder.md +66 -35
  110. package/src/seed/agents/validator.md +10 -4
  111. package/dist/assets/DataModel-DCEgMTjH.js +0 -1
  112. package/dist/assets/HostBilko-CDVHE0hT.js +0 -1
  113. package/dist/assets/Permissions-BGleLja4.js +0 -3
  114. package/dist/assets/ProvenanceBadge-BFczzI1B.js +0 -1
  115. package/dist/assets/Scheduler-C_phpeUS.js +0 -16
  116. package/dist/assets/Settings-BIwZ3FGQ.js +0 -3
  117. package/src/main/__tests__/activeIndexMerge.test.cjs +0 -235
  118. package/src/main/__tests__/agentEffortResolve.test.cjs +0 -117
  119. package/src/main/__tests__/agentLibrary.test.cjs +0 -276
  120. package/src/main/__tests__/agentModelResolve.test.cjs +0 -311
  121. package/src/main/__tests__/agentOverlayWrite.test.cjs +0 -95
  122. package/src/main/__tests__/bilkoHost-deriveSlug.test.cjs +0 -26
  123. package/src/main/__tests__/bilkoHost-integration.test.cjs +0 -118
  124. package/src/main/__tests__/bilkoHostCore.test.cjs +0 -72
  125. package/src/main/__tests__/broadcastCoalescer.test.cjs +0 -122
  126. package/src/main/__tests__/chat-cancel-terminal.test.cjs +0 -120
  127. package/src/main/__tests__/chat-dead-channels.test.cjs +0 -63
  128. package/src/main/__tests__/chat-exit-close-race.test.cjs +0 -146
  129. package/src/main/__tests__/chat-mcp-consent-notice.test.cjs +0 -139
  130. package/src/main/__tests__/chat-preamble-anchors.test.cjs +0 -100
  131. package/src/main/__tests__/chat-queue.test.cjs +0 -97
  132. package/src/main/__tests__/chat-stop-signal.test.cjs +0 -89
  133. package/src/main/__tests__/chatRunner-epic-worktree-execcwd.test.cjs +0 -125
  134. package/src/main/__tests__/chatRunner-session-flag-retry.test.cjs +0 -252
  135. package/src/main/__tests__/classifyPromptTicket.test.cjs +0 -101
  136. package/src/main/__tests__/classifyTranscriptLine.test.cjs +0 -201
  137. package/src/main/__tests__/computeDepHistorySatisfaction.test.cjs +0 -66
  138. package/src/main/__tests__/config-readText-bounded.test.cjs +0 -84
  139. package/src/main/__tests__/configWriteBoundaryOwners.test.cjs +0 -59
  140. package/src/main/__tests__/crossProjectFeedback.test.cjs +0 -334
  141. package/src/main/__tests__/crossProjectFeedbackRoutes.test.cjs +0 -161
  142. package/src/main/__tests__/dep-orphan-archive-health.test.cjs +0 -77
  143. package/src/main/__tests__/develop-skill-failure-modes.test.cjs +0 -70
  144. package/src/main/__tests__/docEdit.test.cjs +0 -244
  145. package/src/main/__tests__/dod-batchkey.test.cjs +0 -183
  146. package/src/main/__tests__/dod-drain-hook.test.cjs +0 -302
  147. package/src/main/__tests__/dod-report.test.cjs +0 -304
  148. package/src/main/__tests__/dod-reverify.test.cjs +0 -285
  149. package/src/main/__tests__/epicContextDigest.test.cjs +0 -174
  150. package/src/main/__tests__/epicMint.test.cjs +0 -332
  151. package/src/main/__tests__/epicMintTelemetryTap.test.cjs +0 -64
  152. package/src/main/__tests__/epicStatusMirror.test.cjs +0 -110
  153. package/src/main/__tests__/epicValidationHook.test.cjs +0 -291
  154. package/src/main/__tests__/exchanges.test.cjs +0 -122
  155. package/src/main/__tests__/exchangesPromptId.test.cjs +0 -61
  156. package/src/main/__tests__/extractJson.test.cjs +0 -51
  157. package/src/main/__tests__/files-reject-credentials.test.cjs +0 -40
  158. package/src/main/__tests__/fixtures/1218-fo-01-move-scripts-lib-into-src-main-lib.log +0 -556
  159. package/src/main/__tests__/flatPrdTickSweep.test.cjs +0 -110
  160. package/src/main/__tests__/health-build-freshness.test.cjs +0 -39
  161. package/src/main/__tests__/health-claude-md-budget.test.cjs +0 -57
  162. package/src/main/__tests__/health-credentials.test.cjs +0 -81
  163. package/src/main/__tests__/health-delegation-chain.test.cjs +0 -124
  164. package/src/main/__tests__/health-per-project-stall.test.cjs +0 -84
  165. package/src/main/__tests__/health-prd-migration.test.cjs +0 -37
  166. package/src/main/__tests__/health-queue-dispatch.test.cjs +0 -135
  167. package/src/main/__tests__/health-starve-escalation.test.cjs +0 -94
  168. package/src/main/__tests__/health-tick-liveness.test.cjs +0 -179
  169. package/src/main/__tests__/health-usage-poller.test.cjs +0 -144
  170. package/src/main/__tests__/health-worktree-cap-blocked.test.cjs +0 -65
  171. package/src/main/__tests__/heapSnapshot.test.cjs +0 -121
  172. package/src/main/__tests__/historyAggregatorIntraday.test.cjs +0 -313
  173. package/src/main/__tests__/historyDashboard.test.cjs +0 -163
  174. package/src/main/__tests__/historyRollup.test.cjs +0 -333
  175. package/src/main/__tests__/intradayRefresh.test.cjs +0 -39
  176. package/src/main/__tests__/ipcSchemas-dependsOn.test.cjs +0 -39
  177. package/src/main/__tests__/kg-augment.test.cjs +0 -195
  178. package/src/main/__tests__/loadGateDetailTick.test.cjs +0 -31
  179. package/src/main/__tests__/machineProfile.test.cjs +0 -152
  180. package/src/main/__tests__/mcpStatus.test.cjs +0 -61
  181. package/src/main/__tests__/memoryAggregate.test.cjs +0 -109
  182. package/src/main/__tests__/memoryStale.test.cjs +0 -88
  183. package/src/main/__tests__/needsReviewLedger.test.cjs +0 -162
  184. package/src/main/__tests__/openExternalApp-spawn-error.test.cjs +0 -25
  185. package/src/main/__tests__/opsErrorLog.test.cjs +0 -109
  186. package/src/main/__tests__/opsErrorLogTelemetryTap.test.cjs +0 -173
  187. package/src/main/__tests__/personaMerge.test.cjs +0 -169
  188. package/src/main/__tests__/planValidator.test.cjs +0 -125
  189. package/src/main/__tests__/pollLoop-dispatch-on-failure.test.cjs +0 -176
  190. package/src/main/__tests__/prd-group-allocator.test.cjs +0 -119
  191. package/src/main/__tests__/prdAdminRouteParity.test.cjs +0 -70
  192. package/src/main/__tests__/prdAdminRoutes.test.cjs +0 -718
  193. package/src/main/__tests__/prdAgentType.test.cjs +0 -103
  194. package/src/main/__tests__/prdAuthoringSeed.test.cjs +0 -39
  195. package/src/main/__tests__/prdCreate.test.cjs +0 -979
  196. package/src/main/__tests__/prdCreateAdoption.test.cjs +0 -205
  197. package/src/main/__tests__/prdCreateDisposition.test.cjs +0 -201
  198. package/src/main/__tests__/prdCreatePlanId.test.cjs +0 -132
  199. package/src/main/__tests__/prdFrontmatterAgentType.test.cjs +0 -117
  200. package/src/main/__tests__/prdFrontmatterDependsOn.test.cjs +0 -136
  201. package/src/main/__tests__/prdFrontmatterDisposition.test.cjs +0 -125
  202. package/src/main/__tests__/prdFrontmatterQuietMachine.test.cjs +0 -108
  203. package/src/main/__tests__/prdLocations.test.cjs +0 -195
  204. package/src/main/__tests__/prdLocationsArchived.test.cjs +0 -201
  205. package/src/main/__tests__/prdMigration.test.cjs +0 -349
  206. package/src/main/__tests__/prdMigrationLegacyAdopt.test.cjs +0 -91
  207. package/src/main/__tests__/prdParserHighWater.test.cjs +0 -74
  208. package/src/main/__tests__/prdParserSourcePromptId.test.cjs +0 -65
  209. package/src/main/__tests__/prdSetDisposition.test.cjs +0 -222
  210. package/src/main/__tests__/prdSizing.test.cjs +0 -106
  211. package/src/main/__tests__/prdSourcePromptIdBackfill.test.cjs +0 -118
  212. package/src/main/__tests__/prdUpdateDependsOn.test.cjs +0 -160
  213. package/src/main/__tests__/proc-role-env.test.cjs +0 -125
  214. package/src/main/__tests__/procname-claude-spawn-sites.test.cjs +0 -304
  215. package/src/main/__tests__/procname-sm-processes.test.cjs +0 -127
  216. package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +0 -177
  217. package/src/main/__tests__/projectPages.test.cjs +0 -137
  218. package/src/main/__tests__/promptSessionEvents.test.cjs +0 -234
  219. package/src/main/__tests__/promptSessionSchema.test.cjs +0 -101
  220. package/src/main/__tests__/promptSessionTranscript.test.cjs +0 -0
  221. package/src/main/__tests__/promptSessionsCreateEpicHandler.test.cjs +0 -159
  222. package/src/main/__tests__/pty-epic-worktree-spawn-cwd.test.cjs +0 -282
  223. package/src/main/__tests__/pty-session-open-telemetry.test.cjs +0 -96
  224. package/src/main/__tests__/pty-write-result.test.cjs +0 -46
  225. package/src/main/__tests__/queue-health-verdict.test.cjs +0 -170
  226. package/src/main/__tests__/queue-starvation-dispatch-driver.test.cjs +0 -286
  227. package/src/main/__tests__/queue-starvation-per-project.test.cjs +0 -147
  228. package/src/main/__tests__/queueHistory.test.cjs +0 -355
  229. package/src/main/__tests__/queueOps-interactive-ac-lint.test.cjs +0 -65
  230. package/src/main/__tests__/queueOpsArchiveDestination.test.cjs +0 -65
  231. package/src/main/__tests__/queueOpsAutoArchive.test.cjs +0 -211
  232. package/src/main/__tests__/rateLimitPollerStreak.test.cjs +0 -128
  233. package/src/main/__tests__/rcaReport.test.cjs +0 -266
  234. package/src/main/__tests__/reconcileFlatPrdSweep.test.cjs +0 -119
  235. package/src/main/__tests__/reconcileTiming.test.cjs +0 -135
  236. package/src/main/__tests__/runLogRetention.test.cjs +0 -489
  237. package/src/main/__tests__/runVerify-atomic-verdicts.test.cjs +0 -26
  238. package/src/main/__tests__/runVerify-blocked-by-foreign-wip.test.cjs +0 -58
  239. package/src/main/__tests__/runVerify-landed-commit-outranks.test.cjs +0 -191
  240. package/src/main/__tests__/runVerify-policy-denial.test.cjs +0 -89
  241. package/src/main/__tests__/runVerify-transcript-commit-evidence.test.cjs +0 -225
  242. package/src/main/__tests__/runVerify.test.cjs +0 -1784
  243. package/src/main/__tests__/scheduleJobSchema.test.cjs +0 -127
  244. package/src/main/__tests__/scheduleJobStatusDrift.test.cjs +0 -65
  245. package/src/main/__tests__/scheduleJobTransitions.test.cjs +0 -277
  246. package/src/main/__tests__/scheduleJobTransitionsGrep.test.cjs +0 -59
  247. package/src/main/__tests__/scheduleJobTransitionsTelemetryTap.test.cjs +0 -72
  248. package/src/main/__tests__/scheduler-admin-routes.test.cjs +0 -199
  249. package/src/main/__tests__/scheduler-adopted-run-supervision.test.cjs +0 -143
  250. package/src/main/__tests__/scheduler-already-satisfied-on-main.test.cjs +0 -105
  251. package/src/main/__tests__/scheduler-archive-completed-prd.test.cjs +0 -102
  252. package/src/main/__tests__/scheduler-archived-twin-guard.test.cjs +0 -155
  253. package/src/main/__tests__/scheduler-autofix-outcome.test.cjs +0 -188
  254. package/src/main/__tests__/scheduler-autofix-select.test.cjs +0 -439
  255. package/src/main/__tests__/scheduler-autopromote.test.cjs +0 -51
  256. package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +0 -101
  257. package/src/main/__tests__/scheduler-blocked-by-foreign-wip.test.cjs +0 -107
  258. package/src/main/__tests__/scheduler-boot-orphans.test.cjs +0 -153
  259. package/src/main/__tests__/scheduler-broadcast-reconcile.test.cjs +0 -121
  260. package/src/main/__tests__/scheduler-clear-queue-history.test.cjs +0 -134
  261. package/src/main/__tests__/scheduler-commit-guard-noop.test.cjs +0 -244
  262. package/src/main/__tests__/scheduler-committed-in-window.test.cjs +0 -182
  263. package/src/main/__tests__/scheduler-cross-project-batch.test.cjs +0 -43
  264. package/src/main/__tests__/scheduler-default-eligible-heal.test.cjs +0 -168
  265. package/src/main/__tests__/scheduler-dispatch-loop.test.cjs +0 -58
  266. package/src/main/__tests__/scheduler-effective-concurrency.test.cjs +0 -81
  267. package/src/main/__tests__/scheduler-epic-digest.test.cjs +0 -227
  268. package/src/main/__tests__/scheduler-failed-autoreset.test.cjs +0 -121
  269. package/src/main/__tests__/scheduler-finalize-dispatch-guards.test.cjs +0 -229
  270. package/src/main/__tests__/scheduler-find-prd-dir.test.cjs +0 -75
  271. package/src/main/__tests__/scheduler-fix-plan-path.test.cjs +0 -119
  272. package/src/main/__tests__/scheduler-force-tick-outcome.test.cjs +0 -46
  273. package/src/main/__tests__/scheduler-foreign-wip-manifest.test.cjs +0 -78
  274. package/src/main/__tests__/scheduler-gate-shadow.test.cjs +0 -119
  275. package/src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs +0 -390
  276. package/src/main/__tests__/scheduler-heal-refusal.test.cjs +0 -61
  277. package/src/main/__tests__/scheduler-heartbeat-payload.test.cjs +0 -80
  278. package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +0 -323
  279. package/src/main/__tests__/scheduler-integration-failure-stamp.test.cjs +0 -41
  280. package/src/main/__tests__/scheduler-investigation-clean-skip.test.cjs +0 -63
  281. package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +0 -123
  282. package/src/main/__tests__/scheduler-job-budget.test.cjs +0 -172
  283. package/src/main/__tests__/scheduler-job-overrun.test.cjs +0 -175
  284. package/src/main/__tests__/scheduler-launch-failure.test.cjs +0 -199
  285. package/src/main/__tests__/scheduler-leftover-fields.test.cjs +0 -52
  286. package/src/main/__tests__/scheduler-leftover-quarantine.test.cjs +0 -199
  287. package/src/main/__tests__/scheduler-looks-done.test.cjs +0 -537
  288. package/src/main/__tests__/scheduler-manual-pause.test.cjs +0 -118
  289. package/src/main/__tests__/scheduler-mechanical-recovery.test.cjs +0 -245
  290. package/src/main/__tests__/scheduler-meta-code-sha.test.cjs +0 -46
  291. package/src/main/__tests__/scheduler-mutate-reentrancy.test.cjs +0 -117
  292. package/src/main/__tests__/scheduler-needs-review-autoresolve.test.cjs +0 -197
  293. package/src/main/__tests__/scheduler-never-stop.test.cjs +0 -157
  294. package/src/main/__tests__/scheduler-no-dead-end-status.test.cjs +0 -152
  295. package/src/main/__tests__/scheduler-no-orphan-run-dir.test.cjs +0 -81
  296. package/src/main/__tests__/scheduler-notify-originating-tab-transcript.test.cjs +0 -87
  297. package/src/main/__tests__/scheduler-notify-originating-tab.test.cjs +0 -343
  298. package/src/main/__tests__/scheduler-periodic-reverify-guard.test.cjs +0 -217
  299. package/src/main/__tests__/scheduler-porcelain-rename.test.cjs +0 -164
  300. package/src/main/__tests__/scheduler-prd-missing-skip.test.cjs +0 -161
  301. package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +0 -178
  302. package/src/main/__tests__/scheduler-quarantine-autoresolve.test.cjs +0 -165
  303. package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +0 -257
  304. package/src/main/__tests__/scheduler-rate-limit-cooldown-freshness.test.cjs +0 -123
  305. package/src/main/__tests__/scheduler-rate-limit-pause.test.cjs +0 -152
  306. package/src/main/__tests__/scheduler-rate-limit-spin-guard.test.cjs +0 -156
  307. package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +0 -754
  308. package/src/main/__tests__/scheduler-reaper-helpers-basics.test.cjs +0 -87
  309. package/src/main/__tests__/scheduler-reconcile-cwd-preserve.test.cjs +0 -100
  310. package/src/main/__tests__/scheduler-reconcile-history-backfill.test.cjs +0 -105
  311. package/src/main/__tests__/scheduler-reconcile-invalid-repair.test.cjs +0 -203
  312. package/src/main/__tests__/scheduler-reconcile-quarantine.test.cjs +0 -247
  313. package/src/main/__tests__/scheduler-reset-job-fields-guard.test.cjs +0 -77
  314. package/src/main/__tests__/scheduler-resume-recovery.test.cjs +0 -254
  315. package/src/main/__tests__/scheduler-shard-quarantine.test.cjs +0 -115
  316. package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +0 -380
  317. package/src/main/__tests__/scheduler-sigterm-commit.test.cjs +0 -43
  318. package/src/main/__tests__/scheduler-stall-per-project.test.cjs +0 -126
  319. package/src/main/__tests__/scheduler-starve-escalation.test.cjs +0 -154
  320. package/src/main/__tests__/scheduler-stranded-autofix-park.test.cjs +0 -252
  321. package/src/main/__tests__/scheduler-stranded-investigation.test.cjs +0 -185
  322. package/src/main/__tests__/scheduler-stuck-failed-escalation.test.cjs +0 -136
  323. package/src/main/__tests__/scheduler-supervisor-record.test.cjs +0 -81
  324. package/src/main/__tests__/scheduler-tick-cancel-token.test.cjs +0 -54
  325. package/src/main/__tests__/scheduler-tick-wedge.test.cjs +0 -172
  326. package/src/main/__tests__/scheduler-transient-failure.test.cjs +0 -141
  327. package/src/main/__tests__/scheduler-unreadable-queue-guard.test.cjs +0 -62
  328. package/src/main/__tests__/scheduler-utilization-hold.test.cjs +0 -89
  329. package/src/main/__tests__/scheduler-verify-prd-path.test.cjs +0 -109
  330. package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +0 -234
  331. package/src/main/__tests__/scheduler-worktree-exec-cwd.test.cjs +0 -120
  332. package/src/main/__tests__/scheduler-writeprd-epic-rollback.test.cjs +0 -105
  333. package/src/main/__tests__/schedulerBatchRootBlocker.test.cjs +0 -117
  334. package/src/main/__tests__/schedulerStateSidecarRestore.test.cjs +0 -110
  335. package/src/main/__tests__/seedAgentPersonas.test.cjs +0 -184
  336. package/src/main/__tests__/seedSchedulerMcp.test.cjs +0 -211
  337. package/src/main/__tests__/seedStatus.test.cjs +0 -100
  338. package/src/main/__tests__/seedValidatorPersona.test.cjs +0 -116
  339. package/src/main/__tests__/stop-signal-anchor.test.cjs +0 -75
  340. package/src/main/__tests__/telemetryClient.test.cjs +0 -1055
  341. package/src/main/__tests__/telemetryContract.test.cjs +0 -930
  342. package/src/main/__tests__/telemetrySettings.test.cjs +0 -210
  343. package/src/main/__tests__/transcripts-batch-flush.test.cjs +0 -249
  344. package/src/main/__tests__/transcripts-doFlush-array.test.cjs +0 -124
  345. package/src/main/__tests__/transcripts-paged-reads.test.cjs +0 -241
  346. package/src/main/__tests__/transcripts-worktree-epic-path.test.cjs +0 -154
  347. package/src/main/__tests__/transcriptsUsageFor.test.cjs +0 -206
  348. package/src/main/__tests__/uniquePrdNumbers.test.cjs +0 -153
  349. package/src/main/__tests__/usageSingleFlight.test.cjs +0 -169
  350. package/src/main/__tests__/validationSentinels.test.cjs +0 -84
  351. package/src/main/__tests__/workTypeLibrary.test.cjs +0 -89
  352. package/src/main/bilkoHost.cjs +0 -314
  353. package/src/main/bilkoHostCore.cjs +0 -89
  354. package/src/main/lib/__tests__/active-sessions.test.cjs +0 -251
  355. package/src/main/lib/__tests__/activeIndexRebuild.test.cjs +0 -179
  356. package/src/main/lib/__tests__/agentPersonaSchema.test.cjs +0 -67
  357. package/src/main/lib/__tests__/auditLog.test.cjs +0 -38
  358. package/src/main/lib/__tests__/bootSelfHeal.test.cjs +0 -107
  359. package/src/main/lib/__tests__/branchSweep.test.cjs +0 -164
  360. package/src/main/lib/__tests__/buildIdentity.test.cjs +0 -121
  361. package/src/main/lib/__tests__/buildTarget.test.cjs +0 -52
  362. package/src/main/lib/__tests__/childWithLog.test.cjs +0 -321
  363. package/src/main/lib/__tests__/coldBootPromptSessionsWrite.test.cjs +0 -87
  364. package/src/main/lib/__tests__/crashTelemetry.test.cjs +0 -103
  365. package/src/main/lib/__tests__/credentials-futile-refresh.test.cjs +0 -115
  366. package/src/main/lib/__tests__/cwdClassify.test.cjs +0 -111
  367. package/src/main/lib/__tests__/definitionOfDoneSequence.test.cjs +0 -95
  368. package/src/main/lib/__tests__/delegationReadiness.test.cjs +0 -1175
  369. package/src/main/lib/__tests__/dispatchLoop.test.cjs +0 -63
  370. package/src/main/lib/__tests__/effectiveModelInfo.test.cjs +0 -244
  371. package/src/main/lib/__tests__/ephemeralCwd.test.cjs +0 -91
  372. package/src/main/lib/__tests__/epicDelegationStats.test.cjs +0 -137
  373. package/src/main/lib/__tests__/epicSpawnCwd.test.cjs +0 -283
  374. package/src/main/lib/__tests__/epicSpawnPlan.test.cjs +0 -196
  375. package/src/main/lib/__tests__/epicTranscriptPath.test.cjs +0 -163
  376. package/src/main/lib/__tests__/epicWorktreeBoot.test.cjs +0 -136
  377. package/src/main/lib/__tests__/epicWorktreeMerge.test.cjs +0 -130
  378. package/src/main/lib/__tests__/epicWorktreeMint.test.cjs +0 -117
  379. package/src/main/lib/__tests__/epicWorktreeProjectConfig.test.cjs +0 -137
  380. package/src/main/lib/__tests__/fixChainDepth.test.cjs +0 -40
  381. package/src/main/lib/__tests__/fixtures/204-mercury-steam-horse.log.txt +0 -13
  382. package/src/main/lib/__tests__/fixtures/scheduler-machine.json.corrupt-1789147548 +0 -34
  383. package/src/main/lib/__tests__/gateFixtures.json +0 -20
  384. package/src/main/lib/__tests__/gitCacheBound.test.cjs +0 -69
  385. package/src/main/lib/__tests__/gitWorktree.test.cjs +0 -1478
  386. package/src/main/lib/__tests__/gitWorktreeSalvage.test.cjs +0 -107
  387. package/src/main/lib/__tests__/gitWorktreeSalvageDelta.test.cjs +0 -153
  388. package/src/main/lib/__tests__/guardShims.test.cjs +0 -158
  389. package/src/main/lib/__tests__/importReferences.spec.cjs +0 -56
  390. package/src/main/lib/__tests__/instanceLock.test.cjs +0 -173
  391. package/src/main/lib/__tests__/jobSupervisorRecord.test.cjs +0 -78
  392. package/src/main/lib/__tests__/jobWorktree.test.cjs +0 -199
  393. package/src/main/lib/__tests__/jobWorktreeBootLive.test.cjs +0 -82
  394. package/src/main/lib/__tests__/landedSinceRun.test.cjs +0 -133
  395. package/src/main/lib/__tests__/launchFailure.test.cjs +0 -220
  396. package/src/main/lib/__tests__/loadGate.test.cjs +0 -303
  397. package/src/main/lib/__tests__/localAdminHttp.test.cjs +0 -214
  398. package/src/main/lib/__tests__/loopDelay.test.cjs +0 -68
  399. package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +0 -107
  400. package/src/main/lib/__tests__/modelCatalog.test.cjs +0 -202
  401. package/src/main/lib/__tests__/opsOwnership.test.cjs +0 -113
  402. package/src/main/lib/__tests__/opsRootAbsoluteCwd.test.cjs +0 -328
  403. package/src/main/lib/__tests__/opsRootNestedWrite.test.cjs +0 -51
  404. package/src/main/lib/__tests__/opsRootResolve.test.cjs +0 -149
  405. package/src/main/lib/__tests__/prdDeclaredPaths.test.cjs +0 -82
  406. package/src/main/lib/__tests__/prdDisposition.test.cjs +0 -224
  407. package/src/main/lib/__tests__/procIdentity.test.cjs +0 -119
  408. package/src/main/lib/__tests__/procName.test.cjs +0 -92
  409. package/src/main/lib/__tests__/projectBriefCore.test.cjs +0 -216
  410. package/src/main/lib/__tests__/projectRootResolve.test.cjs +0 -148
  411. package/src/main/lib/__tests__/queueHealth.test.cjs +0 -58
  412. package/src/main/lib/__tests__/queueStoreAtomicWrite.test.cjs +0 -88
  413. package/src/main/lib/__tests__/queueStoreMachineStateRecovery.test.cjs +0 -190
  414. package/src/main/lib/__tests__/quietMachineLease.test.cjs +0 -39
  415. package/src/main/lib/__tests__/rateLimitWindow.test.cjs +0 -88
  416. package/src/main/lib/__tests__/reaperHelpers.test.cjs +0 -577
  417. package/src/main/lib/__tests__/schedulerBatchDepends.test.cjs +0 -312
  418. package/src/main/lib/__tests__/schedulerBatchFairness.test.cjs +0 -213
  419. package/src/main/lib/__tests__/schedulerBatchLaunchHold.test.cjs +0 -125
  420. package/src/main/lib/__tests__/schedulerBatchProjectCap.test.cjs +0 -127
  421. package/src/main/lib/__tests__/schedulerBatchQuietMachine.test.cjs +0 -109
  422. package/src/main/lib/__tests__/schedulerMcpServerHeadlessRefusal.test.cjs +0 -71
  423. package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +0 -216
  424. package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +0 -183
  425. package/src/main/lib/__tests__/schedulerPaths.test.cjs +0 -226
  426. package/src/main/lib/__tests__/schedulerPathsWorktree.test.cjs +0 -133
  427. package/src/main/lib/__tests__/schedulerRuntimeState.test.cjs +0 -56
  428. package/src/main/lib/__tests__/sessionSlots.test.cjs +0 -144
  429. package/src/main/lib/__tests__/telemetryBacklog.test.cjs +0 -626
  430. package/src/main/lib/__tests__/telemetryBoot.test.cjs +0 -134
  431. package/src/main/lib/__tests__/telemetryConsent.test.cjs +0 -136
  432. package/src/main/lib/__tests__/telemetryCounters.test.cjs +0 -57
  433. package/src/main/lib/__tests__/telemetryCountersMetadataColumn.test.cjs +0 -98
  434. package/src/main/lib/__tests__/terminalRunOutcome.test.cjs +0 -200
  435. package/src/main/lib/__tests__/toolUseClassify.test.cjs +0 -53
  436. package/src/main/lib/__tests__/updateCheck.test.cjs +0 -63
  437. package/src/main/lib/__tests__/upgradeDrain.test.cjs +0 -130
  438. package/src/main/lib/__tests__/usageCircuit.test.cjs +0 -354
  439. package/src/main/lib/__tests__/watchdog-helpers.test.cjs +0 -441
  440. package/src/main/lib/__tests__/watchdog-relaunch.test.cjs +0 -266
  441. package/src/main/lib/kgExchangePairing.cjs +0 -75
@@ -1,160 +0,0 @@
1
- /**
2
- * prdUpdateDependsOn.test.cjs — PRD 1124: scheduler.remote.updatePrd accepts
3
- * a `dependsOn` array patch, validates it write-time against the SAME
4
- * resolver (depSlugResolve.cjs) scheduler_create_prd's prdCreate.cjs uses,
5
- * and accepts an explicit empty array to CLEAR the dependency.
6
- *
7
- * Mirrors scheduler-reconcile-quarantine.test.cjs's HOME-isolation fixture.
8
- *
9
- * Run: timeout 120 npx vitest run src/main/__tests__/prdUpdateDependsOn.test.cjs
10
- */
11
-
12
- 'use strict';
13
-
14
- import { test, expect, beforeAll, afterAll } from 'vitest';
15
- const fs = require('node:fs');
16
- const os = require('node:os');
17
- const path = require('node:path');
18
-
19
- let tmpHome;
20
- let originalHome;
21
- let scheduler;
22
- let queueStore;
23
- let config;
24
-
25
- beforeAll(() => {
26
- originalHome = process.env.HOME;
27
- tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-update-prd-dependson-home-'));
28
- process.env.HOME = tmpHome;
29
-
30
- scheduler = require('../scheduler.cjs');
31
- queueStore = require('../lib/queueStore.cjs');
32
- config = require('../config.cjs');
33
-
34
- if (!scheduler.PRDS_DIR.startsWith(tmpHome)) {
35
- throw new Error(`refusing to run: PRDS_DIR (${scheduler.PRDS_DIR}) is not under the temp HOME (${tmpHome})`);
36
- }
37
- });
38
-
39
- afterAll(() => {
40
- process.env.HOME = originalHome;
41
- fs.rmSync(tmpHome, { recursive: true, force: true });
42
- });
43
-
44
- function registerActiveProject(cwd) {
45
- const projectsDir = path.join(tmpHome, '.claude', 'projects');
46
- const slugDir = path.join(projectsDir, `fake-project-slug-${path.basename(cwd)}`);
47
- fs.mkdirSync(slugDir, { recursive: true });
48
- fs.writeFileSync(path.join(slugDir, 'transcript.jsonl'), JSON.stringify({ cwd }) + '\n');
49
- }
50
-
51
- function makeFixtureProject(prefix) {
52
- const cwd = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
53
- registerActiveProject(cwd);
54
- // updatePrd writes through config.writeTextAtomic, which enforces
55
- // validatePath's allowed-write-root boundary (os.homedir() by default).
56
- // The live app widens this via pty.cjs's spawn / activeIndexMerge.cjs's
57
- // boot registration as a side effect of opening the project; a test that
58
- // never spawns a PTY has to register it explicitly, same as
59
- // prdCreate.cjs's own createPrd does for a chat-only Epic.
60
- config.addAllowedRoot(cwd);
61
- const opsRoot = path.join(cwd, 'session-manager-operations');
62
- const prdsDir = path.join(opsRoot, 'scheduler', 'epics', 'test-epic-1', 'prds');
63
- const stateDir = path.join(opsRoot, 'scheduler', 'state');
64
- fs.mkdirSync(prdsDir, { recursive: true });
65
- fs.mkdirSync(stateDir, { recursive: true });
66
- fs.writeFileSync(path.join(stateDir, 'queue.json'), JSON.stringify({ jobs: [] }, null, 2), 'utf8');
67
- queueStore.bustCwdCache();
68
- return { cwd, prdsDir, stateDir };
69
- }
70
-
71
- function writePrd(prdsDir, filename, cwd, extraFrontmatter = '') {
72
- fs.writeFileSync(
73
- path.join(prdsDir, filename),
74
- `---\ntitle: ${filename}\ncwd: ${cwd}\nestimateMinutes: 10\ncreatedVia: scheduler-api\n${extraFrontmatter}---\n\n# Goal\nDo the thing.\n`,
75
- 'utf8',
76
- );
77
- }
78
-
79
- test('updatePrd patches dependsOn to a new valid list naming an existing bare slug', async () => {
80
- const { cwd, prdsDir } = makeFixtureProject('sm-update-dependson-valid-');
81
- try {
82
- writePrd(prdsDir, '3-widget-base.md', cwd);
83
- writePrd(prdsDir, '4-widget-follow-up.md', cwd);
84
-
85
- const result = await scheduler.remote.updatePrd({
86
- slug: '4-widget-follow-up',
87
- cwd,
88
- frontmatter: { dependsOn: ['widget-base'] },
89
- });
90
-
91
- expect(result.ok).toBe(true);
92
- const written = fs.readFileSync(path.join(prdsDir, '4-widget-follow-up.md'), 'utf8');
93
- expect(written).toMatch(/^dependsOn: \[widget-base\]$/m);
94
- } finally {
95
- fs.rmSync(cwd, { recursive: true, force: true });
96
- }
97
- });
98
-
99
- test('updatePrd refuses a dependsOn entry that resolves to no existing PRD, with a near-match suggestion, and writes nothing', async () => {
100
- const { cwd, prdsDir } = makeFixtureProject('sm-update-dependson-invalid-');
101
- try {
102
- writePrd(prdsDir, '3-widget-base.md', cwd);
103
- writePrd(prdsDir, '4-widget-follow-up.md', cwd);
104
- const before = fs.readFileSync(path.join(prdsDir, '4-widget-follow-up.md'), 'utf8');
105
-
106
- const result = await scheduler.remote.updatePrd({
107
- slug: '4-widget-follow-up',
108
- cwd,
109
- frontmatter: { dependsOn: ['wigdet-bsae'] },
110
- });
111
-
112
- expect(result.ok).toBe(false);
113
- expect(result.error).toMatch(/does not resolve to any existing PRD/);
114
- expect(result.error).toMatch(/widget-base/);
115
- const after = fs.readFileSync(path.join(prdsDir, '4-widget-follow-up.md'), 'utf8');
116
- expect(after).toBe(before);
117
- } finally {
118
- fs.rmSync(cwd, { recursive: true, force: true });
119
- }
120
- });
121
-
122
- test('updatePrd patches dependsOn to an explicit empty array, clearing a previously-set dependency without validation', async () => {
123
- const { cwd, prdsDir } = makeFixtureProject('sm-update-dependson-clear-');
124
- try {
125
- writePrd(prdsDir, '3-widget-base.md', cwd);
126
- writePrd(prdsDir, '4-widget-follow-up.md', cwd, 'dependsOn: [widget-base]\n');
127
-
128
- const result = await scheduler.remote.updatePrd({
129
- slug: '4-widget-follow-up',
130
- cwd,
131
- frontmatter: { dependsOn: [] },
132
- });
133
-
134
- expect(result.ok).toBe(true);
135
- const written = fs.readFileSync(path.join(prdsDir, '4-widget-follow-up.md'), 'utf8');
136
- expect(written).not.toContain('dependsOn');
137
- } finally {
138
- fs.rmSync(cwd, { recursive: true, force: true });
139
- }
140
- });
141
-
142
- test('updatePrd patching an unrelated field leaves a PRD with no dependsOn unaffected', async () => {
143
- const { cwd, prdsDir } = makeFixtureProject('sm-update-dependson-unrelated-');
144
- try {
145
- writePrd(prdsDir, '3-standalone.md', cwd);
146
-
147
- const result = await scheduler.remote.updatePrd({
148
- slug: '3-standalone',
149
- cwd,
150
- frontmatter: { estimateMinutes: 25 },
151
- });
152
-
153
- expect(result.ok).toBe(true);
154
- const written = fs.readFileSync(path.join(prdsDir, '3-standalone.md'), 'utf8');
155
- expect(written).not.toContain('dependsOn');
156
- expect(written).toMatch(/^estimateMinutes: 25$/m);
157
- } finally {
158
- fs.rmSync(cwd, { recursive: true, force: true });
159
- }
160
- });
@@ -1,125 +0,0 @@
1
- /**
2
- * proc-role-env.test.cjs — SM_PROC_ROLE attribution env + scripts/sm-ps.cjs.
3
- *
4
- * Run: timeout 120 npx vitest run src/main/__tests__/proc-role-env.test.cjs
5
- */
6
- 'use strict';
7
-
8
- import { test, expect, describe, beforeEach, afterEach } from 'vitest';
9
-
10
- const fs = require('node:fs');
11
- const os = require('node:os');
12
- const path = require('node:path');
13
- const { spawn, spawnSync } = require('node:child_process');
14
-
15
- const { cleanChildEnv, withProcRole, inferProcRole } = require('../lib/cleanEnv.cjs');
16
- const { runClaudeP } = require('../lib/runClaudeP.cjs');
17
- const { runDocEdit } = require('../docEdit.cjs');
18
-
19
- const SM_PS = path.join(__dirname, '..', '..', '..', 'scripts', 'sm-ps.cjs');
20
-
21
- let tmp;
22
- let savedBin;
23
- beforeEach(() => {
24
- tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-proc-role-'));
25
- savedBin = process.env.SM_CLAUDE_BIN;
26
- });
27
- afterEach(() => {
28
- if (savedBin === undefined) delete process.env.SM_CLAUDE_BIN; else process.env.SM_CLAUDE_BIN = savedBin;
29
- fs.rmSync(tmp, { recursive: true, force: true });
30
- });
31
-
32
- /** Stub `claude` that prints {"after":"<SM_PROC_ROLE>"} — valid for both runClaudeP and docEdit. */
33
- function writeStub() {
34
- const bin = path.join(tmp, 'claude-stub.sh');
35
- fs.writeFileSync(bin, '#!/bin/sh\nprintf \'{"after":"%s"}\' "$SM_PROC_ROLE"\n', { mode: 0o755 });
36
- return bin;
37
- }
38
-
39
- describe('cleanChildEnv role stamping', () => {
40
- test('explicit role wins; inference from existing attribution vars; default aux', () => {
41
- expect(cleanChildEnv({ SM_PROC_ROLE: 'shell' }).SM_PROC_ROLE).toBe('shell');
42
- expect(inferProcRole({ SM_SCHEDULER_JOB_SLUG: 's' })).toBe('job');
43
- expect(inferProcRole({ SM_CHAT_SESSION_ID: 'c' })).toBe('chat');
44
- expect(inferProcRole({ SM_CHAT_SESSION_ID: 'c', SESSION_MANAGER_TAB_ID: 'c' })).toBe('shell');
45
- expect(cleanChildEnv().SM_PROC_ROLE).toBe('aux');
46
- });
47
-
48
- test('is additive: existing attribution vars survive and SM_PROC_ROOT is untouched', () => {
49
- const env = cleanChildEnv({ SM_SCHEDULER_JOB_SLUG: 'slug-1', SM_CHAT_SESSION_ID: 'chat-1', SM_PROJECT_ROOT: '/p' });
50
- expect(env).toMatchObject({ SM_PROC_ROLE: 'job', SM_SCHEDULER_JOB_SLUG: 'slug-1', SM_CHAT_SESSION_ID: 'chat-1', SM_PROJECT_ROOT: '/p' });
51
- expect('SM_PROC_ROOT' in env).toBe(process.env.SM_PROC_ROOT !== undefined);
52
- });
53
-
54
- test('withProcRole returns a copy and does not mutate its input', () => {
55
- const base = { A: '1' };
56
- expect(withProcRole(base, 'aux')).toEqual({ A: '1', SM_PROC_ROLE: 'aux' });
57
- expect(base).toEqual({ A: '1' });
58
- });
59
- });
60
-
61
- describe('real spawn paths carry SM_PROC_ROLE', () => {
62
- test('runClaudeP (bypasses cleanChildEnv)', async () => {
63
- process.env.SM_CLAUDE_BIN = writeStub();
64
- const r = await runClaudeP('hi');
65
- expect(r.ok).toBe(true);
66
- expect(JSON.parse(r.out).after).toBe('aux');
67
- });
68
-
69
- test('docEdit runClaude (bypasses cleanChildEnv)', async () => {
70
- process.env.SM_CLAUDE_BIN = writeStub();
71
- const r = await runDocEdit({ path: path.join(os.homedir(), 'x.md'), before: 'a', instruction: 'b', documentText: '' });
72
- expect(r).toEqual({ ok: true, after: 'aux' });
73
- });
74
-
75
- test('cleanChildEnv-built env reaches a spawned child', async () => {
76
- const out = await new Promise((resolve) => {
77
- const c = spawn('/bin/sh', ['-c', 'printf %s "$SM_PROC_ROLE"'], { env: cleanChildEnv({ SM_SCHEDULER_JOB_SLUG: 'x' }) });
78
- let s = '';
79
- c.stdout.on('data', (d) => { s += d; });
80
- c.on('close', () => resolve(s));
81
- });
82
- expect(out).toBe('job');
83
- });
84
- });
85
-
86
- describe('scripts/sm-ps.cjs', () => {
87
- test('--json lists a tagged stub child (and its descendant) with role, slug, project root', async () => {
88
- const env = cleanChildEnv({ SM_SCHEDULER_JOB_SLUG: 'fixture-slug', SM_PROJECT_ROOT: '/fixture/root' });
89
- // outer sh forks an inner sleep, so we also assert descendants are included
90
- const child = spawn('/bin/sh', ['-c', 'sleep 30 & wait'], { env, stdio: 'ignore' });
91
- try {
92
- await new Promise((r) => setTimeout(r, 300));
93
- const res = spawnSync(process.execPath, [SM_PS, '--json'], { encoding: 'utf8', timeout: 20000 });
94
- expect(res.status).toBe(0);
95
- const { processes } = JSON.parse(res.stdout);
96
- const hit = processes.find((p) => p.pid === child.pid);
97
- expect(hit).toMatchObject({ role: 'job', slug: 'fixture-slug', projectRoot: '/fixture/root', attributed: true });
98
- expect(processes.some((p) => p.ppid === child.pid)).toBe(true);
99
- } finally {
100
- try { process.kill(-child.pid); } catch { /* */ }
101
- child.kill('SIGKILL');
102
- }
103
- });
104
-
105
- test('exits 0 with an empty result set when nothing is running (empty proc root)', () => {
106
- const root = path.join(tmp, 'proc');
107
- fs.mkdirSync(root);
108
- const res = spawnSync(process.execPath, [SM_PS, '--json', '--proc-root', root], { encoding: 'utf8' });
109
- expect(res.status).toBe(0);
110
- expect(JSON.parse(res.stdout)).toEqual({ processes: [] });
111
- });
112
-
113
- test('degrades without attribution on unreadable environ / mid-scan exit, never crashes', () => {
114
- const root = path.join(tmp, 'proc');
115
- fs.mkdirSync(path.join(root, '100'), { recursive: true }); // comm-named ours, environ absent
116
- fs.writeFileSync(path.join(root, '100', 'stat'), '100 (sm-watchdog) S 1 0 0');
117
- fs.writeFileSync(path.join(root, '100', 'cmdline'), 'node\0x.js\0');
118
- fs.mkdirSync(path.join(root, '101')); // vanished: no stat at all
119
- const res = spawnSync(process.execPath, [SM_PS, '--json', '--proc-root', root], { encoding: 'utf8' });
120
- expect(res.status).toBe(0);
121
- const { processes } = JSON.parse(res.stdout);
122
- expect(processes).toHaveLength(1);
123
- expect(processes[0]).toMatchObject({ pid: 100, comm: 'sm-watchdog', role: null, attributed: false });
124
- });
125
- });
@@ -1,304 +0,0 @@
1
- /**
2
- * procname-claude-spawn-sites.test.cjs — PRD pn-02: every `claude` spawn site
3
- * execs a role alias (sm-claude-job/-chat/-aux) with a labelled argv0, WITHOUT
4
- * breaking the four /\bclaude\b/ cmdline gates the reapers depend on.
5
- *
6
- * HOME is redirected BEFORE procName/claudeBin/scheduler load (ALIAS_ROOT is
7
- * computed at require time) — never the real ~/.claude. Linux-only for the
8
- * /proc readbacks; the stubs never touch process.cwd().
9
- *
10
- * Run: timeout 300 npx vitest run src/main/__tests__/procname-claude-spawn-sites.test.cjs
11
- */
12
- 'use strict';
13
-
14
- import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest';
15
- const fs = require('node:fs');
16
- const os = require('node:os');
17
- const path = require('node:path');
18
- const { spawn } = require('node:child_process');
19
-
20
- const HAS_PROC = process.platform === 'linux' && fs.existsSync('/proc/self/comm');
21
-
22
- let tmpHome;
23
- let realHome;
24
- let realClaudeBin;
25
- let procName;
26
- let claudeBin;
27
- let scheduler;
28
- let reaper;
29
- let cr;
30
- let childWithLog;
31
- let procIdentity;
32
-
33
- beforeAll(() => {
34
- realHome = process.env.HOME;
35
- realClaudeBin = process.env.SM_CLAUDE_BIN;
36
- tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-pn02-'));
37
- process.env.HOME = tmpHome;
38
- for (const m of ['procName', 'claudeBin']) {
39
- delete require.cache[require.resolve(`../lib/${m}.cjs`)];
40
- }
41
- procName = require('../lib/procName.cjs');
42
- claudeBin = require('../lib/claudeBin.cjs');
43
- scheduler = require('../scheduler.cjs');
44
- reaper = require('../lib/reaperHelpers.cjs');
45
- cr = require('../chatRunner.cjs');
46
- childWithLog = require('../lib/childWithLog.cjs');
47
- procIdentity = require('../lib/procIdentity.cjs');
48
- });
49
-
50
- afterAll(() => {
51
- process.env.HOME = realHome;
52
- if (realClaudeBin === undefined) delete process.env.SM_CLAUDE_BIN;
53
- else process.env.SM_CLAUDE_BIN = realClaudeBin;
54
- fs.rmSync(tmpHome, { recursive: true, force: true });
55
- });
56
-
57
- afterEach(() => {
58
- delete process.env.SM_CLAUDE_BIN;
59
- if (cr) { cr.__resetQueueForTests(); cr.attachWindow(null); }
60
- });
61
-
62
- // Stub `claude`: reports its OWN comm + cmdline (+ prompt) to `capturePath`,
63
- // emits one stream-json result and exits 0. With `linger` it stays alive so a
64
- // test can inspect it from outside.
65
- function writeStub({ capturePath, linger = false } = {}) {
66
- const stubPath = path.join(tmpHome, `stub-${Math.floor(Math.random() * 1e9)}.cjs`);
67
- const body = `
68
- const fs = require('fs');
69
- ${capturePath ? `fs.writeFileSync(${JSON.stringify(capturePath)}, JSON.stringify({
70
- comm: fs.readFileSync('/proc/self/comm', 'utf8').trim(),
71
- cmdline: fs.readFileSync('/proc/self/cmdline', 'utf8').replace(/\\0/g, ' ').trim(),
72
- }));` : ''}
73
- process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', result: 'ok' }) + '\\n');
74
- ${linger ? 'setTimeout(() => process.exit(0), 30000);' : 'process.exit(0);'}
75
- `;
76
- fs.writeFileSync(stubPath, `#!${process.execPath}\n${body}\n`, { mode: 0o755 });
77
- return stubPath;
78
- }
79
-
80
- async function waitFor(fn, timeoutMs = 8000) {
81
- const start = Date.now();
82
- for (;;) {
83
- const v = fn();
84
- if (v) return v;
85
- if (Date.now() - start > timeoutMs) throw new Error('waitFor timed out');
86
- await new Promise((r) => setTimeout(r, 25));
87
- }
88
- }
89
-
90
- function setupProject() {
91
- const projectCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-pn02-project-'));
92
- fs.mkdirSync(path.join(tmpHome, '.claude'), { recursive: true });
93
- const runDir = fs.mkdtempSync(path.join(tmpHome, '.claude', 'pn02-run-'));
94
- return { projectCwd, runDir };
95
- }
96
-
97
- function writePrd(projectCwd, slug) {
98
- const dir = path.join(projectCwd, 'session-manager-operations', 'scheduler', 'prds');
99
- fs.mkdirSync(dir, { recursive: true });
100
- fs.writeFileSync(path.join(dir, `${slug}.md`), 'do the thing', 'utf8');
101
- }
102
-
103
- // Regexes replicated from the live gates; the reaperHelpers functions are ALSO
104
- // exercised for real below.
105
- const GATE = /\bclaude\b/;
106
-
107
- describe('claudeSpawnTarget', () => {
108
- it('skips aliasing entirely and returns the raw value when SM_CLAUDE_BIN is set', () => {
109
- process.env.SM_CLAUDE_BIN = '/tmp/some stub/with spaces';
110
- expect(claudeBin.claudeSpawnTarget('job', 'slug')).toEqual({ command: '/tmp/some stub/with spaces' });
111
- });
112
-
113
- it('aliases each role to its comm and labels argv0 (SM_CLAUDE_BIN unset)', () => {
114
- const real = writeStub();
115
- for (const [role, alias] of [['job', 'sm-claude-job'], ['chat', 'sm-claude-chat'], ['aux', 'sm-claude-aux']]) {
116
- const t = claudeBin.claudeSpawnTarget(role, 'abc', real);
117
- expect(path.basename(t.command)).toBe(alias);
118
- expect(t.argv0).toBe(`sm-claude-${role}:abc`);
119
- expect(fs.readlinkSync(t.command)).toBe(real);
120
- }
121
- });
122
-
123
- it('every real alias name and argv0 label satisfies /\\bclaude\\b/ (round-trip)', () => {
124
- for (const alias of ['sm-claude-job', 'sm-claude-chat', 'sm-claude-aux']) {
125
- expect(GATE.test(alias)).toBe(true);
126
- expect(GATE.test(path.join(procName.procnamesRoot(), alias))).toBe(true);
127
- }
128
- for (const role of ['job', 'chat', 'aux']) {
129
- expect(GATE.test(procName.smArgv0(role, 'a-slug'))).toBe(true);
130
- expect(GATE.test(procName.smArgv0(role, undefined))).toBe(true);
131
- }
132
- });
133
-
134
- it('falls back to the unchanged bin with NO argv0 when aliasing fails open', () => {
135
- expect(claudeBin.claudeSpawnTarget('job', 's', 'definitely-not-a-real-cmd-xyz')).toEqual({ command: 'definitely-not-a-real-cmd-xyz' });
136
- });
137
- });
138
-
139
- describe.skipIf(!HAS_PROC)('real aliased processes vs the reaper gates', () => {
140
- const kids = [];
141
- afterAll(() => { for (const k of kids) { try { process.kill(-k.pid, 'SIGKILL'); } catch { /* gone */ } } });
142
-
143
- function spawnAliased(role, detail, { detached = true } = {}) {
144
- const real = writeStub({ linger: true });
145
- const t = claudeBin.claudeSpawnTarget(role, detail, real);
146
- const child = spawn(t.command, ['-p', `prompt mentioning ${detail}`], {
147
- cwd: os.tmpdir(), stdio: 'ignore', detached, ...(t.argv0 ? { argv0: t.argv0 } : {}),
148
- });
149
- kids.push(child);
150
- return child;
151
- }
152
-
153
- const comm = (pid) => { try { return fs.readFileSync(`/proc/${pid}/comm`, 'utf8').trim(); } catch { return null; } };
154
- const cmdline = (pid) => fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8').replace(/\0/g, ' ');
155
-
156
- it('kernel comm is the alias, cmdline carries the label + slug, and all four gates match', async () => {
157
- const slug = `pn02-slug-${process.pid}-${Date.now()}`;
158
- const child = spawnAliased('job', slug);
159
- await waitFor(() => comm(child.pid) === 'sm-claude-job');
160
- const cmd = cmdline(child.pid);
161
- // A shebang stub's cmdline[0] is the interpreter and [1] the ALIAS PATH (the
162
- // kernel rewrites argv for scripts, so argv0 is not visible); a native
163
- // binary shows the label instead — see the ELF test below.
164
- expect(cmd.includes(path.join(procName.procnamesRoot(), 'sm-claude-job'))).toBe(true);
165
- expect(cmd.includes(slug)).toBe(true);
166
- // scheduler.cjs killOrphanClaudePid + reaperHelpers.cjs:31 / :105 / :107 regexes
167
- expect(GATE.test(cmd)).toBe(true);
168
- expect(reaper.claudePidAlive(child.pid)).toBe(true);
169
- expect(reaper.findLiveProcessForJob({ slug })).toBe(child.pid);
170
- });
171
-
172
- it('a native (ELF) binary shows the smArgv0 label as cmdline[0] and passes every gate', async () => {
173
- const sleepBin = ['/bin/sleep', '/usr/bin/sleep'].find((p) => fs.existsSync(p));
174
- if (!sleepBin) return;
175
- const slug = `pn02-elf-${process.pid}-${Date.now()}`;
176
- const t = claudeBin.claudeSpawnTarget('job', slug, sleepBin);
177
- const child = spawn(t.command, ['30'], { cwd: os.tmpdir(), stdio: 'ignore', detached: true, argv0: t.argv0 });
178
- kids.push(child);
179
- await waitFor(() => comm(child.pid) === 'sm-claude-job');
180
- const cmd = cmdline(child.pid);
181
- expect(cmd.startsWith(`sm-claude-job:${slug}`)).toBe(true);
182
- expect(GATE.test(cmd)).toBe(true);
183
- expect(reaper.claudePidAlive(child.pid)).toBe(true);
184
- expect(reaper.findLiveProcessForJob({ slug })).toBe(child.pid);
185
- expect(scheduler.killOrphanClaudePid(child.pid)).toBe('killed');
186
- });
187
-
188
- it('findLiveProcessForJob still finds the job by slug when the argv0 label is absent (fail-open path)', async () => {
189
- const slug = 'pn02-noargv0-slug';
190
- const real = writeStub({ linger: true });
191
- const child = spawn(real, ['-p', `claude prompt ${slug}`], { cwd: os.tmpdir(), stdio: 'ignore', detached: true });
192
- kids.push(child);
193
- await waitFor(() => { try { return cmdline(child.pid).includes(slug); } catch { return false; } });
194
- expect(reaper.findLiveProcessForJob({ slug })).toBe(child.pid);
195
- });
196
-
197
- it('killOrphanClaudePid kills an aliased process group', async () => {
198
- const child = spawnAliased('job', 'pn02-kill');
199
- await waitFor(() => comm(child.pid) === 'sm-claude-job');
200
- expect(scheduler.killOrphanClaudePid(child.pid)).toBe('killed');
201
- await waitFor(() => child.exitCode !== null || child.signalCode !== null);
202
- });
203
-
204
- it('pid-recycling migration: identity recorded pre-alias OR post-alias for the same pid never vetoes its own kill', async () => {
205
- // Legacy (unaliased) process, identity recorded "before", kill compared "after".
206
- const legacyReal = writeStub({ linger: true });
207
- const legacy = spawn(legacyReal, ['-p', 'claude legacy'], { cwd: os.tmpdir(), stdio: 'ignore', detached: true });
208
- kids.push(legacy);
209
- await waitFor(() => { try { return cmdline(legacy.pid).includes('legacy'); } catch { return false; } });
210
- const recordedLegacy = procIdentity.identity(legacy.pid);
211
- expect(recordedLegacy.complete).toBe(true);
212
- expect(scheduler.killOrphanClaudePid(legacy.pid, recordedLegacy)).toBe('killed');
213
-
214
- const aliased = spawnAliased('job', 'pn02-mig');
215
- await waitFor(() => comm(aliased.pid) === 'sm-claude-job');
216
- const recorded = procIdentity.identity(aliased.pid);
217
- expect(procIdentity.isDifferentProcess(recorded, procIdentity.identity(aliased.pid))).toBe(false);
218
- expect(scheduler.killOrphanClaudePid(aliased.pid, recorded)).toBe('killed');
219
- // A genuinely recycled pid (different cmdline/starttime) is still vetoed.
220
- expect(procIdentity.isDifferentProcess({ ...recorded, cmdline: '/usr/bin/claude -p old' }, { ...recorded, cmdline: 'sm-claude-job:new' })).toBe(true);
221
- });
222
-
223
- it('process-group semantics unchanged: detached child leads its own group; killTree/cancel reaps it', async () => {
224
- const real = writeStub({ linger: true });
225
- const t = claudeBin.claudeSpawnTarget('job', 'pn02-pgid', real);
226
- const fd = fs.openSync(path.join(tmpHome, 'pgid.log'), 'a');
227
- let exit = null;
228
- const { child } = childWithLog.withChildAndLog({
229
- fd, logPath: path.join(tmpHome, 'pgid.log'), safeLog() {}, closeFd() { try { fs.closeSync(fd); } catch { /* */ } },
230
- spawn: { command: t.command, args: ['-p', 'claude x'], options: { cwd: os.tmpdir(), detached: true, ...(t.argv0 ? { argv0: t.argv0 } : {}) } },
231
- onExit(info) { exit = info; },
232
- });
233
- await waitFor(() => comm(child.pid) === 'sm-claude-job');
234
- const stat = fs.readFileSync(`/proc/${child.pid}/stat`, 'utf8');
235
- const pgrp = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[2]);
236
- expect(pgrp).toBe(child.pid);
237
- process.kill(-child.pid, 'SIGTERM');
238
- await waitFor(() => exit);
239
- expect(exit.signal).toBe('SIGTERM');
240
- expect(exit.leakedDescendants).toEqual([]);
241
- });
242
- });
243
-
244
- describe.skipIf(!HAS_PROC)('comm assertions through the real runners', () => {
245
- it('executeJob: the spawned claude has comm sm-claude-job', async () => {
246
- const { projectCwd, runDir } = setupProject();
247
- try {
248
- const slug = `pn02-comm-${process.pid}-${Math.floor(Math.random() * 1e6)}`;
249
- writePrd(projectCwd, slug);
250
- const capturePath = path.join(runDir, 'cap.json');
251
- const stub = writeStub({ capturePath });
252
- // SM_CLAUDE_BIN skips aliasing by design; the test aliases explicitly.
253
- process.env.SM_CLAUDE_BIN = procName.aliasBinFor(stub, 'sm-claude-job');
254
- expect(path.basename(process.env.SM_CLAUDE_BIN)).toBe('sm-claude-job');
255
- const result = await scheduler.executeJob({ slug, cwd: projectCwd }, runDir, projectCwd, () => Promise.resolve());
256
- expect(result.exitCode).toBe(0);
257
- expect(JSON.parse(fs.readFileSync(capturePath, 'utf8')).comm).toBe('sm-claude-job');
258
- } finally {
259
- fs.rmSync(projectCwd, { recursive: true, force: true });
260
- fs.rmSync(runDir, { recursive: true, force: true });
261
- }
262
- });
263
-
264
- it('chatRunner: the spawned claude has comm sm-claude-chat', async () => {
265
- const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-pn02-chat-'));
266
- try {
267
- const capturePath = path.join(tmpHome, 'chat-cap.json');
268
- const stub = writeStub({ capturePath });
269
- process.env.SM_CLAUDE_BIN = procName.aliasBinFor(stub, 'sm-claude-chat');
270
- cr.run({ tabId: 'pn02-tab', sessionId: `pn02-sess-${process.pid}`, prompt: 'hello', cwd, resume: false });
271
- await waitFor(() => fs.existsSync(capturePath));
272
- expect(JSON.parse(fs.readFileSync(capturePath, 'utf8')).comm).toBe('sm-claude-chat');
273
- } finally {
274
- fs.rmSync(cwd, { recursive: true, force: true });
275
- }
276
- });
277
-
278
- it('fail-open: an unusable ALIAS_ROOT still lets the job run to completion', async () => {
279
- const { projectCwd, runDir } = setupProject();
280
- fs.rmSync(procName.procnamesRoot(), { recursive: true, force: true });
281
- fs.mkdirSync(path.dirname(procName.procnamesRoot()), { recursive: true });
282
- fs.writeFileSync(procName.procnamesRoot(), 'not a directory'); // mkdir/symlink under it must fail
283
- try {
284
- const slug = `pn02-failopen-${process.pid}`;
285
- writePrd(projectCwd, slug);
286
- const capturePath = path.join(runDir, 'cap.json');
287
- const stub = writeStub({ capturePath });
288
- const aliased = procName.aliasBinFor(stub, 'sm-claude-job');
289
- expect(aliased).toBe(stub); // failed open
290
- process.env.SM_CLAUDE_BIN = aliased;
291
- const result = await scheduler.executeJob({ slug, cwd: projectCwd }, runDir, projectCwd, () => Promise.resolve());
292
- expect(result.exitCode).toBe(0);
293
- // Unaliased: comm is the stub's own basename, not an sm-claude-* name.
294
- expect(JSON.parse(fs.readFileSync(capturePath, 'utf8')).comm).not.toMatch(/^sm-claude-/);
295
- // And the target helper degrades to the raw bin with no argv0.
296
- delete process.env.SM_CLAUDE_BIN;
297
- expect(claudeBin.claudeSpawnTarget('job', slug, stub)).toEqual({ command: stub });
298
- } finally {
299
- fs.rmSync(procName.procnamesRoot(), { force: true });
300
- fs.rmSync(projectCwd, { recursive: true, force: true });
301
- fs.rmSync(runDir, { recursive: true, force: true });
302
- }
303
- });
304
- });