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.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +76 -153
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
- package/dist/assets/Scheduler-CNLjn90m.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/Toggle-CYajnSdx.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/index-CdTppjKR.js +3133 -0
- package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +496 -484
- package/package.json +6 -4
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/hooks/hooks.json +15 -0
- package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +2 -0
- package/scripts/hooks/guard-tool-risk.cjs +5 -1
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
- package/scripts/scheduler-mcp-server.cjs +1032 -112
- package/src/main/adminRouteRegistry.cjs +69 -0
- package/src/main/agentLibrary.cjs +72 -4
- package/src/main/agentsIpc.cjs +3 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +336 -23
- package/src/main/config.cjs +35 -1
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +129 -2
- package/src/main/index.cjs +110 -52
- package/src/main/ipcSchemas.cjs +172 -8
- package/src/main/lib/AGENTS.md +1 -1
- package/src/main/lib/chatBootRecovery.cjs +2 -0
- package/src/main/lib/claude/agentModelResolve.cjs +51 -25
- package/src/main/lib/claude/agentSnapshot.cjs +186 -0
- package/src/main/lib/claude/environmentProfiles.cjs +242 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
- package/src/main/lib/claude/personaToolScope.cjs +82 -31
- package/src/main/lib/claude/runClaudeP.cjs +4 -2
- package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
- package/src/main/lib/claude/usageCircuit.cjs +49 -21
- package/src/main/lib/claude/vaultRefs.cjs +277 -0
- package/src/main/lib/demo-video-kit/capture.cjs +282 -12
- package/src/main/lib/demo-video-kit/cast.md +52 -0
- package/src/main/lib/demo-video-kit/character.cjs +778 -30
- package/src/main/lib/demo-video-kit/checks.cjs +120 -1
- package/src/main/lib/demo-video-kit/export.cjs +218 -0
- package/src/main/lib/demo-video-kit/frames.cjs +104 -9
- package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
- package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
- package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
- package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
- package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
- package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
- package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
- package/src/main/lib/epic/artifactIpc.cjs +153 -0
- package/src/main/lib/epic/artifactNotice.cjs +72 -0
- package/src/main/lib/epic/artifactRetention.cjs +356 -0
- package/src/main/lib/epic/artifactStore.cjs +435 -0
- package/src/main/lib/epic/delegationReadiness.cjs +83 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +258 -0
- package/src/main/lib/epic/epicMint.cjs +43 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
- package/src/main/lib/epic/epicOutsideState.cjs +18 -4
- package/src/main/lib/epic/epicPurge.cjs +347 -0
- package/src/main/lib/epic/epicReopen.cjs +5 -2
- package/src/main/lib/epic/epicSettle.cjs +4 -13
- package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +94 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +48 -4
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
- package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
- package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
- package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
- package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
- package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
- package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
- package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
- package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
- package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
- package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
- package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
- package/src/main/lib/git/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +182 -4
- package/src/main/lib/mcpToolCatalog.cjs +399 -29
- package/src/main/lib/opsOwnership.cjs +141 -28
- package/src/main/lib/opsRetentionSettings.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
- package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
- package/src/main/lib/phaseProjection.cjs +103 -0
- package/src/main/lib/prd/depSlugResolve.cjs +4 -13
- package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
- package/src/main/lib/prd/prdCreate.cjs +387 -228
- package/src/main/lib/prd/prdCriteria.cjs +228 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
- package/src/main/lib/prd/prdGateFiles.cjs +125 -49
- package/src/main/lib/prd/prdSizing.cjs +3 -1
- package/src/main/lib/process/cleanEnv.cjs +52 -1
- package/src/main/lib/process/leftoverRenice.cjs +178 -0
- package/src/main/lib/process/memoryScope.cjs +31 -3
- package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
- package/src/main/lib/project-pages/voicePreview.cjs +196 -0
- package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
- package/src/main/lib/scheduler/cpuSample.cjs +133 -42
- package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
- package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
- package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
- package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
- package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
- package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
- package/src/main/lib/tasks/mitigationReview.cjs +314 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
- package/src/main/lib/tasks/taskIpc.cjs +22 -18
- package/src/main/lib/tasks/taskLedger.cjs +147 -25
- package/src/main/lib/tasks/taskRun.cjs +186 -17
- package/src/main/lib/tasks/taskSwitch.cjs +85 -12
- package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
- package/src/main/lib/telemetry/auditEvents.cjs +204 -6
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
- package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
- package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
- package/src/main/lib/toolUseClassify.cjs +181 -0
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +21 -1
- package/src/main/pty.cjs +77 -0
- package/src/main/queueOps.cjs +33 -14
- package/src/main/runVerify.cjs +74 -9
- package/src/main/scheduler/AGENTS.md +1 -0
- package/src/main/scheduler/budget.cjs +6 -5
- package/src/main/scheduler/prdParser.cjs +46 -13
- package/src/main/scheduler/reviewLadder.cjs +9 -25
- package/src/main/scheduler/utilizationHold.cjs +191 -0
- package/src/main/scheduler.cjs +1932 -213
- package/src/main/templates/PRD_AUTHORING.md +11 -3
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +576 -39
- package/src/preload/apiSurface.json +223 -7
- package/src/preload/index.cjs +48 -1
- package/src/seed/agents/architect.md +6 -1
- package/src/seed/agents/blender-artist.md +2 -1
- package/src/seed/agents/competitive-analyst.md +3 -1
- package/src/seed/agents/competitive-researcher.md +2 -1
- package/src/seed/agents/demo-video-builder.md +98 -87
- package/src/seed/agents/dev-lead.md +3 -3
- package/src/seed/agents/project-home-builder.md +9 -31
- package/src/seed/agents/validator.md +23 -23
- package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
- package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
- package/dist/assets/Scheduler-cyr61UAC.js +0 -16
- package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
- package/dist/assets/index-B2TQz3nd.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Playbook: TikTok kind
|
|
2
|
+
|
|
3
|
+
Read this when the `Video kind:` line is TikTok. It is for the demo-video-builder persona: short
|
|
4
|
+
imperative rules for one vertical short built to go viral with this project's own audience.
|
|
5
|
+
|
|
6
|
+
This playbook overrides three persona rules: the stage size, the keystone holds, and the scene
|
|
7
|
+
structure. Everything else in the persona still holds: plain language, the claims list, the
|
|
8
|
+
voice-first rule, the character, the kit-tool failure rule, and the single save call.
|
|
9
|
+
|
|
10
|
+
## Format
|
|
11
|
+
|
|
12
|
+
- Stage: vertical 9:16, 1080x1920 logical pixels, scaled to fit with letterboxing.
|
|
13
|
+
- Put `<meta name="sm-demo-aspect" content="9:16">` in the document head. frames.cjs and export.cjs
|
|
14
|
+
read it to size the viewport and the MP4.
|
|
15
|
+
- Length: 30 s by default; any whole number of seconds from 15 to 60 when the goal asks for it.
|
|
16
|
+
The duration meta and `smDemo.duration` both say it.
|
|
17
|
+
- Frame 0 is the live scene: the subject already on screen, no title card, no fade from black.
|
|
18
|
+
- The hook is visible by 3 s: one on-screen line that names the problem or the surprise.
|
|
19
|
+
- Captions read with the sound muted. Each caption is at most 12 words. Captions carry every
|
|
20
|
+
point the narration makes, so the short works on mute.
|
|
21
|
+
- A cut or a camera move (push in, pan, pull out) at least every 3 s. No hold longer than 3 s;
|
|
22
|
+
the persona's 5 s keystone hold does not apply here.
|
|
23
|
+
- The payoff lands in the last 5 s: what the viewer gets, shown, not told.
|
|
24
|
+
- A loop ending: the last frame matches frame 0's framing and light, so the clip loops cleanly.
|
|
25
|
+
A small "next" tag over the live scene is fine; never a full-screen end card.
|
|
26
|
+
- Safe zone: no text in the bottom 20% or the right 15% of the frame (the app's own buttons and
|
|
27
|
+
caption sit there). Keep text clear of the top bar too.
|
|
28
|
+
|
|
29
|
+
## Structure
|
|
30
|
+
|
|
31
|
+
Replace the persona's title-problem-reveal order with these beats, in order:
|
|
32
|
+
|
|
33
|
+
1. Live open with the hook (0-3 s).
|
|
34
|
+
2. The problem or the mistake, shown.
|
|
35
|
+
3. The turn: the project does the one thing, captured whenever a capture exists.
|
|
36
|
+
4. The payoff (last 5 s).
|
|
37
|
+
5. The loop back to frame 0's framing.
|
|
38
|
+
|
|
39
|
+
One idea per short. If the target has three features, pick the one this audience cares about most.
|
|
40
|
+
|
|
41
|
+
## Episode contract
|
|
42
|
+
|
|
43
|
+
- `seek(t)` is pure: the frame for `t` depends only on `t`, never on history or on the previous
|
|
44
|
+
frame. Re-render from scratch each call.
|
|
45
|
+
- Seeded randomness only: no `Math.random`, no `Date`, in render code. Use a small seeded PRNG
|
|
46
|
+
(mulberry32 or similar) created at module level.
|
|
47
|
+
- One clock: `play()` drives `seek()` from one `requestAnimationFrame` loop. No per-scene timers.
|
|
48
|
+
- Expose on `window.smDemo`, besides the persona's `duration`, `seek`, `play`, `pause`:
|
|
49
|
+
- `smDemo.beats = { hook, payoff, loop }`: the second each beat lands.
|
|
50
|
+
- `smDemo.cuts = [ ... ]`: the second of every cut or camera move, ascending.
|
|
51
|
+
|
|
52
|
+
## Kit checks
|
|
53
|
+
|
|
54
|
+
Run the kit from `~/.claude/session-manager/demo-video-kit/` exactly as the persona says, plus:
|
|
55
|
+
|
|
56
|
+
- Stills check: run frames.cjs `sampleFrames({ htmlPath, lengthS })`, open its contact sheet PNG,
|
|
57
|
+
and look at every still. Each one must read on a phone: subject large, captions legible and inside
|
|
58
|
+
the safe zone, no frame cut off or empty. Fix and re-run until all pass.
|
|
59
|
+
- checks.cjs: pass `tiktok` in the input JSON as
|
|
60
|
+
`{ beats: smDemo.beats, cuts: smDemo.cuts, postCaption: meta.post.caption }`, together with the
|
|
61
|
+
frames from sampleFrames and `lengthS`. The hook, cadence, payoff, loop, safe-zone and
|
|
62
|
+
post-caption checks must all pass before you save.
|
|
63
|
+
- sound.cjs: mix the narration over the music bed; the bed is ducked under speech and the mix is
|
|
64
|
+
normalised to -14 LUFS. When the project has a saved character with a command voice, speak its
|
|
65
|
+
lines with `node character.cjs speak spec.json` first. Pass `projectRoot` (`$SM_PROJECT_ROOT`) in
|
|
66
|
+
its spec: a cue or the spec's `bed` may name one of the persona's own `sounds`, and an unknown name
|
|
67
|
+
fails the run; never swap in another sound.
|
|
68
|
+
- export.cjs: `node export.cjs spec.json` with `{ htmlPath, lengthS, audioPath, outDir }` writes
|
|
69
|
+
`video.mp4` (1080x1920, H.264/AAC) and `poster.png` in `outDir`. It must exit 0.
|
|
70
|
+
|
|
71
|
+
## Audience rule
|
|
72
|
+
|
|
73
|
+
Decide who the short is for from what the project is and who it is for: read its README, its
|
|
74
|
+
landing copy and its docs, not your guess. Write every hook, caption and line for that audience's
|
|
75
|
+
words and that audience's problem. Save it as `meta.post.audience`, one short sentence.
|
|
76
|
+
|
|
77
|
+
## Post caption rule
|
|
78
|
+
|
|
79
|
+
- At most 150 characters.
|
|
80
|
+
- At most 2 hashtags, at the end.
|
|
81
|
+
- No link, no URL, no domain.
|
|
82
|
+
- The text before the hashtags ends in a short question that invites a comment.
|
|
83
|
+
|
|
84
|
+
Save it as `meta.post.caption`. A style file that forbids questions does not apply here: the
|
|
85
|
+
caption always ends in a short question.
|
|
86
|
+
|
|
87
|
+
## Series rule
|
|
88
|
+
|
|
89
|
+
When the `Video target:` line names a series brief file:
|
|
90
|
+
|
|
91
|
+
1. Read the brief, then every season, canon and ledger file it names.
|
|
92
|
+
2. Make the next episode exactly as they say: its premise, cast, topic and beats. Follow the
|
|
93
|
+
brief's topic; never invent a premise, never pick an episode the files do not schedule.
|
|
94
|
+
Keep its sound too: every sound cue at its time and its music as the sound.cjs `bed`,
|
|
95
|
+
by the names the files use.
|
|
96
|
+
3. Use the project persona for the host and voice; never borrow another project's characters.
|
|
97
|
+
4. When the files have no next episode left, in the review stage or the final stage alike,
|
|
98
|
+
call `project_video_outcome_write` once with `{ videoId: <the Entry id>, outcome:
|
|
99
|
+
'season-complete', text: 'Season complete: <brief path> has no next episode' }`. Save no
|
|
100
|
+
video and no review material, end the report with that same `Season complete` line, and
|
|
101
|
+
end PASS: a finished season is a passing run, not a failure.
|
|
102
|
+
|
|
103
|
+
Never update the series files yourself unless the brief says to.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kokoroSay.cjs — speak Kokoro-82M (kokoro-onnx) voices from the kit itself.
|
|
3
|
+
*
|
|
4
|
+
* One spawnSync of python loads the model ONCE and writes one WAV per line, so
|
|
5
|
+
* a voice preview and a full video run go through the same code (and the same
|
|
6
|
+
* voice lane). Node built-ins only: this file is copied into the per-machine
|
|
7
|
+
* kit folder by seedKit.cjs and required from any project's cwd.
|
|
8
|
+
*
|
|
9
|
+
* const { sayKokoro } = require('<kit>/kokoroSay.cjs');
|
|
10
|
+
* sayKokoro([{ text: 'Hello.', out: 'a.wav', voice: 'af_heart' }], { cwd })
|
|
11
|
+
* -> { ok: true, outs: [abs...], audioSeconds, seconds: [...] } | { ok: false, error }
|
|
12
|
+
*
|
|
13
|
+
* python: opts.python, else $SM_KOKORO_PYTHON, else python3 (argv ['-c', KOKORO_SCRIPT],
|
|
14
|
+
* JSON {modelDir, lines} on stdin, no shell). Model dir: opts.modelDir, else
|
|
15
|
+
* $KOKORO_MODEL_DIR, else ~/.cache/kokoro-onnx.
|
|
16
|
+
*/
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const fs = require('node:fs');
|
|
20
|
+
const os = require('node:os');
|
|
21
|
+
const path = require('node:path');
|
|
22
|
+
const { spawnSync } = require('node:child_process');
|
|
23
|
+
|
|
24
|
+
const MODEL_FILE = 'kokoro-v1.0.onnx';
|
|
25
|
+
const VOICES_FILE = 'voices-v1.0.bin';
|
|
26
|
+
const MODEL_URL_BASE = 'https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0';
|
|
27
|
+
const PIP_INSTALL = 'python3 -m pip install --user --break-system-packages kokoro-onnx soundfile';
|
|
28
|
+
const WAV_HEADER_BYTES = 44;
|
|
29
|
+
const STDERR_TAIL = 500;
|
|
30
|
+
const PER_LINE_TIMEOUT_MS = 15 * 60 * 1000;
|
|
31
|
+
const TIMEOUT_CAP_MS = 180 * 60 * 1000;
|
|
32
|
+
const MAX_BUFFER = 16 * 1024 * 1024;
|
|
33
|
+
const SPEED_MIN = 0.5;
|
|
34
|
+
const SPEED_MAX = 2.0;
|
|
35
|
+
const DEFAULT_LANG = 'en-us';
|
|
36
|
+
|
|
37
|
+
/** Python source run as `python -c KOKORO_SCRIPT`; reads {modelDir, lines} JSON from stdin. */
|
|
38
|
+
const KOKORO_SCRIPT = `
|
|
39
|
+
import json, sys
|
|
40
|
+
def fail(msg):
|
|
41
|
+
print(json.dumps({"ok": False, "error": msg}))
|
|
42
|
+
sys.stdout.flush()
|
|
43
|
+
sys.exit(1)
|
|
44
|
+
try:
|
|
45
|
+
req = json.loads(sys.stdin.read())
|
|
46
|
+
except Exception as e:
|
|
47
|
+
fail("bad request JSON on stdin: %s" % e)
|
|
48
|
+
try:
|
|
49
|
+
import soundfile
|
|
50
|
+
from kokoro_onnx import Kokoro
|
|
51
|
+
except Exception as e:
|
|
52
|
+
fail("import failed (%s: %s); install with: ${PIP_INSTALL}" % (type(e).__name__, e))
|
|
53
|
+
try:
|
|
54
|
+
d = req["modelDir"]
|
|
55
|
+
k = Kokoro(d + "/${MODEL_FILE}", d + "/${VOICES_FILE}")
|
|
56
|
+
seconds = []
|
|
57
|
+
for ln in req["lines"]:
|
|
58
|
+
samples, sr = k.create(ln["text"], voice=ln["voice"], speed=float(ln["speed"]), lang=ln["lang"])
|
|
59
|
+
soundfile.write(ln["out"], samples, sr)
|
|
60
|
+
seconds.append(round(len(samples) / float(sr), 3))
|
|
61
|
+
print(json.dumps({"ok": True, "seconds": seconds}))
|
|
62
|
+
except Exception as e:
|
|
63
|
+
fail("%s: %s" % (type(e).__name__, e))
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
function curlCommand(modelDir, file) {
|
|
67
|
+
return `curl -L --max-time 600 -o "${path.join(modelDir, file)}" ${MODEL_URL_BASE}/${file}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function resolveModelDir(opts, env) {
|
|
71
|
+
if (opts.modelDir) return path.resolve(String(opts.modelDir));
|
|
72
|
+
if (env.KOKORO_MODEL_DIR) return path.resolve(env.KOKORO_MODEL_DIR);
|
|
73
|
+
return path.join(os.homedir(), '.cache', 'kokoro-onnx');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** -> {ok: true, lines: normalized[]} | {ok: false, error}. Pure (no fs). */
|
|
77
|
+
function validateLines(lines, cwd) {
|
|
78
|
+
if (!Array.isArray(lines) || lines.length === 0) return { ok: false, error: 'lines must be a non-empty array' };
|
|
79
|
+
const seen = new Map();
|
|
80
|
+
const out = [];
|
|
81
|
+
for (let i = 0; i < lines.length; i++) {
|
|
82
|
+
const ln = lines[i];
|
|
83
|
+
const at = `lines[${i}]`;
|
|
84
|
+
if (!ln || typeof ln !== 'object') return { ok: false, error: `${at} must be an object {text, out, voice, speed?, lang?}` };
|
|
85
|
+
if (typeof ln.text !== 'string' || !ln.text.trim()) return { ok: false, error: `${at}.text must be a non-empty string` };
|
|
86
|
+
if (typeof ln.out !== 'string' || !ln.out.trim() || !ln.out.toLowerCase().endsWith('.wav')) {
|
|
87
|
+
return { ok: false, error: `${at}.out must be a path ending in .wav` };
|
|
88
|
+
}
|
|
89
|
+
if (typeof ln.voice !== 'string' || !ln.voice.trim()) return { ok: false, error: `${at}.voice must be a non-empty string` };
|
|
90
|
+
let speed = 1.0;
|
|
91
|
+
if (ln.speed !== undefined && ln.speed !== null) {
|
|
92
|
+
speed = ln.speed;
|
|
93
|
+
if (typeof speed !== 'number' || !Number.isFinite(speed) || speed < SPEED_MIN || speed > SPEED_MAX) {
|
|
94
|
+
return { ok: false, error: `${at}.speed must be a number from ${SPEED_MIN} to ${SPEED_MAX}` };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let lang = DEFAULT_LANG;
|
|
98
|
+
if (ln.lang !== undefined && ln.lang !== null) {
|
|
99
|
+
if (typeof ln.lang !== 'string' || !ln.lang.trim()) return { ok: false, error: `${at}.lang must be a non-empty string` };
|
|
100
|
+
lang = ln.lang.trim();
|
|
101
|
+
}
|
|
102
|
+
const abs = path.resolve(cwd, ln.out);
|
|
103
|
+
if (seen.has(abs)) return { ok: false, error: `${at}.out duplicates lines[${seen.get(abs)}].out (${abs})` };
|
|
104
|
+
seen.set(abs, i);
|
|
105
|
+
out.push({ text: ln.text, out: abs, voice: ln.voice.trim(), speed, lang });
|
|
106
|
+
}
|
|
107
|
+
return { ok: true, lines: out };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function timeoutFor(lineCount, timeoutMs) {
|
|
111
|
+
const base = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : lineCount * PER_LINE_TIMEOUT_MS;
|
|
112
|
+
return Math.min(base, TIMEOUT_CAP_MS);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function parseLastJsonLine(stdout) {
|
|
116
|
+
const rows = String(stdout || '').trim().split('\n').reverse();
|
|
117
|
+
for (const row of rows) {
|
|
118
|
+
try {
|
|
119
|
+
const v = JSON.parse(row);
|
|
120
|
+
if (v && typeof v === 'object') return v;
|
|
121
|
+
} catch { /* not JSON */ }
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isWav(p) {
|
|
127
|
+
try {
|
|
128
|
+
return fs.statSync(p).size > WAV_HEADER_BYTES;
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Speak `lines` with Kokoro in ONE python process.
|
|
136
|
+
* opts: {python, modelDir, cwd, timeoutMs, env}
|
|
137
|
+
* -> {ok: true, outs, audioSeconds, seconds} | {ok: false, error}
|
|
138
|
+
*/
|
|
139
|
+
function sayKokoro(lines, opts = {}) {
|
|
140
|
+
const env = opts.env || process.env;
|
|
141
|
+
const cwd = path.resolve(opts.cwd || process.cwd());
|
|
142
|
+
const v = validateLines(lines, cwd);
|
|
143
|
+
if (!v.ok) return v;
|
|
144
|
+
|
|
145
|
+
const modelDir = resolveModelDir(opts, env);
|
|
146
|
+
for (const f of [MODEL_FILE, VOICES_FILE]) {
|
|
147
|
+
if (!fs.existsSync(path.join(modelDir, f))) {
|
|
148
|
+
return { ok: false, error: `Kokoro model file ${f} is missing from ${modelDir}; download it with: ${curlCommand(modelDir, f)}` };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
for (const ln of v.lines) {
|
|
154
|
+
fs.mkdirSync(path.dirname(ln.out), { recursive: true });
|
|
155
|
+
fs.rmSync(ln.out, { force: true }); // a stale WAV must never count as this run's output
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return { ok: false, error: `cannot prepare output paths: ${e.message}` };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const python = opts.python || env.SM_KOKORO_PYTHON || 'python3';
|
|
162
|
+
const limit = timeoutFor(v.lines.length, opts.timeoutMs);
|
|
163
|
+
const r = spawnSync(python, ['-c', KOKORO_SCRIPT], {
|
|
164
|
+
shell: false,
|
|
165
|
+
cwd,
|
|
166
|
+
env,
|
|
167
|
+
input: JSON.stringify({ modelDir, lines: v.lines }),
|
|
168
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
169
|
+
timeout: limit,
|
|
170
|
+
maxBuffer: MAX_BUFFER,
|
|
171
|
+
});
|
|
172
|
+
const stderr = r.stderr ? r.stderr.toString('utf8').trim().slice(-STDERR_TAIL) : '';
|
|
173
|
+
const withStderr = (msg) => (stderr ? `${msg}: ${stderr}` : msg);
|
|
174
|
+
const result = parseLastJsonLine(r.stdout ? r.stdout.toString('utf8') : '');
|
|
175
|
+
|
|
176
|
+
if (r.error) {
|
|
177
|
+
if (r.error.code === 'ETIMEDOUT') return { ok: false, error: withStderr(`Kokoro timed out after ${limit} ms`) };
|
|
178
|
+
return { ok: false, error: withStderr(`cannot run ${python}: ${r.error.message}`) };
|
|
179
|
+
}
|
|
180
|
+
if (r.status !== 0) {
|
|
181
|
+
const why = r.signal ? `killed by ${r.signal}` : `exit ${r.status}`;
|
|
182
|
+
let msg = result && result.ok === false && result.error ? `Kokoro failed (${why}): ${result.error}` : `Kokoro failed (${why})`;
|
|
183
|
+
if (/ModuleNotFoundError|ImportError|No module named/.test(stderr) && !msg.includes(PIP_INSTALL)) {
|
|
184
|
+
msg += `; install with: ${PIP_INSTALL}`;
|
|
185
|
+
}
|
|
186
|
+
return { ok: false, error: withStderr(msg) };
|
|
187
|
+
}
|
|
188
|
+
const missing = v.lines.filter((ln) => !isWav(ln.out)).map((ln) => ln.out);
|
|
189
|
+
if (missing.length) return { ok: false, error: withStderr(`Kokoro wrote no WAV to ${missing.join(', ')}`) };
|
|
190
|
+
|
|
191
|
+
const seconds = result && Array.isArray(result.seconds) ? result.seconds.map(Number) : [];
|
|
192
|
+
const audioSeconds = Math.round(seconds.reduce((a, s) => a + (Number.isFinite(s) ? s : 0), 0) * 1000) / 1000;
|
|
193
|
+
return { ok: true, outs: v.lines.map((ln) => ln.out), audioSeconds, seconds };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
sayKokoro,
|
|
198
|
+
KOKORO_SCRIPT,
|
|
199
|
+
validateLines,
|
|
200
|
+
MODEL_FILE,
|
|
201
|
+
VOICES_FILE,
|
|
202
|
+
PIP_INSTALL,
|
|
203
|
+
PER_LINE_TIMEOUT_MS,
|
|
204
|
+
TIMEOUT_CAP_MS,
|
|
205
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Project Home HTML — shared rules
|
|
2
|
+
|
|
3
|
+
The rules every persona that writes HTML for Project Home follows (a demo video, a Knowledge
|
|
4
|
+
Page). Your persona file adds its own kind's rules on top; where it says something stricter or
|
|
5
|
+
different (scripts, size cap), the persona file wins for that point.
|
|
6
|
+
|
|
7
|
+
## Where you run
|
|
8
|
+
|
|
9
|
+
You run inside a Session Manager Epic for the target project. The HTML you produce is rendered
|
|
10
|
+
inside a sandboxed frame in that project's Project Home tab. It is regenerated only when a human
|
|
11
|
+
deliberately presses that Project Home button — never automatically and never in a loop — so this
|
|
12
|
+
run is the one chance to get it right before a person sees it.
|
|
13
|
+
|
|
14
|
+
## Grounding
|
|
15
|
+
|
|
16
|
+
Ground every claim in something you read: the project's manifest (`package.json`,
|
|
17
|
+
`pyproject.toml`, or equivalent), its README or docs, its source tree, or its git log. If you
|
|
18
|
+
can't point to where a claim came from, leave it out rather than guess — leaving something out is
|
|
19
|
+
far better than inventing it. Never invent statistics, metrics, quotes, logos, testimonials,
|
|
20
|
+
screenshots, or features that don't exist. Where the project already describes itself well (a
|
|
21
|
+
tagline, a feature list, a mission statement), reuse its own wording instead of paraphrasing.
|
|
22
|
+
|
|
23
|
+
Read with a bounded pass: the manifest, the README or top-level docs index, the top-level
|
|
24
|
+
directory tree, and `git log --oneline -30` for a sense of recent direction. Stop once you have
|
|
25
|
+
enough to describe the project honestly — you don't need to read every file. Keep a claims list:
|
|
26
|
+
every fact you plan to show, with the source you read it from; drop any claim with no source.
|
|
27
|
+
|
|
28
|
+
## One document
|
|
29
|
+
|
|
30
|
+
Produce exactly one complete HTML document:
|
|
31
|
+
- All CSS lives inline in a single `<style>` block — no `<link href="http...">`, no `@import`,
|
|
32
|
+
and no `url(http...)`. Scripts follow your persona file: a Knowledge Page has no `<script>` at
|
|
33
|
+
all; a demo video has one inline `<script>` block and never `<script src="...">`.
|
|
34
|
+
- No external fonts or images; nothing the browser needs to fetch over the network.
|
|
35
|
+
- Stay under your persona file's size cap.
|
|
36
|
+
|
|
37
|
+
## When the write tool fails
|
|
38
|
+
|
|
39
|
+
If the save tool rejects the HTML, fix the specific problem it reported and call it again — up to
|
|
40
|
+
3 attempts total. If the save tool isn't available in this session at all, that is a Session
|
|
41
|
+
Manager launch bug, not an obstacle to route around: say so plainly, give the absolute path of the
|
|
42
|
+
HTML file you built in your final result, and stop. Don't start Session Manager's MCP server
|
|
43
|
+
yourself, call its admin API, write the saved file by hand, or build any other workaround or tooling, in the target project or anywhere else.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Demo-video kit project sounds: a persona's own named sound effects and music beds —
|
|
3
|
+
// the `sounds` block of character.json ({ sfx: [{name,note}], beds: [{name,note,command}] })
|
|
4
|
+
// and a cast member's `sfx` (names of built-in effects or sounds.sfx entries).
|
|
5
|
+
// Every sfx entry and every bed without `command` is file-backed: its WAV lives in
|
|
6
|
+
// videos/_character/sounds/<name>.wav (see soundFile), written only by
|
|
7
|
+
// POST /admin/project-home/character/write as writer 'project-home'.
|
|
8
|
+
// Seeded with the kit, so it loads standalone: node built-ins and this folder only.
|
|
9
|
+
// sound.cjs and character.cjs are required lazily inside functions (both may require
|
|
10
|
+
// this module at load).
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
|
|
13
|
+
const SOUND_NAME_RE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
14
|
+
const MAX_PROJECT_SFX = 16;
|
|
15
|
+
const MAX_PROJECT_BEDS = 8;
|
|
16
|
+
const MAX_MEMBER_SFX = 8;
|
|
17
|
+
const SOUND_NOTE_MAX = 200;
|
|
18
|
+
const MAX_SFX_WAV_BYTES = 1048576;
|
|
19
|
+
const MAX_BED_WAV_BYTES = 12582912;
|
|
20
|
+
const MAX_SOUNDS_TOTAL_BYTES = 33554432;
|
|
21
|
+
const WINDOWS_RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/;
|
|
22
|
+
|
|
23
|
+
const SFX_KEYS = Object.freeze(['name', 'note']);
|
|
24
|
+
const BED_KEYS = Object.freeze(['name', 'note', 'command']);
|
|
25
|
+
|
|
26
|
+
/** The kit's built-in effect and style names, from sound.cjs. */
|
|
27
|
+
function builtinNames() {
|
|
28
|
+
const { SFX_NAMES, STYLES } = require('./sound.cjs');
|
|
29
|
+
return { sfx: [...SFX_NAMES], styles: Object.keys(STYLES) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isPlainObject(v) {
|
|
33
|
+
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** -> null when `sounds` is a valid character.json `sounds` block, else a reason (first failure wins). */
|
|
37
|
+
function validateSounds(sounds) {
|
|
38
|
+
if (!isPlainObject(sounds)) return 'sounds must be an object with optional sfx and beds arrays';
|
|
39
|
+
for (const k of Object.keys(sounds)) {
|
|
40
|
+
if (k !== 'sfx' && k !== 'beds') return `sounds.${k} is not a known key (sfx, beds)`;
|
|
41
|
+
}
|
|
42
|
+
if ('sfx' in sounds && (!Array.isArray(sounds.sfx) || sounds.sfx.length > MAX_PROJECT_SFX)) {
|
|
43
|
+
return `sounds.sfx must be an array of at most ${MAX_PROJECT_SFX} sound effects`;
|
|
44
|
+
}
|
|
45
|
+
if ('beds' in sounds && (!Array.isArray(sounds.beds) || sounds.beds.length > MAX_PROJECT_BEDS)) {
|
|
46
|
+
return `sounds.beds must be an array of at most ${MAX_PROJECT_BEDS} music beds`;
|
|
47
|
+
}
|
|
48
|
+
const builtin = builtinNames();
|
|
49
|
+
const styleKeys = builtin.styles.map((s) => s.toLowerCase());
|
|
50
|
+
const seen = new Map();
|
|
51
|
+
const groups = [['sfx', SFX_KEYS], ['beds', BED_KEYS]];
|
|
52
|
+
for (const [group, keys] of groups) {
|
|
53
|
+
const items = sounds[group] || [];
|
|
54
|
+
for (let i = 0; i < items.length; i++) {
|
|
55
|
+
const item = items[i];
|
|
56
|
+
const label = `sounds.${group}[${i}]`;
|
|
57
|
+
if (!isPlainObject(item)) return `${label} must be an object`;
|
|
58
|
+
for (const k of Object.keys(item)) {
|
|
59
|
+
if (!keys.includes(k)) return `${label}.${k} is not a known key (${keys.join(', ')})`;
|
|
60
|
+
}
|
|
61
|
+
const n = item.name;
|
|
62
|
+
if (typeof n !== 'string' || !SOUND_NAME_RE.test(n)) return `${label}.name must match ${SOUND_NAME_RE}`;
|
|
63
|
+
if (WINDOWS_RESERVED.test(n)) return `${label}.name "${n}" is a reserved file name`;
|
|
64
|
+
if (builtin.sfx.includes(n)) return `${label}.name "${n}" is a built-in sound (${builtin.sfx.join(', ')})`;
|
|
65
|
+
if (styleKeys.includes(n.toLowerCase())) return `${label}.name "${n}" is a built-in style (${builtin.styles.join(', ')})`;
|
|
66
|
+
if (seen.has(n)) return `${label}.name "${n}" duplicates ${seen.get(n)}.name`;
|
|
67
|
+
seen.set(n, label);
|
|
68
|
+
if ('note' in item && (typeof item.note !== 'string' || item.note.length < 1 || item.note.length > SOUND_NOTE_MAX)) {
|
|
69
|
+
return `${label}.note must be a 1-${SOUND_NOTE_MAX} char string`;
|
|
70
|
+
}
|
|
71
|
+
if (group === 'beds' && 'command' in item) {
|
|
72
|
+
const cmd = item.command;
|
|
73
|
+
if (!Array.isArray(cmd) || cmd.length === 0 || !cmd.every((a) => typeof a === 'string')) {
|
|
74
|
+
return `${label}.command must be a non-empty string[]`;
|
|
75
|
+
}
|
|
76
|
+
if (!cmd[0]) return `${label}.command[0] must be a program name`;
|
|
77
|
+
if (!cmd.some((a) => a.includes('{lengthS}'))) return `${label}.command must contain a {lengthS} placeholder`;
|
|
78
|
+
if (!cmd.some((a) => a.includes('{out}'))) return `${label}.command must contain an {out} placeholder`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** -> null when a cast member's `sfx` names 1-8 distinct built-in effects or sounds.sfx
|
|
86
|
+
* names, else a reason prefixed with `label`. `sounds` may be undefined. */
|
|
87
|
+
function validateMemberSfx(sfx, label, sounds) {
|
|
88
|
+
if (!Array.isArray(sfx) || sfx.length < 1 || sfx.length > MAX_MEMBER_SFX || !sfx.every((n) => typeof n === 'string')) {
|
|
89
|
+
return `${label} must be an array of 1-${MAX_MEMBER_SFX} sound names`;
|
|
90
|
+
}
|
|
91
|
+
const builtin = builtinNames().sfx;
|
|
92
|
+
const own = sounds && Array.isArray(sounds.sfx) ? sounds.sfx.map((e) => e && e.name).filter((n) => typeof n === 'string') : [];
|
|
93
|
+
const firstAt = new Map();
|
|
94
|
+
for (let j = 0; j < sfx.length; j++) {
|
|
95
|
+
const n = sfx[j];
|
|
96
|
+
if (!builtin.includes(n) && !own.includes(n)) {
|
|
97
|
+
return `${label}[${j}] "${n}" is not a built-in sound (${builtin.join(', ')}) or one of sounds.sfx (${own.length ? own.join(', ') : 'none'})`;
|
|
98
|
+
}
|
|
99
|
+
if (firstAt.has(n)) return `${label}[${j}] "${n}" repeats ${label}[${firstAt.get(n)}]`;
|
|
100
|
+
firstAt.set(n, j);
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Names of every file-backed sound in character `c`: each sfx, then each bed without `command`. */
|
|
106
|
+
function fileBackedSoundNames(c) {
|
|
107
|
+
const s = c && isPlainObject(c.sounds) ? c.sounds : null;
|
|
108
|
+
if (!s) return [];
|
|
109
|
+
const out = [];
|
|
110
|
+
if (Array.isArray(s.sfx)) for (const e of s.sfx) if (e && typeof e.name === 'string') out.push(e.name);
|
|
111
|
+
if (Array.isArray(s.beds)) for (const e of s.beds) if (e && typeof e.name === 'string' && !('command' in e)) out.push(e.name);
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** -> { kind: 'sfx' | 'bed', entry } for the project sound named `name` in character `c`, else null. */
|
|
116
|
+
function findProjectSound(c, name) {
|
|
117
|
+
const s = c && isPlainObject(c.sounds) ? c.sounds : null;
|
|
118
|
+
if (!s) return null;
|
|
119
|
+
const sfx = Array.isArray(s.sfx) ? s.sfx.find((e) => e && e.name === name) : undefined;
|
|
120
|
+
if (sfx) return { kind: 'sfx', entry: sfx };
|
|
121
|
+
const bed = Array.isArray(s.beds) ? s.beds.find((e) => e && e.name === name) : undefined;
|
|
122
|
+
if (bed) return { kind: 'bed', entry: bed };
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** -> null when `buf` is a readable PCM / IEEE-float WAV (headers only), else a reason prefixed with `label`. */
|
|
127
|
+
function wavFormatError(buf, label) {
|
|
128
|
+
if (!Buffer.isBuffer(buf) || buf.length < 12 || buf.toString('ascii', 0, 4) !== 'RIFF' || buf.toString('ascii', 8, 12) !== 'WAVE') {
|
|
129
|
+
return `${label} is not a RIFF WAV`;
|
|
130
|
+
}
|
|
131
|
+
let fmt = null;
|
|
132
|
+
let data = null;
|
|
133
|
+
let pos = 12;
|
|
134
|
+
while (pos + 8 <= buf.length) {
|
|
135
|
+
const id = buf.toString('ascii', pos, pos + 4);
|
|
136
|
+
const size = buf.readUInt32LE(pos + 4);
|
|
137
|
+
const body = pos + 8;
|
|
138
|
+
if (id === 'fmt ' && !fmt && size >= 16 && body + 16 <= buf.length) {
|
|
139
|
+
fmt = { tag: buf.readUInt16LE(body), ch: buf.readUInt16LE(body + 2), sr: buf.readUInt32LE(body + 4), bits: buf.readUInt16LE(body + 14) };
|
|
140
|
+
}
|
|
141
|
+
if (id === 'data' && !data) data = { bytes: Math.min(size, buf.length - body) };
|
|
142
|
+
pos = body + size + (size % 2);
|
|
143
|
+
}
|
|
144
|
+
if (!fmt) return `${label} has no fmt chunk`;
|
|
145
|
+
if (![1, 3, 0xfffe].includes(fmt.tag)) return `${label} WAV format tag ${fmt.tag} is not PCM or IEEE float`;
|
|
146
|
+
if (fmt.ch < 1 || fmt.ch > 2) return `${label} WAV must be mono or stereo, not ${fmt.ch} channels`;
|
|
147
|
+
if (fmt.sr < 8000 || fmt.sr > 192000) return `${label} WAV sample rate ${fmt.sr} Hz is outside 8000-192000`;
|
|
148
|
+
if (![8, 16, 24, 32, 64].includes(fmt.bits)) return `${label} WAV has ${fmt.bits}-bit samples`;
|
|
149
|
+
if (!data) return `${label} has no data chunk`;
|
|
150
|
+
if (data.bytes < (fmt.ch * fmt.bits) / 8) return `${label} has no audio samples`;
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** -> null when `buf` is a usable WAV within the byte cap for `kind` ('sfx' | 'bed'), else a reason. */
|
|
155
|
+
function checkSoundWav(buf, label, kind) {
|
|
156
|
+
const cap = kind === 'sfx' ? MAX_SFX_WAV_BYTES : MAX_BED_WAV_BYTES;
|
|
157
|
+
if (Buffer.isBuffer(buf) && buf.length > cap) {
|
|
158
|
+
return `${label} is ${buf.length} bytes, over the ${cap}-byte limit for a ${kind === 'sfx' ? 'sound effect' : 'music bed'}`;
|
|
159
|
+
}
|
|
160
|
+
return wavFormatError(buf, label);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** <characterDir(root)>/sounds — where every file-backed project sound's WAV lives. */
|
|
164
|
+
function soundsDir(root) {
|
|
165
|
+
return path.join(require('./character.cjs').characterDir(root), 'sounds');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** <soundsDir(root)>/<name>.wav; throws for a name not matching SOUND_NAME_RE. */
|
|
169
|
+
function soundFile(root, name) {
|
|
170
|
+
if (typeof name !== 'string' || !SOUND_NAME_RE.test(name)) throw new Error(`soundFile: invalid sound name "${name}"`);
|
|
171
|
+
return path.join(soundsDir(root), `${name}.wav`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module.exports = {
|
|
175
|
+
validateSounds,
|
|
176
|
+
validateMemberSfx,
|
|
177
|
+
fileBackedSoundNames,
|
|
178
|
+
findProjectSound,
|
|
179
|
+
wavFormatError,
|
|
180
|
+
checkSoundWav,
|
|
181
|
+
soundsDir,
|
|
182
|
+
soundFile,
|
|
183
|
+
SOUND_NAME_RE,
|
|
184
|
+
MAX_PROJECT_SFX,
|
|
185
|
+
MAX_PROJECT_BEDS,
|
|
186
|
+
MAX_MEMBER_SFX,
|
|
187
|
+
SOUND_NOTE_MAX,
|
|
188
|
+
MAX_SFX_WAV_BYTES,
|
|
189
|
+
MAX_BED_WAV_BYTES,
|
|
190
|
+
MAX_SOUNDS_TOTAL_BYTES,
|
|
191
|
+
};
|