claude-code-session-manager 0.127.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 (76) hide show
  1. package/dist/assets/{AgentLibrary-DKQznr7o.js → AgentLibrary-cNQU5YWy.js} +1 -1
  2. package/dist/assets/{Button-CZXqmIiM.js → Button-9dIPAOBg.js} +1 -1
  3. package/dist/assets/{DataModel-piyV33To.js → DataModel-DrDJ6ysw.js} +1 -1
  4. package/dist/assets/{History-BxwtrKF2.js → History-4rrDdWNP.js} +1 -1
  5. package/dist/assets/{Hooks-DogeSPII.js → Hooks-Bj_jF5Pa.js} +1 -1
  6. package/dist/assets/{Library-BDt6EeQQ.js → Library-D-Wsxrh7.js} +1 -1
  7. package/dist/assets/{ListDetail-CwS-LKar.js → ListDetail-D7Om0H8j.js} +1 -1
  8. package/dist/assets/{McpServers-D2HVljgS.js → McpServers-CbIbSd5o.js} +1 -1
  9. package/dist/assets/{Memory-hNzuOGn8.js → Memory-DgQlvQrO.js} +1 -1
  10. package/dist/assets/{Panel-BLDrsUeq.js → Panel-DZHiD8Ar.js} +1 -1
  11. package/dist/assets/{Permissions-DzZ5vaJW.js → Permissions-CfzduF4B.js} +1 -1
  12. package/dist/assets/{Plugins-Cz9yaxzG.js → Plugins-D-AG5nAo.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-CCgLO4m9.js → ProvenanceBadge-B9JSEjll.js} +1 -1
  14. package/dist/assets/{SaveBar-Shmn699J.js → SaveBar-mVKig6hL.js} +1 -1
  15. package/dist/assets/{Scheduler-Bqr0WHNd.js → Scheduler-DFTCnh60.js} +1 -1
  16. package/dist/assets/{ScopeSwitcher-CBx1fB5g.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
  17. package/dist/assets/{Settings-Ci8in-yF.js → Settings-BTmxRMaP.js} +1 -1
  18. package/dist/assets/{SkillReferenceGraph-BWwljba8.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
  19. package/dist/assets/{Skills-BON6o-c4.js → Skills-CxOacq0k.js} +1 -1
  20. package/dist/assets/{SystemPrompt-D5epIYYs.js → SystemPrompt-BCWg5FAz.js} +1 -1
  21. package/dist/assets/{TagLibrary-C2qDZROJ.js → TagLibrary-BnF0_PkG.js} +1 -1
  22. package/dist/assets/{TiptapBody-SZhI3-bW.js → TiptapBody-C2Iu6rZd.js} +1 -1
  23. package/dist/assets/{Toggle-C_qFDG0g.js → Toggle-C-oD66BG.js} +1 -1
  24. package/dist/assets/{ViewTabs-C9q5WCEd.js → ViewTabs-Cs4v7vLY.js} +1 -1
  25. package/dist/assets/{historyTotals-BCl7IOhY.js → historyTotals-CbRSLD8f.js} +1 -1
  26. package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
  27. package/dist/assets/index-DzY_GXYY.js +3081 -0
  28. package/dist/assets/{settingsSchema-BBrRBrBr.js → settingsSchema-bSBfHuan.js} +1 -1
  29. package/dist/assets/{skillFrontmatter-B01qJk6N.js → skillFrontmatter-BEseWm8r.js} +1 -1
  30. package/dist/assets/{useAgentsDirWatch-CuR3GSjS.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
  31. package/dist/index.html +2 -2
  32. package/dist-web/app.css +1 -1
  33. package/dist-web/app.js +343 -341
  34. package/package.json +1 -1
  35. package/scripts/scheduler-mcp-server.cjs +170 -6
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/index.cjs +14 -0
  38. package/src/main/ipcSchemas.cjs +107 -0
  39. package/src/main/lib/claude/agentModelResolve.cjs +26 -7
  40. package/src/main/lib/claude/personaToolScope.cjs +40 -2
  41. package/src/main/lib/demo-video-kit/capture.cjs +113 -0
  42. package/src/main/lib/demo-video-kit/character.cjs +97 -0
  43. package/src/main/lib/demo-video-kit/checks.cjs +150 -0
  44. package/src/main/lib/demo-video-kit/frames.cjs +200 -0
  45. package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
  46. package/src/main/lib/demo-video-kit/sound.cjs +312 -0
  47. package/src/main/lib/epic/epicValidationHook.cjs +17 -1
  48. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
  49. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
  50. package/src/main/lib/mcpToolCatalog.cjs +71 -11
  51. package/src/main/lib/opsOwnership.cjs +9 -5
  52. package/src/main/lib/persona-macro/builtinMacros.cjs +19 -5
  53. package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
  54. package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
  55. package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
  56. package/src/main/lib/persona-macro/macroLibrary.cjs +16 -0
  57. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +89 -0
  58. package/src/main/lib/prd/prdCreate.cjs +12 -1
  59. package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
  60. package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
  61. package/src/main/lib/project-pages/playerBridge.cjs +129 -0
  62. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  63. package/src/main/lib/smfileHeaders.cjs +11 -3
  64. package/src/main/projectPages.cjs +107 -30
  65. package/src/main/promptSessionsIpc.cjs +131 -0
  66. package/src/main/scheduler/prdParser.cjs +2 -0
  67. package/src/main/scheduler.cjs +26 -9
  68. package/src/main/seedSchedulerMcp.cjs +10 -1
  69. package/src/main/transcripts.cjs +8 -0
  70. package/src/main/webRemote.cjs +3 -1
  71. package/src/preload/api.d.ts +101 -5
  72. package/src/preload/apiSurface.json +70 -0
  73. package/src/preload/index.cjs +13 -0
  74. package/src/seed/agents/demo-video-builder.md +86 -36
  75. package/src/seed/agents/project-home-builder.md +26 -13
  76. package/dist/assets/index-CMIYLbPb.js +0 -3079
@@ -305,27 +305,69 @@ const MCP_TOOL_CATALOG = [
305
305
  {
306
306
  name: 'project_home_write',
307
307
  group: 'project-home',
308
- purpose: "Write this project's Project Home page — ONE self-contained HTML document — to "
309
- + "session-manager-operations/project-pages/home.html via the session-manager app's admin API. "
310
- + 'The only write path for Project Home.',
311
- whenToUse: 'Use when asked to generate or refresh the project home page. Compose the whole page yourself '
312
- + '(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 '
313
313
  + 'pass the full document as `html`.',
314
314
  whenNotToUse: 'Never fabricate content — every claim must trace to something concrete in the project. The '
315
- + '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 '
316
316
  + '<script src>, <link href="http…">, @import, or url(http…) — no network egress.',
317
- 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>' },
318
318
  notes: "cwd is optional — defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted.",
319
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
+ },
320
362
  {
321
363
  name: 'project_demo_video_write',
322
364
  group: 'project-home',
323
- purpose: "Write this project's 30-second demo video — ONE self-contained HTML/JS document — to "
324
- + "session-manager-operations/project-pages/demo-video/index.html via the session-manager app's admin API. "
325
- + '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.',
326
368
  whenToUse: 'Use when asked to generate or refresh the demo video. Compose the whole document yourself '
327
369
  + '(inline <style>/<script>, data: URIs for assets, CSS/JS-driven animation) from what is really true about '
328
- + '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 '
329
371
  + 'pass the document as `html` or — preferred when it embeds a base64 audio/image data URI — write it to a '
330
372
  + 'local .html file and pass its absolute path as `htmlPath`.',
331
373
  whenNotToUse: 'Never fabricate content — every claim must trace to something concrete in the project. The '
@@ -342,6 +384,24 @@ const MCP_TOOL_CATALOG = [
342
384
  + 'Give exactly one of `html` / `htmlPath` (absolute .html/.htm file, <= 2MB); prefer `htmlPath` for base64 data URIs. '
343
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.',
344
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
+ },
345
405
  {
346
406
  name: 'customer_feedback_list',
347
407
  group: 'customer-feedback',
@@ -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',
@@ -24,10 +24,17 @@ const BUILTIN_MACROS = Object.freeze([
24
24
  tag: 'project-home-builder',
25
25
  surface: 'project-home',
26
26
  projects: ['*'],
27
- builtinVersion: 1,
28
- priorPrompts: Object.freeze([]),
29
- 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([
30
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.",
31
38
  }),
32
39
  Object.freeze({
33
40
  id: 'builtin-demo-video',
@@ -36,14 +43,21 @@ const BUILTIN_MACROS = Object.freeze([
36
43
  tag: 'project-home-builder',
37
44
  surface: 'project-home',
38
45
  projects: ['*'],
39
- builtinVersion: 4,
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
+ }),
40
52
  priorPrompts: Object.freeze([
41
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.',
42
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.',
43
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.',
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.",
44
58
  ]),
45
59
  prompt:
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.",
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.",
47
61
  }),
48
62
  ]);
49
63
 
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * macroJobDispatch.cjs — turn a built-in macro press into ONE artifact-only
5
+ * scheduler PRD inside an existing Epic, so the build runs headless as the
6
+ * macro's persona under the scheduler's budget instead of a chat turn.
7
+ * Never mints an Epic (single-creator law): the caller supplies epicId.
8
+ *
9
+ * Plain Node, no Electron imports; all I/O is injected.
10
+ */
11
+
12
+ const path = require('node:path');
13
+ const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
14
+ const { kebabCase } = require('../util/kebabCase.cjs');
15
+
16
+ const ACTIVE = new Set(['pending', 'held', 'running']);
17
+ const RETRYABLE = new Set(['needs_review', 'failed']);
18
+
19
+ function buildGate(absPath, nowMs) {
20
+ // No shell: everything with shell characters sits inside single quotes, so
21
+ // the script itself uses double quotes only (JSON.stringify).
22
+ const script = `const s=require("fs").statSync(${JSON.stringify(absPath)});process.exit(s.size>0&&s.mtimeMs>${nowMs}?0:1)`;
23
+ return `timeout 60 node -e '${script}'`;
24
+ }
25
+
26
+ const PAGE_IDS = { 'how it works': 'how-it-works', faq: 'faq', overview: 'overview' };
27
+
28
+ // Entry id: videos get a fresh one per press; knowledge pages are named by a
29
+ // 'Page: <name>' line in the extra instructions (default 'overview').
30
+ function entryIdFor(kind, extra, t) {
31
+ if (kind === 'video') return `vid-${t.toString(36)}${Math.random().toString(36).slice(2, 5).padEnd(3, '0')}`;
32
+ const m = /^\s*Page:\s*(.+?)\s*$/im.exec(extra || '');
33
+ if (!m) return 'overview';
34
+ const name = m[1];
35
+ const known = PAGE_IDS[name.toLowerCase()];
36
+ if (known) return known;
37
+ const custom = /^custom topic:\s*(.+)$/i.exec(name);
38
+ return kebabCase(custom ? custom[1] : name, { maxLen: 40, fallback: 'overview' });
39
+ }
40
+
41
+ async function dispatchMacroJob(
42
+ { cwd, macroId, epicId, extraInstructions } = {},
43
+ { createPrd, listRows, archivePrd, builtins = BUILTIN_MACROS, now = Date.now } = {},
44
+ ) {
45
+ const macro = (builtins || []).find((m) => m && m.id === macroId);
46
+ if (!macro || !macro.job) return { ok: false, error: `macro ${macroId} has no background job declaration` };
47
+ if (typeof epicId !== 'string' || !epicId.trim()) return { ok: false, error: 'epicId is required — a background build joins an existing Epic' };
48
+ if (typeof cwd !== 'string' || !cwd) return { ok: false, error: 'cwd is required' };
49
+ if (typeof createPrd !== 'function') return { ok: false, error: 'createPrd is not available' };
50
+
51
+ const t = now();
52
+ const extra = typeof extraInstructions === 'string' ? extraInstructions.trim() : '';
53
+ const entryKind = macro.job.entryKind;
54
+ const entryId = entryKind ? entryIdFor(entryKind, extra, t) : null;
55
+ const artifactPaths = macro.job.artifactPaths.map((p) => (entryId ? p.split('{id}').join(entryId) : p));
56
+ const absPaths = artifactPaths.map((p) => path.join(cwd, p));
57
+ for (const s of [cwd, ...absPaths]) {
58
+ if (s.includes("'") || /[\r\n]/.test(s)) return { ok: false, error: "cwd or artifact path contains a character the gate cannot quote (single quote or newline)" };
59
+ }
60
+
61
+ let rows = [];
62
+ try {
63
+ rows = (typeof listRows === 'function' ? await listRows({ cwd }) : []) || [];
64
+ } catch (e) {
65
+ return { ok: false, error: `could not read queue: ${e?.message ?? e}` };
66
+ }
67
+ const mine = rows.filter((r) => r && r.macroId === macroId && (!r.cwd || r.cwd === cwd));
68
+ const active = mine.find((r) => ACTIVE.has(r.status));
69
+ if (active) return { ok: false, error: `${macro.label} is already building`, activeSlug: active.slug };
70
+
71
+ // Newest row decides: a stale needs_review/failed attempt is archived so the
72
+ // retry is not blocked by (or confused with) it.
73
+ const newest = mine.reduce((a, r) => (!a || (Number(r.lastRunAt ?? r.finishedAt ?? 0) >= Number(a.lastRunAt ?? a.finishedAt ?? 0)) ? r : a), null);
74
+ if (newest && RETRYABLE.has(newest.status) && typeof archivePrd === 'function') {
75
+ try { await archivePrd(newest.slug, cwd); } catch { /* best effort */ }
76
+ }
77
+
78
+ const slug = `${kebabCase(macro.label, { maxLen: 30, fallback: 'macro' })}-build-${t.toString(36)}${Math.random().toString(36).slice(2, 5)}`;
79
+ let goal = extra ? `${macro.prompt}\n\nAdditional instructions: ${extra}` : macro.prompt;
80
+ if (entryId) goal += `\n\nEntry id: ${entryId}. Save with ${entryKind === 'video' ? 'videoId' : 'pageId'} = ${entryId}.`;
81
+
82
+ const input = {
83
+ title: `${macro.label}: background build`,
84
+ slug,
85
+ cwd,
86
+ agentType: macro.agentName,
87
+ tag: macro.tag,
88
+ deliverable: 'artifact',
89
+ artifactPaths,
90
+ files: artifactPaths,
91
+ estimateMinutes: macro.job.estimateMinutes,
92
+ macroId,
93
+ sourcePromptId: epicId,
94
+ disposition: 'new-head',
95
+ goal,
96
+ acceptanceCriteria: [
97
+ `${artifactPaths[0]} is written during this run by the save tool your persona names, never by hand.`,
98
+ 'Nothing in the repository is committed.',
99
+ ],
100
+ implementationNotes:
101
+ `Work as the ${macro.agentName} persona (your system prompt) end to end. This build was started from Project Home and no one is watching: never stop to ask. `
102
+ + 'Build outside the repository (mktemp -d under ~/.cache). SM_PROJECT_ROOT is the project main checkout; the save tool writes there, so omit its cwd.',
103
+ gate: absPaths.map((p) => buildGate(p, t)),
104
+ };
105
+
106
+ let res;
107
+ try {
108
+ res = await createPrd(input);
109
+ } catch (e) {
110
+ return { ok: false, error: `createPrd failed: ${e?.message ?? e}` };
111
+ }
112
+ if (!res || res.ok === false) return { ok: false, error: res?.error || 'createPrd failed' };
113
+ return { ok: true, slug, epicId };
114
+ }
115
+
116
+ module.exports = { dispatchMacroJob };
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * macroJobIpc.cjs — IPC handlers `macros:dispatch-job` and `macros:job-status`.
5
+ * Thin wiring over dispatchMacroJob / macroJobStatuses; every dependency is
6
+ * injected (index.cjs passes the real scheduler, createPrd and archive).
7
+ *
8
+ * deps: { schemas, validatePath, readActiveIndex, createPrd, loadJobs,
9
+ * archivePrd, dispatchMacroJob?, macroJobStatuses?, readHistoryTail? }
10
+ * `createPrd` is called as `chat:create-prd` calls it, so its own
11
+ * remote.requestReconcile() queues the row at once — no second rescan here.
12
+ */
13
+
14
+ const { dispatchMacroJob: realDispatch } = require('./macroJobDispatch.cjs');
15
+ const { macroJobStatuses: realStatuses } = require('./macroJobStatus.cjs');
16
+
17
+ function registerMacroJobIpc(ipcMain, deps = {}) {
18
+ const dispatch = deps.dispatchMacroJob || realDispatch;
19
+ const statuses = deps.macroJobStatuses || realStatuses;
20
+
21
+ ipcMain.handle('macros:dispatch-job', async (_event, rawPayload) => {
22
+ const payload = deps.schemas.macrosDispatchJob.parse(rawPayload);
23
+ const cwd = deps.validatePath(payload.cwd);
24
+ const index = deps.readActiveIndex(cwd);
25
+ const sessions = index && index.sessions ? index.sessions : {};
26
+ const entry = Object.prototype.hasOwnProperty.call(sessions, payload.epicId) ? sessions[payload.epicId] : null;
27
+ if (!entry || entry.status !== 'active') {
28
+ return { ok: false, error: `epic ${payload.epicId} is not an active session in this project` };
29
+ }
30
+ return dispatch(
31
+ { cwd, macroId: payload.macroId, epicId: payload.epicId, extraInstructions: payload.extraInstructions },
32
+ {
33
+ createPrd: deps.createPrd,
34
+ listRows: async () => deps.loadJobs(),
35
+ archivePrd: (slug, rowCwd) => deps.archivePrd(slug, rowCwd),
36
+ },
37
+ );
38
+ });
39
+
40
+ ipcMain.handle('macros:job-status', async (_event, rawPayload) => {
41
+ const payload = deps.schemas.macrosJobStatus.parse(rawPayload);
42
+ const cwd = deps.validatePath(payload.cwd);
43
+ return statuses({ cwd }, {
44
+ loadJobs: deps.loadJobs,
45
+ ...(deps.readHistoryTail ? { readHistoryTail: deps.readHistoryTail } : {}),
46
+ });
47
+ });
48
+ }
49
+
50
+ module.exports = { registerMacroJobIpc };
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * macroJobStatus.cjs — per built-in macro with a `job` declaration, the state of
5
+ * its newest background job for one project: newest live queue row, else newest
6
+ * entry in a bounded tail of the project's scheduler history. Read-only.
7
+ *
8
+ * Plain Node, no Electron imports; all I/O is injected.
9
+ */
10
+
11
+ const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
12
+ const { readTail } = require('../util/fileTail.cjs');
13
+
14
+ const HISTORY_TAIL_BYTES = 524288;
15
+ const RUNNING = new Set(['running', 'investigating']);
16
+ const FAILED = new Set(['failed', 'needs_review', 'skipped', 'cancelled']);
17
+
18
+ function stateOf(status) {
19
+ if (RUNNING.has(status)) return 'running';
20
+ if (status === 'completed') return 'done';
21
+ if (FAILED.has(status)) return 'failed';
22
+ return 'queued'; // pending/held/blocked/deferred/null/unknown
23
+ }
24
+
25
+ function reasonOf(row, status) {
26
+ if (row.verifierVerdict === 'budget_exceeded') {
27
+ const n = row.budgetMinutes;
28
+ return Number.isFinite(n) && n > 0 ? `Timed out at the ${n}-minute job budget` : 'Timed out at the job budget';
29
+ }
30
+ for (const v of [row.error, row.finalizeReason, row.terminalReason]) {
31
+ if (typeof v === 'string' && v.trim()) return v;
32
+ }
33
+ return `Ended as ${status}`;
34
+ }
35
+
36
+ function toStatus(macroId, row) {
37
+ const status = row.status == null ? null : row.status;
38
+ const state = stateOf(status);
39
+ return {
40
+ macroId,
41
+ epicId: row.epicId ?? row.sourcePromptId ?? null,
42
+ slug: row.slug ?? null,
43
+ state,
44
+ status,
45
+ reason: state === 'failed' ? reasonOf(row, status) : null,
46
+ startedAt: row.startedAt ?? null,
47
+ finishedAt: row.finishedAt ?? null,
48
+ };
49
+ }
50
+
51
+ function stamp(row) {
52
+ const t = Date.parse(row.finishedAt || row.startedAt || row.createdAt || row.queuedAt || '');
53
+ return Number.isFinite(t) ? t : 0;
54
+ }
55
+
56
+ /** Newest row of `rows` (ties: later in the list wins). */
57
+ function newest(rows) {
58
+ let best = null;
59
+ let bestT = -Infinity;
60
+ for (const r of rows) {
61
+ const t = stamp(r);
62
+ if (t >= bestT) { best = r; bestT = t; }
63
+ }
64
+ return best;
65
+ }
66
+
67
+ function parseHistory(text) {
68
+ const out = [];
69
+ if (typeof text !== 'string' || !text) return out;
70
+ for (const line of text.split('\n')) {
71
+ if (!line.trim()) continue;
72
+ try {
73
+ const o = JSON.parse(line);
74
+ if (o && typeof o === 'object' && !o.kind) out.push(o);
75
+ } catch { /* torn line (tail cut mid-line, partial write) */ }
76
+ }
77
+ return out;
78
+ }
79
+
80
+ function defaultReadHistoryTail(cwd) {
81
+ const { projectHistoryPath } = require('../scheduler/queueStore.cjs');
82
+ return readTail(projectHistoryPath(cwd), HISTORY_TAIL_BYTES);
83
+ }
84
+
85
+ async function macroJobStatuses({ cwd } = {}, { loadJobs, readHistoryTail = defaultReadHistoryTail, builtins = BUILTIN_MACROS } = {}) {
86
+ const macros = (builtins || []).filter((m) => m && m.job && m.id);
87
+ if (!macros.length) return [];
88
+ let live = [];
89
+ try {
90
+ const rows = typeof loadJobs === 'function' ? await loadJobs() : [];
91
+ live = Array.isArray(rows) ? rows.filter((r) => r && r.cwd === cwd && r.macroId) : [];
92
+ } catch { live = []; }
93
+
94
+ let history = null; // lazily read once, only if some macro has no live row
95
+ const loadHistory = async () => {
96
+ if (history) return history;
97
+ try {
98
+ history = parseHistory(await readHistoryTail(cwd)).filter((r) => r.macroId && (!r.cwd || r.cwd === cwd));
99
+ } catch { history = []; }
100
+ return history;
101
+ };
102
+
103
+ const out = [];
104
+ for (const m of macros) {
105
+ let row = newest(live.filter((r) => r.macroId === m.id));
106
+ if (!row) row = newest((await loadHistory()).filter((r) => r.macroId === m.id));
107
+ if (row) out.push(toStatus(m.id, row));
108
+ }
109
+ return out;
110
+ }
111
+
112
+ module.exports = { macroJobStatuses, HISTORY_TAIL_BYTES };
@@ -481,8 +481,24 @@ async function loadStore(filePath, opts) {
481
481
 
482
482
  // --- public API -------------------------------------------------------------
483
483
 
484
+ /**
485
+ * Decorate built-in entries with their live `job` declaration from BUILTIN_MACROS.
486
+ * Never persisted: `job` is read at list time so a stored copy cannot freeze it.
487
+ */
488
+ function withBuiltinJobs(macros) {
489
+ return macros.map((m) => {
490
+ const { job: _stale, ...rest } = m;
491
+ const b = BUILTIN_MACROS.find((x) => x.id === m.id);
492
+ return b && b.job ? { ...rest, job: b.job } : rest;
493
+ });
494
+ }
495
+
484
496
  /** @returns {Promise<Macro[]>} */
485
497
  async function listMacros(opts = {}) {
498
+ return withBuiltinJobs(await listMacrosRaw(opts));
499
+ }
500
+
501
+ async function listMacrosRaw(opts) {
486
502
  const filePath = resolvePath(opts);
487
503
  const first = await readStore(filePath);
488
504
  if (first.state === 'ok') {
@@ -161,6 +161,18 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
161
161
  },
162
162
  ],
163
163
  "project-home-builder": [
164
+ // Not from src/seed git history: this body was written to ~/.claude/agents by this repo's own
165
+ // agent on 2026-08-02, before the seed file existed, so no seed commit ever contained it.
166
+ {
167
+ commit: "pre-seed-2026-08-02",
168
+ bodySha256: "ad9f77d1279b7e8b0856285c361f45d8b339369a63675307817d781e82588662",
169
+ fm: {
170
+ description: "Generates a project's static Project Home/Project Pages from that project's own saved component library and a computed project summary, if that pipeline exists there.",
171
+ tools: "Read, Grep, Glob, Bash, Write, Edit",
172
+ tags: "project-home-builder",
173
+ title: "Platform — Docs Engineer",
174
+ },
175
+ },
164
176
  {
165
177
  commit: "e9f2f540",
166
178
  bodySha256: "e1c80f465179f814f1e9ea95529434309e5238facdc8c6664cb8f44f8302e148",
@@ -190,6 +202,39 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
190
202
  effort: "medium",
191
203
  },
192
204
  },
205
+ {
206
+ commit: "seed-v3",
207
+ bodySha256: "8cef2256f31d1d166a305923388d1d0d2f4f099275df24d869decc35a6cb11bb",
208
+ fm: {
209
+ description: "Reads a project and writes ONE self-contained overview page (home.html) for its Project Home tab, then saves it with a single project_home_write call.",
210
+ tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_home_write",
211
+ title: "Project Home — Builder",
212
+ model: "sonnet",
213
+ effort: "medium",
214
+ },
215
+ },
216
+ {
217
+ commit: "seed-v4",
218
+ bodySha256: "525ba0b41d540bea5804b9c34765e05566555fb8447659a3b3c6579814c4a563",
219
+ fm: {
220
+ description: "Reads a project and writes ONE Knowledge Page (Overview by default, or How it works, FAQ, or a custom topic) for its Project Home tab, then saves it with a single project_page_write call.",
221
+ tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_home_write, mcp__session-manager-scheduler__project_page_write",
222
+ title: "Project Home — Builder",
223
+ model: "sonnet",
224
+ effort: "medium",
225
+ },
226
+ },
227
+ {
228
+ commit: "persona-no-reach-around",
229
+ bodySha256: "3453b38989b713e6671efdb1417a003dc6fc40fa82e506faf24239c598947c26",
230
+ fm: {
231
+ description: "Reads a project and writes ONE Knowledge Page (Overview by default, or How it works, FAQ, or a custom topic) for its Project Home tab, then saves it with a single project_page_write call.",
232
+ tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_home_write, mcp__session-manager-scheduler__project_page_write",
233
+ title: "Project Home — Builder",
234
+ model: "sonnet",
235
+ effort: "medium",
236
+ },
237
+ },
193
238
  ],
194
239
  "validator": [
195
240
  {
@@ -353,6 +398,50 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
353
398
  effort: "max",
354
399
  },
355
400
  },
401
+ {
402
+ commit: "seed-v6",
403
+ bodySha256: "503ab8eed370d546f0435ac56a1470a1af31c6c665a2660af8c94b4d9ed6361a",
404
+ fm: {
405
+ description: "30-second self-contained HTML/JS demo video for Project Home, saved via project_demo_video_write.",
406
+ tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_demo_video_write",
407
+ title: "Project Home — Demo Video",
408
+ model: "opus",
409
+ effort: "max",
410
+ },
411
+ },
412
+ {
413
+ commit: "seed-v7",
414
+ bodySha256: "7d2040de1734c23148c3870b6ce3a3e5ce2aa319637dc7fc0cc2af63ec1b3036",
415
+ fm: {
416
+ description: "30-second or 1-minute self-contained HTML/JS demo video for Project Home, saved via project_demo_video_write.",
417
+ tools: "Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__project_demo_video_write",
418
+ title: "Project Home — Demo Video",
419
+ model: "opus",
420
+ effort: "max",
421
+ },
422
+ },
423
+ {
424
+ commit: "seed-v8",
425
+ bodySha256: "cf1bff8a70042f93fa18d2102ca71b969825377b9460834f3d2ae15f915d206b",
426
+ fm: {
427
+ description: "30-second or 1-minute self-contained HTML/JS demo video for Project Home, saved via project_video_write.",
428
+ 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",
429
+ title: "Project Home — Demo Video",
430
+ model: "opus",
431
+ effort: "max",
432
+ },
433
+ },
434
+ {
435
+ commit: "persona-no-reach-around",
436
+ bodySha256: "259ae44d41f10990d55d1444d3bbf97012a9330d5bfb2ac5a7229113bb125e36",
437
+ fm: {
438
+ description: "30-second or 1-minute self-contained HTML/JS demo video for Project Home, saved via project_video_write.",
439
+ 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",
440
+ title: "Project Home — Demo Video",
441
+ model: "opus",
442
+ effort: "max",
443
+ },
444
+ },
356
445
  ],
357
446
  "blender-artist": [
358
447
  {
@@ -81,10 +81,15 @@ function deriveSlugFromTitle(title) {
81
81
  * criteria / Files / Implementation notes / Out of scope / Gate /
82
82
  * Engineering standards, in order.
83
83
  */
84
+ const MACRO_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
85
+ function isValidMacroId(id) {
86
+ return typeof id === 'string' && MACRO_ID_RE.test(id);
87
+ }
88
+
84
89
  function buildPrdBody(input) {
85
90
  const {
86
91
  title, cwd, estimateMinutes, goal, acceptanceCriteria,
87
- implementationNotes, outOfScope, sourcePromptId, sourceTabId, tag, agentType, dependsOn, quietMachine, disposition, deliverable, artifactPaths, planId,
92
+ implementationNotes, outOfScope, sourcePromptId, sourceTabId, tag, agentType, dependsOn, quietMachine, disposition, deliverable, artifactPaths, planId, macroId,
88
93
  gate, files, budgetExempt,
89
94
  } = input;
90
95
 
@@ -137,6 +142,7 @@ function buildPrdBody(input) {
137
142
  // criteria are wall-clock/timing measurements that CPU contention from
138
143
  // sibling jobs would otherwise invalidate. Only emitted when true — see
139
144
  // prdFrontmatter.cjs's applyKey for the matching "only true opts in" parse.
145
+ if (isValidMacroId(macroId)) fmLines.push(`macroId: ${macroId}`);
140
146
  if (quietMachine === true) fmLines.push('quietMachine: true');
141
147
  // Budget exemption is for a sweep validator that cannot be split further;
142
148
  // every other caller's budgetExempt is ignored.
@@ -404,6 +410,11 @@ async function createPrdInner(input, remote, ctl, opts = {}) {
404
410
  }
405
411
  }
406
412
 
413
+ // macroId (in-process callers only): refused before NN allocation.
414
+ if (input.macroId != null && !isValidMacroId(input.macroId)) {
415
+ return { ok: false, applied: false, status: 400, error: 'macroId must match /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/ when given' };
416
+ }
417
+
407
418
  // Fake-heading guard (gate-and-files-in-PRD-body unit): a caller-supplied
408
419
  // free-text field that itself contains a "# Gate" or "# Files" heading line
409
420
  // would, after buildPrdBody splices in the real section below, read as TWO