decklight 0.6.0 → 0.8.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 (61) hide show
  1. package/README.md +23 -11
  2. package/SPEC.md +187 -23
  3. package/cli/agents.mjs +52 -2
  4. package/cli/associate.mjs +2 -2
  5. package/cli/banner.mjs +125 -0
  6. package/cli/bundle.mjs +15 -5
  7. package/cli/{rec.mjs → cast.mjs} +25 -8
  8. package/cli/comments.mjs +389 -0
  9. package/cli/commit-flow.mjs +157 -0
  10. package/cli/commit-message.mjs +125 -0
  11. package/cli/decklight.mjs +96 -25
  12. package/cli/dev.mjs +159 -13
  13. package/cli/edit.mjs +981 -40
  14. package/cli/git-tree.mjs +87 -0
  15. package/cli/git.mjs +22 -0
  16. package/cli/import.mjs +41 -11
  17. package/cli/init.mjs +37 -5
  18. package/cli/pdf.mjs +59 -14
  19. package/cli/port-conflict.mjs +187 -16
  20. package/cli/pptx-export.mjs +107 -0
  21. package/cli/present.mjs +8 -4
  22. package/cli/publish.mjs +25 -42
  23. package/cli/record.mjs +154 -0
  24. package/cli/review-remote.mjs +330 -0
  25. package/cli/review-store.mjs +107 -0
  26. package/cli/review-submit.mjs +292 -0
  27. package/cli/review.mjs +361 -0
  28. package/cli/serve.mjs +36 -1
  29. package/cli/skill-content.mjs +4 -1
  30. package/cli/units.mjs +2 -2
  31. package/cli/util.mjs +59 -0
  32. package/dist/build-info.json +1 -0
  33. package/dist/decklight.css +254 -1
  34. package/dist/decklight.js +153 -79
  35. package/dist/decklight.js.map +4 -4
  36. package/docs/architecture.svg +10 -3
  37. package/package.json +3 -1
  38. package/tools/args.mjs +20 -0
  39. package/tools/bridge.mjs +25 -2
  40. package/tools/deck-html.mjs +59 -0
  41. package/tools/elevenlabs-tts.mjs +3 -3
  42. package/tools/exec.mjs +54 -0
  43. package/tools/gemini-tts.mjs +4 -4
  44. package/tools/lipsync-server.mjs +70 -2
  45. package/tools/lipsync.mjs +46 -30
  46. package/tools/local-voice.mjs +243 -19
  47. package/tools/pptx-write.mjs +151 -0
  48. package/tools/pptx.mjs +82 -2
  49. package/tools/publish-site-voices.mjs +2 -2
  50. package/tools/publish-targets.mjs +39 -2
  51. package/tools/publish-voices.mjs +80 -20
  52. package/tools/recording-impact.mjs +110 -0
  53. package/tools/review-anchor.mjs +180 -0
  54. package/tools/template-theme.mjs +154 -0
  55. package/tools/test-impact.mjs +266 -0
  56. package/tools/tts-cache.mjs +191 -0
  57. package/tools/tts-engines.mjs +85 -8
  58. package/tools/tts-setup.mjs +4 -3
  59. package/tools/video.mjs +21 -6
  60. package/tools/voiceover-server.mjs +163 -17
  61. package/tools/voiceover.mjs +124 -16
@@ -48,12 +48,46 @@ import { execFileSync } from 'node:child_process';
48
48
  import { resolve, join, basename } from 'node:path';
49
49
  import { homedir } from 'node:os';
50
50
  import { createEngine } from './tts-engines.mjs';
51
+ import { clipKey, createTtsCache, extFor } from './tts-cache.mjs';
51
52
  import { argReader } from './args.mjs';
52
- import { sectionBodies, NOTES_ASIDE, cleanNotes, notesSegments } from './deck-html.mjs';
53
+ import { sectionBodies, NOTES_ASIDE, cleanNotes, notesSegments, isHiddenSection } from './deck-html.mjs';
54
+ import { run, PROBE_MS, CODEC_MS } from './exec.mjs';
53
55
 
54
56
  const args = process.argv.slice(2);
