claude-code-session-manager 0.126.0 → 0.128.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 (107) hide show
  1. package/bin/cli.cjs +71 -9
  2. package/bin/supervise.cjs +84 -0
  3. package/dist/assets/{AgentLibrary-bzeuZN4F.js → AgentLibrary-cNQU5YWy.js} +1 -1
  4. package/dist/assets/{Button-8dWfDDuQ.js → Button-9dIPAOBg.js} +1 -1
  5. package/dist/assets/{DataModel-D4ybBPZN.js → DataModel-DrDJ6ysw.js} +1 -1
  6. package/dist/assets/{History-hsztE6yh.js → History-4rrDdWNP.js} +1 -1
  7. package/dist/assets/{Hooks-CRmZMQaW.js → Hooks-Bj_jF5Pa.js} +1 -1
  8. package/dist/assets/{Library-Czt3Bojd.js → Library-D-Wsxrh7.js} +1 -1
  9. package/dist/assets/{ListDetail-Cr6Ct_WX.js → ListDetail-D7Om0H8j.js} +1 -1
  10. package/dist/assets/{McpServers-CeXJ2bng.js → McpServers-CbIbSd5o.js} +1 -1
  11. package/dist/assets/{Memory-caujO8O3.js → Memory-DgQlvQrO.js} +1 -1
  12. package/dist/assets/{Panel-D64i9tGz.js → Panel-DZHiD8Ar.js} +1 -1
  13. package/dist/assets/{Permissions-DpWOIrvr.js → Permissions-CfzduF4B.js} +1 -1
  14. package/dist/assets/{Plugins-Bd1ekP5P.js → Plugins-D-AG5nAo.js} +2 -2
  15. package/dist/assets/{ProvenanceBadge-B96A_uZf.js → ProvenanceBadge-B9JSEjll.js} +1 -1
  16. package/dist/assets/{SaveBar-D0Y2t-Ao.js → SaveBar-mVKig6hL.js} +1 -1
  17. package/dist/assets/{Scheduler-Y5_YbNrC.js → Scheduler-DFTCnh60.js} +1 -1
  18. package/dist/assets/{ScopeSwitcher-BmWA_dP9.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
  19. package/dist/assets/{Settings-Bcf65bpL.js → Settings-BTmxRMaP.js} +1 -1
  20. package/dist/assets/{SkillReferenceGraph-BeSNXloA.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
  21. package/dist/assets/{Skills-DwnQKJVc.js → Skills-CxOacq0k.js} +1 -1
  22. package/dist/assets/{SystemPrompt-Dih6SCmL.js → SystemPrompt-BCWg5FAz.js} +1 -1
  23. package/dist/assets/{TagLibrary-BZ-Kp10P.js → TagLibrary-BnF0_PkG.js} +1 -1
  24. package/dist/assets/{TiptapBody-C2nEUmF7.js → TiptapBody-C2Iu6rZd.js} +1 -1
  25. package/dist/assets/{Toggle-Dw8-zNQo.js → Toggle-C-oD66BG.js} +1 -1
  26. package/dist/assets/{ViewTabs-CoYPKGN-.js → ViewTabs-Cs4v7vLY.js} +1 -1
  27. package/dist/assets/{historyTotals-BbKcNpV7.js → historyTotals-CbRSLD8f.js} +1 -1
  28. package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
  29. package/dist/assets/index-DzY_GXYY.js +3081 -0
  30. package/dist/assets/{settingsSchema-6doG_61l.js → settingsSchema-bSBfHuan.js} +1 -1
  31. package/dist/assets/{skillFrontmatter-BYMYWDfb.js → skillFrontmatter-BEseWm8r.js} +1 -1
  32. package/dist/assets/{useAgentsDirWatch-Cqabjieh.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
  33. package/dist/index.html +2 -2
  34. package/dist-web/app.css +1 -1
  35. package/dist-web/app.js +343 -341
  36. package/package.json +1 -1
  37. package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
  38. package/scripts/scheduler-mcp-server.cjs +209 -7
  39. package/src/main/build-info.json +4 -4
  40. package/src/main/chatRunner.cjs +37 -4
  41. package/src/main/crashDiagnostics.cjs +83 -8
  42. package/src/main/health.cjs +16 -5
  43. package/src/main/index.cjs +46 -0
  44. package/src/main/ipcSchemas.cjs +107 -0
  45. package/src/main/lib/chatBootRecovery.cjs +136 -0
  46. package/src/main/lib/chatInflight.cjs +88 -0
  47. package/src/main/lib/claude/agentModelResolve.cjs +26 -7
  48. package/src/main/lib/claude/personaToolScope.cjs +40 -2
  49. package/src/main/lib/demo-video-kit/capture.cjs +113 -0
  50. package/src/main/lib/demo-video-kit/character.cjs +97 -0
  51. package/src/main/lib/demo-video-kit/checks.cjs +150 -0
  52. package/src/main/lib/demo-video-kit/frames.cjs +200 -0
  53. package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
  54. package/src/main/lib/demo-video-kit/sound.cjs +312 -0
  55. package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
  56. package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
  57. package/src/main/lib/epic/epicValidationHook.cjs +31 -3
  58. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
  59. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
  60. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
  61. package/src/main/lib/mcpToolCatalog.cjs +93 -14
  62. package/src/main/lib/opsOwnership.cjs +9 -5
  63. package/src/main/lib/persona-macro/builtinMacros.cjs +30 -5
  64. package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
  65. package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
  66. package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
  67. package/src/main/lib/persona-macro/macroLibrary.cjs +73 -3
  68. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +100 -0
  69. package/src/main/lib/prd/prdCreate.cjs +17 -2
  70. package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
  71. package/src/main/lib/process/childWithLog.cjs +38 -95
  72. package/src/main/lib/process/memoryScope.cjs +140 -0
  73. package/src/main/lib/process/ozonePlatform.cjs +15 -0
  74. package/src/main/lib/process/procIdentity.cjs +10 -3
  75. package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
  76. package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
  77. package/src/main/lib/project-pages/playerBridge.cjs +129 -0
  78. package/src/main/lib/scheduler/cpuSample.cjs +147 -0
  79. package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
  80. package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
  81. package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
  82. package/src/main/lib/scheduler/loadGate.cjs +116 -45
  83. package/src/main/lib/scheduler/queueStore.cjs +5 -2
  84. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  85. package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
  86. package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
  87. package/src/main/lib/smfileHeaders.cjs +11 -3
  88. package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
  89. package/src/main/projectPages.cjs +107 -30
  90. package/src/main/promptSessionsIpc.cjs +131 -0
  91. package/src/main/scheduler/budget.cjs +31 -0
  92. package/src/main/scheduler/prdParser.cjs +2 -0
  93. package/src/main/scheduler/prdPaths.cjs +54 -0
  94. package/src/main/scheduler/reviewLadder.cjs +17 -0
  95. package/src/main/scheduler/starvation.cjs +22 -0
  96. package/src/main/scheduler.cjs +548 -77
  97. package/src/main/seedSchedulerMcp.cjs +10 -1
  98. package/src/main/templates/PRD_AUTHORING.md +5 -2
  99. package/src/main/transcripts.cjs +8 -0
  100. package/src/main/usage.cjs +4 -2
  101. package/src/main/webRemote.cjs +3 -1
  102. package/src/preload/api.d.ts +113 -7
  103. package/src/preload/apiSurface.json +70 -0
  104. package/src/preload/index.cjs +13 -0
  105. package/src/seed/agents/demo-video-builder.md +141 -43
  106. package/src/seed/agents/project-home-builder.md +26 -13
  107. package/dist/assets/index-DgPUERhe.js +0 -3079
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Read-tier IPC for the Sessions (Epics) list/detail path. The renderer used to
5
+ * read active-index.json, per-Epic archives and the Claude session JSONL via
6
+ * config:readJson/listDir/readText — all `deny` for a remote (web) browser, so
7
+ * the remote UI could never list or open a Session. These channels are the
8
+ * dedicated, fenced replacement: every handler reads ONLY under
9
+ * `<cwd>/session-manager-operations/prompt-sessions` (via opsPath()) — except
10
+ * read-session-transcript, which resolves the project's own Claude JSONL via
11
+ * transcripts.cjs — and refuses a cwd that is not a registered project root.
12
+ * Reads only: the single-writer law (opsOwnership.cjs) is untouched.
13
+ */
14
+
15
+ const fs = require('node:fs');
16
+ const path = require('node:path');
17
+
18
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
19
+ const MAX_TRANSCRIPT_BYTES = 64 * 1024 * 1024;
20
+
21
+ function norm(p) {
22
+ return path.resolve(String(p)).replace(/[\\/]+$/, '');
23
+ }
24
+
25
+ /** Default registered-project source: persisted tabs plus every project Claude has seen. */
26
+ function defaultProjectRoots() {
27
+ const roots = [];
28
+ try {
29
+ const sessionsStore = require('./sessionsStore.cjs');
30
+ const data = JSON.parse(fs.readFileSync(sessionsStore.storePath(), 'utf8'));
31
+ for (const t of data.tabs || []) if (t && typeof t.cwd === 'string' && t.cwd) roots.push(t.cwd);
32
+ } catch { /* none */ }
33
+ try {
34
+ for (const c of require('./lib/activeSessions.cjs').allProjectCwds()) roots.push(c);
35
+ } catch { /* none */ }
36
+ return roots;
37
+ }
38
+
39
+ function assertRegistered(cwd, projectRoots) {
40
+ if (typeof cwd !== 'string' || !cwd || !path.isAbsolute(cwd)) throw new Error('cwd must be an absolute project path');
41
+ const { projectRootOf } = require('./lib/activeSessions.cjs');
42
+ const want = norm(projectRootOf(cwd) || cwd);
43
+ for (const r of projectRoots() || []) {
44
+ if (typeof r !== 'string' || !r) continue;
45
+ if (norm(r) === want || norm(projectRootOf(r) || r) === want) return;
46
+ }
47
+ throw new Error('cwd is not a registered project root');
48
+ }
49
+
50
+ function promptSessionsDir(cwd) {
51
+ return require('./lib/opsOwnership.cjs').opsPath(cwd, 'prompt-sessions');
52
+ }
53
+
54
+ function loadActiveIndex(cwd, { projectRoots = defaultProjectRoots } = {}) {
55
+ assertRegistered(cwd, projectRoots);
56
+ const file = path.join(promptSessionsDir(cwd), 'active-index.json');
57
+ try {
58
+ return { exists: true, data: JSON.parse(fs.readFileSync(file, 'utf8')) };
59
+ } catch (err) {
60
+ if (err && err.code === 'ENOENT') return { exists: false, data: null };
61
+ return { exists: false, data: null, error: String(err && err.message ? err.message : err) };
62
+ }
63
+ }
64
+
65
+ function listArchived(cwd, { projectRoots = defaultProjectRoots } = {}) {
66
+ assertRegistered(cwd, projectRoots);
67
+ try {
68
+ const ids = fs.readdirSync(promptSessionsDir(cwd), { withFileTypes: true })
69
+ .filter((e) => e.isFile() && e.name.endsWith('.json') && e.name !== 'active-index.json')
70
+ .map((e) => e.name.slice(0, -'.json'.length))
71
+ .filter((id) => ID_RE.test(id));
72
+ return { ok: true, ids };
73
+ } catch (err) {
74
+ return { ok: false, ids: [], error: String(err && err.message ? err.message : err) };
75
+ }
76
+ }
77
+
78
+ function readArchived(cwd, epicId, { projectRoots = defaultProjectRoots } = {}) {
79
+ assertRegistered(cwd, projectRoots);
80
+ if (typeof epicId !== 'string' || !ID_RE.test(epicId) || epicId === 'active-index') throw new Error('invalid epicId');
81
+ try {
82
+ return { exists: true, data: JSON.parse(fs.readFileSync(path.join(promptSessionsDir(cwd), `${epicId}.json`), 'utf8')) };
83
+ } catch (err) {
84
+ if (err && err.code === 'ENOENT') return { exists: false, data: null };
85
+ return { exists: false, data: null, error: String(err && err.message ? err.message : err) };
86
+ }
87
+ }
88
+
89
+ function readSessionTranscript(cwd, sessionId, { projectRoots = defaultProjectRoots, resolvePath } = {}) {
90
+ assertRegistered(cwd, projectRoots);
91
+ if (typeof sessionId !== 'string' || !ID_RE.test(sessionId)) throw new Error('invalid sessionId');
92
+ const file = (resolvePath || ((c, s) => require('./transcripts.cjs').transcriptPath(c, s)))(cwd, sessionId);
93
+ try {
94
+ if (fs.statSync(file).size > MAX_TRANSCRIPT_BYTES) return { exists: true, text: '', error: 'transcript too large' };
95
+ return { exists: true, text: fs.readFileSync(file, 'utf8') };
96
+ } catch (err) {
97
+ if (err && err.code === 'ENOENT') return { exists: false, text: '' };
98
+ return { exists: false, text: '', error: String(err && err.message ? err.message : err) };
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Write one completed Epic's archive (<cwd>/…/prompt-sessions/<id>.json).
104
+ * Path is built here from opsPath(); the writer id is hardcoded 'epics'
105
+ * (single-writer law). Refuses a non-registered cwd and an archive whose
106
+ * session.id does not match the named epicId.
107
+ */
108
+ async function writeArchive(cwd, epicId, archive, { projectRoots = defaultProjectRoots, writeJson } = {}) {
109
+ assertRegistered(cwd, projectRoots);
110
+ if (typeof epicId !== 'string' || !ID_RE.test(epicId) || epicId === 'active-index') throw new Error('invalid epicId');
111
+ if (!archive || typeof archive !== 'object' || !archive.session || archive.session.id !== epicId) {
112
+ throw new Error('archive.session.id must match epicId');
113
+ }
114
+ const config = require('./config.cjs');
115
+ config.addAllowedRoot(norm(cwd));
116
+ const file = path.join(promptSessionsDir(cwd), `${epicId}.json`);
117
+ await (writeJson || config.writeJson)(file, archive, { writer: 'epics' });
118
+ return { ok: true };
119
+ }
120
+
121
+ function registerPromptSessionsReadHandlers() {
122
+ const { ipcMain } = require('electron');
123
+ const { schemas: s, validated: v } = require('./ipcSchemas.cjs');
124
+ ipcMain.handle('promptSessions:load-active-index', v(s.promptSessionsCwd, ({ cwd }) => loadActiveIndex(cwd)));
125
+ ipcMain.handle('promptSessions:list-archived', v(s.promptSessionsCwd, ({ cwd }) => listArchived(cwd)));
126
+ ipcMain.handle('promptSessions:read-archived', v(s.promptSessionsReadArchived, ({ cwd, epicId }) => readArchived(cwd, epicId)));
127
+ ipcMain.handle('promptSessions:write-archive', v(s.promptSessionsWriteArchive, ({ cwd, epicId, archive }) => writeArchive(cwd, epicId, archive)));
128
+ ipcMain.handle('promptSessions:read-session-transcript', v(s.promptSessionsReadSessionTranscript, ({ cwd, sessionId }) => readSessionTranscript(cwd, sessionId)));
129
+ }
130
+
131
+ module.exports = { loadActiveIndex, listArchived, readArchived, readSessionTranscript, writeArchive, registerPromptSessionsReadHandlers };
@@ -240,6 +240,16 @@ function shouldKillForBudget(elapsedMs, budgetMs) {
240
240
  return elapsedMs >= budgetMs;
241
241
  }
242
242
 
243
+ /**
244
+ * resolveBudgetEstimate({ estimateMinutes, validatorEstimate, personaEstimate }) → number | null
245
+ * An explicit estimate wins; otherwise the larger of the validator-derived and
246
+ * persona-default estimates (persona stays a lower bound); null if neither.
247
+ */
248
+ function resolveBudgetEstimate({ estimateMinutes, validatorEstimate, personaEstimate } = {}) {
249
+ if (estimateMinutes != null) return estimateMinutes;
250
+ return Math.max(validatorEstimate ?? 0, personaEstimate ?? 0) || null;
251
+ }
252
+
243
253
  /**
244
254
  * resolveBudgetKillOutcome({ killedByWatchdog, killedBySignal, durationMs, jobBudgetMs, estimateMinutes })
245
255
  * → { killedByWatchdog: 'budget'|null, budgetKillReason: string|null }
@@ -544,7 +554,27 @@ function selectLeftoverQuarantineTarget(job) {
544
554
  return { slug: job.slug, cwd: job.cwd, paths };
545
555
  }
546
556
 
557
+ /**
558
+ * Why a tick found zero free slots. Pure. A degraded usage-meter cap that
559
+ * binds while the pool still has room is its own reason; a truly full pool
560
+ * stays 'slots-exhausted' even when the meter is also degraded.
561
+ */
562
+ function describeSlotHold({ total, inUse, holders = [], degradedCap = null, running = 0, deferredCount = 0 } = {}) {
563
+ if (degradedCap != null && inUse < total) {
564
+ return {
565
+ reason: 'usage-meter-degraded',
566
+ detail: `usage meter down: running capped at ${degradedCap} (${running} running, ${inUse} of ${total} slots in use)`,
567
+ };
568
+ }
569
+ const owners = (holders || []).map((h) => h.owner).join(', ');
570
+ return {
571
+ reason: 'slots-exhausted',
572
+ detail: `${inUse} of ${total} session slots busy${owners ? ` (${owners})` : ''}`,
573
+ };
574
+ }
575
+
547
576
  module.exports = {
577
+ describeSlotHold,
548
578
  BACKOFF_MAX_MS,
549
579
  FAILURE_STREAK_WARN_THRESHOLD,
550
580
  FAILURE_STREAK_ESCALATION_MS,
@@ -571,6 +601,7 @@ module.exports = {
571
601
  isJobBudgetExempt,
572
602
  shouldKillForBudget,
573
603
  resolveBudgetKillOutcome,
604
+ resolveBudgetEstimate,
574
605
  findStrandedInvestigations,
575
606
  computeDepHistorySatisfaction,
576
607
  };
@@ -131,6 +131,8 @@ async function parsePrdRaw(filePath) {
131
131
  disposition: (fm.disposition === 'append' || fm.disposition === 'new-head') ? fm.disposition : null,
132
132
  // Durable wave identity (createPrd-stamped); malformed values read as absent.
133
133
  planId: (typeof fm.planId === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(fm.planId)) ? fm.planId : null,
134
+ // Macro press that minted this PRD (prdFrontmatter.cjs MACRO_ID_RE); malformed reads as absent.
135
+ macroId: (typeof fm.macroId === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(fm.macroId.trim())) ? fm.macroId.trim() : null,
134
136
  // Opt-in exclusive-lease flag (PRD 1107, quietMachineLease.cjs +
135
137
  // schedulerBatch.cjs's pickNextBatch). Only a literal `true` opts in —
136
138
  // matches prdFrontmatter.cjs's applyKey semantics for this field.
@@ -313,6 +313,59 @@ async function resolveBareSlugFile(slug, cwd) {
313
313
  return { ok: true, path: safe, dir: only.dir };
314
314
  }
315
315
 
316
+ /**
317
+ * Text of each named PRD of one Epic, wherever it lives now: its prds/, its
318
+ * prds-archived/, each direct subfolder of prds-archived/ (newest name first),
319
+ * then the same for ancestor-folder copies of the Epic. First match wins; an
320
+ * exact `<slug>.md` beats a bare-slug match (`fix-x` finds `872-fix-x.md`).
321
+ * Slugs are only compared with readdir names, never joined into a path; only
322
+ * regular `.md` files are read. Never rejects. Returns Map<inputSlug, text>.
323
+ */
324
+ async function readEpicPrdTexts(cwd, epicId, slugs) {
325
+ const out = new Map();
326
+ try {
327
+ if (typeof cwd !== 'string' || !cwd || !Array.isArray(slugs) || slugs.length === 0) return out;
328
+ if (!isSafeEpicId(epicId)) return out;
329
+ const root = projectRootOf(cwd);
330
+ const live = resolveEpicPrdWriteDir(root, epicId);
331
+ const archived = path.join(path.dirname(live), 'prds-archived');
332
+ const dirs = [];
333
+ const addWithSubs = async (dir) => {
334
+ dirs.push(dir);
335
+ const ents = await fsp.readdir(dir, { withFileTypes: true }).catch(() => []);
336
+ const subs = ents.filter((e) => e.isDirectory()).map((e) => e.name).sort().reverse();
337
+ for (const s of subs) dirs.push(path.join(dir, s));
338
+ };
339
+ dirs.push(live);
340
+ await addWithSubs(archived);
341
+ for (const d of ancestorEpicPrdDirs(root, epicId)) dirs.push(d);
342
+ for (const d of ancestorEpicArchivedPrdDirs(root, epicId)) await addWithSubs(d);
343
+ const index = new Map();
344
+ for (const dir of dirs) {
345
+ let ents;
346
+ try { ents = await fsp.readdir(dir, { withFileTypes: true }); } catch { continue; }
347
+ for (const e of ents) {
348
+ if (!e.isFile() || !e.name.endsWith('.md')) continue;
349
+ const key = e.name.slice(0, -3);
350
+ if (!index.has(key)) index.set(key, path.join(dir, e.name));
351
+ }
352
+ }
353
+ for (const slug of slugs) {
354
+ if (typeof slug !== 'string' || !slug || out.has(slug)) continue;
355
+ let file = index.get(slug);
356
+ if (!file) {
357
+ const bare = bareSlug(slug);
358
+ for (const [key, p] of index) {
359
+ if (bareSlug(key) === bare) { file = p; break; }
360
+ }
361
+ }
362
+ if (!file) continue;
363
+ try { out.set(slug, await fsp.readFile(file, 'utf8')); } catch { /* unreadable — no entry */ }
364
+ }
365
+ } catch { /* never rejects */ }
366
+ return out;
367
+ }
368
+
316
369
  /**
317
370
  * The two distinct failure modes safeSlugPath collapses into one nullable
318
371
  * return (the defect this fixes — see the PRD that added this helper's
@@ -568,6 +621,7 @@ module.exports = {
568
621
  realPrdsDir,
569
622
  safeSlugPath,
570
623
  resolveBareSlugFile,
624
+ readEpicPrdTexts,
571
625
  resolveSlugOrReason,
572
626
  jobMatchesSlugAndCwd,
573
627
  unknownSlugMessage,
@@ -1009,7 +1009,24 @@ function selectGateShadowTarget(jobs, headByCwd, { authorityDisabled = false, ba
1009
1009
  return eligible.find((j) => !j.gateShadow) ?? null;
1010
1010
  }
1011
1011
 
1012
+ /**
1013
+ * Resume-recovery rows a periodic pass may launch: every row
1014
+ * selectResumeRecoveryTarget accepts, or only the first when the CPU is
1015
+ * saturated (the rest stay eligible for the next pass).
1016
+ */
1017
+ function selectResumeRecoveryBatch(jobs, { saturated = false } = {}) {
1018
+ const batch = [];
1019
+ for (const job of jobs ?? []) {
1020
+ const target = selectResumeRecoveryTarget(job);
1021
+ if (!target) continue;
1022
+ batch.push({ job, target });
1023
+ if (saturated) break;
1024
+ }
1025
+ return batch;
1026
+ }
1027
+
1012
1028
  module.exports = {
1029
+ selectResumeRecoveryBatch,
1013
1030
  isRefireCapped,
1014
1031
  isCancelledJob,
1015
1032
  selectResumeRecoveryTarget,
@@ -6,6 +6,7 @@
6
6
  'use strict';
7
7
 
8
8
  const launchFailure = require('../lib/scheduler/launchFailure.cjs');
9
+ const { findBlockingDep, DEP_HISTORY_FAIL_OPEN } = require('../lib/scheduler/schedulerBatch.cjs');
9
10
  const { STARVE_ESCALATION_MS } = require('../lib/scheduler/schedulerConfig.cjs');
10
11
 
11
12
  /**
@@ -132,6 +133,26 @@ function launchBlockedSlugs(jobs, launchBlocks) {
132
133
  return out;
133
134
  }
134
135
 
136
+ /**
137
+ * describeStarveHold({ projectRows, launchBlocks, lastTick, lastHoldTick }) → string
138
+ *
139
+ * Pure. Names the real limiter for a starved project: its own dependency wait,
140
+ * then a launch breaker, then the last tick's reason (or the last hold carried
141
+ * past a fired tick). 'unknown' only when the scheduler has not ticked.
142
+ */
143
+ function describeStarveHold({ projectRows = [], launchBlocks = {}, lastTick = null, lastHoldTick = null } = {}) {
144
+ const rows = Array.isArray(projectRows) ? projectRows : [];
145
+ const pending = rows.filter((j) => j && j.status === 'pending');
146
+ if (pending.length) {
147
+ if (pending.every((j) => findBlockingDep(j, rows, DEP_HISTORY_FAIL_OPEN))) return 'dependency-blocked';
148
+ const blocked = launchBlockedSlugs(pending, launchBlocks);
149
+ if (pending.every((j) => blocked.has(j.slug))) return 'launch-blocked';
150
+ }
151
+ if (!lastTick) return 'unknown';
152
+ if (!lastTick.fired && lastTick.reason) return lastTick.reason;
153
+ return lastHoldTick?.reason ?? 'dispatching-elsewhere';
154
+ }
155
+
135
156
  /**
136
157
  * classifyQueueStarvation({ jobs, paused, runningCount, lastRunAtMs, now, thresholdMs })
137
158
  * → null | { kind: 'starved' | 'blocked', pending, dispatchable, blockedChains, idleMs }
@@ -383,6 +404,7 @@ module.exports = {
383
404
  STARVE_ESCALATION_MS,
384
405
  dispatchIdleMs,
385
406
  launchBlockedSlugs,
407
+ describeStarveHold,
386
408
  classifyQueueStarvation,
387
409
  classifyQueueStarvationByProject,
388
410
  classifyQueueHealth,