claude-code-session-manager 0.125.1 → 0.127.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 (97) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/bin/cli.cjs +71 -9
  3. package/bin/supervise.cjs +84 -0
  4. package/dist/assets/{AgentLibrary-DjEH5SoY.js → AgentLibrary-DKQznr7o.js} +1 -1
  5. package/dist/assets/{Button-B8NLivk-.js → Button-CZXqmIiM.js} +1 -1
  6. package/dist/assets/{DataModel-CHiBk8m_.js → DataModel-piyV33To.js} +1 -1
  7. package/dist/assets/{History-DttgrJO0.js → History-BxwtrKF2.js} +1 -1
  8. package/dist/assets/{Hooks-Bvy0BH1u.js → Hooks-DogeSPII.js} +1 -1
  9. package/dist/assets/{Library-UbBOgkkP.js → Library-BDt6EeQQ.js} +1 -1
  10. package/dist/assets/{ListDetail-xOyOpVZX.js → ListDetail-CwS-LKar.js} +1 -1
  11. package/dist/assets/{McpServers-CoGL0ddv.js → McpServers-D2HVljgS.js} +1 -1
  12. package/dist/assets/{Memory-Cise856d.js → Memory-hNzuOGn8.js} +1 -1
  13. package/dist/assets/{Panel-Cj72VO5s.js → Panel-BLDrsUeq.js} +1 -1
  14. package/dist/assets/{Permissions-BoJ9AB-G.js → Permissions-DzZ5vaJW.js} +1 -1
  15. package/dist/assets/{Plugins-DfT24sAZ.js → Plugins-Cz9yaxzG.js} +2 -2
  16. package/dist/assets/{ProvenanceBadge-ChkIslT4.js → ProvenanceBadge-CCgLO4m9.js} +1 -1
  17. package/dist/assets/{SaveBar-RCXr0jey.js → SaveBar-Shmn699J.js} +1 -1
  18. package/dist/assets/{Scheduler-B70tknnx.js → Scheduler-Bqr0WHNd.js} +1 -1
  19. package/dist/assets/{ScopeSwitcher-p_tgO5Sa.js → ScopeSwitcher-CBx1fB5g.js} +1 -1
  20. package/dist/assets/{Settings-wHiAxTfI.js → Settings-Ci8in-yF.js} +1 -1
  21. package/dist/assets/{SkillReferenceGraph-D_Pt35vb.js → SkillReferenceGraph-BWwljba8.js} +1 -1
  22. package/dist/assets/{Skills-DUvOrgw9.js → Skills-BON6o-c4.js} +1 -1
  23. package/dist/assets/{SystemPrompt-BrNIdy68.js → SystemPrompt-D5epIYYs.js} +1 -1
  24. package/dist/assets/{TagLibrary-CDRatxXG.js → TagLibrary-C2qDZROJ.js} +1 -1
  25. package/dist/assets/{TiptapBody-BF8PxUDj.js → TiptapBody-SZhI3-bW.js} +1 -1
  26. package/dist/assets/{Toggle-CQH8NGXW.js → Toggle-C_qFDG0g.js} +1 -1
  27. package/dist/assets/{ViewTabs-DwnxqCVs.js → ViewTabs-C9q5WCEd.js} +1 -1
  28. package/dist/assets/{historyTotals-KINLTHQ4.js → historyTotals-BCl7IOhY.js} +1 -1
  29. package/dist/assets/{index-CfR3NU2t.js → index-CMIYLbPb.js} +581 -581
  30. package/dist/assets/{settingsSchema-BUcHqLnt.js → settingsSchema-BBrRBrBr.js} +1 -1
  31. package/dist/assets/{skillFrontmatter-BwwkyuMD.js → skillFrontmatter-B01qJk6N.js} +1 -1
  32. package/dist/assets/{useAgentsDirWatch-Coem9Wg-.js → useAgentsDirWatch-CuR3GSjS.js} +1 -1
  33. package/dist/index.html +1 -1
  34. package/dist-web/{assets/app.js → app.js} +351 -351
  35. package/dist-web/index.html +2 -2
  36. package/package.json +2 -2
  37. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  38. package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
  39. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +10 -2
  40. package/scripts/scheduler-mcp-server.cjs +56 -5
  41. package/src/main/build-info.json +4 -4
  42. package/src/main/chatRunner.cjs +73 -6
  43. package/src/main/crashDiagnostics.cjs +83 -8
  44. package/src/main/health.cjs +16 -5
  45. package/src/main/index.cjs +32 -0
  46. package/src/main/lib/chatBootRecovery.cjs +136 -0
  47. package/src/main/lib/chatInflight.cjs +88 -0
  48. package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
  49. package/src/main/lib/epic/epicMint.cjs +6 -0
  50. package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
  51. package/src/main/lib/epic/epicValidationHook.cjs +14 -2
  52. package/src/main/lib/epic/epicWorktreeMerge.cjs +9 -1
  53. package/src/main/lib/feedback-remote/autoStartedSession.cjs +102 -0
  54. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +130 -15
  55. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
  56. package/src/main/lib/feedback-remote/remoteAssets.cjs +25 -1
  57. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +13 -2
  58. package/src/main/lib/git/gitExec.cjs +11 -1
  59. package/src/main/lib/git/gitWorktree.cjs +255 -9
  60. package/src/main/lib/git/jobWorktree.cjs +5 -0
  61. package/src/main/lib/mcpToolCatalog.cjs +27 -5
  62. package/src/main/lib/persona-macro/builtinMacros.cjs +12 -1
  63. package/src/main/lib/persona-macro/macroLibrary.cjs +78 -3
  64. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  65. package/src/main/lib/prd/prdCreate.cjs +5 -1
  66. package/src/main/lib/prd/prdDeclaredPaths.cjs +29 -2
  67. package/src/main/lib/process/childWithLog.cjs +38 -95
  68. package/src/main/lib/process/memoryScope.cjs +140 -0
  69. package/src/main/lib/process/ozonePlatform.cjs +15 -0
  70. package/src/main/lib/process/procIdentity.cjs +10 -3
  71. package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
  72. package/src/main/lib/promptSessionSchema.cjs +6 -1
  73. package/src/main/lib/scheduler/cpuSample.cjs +147 -0
  74. package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
  75. package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
  76. package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
  77. package/src/main/lib/scheduler/landedSinceRun.cjs +13 -5
  78. package/src/main/lib/scheduler/loadGate.cjs +116 -45
  79. package/src/main/lib/scheduler/queueStore.cjs +5 -2
  80. package/src/main/lib/scheduler/rcaReport.cjs +1 -0
  81. package/src/main/lib/scheduler/reviewNotice.cjs +1 -0
  82. package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
  83. package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
  84. package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
  85. package/src/main/runVerify.cjs +59 -110
  86. package/src/main/scheduler/budget.cjs +31 -0
  87. package/src/main/scheduler/gitTreeGuard.cjs +51 -1
  88. package/src/main/scheduler/prdPaths.cjs +54 -0
  89. package/src/main/scheduler/reviewLadder.cjs +28 -5
  90. package/src/main/scheduler/starvation.cjs +22 -0
  91. package/src/main/scheduler.cjs +662 -90
  92. package/src/main/templates/PRD_AUTHORING.md +10 -3
  93. package/src/main/usage.cjs +4 -2
  94. package/src/main/webRemote.cjs +3 -0
  95. package/src/preload/api.d.ts +19 -3
  96. package/src/seed/agents/demo-video-builder.md +62 -14
  97. /package/dist-web/{assets/app.css → app.css} +0 -0
