claude-code-session-manager 0.141.0 → 0.143.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +76 -153
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
- package/dist/assets/Scheduler-CNLjn90m.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/Toggle-CYajnSdx.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/index-CdTppjKR.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 +6 -4
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- 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 +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +2 -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 +1032 -112
- package/src/main/adminRouteRegistry.cjs +69 -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 +336 -23
- package/src/main/config.cjs +35 -1
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +129 -2
- package/src/main/index.cjs +110 -52
- package/src/main/ipcSchemas.cjs +172 -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 +52 -0
- package/src/main/lib/demo-video-kit/character.cjs +778 -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 +103 -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/projectSounds.cjs +191 -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/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- 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/activeIndexMerge.cjs +5 -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 +356 -0
- package/src/main/lib/epic/artifactStore.cjs +435 -0
- package/src/main/lib/epic/delegationReadiness.cjs +83 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +258 -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/epicStateEmitter.cjs +248 -0
- 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 +94 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +48 -4
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
- 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 +32 -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 +207 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- 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/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +182 -4
- package/src/main/lib/mcpToolCatalog.cjs +399 -29
- package/src/main/lib/opsOwnership.cjs +141 -28
- 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 +309 -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 +387 -228
- package/src/main/lib/prd/prdCriteria.cjs +228 -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/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/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 +313 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -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 +9 -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 +251 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
- package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
- package/src/main/lib/tasks/mitigationReview.cjs +314 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
- 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 +204 -6
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- 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/atomicFs.cjs +2 -2
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +21 -1
- package/src/main/pty.cjs +77 -0
- package/src/main/queueOps.cjs +33 -14
- 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 +191 -0
- package/src/main/scheduler.cjs +1932 -213
- package/src/main/templates/PRD_AUTHORING.md +11 -3
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +576 -39
- package/src/preload/apiSurface.json +223 -7
- package/src/preload/index.cjs +48 -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 +98 -87
- 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 +23 -23
- 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
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* cache is module-private and keyed by absolute file path.
|
|
7
7
|
*
|
|
8
8
|
* Two-level cache for reconcile():
|
|
9
|
-
* - dirCache:
|
|
9
|
+
* - dirCache: per prds/ dir path → { mtimeMs, files } — invalidated when that
|
|
10
|
+
* dir's files are added/removed. Keyed by path because scheduler.cjs scans
|
|
11
|
+
* every Epic prds/ dir in parallel and dirs often share one mtime tick.
|
|
10
12
|
* - fileCache: per-PRD parse keyed by individual file mtimeMs — survives across
|
|
11
13
|
* dir-cache invalidations so adding ONE new PRD doesn't re-parse the other 197.
|
|
12
14
|
* Both layers also bound by ino so a rename + re-create can't alias.
|
|
@@ -21,6 +23,7 @@ const { splitFrontmatter, parseInlineList, parseFixes, parsePreflightValue, PRD_
|
|
|
21
23
|
const { deriveEpicIdFromPrdPath } = require('../lib/prd/prdLocations.cjs');
|
|
22
24
|
const { parseFilesSection } = require('../lib/prd/prdGateFiles.cjs');
|
|
23
25
|
const { reportDanglingAgentTypeOnce } = require('../lib/prd/prdAgentType.cjs');
|
|
26
|
+
const { VOICE_ID_RE } = require('../lib/demo-video-kit/voiceLibrary.cjs');
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Expand a PRD `cwd` value to an absolute path.
|
|
@@ -41,8 +44,7 @@ function expandCwd(cwd) {
|
|
|
41
44
|
// already ~25k lines and well beyond any legitimate authored doc.
|
|
42
45
|
const PRD_READ_MAX_BYTES = 1024 * 1024;
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
let prdDirFiles = null; // sorted absolute paths
|
|
47
|
+
const prdDirCache = new Map(); // prdsDir -> { mtimeMs, files } (files = sorted absolute paths)
|
|
46
48
|
const prdFileCache = new Map(); // path -> { mtimeMs, ino, parsed }
|
|
47
49
|
|
|
48
50
|
/**
|
|
@@ -153,6 +155,8 @@ async function parsePrdRaw(filePath) {
|
|
|
153
155
|
deliverable: (typeof fm.deliverable === 'string' && fm.deliverable.trim() === 'artifact') ? 'artifact' : null,
|
|
154
156
|
artifactPaths: parseArtifactPaths(fm.artifactPaths),
|
|
155
157
|
effort: (typeof fm.effort === 'string' && PRD_EFFORT_LEVELS.includes(fm.effort.trim())) ? fm.effort.trim() : null,
|
|
158
|
+
// In-process-only library voice (voiceLibrary.cjs VOICE_ID_RE); executeJob hands it to the job as SM_VOICE_ID.
|
|
159
|
+
voiceId: (typeof fm.voiceId === 'string' && VOICE_ID_RE.test(fm.voiceId.trim())) ? fm.voiceId.trim() : null,
|
|
156
160
|
// Optional precondition command (preflightCheck.cjs); reconcile copies it
|
|
157
161
|
// onto the queue row so spawnJob can hold the job while it exits non-zero.
|
|
158
162
|
preflight: typeof fm.preflight === 'string' ? parsePreflightValue(rawFrontmatterValue(text, 'preflight')) : null,
|
|
@@ -192,8 +196,9 @@ function parseDependsOn(raw) {
|
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
/**
|
|
195
|
-
* List `.md` PRD files under the given dir. Caches the result
|
|
196
|
-
*
|
|
199
|
+
* List `.md` PRD files under the given dir. Caches the result per dir path,
|
|
200
|
+
* validated by that dir's mtime, so repeated reconcile() calls don't re-read
|
|
201
|
+
* every dir.
|
|
197
202
|
* Pass `prdsDir` so the scheduler can keep ownership of its PRDS_DIR path
|
|
198
203
|
* without this module needing to know it.
|
|
199
204
|
*/
|
|
@@ -204,7 +209,8 @@ async function listPrdFiles(prdsDir) {
|
|
|
204
209
|
} catch {
|
|
205
210
|
dirMtime = -1;
|
|
206
211
|
}
|
|
207
|
-
|
|
212
|
+
const hit = prdDirCache.get(prdsDir);
|
|
213
|
+
if (hit && hit.mtimeMs === dirMtime) return hit.files;
|
|
208
214
|
let entries;
|
|
209
215
|
try {
|
|
210
216
|
entries = await fsp.readdir(prdsDir);
|
|
@@ -215,16 +221,17 @@ async function listPrdFiles(prdsDir) {
|
|
|
215
221
|
.filter((f) => f.endsWith('.md') && !f.startsWith('.'))
|
|
216
222
|
.map((f) => path.join(prdsDir, f))
|
|
217
223
|
.sort();
|
|
218
|
-
// Drop file-cache entries whose path is no longer on disk so the
|
|
219
|
-
// doesn't accumulate ghosts after archives/deletes.
|
|
224
|
+
// Drop this dir's file-cache entries whose path is no longer on disk so the
|
|
225
|
+
// map doesn't accumulate ghosts after archives/deletes. Other dirs' entries
|
|
226
|
+
// are theirs to prune.
|
|
220
227
|
if (prdFileCache.size > 0) {
|
|
221
228
|
const live = new Set(files);
|
|
229
|
+
const dirKey = path.dirname(path.join(prdsDir, 'x')); // normalized, no trailing sep
|
|
222
230
|
for (const k of prdFileCache.keys()) {
|
|
223
|
-
if (!live.has(k)) prdFileCache.delete(k);
|
|
231
|
+
if (path.dirname(k) === dirKey && !live.has(k)) prdFileCache.delete(k);
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
|
-
|
|
227
|
-
prdDirFiles = files;
|
|
234
|
+
prdDirCache.set(prdsDir, { mtimeMs: dirMtime, files });
|
|
228
235
|
return files;
|
|
229
236
|
}
|
|
230
237
|
|
|
@@ -257,10 +264,34 @@ async function parsePrd(filePath) {
|
|
|
257
264
|
return parsed;
|
|
258
265
|
}
|
|
259
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Drop every dir-cache and file-cache entry whose folder is not in `dirs`.
|
|
269
|
+
* listPrdFiles prunes only within the folder it lists, so a folder the
|
|
270
|
+
* scheduler stopped scanning altogether (a removed Epic's prds/) would keep
|
|
271
|
+
* its entries for the life of the process. scheduler.cjs calls this once per
|
|
272
|
+
* pass with the full candidate folder list.
|
|
273
|
+
* @param {Iterable<string>} dirs
|
|
274
|
+
*/
|
|
275
|
+
function retainPrdDirs(dirs) {
|
|
276
|
+
const norm = (d) => path.dirname(path.join(d, 'x')); // normalized, no trailing sep
|
|
277
|
+
const live = new Set();
|
|
278
|
+
for (const d of dirs) live.add(norm(d));
|
|
279
|
+
for (const k of prdDirCache.keys()) {
|
|
280
|
+
if (!live.has(norm(k))) prdDirCache.delete(k);
|
|
281
|
+
}
|
|
282
|
+
for (const k of prdFileCache.keys()) {
|
|
283
|
+
if (!live.has(path.dirname(k))) prdFileCache.delete(k);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Test-only: current cache keys. */
|
|
288
|
+
function _cacheKeys() {
|
|
289
|
+
return { dirs: [...prdDirCache.keys()], files: [...prdFileCache.keys()] };
|
|
290
|
+
}
|
|
291
|
+
|
|
260
292
|
/** Test-only: drop both cache layers so successive runs see fresh disk state. */
|
|
261
293
|
function _resetCache() {
|
|
262
|
-
|
|
263
|
-
prdDirFiles = null;
|
|
294
|
+
prdDirCache.clear();
|
|
264
295
|
prdFileCache.clear();
|
|
265
296
|
}
|
|
266
297
|
|
|
@@ -461,5 +492,7 @@ module.exports = {
|
|
|
461
492
|
pruneStaleReservations,
|
|
462
493
|
maxParallelGroupInUse,
|
|
463
494
|
PRD_READ_MAX_BYTES,
|
|
495
|
+
retainPrdDirs,
|
|
464
496
|
_resetCache,
|
|
497
|
+
_cacheKeys,
|
|
465
498
|
};
|
|
@@ -14,6 +14,8 @@ const { COMPLETED_EQUIVALENT_VERDICTS } = require('../lib/scheduler/terminalRunO
|
|
|
14
14
|
const { resolveIsFixPlan } = require('../lib/scheduler/fixPlanSlug.cjs');
|
|
15
15
|
const { GATE_AUTHORITY_VERDICTS } = require('../lib/scheduler/gateAuthority.cjs');
|
|
16
16
|
const { DEFAULT_PROJECT_CWD } = require('../lib/scheduler/schedulerBatch.cjs');
|
|
17
|
+
// Every automated selector skips a human-cancelled row (incident 2026-10-19 git-viewer: cancelled rows re-queued and merged).
|
|
18
|
+
const { isCancelledRow } = require('../lib/scheduler/cancelledRow.cjs');
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Resume-first recovery (PRD 1111). A job parked in needs_review with verdict
|
|
@@ -217,7 +219,7 @@ function isFinishReviewKillHealEligible(job) {
|
|
|
217
219
|
if (typeof job.landedCommit !== 'string' || job.landedCommit.length === 0) return false;
|
|
218
220
|
if (job.finishReviewHealAttemptedAt) return false;
|
|
219
221
|
if (job.integrationFailureKind) return false;
|
|
220
|
-
if (
|
|
222
|
+
if (isCancelledRow(job) || isRefireCapped(job)) return false;
|
|
221
223
|
return true;
|
|
222
224
|
}
|
|
223
225
|
|
|
@@ -596,23 +598,6 @@ function healRefusalReason(job, verdict, committedDuringRun) {
|
|
|
596
598
|
* gate or a real non-zero-exit error) is excluded — that failure is
|
|
597
599
|
* evidence, not silence, and must never become a heal candidate (PRD 1102).
|
|
598
600
|
*/
|
|
599
|
-
// A human cancelled this row (scheduler_cancel_job). Incident 2026-10-19
|
|
600
|
-
// (git-viewer): cancelled jobs were parked as 'failed' (source
|
|
601
|
-
// 'remote:cancelJob'), then selectFailedAutoResetTargets re-queued them 10
|
|
602
|
-
// minutes later and they ran and merged unwanted commits. Marker is
|
|
603
|
-
// `cancelledAt`; the statusHistory source is the fallback for rows cancelled
|
|
604
|
-
// before the marker existed. Every automated selector must skip these; only a
|
|
605
|
-
// human scheduler_reset_job revives one.
|
|
606
|
-
function isCancelledJob(job) {
|
|
607
|
-
if (!job) return false;
|
|
608
|
-
if (typeof job.cancelledAt === 'string' && job.cancelledAt) return true;
|
|
609
|
-
const history = Array.isArray(job.statusHistory) ? job.statusHistory : [];
|
|
610
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
611
|
-
if (history[i] && history[i].to === job.status) return history[i].source === 'remote:cancelJob';
|
|
612
|
-
}
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
601
|
function isFailedUnverifiedShaped(job) {
|
|
617
602
|
if (!job || job.status !== 'failed') return false;
|
|
618
603
|
if (job.verifierVerdict && RESCANNABLE_VERDICTS.has(job.verifierVerdict)) return true;
|
|
@@ -623,7 +608,7 @@ function isFailedUnverifiedShaped(job) {
|
|
|
623
608
|
}
|
|
624
609
|
|
|
625
610
|
function isRescanCandidate(job) {
|
|
626
|
-
if (!job ||
|
|
611
|
+
if (!job || isCancelledRow(job) || isRefireCapped(job)) return false;
|
|
627
612
|
// Default-ELIGIBLE: every needs_review row is a heal candidate unless its
|
|
628
613
|
// verdict is in RESCAN_EXCLUDED_VERDICTS. No runId requirement here — a row
|
|
629
614
|
// without one still gets the evidence rung and the unresolvable annotation.
|
|
@@ -655,7 +640,7 @@ function isTranscriptRescannable(job) {
|
|
|
655
640
|
function selectEvidenceScanTargets(jobs, now = Date.now()) {
|
|
656
641
|
const due = [];
|
|
657
642
|
for (const j of jobs ?? []) {
|
|
658
|
-
if (
|
|
643
|
+
if (isCancelledRow(j)) continue;
|
|
659
644
|
if (j.status !== 'needs_review' || !isRescanCandidate(j)) continue;
|
|
660
645
|
if (isTranscriptRescannable(j)) continue;
|
|
661
646
|
if (j.looksDone) continue;
|
|
@@ -785,7 +770,7 @@ function failedAutoResetDisabled() {
|
|
|
785
770
|
function selectFailedAutoResetTargets(jobs, now, thresholdMs) {
|
|
786
771
|
const targets = [];
|
|
787
772
|
for (const j of jobs ?? []) {
|
|
788
|
-
if (
|
|
773
|
+
if (isCancelledRow(j)) continue;
|
|
789
774
|
if (j.status !== 'failed') continue;
|
|
790
775
|
const attempts = j.failedAutoResetAttempts ?? 0;
|
|
791
776
|
if (attempts >= FAILED_AUTORESET_CAP) continue;
|
|
@@ -837,7 +822,7 @@ function selectFailedAutoResetTargets(jobs, now, thresholdMs) {
|
|
|
837
822
|
function findStuckFailedJobs(jobs, now, thresholdMs) {
|
|
838
823
|
const stuck = [];
|
|
839
824
|
for (const j of jobs ?? []) {
|
|
840
|
-
if (
|
|
825
|
+
if (isCancelledRow(j)) continue;
|
|
841
826
|
if (j.status !== 'failed') continue;
|
|
842
827
|
if (j.stuckFailedNotified === true) continue;
|
|
843
828
|
if (!isRescanCandidate(j)) continue;
|
|
@@ -906,7 +891,7 @@ function needsReviewAutoResolveDisabled() {
|
|
|
906
891
|
function selectExhaustedNeedsReviewTargets(jobs, now, thresholdMs) {
|
|
907
892
|
const targets = [];
|
|
908
893
|
for (const j of jobs ?? []) {
|
|
909
|
-
if (
|
|
894
|
+
if (isCancelledRow(j)) continue;
|
|
910
895
|
if (j.status !== 'needs_review') continue;
|
|
911
896
|
if (!isEligibleForNeedsReviewAutoResolve(j, jobs)) continue;
|
|
912
897
|
if ((j.exhaustedResolveAttempts ?? 0) > NEEDS_REVIEW_RESOLVE_CAP) continue;
|
|
@@ -949,7 +934,7 @@ function selectExhaustedNeedsReviewTargets(jobs, now, thresholdMs) {
|
|
|
949
934
|
function selectAutoFixTargets(jobs, { fixSlugExists, resolveJobRunId = resolveRunId }) {
|
|
950
935
|
const slugsInQueue = new Set(jobs.map((j) => j.slug));
|
|
951
936
|
return jobs.filter((job) => {
|
|
952
|
-
if (
|
|
937
|
+
if (isCancelledRow(job)) return false;
|
|
953
938
|
if (isRefireCapped(job)) return false;
|
|
954
939
|
if (job.status !== 'needs_review') return false;
|
|
955
940
|
// A job parked here because it was blocked by a sibling's foreign WIP
|
|
@@ -1117,7 +1102,6 @@ function selectResumeRecoveryBatch(jobs, { saturated = false } = {}) {
|
|
|
1117
1102
|
module.exports = {
|
|
1118
1103
|
selectResumeRecoveryBatch,
|
|
1119
1104
|
isRefireCapped,
|
|
1120
|
-
isCancelledJob,
|
|
1121
1105
|
selectResumeRecoveryTarget,
|
|
1122
1106
|
MECHANICALLY_RESOLVABLE_VERDICTS,
|
|
1123
1107
|
isMechanicalRecoveryFutile,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* scheduler/utilizationHold.cjs — the one rule deciding whether an automatic
|
|
6
|
+
* (non-human) scheduler tick may dispatch. Pure: no I/O, no clock (`now` is a
|
|
7
|
+
* parameter), so every caller (when-available, job-finish, dispatch-loop,
|
|
8
|
+
* slot-release ticks) agrees.
|
|
9
|
+
*
|
|
10
|
+
* Why every window: during a meter outage the top window (a 5-hour session
|
|
11
|
+
* at 97%) can reset while weekly_all in the same payload is still at 92%
|
|
12
|
+
* until Thursday. Reading only the binding window drops the hold at the
|
|
13
|
+
* session reset and the queue dispatches into the weekly limit (Self,
|
|
14
|
+
* 2026-11-23). A window whose reset has passed is skipped — never read as
|
|
15
|
+
* "no hold" for the others.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{ window: string | null, percent: number | null, resetsAt: string | null }} UsageWindow
|
|
20
|
+
* @typedef {{
|
|
21
|
+
* percent: number | null,
|
|
22
|
+
* window: string | null,
|
|
23
|
+
* resetsAt: string | null,
|
|
24
|
+
* known: boolean,
|
|
25
|
+
* windows: UsageWindow[] | null,
|
|
26
|
+
* }} UtilizationReading
|
|
27
|
+
* @typedef {{
|
|
28
|
+
* reason: 'manual-fire-policy' | 'utilization-held',
|
|
29
|
+
* window: string | null,
|
|
30
|
+
* percent: number | null,
|
|
31
|
+
* threshold: number | null,
|
|
32
|
+
* baseThreshold?: number | null,
|
|
33
|
+
* resetsAt: string | null,
|
|
34
|
+
* detail: string,
|
|
35
|
+
* }} AutoDispatchHold
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reset time as ms, or +Infinity when null/unparseable (counts as "resets last").
|
|
40
|
+
* @param {string | null | undefined} resetsAt
|
|
41
|
+
* @returns {number}
|
|
42
|
+
*/
|
|
43
|
+
function resetMs(resetsAt) {
|
|
44
|
+
const ms = typeof resetsAt === 'string' ? Date.parse(resetsAt) : NaN;
|
|
45
|
+
return Number.isFinite(ms) ? ms : Infinity;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
49
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
50
|
+
|
|
51
|
+
/** The pro-rated threshold reaches this in a window's final stretch. */
|
|
52
|
+
const PRO_RATE_CEILING = 100;
|
|
53
|
+
/** Share of a window left at which the threshold reaches the ceiling (last 2 days of a week). */
|
|
54
|
+
const PRO_RATE_FULL_FRACTION = 2 / 7;
|
|
55
|
+
/** Length of each usage window kind. */
|
|
56
|
+
const WINDOW_LENGTH_MS = Object.freeze({ weekly: 7 * DAY_MS, fiveHour: 5 * HOUR_MS });
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Window length from its name, or null for an unknown window.
|
|
60
|
+
* @param {string | null | undefined} window
|
|
61
|
+
* @returns {number | null}
|
|
62
|
+
*/
|
|
63
|
+
function windowLengthMs(window) {
|
|
64
|
+
if (typeof window !== 'string') return null;
|
|
65
|
+
if (/weekly|seven_day/i.test(window)) return WINDOW_LENGTH_MS.weekly;
|
|
66
|
+
if (/five_hour|session/i.test(window)) return WINDOW_LENGTH_MS.fiveHour;
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Effective 'pause above' value for one window: the owner would rather touch
|
|
72
|
+
* the limit than leave credits unspent, so the threshold rises from `base`
|
|
73
|
+
* (whole window left) linearly to PRO_RATE_CEILING once only
|
|
74
|
+
* PRO_RATE_FULL_FRACTION of the window is left. Never below `base`; unknown
|
|
75
|
+
* window, missing/unparseable reset, or non-finite base -> base unchanged.
|
|
76
|
+
* @param {{ base: number, window: string | null | undefined, resetsAt: string | null | undefined, now: number }} args
|
|
77
|
+
* @returns {number}
|
|
78
|
+
*/
|
|
79
|
+
function proRatedThreshold({ base, window, resetsAt, now }) {
|
|
80
|
+
if (typeof base !== 'number' || !Number.isFinite(base)) return base;
|
|
81
|
+
if (base >= PRO_RATE_CEILING) return base;
|
|
82
|
+
const length = windowLengthMs(window);
|
|
83
|
+
if (length === null) return base;
|
|
84
|
+
const reset = resetMs(resetsAt);
|
|
85
|
+
if (!Number.isFinite(reset)) return base;
|
|
86
|
+
const f = (reset - now) / length;
|
|
87
|
+
if (!Number.isFinite(f)) return base;
|
|
88
|
+
if (f >= 1) return base;
|
|
89
|
+
if (f <= PRO_RATE_FULL_FRACTION) return PRO_RATE_CEILING;
|
|
90
|
+
const value = base + (PRO_RATE_CEILING - base) * (1 - f) / (1 - PRO_RATE_FULL_FRACTION);
|
|
91
|
+
return Math.max(base, value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Human time left: "1.7 days", "4.0 h", "25 min".
|
|
96
|
+
* @param {number} ms
|
|
97
|
+
* @returns {string}
|
|
98
|
+
*/
|
|
99
|
+
function formatTimeLeft(ms) {
|
|
100
|
+
if (ms >= DAY_MS) return `${(ms / DAY_MS).toFixed(1)} days`;
|
|
101
|
+
if (ms >= HOUR_MS) return `${(ms / HOUR_MS).toFixed(1)} h`;
|
|
102
|
+
return `${String(Math.max(0, Math.round(ms / 60_000)))} min`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {{
|
|
107
|
+
* firePolicy: string | null | undefined,
|
|
108
|
+
* threshold: number | null | undefined,
|
|
109
|
+
* reading: UtilizationReading | null | undefined,
|
|
110
|
+
* now: number,
|
|
111
|
+
* }} args
|
|
112
|
+
* @returns {AutoDispatchHold | null}
|
|
113
|
+
*/
|
|
114
|
+
function evaluateAutoDispatchHold({ firePolicy, threshold, reading, now }) {
|
|
115
|
+
if (firePolicy === 'manual') {
|
|
116
|
+
return {
|
|
117
|
+
reason: 'manual-fire-policy',
|
|
118
|
+
window: null,
|
|
119
|
+
percent: null,
|
|
120
|
+
threshold: null,
|
|
121
|
+
resetsAt: null,
|
|
122
|
+
detail: 'fire policy is manual: only Run now dispatches',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (reading == null || reading.known !== true) return null;
|
|
126
|
+
if (typeof threshold !== 'number' || !Number.isFinite(threshold)) return null;
|
|
127
|
+
|
|
128
|
+
/** @type {UsageWindow[]} */
|
|
129
|
+
const candidates = Array.isArray(reading.windows) && reading.windows.length > 0
|
|
130
|
+
? reading.windows
|
|
131
|
+
: [{ window: reading.window, percent: reading.percent, resetsAt: reading.resetsAt }];
|
|
132
|
+
|
|
133
|
+
/** @type {{ window: string | null, percent: number, resetsAt: string | null, resetAt: number, limit: number } | null} */
|
|
134
|
+
let pick = null;
|
|
135
|
+
for (const c of candidates) {
|
|
136
|
+
if (!c) continue;
|
|
137
|
+
const percent = c.percent;
|
|
138
|
+
if (typeof percent !== 'number' || !Number.isFinite(percent)) continue;
|
|
139
|
+
const resetAt = resetMs(c.resetsAt);
|
|
140
|
+
if (resetAt <= now) continue; // already reset: its old reading no longer applies
|
|
141
|
+
const limit = utilizationHold.proRatedThreshold({ base: threshold, window: c.window, resetsAt: c.resetsAt, now });
|
|
142
|
+
if (percent < limit) continue;
|
|
143
|
+
if (pick === null || resetAt > pick.resetAt || (resetAt === pick.resetAt && percent > pick.percent)) {
|
|
144
|
+
pick = { window: c.window ?? null, percent, resetsAt: c.resetsAt ?? null, resetAt, limit };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (pick === null) return null;
|
|
148
|
+
|
|
149
|
+
const proRated = pick.limit !== threshold
|
|
150
|
+
? ` (pause above ${String(threshold)}%, pro-rated: ${formatTimeLeft(pick.resetAt - now)} to reset)`
|
|
151
|
+
: '';
|
|
152
|
+
const shownLimit = Math.round(pick.limit * 10) / 10;
|
|
153
|
+
return {
|
|
154
|
+
reason: 'utilization-held',
|
|
155
|
+
window: pick.window,
|
|
156
|
+
percent: pick.percent,
|
|
157
|
+
threshold: pick.limit,
|
|
158
|
+
baseThreshold: threshold,
|
|
159
|
+
resetsAt: pick.resetsAt,
|
|
160
|
+
detail: `${pick.window ?? 'binding'} window at ${String(pick.percent)}% ≥ ${String(shownLimit)}%${proRated}, resets ${pick.resetsAt ?? 'unknown'}`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const MINUTE_MS = 60_000;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Identity of one auto-dispatch hold: reason + window + reset, for the
|
|
168
|
+
* once-per-hold audit keys. The usage API returns a different resets_at string
|
|
169
|
+
* for the same reset on almost every fetch (329 distinct strings for one
|
|
170
|
+
* weekly reset across 640 heartbeat lines, about ±0.5 s either side of the
|
|
171
|
+
* minute), so the reset is rounded to the nearest whole minute. An unparseable
|
|
172
|
+
* resetsAt is used raw ('' when absent) so the key stays stable.
|
|
173
|
+
* @param {{ reason: string, window?: string | null, resetsAt?: string | null }} hold
|
|
174
|
+
* @returns {string}
|
|
175
|
+
*/
|
|
176
|
+
function holdIdentityKey(hold) {
|
|
177
|
+
const raw = hold.resetsAt ?? '';
|
|
178
|
+
const ms = typeof hold.resetsAt === 'string' ? Date.parse(hold.resetsAt) : NaN;
|
|
179
|
+
const reset = Number.isFinite(ms) ? new Date(Math.round(ms / MINUTE_MS) * MINUTE_MS).toISOString() : raw;
|
|
180
|
+
return `${hold.reason}|${hold.window ?? ''}|${reset}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const utilizationHold = {
|
|
184
|
+
evaluateAutoDispatchHold,
|
|
185
|
+
holdIdentityKey,
|
|
186
|
+
proRatedThreshold,
|
|
187
|
+
PRO_RATE_CEILING,
|
|
188
|
+
PRO_RATE_FULL_FRACTION,
|
|
189
|
+
WINDOW_LENGTH_MS,
|
|
190
|
+
};
|
|
191
|
+
module.exports = utilizationHold;
|