claude-code-session-manager 0.141.0 → 0.143.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 (223) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +76 -153
  3. package/bin/cli.cjs +11 -0
  4. package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
  5. package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
  6. package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
  7. package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
  8. package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
  9. package/dist/assets/Scheduler-CNLjn90m.js +16 -0
  10. package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
  11. package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
  12. package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
  13. package/dist/assets/Toggle-CYajnSdx.js +1 -0
  14. package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
  15. package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
  16. package/dist/assets/index-CdTppjKR.js +3133 -0
  17. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  18. package/dist/index.html +2 -2
  19. package/dist-web/app.css +1 -1
  20. package/dist-web/app.js +496 -484
  21. package/package.json +6 -4
  22. package/plugins/AGENTS.md +4 -3
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  25. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  26. package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
  27. package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
  28. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  29. package/scripts/README.md +2 -0
  30. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  31. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  32. package/scripts/scheduler-mcp-server.cjs +1032 -112
  33. package/src/main/adminRouteRegistry.cjs +69 -0
  34. package/src/main/agentLibrary.cjs +72 -4
  35. package/src/main/agentsIpc.cjs +3 -2
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/chatRunner.cjs +336 -23
  38. package/src/main/config.cjs +35 -1
  39. package/src/main/docEdit.cjs +4 -2
  40. package/src/main/health.cjs +129 -2
  41. package/src/main/index.cjs +110 -52
  42. package/src/main/ipcSchemas.cjs +172 -8
  43. package/src/main/lib/AGENTS.md +1 -1
  44. package/src/main/lib/chatBootRecovery.cjs +2 -0
  45. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  46. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  47. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  48. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  49. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  50. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  51. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  52. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  53. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  54. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  55. package/src/main/lib/demo-video-kit/cast.md +52 -0
  56. package/src/main/lib/demo-video-kit/character.cjs +778 -30
  57. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  58. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  59. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  60. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  61. package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
  62. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  63. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  64. package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
  65. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  66. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  67. package/src/main/lib/demo-video-kit/sound.cjs +166 -9
  68. package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
  69. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  70. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  71. package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
  72. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  73. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  74. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  75. package/src/main/lib/epic/artifactRetention.cjs +356 -0
  76. package/src/main/lib/epic/artifactStore.cjs +435 -0
  77. package/src/main/lib/epic/delegationReadiness.cjs +83 -2
  78. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  79. package/src/main/lib/epic/epicEventLog.cjs +258 -0
  80. package/src/main/lib/epic/epicMint.cjs +43 -1
  81. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  82. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  83. package/src/main/lib/epic/epicPurge.cjs +347 -0
  84. package/src/main/lib/epic/epicReopen.cjs +5 -2
  85. package/src/main/lib/epic/epicSettle.cjs +4 -13
  86. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  87. package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
  88. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  89. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  90. package/src/main/lib/epic/epicValidationHook.cjs +94 -4
  91. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  92. package/src/main/lib/externalContract.cjs +48 -4
  93. package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
  94. package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
  95. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  96. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  97. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  98. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  99. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  100. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  101. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  102. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  103. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  104. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  105. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  106. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
  107. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  108. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  109. package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
  110. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
  111. package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
  112. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  113. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  114. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  115. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  116. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  117. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  118. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  119. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  120. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  121. package/src/main/lib/git/gitWorktree.cjs +8 -0
  122. package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
  123. package/src/main/lib/git/worktreeDeps.cjs +182 -4
  124. package/src/main/lib/mcpToolCatalog.cjs +399 -29
  125. package/src/main/lib/opsOwnership.cjs +141 -28
  126. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  127. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  128. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  129. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  130. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  131. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  132. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  133. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
  134. package/src/main/lib/phaseProjection.cjs +103 -0
  135. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  136. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  137. package/src/main/lib/prd/prdCreate.cjs +387 -228
  138. package/src/main/lib/prd/prdCriteria.cjs +228 -0
  139. package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
  140. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  141. package/src/main/lib/prd/prdSizing.cjs +3 -1
  142. package/src/main/lib/process/cleanEnv.cjs +52 -1
  143. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  144. package/src/main/lib/process/memoryScope.cjs +31 -3
  145. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  146. package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
  147. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  148. package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
  149. package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
  150. package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
  151. package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
  152. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  153. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  154. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  155. package/src/main/lib/promptSessionSchema.cjs +6 -0
  156. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  157. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  158. package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
  159. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  160. package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
  161. package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
  162. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  163. package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
  164. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
  165. package/src/main/lib/scheduler/queueStore.cjs +16 -0
  166. package/src/main/lib/scheduler/rcaReport.cjs +79 -15
  167. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  168. package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
  169. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  170. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  171. package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
  172. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  173. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  174. package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
  175. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  176. package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
  177. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
  178. package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
  179. package/src/main/lib/tasks/mitigationReview.cjs +314 -0
  180. package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
  181. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  182. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  183. package/src/main/lib/tasks/taskRun.cjs +186 -17
  184. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  185. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  186. package/src/main/lib/telemetry/auditEvents.cjs +204 -6
  187. package/src/main/lib/telemetry/auditLog.cjs +6 -2
  188. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  189. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  190. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  191. package/src/main/lib/toolUseClassify.cjs +181 -0
  192. package/src/main/lib/util/atomicFs.cjs +2 -2
  193. package/src/main/lib/util/smfileRange.cjs +77 -0
  194. package/src/main/projectPages.cjs +3 -1
  195. package/src/main/promptSessionEvents.cjs +21 -1
  196. package/src/main/pty.cjs +77 -0
  197. package/src/main/queueOps.cjs +33 -14
  198. package/src/main/runVerify.cjs +74 -9
  199. package/src/main/scheduler/AGENTS.md +1 -0
  200. package/src/main/scheduler/budget.cjs +6 -5
  201. package/src/main/scheduler/prdParser.cjs +46 -13
  202. package/src/main/scheduler/reviewLadder.cjs +9 -25
  203. package/src/main/scheduler/utilizationHold.cjs +191 -0
  204. package/src/main/scheduler.cjs +1932 -213
  205. package/src/main/templates/PRD_AUTHORING.md +11 -3
  206. package/src/main/webRemote.cjs +463 -6
  207. package/src/preload/api.d.ts +576 -39
  208. package/src/preload/apiSurface.json +223 -7
  209. package/src/preload/index.cjs +48 -1
  210. package/src/seed/agents/architect.md +6 -1
  211. package/src/seed/agents/blender-artist.md +2 -1
  212. package/src/seed/agents/competitive-analyst.md +3 -1
  213. package/src/seed/agents/competitive-researcher.md +2 -1
  214. package/src/seed/agents/demo-video-builder.md +98 -87
  215. package/src/seed/agents/dev-lead.md +3 -3
  216. package/src/seed/agents/project-home-builder.md +9 -31
  217. package/src/seed/agents/validator.md +23 -23
  218. package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
  219. package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
  220. package/dist/assets/Scheduler-cyr61UAC.js +0 -16
  221. package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
  222. package/dist/assets/index-B2TQz3nd.js +0 -3121
  223. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -2,6 +2,7 @@
