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
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const { spawn } = require('node:child_process');
|
|
19
|
+
const os = require('node:os');
|
|
19
20
|
const { resolveClaudeBin, claudeSpawnTarget } = require('./claudeBin.cjs');
|
|
20
21
|
const { headlessPermissionArgs, ensureCliCapsProbed } = require('./claudeCliCaps.cjs');
|
|
22
|
+
const { buildJobSandboxSettings } = require('./jobSandboxPolicy.cjs');
|
|
21
23
|
const { feedChildStdin } = require('../process/childStdin.cjs');
|
|
22
24
|
const { withProcRole } = require('../process/cleanEnv.cjs');
|
|
23
25
|
|
|
@@ -29,10 +31,13 @@ async function runClaudeP(prompt, { model = 'sonnet', timeoutMs = 180_000, syste
|
|
|
29
31
|
return new Promise((resolve) => {
|
|
30
32
|
let bin;
|
|
31
33
|
try { bin = resolveClaudeBin(); } catch (e) { resolve({ ok: false, error: `claude not found: ${e?.message}` }); return; }
|
|
34
|
+
// No spawn cwd is set, so the child inherits process.cwd() — the sandbox roots there.
|
|
35
|
+
const sandboxDir = process.cwd();
|
|
36
|
+
const sandbox = buildJobSandboxSettings({ agentType: 'aux', worktreeDir: sandboxDir, projectRoot: sandboxDir, homeDir: os.homedir(), tmpDir: os.tmpdir(), deps: { available: false, missing: [] } });
|
|
32
37
|
const args = [
|
|
33
38
|
'-p',
|
|
34
39
|
'--model', model,
|
|
35
|
-
|
|
40
|
+
...sandbox.argv,
|
|
36
41
|
...headlessPermissionArgs(),
|
|
37
42
|
'--strict-mcp-config',
|
|
38
43
|
'--output-format', 'text',
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* toolRiskIpc.cjs — the one main-process API for tool-risk marks:
|
|
5
|
+
*
|
|
6
|
+
* toolRisk:read ({ scope, cwd? }) -> { ok, path, exists, marks, interactive, error? }
|
|
7
|
+
* toolRisk:write ({ scope, cwd?, marks, interactive? }) -> { ok, path, error? }
|
|
8
|
+
*
|
|
9
|
+
* scope 'user' = System ~/.claude/tool-risk.json
|
|
10
|
+
* scope 'project' = Project <cwd>/.claude/tool-risk.json
|
|
11
|
+
*
|
|
12
|
+
* Every read/validate/write goes through toolRiskMarks.cjs (readMarksLayer /
|
|
13
|
+
* validateMarksFile / writeMarksLayer). `interactive` is a Project-only opt-in:
|
|
14
|
+
* turning it on installs guard-tool-risk into <cwd>/.claude/settings.json's
|
|
15
|
+
* PreToolUse hooks via its stable shim (delegationReadiness.cjs installGuard —
|
|
16
|
+
* the same merge/repair path the sanctioned guards use, with a local def, NOT a
|
|
17
|
+
* GUARD_DEFS entry, so the readiness banner never auto-installs it); turning it
|
|
18
|
+
* off removes exactly that hook.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const fs = require('node:fs');
|
|
22
|
+
const os = require('node:os');
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const {
|
|
25
|
+
systemMarksPath,
|
|
26
|
+
projectMarksPath,
|
|
27
|
+
readMarksLayer,
|
|
28
|
+
validateMarksFile,
|
|
29
|
+
writeMarksLayer,
|
|
30
|
+
} = require('./toolRiskMarks.cjs');
|
|
31
|
+
|
|
32
|
+
const TOOL_RISK_GUARD_MATCHER = 'Bash|Write|Edit|NotebookEdit|mcp__.*';
|
|
33
|
+
const TOOL_RISK_GUARD_SCRIPT = path.resolve(__dirname, '..', '..', '..', '..', 'scripts', 'hooks', 'guard-tool-risk.cjs');
|
|
34
|
+
const TOOL_RISK_GUARD_DEF = Object.freeze({
|
|
35
|
+
id: 'tool-risk-guard',
|
|
36
|
+
label: 'Tool-risk guard hook installed',
|
|
37
|
+
guardName: 'guard-tool-risk',
|
|
38
|
+
scriptBasename: 'guard-tool-risk.cjs',
|
|
39
|
+
script: TOOL_RISK_GUARD_SCRIPT,
|
|
40
|
+
matcher: TOOL_RISK_GUARD_MATCHER,
|
|
41
|
+
fixActionId: null,
|
|
42
|
+
nudge: false,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function errMsg(e) {
|
|
46
|
+
return e && e.message ? e.message : String(e);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @returns {{ok:true, path:string} | {ok:false, path:string|null, error:string}} */
|
|
50
|
+
function layerPath({ scope, cwd }, homeDir) {
|
|
51
|
+
if (scope === 'user') return { ok: true, path: systemMarksPath(homeDir) };
|
|
52
|
+
if (scope === 'project') {
|
|
53
|
+
if (typeof cwd !== 'string' || !path.isAbsolute(cwd)) {
|
|
54
|
+
return { ok: false, path: null, error: 'scope "project" needs an absolute cwd' };
|
|
55
|
+
}
|
|
56
|
+
return { ok: true, path: projectMarksPath(cwd) };
|
|
57
|
+
}
|
|
58
|
+
return { ok: false, path: null, error: `unknown scope ${JSON.stringify(scope)}` };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function readToolRisk(payload, { homeDir = os.homedir() } = {}) {
|
|
62
|
+
const p = layerPath(payload || {}, homeDir);
|
|
63
|
+
if (!p.ok) return { ok: false, path: p.path, exists: false, marks: {}, interactive: false, error: p.error };
|
|
64
|
+
const r = readMarksLayer(p.path);
|
|
65
|
+
if (!r.ok) return { ok: false, path: p.path, exists: r.exists === true, marks: {}, interactive: false, error: r.error };
|
|
66
|
+
return { ok: true, path: p.path, exists: r.exists, marks: r.marks, interactive: r.interactive };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Remove every guard-tool-risk hook from <cwd>/.claude/settings.json; drop an emptied entry. */
|
|
70
|
+
async function removeToolRiskGuard({ cwd }) {
|
|
71
|
+
const { readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
72
|
+
const { writeJson, addAllowedRoot } = require('../../config.cjs');
|
|
73
|
+
const settingsPath = path.join(cwd, '.claude', 'settings.json');
|
|
74
|
+
if (!fs.existsSync(settingsPath)) return { ok: true, action: 'not-installed', settingsPath };
|
|
75
|
+
const settings = readJsonOrSync(settingsPath, undefined);
|
|
76
|
+
if (settings === undefined || !settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
77
|
+
return { ok: false, action: 'error', error: `${settingsPath} is not valid JSON — fix it by hand before removing the guard` };
|
|
78
|
+
}
|
|
79
|
+
const hooks = (settings.hooks && typeof settings.hooks === 'object') ? settings.hooks : null;
|
|
80
|
+
if (!hooks || !Array.isArray(hooks.PreToolUse)) return { ok: true, action: 'not-installed', settingsPath };
|
|
81
|
+
|
|
82
|
+
const isOurs = (h) => typeof h?.command === 'string' && h.command.includes(TOOL_RISK_GUARD_DEF.guardName);
|
|
83
|
+
let removed = false;
|
|
84
|
+
const preToolUse = [];
|
|
85
|
+
for (const entry of hooks.PreToolUse) {
|
|
86
|
+
if (!Array.isArray(entry?.hooks) || !entry.hooks.some(isOurs)) { preToolUse.push(entry); continue; }
|
|
87
|
+
removed = true;
|
|
88
|
+
const kept = entry.hooks.filter((h) => !isOurs(h));
|
|
89
|
+
if (kept.length > 0) preToolUse.push({ ...entry, hooks: kept });
|
|
90
|
+
}
|
|
91
|
+
if (!removed) return { ok: true, action: 'not-installed', settingsPath };
|
|
92
|
+
|
|
93
|
+
const nextHooks = { ...hooks };
|
|
94
|
+
if (preToolUse.length > 0) nextHooks.PreToolUse = preToolUse;
|
|
95
|
+
else delete nextHooks.PreToolUse;
|
|
96
|
+
const next = { ...settings };
|
|
97
|
+
if (Object.keys(nextHooks).length > 0) next.hooks = nextHooks;
|
|
98
|
+
else delete next.hooks;
|
|
99
|
+
addAllowedRoot(cwd);
|
|
100
|
+
await writeJson(settingsPath, next);
|
|
101
|
+
return { ok: true, action: 'removed', settingsPath };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function installToolRiskGuard({ cwd, homeDir }) {
|
|
105
|
+
const { installGuard } = require('../epic/delegationReadiness.cjs');
|
|
106
|
+
return installGuard(TOOL_RISK_GUARD_DEF, { cwd, homeDir });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function writeToolRisk(payload, { homeDir = os.homedir() } = {}) {
|
|
110
|
+
const { scope, cwd, marks, interactive } = payload || {};
|
|
111
|
+
const p = layerPath({ scope, cwd }, homeDir);
|
|
112
|
+
if (!p.ok) return { ok: false, path: p.path, error: p.error };
|
|
113
|
+
if (scope === 'user' && interactive !== undefined) {
|
|
114
|
+
return { ok: false, path: p.path, error: '"interactive" is a Project-only opt-in; it cannot be set on the System (user) layer' };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Omitted `interactive` on a Project write keeps the file's current value.
|
|
118
|
+
let nextInteractive = interactive;
|
|
119
|
+
if (scope === 'project' && nextInteractive === undefined) {
|
|
120
|
+
const prev = readMarksLayer(p.path);
|
|
121
|
+
if (prev.ok && prev.exists && prev.interactive) nextInteractive = true;
|
|
122
|
+
}
|
|
123
|
+
const obj = { version: 1, marks };
|
|
124
|
+
if (nextInteractive !== undefined) obj.interactive = nextInteractive;
|
|
125
|
+
|
|
126
|
+
const v = validateMarksFile(obj);
|
|
127
|
+
if (!v.ok) return { ok: false, path: p.path, error: v.error };
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const w = await writeMarksLayer(p.path, obj);
|
|
131
|
+
if (!w.ok) return { ok: false, path: p.path, error: w.error };
|
|
132
|
+
} catch (e) {
|
|
133
|
+
return { ok: false, path: p.path, error: errMsg(e) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (scope === 'project' && interactive !== undefined) {
|
|
137
|
+
let hook;
|
|
138
|
+
try {
|
|
139
|
+
hook = interactive
|
|
140
|
+
? await installToolRiskGuard({ cwd, homeDir })
|
|
141
|
+
: await removeToolRiskGuard({ cwd });
|
|
142
|
+
} catch (e) {
|
|
143
|
+
hook = { ok: false, error: errMsg(e) };
|
|
144
|
+
}
|
|
145
|
+
if (!hook.ok) return { ok: false, path: p.path, error: `marks saved, but the guard hook could not be ${interactive ? 'installed' : 'removed'}: ${hook.error}` };
|
|
146
|
+
}
|
|
147
|
+
return { ok: true, path: p.path };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {import('electron').IpcMain} ipcMain
|
|
152
|
+
* @param {{ schemas: any, validated: Function, validatePath?: (p:string)=>string, homeDir?: string,
|
|
153
|
+
* onChanged?: (info:{path:string}) => void }} deps
|
|
154
|
+
*/
|
|
155
|
+
function registerToolRiskIpc(ipcMain, deps) {
|
|
156
|
+
const { schemas, validated, validatePath, onChanged } = deps;
|
|
157
|
+
const opts = () => ({ homeDir: deps.homeDir || os.homedir() });
|
|
158
|
+
ipcMain.handle('toolRisk:read', validated(schemas.toolRiskRead, async (p) => {
|
|
159
|
+
if (p.cwd && validatePath) validatePath(p.cwd);
|
|
160
|
+
return readToolRisk(p, opts());
|
|
161
|
+
}));
|
|
162
|
+
ipcMain.handle('toolRisk:write', validated(schemas.toolRiskWrite, async (p) => {
|
|
163
|
+
if (p.cwd && validatePath) validatePath(p.cwd);
|
|
164
|
+
const result = await writeToolRisk(p, opts());
|
|
165
|
+
if (result.ok && onChanged) onChanged({ path: result.path });
|
|
166
|
+
return result;
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = {
|
|
171
|
+
TOOL_RISK_GUARD_MATCHER,
|
|
172
|
+
TOOL_RISK_GUARD_DEF,
|
|
173
|
+
readToolRisk,
|
|
174
|
+
writeToolRisk,
|
|
175
|
+
removeToolRiskGuard,
|
|
176
|
+
registerToolRiskIpc,
|
|
177
|
+
};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* toolRiskMarks.cjs — the one module that reads, validates, writes and
|
|
5
|
+
* matches per-tool risk marks kept in the Claude config layers:
|
|
6
|
+
*
|
|
7
|
+
* System = ~/.claude/tool-risk.json
|
|
8
|
+
* Project = <projectRoot>/.claude/tool-risk.json (main checkout, never a worktree)
|
|
9
|
+
*
|
|
10
|
+
* File format, version 1 (pinned):
|
|
11
|
+
* { "version": 1, "interactive"?: boolean, "marks": { "<rule>": "<mark>" } }
|
|
12
|
+
*
|
|
13
|
+
* A rule is an MCP tool name (`mcp__srv__tool`), a server wildcard
|
|
14
|
+
* (`mcp__srv__*`), a Bash prefix (`Bash(npm publish:*)`) or an exact Bash
|
|
15
|
+
* command (`Bash(git push --force)`). A call is the PreToolUse shape
|
|
16
|
+
* `{ tool, input? }`; for Bash, `input.command` is the command line.
|
|
17
|
+
*
|
|
18
|
+
* Precedence: layer first (any matching Project rule beats every System rule),
|
|
19
|
+
* then specificity inside the layer (MCP exact > server wildcard; Bash exact >
|
|
20
|
+
* longer prefix > shorter prefix). A compound Bash command resolves each
|
|
21
|
+
* simple command and returns a blocking result if any one blocks.
|
|
22
|
+
*
|
|
23
|
+
* Pure apart from readMarksLayer / writeMarksLayer. No side effects at
|
|
24
|
+
* require time. readMarksLayer and resolveMark never throw.
|
|
25
|
+
*
|
|
26
|
+
* The Bash splitter/tokenizer copies the approach of
|
|
27
|
+
* scripts/hooks/lib/guard-destructive-git-policy.cjs (src/main never
|
|
28
|
+
* requires from scripts/).
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const fs = require('node:fs');
|
|
32
|
+
const path = require('node:path');
|
|
33
|
+
const { writeJsonAtomic, readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
34
|
+
|
|
35
|
+
const MARKS = Object.freeze(['read', 'write', 'irreversible', 'money', 'public']);
|
|
36
|
+
const BLOCKING_MARKS = new Set(['irreversible', 'money', 'public']);
|
|
37
|
+
const MARK_SET = new Set(MARKS);
|
|
38
|
+
|
|
39
|
+
const FILE_NAME = 'tool-risk.json';
|
|
40
|
+
const FORMAT_VERSION = 1;
|
|
41
|
+
const TOP_LEVEL_KEYS = new Set(['version', 'interactive', 'marks']);
|
|
42
|
+
|
|
43
|
+
const NAME_RE = /^[A-Za-z0-9_.-]+$/;
|
|
44
|
+
const ENV_ASSIGN_RE = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
45
|
+
const WRAPPERS = new Set(['env', 'sudo', 'command', 'exec', 'nohup', 'time']);
|
|
46
|
+
// sudo flags that consume the next word as their argument.
|
|
47
|
+
const SUDO_ARG_FLAGS = new Set(['-u', '-g', '-C', '-D', '-h', '-p', '-r', '-t', '-U', '-R', '-T']);
|
|
48
|
+
const SHELLS = new Set(['bash', 'sh']);
|
|
49
|
+
|
|
50
|
+
function systemMarksPath(homeDir) {
|
|
51
|
+
return path.join(homeDir, '.claude', FILE_NAME);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function projectMarksPath(projectRoot) {
|
|
55
|
+
return path.join(projectRoot, '.claude', FILE_NAME);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isPlainObject(v) {
|
|
59
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── Bash parsing ────────────────────────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
/** Quote-aware split on top-level `&&`, `||`, `;`, `|`, and newlines. */
|
|
65
|
+
function splitTopLevel(cmd) {
|
|
66
|
+
const parts = [];
|
|
67
|
+
let cur = '';
|
|
68
|
+
let inSingle = false;
|
|
69
|
+
let inDouble = false;
|
|
70
|
+
for (let i = 0; i < cmd.length; i++) {
|
|
71
|
+
const c = cmd[i];
|
|
72
|
+
if (inSingle) {
|
|
73
|
+
cur += c;
|
|
74
|
+
if (c === "'") inSingle = false;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (inDouble) {
|
|
78
|
+
cur += c;
|
|
79
|
+
if (c === '"' && cmd[i - 1] !== '\\') inDouble = false;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (c === "'") { inSingle = true; cur += c; continue; }
|
|
83
|
+
if (c === '"') { inDouble = true; cur += c; continue; }
|
|
84
|
+
const two = cmd.slice(i, i + 2);
|
|
85
|
+
if (two === '&&' || two === '||') { parts.push(cur); cur = ''; i++; continue; }
|
|
86
|
+
if (c === ';' || c === '|' || c === '\n') { parts.push(cur); cur = ''; continue; }
|
|
87
|
+
cur += c;
|
|
88
|
+
}
|
|
89
|
+
parts.push(cur);
|
|
90
|
+
return parts.map((s) => s.trim()).filter(Boolean);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Quote-aware whitespace tokenizer. Returns null on an unterminated quote. */
|
|
94
|
+
function tokenize(str) {
|
|
95
|
+
const tokens = [];
|
|
96
|
+
let cur = '';
|
|
97
|
+
let started = false;
|
|
98
|
+
let inSingle = false;
|
|
99
|
+
let inDouble = false;
|
|
100
|
+
for (let i = 0; i < str.length; i++) {
|
|
101
|
+
const c = str[i];
|
|
102
|
+
if (inSingle) {
|
|
103
|
+
if (c === "'") inSingle = false; else cur += c;
|
|
104
|
+
started = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (inDouble) {
|
|
108
|
+
if (c === '"') inDouble = false; else cur += c;
|
|
109
|
+
started = true;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (c === "'") { inSingle = true; started = true; continue; }
|
|
113
|
+
if (c === '"') { inDouble = true; started = true; continue; }
|
|
114
|
+
if (/\s/.test(c)) {
|
|
115
|
+
if (started) { tokens.push(cur); cur = ''; started = false; }
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
cur += c;
|
|
119
|
+
started = true;
|
|
120
|
+
}
|
|
121
|
+
if (started) tokens.push(cur);
|
|
122
|
+
if (inSingle || inDouble) return null;
|
|
123
|
+
return tokens;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Drop leading VAR=value words and env/sudo/command/exec/nohup/time wrappers. */
|
|
127
|
+
function stripPrefixes(tokens) {
|
|
128
|
+
let i = 0;
|
|
129
|
+
for (;;) {
|
|
130
|
+
while (i < tokens.length && ENV_ASSIGN_RE.test(tokens[i])) i++;
|
|
131
|
+
if (i >= tokens.length || !WRAPPERS.has(tokens[i])) break;
|
|
132
|
+
const wrapper = tokens[i++];
|
|
133
|
+
while (i < tokens.length && tokens[i].startsWith('-') && tokens[i] !== '--') {
|
|
134
|
+
const flag = tokens[i++];
|
|
135
|
+
if (wrapper === 'sudo' && SUDO_ARG_FLAGS.has(flag)) i++;
|
|
136
|
+
}
|
|
137
|
+
if (tokens[i] === '--') i++;
|
|
138
|
+
}
|
|
139
|
+
return tokens.slice(i);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Index of the `-c` script argument for `bash -c '<cmd>'` / `sh -lc '<cmd>'`, or -1. */
|
|
143
|
+
function shellScriptIndex(tokens) {
|
|
144
|
+
if (!SHELLS.has(tokens[0])) return -1;
|
|
145
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
146
|
+
const t = tokens[i];
|
|
147
|
+
if (!t.startsWith('-') || t.startsWith('--')) return -1;
|
|
148
|
+
if (t.slice(1).includes('c')) return i + 1 < tokens.length ? i + 1 : -1;
|
|
149
|
+
}
|
|
150
|
+
return -1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Split a command line into simple commands (token arrays), unwrapping one
|
|
155
|
+
* level of `bash -c` / `sh -c`. A wrapper's outer form is kept too, so a rule
|
|
156
|
+
* on `bash` itself still matches.
|
|
157
|
+
*/
|
|
158
|
+
function simpleCommands(command, depth = 0) {
|
|
159
|
+
const out = [];
|
|
160
|
+
for (const part of splitTopLevel(command)) {
|
|
161
|
+
const raw = tokenize(part);
|
|
162
|
+
if (!raw) continue;
|
|
163
|
+
const tokens = stripPrefixes(raw);
|
|
164
|
+
if (tokens.length === 0) continue;
|
|
165
|
+
out.push(tokens);
|
|
166
|
+
if (depth === 0) {
|
|
167
|
+
const idx = shellScriptIndex(tokens);
|
|
168
|
+
if (idx !== -1) out.push(...simpleCommands(tokens[idx], depth + 1));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ── Rules ───────────────────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @returns {{kind:'mcp', server:string, tool:string|null}
|
|
178
|
+
* | {kind:'bash', prefix:string[], exact:boolean} | null}
|
|
179
|
+
*/
|
|
180
|
+
function parseRule(rule) {
|
|
181
|
+
if (typeof rule !== 'string') return null;
|
|
182
|
+
if (rule.trim() === '' || /[\r\n]/.test(rule)) return null;
|
|
183
|
+
if (rule.startsWith('mcp__')) {
|
|
184
|
+
const rest = rule.slice(5);
|
|
185
|
+
const sep = rest.indexOf('__');
|
|
186
|
+
const server = sep === -1 ? rest : rest.slice(0, sep);
|
|
187
|
+
if (!server || !NAME_RE.test(server)) return null;
|
|
188
|
+
if (sep === -1) return { kind: 'mcp', server, tool: null };
|
|
189
|
+
const tool = rest.slice(sep + 2);
|
|
190
|
+
if (tool === '*') return { kind: 'mcp', server, tool: null };
|
|
191
|
+
if (!tool || !NAME_RE.test(tool)) return null;
|
|
192
|
+
return { kind: 'mcp', server, tool };
|
|
193
|
+
}
|
|
194
|
+
const m = /^Bash\((.*)\)$/.exec(rule);
|
|
195
|
+
if (!m) return null;
|
|
196
|
+
let inner = m[1];
|
|
197
|
+
let exact = true;
|
|
198
|
+
if (inner.endsWith(':*')) { inner = inner.slice(0, -2); exact = false; }
|
|
199
|
+
const prefix = tokenize(inner);
|
|
200
|
+
if (!prefix || prefix.length === 0) return null;
|
|
201
|
+
return { kind: 'bash', prefix, exact };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function toParsed(rule) {
|
|
205
|
+
if (isPlainObject(rule) && (rule.kind === 'mcp' || rule.kind === 'bash')) return rule;
|
|
206
|
+
return parseRule(rule);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function tokensMatch(parsed, tokens) {
|
|
210
|
+
if (parsed.exact && tokens.length !== parsed.prefix.length) return false;
|
|
211
|
+
if (tokens.length < parsed.prefix.length) return false;
|
|
212
|
+
for (let i = 0; i < parsed.prefix.length; i++) {
|
|
213
|
+
if (tokens[i] !== parsed.prefix[i]) return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function mcpMatches(parsed, toolName) {
|
|
219
|
+
if (typeof toolName !== 'string') return false;
|
|
220
|
+
if (parsed.tool === null) return toolName.startsWith(`mcp__${parsed.server}__`);
|
|
221
|
+
return toolName === `mcp__${parsed.server}__${parsed.tool}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function bashCommandOf(call) {
|
|
225
|
+
if (!call || call.tool !== 'Bash' || !isPlainObject(call.input)) return null;
|
|
226
|
+
return typeof call.input.command === 'string' ? call.input.command : null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Does `rule` (string or parseRule result) match `call`? Never throws. */
|
|
230
|
+
function ruleMatches(rule, call) {
|
|
231
|
+
try {
|
|
232
|
+
const parsed = toParsed(rule);
|
|
233
|
+
if (!parsed || !call) return false;
|
|
234
|
+
if (parsed.kind === 'mcp') return mcpMatches(parsed, call.tool);
|
|
235
|
+
const command = bashCommandOf(call);
|
|
236
|
+
if (command === null) return false;
|
|
237
|
+
return simpleCommands(command).some((tokens) => tokensMatch(parsed, tokens));
|
|
238
|
+
} catch {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Higher = more specific. */
|
|
244
|
+
function specificity(parsed) {
|
|
245
|
+
if (parsed.kind === 'mcp') return parsed.tool === null ? 1 : 2;
|
|
246
|
+
return (parsed.exact ? 1e6 : 0) + parsed.prefix.length;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ── Validation + fs ─────────────────────────────────────────────────────────
|
|
250
|
+
|
|
251
|
+
/** @returns {{ok:true} | {ok:false, error:string}} */
|
|
252
|
+
function validateMarksFile(obj) {
|
|
253
|
+
if (!isPlainObject(obj)) return { ok: false, error: 'tool-risk file must be a JSON object' };
|
|
254
|
+
for (const key of Object.keys(obj)) {
|
|
255
|
+
if (!TOP_LEVEL_KEYS.has(key)) return { ok: false, error: `unknown top-level key "${key}"` };
|
|
256
|
+
}
|
|
257
|
+
if (obj.version !== FORMAT_VERSION) {
|
|
258
|
+
return { ok: false, error: `"version" must be ${FORMAT_VERSION} (got ${JSON.stringify(obj.version)})` };
|
|
259
|
+
}
|
|
260
|
+
if (obj.interactive !== undefined && typeof obj.interactive !== 'boolean') {
|
|
261
|
+
return { ok: false, error: '"interactive" must be a boolean' };
|
|
262
|
+
}
|
|
263
|
+
if (!isPlainObject(obj.marks)) return { ok: false, error: '"marks" must be an object' };
|
|
264
|
+
for (const [rule, mark] of Object.entries(obj.marks)) {
|
|
265
|
+
if (!parseRule(rule)) return { ok: false, error: `marks key "${rule}" is not a valid rule (use mcp__server__tool, mcp__server__*, Bash(prefix:*) or Bash(exact))` };
|
|
266
|
+
if (!MARK_SET.has(mark)) return { ok: false, error: `marks key "${rule}" has unknown mark ${JSON.stringify(mark)} (expected one of ${MARKS.join(', ')})` };
|
|
267
|
+
}
|
|
268
|
+
return { ok: true };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const UNPARSEABLE = Object.freeze({});
|
|
272
|
+
|
|
273
|
+
/** Read one layer. Never throws. */
|
|
274
|
+
function readMarksLayer(file) {
|
|
275
|
+
try {
|
|
276
|
+
if (typeof file !== 'string' || file === '') {
|
|
277
|
+
return { ok: false, exists: false, error: 'no tool-risk file path given', file: file ?? null };
|
|
278
|
+
}
|
|
279
|
+
if (!fs.existsSync(file)) return { ok: true, exists: false, marks: {}, interactive: false, file };
|
|
280
|
+
const obj = readJsonOrSync(file, UNPARSEABLE);
|
|
281
|
+
if (obj === UNPARSEABLE) return { ok: false, exists: true, error: `${file}: unreadable or not valid JSON`, file };
|
|
282
|
+
const v = validateMarksFile(obj);
|
|
283
|
+
if (!v.ok) return { ok: false, exists: true, error: `${file}: ${v.error}`, file };
|
|
284
|
+
return { ok: true, exists: true, marks: { ...obj.marks }, interactive: obj.interactive === true, file };
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return { ok: false, exists: true, error: `${file}: ${e && e.message ? e.message : String(e)}`, file };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Validate, then write atomically. @returns {Promise<{ok:true}|{ok:false,error:string}>} */
|
|
291
|
+
async function writeMarksLayer(file, obj) {
|
|
292
|
+
const v = validateMarksFile(obj);
|
|
293
|
+
if (!v.ok) return v;
|
|
294
|
+
const out = { version: FORMAT_VERSION };
|
|
295
|
+
if (obj.interactive !== undefined) out.interactive = obj.interactive;
|
|
296
|
+
out.marks = { ...obj.marks };
|
|
297
|
+
await writeJsonAtomic(file, out);
|
|
298
|
+
return { ok: true };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ── Resolution ──────────────────────────────────────────────────────────────
|
|
302
|
+
|
|
303
|
+
function layerEntries(layerObj) {
|
|
304
|
+
if (!layerObj || layerObj.ok === false || !isPlainObject(layerObj.marks)) return [];
|
|
305
|
+
const out = [];
|
|
306
|
+
for (const [rule, mark] of Object.entries(layerObj.marks)) {
|
|
307
|
+
const parsed = parseRule(rule);
|
|
308
|
+
if (parsed && MARK_SET.has(mark)) out.push({ rule, mark, parsed });
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Best match in one layer for a predicate over parsed rules. */
|
|
314
|
+
function bestInLayer(entries, matches) {
|
|
315
|
+
let best = null;
|
|
316
|
+
let bestScore = -1;
|
|
317
|
+
for (const e of entries) {
|
|
318
|
+
if (!matches(e.parsed)) continue;
|
|
319
|
+
const s = specificity(e.parsed);
|
|
320
|
+
if (s > bestScore) { best = e; bestScore = s; }
|
|
321
|
+
}
|
|
322
|
+
return best;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function resolveUnit(layers, matches) {
|
|
326
|
+
for (const { name, obj, entries } of layers) {
|
|
327
|
+
const hit = bestInLayer(entries, matches);
|
|
328
|
+
if (hit) return { mark: hit.mark, rule: hit.rule, layer: name, file: (obj && obj.file) || null };
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @returns {{mark:string, rule:string, layer:'project'|'system', file:string|null} | null}
|
|
335
|
+
* Never throws.
|
|
336
|
+
*/
|
|
337
|
+
function resolveMark(call, layersIn) {
|
|
338
|
+
try {
|
|
339
|
+
const { system, project } = layersIn || {};
|
|
340
|
+
if (!call || typeof call.tool !== 'string') return null;
|
|
341
|
+
const layers = [
|
|
342
|
+
{ name: 'project', obj: project, entries: layerEntries(project) },
|
|
343
|
+
{ name: 'system', obj: system, entries: layerEntries(system) },
|
|
344
|
+
];
|
|
345
|
+
if (call.tool !== 'Bash') {
|
|
346
|
+
return resolveUnit(layers, (p) => p.kind === 'mcp' && mcpMatches(p, call.tool));
|
|
347
|
+
}
|
|
348
|
+
const command = bashCommandOf(call);
|
|
349
|
+
if (command === null) return null;
|
|
350
|
+
let result = null;
|
|
351
|
+
for (const tokens of simpleCommands(command)) {
|
|
352
|
+
const r = resolveUnit(layers, (p) => p.kind === 'bash' && tokensMatch(p, tokens));
|
|
353
|
+
if (!r) continue;
|
|
354
|
+
if (!result || MARKS.indexOf(r.mark) > MARKS.indexOf(result.mark)) result = r;
|
|
355
|
+
}
|
|
356
|
+
return result;
|
|
357
|
+
} catch {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = {
|
|
363
|
+
MARKS,
|
|
364
|
+
BLOCKING_MARKS,
|
|
365
|
+
systemMarksPath,
|
|
366
|
+
projectMarksPath,
|
|
367
|
+
parseRule,
|
|
368
|
+
ruleMatches,
|
|
369
|
+
readMarksLayer,
|
|
370
|
+
validateMarksFile,
|
|
371
|
+
writeMarksLayer,
|
|
372
|
+
resolveMark,
|
|
373
|
+
};
|
|
@@ -7,20 +7,40 @@
|
|
|
7
7
|
* with every npx hash dir). A `KIT_VERSION` stamp file records which kit
|
|
8
8
|
* version is installed; files are overwritten only when the stamp differs, so
|
|
9
9
|
* a normal boot is one small read. Bump KIT_VERSION whenever any kit file
|
|
10
|
-
* changes
|
|
10
|
+
* changes. KIT_DIGEST pins the kit files' bytes; seedKit.test.cjs fails when
|
|
11
|
+
* the digest drifts, so a kit edit cannot ship without a bump.
|
|
11
12
|
*
|
|
12
13
|
* Fire-and-forget from index.cjs: errors are logged, never thrown.
|
|
13
14
|
* Kill-switch: SM_SEED_DEMO_VIDEO_KIT_DISABLE=1.
|
|
14
15
|
*/
|
|
15
16
|
const fs = require('node:fs');
|
|
17
|
+
const crypto = require('node:crypto');
|
|
16
18
|
const path = require('node:path');
|
|
17
19
|
const { schedulerHome } = require('../scheduler/schedulerPaths.cjs');
|
|
18
20
|
const { writeTextAtomic } = require('../util/atomicFs.cjs');
|
|
19
21
|
|
|
20
|
-
const KIT_VERSION = '
|
|
21
|
-
|
|
22
|
+
const KIT_VERSION = '3';
|
|
23
|
+
// sha256 of kitDigest(__dirname). Update together with a KIT_VERSION bump.
|
|
24
|
+
const KIT_DIGEST = 'b3bb70c8984d8b794a20a68d36c22e2f7fe97cdfad8215f5ae7294c47388571c';
|
|
25
|
+
const KIT_FILES = Object.freeze(['checks.cjs', 'sound.cjs', 'capture.cjs', 'frames.cjs', 'character.cjs', 'playwrightLoader.cjs']);
|
|
22
26
|
const STAMP_FILE = 'KIT_VERSION';
|
|
23
27
|
|
|
28
|
+
/** The single list of kit files (paths relative to the kit dir) the seeder copies. */
|
|
29
|
+
function kitFiles() {
|
|
30
|
+
return [...KIT_FILES];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Pure: sha256 hex over kitFiles() sorted by relative path, each as path + NUL + bytes. */
|
|
34
|
+
function kitDigest(srcDir) {
|
|
35
|
+
const h = crypto.createHash('sha256');
|
|
36
|
+
for (const f of kitFiles().sort()) {
|
|
37
|
+
h.update(f);
|
|
38
|
+
h.update(Buffer.from([0]));
|
|
39
|
+
h.update(fs.readFileSync(path.join(srcDir, f)));
|
|
40
|
+
}
|
|
41
|
+
return h.digest('hex');
|
|
42
|
+
}
|
|
43
|
+
|
|
24
44
|
function kitDestDir() {
|
|
25
45
|
return path.join(schedulerHome(), 'demo-video-kit');
|
|
26
46
|
}
|
|
@@ -31,11 +51,12 @@ async function seedDemoVideoKit({ logger = console, writeLog = () => {}, destDir
|
|
|
31
51
|
const stampPath = path.join(destDir, STAMP_FILE);
|
|
32
52
|
let installed = null;
|
|
33
53
|
try { installed = fs.readFileSync(stampPath, 'utf8').trim(); } catch { /* no stamp yet */ }
|
|
34
|
-
const
|
|
54
|
+
const files = kitFiles();
|
|
55
|
+
const filesPresent = files.every((f) => fs.existsSync(path.join(destDir, f)));
|
|
35
56
|
if (installed === String(kitVersion) && filesPresent) return { seeded: false, reason: 'current' };
|
|
36
57
|
|
|
37
58
|
fs.mkdirSync(destDir, { recursive: true });
|
|
38
|
-
for (const f of
|
|
59
|
+
for (const f of files) {
|
|
39
60
|
await writeTextAtomic(path.join(destDir, f), fs.readFileSync(path.join(srcDir, f), 'utf8'));
|
|
40
61
|
}
|
|
41
62
|
// Stamp last: a crash mid-copy leaves the old/no stamp, so the next boot retries.
|
|
@@ -49,4 +70,4 @@ async function seedDemoVideoKit({ logger = console, writeLog = () => {}, destDir
|
|
|
49
70
|
}
|
|
50
71
|
}
|
|
51
72
|
|
|
52
|
-
module.exports = { seedDemoVideoKit, kitDestDir, KIT_VERSION, KIT_FILES };
|
|
73
|
+
module.exports = { seedDemoVideoKit, kitDestDir, kitFiles, kitDigest, KIT_VERSION, KIT_DIGEST, KIT_FILES };
|