claude-code-session-manager 0.136.2 → 0.138.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/assets/{AgentLibrary-CbvVbzm2.js → AgentLibrary-C1d_D7uQ.js} +1 -1
- package/dist/assets/{AppSettings-Blks3xh_.js → AppSettings-CgDhqrsU.js} +1 -1
- package/dist/assets/{Button-hPwe-y_4.js → Button-Bk23rEnZ.js} +1 -1
- package/dist/assets/{DocumentEditorPane-C_fgkNoa.js → DocumentEditorPane-BqY5Nq6W.js} +1 -1
- package/dist/assets/{Extensions-CcDjNq7W.js → Extensions-CXem-uwI.js} +2 -2
- package/dist/assets/{History-D4s5ykcm.js → History-BwO3coo4.js} +1 -1
- package/dist/assets/{Library-BtJ7gnDM.js → Library-BDV69fSe.js} +1 -1
- package/dist/assets/{ListDetail-Bbwwd-HR.js → ListDetail-CD-Fm6mh.js} +1 -1
- package/dist/assets/{Panel-8xYPYH7R.js → Panel-CeDiyuNn.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +25 -0
- package/dist/assets/{ProvenanceBadge-COnyY49b.js → ProvenanceBadge-Bu8NmI_R.js} +1 -1
- package/dist/assets/{Scheduler-CpmSitKx.js → Scheduler-CkhTvG7C.js} +1 -1
- package/dist/assets/{Settings-Blfjp8Bp.js → Settings-COT34hBF.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-pYSyx841.js → SkillReferenceGraph-CFMK8NJh.js} +1 -1
- package/dist/assets/{Skills-C4fV80-T.js → Skills-BgexoUkQ.js} +1 -1
- package/dist/assets/{SourceChip-Bx9marLv.js → SourceChip-BXjcdeb1.js} +1 -1
- package/dist/assets/{SystemPrompt-CBvedERn.js → SystemPrompt-CeeH3EeW.js} +1 -1
- package/dist/assets/{TiptapBody-BV7WhKYF.js → TiptapBody-D1kTj-tn.js} +1 -1
- package/dist/assets/{Toggle-BUPbeHTj.js → Toggle-CENi19iK.js} +1 -1
- package/dist/assets/{ViewTabs-oXSVRUrm.js → ViewTabs-DDBb0x96.js} +1 -1
- package/dist/assets/{VoiceButton-Ca6X_WNA.js → VoiceButton-CZeyPM31.js} +1 -1
- package/dist/assets/{historyTotals-BcJ7QH96.js → historyTotals-B00l64Jw.js} +1 -1
- package/dist/assets/index-CgCxpunJ.js +3116 -0
- package/dist/index.html +1 -1
- package/dist-web/app.js +384 -384
- package/package.json +1 -1
- package/plugins/CLAUDE.md +1 -0
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +1 -0
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +2 -0
- package/scripts/scheduler-mcp-server.cjs +46 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +51 -0
- package/src/main/index.cjs +13 -7
- package/src/main/ipcSchemas.cjs +11 -0
- package/src/main/lib/CLAUDE.md +2 -0
- package/src/main/lib/demo-video-kit/checks.cjs +16 -0
- package/src/main/lib/epic/epicAttachments.cjs +143 -0
- package/src/main/lib/epic/epicMint.cjs +4 -0
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +58 -12
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +14 -1
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +169 -1
- package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
- package/src/main/lib/memoryRefResolve.cjs +64 -2
- package/src/main/lib/memoryStale.cjs +111 -18
- package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/process/bootStdioGuard.cjs +32 -0
- package/src/main/lib/process/stdioGuard.cjs +115 -0
- package/src/main/memoryAssist.cjs +23 -7
- package/src/main/memoryTool.cjs +58 -5
- package/src/main/promptSessionsIpc.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +3 -1
- package/src/preload/api.d.ts +29 -1
- package/src/preload/apiSurface.json +7 -0
- package/src/preload/index.cjs +2 -0
- package/src/seed/agents/demo-video-builder.md +10 -7
- package/dist/assets/ProjectClaudeConfig-B9PlbaSV.js +0 -25
- package/dist/assets/index-h8BmSc_8.js +0 -3116
|
@@ -32,6 +32,18 @@
|
|
|
32
32
|
* Every successful save appends one `admin_macro_save` audit event and calls
|
|
33
33
|
* `onChanged()` exactly once so the Sessions HOT KEYS strip updates live,
|
|
34
34
|
* matching the IPC handlers in index.cjs.
|
|
35
|
+
*
|
|
36
|
+
* POST /admin/macros/run {cwd, id, inputs?, effort?}
|
|
37
|
+
* -> { ok, epicId, alreadyRunning }
|
|
38
|
+
* Starts a saved macro from a script (e.g. a systemd timer) through the
|
|
39
|
+
* renderer's press path (deps.startExternalNewSession: same persona, tag, AIM
|
|
40
|
+
* prompt and source.macroId, so autoStartTargets apply). Refused (400, no
|
|
41
|
+
* launch) unless a human ticked 'Can be started by a script' (scriptStart)
|
|
42
|
+
* on a visible, non-builtin, non-job macro whose persona is listed. {{inputs}}
|
|
43
|
+
* = the macro's defaults overlaid by `inputs`. While that macro's Epic is
|
|
44
|
+
* still running in the cwd it returns that Epic (alreadyRunning:true) instead
|
|
45
|
+
* of a second start. A launch failure is a 503 with no audit event.
|
|
46
|
+
* curl -s -X POST "http://127.0.0.1:$(jq -r .port ~/.claude/session-manager/admin-api.json)/admin/macros/run" -H "Authorization: Bearer $(jq -r .token ~/.claude/session-manager/admin-api.json)" -H 'Content-Type: application/json' -d '{"cwd":"/abs/project","id":"<macro-id>"}'
|
|
35
47
|
*/
|
|
36
48
|
'use strict';
|
|
37
49
|
|
|
@@ -40,6 +52,8 @@ const { resolveCwd } = require('./projectHomeAdminRoutes.cjs');
|
|
|
40
52
|
const macroLibrary = require('../persona-macro/macroLibrary.cjs');
|
|
41
53
|
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
42
54
|
const { findHumanPromptContaining } = require('./humanPromptLedger.cjs');
|
|
55
|
+
const { readActiveIndex } = require('../epic/epicMint.cjs');
|
|
56
|
+
const { PRD_EFFORT_LEVELS } = require('../prd/prdFrontmatter.cjs');
|
|
43
57
|
|
|
44
58
|
const EVERY_PROJECT_RE = /(^|[^a-z0-9])(every|all|each)\s+(of\s+)?(my\s+|the\s+|our\s+)?projects?($|[^a-z0-9])/;
|
|
45
59
|
|
|
@@ -250,11 +264,165 @@ function deleteHandler(onChanged, libOpts) {
|
|
|
250
264
|
};
|
|
251
265
|
}
|
|
252
266
|
|
|
253
|
-
|
|
267
|
+
const RUN_INPUT_MAX_KEYS = 20;
|
|
268
|
+
const RUN_INPUT_MAX_LEN = 2000;
|
|
269
|
+
const RECENT_START_MS = 60_000;
|
|
270
|
+
const OPEN_STATUSES = new Set(['proposed', 'active']);
|
|
271
|
+
/** `${cwd}\u0000${id}` -> { epicId, at } — starts made by this route. */
|
|
272
|
+
const recentRuns = new Map();
|
|
273
|
+
/** `${cwd}\u0000${id}` -> Promise<{ok, epicId?}> — runs still awaiting the renderer. */
|
|
274
|
+
const inProgressRuns = new Map();
|
|
275
|
+
|
|
276
|
+
const SCRIPT_START_HINT = "the human can tick 'Can be started by a script' in the macro editor";
|
|
277
|
+
|
|
278
|
+
/** The open Epic this macro is already running in `cwd`, or null. */
|
|
279
|
+
function findRunningEpic(cwd, id, isTabBusy) {
|
|
280
|
+
const index = readActiveIndex(cwd);
|
|
281
|
+
for (const epic of Object.values(index.sessions)) {
|
|
282
|
+
if (!epic || typeof epic !== 'object' || !OPEN_STATUSES.has(epic.status)) continue;
|
|
283
|
+
const src = epic.source;
|
|
284
|
+
if (!src || src.producer !== 'new-epic-ui' || src.macroId !== id) continue;
|
|
285
|
+
if (typeof epic.id === 'string' && isTabBusy(epic.id)) return epic.id;
|
|
286
|
+
}
|
|
287
|
+
const key = `${cwd}\u0000${id}`;
|
|
288
|
+
const recent = recentRuns.get(key);
|
|
289
|
+
if (recent && Date.now() - recent.at < RECENT_START_MS) {
|
|
290
|
+
const entry = index.sessions[recent.epicId];
|
|
291
|
+
// Not in the index yet = just minted and still being persisted: open.
|
|
292
|
+
const open = entry ? OPEN_STATUSES.has(entry.status) : !index.tombstones[recent.epicId];
|
|
293
|
+
if (open) return recent.epicId;
|
|
294
|
+
} else if (recent) {
|
|
295
|
+
recentRuns.delete(key);
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Returns an error string, or null when `inputs` is acceptable for `macro`. */
|
|
301
|
+
function validateRunInputs(inputs, macro) {
|
|
302
|
+
if (inputs === undefined) return null;
|
|
303
|
+
if (inputs === null || typeof inputs !== 'object' || Array.isArray(inputs)) return 'inputs must be an object';
|
|
304
|
+
const keys = Object.keys(inputs);
|
|
305
|
+
if (keys.length > RUN_INPUT_MAX_KEYS) return `inputs: at most ${RUN_INPUT_MAX_KEYS} keys`;
|
|
306
|
+
const declared = new Set((macro.inputs || []).map((i) => i.name));
|
|
307
|
+
for (const k of keys) {
|
|
308
|
+
if (!declared.has(k)) return `inputs: ${k} is not an input of macro ${macro.id}`;
|
|
309
|
+
const v = inputs[k];
|
|
310
|
+
if (typeof v !== 'string') return `inputs: ${k} must be a string`;
|
|
311
|
+
if (v.length > RUN_INPUT_MAX_LEN) return `inputs: ${k} is longer than ${RUN_INPUT_MAX_LEN} characters`;
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function runHandler(deps, libOpts) {
|
|
317
|
+
const listPersonas = deps.listPersonas || ((...a) => require('../../agentLibrary.cjs').listPersonas(...a));
|
|
318
|
+
return async (req, res) => {
|
|
319
|
+
const body = await readJsonBody(req, res);
|
|
320
|
+
if (!body) return;
|
|
321
|
+
const resolved = resolveCwd(body.cwd);
|
|
322
|
+
if (!resolved.ok) {
|
|
323
|
+
sendJson(res, resolved.status, { ok: false, error: resolved.error });
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const cwd = resolved.cwd;
|
|
327
|
+
const bad = (error) => sendJson(res, 400, { ok: false, error });
|
|
328
|
+
const id = body.id;
|
|
329
|
+
if (typeof id !== 'string' || !id) return bad('id is required');
|
|
330
|
+
if (id.startsWith('builtin-')) return bad('built-in macros cannot be started through this route');
|
|
331
|
+
const macros = await macroLibrary.listMacros(libOpts);
|
|
332
|
+
const macro = macros.find((m) => m.id === id);
|
|
333
|
+
if (!macro) return bad(`macro not found: ${id}`);
|
|
334
|
+
if (!macroLibrary.macroVisibleIn(macro, cwd)) return bad(`macro ${id} is not visible to ${cwd}`);
|
|
335
|
+
if (macro.job) return bad(`macro ${id} runs a job, not a session; it cannot be started through this route`);
|
|
336
|
+
if (macro.scriptStart !== true) {
|
|
337
|
+
return bad(`macro ${id} is not marked 'Can be started by a script'; ${SCRIPT_START_HINT}`);
|
|
338
|
+
}
|
|
339
|
+
const personas = await listPersonas();
|
|
340
|
+
if (!personas.some((a) => a.name === macro.agentName)) return bad(`unknown agent: ${macro.agentName}`);
|
|
341
|
+
const inputsError = validateRunInputs(body.inputs, macro);
|
|
342
|
+
if (inputsError) return bad(inputsError);
|
|
343
|
+
const effort = body.effort;
|
|
344
|
+
if (effort !== undefined && !PRD_EFFORT_LEVELS.includes(effort)) {
|
|
345
|
+
return bad(`effort must be one of: ${PRD_EFFORT_LEVELS.join(', ')}`);
|
|
346
|
+
}
|
|
347
|
+
const rendered = macroLibrary.renderMacroPrompt(macro.prompt, macro.inputs, {
|
|
348
|
+
...macroLibrary.defaultMacroValues(macro.inputs),
|
|
349
|
+
...(body.inputs || {}),
|
|
350
|
+
});
|
|
351
|
+
if (!rendered.ok) return bad(rendered.error);
|
|
352
|
+
|
|
353
|
+
const key = `${cwd}\u0000${id}`;
|
|
354
|
+
const pending = inProgressRuns.get(key);
|
|
355
|
+
if (pending) {
|
|
356
|
+
const first = await pending;
|
|
357
|
+
if (first.ok) {
|
|
358
|
+
sendJson(res, 200, { ok: true, epicId: first.epicId, alreadyRunning: true });
|
|
359
|
+
} else {
|
|
360
|
+
sendJson(res, 503, { ok: false, error: first.error || 'launch failed' });
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const running = findRunningEpic(cwd, id, deps.isTabBusy || (() => false));
|
|
365
|
+
if (running) {
|
|
366
|
+
sendJson(res, 200, { ok: true, epicId: running, alreadyRunning: true });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const payload = {
|
|
371
|
+
cwd,
|
|
372
|
+
agentName: macro.agentName,
|
|
373
|
+
tag: macro.tag,
|
|
374
|
+
title: macro.label,
|
|
375
|
+
prompt: rendered.prompt,
|
|
376
|
+
macroId: macro.id,
|
|
377
|
+
via: 'script',
|
|
378
|
+
...(effort !== undefined ? { effort } : {}),
|
|
379
|
+
};
|
|
380
|
+
const launch = (async () => {
|
|
381
|
+
try {
|
|
382
|
+
return await deps.startExternalNewSession(payload);
|
|
383
|
+
} catch (e) {
|
|
384
|
+
return { ok: false, reason: 'launch-failed', error: e?.message ?? 'launch failed' };
|
|
385
|
+
}
|
|
386
|
+
})();
|
|
387
|
+
inProgressRuns.set(key, launch);
|
|
388
|
+
let result;
|
|
389
|
+
try {
|
|
390
|
+
result = await launch;
|
|
391
|
+
if (result && result.ok) recentRuns.set(key, { epicId: result.epicId, at: Date.now() });
|
|
392
|
+
} finally {
|
|
393
|
+
inProgressRuns.delete(key);
|
|
394
|
+
}
|
|
395
|
+
if (!result || !result.ok) {
|
|
396
|
+
const error = result?.reason === 'timeout'
|
|
397
|
+
? 'timed out waiting for the window; the session may still start, check the Sessions queue before retrying'
|
|
398
|
+
: result?.error || 'launch failed';
|
|
399
|
+
sendJson(res, 503, { ok: false, error });
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
appendAuditEvent('admin_macro_run', {
|
|
403
|
+
route: '/admin/macros/run',
|
|
404
|
+
cwd,
|
|
405
|
+
macroId: macro.id,
|
|
406
|
+
epicId: result.epicId,
|
|
407
|
+
alreadyRunning: false,
|
|
408
|
+
});
|
|
409
|
+
sendJson(res, 200, { ok: true, epicId: result.epicId, alreadyRunning: false });
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @param {{ onChanged?: () => void, startExternalNewSession?: (p: object) => Promise<any>,
|
|
415
|
+
* isTabBusy?: (tabId: string) => boolean, listPersonas?: () => Promise<Array<{name: string}>> }} deps
|
|
416
|
+
*/
|
|
417
|
+
function registerAdminRoute(adminHttp, deps = {}, opts = {}) {
|
|
418
|
+
const { onChanged } = deps;
|
|
254
419
|
const libOpts = opts.filePath ? { filePath: opts.filePath } : undefined;
|
|
255
420
|
adminHttp.registerRoute('GET', '/admin/macros', listHandler(onChanged, libOpts));
|
|
256
421
|
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts));
|
|
257
422
|
adminHttp.registerRoute('POST', '/admin/macros/delete', deleteHandler(onChanged, libOpts));
|
|
423
|
+
if (typeof deps.startExternalNewSession === 'function') {
|
|
424
|
+
adminHttp.registerRoute('POST', '/admin/macros/run', runHandler(deps, libOpts));
|
|
425
|
+
}
|
|
258
426
|
}
|
|
259
427
|
|
|
260
428
|
module.exports = {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Inbound twin of remoteIpcDispatch.cjs's chunkFrames: rebuilds a browser→desktop
|
|
4
|
+
// message that arrived as several E2E-boxed `e2e:frame` envelopes (the bilko.run
|
|
5
|
+
// relay drops any socket message over 256 KB, so large uploads are split into
|
|
6
|
+
// ≤180 KB frames). Pure, per-client state with hard memory bounds — a buggy or
|
|
7
|
+
// hostile browser cannot exhaust desktop memory: bounded frames per message,
|
|
8
|
+
// bounded bytes per message, bounded concurrent messages per client, idle TTL.
|
|
9
|
+
|
|
10
|
+
const { joinFrames } = require('./remoteIpcDispatch.cjs')
|
|
11
|
+
|
|
12
|
+
const FRAME_LIMITS = Object.freeze({
|
|
13
|
+
maxMessageBytes: 25 * 1024 * 1024,
|
|
14
|
+
maxInflightPerClient: 2,
|
|
15
|
+
maxFrames: 200,
|
|
16
|
+
idleTtlMs: 60000,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
20
|
+
|
|
21
|
+
function createFrameAssembler({
|
|
22
|
+
maxMessageBytes = FRAME_LIMITS.maxMessageBytes,
|
|
23
|
+
maxInflightPerClient = FRAME_LIMITS.maxInflightPerClient,
|
|
24
|
+
maxFrames = FRAME_LIMITS.maxFrames,
|
|
25
|
+
idleTtlMs = FRAME_LIMITS.idleTtlMs,
|
|
26
|
+
now = Date.now,
|
|
27
|
+
} = {}) {
|
|
28
|
+
/** @type {Map<string, Map<string, { total: number, frames: Map<number, string>, bytes: number, lastAt: number }>>} */
|
|
29
|
+
const clients = new Map()
|
|
30
|
+
|
|
31
|
+
function free(clientKey, msgId) {
|
|
32
|
+
const msgs = clients.get(clientKey)
|
|
33
|
+
if (!msgs) return
|
|
34
|
+
msgs.delete(msgId)
|
|
35
|
+
if (msgs.size === 0) clients.delete(clientKey)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function refuse(clientKey, msgId, reason) {
|
|
39
|
+
if (msgId !== undefined) free(clientKey, msgId)
|
|
40
|
+
return { status: 'refused', reason }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sweep() {
|
|
44
|
+
const t = now()
|
|
45
|
+
for (const [clientKey, msgs] of clients) {
|
|
46
|
+
for (const [msgId, entry] of msgs) {
|
|
47
|
+
if (t - entry.lastAt > idleTtlMs) msgs.delete(msgId)
|
|
48
|
+
}
|
|
49
|
+
if (msgs.size === 0) clients.delete(clientKey)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function dropClient(clientKey) {
|
|
54
|
+
clients.delete(clientKey)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function accept(clientKey, payload) {
|
|
58
|
+
sweep()
|
|
59
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return refuse(clientKey, undefined, 'malformed')
|
|
60
|
+
const { msgId, seq, total, data } = payload
|
|
61
|
+
if (
|
|
62
|
+
typeof msgId !== 'string' || !UUID_RE.test(msgId) ||
|
|
63
|
+
!Number.isInteger(total) || total < 1 || total > maxFrames ||
|
|
64
|
+
!Number.isInteger(seq) || seq < 0 || seq >= total ||
|
|
65
|
+
typeof data !== 'string'
|
|
66
|
+
) {
|
|
67
|
+
return refuse(clientKey, undefined, 'malformed')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let msgs = clients.get(clientKey)
|
|
71
|
+
let entry = msgs && msgs.get(msgId)
|
|
72
|
+
if (!entry) {
|
|
73
|
+
if (msgs && msgs.size >= maxInflightPerClient) return refuse(clientKey, undefined, 'too_many_inflight')
|
|
74
|
+
if (data.length > maxMessageBytes) return refuse(clientKey, undefined, 'too_large')
|
|
75
|
+
entry = { total, frames: new Map(), bytes: 0, lastAt: now() }
|
|
76
|
+
if (!msgs) {
|
|
77
|
+
msgs = new Map()
|
|
78
|
+
clients.set(clientKey, msgs)
|
|
79
|
+
}
|
|
80
|
+
msgs.set(msgId, entry)
|
|
81
|
+
} else {
|
|
82
|
+
if (entry.total !== total) return refuse(clientKey, msgId, 'total_mismatch')
|
|
83
|
+
if (entry.frames.has(seq)) return refuse(clientKey, msgId, 'duplicate_seq')
|
|
84
|
+
if (entry.bytes + data.length > maxMessageBytes) return refuse(clientKey, msgId, 'too_large')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
entry.frames.set(seq, data)
|
|
88
|
+
entry.bytes += data.length
|
|
89
|
+
entry.lastAt = now()
|
|
90
|
+
if (entry.frames.size < entry.total) return { status: 'partial' }
|
|
91
|
+
|
|
92
|
+
free(clientKey, msgId)
|
|
93
|
+
const ordered = []
|
|
94
|
+
for (let i = 0; i < entry.total; i++) ordered.push({ seq: i, total: entry.total, data: entry.frames.get(i) })
|
|
95
|
+
let envelope
|
|
96
|
+
try {
|
|
97
|
+
envelope = joinFrames(ordered)
|
|
98
|
+
} catch {
|
|
99
|
+
return { status: 'refused', reason: 'bad_json' }
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
!envelope || typeof envelope !== 'object' || Array.isArray(envelope) ||
|
|
103
|
+
typeof envelope.type !== 'string' || envelope.type.startsWith('e2e:')
|
|
104
|
+
) {
|
|
105
|
+
return { status: 'refused', reason: 'bad_inner' }
|
|
106
|
+
}
|
|
107
|
+
return { status: 'complete', envelope }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { accept, dropClient, sweep }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { createFrameAssembler, FRAME_LIMITS }
|
|
@@ -23,7 +23,12 @@ function underHome(abs, home) {
|
|
|
23
23
|
return r === '' || (!r.startsWith('..') && !path.isAbsolute(r));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home = os.homedir() }) {
|
|
26
|
+
function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home = os.homedir(), extraBases = [] }) {
|
|
27
|
+
// Extra absolute bases (e.g. the ops root) a repo-relative ref may resolve under; home-confined.
|
|
28
|
+
const bases = extraBases
|
|
29
|
+
.filter((b) => typeof b === 'string' && path.isAbsolute(b))
|
|
30
|
+
.map((b) => path.normalize(b))
|
|
31
|
+
.filter((b) => underHome(b, home));
|
|
27
32
|
const exact = new Set(trackedFiles);
|
|
28
33
|
const byBase = new Map();
|
|
29
34
|
for (const p of trackedFiles) {
|
|
@@ -45,6 +50,9 @@ function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home
|
|
|
45
50
|
if (exact.has(rel)) return true;
|
|
46
51
|
const candidates = byBase.get(path.posix.basename(rel));
|
|
47
52
|
if (candidates && candidates.some((p) => p === rel || p.endsWith('/' + rel))) return true;
|
|
53
|
+
for (const base of bases) {
|
|
54
|
+
if (exists(path.join(base, rel))) return true;
|
|
55
|
+
}
|
|
48
56
|
for (const root of roots) {
|
|
49
57
|
const abs = expandRoot(root);
|
|
50
58
|
if (abs && underHome(abs, home) && exists(path.join(abs, rel))) return true;
|
|
@@ -61,4 +69,58 @@ function listTrackedFiles(cwd) {
|
|
|
61
69
|
});
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
const MAX_RENAME_HOPS = 10;
|
|
73
|
+
const RENAME_LINE_RE = /^R\d*\t([^\t]+)\t([^\t]+)$/;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Map<oldPath, finalPath> from the repo's rename history, one git call.
|
|
77
|
+
* git log prints newest first, so the first time an old path is seen wins.
|
|
78
|
+
* Chains old -> mid -> new are followed up to MAX_RENAME_HOPS, only through
|
|
79
|
+
* renames newer than the previous hop; a cycle stops at the last unvisited
|
|
80
|
+
* path, and a chain that returns to its start is dropped (the path lives
|
|
81
|
+
* where it began). `exec` is injectable for tests.
|
|
82
|
+
* Complexity: O(lines + renames * MAX_RENAME_HOPS).
|
|
83
|
+
*/
|
|
84
|
+
function listRenames(cwd, exec = execFile) {
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
exec(
|
|
87
|
+
'git',
|
|
88
|
+
['-C', cwd, 'log', '--diff-filter=R', '--name-status', '--format=', '-M', 'HEAD'],
|
|
89
|
+
{ timeout: 10_000, maxBuffer: 32 * 1024 * 1024 },
|
|
90
|
+
(err, stdout) => {
|
|
91
|
+
if (err) return resolve(new Map());
|
|
92
|
+
// direct: old -> { to, order }, order 0 = newest rename.
|
|
93
|
+
const direct = new Map();
|
|
94
|
+
let order = 0;
|
|
95
|
+
for (const line of String(stdout).split('\n')) {
|
|
96
|
+
const m = RENAME_LINE_RE.exec(line.replace(/\r$/, ''));
|
|
97
|
+
if (!m) continue;
|
|
98
|
+
if (!direct.has(m[1])) direct.set(m[1], { to: m[2], order });
|
|
99
|
+
order++;
|
|
100
|
+
}
|
|
101
|
+
const out = new Map();
|
|
102
|
+
for (const [from, first] of direct) {
|
|
103
|
+
const visited = new Set([from]);
|
|
104
|
+
let cur = first.to;
|
|
105
|
+
let curOrder = first.order;
|
|
106
|
+
let returned = false;
|
|
107
|
+
visited.add(cur);
|
|
108
|
+
for (let hop = 1; hop < MAX_RENAME_HOPS; hop++) {
|
|
109
|
+
const next = direct.get(cur);
|
|
110
|
+
// Only a LATER rename of the new path continues the chain.
|
|
111
|
+
if (next === undefined || next.order >= curOrder) break;
|
|
112
|
+
if (next.to === from) { returned = true; break; }
|
|
113
|
+
if (visited.has(next.to)) break;
|
|
114
|
+
visited.add(next.to);
|
|
115
|
+
cur = next.to;
|
|
116
|
+
curOrder = next.order;
|
|
117
|
+
}
|
|
118
|
+
if (!returned && cur !== from) out.set(from, cur);
|
|
119
|
+
}
|
|
120
|
+
resolve(out);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = { makeRefResolver, listTrackedFiles, listRenames };
|
|
@@ -38,6 +38,59 @@ function parseMeta(body) {
|
|
|
38
38
|
return { description, type: pick('type'), originSessionId: pick('originSessionId') };
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Top-level (unindented) frontmatter `name:` value, surrounding quotes
|
|
43
|
+
* stripped. A sibling of parseMeta so the result's `name` (the filename) is
|
|
44
|
+
* never clobbered by the meta spread.
|
|
45
|
+
*/
|
|
46
|
+
function parseFrontmatterName(body) {
|
|
47
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(body);
|
|
48
|
+
if (!fm) return null;
|
|
49
|
+
const m = /^name:[ \t]*(.+?)[ \t]*$/m.exec(fm[1]);
|
|
50
|
+
if (!m) return null;
|
|
51
|
+
const v = m[1].replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1').trim();
|
|
52
|
+
return v || null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Lowercase; collapse runs of '-', '_' and whitespace to a single '-'. */
|
|
56
|
+
function normalizeLinkKey(s) {
|
|
57
|
+
return String(s).trim().toLowerCase().replace(/[-_\s]+/g, '-');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* makeLinkResolver(entries) => (target) => canonical filename stem | null
|
|
62
|
+
*
|
|
63
|
+
* entries: Array<{ name, body }>. A wikilink target matches an entry when its
|
|
64
|
+
* normalized form equals the normalized filename stem OR the normalized
|
|
65
|
+
* frontmatter `name:` (Claude Code links memories by the kebab frontmatter
|
|
66
|
+
* name while files are snake_case). Collisions: an exact stem match wins;
|
|
67
|
+
* otherwise filename stems claim keys before frontmatter names, and within
|
|
68
|
+
* each pass the entry whose filename sorts first wins — independent of input
|
|
69
|
+
* order. Complexity: O(entries log entries) build, O(target length) lookup.
|
|
70
|
+
*/
|
|
71
|
+
function makeLinkResolver(entries) {
|
|
72
|
+
const sorted = [...entries].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
73
|
+
const exactStems = new Set();
|
|
74
|
+
const byKey = new Map();
|
|
75
|
+
for (const e of sorted) {
|
|
76
|
+
const stem = stripName(e.name);
|
|
77
|
+
exactStems.add(stem);
|
|
78
|
+
const key = normalizeLinkKey(stem);
|
|
79
|
+
if (!byKey.has(key)) byKey.set(key, stem);
|
|
80
|
+
}
|
|
81
|
+
for (const e of sorted) {
|
|
82
|
+
const fmName = parseFrontmatterName(e.body || '');
|
|
83
|
+
if (fmName === null) continue;
|
|
84
|
+
const key = normalizeLinkKey(fmName);
|
|
85
|
+
if (!byKey.has(key)) byKey.set(key, stripName(e.name));
|
|
86
|
+
}
|
|
87
|
+
return (target) => {
|
|
88
|
+
const t = String(target).trim();
|
|
89
|
+
if (exactStems.has(t)) return t;
|
|
90
|
+
return byKey.get(normalizeLinkKey(t)) ?? null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
41
94
|
/**
|
|
42
95
|
* Extract dead-ref candidate paths from a memory body.
|
|
43
96
|
* Complexity: O(body length) — one regex pass, then O(candidates) filtering.
|
|
@@ -78,41 +131,69 @@ function extractRoots(body) {
|
|
|
78
131
|
return out;
|
|
79
132
|
}
|
|
80
133
|
|
|
134
|
+
function escapeRegExp(s) {
|
|
135
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Compile projectRoots ({name, root}[]) into whole-word, case-insensitive
|
|
140
|
+
* matchers. A word boundary is any non-[A-Za-z0-9_] char, so 'Bilko' matches
|
|
141
|
+
* 'bilko-run' but not 'notbilkos'.
|
|
142
|
+
*/
|
|
143
|
+
function compileProjectRoots(projectRoots) {
|
|
144
|
+
return projectRoots
|
|
145
|
+
.filter((p) => p && typeof p.name === 'string' && p.name !== '' && typeof p.root === 'string' && p.root !== '')
|
|
146
|
+
.map((p) => ({ root: p.root, re: new RegExp(`(?<![A-Za-z0-9_])${escapeRegExp(p.name)}(?![A-Za-z0-9_])`, 'i') }));
|
|
147
|
+
}
|
|
148
|
+
|
|
81
149
|
/**
|
|
82
|
-
* scoreMemories({ entries, now, existsPath })
|
|
150
|
+
* scoreMemories({ entries, now, existsPath, projectRoots, renamedTo })
|
|
83
151
|
*
|
|
84
152
|
* entries: Array<{ name, mtimeMs, body }>
|
|
85
153
|
* now: ms epoch
|
|
86
154
|
* existsPath: (relPath: string, roots?: string[]) => boolean
|
|
155
|
+
* projectRoots: Array<{ name, root }> — a root joins a memory's roots when its
|
|
156
|
+
* name appears in the body as a whole word (case-insensitive)
|
|
157
|
+
* renamedTo: (relPath) => string | null — git rename target; a dead candidate
|
|
158
|
+
* whose target exists is reported in movedRefs, not deadRefs, and is not stale
|
|
87
159
|
*
|
|
88
160
|
* Complexity: O(total body bytes) — a single pass per entry to extract
|
|
89
161
|
* wikilink targets and dead-ref candidates; the inbound-link fold is
|
|
90
162
|
* O(entries + total links), NOT O(n^2) substring scans.
|
|
91
163
|
*/
|
|
92
|
-
function scoreMemories({ entries, now, existsPath }) {
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
//
|
|
164
|
+
function scoreMemories({ entries, now, existsPath, projectRoots = [], renamedTo = () => null }) {
|
|
165
|
+
const projectMatchers = compileProjectRoots(projectRoots);
|
|
166
|
+
// Signal 2 (pass 1): per-entry set of wikilink targets, each resolved to its
|
|
167
|
+
// canonical filename stem (raw text when unresolved), deduped so repeated
|
|
168
|
+
// links to the same memory within one body count once toward its inbound
|
|
169
|
+
// count. Self-links (by stem or frontmatter name) are dropped here.
|
|
170
|
+
const resolve = makeLinkResolver(entries);
|
|
96
171
|
const perEntryTargets = entries.map((e) => {
|
|
172
|
+
const selfSlug = stripName(e.name);
|
|
97
173
|
const targets = new Set();
|
|
174
|
+
const dangling = new Set();
|
|
98
175
|
let m;
|
|
99
176
|
WIKILINK_RE.lastIndex = 0;
|
|
100
177
|
while ((m = WIKILINK_RE.exec(e.body)) !== null) {
|
|
101
|
-
|
|
178
|
+
const raw = m[1].trim();
|
|
179
|
+
const canonical = resolve(raw);
|
|
180
|
+
if (canonical === null) {
|
|
181
|
+
targets.add(raw);
|
|
182
|
+
dangling.add(raw);
|
|
183
|
+
} else if (canonical !== selfSlug) {
|
|
184
|
+
targets.add(canonical);
|
|
185
|
+
}
|
|
102
186
|
}
|
|
103
|
-
return targets;
|
|
187
|
+
return { targets, dangling };
|
|
104
188
|
});
|
|
105
189
|
|
|
106
190
|
const inboundCounts = new Map();
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (target === selfSlug) continue; // a memory linking itself isn't an inbound reference
|
|
191
|
+
for (const { targets, dangling } of perEntryTargets) {
|
|
192
|
+
for (const target of targets) {
|
|
193
|
+
if (dangling.has(target)) continue;
|
|
111
194
|
inboundCounts.set(target, (inboundCounts.get(target) || 0) + 1);
|
|
112
195
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const knownSlugs = new Set(entries.map((e) => stripName(e.name)));
|
|
196
|
+
}
|
|
116
197
|
|
|
117
198
|
return entries.map((e, i) => {
|
|
118
199
|
const ageDays = Math.floor((now - e.mtimeMs) / DAY_MS);
|
|
@@ -121,7 +202,17 @@ function scoreMemories({ entries, now, existsPath }) {
|
|
|
121
202
|
|
|
122
203
|
const candidates = extractCandidates(e.body);
|
|
123
204
|
const roots = extractRoots(e.body);
|
|
124
|
-
const
|
|
205
|
+
for (const { root, re } of projectMatchers) {
|
|
206
|
+
if (!roots.includes(root) && re.test(e.body)) roots.push(root);
|
|
207
|
+
}
|
|
208
|
+
const deadRefs = [];
|
|
209
|
+
const movedRefs = [];
|
|
210
|
+
for (const c of candidates) {
|
|
211
|
+
if (existsPath(c, roots)) continue;
|
|
212
|
+
const to = renamedTo(c);
|
|
213
|
+
if (typeof to === 'string' && to !== '' && to !== c && existsPath(to, roots)) movedRefs.push({ from: c, to });
|
|
214
|
+
else deadRefs.push(c);
|
|
215
|
+
}
|
|
125
216
|
|
|
126
217
|
const reasons = [];
|
|
127
218
|
if (deadRefs.length > 0) {
|
|
@@ -136,20 +227,22 @@ function scoreMemories({ entries, now, existsPath }) {
|
|
|
136
227
|
reasons.push('90+ days old with no inbound links');
|
|
137
228
|
}
|
|
138
229
|
|
|
139
|
-
const
|
|
230
|
+
const { targets, dangling } = perEntryTargets[i];
|
|
231
|
+
const outLinks = [...targets];
|
|
140
232
|
|
|
141
233
|
return {
|
|
142
234
|
name: e.name,
|
|
143
235
|
...parseMeta(e.body),
|
|
144
236
|
outLinks,
|
|
145
|
-
danglingLinks:
|
|
237
|
+
danglingLinks: [...dangling],
|
|
146
238
|
ageDays,
|
|
147
239
|
inboundLinks,
|
|
148
240
|
deadRefs,
|
|
241
|
+
movedRefs,
|
|
149
242
|
stale: deadRefs.length > 0 || oldAndUnlinked,
|
|
150
243
|
reasons,
|
|
151
244
|
};
|
|
152
245
|
});
|
|
153
246
|
}
|
|
154
247
|
|
|
155
|
-
module.exports = { scoreMemories, extractRoots };
|
|
248
|
+
module.exports = { scoreMemories, extractRoots, makeLinkResolver };
|
|
@@ -167,6 +167,8 @@ const MacroSchema = z.object({
|
|
|
167
167
|
inputs: MacroInputsSchema.optional(),
|
|
168
168
|
// Projects this macro's session may start work in without approval. Set only by the app's IPC save.
|
|
169
169
|
autoStartTargets: MacroProjectsSchema.optional(),
|
|
170
|
+
// Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
|
|
171
|
+
scriptStart: z.boolean().optional(),
|
|
170
172
|
}).superRefine(refineInputs);
|
|
171
173
|
|
|
172
174
|
const MacroSaveSchema = z.object({
|
|
@@ -184,6 +186,8 @@ const MacroSaveSchema = z.object({
|
|
|
184
186
|
inputs: MacroInputsSchema.optional(),
|
|
185
187
|
// Omitted keeps the stored list on update; `[]` clears it.
|
|
186
188
|
autoStartTargets: MacroProjectsSchema.optional(),
|
|
189
|
+
// Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
|
|
190
|
+
scriptStart: z.boolean().optional(),
|
|
187
191
|
}).superRefine(refineInputs);
|
|
188
192
|
|
|
189
193
|
const MacroDeleteSchema = z.object({ id: MacroIdSchema });
|
|
@@ -617,6 +621,8 @@ async function saveMacro(input, opts = {}) {
|
|
|
617
621
|
} else {
|
|
618
622
|
saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
|
|
619
623
|
}
|
|
624
|
+
if (parsed.scriptStart === true) saved.scriptStart = true;
|
|
625
|
+
else if (parsed.scriptStart === false) delete saved.scriptStart;
|
|
620
626
|
assertPlaceholdersDeclared(saved);
|
|
621
627
|
macros[idx] = saved;
|
|
622
628
|
} else {
|
|
@@ -639,6 +645,7 @@ async function saveMacro(input, opts = {}) {
|
|
|
639
645
|
if (parsed.autoStartTargets && parsed.autoStartTargets.length > 0) {
|
|
640
646
|
saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
|
|
641
647
|
}
|
|
648
|
+
if (parsed.scriptStart === true) saved.scriptStart = true;
|
|
642
649
|
assertPlaceholdersDeclared(saved);
|
|
643
650
|
macros.push(saved);
|
|
644
651
|
}
|
|
@@ -555,6 +555,17 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
|
|
|
555
555
|
effort: "max",
|
|
556
556
|
},
|
|
557
557
|
},
|
|
558
|
+
{
|
|
559
|
+
commit: "seed-v14",
|
|
560
|
+
bodySha256: "b65ef654c1ab9671b3781dfe6d70f936b984f226d11a03dd894f1b66993b8b35",
|
|
561
|
+
fm: {
|
|
562
|
+
description: "30-second or 1-minute self-contained HTML/JS demo video for Project Home, saved via project_video_write.",
|
|
563
|
+
tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_demo_video_write, mcp__session-manager-scheduler__project_video_write, mcp__session-manager-scheduler__project_character_write",
|
|
564
|
+
title: "Project Home — Demo Video",
|
|
565
|
+
model: "opus",
|
|
566
|
+
effort: "max",
|
|
567
|
+
},
|
|
568
|
+
},
|
|
558
569
|
],
|
|
559
570
|
"blender-artist": [
|
|
560
571
|
{
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Boot wiring for the dead-stdio guard, extracted from index.cjs so it is behavior-testable.
|
|
3
|
+
// After the launching terminal closes, writes to the inherited stdout/stderr fail EIO/EPIPE and
|
|
4
|
+
// would surface as one uncaughtException per console line. The notice goes to the file logger
|
|
5
|
+
// (required lazily: logs.cjs pulls in electron's app), never to the dead stream.
|
|
6
|
+
const { guardStdio, createUncaughtReportFilter } = require('./stdioGuard.cjs');
|
|
7
|
+
|
|
8
|
+
function installBootStdioGuard({ streams, requireLogs = () => require('../../logs.cjs') } = {}) {
|
|
9
|
+
try {
|
|
10
|
+
guardStdio({
|
|
11
|
+
streams,
|
|
12
|
+
log: ({ stream, code }) => {
|
|
13
|
+
try {
|
|
14
|
+
requireLogs().writeLine({ scope: 'main', level: 'warn', message: 'stdio stream dead; output to it is dropped', meta: { stream, code } });
|
|
15
|
+
} catch { /* best-effort */ }
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
} catch { /* the guard must never stop boot */ }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createUncaughtExceptionHandler({ reportError, writeLine }) {
|
|
22
|
+
const shouldReport = createUncaughtReportFilter();
|
|
23
|
+
return (err) => {
|
|
24
|
+
if (!shouldReport(err)) return;
|
|
25
|
+
try {
|
|
26
|
+
reportError({ name: 'uncaughtException', msg: err?.message, stack: err?.stack });
|
|
27
|
+
} catch { /* telemetry must never break the existing handling below */ }
|
|
28
|
+
writeLine({ scope: 'main', level: 'error', message: 'uncaughtException', meta: { error: err?.message, stack: err?.stack } });
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { installBootStdioGuard, createUncaughtExceptionHandler };
|