57
+
58
+ const HELP = `decklight voiceover — batch-synthesize a deck's narration into a folder
59
+
60
+ Usage:
61
+ decklight voiceover <deck.html> [-o <dir>] [--engine piper|chirp|gemini|elevenlabs]
62
+ [--voice <name>] [--no-llm] [--reuse-text] [--keep-wav]
63
+ [--no-cache]
64
+
65
+ The headless counterpart of the deck's V \u2192 Record this deck\u2026: it reads each slide's speaker
66
+ notes and writes one slide-NN.m4a per slide (plus a file per \u27e8CLICK\u27e9 beat)
67
+ and a manifest.json into <dir>, so a deck can point at it with
68
+ narration: { files: [{ label, dir, segments: true }] }.
69
+
70
+ -o <dir> output folder (default: <deck>/voiceover)
71
+ --engine piper (local, free, default) · chirp · gemini · elevenlabs
72
+ --voice the engine's voice name (piper: a model name; elevenlabs: omit
73
+ for the first of YOUR voices)
74
+ --no-llm skip the local-LLM notes rewrite; voice the notes as written
75
+ --reuse-text re-voice the existing slide-NN.txt without re-rolling the text
76
+ — switch voices or engines without a new narration pass
77
+ --keep-wav keep the lossless WAVs (tools/lipsync.mjs consumes them)
78
+ --no-cache re-synthesize every slide, ignoring the shared clip cache
79
+
80
+ Synthesis is cached on disk (~/.cache/decklight/tts) under a key made of
81
+ (engine, model, format, voice, style, text) — the SAME key the live bridge
82
+ uses, so a sentence you previewed in the deck is recorded here for free
83
+ instead of being billed a second time.
84
+
85
+ Cloud engines need --project or $GOOGLE_CLOUD_PROJECT and application-default
86
+ credentials; elevenlabs needs $ELEVENLABS_API_KEY. Audio is a build artifact.`;
87
+
88
+ if (args.includes('--help') || args.includes('-h')) { console.log(HELP); process.exit(0); }
55
89
  const deckPath = args.find((a) => !a.startsWith('-'));
56
- if (!deckPath) { console.error('usage: voiceover.mjs <deck.html> [-o dir] [--engine piper|chirp|gemini|elevenlabs] [--voice name] [--no-llm] [--reuse-text]'); process.exit(1); }
90
+ if (!deckPath) { console.error('decklight voiceover: name the deck to voice\n\n' + HELP); process.exit(1); }
57
91
  const { opt } = argReader(args);
58
92
  const outDir = resolve(opt('-o', join(resolve(deckPath, '..'), 'voiceover')));
59
93
  const engine = opt('--engine', 'piper');
@@ -70,6 +104,7 @@ const model = opt('--model', 'qwen3:30b-a3b');
70
104
  const useLlm = !args.includes('--no-llm');
71
105
  const reuseText = args.includes('--reuse-text');
72
106
  const keepWav = args.includes('--keep-wav');
107
+ const useCache = !args.includes('--no-cache');
73
108
 
74
109
  // one factory, three engines — the same ones the live bridge speaks with
75
110
  let tts;