2
2
  * projectHomeAdminRoutes.cjs — admin routes behind Project Home's library:
3
3
  * POST /admin/project-home/pages/write -> project-pages/knowledge/<pageId>/{index.html,meta.json}
4
4
  * POST /admin/project-home/videos/write -> project-pages/videos/<videoId>/{index.html,meta.json}
5
+ * (+ video.mp4 and poster.png, required for kind 'tiktok' / 'marketing')
5
6
  * POST /admin/project-home/write alias: {cwd, html} -> knowledge/overview/
6
7
  * POST /admin/project-home/demo-video/write alias: {cwd, html} -> a new videos/vid-<id>/ project-demo entry
7
8
  * POST /admin/project-home/matrix/read {cwd} -> project-pages/matrix/matrix.json (+ its JSON Schema)
@@ -9,6 +10,8 @@
9
10
  * POST /admin/project-home/videos/review/write {cwd, videoId, text, images:[{base64}]} -> videoReview.writeMaterial
10
11
  * (review material only; there is deliberately no route that decides, approves or retries —
11
12
  * only the human buttons in the app record a decision)
13
+ * POST /admin/project-home/videos/outcome/write {cwd, videoId, outcome, text} -> videos/<videoId>/outcome.json
14
+ * (a run that ends without a video by design, e.g. a finished TikTok series: outcome 'season-complete')
12
15
  * all owned by writer 'project-home' (see opsOwnership.cjs). Registered
13
16
  * against the same injected localAdminHttp.cjs transport as
14
17
  * prdAdminRoutes.cjs.
@@ -31,11 +34,13 @@ const path = require('node:path');
31
34
  const crypto = require('node:crypto');
32
35
  const { readBody, sendJson } = require('./localAdminHttp.cjs');
33
36
  const { resolveProjectContext } = require('../projectRootResolve.cjs');
34
- const { opsPath, OPS_ROOT_DIR } = require('../opsOwnership.cjs');
37
+ const { opsPath, OPS_ROOT_DIR, assertOpsWrite } = require('../opsOwnership.cjs');
35
38
  const config = require('../../config.cjs');
36
39
  const { schemas, ENTRY_ID_RE } = require('../../ipcSchemas.cjs');
37
- const { validateCharacterJson, validateCharacterJs, readCharacter, characterDir, MAX_JS_BYTES: MAX_CHARACTER_JS_BYTES } = require('../demo-video-kit/character.cjs');
38
- const { checkHtmlLimits } = require('../demo-video-kit/checks.cjs');
40
+ const { validateCharacterJson, validateCharacterJs, voiceIdRefsOf, inspectCharacter, characterDir, MAX_JSON_BYTES: MAX_CHARACTER_JSON_BYTES, MAX_JS_BYTES: MAX_CHARACTER_JS_BYTES } = require('../demo-video-kit/character.cjs');
41
+ const voiceLibrary = require('../demo-video-kit/voiceLibrary.cjs');
42
+ const projectSounds = require('../demo-video-kit/projectSounds.cjs');
43
+ const { checkHtmlLimits, checkPostCaption, TIKTOK_CHECK_IDS } = require('../demo-video-kit/checks.cjs');
39
44
  const { injectPlayerBridge } = require('../project-pages/playerBridge.cjs');
40
45
  const { readMatrix, matrixJsonSchema, MAX_MATRIX_BYTES } = require('../project-pages/competitiveMatrix.cjs');
41
46
  const { writeMatrix } = require('../project-pages/matrixStore.cjs');
