claude-code-session-manager 0.138.0 → 0.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +352 -79
- package/dist/assets/AppSettings-CMFEM68R.js +2 -0
- package/dist/assets/History--JwsFnbn.js +2 -0
- package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
- package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
- package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
- package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
- package/dist/assets/Skills-DtRzghn5.js +67 -0
- package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
- package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
- package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
- package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
- package/dist/assets/index-CtxruO1L.js +3121 -0
- package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +467 -451
- package/package.json +17 -6
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
- package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
- package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
- package/scripts/README.md +2 -0
- package/scripts/hooks/guard-tool-risk.cjs +91 -0
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
- package/scripts/ops-sweep.cjs +53 -23
- package/scripts/scheduler-mcp-server.cjs +360 -35
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +2 -2
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/exchanges.cjs +70 -5
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +172 -63
- package/src/main/historyDashboard.cjs +87 -17
- package/src/main/index.cjs +78 -4
- package/src/main/ipcSchemas.cjs +233 -20
- package/src/main/lib/AGENTS.md +54 -0
- package/src/main/lib/CLAUDE.md +1 -54
- package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
- package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
- package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
- package/src/main/lib/claude/effectiveModelInfo.cjs +92 -22
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/modelPricing.cjs +148 -0
- package/src/main/lib/claude/personaToolScope.cjs +12 -6
- package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
- package/src/main/lib/claude/runClaudeP.cjs +6 -1
- package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
- package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
- package/src/main/lib/ephemeralCwd.cjs +37 -2
- package/src/main/lib/epic/delegationReadiness.cjs +42 -9
- package/src/main/lib/epic/epicAdminRoutes.cjs +121 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
- package/src/main/lib/epic/epicOutsideState.cjs +233 -0
- package/src/main/lib/epic/epicSettle.cjs +1 -1
- package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +137 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
- package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
- package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
- package/src/main/lib/git/branchSweep.cjs +209 -4
- package/src/main/lib/git/gitWorktree.cjs +41 -5
- package/src/main/lib/guardShims.cjs +1 -1
- package/src/main/lib/historyRollup.cjs +58 -5
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +232 -25
- package/src/main/lib/mdDocCensus.cjs +59 -78
- package/src/main/lib/mdDocRefs.cjs +71 -93
- package/src/main/lib/mdNetworkScan.cjs +245 -250
- package/src/main/lib/mdReviewRecord.cjs +22 -9
- package/src/main/lib/memoryMdNetwork.cjs +5 -12
- package/src/main/lib/opsOwnership.cjs +18 -2
- package/src/main/lib/opsRetentionSettings.cjs +28 -4
- package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
- package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
- package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
- package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
- package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/depSlugResolve.cjs +104 -4
- package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
- package/src/main/lib/prd/prdCreate.cjs +351 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
- package/src/main/lib/process/loginItem.cjs +171 -0
- package/src/main/lib/process/loginItemPlan.cjs +193 -0
- package/src/main/lib/project-pages/playerBridge.cjs +4 -0
- package/src/main/lib/project-pages/videoReview.cjs +268 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
- package/src/main/lib/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- package/src/main/lib/scheduler/cpuSample.cjs +131 -4
- package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
- package/src/main/lib/scheduler/loadGate.cjs +24 -6
- package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
- package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
- package/src/main/lib/scheduler/queueStore.cjs +7 -0
- package/src/main/lib/scheduler/rcaReport.cjs +21 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
- package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
- package/src/main/lib/scheduler/schedulerPaths.cjs +12 -0
- package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
- package/src/main/lib/scheduler/validationQuality.cjs +282 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
- package/src/main/lib/tasks/taskIpc.cjs +80 -0
- package/src/main/lib/tasks/taskLedger.cjs +502 -0
- package/src/main/lib/tasks/taskRun.cjs +313 -0
- package/src/main/lib/tasks/taskSwitch.cjs +120 -0
- package/src/main/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +11 -2
- package/src/main/projectPages.cjs +6 -15
- package/src/main/promptSessionEvents.cjs +9 -1
- package/src/main/queueOps.cjs +260 -3
- package/src/main/runVerify.cjs +53 -25
- package/src/main/scheduler/AGENTS.md +26 -0
- package/src/main/scheduler/CLAUDE.md +1 -26
- package/src/main/scheduler/budget.cjs +239 -9
- package/src/main/scheduler/cancelDependents.cjs +154 -0
- package/src/main/scheduler/prdParser.cjs +4 -1
- package/src/main/scheduler/starvation.cjs +20 -18
- package/src/main/scheduler.cjs +774 -64
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +7 -1
- package/src/main/transcripts.cjs +62 -7
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +132 -20
- package/src/preload/api.d.ts +434 -28
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +485 -81
- package/src/preload/index.cjs +38 -5
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
- package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
- package/dist/assets/Button-Bk23rEnZ.js +0 -1
- package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
- package/dist/assets/Extensions-CXem-uwI.js +0 -2
- package/dist/assets/History-BwO3coo4.js +0 -2
- package/dist/assets/Library-BDV69fSe.js +0 -32
- package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
- package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
- package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
- package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
- package/dist/assets/Settings-COT34hBF.js +0 -2
- package/dist/assets/Skills-BgexoUkQ.js +0 -29
- package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
- package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
- package/dist/assets/Toggle-CENi19iK.js +0 -1
- package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-CgCxpunJ.js +0 -3116
|
@@ -7,7 +7,17 @@
|
|
|
7
7
|
* it can read high on a mostly idle machine (2026-11-01, 14 CPUs: 25 D-state
|
|
8
8
|
* tasks gave loadavg1 22.39 while the CPU was only 24% busy over 75 s). This
|
|
9
9
|
* helper derives busy/total from cumulative counters over a window of about a
|
|
10
|
-
* minute instead. Pure and injectable (`read`, `now`).
|
|
10
|
+
* minute instead. Pure and injectable (`read`, `readOwn`, `now`).
|
|
11
|
+
*
|
|
12
|
+
* Own-process exclusion (PRD 3495): 2026-11-22 the gate held launches at
|
|
13
|
+
* loadavg ratios 2.21 … 1.01 on 14 cores while this app's own renderer averaged
|
|
14
|
+
* ~81% CPU and main ~45%. The app must not gate on its own load, so the sampler
|
|
15
|
+
* also tracks the app's own process tree (main + Electron `--type=` helpers:
|
|
16
|
+
* zygote, renderer, GPU, utility) from /proc/<pid>/stat and reports busy both
|
|
17
|
+
* raw and net of it. Spawned jobs (claude -p and their children) are NOT own
|
|
18
|
+
* processes — they carry no `--type=` flag — so they stay in the net figure.
|
|
19
|
+
* /proc/stat and /proc/<pid>/stat are both in USER_HZ clock ticks, so the
|
|
20
|
+
* deltas subtract directly. Off Linux the own reading is null and net = raw.
|
|
11
21
|
*/
|
|
12
22
|
|
|
13
23
|
const fs = require('node:fs');
|
|
@@ -81,18 +91,128 @@ function readCpuTimes({
|
|
|
81
91
|
}
|
|
82
92
|
|
|
83
93
|
/**
|
|
84
|
-
*
|
|
94
|
+
* Parse one /proc/<pid>/stat line → { pid, ppid, ticks: utime+stime }.
|
|
95
|
+
* comm (field 2) may contain spaces and parens, so split after the LAST ')'.
|
|
96
|
+
* @param {string} text
|
|
97
|
+
* @returns {{ pid: number, ppid: number, ticks: number } | null}
|
|
98
|
+
*/
|
|
99
|
+
function parsePidStat(text) {
|
|
100
|
+
if (typeof text !== 'string' || !text) return null;
|
|
101
|
+
const close = text.lastIndexOf(')');
|
|
102
|
+
const open = text.indexOf('(');
|
|
103
|
+
if (close < 0 || open < 0) return null;
|
|
104
|
+
const pid = Number(text.slice(0, open).trim());
|
|
105
|
+
// After ')': state(3) ppid(4) ... utime(14) stime(15) → indices 0,1,...,11,12.
|
|
106
|
+
const rest = text.slice(close + 1).trim().split(/\s+/);
|
|
107
|
+
const ppid = Number(rest[1]);
|
|
108
|
+
const utime = Number(rest[11]);
|
|
109
|
+
const stime = Number(rest[12]);
|
|
110
|
+
if (![pid, ppid, utime, stime].every(Number.isFinite)) return null;
|
|
111
|
+
return { pid, ppid, ticks: utime + stime };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* True when a /proc/<pid>/cmdline names an Electron/Chromium helper: `--type=`
|
|
116
|
+
* among the first two arguments. Chromium helpers rewrite their argv into one
|
|
117
|
+
* space-joined string (setproctitle), so split on NUL and space.
|
|
118
|
+
* @param {string} cmd
|
|
119
|
+
*/
|
|
120
|
+
function isElectronHelperCmdline(cmd) {
|
|
121
|
+
if (typeof cmd !== 'string') return false;
|
|
122
|
+
return cmd.split(/[\0 ]+/).slice(1, 3).some((a) => a.startsWith('--type='));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The app's own process tree as Map<pid, cumulative utime+stime ticks>: the
|
|
127
|
+
* root (Electron main) plus every descendant reached only through processes
|
|
128
|
+
* whose cmdline carries an Electron `--type=` flag. Linux only; null elsewhere
|
|
129
|
+
* or when /proc cannot be listed. Never throws.
|
|
130
|
+
* A helper must also run the same executable as the root (when /proc/<pid>/exe
|
|
131
|
+
* is readable), so a job whose prompt text happens to contain "--type=" never
|
|
132
|
+
* counts as own.
|
|
133
|
+
* @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}
|
|
136
|
+
*/
|
|
137
|
+
function readOwnProcessTicks({
|
|
138
|
+
rootPid = process.pid,
|
|
139
|
+
platform = process.platform,
|
|
140
|
+
readdir = (p) => fs.readdirSync(p),
|
|
141
|
+
readFile = (p) => fs.readFileSync(p, 'utf8'),
|
|
142
|
+
readlink = (p) => fs.readlinkSync(p),
|
|
143
|
+
} = {}) {
|
|
144
|
+
if (platform !== 'linux') return null;
|
|
145
|
+
try {
|
|
146
|
+
/** @type {Map<number, { ppid: number, ticks: number }>} */
|
|
147
|
+
const procs = new Map();
|
|
148
|
+
/** @type {Map<number, number[]>} */
|
|
149
|
+
const children = new Map();
|
|
150
|
+
for (const name of readdir('/proc')) {
|
|
151
|
+
if (!/^\d+$/.test(name)) continue;
|
|
152
|
+
let st;
|
|
153
|
+
try { st = parsePidStat(readFile(`/proc/${name}/stat`)); } catch { continue; }
|
|
154
|
+
if (!st) continue;
|
|
155
|
+
procs.set(st.pid, { ppid: st.ppid, ticks: st.ticks });
|
|
156
|
+
const list = children.get(st.ppid);
|
|
157
|
+
if (list) list.push(st.pid); else children.set(st.ppid, [st.pid]);
|
|
158
|
+
}
|
|
159
|
+
const root = procs.get(rootPid);
|
|
160
|
+
if (!root) return null;
|
|
161
|
+
const exeOf = (/** @type {number} */ pid) => { try { return readlink(`/proc/${pid}/exe`); } catch { return null; } };
|
|
162
|
+
const rootExe = exeOf(rootPid);
|
|
163
|
+
/** @type {Map<number, number>} */
|
|
164
|
+
const own = new Map([[rootPid, root.ticks]]);
|
|
165
|
+
const queue = [rootPid];
|
|
166
|
+
while (queue.length) {
|
|
167
|
+
const parent = /** @type {number} */ (queue.shift());
|
|
168
|
+
for (const child of children.get(parent) || []) {
|
|
169
|
+
let cmd = '';
|
|
170
|
+
try { cmd = readFile(`/proc/${child}/cmdline`); } catch { continue; }
|
|
171
|
+
if (!isElectronHelperCmdline(cmd)) continue;
|
|
172
|
+
if (rootExe !== null && exeOf(child) !== rootExe) continue;
|
|
173
|
+
own.set(child, /** @type {{ticks:number}} */ (procs.get(child)).ticks);
|
|
174
|
+
queue.push(child);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return own;
|
|
178
|
+
} catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Own-process ticks consumed between two readings. A pid only in `before`
|
|
185
|
+
* exited (its last ticks are lost, count 0); a pid only in `after` started in
|
|
186
|
+
* the window, so all its ticks count.
|
|
187
|
+
* @param {Map<number, number> | null} before
|
|
188
|
+
* @param {Map<number, number> | null} after
|
|
189
|
+
* @returns {number | null}
|
|
190
|
+
*/
|
|
191
|
+
function ownTicksDelta(before, after) {
|
|
192
|
+
if (!before || !after) return null;
|
|
193
|
+
let d = 0;
|
|
194
|
+
for (const [pid, ticks] of after) {
|
|
195
|
+
const prev = before.get(pid);
|
|
196
|
+
d += prev === undefined ? ticks : Math.max(0, ticks - prev);
|
|
197
|
+
}
|
|
198
|
+
return d;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {{ read?: () => ({busy:number,iowait?:number,total:number}|null),
|
|
203
|
+
* readOwn?: () => (Map<number, number>|null), now?: () => number,
|
|
85
204
|
* windowMs?: number, minWindowMs?: number, maxWindowMs?: number, minSpacingMs?: number }} [opts]
|
|
86
205
|
*/
|
|
87
206
|
function createCpuSampler({
|
|
88
207
|
read = readCpuTimes,
|
|
208
|
+
readOwn = () => readOwnProcessTicks(),
|
|
89
209
|
now = () => Date.now(),
|
|
90
210
|
windowMs = DEFAULT_WINDOW_MS,
|
|
91
211
|
minWindowMs = MIN_WINDOW_MS,
|
|
92
212
|
maxWindowMs = MAX_WINDOW_MS,
|
|
93
213
|
minSpacingMs = MIN_SPACING_MS,
|
|
94
214
|
} = {}) {
|
|
95
|
-
/** @type {{ at: number, busy: number, iowait: number, total: number }[]} */
|
|
215
|
+
/** @type {{ at: number, busy: number, iowait: number, total: number, own: Map<number, number> | null }[]} */
|
|
96
216
|
let entries = [];
|
|
97
217
|
|
|
98
218
|
function observe() {
|
|
@@ -101,7 +221,7 @@ function createCpuSampler({
|
|
|
101
221
|
if (!r) return;
|
|
102
222
|
const newest = entries[entries.length - 1];
|
|
103
223
|
if (newest && t - newest.at < minSpacingMs) return;
|
|
104
|
-
entries.push({ at: t, busy: r.busy, iowait: r.iowait ?? 0, total: r.total });
|
|
224
|
+
entries.push({ at: t, busy: r.busy, iowait: r.iowait ?? 0, total: r.total, own: readOwn() });
|
|
105
225
|
entries = entries.filter((e) => t - e.at <= maxWindowMs);
|
|
106
226
|
}
|
|
107
227
|
|
|
@@ -126,8 +246,12 @@ function createCpuSampler({
|
|
|
126
246
|
const dIowait = (r.iowait ?? 0) - best.iowait;
|
|
127
247
|
// Per-CPU idle and iowait counters can step backwards.
|
|
128
248
|
if (dTotal <= 0 || dBusy < 0) return null;
|
|
249
|
+
const dOwnRaw = ownTicksDelta(best.own, readOwn());
|
|
250
|
+
const dOwn = dOwnRaw === null ? null : Math.min(dBusy, dOwnRaw);
|
|
129
251
|
return {
|
|
130
252
|
busyFraction: Math.min(1, dBusy / dTotal),
|
|
253
|
+
ownFraction: dOwn === null ? null : dOwn / dTotal,
|
|
254
|
+
netBusyFraction: Math.min(1, (dBusy - (dOwn ?? 0)) / dTotal),
|
|
131
255
|
iowaitFraction: Math.min(1, Math.max(0, dIowait / dTotal)),
|
|
132
256
|
windowMs: t - best.at,
|
|
133
257
|
};
|
|
@@ -138,6 +262,9 @@ function createCpuSampler({
|
|
|
138
262
|
|
|
139
263
|
module.exports = {
|
|
140
264
|
parseProcStat,
|
|
265
|
+
parsePidStat,
|
|
266
|
+
readOwnProcessTicks,
|
|
267
|
+
ownTicksDelta,
|
|
141
268
|
readCpuTimes,
|
|
142
269
|
createCpuSampler,
|
|
143
270
|
DEFAULT_WINDOW_MS,
|
|
@@ -63,13 +63,14 @@ function resolveIsFixPlan(slug, isFixPlan) {
|
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* The ONE repo-relative path a fix plan may name for a validation record
|
|
66
|
-
* (PRD 2883). Lives under the
|
|
67
|
-
*
|
|
66
|
+
* (PRD 2883). Lives under the `plan-records/` runtime namespace, which the
|
|
67
|
+
* scheduler harvests from the job worktree into the main checkout — never
|
|
68
|
+
* under the `scheduler/` runtime folder, where the fix-plan PRD file itself
|
|
68
69
|
* sits. An unsafe/missing epicId drops the epic segment rather than
|
|
69
70
|
* concatenating it into a path.
|
|
70
71
|
*/
|
|
71
72
|
function fixPlanRecordPath(epicId, fixSlug) {
|
|
72
|
-
const base = 'session-manager-operations/
|
|
73
|
+
const base = 'session-manager-operations/plan-records';
|
|
73
74
|
return isSafeEpicId(epicId) ? `${base}/${epicId}/${fixSlug}.md` : `${base}/${fixSlug}.md`;
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -47,6 +47,16 @@ const MOSTLY_IDLE_BUSY = 0.5;
|
|
|
47
47
|
// Both bars use Math.min(threshold, bar) so a strict threshold stays strict.
|
|
48
48
|
const SATURATED_BUSY = 0.85;
|
|
49
49
|
|
|
50
|
+
// The busy fraction every band above judges is NET of this app's own process
|
|
51
|
+
// tree (PRD 3495; cpuSample.cjs readOwnProcessTicks) — the app must not gate on
|
|
52
|
+
// its own renderer/main load. Raw and own shares are still reported. A sampler
|
|
53
|
+
// without a net figure (non-Linux, legacy injection) falls back to raw.
|
|
54
|
+
function busyOf(sample) {
|
|
55
|
+
if (!sample) return null;
|
|
56
|
+
return Number.isFinite(sample.netBusyFraction) ? sample.netBusyFraction : sample.busyFraction;
|
|
57
|
+
}
|
|
58
|
+
const round3 = (n) => (Number.isFinite(n) ? Number(n.toFixed(3)) : null);
|
|
59
|
+
|
|
50
60
|
// One audit row per this interval while continuously gated — the poll loop
|
|
51
61
|
// ticks every 60 s and a saturated box stays saturated for a while; auditing
|
|
52
62
|
// every tick would bury the signal in its own noise.
|
|
@@ -111,7 +121,8 @@ function topCpuConsumers(n = 3, { execImpl = execFileSync, platform = process.pl
|
|
|
111
121
|
/**
|
|
112
122
|
* createLoadGate(opts) → { evaluate, observe, snapshot, endHold }
|
|
113
123
|
*
|
|
114
|
-
* Decision: loadavg over threshold AND the CPU sample
|
|
124
|
+
* Decision: loadavg over threshold AND the CPU sample (net of the app's own
|
|
125
|
+
* processes, see busyOf) not mostly idle (busy
|
|
115
126
|
* fraction >= min(threshold, MOSTLY_IDLE_BUSY)) holds; over threshold with a
|
|
116
127
|
* mostly idle sample stands down (standDown:true); no sample keeps the loadavg
|
|
117
128
|
* verdict. observe() feeds the sampler and must run every tick.
|
|
@@ -172,6 +183,9 @@ function createLoadGate({
|
|
|
172
183
|
threshold: typeof threshold === 'function' ? threshold() : threshold,
|
|
173
184
|
loadavg1: null,
|
|
174
185
|
cpuBusy: null,
|
|
186
|
+
cpuBusyRaw: null,
|
|
187
|
+
cpuBusyNet: null,
|
|
188
|
+
cpuOwnBusy: null,
|
|
175
189
|
cpuIowait: null,
|
|
176
190
|
cpuWindowMs: null,
|
|
177
191
|
standDown: false,
|
|
@@ -188,8 +202,9 @@ function createLoadGate({
|
|
|
188
202
|
const th = typeof threshold === 'function' ? threshold() : threshold;
|
|
189
203
|
const ratio = c > 0 && Number.isFinite(l1) ? l1 / c : 0;
|
|
190
204
|
const sample = cpu.sample();
|
|
205
|
+
const busy = busyOf(sample);
|
|
191
206
|
const overLoad = isLoadGated(l1, c, th);
|
|
192
|
-
const standDown = overLoad &&
|
|
207
|
+
const standDown = overLoad && busy !== null && busy < Math.min(th, MOSTLY_IDLE_BUSY);
|
|
193
208
|
const wouldGate = overLoad && !standDown;
|
|
194
209
|
|
|
195
210
|
const holding = wouldGate && !bypass;
|
|
@@ -198,7 +213,7 @@ function createLoadGate({
|
|
|
198
213
|
lastHeldAt = t;
|
|
199
214
|
}
|
|
200
215
|
// A yield stays armed until the caller proves a launch with endHold().
|
|
201
|
-
const saturated =
|
|
216
|
+
const saturated = busy !== null && busy >= Math.min(th, SATURATED_BUSY);
|
|
202
217
|
const atLimit = holding && heldMs >= yieldAfterMs;
|
|
203
218
|
const yielded = atLimit && !saturated;
|
|
204
219
|
const gated = holding && !yielded;
|
|
@@ -225,7 +240,10 @@ function createLoadGate({
|
|
|
225
240
|
ratio: Number(ratio.toFixed(3)),
|
|
226
241
|
threshold: th,
|
|
227
242
|
loadavg1: Number.isFinite(l1) ? Number(l1.toFixed(2)) : null,
|
|
228
|
-
cpuBusy:
|
|
243
|
+
cpuBusy: round3(busy), // the decision value (net of own processes)
|
|
244
|
+
cpuBusyRaw: sample ? round3(sample.busyFraction) : null,
|
|
245
|
+
cpuBusyNet: round3(busy),
|
|
246
|
+
cpuOwnBusy: sample && Number.isFinite(sample.ownFraction) ? round3(sample.ownFraction) : null,
|
|
229
247
|
cpuIowait: sample ? Number(sample.iowaitFraction.toFixed(3)) : null,
|
|
230
248
|
cpuWindowMs: sample ? sample.windowMs : null,
|
|
231
249
|
standDown,
|
|
@@ -257,8 +275,8 @@ function createLoadGate({
|
|
|
257
275
|
const [l1] = loadavg();
|
|
258
276
|
const th = typeof threshold === 'function' ? threshold() : threshold;
|
|
259
277
|
if (!isLoadGated(l1, cores(), th)) return false;
|
|
260
|
-
const
|
|
261
|
-
return
|
|
278
|
+
const busy = busyOf(cpu.sample());
|
|
279
|
+
return busy !== null && busy >= Math.min(th, SATURATED_BUSY);
|
|
262
280
|
}
|
|
263
281
|
|
|
264
282
|
return { evaluate, observe, snapshot, endHold, isSaturated };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* planRecordHarvest.cjs — copy the plan records a job wrote inside its git
|
|
5
|
+
* worktree (`<ops>/plan-records/<epic-id>/*.md`, never committed) into the
|
|
6
|
+
* main checkout's `plan-records/<epic-id>/`, writing as the namespace owner
|
|
7
|
+
* ('scheduler'), so they survive worktree teardown without a commit.
|
|
8
|
+
*
|
|
9
|
+
* Never throws: every refusal is reported in `skipped` with a reason.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('node:fs');
|
|
13
|
+
const path = require('node:path');
|
|
14
|
+
const { OPS_ROOT_DIR, opsPath, checkOpsWrite, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
15
|
+
const { writeTextAtomicSync } = require('../util/atomicFs.cjs');
|
|
16
|
+
|
|
17
|
+
const NAMESPACE = 'plan-records';
|
|
18
|
+
const WRITER = 'scheduler';
|
|
19
|
+
const MAX_BYTES = 1024 * 1024;
|
|
20
|
+
const NAME_RE = /^[A-Za-z0-9._-]+\.md$/;
|
|
21
|
+
const EPIC_ID_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
22
|
+
|
|
23
|
+
function errMsg(e) {
|
|
24
|
+
return e && e.message ? e.message : String(e);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* harvestPlanRecords({ worktreeDir, projectRoot, epicId, fsImpl })
|
|
29
|
+
* → { copied: string[], skipped: { path, reason }[] }
|
|
30
|
+
* `copied` holds destination absolute paths.
|
|
31
|
+
*/
|
|
32
|
+
function harvestPlanRecords({ worktreeDir, projectRoot, epicId, fsImpl = fs } = {}) {
|
|
33
|
+
/** @type {string[]} */
|
|
34
|
+
const copied = [];
|
|
35
|
+
/** @type {{ path: string, reason: string }[]} */
|
|
36
|
+
const skipped = [];
|
|
37
|
+
try {
|
|
38
|
+
if (typeof epicId !== 'string' || !EPIC_ID_RE.test(epicId)) {
|
|
39
|
+
skipped.push({ path: String(epicId), reason: 'unsafe epicId' });
|
|
40
|
+
return { copied, skipped };
|
|
41
|
+
}
|
|
42
|
+
if (typeof worktreeDir !== 'string' || !path.isAbsolute(worktreeDir)
|
|
43
|
+
|| typeof projectRoot !== 'string' || !path.isAbsolute(projectRoot)) {
|
|
44
|
+
skipped.push({ path: String(worktreeDir), reason: 'worktreeDir and projectRoot must be absolute paths' });
|
|
45
|
+
return { copied, skipped };
|
|
46
|
+
}
|
|
47
|
+
if (path.resolve(worktreeDir) === path.resolve(projectRoot)) return { copied, skipped };
|
|
48
|
+
|
|
49
|
+
const srcDir = path.join(path.resolve(worktreeDir), OPS_ROOT_DIR, NAMESPACE, epicId);
|
|
50
|
+
let destDir;
|
|
51
|
+
try {
|
|
52
|
+
destDir = path.resolve(opsPath(projectRoot, NAMESPACE, epicId));
|
|
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);
|
|
80
|
+
try {
|
|
81
|
+
if (!NAME_RE.test(name)) { skipped.push({ path: src, reason: 'name not allowed' }); continue; }
|
|
82
|
+
const st = fsImpl.lstatSync(src);
|
|
83
|
+
if (st.isSymbolicLink()) { skipped.push({ path: src, reason: 'symlink' }); continue; }
|
|
84
|
+
if (st.isDirectory()) { skipped.push({ path: src, reason: 'directory' }); continue; }
|
|
85
|
+
if (!st.isFile()) { skipped.push({ path: src, reason: 'not a regular file' }); continue; }
|
|
86
|
+
if (st.size > MAX_BYTES) { skipped.push({ path: src, reason: `oversize (${st.size} > ${MAX_BYTES} bytes)` }); continue; }
|
|
87
|
+
|
|
88
|
+
const dest = path.resolve(opsPath(projectRoot, NAMESPACE, epicId, name));
|
|
89
|
+
if (path.dirname(dest) !== destDir) { skipped.push({ path: src, reason: 'destination escapes plan-records folder' }); continue; }
|
|
90
|
+
const verdict = checkOpsWrite(dest, WRITER);
|
|
91
|
+
if (!verdict.ok) { skipped.push({ path: src, reason: `write refused: ${verdict.error}` }); continue; }
|
|
92
|
+
assertOpsWrite(dest, WRITER);
|
|
93
|
+
|
|
94
|
+
const text = fsImpl.readFileSync(src, 'utf8');
|
|
95
|
+
if (Buffer.byteLength(text, 'utf8') > MAX_BYTES) { skipped.push({ path: src, reason: 'oversize after read' }); continue; }
|
|
96
|
+
writeTextAtomicSync(dest, text);
|
|
97
|
+
copied.push(dest);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
skipped.push({ path: src, reason: `copy failed: ${errMsg(e)}` });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
skipped.push({ path: String(worktreeDir), reason: `harvest failed: ${errMsg(e)}` });
|
|
104
|
+
}
|
|
105
|
+
return { copied, skipped };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { harvestPlanRecords, MAX_BYTES, NAME_RE, EPIC_ID_RE };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* planRecordRetention — retention sweep for `session-manager-operations/plan-records/<epic-id>/`.
|
|
3
|
+
*
|
|
4
|
+
* prunePlanRecords({ projectRoot, epicStatus, now, days, dryRun, fsImpl })
|
|
5
|
+
* → { removed: string[] (epic ids), kept: number }. Never throws.
|
|
6
|
+
*
|
|
7
|
+
* A folder is removed when:
|
|
8
|
+
* - epicStatus(id) → { status: 'completed', completedAt } with completedAt older than `days`, or
|
|
9
|
+
* - epicStatus(id) → null (orphan) and its newest file mtime is older than `days`.
|
|
10
|
+
* Never removed: proposed/active (any non-completed) Epics, a completed Epic with no
|
|
11
|
+
* parseable completedAt, README.md / .gitignore (or any non-directory), symlinks, and
|
|
12
|
+
* folder names that fail SAFE_ID_RE. A throwing epicStatus keeps the folder.
|
|
13
|
+
* dryRun reports the exact same list and deletes nothing.
|
|
14
|
+
*
|
|
15
|
+
* Writes go through opsPath(projectRoot, 'plan-records', id) and the opsOwnership write
|
|
16
|
+
* guard as writer 'scheduler' (the namespace owner). epicStatus and fsImpl are injected
|
|
17
|
+
* so the module is pure; defaultEpicStatus(projectRoot) reads prompt-sessions/<id>.json.
|
|
18
|
+
* days defaults to opsRetentionSettings.read().planRecordsDays.
|
|
19
|
+
*/
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const nodeFs = require('node:fs');
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const opsOwnership = require('../opsOwnership.cjs');
|
|
25
|
+
const { readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
26
|
+
|
|
27
|
+
const WRITER = 'scheduler';
|
|
28
|
+
const NS = 'plan-records';
|
|
29
|
+
const DAY_MS = 86400000;
|
|
30
|
+
const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
|
|
31
|
+
const RESERVED = new Set(['README.md', '.gitignore']);
|
|
32
|
+
|
|
33
|
+
function toMs(v) {
|
|
34
|
+
if (typeof v === 'number' && Number.isFinite(v)) return v;
|
|
35
|
+
if (typeof v === 'string' && v) {
|
|
36
|
+
const ms = Date.parse(v);
|
|
37
|
+
if (Number.isFinite(ms)) return ms;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isSafeId(name) {
|
|
43
|
+
return typeof name === 'string' && SAFE_ID_RE.test(name) && name !== '.' && name !== '..' && !RESERVED.has(name);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Newest mtime of any file under dir (recursive, symlinks not followed); dir mtime when empty. */
|
|
47
|
+
function newestMtime(fsImpl, dir) {
|
|
48
|
+
let newest = null;
|
|
49
|
+
const walk = (d) => {
|
|
50
|
+
let entries;
|
|
51
|
+
try { entries = fsImpl.readdirSync(d, { withFileTypes: true }); } catch { return; }
|
|
52
|
+
for (const e of entries) {
|
|
53
|
+
const p = path.join(d, e.name);
|
|
54
|
+
if (e.isDirectory()) { walk(p); continue; }
|
|
55
|
+
try {
|
|
56
|
+
const st = fsImpl.lstatSync(p);
|
|
57
|
+
if (newest === null || st.mtimeMs > newest) newest = st.mtimeMs;
|
|
58
|
+
} catch { /* vanished */ }
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
walk(dir);
|
|
62
|
+
if (newest === null) {
|
|
63
|
+
try { newest = fsImpl.lstatSync(dir).mtimeMs; } catch { /* vanished */ }
|
|
64
|
+
}
|
|
65
|
+
return newest;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function resolveDays(days) {
|
|
69
|
+
if (typeof days === 'number' && Number.isFinite(days) && days > 0) return days;
|
|
70
|
+
try {
|
|
71
|
+
return require('../opsRetentionSettings.cjs').read().planRecordsDays;
|
|
72
|
+
} catch {
|
|
73
|
+
return 14;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isEligible({ id, dir, epicStatus, cutoffMs, fsImpl }) {
|
|
78
|
+
let st;
|
|
79
|
+
try { st = epicStatus(id); } catch { return false; }
|
|
80
|
+
if (st === null || st === undefined) {
|
|
81
|
+
const m = newestMtime(fsImpl, dir);
|
|
82
|
+
return m !== null && m < cutoffMs;
|
|
83
|
+
}
|
|
84
|
+
if (!st || typeof st !== 'object' || st.status !== 'completed') return false;
|
|
85
|
+
const done = toMs(st.completedAt);
|
|
86
|
+
return done !== null && done < cutoffMs;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function prunePlanRecords(opts) {
|
|
90
|
+
const result = { removed: [], kept: 0 };
|
|
91
|
+
try {
|
|
92
|
+
const o = opts || {};
|
|
93
|
+
const fsImpl = o.fsImpl || nodeFs;
|
|
94
|
+
if (typeof o.epicStatus !== 'function') return result;
|
|
95
|
+
const now = typeof o.now === 'number' && Number.isFinite(o.now) ? o.now : Date.now();
|
|
96
|
+
const cutoffMs = now - resolveDays(o.days) * DAY_MS;
|
|
97
|
+
const root = opsOwnership.opsPath(o.projectRoot, NS);
|
|
98
|
+
let entries;
|
|
99
|
+
try { entries = fsImpl.readdirSync(root, { withFileTypes: true }); } catch { return result; }
|
|
100
|
+
for (const e of entries) {
|
|
101
|
+
if (!e.isDirectory() || e.isSymbolicLink() || !isSafeId(e.name)) continue;
|
|
102
|
+
const id = e.name;
|
|
103
|
+
let target;
|
|
104
|
+
try {
|
|
105
|
+
target = opsOwnership.opsPath(o.projectRoot, NS, id);
|
|
106
|
+
if (!isEligible({ id, dir: target, epicStatus: o.epicStatus, cutoffMs, fsImpl })) {
|
|
107
|
+
result.kept += 1;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
opsOwnership.assertOpsWrite(target, WRITER);
|
|
111
|
+
if (!o.dryRun) fsImpl.rmSync(target, { recursive: true, force: true });
|
|
112
|
+
result.removed.push(id);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
console.warn(`[planRecordRetention] keep ${id}:`, err && err.message);
|
|
115
|
+
result.kept += 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.warn('[planRecordRetention] sweep skipped:', err && err.message);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* defaultEpicStatus(projectRoot) → epicStatus(id) reading prompt-sessions/<id>.json
|
|
126
|
+
* (live mirror is flat; a completed archive nests the record under `session`).
|
|
127
|
+
* Returns null when the file is absent/unreadable or carries no status. Never throws.
|
|
128
|
+
*/
|
|
129
|
+
function defaultEpicStatus(projectRoot) {
|
|
130
|
+
return (id) => {
|
|
131
|
+
try {
|
|
132
|
+
if (!isSafeId(id)) return null;
|
|
133
|
+
const doc = readJsonOrSync(opsOwnership.opsPath(projectRoot, 'prompt-sessions', `${id}.json`), null);
|
|
134
|
+
if (!doc || typeof doc !== 'object') return null;
|
|
135
|
+
const rec = doc.session && typeof doc.session === 'object' ? doc.session : doc;
|
|
136
|
+
if (typeof rec.status !== 'string') return null;
|
|
137
|
+
return { status: rec.status, completedAt: rec.completedAt ?? null };
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = { prunePlanRecords, defaultEpicStatus };
|
|
@@ -570,6 +570,13 @@ async function writeSplit(state, defaultCwd) {
|
|
|
570
570
|
byCwd.get(cwd).push(job);
|
|
571
571
|
}
|
|
572
572
|
for (const [cwd, jobs] of byCwd) {
|
|
573
|
+
// Never materialize a missing project root: a deleted cwd remembered only
|
|
574
|
+
// as a transcript dir got {"jobs": []} recreated every reconcile pass
|
|
575
|
+
// (2026-11-22, /tmp/sm-sbx-probe-*/work + ~/.sm-sbx-chk-*/work).
|
|
576
|
+
if (typeof cwd === 'string' && path.isAbsolute(cwd) && !fs.existsSync(cwd)) {
|
|
577
|
+
console.warn('[queueStore] skip queue write for missing cwd', cwd);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
573
580
|
const file = queuePathOrSkip(cwd, 'writeSplit');
|
|
574
581
|
if (!file) continue;
|
|
575
582
|
try {
|
|
@@ -168,6 +168,26 @@ const SENTINEL_PASS_RE = /SCHEDULER_VERDICT:\s*PASS/;
|
|
|
168
168
|
const STUCK_LOOP_WINDOW = 40; // "final lines" per AC
|
|
169
169
|
const POST_AC_OVERRUN_MIN_TAIL_FRACTION = 0.3;
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* True when a log line is a stream-json result event whose `--json-schema`
|
|
173
|
+
* structured_output says schedulerVerdict PASS — judged by runVerify.cjs's
|
|
174
|
+
* scanSentinel (the one SCHEDULER_VERDICT parser). Under --json-schema the
|
|
175
|
+
* result text is the JSON string, so SENTINEL_PASS_RE never sees a PASS line.
|
|
176
|
+
*/
|
|
177
|
+
function structuredPassLine(line) {
|
|
178
|
+
if (!line.includes('"type":"result"') || !line.includes('"structured_output"')) return false;
|
|
179
|
+
try {
|
|
180
|
+
const obj = JSON.parse(line.trim());
|
|
181
|
+
const so = obj && obj.type === 'result' ? obj.structured_output : null;
|
|
182
|
+
if (!so || typeof so !== 'object' || Array.isArray(so)) return false;
|
|
183
|
+
// Lazy require: runVerify.cjs is large; only result lines pay for it.
|
|
184
|
+
const { scanSentinel } = require('../../runVerify.cjs');
|
|
185
|
+
return scanSentinel({ resultText: '', structuredOutput: so }, []) === 'pass';
|
|
186
|
+
} catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
171
191
|
/**
|
|
172
192
|
* Drop every stream-json harness init event (`"type":"system"` +
|
|
173
193
|
* `"subtype":"init"`) from a log tail. That line names every available tool
|
|
@@ -247,7 +267,7 @@ function classifyFailure({ verdict, logTail: rawLogTail }) {
|
|
|
247
267
|
});
|
|
248
268
|
if (lastAcIdx >= 0 && lines.length > 0) {
|
|
249
269
|
const tailAfterAc = lines.slice(lastAcIdx + 1);
|
|
250
|
-
const passSeenAfter = tailAfterAc.some((l) => SENTINEL_PASS_RE.test(l));
|
|
270
|
+
const passSeenAfter = tailAfterAc.some((l) => SENTINEL_PASS_RE.test(l) || structuredPassLine(l));
|
|
251
271
|
const remainingFraction = tailAfterAc.length / lines.length;
|
|
252
272
|
if (!passSeenAfter && remainingFraction > POST_AC_OVERRUN_MIN_TAIL_FRACTION) {
|
|
253
273
|
return FAILURE_CLASSES.POST_AC_OVERRUN;
|
|
@@ -289,12 +289,18 @@ function mapOutcomeToGateOutcome(outcome) {
|
|
|
289
289
|
* was stamped 'passed'). 'passed' requires the run's own LAST
|
|
290
290
|
* `SCHEDULER_VERDICT:` line to say PASS. Each line is classified by
|
|
291
291
|
* runVerify.cjs's scanSentinel (the one SCHEDULER_VERDICT parser), scanned
|
|
292
|
-
* from the end so the final say wins.
|
|
292
|
+
* from the end so the final say wins. A `--json-schema` run's
|
|
293
|
+
* structured_output.schedulerVerdict (same scanSentinel) is checked first.
|
|
293
294
|
*/
|
|
294
|
-
function lastVerdictLine(resultText) {
|
|
295
|
-
if (typeof resultText !== 'string' || !resultText) return null;
|
|
295
|
+
function lastVerdictLine(resultText, structuredOutput) {
|
|
296
296
|
// Lazy require: runVerify.cjs is a larger module; keep this lib cheap to load.
|
|
297
297
|
const { scanSentinel } = require('../../runVerify.cjs');
|
|
298
|
+
const so = structuredOf(resultText, structuredOutput);
|
|
299
|
+
if (so) {
|
|
300
|
+
const v = scanSentinel({ resultText: '', structuredOutput: so }, []);
|
|
301
|
+
if (v) return v;
|
|
302
|
+
}
|
|
303
|
+
if (typeof resultText !== 'string' || !resultText) return null;
|
|
298
304
|
const lines = resultText.split('\n');
|
|
299
305
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
300
306
|
const v = scanSentinel({ resultText: lines[i].replace(/\r$/, '') }, []);
|
|
@@ -303,11 +309,35 @@ function lastVerdictLine(resultText) {
|
|
|
303
309
|
return null;
|
|
304
310
|
}
|
|
305
311
|
|
|
306
|
-
|
|
312
|
+
/**
|
|
313
|
+
* The run's `--json-schema` structured output: the explicit object when the
|
|
314
|
+
* caller has it, else the result text parsed as a JSON object (under
|
|
315
|
+
* `--json-schema` the CLI's `result` is the structured output's string form).
|
|
316
|
+
* null for text-only runs.
|
|
317
|
+
*/
|
|
318
|
+
function structuredOf(resultText, structuredOutput) {
|
|
319
|
+
if (structuredOutput && typeof structuredOutput === 'object' && !Array.isArray(structuredOutput)) return structuredOutput;
|
|
320
|
+
if (typeof resultText !== 'string') return null;
|
|
321
|
+
const t = resultText.trim();
|
|
322
|
+
if (!t.startsWith('{')) return null;
|
|
323
|
+
try {
|
|
324
|
+
const obj = JSON.parse(t);
|
|
325
|
+
return obj && typeof obj === 'object' && !Array.isArray(obj) ? obj : null;
|
|
326
|
+
} catch {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @param {string} outcome classifyRunOutcome() result
|
|
333
|
+
* @param {string|null} resultText the last result event's `result` string
|
|
334
|
+
* @param {object|null} [structuredOutput] the last result event's `structured_output`
|
|
335
|
+
*/
|
|
336
|
+
function resolveReapGateOutcome(outcome, resultText, structuredOutput) {
|
|
307
337
|
if (outcome === 'failed') return 'failed';
|
|
308
338
|
if (outcome === 'no_result') return 'never_ran';
|
|
309
339
|
if (outcome !== 'success') return 'unknown';
|
|
310
|
-
const verdict = lastVerdictLine(resultText);
|
|
340
|
+
const verdict = lastVerdictLine(resultText, structuredOutput);
|
|
311
341
|
if (verdict === 'pass') return 'passed';
|
|
312
342
|
if (verdict === 'fail') return 'failed';
|
|
313
343
|
return 'unknown';
|