claude-code-session-manager 0.141.0 → 0.143.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 (223) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +76 -153
  3. package/bin/cli.cjs +11 -0
  4. package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
  5. package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
  6. package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
  7. package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
  8. package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
  9. package/dist/assets/Scheduler-CNLjn90m.js +16 -0
  10. package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
  11. package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
  12. package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
  13. package/dist/assets/Toggle-CYajnSdx.js +1 -0
  14. package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
  15. package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
  16. package/dist/assets/index-CdTppjKR.js +3133 -0
  17. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  18. package/dist/index.html +2 -2
  19. package/dist-web/app.css +1 -1
  20. package/dist-web/app.js +496 -484
  21. package/package.json +6 -4
  22. package/plugins/AGENTS.md +4 -3
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  25. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  26. package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
  27. package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
  28. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  29. package/scripts/README.md +2 -0
  30. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  31. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  32. package/scripts/scheduler-mcp-server.cjs +1032 -112
  33. package/src/main/adminRouteRegistry.cjs +69 -0
  34. package/src/main/agentLibrary.cjs +72 -4
  35. package/src/main/agentsIpc.cjs +3 -2
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/chatRunner.cjs +336 -23
  38. package/src/main/config.cjs +35 -1
  39. package/src/main/docEdit.cjs +4 -2
  40. package/src/main/health.cjs +129 -2
  41. package/src/main/index.cjs +110 -52
  42. package/src/main/ipcSchemas.cjs +172 -8
  43. package/src/main/lib/AGENTS.md +1 -1
  44. package/src/main/lib/chatBootRecovery.cjs +2 -0
  45. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  46. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  47. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  48. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  49. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  50. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  51. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  52. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  53. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  54. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  55. package/src/main/lib/demo-video-kit/cast.md +52 -0
  56. package/src/main/lib/demo-video-kit/character.cjs +778 -30
  57. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  58. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  59. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  60. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  61. package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
  62. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  63. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  64. package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
  65. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  66. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  67. package/src/main/lib/demo-video-kit/sound.cjs +166 -9
  68. package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
  69. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  70. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  71. package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
  72. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  73. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  74. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  75. package/src/main/lib/epic/artifactRetention.cjs +356 -0
  76. package/src/main/lib/epic/artifactStore.cjs +435 -0
  77. package/src/main/lib/epic/delegationReadiness.cjs +83 -2
  78. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  79. package/src/main/lib/epic/epicEventLog.cjs +258 -0
  80. package/src/main/lib/epic/epicMint.cjs +43 -1
  81. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  82. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  83. package/src/main/lib/epic/epicPurge.cjs +347 -0
  84. package/src/main/lib/epic/epicReopen.cjs +5 -2
  85. package/src/main/lib/epic/epicSettle.cjs +4 -13
  86. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  87. package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
  88. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  89. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  90. package/src/main/lib/epic/epicValidationHook.cjs +94 -4
  91. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  92. package/src/main/lib/externalContract.cjs +48 -4
  93. package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
  94. package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
  95. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  96. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  97. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  98. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  99. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  100. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  101. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  102. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  103. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  104. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  105. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  106. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
  107. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  108. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  109. package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
  110. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
  111. package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
  112. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  113. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  114. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  115. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  116. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  117. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  118. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  119. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  120. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  121. package/src/main/lib/git/gitWorktree.cjs +8 -0
  122. package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
  123. package/src/main/lib/git/worktreeDeps.cjs +182 -4
  124. package/src/main/lib/mcpToolCatalog.cjs +399 -29
  125. package/src/main/lib/opsOwnership.cjs +141 -28
  126. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  127. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  128. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  129. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  130. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  131. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  132. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  133. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
  134. package/src/main/lib/phaseProjection.cjs +103 -0
  135. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  136. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  137. package/src/main/lib/prd/prdCreate.cjs +387 -228
  138. package/src/main/lib/prd/prdCriteria.cjs +228 -0
  139. package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
  140. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  141. package/src/main/lib/prd/prdSizing.cjs +3 -1
  142. package/src/main/lib/process/cleanEnv.cjs +52 -1
  143. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  144. package/src/main/lib/process/memoryScope.cjs +31 -3
  145. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  146. package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
  147. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  148. package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
  149. package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
  150. package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
  151. package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
  152. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  153. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  154. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  155. package/src/main/lib/promptSessionSchema.cjs +6 -0
  156. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  157. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  158. package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
  159. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  160. package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
  161. package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
  162. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  163. package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
  164. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
  165. package/src/main/lib/scheduler/queueStore.cjs +16 -0
  166. package/src/main/lib/scheduler/rcaReport.cjs +79 -15
  167. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  168. package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
  169. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  170. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  171. package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
  172. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  173. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  174. package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
  175. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  176. package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
  177. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
  178. package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
  179. package/src/main/lib/tasks/mitigationReview.cjs +314 -0
  180. package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
  181. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  182. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  183. package/src/main/lib/tasks/taskRun.cjs +186 -17
  184. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  185. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  186. package/src/main/lib/telemetry/auditEvents.cjs +204 -6
  187. package/src/main/lib/telemetry/auditLog.cjs +6 -2
  188. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  189. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  190. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  191. package/src/main/lib/toolUseClassify.cjs +181 -0
  192. package/src/main/lib/util/atomicFs.cjs +2 -2
  193. package/src/main/lib/util/smfileRange.cjs +77 -0
  194. package/src/main/projectPages.cjs +3 -1
  195. package/src/main/promptSessionEvents.cjs +21 -1
  196. package/src/main/pty.cjs +77 -0
  197. package/src/main/queueOps.cjs +33 -14
  198. package/src/main/runVerify.cjs +74 -9
  199. package/src/main/scheduler/AGENTS.md +1 -0
  200. package/src/main/scheduler/budget.cjs +6 -5
  201. package/src/main/scheduler/prdParser.cjs +46 -13
  202. package/src/main/scheduler/reviewLadder.cjs +9 -25
  203. package/src/main/scheduler/utilizationHold.cjs +191 -0
  204. package/src/main/scheduler.cjs +1932 -213
  205. package/src/main/templates/PRD_AUTHORING.md +11 -3
  206. package/src/main/webRemote.cjs +463 -6
  207. package/src/preload/api.d.ts +576 -39
  208. package/src/preload/apiSurface.json +223 -7
  209. package/src/preload/index.cjs +48 -1
  210. package/src/seed/agents/architect.md +6 -1
  211. package/src/seed/agents/blender-artist.md +2 -1
  212. package/src/seed/agents/competitive-analyst.md +3 -1
  213. package/src/seed/agents/competitive-researcher.md +2 -1
  214. package/src/seed/agents/demo-video-builder.md +98 -87
  215. package/src/seed/agents/dev-lead.md +3 -3
  216. package/src/seed/agents/project-home-builder.md +9 -31
  217. package/src/seed/agents/validator.md +23 -23
  218. package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
  219. package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
  220. package/dist/assets/Scheduler-cyr61UAC.js +0 -16
  221. package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
  222. package/dist/assets/index-B2TQz3nd.js +0 -3121
  223. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * phaseProjection.cjs — one outside "phase" for every Epic, scheduler job and Task.