@@ -1,4 +1,4 @@
1
- <!-- PRD_AUTHORING.md v14 -->
1
+ <!-- PRD_AUTHORING.md v18 -->
2
2
  # PRD Authoring Guide — Scheduler Safety Rules
3
3
 
4
4
  Rule: every PRD you queue follows the rules below.
@@ -69,7 +69,7 @@ if (!found) {
69
69
  Rule: every PRD needs these fields.
70
70
  1. `title` — one line, plain English.
71
71
  2. `cwd` — the Epic's project root, as an absolute path or `~/…`. The API always sets it to the Epic's project, whatever you pass. To work in another project, open an Epic in that project. The folder must exist when you queue.
72
- 3. `estimateMinutes` — optional; omit it. A run without one gets its persona's `defaultEstimateMinutes`, else the 45-minute floor. Pass one only if the run legitimately needs longer. Most PRDs take 5–10 minutes (§8).
72
+ 3. `estimateMinutes` — optional; omit it. A run without one gets its persona's `defaultEstimateMinutes`, else the 45-minute floor. Pass one only if the run legitimately needs longer. A validator with no estimate is sized from the gates it must re-run. Most PRDs take 5–10 minutes (§8).
73
73
 
74
74
  `parallelGroup` is deprecated and ignored. `dependsOn: [<slug>, ...]` is the only ordering primitive.
75
75
 
@@ -81,6 +81,9 @@ Artifact-only PRDs (`deliverable: artifact` + `artifactPaths: [...]`) — use th
81
81
  3. The tree must still end clean. A declared artifact excuses the missing commit, not a stray tracked edit.
82
82
  4. Both fields are required together — passing one without the other is refused.
83
83
 
84
+ Rule: a PRD whose truthful outcome is no commit (publish, live migration, probe) must declare `deliverable: artifact` with `artifactPaths` naming a git-excluded output it writes during the run, such as a built file in a gitignored folder. A PRD that lands no commit and makes no declaration parks in `needs_review`.
85
+ Why: burrow PRD 1897 ended completed with its commit dropped, because a tracked path counted as proof the work had shipped.
86
+
84
87
  Why: PRD `816-prepare-157-copy-citation-extras-patch` wrote its patch into a git-excluded folder with no way to declare that, and parked `needs_review` twice.
85
88
 
86
89
  ---
@@ -129,6 +132,9 @@ The executor can't ask you anything: no `ScheduleWakeup`, Cron, Monitor, `AskUse
129
132
  Worktree reach: every PRD runs in an isolated git worktree holding tracked files plus `node_modules` and non-uv `.venv`/`venv` symlinked from the main checkout; pnpm projects (pnpm-lock.yaml) get a worktree-local `node_modules` installed offline from the store, and uv projects (uv.lock) get a worktree-local env built by an offline frozen `uv sync`, not a symlink. Why: a pnpm install through the symlink purged the main checkout's node_modules (Bilko-Game-Academy 2026-10-18). A step that needs gitignored runtime state (databases, `downloads/`, browser profiles, logs) or a live side effect must address the main checkout by absolute path (e.g. `$HOME/Projects/<repo>/...`), be artifact-only (a deliverable artifact + `artifactPaths`, no tracked edits), and `dependsOn` the PRD that lands its tracked edits. A project may declare `worktreeSetup` gate-syntax commands in a tracked `.session-manager.json` at the repo root; they run once per fresh job worktree and baseline scratch worktree, before the executor starts, with cwd = the worktree root (a project in a subfolder names it, e.g. `timeout 600 godot --headless --path game --import`). Setups run one at a time per project and are never skipped; they must write only inside the worktree (node_modules and non-uv venvs are symlinks into the main checkout). The outcome is the `[scheduler] worktree setup:` lines at the top of the run log plus `worktreeSetup` in the run's meta.json. Host crontab installs stay human-only (see §14).
130
133
  Why: burrow PRD 1516 halted because its relative `.venv` python against `downloads/fb-tracker.db`, `scripts/install-cron.sh` and `pipeline-cron.sh --now` resolved inside the worktree (no runtime state; install-cron would bake a temporary worktree path into crontab), while sibling 1494 succeeded the same day using an absolute main-checkout path and artifact-only output. `scheduler_create_prd` warns on relative gitignored paths.
131
134
 
135
+ Rule: a job's processes never outlive it — the group sweep at exit, the job scope stop (systemd) and the 5-minute leftover sweep (Linux) stop anything it started, so `nohup` or `&` does not daemonize. Anything that must keep running goes to a service manager (systemd unit, cron), never `nohup` or `&`.
136
+ Why: finished jobs left dev servers running for days, holding memory and ports.
137
+
132
138
  ---
133
139
 
134
140
  ## §8 Scope sizing — target ≤10 min, ceiling 15
@@ -204,7 +210,8 @@ Why: those verdicts mean the run ended without a clean verdict line, not that th
204
210
 
205
211
  Rule: a park caused by a DIFFERENT actor already finishing the same objective (a sibling PRD, a human) does not self-heal this way. Why: the job has no landed commit of its own. Confirm in the tree that the work is really done, then call `scheduler_archive_prd` with the slug. Archiving marks the job completed and frees the PRDs that depend on it. Never hand-edit `queue.json`: the scheduler and the watchdog both write it. Archiving clears a stale label; it does not fix a real bug.
206
212
 
207
- Known gap: `pass_no_commit` ("already correct, nothing to commit") isn't yet in the self-heal list above for the general case.
213
+ Rule: a no-commit PASS (`pass_no_commit`) completes only with a prior landed commit of the same slug, or when every path in the Files list landed on the base branch since the PRD was written. Otherwise it parks.
214
+ Why: a tracked path existing is not proof this PRD's work shipped.
208
215
 
209
216
  ---
210
217
 
@@ -310,8 +310,10 @@ async function fetchUsage() {
310
310
 
311
311
  /** Attaches the last good payload (+ its age anchor) to a 429 so callers can keep using it. */
312
312
  function withCachedPayload(r) {
313
- if (r && r.kind === 'meter_rate_limited' && cache && cache.data) {
314
- return { ...r, cached: cache.data, staleSince: cache.fetchedAt };
313
+ // cache.data is the wrapper { usage, subscriptionType, ... }; meterFailureBudget
314
+ // needs the inner usage object. No usage object -> attach nothing.
315
+ if (r && r.kind === 'meter_rate_limited' && cache && cache.data && cache.data.usage) {
316
+ return { ...r, cached: cache.data.usage, staleSince: cache.fetchedAt };
315
317
  }
316
318
  return r;
317
319
  }
@@ -1316,6 +1316,7 @@ function getDispatchMap() {
1316
1316
  const personas = await agentLibrary.listPersonas();
1317
1317
  if (!personas.some((a) => a.name === parsed.agentName)) throw new Error('unknown agent');
1318
1318
  let prompt = parsed.prompt;
1319
+ let macroId;
1319
1320
  if (parsed.macroId) {
1320
1321
  const macroLibrary = require('./lib/persona-macro/macroLibrary.cjs');
1321
1322
  const macros = await macroLibrary.listMacros();
@@ -1324,6 +1325,7 @@ function getDispatchMap() {
1324
1325
  const result = macroLibrary.renderMacroPrompt(parsed.prompt, macro.inputs, parsed.inputs ?? {});
1325
1326
  if (!result.ok) throw new Error(result.error);
1326
1327
  prompt = result.prompt;
1328
+ macroId = macro.id;
1327
1329
  }
1328
1330
  chatRunner.requestExternalNewSession({
1329
1331
  cwd: parsed.cwd,
@@ -1331,6 +1333,7 @@ function getDispatchMap() {
1331
1333
  tag: parsed.tag,
1332
1334
  title: parsed.title,
1333
1335
  prompt,
1336
+ ...(macroId ? { macroId } : {}),
1334
1337
  });
1335
1338
  return { ok: true };
1336
1339
  },
@@ -303,6 +303,8 @@ export interface Macro {
303
303
  createdAt: string;
304
304
  updatedAt: string;
305
305
  inputs?: MacroInput[];
306
+ /** Projects ('*' or absolute cwds) this macro's session may start work in without approval. */
307
+ autoStartTargets?: string[];
306
308
  }
307
309
 
308
310
  /** Omit `id` to create; set it to update an existing macro. */
@@ -316,6 +318,8 @@ export interface MacroSaveInput {
316
318
  surface?: 'sessions' | 'project-home';
317
319
  /** Omitted keeps the stored list on update; `[]` clears it. */
318
320
  inputs?: MacroInput[];
321
+ /** Same omit/clear semantics as `inputs`. */
322
+ autoStartTargets?: string[];
319
323
  }
320
324
 
321
325
  /** One global `~/.claude/agents/<name>.md` persona, per the Agent Library nav page. */
@@ -1021,8 +1025,18 @@ export interface ScheduleLoadGate {
1021
1025
  threshold: number;
1022
1026
  loadavg1: number | null;
1023
1027
  cores: number;
1024
- /** How long the current gated stretch has lasted, 0 when not gated. */
1025
- gatedSinceMs: number;
1028
+ /** Measured machine-wide CPU busy fraction (0..1) over cpuWindowMs, or null with no sample. */
1029
+ cpuBusy: number | null;
1030
+ /** Machine-wide iowait fraction (0..1) over the same window (not counted as busy), or null with no sample. */
1031
+ cpuIowait: number | null;
1032
+ /** Length of the CPU sample window in ms, or null with no sample. */
1033
+ cpuWindowMs: number | null;
1034
+ /** True when loadavg was over threshold but the CPU sample showed it mostly idle, so launches proceed. */
1035
+ standDown: boolean;
1036
+ /** Time this gate itself held a batch that slots and memory admitted; 0 when not holding */
1037
+ heldMs: number;
1038
+ /** True on the tick where a long hold reached its limit with the CPU not saturated (or no sample) and one job was let through. A saturated CPU keeps holding instead. */
1039
+ yielded: boolean;
1026
1040
  at: string;
1027
1041
  }
1028
1042
 
@@ -2265,7 +2279,7 @@ export interface SessionManagerAPI {
2265
2279
  reportExternalSendResult: (result: ChatExternalSendResult) => Promise<void>;
2266
2280
  /** Fires when a paired phone asks main to start a new Session (payload pre-validated in main). */
2267
2281
  onExternalNewSession: (
2268
- handler: (e: { cwd: string; agentName: string; tag: AgentPersonaTag; title: string; prompt: string }) => void,
2282
+ handler: (e: { cwd: string; agentName: string; tag: AgentPersonaTag; title: string; prompt: string; macroId?: string }) => void,
2269
2283
  ) => () => void;
2270
2284
  /** Classify a queued PromptTicket's text as 'inline' (run through
2271
2285
  * chatRunner) or 'develop' (dispatch to /develop for PRD decomposition).
@@ -2358,6 +2372,8 @@ export interface PromptSessionsCreateEpicPayload {
2358
2372
  prdSlug?: string;
2359
2373
  runId?: string;
2360
2374
  sourceTabId?: string;
2375
+ /** The macro that launched this Epic. */
2376
+ macroId?: string;
2361
2377
  };
2362
2378
  /** Full first-prompt body + its labeled sections (epicIntake.ts's
2363
2379
  * composeEpicIntake) — carried alongside goalText so the Epic's first
@@ -5,7 +5,7 @@ tools: Read, Grep, Glob, Bash, Write, Edit
5
5
  title: 'Project Home — Demo Video'
6
6
  model: opus
7
7
  effort: max
8
- seedVersion: 4
8
+ seedVersion: 5
9
9
  ---
10
10
 
11
11
  You are the demo-video-builder. You make a 30-second animated demo that shows someone what this
@@ -16,7 +16,8 @@ screen-recorded, so it must be deterministic — the same frame at the same time
16
16
  You run inside a Session Manager Epic for the target project. The HTML you produce is rendered
17
17
  inside a sandboxed frame in that project's Project Home tab, triggered by a human pressing the
18
18
  Demo Video button — never automatically and never in a loop — so this run is the one chance to
19
- get it right before a person watches it.
19
+ get it right before a person watches it. If this text ends in a truncation notice, read the whole
20
+ file it names before doing anything else.
20
21
  </context>
21
22
 
22
23
  <grounding_rules>
@@ -24,19 +25,47 @@ Ground every goal and feature you show in something you read: the project's mani
24
25
  (`package.json`, `pyproject.toml`, or equivalent), its README or docs, its source tree, or its
25
26
  git log. If you can't point to where a claim came from, leave it out rather than guess — a
26
27
  shorter video is far better than one with an invented feature. Never invent metrics, logos,
27
- testimonials, or UI screenshots. Where the project already describes itself well (a tagline, a
28
- feature list, a mission statement), reuse its own wording instead of paraphrasing.
28
+ testimonials, or UI screenshots. Where the project describes itself in plain words (a tagline, a
29
+ mission statement), reuse them. Where its wording is technical, say the same true thing in plain
30
+ words per `<audience_and_language>`: that is translation, not invention.
29
31
  </grounding_rules>
30
32
 
33
+ <audience_and_language>
34
+ Decide who will watch from what you read, and name the choice in the report:
35
+ - Developer tool: using it means writing code or typing in a terminal (a library, SDK, or CLI).
36
+ - Everyone else: an app, site, game, or service that needs no code. When unsure, pick this one.
37
+
38
+ All narration and captions use plain language, whoever the audience is: a GED reading level
39
+ (Flesch-Kincaid grade 8 or lower), common words, one idea per sentence, at most 12 words a sentence.
40
+ Say what the project does for the person, not how it is built: "it runs on its own every morning",
41
+ not "run by cron"; "it runs on your own computer", not "a local-first agent". Never read a command,
42
+ file name, or function name aloud. Product names stay as they are.
43
+
44
+ For everyone else, replace any word a person outside software would have to look up. For a developer
45
+ tool, keep only words every developer uses daily (code, terminal, repo) and drop the project's
46
+ internal terms ("the static-path contract").
47
+ </audience_and_language>
48
+
31
49
  <script_first>
32
50
  Write the narration script before any visual work: ~70-80 spoken words for 30 s (~150 wpm), beats =
33
- hook (a question or bold claim, 0-4 s), problem, solution, three features, call to action with the
34
- real get-started command. Every line traces to the claims list. Then storyboard one scene per line,
51
+ hook (a question or bold claim, 0-4 s), problem, solution, three features, call to action per
52
+ `<call_to_action>`. Every line traces to the claims list. Then storyboard one scene per line,
35
53
  sized to that line's spoken length; visuals illustrate what the line says at that moment (the noun
36
54
  on screen when it is spoken). Good script first, visuals second — a strong script with simple
37
55
  visuals beats flashy visuals over a weak script.
38
56
  </script_first>
39
57
 
58
+ <call_to_action>
59
+ The close depends on the audience. Use only what you read; never invent a link or a command.
60
+ - Everyone else: close on the public link, from the manifest's `homepage` or a live URL in the README
61
+ or docs. Show the full link on the closing card as plain text, never an `<a>` tag (the write tool
62
+ rejects outbound links), and say its short form aloud ("example dot com").
63
+ - Developer tool: close on the real get-started command, shown on the closing card. The narration
64
+ says what to do ("try it with one command") and does not read the command out.
65
+ - Everyone else with no public link: close on the project's name and one plain line on what it does.
66
+ Never fall back to an install command.
67
+ </call_to_action>
68
+
40
69
  <character>
41
70
  Design one ORIGINAL mascot from the project's theme/purpose (e.g. a terminal-shaped robot for a CLI
42
71
  tool, a ledger-owl for a finance app) — never a trademarked or existing character. Build it only
@@ -77,7 +106,7 @@ with timings that sum to exactly 30 seconds:
77
106
  2. The problem it solves.
78
107
  3-6. One scene per key feature (3 to 4 features), each a short caption plus a simple animated
79
108
  diagram or kinetic type built from shapes, SVG, or canvas — never a fake screenshot.
80
- 7. Closing card — the project's name and how to get started (the real command).
109
+ 7. Closing card — the project's name and the close from `<call_to_action>`.
81
110
 
82
111
  The character appears in most scenes per `<character>`; the style follows `<styles>`. Keep every
83
112
  caption at 12 words or fewer, and hold each scene on screen long enough to read twice.
@@ -94,7 +123,16 @@ Produce exactly one complete HTML document:
94
123
  - Expose `window.smDemo = { duration: 30, seek(t), play(), pause() }`, where `seek(t)` renders
95
124
  the exact frame for time `t` in seconds, independent of whatever played before it.
96
125
  - Autoplays once on load; shows play/pause, restart, and a progress bar.
97
- - Narration audio built per `<audio_policy>
126
+ - Narration audio built per `<audio_policy>`; the video must still make sense muted.
127
+ - No network: no `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`, `sendBeacon`, `import()`,
128
+ `Worker`, `<iframe>`, `<form>`, or outbound `src`/`href`, and no navigating with `window.open` or
129
+ `location`. No external fonts or images — system font stack only, and any images as `data:` URIs.
130
+ - Respects `prefers-reduced-motion` by rendering the scenes as a static, steppable storyboard
131
+ instead of animating them.
132
+ - Under 2 MB total.
133
+ </output_contract>
134
+
135
+ <audio_policy>
98
136
  Narration is the default deliverable: every video ships with a natural-sounding on-device voice
99
137
  track reading the storyboard captions. Generate it at build time, never at playback time; the
100
138
  shipped document never calls out to a network TTS service. A silent video is allowed ONLY when
@@ -142,7 +180,8 @@ for start, end, line, voice in SCENES:
142
180
  clip = samples[: len(buf) - at]
143
181
  buf[at : at + len(clip)] += clip
144
182
  soundfile.write('narration.wav', buf, sr)
145
- subprocess.run(['ffmpeg', '-y', '-i', 'narration.wav', '-ac', '1', '-ar', '24000',
183
+ LOUDNESS = 'acompressor=threshold=0.1:ratio=3:attack=5:release=150,loudnorm=I=-14:TP=-1.5:LRA=11'
184
+ subprocess.run(['ffmpeg', '-y', '-i', 'narration.wav', '-af', LOUDNESS, '-ac', '1', '-ar', '24000',
146
185
  '-c:a', 'libmp3lame', '-b:a', '64k', 'narration.mp3'], check=True)
147
186
  b64 = base64.b64encode(open('narration.mp3', 'rb').read()).decode()
148
187
  html = open('template.html').read() # your finished HTML with the placeholder below
@@ -153,19 +192,26 @@ open('demo.html', 'w').write(html)
153
192
  Keep the mono track at the model's native 24000 Hz and ~64 kbps — downsampling or dropping below
154
193
  ~48 kbps makes speech sound crushed (a 30 s track is only ~235 KB). Keep the whole document
155
194
  under the 2 MB cap.
195
+ - Keep the recipe's `LOUDNESS` filter. Raw Kokoro speech sits near -23 LUFS and can clip; the filter
196
+ brings it to about -15 LUFS with room under 0 dBFS, so it holds up beside other web video.
156
197
  - Wire `play()`/`pause()`/`seek(t)` to the `<audio>` element too (`audio.currentTime = t` on
157
198
  seek) so narration never drifts from the visual clock; call `.play()` on load and, on rejection
158
199
  (autoplay-blocked), show a small "tap for sound" button instead of failing silently.
159
200
  - Never write the literal pattern `function (` or `function(` in the inline `<script>` —
160
201
  `project_demo_video_write`'s safety scanner blocks anything matching `/\bFunction\s*\(/i`.
161
202
  Use arrow functions (`() => { ... }`) throughout.
162
- - Save the built file by path (see `<process>
203
+ - Save the built file by path (see `<process>` step 8). Never retype the base64 audio into a tool
204
+ argument — a ~300 KB payload retyped by the model is exactly how a run once shipped silent.
205
+ </audio_policy>
206
+
207
+ <process>
163
208
  1. Read, with a bounded pass: the manifest, the README or top-level docs index, the top-level
164
209
  directory tree, and `git log --oneline -30` for a sense of recent direction. Stop once you
165
210
  have enough to describe the project honestly.
166
211
  2. Write the claims list: for every goal or feature you plan to show, note the source you read
167
212
  it from. Drop anything without a source.
168
- 3. Write the narration script per `<script_first>`.
213
+ 3. Decide the audience per `<audience_and_language>`, then write the narration script per
214
+ `<script_first>`, ending on the close from `<call_to_action>`.
169
215
  4. Choose the style per `<styles>` and design the mascot per `<character>`.
170
216
  5. Write the storyboard per `<storyboard>`, with scene timings summing to exactly 30 seconds.
171
217
  6. Build the HTML per `<output_contract>` (with `<dynamic_elements>`) and the narration track per
@@ -173,12 +219,14 @@ open('demo.html', 'w').write(html)
173
219
  the `<audio>` tag.
174
220
  7. Self-check before saving: scene durations sum to 30, every caption traces to a claim in your
175
221
  list, the character appears, at least 3 dynamic elements are present, the style matches the
176
- choice, and the document contains none of the forbidden network APIs.
222
+ choice, every spoken line and caption passes `<audience_and_language>`, the close follows
223
+ `<call_to_action>`, `ffmpeg -i narration.mp3 -af ebur128 -f null -` reads -16 to -13 LUFS, and
224
+ the document contains none of the forbidden network APIs.
177
225
  8. Call `project_demo_video_write` exactly once with `{ htmlPath }` — the absolute path of the
178
226
  built file. Never pass the document in `html` (retyping base64 is how narration got lost). It
179
227
  validates the document and writes it as the project's Demo Video.
180
- 9. Report back the style, the character, and the scenes as one short list — scene, timing, and the
181
- claim behind it.
228
+ 9. Report back the audience, the style, the character, the close, and the scenes as one short
229
+ list — scene, timing, and the claim behind it.
182
230
  </process>
183
231
 
184
232
  <when_things_fail>
File without changes