claude-code-session-manager 0.142.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +20 -107
- package/dist/assets/{AppSettings-BcZgIvvY.js → AppSettings-BO4jDVGO.js} +1 -1
- package/dist/assets/{History-DpZuJXi1.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/{HomeClaudeConfig-D32ZJtU-.js → HomeClaudeConfig-DADP5bfn.js} +2 -2
- package/dist/assets/{Panel-BjdJjhqt.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BTClYV6i.js → ProjectClaudeConfig-DPnDJKcr.js} +1 -1
- package/dist/assets/{Scheduler-DPobKx1Z.js → Scheduler-CNLjn90m.js} +8 -8
- package/dist/assets/{SkillReferenceGraph-Cqyu4mef.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-vv0noNVI.js → Skills-cfV7sgk6.js} +1 -1
- package/dist/assets/{TiptapBody-CXi8Pvut.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/{Toggle-CiYCWLjh.js → Toggle-CYajnSdx.js} +1 -1
- package/dist/assets/{VoiceButton-4NKKd1sC.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-DDunb8Ch.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/{index-Cn5E9958.js → index-CdTppjKR.js} +436 -436
- package/dist/index.html +1 -1
- package/dist-web/app.js +356 -356
- package/package.json +3 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +9 -3
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +304 -6
- package/src/main/adminRouteRegistry.cjs +10 -0
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +105 -7
- package/src/main/config.cjs +5 -1
- package/src/main/health.cjs +38 -2
- package/src/main/index.cjs +12 -4
- package/src/main/ipcSchemas.cjs +11 -0
- package/src/main/lib/demo-video-kit/cast.md +10 -1
- package/src/main/lib/demo-video-kit/character.cjs +77 -21
- package/src/main/lib/demo-video-kit/kind-tiktok.md +5 -1
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactRetention.cjs +55 -9
- package/src/main/lib/epic/artifactStore.cjs +78 -35
- package/src/main/lib/epic/delegationReadiness.cjs +10 -3
- package/src/main/lib/epic/epicEventLog.cjs +45 -1
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicValidationHook.cjs +13 -2
- package/src/main/lib/externalContract.cjs +12 -1
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +96 -8
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +30 -0
- package/src/main/lib/feedback-remote/pendingReplies.cjs +18 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +94 -4
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- package/src/main/lib/git/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +113 -10
- package/src/main/lib/mcpToolCatalog.cjs +102 -8
- package/src/main/lib/opsOwnership.cjs +113 -28
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +46 -0
- package/src/main/lib/prd/prdCreate.cjs +350 -227
- package/src/main/lib/prd/prdCriteria.cjs +7 -4
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/scheduler/criteriaChecks.cjs +164 -20
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +13 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +120 -52
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +60 -2
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +13 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/scheduler/slotsRoute.cjs +101 -87
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +16 -5
- package/src/main/lib/tasks/memoryConsolidation.cjs +14 -2
- package/src/main/lib/tasks/mitigationReview.cjs +21 -1
- package/src/main/lib/tasks/taskAdminRoutes.cjs +78 -3
- package/src/main/lib/tasks/taskLedger.cjs +2 -2
- package/src/main/lib/telemetry/auditEvents.cjs +21 -24
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/promptSessionEvents.cjs +16 -1
- package/src/main/pty.cjs +11 -2
- package/src/main/queueOps.cjs +1 -1
- package/src/main/runVerify.cjs +1 -1
- package/src/main/scheduler/utilizationHold.cjs +96 -6
- package/src/main/scheduler.cjs +533 -39
- package/src/main/templates/PRD_AUTHORING.md +7 -2
- package/src/preload/api.d.ts +47 -1
- package/src/preload/apiSurface.json +14 -0
- package/src/preload/index.cjs +2 -0
- package/src/seed/agents/demo-video-builder.md +15 -8
- package/src/seed/agents/validator.md +20 -19
|
@@ -24,16 +24,86 @@ function errMsg(e) {
|
|
|
24
24
|
return e && e.message ? e.message : String(e);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const DECLARED_PREFIX = `${OPS_ROOT_DIR}/${NAMESPACE}/`;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* parseDeclaredPath(p) → { folder, name } | { reason }
|
|
31
|
+
* A declared record must be exactly
|
|
32
|
+
* `session-manager-operations/plan-records/<epic-folder>/<name>.md` (posix,
|
|
33
|
+
* repo-relative), with no `..` segment and no NUL byte.
|
|
34
|
+
*/
|
|
35
|
+
function parseDeclaredPath(p) {
|
|
36
|
+
if (typeof p !== 'string' || !p) return { reason: 'declared path is not a string' };
|
|
37
|
+
if (p.includes('\0')) return { reason: 'declared path contains a NUL byte' };
|
|
38
|
+
const posix = p.replace(/\\/g, '/');
|
|
39
|
+
if (posix.split('/').includes('..')) return { reason: 'declared path contains ..' };
|
|
40
|
+
if (path.posix.isAbsolute(posix)) return { reason: 'declared path is absolute' };
|
|
41
|
+
const norm = path.posix.normalize(posix);
|
|
42
|
+
if (!norm.startsWith(DECLARED_PREFIX)) return { reason: 'declared path is not under plan-records/' };
|
|
43
|
+
const parts = norm.slice(DECLARED_PREFIX.length).split('/');
|
|
44
|
+
if (parts.length !== 2) return { reason: 'declared path must be plan-records/<epic-folder>/<name>.md' };
|
|
45
|
+
const [folder, name] = parts;
|
|
46
|
+
if (!EPIC_ID_RE.test(folder)) return { reason: 'declared epic folder not allowed' };
|
|
47
|
+
if (!NAME_RE.test(name)) return { reason: 'name not allowed' };
|
|
48
|
+
return { folder, name };
|
|
49
|
+
}
|
|
50
|
+
|
|
27
51
|
/**
|
|
28
|
-
* harvestPlanRecords({ worktreeDir, projectRoot, epicId, fsImpl })
|
|
52
|
+
* harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths, fsImpl })
|
|
29
53
|
* → { copied: string[], skipped: { path, reason }[] }
|
|
30
|
-
*
|
|
54
|
+
* Copies every record in the job's own `plan-records/<epicId>/` folder, plus
|
|
55
|
+
* each well-formed `declaredPaths` entry (the PRD's frontmatter
|
|
56
|
+
* artifactPaths), whose folder may be a different Epic's. `copied` holds
|
|
57
|
+
* destination absolute paths.
|
|
31
58
|
*/
|
|
32
|
-
function harvestPlanRecords({ worktreeDir, projectRoot, epicId, fsImpl = fs } = {}) {
|
|
59
|
+
function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths = [], fsImpl = fs } = {}) {
|
|
33
60
|
/** @type {string[]} */
|
|
34
61
|
const copied = [];
|
|
35
62
|
/** @type {{ path: string, reason: string }[]} */
|
|
36
63
|
const skipped = [];
|
|
64
|
+
/** @type {Set<string>} source paths already handled */
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Copy one record `src` to `plan-records/<folder>/<name>` in the main
|
|
69
|
+
* checkout with every safety check. Returns false when `missingReason` is
|
|
70
|
+
* set and the source does not exist (reported with that reason).
|
|
71
|
+
* @param {string} src @param {string} folder @param {string} name
|
|
72
|
+
* @param {string} [missingReason]
|
|
73
|
+
*/
|
|
74
|
+
function copyOne(src, folder, name, missingReason) {
|
|
75
|
+
seen.add(src);
|
|
76
|
+
try {
|
|
77
|
+
if (!NAME_RE.test(name)) { skipped.push({ path: src, reason: 'name not allowed' }); return; }
|
|
78
|
+
let st;
|
|
79
|
+
try {
|
|
80
|
+
st = fsImpl.lstatSync(src);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (missingReason && e && e.code === 'ENOENT') { skipped.push({ path: src, reason: missingReason }); return; }
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
if (st.isSymbolicLink()) { skipped.push({ path: src, reason: 'symlink' }); return; }
|
|
86
|
+
if (st.isDirectory()) { skipped.push({ path: src, reason: 'directory' }); return; }
|
|
87
|
+
if (!st.isFile()) { skipped.push({ path: src, reason: 'not a regular file' }); return; }
|
|
88
|
+
if (st.size > MAX_BYTES) { skipped.push({ path: src, reason: `oversize (${st.size} > ${MAX_BYTES} bytes)` }); return; }
|
|
89
|
+
|
|
90
|
+
const destDir = path.resolve(opsPath(projectRoot, NAMESPACE, folder));
|
|
91
|
+
const dest = path.resolve(opsPath(projectRoot, NAMESPACE, folder, name));
|
|
92
|
+
if (path.dirname(dest) !== destDir) { skipped.push({ path: src, reason: 'destination escapes plan-records folder' }); return; }
|
|
93
|
+
if (dest === src) return;
|
|
94
|
+
const verdict = checkOpsWrite(dest, WRITER);
|
|
95
|
+
if (!verdict.ok) { skipped.push({ path: src, reason: `write refused: ${verdict.error}` }); return; }
|
|
96
|
+
assertOpsWrite(dest, WRITER);
|
|
97
|
+
|
|
98
|
+
const text = fsImpl.readFileSync(src, 'utf8');
|
|
99
|
+
if (Buffer.byteLength(text, 'utf8') > MAX_BYTES) { skipped.push({ path: src, reason: 'oversize after read' }); return; }
|
|
100
|
+
writeTextAtomicSync(dest, text);
|
|
101
|
+
copied.push(dest);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
skipped.push({ path: src, reason: `copy failed: ${errMsg(e)}` });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
37
107
|
try {
|
|
38
108
|
if (typeof epicId !== 'string' || !EPIC_ID_RE.test(epicId)) {
|
|
39
109
|
skipped.push({ path: String(epicId), reason: 'unsafe epicId' });
|
|
@@ -45,59 +115,57 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, fsImpl = fs } =
|
|
|
45
115
|
return { copied, skipped };
|
|
46
116
|
}
|
|
47
117
|
if (path.resolve(worktreeDir) === path.resolve(projectRoot)) return { copied, skipped };
|
|
118
|
+
const wtRoot = path.resolve(worktreeDir);
|
|
48
119
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
destDir
|
|
53
|
-
} catch (e) {
|
|
54
|
-
skipped.push({ path: srcDir, reason: `destination refused: ${errMsg(e)}` });
|
|
55
|
-
return { copied, skipped };
|
|
56
|
-
}
|
|
57
|
-
if (destDir === srcDir) return { copied, skipped };
|
|
58
|
-
|
|
59
|
-
let srcStat;
|
|
60
|
-
try {
|
|
61
|
-
srcStat = fsImpl.lstatSync(srcDir);
|
|
62
|
-
} catch {
|
|
63
|
-
return { copied, skipped }; // no records written by this job
|
|
64
|
-
}
|
|
65
|
-
if (!srcStat.isDirectory()) {
|
|
66
|
-
skipped.push({ path: srcDir, reason: 'source is not a directory' });
|
|
67
|
-
return { copied, skipped };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let names;
|
|
71
|
-
try {
|
|
72
|
-
names = fsImpl.readdirSync(srcDir).map(String).sort();
|
|
73
|
-
} catch (e) {
|
|
74
|
-
skipped.push({ path: srcDir, reason: `cannot list source: ${errMsg(e)}` });
|
|
75
|
-
return { copied, skipped };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
for (const name of names) {
|
|
79
|
-
const src = path.join(srcDir, name);
|
|
120
|
+
// Pass 1: everything in the job's own plan-records/<epicId>/ folder.
|
|
121
|
+
folderPass: {
|
|
122
|
+
const srcDir = path.join(wtRoot, OPS_ROOT_DIR, NAMESPACE, epicId);
|
|
123
|
+
let destDir;
|
|
80
124
|
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
125
|
+
destDir = path.resolve(opsPath(projectRoot, NAMESPACE, epicId));
|
|
126
|
+
} catch (e) {
|
|
127
|
+
skipped.push({ path: srcDir, reason: `destination refused: ${errMsg(e)}` });
|
|
128
|
+
break folderPass;
|
|
129
|
+
}
|
|
130
|
+
if (destDir === srcDir) break folderPass;
|
|
131
|
+
let srcStat;
|
|
132
|
+
try {
|
|
133
|
+
srcStat = fsImpl.lstatSync(srcDir);
|
|
134
|
+
} catch {
|
|
135
|
+
break folderPass; // no records written by this job in its own folder
|
|
136
|
+
}
|
|
137
|
+
if (!srcStat.isDirectory()) {
|
|
138
|
+
skipped.push({ path: srcDir, reason: 'source is not a directory' });
|
|
139
|
+
break folderPass;
|
|
140
|
+
}
|
|
141
|
+
let names;
|
|
142
|
+
try {
|
|
143
|
+
names = fsImpl.readdirSync(srcDir).map(String).sort();
|
|
98
144
|
} catch (e) {
|
|
99
|
-
skipped.push({ path:
|
|
145
|
+
skipped.push({ path: srcDir, reason: `cannot list source: ${errMsg(e)}` });
|
|
146
|
+
break folderPass;
|
|
147
|
+
}
|
|
148
|
+
for (const name of names) copyOne(path.join(srcDir, name), epicId, name);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Pass 2: records the PRD declared in frontmatter artifactPaths.
|
|
152
|
+
const declared = Array.isArray(declaredPaths) ? declaredPaths : [];
|
|
153
|
+
for (const p of declared) {
|
|
154
|
+
const parsed = parseDeclaredPath(p);
|
|
155
|
+
if (!('folder' in parsed)) { skipped.push({ path: String(p), reason: parsed.reason }); continue; }
|
|
156
|
+
const src = path.join(wtRoot, OPS_ROOT_DIR, NAMESPACE, parsed.folder, parsed.name);
|
|
157
|
+
if (seen.has(src)) continue;
|
|
158
|
+
// Pass 1 refuses a symlinked/non-directory own folder; hold every
|
|
159
|
+
// declared folder to the same rule so a declaration cannot bypass it.
|
|
160
|
+
const folderDir = path.dirname(src);
|
|
161
|
+
let folderStat = null;
|
|
162
|
+
try { folderStat = fsImpl.lstatSync(folderDir); } catch { /* missing: copyOne reports */ }
|
|
163
|
+
if (folderStat && (folderStat.isSymbolicLink() || !folderStat.isDirectory())) {
|
|
164
|
+
seen.add(src);
|
|
165
|
+
skipped.push({ path: src, reason: 'declared epic folder is not a directory' });
|
|
166
|
+
continue;
|
|
100
167
|
}
|
|
168
|
+
copyOne(src, parsed.folder, parsed.name, 'declared plan record not found in worktree');
|
|
101
169
|
}
|
|
102
170
|
} catch (e) {
|
|
103
171
|
skipped.push({ path: String(worktreeDir), reason: `harvest failed: ${errMsg(e)}` });
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
const path = require('node:path');
|
|
20
20
|
const { opsPath, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
21
|
-
const { writeJsonAtomic } = require('../util/atomicFs.cjs');
|
|
21
|
+
const { writeJsonAtomic, writeTextAtomic, readJsonOr } = require('../util/atomicFs.cjs');
|
|
22
22
|
|
|
23
23
|
const WRITER = 'scheduler';
|
|
24
24
|
const SCHEMA_VERSION = 1;
|
|
@@ -77,6 +77,64 @@ async function writeOutcomeRecord({
|
|
|
77
77
|
return file;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* mergeOutcomeChecks({ cwd, epicId, slug, checks, write? }) → Promise<boolean>
|
|
82
|
+
* (true when a record was rewritten). Replaces the existing record's `checks`
|
|
83
|
+
* entries by id with the fresh ones (each stamped ranAt + stage
|
|
84
|
+
* 'validator-dispatch' unless already stamped), keeps every other entry, and
|
|
85
|
+
* writes atomically as 'scheduler'. No record on disk → no write. Never throws.
|
|
86
|
+
*/
|
|
87
|
+
async function mergeOutcomeChecks({ cwd, epicId, slug, checks, write = writeJsonAtomic } = {}) {
|
|
88
|
+
try {
|
|
89
|
+
const file = outcomeRecordPath(cwd, epicId, slug);
|
|
90
|
+
const record = await readJsonOr(file, null);
|
|
91
|
+
if (!record || typeof record !== 'object' || Array.isArray(record)) return false;
|
|
92
|
+
const ranAt = new Date().toISOString();
|
|
93
|
+
const fresh = objList(checks)
|
|
94
|
+
.filter((c) => typeof c.id === 'string' && c.id)
|
|
95
|
+
.map((c) => ({ ...c, ranAt: c.ranAt || ranAt, stage: c.stage || 'validator-dispatch' }));
|
|
96
|
+
const freshById = new Map(fresh.map((c) => [c.id, c]));
|
|
97
|
+
const merged = [];
|
|
98
|
+
const seen = new Set();
|
|
99
|
+
for (const c of objList(record.checks)) {
|
|
100
|
+
if (typeof c.id === 'string' && freshById.has(c.id)) {
|
|
101
|
+
if (!seen.has(c.id)) { merged.push(freshById.get(c.id)); seen.add(c.id); }
|
|
102
|
+
} else merged.push(c);
|
|
103
|
+
}
|
|
104
|
+
for (const c of fresh) if (!seen.has(c.id)) { merged.push(c); seen.add(c.id); }
|
|
105
|
+
assertOpsWrite(file, WRITER);
|
|
106
|
+
await write(file, { ...record, checks: merged });
|
|
107
|
+
return true;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.error('[prdOutcomeRecord] mergeOutcomeChecks failed', epicId, slug, e && e.message ? e.message : e);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* writeCheckBody({ cwd, epicId, slug, id, body, write? }) → Promise<string|null>.
|
|
116
|
+
* Writes one http check's response body to
|
|
117
|
+
* scheduler/epics/<epicId>/outcomes/<slug>.bodies/<id>.txt (atomic, writer
|
|
118
|
+
* 'scheduler'; overwritten per id, so each check keeps one copy). Returns the
|
|
119
|
+
* absolute path, or null on a bad id / write failure. Never throws. The
|
|
120
|
+
* directory lives under the Epic's scheduler folder, so epicPurge removes it
|
|
121
|
+
* with the outcome records.
|
|
122
|
+
*/
|
|
123
|
+
async function writeCheckBody({ cwd, epicId, slug, id, body, write = writeTextAtomic } = {}) {
|
|
124
|
+
try {
|
|
125
|
+
assertIds(epicId, slug);
|
|
126
|
+
if (typeof id !== 'string' || !SLUG_RE.test(id) || id.includes('..')) throw new Error(`invalid check id "${id}"`);
|
|
127
|
+
if (typeof body !== 'string') throw new Error('body must be a string');
|
|
128
|
+
const file = opsPath(cwd, 'scheduler', 'epics', epicId, 'outcomes', `${slug}.bodies`, `${id}.txt`);
|
|
129
|
+
assertOpsWrite(file, WRITER);
|
|
130
|
+
await write(file, body);
|
|
131
|
+
return file;
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.error('[prdOutcomeRecord] writeCheckBody failed', epicId, slug, id, e && e.message ? e.message : e);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
80
138
|
/**
|
|
81
139
|
* Pure: derive { verdict, commits, files, gates, checks } from a finalized
|
|
82
140
|
* job row plus the run's verifyResult. `gates` holds the verifier verdict
|
|
@@ -129,5 +187,5 @@ async function listCommitFiles(cwd, shas) {
|
|
|
129
187
|
}
|
|
130
188
|
|
|
131
189
|
module.exports = {
|
|
132
|
-
writeOutcomeRecord, outcomeRecordPath, buildOutcomeFromJob, listCommitFiles, SCHEMA_VERSION,
|
|
190
|
+
writeOutcomeRecord, mergeOutcomeChecks, writeCheckBody, outcomeRecordPath, buildOutcomeFromJob, listCommitFiles, SCHEMA_VERSION,
|
|
133
191
|
};
|
|
@@ -403,6 +403,21 @@ function loadMachineStateSync() {
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
/**
|
|
407
|
+
* The machine-runtime state file's `config` (firePolicy, utilizationThreshold,
|
|
408
|
+
* …) or {} when the file is missing, unreadable or carries none. Reads only the
|
|
409
|
+
* small machine file — never a project queue shard — and never throws.
|
|
410
|
+
*/
|
|
411
|
+
function readMachineConfigSync() {
|
|
412
|
+
try {
|
|
413
|
+
const m = loadMachineStateSync();
|
|
414
|
+
const c = m && m.shaped && m.shaped.config;
|
|
415
|
+
return c && typeof c === 'object' ? c : {};
|
|
416
|
+
} catch {
|
|
417
|
+
return {};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
406
421
|
async function loadMachineState() {
|
|
407
422
|
let raw;
|
|
408
423
|
try {
|
|
@@ -604,6 +619,7 @@ module.exports = {
|
|
|
604
619
|
writeJsonAtomic,
|
|
605
620
|
writeJsonAtomicSync,
|
|
606
621
|
findLongestValidJsonPrefix,
|
|
622
|
+
readMachineConfigSync,
|
|
607
623
|
};
|
|
608
624
|
|
|
609
625
|
// Lazy path getters (SM_SCHEDULER_HOME resolved at read, never at require).
|
|
@@ -34,7 +34,13 @@ const fs = require('node:fs');
|
|
|
34
34
|
const path = require('node:path');
|
|
35
35
|
const { splitFrontmatter } = require('../prd/prdFrontmatter.cjs');
|
|
36
36
|
const { readTail } = require('../util/fileTail.cjs');
|
|
37
|
-
const {
|
|
37
|
+
const {
|
|
38
|
+
resolvePrdWriteDir,
|
|
39
|
+
resolveEpicPrdWriteDir,
|
|
40
|
+
listEpicPrdDirs,
|
|
41
|
+
listArchivedPrdDirs,
|
|
42
|
+
isSafeEpicId,
|
|
43
|
+
} = require('../prd/prdLocations.cjs');
|
|
38
44
|
const atomicFs = require('../util/atomicFs.cjs');
|
|
39
45
|
|
|
40
46
|
// ─── VERDICT_LABELS — deliberate duplicate ──────────────────────────────────
|
|
@@ -74,6 +80,7 @@ const FAILURE_CLASSES = {
|
|
|
74
80
|
TRANSCRIPT_ERRORS: 'transcript-errors',
|
|
75
81
|
ABANDONED_BACKGROUND_TASK: 'abandoned-background-task',
|
|
76
82
|
BLOCKED_BY_FOREIGN_WIP: 'blocked-by-foreign-wip',
|
|
83
|
+
EXECUTOR_FAIL: 'executor-fail',
|
|
77
84
|
UNKNOWN: 'unknown',
|
|
78
85
|
};
|
|
79
86
|
|
|
@@ -105,6 +112,7 @@ const RECOVERY_ACTIONS = {
|
|
|
105
112
|
// guidance into that cold-read investigation.
|
|
106
113
|
[FAILURE_CLASSES.ABANDONED_BACKGROUND_TASK]: 'investigate',
|
|
107
114
|
[FAILURE_CLASSES.BLOCKED_BY_FOREIGN_WIP]: 'archive',
|
|
115
|
+
[FAILURE_CLASSES.EXECUTOR_FAIL]: 'investigate',
|
|
108
116
|
[FAILURE_CLASSES.UNKNOWN]: 'investigate',
|
|
109
117
|
};
|
|
110
118
|
|
|
@@ -132,6 +140,8 @@ const PREVENTION_HINTS = {
|
|
|
132
140
|
'A headless run cannot receive a background-task completion notification — never let a long Bash command auto-background past its foreground timeout and then wait for it. Run long commands with an explicit bound (`timeout <N> <cmd>`) so they finish in the foreground, or poll their output file directly instead of waiting on Monitor/notification.',
|
|
133
141
|
[FAILURE_CLASSES.BLOCKED_BY_FOREIGN_WIP]:
|
|
134
142
|
'This job correctly reported `SCHEDULER_VERDICT: BLOCKED_BY_FOREIGN_WIP` against a sibling job\'s in-flight, uncommitted files three times in a row — auto-requeue is exhausted (reconcile() only clears this once the blocked paths go clean). This is not a defect in this PRD\'s own work: check on the sibling job/human that owns the still-dirty path(s) named on the job row, and either wait for them to commit or manually reset this job to `pending` once the tree is clear. Do not author a fix-plan PRD against it.',
|
|
143
|
+
[FAILURE_CLASSES.EXECUTOR_FAIL]:
|
|
144
|
+
"The executor ended `SCHEDULER_VERDICT: FAIL` and stated why — read its reason under 'What happened'. That stated reason, not a log-tail pattern, is what to fix. If the blocker is a step only a person can do (an account, dashboard or signing action), it belongs behind a preflight hold, not in the job body (PRD_AUTHORING.md §6).",
|
|
135
145
|
[FAILURE_CLASSES.UNKNOWN]:
|
|
136
146
|
'Re-run the acceptance criteria gate locally against the failure log to pin down the specific break before re-queuing.',
|
|
137
147
|
};
|
|
@@ -162,7 +172,13 @@ const SELF_QUEUE_SKILL_RE = /Launching skill: session-manager-dev:(develop|proce
|
|
|
162
172
|
// rule now requires a stream-json tool_use `"name":"ScheduleWakeup"` field, and
|
|
163
173
|
// classifyFailure strips init events before any rule runs.
|
|
164
174
|
const SELF_QUEUE_WAKEUP_RE = /"name"\s*:\s*"ScheduleWakeup"/;
|
|
165
|
-
|
|
175
|
+
// Stuck-loop rule: matched only against real Bash tool_use commands (see
|
|
176
|
+
// bashCommandsIn), never prose. Incident: starry-night-2
|
|
177
|
+
// 856-ios-testflight-public-link (run 2026-11-24T17-02-30-189Z) — the old
|
|
178
|
+
// word rule matched 'until ' in skill-catalog text in the log tail; 49 of 114
|
|
179
|
+
// reports since 2026-11-17 were prose false positives.
|
|
180
|
+
const UNBOUNDED_LOOP_RE = /\b(?:while\s+(?:true\b|:)|until\s)[\s\S]*?(?:;|\n)\s*do\b/;
|
|
181
|
+
const TIMEOUT_BOUND_RE = /\btimeout\s+(?:-\S+\s+)*\d/;
|
|
166
182
|
const AC_CHECKBOX_RE = /^\s*[-*]\s*\[[xX]\]/;
|
|
167
183
|
const SENTINEL_PASS_RE = /SCHEDULER_VERDICT:\s*PASS/;
|
|
168
184
|
const STUCK_LOOP_WINDOW = 40; // "final lines" per AC
|
|
@@ -188,6 +204,31 @@ function structuredPassLine(line) {
|
|
|
188
204
|
}
|
|
189
205
|
}
|
|
190
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Shell commands from stream-json Bash tool_use events in `lines`. Plain-text
|
|
209
|
+
* lines, assistant text blocks, tool_result content and system events yield
|
|
210
|
+
* nothing; malformed JSON lines are skipped. Pure; O(n) in characters.
|
|
211
|
+
*/
|
|
212
|
+
function bashCommandsIn(lines) {
|
|
213
|
+
const out = [];
|
|
214
|
+
for (const line of lines || []) {
|
|
215
|
+
if (typeof line !== 'string' || !line.includes('"tool_use"') || !line.includes('"Bash"')) continue;
|
|
216
|
+
let obj;
|
|
217
|
+
try {
|
|
218
|
+
obj = JSON.parse(line.trim());
|
|
219
|
+
} catch {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (!obj || obj.type !== 'assistant' || !Array.isArray(obj.message?.content)) continue;
|
|
223
|
+
for (const c of obj.message.content) {
|
|
224
|
+
if (c && c.type === 'tool_use' && c.name === 'Bash' && typeof c.input?.command === 'string') {
|
|
225
|
+
out.push(c.input.command);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
|
|
191
232
|
/**
|
|
192
233
|
* Drop every stream-json harness init event (`"type":"system"` +
|
|
193
234
|
* `"subtype":"init"`) from a log tail. That line names every available tool
|
|
@@ -239,22 +280,27 @@ function classifyFailure({ verdict, logTail: rawLogTail }) {
|
|
|
239
280
|
// Checked before SELF_QUEUE/STUCK_LOOP: the verifier already did the real
|
|
240
281
|
// detection work (scanning for the harness's own auto-background marker
|
|
241
282
|
// text) to produce this verdict — trust it rather than re-deriving from the
|
|
242
|
-
// log tail, which can otherwise false-match SELF_QUEUE_WAKEUP_RE
|
|
243
|
-
//
|
|
244
|
-
//
|
|
283
|
+
// log tail, which can otherwise false-match SELF_QUEUE_WAKEUP_RE on words
|
|
284
|
+
// like "background" that appear in the harness's own auto-background
|
|
285
|
+
// tool_result.
|
|
245
286
|
if (verdict === 'abandoned_background_task') {
|
|
246
287
|
return FAILURE_CLASSES.ABANDONED_BACKGROUND_TASK;
|
|
247
288
|
}
|
|
248
289
|
|
|
249
290
|
// Checked before STUCK_LOOP: a backgrounded command + ScheduleWakeup
|
|
250
291
|
// (variant b) can land words like "sleep"/"poll" in the tail via the PRD's
|
|
251
|
-
// own AC text
|
|
292
|
+
// own AC text; self-queue is the truer class for that run (see PRD 771).
|
|
252
293
|
if (SELF_QUEUE_SKILL_RE.test(logTail || '') || SELF_QUEUE_WAKEUP_RE.test(logTail || '')) {
|
|
253
294
|
return FAILURE_CLASSES.SELF_QUEUE;
|
|
254
295
|
}
|
|
255
296
|
|
|
297
|
+
// Checked before STUCK_LOOP: the executor ended SCHEDULER_VERDICT: FAIL and
|
|
298
|
+
// stated its own reason — trust that over any log-tail pattern.
|
|
299
|
+
if (verdict === 'sentinel_fail') return FAILURE_CLASSES.EXECUTOR_FAIL;
|
|
300
|
+
|
|
301
|
+
// Only a real, unbounded Bash loop command counts — never prose.
|
|
256
302
|
const tailWindow = lines.slice(-STUCK_LOOP_WINDOW);
|
|
257
|
-
if (tailWindow.some((
|
|
303
|
+
if (bashCommandsIn(tailWindow).some((cmd) => UNBOUNDED_LOOP_RE.test(cmd) && !TIMEOUT_BOUND_RE.test(cmd))) {
|
|
258
304
|
return FAILURE_CLASSES.STUCK_LOOP;
|
|
259
305
|
}
|
|
260
306
|
|
|
@@ -317,14 +363,31 @@ function readRunMeta(runDir, slug) {
|
|
|
317
363
|
}
|
|
318
364
|
}
|
|
319
365
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Read the parked job's PRD body (frontmatter stripped). Looks where PRDs
|
|
368
|
+
* really live, in order: the job's own Epic prds/, every Epic prds/ of the
|
|
369
|
+
* project, every prds-archived/ twin, then the retired flat dir. Scoped to
|
|
370
|
+
* job.cwd only — never a machine-wide scan. Returns '' when not found; never
|
|
371
|
+
* throws.
|
|
372
|
+
*/
|
|
373
|
+
function readPrdBody(job) {
|
|
374
|
+
const cwd = job?.cwd;
|
|
375
|
+
const slug = job?.slug;
|
|
376
|
+
if (!cwd || typeof cwd !== 'string' || !slug) return '';
|
|
377
|
+
const candidates = [];
|
|
378
|
+
const add = (dir) => { if (dir && !candidates.includes(dir)) candidates.push(dir); };
|
|
379
|
+
if (isSafeEpicId(job.epicId)) {
|
|
380
|
+
try { add(resolveEpicPrdWriteDir(cwd, job.epicId)); } catch { /* skip */ }
|
|
381
|
+
}
|
|
382
|
+
try { for (const d of listEpicPrdDirs(cwd)) add(d); } catch { /* skip */ }
|
|
383
|
+
try { for (const d of listArchivedPrdDirs(cwd)) add(d); } catch { /* skip */ }
|
|
384
|
+
try { add(resolvePrdWriteDir(cwd)); } catch { /* skip */ }
|
|
385
|
+
for (const dir of candidates) {
|
|
386
|
+
let raw;
|
|
387
|
+
try { raw = fs.readFileSync(path.join(dir, `${slug}.md`), 'utf8'); } catch { continue; }
|
|
388
|
+
try { return splitFrontmatter(raw).body; } catch { return ''; }
|
|
327
389
|
}
|
|
390
|
+
return '';
|
|
328
391
|
}
|
|
329
392
|
|
|
330
393
|
/**
|
|
@@ -412,7 +475,7 @@ async function writeRcaReport({ job, runDir, verdict, annotations, investigation
|
|
|
412
475
|
const meta = readRunMeta(runDir, job.slug);
|
|
413
476
|
const logPath = runDir ? path.join(runDir, `${job.slug}.log`) : null;
|
|
414
477
|
const logTail = logPath ? readTail(logPath, 64 * 1024) : '';
|
|
415
|
-
const acText = extractAcceptanceCriteria(readPrdBody(job
|
|
478
|
+
const acText = extractAcceptanceCriteria(readPrdBody(job));
|
|
416
479
|
const failureClass = classifyFailure({ verdict, logTail });
|
|
417
480
|
|
|
418
481
|
const markdown = buildRcaMarkdown({
|
|
@@ -442,6 +505,7 @@ module.exports = {
|
|
|
442
505
|
// Pure helpers, exported for unit tests.
|
|
443
506
|
humanVerdict,
|
|
444
507
|
classifyFailure,
|
|
508
|
+
bashCommandsIn,
|
|
445
509
|
stripHarnessInitEvents,
|
|
446
510
|
extractAcceptanceCriteria,
|
|
447
511
|
extractRcaBlock,
|
|
@@ -117,6 +117,15 @@ const ScheduleJobSchema = z
|
|
|
117
117
|
quietLeaseDegraded: z.boolean().optional(),
|
|
118
118
|
// Salvaged uncommitted diff patch path (PRD 1098).
|
|
119
119
|
salvagePatch: z.string().nullable().optional(),
|
|
120
|
+
// Artifact evidence captured before the job worktree was removed, bound
|
|
121
|
+
// to the run that captured it (reverifyNeedsReview reuses it for that run only).
|
|
122
|
+
artifactEvidence: z.object({
|
|
123
|
+
runId: z.string(),
|
|
124
|
+
ok: z.boolean(),
|
|
125
|
+
verified: z.array(z.any()),
|
|
126
|
+
paths: z.array(z.string()),
|
|
127
|
+
capturedAt: z.string(),
|
|
128
|
+
}).passthrough().nullable().optional(),
|
|
120
129
|
// Pin of a dead run's uncommitted checkout work (refs/sm-uncommitted/...), PRD 2892.
|
|
121
130
|
uncommittedSnapshot: z.object({ sha: z.string(), ref: z.string() }).optional(),
|
|
122
131
|
// Leftover-attribution fields: the newly-dirty paths a terminal run left
|
|
@@ -152,6 +161,10 @@ const ScheduleJobSchema = z
|
|
|
152
161
|
// Content id of the AgentSnapshot (agentSnapshot.cjs) the job's first
|
|
153
162
|
// dispatch pinned; every later dispatch (resume) re-runs that snapshot.
|
|
154
163
|
agentSnapshotId: z.string().optional(),
|
|
164
|
+
// Validator only: the { ids, failedIds } per judged PRD built at dispatch
|
|
165
|
+
// from the check results the validator was shown; notifyOriginatingTab
|
|
166
|
+
// cross-checks the verdict against it instead of re-running the checks.
|
|
167
|
+
validatorCriteriaExpected: z.record(z.string(), z.object({ ids: z.array(z.string()), failedIds: z.array(z.string()) })).optional(),
|
|
155
168
|
})
|
|
156
169
|
.passthrough();
|
|
157
170
|
|
|
@@ -109,6 +109,12 @@ function heartbeatPath() { return assertNotLiveRoot(path.join(schedulerHome(), '
|
|
|
109
109
|
function sessionSlotsConfigPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'session-slots-config.json'), 'sessionSlotsConfigPath'); }
|
|
110
110
|
/** Machine-level per-project 'Scripts may run Tasks' switches, keyed by abs cwd (tasks/taskSwitch.cjs). */
|
|
111
111
|
function taskSwitchesPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'task-switches.json'), 'taskSwitchesPath'); }
|
|
112
|
+
/** Machine-level scheduler chat turns the usage hold kept, delivered later per tab (heldSchedulerTurns.cjs). */
|
|
113
|
+
function heldSchedulerTurnsPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'held-scheduler-turns.json'), 'heldSchedulerTurnsPath'); }
|
|
114
|
+
/** Machine-level per-project 'Scripts may run Demo Video' switches, keyed by abs cwd (project-pages/videoScriptPress.cjs). */
|
|
115
|
+
function videoScriptSwitchesPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'video-script-switches.json'), 'videoScriptSwitchesPath'); }
|
|
116
|
+
/** Machine-level ledger of scripted Demo Video presses (entryId -> epicId, slug, externalRef) (project-pages/videoScriptPress.cjs). */
|
|
117
|
+
function videoScriptRunsPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'video-script-runs.json'), 'videoScriptRunsPath'); }
|
|
112
118
|
/** Machine-level (project cwd, externalRef) -> Epic id index (epic/externalRefIndex.cjs). */
|
|
113
119
|
function externalRefIndexPath() { return assertNotLiveRoot(path.join(schedulerHome(), 'external-refs.json'), 'externalRefIndexPath'); }
|
|
114
120
|
/** Machine-level "Needs you" items posted by outside apps (feedback-remote/needsYouStore.cjs). */
|
|
@@ -205,6 +211,9 @@ module.exports = {
|
|
|
205
211
|
heartbeatPath,
|
|
206
212
|
sessionSlotsConfigPath,
|
|
207
213
|
taskSwitchesPath,
|
|
214
|
+
heldSchedulerTurnsPath,
|
|
215
|
+
videoScriptSwitchesPath,
|
|
216
|
+
videoScriptRunsPath,
|
|
208
217
|
externalRefIndexPath,
|
|
209
218
|
needsYouPath,
|
|
210
219
|
adminTokenPath,
|