claude-code-session-manager 0.140.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--JwsFnbn.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-CALyU0pe.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-sdlA-fUb.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-CxAuwhNN.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-DtRzghn5.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-DApeu7x8.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-DtStfv1H.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-ydfnwepc.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/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +55 -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 +737 -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 +171 -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 +315 -30
- 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 +67 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +68 -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/preflightCheck.cjs +97 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +39 -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 +62 -14
- package/src/main/scheduler/reviewLadder.cjs +45 -28
- package/src/main/scheduler/starvation.cjs +69 -0
- package/src/main/scheduler/utilizationHold.cjs +101 -0
- package/src/main/scheduler.cjs +1745 -210
- package/src/main/templates/PRD_AUTHORING.md +13 -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-CMFEM68R.js +0 -2
- package/dist/assets/HomeClaudeConfig-ijEXs--3.js +0 -3
- package/dist/assets/Scheduler-YT3j8SUa.js +0 -16
- package/dist/assets/ViewTabs-B7qLXRAH.js +0 -1
- package/dist/assets/index-CtxruO1L.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -145,6 +145,40 @@ function validateGate(gate) {
|
|
|
145
145
|
return { ok: true, commands: trimmed, warnings };
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* The one per-entry `files` rule set, shared by validateFiles (create time)
|
|
150
|
+
* and parseFilesSection (read back from any PRD body, including ones written
|
|
151
|
+
* raw outside the API). `entry` must already be trimmed and non-empty.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} entry
|
|
154
|
+
* @returns {{ok:true, path:string}|{ok:false, reason:string}}
|
|
155
|
+
* path has every leading `./` stripped.
|
|
156
|
+
*/
|
|
157
|
+
function isValidFilesEntry(entry) {
|
|
158
|
+
if (typeof entry !== 'string' || entry.length === 0) return { ok: false, reason: 'must not be empty.' };
|
|
159
|
+
if (entry.length > FILES_ENTRY_MAX_CHARS) return { ok: false, reason: `must be at most ${FILES_ENTRY_MAX_CHARS} chars.` };
|
|
160
|
+
if (/[\r\n]/.test(entry)) return { ok: false, reason: 'must not contain a newline.' };
|
|
161
|
+
if (FILES_FOREIGN_WHITESPACE_RE.test(entry)) {
|
|
162
|
+
return { ok: false, reason: 'has a character that is not a plain space (for example a tab, a no-break space, or a line break). Retype it.' };
|
|
163
|
+
}
|
|
164
|
+
if (entry.includes('\\')) return { ok: false, reason: 'use "/" between folders, not "\\".' };
|
|
165
|
+
if (entry.includes('`')) return { ok: false, reason: 'must not contain a backtick.' };
|
|
166
|
+
if (entry.startsWith('-')) return { ok: false, reason: 'must not start with "-".' };
|
|
167
|
+
if (entry.startsWith('/') || entry.startsWith('~') || /^[A-Za-z]:/.test(entry)) {
|
|
168
|
+
return { ok: false, reason: 'must be repo-relative — absolute paths are not allowed.' };
|
|
169
|
+
}
|
|
170
|
+
if (entry.includes('*') || entry.includes('?')) return { ok: false, reason: 'must not contain "*" or "?" (no globs).' };
|
|
171
|
+
|
|
172
|
+
let normalized = entry;
|
|
173
|
+
while (normalized.startsWith('./')) normalized = normalized.slice(2);
|
|
174
|
+
if (normalized.length === 0) return { ok: false, reason: 'is empty after removing "./".' };
|
|
175
|
+
const segments = normalized.split('/');
|
|
176
|
+
if (segments.includes('..')) return { ok: false, reason: 'must not contain a ".." path segment.' };
|
|
177
|
+
if (segments.includes('.')) return { ok: false, reason: 'must not contain a "." path segment.' };
|
|
178
|
+
if (normalized.includes('//')) return { ok: false, reason: 'must not contain an empty path segment ("//").' };
|
|
179
|
+
return { ok: true, path: normalized };
|
|
180
|
+
}
|
|
181
|
+
|
|
148
182
|
/**
|
|
149
183
|
* Validate a PRD's `files` field.
|
|
150
184
|
*
|
|
@@ -173,50 +207,11 @@ function validateFiles(files) {
|
|
|
173
207
|
if (entry.length === 0) {
|
|
174
208
|
return { ok: false, error: `files entry ${idx}: must not be empty.` };
|
|
175
209
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (/[\r\n]/.test(entry)) {
|
|
180
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a newline.') };
|
|
181
|
-
}
|
|
182
|
-
if (FILES_FOREIGN_WHITESPACE_RE.test(entry)) {
|
|
183
|
-
return {
|
|
184
|
-
ok: false,
|
|
185
|
-
error: entryError('files', idx, entry, 'has a character that is not a plain space (for example a tab, a no-break space, or a line break). Retype it.'),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
if (entry.includes('\\')) {
|
|
189
|
-
return { ok: false, error: entryError('files', idx, entry, 'use "/" between folders, not "\\".') };
|
|
190
|
-
}
|
|
191
|
-
if (entry.includes('`')) {
|
|
192
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a backtick.') };
|
|
193
|
-
}
|
|
194
|
-
if (entry.startsWith('-')) {
|
|
195
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not start with "-".') };
|
|
196
|
-
}
|
|
197
|
-
if (entry.startsWith('/') || entry.startsWith('~') || /^[A-Za-z]:/.test(entry)) {
|
|
198
|
-
return { ok: false, error: entryError('files', idx, entry, 'must be repo-relative — absolute paths are not allowed.') };
|
|
199
|
-
}
|
|
200
|
-
if (entry.includes('*') || entry.includes('?')) {
|
|
201
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain "*" or "?" (no globs).') };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
let normalized = entry;
|
|
205
|
-
while (normalized.startsWith('./')) normalized = normalized.slice(2);
|
|
206
|
-
if (normalized.length === 0) {
|
|
207
|
-
return { ok: false, error: entryError('files', idx, entry, 'is empty after removing "./".') };
|
|
208
|
-
}
|
|
209
|
-
const segments = normalized.split('/');
|
|
210
|
-
if (segments.includes('..')) {
|
|
211
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a ".." path segment.') };
|
|
210
|
+
const checked = isValidFilesEntry(entry);
|
|
211
|
+
if (!checked.ok) {
|
|
212
|
+
return { ok: false, error: entryError('files', idx, entry, checked.reason) };
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a "." path segment.') };
|
|
215
|
-
}
|
|
216
|
-
if (normalized.includes('//')) {
|
|
217
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain an empty path segment ("//").') };
|
|
218
|
-
}
|
|
219
|
-
|
|
214
|
+
const normalized = checked.path;
|
|
220
215
|
if (!seen.has(normalized)) {
|
|
221
216
|
seen.add(normalized);
|
|
222
217
|
out.push(normalized);
|
|
@@ -247,8 +242,10 @@ function renderFilesSection(files) {
|
|
|
247
242
|
/**
|
|
248
243
|
* Inverse of renderFilesSection: read the bullet entries under the `# Files`
|
|
249
244
|
* heading (up to the next top-level heading) back out of a PRD body. Returns
|
|
250
|
-
* [] when there is no such section
|
|
251
|
-
*
|
|
245
|
+
* [] when there is no such section; never throws. Each bullet keeps only the
|
|
246
|
+
* paths that pass isValidFilesEntry (see parseFilesEntry) — a trailing note
|
|
247
|
+
* is cut off, a ", " list is split, prose and invalid bullets are dropped,
|
|
248
|
+
* duplicates removed.
|
|
252
249
|
*
|
|
253
250
|
* @param {string} body
|
|
254
251
|
* @returns {string[]}
|
|
@@ -266,14 +263,92 @@ function parseFilesSection(body) {
|
|
|
266
263
|
if (!inFence && /^#\s/.test(line)) break;
|
|
267
264
|
const m = line.match(/^[-*]\s+(.+?)\s*$/);
|
|
268
265
|
if (!m) continue;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (entry && !out.includes(entry)) out.push(entry);
|
|
266
|
+
for (const entry of parseFilesEntry(m[1])) {
|
|
267
|
+
if (!out.includes(entry)) out.push(entry);
|
|
268
|
+
}
|
|
273
269
|
}
|
|
274
270
|
return out;
|
|
275
271
|
}
|
|
276
272
|
|
|
273
|
+
const unwrapTicks = (s) => { const t = s.match(/^`([^`]+)`$/); return (t ? t[1] : s).trim(); };
|
|
274
|
+
|
|
275
|
+
// Separators a `# Files` bullet uses between a path and a note (or, for
|
|
276
|
+
// ", ", between two paths). Matched only when what comes before is a path.
|
|
277
|
+
const FILES_NOTE_SEPARATORS = [' (', ' - ', ' — ', ': ', ', '];
|
|
278
|
+
|
|
279
|
+
/** The validated path when `s` is a valid entry ending in a file extension or "/", else null. */
|
|
280
|
+
function pathLikePrefix(s) {
|
|
281
|
+
const lead = unwrapTicks(s);
|
|
282
|
+
if (!lead) return null;
|
|
283
|
+
const checked = isValidFilesEntry(lead);
|
|
284
|
+
if (!checked.ok) return null;
|
|
285
|
+
return /\.[A-Za-z0-9]+$/.test(checked.path) || checked.path.endsWith('/') ? checked.path : null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Note separators (", " excluded — it lists paths, never a note).
|
|
289
|
+
const FILES_WHOLE_TIEBREAK_SEPARATORS = FILES_NOTE_SEPARATORS.filter((sep) => sep !== ', ');
|
|
290
|
+
|
|
291
|
+
/** True when `text` has no note separator, or the text after its earliest one is a single whitespace-free token. */
|
|
292
|
+
function isSingleTokenRemainder(text) {
|
|
293
|
+
let earliest = null;
|
|
294
|
+
for (const sep of FILES_WHOLE_TIEBREAK_SEPARATORS) {
|
|
295
|
+
const at = text.indexOf(sep);
|
|
296
|
+
if (at > 0 && (earliest === null || at < earliest.at)) earliest = { at, sep };
|
|
297
|
+
}
|
|
298
|
+
if (earliest === null) return true;
|
|
299
|
+
const rest = text.slice(earliest.at + earliest.sep.length);
|
|
300
|
+
return rest.length > 0 && !/\s/.test(rest);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* One `# Files` bullet's text -> the paths it names ([] when none). An
|
|
305
|
+
* entry with no ", " that is itself a path (valid, ending in a file
|
|
306
|
+
* extension or "/") is kept whole first, but only when the text after its
|
|
307
|
+
* earliest note separator (" (", " - ", " — ", ": ") is one whitespace-free
|
|
308
|
+
* token — more than one word there is a note. Otherwise walks
|
|
309
|
+
* every separator occurrence (" (", " - ", " — ", ": ", ", ") left to right
|
|
310
|
+
* and splits at the first whose prefix is a path (valid entry ending in a
|
|
311
|
+
* file extension or "/"): after ", " the rest is parsed again as more
|
|
312
|
+
* entries; after any other separator the rest is a note and dropped. With no
|
|
313
|
+
* such split, the whole (unwrapped) entry is kept when it passes
|
|
314
|
+
* isValidFilesEntry — so a spaced path like "docs/A - B.md" round-trips. A
|
|
315
|
+
* whole entry with a space must still look like a path (contain "/", not end
|
|
316
|
+
* in sentence punctuation) — the API allows spaced paths, but a spaced entry
|
|
317
|
+
* with neither is prose.
|
|
318
|
+
*
|
|
319
|
+
* @param {string} raw
|
|
320
|
+
* @returns {string[]}
|
|
321
|
+
*/
|
|
322
|
+
function parseFilesEntry(raw) {
|
|
323
|
+
const text = unwrapTicks(String(raw).trim());
|
|
324
|
+
if (!text) return [];
|
|
325
|
+
// A whole entry that is itself a path wins over a note split only when the
|
|
326
|
+
// text after its earliest note separator is one whitespace-free token, so
|
|
327
|
+
// "docs/v1.2 - notes.md" is not cut to "docs/v1.2" but "src/a.cjs -
|
|
328
|
+
// renamed from old.cjs" is a note. A ", " list still splits:
|
|
329
|
+
// "src/a.cjs, src/b.cjs" is two paths, not one spaced name.
|
|
330
|
+
if (!text.includes(', ')) {
|
|
331
|
+
const whole = pathLikePrefix(text);
|
|
332
|
+
if (whole && isSingleTokenRemainder(text)) return [whole];
|
|
333
|
+
}
|
|
334
|
+
/** @type {{at:number, sep:string}[]} */
|
|
335
|
+
const hits = [];
|
|
336
|
+
for (const sep of FILES_NOTE_SEPARATORS) {
|
|
337
|
+
for (let at = text.indexOf(sep); at > 0; at = text.indexOf(sep, at + 1)) hits.push({ at, sep });
|
|
338
|
+
}
|
|
339
|
+
hits.sort((a, b) => a.at - b.at);
|
|
340
|
+
for (const { at, sep } of hits) {
|
|
341
|
+
const lead = pathLikePrefix(text.slice(0, at));
|
|
342
|
+
if (!lead) continue;
|
|
343
|
+
if (sep !== ', ') return [lead];
|
|
344
|
+
return [lead, ...parseFilesEntry(text.slice(at + sep.length))];
|
|
345
|
+
}
|
|
346
|
+
const checked = isValidFilesEntry(text);
|
|
347
|
+
if (!checked.ok) return [];
|
|
348
|
+
if (/\s/.test(checked.path) && (!checked.path.includes('/') || /[.,:;!?)]$/.test(checked.path))) return [];
|
|
349
|
+
return [checked.path];
|
|
350
|
+
}
|
|
351
|
+
|
|
277
352
|
/**
|
|
278
353
|
* Render the `# Gate` body section as an array of lines. `commandsOrNone`
|
|
279
354
|
* must already be validated (validateGate's `commands` output) — either
|
|
@@ -307,6 +382,7 @@ function renderGateSection(commandsOrNone) {
|
|
|
307
382
|
}
|
|
308
383
|
|
|
309
384
|
module.exports = {
|
|
385
|
+
NONE_GATE_WARNING,
|
|
310
386
|
validateGate,
|
|
311
387
|
validateFiles,
|
|
312
388
|
renderFilesSection,
|
|
@@ -35,7 +35,9 @@ function sizingWarnings(input) {
|
|
|
35
35
|
|
|
36
36
|
const warnings = [];
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
// A validator PRD's criteria list one check per PRD in its plan, so a long
|
|
39
|
+
// list is expected; every other sizing rule still applies to it.
|
|
40
|
+
if (input?.agentType !== 'validator' && acceptanceCriteria.length > SIZING_LIMITS.acLines) {
|
|
39
41
|
warnings.push(
|
|
40
42
|
`acceptanceCriteria has ${acceptanceCriteria.length} lines, exceeding the ${SIZING_LIMITS.acLines}-line sizing limit — split into smaller, single-purpose PRDs.`,
|
|
41
43
|
);
|
|
@@ -102,4 +102,55 @@ function cleanChildEnv(extra = {}) {
|
|
|
102
102
|
return env;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/**
|
|
106
|
+
* The ONLY spawn sites allowed to hand a headless child an env that still
|
|
107
|
+
* carries secret-shaped keys. Both are internal one-shot `claude -p` helpers
|
|
108
|
+
* that deliberately inherit process.env verbatim (withProcRole, not
|
|
109
|
+
* cleanChildEnv). Adding an entry is a deliberate security decision.
|
|
110
|
+
*/
|
|
111
|
+
const CREDENTIAL_EXCEPTIONS = Object.freeze([
|
|
112
|
+
Object.freeze({ site: 'runClaudeP', reason: 'internal one-shot aux claude -p (no tools beyond its sandbox, --strict-mcp-config); inherits process.env so the CLI auth env it was launched with keeps working' }),
|
|
113
|
+
Object.freeze({ site: 'docEdit', reason: 'internal one-shot aux claude -p that rewrites a doc the user asked to edit; inherits process.env for the same CLI-auth reason as runClaudeP' }),
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
/** Spawn sites that must pass a credential-free env. */
|
|
117
|
+
const CREDENTIAL_CHECKED_SITES = Object.freeze(['scheduler-job', 'task', 'chat', 'chat-agent']);
|
|
118
|
+
|
|
119
|
+
/** Secret-shaped keys (SECRET_KEY_RE) present in env with a non-empty value. */
|
|
120
|
+
function credentialKeys(env) {
|
|
121
|
+
return Object.keys(env || {}).filter((k) => SECRET_KEY_RE.test(k) && env[k] !== undefined && env[k] !== null && env[k] !== '');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Spawn-time assertion: throw if `env` carries any key matching
|
|
126
|
+
* SECRET_KEY_RE. The error names each offending key, never its value.
|
|
127
|
+
* `site` must be a known spawn site: an exception site passes unchecked, a
|
|
128
|
+
* checked site is scanned, and an unknown site is refused outright.
|
|
129
|
+
* @param {Record<string, any>} env
|
|
130
|
+
* @param {{ site: string }} opts
|
|
131
|
+
*/
|
|
132
|
+
function assertNoCredentials(env, opts) {
|
|
133
|
+
const site = opts && typeof opts.site === 'string' ? opts.site : '';
|
|
134
|
+
if (CREDENTIAL_EXCEPTIONS.some((e) => e.site === site)) return;
|
|
135
|
+
if (!CREDENTIAL_CHECKED_SITES.includes(site)) {
|
|
136
|
+
const err = /** @type {Error & { code?: string }} */ (new Error(`assertNoCredentials: unknown spawn site ${JSON.stringify(site)} — refused`));
|
|
137
|
+
err.code = 'credential_site_unknown';
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
const keys = credentialKeys(env);
|
|
141
|
+
if (keys.length) {
|
|
142
|
+
const err = /** @type {Error & { code?: string, keys?: string[] }} */ (new Error(`assertNoCredentials: ${site} env carries credential keys: ${keys.join(', ')} — refused`));
|
|
143
|
+
err.code = 'credentials_in_env';
|
|
144
|
+
err.keys = keys;
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Copy of env with every SECRET_KEY_RE key removed. */
|
|
150
|
+
function stripCredentials(env) {
|
|
151
|
+
const out = { ...(env || {}) };
|
|
152
|
+
for (const k of Object.keys(out)) if (SECRET_KEY_RE.test(k)) delete out[k];
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = { cleanChildEnv, assertNoCredentials, stripCredentials, CREDENTIAL_EXCEPTIONS, CREDENTIAL_CHECKED_SITES, SECRET_KEY_RE, withProcRole, inferProcRole, PROC_ROLE_ENV, userBinDirs, pathWithUserBins };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* leftoverRenice.cjs — lower leftover chat/aux tool processes to idle priority.
|
|
5
|
+
*
|
|
6
|
+
* 2026-11-23: a Chatterbox voice render started by a one-shot Burrow chat turn
|
|
7
|
+
* kept running after the turn ended (its `claude` process gone, parent bash
|
|
8
|
+
* reparented to pid 1) and used 8 cores for 40+ minutes at the app's nice 12,
|
|
9
|
+
* so the CPU load gate held every scheduler job. Evidence: pid 2893850
|
|
10
|
+
* `/tmp/cbtest/bin/python /tmp/cb-script/takes.py`, SM_PROC_ROLE=chat,
|
|
11
|
+
* CLAUDE_PID=2858266 (gone).
|
|
12
|
+
*
|
|
13
|
+
* A leftover = a process of THIS user whose environment carries
|
|
14
|
+
* SM_PROC_ROLE=chat|aux AND a CLAUDE_PID whose process no longer exists. Such a
|
|
15
|
+
* process is set to nice 19 (never killed — its output may be wanted); the CPU
|
|
16
|
+
* sampler (cpuSample.cjs, PRD 4021) then stops counting it as load.
|
|
17
|
+
*
|
|
18
|
+
* - A process with no CLAUDE_PID (e.g. the chat's own `claude`) is never a
|
|
19
|
+
* leftover: there is no turn to judge it by.
|
|
20
|
+
* - Raising one's own process niceness needs no privileges; lowering it would.
|
|
21
|
+
* - A process whose CLAUDE_PID equals the one the app itself inherited at
|
|
22
|
+
* startup (app launched from inside a claude session) is never a leftover:
|
|
23
|
+
* every chat process carries that value, so it says nothing about the turn.
|
|
24
|
+
* - Only /proc/<pid>/status (Uid) and /proc/<pid>/environ are read; from
|
|
25
|
+
* environ only SM_PROC_ROLE and CLAUDE_PID are kept.
|
|
26
|
+
* - A scan reads at most MAX_SCAN pids, skips unreadable entries, never throws,
|
|
27
|
+
* and never sends a signal.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const fs = require('node:fs');
|
|
31
|
+
const os = require('node:os');
|
|
32
|
+
const path = require('node:path');
|
|
33
|
+
const { pidAlive } = require('./pidAlive.cjs');
|
|
34
|
+
|
|
35
|
+
const MAX_SCAN = 4000;
|
|
36
|
+
const IDLE_NICE = 19;
|
|
37
|
+
const LEFTOVER_ROLES = new Set(['chat', 'aux']);
|
|
38
|
+
|
|
39
|
+
/** CLAUDE_PID the app main process inherited, read once at module load. */
|
|
40
|
+
const APP_CLAUDE_PID = parseEnviron(`CLAUDE_PID=${process.env.CLAUDE_PID ?? ''}`).claudePid;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Pick SM_PROC_ROLE and CLAUDE_PID out of NUL-separated environ text.
|
|
44
|
+
* @param {string} text
|
|
45
|
+
* @returns {{ role: string | null, claudePid: number | null }}
|
|
46
|
+
*/
|
|
47
|
+
function parseEnviron(text) {
|
|
48
|
+
let role = null;
|
|
49
|
+
let claudePid = null;
|
|
50
|
+
if (typeof text !== 'string') return { role, claudePid };
|
|
51
|
+
for (const entry of text.split('\0')) {
|
|
52
|
+
if (entry.startsWith('SM_PROC_ROLE=')) role = entry.slice('SM_PROC_ROLE='.length);
|
|
53
|
+
else if (entry.startsWith('CLAUDE_PID=')) {
|
|
54
|
+
const raw = entry.slice('CLAUDE_PID='.length);
|
|
55
|
+
const n = /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
56
|
+
claudePid = Number.isInteger(n) ? n : null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { role, claudePid };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Real uid from /proc/<pid>/status text, or null.
|
|
64
|
+
* @param {string} text
|
|
65
|
+
*/
|
|
66
|
+
function parseStatusUid(text) {
|
|
67
|
+
if (typeof text !== 'string') return null;
|
|
68
|
+
const m = /^Uid:\s+(\d+)/m.exec(text);
|
|
69
|
+
return m ? Number(m[1]) : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function currentUid() {
|
|
73
|
+
return typeof process.getuid === 'function' ? process.getuid() : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Leftover processes (see header). Never throws; [] off Linux-like hosts.
|
|
78
|
+
* @param {{ procRoot?: string, uid?: number | null, maxPids?: number,
|
|
79
|
+
* readdir?: (p: string) => string[], readFile?: (p: string) => string,
|
|
80
|
+
* isAlive?: (pid: number) => boolean, selfPid?: number,
|
|
81
|
+
* appClaudePid?: number | null }} [opts]
|
|
82
|
+
* @returns {{ pid: number, role: string, claudePid: number }[]}
|
|
83
|
+
*/
|
|
84
|
+
function findLeftovers({
|
|
85
|
+
procRoot = '/proc',
|
|
86
|
+
uid = currentUid(),
|
|
87
|
+
maxPids = MAX_SCAN,
|
|
88
|
+
readdir = (p) => fs.readdirSync(p),
|
|
89
|
+
readFile = (p) => fs.readFileSync(p, 'latin1'),
|
|
90
|
+
isAlive,
|
|
91
|
+
selfPid = process.pid,
|
|
92
|
+
appClaudePid = APP_CLAUDE_PID,
|
|
93
|
+
} = {}) {
|
|
94
|
+
if (uid === null || uid === undefined) return [];
|
|
95
|
+
// Under an injected tree a pid is alive when its directory exists there.
|
|
96
|
+
const alive = isAlive || (procRoot === '/proc'
|
|
97
|
+
? pidAlive
|
|
98
|
+
: (/** @type {number} */ pid) => {
|
|
99
|
+
try { return fs.existsSync(path.join(procRoot, String(pid))); } catch { return false; }
|
|
100
|
+
});
|
|
101
|
+
/** @type {{ pid: number, role: string, claudePid: number }[]} */
|
|
102
|
+
const out = [];
|
|
103
|
+
let names;
|
|
104
|
+
try { names = readdir(procRoot); } catch { return out; }
|
|
105
|
+
if (!Array.isArray(names)) return out;
|
|
106
|
+
let scanned = 0;
|
|
107
|
+
for (const name of names) {
|
|
108
|
+
if (!/^\d+$/.test(name)) continue;
|
|
109
|
+
if (scanned >= maxPids) break;
|
|
110
|
+
scanned += 1;
|
|
111
|
+
const pid = Number(name);
|
|
112
|
+
if (pid === selfPid || pid <= 1) continue;
|
|
113
|
+
try {
|
|
114
|
+
if (parseStatusUid(readFile(path.join(procRoot, name, 'status'))) !== uid) continue;
|
|
115
|
+
const { role, claudePid } = parseEnviron(readFile(path.join(procRoot, name, 'environ')));
|
|
116
|
+
if (!role || !LEFTOVER_ROLES.has(role)) continue;
|
|
117
|
+
if (claudePid === null || claudePid <= 1) continue;
|
|
118
|
+
if (appClaudePid !== null && appClaudePid !== undefined && claudePid === appClaudePid) continue;
|
|
119
|
+
if (alive(claudePid)) continue;
|
|
120
|
+
out.push({ pid, role, claudePid });
|
|
121
|
+
} catch {
|
|
122
|
+
// Unreadable or vanished entry: skip it.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Pids already logged, so each leftover is reported once. */
|
|
129
|
+
const logged = new Set();
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Set every leftover to nice 19 and log each pid once. Never throws, never
|
|
133
|
+
* sends a signal. Returns the pids reniced this call.
|
|
134
|
+
* @param {Parameters<typeof findLeftovers>[0] & {
|
|
135
|
+
* setPriority?: (pid: number, prio: number) => void,
|
|
136
|
+
* getPriority?: (pid: number) => number,
|
|
137
|
+
* log?: (msg: string) => void, seen?: Set<number> }} [opts]
|
|
138
|
+
* @returns {number[]}
|
|
139
|
+
*/
|
|
140
|
+
function reniceLeftovers(opts = {}) {
|
|
141
|
+
const {
|
|
142
|
+
setPriority = (pid, prio) => os.setPriority(pid, prio),
|
|
143
|
+
getPriority = (pid) => os.getPriority(pid),
|
|
144
|
+
log = (msg) => console.log(msg),
|
|
145
|
+
seen = logged,
|
|
146
|
+
...findOpts
|
|
147
|
+
} = opts;
|
|
148
|
+
/** @type {number[]} */
|
|
149
|
+
const done = [];
|
|
150
|
+
try {
|
|
151
|
+
const leftovers = findLeftovers(findOpts);
|
|
152
|
+
const current = new Set();
|
|
153
|
+
for (const l of leftovers) {
|
|
154
|
+
current.add(l.pid);
|
|
155
|
+
try {
|
|
156
|
+
let prio = null;
|
|
157
|
+
try { prio = getPriority(l.pid); } catch { prio = null; }
|
|
158
|
+
if (prio !== IDLE_NICE) {
|
|
159
|
+
setPriority(l.pid, IDLE_NICE);
|
|
160
|
+
done.push(l.pid);
|
|
161
|
+
}
|
|
162
|
+
if (!seen.has(l.pid)) {
|
|
163
|
+
seen.add(l.pid);
|
|
164
|
+
log(`[leftoverRenice] pid ${l.pid} (SM_PROC_ROLE=${l.role}, CLAUDE_PID ${l.claudePid} gone) set to nice ${IDLE_NICE}`);
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
// Vanished, or not ours after all: leave it.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Forget pids that are no longer leftovers so a reused pid logs again.
|
|
171
|
+
for (const pid of seen) if (!current.has(pid)) seen.delete(pid);
|
|
172
|
+
} catch {
|
|
173
|
+
// Never throws.
|
|
174
|
+
}
|
|
175
|
+
return done;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = { findLeftovers, APP_CLAUDE_PID, reniceLeftovers, parseEnviron, parseStatusUid, MAX_SCAN, IDLE_NICE };
|
|
@@ -19,6 +19,13 @@ const DEFAULT_MAX_FRACTION = 0.45;
|
|
|
19
19
|
const HIGH_FRACTION = 0.85;
|
|
20
20
|
const DEFAULT_SWAP_MAX_MB = 4096;
|
|
21
21
|
|
|
22
|
+
// Fixed caps for every scheduler job's scope. MemoryHigh throttles (reclaim
|
|
23
|
+
// pressure) above 6 GB; MemoryMax OOM-kills inside the scope at 10 GB. The
|
|
24
|
+
// largest recorded job peak is 9,142 MB, so 10 GB kills only true runaways —
|
|
25
|
+
// what makes the lower per-job reservations in the memory gate safe.
|
|
26
|
+
const JOB_MEMORY_HIGH_MB = 6144;
|
|
27
|
+
const JOB_MEMORY_MAX_MB = 10240;
|
|
28
|
+
|
|
22
29
|
/**
|
|
23
30
|
* @param {{ totalRamMb?: number, env?: Record<string, string | undefined> }} [opts]
|
|
24
31
|
* @returns {{ memoryMaxMb: number, memoryHighMb: number, swapMaxMb: number } | null} null = disabled
|
|
@@ -42,6 +49,24 @@ function memoryLimitsFor(opts = {}) {
|
|
|
42
49
|
};
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Limits for a scheduler job's scope: JOB_MEMORY_HIGH_MB / JOB_MEMORY_MAX_MB.
|
|
54
|
+
* SM_JOB_MEMORY_MAX_MB still overrides (0 disables), via memoryLimitsFor.
|
|
55
|
+
* @param {{ env?: Record<string, string | undefined> }} [opts]
|
|
56
|
+
* @returns {{ memoryMaxMb: number, memoryHighMb: number, swapMaxMb: number } | null}
|
|
57
|
+
*/
|
|
58
|
+
function schedulerJobMemoryLimits(opts = {}) {
|
|
59
|
+
const env = opts.env || process.env;
|
|
60
|
+
const raw = env.SM_JOB_MEMORY_MAX_MB;
|
|
61
|
+
if (raw !== undefined && raw !== '') return memoryLimitsFor({ env });
|
|
62
|
+
return { memoryMaxMb: JOB_MEMORY_MAX_MB, memoryHighMb: JOB_MEMORY_HIGH_MB, swapMaxMb: DEFAULT_SWAP_MAX_MB };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** systemd size: whole GiB as `<n>G`, otherwise `<n>M`. @param {number} mb */
|
|
66
|
+
function sizeArg(mb) {
|
|
67
|
+
return mb > 0 && mb % 1024 === 0 ? `${mb / 1024}G` : `${mb}M`;
|
|
68
|
+
}
|
|
69
|
+
|
|
45
70
|
/** @type {boolean | null} */
|
|
46
71
|
let cachedSupport = null;
|
|
47
72
|
|
|
@@ -100,9 +125,9 @@ function wrapInMemoryScope(o) {
|
|
|
100
125
|
'--quiet',
|
|
101
126
|
'--collect',
|
|
102
127
|
`--unit=${sanitizeUnit(unit)}.scope`,
|
|
103
|
-
'-p', `MemoryHigh=${limits.memoryHighMb}
|
|
104
|
-
'-p', `MemoryMax=${limits.memoryMaxMb}
|
|
105
|
-
'-p', `MemorySwapMax=${limits.swapMaxMb}
|
|
128
|
+
'-p', `MemoryHigh=${sizeArg(limits.memoryHighMb)}`,
|
|
129
|
+
'-p', `MemoryMax=${sizeArg(limits.memoryMaxMb)}`,
|
|
130
|
+
'-p', `MemorySwapMax=${sizeArg(limits.swapMaxMb)}`,
|
|
106
131
|
'-p', 'OOMPolicy=continue',
|
|
107
132
|
'--',
|
|
108
133
|
command,
|
|
@@ -131,7 +156,10 @@ function stopScope(unit, deps = {}) {
|
|
|
131
156
|
}
|
|
132
157
|
|
|
133
158
|
module.exports = {
|
|
159
|
+
JOB_MEMORY_HIGH_MB,
|
|
160
|
+
JOB_MEMORY_MAX_MB,
|
|
134
161
|
memoryLimitsFor,
|
|
162
|
+
schedulerJobMemoryLimits,
|
|
135
163
|
scopeSupported,
|
|
136
164
|
wrapInMemoryScope,
|
|
137
165
|
stopScope,
|
|
@@ -17,6 +17,7 @@ const crypto = require('node:crypto');
|
|
|
17
17
|
const config = require('../../config.cjs');
|
|
18
18
|
const { opsPath, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
19
19
|
const { injectPlayerBridge } = require('./playerBridge.cjs');
|
|
20
|
+
const { readCharacter } = require('../demo-video-kit/character.cjs');
|
|
20
21
|
|
|
21
22
|
const WRITER = 'project-home';
|
|
22
23
|
const MAX_ENTRIES = 500;
|
|
@@ -57,10 +58,62 @@ async function readEntry(kind, dir, id) {
|
|
|
57
58
|
} catch (e) {
|
|
58
59
|
error = oneLine(e && e.code === 'ENOENT' ? 'meta.json missing' : `meta.json unreadable: ${e && e.message}`);
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
const entry = { id, path: file, mtimeMs: st.mtimeMs, meta, error };
|
|
62
|
+
if (kind === 'videos') entry.exports = await readExports(dir);
|
|
63
|
+
return entry;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
/** Absolute path of `file` when it exists as a regular file, else null. */
|
|
67
|
+
async function fileOrNull(file) {
|
|
68
|
+
try {
|
|
69
|
+
return (await fsp.stat(file)).isFile() ? file : null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Fixed names the save route writes: video.mp4 + poster.png. */
|
|
76
|
+
async function readExports(dir) {
|
|
77
|
+
const [mp4, poster] = await Promise.all([
|
|
78
|
+
fileOrNull(path.join(dir, 'video.mp4')),
|
|
79
|
+
fileOrNull(path.join(dir, 'poster.png')),
|
|
80
|
+
]);
|
|
81
|
+
return { mp4, poster };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** -> { name } when videos/_character holds a valid character, else null. Never throws. */
|
|
85
|
+
function readPersona(realCwd) {
|
|
86
|
+
try {
|
|
87
|
+
const c = readCharacter(realCwd);
|
|
88
|
+
return c ? { name: c.json.name } : null;
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The only outcome a run may record instead of a video (projectHomeAdminRoutes.cjs VIDEO_OUTCOMES). */
|
|
95
|
+
const VIDEO_OUTCOMES = new Set(['season-complete']);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* -> { id, outcome, text, at } from videos/<id>/outcome.json (written by
|
|
99
|
+
* project_video_outcome_write), or null when absent, unreadable or invalid. Never throws.
|
|
100
|
+
*/
|
|
101
|
+
async function readOutcome(dir, id) {
|
|
102
|
+
let rec;
|
|
103
|
+
try {
|
|
104
|
+
rec = JSON.parse(await fsp.readFile(path.join(dir, 'outcome.json'), 'utf8'));
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (!rec || typeof rec !== 'object' || Array.isArray(rec)) return null;
|
|
109
|
+
const { outcome, text, at } = rec;
|
|
110
|
+
if (rec.id !== id || !VIDEO_OUTCOMES.has(outcome)) return null;
|
|
111
|
+
if (typeof text !== 'string' || !text.trim() || typeof at !== 'string' || !Number.isFinite(Date.parse(at))) return null;
|
|
112
|
+
return { id, outcome, text, at };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Lists one kind's entries; for videos, folders with no index.html but a valid outcome.json go to `outcomes`. */
|
|
116
|
+
async function listKind(realCwd, kind, outcomes = []) {
|
|
64
117
|
const root = pagesPath(realCwd, kind);
|
|
65
118
|
if (!root) return [];
|
|
66
119
|
let dirents;
|
|
@@ -71,7 +124,15 @@ async function listKind(realCwd, kind) {
|
|
|
71
124
|
throw e;
|
|
72
125
|
}
|
|
73
126
|
const dirs = dirents.filter((d) => d.isDirectory() && !SKIP_DIRS.has(d.name)).slice(0, MAX_ENTRIES);
|
|
74
|
-
const
|
|
127
|
+
const read = await Promise.all(dirs.map((d) => readEntry(kind, path.join(root, d.name), d.name)));
|
|
128
|
+
if (kind === 'videos') {
|
|
129
|
+
const found = await Promise.all(
|
|
130
|
+
dirs.map((d, i) => (read[i] ? null : readOutcome(path.join(root, d.name), d.name))),
|
|
131
|
+
);
|
|
132
|
+
for (const o of found) if (o) outcomes.push(o);
|
|
133
|
+
outcomes.sort((a, b) => Date.parse(b.at) - Date.parse(a.at));
|
|
134
|
+
}
|
|
135
|
+
const entries = read.filter(Boolean);
|
|
75
136
|
const stamp = (e) => {
|
|
76
137
|
const t = e.meta ? Date.parse(e.meta.createdAt) : NaN;
|
|
77
138
|
return Number.isFinite(t) ? t : e.mtimeMs;
|
|
@@ -79,10 +140,15 @@ async function listKind(realCwd, kind) {
|
|
|
79
140
|
return entries.sort((a, b) => stamp(b) - stamp(a));
|
|
80
141
|
}
|
|
81
142
|
|
|
82
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* -> { knowledge: Entry[], videos: Entry[] (with exports), persona: {name}|null,
|
|
145
|
+
* outcomes: {id, outcome, text, at}[] (video folders with an outcome and no index.html) }, newest first.
|
|
146
|
+
*/
|
|
83
147
|
async function listLibrary(realCwd) {
|
|
84
|
-
const
|
|
85
|
-
|
|
148
|
+
const outcomes = [];
|
|
149
|
+
const [knowledge, videos] = await Promise.all(KINDS.map((k) => listKind(realCwd, k, outcomes)));
|
|
150
|
+
const persona = pagesPath(realCwd) ? readPersona(realCwd) : null;
|
|
151
|
+
return { knowledge, videos, persona, outcomes };
|
|
86
152
|
}
|
|
87
153
|
|
|
88
154
|
/** Write `outBuf` into `destDir/index.html` + meta; true only after a byte-equal verified write. */
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* videoReviewIpc.cjs — IPC handlers `project-videos:review-list`,
|
|
5
5
|
* `project-videos:review-decide` and `project-videos:review-retry`: the human
|
|
6
|
-
* review step of a project Video
|
|
7
|
-
*
|
|
6
|
+
* review step of a project Video tool entry or a built-in Demo Video entry
|
|
7
|
+
* (dispatch.macroId 'builtin-demo-video') — decide/retry re-dispatch whatever
|
|
8
|
+
* macroId dispatch.json recorded, with no tool lookup of their own. Renderer IPC only — no admin route or MCP tool reaches a
|
|
8
9
|
* decision, and nothing here mints an Epic.
|
|
9
10
|
*
|
|
10
11
|
* approve — starts the tool's final run in the Epic that built the entry
|