claude-code-session-manager 0.126.0 → 0.128.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.
Files changed (107) hide show
  1. package/bin/cli.cjs +71 -9
  2. package/bin/supervise.cjs +84 -0
  3. package/dist/assets/{AgentLibrary-bzeuZN4F.js → AgentLibrary-cNQU5YWy.js} +1 -1
  4. package/dist/assets/{Button-8dWfDDuQ.js → Button-9dIPAOBg.js} +1 -1
  5. package/dist/assets/{DataModel-D4ybBPZN.js → DataModel-DrDJ6ysw.js} +1 -1
  6. package/dist/assets/{History-hsztE6yh.js → History-4rrDdWNP.js} +1 -1
  7. package/dist/assets/{Hooks-CRmZMQaW.js → Hooks-Bj_jF5Pa.js} +1 -1
  8. package/dist/assets/{Library-Czt3Bojd.js → Library-D-Wsxrh7.js} +1 -1
  9. package/dist/assets/{ListDetail-Cr6Ct_WX.js → ListDetail-D7Om0H8j.js} +1 -1
  10. package/dist/assets/{McpServers-CeXJ2bng.js → McpServers-CbIbSd5o.js} +1 -1
  11. package/dist/assets/{Memory-caujO8O3.js → Memory-DgQlvQrO.js} +1 -1
  12. package/dist/assets/{Panel-D64i9tGz.js → Panel-DZHiD8Ar.js} +1 -1
  13. package/dist/assets/{Permissions-DpWOIrvr.js → Permissions-CfzduF4B.js} +1 -1
  14. package/dist/assets/{Plugins-Bd1ekP5P.js → Plugins-D-AG5nAo.js} +2 -2
  15. package/dist/assets/{ProvenanceBadge-B96A_uZf.js → ProvenanceBadge-B9JSEjll.js} +1 -1
  16. package/dist/assets/{SaveBar-D0Y2t-Ao.js → SaveBar-mVKig6hL.js} +1 -1
  17. package/dist/assets/{Scheduler-Y5_YbNrC.js → Scheduler-DFTCnh60.js} +1 -1
  18. package/dist/assets/{ScopeSwitcher-BmWA_dP9.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
  19. package/dist/assets/{Settings-Bcf65bpL.js → Settings-BTmxRMaP.js} +1 -1
  20. package/dist/assets/{SkillReferenceGraph-BeSNXloA.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
  21. package/dist/assets/{Skills-DwnQKJVc.js → Skills-CxOacq0k.js} +1 -1
  22. package/dist/assets/{SystemPrompt-Dih6SCmL.js → SystemPrompt-BCWg5FAz.js} +1 -1
  23. package/dist/assets/{TagLibrary-BZ-Kp10P.js → TagLibrary-BnF0_PkG.js} +1 -1
  24. package/dist/assets/{TiptapBody-C2nEUmF7.js → TiptapBody-C2Iu6rZd.js} +1 -1
  25. package/dist/assets/{Toggle-Dw8-zNQo.js → Toggle-C-oD66BG.js} +1 -1
  26. package/dist/assets/{ViewTabs-CoYPKGN-.js → ViewTabs-Cs4v7vLY.js} +1 -1
  27. package/dist/assets/{historyTotals-BbKcNpV7.js → historyTotals-CbRSLD8f.js} +1 -1
  28. package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
  29. package/dist/assets/index-DzY_GXYY.js +3081 -0
  30. package/dist/assets/{settingsSchema-6doG_61l.js → settingsSchema-bSBfHuan.js} +1 -1
  31. package/dist/assets/{skillFrontmatter-BYMYWDfb.js → skillFrontmatter-BEseWm8r.js} +1 -1
  32. package/dist/assets/{useAgentsDirWatch-Cqabjieh.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
  33. package/dist/index.html +2 -2
  34. package/dist-web/app.css +1 -1
  35. package/dist-web/app.js +343 -341
  36. package/package.json +1 -1
  37. package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
  38. package/scripts/scheduler-mcp-server.cjs +209 -7
  39. package/src/main/build-info.json +4 -4
  40. package/src/main/chatRunner.cjs +37 -4
  41. package/src/main/crashDiagnostics.cjs +83 -8
  42. package/src/main/health.cjs +16 -5
  43. package/src/main/index.cjs +46 -0
  44. package/src/main/ipcSchemas.cjs +107 -0
  45. package/src/main/lib/chatBootRecovery.cjs +136 -0
  46. package/src/main/lib/chatInflight.cjs +88 -0
  47. package/src/main/lib/claude/agentModelResolve.cjs +26 -7
  48. package/src/main/lib/claude/personaToolScope.cjs +40 -2
  49. package/src/main/lib/demo-video-kit/capture.cjs +113 -0
  50. package/src/main/lib/demo-video-kit/character.cjs +97 -0
  51. package/src/main/lib/demo-video-kit/checks.cjs +150 -0
  52. package/src/main/lib/demo-video-kit/frames.cjs +200 -0
  53. package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
  54. package/src/main/lib/demo-video-kit/sound.cjs +312 -0
  55. package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
  56. package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
  57. package/src/main/lib/epic/epicValidationHook.cjs +31 -3
  58. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
  59. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
  60. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
  61. package/src/main/lib/mcpToolCatalog.cjs +93 -14
  62. package/src/main/lib/opsOwnership.cjs +9 -5
  63. package/src/main/lib/persona-macro/builtinMacros.cjs +30 -5
  64. package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
  65. package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
  66. package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
  67. package/src/main/lib/persona-macro/macroLibrary.cjs +73 -3
  68. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +100 -0
  69. package/src/main/lib/prd/prdCreate.cjs +17 -2
  70. package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
  71. package/src/main/lib/process/childWithLog.cjs +38 -95
  72. package/src/main/lib/process/memoryScope.cjs +140 -0
  73. package/src/main/lib/process/ozonePlatform.cjs +15 -0
  74. package/src/main/lib/process/procIdentity.cjs +10 -3
  75. package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
  76. package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
  77. package/src/main/lib/project-pages/playerBridge.cjs +129 -0
  78. package/src/main/lib/scheduler/cpuSample.cjs +147 -0
  79. package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
  80. package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
  81. package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
  82. package/src/main/lib/scheduler/loadGate.cjs +116 -45
  83. package/src/main/lib/scheduler/queueStore.cjs +5 -2
  84. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  85. package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
  86. package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
  87. package/src/main/lib/smfileHeaders.cjs +11 -3
  88. package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
  89. package/src/main/projectPages.cjs +107 -30
  90. package/src/main/promptSessionsIpc.cjs +131 -0
  91. package/src/main/scheduler/budget.cjs +31 -0
  92. package/src/main/scheduler/prdParser.cjs +2 -0
  93. package/src/main/scheduler/prdPaths.cjs +54 -0
  94. package/src/main/scheduler/reviewLadder.cjs +17 -0
  95. package/src/main/scheduler/starvation.cjs +22 -0
  96. package/src/main/scheduler.cjs +548 -77
  97. package/src/main/seedSchedulerMcp.cjs +10 -1
  98. package/src/main/templates/PRD_AUTHORING.md +5 -2
  99. package/src/main/transcripts.cjs +8 -0
  100. package/src/main/usage.cjs +4 -2
  101. package/src/main/webRemote.cjs +3 -1
  102. package/src/preload/api.d.ts +113 -7
  103. package/src/preload/apiSurface.json +70 -0
  104. package/src/preload/index.cjs +13 -0
  105. package/src/seed/agents/demo-video-builder.md +141 -43
  106. package/src/seed/agents/project-home-builder.md +26 -13
  107. package/dist/assets/index-DgPUERhe.js +0 -3079
@@ -1,9 +1,10 @@
1
1
  /**
2
- * projectHomeAdminRoutes.cjs — the two admin routes behind the
3
- * project_home_write MCP tool and its demo-video sibling:
4
- * POST /admin/project-home/write {cwd, html} -> project-pages/home.html
5
- * POST /admin/project-home/demo-video/write {cwd, html} -> project-pages/demo-video/index.html
6
- * both owned by writer 'project-home' (see opsOwnership.cjs). Registered
2
+ * projectHomeAdminRoutes.cjs — admin routes behind Project Home's library:
3
+ * POST /admin/project-home/pages/write -> project-pages/knowledge/<pageId>/{index.html,meta.json}
4
+ * POST /admin/project-home/videos/write -> project-pages/videos/<videoId>/{index.html,meta.json}
5
+ * POST /admin/project-home/write alias: {cwd, html} -> knowledge/overview/
6
+ * POST /admin/project-home/demo-video/write alias: {cwd, html} -> a new videos/vid-<id>/ project-demo entry
7
+ * all owned by writer 'project-home' (see opsOwnership.cjs). Registered
7
8
  * against the same injected localAdminHttp.cjs transport as
8
9
  * prdAdminRoutes.cjs.
9
10
  *
@@ -22,11 +23,15 @@
22
23
 
23
24
  const fs = require('node:fs');
24
25
  const path = require('node:path');
26
+ const crypto = require('node:crypto');
25
27
  const { readBody, sendJson } = require('./localAdminHttp.cjs');
26
28
  const { resolveProjectContext } = require('../projectRootResolve.cjs');
27
29
  const { opsPath, OPS_ROOT_DIR } = require('../opsOwnership.cjs');
28
30
  const config = require('../../config.cjs');
29
- const { schemas } = require('../../ipcSchemas.cjs');
31
+ const { schemas, ENTRY_ID_RE } = require('../../ipcSchemas.cjs');
32
+ const { validateCharacterJson, validateCharacterJs, readCharacter, characterDir, MAX_JS_BYTES: MAX_CHARACTER_JS_BYTES } = require('../demo-video-kit/character.cjs');
33
+ const { checkHtmlLimits } = require('../demo-video-kit/checks.cjs');
34
+ const { injectPlayerBridge } = require('../project-pages/playerBridge.cjs');
30
35
 
31
36
  const MAX_HTML_BYTES = 1024 * 1024;
32
37
  const MAX_DEMO_VIDEO_BYTES = 2 * 1024 * 1024;
@@ -72,7 +77,7 @@ const NETWORK_CHECKS = [
72
77
 
73
78
  const DURATION_META_RE = /<meta\b[^>]*\bname\s*=\s*["']sm-demo-duration["'][^>]*\bcontent\s*=\s*["'](\d+)["'][^>]*>/i;
74
79
  const MIN_DEMO_DURATION_S = 5;
75
- const MAX_DEMO_DURATION_S = 30;
80
+ const MAX_DEMO_DURATION_S = 60;
76
81
 
77
82
  const DEMO_VIDEO_CSP = '<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'unsafe-inline\'; style-src \'unsafe-inline\'; img-src data: blob:; media-src data: blob:; font-src data:; connect-src \'none\'">';
78
83
 
@@ -87,9 +92,9 @@ function validateHomeHtml(html) {
87
92
  }
88
93
 
89
94
  /** -> null when `html` is acceptable, else a human-readable rejection reason. */
90
- function validateDemoVideoHtml(html) {
95
+ function validateDemoVideoHtml(html, maxBytes = MAX_DEMO_VIDEO_BYTES) {
91
96
  if (typeof html !== 'string' || html.trim().length === 0) return 'html must be a non-empty string';
92
- if (Buffer.byteLength(html, 'utf8') > MAX_DEMO_VIDEO_BYTES) return `html exceeds the ${MAX_DEMO_VIDEO_BYTES}-byte limit`;
97
+ if (Buffer.byteLength(html, 'utf8') > maxBytes) return `html exceeds the ${maxBytes}-byte limit`;
93
98
  for (const { re, message } of REMOTE_REFERENCE_CHECKS) {
94
99
  if (re.test(html)) return `html must be self-contained: ${message}`;
95
100
  }
@@ -162,19 +167,20 @@ function resolveCwd(rawCwd) {
162
167
  }
163
168
 
164
169
  /**
165
- * Builds a POST handler shared by both routes: read+parse the body, validate
166
- * against `schema`, resolve cwd, run `validate(html)`, optionally `transform`
167
- * the html (CSP injection), then write it atomically as writer 'project-home'.
170
+ * Builds a POST handler shared by every route: read+parse the body, validate
171
+ * against `schema`, resolve cwd, then `build(input)` -> {error} | {dir, html,
172
+ * meta}. The entry folder gets index.html then meta.json, both atomically as
173
+ * writer 'project-home'. Responds {ok, path (index.html), bytes}.
168
174
  */
169
- function makeWriteHandler({ schema, maxBytes, validate, transform, targetPath }) {
175
+ function makeWriteHandler({ schema, bodyLimit, build }) {
170
176
  return async (req, res) => {
171
- // Allow headroom over maxBytes for JSON escaping; the html byte limit
172
- // itself is enforced by `validate` below.
177
+ // Headroom over the html limit for JSON escaping; the html byte limit
178
+ // itself is enforced by `build`.
173
179
  let raw;
174
180
  try {
175
- raw = await readBody(req, maxBytes * 2 + 4096);
181
+ raw = await readBody(req, bodyLimit * 2 + 4096);
176
182
  } catch (e) {
177
- sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (html limit is ${maxBytes} bytes)` });
183
+ sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (html limit is ${bodyLimit} bytes)` });
178
184
  return;
179
185
  }
180
186
  let body;
@@ -196,43 +202,187 @@ function makeWriteHandler({ schema, maxBytes, validate, transform, targetPath })
196
202
  sendJson(res, resolved.status, { ok: false, error: resolved.error });
197
203
  return;
198
204
  }
199
- const rejection = validate(input.html);
200
- if (rejection) {
201
- sendJson(res, 400, { ok: false, error: rejection });
205
+ const built = build(input);
206
+ if (built.error) {
207
+ sendJson(res, 400, { ok: false, error: built.error });
202
208
  return;
203
209
  }
204
210
  // Only a route that is actually about to write widens config.cjs's
205
211
  // write boundary to this project root.
206
212
  config.addAllowedRoot(resolved.cwd);
207
- const finalHtml = transform ? transform(input.html) : input.html;
208
213
  try {
209
- const abs = targetPath(resolved.cwd);
210
- await fs.promises.mkdir(path.dirname(abs), { recursive: true });
211
- await config.writeTextAtomic(abs, finalHtml, { writer: 'project-home' });
212
- sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(finalHtml, 'utf8') });
214
+ const dir = opsPath(resolved.cwd, 'project-pages', ...built.dirParts);
215
+ await fs.promises.mkdir(dir, { recursive: true });
216
+ const abs = path.join(dir, 'index.html');
217
+ await config.writeTextAtomic(abs, built.html, { writer: 'project-home' });
218
+ await config.writeTextAtomic(path.join(dir, 'meta.json'), JSON.stringify(built.meta, null, 2) + '\n', { writer: 'project-home' });
219
+ sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(built.html, 'utf8'), id: built.meta.id });
213
220
  } catch (e) {
214
221
  sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
215
222
  }
216
223
  };
217
224
  }