@@ -88,21 +123,22 @@ try {
88
123
  // macOS — probing in that order keeps this working off a Mac (as tools/lipsync.mjs
89
124
  // already does), and both engines' output goes through here.
90
125
  const have = (bin, flags = ['-version']) => {
91
- try { execFileSync(bin, flags, { stdio: 'ignore' }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
126
+ try { run(bin, flags, { stdio: 'ignore', timeout: PROBE_MS }); return true; } catch (e) { return e?.code !== 'ENOENT'; }
92
127
  };
93
128
  const encoder = have('ffmpeg') ? 'ffmpeg' : have('afconvert') ? 'afconvert' : null;
94
129
  if (!encoder) {
95
130
  console.error('no AAC encoder — install ffmpeg (apt install ffmpeg / brew install ffmpeg)');
96
131
  process.exit(1);
97
132
  }
98
- const toAac = (wav, m4a) => execFileSync(encoder, encoder === 'ffmpeg'
133
+ const toAac = (wav, m4a) => run(encoder, encoder === 'ffmpeg'
99
134
  ? ['-y', '-i', wav, '-c:a', 'aac', '-b:a', '128k', m4a]
100
- : ['-f', 'm4af', '-d', 'aac', wav, m4a], { stdio: 'ignore' });
135
+ : ['-f', 'm4af', '-d', 'aac', wav, m4a], { stdio: 'ignore', timeout: CODEC_MS, why: 'the encoder is stuck on this file — check it plays, then retry' });
101
136
 
102
137
  // ── extract per-slide narration text ─────────────────────────────────────────
103
138
  const html = readFileSync(deckPath, 'utf8');
104
139
  const sections = sectionBodies(html);
105
140
  const raw = sections.map((sec) => {
141
+ if (isHiddenSection(sec)) return ''; // no file for a hidden slide; the numbering stays
106
142
  const aside = sec.match(NOTES_ASIDE);
107
143
  if (aside) return aside[1];
108
144
  const md = sec.match(/^Note:\s*$([\s\S]*?)(?=^Rehearse:\s*$|<\/script>)/m);
@@ -149,12 +185,71 @@ function narrate(text, slideNo) {
149
185
  }
150
186
 
151
187
  // ── synthesize ────────────────────────────────────────────────────────────────
152
- // Incremental: the manifest stores a hash of (engine, voice, style, text) per
153
- // slide, so a rerun only synthesizes slides whose narration actually changed.
188
+ // TWO layers of reuse, and they answer different questions.
189
+ //
190
+ // The MANIFEST answers "is this folder already correct?" — a hash per slide,
191
+ // so a rerun re-synthesizes only the slides whose narration actually changed
192
+ // and leaves the rest of the .m4a files alone.
193
+ //
194
+ // The CLIP CACHE (tools/tts-cache.mjs) answers "has anyone, ever, paid for
195
+ // these exact words?" — it is keyed by content rather than by folder, so it
196
+ // survives a different -o, a deleted manifest, and above all the process
197
+ // boundary: the live bridge fills the same cache while you preview the deck,
198
+ // and this run collects it. An ElevenLabs deck used to be billed twice for
199
+ // that, once in the browser and once here.
200
+ //
201
+ // Both keys carry the same fields, and the reason is one bug rather than two:
202
+ // anything that changes the AUDIO must change the key. `model` is in them
203
+ // because `--tts-model eleven_v3` is a different voice performance of the same
204
+ // words, and a hash without it skipped the slide and kept the old take. STYLE
205
+ // is in them only when the engine can act on it — every engine but gemini and
206
+ // ElevenLabs v3 ignores the instruction entirely, and letting a style the
207
+ // engine never read change the hash would miss the bridge's own clip for no
208
+ // audible reason.
154
209
  mkdirSync(outDir, { recursive: true });
155
210
  let totalCost = 0;
156
- const slideHash = (text) =>
157
- createHash('sha256').update(`${engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
211
+ const audioExt = extFor(tts.synth.mimeType ?? 'audio/wav');
212
+ const clips = createTtsCache({ enabled: useCache });
213
+ clips.prune();
214
+ // `--voice` omitted on ElevenLabs means "the first of your voices", and the
215
+ // deck's picker offers that same roster in that same order — so the name is
216
+ // resolved HERE, for the key. Left undefined it would hash differently from
217
+ // the identical sentence the bridge just synthesized, and the cross-process
218
+ // reuse this cache exists for would silently never hit.
219
+ let keyVoice = voice;
220
+ if (!keyVoice && tts.listVoices) {
221
+ try { keyVoice = (await tts.listVoices())[0]?.name; } catch { /* keep it undefined */ }
222
+ }
223
+
224
+ /** `tts.synth`, but a sentence anyone has already paid for is free. */
225
+ async function synth(text) {
226
+ const key = clipKey(tts, { voice: keyVoice, style, text });
227
+ const hit = clips.read(key, audioExt);
228
+ if (hit) return { wav: hit, usage: { chars: 0, cost: 0 }, cached: true };
229
+ const out = await tts.synth(text, { voice, style });
230
+ clips.write(key, out.wav, audioExt);
231
+ return { ...out, cached: false };
232
+ }
233
+ // The manifest hash is the CLIP KEY, shortened: one definition of "the same
234
+ // audio", so the folder-level skip and the content-level cache can never
235
+ // disagree about whether a slide changed.
236
+ const slideHash = (text) => clipKey(tts, { voice: keyVoice, style, text }).slice(0, 16);
237
+ // ONE-TIME MIGRATION. The hash above gained `model` and lost the style no
238
+ // engine reads, so every folder recorded before this change hashes differently
239
+ // — and a folder that hashes differently is re-synthesized in full. That audio
240
+ // is not stale; it is exactly what today's key describes, and re-rolling it
241
+ // would hand an ElevenLabs user a bill for clips already on their disk.
242
+ //
243
+ // So a slide matching the OLD formula is accepted once and re-stamped. The
244
+ // gate is `prev.model === undefined`: only a manifest written before this
245
+ // change lacks that field, so the allowance cannot be claimed twice, and a
246
+ // later `--tts-model` switch is a genuine miss again. The one case it lets
247
+ // through is changing the model in the SAME run as the upgrade — narrow, and
248
+ // `--no-cache` is the way out of it.
249
+ const legacyHash = (text) => createHash('sha256')
250
+ .update(`${engine}|${voice}|${style}|${text}`).digest('hex').slice(0, 16);
251
+ const preDatesModel = (m) => m && m.model === undefined
252
+ && m.engine === engine && m.voice === voice && m.style === style;
158
253
  let prev = null;
159
254
  try {
160
255
  const m = JSON.parse(readFileSync(join(outDir, 'manifest.json'), 'utf8'));
@@ -176,7 +271,8 @@ for (let i = 0; i < slides.length; i++) {
176
271
  writeFileSync(txt, text);
177
272
  const hash = slideHash(text);
178
273
  manifest.push({ file: `slide-${n}.m4a`, hash });
179
- if (prev?.slides?.[i]?.hash === hash && existsSync(m4a)) {
274
+ const stamped = prev?.slides?.[i]?.hash;
275
+ if ((stamped === hash || (preDatesModel(prev) && stamped === legacyHash(text))) && existsSync(m4a)) {
180
276
  // Carry the segments across, or an unchanged slide loses its build sync on
181
277
  // the next rerun: the audio is still on disk and the manifest is the only
182
278
  // thing that knows it is there.
@@ -193,14 +289,20 @@ for (let i = 0; i < slides.length; i++) {
193
289
  // path, since its prior text is one script rather than segments.
194
290
  const segs = prior ? null : segmented[i];
195
291
  let usage = { cost: 0 };
292
+ let cachedBeats = 0;
196
293
  if (segs) {
197
294
  const parts = [];
198
295
  for (let k = 0; k < segs.length; k++) {
199
296
  const kk = String(k + 1).padStart(2, '0');
200
297
  const sWav = join(outDir, `slide-${n}-${kk}.wav`);
201
298
  const sM4a = join(outDir, `slide-${n}-${kk}.m4a`);
202
- const out = await tts.synth(segs[k], { voice, style });
299
+ const out = await synth(segs[k]);
300
+ if (out.cached) cachedBeats++;
203
301
  writeFileSync(sWav, out.wav);
302
+ // The beat's own words, beside its own audio — tools/lipsync.mjs hands
303
+ // this to Rhubarb as the dialog hint, and a hint for the whole slide
304
+ // would be worse than none against one beat of it.
305
+ writeFileSync(join(outDir, `slide-${n}-${kk}.txt`), segs[k]);
204
306
  usage = { cost: usage.cost + (out.usage?.cost ?? 0) };
205
307
  toAac(sWav, sM4a);
206
308
  if (!keepWav) rmSync(sWav);
@@ -208,12 +310,13 @@ for (let i = 0; i < slides.length; i++) {
208
310
  }
209
311
  const list = join(outDir, `slide-${n}.concat`);
210
312
  writeFileSync(list, `${parts.map((p) => `file '${p.path.replaceAll("'", "'\\''")}'`).join('\n')}\n`);
211
- execFileSync('ffmpeg', ['-y', '-f', 'concat', '-safe', '0', '-i', list, '-c', 'copy', m4a],
313
+ run('ffmpeg', ['-y', '-f', 'concat', '-safe', '0', '-i', list, '-c', 'copy', m4a],
212
314
  { stdio: 'ignore' });
213
315
  rmSync(list, { force: true });
214
316
  manifest[i].segments = parts.map((p) => ({ file: p.file }));
215
317
  } else {
216
- const out = await tts.synth(text, { voice, style });
318
+ const out = await synth(text);
319
+ if (out.cached) cachedBeats++;
217
320
  writeFileSync(wav, out.wav);
218
321
  usage = out.usage ?? { cost: 0 };
219
322
  toAac(wav, m4a);
@@ -221,15 +324,20 @@ for (let i = 0; i < slides.length; i++) {
221
324
  }
222
325
  totalCost += usage.cost ?? 0;
223
326
  const costNote = usage.cost ? ` · ~$${usage.cost.toFixed(4)}` : '';
327
+ // "cached" is worth a word: on a paid engine it is the difference between a
328
+ // rerun that costs nothing and one that quietly re-bills the whole deck
329
+ const cacheNote = cachedBeats
330
+ ? ` · ${segs ? `${cachedBeats}/${segs.length} ` : ''}cached`
331
+ : '';
224
332
  console.log(` slide ${n}: ${text.length} chars → ${basename(m4a)}`
225
- + `${segs ? ` (${segs.length} ⟨CLICK⟩ segments)` : ''}${costNote}`);
333
+ + `${segs ? ` (${segs.length} ⟨CLICK⟩ segments)` : ''}${cacheNote}${costNote}`);
226
334
  // crash-safe: persist progress after every slide so an interrupted run
227
335
  // resumes incrementally instead of re-synthesizing everything
228
336
  writeFileSync(join(outDir, 'manifest.json'),
229
- JSON.stringify({ engine, voice, style, slides: manifest }, null, 1));
337
+ JSON.stringify({ engine, model: tts.model ?? null, voice, style, slides: manifest }, null, 1));
230
338
  }
231
339
  writeFileSync(join(outDir, 'manifest.json'),
232
- JSON.stringify({ engine, voice, style, slides: manifest }, null, 1));
340
+ JSON.stringify({ engine, model: tts.model ?? null, voice, style, slides: manifest }, null, 1));
233
341
  // piper is held resident (§ createPiper) — without this the tool prints `done`
234
342
  // and then hangs on the live child process
235
343
  tts.synth.close?.();