claude-code-session-manager 0.138.0 → 0.140.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 (194) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +352 -79
  3. package/dist/assets/AppSettings-CMFEM68R.js +2 -0
  4. package/dist/assets/History--JwsFnbn.js +2 -0
  5. package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
  6. package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
  7. package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
  8. package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
  10. package/dist/assets/Skills-DtRzghn5.js +67 -0
  11. package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
  12. package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
  13. package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
  14. package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
  15. package/dist/assets/index-CtxruO1L.js +3121 -0
  16. package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +467 -451
  20. package/package.json +17 -6
  21. package/plugins/AGENTS.md +60 -0
  22. package/plugins/CLAUDE.md +1 -60
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
  25. package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
  26. package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
  27. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
  28. package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
  29. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
  30. package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
  31. package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
  32. package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
  33. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
  34. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
  35. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
  36. package/scripts/README.md +2 -0
  37. package/scripts/hooks/guard-tool-risk.cjs +91 -0
  38. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
  39. package/scripts/ops-sweep.cjs +53 -23
  40. package/scripts/scheduler-mcp-server.cjs +360 -35
  41. package/src/main/build-info.json +4 -4
  42. package/src/main/chatRunner.cjs +2 -2
  43. package/src/main/config.cjs +112 -8
  44. package/src/main/docEdit.cjs +6 -1
  45. package/src/main/exchanges.cjs +70 -5
  46. package/src/main/files.cjs +7 -27
  47. package/src/main/health.cjs +48 -15
  48. package/src/main/historyAggregator.cjs +172 -63
  49. package/src/main/historyDashboard.cjs +87 -17
  50. package/src/main/index.cjs +78 -4
  51. package/src/main/ipcSchemas.cjs +233 -20
  52. package/src/main/lib/AGENTS.md +54 -0
  53. package/src/main/lib/CLAUDE.md +1 -54
  54. package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
  55. package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
  56. package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
  57. package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
  58. package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
  59. package/src/main/lib/claude/effectiveModelInfo.cjs +92 -22
  60. package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
  61. package/src/main/lib/claude/modelPricing.cjs +148 -0
  62. package/src/main/lib/claude/personaToolScope.cjs +12 -6
  63. package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
  64. package/src/main/lib/claude/runClaudeP.cjs +6 -1
  65. package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
  66. package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
  67. package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
  68. package/src/main/lib/ephemeralCwd.cjs +37 -2
  69. package/src/main/lib/epic/delegationReadiness.cjs +42 -9
  70. package/src/main/lib/epic/epicAdminRoutes.cjs +121 -0
  71. package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
  72. package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
  73. package/src/main/lib/epic/epicOutsideState.cjs +233 -0
  74. package/src/main/lib/epic/epicSettle.cjs +1 -1
  75. package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
  76. package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
  77. package/src/main/lib/epic/epicValidationHook.cjs +24 -4
  78. package/src/main/lib/epic/externalRef.cjs +37 -0
  79. package/src/main/lib/epic/externalRefIndex.cjs +136 -0
  80. package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
  81. package/src/main/lib/epic/restorableSessions.cjs +151 -17
  82. package/src/main/lib/epic/transcriptUsage.cjs +197 -0
  83. package/src/main/lib/externalContract.cjs +137 -0
  84. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
  85. package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
  86. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
  87. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
  88. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
  89. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
  90. package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
  91. package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
  92. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
  93. package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
  94. package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
  95. package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
  96. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
  97. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
  98. package/src/main/lib/git/branchSweep.cjs +209 -4
  99. package/src/main/lib/git/gitWorktree.cjs +41 -5
  100. package/src/main/lib/guardShims.cjs +1 -1
  101. package/src/main/lib/historyRollup.cjs +58 -5
  102. package/src/main/lib/insideHome.cjs +27 -1
  103. package/src/main/lib/mcpToolCatalog.cjs +232 -25
  104. package/src/main/lib/mdDocCensus.cjs +59 -78
  105. package/src/main/lib/mdDocRefs.cjs +71 -93
  106. package/src/main/lib/mdNetworkScan.cjs +245 -250
  107. package/src/main/lib/mdReviewRecord.cjs +22 -9
  108. package/src/main/lib/memoryMdNetwork.cjs +5 -12
  109. package/src/main/lib/opsOwnership.cjs +18 -2
  110. package/src/main/lib/opsRetentionSettings.cjs +28 -4
  111. package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
  112. package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
  113. package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
  114. package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
  115. package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
  116. package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
  117. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
  118. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  119. package/src/main/lib/prd/depSlugResolve.cjs +104 -4
  120. package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
  121. package/src/main/lib/prd/prdCreate.cjs +351 -23
  122. package/src/main/lib/prd/prdDisposition.cjs +11 -2
  123. package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
  124. package/src/main/lib/process/loginItem.cjs +171 -0
  125. package/src/main/lib/process/loginItemPlan.cjs +193 -0
  126. package/src/main/lib/project-pages/playerBridge.cjs +4 -0
  127. package/src/main/lib/project-pages/videoReview.cjs +268 -0
  128. package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
  129. package/src/main/lib/promptSessionSchema.cjs +4 -0
  130. package/src/main/lib/remoteTranscriptTail.cjs +32 -1
  131. package/src/main/lib/scheduler/cpuSample.cjs +131 -4
  132. package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
  133. package/src/main/lib/scheduler/loadGate.cjs +24 -6
  134. package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
  135. package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
  136. package/src/main/lib/scheduler/queueStore.cjs +7 -0
  137. package/src/main/lib/scheduler/rcaReport.cjs +21 -1
  138. package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
  139. package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
  140. package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
  141. package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
  142. package/src/main/lib/scheduler/schedulerPaths.cjs +12 -0
  143. package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
  144. package/src/main/lib/scheduler/validationQuality.cjs +282 -0
  145. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
  146. package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
  147. package/src/main/lib/tasks/taskIpc.cjs +80 -0
  148. package/src/main/lib/tasks/taskLedger.cjs +502 -0
  149. package/src/main/lib/tasks/taskRun.cjs +313 -0
  150. package/src/main/lib/tasks/taskSwitch.cjs +120 -0
  151. package/src/main/lib/telemetry/auditEvents.cjs +176 -0
  152. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
  153. package/src/main/loginItemIpc.cjs +35 -0
  154. package/src/main/loopEfficiencyHandlers.cjs +11 -2
  155. package/src/main/projectPages.cjs +6 -15
  156. package/src/main/promptSessionEvents.cjs +9 -1
  157. package/src/main/queueOps.cjs +260 -3
  158. package/src/main/runVerify.cjs +53 -25
  159. package/src/main/scheduler/AGENTS.md +26 -0
  160. package/src/main/scheduler/CLAUDE.md +1 -26
  161. package/src/main/scheduler/budget.cjs +239 -9
  162. package/src/main/scheduler/cancelDependents.cjs +154 -0
  163. package/src/main/scheduler/prdParser.cjs +4 -1
  164. package/src/main/scheduler/starvation.cjs +20 -18
  165. package/src/main/scheduler.cjs +774 -64
  166. package/src/main/supervisor.cjs +5 -1
  167. package/src/main/templates/PRD_AUTHORING.md +7 -1
  168. package/src/main/transcripts.cjs +62 -7
  169. package/src/main/validationQualityHandlers.cjs +199 -0
  170. package/src/main/webRemote.cjs +132 -20
  171. package/src/preload/api.d.ts +434 -28
  172. package/src/preload/apiSurface.cjs +7 -0
  173. package/src/preload/apiSurface.json +485 -81
  174. package/src/preload/index.cjs +38 -5
  175. package/src/seed/agents/validator.md +19 -8
  176. package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
  177. package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
  178. package/dist/assets/Button-Bk23rEnZ.js +0 -1
  179. package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
  180. package/dist/assets/Extensions-CXem-uwI.js +0 -2
  181. package/dist/assets/History-BwO3coo4.js +0 -2
  182. package/dist/assets/Library-BDV69fSe.js +0 -32
  183. package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
  184. package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
  185. package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
  186. package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
  187. package/dist/assets/Settings-COT34hBF.js +0 -2
  188. package/dist/assets/Skills-BgexoUkQ.js +0 -29
  189. package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
  190. package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
  191. package/dist/assets/Toggle-CENi19iK.js +0 -1
  192. package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
  193. package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
  194. package/dist/assets/index-CgCxpunJ.js +0 -3116