218
225
 
226
+ /** Size cap for a video of `lengthS` seconds: 2 MiB per started 30 s. */
227
+ function maxVideoBytes(lengthS) {
228
+ return Math.ceil(lengthS / 30) * MAX_DEMO_VIDEO_BYTES;
229
+ }
230
+
231
+ function buildPage(input, { pageId, title, topic }) {
232
+ if (!ENTRY_ID_RE.test(pageId)) return { error: 'invalid pageId' };
233
+ const rejection = validateHomeHtml(input.html);
234
+ if (rejection) return { error: rejection };
235
+ return {
236
+ dirParts: ['knowledge', pageId],
237
+ html: input.html,
238
+ meta: schemas.projectPageMeta.parse({ id: pageId, title, topic, createdAt: new Date().toISOString(), model: '' }),
239
+ };
240
+ }
241
+
242
+ /** Shared video path. `meta` is the full video meta minus id/createdAt/report.bytes. */
243
+ function buildVideo(input, { videoId, title, kind, lengthS, meta }) {
244
+ if (!ENTRY_ID_RE.test(videoId)) return { error: 'invalid videoId' };
245
+ const cap = maxVideoBytes(lengthS);
246
+ const rejection = validateDemoVideoHtml(input.html, cap);
247
+ if (rejection) return { error: rejection };
248
+ const declared = Number(input.html.match(DURATION_META_RE)[1]);
249
+ if (declared !== lengthS) return { error: `sm-demo-duration (${declared}) must equal lengthS (${lengthS})` };
250
+ const html = injectPlayerBridge(injectCsp(input.html));
251
+ const bytes = Buffer.byteLength(html, 'utf8');
252
+ return {
253
+ dirParts: ['videos', videoId],
254
+ html,
255
+ meta: schemas.projectVideoMeta.parse({
256
+ ...meta,
257
+ id: videoId,
258
+ title,
259
+ kind,
260
+ lengthS,
261
+ createdAt: new Date().toISOString(),
262
+ report: { ...meta.report, bytes },
263
+ }),
264
+ };
265
+ }
266
+
267
+ function newVideoId() {
268
+ const alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
269
+ const bytes = crypto.randomBytes(3);
270
+ let rnd = '';
271
+ for (const b of bytes) rnd += alphabet[b % alphabet.length];
272
+ return `vid-${Date.now().toString(36)}${rnd}`;
273
+ }
274
+
219
275
  function registerAdminRoute(adminHttp) {
220
- // POST /admin/project-home/write {cwd, html}
276
+ // POST /admin/project-home/pages/write {cwd, pageId, title, topic?, html}
277
+ adminHttp.registerRoute('POST', '/admin/project-home/pages/write', makeWriteHandler({
278
+ schema: schemas.projectPageAdminWriteBody,
279
+ bodyLimit: MAX_HTML_BYTES,
280
+ build: (i) => buildPage(i, { pageId: i.pageId, title: i.title, topic: i.topic ?? '' }),
281
+ }));
282
+
283
+ // POST /admin/project-home/videos/write {cwd, videoId, title, kind, lengthS, html, meta}
284
+ adminHttp.registerRoute('POST', '/admin/project-home/videos/write', makeWriteHandler({
285
+ schema: schemas.projectVideoAdminWriteBody,
286
+ bodyLimit: maxVideoBytes(MAX_DEMO_DURATION_S),
287
+ build: (i) => {
288
+ // Cheap kit checks re-run server-side; the alias route is exempt (Burrow sends no report).
289
+ const failed = (i.meta?.report?.checks ?? []).find((c) => c.ok === false);
290
+ if (failed) return { error: `report.checks failed: ${failed.id}${failed.detail ? ` (${failed.detail})` : ''}` };
291
+ const limits = checkHtmlLimits({ html: i.html, lengthS: i.lengthS });
292
+ if (!limits.ok) return { error: `${limits.id} check failed: ${limits.detail}` };
293
+ return buildVideo(i, i);
294
+ },
295
+ }));
296
+
297
+ // Alias: POST /admin/project-home/write {cwd, html} -> knowledge/overview/
221
298
  adminHttp.registerRoute('POST', '/admin/project-home/write', makeWriteHandler({
222
299
  schema: schemas.projectHomeAdminWriteBody,
223
- maxBytes: MAX_HTML_BYTES,
224
- validate: validateHomeHtml,
225
- targetPath: (cwd) => opsPath(cwd, 'project-pages', 'home.html'),
300
+ bodyLimit: MAX_HTML_BYTES,
301
+ build: (i) => buildPage(i, { pageId: 'overview', title: 'Overview', topic: 'overview' }),
226
302
  }));
227
303
 
228
- // POST /admin/project-home/demo-video/write {cwd, html}
304
+ // Alias: POST /admin/project-home/demo-video/write {cwd, html} -> a NEW videos/vid-*/ entry
229
305
  adminHttp.registerRoute('POST', '/admin/project-home/demo-video/write', makeWriteHandler({
230
306
  schema: schemas.projectDemoVideoAdminWriteBody,
231
- maxBytes: MAX_DEMO_VIDEO_BYTES,
232
- validate: validateDemoVideoHtml,
233
- transform: injectCsp,
234
- targetPath: (cwd) => opsPath(cwd, 'project-pages', 'demo-video', 'index.html'),
307
+ bodyLimit: maxVideoBytes(MAX_DEMO_DURATION_S),
308
+ build: (i) => {
309
+ const rejection = validateDemoVideoHtml(i.html, maxVideoBytes(MAX_DEMO_DURATION_S));
310
+ if (rejection) return { error: rejection };
311
+ const lengthS = Number(i.html.match(DURATION_META_RE)[1]);
312
+ return buildVideo(i, {
313
+ videoId: newVideoId(),
314
+ title: 'Demo video',
315
+ kind: 'project-demo',
316
+ lengthS,
317
+ meta: {
318
+ style: '',
319
+ character: null,
320
+ sources: [],
321
+ report: { lufs: null, truePeakDb: null, speechS: null, readingGrade: null, checks: [] },
322
+ macroVersion: 0,
323
+ seedVersion: 0,
324
+ model: '',
325
+ effort: '',
326
+ },
327
+ });
328
+ },
235
329
  }));
330
+
331
+ // POST /admin/project-home/character/write {cwd, json, js, replace?} -> videos/_character/
332
+ adminHttp.registerRoute('POST', '/admin/project-home/character/write', characterWriteHandler);
333
+ }
334
+
335
+ async function characterWriteHandler(req, res) {
336
+ let raw;
337
+ try {
338
+ raw = await readBody(req, MAX_CHARACTER_JS_BYTES * 2 + 64 * 1024);
339
+ } catch (e) {
340
+ sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
341
+ return;
342
+ }
343
+ let body;
344
+ try {
345
+ body = raw ? JSON.parse(raw) : {};
346
+ } catch {
347
+ sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
348
+ return;
349
+ }
350
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
351
+ sendJson(res, 400, { ok: false, error: 'invalid payload' });
352
+ return;
353
+ }
354
+ const resolved = resolveCwd(body.cwd);
355
+ if (!resolved.ok) {
356
+ sendJson(res, resolved.status, { ok: false, error: resolved.error });
357
+ return;
358
+ }
359
+ const json = body.json;
360
+ const jsonObj = typeof json === 'string' ? (() => { try { return JSON.parse(json); } catch { return null; } })() : json;
361
+ const jsonErr = validateCharacterJson(jsonObj);
362
+ if (jsonErr) {
363
+ sendJson(res, 400, { ok: false, error: `character.json invalid: ${jsonErr}` });
364
+ return;
365
+ }
366
+ const jsErr = validateCharacterJs(body.js, [...REMOTE_REFERENCE_CHECKS, ...NETWORK_CHECKS]);
367
+ if (jsErr) {
368
+ sendJson(res, 400, { ok: false, error: jsErr });
369
+ return;
370
+ }
371
+ if (!body.replace && readCharacter(resolved.cwd)) {
372
+ sendJson(res, 409, { ok: false, error: 'a character already exists — pass replace: true to overwrite it' });
373
+ return;
374
+ }
375
+ config.addAllowedRoot(resolved.cwd);
376
+ try {
377
+ const dir = characterDir(resolved.cwd);
378
+ await fs.promises.mkdir(dir, { recursive: true });
379
+ const jsPath = path.join(dir, 'character.js');
380
+ await config.writeTextAtomic(jsPath, body.js, { writer: 'project-home' });
381
+ await config.writeTextAtomic(path.join(dir, 'character.json'), JSON.stringify(jsonObj, null, 2) + '\n', { writer: 'project-home' });
382
+ sendJson(res, 200, { ok: true, path: dir, bytes: Buffer.byteLength(body.js, 'utf8') });
383
+ } catch (e) {
384
+ sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
385
+ }
236
386
  }
