claude-code-session-manager 0.141.0 → 0.142.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 (200) hide show
  1. package/README.md +80 -70
  2. package/bin/cli.cjs +11 -0
  3. package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
  4. package/dist/assets/{History-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
  5. package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
  6. package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
  7. package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
  8. package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
  10. package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
  11. package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
  12. package/dist/assets/Toggle-CiYCWLjh.js +1 -0
  13. package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
  14. package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-DDunb8Ch.js} +1 -1
  15. package/dist/assets/index-Cn5E9958.js +3133 -0
  16. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +496 -484
  20. package/package.json +4 -2
  21. package/plugins/AGENTS.md +4 -3
  22. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  23. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  24. package/plugins/session-manager-dev/skills/develop/SKILL.md +52 -18
  25. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  26. package/scripts/README.md +1 -0
  27. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  28. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  29. package/scripts/scheduler-mcp-server.cjs +732 -110
  30. package/src/main/adminRouteRegistry.cjs +59 -0
  31. package/src/main/agentLibrary.cjs +72 -4
  32. package/src/main/agentsIpc.cjs +3 -2
  33. package/src/main/build-info.json +4 -4
  34. package/src/main/chatRunner.cjs +231 -16
  35. package/src/main/config.cjs +30 -0
  36. package/src/main/docEdit.cjs +4 -2
  37. package/src/main/health.cjs +91 -0
  38. package/src/main/index.cjs +98 -48
  39. package/src/main/ipcSchemas.cjs +161 -8
  40. package/src/main/lib/AGENTS.md +1 -1
  41. package/src/main/lib/chatBootRecovery.cjs +2 -0
  42. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  43. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  44. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  45. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  46. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  47. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  48. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  49. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  50. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  51. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  52. package/src/main/lib/demo-video-kit/cast.md +43 -0
  53. package/src/main/lib/demo-video-kit/character.cjs +722 -30
  54. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  55. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  56. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  57. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  58. package/src/main/lib/demo-video-kit/kind-tiktok.md +99 -0
  59. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  60. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  61. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  62. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  63. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  64. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  65. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  66. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  67. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  68. package/src/main/lib/epic/artifactRetention.cjs +310 -0
  69. package/src/main/lib/epic/artifactStore.cjs +392 -0
  70. package/src/main/lib/epic/delegationReadiness.cjs +76 -2
  71. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  72. package/src/main/lib/epic/epicEventLog.cjs +214 -0
  73. package/src/main/lib/epic/epicMint.cjs +43 -1
  74. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  75. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  76. package/src/main/lib/epic/epicPurge.cjs +347 -0
  77. package/src/main/lib/epic/epicReopen.cjs +5 -2
  78. package/src/main/lib/epic/epicSettle.cjs +4 -13
  79. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  80. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  81. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  82. package/src/main/lib/epic/epicValidationHook.cjs +81 -2
  83. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  84. package/src/main/lib/externalContract.cjs +37 -4
  85. package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
  86. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  87. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  88. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  89. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  90. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  91. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  92. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  93. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  94. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  95. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  96. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  97. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
  98. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  99. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  100. package/src/main/lib/feedback-remote/pendingReplies.cjs +189 -0
  101. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
  102. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  103. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  104. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  105. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  106. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  107. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  108. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  109. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  110. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  111. package/src/main/lib/git/worktreeDeps.cjs +77 -2
  112. package/src/main/lib/mcpToolCatalog.cjs +304 -28
  113. package/src/main/lib/opsOwnership.cjs +29 -1
  114. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  115. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  116. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  117. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  118. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  119. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  120. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  121. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +263 -0
  122. package/src/main/lib/phaseProjection.cjs +103 -0
  123. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  124. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  125. package/src/main/lib/prd/prdCreate.cjs +41 -5
  126. package/src/main/lib/prd/prdCriteria.cjs +225 -0
  127. package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
  128. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  129. package/src/main/lib/prd/prdSizing.cjs +3 -1
  130. package/src/main/lib/process/cleanEnv.cjs +52 -1
  131. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  132. package/src/main/lib/process/memoryScope.cjs +31 -3
  133. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  134. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  135. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  136. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  137. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  138. package/src/main/lib/promptSessionSchema.cjs +6 -0
  139. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  140. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  141. package/src/main/lib/scheduler/criteriaChecks.cjs +169 -0
  142. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  143. package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
  144. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  145. package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
  146. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
  147. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  148. package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -0
  149. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  150. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  151. package/src/main/lib/scheduler/schedulerPaths.cjs +0 -3
  152. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  153. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  154. package/src/main/lib/scheduler/slotsRoute.cjs +237 -0
  155. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  156. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
  157. package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
  158. package/src/main/lib/tasks/mitigationReview.cjs +294 -0
  159. package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
  160. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  161. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  162. package/src/main/lib/tasks/taskRun.cjs +186 -17
  163. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  164. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  165. package/src/main/lib/telemetry/auditEvents.cjs +207 -6
  166. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  167. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  168. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  169. package/src/main/lib/toolUseClassify.cjs +181 -0
  170. package/src/main/lib/util/smfileRange.cjs +77 -0
  171. package/src/main/projectPages.cjs +3 -1
  172. package/src/main/promptSessionEvents.cjs +5 -0
  173. package/src/main/pty.cjs +68 -0
  174. package/src/main/queueOps.cjs +32 -13
  175. package/src/main/runVerify.cjs +74 -9
  176. package/src/main/scheduler/AGENTS.md +1 -0
  177. package/src/main/scheduler/budget.cjs +6 -5
  178. package/src/main/scheduler/prdParser.cjs +46 -13
  179. package/src/main/scheduler/reviewLadder.cjs +9 -25
  180. package/src/main/scheduler/utilizationHold.cjs +101 -0
  181. package/src/main/scheduler.cjs +1414 -189
  182. package/src/main/templates/PRD_AUTHORING.md +5 -2
  183. package/src/main/webRemote.cjs +463 -6
  184. package/src/preload/api.d.ts +529 -38
  185. package/src/preload/apiSurface.json +209 -7
  186. package/src/preload/index.cjs +46 -1
  187. package/src/seed/agents/architect.md +6 -1
  188. package/src/seed/agents/blender-artist.md +2 -1
  189. package/src/seed/agents/competitive-analyst.md +3 -1
  190. package/src/seed/agents/competitive-researcher.md +2 -1
  191. package/src/seed/agents/demo-video-builder.md +87 -83
  192. package/src/seed/agents/dev-lead.md +3 -3
  193. package/src/seed/agents/project-home-builder.md +9 -31
  194. package/src/seed/agents/validator.md +9 -10
  195. package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
  196. package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
  197. package/dist/assets/Scheduler-cyr61UAC.js +0 -16
  198. package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
  199. package/dist/assets/index-B2TQz3nd.js +0 -3121
  200. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -51,11 +51,13 @@ const BUILTIN_MACROS = Object.freeze([
51
51
  tag: 'project-home-builder',
52
52
  surface: 'project-home',
53
53
  projects: ['*'],
54
- builtinVersion: 9,
54
+ builtinVersion: 12,
55
55
  job: Object.freeze({
56
56
  estimateMinutes: 60,
57
57
  entryKind: 'video',
58
58
  artifactPaths: Object.freeze(['session-manager-operations/project-pages/videos/{id}/index.html']),
59
+ // A press may opt into the review stage (reviewStage: true); see macroJobDispatch.cjs.
60
+ reviewable: true,
59
61
  }),
60
62
  priorPrompts: Object.freeze([
61
63
  '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.',
@@ -66,9 +68,12 @@ const BUILTIN_MACROS = Object.freeze([
66
68
  "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.",
67
69
  "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; a 'Video length: 30' line means 30 seconds. 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. A 'Video kind: Project demo' line means that same whole-project demo. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style 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.",
68
70
  "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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. A 'Video kind: Project demo' line means that same whole-project demo. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style 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.",
71
+ "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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. A 'Video kind: Project demo' line means that same whole-project demo. A Blog post or Feature kind with no 'Video target:' line, or with a target you cannot find in the repository or read at its URL, also means that same whole-project demo: never pick a post or feature yourself, say so in your report, and save the kind as project-demo. When the target makes claims about how this project works, check each one against the code: drop a claim the code contradicts or attribute it to the post, and never narrate it as fact about the project. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style 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.",
72
+ "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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; a 'Video kind: TikTok' line means a vertical 9:16 short for this project's own audience, made by following the kit's kind-tiktok.md playbook and saved as kind tiktok with its MP4, poster and post caption, and a 'Video kind: Marketing' line means a 16:9 landing-page video made by following the kit's kind-marketing.md playbook and saved as kind marketing with its MP4 and poster; a TikTok or Marketing video with no target is about the whole project and never falls back to a Project demo. A 'Video kind: Project demo' line means that same whole-project demo. A Blog post or Feature kind with no 'Video target:' line, or with a target you cannot find in the repository or read at its URL, also means that same whole-project demo: never pick a post or feature yourself, say so in your report, and save the kind as project-demo. When the target makes claims about how this project works, check each one against the code: drop a claim the code contradicts or attribute it to the post, and never narrate it as fact about the project. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style that best fits. When the project has a saved persona in videos/_character, it hosts the video and narration uses the saved project persona's voice: a command voice speaks every line with no fallback, and a failure fails the run, and a Kokoro persona voice uses its own voice id. Narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona only when there is no saved persona. Save it with a single project_video_write call passing the htmlPath and the id on the 'Entry id' line.",
73
+ "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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; a 'Video kind: TikTok' line means a vertical 9:16 short for this project's own audience, made by following the kit's kind-tiktok.md playbook and saved as kind tiktok with its MP4, poster and post caption, and a 'Video kind: Marketing' line means a 16:9 landing-page video made by following the kit's kind-marketing.md playbook and saved as kind marketing with its MP4 and poster; a TikTok or Marketing video with no target is about the whole project and never falls back to a Project demo. A 'Video kind: Project demo' line means that same whole-project demo. A Blog post or Feature kind with no 'Video target:' line, or with a target you cannot find in the repository or read at its URL, also means that same whole-project demo: never pick a post or feature yourself, say so in your report, and save the kind as project-demo. When the target makes claims about how this project works, check each one against the code: drop a claim the code contradicts or attribute it to the post, and never narrate it as fact about the project. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style that best fits. When the project has a saved persona in videos/_character, it hosts the video and narration uses the saved project persona's voice: a command voice speaks every line with no fallback, and a failure fails the run, and a Kokoro persona voice uses its own voice id. When the saved persona has a cast, every line is spoken in its own speaker's voice, the host's or that cast member's, with the same no-fallback rule, and a cast member with no voice never speaks. Narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona only when there is no saved persona. Save it with a single project_video_write call passing the htmlPath and the id on the 'Entry id' line.",
69
74
  ]),
70
75
  prompt:
71
- "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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. A 'Video kind: Project demo' line means that same whole-project demo. A Blog post or Feature kind with no 'Video target:' line, or with a target you cannot find in the repository or read at its URL, also means that same whole-project demo: never pick a post or feature yourself, say so in your report, and save the kind as project-demo. When the target makes claims about how this project works, check each one against the code: drop a claim the code contradicts or attribute it to the post, and never narrate it as fact about the project. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style 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."
76
+ "Generate a cute animated JavaScript video with an original mascot character unless a Character: off line says otherwise, as one self-contained HTML/JavaScript animation, 60 seconds long when the additional instructions carry a 'Video length: 60' line and 30 seconds otherwise; a 'Video length: 30' line means 30 seconds. 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; a 'Video kind: TikTok' line means a vertical 9:16 short for this project's own audience, made by following the kit's kind-tiktok.md playbook and saved as kind tiktok with its MP4, poster and post caption, and a 'Video kind: Marketing' line means a 16:9 landing-page video made by following the kit's kind-marketing.md playbook and saved as kind marketing with its MP4 and poster; a TikTok or Marketing video with no target is about the whole project and never falls back to a Project demo. A 'Video kind: Project demo' line means that same whole-project demo. A Blog post or Feature kind with no 'Video target:' line, or with a target you cannot find in the repository or read at its URL, also means that same whole-project demo: never pick a post or feature yourself, say so in your report, and save the kind as project-demo. When the target makes claims about how this project works, check each one against the code: drop a claim the code contradicts or attribute it to the post, and never narrate it as fact about the project. 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. A 'Character: off' line means no mascot: make a type-led animation in the chosen style that tells the same real story through moving type and shapes, skip the character wherever the persona uses one (design, _character, project_character_write, lip-sync, the character self-check) and save meta.character as null; a 'Character: on' line or no Character line keeps the mascot. 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. A 'Video style: Auto' line means the same: pick the style that best fits. When the project has a saved persona in videos/_character, it hosts the video and narration uses the saved project persona's voice: a command voice speaks every line with no fallback, and a failure fails the run, and a Kokoro persona voice uses its own voice id. When the saved persona has a cast, every line is spoken in its own speaker's voice, the host's or that cast member's, with the same no-fallback rule, and a cast member with no voice never speaks. Speak every narration line through the kit with node <kit>/character.cjs speak spec.json, never a hand-written TTS script: a 'Voice: <id>' line in the additional instructions picks the voice first (as spec.voice), then the saved persona's voice, then, only when there is no saved persona, the kit default 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.",
72
77
  }),
73
78
  Object.freeze({
74
79
  id: 'builtin-review-md-network',
@@ -9,6 +9,12 @@
9
9
  * A project's own Video tool (library macro, surface 'project-video', projects
10
10
  * [cwd], with a job) dispatches the same way: artifact-only, or a committing PRD
11
11
  * when job.repoPaths is set, with an optional review stage when job.review is set.
12
+ * A built-in whose job.reviewable is true (Demo Video) runs that same review
13
+ * stage when the press passes reviewStage: true or a review decision.
14
+ * A project Video tool's job gets voiceId = the press's voiceId, else the tool's
15
+ * default voiceId, else nothing; handed to createPrd as `voiceId` (PRD
16
+ * frontmatter, which the scheduler exports as SM_VOICE_ID) and named in the
17
+ * job's implementation notes as a 'Voice: <id>' line.
12
18
  *
13
19
  * Plain Node, no Electron imports; all I/O is injected.
14
20
  */
@@ -18,14 +24,22 @@ const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
18
24
  const { kebabCase } = require('../util/kebabCase.cjs');
19
25
  const { PRD_EFFORT_LEVELS } = require('../prd/prdFrontmatter.cjs');
20
26
  const { renderMacroPrompt } = require('./macroLibrary.cjs');
27
+ const { VOICE_ID_RE } = require('../demo-video-kit/voiceLibrary.cjs');
21
28
 
22
29
  const ACTIVE = new Set(['pending', 'held', 'running']);
23
30
  const RETRYABLE = new Set(['needs_review', 'failed']);
24
31
 
25
- function buildGate(absPath, nowMs) {
32
+ // One path keeps the original single-stat script. Alternatives (Demo Video:
33
+ // the stage artifact OR outcome.json) pass when ANY is fresh (size > 0,
34
+ // mtime after dispatch); a missing alternative counts as not fresh.
35
+ function buildGate(absPaths, nowMs) {
36
+ const list = Array.isArray(absPaths) ? absPaths : [absPaths];
26
37
  // No shell: everything with shell characters sits inside single quotes, so
27
- // the script itself uses double quotes only (JSON.stringify).
28
- const script = `const s=require("fs").statSync(${JSON.stringify(absPath)});process.exit(s.size>0&&s.mtimeMs>${nowMs}?0:1)`;
38
+ // the script itself uses double quotes only (JSON.stringify) and never a
39
+ // single quote.
40
+ const script = list.length === 1
41
+ ? `const s=require("fs").statSync(${JSON.stringify(list[0])});process.exit(s.size>0&&s.mtimeMs>${nowMs}?0:1)`
42
+ : `const f=require("fs");process.exit(${JSON.stringify(list)}.some((p)=>{try{const s=f.statSync(p);return s.size>0&&s.mtimeMs>${nowMs}}catch{return false}})?0:1)`;
29
43
  return `timeout 60 node -e '${script}'`;
30
44
  }
31
45
 
@@ -62,6 +76,10 @@ function rawEntryIdFor(kind, extra, t) {
62
76
  const VIDEO_INDEX_REL = 'session-manager-operations/project-pages/videos/{id}/index.html';
63
77
  // Same string as video-review-store's REVIEW_MATERIAL_REL (asserted by the IPC wiring test).
64
78
  const REVIEW_MATERIAL_REL = 'session-manager-operations/project-pages/videos/{id}/review/material.json';
79
+ // Written by project_video_outcome_write (projectHomeAdminRoutes.cjs): a run that
80
+ // ends with a saved outcome (season-complete) and no video on purpose.
81
+ const OUTCOME_REL = 'session-manager-operations/project-pages/videos/{id}/outcome.json';
82
+ const OUTCOME_MACRO_ID = 'builtin-demo-video';
65
83
 
66
84
  const oneLine = (v) => String(v).replace(/[\r\n]+/g, ' ').trim();
67
85
 
@@ -91,8 +109,19 @@ function resolveProjectTool(macros, macroId, cwd) {
91
109
  return m;
92
110
  }
93
111
 
112
+ // Review stage: a project tool with job.review always reviews first; a built-in
113
+ // with job.reviewable reviews only when the press opts in (reviewStage === true)
114
+ // or a 'changes' decision sends it back. An approved review is the final build.
115
+ function stageFor(tool, builtin, review, reviewStage) {
116
+ const decision = review && typeof review === 'object' ? review.decision : undefined;
117
+ if (tool) return tool.job.review ? (decision === 'approved' ? 'final' : 'review') : null;
118
+ if (!builtin || builtin.job.reviewable !== true) return null;
119
+ if (decision === 'approved') return 'final';
120
+ return reviewStage === true || decision === 'changes' ? 'review' : null;
121
+ }
122
+
94
123
  async function dispatchMacroJob(
95
- { cwd, macroId, epicId, extraInstructions, effort, inputValues, review } = {},
124
+ { cwd, macroId, epicId, extraInstructions, effort, inputValues, review, reviewStage, voiceId } = {},
96
125
  { createPrd, listRows, archivePrd, builtins = BUILTIN_MACROS, macros = [], now = Date.now } = {},
97
126
  ) {
98
127
  const builtin = (builtins || []).find((m) => m && m.id === macroId);
@@ -101,6 +130,9 @@ async function dispatchMacroJob(
101
130
  if (!macro || !macro.job) return { ok: false, error: `macro ${macroId} has no background job declaration` };
102
131
  if (typeof epicId !== 'string' || !epicId.trim()) return { ok: false, error: 'epicId is required — a background build joins an existing Epic' };
103
132
  if (typeof cwd !== 'string' || !cwd) return { ok: false, error: 'cwd is required' };
133
+ if (voiceId != null && (typeof voiceId !== 'string' || !VOICE_ID_RE.test(voiceId))) {
134
+ return { ok: false, error: `voiceId must match /${VOICE_ID_RE.source}/ when given` };
135
+ }
104
136
  if (typeof createPrd !== 'function') return { ok: false, error: 'createPrd is not available' };
105
137
 
106
138
  let prompt = macro.prompt;
@@ -115,13 +147,16 @@ async function dispatchMacroJob(
115
147
  const extra = [stripReviewLines(typeof extraInstructions === 'string' ? extraInstructions : ''), rLine].filter(Boolean).join('\n');
116
148
  const entryKind = tool ? 'video' : macro.job.entryKind;
117
149
  const entryId = entryKind ? entryIdFor(entryKind, extra, t) : null;
118
- const stage = tool && tool.job.review ? (review && review.decision === 'approved' ? 'final' : 'review') : null;
150
+ const stage = stageFor(tool, builtin, review, reviewStage);
119
151
  const repoPaths = tool && Array.isArray(tool.job.repoPaths) && tool.job.repoPaths.length ? tool.job.repoPaths.slice() : null;
120
- const artifactPaths = tool
152
+ const artifactPaths = tool || stage === 'review'
121
153
  ? [(stage === 'review' ? REVIEW_MATERIAL_REL : VIDEO_INDEX_REL).split('{id}').join(entryId)]
122
154
  : macro.job.artifactPaths.map((p) => (entryId ? p.split('{id}').join(entryId) : p));
123
155
  const absPaths = artifactPaths.map((p) => path.join(cwd, p));
124
- for (const s of [cwd, ...absPaths]) {
156
+ // Built-in Demo Video only: a saved outcome is an alternative pass for every gate.
157
+ const outcomeRel = builtin && macroId === OUTCOME_MACRO_ID && entryId ? OUTCOME_REL.split('{id}').join(entryId) : null;
158
+ const outcomeAbs = outcomeRel ? path.join(cwd, outcomeRel) : null;
159
+ for (const s of [cwd, ...absPaths, ...(outcomeAbs ? [outcomeAbs] : [])]) {
125
160
  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)" };
126
161
  }
127
162
 
@@ -161,7 +196,7 @@ async function dispatchMacroJob(
161
196
  sourcePromptId: epicId,
162
197
  disposition: 'new-head',
163
198
  goal,
164
- gate: absPaths.map((p) => buildGate(p, t)),
199
+ gate: absPaths.map((p) => buildGate(outcomeAbs ? [p, outcomeAbs] : [p], t)),
165
200
  };
166
201
  if (repoPaths) {
167
202
  Object.assign(input, {
@@ -183,6 +218,7 @@ async function dispatchMacroJob(
183
218
  acceptanceCriteria: [
184
219
  `${artifactPaths[0]} is written during this run by ${saveTool}, never by hand.`,
185
220
  'Nothing in the repository is committed. No commit is the expected result: once the gate is green, end with SCHEDULER_VERDICT: PASS, never FAIL for the missing commit.',
221
+ ...(outcomeRel ? [`A saved outcome is a passing result with no video: when a kind playbook says to stop with an outcome, ${outcomeRel} written during this run by project_video_outcome_write passes the gate in place of ${artifactPaths[0]}; save no video or review material and end with SCHEDULER_VERDICT: PASS.`] : []),
186
222
  ],
187
223
  implementationNotes:
188
224
  `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. `
@@ -191,6 +227,14 @@ async function dispatchMacroJob(
191
227
  });
192
228
  }
193
229
  if (typeof effort === 'string' && PRD_EFFORT_LEVELS.includes(effort)) input.effort = effort;
230
+ // Press pick beats the tool default; only a project Video tool's job carries a voice.
231
+ const jobVoiceId = tool
232
+ ? (voiceId || (typeof tool.voiceId === 'string' && VOICE_ID_RE.test(tool.voiceId) ? tool.voiceId : null))
233
+ : null;
234
+ if (jobVoiceId) {
235
+ input.voiceId = jobVoiceId;
236
+ input.implementationNotes += ` Voice: ${jobVoiceId} (also in SM_VOICE_ID): speak every narration line with this library voice.`;
237
+ }
194
238
 
195
239
  let res;
196
240
  try {
@@ -13,9 +13,12 @@
13
13
  * checkProjectVideoToolRunnable? (default projectVideoToolCheck.cjs) }
14
14
  *
15
15
  * runToolJob is the one dispatch path: macros:dispatch-job calls it without a
16
- * review decision; the review-decision IPC calls it with one. After an ok
17
- * dispatch of a project Video tool it records the entry's review dispatch
18
- * (dispatch.json), so every tool entry links to its tool, run and inputs.
16
+ * review decision (but with the press's reviewStage opt-in); the
17
+ * review-decision IPC calls it with one. After an ok dispatch of a project
18
+ * Video tool — or of builtin-demo-video when the result has a stage ('review'
19
+ * or 'final') — it records the entry's review dispatch (dispatch.json), so the
20
+ * review card, Approve, Ask for changes and Retry can re-dispatch it. A plain
21
+ * Demo Video press (stage null) records nothing.
19
22
  * Before dispatching a library 'project-video' tool with a job it runs
20
23
  * checkProjectVideoToolRunnable; a refusal returns { ok: false, error } with
21
24
  * no PRD written and the job-not-queued notice. Built-ins are never checked.
@@ -36,6 +39,8 @@ const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
36
39
  const macroLibrary = require('./macroLibrary.cjs');
37
40
 
38
41
  const JOB_NOT_QUEUED_NOTICE = 'job-not-queued';
42
+ /** The one built-in whose review-stage runs are recorded for the review card. */
43
+ const DEMO_VIDEO_ID = 'builtin-demo-video';
39
44
 
40
45
  function noticeText(label, error) {
41
46
  return `${label} background build was not queued: ${error} — press it again in Project Home ▸ Tools to retry.`;
@@ -74,10 +79,10 @@ async function listLibraryMacros(deps) {
74
79
  }
75
80
 
76
81
  /**
77
- * runToolJob(deps, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review })
82
+ * runToolJob(deps, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review, reviewStage, voiceId })
78
83
  * `cwd` must already be validated. Returns dispatchMacroJob's result.
79
84
  */
80
- async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review } = {}) {
85
+ async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review, reviewStage, voiceId } = {}) {
81
86
  const dispatch = deps.dispatchMacroJob || realDispatch;
82
87
  const index = deps.readActiveIndex(cwd);
83
88
  const sessions = index && index.sessions ? index.sessions : {};
@@ -101,6 +106,8 @@ async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions,
101
106
  const args = { cwd, macroId, epicId, extraInstructions, effort };
102
107
  if (inputValues !== undefined) args.inputValues = inputValues;
103
108
  if (review !== undefined) args.review = review;
109
+ if (reviewStage !== undefined) args.reviewStage = reviewStage;
110
+ if (voiceId !== undefined) args.voiceId = voiceId;
104
111
  const dispatchDeps = {
105
112
  createPrd: deps.createPrd,
106
113
  listRows: async () => deps.loadJobs(),
@@ -119,7 +126,8 @@ async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions,
119
126
  if (result && result.ok === true && result.entryId) {
120
127
  const isBuiltin = !!findById(deps.builtins || BUILTIN_MACROS, macroId);
121
128
  const tool = isBuiltin ? null : findById(macros, macroId);
122
- if (tool && !tool.builtin && macroLibrary.isProjectVideoTool(tool, cwd)) {
129
+ const reviewedBuiltin = isBuiltin && macroId === DEMO_VIDEO_ID && (result.stage === 'review' || result.stage === 'final');
130
+ if (reviewedBuiltin || (tool && !tool.builtin && macroLibrary.isProjectVideoTool(tool, cwd))) {
123
131
  await recordToolDispatch(deps, cwd, result, { macroId, epicId, inputValues, extraInstructions });
124
132
  }
125
133
  }
@@ -170,6 +178,8 @@ function registerMacroJobIpc(ipcMain, deps = {}) {
170
178
  extraInstructions: payload.extraInstructions,
171
179
  inputValues: payload.inputValues,
172
180
  effort: payload.effort,
181
+ reviewStage: payload.reviewStage,
182
+ voiceId: payload.voiceId,
173
183
  });
174
184
  });
175
185
 
@@ -42,6 +42,12 @@
42
42
  * refuses `job` on every other surface and on built-ins; a read drops such a
43
43
  * stale key (a built-in's job is read live from BUILTIN_MACROS by withBuiltinJobs).
44
44
  *
45
+ * A non-built-in 'project-home' or 'project-video' macro may carry `voiceId`, the
46
+ * tool's default library voice (VOICE_ID_RE); a project-video job gets it as
47
+ * SM_VOICE_ID unless the press picks another (macroJobDispatch.cjs). saveMacro
48
+ * refuses it on a 'sessions' macro (VOICE_SURFACE_ONLY) and on a built-in
49
+ * (VOICE_NOT_ON_BUILTIN); a read drops such a stale key.
50
+ *
45
51
  * Plain Node, no Electron imports.
46
52
  */
47
53
 
@@ -74,6 +80,11 @@ const MacroSurfaceSchema = z.enum(['sessions', 'project-home', 'project-video'])
74
80
  const PROJECT_VIDEO_ONE_PROJECT = 'a Project Video tool belongs to exactly one project';
75
81
  const JOB_SURFACE_ONLY = 'job is allowed only on a Project Video tool';
76
82
  const JOB_NOT_ON_BUILTIN = 'a built-in macro job cannot be set';
83
+ const VOICE_SURFACE_ONLY = 'voiceId is allowed only on a Project Home or Project Video tool';
84
+ const VOICE_NOT_ON_BUILTIN = 'a built-in macro voiceId cannot be set';
85
+ const { VOICE_ID_RE } = require('../demo-video-kit/voiceLibrary.cjs');
86
+ const MacroVoiceIdSchema = z.string().regex(VOICE_ID_RE, 'invalid voiceId');
87
+ const VOICE_SURFACES = new Set(['project-home', 'project-video']);
77
88
 
78
89
  /** Repo-relative path a Project Video job may write: '/'-separated, inside the repo, outside ops/git state. */
79
90
  const JobRepoPathSchema = z.string().min(1).max(200).superRefine((v, ctx) => {
@@ -190,10 +201,17 @@ function renderMacroPrompt(prompt, inputs, values) {
190
201
  * refuses such a job outright; reads stay tolerant.
191
202
  */
192
203
  function stripForeignJob(entry) {
193
- if (!entry || typeof entry !== 'object' || Array.isArray(entry) || !('job' in entry)) return entry;
194
- if (entry.surface === 'project-video' && !entry.builtin) return entry;
195
- const { job: _stale, ...rest } = entry;
196
- return rest;
204
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
205
+ let out = entry;
206
+ if ('job' in out && !(out.surface === 'project-video' && !out.builtin)) {
207
+ const { job: _stale, ...rest } = out;
208
+ out = rest;
209
+ }
210
+ if ('voiceId' in out && !(VOICE_SURFACES.has(out.surface) && !out.builtin)) {
211
+ const { voiceId: _staleVoice, ...rest } = out;
212
+ out = rest;
213
+ }
214
+ return out;
197
215
  }
198
216
 
199
217
  const MacroObjectSchema = z.object({
@@ -215,11 +233,17 @@ const MacroObjectSchema = z.object({
215
233
  scriptStart: z.boolean().optional(),
216
234
  // Background job declaration; only on a non-built-in 'project-video' macro.
217
235
  job: MacroJobSchema.optional(),
236
+ // Default library voice; only on a non-built-in 'project-home' / 'project-video' macro.
237
+ voiceId: MacroVoiceIdSchema.optional(),
218
238
  }).superRefine((value, ctx) => {
219
239
  refineInputs(value, ctx);
220
240
  if (value.surface === 'project-video' && !isSingleProject(value.projects)) {
221
241
  ctx.addIssue({ code: 'custom', path: ['projects'], message: PROJECT_VIDEO_ONE_PROJECT });
222
242
  }
243
+ if (value.voiceId !== undefined) {
244
+ if (value.builtin) ctx.addIssue({ code: 'custom', path: ['voiceId'], message: VOICE_NOT_ON_BUILTIN });
245
+ else if (!VOICE_SURFACES.has(value.surface)) ctx.addIssue({ code: 'custom', path: ['voiceId'], message: VOICE_SURFACE_ONLY });
246
+ }
223
247
  });
224
248
  const MacroSchema = z.preprocess(stripForeignJob, MacroObjectSchema);
225
249
 
@@ -242,6 +266,8 @@ const MacroSaveSchema = z.object({
242
266
  scriptStart: z.boolean().optional(),
243
267
  // Omitted keeps the stored job on update; `null` removes it. Only on a 'project-video' macro.
244
268
  job: MacroJobSchema.nullable().optional(),
269
+ // Omitted keeps the stored voiceId on update; `null` removes it. Only on a 'project-home' / 'project-video' macro.
270
+ voiceId: MacroVoiceIdSchema.nullable().optional(),
245
271
  }).superRefine(refineInputs);
246
272
 
247
273
  const MacroDeleteSchema = z.object({ id: MacroIdSchema });
@@ -610,7 +636,7 @@ function isProjectVideoTool(macro, cwd) {
610
636
  }
611
637
 
612
638
  /** Throws unless the merged save's surface/projects/job combination is allowed. */
613
- function assertSurfaceRules(saved, parsedJob) {
639
+ function assertSurfaceRules(saved, parsedJob, parsedVoiceId) {
614
640
  if (saved.surface === 'project-video' && !isSingleProject(saved.projects)) {
615
641
  throw new Error(PROJECT_VIDEO_ONE_PROJECT);
616
642
  }
@@ -618,6 +644,17 @@ function assertSurfaceRules(saved, parsedJob) {
618
644
  if (saved.builtin) throw new Error(JOB_NOT_ON_BUILTIN);
619
645
  if (saved.surface !== 'project-video') throw new Error(JOB_SURFACE_ONLY);
620
646
  }
647
+ if (parsedVoiceId !== undefined && parsedVoiceId !== null) {
648
+ if (saved.builtin) throw new Error(VOICE_NOT_ON_BUILTIN);
649
+ if (!VOICE_SURFACES.has(saved.surface)) throw new Error(VOICE_SURFACE_ONLY);
650
+ }
651
+ }
652
+
653
+ /** Apply the save's `voiceId` (omitted = keep, null = remove) and drop any voiceId the surface cannot carry. */
654
+ function applyVoiceId(saved, parsedVoiceId) {
655
+ if (parsedVoiceId === null) delete saved.voiceId;
656
+ else if (parsedVoiceId !== undefined) saved.voiceId = parsedVoiceId;
657
+ if (!VOICE_SURFACES.has(saved.surface) || saved.builtin) delete saved.voiceId;
621
658
  }
622
659
 
623
660
  /** Apply the save's `job` (omitted = keep, null = remove) and drop any job the surface cannot carry. */
@@ -705,8 +742,9 @@ async function saveMacro(input, opts = {}) {
705
742
  }
706
743
  if (parsed.scriptStart === true) saved.scriptStart = true;
707
744
  else if (parsed.scriptStart === false) delete saved.scriptStart;
708
- assertSurfaceRules(saved, parsed.job);
745
+ assertSurfaceRules(saved, parsed.job, parsed.voiceId);
709
746
  applyJob(saved, parsed.job);
747
+ applyVoiceId(saved, parsed.voiceId);
710
748
  assertPlaceholdersDeclared(saved);
711
749
  macros[idx] = saved;
712
750
  } else {
@@ -730,8 +768,9 @@ async function saveMacro(input, opts = {}) {
730
768
  saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
731
769
  }
732
770
  if (parsed.scriptStart === true) saved.scriptStart = true;
733
- assertSurfaceRules(saved, parsed.job);
771
+ assertSurfaceRules(saved, parsed.job, parsed.voiceId);
734
772
  applyJob(saved, parsed.job);
773
+ applyVoiceId(saved, parsed.voiceId);
735
774
  assertPlaceholdersDeclared(saved);
736
775
  macros.push(saved);
737
776
  }
@@ -822,6 +861,9 @@ async function removeMacroFromProject(input, opts = {}) {
822
861
 
823
862
  module.exports = {
824
863
  ALL_PROJECTS,
864
+ VOICE_ID_RE,
865
+ VOICE_SURFACE_ONLY,
866
+ VOICE_NOT_ON_BUILTIN,
825
867
  MACRO_INPUT_MAX_LEN,
826
868
  MACRO_PLACEHOLDER_RE,
827
869
  MacroInputSchema,
@@ -0,0 +1,83 @@
1
+ // @ts-check
2
+ /**
3
+ * The one owning schema for a persona file's FRONTMATTER (the parsed
4
+ * `fm` object splitFrontmatter returns for ~/.claude/agents/*.md or a seed in
5
+ * src/seed/agents/). Managed Agents' "an agent definition is validated" rule,
6
+ * kept local: an invalid persona is refused instead of silently tolerated.
7
+ *
8
+ * - `.strict()` over exactly agentLibrary.cjs's MANAGED_PERSONA_KEYS
9
+ * (imported, never copied) — an unknown key fails, naming the key.
10
+ * - `mcpServers` / `packs` are string lists (or a comma string): the exact
11
+ * MCP servers and context packs a scheduler job running as this persona
12
+ * loads under --strict-mcp-config.
13
+ * - `environment` names a declared environment profile
14
+ * (lib/claude/environmentProfiles.cjs); absent = headless-default.
15
+ * - `model` is required and must be concrete (not `inherit`): every persona
16
+ * can be a PRD `agentType`, so every persona is headless-capable, and an
17
+ * unpinned headless run drifts to the CLI default model.
18
+ *
19
+ * Distinct from agentPersonaSchema.cjs, which validates the structured IPC
20
+ * save payload. Dispatch (agentModelResolve.cjs's resolvePrdPersonaForSpawn)
21
+ * refuses a persona that fails it.
22
+ */
23
+ 'use strict';
24
+
25
+ const { z } = require('zod');
26
+ const { MANAGED_PERSONA_KEYS } = require('../../agentLibrary.cjs');
27
+
28
+ // Parsed frontmatter values are strings; structured callers may pass
29
+ // numbers (seedVersion), booleans (executorOnly) or string lists (tools/tags).
30
+ const FmValue = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
31
+
32
+ const ModelSchema = z
33
+ .string({ error: 'model is required: pin a concrete model (e.g. opus, sonnet, haiku)' })
34
+ .trim()
35
+ .min(1, 'model is required: pin a concrete model (e.g. opus, sonnet, haiku)')
36
+ .refine((v) => v.toLowerCase() !== 'inherit', 'model must be a concrete model, not "inherit" (personas run headless)');
37
+
38
+ /** @type {Record<string, z.ZodType>} */
39
+ const shape = {};
40
+ for (const key of MANAGED_PERSONA_KEYS) shape[key] = FmValue.optional();
41
+ shape.model = ModelSchema;
42
+ // Declared capabilities (personaToolScope.cjs): a string list, or the parsed
43
+ // frontmatter's comma string ("a, b") of non-empty names — never a number or
44
+ // boolean. Every listed name must resolve at dispatch or the job parks.
45
+ const CapabilityList = z.union([
46
+ z.array(z.string().trim().min(1, 'entries must be non-empty names')),
47
+ z.string().trim().min(1, 'must list at least one name (or omit the key)'),
48
+ ]);
49
+ shape.mcpServers = CapabilityList.optional();
50
+ shape.packs = CapabilityList.optional();
51
+ // The declared environment profile (lib/claude/environmentProfiles.cjs) a
52
+ // headless run as this persona uses; absent = headless-default. Same name rule
53
+ // as an environment file name. Existence is checked at load, not here.
54
+ shape.environment = z
55
+ .string()
56
+ .trim()
57
+ .regex(/^[a-z0-9][a-z0-9-]*$/, 'environment must be a lowercase, hyphenated profile name (e.g. headless-default)')
58
+ .optional();
59
+ // Not a MANAGED_PERSONA_KEYS entry (the save path preserves it as an
60
+ // unmanaged line), but prdAgentType.cjs's readPersonaDefaultEstimateMinutes
61
+ // reads it at dispatch, so a dispatch-time validation must admit it.
62
+ shape.defaultEstimateMinutes = FmValue.optional();
63
+
64
+ const PersonaFrontmatterSchema = z.object(shape).strict();
65
+
66
+ /**
67
+ * @param {unknown} fm
68
+ * @returns {{ ok: true } | { ok: false, errors: string[] }}
69
+ */
70
+ function validatePersonaFrontmatter(fm) {
71
+ const r = PersonaFrontmatterSchema.safeParse(fm);
72
+ if (r.success) return { ok: true };
73
+ const errors = r.error.issues.map((issue) => {
74
+ if (issue.code === 'unrecognized_keys') {
75
+ return `unknown frontmatter key(s): ${issue.keys.join(', ')}`;
76
+ }
77
+ const where = issue.path.length ? issue.path.join('.') : '(frontmatter)';
78
+ return `${where}: ${issue.message}`;
79
+ });
80
+ return { ok: false, errors };
81
+ }
82
+
83
+ module.exports = { PersonaFrontmatterSchema, validatePersonaFrontmatter };
@@ -68,6 +68,9 @@ async function checkProjectVideoToolRunnable({ cwd, agentName, job } = /** @type
68
68
  const msg = err && /** @type {Error} */ (err).message ? /** @type {Error} */ (err).message : String(err);
69
69
  return { ok: false, error: `${PERSONA_PREFIX} ${msg}` };
70
70
  }
71
+ if (persona && persona.refusal) {
72
+ return { ok: false, error: `${PERSONA_PREFIX} ${persona.refusal.code}: ${persona.refusal.detail}` };
73
+ }
71
74
  if (!persona || !persona.personaPath) {
72
75
  return { ok: false, error: `${PERSONA_PREFIX} persona '${agentName}' could not be read.` };
73
76
  }