decklight 0.8.1 → 0.10.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 (138) hide show
  1. package/PLATFORM.md +707 -0
  2. package/README.md +226 -150
  3. package/SPEC.md +803 -888
  4. package/cli/agent-review.mjs +246 -0
  5. package/cli/agents.mjs +35 -9
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +190 -0
  10. package/cli/bundle-module.mjs +95 -0
  11. package/cli/bundle.mjs +439 -35
  12. package/cli/cast.mjs +48 -12
  13. package/cli/check-fixes.mjs +186 -0
  14. package/cli/check.mjs +988 -0
  15. package/cli/clone-deck.mjs +179 -0
  16. package/cli/commands.mjs +345 -0
  17. package/cli/comments.mjs +64 -18
  18. package/cli/commit-flow.mjs +51 -22
  19. package/cli/commit-message.mjs +51 -74
  20. package/cli/commit-split.mjs +601 -0
  21. package/cli/deck-refs.mjs +64 -0
  22. package/cli/deck-routes.mjs +67 -0
  23. package/cli/deckfile.mjs +3 -5
  24. package/cli/decklight.mjs +68 -289
  25. package/cli/design-system-deps.mjs +209 -0
  26. package/cli/design-system-edit.mjs +194 -0
  27. package/cli/design-system-refs.mjs +666 -0
  28. package/cli/design-system.mjs +497 -0
  29. package/cli/doctor.mjs +115 -0
  30. package/cli/edit-git.mjs +353 -0
  31. package/cli/edit-handover.mjs +551 -0
  32. package/cli/edit-look.mjs +631 -0
  33. package/cli/edit-slides.mjs +683 -0
  34. package/cli/edit.mjs +2585 -855
  35. package/cli/enhance.mjs +485 -0
  36. package/cli/extension.mjs +10 -10
  37. package/cli/font-refs.mjs +273 -0
  38. package/cli/font.mjs +246 -0
  39. package/cli/git-tree.mjs +1 -1
  40. package/cli/git.mjs +78 -11
  41. package/cli/import.mjs +56 -10
  42. package/cli/init.mjs +407 -236
  43. package/cli/library.mjs +127 -0
  44. package/cli/loader.mjs +3 -1
  45. package/cli/marketplace-autocheck.mjs +200 -0
  46. package/cli/marketplace.mjs +460 -29
  47. package/cli/narrate.mjs +251 -0
  48. package/cli/open-browser.mjs +63 -0
  49. package/cli/open.mjs +961 -0
  50. package/cli/pdf.mjs +64 -17
  51. package/cli/pkg.mjs +44 -2
  52. package/cli/plugin.mjs +43 -41
  53. package/cli/port-conflict.mjs +53 -23
  54. package/cli/pptx-export.mjs +63 -27
  55. package/cli/publish.mjs +8 -4
  56. package/cli/qr.mjs +1 -1
  57. package/cli/record.mjs +85 -23
  58. package/cli/remote.mjs +43 -17
  59. package/cli/restore.mjs +11 -4
  60. package/cli/review-ref.mjs +125 -0
  61. package/cli/review-remote.mjs +92 -48
  62. package/cli/review-routes.mjs +254 -0
  63. package/cli/review-store.mjs +47 -7
  64. package/cli/review-submit.mjs +47 -57
  65. package/cli/runtime-link.mjs +560 -0
  66. package/cli/serve.mjs +236 -45
  67. package/cli/setup.mjs +112 -0
  68. package/cli/sign.mjs +1 -1
  69. package/cli/skill-content.mjs +229 -35
  70. package/cli/skills.mjs +353 -26
  71. package/cli/start.mjs +110 -0
  72. package/cli/supervise.mjs +6 -6
  73. package/cli/theme-refs.mjs +527 -0
  74. package/cli/theme.mjs +181 -137
  75. package/cli/trust.mjs +83 -0
  76. package/cli/units.mjs +112 -47
  77. package/cli/update-check.mjs +1 -5
  78. package/cli/upgrade.mjs +194 -28
  79. package/cli/upstream.mjs +4 -3
  80. package/cli/util.mjs +4 -4
  81. package/cli/wizard.mjs +6 -6
  82. package/dist/build-info.json +1 -1
  83. package/dist/decklight.css +1533 -59
  84. package/dist/decklight.js +258 -115
  85. package/dist/decklight.js.map +4 -4
  86. package/docs/GLOSSARY.md +141 -0
  87. package/docs/architecture.svg +17 -17
  88. package/package.json +4 -2
  89. package/themes/README.md +9 -8
  90. package/themes/reveal-solarized.css +10 -0
  91. package/tools/args.mjs +20 -0
  92. package/tools/atomic-write.mjs +48 -0
  93. package/tools/brand-palette.mjs +717 -0
  94. package/tools/bridge.mjs +1 -1
  95. package/tools/build-groups.mjs +42 -0
  96. package/tools/color.mjs +48 -0
  97. package/tools/deck-html.mjs +396 -11
  98. package/tools/design-system-format.mjs +778 -0
  99. package/tools/design-system-migrations.mjs +207 -0
  100. package/tools/elevenlabs-tts.mjs +110 -17
  101. package/tools/exec.mjs +11 -3
  102. package/tools/extension-check.mjs +31 -7
  103. package/tools/font-format.mjs +190 -0
  104. package/tools/font-stacks.mjs +24 -0
  105. package/tools/gemini-tts.mjs +3 -0
  106. package/tools/lipsync-config.mjs +103 -0
  107. package/tools/lipsync-engines.mjs +205 -2
  108. package/tools/lipsync-server.mjs +264 -41
  109. package/tools/lipsync.mjs +37 -18
  110. package/tools/local-voice.mjs +32 -42
  111. package/tools/narration-manifest.mjs +270 -0
  112. package/tools/narration-synth.mjs +416 -0
  113. package/tools/pptx.mjs +776 -19
  114. package/tools/publish-targets.mjs +1 -1
  115. package/tools/publish-voices.mjs +3 -3
  116. package/tools/recording-impact.mjs +7 -3
  117. package/tools/render-theme.mjs +33 -0
  118. package/tools/review-anchor.mjs +28 -12
  119. package/tools/semver.mjs +40 -0
  120. package/tools/sentences.mjs +180 -0
  121. package/tools/shot.mjs +14 -7
  122. package/tools/site-clip.mjs +114 -0
  123. package/tools/site-voices.mjs +232 -0
  124. package/tools/template-theme.mjs +1 -1
  125. package/tools/test-impact.mjs +17 -10
  126. package/tools/theme-check.mjs +30 -3
  127. package/tools/tts-cache.mjs +4 -3
  128. package/tools/tts-engines.mjs +38 -20
  129. package/tools/tts-setup.mjs +7 -7
  130. package/tools/video-options.mjs +34 -0
  131. package/tools/video.mjs +530 -54
  132. package/tools/voiceover-server.mjs +185 -104
  133. package/tools/voiceover.mjs +119 -261
  134. package/tools/zip.mjs +1 -1
  135. package/cli/dev.mjs +0 -623
  136. package/cli/present.mjs +0 -853
  137. package/cli/review.mjs +0 -361
  138. package/tools/publish-site-voices.mjs +0 -75