237
387
 
238
388
  module.exports = {
@@ -240,6 +390,7 @@ module.exports = {
240
390
  validateHomeHtml,
241
391
  validateDemoVideoHtml,
242
392
  injectCsp,
393
+ maxVideoBytes,
243
394
  DEMO_VIDEO_CSP,
244
395
  MAX_HTML_BYTES,
245
396
  MAX_DEMO_VIDEO_BYTES,
@@ -27,6 +27,15 @@ function captureIpcHandlers(ipcMain) {
27
27
  handlers.set(channel, fn)
28
28
  return original(channel, fn)
29
29
  }
30
+ // Send-kind rows (renderer ipcRenderer.send, e.g. log:write) are served by ipcMain.on
31
+ // listeners. Capture the first listener per channel; an invoke handler always wins.
32
+ if (typeof ipcMain.on === 'function') {
33
+ const originalOn = ipcMain.on.bind(ipcMain)
34
+ ipcMain.on = (channel, fn) => {
35
+ if (!handlers.has(channel) && typeof fn === 'function') handlers.set(channel, fn)
36
+ return originalOn(channel, fn)
37
+ }
38
+ }
30
39
  return handlers
31
40
  }
32
41
 
@@ -44,7 +53,13 @@ const PATH_FENCED_CHANNELS = Object.freeze({
44
53
  'files:list': { field: 'path', mode: 'root', allowHomeListing: true },
45
54
  'transcript:readRef': { field: 'filePath', mode: 'secret' },
46
55
  'transcript:path': { field: 'cwd', mode: 'secret' },
56
+ 'transcript:exists': { field: 'cwd', mode: 'secret' },
47
57
  'memory:read': { field: 'cwd', mode: 'secret' },
58
+ // Sessions read tier (main/promptSessionsIpc.cjs): cwd must sit inside a registered project root.
59
+ 'promptSessions:load-active-index': { field: 'cwd', mode: 'root' },
60
+ 'promptSessions:list-archived': { field: 'cwd', mode: 'root' },
61
+ 'promptSessions:read-archived': { field: 'cwd', mode: 'root' },
62
+ 'promptSessions:read-session-transcript': { field: 'cwd', mode: 'root' },
48
63
  })
49
64
 
50
65
  const SECRET_DIRS = new Set(['.ssh', '.gnupg', '.aws', '.kube', '.docker', '.password-store', '.azure', '.terraform.d'])
@@ -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: 'No-ops if the tab is unknown/closed.',
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',
@@ -304,27 +305,69 @@ const MCP_TOOL_CATALOG = [
304
305
  {
305
306
  name: 'project_home_write',
306
307
  group: 'project-home',
307
- purpose: "Write this project's Project Home page — ONE self-contained HTML document — to "
308
- + "session-manager-operations/project-pages/home.html via the session-manager app's admin API. "
309
- + 'The only write path for Project Home.',
310
- whenToUse: 'Use when asked to generate or refresh the project home page. Compose the whole page yourself '
311
- + '(inline <style>/<script>, data: URIs for assets) from what is really true about the project, then '
308
+ purpose: "ALIAS of project_page_write for the Overview page: write this project's Project Home Overview page — ONE self-contained HTML document — to "
309
+ + "session-manager-operations/project-pages/knowledge/overview/ via the session-manager app's admin API. "
310
+ + 'Prefer project_page_write for any new knowledge page.',
311
+ whenToUse: 'Use when asked to generate or refresh the project home Overview page. Compose the whole page yourself '
312
+ + '(inline <style> only — scripts never run in a page; data: URIs for assets) from what is really true about the project, then '
312
313
  + 'pass the full document as `html`.',
313
314
  whenNotToUse: 'Never fabricate content — every claim must trace to something concrete in the project. The '
314
- + 'document must be self-contained: the call is rejected for empty input, more than 1MB, any '
315
+ + 'document must be self-contained and script-free: the call is rejected for empty input, more than 1MB, any '
315
316
  + '<script src>, <link href="http…">, @import, or url(http…) — no network egress.',
316
- exampleArgs: { cwd: '/home/bilko/Projects/session-manager', html: '<!DOCTYPE html><html><body><h1>Example</h1></body></html>' },
317
+ exampleArgs: { cwd: '/home/bilko/Projects/session-manager', html: '<!DOCTYPE html><html><head><style>body{font:16px sans-serif}</style></head><body><h1>Example</h1></body></html>' },
317
318
  notes: "cwd is optional — defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted.",
318
319
  },
320
+ {
321
+ name: 'project_page_write',
322
+ group: 'project-home',
323
+ purpose: "Write one knowledge page for this project's Project Home — ONE self-contained HTML document identified by `pageId` — "
324
+ + "via the session-manager app's admin API. Writing an existing pageId replaces that page.",
325
+ whenToUse: 'Use when asked to document a topic of the project as a page (architecture, how-to, status). Compose the whole page yourself '
326
+ + 'with inline <style> only — scripts never run in a page — from what is really true about the project, then pass it as `html` '
327
+ + 'or, for a large document, write it to a local .html file and pass its absolute path as `htmlPath`.',
328
+ whenNotToUse: 'Never fabricate content. Do not use for videos — use project_video_write. The call is rejected for empty input, more than 1MB, '
329
+ + 'any <script src>, <link href="http…">, @import, or url(http…) — no network egress.',
330
+ exampleArgs: {
331
+ cwd: '/home/bilko/Projects/session-manager',
332
+ pageId: 'architecture',
333
+ title: 'Architecture',
334
+ topic: 'How the app is put together',
335
+ html: '<!DOCTYPE html><html><head><style>body{font:16px sans-serif}</style></head><body><h1>Architecture</h1></body></html>',
336
+ },
337
+ notes: "cwd is optional — defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted. "
338
+ + 'Give exactly one of `html` / `htmlPath` (absolute .html/.htm file, <= 2MB read limit).',
339
+ },
340
+ {
341
+ name: 'project_video_write',
342
+ group: 'project-home',
343
+ purpose: "Write one video for this project's Project Home — ONE self-contained HTML/JS document identified by `videoId` — "
344
+ + "via the session-manager app's admin API. Writing an existing videoId replaces that video.",
345
+ whenToUse: 'Use when asked to make a project video (demo, marketing). Compose the whole document yourself (inline <style>/<script>, '
346
+ + 'data: URIs for assets, CSS/JS-driven animation) from what is really true about the project, declare `kind` and `lengthS`, '
347
+ + 'then pass the document as `html` or — preferred when it embeds a base64 audio/image data URI — as an absolute `htmlPath`.',
348
+ whenNotToUse: 'Never fabricate content. Do not use for static knowledge pages — use project_page_write. The document must be self-contained '
349
+ + 'and non-network-capable: the call is rejected for empty input, more than 2MB, remote references, or network-capable APIs.',
350
+ exampleArgs: {
351
+ cwd: '/home/bilko/Projects/session-manager',
352
+ videoId: 'demo-30s',
353
+ title: 'Product demo',
354
+ kind: 'project-demo',
355
+ lengthS: 30,
356
+ html: '<!DOCTYPE html><html><head><meta name="sm-demo-duration" content="30"></head><body><h1>Example</h1></body></html>',
357
+ meta: {},
358
+ },
359
+ notes: "cwd is optional — defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted. "
360
+ + 'Give exactly one of `html` / `htmlPath` (absolute .html/.htm file, <= 2MB).',
361
+ },
319
362
  {
320
363
  name: 'project_demo_video_write',
321
364
  group: 'project-home',
322
- purpose: "Write this project's 30-second demo video — ONE self-contained HTML/JS document — to "
323
- + "session-manager-operations/project-pages/demo-video/index.html via the session-manager app's admin API. "
324
- + 'The only write path for the demo video.',
365
+ purpose: "ALIAS of project_video_write that adds a project-demo video: write this project's demo video (30 seconds or 1 minute) — ONE self-contained HTML/JS document — as a new "
366
+ + "project-demo entry under session-manager-operations/project-pages/videos/<id>/ via the session-manager app's admin API. "
367
+ + 'project_video_write is the primary video tool; use this alias only for a quick project-demo.',
325
368
  whenToUse: 'Use when asked to generate or refresh the demo video. Compose the whole document yourself '
326
369
  + '(inline <style>/<script>, data: URIs for assets, CSS/JS-driven animation) from what is really true about '
327
- + 'the project, declare its length with <meta name="sm-demo-duration" content="N"> (5-30 seconds), then '
370
+ + 'the project, declare its length with <meta name="sm-demo-duration" content="N"> (5-60 seconds), then '
328
371
  + 'pass the document as `html` or — preferred when it embeds a base64 audio/image data URI — write it to a '
329
372
  + 'local .html file and pass its absolute path as `htmlPath`.',
330
373
  whenNotToUse: 'Never fabricate content — every claim must trace to something concrete in the project. The '
@@ -341,6 +384,24 @@ const MCP_TOOL_CATALOG = [
341
384
  + 'Give exactly one of `html` / `htmlPath` (absolute .html/.htm file, <= 2MB); prefer `htmlPath` for base64 data URIs. '
342
385
  + 'The document is CSP-stamped after it is written, so the viewer sandbox is the real network fence — these checks are defence in depth.',
343
386
  },
387
+ {
388
+ name: 'project_character_write',
389
+ group: 'project-home',
390
+ purpose: "Write this project's reusable video character — a `character.json` descriptor plus a `character.js` drawing module — to "
391
+ + "the project's videos/_character/ folder via the session-manager app's admin API, so every later video can reuse the same mascot.",
392
+ whenToUse: 'Use once per project, before building character videos, to save the mascot you designed. Pass `json` (the descriptor object or its JSON text) '
393
+ + 'and the module as `js` or — preferred for large modules — an absolute `jsPath` to a local .js file. Pass `replace: true` only to deliberately overwrite an existing character.',
394
+ whenNotToUse: 'Never fabricate content. Do not use to write a video — use project_video_write. The call is rejected (409) when a character already exists and `replace` is not set, '
395
+ + 'and for invalid `json`, `js` over 300KB, or `js` with remote references or network-capable APIs.',
396
+ exampleArgs: {
397
+ cwd: '/home/bilko/Projects/session-manager',
398
+ json: { name: 'Bit', voice: 'af_heart' },
399
+ js: 'export function draw(ctx, t) {}',
400
+ replace: false,
401
+ },
402
+ notes: "cwd is optional — defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted. "
403
+ + 'Give exactly one of `js` / `jsPath` (absolute .js file, <= 300KB).',
404
+ },
344
405
  {
345
406
  name: 'customer_feedback_list',
346
407
  group: 'customer-feedback',
@@ -375,7 +436,7 @@ const MCP_TOOL_CATALOG = [
375
436
  purpose: "List this project's HOT KEYS macros — the saved (agent, tag, prompt) one-click buttons shown "
376
437
  + "in the Sessions tab's HOT KEYS strip, via the session-manager app's admin API.",
377
438
  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 update one.',
439
+ + 'built-ins) before deciding whether to add, update or delete one.',
379
440
  whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this only ever returns '
380
441
  + "macros visible to the resolved cwd, never another project's.",
381
442
  exampleArgs: { cwd: '/home/bilko/Projects/session-manager' },
@@ -393,7 +454,8 @@ const MCP_TOOL_CATALOG = [
393
454
  whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this call is refused if '
394
455
  + '`id` resolves to a macro not visible to this project. Built-in macros (`id` starting with `builtin-`) '
395
456
  + "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.',
457
+ + 'create or update one unless the human has actually asked for that macro to exist. '
458
+ + 'To remove a macro use macro_delete; never rewrite it into a placeholder.',
397
459
  exampleArgs: {
398
460
  cwd: '/home/bilko/Projects/session-manager',
399
461
  label: 'Publish git + npm',
@@ -408,6 +470,23 @@ const MCP_TOOL_CATALOG = [
408
470
  + 'when pressing the macro; reference each in the prompt as {{name}}. Omitting `inputs` on update keeps '
409
471
  + 'the existing inputs; `[]` clears them.',
410
472
  },
473
+ {
474
+ name: 'macro_delete',
475
+ group: 'macros',
476
+ purpose: "Remove one of this project's HOT KEYS macros via the session-manager app's admin API, through the same "
477
+ + 'macroLibrary.cjs store the Sessions HOT KEYS strip reads from, so an open strip updates at once.',
478
+ whenToUse: 'Use when the human has asked for that macro to go, for example after its work moved to another project. '
479
+ + 'Get the `id` from macro_list first.',
480
+ whenNotToUse: "WHEN NOT TO USE IT: a macro is a HUMAN's one-click button and this cannot be undone — never delete one "
481
+ + "unless the human has asked for that macro to go. It always acts for the calling session's own project: there is "
482
+ + 'no `cwd` argument, and a macro not listed for this project is refused. Built-in macros are refused. A macro shown '
483
+ + 'in every project is refused too; only the human can remove it, from the HOT KEYS panel. Refused in a scheduled job '
484
+ + "and outside a Session Manager session, because no human is there to ask. To change a macro, use macro_save. "
485
+ + "Another project's macro belongs to that project: use feedback_open_session.",
486
+ exampleArgs: { id: 'blog-video-8d618a' },
487
+ notes: 'Returns { ok, deleted, macro }. `deleted: true` means the macro is gone and `macro` is its last copy. '
488
+ + '`deleted: false` means other projects still list it, so only this project was dropped. A refusal comes back as an error result.',
489
+ },
411
490
  {
412
491
  name: 'session_manager_help',
413
492
  group: 'help',
@@ -48,11 +48,15 @@ const OWNERS = Object.freeze({
48
48
  'scheduler': 'scheduler',
49
49
  // Project Home owns the synthesized Brief (generate + hand-edit).
50
50
  'project-brief': 'project-home',
51
- // Project Home owns project-pages/home.html and project-pages/demo-video/
52
- // index.html, written only via the project_home_write ->
53
- // /admin/project-home/write and project_demo_video_write ->
54
- // /admin/project-home/demo-video/write routes (config.cjs's
55
- // writeTextAtomic). See session-manager-operations/project-pages/README.md.
51
+ // Project Home owns the project-pages library: knowledge/<id>/ pages,
52
+ // videos/<id>/ videos and videos/_character/. Written only via the
53
+ // /admin/project-home/pages/write, /videos/write and /character/write
54
+ // routes (project_page_write, project_video_write, project_character_write),
55
+ // plus the two alias routes /admin/project-home/write (project_home_write ->
56
+ // knowledge/overview/) and /admin/project-home/demo-video/write
57
+ // (project_demo_video_write -> a project-demo entry under videos/<id>/),
58
+ // all via config.cjs's writeTextAtomic.
59
+ // See session-manager-operations/project-pages/README.md.
56
60
  'project-pages': 'project-home',
57
61
  // Structured per-tab error log lines (JSONL), tagged for tracing/analysis.
58
62
  'logs': 'logs',
@@ -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 an unedited stored copy whose `builtinVersion` is behind this file.
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
  */
@@ -19,9 +24,17 @@ const BUILTIN_MACROS = Object.freeze([
19
24
  tag: 'project-home-builder',
20
25
  surface: 'project-home',
21
26
  projects: ['*'],
22
- builtinVersion: 1,
23
- prompt:
27
+ builtinVersion: 2,
28
+ job: Object.freeze({
29
+ estimateMinutes: 20,
30
+ entryKind: 'knowledge',
31
+ artifactPaths: Object.freeze(['session-manager-operations/project-pages/knowledge/{id}/index.html']),
32
+ }),
33
+ priorPrompts: Object.freeze([
24
34
  "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.",
35
+ ]),
36
+ prompt:
37
+ "Generate ONE Knowledge Page for this project as one self-contained HTML page, grounded only in what you read in the repository. The page is named on a 'Page: <name>' line in the additional instructions: Overview (the default when there is no Page line: what it is, who it is for, key features, structure, how to run it, key commands), How it works (architecture and main flows), FAQ (common questions with answers), or 'Custom topic: <text>' (a page about that topic). Build only that page; other pages stay untouched. Save it with a single project_page_write call, passing pageId equal to the id on the 'Entry id' line.",
25
38
  }),
26
39
  Object.freeze({
27
40
  id: 'builtin-demo-video',
@@ -30,9 +43,21 @@ const BUILTIN_MACROS = Object.freeze([
30
43
  tag: 'project-home-builder',
31
44
  surface: 'project-home',
32
45
  projects: ['*'],
33
- builtinVersion: 4,
34
- prompt:
46
+ builtinVersion: 6,
47
+ job: Object.freeze({
48
+ estimateMinutes: 60,
49
+ entryKind: 'video',
50
+ artifactPaths: Object.freeze(['session-manager-operations/project-pages/videos/{id}/index.html']),
51
+ }),
52
+ priorPrompts: Object.freeze([
53
+ '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.',
54
+ '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.',
55
+ '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.',
35
56
  "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.",
57
+ "Generate a character and cute animated JavaScript video: a demo of this project as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise. 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, key features, call to action), then build every keystone to match its lines, with the pacing and 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.",
58
+ ]),
59
+ prompt:
60
+ "Generate a character and cute animated JavaScript video as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise. The video kind is named on a 'Video kind: <name>' line in the additional instructions: Blog post (a video that presents the blog post named on the 'Video target:' line — a post path in this repository or a URL; read it and tell its real content) or Feature (a video about the feature named on the 'Video target:' line, found in the repository); with no Video kind line, make a Project demo of the whole project's main goals and key features. Ground everything in what you read in the repository (and the target) — invent an original mascot character whose look, name and personality match the subject's theme and purpose, and tell its real story through it. Write the narration script first (hook, problem, solution, key points, call to action), then build every keystone to match its lines, with the pacing and 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. 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_video_write call passing the htmlPath and the id on the 'Entry id' line.",
36
61
  }),
37
62
  ]);
38
63