@@ -43,10 +48,24 @@ const videoReview = require('../project-pages/videoReview.cjs');
43
48
 
44
49
  const MAX_HTML_BYTES = 1024 * 1024;
45
50
  const MAX_DEMO_VIDEO_BYTES = 2 * 1024 * 1024;
51
+ /** Exported MP4 cap: 24 MiB per started 30 s of lengthS. */
52
+ const MAX_EXPORT_MP4_BYTES_PER_30S = 24 * 1024 * 1024;
53
+ const MAX_EXPORT_POSTER_BYTES = 4 * 1024 * 1024;
54
+ /** Kinds whose save must carry an MP4 + poster export, and the aspect each requires. */
55
+ const EXPORT_KIND_ASPECT = Object.freeze({ tiktok: '9:16', marketing: '16:9' });
56
+ const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
57
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
46
58
  /** Review write body cap: 6 base64 images of 2 MiB (16 MiB) + a 32000-char text and JSON overhead. */
47
59
  const REVIEW_WRITE_BODY_MAX = 18 * 1024 * 1024;
48
60
  const REVIEW_DECISION_KEYS = Object.freeze(['decision', 'status', 'approved', 'approvedAt']);
49
61
  const REVIEW_DECISION_REFUSAL = 'review decisions are made only by a human in the app';
62
+ /** Outcomes a run may record instead of a video, the outcome text cap, and the only body keys accepted. */
63
+ const VIDEO_OUTCOMES = ['season-complete'];
64
+ const OUTCOME_TEXT_MAX = 300;
65
+ const OUTCOME_BODY_KEYS = ['cwd', 'videoId', 'outcome', 'text'];
66
+ const OUTCOME_WRITE_BODY_MAX = 64 * 1024;
67
+ /** Character write body cap: js + json, every project sound WAV as base64, and 128 KiB of overhead. */
68
+ const CHARACTER_WRITE_BODY_MAX = MAX_CHARACTER_JS_BYTES * 2 + base64LengthFor(projectSounds.MAX_SOUNDS_TOTAL_BYTES) + 128 * 1024;
50
69
 
51
70
  // Each detector is a linear regex scan; the input is capped first.
