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
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* macroJobStatus.cjs — per built-in macro with a `job` declaration,
|
|
5
|
-
*
|
|
4
|
+
* macroJobStatus.cjs — per built-in macro with a `job` declaration, and per
|
|
5
|
+
* project Video tool (isProjectVideoTool) of this project, the state of its
|
|
6
|
+
* newest background job for one project: newest live queue row, else newest
|
|
6
7
|
* entry in a bounded tail of the project's scheduler history. Read-only.
|
|
8
|
+
* A tool's status also carries entryId (from the video entry's review
|
|
9
|
+
* dispatch.json, matched by slug); a completed review-stage run whose entry is
|
|
10
|
+
* waiting on the human reports status 'awaiting_review'.
|
|
7
11
|
*
|
|
8
12
|
* Plain Node, no Electron imports; all I/O is injected.
|
|
9
13
|
*/
|
|
10
14
|
|
|
11
15
|
const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
|
|
12
16
|
const { readTail } = require('../util/fileTail.cjs');
|
|
17
|
+
const { isProjectVideoTool } = require('./macroLibrary.cjs');
|
|
13
18
|
|
|
14
19
|
const HISTORY_TAIL_BYTES = 524288;
|
|
15
20
|
const RUNNING = new Set(['running', 'investigating']);
|
|
16
21
|
const FAILED = new Set(['failed', 'needs_review', 'skipped', 'cancelled']);
|
|
22
|
+
const REASON_MAX = 200;
|
|
23
|
+
const AWAITING_REVIEW = 'awaiting_review';
|
|
24
|
+
|
|
25
|
+
/** First non-empty line, at most REASON_MAX chars. */
|
|
26
|
+
function oneLineReason(v) {
|
|
27
|
+
const line = String(v).split(/\r?\n/).map((l) => l.trim()).find(Boolean) || '';
|
|
28
|
+
return line.length > REASON_MAX ? line.slice(0, REASON_MAX) : line;
|
|
29
|
+
}
|
|
17
30
|
|
|
18
31
|
function stateOf(status) {
|
|
19
32
|
if (RUNNING.has(status)) return 'running';
|
|
@@ -28,7 +41,7 @@ function reasonOf(row, status) {
|
|
|
28
41
|
return Number.isFinite(n) && n > 0 ? `Timed out at the ${n}-minute job budget` : 'Timed out at the job budget';
|
|
29
42
|
}
|
|
30
43
|
for (const v of [row.error, row.finalizeReason, row.terminalReason]) {
|
|
31
|
-
if (typeof v === 'string' && v.trim()) return v;
|
|
44
|
+
if (typeof v === 'string' && v.trim()) return oneLineReason(v);
|
|
32
45
|
}
|
|
33
46
|
return `Ended as ${status}`;
|
|
34
47
|
}
|
|
@@ -77,14 +90,25 @@ function parseHistory(text) {
|
|
|
77
90
|
return out;
|
|
78
91
|
}
|
|
79
92
|
|
|
93
|
+
function defaultListReviews(cwd) {
|
|
94
|
+
return require('../project-pages/videoReview.cjs').listReviews(cwd);
|
|
95
|
+
}
|
|
96
|
+
|
|
80
97
|
function defaultReadHistoryTail(cwd) {
|
|
81
98
|
const { projectHistoryPath } = require('../scheduler/queueStore.cjs');
|
|
82
99
|
return readTail(projectHistoryPath(cwd), HISTORY_TAIL_BYTES);
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
async function macroJobStatuses(
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
async function macroJobStatuses(
|
|
103
|
+
{ cwd } = {},
|
|
104
|
+
{ loadJobs, readHistoryTail = defaultReadHistoryTail, builtins = BUILTIN_MACROS, macros = [], listReviews = defaultListReviews } = {},
|
|
105
|
+
) {
|
|
106
|
+
const jobBuiltins = (builtins || []).filter((m) => m && m.job && m.id);
|
|
107
|
+
const builtinIds = new Set(jobBuiltins.map((m) => m.id));
|
|
108
|
+
const tools = (Array.isArray(macros) ? macros : [])
|
|
109
|
+
.filter((m) => m && m.id && !m.builtin && !builtinIds.has(m.id) && isProjectVideoTool(m, cwd));
|
|
110
|
+
const all = [...jobBuiltins.map((m) => ({ m, tool: false })), ...tools.map((m) => ({ m, tool: true }))];
|
|
111
|
+
if (!all.length) return [];
|
|
88
112
|
let live = [];
|
|
89
113
|
try {
|
|
90
114
|
const rows = typeof loadJobs === 'function' ? await loadJobs() : [];
|
|
@@ -100,13 +124,67 @@ async function macroJobStatuses({ cwd } = {}, { loadJobs, readHistoryTail = defa
|
|
|
100
124
|
return history;
|
|
101
125
|
};
|
|
102
126
|
|
|
127
|
+
let reviews = null; // lazily read once, only if some tool has a row
|
|
128
|
+
const loadReviews = async () => {
|
|
129
|
+
if (reviews) return reviews;
|
|
130
|
+
try {
|
|
131
|
+
const list = typeof listReviews === 'function' ? await listReviews(cwd) : [];
|
|
132
|
+
reviews = Array.isArray(list) ? list.filter((r) => r && r.dispatch && typeof r.dispatch.slug === 'string' && r.dispatch.slug) : [];
|
|
133
|
+
} catch { reviews = []; }
|
|
134
|
+
return reviews;
|
|
135
|
+
};
|
|
136
|
+
|
|
103
137
|
const out = [];
|
|
104
|
-
for (const m of
|
|
138
|
+
for (const { m, tool } of all) {
|
|
105
139
|
let row = newest(live.filter((r) => r.macroId === m.id));
|
|
106
140
|
if (!row) row = newest((await loadHistory()).filter((r) => r.macroId === m.id));
|
|
107
|
-
if (row)
|
|
141
|
+
if (!row) continue;
|
|
142
|
+
const st = toStatus(m.id, row);
|
|
143
|
+
if (tool) {
|
|
144
|
+
const review = row.slug ? (await loadReviews()).find((r) => r.dispatch.slug === row.slug) : null;
|
|
145
|
+
st.entryId = review ? review.entryId : null;
|
|
146
|
+
if (review && row.status === 'completed' && review.dispatch.stage === 'review' && review.status === 'waiting') {
|
|
147
|
+
st.status = AWAITING_REVIEW;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
out.push(st);
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Per run slug, the job state of that run: the newest live queue row for cwd,
|
|
157
|
+
* else the newest row in the project's history tail (read at most once).
|
|
158
|
+
* Value is null when no row with that slug exists for cwd. Never throws.
|
|
159
|
+
*/
|
|
160
|
+
async function jobStatusesBySlug({ cwd, slugs } = {}, { loadJobs, readHistoryTail = defaultReadHistoryTail } = {}) {
|
|
161
|
+
const wanted = [...new Set((Array.isArray(slugs) ? slugs : []).filter((s) => typeof s === 'string' && s))];
|
|
162
|
+
if (!wanted.length) return {};
|
|
163
|
+
const set = new Set(wanted);
|
|
164
|
+
let live = [];
|
|
165
|
+
try {
|
|
166
|
+
const rows = typeof loadJobs === 'function' ? await loadJobs() : [];
|
|
167
|
+
live = Array.isArray(rows) ? rows.filter((r) => r && r.cwd === cwd && set.has(r.slug)) : [];
|
|
168
|
+
} catch { live = []; }
|
|
169
|
+
|
|
170
|
+
let history = null; // lazily read once, only if some slug has no live row
|
|
171
|
+
const loadHistory = async () => {
|
|
172
|
+
if (history) return history;
|
|
173
|
+
try {
|
|
174
|
+
history = parseHistory(await readHistoryTail(cwd)).filter((r) => set.has(r.slug) && (!r.cwd || r.cwd === cwd));
|
|
175
|
+
} catch { history = []; }
|
|
176
|
+
return history;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const out = {};
|
|
180
|
+
for (const slug of wanted) {
|
|
181
|
+
let row = newest(live.filter((r) => r.slug === slug));
|
|
182
|
+
if (!row) row = newest((await loadHistory()).filter((r) => r.slug === slug));
|
|
183
|
+
if (!row) { out[slug] = null; continue; }
|
|
184
|
+
const { state, status, reason, startedAt, finishedAt } = toStatus(row.macroId ?? null, row);
|
|
185
|
+
out[slug] = { slug, state, status, reason, startedAt, finishedAt };
|
|
108
186
|
}
|
|
109
187
|
return out;
|
|
110
188
|
}
|
|
111
189
|
|
|
112
|
-
module.exports = { macroJobStatuses, HISTORY_TAIL_BYTES };
|
|
190
|
+
module.exports = { macroJobStatuses, jobStatusesBySlug, HISTORY_TAIL_BYTES, REASON_MAX, AWAITING_REVIEW };
|
|
@@ -35,6 +35,13 @@
|
|
|
35
35
|
* artifacts are per project); this module enforces that on load (a narrowed
|
|
36
36
|
* stored entry is widened to ['*']) and on save (projects forced to ['*']).
|
|
37
37
|
*
|
|
38
|
+
* A surface 'project-video' macro is one project's own Video tool (Project
|
|
39
|
+
* Home ▸ Video): its `projects` is exactly one absolute cwd — never '*', never
|
|
40
|
+
* widened, never given a second project — and it may carry a `job`
|
|
41
|
+
* declaration `{ estimateMinutes, repoPaths?, review? }` stored as is. saveMacro
|
|
42
|
+
* refuses `job` on every other surface and on built-ins; a read drops such a
|
|
43
|
+
* stale key (a built-in's job is read live from BUILTIN_MACROS by withBuiltinJobs).
|
|
44
|
+
*
|
|
38
45
|
* Plain Node, no Electron imports.
|
|
39
46
|
*/
|
|
40
47
|
|
|
@@ -62,7 +69,32 @@ const AbsolutePathSchema = z.string().max(1024).refine(
|
|
|
62
69
|
);
|
|
63
70
|
const MacroProjectEntrySchema = z.union([z.literal(ALL_PROJECTS), AbsolutePathSchema]);
|
|
64
71
|
const MacroProjectsSchema = z.array(MacroProjectEntrySchema).max(200);
|
|
65
|
-
const MacroSurfaceSchema = z.enum(['sessions', 'project-home']);
|
|
72
|
+
const MacroSurfaceSchema = z.enum(['sessions', 'project-home', 'project-video']);
|
|
73
|
+
|
|
74
|
+
const PROJECT_VIDEO_ONE_PROJECT = 'a Project Video tool belongs to exactly one project';
|
|
75
|
+
const JOB_SURFACE_ONLY = 'job is allowed only on a Project Video tool';
|
|
76
|
+
const JOB_NOT_ON_BUILTIN = 'a built-in macro job cannot be set';
|
|
77
|
+
|
|
78
|
+
/** Repo-relative path a Project Video job may write: '/'-separated, inside the repo, outside ops/git state. */
|
|
79
|
+
const JobRepoPathSchema = z.string().min(1).max(200).superRefine((v, ctx) => {
|
|
80
|
+
const bad = (message) => ctx.addIssue({ code: 'custom', message });
|
|
81
|
+
if (v.includes('\\')) bad('repoPath must use "/", not a backslash');
|
|
82
|
+
if (v.includes('\0')) bad('repoPath must not contain a NUL byte');
|
|
83
|
+
if (v.startsWith('/')) bad('repoPath must be relative (no leading "/")');
|
|
84
|
+
if (v.split('/').some((seg) => seg === '..' || seg === '.')) bad('repoPath must not contain a "." or ".." segment');
|
|
85
|
+
if (v.startsWith('session-manager-operations/')) bad('repoPath must not be under session-manager-operations/');
|
|
86
|
+
if (v.startsWith('.git')) bad('repoPath must not start with .git');
|
|
87
|
+
});
|
|
88
|
+
const MacroJobSchema = z.object({
|
|
89
|
+
estimateMinutes: z.number().int().min(5).max(60),
|
|
90
|
+
repoPaths: z.array(JobRepoPathSchema).min(1).max(20).optional(),
|
|
91
|
+
review: z.boolean().optional(),
|
|
92
|
+
}).strict();
|
|
93
|
+
|
|
94
|
+
/** True iff `projects` is exactly one absolute cwd (not '*'). */
|
|
95
|
+
function isSingleProject(projects) {
|
|
96
|
+
return Array.isArray(projects) && projects.length === 1 && projects[0] !== ALL_PROJECTS;
|
|
97
|
+
}
|
|
66
98
|
|
|
67
99
|
const MACRO_INPUT_MAX_LEN = 500;
|
|
68
100
|
const MACRO_PLACEHOLDER_RE = /\{\{\s*([a-z][a-z0-9_]{0,31})\s*\}\}/g;
|
|
@@ -152,7 +184,19 @@ function renderMacroPrompt(prompt, inputs, values) {
|
|
|
152
184
|
return { ok: true, prompt: rendered };
|
|
153
185
|
}
|
|
154
186
|
|
|
155
|
-
|
|
187
|
+
/**
|
|
188
|
+
* A job outside a custom Project Video tool is stale (e.g. a stored or live
|
|
189
|
+
* built-in job of a different shape): drop the key, keep the macro. saveMacro
|
|
190
|
+
* refuses such a job outright; reads stay tolerant.
|
|
191
|
+
*/
|
|
192
|
+
function stripForeignJob(entry) {
|
|
193
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry) || !('job' in entry)) return entry;
|
|
194
|
+
if (entry.surface === 'project-video' && !entry.builtin) return entry;
|
|
195
|
+
const { job: _stale, ...rest } = entry;
|
|
196
|
+
return rest;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const MacroObjectSchema = z.object({
|
|
156
200
|
id: MacroIdSchema,
|
|
157
201
|
label: MacroLabelSchema,
|
|
158
202
|
agentName: MacroAgentNameSchema,
|
|
@@ -169,7 +213,15 @@ const MacroSchema = z.object({
|
|
|
169
213
|
autoStartTargets: MacroProjectsSchema.optional(),
|
|
170
214
|
// Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
|
|
171
215
|
scriptStart: z.boolean().optional(),
|
|
172
|
-
|
|
216
|
+
// Background job declaration; only on a non-built-in 'project-video' macro.
|
|
217
|
+
job: MacroJobSchema.optional(),
|
|
218
|
+
}).superRefine((value, ctx) => {
|
|
219
|
+
refineInputs(value, ctx);
|
|
220
|
+
if (value.surface === 'project-video' && !isSingleProject(value.projects)) {
|
|
221
|
+
ctx.addIssue({ code: 'custom', path: ['projects'], message: PROJECT_VIDEO_ONE_PROJECT });
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const MacroSchema = z.preprocess(stripForeignJob, MacroObjectSchema);
|
|
173
225
|
|
|
174
226
|
const MacroSaveSchema = z.object({
|
|
175
227
|
id: MacroIdSchema.optional(),
|
|
@@ -188,6 +240,8 @@ const MacroSaveSchema = z.object({
|
|
|
188
240
|
autoStartTargets: MacroProjectsSchema.optional(),
|
|
189
241
|
// Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
|
|
190
242
|
scriptStart: z.boolean().optional(),
|
|
243
|
+
// Omitted keeps the stored job on update; `null` removes it. Only on a 'project-video' macro.
|
|
244
|
+
job: MacroJobSchema.nullable().optional(),
|
|
191
245
|
}).superRefine(refineInputs);
|
|
192
246
|
|
|
193
247
|
const MacroDeleteSchema = z.object({ id: MacroIdSchema });
|
|
@@ -536,15 +590,43 @@ async function loadStore(filePath, opts) {
|
|
|
536
590
|
/**
|
|
537
591
|
* Decorate built-in entries with their live `job` declaration from BUILTIN_MACROS.
|
|
538
592
|
* Never persisted: `job` is read at list time so a stored copy cannot freeze it.
|
|
593
|
+
* A non-built-in macro's stored job (a Project Video tool's) is returned unchanged.
|
|
539
594
|
*/
|
|
540
595
|
function withBuiltinJobs(macros) {
|
|
541
596
|
return macros.map((m) => {
|
|
542
|
-
const { job: _stale, ...rest } = m;
|
|
543
597
|
const b = BUILTIN_MACROS.find((x) => x.id === m.id);
|
|
544
|
-
|
|
598
|
+
if (!b) return m;
|
|
599
|
+
const { job: _stale, ...rest } = m;
|
|
600
|
+
return b.job ? { ...rest, job: b.job } : rest;
|
|
545
601
|
});
|
|
546
602
|
}
|
|
547
603
|
|
|
604
|
+
/** Pure. True only for a 'project-video' macro whose projects is exactly [cwd] and that declares a job. */
|
|
605
|
+
function isProjectVideoTool(macro, cwd) {
|
|
606
|
+
if (!macro || macro.surface !== 'project-video') return false;
|
|
607
|
+
if (!macro.job || typeof macro.job !== 'object') return false;
|
|
608
|
+
const projects = macro.projects;
|
|
609
|
+
return isSingleProject(projects) && typeof cwd === 'string' && projects[0] === normalizeCwd(cwd);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** Throws unless the merged save's surface/projects/job combination is allowed. */
|
|
613
|
+
function assertSurfaceRules(saved, parsedJob) {
|
|
614
|
+
if (saved.surface === 'project-video' && !isSingleProject(saved.projects)) {
|
|
615
|
+
throw new Error(PROJECT_VIDEO_ONE_PROJECT);
|
|
616
|
+
}
|
|
617
|
+
if (parsedJob !== undefined && parsedJob !== null) {
|
|
618
|
+
if (saved.builtin) throw new Error(JOB_NOT_ON_BUILTIN);
|
|
619
|
+
if (saved.surface !== 'project-video') throw new Error(JOB_SURFACE_ONLY);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Apply the save's `job` (omitted = keep, null = remove) and drop any job the surface cannot carry. */
|
|
624
|
+
function applyJob(saved, parsedJob) {
|
|
625
|
+
if (parsedJob === null) delete saved.job;
|
|
626
|
+
else if (parsedJob !== undefined) saved.job = parsedJob;
|
|
627
|
+
if (saved.surface !== 'project-video' || saved.builtin) delete saved.job;
|
|
628
|
+
}
|
|
629
|
+
|
|
548
630
|
/** @returns {Promise<Macro[]>} */
|
|
549
631
|
async function listMacros(opts = {}) {
|
|
550
632
|
return withBuiltinJobs(await listMacrosRaw(opts));
|
|
@@ -623,6 +705,8 @@ async function saveMacro(input, opts = {}) {
|
|
|
623
705
|
}
|
|
624
706
|
if (parsed.scriptStart === true) saved.scriptStart = true;
|
|
625
707
|
else if (parsed.scriptStart === false) delete saved.scriptStart;
|
|
708
|
+
assertSurfaceRules(saved, parsed.job);
|
|
709
|
+
applyJob(saved, parsed.job);
|
|
626
710
|
assertPlaceholdersDeclared(saved);
|
|
627
711
|
macros[idx] = saved;
|
|
628
712
|
} else {
|
|
@@ -646,6 +730,8 @@ async function saveMacro(input, opts = {}) {
|
|
|
646
730
|
saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
|
|
647
731
|
}
|
|
648
732
|
if (parsed.scriptStart === true) saved.scriptStart = true;
|
|
733
|
+
assertSurfaceRules(saved, parsed.job);
|
|
734
|
+
applyJob(saved, parsed.job);
|
|
649
735
|
assertPlaceholdersDeclared(saved);
|
|
650
736
|
macros.push(saved);
|
|
651
737
|
}
|
|
@@ -690,6 +776,8 @@ async function setMacroProject(input, opts = {}) {
|
|
|
690
776
|
if (macro.builtin && !enabled) return { ok: false, error: 'built-in macro visibility cannot be narrowed' };
|
|
691
777
|
const has = macro.projects.includes(target);
|
|
692
778
|
if (enabled === has) return { ok: true, macro };
|
|
779
|
+
// A Project Video tool never gains a second project nor loses its only one.
|
|
780
|
+
if (macro.surface === 'project-video') return { ok: false, error: PROJECT_VIDEO_ONE_PROJECT };
|
|
693
781
|
const projects = enabled ? [...macro.projects, target] : macro.projects.filter((p) => p !== target);
|
|
694
782
|
if (projects.length > 200) return { ok: false, error: 'too many projects' };
|
|
695
783
|
const updated = { ...macro, projects, updatedAt: new Date().toISOString() };
|
|
@@ -747,6 +835,8 @@ module.exports = {
|
|
|
747
835
|
renderMacroPrompt,
|
|
748
836
|
macroVisibleIn,
|
|
749
837
|
macroAllowsAutoStart,
|
|
838
|
+
isProjectVideoTool,
|
|
839
|
+
MacroJobSchema,
|
|
750
840
|
listMacros,
|
|
751
841
|
saveMacro,
|
|
752
842
|
deleteMacro,
|
|
@@ -21,32 +21,92 @@ const os = require('node:os');
|
|
|
21
21
|
const path = require('node:path');
|
|
22
22
|
const { execFileSync } = require('node:child_process');
|
|
23
23
|
|
|
24
|
+
const { lexer } = require('marked');
|
|
25
|
+
|
|
24
26
|
const MAX_IMPORT_DEPTH = 5;
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
const
|
|
27
|
+
// The claude CLI's (v2.1.325) @-import token rule: `@` at line start or after
|
|
28
|
+
// whitespace, then a run of non-space chars where `\ ` is an escaped space.
|
|
29
|
+
const IMPORT_TOKEN_RE = /(?:^|\s)@((?:[^\s\\]|\\ )+)/g;
|
|
30
|
+
const EXPLICIT_PREFIXES = ['./', '../', '~/', '/'];
|
|
28
31
|
|
|
29
|
-
function resolveImportPath(rawPath) {
|
|
32
|
+
function resolveImportPath(rawPath, fromFile) {
|
|
30
33
|
if (rawPath.startsWith('~/')) return path.join(os.homedir(), rawPath.slice(2));
|
|
31
34
|
if (rawPath === '~') return os.homedir();
|
|
32
|
-
return rawPath;
|
|
35
|
+
if (path.isAbsolute(rawPath) || !fromFile) return rawPath;
|
|
36
|
+
return path.resolve(path.dirname(fromFile), rawPath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Same acceptance test the CLI applies to a token after fragment-cut + unescape.
|
|
40
|
+
function isImportToken(tok) {
|
|
41
|
+
if (tok.startsWith('./') || tok.startsWith('~/')) return true;
|
|
42
|
+
if (tok.startsWith('/')) return tok !== '/';
|
|
43
|
+
return !tok.startsWith('@') && !/^[#%^&*()]+/.test(tok) && /^[a-zA-Z0-9._-]/.test(tok);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function scanText(text, fromFile, out) {
|
|
47
|
+
IMPORT_TOKEN_RE.lastIndex = 0;
|
|
48
|
+
let m;
|
|
49
|
+
while ((m = IMPORT_TOKEN_RE.exec(text)) !== null) {
|
|
50
|
+
const raw = m[1];
|
|
51
|
+
if (!raw) continue;
|
|
52
|
+
let tok = raw;
|
|
53
|
+
const hash = tok.indexOf('#');
|
|
54
|
+
if (hash !== -1) tok = tok.substring(0, hash);
|
|
55
|
+
if (!tok) continue;
|
|
56
|
+
tok = tok.replaceAll('\\ ', ' ');
|
|
57
|
+
if (!tok || !isImportToken(tok)) continue;
|
|
58
|
+
// Whole-line check: the line holding this match is exactly `@<raw>`.
|
|
59
|
+
const atIdx = m.index + m[0].length - raw.length - 1;
|
|
60
|
+
const lineStart = text.lastIndexOf('\n', atIdx) + 1;
|
|
61
|
+
const nl = text.indexOf('\n', atIdx);
|
|
62
|
+
const line = text.slice(lineStart, nl === -1 ? text.length : nl).trim();
|
|
63
|
+
const explicit = EXPLICIT_PREFIXES.some((p) => tok.startsWith(p)) || line === `@${raw}`;
|
|
64
|
+
out.push({ path: resolveImportPath(tok, fromFile), explicit });
|
|
65
|
+
}
|
|
33
66
|
}
|
|
34
67
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
68
|
+
function walkTokens(tokens, fromFile, out) {
|
|
69
|
+
for (const t of tokens) {
|
|
70
|
+
if (t.type === 'code' || t.type === 'codespan') continue;
|
|
71
|
+
if (t.type === 'html') {
|
|
72
|
+
const raw = t.raw || '';
|
|
73
|
+
const trimmed = raw.trimStart();
|
|
74
|
+
if (trimmed.startsWith('<!--') && trimmed.includes('-->')) {
|
|
75
|
+
const rest = raw.replace(/<!--[\s\S]*?-->/g, '');
|
|
76
|
+
if (rest.trim().length > 0) scanText(rest, fromFile, out);
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (t.type === 'text') scanText(t.text || '', fromFile, out);
|
|
81
|
+
if (t.tokens) walkTokens(t.tokens, fromFile, out);
|
|
82
|
+
if (t.items) walkTokens(t.items, fromFile, out);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Extracts every `@<path>` import from a file's raw markdown, using the claude
|
|
87
|
+
// CLI's rules (markdown-aware: code blocks/spans skipped). Relative paths
|
|
88
|
+
// resolve against fromFile's folder. Returns `{ path, explicit }[]`, deduped by
|
|
89
|
+
// path in first-seen order; `explicit` = written with path syntax
|
|
90
|
+
// (./ ../ ~/ /) or alone on its line.
|
|
91
|
+
function extractImportPaths(content, fromFile) {
|
|
92
|
+
const found = [];
|
|
93
|
+
walkTokens(lexer(content), fromFile, found);
|
|
94
|
+
const byPath = new Map();
|
|
95
|
+
for (const f of found) {
|
|
96
|
+
const prev = byPath.get(f.path);
|
|
97
|
+
if (prev) prev.explicit = prev.explicit || f.explicit;
|
|
98
|
+
else byPath.set(f.path, { ...f });
|
|
41
99
|
}
|
|
42
|
-
return
|
|
100
|
+
return [...byPath.values()];
|
|
43
101
|
}
|
|
44
102
|
|
|
45
103
|
// Recursively walks the import chain starting at rootPath, collecting a
|
|
46
104
|
// result per resolved import: { importPath, exists, nonEmpty, ok }.
|
|
47
105
|
// Depth-capped to guard against a cyclic-import pathological case. Visited
|
|
48
106
|
// paths are deduped so a diamond-shaped import graph doesn't get reported
|
|
49
|
-
// twice or blow the depth budget.
|
|
107
|
+
// twice or blow the depth budget. A non-regular-file target counts as
|
|
108
|
+
// missing; an unresolved import is only reported when written explicitly
|
|
109
|
+
// (so prose like "ping @bilko" is not flagged).
|
|
50
110
|
function walkImports(rootPath, depth = MAX_IMPORT_DEPTH, seen = new Set()) {
|
|
51
111
|
const results = [];
|
|
52
112
|
if (depth <= 0) return results;
|
|
@@ -59,20 +119,21 @@ function walkImports(rootPath, depth = MAX_IMPORT_DEPTH, seen = new Set()) {
|
|
|
59
119
|
return results;
|
|
60
120
|
}
|
|
61
121
|
|
|
62
|
-
for (const importPath of extractImportPaths(content)) {
|
|
122
|
+
for (const { path: importPath, explicit } of extractImportPaths(content, rootPath)) {
|
|
63
123
|
if (seen.has(importPath)) continue;
|
|
64
|
-
seen.add(importPath);
|
|
65
124
|
|
|
66
125
|
let exists = false;
|
|
67
126
|
let nonEmpty = false;
|
|
68
127
|
try {
|
|
69
128
|
const stat = fs.statSync(importPath);
|
|
70
|
-
exists =
|
|
71
|
-
nonEmpty = stat.size > 0;
|
|
129
|
+
exists = stat.isFile();
|
|
130
|
+
nonEmpty = exists && stat.size > 0;
|
|
72
131
|
} catch {
|
|
73
132
|
exists = false;
|
|
74
133
|
}
|
|
75
134
|
|
|
135
|
+
if (!exists && !explicit) continue;
|
|
136
|
+
seen.add(importPath);
|
|
76
137
|
results.push({ importPath, exists, nonEmpty, ok: exists && nonEmpty });
|
|
77
138
|
|
|
78
139
|
if (exists && nonEmpty) {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* projectVideoToolCheck.cjs — says whether a Project Video tool can actually
|
|
5
|
+
* run, with an actionable reason when it cannot.
|
|
6
|
+
*
|
|
7
|
+
* A Project Video tool runs as a headless scheduled job, so:
|
|
8
|
+
* 1. its persona must resolve as a PRD agentType (a file in
|
|
9
|
+
* <cwd>/.claude/agents/ or ~/.claude/agents/), and
|
|
10
|
+
* 2. when the persona declares a tools list, the job is scoped to it, so
|
|
11
|
+
* that list must include the SM MCP save tools the run calls.
|
|
12
|
+
*
|
|
13
|
+
* The MCP name rule mirrors scripts/scheduler-mcp-server.cjs jobToolScope
|
|
14
|
+
* (src/main never requires from scripts/; the test pins the agreement).
|
|
15
|
+
* Plain Node, no Electron imports. Never throws.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const { buildPersonaToolScope } = require('../claude/personaToolScope.cjs');
|
|
19
|
+
|
|
20
|
+
const MCP_SERVER = 'session-manager-scheduler';
|
|
21
|
+
const PROJECT_VIDEO_WRITE_ID = `mcp__${MCP_SERVER}__project_video_write`;
|
|
22
|
+
const PROJECT_VIDEO_REVIEW_WRITE_ID = `mcp__${MCP_SERVER}__project_video_review_write`;
|
|
23
|
+
|
|
24
|
+
const PERSONA_PREFIX = 'A Project Video tool runs as a scheduled job, so its persona must be a file in '
|
|
25
|
+
+ '<cwd>/.claude/agents/ or ~/.claude/agents/:';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* MCP tool names a scope admits, derived exactly as jobToolScope does:
|
|
29
|
+
* entries starting 'mcp__'; the name after the second '__'.
|
|
30
|
+
* @param {{ tools: string[] }} scope
|
|
31
|
+
* @returns {Set<string>}
|
|
32
|
+
*/
|
|
33
|
+
function mcpToolNamesFromScope(scope) {
|
|
34
|
+
const names = new Set();
|
|
35
|
+
for (const entry of scope.tools.map(String)) {
|
|
36
|
+
if (!entry.startsWith('mcp__')) continue;
|
|
37
|
+
const i = entry.indexOf('__', 5);
|
|
38
|
+
if (i > 0) names.add(entry.slice(i + 2));
|
|
39
|
+
}
|
|
40
|
+
return names;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {{ cwd: string, agentName: string, job?: { review?: boolean }|null }} input
|
|
45
|
+
* @param {{ assertAgentTypeWritable?: Function, resolvePrdPersonaForSpawn?: Function }} [deps]
|
|
46
|
+
* @returns {Promise<{ ok: true }|{ ok: false, error: string }>}
|
|
47
|
+
*/
|
|
48
|
+
async function checkProjectVideoToolRunnable({ cwd, agentName, job } = /** @type {any} */ ({}), deps = {}) {
|
|
49
|
+
const assertWritable = deps.assertAgentTypeWritable
|
|
50
|
+
|| require('../prd/prdAgentType.cjs').assertAgentTypeWritable;
|
|
51
|
+
const resolvePersona = deps.resolvePrdPersonaForSpawn
|
|
52
|
+
|| require('../claude/agentModelResolve.cjs').resolvePrdPersonaForSpawn;
|
|
53
|
+
|
|
54
|
+
if (!agentName || typeof agentName !== 'string') {
|
|
55
|
+
return { ok: false, error: `${PERSONA_PREFIX} no persona (agentName) is set.` };
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await assertWritable(cwd, agentName);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
const msg = err && /** @type {Error} */ (err).message ? /** @type {Error} */ (err).message : String(err);
|
|
61
|
+
return { ok: false, error: `${PERSONA_PREFIX} ${msg}` };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let persona;
|
|
65
|
+
try {
|
|
66
|
+
persona = await resolvePersona({ cwd, agentType: agentName });
|
|
67
|
+
} catch (err) {
|
|
68
|
+
const msg = err && /** @type {Error} */ (err).message ? /** @type {Error} */ (err).message : String(err);
|
|
69
|
+
return { ok: false, error: `${PERSONA_PREFIX} ${msg}` };
|
|
70
|
+
}
|
|
71
|
+
if (!persona || !persona.personaPath) {
|
|
72
|
+
return { ok: false, error: `${PERSONA_PREFIX} persona '${agentName}' could not be read.` };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const scope = buildPersonaToolScope(persona.tools);
|
|
76
|
+
if (!scope) return { ok: true };
|
|
77
|
+
|
|
78
|
+
const names = mcpToolNamesFromScope(scope);
|
|
79
|
+
const needed = [['project_video_write', PROJECT_VIDEO_WRITE_ID]];
|
|
80
|
+
if (job && job.review === true) needed.push(['project_video_review_write', PROJECT_VIDEO_REVIEW_WRITE_ID]);
|
|
81
|
+
const missing = needed.filter(([name]) => !names.has(name)).map(([, id]) => id);
|
|
82
|
+
if (missing.length === 0) return { ok: true };
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
error: `Persona '${agentName}' lists its tools, and a scheduled job can call only the MCP tools its persona lists. `
|
|
87
|
+
+ `Add ${missing.join(', ')} to the tools: line of ${persona.personaPath}, or the run cannot save its video.`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = {
|
|
92
|
+
checkProjectVideoToolRunnable,
|
|
93
|
+
mcpToolNamesFromScope,
|
|
94
|
+
PROJECT_VIDEO_WRITE_ID,
|
|
95
|
+
PROJECT_VIDEO_REVIEW_WRITE_ID,
|
|
96
|
+
};
|
|
@@ -377,6 +377,17 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
|
|
|
377
377
|
tools: "Read, Grep, Glob, Bash",
|
|
378
378
|
},
|
|
379
379
|
},
|
|
380
|
+
{
|
|
381
|
+
commit: "704173f3",
|
|
382
|
+
bodySha256: "043eefdb702c1e99cd1378428828e48d894b585d2f1617810f33e75688f7b39e",
|
|
383
|
+
fm: {
|
|
384
|
+
description: "Validates a finished PLAN (the PRDs its validate PRD lists) once, after its last PRD lands — re-runs each PRD's gate, checks every acceptance criterion against the real tree, reviews the plan's combined diff, and reports one VERIFIED/REFUTED verdict per PRD as checked JSON (the CLI enforces the schema). Runs headless as a scheduled PRD (agentType: validator); never edits product code and never queues work.",
|
|
385
|
+
executorOnly: "true",
|
|
386
|
+
model: "sonnet",
|
|
387
|
+
title: "Engineering — Plan Validator",
|
|
388
|
+
tools: "Read, Grep, Glob, Bash",
|
|
389
|
+
},
|
|
390
|
+
},
|
|
380
391
|
],
|
|
381
392
|
"demo-video-builder": [
|
|
382
393
|
{
|