@@ -21,32 +21,92 @@ const os = require('node:os');
21
21
  const path = require('node:path');
22
22
  const { execFileSync } = require('node:child_process');
23
23
 
24
+ const { lexer } = require('marked');
25
+
24
26
  const MAX_IMPORT_DEPTH = 5;
25
- // Matches a line consisting of `@` followed by an absolute or ~-relative path,
26
- // e.g. "@/home/user/foo.md" or "@~/Projects/Agents/shared/core.md".
27
- const IMPORT_LINE_RE = /^@(~?\/\S+)\s*$/;
27
+ // The claude CLI's (v2.1.325) @-import token rule: `@` at line start or after
28
+ // whitespace, then a run of non-space chars where `\ ` is an escaped space.
29
+ const IMPORT_TOKEN_RE = /(?:^|\s)@((?:[^\s\\]|\\ )+)/g;
30
+ const EXPLICIT_PREFIXES = ['./', '../', '~/', '/'];
28
31
 
29
- function resolveImportPath(rawPath) {
32
+ function resolveImportPath(rawPath, fromFile) {
30
33
  if (rawPath.startsWith('~/')) return path.join(os.homedir(), rawPath.slice(2));
31
34
  if (rawPath === '~') return os.homedir();
32
- return rawPath;
35
+ if (path.isAbsolute(rawPath) || !fromFile) return rawPath;
36
+ return path.resolve(path.dirname(fromFile), rawPath);
37
+ }
38
+
39
+ // Same acceptance test the CLI applies to a token after fragment-cut + unescape.
40
+ function isImportToken(tok) {
41
+ if (tok.startsWith('./') || tok.startsWith('~/')) return true;
42
+ if (tok.startsWith('/')) return tok !== '/';
43
+ return !tok.startsWith('@') && !/^[#%^&*()]+/.test(tok) && /^[a-zA-Z0-9._-]/.test(tok);
44
+ }
45
+
46
+ function scanText(text, fromFile, out) {
47
+ IMPORT_TOKEN_RE.lastIndex = 0;
48
+ let m;
49
+ while ((m = IMPORT_TOKEN_RE.exec(text)) !== null) {
50
+ const raw = m[1];
51
+ if (!raw) continue;
52
+ let tok = raw;
53
+ const hash = tok.indexOf('#');
54
+ if (hash !== -1) tok = tok.substring(0, hash);
55
+ if (!tok) continue;
56
+ tok = tok.replaceAll('\\ ', ' ');
57
+ if (!tok || !isImportToken(tok)) continue;
58
+ // Whole-line check: the line holding this match is exactly `@<raw>`.
59
+ const atIdx = m.index + m[0].length - raw.length - 1;
60
+ const lineStart = text.lastIndexOf('\n', atIdx) + 1;
61
+ const nl = text.indexOf('\n', atIdx);
62
+ const line = text.slice(lineStart, nl === -1 ? text.length : nl).trim();
63
+ const explicit = EXPLICIT_PREFIXES.some((p) => tok.startsWith(p)) || line === `@${raw}`;
64
+ out.push({ path: resolveImportPath(tok, fromFile), explicit });
65
+ }
33
66
  }
34
67
 
35
- // Extracts every `@<path>` import reference from a file's raw text content.
36
- function extractImportPaths(content) {
37
- const paths = [];
38
- for (const line of content.split('\n')) {
39
- const match = IMPORT_LINE_RE.exec(line.trim());
40
- if (match) paths.push(resolveImportPath(match[1]));
68
+ function walkTokens(tokens, fromFile, out) {
69
+ for (const t of tokens) {
70
+ if (t.type === 'code' || t.type === 'codespan') continue;
71
+ if (t.type === 'html') {
72
+ const raw = t.raw || '';
73
+ const trimmed = raw.trimStart();
74
+ if (trimmed.startsWith('<!--') && trimmed.includes('-->')) {
75
+ const rest = raw.replace(/<!--[\s\S]*?-->/g, '');
76
+ if (rest.trim().length > 0) scanText(rest, fromFile, out);
77
+ }
78
+ continue;
79
+ }
80
+ if (t.type === 'text') scanText(t.text || '', fromFile, out);
81
+ if (t.tokens) walkTokens(t.tokens, fromFile, out);
82
+ if (t.items) walkTokens(t.items, fromFile, out);
83
+ }
84
+ }
85
+
86
+ // Extracts every `@<path>` import from a file's raw markdown, using the claude
87
+ // CLI's rules (markdown-aware: code blocks/spans skipped). Relative paths
88
+ // resolve against fromFile's folder. Returns `{ path, explicit }[]`, deduped by
89
+ // path in first-seen order; `explicit` = written with path syntax
90
+ // (./ ../ ~/ /) or alone on its line.
91
+ function extractImportPaths(content, fromFile) {
92
+ const found = [];
93
+ walkTokens(lexer(content), fromFile, found);
94
+ const byPath = new Map();
95
+ for (const f of found) {
96
+ const prev = byPath.get(f.path);
97
+ if (prev) prev.explicit = prev.explicit || f.explicit;
98
+ else byPath.set(f.path, { ...f });
41
99
  }
42
- return paths;
100
+ return [...byPath.values()];
43
101
  }
44
102
 
45
103
  // Recursively walks the import chain starting at rootPath, collecting a
46
104
  // result per resolved import: { importPath, exists, nonEmpty, ok }.
47
105
  // Depth-capped to guard against a cyclic-import pathological case. Visited
48
106
  // paths are deduped so a diamond-shaped import graph doesn't get reported
49
- // twice or blow the depth budget.
107
+ // twice or blow the depth budget. A non-regular-file target counts as
108
+ // missing; an unresolved import is only reported when written explicitly
109
+ // (so prose like "ping @bilko" is not flagged).
50
110
  function walkImports(rootPath, depth = MAX_IMPORT_DEPTH, seen = new Set()) {
51
111
  const results = [];
52
112
  if (depth <= 0) return results;
@@ -59,20 +119,21 @@ function walkImports(rootPath, depth = MAX_IMPORT_DEPTH, seen = new Set()) {
59
119
  return results;
60
120
  }
61
121
 
62
- for (const importPath of extractImportPaths(content)) {
122
+ for (const { path: importPath, explicit } of extractImportPaths(content, rootPath)) {
63
123
  if (seen.has(importPath)) continue;
64
- seen.add(importPath);
65
124
 
66
125
  let exists = false;
67
126
  let nonEmpty = false;
68
127
  try {
69
128
  const stat = fs.statSync(importPath);
70
- exists = true;
71
- nonEmpty = stat.size > 0;
129
+ exists = stat.isFile();
130
+ nonEmpty = exists && stat.size > 0;
72
131
  } catch {
73
132
  exists = false;
74
133
  }
75
134
 
135
+ if (!exists && !explicit) continue;
136
+ seen.add(importPath);
76
137
  results.push({ importPath, exists, nonEmpty, ok: exists && nonEmpty });
77
138
 
78
139
  if (exists && nonEmpty) {
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * projectVideoToolCheck.cjs — says whether a Project Video tool can actually
5
+ * run, with an actionable reason when it cannot.
6
+ *
7
+ * A Project Video tool runs as a headless scheduled job, so:
8
+ * 1. its persona must resolve as a PRD agentType (a file in
9
+ * <cwd>/.claude/agents/ or ~/.claude/agents/), and
10
+ * 2. when the persona declares a tools list, the job is scoped to it, so
11
+ * that list must include the SM MCP save tools the run calls.
12
+ *
13
+ * The MCP name rule mirrors scripts/scheduler-mcp-server.cjs jobToolScope
14
+ * (src/main never requires from scripts/; the test pins the agreement).
15
+ * Plain Node, no Electron imports. Never throws.
16
+ */
17
+
18
+ const { buildPersonaToolScope } = require('../claude/personaToolScope.cjs');
19
+
20
+ const MCP_SERVER = 'session-manager-scheduler';
21
+ const PROJECT_VIDEO_WRITE_ID = `mcp__${MCP_SERVER}__project_video_write`;
22
+ const PROJECT_VIDEO_REVIEW_WRITE_ID = `mcp__${MCP_SERVER}__project_video_review_write`;
23
+
24
+ const PERSONA_PREFIX = 'A Project Video tool runs as a scheduled job, so its persona must be a file in '
25
+ + '<cwd>/.claude/agents/ or ~/.claude/agents/:';
26
+
27
+ /**
28
+ * MCP tool names a scope admits, derived exactly as jobToolScope does:
29
+ * entries starting 'mcp__'; the name after the second '__'.
30
+ * @param {{ tools: string[] }} scope
31
+ * @returns {Set<string>}
32
+ */
33
+ function mcpToolNamesFromScope(scope) {
34
+ const names = new Set();
35
+ for (const entry of scope.tools.map(String)) {
36
+ if (!entry.startsWith('mcp__')) continue;
37
+ const i = entry.indexOf('__', 5);
38
+ if (i > 0) names.add(entry.slice(i + 2));
39
+ }
40
+ return names;
41
+ }
42
+
43
+ /**
44
+ * @param {{ cwd: string, agentName: string, job?: { review?: boolean }|null }} input
45
+ * @param {{ assertAgentTypeWritable?: Function, resolvePrdPersonaForSpawn?: Function }} [deps]
46
+ * @returns {Promise<{ ok: true }|{ ok: false, error: string }>}
47
+ */
48
+ async function checkProjectVideoToolRunnable({ cwd, agentName, job } = /** @type {any} */ ({}), deps = {}) {
49
+ const assertWritable = deps.assertAgentTypeWritable
50
+ || require('../prd/prdAgentType.cjs').assertAgentTypeWritable;
51
+ const resolvePersona = deps.resolvePrdPersonaForSpawn
52
+ || require('../claude/agentModelResolve.cjs').resolvePrdPersonaForSpawn;
53
+
54
+ if (!agentName || typeof agentName !== 'string') {
55
+ return { ok: false, error: `${PERSONA_PREFIX} no persona (agentName) is set.` };
56
+ }
57
+ try {
58
+ await assertWritable(cwd, agentName);
59
+ } catch (err) {
60
+ const msg = err && /** @type {Error} */ (err).message ? /** @type {Error} */ (err).message : String(err);
61
+ return { ok: false, error: `${PERSONA_PREFIX} ${msg}` };
62
+ }
63
+
64
+ let persona;
65
+ try {
66
+ persona = await resolvePersona({ cwd, agentType: agentName });
67
+ } catch (err) {
68
+ const msg = err && /** @type {Error} */ (err).message ? /** @type {Error} */ (err).message : String(err);
69
+ return { ok: false, error: `${PERSONA_PREFIX} ${msg}` };
70
+ }
71
+ if (!persona || !persona.personaPath) {
72
+ return { ok: false, error: `${PERSONA_PREFIX} persona '${agentName}' could not be read.` };
73
+ }
74
+
75
+ const scope = buildPersonaToolScope(persona.tools);
76
+ if (!scope) return { ok: true };
77
+
78
+ const names = mcpToolNamesFromScope(scope);
79
+ const needed = [['project_video_write', PROJECT_VIDEO_WRITE_ID]];
80
+ if (job && job.review === true) needed.push(['project_video_review_write', PROJECT_VIDEO_REVIEW_WRITE_ID]);
81
+ const missing = needed.filter(([name]) => !names.has(name)).map(([, id]) => id);
82
+ if (missing.length === 0) return { ok: true };
83
+
84
+ return {
85
+ ok: false,
86
+ error: `Persona '${agentName}' lists its tools, and a scheduled job can call only the MCP tools its persona lists. `
87
+ + `Add ${missing.join(', ')} to the tools: line of ${persona.personaPath}, or the run cannot save its video.`,
88
+ };
89
+ }
90
+
91
+ module.exports = {
92
+ checkProjectVideoToolRunnable,
93
+ mcpToolNamesFromScope,
94
+ PROJECT_VIDEO_WRITE_ID,
95
+ PROJECT_VIDEO_REVIEW_WRITE_ID,
96
+ };
@@ -377,6 +377,17 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
377
377
  tools: "Read, Grep, Glob, Bash",
378
378
  },
379
379
  },
380
+ {
381
+ commit: "704173f3",
382
+ bodySha256: "043eefdb702c1e99cd1378428828e48d894b585d2f1617810f33e75688f7b39e",
383
+ fm: {
384
+ description: "Validates a finished PLAN (the PRDs its validate PRD lists) once, after its last PRD lands — re-runs each PRD's gate, checks every acceptance criterion against the real tree, reviews the plan's combined diff, and reports one VERIFIED/REFUTED verdict per PRD as checked JSON (the CLI enforces the schema). Runs headless as a scheduled PRD (agentType: validator); never edits product code and never queues work.",
385
+ executorOnly: "true",
386
+ model: "sonnet",
387
+ title: "Engineering — Plan Validator",
388
+ tools: "Read, Grep, Glob, Bash",
389
+ },
390
+ },
380
391
  ],
381
392
  "demo-video-builder": [
382
393
  {
@@ -9,9 +9,11 @@
9
9
  * could still fail to block at run time (or vice versa) — so the matching
10
10
  * rule lives here once, not copied into each caller.
11
11
  *
12
- * Resolution rule: exact slug match first; else bare-name match after
13
- * stripping one leading `NN-` prefix — a human-authored `dependsOn:` can't
14
- * know the `NN-` prefix the allocator will hand a sibling PRD.
12
+ * Resolution rule (write-time resolveDepSlug): exact slug match first; else
13
+ * bare-name match after stripping one leading `NN-` prefix — a human-authored
14
+ * `dependsOn:` can't know the `NN-` prefix the allocator will hand a sibling
15
+ * PRD. Run-time gating uses makeDepResolver below, which adds the satisfied
16
+ * record and Epic ordering on top of the same bare-name rule.
15
17
  */
16
18
 
17
19
  /** Strip one leading `NN-` prefix, if present. */
@@ -84,4 +86,102 @@ function findNearMatches(depSlug, candidateSlugs, limit = 3) {
84
86
  .map((entry) => entry.slug);
85
87
  }
86
88
 
87
- module.exports = { bareSlug, resolveDepSlug, findNearMatches, isSatisfiedDepRow };
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
+ /** The Epic a queue row belongs to: `epicId`, else its `sourcePromptId`. */
101
+ function epicOf(job) {
102
+ return job?.epicId ?? job?.sourcePromptId ?? null;
103
+ }
104
+
105
+ /** True when `slug` carries a leading `NN-` allocator prefix. */
106
+ function isPrefixedSlug(slug) {
107
+ return /^\d+-/.test(String(slug ?? ''));
108
+ }
109
+
110
+ /**
111
+ * makeDepResolver(projectJobs, satisfiedSlugs, { failOpen, epicId }) — the ONE
112
+ * run-time `dependsOn` resolution rule, shared by every schedulerBatch.cjs
113
+ * gate (findBlockingDep, findUnresolvableDepRoots, pickForProject's hold
114
+ * records and root-blocker walk) so gating, holds and the root walk can never
115
+ * disagree about what a dep names.
116
+ *
117
+ * resolve(dep, dependentJob) → { kind: 'row'|'satisfied'|'unresolved', rows }, in order:
118
+ * 1. an exact live row → 'row'
119
+ * 2. the exact slug in satisfiedSlugs → 'satisfied'
120
+ * 3. NN-prefixed dep: a live row with the same bare name IN THE DEPENDENT'S
121
+ * EPIC → 'row'; else 'unresolved'
122
+ * (a dep written with a full slug names one PRD — another Epic's
123
+ * re-allocated sibling is not it)
124
+ * 4. bare dep: live rows with that bare name, preferring rows in the
125
+ * dependent's Epic → 'row'
126
+ * 5. bare dep: a satisfied record with that bare name → 'satisfied'
127
+ * 6. → 'unresolved'
128
+ * In steps 3-4 a cancelled row (isCancelledRow) is dropped when a satisfied
129
+ * record shares its bare name — a human-cancelled duplicate must never freeze
130
+ * the dependents of the PRD that genuinely finished (Self, 2026-11-22: the
131
+ * cancelled 1056-sm-contract-client froze 16 dependents of the completed
132
+ * 1047-sm-contract-client).
133
+ *
134
+ * `failOpen` (the caller's history/archive lookup failed this tick): any dep
135
+ * that resolves to no live row is 'satisfied' instead of 'unresolved'.
136
+ * `epicId` is the fallback Epic when resolve() is called without a dependent.
137
+ */
138
+ function makeDepResolver(projectJobs, satisfiedSlugs = new Set(), opts = {}) {
139
+ const failOpen = opts.failOpen === true;
140
+ const satisfied = satisfiedSlugs instanceof Set ? satisfiedSlugs : new Set(satisfiedSlugs ?? []);
141
+ const rowBySlug = new Map();
142
+ const rowsByBareSlug = new Map();
143
+ for (const j of projectJobs) {
144
+ if (!rowBySlug.has(j.slug)) rowBySlug.set(j.slug, j);
145
+ const bare = bareSlug(j.slug);
146
+ if (!rowsByBareSlug.has(bare)) rowsByBareSlug.set(bare, []);
147
+ rowsByBareSlug.get(bare).push(j);
148
+ }
149
+ let satisfiedBareSlugs = null;
150
+ const hasSatisfiedBare = (bare) => {
151
+ if (satisfiedBareSlugs === null) {
152
+ satisfiedBareSlugs = new Set();
153
+ for (const s of satisfied) satisfiedBareSlugs.add(bareSlug(s));
154
+ }
155
+ return satisfiedBareSlugs.has(bare);
156
+ };
157
+ const unresolved = () => (failOpen ? { kind: 'satisfied', rows: [] } : { kind: 'unresolved', rows: [] });
158
+
159
+ const resolve = (dep, dependentJob) => {
160
+ const exact = rowBySlug.get(dep);
161
+ if (exact) return { kind: 'row', rows: [exact] };
162
+ if (satisfied.has(dep)) return { kind: 'satisfied', rows: [] };
163
+ const bare = bareSlug(dep);
164
+ const depEpic = dependentJob ? epicOf(dependentJob) : (opts.epicId ?? null);
165
+ const sameEpic = (r) => depEpic != null && epicOf(r) === depEpic;
166
+ const bareRows = rowsByBareSlug.get(bare) ?? [];
167
+ const bareSatisfied = hasSatisfiedBare(bare);
168
+ const live = (rows) => (bareSatisfied ? rows.filter((r) => !isCancelledRow(r)) : rows);
169
+
170
+ if (isPrefixedSlug(dep)) {
171
+ const rows = live(bareRows.filter(sameEpic));
172
+ return rows.length > 0 ? { kind: 'row', rows } : unresolved();
173
+ }
174
+ const preferred = bareRows.filter(sameEpic);
175
+ const rows = live(preferred.length > 0 ? preferred : bareRows);
176
+ if (rows.length > 0) return { kind: 'row', rows };
177
+ if (bareSatisfied) return { kind: 'satisfied', rows: [] };
178
+ return unresolved();
179
+ };
180
+ const rowsForDep = (dep, dependentJob) => resolve(dep, dependentJob).rows;
181
+ const isKnownSatisfied = (dep, dependentJob) => resolve(dep, dependentJob).kind === 'satisfied';
182
+ return { resolve, rowsForDep, isKnownSatisfied };
183
+ }
184
+
185
+ module.exports = {
186
+ bareSlug, resolveDepSlug, findNearMatches, isSatisfiedDepRow, isCancelledRow, epicOf, makeDepResolver,
187
+ };
@@ -185,9 +185,12 @@ function registerAdminRoute(adminHttp, remote) {
185
185
  sendJson(res, 400, { ok: false, error: 'invalid payload', details: e?.issues ?? e?.message });
186
186
  return;
187
187
  }
188
- const result = await remote.cancelJob(input.slug, { cwd: input.cwd });
188
+ const result = await remote.cancelJob(input.slug, { cwd: input.cwd, dependents: input.dependents });
189
189
  if (!result.ok) {
190
- const status = result.error === 'invalid slug' ? 400
190
+ // A dependents refusal/abort (result.dependents set) is always a 409 —
191
+ // the job exists; the caller must pass or fix a dependents choice.
192
+ const status = Array.isArray(result.dependents) ? 409
193
+ : result.error === 'invalid slug' ? 400
191
194
  : /unknown slug|not found/i.test(result.error ?? '') ? 404
192
195
  : 409;
193
196
  sendJson(res, status, result);
@@ -197,6 +200,36 @@ function registerAdminRoute(adminHttp, remote) {
197
200
  sendJson(res, 200, result);
198
201
  });
199
202
 
203
+ // POST /admin/scheduler/dismiss-cancelled — the honest exit for a cancelled
204
+ // row (PRD 3492): removes it from the live queue and files its PRD under
205
+ // prds-cancelled/, which never satisfies a dependsOn (archive-prd refuses
206
+ // cancelled rows). Same body shape as cancel-job, including `dependents`.
207
+ adminHttp.registerRoute('POST', '/admin/scheduler/dismiss-cancelled', async (req, res) => {
208
+ const raw = await readBody(req);
209
+ const parsedBody = parseJsonBody(raw);
210
+ if (!parsedBody.ok) {
211
+ sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
212
+ return;
213
+ }
214
+ let input;
215
+ try {
216
+ input = schemas.adminCancelJob.parse(parsedBody.value);
217
+ } catch (e) {
218
+ sendJson(res, 400, { ok: false, error: 'invalid payload', details: e?.issues ?? e?.message });
219
+ return;
220
+ }
221
+ const result = await queueOps.dismissCancelled(input.slug, input.cwd, { dependents: input.dependents });
222
+ if (!result.ok) {
223
+ const status = Array.isArray(result.dependents) || result.notCancelled ? 409
224
+ : result.error === 'invalid slug' ? 400
225
+ : /unknown slug/i.test(result.error ?? '') ? 404
226
+ : 500;
227
+ sendJson(res, status, result);
228
+ return;
229
+ }
230
+ sendJson(res, 200, result);
231
+ });
232
+
200
233
  adminHttp.registerRoute('POST', '/admin/scheduler/retag-prd', async (req, res) => {
201
234
  const raw = await readBody(req);
202
235
  const parsedBody = parseJsonBody(raw);