52
71
  const REMOTE_REFERENCE_CHECKS = [
@@ -201,13 +220,14 @@ function resolveCwd(rawCwd) {
201
220
  * meta}. The entry folder gets index.html then meta.json, both atomically as
202
221
  * writer 'project-home'. Responds {ok, path (index.html), bytes}.
203
222
  */
204
- function makeWriteHandler({ schema, bodyLimit, build }) {
223
+ function makeWriteHandler({ schema, bodyLimit, extraBodyBytes = 0, build }) {
205
224
  return async (req, res) => {
206
225
  // Headroom over the html limit for JSON escaping; the html byte limit
207
- // itself is enforced by `build`.
226
+ // itself is enforced by `build`. `extraBodyBytes` makes room for base64
227
+ // binary exports, whose decoded caps `build` enforces too.
208
228
  let raw;
209
229
  try {
210
- raw = await readBody(req, bodyLimit * 2 + 4096);
230
+ raw = await readBody(req, bodyLimit * 2 + extraBodyBytes + 4096);
211
231
  } catch (e) {
212
232
  sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (html limit is ${bodyLimit} bytes)` });
213
233
  return;
@@ -242,6 +262,10 @@ function makeWriteHandler({ schema, bodyLimit, build }) {
242
262
  try {
243
263
  const dir = opsPath(resolved.cwd, 'project-pages', ...built.dirParts);
244
264
  await fs.promises.mkdir(dir, { recursive: true });
265
+ // Binary exports first, then index.html, then meta.json last: meta.json marks a complete entry.
266
+ for (const file of built.files ?? []) {
267
+ await config.writeBinaryAtomic(path.join(dir, file.name), file.buffer, { writer: 'project-home' });
268
+ }
245
269
  const abs = path.join(dir, 'index.html');
246
270
  await config.writeTextAtomic(abs, built.html, { writer: 'project-home' });
247
271
  await config.writeTextAtomic(path.join(dir, 'meta.json'), JSON.stringify(built.meta, null, 2) + '\n', { writer: 'project-home' });
@@ -257,6 +281,63 @@ function maxVideoBytes(lengthS) {
257
281
  return Math.ceil(lengthS / 30) * MAX_DEMO_VIDEO_BYTES;
258
282
  }
259
283
 
284
+ /** Exported MP4 cap for a video of `lengthS` seconds: 24 MiB per started 30 s. */
285
+ function maxExportMp4Bytes(lengthS) {
286
+ return Math.ceil(lengthS / 30) * MAX_EXPORT_MP4_BYTES_PER_30S;
287
+ }
288
+
289
+ /** Base64 length that decodes to at most `bytes` bytes. */
290
+ function base64LengthFor(bytes) {
291
+ return Math.ceil(bytes / 3) * 4;
292
+ }
293
+
294
+ /** Decodes one base64 export under `maxBytes`; -> {buffer} | {error}. Errors never echo the payload. */
295
+ function decodeExport(b64, label, maxBytes) {
296
+ if (b64.length > base64LengthFor(maxBytes)) return { error: `exports.${label} exceeds the ${maxBytes}-byte limit` };
297
+ if (b64.length % 4 !== 0 || !BASE64_RE.test(b64)) return { error: `exports.${label} is not valid base64` };
298
+ const buffer = Buffer.from(b64, 'base64');
299
+ if (buffer.length > maxBytes) return { error: `exports.${label} exceeds the ${maxBytes}-byte limit` };
300
+ return { buffer };
301
+ }
302
+
303
+ /**
304
+ * Rules for kinds that must ship an MP4 + poster ('tiktok', 'marketing'):
305
+ * both exports present, magic bytes, size caps, the kind's aspect, and for
306
+ * 'tiktok' the post caption and every TikTok check passing.
307
+ * -> {files: [{name, buffer}]} | {error}.
308
+ */
309
+ function validateExportKind(input, aspect) {
310
+ const { kind, lengthS } = input;
311
+ const exp = input.exports;
312
+ if (!exp || !exp.mp4Base64 || !exp.posterBase64) {
313
+ return { error: `kind '${kind}' requires exports.mp4Base64 and exports.posterBase64 (the MP4 and poster)` };
314
+ }
315
+ const mp4 = decodeExport(exp.mp4Base64, 'mp4Base64', maxExportMp4Bytes(lengthS));
316
+ if (mp4.error) return { error: `${mp4.error} (24 MiB per started 30 s of lengthS ${lengthS})` };
317
+ if (mp4.buffer.length < 8 || mp4.buffer.toString('latin1', 4, 8) !== 'ftyp') {
318
+ return { error: "exports.mp4Base64 is not an MP4 (no 'ftyp' at bytes 4-7)" };
319
+ }
320
+ const poster = decodeExport(exp.posterBase64, 'posterBase64', MAX_EXPORT_POSTER_BYTES);
321
+ if (poster.error) return { error: poster.error };
322
+ if (poster.buffer.length < PNG_SIGNATURE.length || !poster.buffer.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) {
323
+ return { error: 'exports.posterBase64 is not a PNG (missing the PNG signature)' };
324
+ }
325
+ const wantAspect = EXPORT_KIND_ASPECT[kind];
326
+ if (aspect !== wantAspect) {
327
+ return { error: `kind '${kind}' requires aspect '${wantAspect}' (the document declares '${aspect}' via sm-demo-aspect)` };
328
+ }
329
+ if (kind === 'tiktok') {
330
+ const post = input.meta?.post;
331
+ if (!post) return { error: "kind 'tiktok' requires meta.post {caption, audience}" };
332
+ const caption = checkPostCaption(post.caption);
333
+ if (!caption.ok) return { error: `kind 'tiktok' post caption check failed: ${caption.detail}` };
334
+ const checks = input.meta?.report?.checks ?? [];
335
+ const missing = TIKTOK_CHECK_IDS.filter((id) => !checks.some((c) => c.id === id && c.ok === true));
336
+ if (missing.length) return { error: `kind 'tiktok' requires every TikTok check in meta.report.checks with ok true; missing or failed: ${missing.join(', ')}` };
337
+ }
338
+ return { files: [{ name: 'video.mp4', buffer: mp4.buffer }, { name: 'poster.png', buffer: poster.buffer }] };
339
+ }
340
+
260
341
  // Owned by the Competitor matrix store (project-pages/matrixStore.cjs writes
261
342
  // knowledge/<id>/ directly). Kept local on purpose; macroJobDispatch.cjs holds
262
343
  // the same constant so the builder never derives this id.
@@ -323,13 +404,19 @@ function registerAdminRoute(adminHttp) {
323
404
  adminHttp.registerRoute('POST', '/admin/project-home/videos/write', makeWriteHandler({
324
405
  schema: schemas.projectVideoAdminWriteBody,
325
406
  bodyLimit: maxVideoBytes(MAX_DEMO_DURATION_S),
407
+ extraBodyBytes: base64LengthFor(maxExportMp4Bytes(MAX_DEMO_DURATION_S)) + base64LengthFor(MAX_EXPORT_POSTER_BYTES),
326
408
  build: (i) => {
327
409
  // Cheap kit checks re-run server-side; the alias route is exempt (Burrow sends no report).
328
410
  const failed = (i.meta?.report?.checks ?? []).find((c) => c.ok === false);
329
411
  if (failed) return { error: `report.checks failed: ${failed.id}${failed.detail ? ` (${failed.detail})` : ''}` };
330
412
  const limits = checkHtmlLimits({ html: i.html, lengthS: i.lengthS });
331
413
  if (!limits.ok) return { error: `${limits.id} check failed: ${limits.detail}` };
332
- return buildVideo(i, i);
414
+ const built = buildVideo(i, i);
415
+ // Other kinds ignore any exports, exactly as before.
416
+ if (built.error || !Object.hasOwn(EXPORT_KIND_ASPECT, i.kind)) return built;
417
+ const exported = validateExportKind(i, built.meta.aspect ?? '16:9');
418
+ if (exported.error) return { error: exported.error };
419
+ return { ...built, files: exported.files };
333
420
  },
334
421
  }));
335
422
 
@@ -370,7 +457,12 @@ function registerAdminRoute(adminHttp) {
370
457
  // POST /admin/project-home/videos/review/write {cwd, videoId, text, images:[{base64}]} -> review/material.json
371
458
  adminHttp.registerRoute('POST', '/admin/project-home/videos/review/write', reviewWriteHandler);
372
459
 
373
- // POST /admin/project-home/character/write {cwd, json, js, replace?} -> videos/_character/
460
+ // POST /admin/project-home/videos/outcome/write {cwd, videoId, outcome, text} -> videos/<videoId>/outcome.json
461
+ adminHttp.registerRoute('POST', '/admin/project-home/videos/outcome/write', outcomeWriteHandler);
462
+
463
+ // POST /admin/project-home/character/write {cwd, json, js, replace?, sounds?} -> videos/_character/
464
+ // (sounds = { <name>: <base64 WAV> } for every file-backed sound, written to sounds/<name>.wav;
465
+ // answers {ok, path, bytes, sounds: <names written>})
374
466
  adminHttp.registerRoute('POST', '/admin/project-home/character/write', characterWriteHandler);
375
467
 
376
468
  // POST /admin/project-home/matrix/read {cwd?} -> {ok, matrix|null, error, path, schema}
@@ -489,10 +581,143 @@ async function reviewWriteHandler(req, res) {
489
581
  }
490
582
  }
491
583
 
584
+ /** Returns a refusal reason for an outcome body, or null when it is valid. */
585
+ function validateOutcomeBody(body) {
586
+ const unknown = Object.keys(body).filter((k) => !OUTCOME_BODY_KEYS.includes(k));
587
+ if (unknown.length) return `unknown body keys: ${unknown.join(', ')} (allowed: ${OUTCOME_BODY_KEYS.join(', ')})`;
588
+ if (typeof body.videoId !== 'string' || !ENTRY_ID_RE.test(body.videoId)) return 'invalid videoId';
589
+ if (!VIDEO_OUTCOMES.includes(body.outcome)) return `outcome must be one of: ${VIDEO_OUTCOMES.join(', ')}`;
590
+ const { text } = body;
591
+ if (typeof text !== 'string' || !text.trim()) return 'text must be a non-empty string';
592
+ if (/[\r\n]/.test(text)) return 'text must be one line';
593
+ if (text.length > OUTCOME_TEXT_MAX) return `text must be at most ${OUTCOME_TEXT_MAX} characters`;
594
+ return null;
595
+ }
596
+
597
+ /**
598
+ * Records that a video entry ended without a video by design (a finished
599
+ * TikTok series): writes videos/<videoId>/outcome.json = {id, outcome, text, at}.
600
+ * Refused when the entry already has its video (index.html).
601
+ */
602
+ async function outcomeWriteHandler(req, res) {
603
+ let raw;
604
+ try {
605
+ raw = await readBody(req, OUTCOME_WRITE_BODY_MAX);
606
+ } catch (e) {
607
+ sendJson(res, 413, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (limit is ${OUTCOME_WRITE_BODY_MAX} bytes)` });
608
+ return;
609
+ }
610
+ let body;
611
+ try {
612
+ body = raw ? JSON.parse(raw) : {};
613
+ } catch {
614
+ sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
615
+ return;
616
+ }
617
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
618
+ sendJson(res, 400, { ok: false, error: 'invalid payload' });
619
+ return;
620
+ }
621
+ const invalid = validateOutcomeBody(body);
622
+ if (invalid) {
623
+ sendJson(res, 400, { ok: false, error: invalid });
624
+ return;
625
+ }
626
+ const resolved = resolveCwd(body.cwd);
627
+ if (!resolved.ok) {
628
+ sendJson(res, resolved.status, { ok: false, error: resolved.error });
629
+ return;
630
+ }
631
+ const { videoId, outcome, text } = body;
632
+ const dir = opsPath(resolved.cwd, 'project-pages', 'videos', videoId);
633
+ if (fs.existsSync(path.join(dir, 'index.html'))) {
634
+ sendJson(res, 400, { ok: false, error: `entry ${videoId} already has a video (index.html) — an outcome is only for a run that ends without one` });
635
+ return;
636
+ }
637
+ config.addAllowedRoot(resolved.cwd);
638
+ try {
639
+ await fs.promises.mkdir(dir, { recursive: true });
640
+ const abs = opsPath(resolved.cwd, 'project-pages', 'videos', videoId, 'outcome.json');
641
+ const record = { id: videoId, outcome, text, at: new Date().toISOString() };
642
+ await config.writeTextAtomic(abs, JSON.stringify(record, null, 2) + '\n', { writer: 'project-home' });
643
+ sendJson(res, 200, { ok: true, entryId: videoId, path: abs });
644
+ } catch (e) {
645
+ sendJson(res, 500, { ok: false, error: e?.message ?? 'outcome write failed' });
646
+ }
647
+ }
648
+
649
+ /**
650
+ * Checks a character write's `sounds` payload ({ <name>: <base64 WAV> }) against the
651
+ * file-backed sounds `jsonObj` declares: exactly one entry per name, valid base64, each
652
+ * WAV within its kind's cap and readable, and the total within MAX_SOUNDS_TOTAL_BYTES.
653
+ * -> {files: [{name, buffer}]} | {error}. Errors never echo the payload.
654
+ */
655
+ function checkSoundPayload(jsonObj, sounds) {
656
+ const payload = sounds === undefined || sounds === null ? {} : sounds;
657
+ if (typeof payload !== 'object' || Array.isArray(payload)) {
658
+ return { error: 'sounds payload must be an object of { name: base64 WAV }' };
659
+ }
660
+ const names = projectSounds.fileBackedSoundNames(jsonObj);
661
+ for (const name of names) {
662
+ if (!Object.prototype.hasOwnProperty.call(payload, name)) {
663
+ return { error: `sound '${name}' has no WAV: send it as sounds.${name} (project_character_write soundPaths.${name})` };
664
+ }
665
+ }
666
+ for (const key of Object.keys(payload)) {
667
+ if (!names.includes(key)) return { error: `sound '${key}' was sent but character.json declares no file-backed sound by that name` };
668
+ }
669
+ const files = [];
670
+ let total = 0;
671
+ for (const name of names) {
672
+ const b64 = payload[name];
673
+ if (typeof b64 !== 'string' || b64.length % 4 !== 0 || !BASE64_RE.test(b64)) {
674
+ return { error: `sound '${name}' is not valid base64` };
675
+ }
676
+ const kind = projectSounds.findProjectSound(jsonObj, name).kind;
677
+ const cap = kind === 'sfx' ? projectSounds.MAX_SFX_WAV_BYTES : projectSounds.MAX_BED_WAV_BYTES;
678
+ const label = `sound '${name}'`;
679
+ if (b64.length > base64LengthFor(cap)) {
680
+ return { error: `${label} is over the ${cap}-byte limit for a ${kind === 'sfx' ? 'sound effect' : 'music bed'}` };
681
+ }
682
+ const buffer = Buffer.from(b64, 'base64');
683
+ const wavErr = projectSounds.checkSoundWav(buffer, label, kind);
684
+ if (wavErr) return { error: wavErr };
685
+ total += buffer.length;
686
+ files.push({ name, buffer });
687
+ }
688
+ if (total > projectSounds.MAX_SOUNDS_TOTAL_BYTES) {
689
+ return { error: `sounds total ${total} bytes exceed the ${projectSounds.MAX_SOUNDS_TOTAL_BYTES}-byte limit` };
690
+ }
691
+ return { files };
692
+ }
693
+
694
+ /** Removes every entry of soundsDir(cwd) that is not a declared <name>.wav; removes the folder when nothing is declared. */
695
+ async function pruneSounds(cwd, names) {
696
+ const dir = projectSounds.soundsDir(cwd);
697
+ let entries;
698
+ try {
699
+ entries = await fs.promises.readdir(dir);
700
+ } catch (e) {
701
+ if (e && e.code === 'ENOENT') return;
702
+ throw e;
703
+ }
704
+ const keep = new Set(names.map((n) => `${n}.wav`));
705
+ for (const entry of entries) {
706
+ if (keep.has(entry)) continue;
707
+ const abs = path.join(dir, entry);
708
+ assertOpsWrite(abs, 'project-home');
709
+ await fs.promises.rm(abs, { recursive: true, force: true });
710
+ }
711
+ if (names.length === 0) {
712
+ assertOpsWrite(dir, 'project-home');
713
+ await fs.promises.rmdir(dir);
714
+ }
715
+ }
716
+
492
717
  async function characterWriteHandler(req, res) {
493
718
  let raw;
494
719
  try {
495
- raw = await readBody(req, MAX_CHARACTER_JS_BYTES * 2 + 64 * 1024);
720
+ raw = await readBody(req, CHARACTER_WRITE_BODY_MAX);
496
721
  } catch (e) {
497
722
  sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
498
723
  return;
@@ -520,23 +745,62 @@ async function characterWriteHandler(req, res) {
520
745
  sendJson(res, 400, { ok: false, error: `character.json invalid: ${jsonErr}` });
521
746
  return;
522
747
  }
748
+ // A {voiceId} voice must name a library voice this project can use (unknown or
749
+ // tampered-approved ids are refused by voiceLibrary's own reason) before anything is written.
750
+ for (const ref of voiceIdRefsOf(jsonObj)) {
751
+ const r = voiceLibrary.resolveVoiceId(resolved.cwd, ref.voiceId);
752
+ if (!r.ok) {
753
+ sendJson(res, 400, { ok: false, error: r.error });
754
+ return;
755
+ }
756
+ }
757
+ const jsonText = JSON.stringify(jsonObj, null, 2) + '\n';
758
+ const jsonBytes = Buffer.byteLength(jsonText, 'utf8');
759
+ if (jsonBytes > MAX_CHARACTER_JSON_BYTES) {
760
+ sendJson(res, 400, { ok: false, error: `character.json exceeds the ${MAX_CHARACTER_JSON_BYTES}-byte limit (${jsonBytes} bytes as saved)` });
761
+ return;
762
+ }
763
+ const soundPayload = checkSoundPayload(jsonObj, body.sounds);
764
+ if (soundPayload.error) {
765
+ sendJson(res, 400, { ok: false, error: `character.json invalid: ${soundPayload.error}` });
766
+ return;
767
+ }
523
768
  const jsErr = validateCharacterJs(body.js, [...REMOTE_REFERENCE_CHECKS, ...NETWORK_CHECKS]);
524
769
  if (jsErr) {
525
770
  sendJson(res, 400, { ok: false, error: jsErr });
526
771
  return;
527
772
  }
528
- if (!body.replace && readCharacter(resolved.cwd)) {
529
- sendJson(res, 409, { ok: false, error: 'a character already exists — pass replace: true to overwrite it' });
530
- return;
773
+ if (!body.replace) {
774
+ const existing = inspectCharacter(resolved.cwd);
775
+ if (existing.ok) {
776
+ sendJson(res, 409, { ok: false, error: 'a character already exists — pass replace: true to overwrite it' });
777
+ return;
778
+ }
779
+ if (existing.exists) {
780
+ sendJson(res, 409, { ok: false, error: `a character already exists but cannot be used (${existing.error}) — fix it, or pass replace: true to overwrite it` });
781
+ return;
782
+ }
531
783
  }
532
784
  config.addAllowedRoot(resolved.cwd);
533
785
  try {
534
786
  const dir = characterDir(resolved.cwd);
535
787
  await fs.promises.mkdir(dir, { recursive: true });
788
+ for (const f of soundPayload.files) {
789
+ await config.writeBinaryAtomic(projectSounds.soundFile(resolved.cwd, f.name), f.buffer, { writer: 'project-home' });
790
+ }
536
791
  const jsPath = path.join(dir, 'character.js');
537
792
  await config.writeTextAtomic(jsPath, body.js, { writer: 'project-home' });
538
- await config.writeTextAtomic(path.join(dir, 'character.json'), JSON.stringify(jsonObj, null, 2) + '\n', { writer: 'project-home' });
539
- sendJson(res, 200, { ok: true, path: dir, bytes: Buffer.byteLength(body.js, 'utf8') });
793
+ await config.writeTextAtomic(path.join(dir, 'character.json'), jsonText, { writer: 'project-home' });
794
+ // character.json is saved: the persona is usable, so a stale-WAV prune failure is reported, never a 500.
795
+ let pruneError;
796
+ try {
797
+ await pruneSounds(resolved.cwd, soundPayload.files.map((f) => f.name));
798
+ } catch (e) {
799
+ pruneError = e?.message ?? String(e);
800
+ }
801
+ const answer = { ok: true, path: dir, bytes: Buffer.byteLength(body.js, 'utf8'), sounds: soundPayload.files.map((f) => f.name) };
802
+ if (pruneError !== undefined) answer.pruneError = pruneError;
803
+ sendJson(res, 200, answer);
540
804
  } catch (e) {
541
805
  sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
542
806
  }
@@ -548,9 +812,13 @@ module.exports = {
548
812
  validateDemoVideoHtml,
549
813
  injectCsp,
550
814
  maxVideoBytes,
815
+ maxExportMp4Bytes,
816
+ MAX_EXPORT_POSTER_BYTES,
551
817
  DEMO_VIDEO_CSP,
552
818
  MAX_HTML_BYTES,
553
819
  MAX_DEMO_VIDEO_BYTES,
554
820
  REVIEW_WRITE_BODY_MAX,
821
+ VIDEO_OUTCOMES,
822
+ OUTCOME_TEXT_MAX,
555
823
  resolveCwd,
556
824
  };
@@ -0,0 +1,159 @@
1
+ /**
2
+ * replyClaims.cjs — the single decider for whether a cross-project reply's
3
+ * release claim is true.
4
+ *
5
+ * Used by crossProjectReply.cjs (the app route) and
6
+ * scripts/scheduler-mcp-server.cjs (the MCP server), so it must load outside
7
+ * Electron: requires only node built-ins and ../git/gitExec.cjs.
8
+ *
9
+ * - findUnfilledPlaceholders: version-ish template tokens left in a message
10
+ * ('{version}', '{{appVersion}}', '${release}', '<semver>', ...).
11
+ * - findSessionManagerVersions: the x.y.z a message names as a Session
12
+ * Manager release ('Session Manager 0.143.0', 'SM v0.143.0').
13
+ * - normalizeReleaseClaim: validates a caller's `{ commits }` claim.
14
+ * - isSessionManagerRepo / checkReleaseContains: verify with git that tag
15
+ * v<version> contains every claimed commit. Never throws.
16
+ */
17
+ 'use strict';
18
+
19
+ const fs = require('node:fs');
20
+ const path = require('node:path');
21
+
22
+ const SM_PACKAGE_NAME = 'claude-code-session-manager';
23
+ const VERSION_RE = /^\d+\.\d+\.\d+$/;
24
+ const COMMIT_RE = /^[0-9a-f]{7,40}$/i;
25
+ const MAX_COMMITS = 20;
26
+
27
+ const PLACEHOLDER_NAMES = [
28
+ 'version', 'appversion', 'app_version', 'app-version', 'release',
29
+ 'releaseversion', 'release_version', 'smversion', 'sm_version', 'semver',
30
+ ];
31
+ // Longest first so alternation never stops at a prefix ('release' vs 'release_version').
32
+ const NAME_ALT = PLACEHOLDER_NAMES.slice()
33
+ .sort((a, b) => b.length - a.length)
34
+ .map((n) => n.replace(/[-_]/g, (c) => `\\${c}`))
35
+ .join('|');
36
+ const INNER = `[ \\t]*(?:${NAME_ALT})[ \\t]*`;
37
+ // Two-char openers before one-char ones so '{{x}}' / '${x}' match whole.
38
+ const PLACEHOLDER_SRC = [
39
+ `\\{\\{${INNER}\\}\\}`,
40
+ `\\$\\{${INNER}\\}`,
41
+ `\\{${INNER}\\}`,
42
+ `<${INNER}>`,
43
+ `\\[${INNER}\\]`,
44
+ `%${INNER}%`,
45
+ ].join('|');
46
+
47
+ function findUnfilledPlaceholders(message, opts = {}) {
48
+ if (typeof message !== 'string') return [];
49
+ const allowVersionToken = !!(opts && opts.allowVersionToken);
50
+ const re = new RegExp(PLACEHOLDER_SRC, 'gi');
51
+ const out = [];
52
+ for (const m of message.matchAll(re)) {
53
+ const tok = m[0];
54
+ if (allowVersionToken && tok === '{version}') continue;
55
+ if (!out.includes(tok)) out.push(tok);
56
+ }
57
+ return out;
58
+ }
59
+
60
+ const SM_VERSION_SRC = '\\b(?:[Ss][Ee][Ss][Ss][Ii][Oo][Nn] [Mm][Aa][Nn][Aa][Gg][Ee][Rr]|SM)'
61
+ + '(?:\\s+(?:release|version|app))?\\s+v?(\\d+\\.\\d+\\.\\d+)\\b';
62
+
63
+ function findSessionManagerVersions(message) {
64
+ if (typeof message !== 'string') return [];
65
+ const out = [];
66
+ for (const m of message.matchAll(new RegExp(SM_VERSION_SRC, 'g'))) {
67
+ if (!out.includes(m[1])) out.push(m[1]);
68
+ }
69
+ return out;
70
+ }
71
+
72
+ function isPlainObject(v) {
73
+ if (!v || typeof v !== 'object' || Array.isArray(v)) return false;
74
+ const proto = Object.getPrototypeOf(v);
75
+ return proto === Object.prototype || proto === null;
76
+ }
77
+
78
+ function normalizeReleaseClaim(raw) {
79
+ const fail = (error) => ({ ok: false, error });
80
+ if (!isPlainObject(raw)) return fail('release must be an object { commits: [...] }');
81
+ const keys = Object.keys(raw);
82
+ if (keys.length !== 1 || keys[0] !== 'commits') {
83
+ return fail('release must have exactly one key, commits');
84
+ }
85
+ const { commits } = raw;
86
+ if (!Array.isArray(commits) || commits.length < 1 || commits.length > MAX_COMMITS) {
87
+ return fail(`release.commits must be an array of 1-${MAX_COMMITS} commit hashes`);
88
+ }
89
+ const out = [];
90
+ for (const c of commits) {
91
+ if (typeof c !== 'string' || !COMMIT_RE.test(c)) {
92
+ return fail(`release.commits has an invalid commit hash: ${JSON.stringify(c)}`);
93
+ }
94
+ const lc = c.toLowerCase();
95
+ if (!out.includes(lc)) out.push(lc);
96
+ }
97
+ return { ok: true, value: { commits: out } };
98
+ }
99
+
100
+ function isSessionManagerRepo(cwd) {
101
+ try {
102
+ if (typeof cwd !== 'string' || !cwd) return false;
103
+ const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
104
+ return !!pkg && typeof pkg === 'object' && pkg.name === SM_PACKAGE_NAME;
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+
110
+ function defaultRunGit(cwd, args) {
111
+ const { execGit } = require('../git/gitExec.cjs');
112
+ return execGit(cwd, args, { timeout: 15000 });
113
+ }
114
+
115
+ async function checkReleaseContains(input, opts = {}) {
116
+ try {
117
+ const { repoCwd, version, commits } = input || {};
118
+ if (typeof version !== 'string' || !VERSION_RE.test(version)) {
119
+ return { ok: false, error: `release version ${JSON.stringify(version)} is not x.y.z` };
120
+ }
121
+ if (typeof repoCwd !== 'string' || !repoCwd) {
122
+ return { ok: false, error: 'no repository to check the release against' };
123
+ }
124
+ const claim = normalizeReleaseClaim({ commits });
125
+ if (!claim.ok) return { ok: false, error: claim.error };
126
+ const runGit = (opts && typeof opts.runGit === 'function') ? opts.runGit : defaultRunGit;
127
+ const tag = `v${version}`;
128
+ const git = async (args) => { await runGit(repoCwd, args); };
129
+
130
+ try {
131
+ await git(['rev-parse', '-q', '--verify', `refs/tags/${tag}^{commit}`]);
132
+ } catch {
133
+ return { ok: false, error: `release tag ${tag} does not exist` };
134
+ }
135
+ for (const c of claim.value.commits) {
136
+ try {
137
+ await git(['rev-parse', '-q', '--verify', `${c}^{commit}`]);
138
+ } catch {
139
+ return { ok: false, error: `commit ${c} is not known to this repository` };
140
+ }
141
+ try {
142
+ await git(['merge-base', '--is-ancestor', c, tag]);
143
+ } catch {
144
+ return { ok: false, error: `release tag ${tag} does not contain commit ${c}` };
145
+ }
146
+ }
147
+ return { ok: true, tag };
148
+ } catch (err) {
149
+ return { ok: false, error: `release check failed: ${err && err.message ? err.message : String(err)}` };
150
+ }
151
+ }
152
+
153
+ module.exports = {
154
+ findUnfilledPlaceholders,
155
+ findSessionManagerVersions,
156
+ normalizeReleaseClaim,
157
+ isSessionManagerRepo,
158
+ checkReleaseContains,
159
+ };