@@ -24,7 +24,7 @@ import { run, PROBE_MS } from './exec.mjs';
24
24
  // beats a bridge that starts and never speaks.
25
25
 
26
26
  const PIPER_SUGGEST = 'piper is the free offline voice — install it with '
27
- + '`uv tool install piper-tts`, then run `decklight tts --engine piper`';
27
+ + '`uv tool install piper-tts`, then run `decklight setup voice`';
28
28
 
29
29
  /** `say -v '?'` on macOS: one voice per line, name, locale, sample sentence. */
30
30
  export const SAY_LIST = ['-v', '?'];
@@ -117,6 +117,23 @@ const QUALITY_SUFFIX = /\s*\((?:Personal Voice|Siri[^)]*|Premium|Neural|Enhanced
117
117
  /** `Daniel (Enhanced)` → `Daniel`; `Eddy (English (UK))` → unchanged. */
118
118
  export const plainName = (name) => String(name ?? '').replace(QUALITY_SUFFIX, '').trim();
119
119
 
120
+ /**
121
+ * macOS 27 names a plain voice by its language too — `Daniel (English (UK))`,
122
+ * `Samantha (English (US))`, where earlier releases said `Daniel` and
123
+ * `Samantha`. A language-and-region pair, always nested exactly this way; a
124
+ * quality marker (`(Enhanced)`) is never nested, so the two cannot be taken for
125
+ * each other.
126
+ */
127
+ const LANGUAGE_SUFFIX = /\s*\([^()]+\([^()]+\)\)\s*$/;
128
+
129
+ /**
130
+ * The name under both suffixes: `Daniel (English (UK))` and `Daniel (Enhanced)`
131
+ * are both `Daniel`. For MATCHING only — a row keeps the name `say -v` was
132
+ * given, because the two are different builds: on macOS 27 `say -v Daniel`
133
+ * speaks the Enhanced one and `say -v "Daniel (English (UK))"` the compact one.
134
+ */
135
+ export const baseName = (name) => plainName(name).replace(LANGUAGE_SUFFIX, '').trim();
136
+
120
137
  /**
121
138
  * Drop a plain voice that is the SAME VOICE as a better one beside it.
122
139
  *
@@ -162,7 +179,10 @@ export function withoutSupersededPlain(voices = [], { keep } = {}) {
162
179
  return voices.filter((v) => {
163
180
  if (!Number.isInteger(v?.tier) || v.tier !== PLAIN_TIER) return true;
164
181
  if (keep && v.name === keep) return true;
165
- return !better.has(`${(v.locale || '').toLowerCase()}\u0000${v.name}`);
182
+ // by BASE name: on macOS 27 the plain twin of `Daniel (Enhanced)` is
183
+ // listed as `Daniel (English (UK))`, and matching the whole name let every
184
+ // one of them through
185
+ return !better.has(`${(v.locale || '').toLowerCase()}\u0000${baseName(v.name)}`);
166
186
  });
167
187
  }
168
188
 
@@ -189,7 +209,13 @@ export function parseSayVoices(stdout, { lang } = {}) {
189
209
  const name = m[1].trim();
190
210
  if (!name) continue;
191
211
  const sample = (m[3] ?? '').trim();
192
- out.push({ name, locale: m[2].replace('-', '_'), tier: sayTier(name, sample), sample });
212
+ const locale = m[2].replace('-', '_');
213
+ // macOS 27 prints some voices twice, line for line — one voice, and a
214
+ // picker that offered it twice would be offering nothing more. Line for
215
+ // line means the SAMPLE too: a Siri voice listed under a plain voice's name
216
+ // differs only there, and is the other rule's to drop (below).
217
+ if (out.some((v) => v.name === name && v.locale === locale && v.sample === sample)) continue;
218
+ out.push({ name, locale, tier: sayTier(name, sample), sample });
193
219
  }
194
220
  // the unaddressable Siri duplicates (see above), and the `((null))`
195
221
  // artifacts an undownloaded Siri stub can leave in the listing — both are
@@ -355,7 +381,7 @@ export function detectLocalVoice({
355
381
  engine: null,
356
382
  why: 'Android has a system voice, but only as an in-app Java API — there is no '
357
383
  + 'command line behind it, so nothing here can drive it',
358
- suggest: 'record the narration on a desktop (decklight tts, then V → Record this deck…) and ship the '
384
+ suggest: 'record the narration on a desktop (decklight <deck>, then V → Record this deck…) and ship the '
359
385
  + 'audio with the deck — a recorded track needs no bridge at all',
360
386
  };
361
387
  }
@@ -376,7 +402,7 @@ export function detectLocalVoice({
376
402
  caveat: 'the best voices here are Siri’s, a free download: System Settings '
377
403
  + '→ Accessibility → Spoken Content → System Voice → Manage Voices… '
378
404
  + '(open it with: open "x-apple.systempreferences:com.apple.preference.universalaccess") '
379
- + '— then restart decklight tts',
405
+ + '— then open the deck again',
380
406
  }),
381
407
  };
382
408
  }
@@ -399,7 +425,7 @@ export function detectLocalVoice({
399
425
  ...(voices.some((v) => v.tier === 0) ? {} : {
400
426
  caveat: 'the best voices here are Windows’ natural ones, a free download: Settings '
401
427
  + '→ Accessibility → Narrator → Add natural voices '
402
- + '(open it with: start ms-settings:easeofaccess-narrator) — then restart decklight tts',
428
+ + '(open it with: start ms-settings:easeofaccess-narrator) — then open the deck again',
403
429
  }),
404
430
  };
405
431
  }
@@ -426,39 +452,3 @@ export function detectLocalVoice({
426
452
  suggest: PIPER_SUGGEST,
427
453
  };
428
454
  }
429
-
430
- /**
431
- * Ollama, which is not a speech engine and is the single most common thing a
432
- * local-AI user expects to be one.
433
- *
434
- * It is probed only so the answer can be honest. Serving LLMs is not serving
435
- * speech: there is no audio endpoint, and the models people name in this
436
- * context (Kokoro, Orpheus) either are not Ollama models or need a separate
437
- * audio decoder Ollama does not run.
438
- */
439
- export const OLLAMA_URL = 'http://127.0.0.1:11434/api/tags';
440
-
441
- export async function ollamaRunning({ fetchImpl = fetch, timeoutMs = 300 } = {}) {
442
- // A machine without Ollama must not pay for the question. The signal alone is
443
- // not enough: it only helps if the implementation honors it, and a socket
444
- // that hangs before the abort lands would stall dev's startup — which is the
445
- // one thing this budget exists to prevent. So the timeout is RACED, and the
446
- // abort is the courtesy that lets the request stop early.
447
- const ac = new AbortController();
448
- let timer;
449
- const expired = new Promise((done) => {
450
- timer = setTimeout(() => { ac.abort(); done(null); }, timeoutMs);
451
- });
452
- try {
453
- const answered = Promise.resolve()
454
- .then(() => fetchImpl(OLLAMA_URL, { signal: ac.signal }))
455
- .catch(() => null);
456
- const r = await Promise.race([answered, expired]);
457
- return !!r?.ok;
458
- } finally {
459
- clearTimeout(timer);
460
- }
461
- }
462
-
463
- export const OLLAMA_NOTE = 'Ollama is running, but it serves LLMs and cannot speak — '
464
- + 'it has no speech endpoint';
@@ -0,0 +1,270 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * A narration track's manifest.json — what the synthesis core writes
6
+ * (tools/narration-synth.mjs, behind `decklight narrate`) and
7
+ * the deck's own synthesized recorder now writes too (#535), so the two are
8
+ * interchangeable to everything that reads one: `decklight video`, the export
9
+ * dialog, the narration picker.
10
+ *
11
+ * { engine, model, voice, style, slides: [{ file, hash, segments: [{ file }] } | null] }
12
+ *
13
+ * `hash` is the CLIP KEY shortened — the same key the on-disk clip cache files
14
+ * a sentence under — computed over the slide's whole cleaned notes, so "is
15
+ * this folder still the deck's notes?" (`video`, #536) and "has anyone paid
16
+ * for these words?" (the cache) are one definition, never two.
17
+ */
18
+
19
+ import { createHash } from 'node:crypto';
20
+ import { cacheKey } from './tts-cache.mjs';
21
+ import { readsAudioTags } from './elevenlabs-tts.mjs';
22
+ import { sectionBodies, NOTES_ASIDE, cleanNotes, readNotes, isHiddenSection, notesSegments } from './deck-html.mjs';
23
+ import { deckConfig } from '../cli/runtime-link.mjs';
24
+ import { PAUSE_MARK } from './sentences.mjs';
25
+
26
+ /**
27
+ * Each slide's notes as WRITTEN — the notes aside's markup, or a markdown
28
+ * Note: block, ⟨CLICK⟩ markers and all; '' for a hidden slide (no file, and
29
+ * the numbering stays) or one with no notes. Index i is slide i+1. The raw
30
+ * form is what the ⟨CLICK⟩ beats are cut from (tools/narration-synth.mjs), so
31
+ * every marker comes back in its canonical form (`readNotes`): entity
32
+ * brackets, `[click]`, `<pause>` and the rest, the way the runtime reads them.
33
+ */
34
+ export function slideNotes(html) {
35
+ return sectionBodies(html).map((sec) => {
36
+ if (isHiddenSection(sec)) return '';
37
+ const aside = sec.match(NOTES_ASIDE);
38
+ if (aside) return readNotes(aside[1]);
39
+ const md = sec.match(/^Note:\s*$([\s\S]*?)(?=^Rehearse:\s*$|<\/script>)/m);
40
+ return md ? readNotes(md[1]) : '';
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Each slide's narration text, from the deck FILE — exactly what the
46
+ * synthesis core voices (tools/narration-synth.mjs): the notes, ⟨CLICK⟩
47
+ * markers removed, whitespace collapsed; '' for a hidden slide or one with no
48
+ * notes. Index i is slide i+1.
49
+ *
50
+ * ⟨PAUSE⟩ markers STAY (#560). A recording bakes the hold into its audio, so
51
+ * a take made before a marker was added — or moved — is not the deck's take
52
+ * any more, and this is the text the hash is taken over. A slide with no
53
+ * marker reads exactly as it did before markers existed: no track churns.
54
+ */
55
+ export const slideTexts = (html) => slideNotes(html).map((raw) => (raw ? cleanNotes(raw, { marks: true }) : ''));
56
+
57
+ /**
58
+ * Each slide's narration text as this file read it before it decoded entities
59
+ * beyond `&lt; &gt; &amp;` — `&mdash;` was the letters of its name, and a
60
+ * marker written with entity brackets was not a marker.
61
+ *
62
+ * Only the DECK's recorder (`recorder: 'deck'`) needs it: it voiced the
63
+ * browser's reading, which always decoded, but was stamped over this one, so a
64
+ * slide of it whose stamp matches this text is still these words — not stale
65
+ * because the reader got better. A track the synthesis core voiced from this
66
+ * text spoke the entity's name, and being flagged is the fix.
67
+ */
68
+ export const priorSlideTexts = (html) => sectionBodies(html).map((sec) => {
69
+ if (isHiddenSection(sec)) return '';
70
+ const raw = sec.match(NOTES_ASIDE)?.[1] ?? sec.match(/^Note:\s*$([\s\S]*?)(?=^Rehearse:\s*$|<\/script>)/m)?.[1];
71
+ return raw ? raw.replace(/⟨CLICK⟩/g, ' ').replace(/⟨PAUSE⟩/g, ` ${PAUSE_MARK} `).replace(/<[^>]+>/g, ' ')
72
+ .replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&')
73
+ .replace(/\s+/g, ' ').trim() : '';
74
+ });
75
+
76
+ /**
77
+ * The built-in beat pause, mirrored from the runtime (src/core/narration.js
78
+ * `BEAT_PAUSE_S`), which the CLI may not import; test/narration-manifest
79
+ * pins the two together, the way test/video pins the slide pause.
80
+ */
81
+ export const BEAT_PAUSE_DEFAULT = 0.5;
82
+
83
+ /**
84
+ * Seconds one ⟨PAUSE⟩ holds on each slide: two beat pauses (#560), resolved
85
+ * the way the runtime's `pauseFor` resolves every narration pause — the
86
+ * section's `data-narration-beat-pause`, else the configuration block's
87
+ * `narration.beatPause`, else the default; a value that is not a finite
88
+ * number ≥ 0 falls through to the next tier. Read off the section's OPEN tag,
89
+ * so the attribute in a slide's content is never mistaken for the slide's.
90
+ * Index i is slide i+1.
91
+ */
92
+ export function markerPauses(html) {
93
+ const cfg = deckConfig(html)?.narration?.beatPause;
94
+ const deck = typeof cfg === 'number' && Number.isFinite(cfg) && cfg >= 0 ? cfg : BEAT_PAUSE_DEFAULT;
95
+ return sectionBodies(html).map((sec) => {
96
+ const raw = sec.slice(0, sec.indexOf('>')).match(/\sdata-narration-beat-pause="([^"]*)"/)?.[1];
97
+ const n = raw != null && raw.trim() !== '' ? Number(raw) : NaN;
98
+ return 2 * (Number.isFinite(n) && n >= 0 ? n : deck);
99
+ });
100
+ }
101
+
102
+
103
+ /**
104
+ * The key fields for a manifest header, the way `clipKey` derives them from
105
+ * an engine object (tools/tts-cache.mjs) — spelled out per engine here
106
+ * because a manifest is written where no engine object exists: the author
107
+ * server writing the deck recorder's take knows only what the bridge said of
108
+ * itself. The traits are the engines' own (tools/tts-engines.mjs):
109
+ * piper voiceIsFixed — the model IS the voice, and it is what is keyed
110
+ * say, sapi modelIsDefaultVoice — the spoken voice is keyed, the boot voice is not
111
+ * elevenlabs voice and model both; a delivery style only on eleven_v3 / v4
112
+ * chirp voice and its one model; no style
113
+ * gemini voice and model; the one engine every style reaches
114
+ * `format` is the audio's extension, wav unless a header says otherwise —
115
+ * ElevenLabs alone can be told to speak mp3.
116
+ */
117
+ export function manifestKey({ engine, model, voice, style, format } = {}, text) {
118
+ const e = engine ?? '';
119
+ const fixed = e === 'piper';
120
+ const defaultVoice = e === 'say' || e === 'sapi';
121
+ const stylable = e === 'gemini' || (e === 'elevenlabs' && readsAudioTags(model));
122
+ return cacheKey({
123
+ engine: e,
124
+ model: fixed || defaultVoice ? undefined : (model ?? undefined),
125
+ format: format ?? 'wav',
126
+ voice: fixed ? model : defaultVoice ? (voice ?? model) : voice,
127
+ style: stylable ? style : undefined,
128
+ text,
129
+ });
130
+ }
131
+
132
+ /** The manifest's per-slide hash: the clip key, shortened (voiceover.mjs `slideHash`). */
133
+ export const manifestHash = (header, text) => manifestKey(header, text).slice(0, 16);
134
+
135
+ /**
136
+ * The hash a manifest written before the key carried `model` used
137
+ * (voiceover.mjs `legacyHash`): accepted for a header that predates the
138
+ * field, so a folder recorded then is not flagged for a formula change.
139
+ */
140
+ export const legacyHash = ({ engine, voice, style } = {}, text) => createHash('sha256')
141
+ .update(`${engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
142
+
143
+ /** Does this manifest slide entry vouch for `text`, under its header? */
144
+ export function entryMatches(header, entry, text) {
145
+ if (!entry?.hash) return true; // a hand-recorded take carries no hash to disagree
146
+ if (entry.hash === manifestHash(header, text)) return true;
147
+ return header?.model === undefined && entry.hash === legacyHash(header, text);
148
+ }
149
+
150
+ /**
151
+ * The slides of `manifest` whose audio was voiced from other notes than
152
+ * `texts` — 1-based, within `range` (default: every slide the manifest has).
153
+ * `hashless` counts the entries with no hash at all, which are exempt and
154
+ * worth one line rather than a verdict. `prior` (`priorSlideTexts`) lets a
155
+ * deck-recorded slide stamped under the old reading of the file stand.
156
+ */
157
+ export function staleSlides(manifest, texts, range = null, prior = null) {
158
+ const out = { stale: [], hashless: 0 };
159
+ const slides = manifest?.slides ?? [];
160
+ for (let i = 0; i < slides.length; i++) {
161
+ const n = i + 1;
162
+ if (range && (n < range.from || n > range.to)) continue;
163
+ const entry = slides[i];
164
+ if (!entry) continue;
165
+ if (!entry.hash) { out.hashless++; continue; }
166
+ if (entryMatches(manifest, entry, texts[i] ?? '')) continue;
167
+ if (manifest.recorder === 'deck' && prior?.[i] && entryMatches(manifest, entry, prior[i])) continue;
168
+ out.stale.push(n);
169
+ }
170
+ return out;
171
+ }
172
+
173
+ /**
174
+ * Each slide's beats as a reader is shown them: the ⟨CLICK⟩ segments with
175
+ * words, ⟨PAUSE⟩ kept, or the whole slide as one beat when it is not
176
+ * segmented; [] for a slide with nothing to say. Index i is slide i+1.
177
+ *
178
+ * What your own voice's manifest records per slide (#850). A hash says THAT
179
+ * the notes moved; this says how: a recorded beat is cut where you pressed →,
180
+ * so moving a ⟨CLICK⟩ changes nothing you hear, and the one fix is to read
181
+ * those beats again. A synthesized track is re-voiced from the notes, so
182
+ * its hash is all it needs.
183
+ */
184
+ export const slideBeats = (html) => slideNotes(html).map((raw) => {
185
+ if (!raw) return [];
186
+ const segs = notesSegments(raw, { marks: true });
187
+ if (segs) return segs;
188
+ const text = cleanNotes(raw, { marks: true });
189
+ return text ? [text] : [];
190
+ });
191
+
192
+ /**
193
+ * How a slide recorded in your own voice differs from its notes now: null in
194
+ * step; `{ why: 'text' }` when the words moved; `{ why: 'clicks', was, now }`
195
+ * when the words are the same and only the ⟨CLICK⟩ split moved (`was`/`now`
196
+ * the beat counts). `undefined` when the entry carries no record of what was
197
+ * read (anything recorded before #850): unknown, which is never a verdict.
198
+ */
199
+ export function scriptDrift(entry, beats) {
200
+ if (!Array.isArray(entry?.beats)) return undefined;
201
+ const was = entry.beats.map(String);
202
+ const now = (beats ?? []).map(String);
203
+ if (was.length === now.length && was.every((b, k) => b === now[k])) return null;
204
+ const words = (list) => list.join(' ').replace(/\s+/g, ' ').trim();
205
+ if (words(was) === words(now)) return { why: 'clicks', was: was.length, now: now.length };
206
+ return { why: 'text' };
207
+ }
208
+
209
+ /**
210
+ * Every slide of `manifest` out of step with the deck: `drift` lists
211
+ * `{ slide, why, was?, now? }`, from the beats a take of your own voice
212
+ * recorded, else from the notes hash; `unknown` counts the slides that carry
213
+ * neither (recorded by hand before either existed), which are left alone.
214
+ */
215
+ export function trackDrift(manifest, html) {
216
+ const out = { drift: [], unknown: 0 };
217
+ const beats = slideBeats(html);
218
+ const texts = slideTexts(html);
219
+ const prior = priorSlideTexts(html);
220
+ const slides = manifest?.slides ?? [];
221
+ for (let i = 0; i < slides.length; i++) {
222
+ const entry = slides[i];
223
+ if (!entry) continue;
224
+ const d = scriptDrift(entry, beats[i]);
225
+ if (d) { out.drift.push({ slide: i + 1, ...d }); continue; }
226
+ if (d === null) continue;
227
+ if (!entry.hash) { out.unknown++; continue; }
228
+ if (entryMatches(manifest, entry, texts[i] ?? '')) continue;
229
+ if (manifest.recorder === 'deck' && prior[i] && entryMatches(manifest, entry, prior[i])) continue;
230
+ out.drift.push({ slide: i + 1, why: 'text' });
231
+ }
232
+ return out;
233
+ }
234
+
235
+ /**
236
+ * What a re-record of `slides` takes, as a line to paste: your own voice at
237
+ * the microphone, or the track's engine from the notes.
238
+ */
239
+ export function rerecordLine(deck, dir, slides, { mine = false } = {}) {
240
+ const range = slides.length === 1 ? String(slides[0]) : `${Math.min(...slides)}-${Math.max(...slides)}`;
241
+ return `decklight narrate ${deck}${mine ? ' --mic' : ''} --slides ${range} --dir ${dir}`;
242
+ }
243
+
244
+ /**
245
+ * The manifest the deck recorder writes, after each slide of a take (#535):
246
+ * `recorded` maps slide number → its beat file numbers; every slide inside
247
+ * `range` not in it has no notes and is null; every slide outside it keeps
248
+ * `prev`'s entry — a ranged re-record is a surgical redo, the same promise
249
+ * `voiceover --slides` makes. Files are wav: the recorder stitches WAV.
250
+ */
251
+ export function recorderManifest({ prev, header, texts, range, recorded, recorder = 'deck', beats = null }) {
252
+ const total = Math.max(texts.length, prev?.slides?.length ?? 0);
253
+ const slides = [];
254
+ for (let i = 0; i < total; i++) {
255
+ const n = i + 1;
256
+ if (n < range.from || n > range.to) { slides.push(prev?.slides?.[i] ?? null); continue; }
257
+ const take = recorded[n];
258
+ if (!take) { slides.push(null); continue; }
259
+ const nn = String(n).padStart(2, '0');
260
+ const entry = { file: `slide-${nn}.wav`, hash: manifestHash(header, texts[i] ?? '') };
261
+ const segs = (take.segments ?? []).filter((k) => Number.isInteger(k) && k > 0);
262
+ if (segs.length) entry.segments = segs.map((k) => ({ file: `slide-${nn}-${String(k).padStart(2, '0')}.wav` }));
263
+ // your own voice: the beats as you read them, which is what tells a moved
264
+ // ⟨CLICK⟩ from changed words (scriptDrift)
265
+ if (beats) entry.beats = beats[i] ?? [];
266
+ slides.push(entry);
267
+ }
268
+ const { engine, model, voice, style } = header;
269
+ return { engine, model, voice, style, recorder, slides };
270
+ }