claude-code-session-manager 0.126.0 → 0.127.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/bin/cli.cjs +71 -9
- package/bin/supervise.cjs +84 -0
- package/dist/assets/{AgentLibrary-bzeuZN4F.js → AgentLibrary-DKQznr7o.js} +1 -1
- package/dist/assets/{Button-8dWfDDuQ.js → Button-CZXqmIiM.js} +1 -1
- package/dist/assets/{DataModel-D4ybBPZN.js → DataModel-piyV33To.js} +1 -1
- package/dist/assets/{History-hsztE6yh.js → History-BxwtrKF2.js} +1 -1
- package/dist/assets/{Hooks-CRmZMQaW.js → Hooks-DogeSPII.js} +1 -1
- package/dist/assets/{Library-Czt3Bojd.js → Library-BDt6EeQQ.js} +1 -1
- package/dist/assets/{ListDetail-Cr6Ct_WX.js → ListDetail-CwS-LKar.js} +1 -1
- package/dist/assets/{McpServers-CeXJ2bng.js → McpServers-D2HVljgS.js} +1 -1
- package/dist/assets/{Memory-caujO8O3.js → Memory-hNzuOGn8.js} +1 -1
- package/dist/assets/{Panel-D64i9tGz.js → Panel-BLDrsUeq.js} +1 -1
- package/dist/assets/{Permissions-DpWOIrvr.js → Permissions-DzZ5vaJW.js} +1 -1
- package/dist/assets/{Plugins-Bd1ekP5P.js → Plugins-Cz9yaxzG.js} +2 -2
- package/dist/assets/{ProvenanceBadge-B96A_uZf.js → ProvenanceBadge-CCgLO4m9.js} +1 -1
- package/dist/assets/{SaveBar-D0Y2t-Ao.js → SaveBar-Shmn699J.js} +1 -1
- package/dist/assets/{Scheduler-Y5_YbNrC.js → Scheduler-Bqr0WHNd.js} +1 -1
- package/dist/assets/{ScopeSwitcher-BmWA_dP9.js → ScopeSwitcher-CBx1fB5g.js} +1 -1
- package/dist/assets/{Settings-Bcf65bpL.js → Settings-Ci8in-yF.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-BeSNXloA.js → SkillReferenceGraph-BWwljba8.js} +1 -1
- package/dist/assets/{Skills-DwnQKJVc.js → Skills-BON6o-c4.js} +1 -1
- package/dist/assets/{SystemPrompt-Dih6SCmL.js → SystemPrompt-D5epIYYs.js} +1 -1
- package/dist/assets/{TagLibrary-BZ-Kp10P.js → TagLibrary-C2qDZROJ.js} +1 -1
- package/dist/assets/{TiptapBody-C2nEUmF7.js → TiptapBody-SZhI3-bW.js} +1 -1
- package/dist/assets/{Toggle-Dw8-zNQo.js → Toggle-C_qFDG0g.js} +1 -1
- package/dist/assets/{ViewTabs-CoYPKGN-.js → ViewTabs-C9q5WCEd.js} +1 -1
- package/dist/assets/{historyTotals-BbKcNpV7.js → historyTotals-BCl7IOhY.js} +1 -1
- package/dist/assets/{index-DgPUERhe.js → index-CMIYLbPb.js} +73 -73
- package/dist/assets/{settingsSchema-6doG_61l.js → settingsSchema-BBrRBrBr.js} +1 -1
- package/dist/assets/{skillFrontmatter-BYMYWDfb.js → skillFrontmatter-B01qJk6N.js} +1 -1
- package/dist/assets/{useAgentsDirWatch-Cqabjieh.js → useAgentsDirWatch-CuR3GSjS.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-web/app.js +307 -307
- package/package.json +1 -1
- package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
- package/scripts/scheduler-mcp-server.cjs +39 -1
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +37 -4
- package/src/main/crashDiagnostics.cjs +83 -8
- package/src/main/health.cjs +16 -5
- package/src/main/index.cjs +32 -0
- package/src/main/lib/chatBootRecovery.cjs +136 -0
- package/src/main/lib/chatInflight.cjs +88 -0
- package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
- package/src/main/lib/epic/epicValidationHook.cjs +14 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
- package/src/main/lib/mcpToolCatalog.cjs +22 -3
- package/src/main/lib/persona-macro/builtinMacros.cjs +12 -1
- package/src/main/lib/persona-macro/macroLibrary.cjs +57 -3
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/prdCreate.cjs +5 -1
- package/src/main/lib/process/childWithLog.cjs +38 -95
- package/src/main/lib/process/memoryScope.cjs +140 -0
- package/src/main/lib/process/ozonePlatform.cjs +15 -0
- package/src/main/lib/process/procIdentity.cjs +10 -3
- package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
- package/src/main/lib/scheduler/cpuSample.cjs +147 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
- package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
- package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
- package/src/main/lib/scheduler/loadGate.cjs +116 -45
- package/src/main/lib/scheduler/queueStore.cjs +5 -2
- package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
- package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
- package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
- package/src/main/scheduler/budget.cjs +31 -0
- package/src/main/scheduler/prdPaths.cjs +54 -0
- package/src/main/scheduler/reviewLadder.cjs +17 -0
- package/src/main/scheduler/starvation.cjs +22 -0
- package/src/main/scheduler.cjs +522 -68
- package/src/main/templates/PRD_AUTHORING.md +5 -2
- package/src/main/usage.cjs +4 -2
- package/src/preload/api.d.ts +12 -2
- package/src/seed/agents/demo-video-builder.md +62 -14
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Durable ledger of in-flight chat turns (~/.claude/session-manager/chat-inflight.json).
|
|
5
|
+
* begin() after a successful spawn, end() when the turn settles; list() lets the next
|
|
6
|
+
* boot see what was running. Carries NO prompt text and nothing from childEnv.
|
|
7
|
+
* Never throws into a turn: a missing/corrupt ledger reads as empty.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const { readJsonOr, writeJsonAtomic } = require('./util/atomicFs.cjs');
|
|
12
|
+
const { schedulerHome } = require('./scheduler/schedulerPaths.cjs');
|
|
13
|
+
|
|
14
|
+
function ledgerPath() {
|
|
15
|
+
return process.env.SM_CHAT_INFLIGHT_PATH || path.join(schedulerHome(), 'chat-inflight.json');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// One in-process chain serializes every read-modify-write.
|
|
19
|
+
let chain = Promise.resolve();
|
|
20
|
+
|
|
21
|
+
async function readAll() {
|
|
22
|
+
try {
|
|
23
|
+
const data = await readJsonOr(ledgerPath(), {});
|
|
24
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
25
|
+
} catch { return {}; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function enqueue(mutate) {
|
|
29
|
+
const next = chain.then(async () => {
|
|
30
|
+
try {
|
|
31
|
+
const all = await readAll();
|
|
32
|
+
mutate(all);
|
|
33
|
+
await writeJsonAtomic(ledgerPath(), all);
|
|
34
|
+
} catch { /* ledger is best-effort */ }
|
|
35
|
+
});
|
|
36
|
+
chain = next;
|
|
37
|
+
return next;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Fields of a run() payload that may be persisted (never prompt / env). */
|
|
41
|
+
function sanitize(sessionId, entry) {
|
|
42
|
+
const e = entry || {};
|
|
43
|
+
const out = { sessionId, startedAt: Date.now() };
|
|
44
|
+
for (const k of ['tabId', 'cwd', 'pid', 'startedAt', 'resume', 'silent', 'promptId', 'origin', 'worktreeDirHint']) {
|
|
45
|
+
if (e[k] !== undefined && typeof e[k] !== 'function') out[k] = e[k];
|
|
46
|
+
}
|
|
47
|
+
out.sessionId = sessionId;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function begin(sessionId, entry) {
|
|
52
|
+
if (!sessionId) return Promise.resolve();
|
|
53
|
+
return enqueue((all) => { all[sessionId] = sanitize(sessionId, entry); });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function end(sessionId) {
|
|
57
|
+
if (!sessionId) return Promise.resolve();
|
|
58
|
+
return enqueue((all) => { delete all[sessionId]; });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const RECOVERED_KEY = '__recovered';
|
|
62
|
+
|
|
63
|
+
/** @returns {Promise<object[]>} */
|
|
64
|
+
async function list() {
|
|
65
|
+
await chain;
|
|
66
|
+
const all = await readAll();
|
|
67
|
+
return Object.entries(all).filter(([k]) => k !== RECOVERED_KEY).map(([, v]) => v);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Stamp a session as boot-recovered now (separate key, survives begin/end). */
|
|
71
|
+
function markRecovered(sessionId, at = Date.now()) {
|
|
72
|
+
if (!sessionId) return Promise.resolve();
|
|
73
|
+
return enqueue((all) => {
|
|
74
|
+
const m = all[RECOVERED_KEY] && typeof all[RECOVERED_KEY] === 'object' ? all[RECOVERED_KEY] : {};
|
|
75
|
+
for (const [k, v] of Object.entries(m)) if (at - Number(v) > 7 * 86400000) delete m[k];
|
|
76
|
+
m[sessionId] = at;
|
|
77
|
+
all[RECOVERED_KEY] = m;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @returns {Promise<Record<string, number>>} sessionId → last recovery ms */
|
|
82
|
+
async function recoveredMap() {
|
|
83
|
+
await chain;
|
|
84
|
+
const m = (await readAll())[RECOVERED_KEY];
|
|
85
|
+
return m && typeof m === 'object' ? m : {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { begin, end, list, ledgerPath, markRecovered, recoveredMap };
|
|
@@ -6,12 +6,38 @@
|
|
|
6
6
|
* checks the completed PRDs of a settled Epic that no validator has checked.
|
|
7
7
|
* Pure: no fs, no child_process. The caller decides when a sweep is needed and
|
|
8
8
|
* whether to create the PRD.
|
|
9
|
+
*
|
|
10
|
+
* Sizing: the sweep's kill budget must cover every gate running to its own
|
|
11
|
+
* timeout plus reading/writing time, because a kill loses every minute of
|
|
12
|
+
* evidence. Why these numbers: across 916 real validator runs the most
|
|
13
|
+
* non-gate time was 13.7 minutes, hence VALIDATOR_OVERHEAD_MS = 15 minutes;
|
|
14
|
+
* UNKNOWN_GATE_MS matches definitionOfDone's DEFAULT_GATE_TIMEOUT_MS; the plain
|
|
15
|
+
* sum with no dedupe follows the validator's rule to re-run every command in
|
|
16
|
+
* each PRD's gate. Real runs sit far under their timeouts (median 7%), so about
|
|
17
|
+
* 2.3% of sweeps (3 of 130) will split that strictly did not need it. An extra
|
|
18
|
+
* validator costs far less than a lost run, so that is accepted.
|
|
9
19
|
*/
|
|
10
20
|
|
|
11
21
|
const { bareSlug } = require('../prd/depSlugResolve.cjs');
|
|
22
|
+
const { JOB_BUDGET_FACTOR, JOB_BUDGET_CEILING_MS } = require('../scheduler/schedulerConfig.cjs');
|
|
12
23
|
|
|
13
24
|
const SWEEP_SLUG_PREFIX = 'validate-sweep';
|
|
14
25
|
const MAX_SWEEP_PRDS = 25;
|
|
26
|
+
const VALIDATOR_OVERHEAD_MS = 15 * 60_000;
|
|
27
|
+
const UNKNOWN_GATE_MS = 5 * 60_000;
|
|
28
|
+
const MIN_VALIDATOR_ESTIMATE_MINUTES = 10;
|
|
29
|
+
|
|
30
|
+
/** A value that is not a finite number >= 0 counts UNKNOWN_GATE_MS; 0 stays 0. */
|
|
31
|
+
function gateMsOrUnknown(v) {
|
|
32
|
+
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : UNKNOWN_GATE_MS;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** max(10, ceil((sum + overhead) / 60000 / factor)). */
|
|
36
|
+
function validatorEstimateMinutes(gateMsValues, { factor } = {}) {
|
|
37
|
+
const f = typeof factor === 'number' && factor > 0 ? factor : JOB_BUDGET_FACTOR;
|
|
38
|
+
const sum = (Array.isArray(gateMsValues) ? gateMsValues : []).reduce((a, v) => a + gateMsOrUnknown(v), 0);
|
|
39
|
+
return Math.max(MIN_VALIDATOR_ESTIMATE_MINUTES, Math.ceil((sum + VALIDATOR_OVERHEAD_MS) / 60_000 / f));
|
|
40
|
+
}
|
|
15
41
|
|
|
16
42
|
const PERSONA_LINE = 'Work as the validator persona — the procedure is your system prompt.';
|
|
17
43
|
|
|
@@ -27,14 +53,31 @@ function isSweepValidatorSlug(slug) {
|
|
|
27
53
|
* baseSha?: string | null, now: number | Date | string }} args
|
|
28
54
|
* @returns {{ input: object | null, carried: Array<object> }}
|
|
29
55
|
*/
|
|
30
|
-
function buildSweepValidatorInput({ epicId, cwd, uncovered, baseSha, now }) {
|
|
56
|
+
function buildSweepValidatorInput({ epicId, cwd, uncovered, baseSha, now, jobBudget }) {
|
|
31
57
|
if (!Array.isArray(uncovered) || uncovered.length === 0) return { input: null, carried: [] };
|
|
32
58
|
|
|
33
|
-
const
|
|
34
|
-
|
|
59
|
+
const factor = jobBudget && typeof jobBudget.factor === 'number' && jobBudget.factor > 0
|
|
60
|
+
? jobBudget.factor : JOB_BUDGET_FACTOR;
|
|
61
|
+
const ceilingMs = jobBudget && typeof jobBudget.ceilingMs === 'number' && jobBudget.ceilingMs > 0
|
|
62
|
+
? jobBudget.ceilingMs : JOB_BUDGET_CEILING_MS;
|
|
63
|
+
|
|
64
|
+
// First-fit in input order; the first entry always joins.
|
|
65
|
+
const covered = [];
|
|
66
|
+
const carried = [];
|
|
67
|
+
let workMs = VALIDATOR_OVERHEAD_MS;
|
|
68
|
+
for (const entry of uncovered) {
|
|
69
|
+
const g = gateMsOrUnknown(entry && entry.gateMs);
|
|
70
|
+
if (covered.length === 0 || (covered.length < MAX_SWEEP_PRDS && workMs + g <= ceilingMs)) {
|
|
71
|
+
covered.push(entry);
|
|
72
|
+
workMs += g;
|
|
73
|
+
} else {
|
|
74
|
+
carried.push(entry);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const budgetExempt = covered.length === 1 && workMs > ceilingMs;
|
|
35
78
|
const names = covered.map((entry) => entry.bareSlug || bareSlug(entry.slug));
|
|
36
79
|
|
|
37
|
-
const stamp = new Date(now).toISOString().replace(/\D/g, '').slice(0,
|
|
80
|
+
const stamp = new Date(now).toISOString().replace(/\D/g, '').slice(0, 14);
|
|
38
81
|
const slug = `${SWEEP_SLUG_PREFIX}-${stamp}`;
|
|
39
82
|
const recordPath = `session-manager-operations/reviews/validation/${epicId}/${slug}.md`;
|
|
40
83
|
|
|
@@ -60,7 +103,7 @@ function buildSweepValidatorInput({ epicId, cwd, uncovered, baseSha, now }) {
|
|
|
60
103
|
outOfScope: ['Editing product code', 'Queuing fix PRDs'],
|
|
61
104
|
gate: ['none'],
|
|
62
105
|
files: [recordPath],
|
|
63
|
-
estimateMinutes:
|
|
106
|
+
estimateMinutes: validatorEstimateMinutes(covered.map((e) => e.gateMs), { factor }),
|
|
64
107
|
agentType: 'validator',
|
|
65
108
|
tag: 'build',
|
|
66
109
|
sourcePromptId: epicId,
|
|
@@ -68,7 +111,18 @@ function buildSweepValidatorInput({ epicId, cwd, uncovered, baseSha, now }) {
|
|
|
68
111
|
dependsOn: names,
|
|
69
112
|
};
|
|
70
113
|
|
|
114
|
+
if (budgetExempt) input.budgetExempt = true;
|
|
115
|
+
|
|
71
116
|
return { input, carried };
|
|
72
117
|
}
|
|
73
118
|
|
|
74
|
-
module.exports = {
|
|
119
|
+
module.exports = {
|
|
120
|
+
SWEEP_SLUG_PREFIX,
|
|
121
|
+
MAX_SWEEP_PRDS,
|
|
122
|
+
VALIDATOR_OVERHEAD_MS,
|
|
123
|
+
UNKNOWN_GATE_MS,
|
|
124
|
+
MIN_VALIDATOR_ESTIMATE_MINUTES,
|
|
125
|
+
isSweepValidatorSlug,
|
|
126
|
+
validatorEstimateMinutes,
|
|
127
|
+
buildSweepValidatorInput,
|
|
128
|
+
};
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* Kill-switch: SM_EPIC_VALIDATION_DISABLE=1 turns the whole runner off.
|
|
12
12
|
* SM_EPIC_SETTLE_SECONDS sets the debounce before a settle run (default 120).
|
|
13
13
|
*
|
|
14
|
+
* A sweep covers what fits one budget; the rest go to the next settle.
|
|
15
|
+
*
|
|
14
16
|
* This module spawns NO process itself: the sweep validator is a PRD queued
|
|
15
17
|
* through the scheduler (which acquires a lib/scheduler/sessionSlots.cjs slot),
|
|
16
18
|
* and the digest goes through the chat queue's pump, which does the same.
|
|
@@ -108,6 +110,8 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
|
|
|
108
110
|
loadHistory = async () => [],
|
|
109
111
|
createPrd,
|
|
110
112
|
resolveBaseSha = async () => null,
|
|
113
|
+
readGateMs = async () => new Map(),
|
|
114
|
+
jobBudget,
|
|
111
115
|
sendPrompt,
|
|
112
116
|
appendResponseEvent,
|
|
113
117
|
now = Date.now,
|
|
@@ -158,14 +162,22 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
|
|
|
158
162
|
}
|
|
159
163
|
let baseSha = null;
|
|
160
164
|
try { baseSha = earliest ? await resolveBaseSha(cwd, earliest.landedCommit) : null; } catch { baseSha = null; }
|
|
161
|
-
|
|
165
|
+
let gateMap = new Map();
|
|
166
|
+
try {
|
|
167
|
+
const m = await readGateMs(cwd, epicId, candidates.map((c) => c.slug));
|
|
168
|
+
if (m instanceof Map) gateMap = m;
|
|
169
|
+
} catch (e) {
|
|
170
|
+
try { (log || console).error('[epicValidationHook] readGateMs failed', epicId, e); } catch { /* noop */ }
|
|
171
|
+
}
|
|
172
|
+
const sized = candidates.map((c) => ({ ...c, gateMs: gateMap.get(c.slug) }));
|
|
173
|
+
const { input, carried } = buildSweepValidatorInput({ epicId, cwd, uncovered: sized, baseSha, now: now(), jobBudget });
|
|
162
174
|
let res;
|
|
163
175
|
try {
|
|
164
176
|
res = await createPrd(input);
|
|
165
177
|
} catch (e) {
|
|
166
178
|
res = { ok: false, error: e && e.message ? e.message : String(e) };
|
|
167
179
|
}
|
|
168
|
-
if (res && res.ok) return { action: 'sweep-queued', slug: input.slug };
|
|
180
|
+
if (res && res.ok) return { action: 'sweep-queued', slug: input.slug, carried: carried.length };
|
|
169
181
|
notValidatedReason = `the validator persona could not be queued: ${(res && res.error) || 'unknown error'}`;
|
|
170
182
|
} else {
|
|
171
183
|
notValidatedReason = 'a sweep validator already ran and did not check them';
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* macroAdminRoutes.cjs — loopback admin HTTP routes so an agent session (via
|
|
3
|
-
* the scheduler MCP
|
|
3
|
+
* the scheduler MCP) can list, create/update and delete a HOT KEYS macro
|
|
4
4
|
* for its own project, through the existing macroLibrary.cjs store:
|
|
5
5
|
* GET /admin/macros?cwd=… -> { ok, macros }
|
|
6
6
|
* POST /admin/macros/save {cwd, id?, label, agentName, tag, prompt, inputs?}
|
|
7
|
+
* POST /admin/macros/delete {cwd, id, originClaudeSessionId?}
|
|
8
|
+
* -> { ok, deleted, macro }
|
|
9
|
+
* delete removes the macro from THIS project through
|
|
10
|
+
* macroLibrary.removeMacroFromProject (deleted:false when other projects still
|
|
11
|
+
* list it), fires onChanged once and appends one `admin_macro_delete` audit
|
|
12
|
+
* event on success; every refusal is a 400 with no onChanged and no audit.
|
|
7
13
|
*
|
|
8
14
|
* cwd resolution matches projectHomeAdminRoutes.cjs's resolveCwd exactly
|
|
9
15
|
* (reused, not copied). A create always stores `projects: [resolvedCwd]`,
|
|
@@ -20,6 +26,30 @@
|
|
|
20
26
|
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
21
27
|
const { resolveCwd } = require('./projectHomeAdminRoutes.cjs');
|
|
22
28
|
const macroLibrary = require('../persona-macro/macroLibrary.cjs');
|
|
29
|
+
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
30
|
+
|
|
31
|
+
/** Read + parse a JSON object body; on failure sends the 400 and returns null. */
|
|
32
|
+
async function readJsonBody(req, res) {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = await readBody(req);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
let body;
|
|
41
|
+
try {
|
|
42
|
+
body = raw ? JSON.parse(raw) : {};
|
|
43
|
+
} catch {
|
|
44
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (body === null || typeof body !== 'object') {
|
|
48
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
23
53
|
|
|
24
54
|
function listHandler(onChanged, libOpts) {
|
|
25
55
|
return async (_req, res, query) => {
|
|
@@ -38,20 +68,8 @@ function listHandler(onChanged, libOpts) {
|
|
|
38
68
|
|
|
39
69
|
function saveHandler(onChanged, libOpts) {
|
|
40
70
|
return async (req, res) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
raw = await readBody(req);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
let body;
|
|
49
|
-
try {
|
|
50
|
-
body = raw ? JSON.parse(raw) : {};
|
|
51
|
-
} catch {
|
|
52
|
-
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
71
|
+
const body = await readJsonBody(req, res);
|
|
72
|
+
if (!body) return;
|
|
55
73
|
const resolved = resolveCwd(body.cwd);
|
|
56
74
|
if (!resolved.ok) {
|
|
57
75
|
sendJson(res, resolved.status, { ok: false, error: resolved.error });
|
|
@@ -101,10 +119,48 @@ function saveHandler(onChanged, libOpts) {
|
|
|
101
119
|
};
|
|
102
120
|
}
|
|
103
121
|
|
|
122
|
+
function deleteHandler(onChanged, libOpts) {
|
|
123
|
+
return async (req, res) => {
|
|
124
|
+
const body = await readJsonBody(req, res);
|
|
125
|
+
if (!body) return;
|
|
126
|
+
const resolved = resolveCwd(body.cwd);
|
|
127
|
+
if (!resolved.ok) {
|
|
128
|
+
sendJson(res, resolved.status, { ok: false, error: resolved.error });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (typeof body.id !== 'string' || !body.id) {
|
|
132
|
+
sendJson(res, 400, { ok: false, error: 'id is required' });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let result;
|
|
136
|
+
try {
|
|
137
|
+
result = await macroLibrary.removeMacroFromProject({ id: body.id, cwd: resolved.cwd }, libOpts);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
sendJson(res, 400, { ok: false, error: e?.issues?.[0]?.message ?? e?.message ?? 'delete failed' });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!result.ok) {
|
|
143
|
+
sendJson(res, 400, result);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const origin = body.originClaudeSessionId;
|
|
147
|
+
appendAuditEvent('admin_macro_delete', {
|
|
148
|
+
route: '/admin/macros/delete',
|
|
149
|
+
cwd: resolved.cwd,
|
|
150
|
+
deleted: result.deleted,
|
|
151
|
+
macro: result.macro,
|
|
152
|
+
originClaudeSessionId: typeof origin === 'string' && origin.length >= 1 && origin.length <= 128 ? origin : null,
|
|
153
|
+
});
|
|
154
|
+
if (onChanged) onChanged();
|
|
155
|
+
sendJson(res, 200, result);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
104
159
|
function registerAdminRoute(adminHttp, { onChanged } = {}, opts = {}) {
|
|
105
160
|
const libOpts = opts.filePath ? { filePath: opts.filePath } : undefined;
|
|
106
161
|
adminHttp.registerRoute('GET', '/admin/macros', listHandler(onChanged, libOpts));
|
|
107
162
|
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts));
|
|
163
|
+
adminHttp.registerRoute('POST', '/admin/macros/delete', deleteHandler(onChanged, libOpts));
|
|
108
164
|
}
|
|
109
165
|
|
|
110
166
|
module.exports = {
|
|
@@ -246,7 +246,8 @@ const MCP_TOOL_CATALOG = [
|
|
|
246
246
|
whenToUse: 'Use to programmatically continue a conversation in a tab that is already open in the running app.',
|
|
247
247
|
whenNotToUse: 'Do not use to start new work in a project you are not already chatting in — that is /develop (scheduler_create_prd) or feedback_open_session.',
|
|
248
248
|
exampleArgs: { tabId: 'a1b2c3d4-tab-id', prompt: 'Please continue with the next step.' },
|
|
249
|
-
notes: '
|
|
249
|
+
notes: 'tabId is an open tab\'s id or an Epic id (Epic chats are keyed by Epic id), never a Claude session id. '
|
|
250
|
+
+ 'A refused send (unknown tab/Epic) returns ok false with disposition and reason; an unconfirmed send (no window or ack timeout) stays ok true.',
|
|
250
251
|
},
|
|
251
252
|
{
|
|
252
253
|
name: 'feedback_list_projects',
|
|
@@ -375,7 +376,7 @@ const MCP_TOOL_CATALOG = [
|
|
|
375
376
|
purpose: "List this project's HOT KEYS macros — the saved (agent, tag, prompt) one-click buttons shown "
|
|
376
377
|
+ "in the Sessions tab's HOT KEYS strip, via the session-manager app's admin API.",
|
|
377
378
|
whenToUse: 'Use to see what macros already exist for this project (including machine-wide `*` macros and '
|
|
378
|
-
+ 'built-ins) before deciding whether to add or
|
|
379
|
+
+ 'built-ins) before deciding whether to add, update or delete one.',
|
|
379
380
|
whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this only ever returns '
|
|
380
381
|
+ "macros visible to the resolved cwd, never another project's.",
|
|
381
382
|
exampleArgs: { cwd: '/home/bilko/Projects/session-manager' },
|
|
@@ -393,7 +394,8 @@ const MCP_TOOL_CATALOG = [
|
|
|
393
394
|
whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this call is refused if '
|
|
394
395
|
+ '`id` resolves to a macro not visible to this project. Built-in macros (`id` starting with `builtin-`) '
|
|
395
396
|
+ "cannot be edited through this route. A macro is a HUMAN's one-click button, not a task runner — never "
|
|
396
|
-
+ 'create or update one unless the human has actually asked for that macro to exist.'
|
|
397
|
+
+ 'create or update one unless the human has actually asked for that macro to exist. '
|
|
398
|
+
+ 'To remove a macro use macro_delete; never rewrite it into a placeholder.',
|
|
397
399
|
exampleArgs: {
|
|
398
400
|
cwd: '/home/bilko/Projects/session-manager',
|
|
399
401
|
label: 'Publish git + npm',
|
|
@@ -408,6 +410,23 @@ const MCP_TOOL_CATALOG = [
|
|
|
408
410
|
+ 'when pressing the macro; reference each in the prompt as {{name}}. Omitting `inputs` on update keeps '
|
|
409
411
|
+ 'the existing inputs; `[]` clears them.',
|
|
410
412
|
},
|
|
413
|
+
{
|
|
414
|
+
name: 'macro_delete',
|
|
415
|
+
group: 'macros',
|
|
416
|
+
purpose: "Remove one of this project's HOT KEYS macros via the session-manager app's admin API, through the same "
|
|
417
|
+
+ 'macroLibrary.cjs store the Sessions HOT KEYS strip reads from, so an open strip updates at once.',
|
|
418
|
+
whenToUse: 'Use when the human has asked for that macro to go, for example after its work moved to another project. '
|
|
419
|
+
+ 'Get the `id` from macro_list first.',
|
|
420
|
+
whenNotToUse: "WHEN NOT TO USE IT: a macro is a HUMAN's one-click button and this cannot be undone — never delete one "
|
|
421
|
+
+ "unless the human has asked for that macro to go. It always acts for the calling session's own project: there is "
|
|
422
|
+
+ 'no `cwd` argument, and a macro not listed for this project is refused. Built-in macros are refused. A macro shown '
|
|
423
|
+
+ 'in every project is refused too; only the human can remove it, from the HOT KEYS panel. Refused in a scheduled job '
|
|
424
|
+
+ "and outside a Session Manager session, because no human is there to ask. To change a macro, use macro_save. "
|
|
425
|
+
+ "Another project's macro belongs to that project: use feedback_open_session.",
|
|
426
|
+
exampleArgs: { id: 'blog-video-8d618a' },
|
|
427
|
+
notes: 'Returns { ok, deleted, macro }. `deleted: true` means the macro is gone and `macro` is its last copy. '
|
|
428
|
+
+ '`deleted: false` means other projects still list it, so only this project was dropped. A refusal comes back as an error result.',
|
|
429
|
+
},
|
|
411
430
|
{
|
|
412
431
|
name: 'session_manager_help',
|
|
413
432
|
group: 'help',
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
* These drive Project Home's one-click actions through the same (agent, tag,
|
|
7
7
|
* prompt) hot-key framework as user-created macros. `macroLibrary.cjs`'s
|
|
8
8
|
* `ensureBuiltins` seeds any entry here that is missing from macros.json, and
|
|
9
|
-
* upgrades
|
|
9
|
+
* upgrades a stored copy whose `builtinVersion` is behind this file when it is
|
|
10
|
+
* unedited: `updatedAt === createdAt`, OR its label/agent/tag match and its
|
|
11
|
+
* prompt is one of `priorPrompts` (the editor re-stamps `updatedAt` on every
|
|
12
|
+
* Save, so timestamps alone cannot prove a real edit). Changing a built-in
|
|
13
|
+
* prompt means moving the OLD prompt into `priorPrompts` (oldest first) and
|
|
14
|
+
* bumping `builtinVersion`; `builtinVersion === priorPrompts.length + 1`.
|
|
10
15
|
*
|
|
11
16
|
* Plain Node, no Electron imports.
|
|
12
17
|
*/
|
|
@@ -20,6 +25,7 @@ const BUILTIN_MACROS = Object.freeze([
|
|
|
20
25
|
surface: 'project-home',
|
|
21
26
|
projects: ['*'],
|
|
22
27
|
builtinVersion: 1,
|
|
28
|
+
priorPrompts: Object.freeze([]),
|
|
23
29
|
prompt:
|
|
24
30
|
"Generate this project's Project Home page: one self-contained HTML overview (what it is, who it is for, key features, structure, how to run it, key commands), grounded only in what you read in the repository. Save it with a single project_home_write call.",
|
|
25
31
|
}),
|
|
@@ -31,6 +37,11 @@ const BUILTIN_MACROS = Object.freeze([
|
|
|
31
37
|
surface: 'project-home',
|
|
32
38
|
projects: ['*'],
|
|
33
39
|
builtinVersion: 4,
|
|
40
|
+
priorPrompts: Object.freeze([
|
|
41
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository. Save it with a single project_demo_video_write call.',
|
|
42
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository, with a matching on-device narration track per the audio policy in the persona. Save it with a single project_demo_video_write call.',
|
|
43
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository, with a matching on-device narration track: narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona. Save it with a single project_demo_video_write call passing htmlPath.',
|
|
44
|
+
]),
|
|
34
45
|
prompt:
|
|
35
46
|
"Generate a character and cute animated JavaScript video: a 30-second demo of this project as one self-contained HTML/JavaScript animation. Ground everything in what you read in the repository — invent an original mascot character whose look, name and personality match the project's theme and purpose, and tell the project's real goals and key features through it. The character, story and visuals must match the project's theme and purpose as read from the repository. Write the narration script first (hook, problem, solution, three features, call to action), then build every scene to match its line, with fun dynamic elements per the persona. Use the style named on a 'Video style: <name>' line in the additional instructions — Professional, Fun, Animated whiteboard, or Kinetic typography — otherwise pick the one that best fits the project. Narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona. Save it with a single project_demo_video_write call passing htmlPath.",
|
|
36
47
|
}),
|
|
@@ -190,6 +190,8 @@ const MacroSetProjectSchema = z.object({
|
|
|
190
190
|
enabled: z.boolean(),
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
+
const MacroRemoveFromProjectSchema = z.object({ id: MacroIdSchema, cwd: AbsolutePathSchema });
|
|
194
|
+
|
|
193
195
|
function defaultFilePath() {
|
|
194
196
|
return path.join(schedulerHome(), 'macros.json');
|
|
195
197
|
}
|
|
@@ -308,9 +310,26 @@ function resolveBuiltins(opts) {
|
|
|
308
310
|
/**
|
|
309
311
|
* Pure. Seeds any `builtins` entry missing from `macros` (as `builtin: true`),
|
|
310
312
|
* and upgrades a stored built-in that is behind the shipped `builtinVersion`
|
|
311
|
-
* AND
|
|
312
|
-
*
|
|
313
|
+
* AND unedited: `updatedAt === createdAt`, OR `isShippedCopy` (label/agent/tag
|
|
314
|
+
* match and the prompt is one of the built-in's `priorPrompts`). A really
|
|
315
|
+
* edited built-in is left untouched. Changing a built-in prompt means moving
|
|
316
|
+
* the old prompt into `priorPrompts` in builtinMacros.cjs. Returns
|
|
317
|
+
* `{ macros, changed }`.
|
|
318
|
+
*/
|
|
319
|
+
/**
|
|
320
|
+
* True when `stored` matches an earlier shipped version of `builtin`. The
|
|
321
|
+
* editor stamps `updatedAt` on every Save (even an unchanged one), so
|
|
322
|
+
* timestamps alone cannot prove a real edit.
|
|
313
323
|
*/
|
|
324
|
+
function isShippedCopy(stored, builtin) {
|
|
325
|
+
return (
|
|
326
|
+
stored.label === builtin.label &&
|
|
327
|
+
stored.agentName === builtin.agentName &&
|
|
328
|
+
stored.tag === builtin.tag &&
|
|
329
|
+
(builtin.priorPrompts || []).includes(stored.prompt)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
314
333
|
function ensureBuiltins(macros, builtins) {
|
|
315
334
|
if (!builtins || builtins.length === 0) return { macros, changed: false };
|
|
316
335
|
let changed = false;
|
|
@@ -337,7 +356,7 @@ function ensureBuiltins(macros, builtins) {
|
|
|
337
356
|
}
|
|
338
357
|
const stored = next[idx];
|
|
339
358
|
const storedVersion = stored.builtinVersion || 0;
|
|
340
|
-
const neverEdited = stored.updatedAt === stored.createdAt;
|
|
359
|
+
const neverEdited = stored.updatedAt === stored.createdAt || isShippedCopy(stored, b);
|
|
341
360
|
if (storedVersion < b.builtinVersion && neverEdited) {
|
|
342
361
|
next[idx] = {
|
|
343
362
|
...stored,
|
|
@@ -600,6 +619,39 @@ async function setMacroProject(input, opts = {}) {
|
|
|
600
619
|
});
|
|
601
620
|
}
|
|
602
621
|
|
|
622
|
+
/**
|
|
623
|
+
* One project gives up a macro. The macro is deleted when `cwd` was its last
|
|
624
|
+
* project; otherwise only `cwd` is dropped, so one project can never take a
|
|
625
|
+
* button from another. Refuses a built-in, a '*' macro, and a macro not listed
|
|
626
|
+
* for `cwd`. Returns `{ ok: true, deleted, macro }` or `{ ok: false, error }`;
|
|
627
|
+
* when `deleted`, `macro` is the removed copy.
|
|
628
|
+
*/
|
|
629
|
+
async function removeMacroFromProject(input, opts = {}) {
|
|
630
|
+
const { id, cwd } = MacroRemoveFromProjectSchema.parse(input);
|
|
631
|
+
const filePath = resolvePath(opts);
|
|
632
|
+
const target = normalizeCwd(cwd);
|
|
633
|
+
return serialize(async () => {
|
|
634
|
+
const macros = await loadForWrite(filePath, opts);
|
|
635
|
+
const idx = macros.findIndex((m) => m.id === id);
|
|
636
|
+
if (idx === -1) return { ok: false, error: `macro not found: ${id}` };
|
|
637
|
+
const macro = macros[idx];
|
|
638
|
+
if (macro.builtin) return { ok: false, error: 'built-in macros cannot be deleted' };
|
|
639
|
+
if (macro.projects.includes(ALL_PROJECTS)) {
|
|
640
|
+
return { ok: false, error: `macro ${id} is shown in every project; only the human can remove it, from the HOT KEYS panel` };
|
|
641
|
+
}
|
|
642
|
+
if (!macro.projects.includes(target)) return { ok: false, error: `macro ${id} is not visible to ${target}` };
|
|
643
|
+
const projects = macro.projects.filter((p) => p !== target);
|
|
644
|
+
if (projects.length === 0) {
|
|
645
|
+
await writeStore(filePath, macros.filter((m) => m.id !== id));
|
|
646
|
+
return { ok: true, deleted: true, macro };
|
|
647
|
+
}
|
|
648
|
+
const updated = { ...macro, projects, updatedAt: new Date().toISOString() };
|
|
649
|
+
macros[idx] = updated;
|
|
650
|
+
await writeStore(filePath, macros);
|
|
651
|
+
return { ok: true, deleted: false, macro: updated };
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
603
655
|
module.exports = {
|
|
604
656
|
ALL_PROJECTS,
|
|
605
657
|
MACRO_INPUT_MAX_LEN,
|
|
@@ -609,6 +661,7 @@ module.exports = {
|
|
|
609
661
|
MacroSaveSchema,
|
|
610
662
|
MacroDeleteSchema,
|
|
611
663
|
MacroSetProjectSchema,
|
|
664
|
+
MacroRemoveFromProjectSchema,
|
|
612
665
|
macroPlaceholders,
|
|
613
666
|
defaultMacroValues,
|
|
614
667
|
renderMacroPrompt,
|
|
@@ -618,6 +671,7 @@ module.exports = {
|
|
|
618
671
|
saveMacro,
|
|
619
672
|
deleteMacro,
|
|
620
673
|
setMacroProject,
|
|
674
|
+
removeMacroFromProject,
|
|
621
675
|
defaultFilePath,
|
|
622
676
|
ensureBuiltins,
|
|
623
677
|
};
|
|
@@ -342,6 +342,17 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
|
|
|
342
342
|
effort: "max",
|
|
343
343
|
},
|
|
344
344
|
},
|
|
345
|
+
{
|
|
346
|
+
commit: "seed-v5",
|
|
347
|
+
bodySha256: "503ab8eed370d546f0435ac56a1470a1af31c6c665a2660af8c94b4d9ed6361a",
|
|
348
|
+
fm: {
|
|
349
|
+
description: "30-second self-contained HTML/JS demo video for Project Home, saved via project_demo_video_write.",
|
|
350
|
+
tools: "Read, Grep, Glob, Bash, Write, Edit",
|
|
351
|
+
title: "Project Home — Demo Video",
|
|
352
|
+
model: "opus",
|
|
353
|
+
effort: "max",
|
|
354
|
+
},
|
|
355
|
+
},
|
|
345
356
|
],
|
|
346
357
|
"blender-artist": [
|
|
347
358
|
{
|
|
@@ -37,6 +37,7 @@ const { sizingWarnings } = require('./prdSizing.cjs');
|
|
|
37
37
|
const telemetryCounters = require('../telemetry/telemetryCounters.cjs');
|
|
38
38
|
const { execGit } = require('../git/gitExec.cjs');
|
|
39
39
|
const { extractRepoPathCandidates, worktreeReachWarnings } = require('./prdWorktreeReach.cjs');
|
|
40
|
+
const { isSweepValidatorSlug } = require('../epic/epicSweepValidator.cjs');
|
|
40
41
|
const { validateGate, validateFiles, renderFilesSection, renderGateSection } = require('./prdGateFiles.cjs');
|
|
41
42
|
const { resolveGate, parseChain, isNoneGate } = require('../scheduler/definitionOfDone.cjs');
|
|
42
43
|
|
|
@@ -84,7 +85,7 @@ function buildPrdBody(input) {
|
|
|
84
85
|
const {
|
|
85
86
|
title, cwd, estimateMinutes, goal, acceptanceCriteria,
|
|
86
87
|
implementationNotes, outOfScope, sourcePromptId, sourceTabId, tag, agentType, dependsOn, quietMachine, disposition, deliverable, artifactPaths, planId,
|
|
87
|
-
gate, files,
|
|
88
|
+
gate, files, budgetExempt,
|
|
88
89
|
} = input;
|
|
89
90
|
|
|
90
91
|
// No `parallelGroup` frontmatter key (PRD_AUTHORING.md §5) — the NN-
|
|
@@ -137,6 +138,9 @@ function buildPrdBody(input) {
|
|
|
137
138
|
// sibling jobs would otherwise invalidate. Only emitted when true — see
|
|
138
139
|
// prdFrontmatter.cjs's applyKey for the matching "only true opts in" parse.
|
|
139
140
|
if (quietMachine === true) fmLines.push('quietMachine: true');
|
|
141
|
+
// Budget exemption is for a sweep validator that cannot be split further;
|
|
142
|
+
// every other caller's budgetExempt is ignored.
|
|
143
|
+
if (budgetExempt === true && agentType === 'validator' && isSweepValidatorSlug(input.slug)) fmLines.push('budgetExempt: true');
|
|
140
144
|
fmLines.push('---', '');
|
|
141
145
|
|
|
142
146
|
const acLines = acceptanceCriteria.map((line) => `- [ ] ${line}`).join('\n');
|