claude-code-session-manager 0.143.0 → 0.145.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/README.md +3 -1
- package/dist/assets/AppSettings-BR5b6oof.js +2 -0
- package/dist/assets/{History-DTttbvPb.js → History-B4U0mCdK.js} +2 -2
- package/dist/assets/HomeClaudeConfig-DQqG7lFE.js +5 -0
- package/dist/assets/{Panel-B_D4Bg7L.js → Panel-CwsOJ0nI.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-BzRowu8x.js +26 -0
- package/dist/assets/Scheduler-dr7CNOcL.js +16 -0
- package/dist/assets/{SkillReferenceGraph-D1b2aiol.js → SkillReferenceGraph-CroBPY4C.js} +1 -1
- package/dist/assets/{Skills-cfV7sgk6.js → Skills-BiW2lCnD.js} +23 -23
- package/dist/assets/{TiptapBody-DVXtEIVy.js → TiptapBody-CYTkQiva.js} +27 -27
- package/dist/assets/{Toggle-CYajnSdx.js → Toggle-WFBYo8JI.js} +1 -1
- package/dist/assets/{VoiceButton-DJ4gGRuE.js → VoiceButton-DZu8dTpO.js} +1 -1
- package/dist/assets/{historyTotals-D3MoHY2U.js → historyTotals-B7KeXLSE.js} +1 -1
- package/dist/assets/{index-DVHIHoJf.css → index-BJ5TJvmz.css} +1 -1
- package/dist/assets/{index-CdTppjKR.js → index-hXRNm0UJ.js} +698 -697
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +442 -439
- package/package.json +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +25 -19
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +16 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/weekly-consolidation.md +91 -0
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +9 -6
- package/scripts/README.md +1 -1
- package/scripts/scheduler-mcp-server.cjs +77 -0
- package/src/main/adminRouteRegistry.cjs +6 -0
- package/src/main/agentLibrary.cjs +60 -11
- package/src/main/agentsIpc.cjs +19 -0
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +139 -0
- package/src/main/config.cjs +12 -0
- package/src/main/health.cjs +59 -17
- package/src/main/index.cjs +6 -2
- package/src/main/ipcSchemas.cjs +55 -1
- package/src/main/lib/claude/agentArmory.cjs +128 -0
- package/src/main/lib/claude/agentModelResolve.cjs +3 -2
- package/src/main/lib/claude/agentSnapshot.cjs +24 -3
- package/src/main/lib/claude/builtinTools.cjs +110 -0
- package/src/main/lib/claude/environmentProfiles.cjs +1 -1
- package/src/main/lib/claude/headlessMcpServers.cjs +138 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +8 -2
- package/src/main/lib/claude/personaToolScope.cjs +100 -14
- package/src/main/lib/demo-video-kit/resumableRun.cjs +21 -14
- package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
- package/src/main/lib/epic/epicDepsSync.cjs +66 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +74 -2
- package/src/main/lib/epic/epicSettle.cjs +48 -4
- package/src/main/lib/epic/epicSpawnPlan.cjs +3 -1
- package/src/main/lib/epic/epicValidationHook.cjs +9 -1
- package/src/main/lib/epic/planReviewInput.cjs +125 -0
- package/src/main/lib/epic/restorableSessions.cjs +1 -0
- package/src/main/lib/epic/scriptStartedBy.cjs +86 -0
- package/src/main/lib/externalContract.cjs +12 -0
- package/src/main/lib/feedback-remote/createdProjects.cjs +291 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +108 -14
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +5 -1
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +24 -3
- package/src/main/lib/feedback-remote/pendingReplies.cjs +8 -4
- package/src/main/lib/feedback-remote/projectCreate.cjs +415 -0
- package/src/main/lib/feedback-remote/replyClaims.cjs +15 -6
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +35 -4
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +43 -2
- package/src/main/lib/feedback-remote/servicePairLocalRoutes.cjs +91 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +95 -7
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +104 -1
- package/src/main/lib/git/gitWorktree.cjs +1 -1
- package/src/main/lib/git/worktreeDeps.cjs +9 -3
- package/src/main/lib/mcpToolCatalog.cjs +47 -7
- package/src/main/lib/mcpToolsProbe.cjs +19 -2
- package/src/main/lib/opsOwnership.cjs +2 -0
- package/src/main/lib/packs/packCatalog.cjs +98 -5
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +6 -0
- package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +9 -0
- package/src/main/lib/persona-macro/personaLoadout.cjs +58 -0
- package/src/main/lib/persona-macro/personaMerge.cjs +11 -3
- package/src/main/lib/persona-macro/personaUpgrade.cjs +96 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +1 -1
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +94 -0
- package/src/main/lib/prd/prdCreate.cjs +49 -5
- package/src/main/lib/prd/prdFrontmatter.cjs +5 -2
- package/src/main/lib/prd/prdMcpReachWarnings.cjs +46 -0
- package/src/main/lib/prd/prdSandboxWarnings.cjs +49 -0
- package/src/main/lib/process/peerChatSession.cjs +165 -0
- package/src/main/lib/project-pages/videoScriptPress.cjs +6 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +24 -4
- package/src/main/lib/promptSessionSchema.cjs +2 -0
- package/src/main/lib/scheduler/baselineGate.cjs +31 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +104 -12
- package/src/main/lib/scheduler/planReleaseRoute.cjs +110 -0
- package/src/main/lib/scheduler/planReviewSchema.cjs +182 -0
- package/src/main/lib/scheduler/planReviewStats.cjs +63 -0
- package/src/main/lib/scheduler/planReviewStore.cjs +150 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +3 -1
- package/src/main/lib/scheduler/sandboxEnvironmentLimit.cjs +141 -0
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/upgradeDrain.cjs +32 -5
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +12 -2
- package/src/main/lib/tasks/memoryConsolidation.cjs +118 -37
- package/src/main/lib/tasks/taskAdminRoutes.cjs +26 -14
- package/src/main/lib/tasks/taskRun.cjs +3 -1
- package/src/main/lib/tasks/weeklyConsolidationInputs.cjs +298 -0
- package/src/main/projectPages.cjs +22 -14
- package/src/main/pty.cjs +3 -0
- package/src/main/runVerify.cjs +80 -5
- package/src/main/scheduler/gitTreeGuard.cjs +6 -0
- package/src/main/scheduler/planReviewHold.cjs +146 -0
- package/src/main/scheduler/prdParser.cjs +1 -0
- package/src/main/scheduler/prdPaths.cjs +10 -1
- package/src/main/scheduler/reviewLadder.cjs +2 -0
- package/src/main/scheduler/utilizationHold.cjs +7 -2
- package/src/main/scheduler.cjs +692 -86
- package/src/main/seedAgentPersonas.cjs +11 -6
- package/src/main/seedStatus.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +17 -2
- package/src/main/webRemote.cjs +69 -7
- package/src/preload/api.d.ts +79 -1
- package/src/preload/apiSurface.json +39 -0
- package/src/preload/index.cjs +11 -0
- package/src/seed/agents/architect.md +28 -43
- package/src/seed/agents/dev-lead.md +3 -1
- package/src/seed/agents/md-network-curator.md +27 -0
- package/src/seed/agents/plan-reviewer.md +47 -0
- package/src/seed/agents/validator.md +2 -1
- package/dist/assets/AppSettings-BO4jDVGO.js +0 -2
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +0 -3
- package/dist/assets/ProjectClaudeConfig-DPnDJKcr.js +0 -26
- package/dist/assets/Scheduler-CNLjn90m.js +0 -16
|
@@ -25,6 +25,76 @@ function errMsg(e) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const DECLARED_PREFIX = `${OPS_ROOT_DIR}/${NAMESPACE}/`;
|
|
28
|
+
const CROSS_EPIC_EXISTS = 'exists in another Epic folder; not overwritten';
|
|
29
|
+
const SYMLINKED_PARENT = 'symlinked parent refused';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* refusedParent(chain) → { path, reason } | null
|
|
33
|
+
* lstat-checks each source parent in order (outermost first) without ever
|
|
34
|
+
* following a link. A symlink anywhere in the chain is refused; a missing
|
|
35
|
+
* entry ends the check (nothing below it exists to copy); any other lstat
|
|
36
|
+
* error is refused too, so an unreadable parent never lets a pass through.
|
|
37
|
+
* @param {string[]} chain @param {typeof fs} [fsImpl]
|
|
38
|
+
* @returns {{ path: string, reason: string } | null}
|
|
39
|
+
*/
|
|
40
|
+
function refusedParent(chain, fsImpl = fs) {
|
|
41
|
+
for (const p of chain) {
|
|
42
|
+
let st;
|
|
43
|
+
try {
|
|
44
|
+
st = fsImpl.lstatSync(p);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e && /** @type {NodeJS.ErrnoException} */ (e).code === 'ENOENT') return null;
|
|
47
|
+
return { path: p, reason: `cannot check parent: ${errMsg(e)}` };
|
|
48
|
+
}
|
|
49
|
+
if (st.isSymbolicLink()) return { path: p, reason: SYMLINKED_PARENT };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* destExists(dest) → true when anything (file, folder, symlink — never
|
|
56
|
+
* followed) sits at `dest`. Any lstat error other than ENOENT counts as
|
|
57
|
+
* existing, so an unreadable destination is never overwritten.
|
|
58
|
+
* @param {string} dest @param {typeof fs} [fsImpl]
|
|
59
|
+
*/
|
|
60
|
+
function destExists(dest, fsImpl = fs) {
|
|
61
|
+
try {
|
|
62
|
+
fsImpl.lstatSync(dest);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return !(e && /** @type {NodeJS.ErrnoException} */ (e).code === 'ENOENT');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* createExclusive(dest, text, fsImpl) → true when created, false when `dest`
|
|
71
|
+
* already existed (EEXIST). Writes a temp file beside `dest`, then hard-links
|
|
72
|
+
* it into place: link fails with EEXIST rather than overwriting, so create-only
|
|
73
|
+
* is one atomic step with no check-then-write gap. The temp file is always
|
|
74
|
+
* removed. Other errors throw.
|
|
75
|
+
* @param {string} dest @param {string} text @param {any} [fsImpl]
|
|
76
|
+
*/
|
|
77
|
+
function createExclusive(dest, text, fsImpl = fs) {
|
|
78
|
+
const link = fsImpl.linkSync || fs.linkSync;
|
|
79
|
+
const unlink = fsImpl.unlinkSync || fs.unlinkSync;
|
|
80
|
+
const mkdir = fsImpl.mkdirSync || fs.mkdirSync;
|
|
81
|
+
const write = fsImpl.writeFileSync || fs.writeFileSync;
|
|
82
|
+
const dir = path.dirname(dest);
|
|
83
|
+
mkdir(dir, { recursive: true });
|
|
84
|
+
const tmp = path.join(dir, `.${path.basename(dest)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
85
|
+
try {
|
|
86
|
+
write(tmp, text, { encoding: 'utf8', flag: 'wx' });
|
|
87
|
+
try {
|
|
88
|
+
link(tmp, dest);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (e && /** @type {NodeJS.ErrnoException} */ (e).code === 'EEXIST') return false;
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
} finally {
|
|
95
|
+
try { unlink(tmp); } catch { /* already gone */ }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
28
98
|
|
|
29
99
|
/**
|
|
30
100
|
* parseDeclaredPath(p) → { folder, name } | { reason }
|
|
@@ -53,8 +123,9 @@ function parseDeclaredPath(p) {
|
|
|
53
123
|
* → { copied: string[], skipped: { path, reason }[] }
|
|
54
124
|
* Copies every record in the job's own `plan-records/<epicId>/` folder, plus
|
|
55
125
|
* each well-formed `declaredPaths` entry (the PRD's frontmatter
|
|
56
|
-
* artifactPaths), whose folder may be a different Epic's
|
|
57
|
-
* destination
|
|
126
|
+
* artifactPaths), whose folder may be a different Epic's — create-only there:
|
|
127
|
+
* an existing destination in another Epic's folder is never overwritten.
|
|
128
|
+
* `copied` holds destination absolute paths.
|
|
58
129
|
*/
|
|
59
130
|
function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths = [], fsImpl = fs } = {}) {
|
|
60
131
|
/** @type {string[]} */
|
|
@@ -70,8 +141,10 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
70
141
|
* set and the source does not exist (reported with that reason).
|
|
71
142
|
* @param {string} src @param {string} folder @param {string} name
|
|
72
143
|
* @param {string} [missingReason]
|
|
144
|
+
* @param {boolean} [createOnly] another Epic's folder: never overwrite an
|
|
145
|
+
* existing destination (checked with lstat, so a symlink counts as existing)
|
|
73
146
|
*/
|
|
74
|
-
function copyOne(src, folder, name, missingReason) {
|
|
147
|
+
function copyOne(src, folder, name, missingReason, createOnly = false) {
|
|
75
148
|
seen.add(src);
|
|
76
149
|
try {
|
|
77
150
|
if (!NAME_RE.test(name)) { skipped.push({ path: src, reason: 'name not allowed' }); return; }
|
|
@@ -97,6 +170,11 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
97
170
|
|
|
98
171
|
const text = fsImpl.readFileSync(src, 'utf8');
|
|
99
172
|
if (Buffer.byteLength(text, 'utf8') > MAX_BYTES) { skipped.push({ path: src, reason: 'oversize after read' }); return; }
|
|
173
|
+
if (createOnly) {
|
|
174
|
+
if (!createExclusive(dest, text, fsImpl)) { skipped.push({ path: src, reason: CROSS_EPIC_EXISTS }); return; }
|
|
175
|
+
copied.push(dest);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
100
178
|
writeTextAtomicSync(dest, text);
|
|
101
179
|
copied.push(dest);
|
|
102
180
|
} catch (e) {
|
|
@@ -105,10 +183,10 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
105
183
|
}
|
|
106
184
|
|
|
107
185
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
186
|
+
// An unsafe epicId only disqualifies pass 1 (the job's own folder); each
|
|
187
|
+
// declared path is validated on its own in pass 2.
|
|
188
|
+
const ownFolderSafe = typeof epicId === 'string' && EPIC_ID_RE.test(epicId);
|
|
189
|
+
if (!ownFolderSafe) skipped.push({ path: String(epicId), reason: 'unsafe epicId' });
|
|
112
190
|
if (typeof worktreeDir !== 'string' || !path.isAbsolute(worktreeDir)
|
|
113
191
|
|| typeof projectRoot !== 'string' || !path.isAbsolute(projectRoot)) {
|
|
114
192
|
skipped.push({ path: String(worktreeDir), reason: 'worktreeDir and projectRoot must be absolute paths' });
|
|
@@ -116,10 +194,13 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
116
194
|
}
|
|
117
195
|
if (path.resolve(worktreeDir) === path.resolve(projectRoot)) return { copied, skipped };
|
|
118
196
|
const wtRoot = path.resolve(worktreeDir);
|
|
197
|
+
const opsSrc = path.join(wtRoot, OPS_ROOT_DIR);
|
|
198
|
+
const recordsSrc = path.join(opsSrc, NAMESPACE);
|
|
119
199
|
|
|
120
200
|
// Pass 1: everything in the job's own plan-records/<epicId>/ folder.
|
|
121
201
|
folderPass: {
|
|
122
|
-
|
|
202
|
+
if (!ownFolderSafe) break folderPass;
|
|
203
|
+
const srcDir = path.join(recordsSrc, epicId);
|
|
123
204
|
let destDir;
|
|
124
205
|
try {
|
|
125
206
|
destDir = path.resolve(opsPath(projectRoot, NAMESPACE, epicId));
|
|
@@ -128,6 +209,10 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
128
209
|
break folderPass;
|
|
129
210
|
}
|
|
130
211
|
if (destDir === srcDir) break folderPass;
|
|
212
|
+
// Never read through a symlinked session-manager-operations/,
|
|
213
|
+
// plan-records/ or epic folder: it could point outside the worktree.
|
|
214
|
+
const refused = refusedParent([opsSrc, recordsSrc, srcDir], fsImpl);
|
|
215
|
+
if (refused) { skipped.push(refused); break folderPass; }
|
|
131
216
|
let srcStat;
|
|
132
217
|
try {
|
|
133
218
|
srcStat = fsImpl.lstatSync(srcDir);
|
|
@@ -150,22 +235,29 @@ function harvestPlanRecords({ worktreeDir, projectRoot, epicId, declaredPaths =
|
|
|
150
235
|
|
|
151
236
|
// Pass 2: records the PRD declared in frontmatter artifactPaths.
|
|
152
237
|
const declared = Array.isArray(declaredPaths) ? declaredPaths : [];
|
|
153
|
-
|
|
238
|
+
// The shared parents are checked once; a symlink there refuses the pass.
|
|
239
|
+
const sharedRefused = declared.length ? refusedParent([opsSrc, recordsSrc], fsImpl) : null;
|
|
240
|
+
if (sharedRefused) skipped.push(sharedRefused);
|
|
241
|
+
for (const p of sharedRefused ? [] : declared) {
|
|
154
242
|
const parsed = parseDeclaredPath(p);
|
|
155
243
|
if (!('folder' in parsed)) { skipped.push({ path: String(p), reason: parsed.reason }); continue; }
|
|
156
|
-
const src = path.join(
|
|
244
|
+
const src = path.join(recordsSrc, parsed.folder, parsed.name);
|
|
157
245
|
if (seen.has(src)) continue;
|
|
158
246
|
// Pass 1 refuses a symlinked/non-directory own folder; hold every
|
|
159
247
|
// declared folder to the same rule so a declaration cannot bypass it.
|
|
160
248
|
const folderDir = path.dirname(src);
|
|
249
|
+
const folderRefused = refusedParent([folderDir], fsImpl);
|
|
250
|
+
if (folderRefused) { seen.add(src); skipped.push(folderRefused); continue; }
|
|
161
251
|
let folderStat = null;
|
|
162
252
|
try { folderStat = fsImpl.lstatSync(folderDir); } catch { /* missing: copyOne reports */ }
|
|
163
|
-
if (folderStat && (
|
|
253
|
+
if (folderStat && (!folderStat.isDirectory())) {
|
|
164
254
|
seen.add(src);
|
|
165
255
|
skipped.push({ path: src, reason: 'declared epic folder is not a directory' });
|
|
166
256
|
continue;
|
|
167
257
|
}
|
|
168
|
-
|
|
258
|
+
// Another Epic's folder is create-only: a job may add a record there
|
|
259
|
+
// (a validator writing into the Epic it validates) but never overwrite one.
|
|
260
|
+
copyOne(src, parsed.folder, parsed.name, 'declared plan record not found in worktree', parsed.folder !== epicId);
|
|
169
261
|
}
|
|
170
262
|
} catch (e) {
|
|
171
263
|
skipped.push({ path: String(worktreeDir), reason: `harvest failed: ${errMsg(e)}` });
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* planReleaseRoute.cjs — POST /admin/scheduler/release-plan: the planner's one
|
|
3
|
+
* call that releases a plan held for independent review.
|
|
4
|
+
*
|
|
5
|
+
* body { cwd, epicId, validateSlug, rejected: [{ finding, reason }],
|
|
6
|
+
* accepted: number, rereview?: boolean }
|
|
7
|
+
*
|
|
8
|
+
* - release: records plan-records/<epic>/<slug>.plan-review.json release
|
|
9
|
+
* { by: 'planner', rejected, accepted }. A second call → 200 alreadyReleased.
|
|
10
|
+
* Every rejected entry needs a non-empty one-line reason (400 otherwise).
|
|
11
|
+
* - rereview: true instead asks for ONE more review after a block. Accepted
|
|
12
|
+
* only when the latest review has a `block` decision and round is 1 and the
|
|
13
|
+
* plan is not released; writes rereviewRequested: true, else 400 + reason.
|
|
14
|
+
* - cwd must be an existing absolute project root outside session-manager-operations/ → else 400 bad_cwd.
|
|
15
|
+
* - unsafe epicId / validateSlug → 400.
|
|
16
|
+
*/
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const { z } = require('zod');
|
|
20
|
+
const { readBody, sendJson } = require('../feedback-remote/localAdminHttp.cjs');
|
|
21
|
+
const { planReviewPath, readPlanReview, recordPlanRelease } = require('./planReviewStore.cjs');
|
|
22
|
+
const fs = require('node:fs');
|
|
23
|
+
const { assertOpsWrite, resolveProjectRoot } = require('../opsOwnership.cjs');
|
|
24
|
+
const { writeJsonAtomic } = require('../util/atomicFs.cjs');
|
|
25
|
+
const { EPIC_ID_RE } = require('./planRecordHarvest.cjs');
|
|
26
|
+
|
|
27
|
+
const MAX_BODY_BYTES = 256 * 1024;
|
|
28
|
+
const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
29
|
+
|
|
30
|
+
const bodySchema = z.object({
|
|
31
|
+
cwd: z.string().min(1),
|
|
32
|
+
epicId: z.string(),
|
|
33
|
+
validateSlug: z.string(),
|
|
34
|
+
rejected: z.array(z.object({ finding: z.string(), reason: z.string() })).optional().default([]),
|
|
35
|
+
accepted: z.number().finite().min(0).optional().default(0),
|
|
36
|
+
rereview: z.boolean().optional(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** @param {any} record */
|
|
40
|
+
function latestHasBlock(record) {
|
|
41
|
+
const reviews = record && Array.isArray(record.reviews) ? record.reviews : [];
|
|
42
|
+
const last = reviews[reviews.length - 1];
|
|
43
|
+
const prds = last && last.review && Array.isArray(last.review.prds) ? last.review.prds : [];
|
|
44
|
+
return prds.some((/** @type {any} */ p) => p && p.decision === 'block');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {{ registerRoute: Function }} adminHttp */
|
|
48
|
+
function registerPlanReleaseRoute(adminHttp) {
|
|
49
|
+
adminHttp.registerRoute('POST', '/admin/scheduler/release-plan', async (/** @type {any} */ req, /** @type {any} */ res) => {
|
|
50
|
+
const bad = (/** @type {any} */ details) => sendJson(res, 400, { ok: false, error: 'invalid_request', details });
|
|
51
|
+
let raw;
|
|
52
|
+
try { raw = await readBody(req, MAX_BODY_BYTES); } catch (e) {
|
|
53
|
+
bad(e instanceof Error ? e.message : String(e));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let json;
|
|
57
|
+
try { json = JSON.parse(raw || '{}'); } catch { bad('body is not valid JSON'); return; }
|
|
58
|
+
const parsed = bodySchema.safeParse(json);
|
|
59
|
+
if (!parsed.success) { bad(parsed.error.issues); return; }
|
|
60
|
+
const { epicId, validateSlug, rejected, accepted, rereview } = parsed.data;
|
|
61
|
+
/** @type {string} */
|
|
62
|
+
let cwd;
|
|
63
|
+
try {
|
|
64
|
+
cwd = resolveProjectRoot(parsed.data.cwd, { opsInternal: 'refuse' });
|
|
65
|
+
if (!fs.statSync(cwd).isDirectory()) throw new Error('not a directory');
|
|
66
|
+
} catch {
|
|
67
|
+
sendJson(res, 400, { ok: false, error: 'bad_cwd' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!EPIC_ID_RE.test(epicId) || !SLUG_RE.test(validateSlug) || validateSlug.includes('..')) {
|
|
71
|
+
bad('unsafe epicId or validateSlug');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const prior = readPlanReview(cwd, epicId, validateSlug);
|
|
76
|
+
|
|
77
|
+
if (rereview) {
|
|
78
|
+
let reason = null;
|
|
79
|
+
if (!prior || !Array.isArray(prior.reviews) || prior.reviews.length === 0) reason = 'no review on record for this plan';
|
|
80
|
+
else if (prior.release) reason = 'the plan is already released';
|
|
81
|
+
else if (!latestHasBlock(prior)) reason = 'the latest review has no block decision';
|
|
82
|
+
else if (prior.round !== 1) reason = `a re-review is allowed once per plan; the plan is at round ${prior.round}`;
|
|
83
|
+
else if (prior.rereviewRequested) reason = 're-review was already requested';
|
|
84
|
+
if (reason) { sendJson(res, 400, { ok: false, error: 'rereview_refused', reason }); return; }
|
|
85
|
+
const file = planReviewPath(cwd, epicId, validateSlug);
|
|
86
|
+
assertOpsWrite(file, 'scheduler');
|
|
87
|
+
await writeJsonAtomic(file, { ...prior, rereviewRequested: true });
|
|
88
|
+
sendJson(res, 200, { ok: true, rereviewRequested: true });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const missing = rejected.findIndex((r) => !r.reason.trim());
|
|
93
|
+
if (missing !== -1) {
|
|
94
|
+
sendJson(res, 400, { ok: false, error: 'reason_required', reason: `rejected[${missing}] needs a non-empty one-line reason` });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const out = await recordPlanRelease({
|
|
98
|
+
cwd, epicId, validateSlug, by: 'planner',
|
|
99
|
+
rejected: rejected.map((r) => ({ finding: r.finding, reason: r.reason.trim() })),
|
|
100
|
+
accepted,
|
|
101
|
+
});
|
|
102
|
+
if (out && out.alreadyReleased) { sendJson(res, 200, { ok: true, alreadyReleased: true }); return; }
|
|
103
|
+
sendJson(res, 200, { ok: true, released: true, accepted, rejected: rejected.length });
|
|
104
|
+
} catch (e) {
|
|
105
|
+
sendJson(res, 500, { ok: false, error: 'release_failed', details: e instanceof Error ? e.message : String(e) });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { registerPlanReleaseRoute };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* planReviewSchema.cjs — the JSON Schema the plan-reviewer returns through
|
|
5
|
+
* `claude -p --json-schema`, a strict parser, and an allOk predicate.
|
|
6
|
+
* Mirrors validatorVerdictSchema.cjs: the CLI enforces the simple schema
|
|
7
|
+
* (enums + required); parsePlanReview adds the cross-field rules (PRD slugs
|
|
8
|
+
* match `expected`, amend|block needs findings, no unknown keys).
|
|
9
|
+
*
|
|
10
|
+
* Pure: no I/O, never throws, never mutates its input.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @typedef {'Critical'|'Important'|'Minor'} Severity */
|
|
14
|
+
/** @typedef {'ok'|'amend'|'block'} Decision */
|
|
15
|
+
/** @typedef {{ severity: Severity, check: string, text: string, suggestedEdit?: string, field?: string }} PrdFinding */
|
|
16
|
+
/** @typedef {{ prd: string, decision: Decision, findings: PrdFinding[] }} PrdReview */
|
|
17
|
+
/** @typedef {{ severity: Severity, check: string, text: string }} PlanFinding */
|
|
18
|
+
/** @typedef {{ prds: PrdReview[], planFindings: PlanFinding[] }} PlanReview */
|
|
19
|
+
/** @typedef {{ ok: true, value: PlanReview } | { ok: false, error: string }} ParseResult */
|
|
20
|
+
|
|
21
|
+
const PLAN_REVIEW_CHECKS = [
|
|
22
|
+
'provable-criterion',
|
|
23
|
+
'failure-path',
|
|
24
|
+
'edge-case',
|
|
25
|
+
'vacuous-by-sibling',
|
|
26
|
+
'depends-on',
|
|
27
|
+
'gate-green-at-base',
|
|
28
|
+
'http-criterion',
|
|
29
|
+
'doc-after-code',
|
|
30
|
+
];
|
|
31
|
+
const SEVERITIES = ['Critical', 'Important', 'Minor'];
|
|
32
|
+
const DECISIONS = ['ok', 'amend', 'block'];
|
|
33
|
+
|
|
34
|
+
const PLAN_REVIEW_SCHEMA = {
|
|
35
|
+
type: 'object',
|
|
36
|
+
required: ['prds', 'planFindings'],
|
|
37
|
+
properties: {
|
|
38
|
+
prds: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
items: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
required: ['prd', 'decision', 'findings'],
|
|
43
|
+
properties: {
|
|
44
|
+
prd: { type: 'string' },
|
|
45
|
+
decision: { type: 'string', enum: DECISIONS },
|
|
46
|
+
findings: {
|
|
47
|
+
type: 'array',
|
|
48
|
+
items: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
required: ['severity', 'check', 'text'],
|
|
51
|
+
properties: {
|
|
52
|
+
severity: { type: 'string', enum: SEVERITIES },
|
|
53
|
+
check: { type: 'string', enum: PLAN_REVIEW_CHECKS },
|
|
54
|
+
text: { type: 'string' },
|
|
55
|
+
suggestedEdit: { type: 'string' },
|
|
56
|
+
field: { type: 'string' },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
planFindings: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
items: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
required: ['severity', 'check', 'text'],
|
|
68
|
+
properties: {
|
|
69
|
+
severity: { type: 'string', enum: SEVERITIES },
|
|
70
|
+
check: { type: 'string', enum: PLAN_REVIEW_CHECKS },
|
|
71
|
+
text: { type: 'string' },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** @param {unknown} v @returns {v is Record<string, unknown>} */
|
|
79
|
+
function isPlainObject(v) {
|
|
80
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {Record<string, unknown>} obj
|
|
85
|
+
* @param {string[]} required
|
|
86
|
+
* @param {string[]} allowed
|
|
87
|
+
* @param {string} where
|
|
88
|
+
* @returns {string|null}
|
|
89
|
+
*/
|
|
90
|
+
function checkKeys(obj, required, allowed, where) {
|
|
91
|
+
for (const k of required) if (!(k in obj)) return `${where}: missing ${k}`;
|
|
92
|
+
for (const k of Object.keys(obj)) if (!allowed.includes(k)) return `${where}: unexpected key ${k}`;
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {unknown} f
|
|
98
|
+
* @param {string} where
|
|
99
|
+
* @param {boolean} prdLevel
|
|
100
|
+
* @returns {string|null}
|
|
101
|
+
*/
|
|
102
|
+
function checkFinding(f, where, prdLevel) {
|
|
103
|
+
if (!isPlainObject(f)) return `${where}: not an object`;
|
|
104
|
+
const keyErr = checkKeys(
|
|
105
|
+
f,
|
|
106
|
+
['severity', 'check', 'text'],
|
|
107
|
+
prdLevel ? ['severity', 'check', 'text', 'suggestedEdit', 'field'] : ['severity', 'check', 'text'],
|
|
108
|
+
where,
|
|
109
|
+
);
|
|
110
|
+
if (keyErr) return keyErr;
|
|
111
|
+
if (!SEVERITIES.includes(/** @type {string} */ (f.severity))) return `${where}.severity: not one of ${SEVERITIES.join(', ')}`;
|
|
112
|
+
if (!PLAN_REVIEW_CHECKS.includes(/** @type {string} */ (f.check))) return `${where}.check: unknown check ${String(f.check)}`;
|
|
113
|
+
if (typeof f.text !== 'string') return `${where}.text: not a string`;
|
|
114
|
+
if (f.suggestedEdit !== undefined && typeof f.suggestedEdit !== 'string') return `${where}.suggestedEdit: not a string`;
|
|
115
|
+
if (f.field !== undefined && typeof f.field !== 'string') return `${where}.field: not a string`;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* parsePlanReview(value, { expected }) → { ok, value | error }.
|
|
121
|
+
* `expected` is the list (array or Set) of PRD slugs the review must cover
|
|
122
|
+
* exactly: none missing, none extra, none duplicated.
|
|
123
|
+
* @param {unknown} value
|
|
124
|
+
* @param {{ expected?: Iterable<string>|null }} [opts]
|
|
125
|
+
* @returns {ParseResult}
|
|
126
|
+
*/
|
|
127
|
+
function parsePlanReview(value, opts = {}) {
|
|
128
|
+
try {
|
|
129
|
+
if (!isPlainObject(value)) return { ok: false, error: 'review: not an object' };
|
|
130
|
+
const keyErr = checkKeys(value, ['prds', 'planFindings'], ['prds', 'planFindings'], 'review');
|
|
131
|
+
if (keyErr) return { ok: false, error: keyErr };
|
|
132
|
+
if (!Array.isArray(value.prds)) return { ok: false, error: 'prds: not an array' };
|
|
133
|
+
if (!Array.isArray(value.planFindings)) return { ok: false, error: 'planFindings: not an array' };
|
|
134
|
+
/** @type {Set<string>} */
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
for (let i = 0; i < value.prds.length; i++) {
|
|
137
|
+
const where = `prds[${i}]`;
|
|
138
|
+
const p = value.prds[i];
|
|
139
|
+
if (!isPlainObject(p)) return { ok: false, error: `${where}: not an object` };
|
|
140
|
+
const pe = checkKeys(p, ['prd', 'decision', 'findings'], ['prd', 'decision', 'findings'], where);
|
|
141
|
+
if (pe) return { ok: false, error: pe };
|
|
142
|
+
if (typeof p.prd !== 'string' || !p.prd) return { ok: false, error: `${where}.prd: not a non-empty string` };
|
|
143
|
+
if (seen.has(p.prd)) return { ok: false, error: `${where}.prd: duplicate ${p.prd}` };
|
|
144
|
+
seen.add(p.prd);
|
|
145
|
+
if (!DECISIONS.includes(/** @type {string} */ (p.decision))) {
|
|
146
|
+
return { ok: false, error: `${where}.decision: not one of ${DECISIONS.join(', ')}` };
|
|
147
|
+
}
|
|
148
|
+
if (!Array.isArray(p.findings)) return { ok: false, error: `${where}.findings: not an array` };
|
|
149
|
+
for (let j = 0; j < p.findings.length; j++) {
|
|
150
|
+
const err = checkFinding(p.findings[j], `${where}.findings[${j}]`, true);
|
|
151
|
+
if (err) return { ok: false, error: err };
|
|
152
|
+
}
|
|
153
|
+
if (p.decision !== 'ok' && p.findings.length === 0) {
|
|
154
|
+
return { ok: false, error: `${where}: decision ${p.decision} needs at least one finding` };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (let i = 0; i < value.planFindings.length; i++) {
|
|
158
|
+
const err = checkFinding(value.planFindings[i], `planFindings[${i}]`, false);
|
|
159
|
+
if (err) return { ok: false, error: err };
|
|
160
|
+
}
|
|
161
|
+
if (opts && opts.expected) {
|
|
162
|
+
const exp = new Set(opts.expected);
|
|
163
|
+
for (const slug of exp) if (!seen.has(slug)) return { ok: false, error: `prds: missing ${slug}` };
|
|
164
|
+
for (const slug of seen) if (!exp.has(slug)) return { ok: false, error: `prds: unexpected ${slug}` };
|
|
165
|
+
}
|
|
166
|
+
return { ok: true, value: /** @type {PlanReview} */ (/** @type {unknown} */ (value)) };
|
|
167
|
+
} catch (err) {
|
|
168
|
+
return { ok: false, error: `review: ${err instanceof Error ? err.message : String(err)}` };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* True only when every PRD decision is ok and planFindings is empty.
|
|
174
|
+
* @param {PlanReview} review
|
|
175
|
+
* @returns {boolean}
|
|
176
|
+
*/
|
|
177
|
+
function isAllOk(review) {
|
|
178
|
+
if (!review || !Array.isArray(review.prds) || !Array.isArray(review.planFindings)) return false;
|
|
179
|
+
return review.planFindings.length === 0 && review.prds.every((p) => p && p.decision === 'ok');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = { PLAN_REVIEW_SCHEMA, PLAN_REVIEW_CHECKS, parsePlanReview, isAllOk };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* planReviewStats.cjs — pure aggregate comparing an Epic's reviewed plans (a
|
|
5
|
+
* stored plan-review record with a release) against its unreviewed ones, on
|
|
6
|
+
* review findings accepted/rejected, validator findings, REFUTED verdicts and
|
|
7
|
+
* fixes[] escapes (missKind spec-gap | missing-test).
|
|
8
|
+
*
|
|
9
|
+
* A plan is a validate slug. A PRD belongs to a reviewed plan when it appears
|
|
10
|
+
* in that record's reviews[].review.prds[].prd (bare slug). Every other verdict
|
|
11
|
+
* or fix is unreviewed; unreviewed `plans` counts the distinct `validator` slugs (else `plan`) a
|
|
12
|
+
* verdict entry carries; a record with no stored review or a timeout release is not reviewed (entries with none add to the totals only).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const ESCAPE_KINDS = new Set(['spec-gap', 'missing-test']);
|
|
16
|
+
const isObj = (v) => v != null && typeof v === 'object' && !Array.isArray(v);
|
|
17
|
+
const bare = (s) => String(s).replace(/^\d+-/, '');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {{ planReviews?: any[], verdictFiles?: any[], fixes?: any[] }} [input]
|
|
21
|
+
*/
|
|
22
|
+
function planReviewStats({ planReviews, verdictFiles, fixes } = {}) {
|
|
23
|
+
const reviewed = { plans: 0, acceptedFindings: 0, rejectedFindings: 0, validatorFindings: 0, refuted: 0, escapes: 0 };
|
|
24
|
+
const unreviewed = { plans: 0, validatorFindings: 0, refuted: 0, escapes: 0 };
|
|
25
|
+
const member = new Map(); // bare prd slug -> validateSlug of a reviewed plan
|
|
26
|
+
|
|
27
|
+
for (const rec of Array.isArray(planReviews) ? planReviews : []) {
|
|
28
|
+
if (!isObj(rec) || !isObj(rec.release)) continue;
|
|
29
|
+
if (!Array.isArray(rec.reviews) || rec.reviews.length === 0) continue;
|
|
30
|
+
if (rec.release.by === 'timeout') continue;
|
|
31
|
+
reviewed.plans += 1;
|
|
32
|
+
const acc = rec.release.accepted;
|
|
33
|
+
if (Number.isFinite(acc)) reviewed.acceptedFindings += acc;
|
|
34
|
+
if (Array.isArray(rec.release.rejected)) reviewed.rejectedFindings += rec.release.rejected.length;
|
|
35
|
+
for (const r of Array.isArray(rec.reviews) ? rec.reviews : []) {
|
|
36
|
+
const prds = isObj(r) && isObj(r.review) && Array.isArray(r.review.prds) ? r.review.prds : [];
|
|
37
|
+
for (const p of prds) if (isObj(p) && typeof p.prd === 'string') member.set(bare(p.prd), rec.validateSlug);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const unreviewedPlanKeys = new Set();
|
|
42
|
+
for (const v of Array.isArray(verdictFiles) ? verdictFiles : []) {
|
|
43
|
+
if (!isObj(v) || typeof v.prd !== 'string') continue;
|
|
44
|
+
const target = member.has(bare(v.prd)) ? reviewed : unreviewed;
|
|
45
|
+
if (target === unreviewed) {
|
|
46
|
+
const raw = typeof v.validator === 'string' && v.validator ? v.validator : v.plan;
|
|
47
|
+
const key = typeof raw === 'string' && raw ? bare(raw) : null;
|
|
48
|
+
if (key) unreviewedPlanKeys.add(key);
|
|
49
|
+
}
|
|
50
|
+
target.validatorFindings += Array.isArray(v.findings) ? v.findings.length : 0;
|
|
51
|
+
if (v.verdict === 'REFUTED') target.refuted += 1;
|
|
52
|
+
}
|
|
53
|
+
unreviewed.plans = unreviewedPlanKeys.size;
|
|
54
|
+
|
|
55
|
+
for (const f of Array.isArray(fixes) ? fixes : []) {
|
|
56
|
+
if (!isObj(f) || typeof f.prd !== 'string' || !ESCAPE_KINDS.has(f.missKind)) continue;
|
|
57
|
+
(member.has(bare(f.prd)) ? reviewed : unreviewed).escapes += 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { reviewed, unreviewed };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { planReviewStats };
|