5
+ *
6
+ * Top-level in lib/ (not under epic/, scheduler/ or tasks/) because it spans
7
+ * all three domains: each has its own status vocabulary, and an outside
8
+ * reader needs ONE small answer to "is anything happening, and is it mine to
9
+ * act on?". Pure: no fs, no clock, no mutation.
10
+ *
11
+ * idle — nothing is running and nothing is asked of anyone
12
+ * running — work is in flight (or queued to run)
13
+ * rescheduling — something stopped and the scheduler's own recovery
14
+ * ladder is still working on it
15
+ * waiting_on_human — a real question is open, or the ladder gave up
16
+ * terminated — finished for good (done, skipped, cancelled, closed)
17
+ *
18
+ * Matches src/renderer/lib/needsHuman.ts: a needs_review park is the
19
+ * scheduler's job ("being fixed"), never the human's — UNTIL the ladder gives
20
+ * up. The ladder's give-up signal is the grouped review notice going out
21
+ * (reviewNotice.sentAt — sent only when the ladder fails or the hold window
22
+ * ends; lib/scheduler/reviewNotice.cjs), or a park the ladder never touches
23
+ * by design (verdict 'refire_capped', see scheduler/reviewLadder.cjs
24
+ * isRefireCapped). A run that asked a question (verdict 'needs_human') and an
25
+ * Epic chat with an open question (needs-input) are real questions.
26
+ */
27
+
28
+ const { isCancelledRow } = require('./scheduler/cancelledRow.cjs');
29
+
30
+ const PHASES = Object.freeze(['idle', 'running', 'rescheduling', 'waiting_on_human', 'terminated']);
31
+
32
+ /** Precedence when several jobs make up one Epic: the first match wins. */
33
+ const EPIC_PRECEDENCE = Object.freeze(['waiting_on_human', 'rescheduling', 'running']);
34
+
35
+ const isObj = (v) => v != null && typeof v === 'object';
36
+
37
+ /** True when a needs_review row is no longer the ladder's to fix. */
38
+ function ladderGaveUp(job) {
39
+ if (job.verifierVerdict === 'refire_capped') return true;
40
+ const n = isObj(job.reviewNotice) ? job.reviewNotice : null;
41
+ return !!(n && typeof n.sentAt === 'string' && n.sentAt);
42
+ }
43
+
44
+ /**
45
+ * @param {any} job a scheduler queue row (or any { status, ... } shape)
46
+ * @returns {'idle'|'running'|'rescheduling'|'waiting_on_human'|'terminated'}
47
+ */
48
+ function phaseOfJob(job) {
49
+ if (!isObj(job)) return 'idle';
50
+ const status = typeof job.status === 'string' ? job.status : '';
51
+ if (isCancelledRow(job)) return 'terminated';
52
+ switch (status) {
53
+ case 'pending': return 'idle';
54
+ case 'running': return 'running';
55
+ // An auto-fix investigation and a quarantine are both ladder rungs.
56
+ case 'investigating':
57
+ case 'quarantined': return 'rescheduling';
58
+ case 'failed': return ladderGaveUp(job) ? 'waiting_on_human' : 'rescheduling';
59
+ case 'needs_review':
60
+ if (job.verifierVerdict === 'needs_human') return 'waiting_on_human';
61
+ return ladderGaveUp(job) ? 'waiting_on_human' : 'rescheduling';
62
+ case 'completed':
63
+ case 'skipped': return 'terminated';
64
+ default: return 'idle';
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @param {{ status?: string, needsInput?: boolean, chatBusy?: boolean, jobPhases?: string[], refuted?: number }} [args]
70
+ * status — the Epic's lifecycle status (proposed / active / completed)
71
+ * jobPhases — phaseOfJob of each of the Epic's known PRDs
72
+ * refuted — count of PRDs whose newest verdict is refuted (the Epic's
73
+ * automated turn queues their fix, so: rescheduling)
74
+ * @returns {'idle'|'running'|'rescheduling'|'waiting_on_human'|'terminated'}
75
+ */
76
+ function phaseOfEpic(args) {
77
+ const a = isObj(args) ? args : {};
78
+ if (a.status === 'completed') return 'terminated';
79
+ // A proposed Epic waits for a human to approve it.
80
+ if (a.status === 'proposed') return 'waiting_on_human';
81
+ if (a.needsInput === true && a.chatBusy !== true) return 'waiting_on_human';
82
+ const phases = Array.isArray(a.jobPhases) ? a.jobPhases : [];
83
+ if (phases.includes('waiting_on_human')) return 'waiting_on_human';
84
+ if (phases.includes('rescheduling') || (typeof a.refuted === 'number' && a.refuted > 0)) return 'rescheduling';
85
+ // A queued (idle) PRD inside an active Epic is work about to run.
86
+ if (a.chatBusy === true || phases.includes('running') || phases.includes('idle')) return 'running';
87
+ return 'idle';
88
+ }
89
+
90
+ /**
91
+ * @param {any} task a folded Task ledger row ({ status: 'running' | an end status })
92
+ * @returns {'idle'|'running'|'rescheduling'|'waiting_on_human'|'terminated'}
93
+ */
94
+ function phaseOfTask(task) {
95
+ const status = isObj(task) && typeof task.status === 'string' ? task.status : '';
96
+ if (!status) return 'idle';
97
+ if (status === 'running') return 'running';
98
+ // Every other Task status is a terminal end status (taskLedger.cjs
99
+ // TERMINAL_STATUSES); a Task is never retried by Session Manager.
100
+ return 'terminated';
101
+ }
102
+
103
+ module.exports = { PHASES, EPIC_PRECEDENCE, phaseOfJob, phaseOfEpic, phaseOfTask };
@@ -16,6 +16,8 @@
16
16
  * record and Epic ordering on top of the same bare-name rule.
17
17
  */
18
18
 
19
+ const { isCancelledRow } = require('../scheduler/cancelledRow.cjs');
20
+
19
21
  /** Strip one leading `NN-` prefix, if present. */
20
22
  function bareSlug(slug) {
21
23
  return String(slug ?? '').replace(/^\d+-/, '');
@@ -86,17 +88,6 @@ function findNearMatches(depSlug, candidateSlugs, limit = 3) {
86
88
  .map((entry) => entry.slug);
87
89
  }
88
90
 
89
- /**
90
- * Was this row cancelled by a human (admin API cancel), rather than failing on
91
- * its own? scheduler.cjs's cancel handler stamps `cancelledAt` and an error
92
- * starting 'cancelled via admin API'; either marker counts.
93
- */
94
- function isCancelledRow(row) {
95
- if (!row) return false;
96
- if (typeof row.cancelledAt === 'string' ? row.cancelledAt.length > 0 : row.cancelledAt != null) return true;
97
- return typeof row.error === 'string' && row.error.startsWith('cancelled via admin API');
98
- }
99
-
100
91
  /** The Epic a queue row belongs to: `epicId`, else its `sourcePromptId`. */
101
92
  function epicOf(job) {
102
93
  return job?.epicId ?? job?.sourcePromptId ?? null;
@@ -125,7 +116,7 @@ function isPrefixedSlug(slug) {
125
116
  * dependent's Epic → 'row'
126
117
  * 5. bare dep: a satisfied record with that bare name → 'satisfied'
127
118
  * 6. → 'unresolved'
128
- * In steps 3-4 a cancelled row (isCancelledRow) is dropped when a satisfied
119
+ * In steps 3-4 a cancelled row (isCancelledRow, lib/scheduler/cancelledRow.cjs) is dropped when a satisfied
129
120
  * record shares its bare name — a human-cancelled duplicate must never freeze
130
121
  * the dependents of the PRD that genuinely finished (Self, 2026-11-22: the
131
122
  * cancelled 1056-sm-contract-client froze 16 dependents of the completed
@@ -183,5 +174,5 @@ function makeDepResolver(projectJobs, satisfiedSlugs = new Set(), opts = {}) {
183
174
  }
184
175
 
185
176
  module.exports = {
186
- bareSlug, resolveDepSlug, findNearMatches, isSatisfiedDepRow, isCancelledRow, epicOf, makeDepResolver,
177
+ bareSlug, resolveDepSlug, findNearMatches, isSatisfiedDepRow, epicOf, makeDepResolver,
187
178
  };
@@ -8,6 +8,7 @@
8
8
 
9
9
  const { validateGate, validateFiles, renderFilesSection, renderGateSection } = require('./prdGateFiles.cjs');
10
10
  const { resolveGate, parseChain, isNoneGate } = require('../scheduler/definitionOfDone.cjs');
11
+ const { validateCriteria, renderCriteriaLines } = require('./prdCriteria.cjs');
11
12
 
12
13
  const H_AC = '# Acceptance criteria';
13
14
  const H_FILES = '# Files';
@@ -58,8 +59,11 @@ function gateSignature(body) {
58
59
 
59
60
  /**
60
61
  * @param {string} body
61
- * @param {{gate?: string[], files?: string[], acceptanceCriteria?: string[]}} patch
62
- * @returns {{ok:true, body:string, warnings:string[]}|{ok:false, error:string}}
62
+ * @param {{gate?: string[], files?: string[], acceptanceCriteria?: unknown[], previousCriteria?: unknown}} patch
63
+ * acceptanceCriteria entries are strings or structured criteria (prdCriteria.cjs);
64
+ * previousCriteria (the PRD's frontmatter `criteria`) keeps ids stable.
65
+ * @returns {{ok:true, body:string, warnings:string[], criteria?: object[]}|{ok:false, error:string}}
66
+ * `criteria` (when acceptanceCriteria was patched) is what the caller writes to frontmatter.
63
67
  */
64
68
  function applyStructuredPrdPatch(body, patch) {
65
69
  if (typeof body !== 'string') return { ok: false, error: 'body must be a string.' };
@@ -87,21 +91,12 @@ function applyStructuredPrdPatch(body, patch) {
87
91
  if (!f.ok) return { ok: false, error: f.error };
88
92
  filesList = f.files;
89
93
  }
94
+ let criteria = null;
90
95
  if (hasAc) {
91
- const ac = patch.acceptanceCriteria;
92
- if (!Array.isArray(ac) || ac.length === 0) {
93
- return { ok: false, error: 'acceptanceCriteria must be a non-empty array of strings.' };
94
- }
95
- acLines = [];
96
- for (let i = 0; i < ac.length; i++) {
97
- if (typeof ac[i] !== 'string' || ac[i].trim() === '') {
98
- return { ok: false, error: `acceptanceCriteria entry ${i + 1}: must be a non-empty string.` };
99
- }
100
- if (/[\r\n]/.test(ac[i])) {
101
- return { ok: false, error: `acceptanceCriteria entry ${i + 1}: must not contain a newline.` };
102
- }
103
- acLines.push(`- [ ] ${ac[i].trim()}`);
104
- }
96
+ const cv = validateCriteria(patch.acceptanceCriteria, { previous: patch.previousCriteria });
97
+ if (!cv.ok) return { ok: false, error: `acceptanceCriteria: ${cv.error}` };
98
+ criteria = cv.criteria;
99
+ acLines = renderCriteriaLines(criteria);
105
100
  }
106
101
 
107
102
  const lines = body.split('\n');
@@ -132,7 +127,7 @@ function applyStructuredPrdPatch(body, patch) {
132
127
  return { ok: false, error: 'The patch would change how the scheduler reads the PRD gate (stray gate fence in the new text).' };
133
128
  }
134
129
 
135
- return { ok: true, body: next, warnings };
130
+ return criteria ? { ok: true, body: next, warnings, criteria } : { ok: true, body: next, warnings };
136
131
  }
137
132
 
138
133
  module.exports = { applyStructuredPrdPatch };