claude-code-session-manager 0.141.0 → 0.142.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 +80 -70
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-DDunb8Ch.js} +1 -1
- package/dist/assets/index-Cn5E9958.js +3133 -0
- package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +496 -484
- package/package.json +4 -2
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/hooks/hooks.json +15 -0
- package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +52 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +1 -0
- package/scripts/hooks/guard-tool-risk.cjs +5 -1
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
- package/scripts/scheduler-mcp-server.cjs +732 -110
- package/src/main/adminRouteRegistry.cjs +59 -0
- package/src/main/agentLibrary.cjs +72 -4
- package/src/main/agentsIpc.cjs +3 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +231 -16
- package/src/main/config.cjs +30 -0
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +91 -0
- package/src/main/index.cjs +98 -48
- package/src/main/ipcSchemas.cjs +161 -8
- package/src/main/lib/AGENTS.md +1 -1
- package/src/main/lib/chatBootRecovery.cjs +2 -0
- package/src/main/lib/claude/agentModelResolve.cjs +51 -25
- package/src/main/lib/claude/agentSnapshot.cjs +186 -0
- package/src/main/lib/claude/environmentProfiles.cjs +242 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
- package/src/main/lib/claude/personaToolScope.cjs +82 -31
- package/src/main/lib/claude/runClaudeP.cjs +4 -2
- package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
- package/src/main/lib/claude/usageCircuit.cjs +49 -21
- package/src/main/lib/claude/vaultRefs.cjs +277 -0
- package/src/main/lib/demo-video-kit/capture.cjs +282 -12
- package/src/main/lib/demo-video-kit/cast.md +43 -0
- package/src/main/lib/demo-video-kit/character.cjs +722 -30
- package/src/main/lib/demo-video-kit/checks.cjs +120 -1
- package/src/main/lib/demo-video-kit/export.cjs +218 -0
- package/src/main/lib/demo-video-kit/frames.cjs +104 -9
- package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
- package/src/main/lib/demo-video-kit/kind-tiktok.md +99 -0
- package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
- package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
- package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
- package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
- package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
- package/src/main/lib/epic/artifactIpc.cjs +153 -0
- package/src/main/lib/epic/artifactNotice.cjs +72 -0
- package/src/main/lib/epic/artifactRetention.cjs +310 -0
- package/src/main/lib/epic/artifactStore.cjs +392 -0
- package/src/main/lib/epic/delegationReadiness.cjs +76 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +214 -0
- package/src/main/lib/epic/epicMint.cjs +43 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
- package/src/main/lib/epic/epicOutsideState.cjs +18 -4
- package/src/main/lib/epic/epicPurge.cjs +347 -0
- package/src/main/lib/epic/epicReopen.cjs +5 -2
- package/src/main/lib/epic/epicSettle.cjs +4 -13
- package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
- package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +81 -2
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +37 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
- package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
- package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
- package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
- package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
- package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
- package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
- package/src/main/lib/feedback-remote/pendingReplies.cjs +189 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
- package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
- package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
- package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
- package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
- package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
- package/src/main/lib/git/worktreeDeps.cjs +77 -2
- package/src/main/lib/mcpToolCatalog.cjs +304 -28
- package/src/main/lib/opsOwnership.cjs +29 -1
- package/src/main/lib/opsRetentionSettings.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
- package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +263 -0
- package/src/main/lib/phaseProjection.cjs +103 -0
- package/src/main/lib/prd/depSlugResolve.cjs +4 -13
- package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
- package/src/main/lib/prd/prdCreate.cjs +41 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
- package/src/main/lib/prd/prdGateFiles.cjs +125 -49
- package/src/main/lib/prd/prdSizing.cjs +3 -1
- package/src/main/lib/process/cleanEnv.cjs +52 -1
- package/src/main/lib/process/leftoverRenice.cjs +178 -0
- package/src/main/lib/process/memoryScope.cjs +31 -3
- package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
- package/src/main/lib/project-pages/voicePreview.cjs +196 -0
- package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
- package/src/main/lib/scheduler/cpuSample.cjs +133 -42
- package/src/main/lib/scheduler/criteriaChecks.cjs +169 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
- package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +0 -3
- package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
- package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
- package/src/main/lib/scheduler/slotsRoute.cjs +237 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
- package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
- package/src/main/lib/tasks/mitigationReview.cjs +294 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
- package/src/main/lib/tasks/taskIpc.cjs +22 -18
- package/src/main/lib/tasks/taskLedger.cjs +147 -25
- package/src/main/lib/tasks/taskRun.cjs +186 -17
- package/src/main/lib/tasks/taskSwitch.cjs +85 -12
- package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
- package/src/main/lib/telemetry/auditEvents.cjs +207 -6
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
- package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
- package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
- package/src/main/lib/toolUseClassify.cjs +181 -0
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +5 -0
- package/src/main/pty.cjs +68 -0
- package/src/main/queueOps.cjs +32 -13
- package/src/main/runVerify.cjs +74 -9
- package/src/main/scheduler/AGENTS.md +1 -0
- package/src/main/scheduler/budget.cjs +6 -5
- package/src/main/scheduler/prdParser.cjs +46 -13
- package/src/main/scheduler/reviewLadder.cjs +9 -25
- package/src/main/scheduler/utilizationHold.cjs +101 -0
- package/src/main/scheduler.cjs +1414 -189
- package/src/main/templates/PRD_AUTHORING.md +5 -2
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +529 -38
- package/src/preload/apiSurface.json +209 -7
- package/src/preload/index.cjs +46 -1
- package/src/seed/agents/architect.md +6 -1
- package/src/seed/agents/blender-artist.md +2 -1
- package/src/seed/agents/competitive-analyst.md +3 -1
- package/src/seed/agents/competitive-researcher.md +2 -1
- package/src/seed/agents/demo-video-builder.md +87 -83
- package/src/seed/agents/dev-lead.md +3 -3
- package/src/seed/agents/project-home-builder.md +9 -31
- package/src/seed/agents/validator.md +9 -10
- package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
- package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
- package/dist/assets/Scheduler-cyr61UAC.js +0 -16
- package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
- package/dist/assets/index-B2TQz3nd.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -18,6 +18,15 @@
|
|
|
18
18
|
* processes — they carry no `--type=` flag — so they stay in the net figure.
|
|
19
19
|
* /proc/stat and /proc/<pid>/stat are both in USER_HZ clock ticks, so the
|
|
20
20
|
* deltas subtract directly. Off Linux the own reading is null and net = raw.
|
|
21
|
+
*
|
|
22
|
+
* Idle-priority exclusion (PRD 4021): 2026-11-23 6:20 PM PST the gate held all
|
|
23
|
+
* 163 pending jobs with 0 running while two local voice renders used ~13.5 of
|
|
24
|
+
* 14 cores; one ran at nice 19. A nice-19 process yields to anything at a
|
|
25
|
+
* higher priority, jobs included, so it is not load the gate should defend.
|
|
26
|
+
* The same bounded /proc scan that finds the own tree also collects every
|
|
27
|
+
* process at nice 19 (field 19 of /proc/<pid>/stat) that is not an own
|
|
28
|
+
* process; its ticks are subtracted from the net figure and reported as
|
|
29
|
+
* idleNiceShare. Nice 12 and below still count as busy.
|
|
21
30
|
*/
|
|
22
31
|
|
|
23
32
|
const fs = require('node:fs');
|
|
@@ -30,6 +39,12 @@ const DEFAULT_WINDOW_MS = 60_000;
|
|
|
30
39
|
const MIN_WINDOW_MS = 20_000;
|
|
31
40
|
const MAX_WINDOW_MS = 180_000;
|
|
32
41
|
const MIN_SPACING_MS = 5_000;
|
|
42
|
+
// One /proc scan reads at most this many pids, so a pid-storm host cannot turn
|
|
43
|
+
// a sample into thousands of file reads every tick.
|
|
44
|
+
const MAX_PROC_SCAN = 4096;
|
|
45
|
+
// The lowest scheduling priority Linux offers: such a process only gets CPU
|
|
46
|
+
// time no one else wants.
|
|
47
|
+
const IDLE_NICE = 19;
|
|
33
48
|
|
|
34
49
|
/**
|
|
35
50
|
* Parse the aggregate `cpu ` line of /proc/stat into { busy, iowait, total }.
|
|
@@ -91,24 +106,36 @@ function readCpuTimes({
|
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
/**
|
|
94
|
-
* Parse one /proc/<pid>/stat line → { pid, ppid, ticks: utime+stime }.
|
|
109
|
+
* Parse one /proc/<pid>/stat line → { pid, ppid, ticks: utime+stime, nice }.
|
|
95
110
|
* comm (field 2) may contain spaces and parens, so split after the LAST ')'.
|
|
111
|
+
* nice is null when the line is too short to carry field 19.
|
|
96
112
|
* @param {string} text
|
|
97
|
-
* @returns {{ pid: number, ppid: number, ticks: number } | null}
|
|
113
|
+
* @returns {{ pid: number, ppid: number, ticks: number, nice: number | null } | null}
|
|
98
114
|
*/
|
|
99
|
-
function
|
|
115
|
+
function parsePidStatFields(text) {
|
|
100
116
|
if (typeof text !== 'string' || !text) return null;
|
|
101
117
|
const close = text.lastIndexOf(')');
|
|
102
118
|
const open = text.indexOf('(');
|
|
103
119
|
if (close < 0 || open < 0) return null;
|
|
104
120
|
const pid = Number(text.slice(0, open).trim());
|
|
105
|
-
// After ')': state(3) ppid(4) ... utime(14) stime(15) → indices 0,1,...,11,12.
|
|
121
|
+
// After ')': state(3) ppid(4) ... utime(14) stime(15) ... nice(19) → indices 0,1,...,11,12,...,16.
|
|
106
122
|
const rest = text.slice(close + 1).trim().split(/\s+/);
|
|
107
123
|
const ppid = Number(rest[1]);
|
|
108
124
|
const utime = Number(rest[11]);
|
|
109
125
|
const stime = Number(rest[12]);
|
|
110
126
|
if (![pid, ppid, utime, stime].every(Number.isFinite)) return null;
|
|
111
|
-
|
|
127
|
+
const nice = rest.length > 16 && rest[16] !== '' ? Number(rest[16]) : NaN;
|
|
128
|
+
return { pid, ppid, ticks: utime + stime, nice: Number.isFinite(nice) ? nice : null };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Parse one /proc/<pid>/stat line → { pid, ppid, ticks: utime+stime }.
|
|
133
|
+
* @param {string} text
|
|
134
|
+
* @returns {{ pid: number, ppid: number, ticks: number } | null}
|
|
135
|
+
*/
|
|
136
|
+
function parsePidStat(text) {
|
|
137
|
+
const f = parsePidStatFields(text);
|
|
138
|
+
return f ? { pid: f.pid, ppid: f.ppid, ticks: f.ticks } : null;
|
|
112
139
|
}
|
|
113
140
|
|
|
114
141
|
/**
|
|
@@ -123,63 +150,87 @@ function isElectronHelperCmdline(cmd) {
|
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
153
|
+
* One bounded /proc scan (at most maxPids pids) → { own, idleNice }.
|
|
154
|
+
* - own: the app's own process tree as Map<pid, cumulative utime+stime ticks>:
|
|
155
|
+
* the root (Electron main) plus every descendant reached only through
|
|
156
|
+
* processes whose cmdline carries an Electron `--type=` flag. A helper must
|
|
157
|
+
* also run the same executable as the root (when /proc/<pid>/exe is
|
|
158
|
+
* readable), so a job whose prompt text happens to contain "--type=" never
|
|
159
|
+
* counts as own. null when the root is not in the scan.
|
|
160
|
+
* - idleNice: Map<pid, ticks> of every process at nice 19 that is not own
|
|
161
|
+
* (own ticks are already subtracted, so they never count twice).
|
|
162
|
+
* Linux only; both null elsewhere or when /proc cannot be listed. Never throws.
|
|
133
163
|
* @param {{ rootPid?: number, platform?: string, readdir?: (p: string) => string[],
|
|
134
|
-
* readFile?: (p: string) => string, readlink?: (p: string) => string }} [deps]
|
|
135
|
-
* @returns {Map<number, number> | null}
|
|
164
|
+
* readFile?: (p: string) => string, readlink?: (p: string) => string, maxPids?: number }} [deps]
|
|
165
|
+
* @returns {{ own: Map<number, number> | null, idleNice: Map<number, number> | null }}
|
|
136
166
|
*/
|
|
137
|
-
function
|
|
167
|
+
function readProcessTicks({
|
|
138
168
|
rootPid = process.pid,
|
|
139
169
|
platform = process.platform,
|
|
140
170
|
readdir = (p) => fs.readdirSync(p),
|
|
141
171
|
readFile = (p) => fs.readFileSync(p, 'utf8'),
|
|
142
172
|
readlink = (p) => fs.readlinkSync(p),
|
|
173
|
+
maxPids = MAX_PROC_SCAN,
|
|
143
174
|
} = {}) {
|
|
144
|
-
if (platform !== 'linux') return null;
|
|
175
|
+
if (platform !== 'linux') return { own: null, idleNice: null };
|
|
145
176
|
try {
|
|
146
|
-
/** @type {Map<number, { ppid: number, ticks: number }>} */
|
|
177
|
+
/** @type {Map<number, { ppid: number, ticks: number, nice: number | null }>} */
|
|
147
178
|
const procs = new Map();
|
|
148
179
|
/** @type {Map<number, number[]>} */
|
|
149
180
|
const children = new Map();
|
|
181
|
+
let scanned = 0;
|
|
150
182
|
for (const name of readdir('/proc')) {
|
|
151
183
|
if (!/^\d+$/.test(name)) continue;
|
|
184
|
+
if (scanned >= maxPids) break;
|
|
185
|
+
scanned += 1;
|
|
152
186
|
let st;
|
|
153
|
-
try { st =
|
|
187
|
+
try { st = parsePidStatFields(readFile(`/proc/${name}/stat`)); } catch { continue; }
|
|
154
188
|
if (!st) continue;
|
|
155
|
-
procs.set(st.pid, { ppid: st.ppid, ticks: st.ticks });
|
|
189
|
+
procs.set(st.pid, { ppid: st.ppid, ticks: st.ticks, nice: st.nice });
|
|
156
190
|
const list = children.get(st.ppid);
|
|
157
191
|
if (list) list.push(st.pid); else children.set(st.ppid, [st.pid]);
|
|
158
192
|
}
|
|
193
|
+
/** @type {Map<number, number> | null} */
|
|
194
|
+
let own = null;
|
|
159
195
|
const root = procs.get(rootPid);
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
196
|
+
if (root) {
|
|
197
|
+
const exeOf = (/** @type {number} */ pid) => { try { return readlink(`/proc/${pid}/exe`); } catch { return null; } };
|
|
198
|
+
const rootExe = exeOf(rootPid);
|
|
199
|
+
own = new Map([[rootPid, root.ticks]]);
|
|
200
|
+
const queue = [rootPid];
|
|
201
|
+
while (queue.length) {
|
|
202
|
+
const parent = /** @type {number} */ (queue.shift());
|
|
203
|
+
for (const child of children.get(parent) || []) {
|
|
204
|
+
let cmd = '';
|
|
205
|
+
try { cmd = readFile(`/proc/${child}/cmdline`); } catch { continue; }
|
|
206
|
+
if (!isElectronHelperCmdline(cmd)) continue;
|
|
207
|
+
if (rootExe !== null && exeOf(child) !== rootExe) continue;
|
|
208
|
+
own.set(child, /** @type {{ticks:number}} */ (procs.get(child)).ticks);
|
|
209
|
+
queue.push(child);
|
|
210
|
+
}
|
|
175
211
|
}
|
|
176
212
|
}
|
|
177
|
-
|
|
213
|
+
/** @type {Map<number, number>} */
|
|
214
|
+
const idleNice = new Map();
|
|
215
|
+
for (const [pid, p] of procs) {
|
|
216
|
+
if (p.nice === IDLE_NICE && !(own && own.has(pid))) idleNice.set(pid, p.ticks);
|
|
217
|
+
}
|
|
218
|
+
return { own, idleNice };
|
|
178
219
|
} catch {
|
|
179
|
-
return null;
|
|
220
|
+
return { own: null, idleNice: null };
|
|
180
221
|
}
|
|
181
222
|
}
|
|
182
223
|
|
|
224
|
+
/**
|
|
225
|
+
* The app's own process tree (see readProcessTicks). Linux only; null
|
|
226
|
+
* elsewhere, when /proc cannot be listed, or when the root is not found.
|
|
227
|
+
* @param {Parameters<typeof readProcessTicks>[0]} [deps]
|
|
228
|
+
* @returns {Map<number, number> | null}
|
|
229
|
+
*/
|
|
230
|
+
function readOwnProcessTicks(deps) {
|
|
231
|
+
return readProcessTicks(deps).own;
|
|
232
|
+
}
|
|
233
|
+
|
|
183
234
|
/**
|
|
184
235
|
* Own-process ticks consumed between two readings. A pid only in `before`
|
|
185
236
|
* exited (its last ticks are lost, count 0); a pid only in `after` started in
|
|
@@ -199,20 +250,49 @@ function ownTicksDelta(before, after) {
|
|
|
199
250
|
}
|
|
200
251
|
|
|
201
252
|
/**
|
|
253
|
+
* Nice-19 ticks consumed between two readings, counting only pids at nice 19
|
|
254
|
+
* in BOTH. Unlike own processes, a pid absent from `before` may have run the
|
|
255
|
+
* whole window at a higher priority and only now been reniced (its cumulative
|
|
256
|
+
* ticks would then wipe out real load), so it waits for the next window. Erring
|
|
257
|
+
* that way keeps the gate holding rather than launching onto a busy CPU.
|
|
258
|
+
* @param {Map<number, number> | null} before
|
|
259
|
+
* @param {Map<number, number> | null} after
|
|
260
|
+
* @returns {number | null}
|
|
261
|
+
*/
|
|
262
|
+
function idleNiceTicksDelta(before, after) {
|
|
263
|
+
if (!before || !after) return null;
|
|
264
|
+
let d = 0;
|
|
265
|
+
for (const [pid, ticks] of after) {
|
|
266
|
+
const prev = before.get(pid);
|
|
267
|
+
if (prev !== undefined) d += Math.max(0, ticks - prev);
|
|
268
|
+
}
|
|
269
|
+
return d;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* `readProcs` returns { own, idleNice } from one /proc scan (default
|
|
274
|
+
* readProcessTicks). Injecting `readOwn` and/or `readIdleNice` instead builds
|
|
275
|
+
* it from those (a missing one reads null).
|
|
202
276
|
* @param {{ read?: () => ({busy:number,iowait?:number,total:number}|null),
|
|
203
|
-
*
|
|
277
|
+
* readProcs?: () => ({ own: Map<number, number>|null, idleNice: Map<number, number>|null }),
|
|
278
|
+
* readOwn?: () => (Map<number, number>|null), readIdleNice?: () => (Map<number, number>|null),
|
|
279
|
+
* now?: () => number,
|
|
204
280
|
* windowMs?: number, minWindowMs?: number, maxWindowMs?: number, minSpacingMs?: number }} [opts]
|
|
205
281
|
*/
|
|
206
282
|
function createCpuSampler({
|
|
207
283
|
read = readCpuTimes,
|
|
208
|
-
readOwn
|
|
284
|
+
readOwn,
|
|
285
|
+
readIdleNice,
|
|
286
|
+
readProcs = (readOwn || readIdleNice)
|
|
287
|
+
? () => ({ own: readOwn ? readOwn() : null, idleNice: readIdleNice ? readIdleNice() : null })
|
|
288
|
+
: () => readProcessTicks(),
|
|
209
289
|
now = () => Date.now(),
|
|
210
290
|
windowMs = DEFAULT_WINDOW_MS,
|
|
211
291
|
minWindowMs = MIN_WINDOW_MS,
|
|
212
292
|
maxWindowMs = MAX_WINDOW_MS,
|
|
213
293
|
minSpacingMs = MIN_SPACING_MS,
|
|
214
294
|
} = {}) {
|
|
215
|
-
/** @type {{ at: number, busy: number, iowait: number, total: number, own: Map<number, number> | null }[]} */
|
|
295
|
+
/** @type {{ at: number, busy: number, iowait: number, total: number, own: Map<number, number> | null, idleNice: Map<number, number> | null }[]} */
|
|
216
296
|
let entries = [];
|
|
217
297
|
|
|
218
298
|
function observe() {
|
|
@@ -221,7 +301,8 @@ function createCpuSampler({
|
|
|
221
301
|
if (!r) return;
|
|
222
302
|
const newest = entries[entries.length - 1];
|
|
223
303
|
if (newest && t - newest.at < minSpacingMs) return;
|
|
224
|
-
|
|
304
|
+
const p = readProcs() || { own: null, idleNice: null };
|
|
305
|
+
entries.push({ at: t, busy: r.busy, iowait: r.iowait ?? 0, total: r.total, own: p.own ?? null, idleNice: p.idleNice ?? null });
|
|
225
306
|
entries = entries.filter((e) => t - e.at <= maxWindowMs);
|
|
226
307
|
}
|
|
227
308
|
|
|
@@ -246,12 +327,17 @@ function createCpuSampler({
|
|
|
246
327
|
const dIowait = (r.iowait ?? 0) - best.iowait;
|
|
247
328
|
// Per-CPU idle and iowait counters can step backwards.
|
|
248
329
|
if (dTotal <= 0 || dBusy < 0) return null;
|
|
249
|
-
const
|
|
330
|
+
const p = readProcs() || { own: null, idleNice: null };
|
|
331
|
+
const dOwnRaw = ownTicksDelta(best.own, p.own ?? null);
|
|
250
332
|
const dOwn = dOwnRaw === null ? null : Math.min(dBusy, dOwnRaw);
|
|
333
|
+
// Clamped so net never drops below 0.
|
|
334
|
+
const dIdleRaw = idleNiceTicksDelta(best.idleNice, p.idleNice ?? null);
|
|
335
|
+
const dIdle = dIdleRaw === null ? null : Math.min(dBusy - (dOwn ?? 0), dIdleRaw);
|
|
251
336
|
return {
|
|
252
337
|
busyFraction: Math.min(1, dBusy / dTotal),
|
|
253
338
|
ownFraction: dOwn === null ? null : dOwn / dTotal,
|
|
254
|
-
|
|
339
|
+
idleNiceShare: dIdle === null ? null : dIdle / dTotal,
|
|
340
|
+
netBusyFraction: Math.min(1, (dBusy - (dOwn ?? 0) - (dIdle ?? 0)) / dTotal),
|
|
255
341
|
iowaitFraction: Math.min(1, Math.max(0, dIowait / dTotal)),
|
|
256
342
|
windowMs: t - best.at,
|
|
257
343
|
};
|
|
@@ -263,12 +349,17 @@ function createCpuSampler({
|
|
|
263
349
|
module.exports = {
|
|
264
350
|
parseProcStat,
|
|
265
351
|
parsePidStat,
|
|
352
|
+
parsePidStatFields,
|
|
353
|
+
readProcessTicks,
|
|
266
354
|
readOwnProcessTicks,
|
|
267
355
|
ownTicksDelta,
|
|
356
|
+
idleNiceTicksDelta,
|
|
268
357
|
readCpuTimes,
|
|
269
358
|
createCpuSampler,
|
|
270
359
|
DEFAULT_WINDOW_MS,
|
|
271
360
|
MIN_WINDOW_MS,
|
|
272
361
|
MAX_WINDOW_MS,
|
|
273
362
|
MIN_SPACING_MS,
|
|
363
|
+
MAX_PROC_SCAN,
|
|
364
|
+
IDLE_NICE,
|
|
274
365
|
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* criteriaChecks.cjs — run each structured acceptance criterion's mechanical
|
|
5
|
+
* check (prdCriteria.cjs shape) in a job's tree, so the outcome record and
|
|
6
|
+
* the validator get observed results instead of the job's own prose.
|
|
7
|
+
*
|
|
8
|
+
* - command: parsed with the gate's no-shell parser (parseChain) and run
|
|
9
|
+
* through the gate's own runner (runIsolatedSequence: own TMPDIR, CI=1,
|
|
10
|
+
* no shell). The whole chain is capped at COMMAND_CAP_MS.
|
|
11
|
+
* - file: repo-relative path must exist (and contain `contains`, if set);
|
|
12
|
+
* a path that escapes `cwd` fails closed.
|
|
13
|
+
* - http: loopback hosts only (re-checked here, never trusted from the
|
|
14
|
+
* frontmatter), no redirects followed, HTTP_TIMEOUT_MS timeout; ok when
|
|
15
|
+
* the response status equals the expected one (default 200).
|
|
16
|
+
* - manual: never run — ok: null; detail carries the guidance line.
|
|
17
|
+
*
|
|
18
|
+
* Never throws: every failure becomes { ok: false, detail }. Checks run
|
|
19
|
+
* sequentially — one command at a time, like the gate.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const fs = require('node:fs');
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const http = require('node:http');
|
|
25
|
+
const https = require('node:https');
|
|
26
|
+
const { parseChain, runIsolatedSequence } = require('./definitionOfDone.cjs');
|
|
27
|
+
|
|
28
|
+
const COMMAND_CAP_MS = 300_000;
|
|
29
|
+
const HTTP_TIMEOUT_MS = 15_000;
|
|
30
|
+
const FILE_READ_MAX_BYTES = 16 * 1024 * 1024;
|
|
31
|
+
const DETAIL_MAX_CHARS = 500;
|
|
32
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
|
33
|
+
|
|
34
|
+
/** @param {string} s */
|
|
35
|
+
function clip(s) {
|
|
36
|
+
const t = String(s ?? '').trim();
|
|
37
|
+
return t.length > DETAIL_MAX_CHARS ? `…${t.slice(-DETAIL_MAX_CHARS)}` : t;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {unknown} spec
|
|
42
|
+
* @param {number} capMs
|
|
43
|
+
* @param {string} cwd
|
|
44
|
+
* @returns {Promise<{ok: boolean, detail: string}>}
|
|
45
|
+
*/
|
|
46
|
+
async function runCommandCheck(spec, capMs, cwd) {
|
|
47
|
+
if (typeof spec !== 'string' || !spec.trim()) return { ok: false, detail: 'command check has no command' };
|
|
48
|
+
const steps = parseChain(spec.trim());
|
|
49
|
+
if (!steps.length) return { ok: false, detail: 'command cannot run without a shell (refused by the gate parser)' };
|
|
50
|
+
const deadline = Date.now() + capMs;
|
|
51
|
+
for (const step of steps) {
|
|
52
|
+
const remaining = deadline - Date.now();
|
|
53
|
+
if (remaining <= 0) return { ok: false, detail: `timed out after ${capMs} ms cap` };
|
|
54
|
+
const timeoutMs = Math.min(step.timeoutMs, remaining);
|
|
55
|
+
const r = await runIsolatedSequence([{ ...step, timeoutMs }], { cwd });
|
|
56
|
+
const res = r.results[0];
|
|
57
|
+
if (r.status === 'green') continue;
|
|
58
|
+
if (res && res.timedOut) return { ok: false, detail: `timed out after ${timeoutMs} ms: ${res.cmd}` };
|
|
59
|
+
if (r.status === 'unavailable') return { ok: false, detail: `could not run: ${res ? res.cmd : step.argv.join(' ')}` };
|
|
60
|
+
return { ok: false, detail: clip(`exit ${res ? res.code : '?'}: ${res ? res.cmd : ''}\n${res ? res.tail : ''}`) };
|
|
61
|
+
}
|
|
62
|
+
return { ok: true, detail: `exit 0 (${steps.length} step${steps.length === 1 ? '' : 's'})` };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {unknown} spec
|
|
67
|
+
* @param {string} cwd
|
|
68
|
+
* @returns {{ok: boolean, detail: string}}
|
|
69
|
+
*/
|
|
70
|
+
function runFileCheck(spec, cwd) {
|
|
71
|
+
/** @type {{path?: unknown, contains?: unknown}} */
|
|
72
|
+
const obj = typeof spec === 'string' ? { path: spec } : (spec && typeof spec === 'object' ? /** @type {any} */ (spec) : {});
|
|
73
|
+
const rel = obj.path;
|
|
74
|
+
if (typeof rel !== 'string' || !rel.trim()) return { ok: false, detail: 'file check has no path' };
|
|
75
|
+
const root = path.resolve(cwd);
|
|
76
|
+
const abs = path.resolve(root, rel);
|
|
77
|
+
if (path.isAbsolute(rel) || (abs !== root && !abs.startsWith(root + path.sep))) {
|
|
78
|
+
return { ok: false, detail: `path is not repo-relative: ${rel}` };
|
|
79
|
+
}
|
|
80
|
+
let st;
|
|
81
|
+
try { st = fs.statSync(abs); } catch { return { ok: false, detail: `missing: ${rel}` }; }
|
|
82
|
+
if (obj.contains === undefined || obj.contains === null) return { ok: true, detail: `exists: ${rel}` };
|
|
83
|
+
if (typeof obj.contains !== 'string') return { ok: false, detail: 'file check contains must be a string' };
|
|
84
|
+
if (!st.isFile()) return { ok: false, detail: `not a file: ${rel}` };
|
|
85
|
+
if (st.size > FILE_READ_MAX_BYTES) return { ok: false, detail: `too large to search (${st.size} bytes): ${rel}` };
|
|
86
|
+
let text;
|
|
87
|
+
try { text = fs.readFileSync(abs, 'utf8'); } catch (e) { return { ok: false, detail: `unreadable: ${rel}` }; }
|
|
88
|
+
return text.includes(obj.contains)
|
|
89
|
+
? { ok: true, detail: `${rel} contains the text` }
|
|
90
|
+
: { ok: false, detail: `${rel} does not contain ${JSON.stringify(obj.contains)}` };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {unknown} spec
|
|
95
|
+
* @param {number} timeoutMs
|
|
96
|
+
* @returns {Promise<{ok: boolean, detail: string}>}
|
|
97
|
+
*/
|
|
98
|
+
function runHttpCheck(spec, timeoutMs) {
|
|
99
|
+
/** @type {{url?: unknown, status?: unknown}} */
|
|
100
|
+
const obj = typeof spec === 'string' ? { url: spec } : (spec && typeof spec === 'object' ? /** @type {any} */ (spec) : {});
|
|
101
|
+
let url;
|
|
102
|
+
try { url = new URL(String(obj.url)); } catch { return Promise.resolve({ ok: false, detail: 'http check url is not a valid URL' }); }
|
|
103
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
104
|
+
return Promise.resolve({ ok: false, detail: `refused: protocol ${url.protocol} (http/https only)` });
|
|
105
|
+
}
|
|
106
|
+
if (!LOOPBACK_HOSTS.has(url.hostname) || url.username || url.password) {
|
|
107
|
+
return Promise.resolve({ ok: false, detail: `refused: host "${url.hostname}" is not loopback` });
|
|
108
|
+
}
|
|
109
|
+
const want = Number.isInteger(obj.status) ? /** @type {number} */ (obj.status) : 200;
|
|
110
|
+
const lib = url.protocol === 'https:' ? https : http;
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
let done = false;
|
|
113
|
+
/** @param {{ok: boolean, detail: string}} r */
|
|
114
|
+
const finish = (r) => { if (!done) { done = true; clearTimeout(timer); resolve(r); } };
|
|
115
|
+
/** @type {import('node:http').ClientRequest} */
|
|
116
|
+
let req;
|
|
117
|
+
const timer = setTimeout(() => {
|
|
118
|
+
finish({ ok: false, detail: `timed out after ${timeoutMs} ms: ${url.href}` });
|
|
119
|
+
try { req.destroy(); } catch { /* already gone */ }
|
|
120
|
+
}, timeoutMs);
|
|
121
|
+
try {
|
|
122
|
+
// Self-signed certs are normal on a loopback dev server.
|
|
123
|
+
req = lib.request(url, { method: 'GET', ...(lib === https ? { rejectUnauthorized: false } : {}) }, (res) => {
|
|
124
|
+
res.resume();
|
|
125
|
+
const got = res.statusCode;
|
|
126
|
+
finish(got === want
|
|
127
|
+
? { ok: true, detail: `HTTP ${got}` }
|
|
128
|
+
: { ok: false, detail: `HTTP ${got}, expected ${want}` });
|
|
129
|
+
});
|
|
130
|
+
req.on('error', (e) => finish({ ok: false, detail: `request failed: ${e && e.message ? e.message : e}` }));
|
|
131
|
+
req.end();
|
|
132
|
+
} catch (e) {
|
|
133
|
+
finish({ ok: false, detail: `request failed: ${e && /** @type {Error} */ (e).message ? /** @type {Error} */ (e).message : e}` });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Run every criterion's check in `cwd`, in order.
|
|
140
|
+
*
|
|
141
|
+
* @param {{ criteria: unknown, cwd: string, commandCapMs?: number, httpTimeoutMs?: number }} opts
|
|
142
|
+
* commandCapMs / httpTimeoutMs exist for tests; callers use the defaults.
|
|
143
|
+
* @returns {Promise<Array<{id: string, kind: string, ok: boolean|null, detail: string}>>}
|
|
144
|
+
*/
|
|
145
|
+
async function runCriteriaChecks({ criteria, cwd, commandCapMs = COMMAND_CAP_MS, httpTimeoutMs = HTTP_TIMEOUT_MS }) {
|
|
146
|
+
if (!Array.isArray(criteria) || !criteria.length) return [];
|
|
147
|
+
const out = [];
|
|
148
|
+
for (let i = 0; i < criteria.length; i++) {
|
|
149
|
+
const c = criteria[i];
|
|
150
|
+
const id = c && typeof c.id === 'string' ? c.id : `ac-${i + 1}`;
|
|
151
|
+
const check = c && c.check && typeof c.check === 'object' ? c.check : { kind: 'manual' };
|
|
152
|
+
const kind = typeof check.kind === 'string' ? check.kind : 'manual';
|
|
153
|
+
/** @type {{ok: boolean|null, detail: string}} */
|
|
154
|
+
let r;
|
|
155
|
+
try {
|
|
156
|
+
if (kind === 'manual') r = { ok: null, detail: typeof check.spec === 'string' && check.spec ? check.spec : 'manual check' };
|
|
157
|
+
else if (kind === 'command') r = await runCommandCheck(check.spec, commandCapMs, cwd);
|
|
158
|
+
else if (kind === 'file') r = runFileCheck(check.spec, cwd);
|
|
159
|
+
else if (kind === 'http') r = await runHttpCheck(check.spec, httpTimeoutMs);
|
|
160
|
+
else r = { ok: false, detail: `unknown check kind ${JSON.stringify(kind)}` };
|
|
161
|
+
} catch (e) {
|
|
162
|
+
r = { ok: false, detail: `check error: ${e && /** @type {Error} */ (e).message ? /** @type {Error} */ (e).message : e}` };
|
|
163
|
+
}
|
|
164
|
+
out.push({ id, kind, ok: r.ok, detail: r.detail });
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = { runCriteriaChecks, COMMAND_CAP_MS, HTTP_TIMEOUT_MS };
|
|
@@ -12,7 +12,7 @@ const fs = require('node:fs');
|
|
|
12
12
|
const os = require('node:os');
|
|
13
13
|
const path = require('node:path');
|
|
14
14
|
const { spawn, spawnSync } = require('node:child_process');
|
|
15
|
-
const { splitFrontmatter } = require('../prd/prdFrontmatter.cjs');
|
|
15
|
+
const { splitFrontmatter, parsePrdFile } = require('../prd/prdFrontmatter.cjs');
|
|
16
16
|
const { resolvePrdWriteDir } = require('../prd/prdLocations.cjs');
|
|
17
17
|
const schedulerPaths = require('./schedulerPaths.cjs');
|
|
18
18
|
const atomicFs = require('../util/atomicFs.cjs');
|
|
@@ -488,7 +488,9 @@ function extractAcCommand(prdBody) {
|
|
|
488
488
|
* @param {{ resolvePrdPath?: (job: object) => (string|null|Promise<string|null>) }} opts
|
|
489
489
|
* resolvePrdPath Finds the PRD's current absolute path for this job.
|
|
490
490
|
* Required — with none, the result is always unverifiable.
|
|
491
|
-
* @returns {Promise<{ slug: string, status: 'pass'|'fail'|'unverifiable', code: number|null, ms: number, reason?: string }>}
|
|
491
|
+
* @returns {Promise<{ slug: string, status: 'pass'|'fail'|'unverifiable', code: number|null, ms: number, reason?: string, criteriaChecks?: Array<{id: string, kind: string, ok: boolean|null, detail: string}> }>}
|
|
492
|
+
* criteriaChecks present when the PRD frontmatter has structured `criteria`
|
|
493
|
+
* and the gate actually ran (see criteriaChecks.cjs).
|
|
492
494
|
*/
|
|
493
495
|
async function reverifyAc(job, { resolvePrdPath } = {}) {
|
|
494
496
|
const startNs = process.hrtime.bigint();
|
|
@@ -531,19 +533,33 @@ async function reverifyAc(job, { resolvePrdPath } = {}) {
|
|
|
531
533
|
if (source === 'none' || source === 'absent' || !sequence.length) return unverifiable('no-parseable-gate');
|
|
532
534
|
|
|
533
535
|
const result = await runGateSequence(sequence, { cwd: job.cwd });
|
|
534
|
-
if (result.status === 'green') return { slug: job.slug, status: 'pass', code: 0, ms: elapsedMs() };
|
|
535
536
|
if (result.status === 'busy') return unverifiable('busy');
|
|
536
537
|
if (result.status === 'unavailable') return unverifiable('gate-unavailable');
|
|
537
538
|
|
|
539
|
+
// Structured criteria: after the gate re-run, run each criterion's
|
|
540
|
+
// mechanical check in the same tree (criteriaChecks.cjs) and attach the
|
|
541
|
+
// observed results. Lazy require — criteriaChecks requires this module.
|
|
542
|
+
let criteriaChecks;
|
|
543
|
+
let fmCriteria = null;
|
|
544
|
+
try { fmCriteria = parsePrdFile(raw).frontmatter.criteria; } catch { fmCriteria = null; }
|
|
545
|
+
if (Array.isArray(fmCriteria) && fmCriteria.length) {
|
|
546
|
+
try {
|
|
547
|
+
criteriaChecks = await require('./criteriaChecks.cjs').runCriteriaChecks({ criteria: fmCriteria, cwd: job.cwd });
|
|
548
|
+
} catch { criteriaChecks = undefined; }
|
|
549
|
+
}
|
|
550
|
+
const withChecks = (r) => (criteriaChecks ? { ...r, criteriaChecks } : r);
|
|
551
|
+
|
|
552
|
+
if (result.status === 'green') return withChecks({ slug: job.slug, status: 'pass', code: 0, ms: elapsedMs() });
|
|
553
|
+
|
|
538
554
|
// status === 'red': a step exited non-zero. A step that was killed for
|
|
539
555
|
// running past its own `timeout N` is not trustworthy evidence of a real
|
|
540
556
|
// failure (the machine may just be slow right now), so it is reported as
|
|
541
557
|
// unverifiable instead of fail — same reasoning reverifyAc has always used
|
|
542
558
|
// for a step that couldn't even start.
|
|
543
559
|
const timedOutStep = result.results.find((r) => r.timedOut);
|
|
544
|
-
if (timedOutStep) return unverifiable('timeout');
|
|
560
|
+
if (timedOutStep) return withChecks(unverifiable('timeout'));
|
|
545
561
|
const failedStep = result.results.find((r) => r.status === 'fail');
|
|
546
|
-
return { slug: job.slug, status: 'fail', code: failedStep ? failedStep.code : null, ms: elapsedMs() };
|
|
562
|
+
return withChecks({ slug: job.slug, status: 'fail', code: failedStep ? failedStep.code : null, ms: elapsedMs() });
|
|
547
563
|
}
|
|
548
564
|
|
|
549
565
|
/**
|
|
@@ -730,6 +746,20 @@ function writeReport(key, { acResults = [], riskFlags = [], runsDir } = {}) {
|
|
|
730
746
|
...acRows,
|
|
731
747
|
].join('\n');
|
|
732
748
|
|
|
749
|
+
// ── Criteria checks (structured criteria, criteriaChecks.cjs) ───────────────
|
|
750
|
+
const CHECK_MARK = (ok) => (ok === true ? '✅ pass' : ok === false ? '❌ fail' : '— manual');
|
|
751
|
+
const cell = (v) => String(v ?? '').replace(/\|/g, '\\|').replace(/[\r\n]+/g, ' ');
|
|
752
|
+
const criteriaRows = [];
|
|
753
|
+
for (const r of acResults) {
|
|
754
|
+
if (!Array.isArray(r.criteriaChecks)) continue;
|
|
755
|
+
for (const c of r.criteriaChecks) {
|
|
756
|
+
criteriaRows.push(`| ${r.slug} | ${cell(c.id)} | ${cell(c.kind)} | ${CHECK_MARK(c.ok)} | ${cell(c.detail)} |`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
const criteriaSection = criteriaRows.length
|
|
760
|
+
? ['| Slug | Criterion | Kind | Result | Detail |', '|------|-----------|------|--------|--------|', ...criteriaRows].join('\n')
|
|
761
|
+
: '_No structured criteria._';
|
|
762
|
+
|
|
733
763
|
// ── Risk flags table ─────────────────────────────────────────────────────────
|
|
734
764
|
let riskSection;
|
|
735
765
|
if (riskFlags.length === 0) {
|
|
@@ -751,6 +781,11 @@ function writeReport(key, { acResults = [], riskFlags = [], runsDir } = {}) {
|
|
|
751
781
|
attentionLines.push(`- **${r.slug}** — unverifiable AC; manual inspection recommended for ${r.slug}`);
|
|
752
782
|
}
|
|
753
783
|
}
|
|
784
|
+
for (const r of acResults) {
|
|
785
|
+
if (!Array.isArray(r.criteriaChecks)) continue;
|
|
786
|
+
const failed = r.criteriaChecks.filter((c) => c.ok === false).map((c) => c.id);
|
|
787
|
+
if (failed.length) attentionLines.push(`- **${r.slug}** — criteria check failed: ${failed.join(', ')}`);
|
|
788
|
+
}
|
|
754
789
|
for (const r of riskFlags) {
|
|
755
790
|
attentionLines.push(
|
|
756
791
|
`- **${r.slug}** — touches ${r.surfaces.join(', ')}; run \`/code-review\` on ${r.slug} — ${r.surfaces.join('/')} path`
|
|
@@ -774,6 +809,10 @@ function writeReport(key, { acResults = [], riskFlags = [], runsDir } = {}) {
|
|
|
774
809
|
'',
|
|
775
810
|
acTable,
|
|
776
811
|
'',
|
|
812
|
+
'## Criteria Checks',
|
|
813
|
+
'',
|
|
814
|
+
criteriaSection,
|
|
815
|
+
'',
|
|
777
816
|
'## Risk Flags',
|
|
778
817
|
'',
|
|
779
818
|
riskSection,
|