claude-code-session-manager 0.139.0 → 0.141.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 +20 -4
- package/dist/assets/AppSettings-DExeJhqQ.js +2 -0
- package/dist/assets/History-DJMiuXyK.js +2 -0
- package/dist/assets/{HomeClaudeConfig-CGD2Onjv.js → HomeClaudeConfig-CTp2tkZ4.js} +2 -2
- package/dist/assets/{Panel-Csyd9HbD.js → Panel-Bf1Cf8UL.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-C-jlYpC_.js → ProjectClaudeConfig-BWPpypf9.js} +1 -1
- package/dist/assets/Scheduler-cyr61UAC.js +16 -0
- package/dist/assets/{SkillReferenceGraph-DcscPXAG.js → SkillReferenceGraph-Ba4TkX2C.js} +1 -1
- package/dist/assets/{Skills-BpGRKOcY.js → Skills-C1v91GEO.js} +26 -26
- package/dist/assets/{TiptapBody-DSU3769X.js → TiptapBody-BrcWVpiW.js} +1 -1
- package/dist/assets/{ViewTabs-C0PRZx4_.js → ViewTabs-DXhOWFG0.js} +1 -1
- package/dist/assets/{VoiceButton-D2rMurNg.js → VoiceButton-qivnDV6K.js} +1 -1
- package/dist/assets/{historyTotals-TcIQs2sh.js → historyTotals-CMCPTKqC.js} +1 -1
- package/dist/assets/index-B2TQz3nd.js +3121 -0
- package/dist/assets/{index-BCySPdtU.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +423 -426
- package/package.json +5 -2
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -19
- 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 +1 -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 +205 -18
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +88 -5
- package/src/main/historyDashboard.cjs +69 -4
- package/src/main/index.cjs +56 -2
- package/src/main/ipcSchemas.cjs +122 -16
- 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 +90 -20
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -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 +25 -5
- package/src/main/lib/epic/epicOutsideRead.cjs +118 -1
- package/src/main/lib/epic/epicOutsideState.cjs +2 -2
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/externalContract.cjs +31 -5
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +55 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +106 -11
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +47 -19
- package/src/main/lib/feedback-remote/needsYouStore.cjs +6 -2
- 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 +26 -0
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +132 -13
- 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/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 +377 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +121 -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/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/preflightCheck.cjs +97 -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/reviewNotice.cjs +39 -0
- 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 +3 -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/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +10 -1
- 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 +19 -1
- package/src/main/scheduler/reviewLadder.cjs +36 -3
- package/src/main/scheduler/starvation.cjs +89 -18
- package/src/main/scheduler.cjs +1080 -89
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +14 -1
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +10 -2
- package/src/preload/api.d.ts +364 -21
- package/src/preload/apiSurface.json +89 -10
- package/src/preload/index.cjs +23 -2
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AppSettings-CUfWY9vN.js +0 -2
- package/dist/assets/History-DDnqaLyw.js +0 -2
- package/dist/assets/Scheduler-NLs08fx7.js +0 -16
- package/dist/assets/index-C-d0DCre.js +0 -3124
package/src/main/config.cjs
CHANGED
|
@@ -19,7 +19,8 @@ const fs = require('node:fs');
|
|
|
19
19
|
const fsp = require('node:fs/promises');
|
|
20
20
|
const path = require('node:path');
|
|
21
21
|
const os = require('node:os');
|
|
22
|
-
const { assertOpsWrite, opsPath, OWNERS } = require('./lib/opsOwnership.cjs');
|
|
22
|
+
const { assertOpsWrite, opsPath, OWNERS, OPS_ROOT_DIR } = require('./lib/opsOwnership.cjs');
|
|
23
|
+
const { walkImports } = require('./lib/persona-macro/personaImportHealth.cjs');
|
|
23
24
|
const chokidar = require('chokidar');
|
|
24
25
|
const logs = require('./logs.cjs');
|
|
25
26
|
const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
|
|
@@ -193,6 +194,82 @@ function validateWrite(realAbs) {
|
|
|
193
194
|
throw new Error(`Write outside allowed write boundaries: ${realAbs}`);
|
|
194
195
|
}
|
|
195
196
|
|
|
197
|
+
// ── Renderer instruction-file writes ────────────────────────────────────────
|
|
198
|
+
// The renderer's config:write-text (and only it) may also save instruction
|
|
199
|
+
// files: any CLAUDE.md / CLAUDE.local.md inside the read boundary, and any file
|
|
200
|
+
// main itself proves sits in the @-import closure of a CLAUDE.md /
|
|
201
|
+
// CLAUDE.local.md the caller names as `importedBy`. Main's own writers
|
|
202
|
+
// (writeTextAtomic, writeJson, writeJsonSync, writeBinaryAtomic) never take
|
|
203
|
+
// this path — they keep validateWrite's strict boundary.
|
|
204
|
+
const INSTRUCTION_FILE_NAMES = new Set(['CLAUDE.md', 'CLAUDE.local.md']);
|
|
205
|
+
|
|
206
|
+
function isInstructionFileName(p) {
|
|
207
|
+
return INSTRUCTION_FILE_NAMES.has(pathFor().basename(p));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** True when any path segment is the ops root dir (single-writer law territory). */
|
|
211
|
+
function isInsideOpsRoot(realAbs) {
|
|
212
|
+
return realAbs.split(/[\\/]/).includes(OPS_ROOT_DIR);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Instruction-file rule for renderer writes. `realAbs` must already have
|
|
217
|
+
* passed validatePath (it is the realpath).
|
|
218
|
+
* @param {string} realAbs
|
|
219
|
+
* @param {{ importedBy?: string }} [opts]
|
|
220
|
+
* @returns {{ ok: true } | { ok: false, reason: 'sensitive' | 'ops-root' | 'not-imported' }}
|
|
221
|
+
*/
|
|
222
|
+
function checkInstructionWrite(realAbs, { importedBy } = {}) {
|
|
223
|
+
let realHome;
|
|
224
|
+
try { realHome = canon(os.homedir()); } catch { realHome = os.homedir(); }
|
|
225
|
+
try {
|
|
226
|
+
insideHome.assertNotSensitiveWrite(realAbs, realHome);
|
|
227
|
+
} catch {
|
|
228
|
+
return { ok: false, reason: 'sensitive' };
|
|
229
|
+
}
|
|
230
|
+
if (isInsideOpsRoot(realAbs)) return { ok: false, reason: 'ops-root' };
|
|
231
|
+
if (isInstructionFileName(realAbs)) return { ok: true };
|
|
232
|
+
if (typeof importedBy === 'string' && importedBy) {
|
|
233
|
+
let realImporter = null;
|
|
234
|
+
try { realImporter = validatePath(expandHome(importedBy)); } catch { realImporter = null; }
|
|
235
|
+
if (realImporter && isInstructionFileName(realImporter)) {
|
|
236
|
+
for (const entry of walkImports(realImporter)) {
|
|
237
|
+
if (!entry.exists) continue;
|
|
238
|
+
let realImport;
|
|
239
|
+
try { realImport = canon(entry.importPath); } catch { continue; }
|
|
240
|
+
if (realImport === realAbs) return { ok: true };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return { ok: false, reason: 'not-imported' };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The one decision both config:write-text and config:can-write use for a
|
|
249
|
+
* realpath that already passed validatePath: the strict validateWrite
|
|
250
|
+
* boundary, else the instruction-file rule.
|
|
251
|
+
*/
|
|
252
|
+
function decideRendererWrite(real, importedBy) {
|
|
253
|
+
try {
|
|
254
|
+
validateWrite(real);
|
|
255
|
+
return { ok: true };
|
|
256
|
+
} catch {
|
|
257
|
+
return checkInstructionWrite(real, { importedBy });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** config:write-text's writer — validateWrite OR checkInstructionWrite, then the ops law + atomic write. */
|
|
262
|
+
async function writeRendererText(abs, text, { writer, importedBy } = {}) {
|
|
263
|
+
const real = validatePath(expandHome(abs));
|
|
264
|
+
if (!decideRendererWrite(real, importedBy).ok) {
|
|
265
|
+
throw new Error(`Write outside allowed write boundaries: ${real}`);
|
|
266
|
+
}
|
|
267
|
+
assertOpsWrite(real, writer);
|
|
268
|
+
await atomicFs.writeTextAtomic(real, text, {});
|
|
269
|
+
const stat = await fsp.stat(real);
|
|
270
|
+
return { ok: true, mtimeMs: stat.mtimeMs };
|
|
271
|
+
}
|
|
272
|
+
|
|
196
273
|
async function readJson(abs) {
|
|
197
274
|
try {
|
|
198
275
|
abs = validatePath(expandHome(abs));
|
|
@@ -358,14 +435,38 @@ async function listDir(abs, { filesOnly = false, dirsOnly = false, includeHidden
|
|
|
358
435
|
}
|
|
359
436
|
}
|
|
360
437
|
|
|
361
|
-
/**
|
|
362
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Whether config:write-text would accept `abs` — same decision as
|
|
440
|
+
* writeRendererText, plus a W_OK probe on the file (or its nearest existing
|
|
441
|
+
* parent folder when it does not exist yet).
|
|
442
|
+
* @returns {Promise<{ ok: boolean, reason?: 'outside-boundary' | 'sensitive' | 'ops-root' | 'not-imported' | 'permission' }>}
|
|
443
|
+
*/
|
|
444
|
+
async function canWrite(abs, { importedBy } = {}) {
|
|
445
|
+
let real;
|
|
363
446
|
try {
|
|
364
|
-
|
|
365
|
-
return true;
|
|
447
|
+
real = validatePath(expandHome(abs));
|
|
366
448
|
} catch {
|
|
367
|
-
return false;
|
|
449
|
+
return { ok: false, reason: 'outside-boundary' };
|
|
450
|
+
}
|
|
451
|
+
const decision = decideRendererWrite(real, importedBy);
|
|
452
|
+
if (!decision.ok) return decision;
|
|
453
|
+
let probe = real;
|
|
454
|
+
for (;;) {
|
|
455
|
+
try {
|
|
456
|
+
await fsp.access(probe, fs.constants.F_OK);
|
|
457
|
+
break;
|
|
458
|
+
} catch {
|
|
459
|
+
const parent = path.dirname(probe);
|
|
460
|
+
if (parent === probe) break;
|
|
461
|
+
probe = parent;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
try {
|
|
465
|
+
await fsp.access(probe, fs.constants.W_OK);
|
|
466
|
+
} catch {
|
|
467
|
+
return { ok: false, reason: 'permission' };
|
|
368
468
|
}
|
|
469
|
+
return { ok: true };
|
|
369
470
|
}
|
|
370
471
|
|
|
371
472
|
async function exists(abs) {
|
|
@@ -530,9 +631,9 @@ function registerConfigHandlers() {
|
|
|
530
631
|
registerPromptSessionsRoot(p);
|
|
531
632
|
return writeJson(p, data, { writer });
|
|
532
633
|
}));
|
|
533
|
-
ipcMain.handle('config:write-text', v(s.configWriteText, ({ path: p, text, writer }) =>
|
|
634
|
+
ipcMain.handle('config:write-text', v(s.configWriteText, ({ path: p, text, writer, importedBy }) => writeRendererText(p, text, { writer, importedBy })));
|
|
534
635
|
ipcMain.handle('config:list-dir', v(s.configListDir, ({ path: p, opts }) => listDir(p, opts || {})));
|
|
535
|
-
ipcMain.handle('config:can-write', v(s.
|
|
636
|
+
ipcMain.handle('config:can-write', v(s.configCanWrite, ({ path: p, importedBy }) => canWrite(p, { importedBy })));
|
|
536
637
|
ipcMain.handle('config:exists', v(s.configPath, ({ path: p }) => exists(p)));
|
|
537
638
|
ipcMain.handle('config:parse-imports', v(s.configParseImports, async ({ path: p }) => {
|
|
538
639
|
try {
|
|
@@ -563,6 +664,9 @@ module.exports = {
|
|
|
563
664
|
migrateLegacyHomeFile,
|
|
564
665
|
writeTextAtomic,
|
|
565
666
|
writeBinaryAtomic,
|
|
667
|
+
writeRendererText,
|
|
668
|
+
checkInstructionWrite,
|
|
669
|
+
canWrite,
|
|
566
670
|
listDir,
|
|
567
671
|
exists,
|
|
568
672
|
addAllowedRoot,
|
package/src/main/docEdit.cjs
CHANGED
|
@@ -18,8 +18,10 @@ const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
|
|
|
18
18
|
const { ipcMain } = require('electron');
|
|
19
19
|
const { spawn } = require('node:child_process');
|
|
20
20
|
const crypto = require('node:crypto');
|
|
21
|
+
const os = require('node:os');
|
|
21
22
|
const { resolveClaudeBin, claudeSpawnTarget } = require('./lib/claude/claudeBin.cjs');
|
|
22
23
|
const { headlessPermissionArgs, ensureCliCapsProbed } = require('./lib/claude/claudeCliCaps.cjs');
|
|
24
|
+
const { buildJobSandboxSettings } = require('./lib/claude/jobSandboxPolicy.cjs');
|
|
23
25
|
const { feedChildStdin } = require('./lib/process/childStdin.cjs');
|
|
24
26
|
const { withProcRole } = require('./lib/process/cleanEnv.cjs');
|
|
25
27
|
const { extractJson } = require('./lib/util/extractJson.cjs');
|
|
@@ -94,10 +96,13 @@ async function runClaude(prompt, { model = 'sonnet', timeoutMs = 90_000, systemP
|
|
|
94
96
|
return new Promise((resolve) => {
|
|
95
97
|
let bin;
|
|
96
98
|
try { bin = resolveClaudeBin(); } catch (e) { resolve({ ok: false, error: `claude not found: ${e?.message}` }); return; }
|
|
99
|
+
// No spawn cwd is set, so the child inherits process.cwd() — the sandbox roots there.
|
|
100
|
+
const sandboxDir = process.cwd();
|
|
101
|
+
const sandbox = buildJobSandboxSettings({ agentType: 'aux', worktreeDir: sandboxDir, projectRoot: sandboxDir, homeDir: os.homedir(), tmpDir: os.tmpdir(), deps: { available: false, missing: [] } });
|
|
97
102
|
const args = [
|
|
98
103
|
'-p',
|
|
99
104
|
'--model', model,
|
|
100
|
-
|
|
105
|
+
...sandbox.argv,
|
|
101
106
|
...headlessPermissionArgs(),
|
|
102
107
|
'--strict-mcp-config',
|
|
103
108
|
'--output-format', 'text',
|
package/src/main/files.cjs
CHANGED
|
@@ -20,7 +20,7 @@ const path = require('node:path');
|
|
|
20
20
|
const os = require('node:os');
|
|
21
21
|
|
|
22
22
|
const { z } = require('zod');
|
|
23
|
-
const { assertInsideHomeOrRoots } = require('./lib/insideHome.cjs');
|
|
23
|
+
const { assertInsideHomeOrRoots, assertNotSensitiveWrite } = require('./lib/insideHome.cjs');
|
|
24
24
|
const { getAllowedRoots } = require('./config.cjs');
|
|
25
25
|
const { expandHome } = require('./lib/util/expandHome.cjs');
|
|
26
26
|
const atomicFs = require('./lib/util/atomicFs.cjs');
|
|
@@ -36,25 +36,6 @@ function validateHomePath(abs) {
|
|
|
36
36
|
return assertInsideHomeOrRoots(expandHome(abs), getAllowedRoots()).realPath;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** Reject .credentials.json writes regardless of where they sit. */
|
|
40
|
-
function rejectCredentials(real) {
|
|
41
|
-
if (path.basename(real) === '.credentials.json') {
|
|
42
|
-
throw new Error('Write to .credentials.json denied');
|
|
43
|
-
}
|
|
44
|
-
// Defense-in-depth: files:* is renderer-only (not web-remote reachable), but a
|
|
45
|
-
// renderer compromise could otherwise write code-execution-persistence or
|
|
46
|
-
// credential material a cockpit file browser has no business modifying. Block
|
|
47
|
-
// WRITES to these (reads are unaffected — they don't call this). Shell rc files
|
|
48
|
-
// are deliberately NOT blocked; developers legitimately edit those.
|
|
49
|
-
const rel = path.relative(os.homedir(), real);
|
|
50
|
-
if (rel === '.ssh' || rel.startsWith('.ssh' + path.sep)) {
|
|
51
|
-
throw new Error('Write inside ~/.ssh denied');
|
|
52
|
-
}
|
|
53
|
-
if (rel.startsWith(path.join('.config', 'autostart') + path.sep)) {
|
|
54
|
-
throw new Error('Write to ~/.config/autostart denied');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
39
|
// Invalid characters for file/folder names (cross-platform).
|
|
59
40
|
const INVALID_NAME_CHARS = /[<>:"/\\|?*\x00-\x1f]/;
|
|
60
41
|
const RESERVED_NAMES = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
@@ -160,7 +141,7 @@ async function writeFile(filePath, content) {
|
|
|
160
141
|
let resolved;
|
|
161
142
|
try {
|
|
162
143
|
resolved = validateHomePath(filePath);
|
|
163
|
-
|
|
144
|
+
assertNotSensitiveWrite(resolved);
|
|
164
145
|
} catch (e) {
|
|
165
146
|
return { ok: false, error: e.message };
|
|
166
147
|
}
|
|
@@ -185,7 +166,7 @@ async function createEntry(parentPath, name, kind) {
|
|
|
185
166
|
// produce something outside parent (defense in depth).
|
|
186
167
|
try { validateHomePath(target); }
|
|
187
168
|
catch (e) { return { ok: false, error: e.message }; }
|
|
188
|
-
try {
|
|
169
|
+
try { assertNotSensitiveWrite(target); }
|
|
189
170
|
catch (e) { return { ok: false, error: e.message }; }
|
|
190
171
|
|
|
191
172
|
try {
|
|
@@ -222,7 +203,7 @@ async function renameEntry(oldPath, newName) {
|
|
|
222
203
|
const newPath = path.join(path.dirname(resolvedOld), newName);
|
|
223
204
|
try { validateHomePath(newPath); }
|
|
224
205
|
catch (e) { return { ok: false, error: e.message }; }
|
|
225
|
-
try {
|
|
206
|
+
try { assertNotSensitiveWrite(newPath); }
|
|
226
207
|
catch (e) { return { ok: false, error: e.message }; }
|
|
227
208
|
|
|
228
209
|
try {
|
|
@@ -256,7 +237,7 @@ async function duplicateEntry(filePath) {
|
|
|
256
237
|
let resolved;
|
|
257
238
|
try { resolved = validateHomePath(filePath); }
|
|
258
239
|
catch (e) { return { ok: false, error: e.message }; }
|
|
259
|
-
try {
|
|
240
|
+
try { assertNotSensitiveWrite(resolved); }
|
|
260
241
|
catch (e) { return { ok: false, error: e.message }; }
|
|
261
242
|
|
|
262
243
|
let st;
|
|
@@ -273,7 +254,7 @@ async function duplicateEntry(filePath) {
|
|
|
273
254
|
|
|
274
255
|
const target = path.join(dir, nameResult.name);
|
|
275
256
|
try { validateHomePath(target); } catch (e) { return { ok: false, error: e.message }; }
|
|
276
|
-
try {
|
|
257
|
+
try { assertNotSensitiveWrite(target); } catch (e) { return { ok: false, error: e.message }; }
|
|
277
258
|
|
|
278
259
|
try {
|
|
279
260
|
await fsp.copyFile(resolved, target, fs.constants.COPYFILE_EXCL);
|
|
@@ -302,7 +283,7 @@ async function deleteEntry(filePath) {
|
|
|
302
283
|
if (isCriticalPath(resolved)) {
|
|
303
284
|
return { ok: false, error: 'Cannot delete system-critical paths' };
|
|
304
285
|
}
|
|
305
|
-
try {
|
|
286
|
+
try { assertNotSensitiveWrite(resolved); }
|
|
306
287
|
catch (e) { return { ok: false, error: e.message }; }
|
|
307
288
|
|
|
308
289
|
try {
|
|
@@ -423,7 +404,6 @@ module.exports = {
|
|
|
423
404
|
openExternal,
|
|
424
405
|
showInFinder,
|
|
425
406
|
// exported for tests
|
|
426
|
-
rejectCredentials,
|
|
427
407
|
validateHomePath,
|
|
428
408
|
isCriticalPath,
|
|
429
409
|
listDir,
|
package/src/main/health.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const { evaluateDispatchLiveness } = require('./lib/scheduler/watchdogHelpers.cj
|
|
|
22
22
|
const { computeStallSummary, computeDepHistorySatisfaction, FAILURE_STREAK_ESCALATION_MS } = require('./scheduler/budget.cjs');
|
|
23
23
|
const { classifyQueueStarvation, launchBlockedSlugs, STARVE_ESCALATION_MS } = require('./scheduler/starvation.cjs');
|
|
24
24
|
const { REVERIFY_INTERVAL_MS } = require('./scheduler/reviewLadder.cjs');
|
|
25
|
+
const { makeDepResolver } = require('./lib/prd/depSlugResolve.cjs');
|
|
25
26
|
const { findStarvedProjects, findUnresolvableDepRoots, DEFAULT_PROJECT_CWD, DEP_HISTORY_FAIL_OPEN } = require('./lib/scheduler/schedulerBatch.cjs');
|
|
26
27
|
const { auditLogPath, readTail } = require('./lib/telemetry/auditLog.cjs');
|
|
27
28
|
const { checkMainDependencyHealth } = require('./lib/git/depHealth.cjs');
|
|
@@ -116,8 +117,10 @@ function evaluateTickLiveness(queueState, heartbeat, now, runningCount) {
|
|
|
116
117
|
// The scheduler's private concurrencyCap is retired — the machine-wide
|
|
117
118
|
// sessionSlots pool is the only limit. Read it lazily so this stays a pure
|
|
118
119
|
// function of its args when a caller supplies slotCap explicitly.
|
|
120
|
+
// jobCapacity() = cap minus the held interactive-Task slot, so a held slot
|
|
121
|
+
// never reads as a stall.
|
|
119
122
|
const concurrencyCap = queueState.slotCap
|
|
120
|
-
?? (() => { try { return require('./lib/scheduler/sessionSlots.cjs').
|
|
123
|
+
?? (() => { try { return require('./lib/scheduler/sessionSlots.cjs').jobCapacity(); } catch { return Infinity; } })();
|
|
121
124
|
|
|
122
125
|
if (pending.length === 0) return { stalled: false, reason: 'no-pending-jobs' };
|
|
123
126
|
if (effectivePaused(queueState)) return { stalled: false, reason: queueState.paused ? 'paused' : 'draining' };
|
|
@@ -274,7 +277,7 @@ function parseClaudeMdBudget(text) {
|
|
|
274
277
|
// Pure comparison of CLAUDE.md's actual byte size against its self-declared
|
|
275
278
|
// budget (see parseClaudeMdBudget). budget === null means "no budget
|
|
276
279
|
// declared" — skip silently rather than treating it as 0 or infinite.
|
|
277
|
-
function evaluateClaudeMdBudget(chars, budget) {
|
|
280
|
+
function evaluateClaudeMdBudget(chars, budget, label = 'CLAUDE.md', mapName = 'CLAUDE.md') {
|
|
278
281
|
if (budget == null) return { ok: true, applicable: false };
|
|
279
282
|
const overage = chars - budget;
|
|
280
283
|
if (overage <= 0) return { ok: true, applicable: true, chars, budget };
|
|
@@ -284,10 +287,40 @@ function evaluateClaudeMdBudget(chars, budget) {
|
|
|
284
287
|
chars,
|
|
285
288
|
budget,
|
|
286
289
|
overage,
|
|
287
|
-
message:
|
|
290
|
+
message: `${label} is ${chars} chars, over its ${budget}-char budget by ${overage} (see the SIZE BUDGET note in ${mapName})`,
|
|
288
291
|
};
|
|
289
292
|
}
|
|
290
293
|
|
|
294
|
+
// Measures a project root's entry-map pair. The map is AGENTS.md when it
|
|
295
|
+
// exists (CLAUDE.md is then a one-line @AGENTS.md stub), else CLAUDE.md. The
|
|
296
|
+
// SIZE BUDGET is parsed from the map; the size counted is CLAUDE.md +
|
|
297
|
+
// AGENTS.md together, since the CLI loads both every turn. Returns null when
|
|
298
|
+
// neither file exists.
|
|
299
|
+
function measureRootClaudeMdPair(rootDir) {
|
|
300
|
+
const read = (name) => {
|
|
301
|
+
try { return fs.readFileSync(path.join(rootDir, name), 'utf8'); } catch { return null; }
|
|
302
|
+
};
|
|
303
|
+
const claude = read('CLAUDE.md');
|
|
304
|
+
const agents = read('AGENTS.md');
|
|
305
|
+
if (claude == null && agents == null) return null;
|
|
306
|
+
const mapName = agents != null ? 'AGENTS.md' : 'CLAUDE.md';
|
|
307
|
+
const present = [claude != null && 'CLAUDE.md', agents != null && 'AGENTS.md'].filter(Boolean);
|
|
308
|
+
const chars = Buffer.byteLength(claude || '', 'utf8') + Buffer.byteLength(agents || '', 'utf8');
|
|
309
|
+
return {
|
|
310
|
+
mapName,
|
|
311
|
+
label: present.join(' + '),
|
|
312
|
+
chars,
|
|
313
|
+
budget: parseClaudeMdBudget(agents != null ? agents : claude),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Root pair (measureRootClaudeMdPair) evaluated against the map's budget.
|
|
318
|
+
function evaluateRootClaudeMdBudget(rootDir) {
|
|
319
|
+
const m = measureRootClaudeMdPair(rootDir);
|
|
320
|
+
if (!m) return { ok: true, applicable: false };
|
|
321
|
+
return evaluateClaudeMdBudget(m.chars, m.budget, m.label, m.mapName);
|
|
322
|
+
}
|
|
323
|
+
|
|
291
324
|
// Pure evaluator over migratePrds()'s { moved, skipped, unresolved } result —
|
|
292
325
|
// kept separate from the fs-touching check() call site so it's directly
|
|
293
326
|
// unit-testable, matching evaluateTickLiveness's pattern.
|
|
@@ -602,7 +635,8 @@ function evaluateUnresolvableDepHealth(jobs, satisfiedSlugsByCwd) {
|
|
|
602
635
|
const roots = findUnresolvableDepRoots(rows, satisfied);
|
|
603
636
|
if (roots.length === 0) continue;
|
|
604
637
|
const rootSet = new Set(roots);
|
|
605
|
-
|
|
638
|
+
// Same resolver dispatch uses (depSlugResolve.cjs makeDepResolver).
|
|
639
|
+
const { rowsForDep } = makeDepResolver(rows, satisfied);
|
|
606
640
|
const held = new Set();
|
|
607
641
|
let grew = true;
|
|
608
642
|
while (grew) {
|
|
@@ -610,7 +644,7 @@ function evaluateUnresolvableDepHealth(jobs, satisfiedSlugsByCwd) {
|
|
|
610
644
|
for (const j of pending) {
|
|
611
645
|
if (held.has(j.slug)) continue;
|
|
612
646
|
const isHeld = (j.dependsOn ?? []).some((d) => rootSet.has(d)
|
|
613
|
-
||
|
|
647
|
+
|| rowsForDep(d, j).some((p) => p.status === 'pending' && held.has(p.slug)));
|
|
614
648
|
if (isHeld) { held.add(j.slug); grew = true; }
|
|
615
649
|
}
|
|
616
650
|
}
|
|
@@ -806,8 +840,8 @@ function loadUsagePollerState(statePath) {
|
|
|
806
840
|
*
|
|
807
841
|
* Pure. A `needs_review` row parked longer than one full periodic-reverify
|
|
808
842
|
* interval that STILL holds >= 1 pending dependent (transitively, through
|
|
809
|
-
* pending rows, via dependsOn —
|
|
810
|
-
* picker) is a silently-blocking park: the self-heal ladder had a full pass
|
|
843
|
+
* pending rows, via dependsOn — resolved by depSlugResolve.cjs
|
|
844
|
+
* makeDepResolver, the picker's own rule) is a silently-blocking park: the self-heal ladder had a full pass
|
|
811
845
|
* and did not release it. 2026-09-18: 1229-fo-03 held 19 of 20 pending rows
|
|
812
846
|
* while every other component read GREEN. Parked-since is the row's last
|
|
813
847
|
* `to: needs_review` statusHistory entry (fallback finishedAt); a row with no
|
|
@@ -815,7 +849,6 @@ function loadUsagePollerState(statePath) {
|
|
|
815
849
|
*/
|
|
816
850
|
function evaluateBlockingParkHealth(jobs, now, thresholdMs = REVERIFY_INTERVAL_MS) {
|
|
817
851
|
const rows = (Array.isArray(jobs) ? jobs : []).filter(Boolean);
|
|
818
|
-
const bare = (x) => String(x ?? '').replace(/^\d+-/, '');
|
|
819
852
|
const byCwd = new Map();
|
|
820
853
|
for (const j of rows) {
|
|
821
854
|
const cwd = j.cwd || DEFAULT_PROJECT_CWD;
|
|
@@ -826,6 +859,8 @@ function evaluateBlockingParkHealth(jobs, now, thresholdMs = REVERIFY_INTERVAL_M
|
|
|
826
859
|
for (const [cwd, group] of byCwd) {
|
|
827
860
|
const pending = group.filter((j) => j.status === 'pending');
|
|
828
861
|
if (pending.length === 0) continue;
|
|
862
|
+
// Same resolver dispatch uses (depSlugResolve.cjs makeDepResolver).
|
|
863
|
+
const { rowsForDep } = makeDepResolver(group);
|
|
829
864
|
for (const park of group) {
|
|
830
865
|
if (park.status !== 'needs_review') continue;
|
|
831
866
|
const history = Array.isArray(park.statusHistory) ? park.statusHistory : [];
|
|
@@ -836,13 +871,13 @@ function evaluateBlockingParkHealth(jobs, now, thresholdMs = REVERIFY_INTERVAL_M
|
|
|
836
871
|
const since = Date.parse(at ?? park.finishedAt ?? '');
|
|
837
872
|
if (Number.isNaN(since) || now - since <= thresholdMs) continue;
|
|
838
873
|
const held = new Set();
|
|
839
|
-
const heldBy = (d, root) => root.slug === d || bare(root.slug) === bare(d);
|
|
840
874
|
let grew = true;
|
|
841
875
|
while (grew) {
|
|
842
876
|
grew = false;
|
|
843
877
|
for (const j of pending) {
|
|
844
878
|
if (held.has(j.slug)) continue;
|
|
845
|
-
if ((j.dependsOn ?? []).some((d) =>
|
|
879
|
+
if ((j.dependsOn ?? []).some((d) => rowsForDep(d, j)
|
|
880
|
+
.some((p) => p === park || (p.status === 'pending' && held.has(p.slug))))) {
|
|
846
881
|
held.add(j.slug);
|
|
847
882
|
grew = true;
|
|
848
883
|
}
|
|
@@ -1222,11 +1257,7 @@ async function check(opts = {}) {
|
|
|
1222
1257
|
// header (see the CLAUDE.md size-budget note). Skips silently when no
|
|
1223
1258
|
// budget line is present — this is not required for every project.
|
|
1224
1259
|
try {
|
|
1225
|
-
const
|
|
1226
|
-
const claudeMdText = fs.readFileSync(claudeMdPath, 'utf8');
|
|
1227
|
-
const chars = Buffer.byteLength(claudeMdText, 'utf8');
|
|
1228
|
-
const budget = parseClaudeMdBudget(claudeMdText);
|
|
1229
|
-
const budgetResult = evaluateClaudeMdBudget(chars, budget);
|
|
1260
|
+
const budgetResult = evaluateRootClaudeMdBudget(PROJECT_ROOT);
|
|
1230
1261
|
status.components.claude_md_budget = budgetResult;
|
|
1231
1262
|
if (!budgetResult.ok) {
|
|
1232
1263
|
status.issues.push(budgetResult.message);
|
|
@@ -1463,6 +1494,8 @@ module.exports = {
|
|
|
1463
1494
|
evaluatePerProjectStall,
|
|
1464
1495
|
parseClaudeMdBudget,
|
|
1465
1496
|
evaluateClaudeMdBudget,
|
|
1497
|
+
measureRootClaudeMdPair,
|
|
1498
|
+
evaluateRootClaudeMdBudget,
|
|
1466
1499
|
evaluateUsagePollerHealth,
|
|
1467
1500
|
loadUsagePollerState,
|
|
1468
1501
|
evaluateQueueDispatchHealth,
|
|
@@ -498,12 +498,13 @@ function bucketToRollupLines(b) {
|
|
|
498
498
|
return lines;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
function finalizedMarkerLine(date) {
|
|
501
|
+
function finalizedMarkerLine(date, cycleStartedAt) {
|
|
502
502
|
return {
|
|
503
503
|
date,
|
|
504
504
|
projectDir: historyRollup.FINALIZED_PROJECT_ID,
|
|
505
505
|
modelId: historyRollup.FINALIZED_MODEL_ID,
|
|
506
506
|
finalizedAt: Date.now(),
|
|
507
|
+
cycleStartedAt,
|
|
507
508
|
v: historyRollup.ROLLUP_VERSION,
|
|
508
509
|
};
|
|
509
510
|
}
|
|
@@ -607,6 +608,22 @@ async function finalizeClosedDays({ budgetMs, dryRun = false, cursorPath } = {})
|
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
610
|
|
|
611
|
+
// Skip threshold: local midnight of the day the last completed pass (at
|
|
612
|
+
// this ROLLUP_VERSION) started. That pass skipped only that day's content,
|
|
613
|
+
// so a folder with no transcript modified since that midnight holds nothing
|
|
614
|
+
// it did not already count. No such marker => no threshold => full pass.
|
|
615
|
+
let skipBeforeMs = null;
|
|
616
|
+
try {
|
|
617
|
+
const lastCycle = await historyRollup.readNewestFinalizedCycleStart();
|
|
618
|
+
if (lastCycle !== null) {
|
|
619
|
+
const midnight = new Date(lastCycle);
|
|
620
|
+
midnight.setHours(0, 0, 0, 0);
|
|
621
|
+
skipBeforeMs = midnight.getTime();
|
|
622
|
+
}
|
|
623
|
+
} catch {
|
|
624
|
+
skipBeforeMs = null;
|
|
625
|
+
}
|
|
626
|
+
|
|
610
627
|
let projectDirs;
|
|
611
628
|
try {
|
|
612
629
|
projectDirs = await fsp.readdir(PROJECTS_DIR, { withFileTypes: true });
|
|
@@ -622,6 +639,7 @@ async function finalizeClosedDays({ budgetMs, dryRun = false, cursorPath } = {})
|
|
|
622
639
|
const buckets = new Map();
|
|
623
640
|
let partial = false;
|
|
624
641
|
let walkedLast = lastDir;
|
|
642
|
+
const taskIds = await taskSessionIdSet();
|
|
625
643
|
|
|
626
644
|
for (const projEntry of projectDirs) {
|
|
627
645
|
if (deadline !== null && Date.now() >= deadline) {
|
|
@@ -635,13 +653,21 @@ async function finalizeClosedDays({ budgetMs, dryRun = false, cursorPath } = {})
|
|
|
635
653
|
let files;
|
|
636
654
|
try { files = await fsp.readdir(projectDir, { withFileTypes: true }); } catch { walkedLast = encodedCwd; continue; }
|
|
637
655
|
|
|
656
|
+
// Stat the whole folder first: a day's lines are whole-folder totals, so
|
|
657
|
+
// the folder is either skipped entirely or read entirely.
|
|
658
|
+
const stated = [];
|
|
638
659
|
for (const fileEntry of files) {
|
|
639
660
|
if (!fileEntry.name.endsWith('.jsonl')) continue;
|
|
661
|
+
if (isTaskTranscript(fileEntry.name, taskIds)) continue;
|
|
640
662
|
const filePath = path.join(projectDir, fileEntry.name);
|
|
663
|
+
try { stated.push({ filePath, stat: await fsp.stat(filePath) }); } catch { continue; }
|
|
664
|
+
}
|
|
665
|
+
if (skipBeforeMs !== null && !stated.some((f) => f.stat.mtimeMs >= skipBeforeMs)) {
|
|
666
|
+
walkedLast = encodedCwd;
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
641
669
|
|
|
642
|
-
|
|
643
|
-
try { stat = await fsp.stat(filePath); } catch { continue; }
|
|
644
|
-
|
|
670
|
+
for (const { filePath, stat } of stated) {
|
|
645
671
|
const { result: parsed } = await parseJSONL(filePath, stat);
|
|
646
672
|
if (parsed.skipped) continue;
|
|
647
673
|
|
|
@@ -663,7 +689,7 @@ async function finalizeClosedDays({ budgetMs, dryRun = false, cursorPath } = {})
|
|
|
663
689
|
// Only stamp dates as finalized (safe to trust with no live re-scan) once a
|
|
664
690
|
// full cycle has covered every project directory — possibly across calls.
|
|
665
691
|
if (!partial) {
|
|
666
|
-
for (const date of dates) entries.push(finalizedMarkerLine(date));
|
|
692
|
+
for (const date of dates) entries.push(finalizedMarkerLine(date, cycleStartedAt));
|
|
667
693
|
}
|
|
668
694
|
|
|
669
695
|
if (!dryRun) {
|
|
@@ -751,6 +777,7 @@ async function computeIntradayBuckets() {
|
|
|
751
777
|
}
|
|
752
778
|
|
|
753
779
|
const dirEntries = projectDirs.filter((e) => e.isDirectory());
|
|
780
|
+
const taskIds = await taskSessionIdSet();
|
|
754
781
|
|
|
755
782
|
// Directory count (thousands) is far smaller than file count (tens of
|
|
756
783
|
// thousands), so stat-ing every directory concurrently is cheap and tells
|
|
@@ -783,6 +810,7 @@ async function computeIntradayBuckets() {
|
|
|
783
810
|
intradayDirRegistry.set(d.encodedCwd, { mtimeMs: d.mtimeMs, fileNames });
|
|
784
811
|
}
|
|
785
812
|
for (const name of fileNames) {
|
|
813
|
+
if (isTaskTranscript(name, taskIds)) continue;
|
|
786
814
|
const filePath = path.join(d.dirPath, name);
|
|
787
815
|
if (intradayNotToday.has(filePath)) continue;
|
|
788
816
|
fileCandidates.push({ filePath, encodedCwd: d.encodedCwd });
|
|
@@ -852,6 +880,57 @@ async function refreshIntradayToday() {
|
|
|
852
880
|
return { date: today, projectsUpdated: buckets.size, strategy: INTRADAY_STRATEGY };
|
|
853
881
|
}
|
|
854
882
|
|
|
883
|
+
// ── persisted Task transcripts ────────────────────────────────────────────────
|
|
884
|
+
//
|
|
885
|
+
// A Task that persists its claude session (runtime.persistSession / resume)
|
|
886
|
+
// leaves a transcript under ~/.claude/projects/ AND an sm-task ledger row that
|
|
887
|
+
// historyDashboard joins in. Counting the transcript too would double it, so
|
|
888
|
+
// every rollup-feeding walk skips `<sessionId>.jsonl` for a persisted Task id.
|
|
889
|
+
// The ledger's start line is written before the process spawns, so a mid-run
|
|
890
|
+
// pass never meets a Task transcript whose id is not yet in this Set.
|
|
891
|
+
|
|
892
|
+
let taskReadersOverride = null;
|
|
893
|
+
|
|
894
|
+
/** Test-only: inject { listTaskProjects, listPersistedSessionIds }; null restores the real modules. */
|
|
895
|
+
function setTaskSessionReadersForTests(readers) {
|
|
896
|
+
taskReadersOverride = readers || null;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Set of persisted Task session ids across every project in
|
|
901
|
+
* taskSwitch.listTaskProjects(). Never throws: a failed project listing yields
|
|
902
|
+
* an empty Set, a failed ledger read skips that project only.
|
|
903
|
+
*/
|
|
904
|
+
async function taskSessionIdSet(deps = taskReadersOverride) {
|
|
905
|
+
const ids = new Set();
|
|
906
|
+
let listTaskProjects;
|
|
907
|
+
let listPersistedSessionIds;
|
|
908
|
+
try {
|
|
909
|
+
listTaskProjects = deps?.listTaskProjects ?? require('./lib/tasks/taskSwitch.cjs').listTaskProjects;
|
|
910
|
+
listPersistedSessionIds = deps?.listPersistedSessionIds ?? require('./lib/tasks/taskLedger.cjs').listPersistedSessionIds;
|
|
911
|
+
} catch {
|
|
912
|
+
return ids;
|
|
913
|
+
}
|
|
914
|
+
let projects;
|
|
915
|
+
try { projects = await listTaskProjects(); } catch { return ids; }
|
|
916
|
+
if (!Array.isArray(projects)) return ids;
|
|
917
|
+
for (const p of projects) {
|
|
918
|
+
const cwd = typeof p === 'string' ? p : p?.cwd;
|
|
919
|
+
if (typeof cwd !== 'string' || !cwd) continue;
|
|
920
|
+
try {
|
|
921
|
+
const got = await listPersistedSessionIds(cwd);
|
|
922
|
+
if (got) for (const id of got) if (typeof id === 'string' && id) ids.add(id);
|
|
923
|
+
} catch {
|
|
924
|
+
// Unreadable ledger: this project's ids are skipped; the pass goes on.
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return ids;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function isTaskTranscript(fileName, taskIds) {
|
|
931
|
+
return taskIds.size > 0 && taskIds.has(fileName.replace(/\.jsonl$/, ''));
|
|
932
|
+
}
|
|
933
|
+
|
|
855
934
|
// ── aggregate ─────────────────────────────────────────────────────────────────
|
|
856
935
|
|
|
857
936
|
async function aggregate(req) {
|
|
@@ -895,6 +974,7 @@ async function aggregate(req) {
|
|
|
895
974
|
} catch {
|
|
896
975
|
return { rows: [], partial: false, truncated: false, scannedMs: Date.now() - t0, cacheSavingsUsd: 0, rollupDays: 0, liveDays: 0 };
|
|
897
976
|
}
|
|
977
|
+
const taskIds = await taskSessionIdSet();
|
|
898
978
|
|
|
899
979
|
outer:
|
|
900
980
|
for (const projEntry of projectDirs) {
|
|
@@ -911,6 +991,7 @@ async function aggregate(req) {
|
|
|
911
991
|
|
|
912
992
|
for (const fileEntry of files) {
|
|
913
993
|
if (!fileEntry.name.endsWith('.jsonl')) continue;
|
|
994
|
+
if (isTaskTranscript(fileEntry.name, taskIds)) continue;
|
|
914
995
|
const filePath = path.join(projectDir, fileEntry.name);
|
|
915
996
|
|
|
916
997
|
let stat;
|
|
@@ -1064,6 +1145,8 @@ module.exports = {
|
|
|
1064
1145
|
rollupMapToRows,
|
|
1065
1146
|
mapWithConcurrency,
|
|
1066
1147
|
resetIntradayRegistryForTests,
|
|
1148
|
+
setTaskSessionReadersForTests,
|
|
1149
|
+
taskSessionIdSet,
|
|
1067
1150
|
INTRADAY_STAT_CONCURRENCY,
|
|
1068
1151
|
// exported for historyDashboard.cjs (pure, no I/O at require-time; reused
|
|
1069
1152
|
// rather than re-implemented so date-range math stays in one place)
|