decklight 0.10.0 → 0.11.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 (117) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +17 -0
  3. package/README.md +53 -25
  4. package/SPEC.md +1239 -67
  5. package/cli/agents.mjs +139 -15
  6. package/cli/bundle.mjs +68 -2
  7. package/cli/cast.mjs +45 -14
  8. package/cli/check-fixes.mjs +12 -4
  9. package/cli/check-watch.mjs +151 -0
  10. package/cli/check.mjs +460 -71
  11. package/cli/code-editor.mjs +287 -0
  12. package/cli/commands.mjs +13 -2
  13. package/cli/commit-message.mjs +34 -7
  14. package/cli/commit-split.mjs +123 -23
  15. package/cli/decklight.mjs +11 -1
  16. package/cli/design-system-edit.mjs +37 -1
  17. package/cli/edit-address.mjs +184 -0
  18. package/cli/edit-git.mjs +21 -4
  19. package/cli/edit-handover.mjs +136 -25
  20. package/cli/edit-look.mjs +45 -1
  21. package/cli/edit-open.mjs +143 -0
  22. package/cli/edit-slides.mjs +1043 -67
  23. package/cli/edit-translate.mjs +243 -0
  24. package/cli/edit.mjs +3182 -267
  25. package/cli/editor-support.mjs +286 -0
  26. package/cli/enhance.mjs +148 -20
  27. package/cli/find-replace.mjs +142 -0
  28. package/cli/fix-review.mjs +368 -0
  29. package/cli/init.mjs +93 -19
  30. package/cli/keep-awake.mjs +68 -0
  31. package/cli/migrate-writing.mjs +214 -0
  32. package/cli/narrate.mjs +51 -10
  33. package/cli/open.mjs +29 -9
  34. package/cli/outside-edit.mjs +257 -0
  35. package/cli/paste.mjs +92 -0
  36. package/cli/pdf.mjs +61 -2
  37. package/cli/pptx-export.mjs +3 -1
  38. package/cli/publish.mjs +24 -3
  39. package/cli/record.mjs +19 -8
  40. package/cli/rewrite.mjs +265 -0
  41. package/cli/runtime-link.mjs +218 -17
  42. package/cli/serve.mjs +7 -4
  43. package/cli/setup.mjs +2 -2
  44. package/cli/skill-content.mjs +212 -8
  45. package/cli/skills/slide-writing.md +333 -0
  46. package/cli/skills/voiceover.md +423 -0
  47. package/cli/skills.mjs +36 -13
  48. package/cli/starter-full.mjs +353 -0
  49. package/cli/supervise.mjs +14 -0
  50. package/cli/theme.mjs +3 -2
  51. package/cli/translate-core.mjs +466 -0
  52. package/cli/translate-files.mjs +149 -0
  53. package/cli/translate.mjs +458 -0
  54. package/cli/util.mjs +25 -0
  55. package/cli/vocabulary-docs.mjs +138 -0
  56. package/dist/decklight.css +2087 -91
  57. package/dist/decklight.js +367 -203
  58. package/dist/decklight.js.map +4 -4
  59. package/docs/GLOSSARY.md +9 -2
  60. package/docs/WRITING_RESEARCH.md +327 -0
  61. package/package.json +5 -3
  62. package/themes/coastal.css +3 -0
  63. package/themes/metropolis.css +2 -0
  64. package/themes/reveal-blood.css +3 -0
  65. package/themes/reveal-league.css +2 -0
  66. package/themes/reveal-moon.css +2 -0
  67. package/themes/reveal-serif.css +1 -0
  68. package/themes/reveal-sky.css +1 -0
  69. package/themes/reveal-solarized.css +4 -0
  70. package/tools/brand-palette.mjs +6 -1
  71. package/tools/build-groups.mjs +28 -8
  72. package/tools/cdp.mjs +176 -0
  73. package/tools/chart-spec.mjs +242 -0
  74. package/tools/click-match.mjs +70 -0
  75. package/tools/code-options.mjs +174 -0
  76. package/tools/conversation.mjs +49 -0
  77. package/tools/deck-family.mjs +101 -0
  78. package/tools/deck-html.mjs +212 -15
  79. package/tools/design-system-format.mjs +15 -1
  80. package/tools/diagram-shapes.mjs +221 -0
  81. package/tools/elevenlabs-tts.mjs +62 -53
  82. package/tools/face-clip.mjs +96 -0
  83. package/tools/face-layout.mjs +94 -0
  84. package/tools/gemini-tts.mjs +1 -1
  85. package/tools/invisible-in-print.mjs +27 -0
  86. package/tools/lipsync-auto.mjs +197 -0
  87. package/tools/lipsync-config.mjs +16 -0
  88. package/tools/lipsync-engines.mjs +22 -4
  89. package/tools/lipsync-server.mjs +8 -5
  90. package/tools/lipsync.mjs +122 -30
  91. package/tools/local-voice.mjs +1 -1
  92. package/tools/mouth-file.mjs +26 -0
  93. package/tools/mouth.mjs +320 -0
  94. package/tools/narration-manifest.mjs +24 -4
  95. package/tools/narration-synth.mjs +96 -76
  96. package/tools/recording-impact.mjs +16 -1
  97. package/tools/sentences.mjs +7 -1
  98. package/tools/starters.mjs +402 -0
  99. package/tools/steps.mjs +118 -0
  100. package/tools/take-check.mjs +146 -0
  101. package/tools/template-theme.mjs +3 -1
  102. package/tools/test-impact.mjs +36 -12
  103. package/tools/theme-check.mjs +196 -1
  104. package/tools/tone-cue.mjs +108 -0
  105. package/tools/tts-cache.mjs +9 -3
  106. package/tools/tts-engines.mjs +100 -11
  107. package/tools/video-cache.mjs +93 -0
  108. package/tools/video-live.mjs +349 -0
  109. package/tools/video-options.mjs +11 -0
  110. package/tools/video.mjs +772 -127
  111. package/tools/viseme-fit.mjs +27 -0
  112. package/tools/viseme-match.mjs +77 -0
  113. package/tools/vocabulary.mjs +397 -0
  114. package/tools/voice-renumber.mjs +605 -0
  115. package/tools/voiceover-server.mjs +42 -11
  116. package/tools/voiceover.mjs +48 -20
  117. package/dist/build-info.json +0 -1
package/cli/narrate.mjs CHANGED
@@ -32,6 +32,8 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
32
32
  import { dirname, join, relative, resolve, isAbsolute } from 'node:path';
33
33
  import { fileURLToPath } from 'node:url';
34
34
  import { firstPositional, isMain } from '../tools/args.mjs';
35
+ import { deckLang } from '../tools/deck-html.mjs';
36
+ import { deckFamily, ownsTrack, readManifest, defaultTrackDir } from '../tools/deck-family.mjs';
35
37
  import { runMain, wrongRecorder } from './util.mjs';
36
38
  import { configuredTrackDirs } from './edit.mjs';
37
39
 
@@ -53,6 +55,7 @@ export const USAGE = `usage: decklight narrate <deck.html> [--mic] [--slides a-b
53
55
  --voice V the engine's voice name
54
56
  --format F m4a (a new track's default) · wav · mp3
55
57
  --reuse-text, --keep-wav, --no-cache (decklight narrate <deck> --help --engine)
58
+ a deck with a 2D character gets the lip-sync of what was voiced too (--no-face: not)
56
59
  EXAMPLE: decklight narrate talk.html --engine chirp --voice Achernar
57
60
 
58
61
  you read the notes, into the microphone
@@ -64,6 +67,7 @@ export const USAGE = `usage: decklight narrate <deck.html> [--mic] [--slides a-b
64
67
  --countdown N seconds of count-in before each take, 0 for none
65
68
  --remote the phone remote too: its next ends a beat, its retake redoes one,
66
69
  so no keystroke gets into the take
70
+ --camera film your face too, beat by beat; the deck and decklight video show it
67
71
  --port N, --no-open
68
72
  EXAMPLE: decklight narrate talk.html --mic
69
73
 
@@ -85,8 +89,13 @@ export const USAGE = `usage: decklight narrate <deck.html> [--mic] [--slides a-b
85
89
  --check every track beside the deck, slide by slide: in step, the words
86
90
  changed, or (your own voice) only the [click] split moved, which
87
91
  a recording cannot follow; each with the command that fixes it.
88
- Exits 1 when something is out of step
92
+ An engine's clips far longer or shorter than their text runs are
93
+ listed as worth a listen. Exits 1 when something is out of step
89
94
  --dir NAME only this folder
95
+ --realign a track whose recordings are only in the wrong place (slides
96
+ inserted, moved or deleted outside decklight's own slide ops) is
97
+ moved back onto the slides they were read from; nothing is
98
+ deleted, and a rename onto a file outside the plan stops it
90
99
  EXAMPLE: decklight narrate talk.html --check
91
100
 
92
101
  the deck plays the folder back with
@@ -132,7 +141,7 @@ export function faceFolders(deckPath, html, dirArg) {
132
141
  const deckDir = dirname(resolve(deckPath));
133
142
  if (dirArg) return [resolve(deckDir, dirArg)];
134
143
  const named = configuredTrackDirs(html).filter((d) => !/^[a-z][a-z0-9+.-]*:/i.test(d));
135
- const dirs = (named.length ? named : ['voiceover']).map((d) => resolve(deckDir, d));
144
+ const dirs = (named.length ? named : [defaultTrackDir(resolve(deckPath))]).map((d) => resolve(deckDir, d));
136
145
  return [...new Set(dirs)].filter(hasAudio);
137
146
  }
138
147
 
@@ -158,8 +167,11 @@ function faceMain(plan, argv) {
158
167
  // --face and --dir NAME are this command's, not the tool's
159
168
  const deckAt = argv.indexOf(plan.deck);
160
169
  const rest = argv.filter((a, i) => i !== deckAt && a !== '--face' && (dirAt === -1 || (i !== dirAt && i !== dirAt + 1)));
170
+ // the deck's language picks the recogniser, unless --lang already did
171
+ const lang = deckLang(html);
172
+ const langArgs = lang && !rest.includes('--lang') ? ['--lang', lang] : [];
161
173
  for (const dir of folders) {
162
- const r = spawnSync(process.execPath, [LIPSYNC, dir, ...rest], { stdio: 'inherit' });
174
+ const r = spawnSync(process.execPath, [LIPSYNC, dir, ...rest, ...langArgs], { stdio: 'inherit' });
163
175
  if (r.status !== 0) return r.status ?? 1;
164
176
  }
165
177
  return 0;
@@ -168,13 +180,17 @@ function faceMain(plan, argv) {
168
180
  /**
169
181
  * The track folders beside a deck that carry a manifest: the same two levels
170
182
  * the edit server's track list walks (`voices/<voice>`), relative to the deck.
183
+ * With `deckPath`, only that deck's: a track in the language of another file
184
+ * of its family (`voices-fr/…` beside `talk.html`) is that file's to check.
171
185
  */
172
- export function manifestTracks(deckDir) {
186
+ export function manifestTracks(deckDir, deckPath = null) {
187
+ const family = deckPath ? deckFamily(deckPath) : null;
188
+ const own = (rel) => !family || ownsTrack(family, rel, readManifest(join(deckDir, rel)));
173
189
  const out = [];
174
190
  const look = (rel) => {
175
191
  let entries;
176
192
  try { entries = readdirSync(join(deckDir, rel), { withFileTypes: true }); } catch { return []; }
177
- if (entries.some((e) => e.isFile() && e.name === 'manifest.json')) out.push(rel);
193
+ if (entries.some((e) => e.isFile() && e.name === 'manifest.json') && own(rel)) out.push(rel);
178
194
  return entries.filter((e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'node_modules');
179
195
  };
180
196
  for (const e of look('.')) {
@@ -191,10 +207,13 @@ export function manifestTracks(deckDir) {
191
207
  async function checkMain(plan, argv) {
192
208
  if (!plan.deck || !existsSync(plan.deck)) { console.error(`decklight narrate: ${plan.deck ? `no deck at ${plan.deck}` : 'name the deck'}`); return 1; }
193
209
  const { trackDrift, rerecordLine } = await import('../tools/narration-manifest.mjs');
210
+ const { realignMoves, planFolder, applyPlans, trackScripts } = await import('../tools/voice-renumber.mjs');
211
+ const { auditTrack } = await import('../tools/take-check.mjs');
212
+ const realign = argv.includes('--realign');
194
213
  const html = readFileSync(plan.deck, 'utf8');
195
214
  const deckDir = dirname(resolve(plan.deck));
196
215
  const dirAt = argv.indexOf('--dir');
197
- const dirs = dirAt === -1 ? manifestTracks(deckDir) : [argv[dirAt + 1]];
216
+ const dirs = dirAt === -1 ? manifestTracks(deckDir, resolve(plan.deck)) : [argv[dirAt + 1]];
198
217
  let out = 0;
199
218
  if (!dirs.length) { console.log('no narration track with a manifest beside this deck — nothing to check'); return 0; }
200
219
  for (const dir of dirs) {
@@ -203,11 +222,32 @@ async function checkMain(plan, argv) {
203
222
  if (!Array.isArray(m?.slides)) { console.log(`${dir}/ no manifest: recorded before decklight kept one, not checked`); continue; }
204
223
  const mine = m.recorder === 'mic';
205
224
  const who = mine ? 'your voice' : [m.voice, m.engine].filter(Boolean).join(' · ') || 'recorded';
206
- const { drift, unknown } = trackDrift(m, html);
225
+ let { drift, unknown } = trackDrift(m, html);
226
+ // only in the wrong place (#916): said, and with --realign, moved
227
+ const { moves, said } = realignMoves(m, html, { scripts: trackScripts(join(deckDir, dir)) });
228
+ if (moves.length && realign) {
229
+ const plan = planFolder(deckDir, { dir, pairs: moves });
230
+ if (plan.conflicts.length) { console.log(`${dir}/ ${said}, but ${plan.conflicts[0]} — nothing was moved`); out = 1; continue; }
231
+ try { applyPlans(deckDir, [plan]); } catch (e) { console.log(`${dir}/ ${said}, but the move failed (${e.message}) — the folder is as it was`); out = 1; continue; }
232
+ console.log(`${dir}/ ${said}: moved back onto their slides`);
233
+ m = JSON.parse(readFileSync(join(deckDir, dir, 'manifest.json'), 'utf8'));
234
+ ({ drift, unknown } = trackDrift(m, html));
235
+ } else if (moves.length) {
236
+ console.log(`${dir}/ ${said} — move them: decklight narrate ${plan.deck} --realign --dir ${dir}`);
237
+ }
207
238
  const note = unknown ? ` (${unknown} slide${unknown === 1 ? '' : 's'} recorded before the script was kept: not checked)` : '';
208
- if (!drift.length) { console.log(`${dir}/ ${who}: in step with the notes${note}`); continue; }
239
+ // an engine's takes whose length does not fit their text (#1005): a
240
+ // repeated or dropped phrase, worth a listen; said, not failed on
241
+ const odd = mine ? [] : auditTrack(join(deckDir, dir), m.engine);
242
+ const listen = () => {
243
+ if (!odd.length) return;
244
+ console.log(` ${odd.length} clip${odd.length === 1 ? '' : 's'} not the length ${odd.length === 1 ? 'its' : 'their'} text runs, worth a listen:`);
245
+ for (const t of odd) console.log(` ${t.file}: ${t.seconds.toFixed(2)} s against ~${t.expected.toFixed(2)} s`);
246
+ };
247
+ if (!drift.length) { console.log(`${dir}/ ${who}: in step with the notes${note}`); listen(); continue; }
209
248
  out = 1;
210
- console.log(`${dir}/ ${who}: ${drift.length} slide${drift.length === 1 ? '' : 's'} out of step${note}`);
249
+ // your own voice is re-recorded, an engine's track re-voiced (#919)
250
+ console.log(`${dir}/ ${who}: ${drift.length} slide${drift.length === 1 ? '' : 's'} to ${mine ? 're-record' : 're-voice'}${note}`);
211
251
  for (const d of drift) {
212
252
  console.log(d.why === 'clicks'
213
253
  ? ` slide ${d.slide}: the [click] split moved${d.was !== d.now ? ` (${d.was} beats → ${d.now})` : ''}, the words did not`
@@ -215,6 +255,7 @@ async function checkMain(plan, argv) {
215
255
  : ` slide ${d.slide}: the notes changed since it was recorded`);
216
256
  console.log(` ${rerecordLine(plan.deck, dir, [d.slide], { mine })}`);
217
257
  }
258
+ listen();
218
259
  }
219
260
  return out;
220
261
  }
@@ -226,7 +267,7 @@ export async function narrateMain(argv = []) {
226
267
  return argv.length ? 0 : 1;
227
268
  }
228
269
  const plan = narratePlan(argv);
229
- if (argv.includes('--check')) return checkMain(plan, argv);
270
+ if (argv.includes('--check') || argv.includes('--realign')) return checkMain(plan, argv);
230
271
  if (argv.includes('--face')) return faceMain(plan, argv);
231
272
  // a terminal script is `cast`'s, whichever way it was meant to be narrated
232
273
  const mixedUp = wrongRecorder('narrate', plan.deck);
package/cli/open.mjs CHANGED
@@ -31,10 +31,11 @@ import { onPath, detectAgents, AGENTS } from './agents.mjs';
31
31
  import { validProjectId } from '../tools/gemini-tts.mjs';
32
32
  import {
33
33
  ENGINES as TTS_ENGINES, PIPER_DEFAULT_VOICE, piperModelDir, engineStatus,
34
- piperDownloadCmd, piperDownloadLine,
34
+ piperDownloadCmd, piperDownloadLine, voiceLang,
35
35
  } from '../tools/tts-engines.mjs';
36
36
  import { KEY_ENV as ELEVENLABS_KEY_ENV } from '../tools/elevenlabs-tts.mjs';
37
37
  import { loadTtsConfig } from '../tools/tts-setup.mjs';
38
+ import { deckLang } from '../tools/deck-html.mjs';
38
39
  import { detectLocalVoice } from '../tools/local-voice.mjs';
39
40
  import { relative } from 'node:path';
40
41
  import { argReader, firstPositional, isMain } from '../tools/args.mjs';
@@ -70,6 +71,9 @@ const USAGE = `usage: decklight <deck.html | git url> [--no-trust | --trust] [--
70
71
  --git / --no-git keep the deck in git (snapshots, K commits) / never touch git
71
72
  (no repository and no flag: decklight asks whether to create one)
72
73
  --agent <name> preferred AI agent for A (default: first detected)
74
+ --agent-model <id> the model that agent runs on, this run only (default: the
75
+ one remembered from A's card, else the agent's own). Also
76
+ DECKLIGHT_AGENT_MODEL; --agent-ask-model for its quick questions
73
77
  --no-plugins play without your presenter plugins (decklight library add plugin)
74
78
  --remote also listen on the LAN for the phone remote
75
79
  --no-tts don't start the voice bridge
@@ -123,6 +127,9 @@ const USAGE_ALL = `usage: decklight <deck.html | git url> [--no-trust] [--port 8
123
127
  way the deck's changes go to the agent installed on this
124
128
  machine, which may pass them to its provider
125
129
  --agent <name> preferred AI agent for A (default: first detected)
130
+ --agent-model <id> the model that agent runs on, this run only (default: the
131
+ one remembered from A's card, else the agent's own). Also
132
+ DECKLIGHT_AGENT_MODEL; --agent-ask-model for its quick questions
126
133
 
127
134
  --no-trust the same server in no-trust mode: the deck is served from
128
135
  its own directory under a Content-Security-Policy header,
@@ -155,7 +162,7 @@ const USAGE_ALL = `usage: decklight <deck.html | git url> [--no-trust] [--port 8
155
162
 
156
163
  // flags that take a value (so the deck argument can be found past them)
157
164
  const VALUE_FLAGS = new Set([
158
- '--port', '--tts-port', '--lipsync-port', '--tts-engine', '--commit-every', '--agent', '--git-mode',
165
+ '--port', '--tts-port', '--lipsync-port', '--tts-engine', '--commit-every', '--agent', '--agent-model', '--agent-ask-model', '--git-mode',
159
166
  '--branch', '--into', '--host',
160
167
  ]);
161
168
 
@@ -207,11 +214,22 @@ export function movedFlagLines(args = []) {
207
214
  * the bridges go through the dispatcher, the edit server (no longer a
208
215
  * command there) runs its own module.
209
216
  */
217
+ /** The `<html lang>` of the deck `args` names, or null: a URL, or a file not there yet, has none to read. */
218
+ function langOfDeck(args) {
219
+ try { return deckLang(readFileSync(firstPositional(args, VALUE_FLAGS), 'utf8')); } catch { return null; }
220
+ }
221
+
210
222
  export function planServices({
211
223
  args = [], env = process.env, hasBin = onPath, saved = null, lipsync = null,
212
224
  detect = detectLocalVoice, exists = existsSync,
225
+ // the deck's `<html lang>`, read by the caller: this function touches no file
226
+ deckLanguage = null,
213
227
  } = {}) {
214
228
  const { opt } = argReader(args);
229
+ // the language the voice is asked for: the deck's own when it is not in
230
+ // English, else the one saved by `setup voice --lang` (PRESENTING_VOICE)
231
+ const lang = voiceLang({ deck: deckLanguage, saved: saved?.lang });
232
+ const langFromDeck = lang !== undefined && lang !== saved?.lang;
215
233
  const has = (flag) => args.includes(flag);
216
234
  const pass = (flag) => (opt(flag) !== undefined ? [flag, opt(flag)] : []);
217
235
 
@@ -229,7 +247,7 @@ export function planServices({
229
247
  entry: EDIT,
230
248
  args: [deck, '--port', editPort,
231
249
  ...(has('--git') ? ['--git'] : []), ...(has('--no-git') ? ['--no-git'] : []),
232
- ...pass('--commit-every'), ...pass('--agent'), ...pass('--git-mode'),
250
+ ...pass('--commit-every'), ...pass('--agent'), ...pass('--agent-model'), ...pass('--agent-ask-model'), ...pass('--git-mode'),
233
251
  // the deck reaches both bridges on the edit server's own origin (#520):
234
252
  // `/tts` and `/lipsync/*` are proxied to the ports the bridges below take
235
253
  ...pass('--tts-port'), ...pass('--lipsync-port'),
@@ -257,7 +275,7 @@ export function planServices({
257
275
  // --tts-engine, a saved engine, or a project all win over this: flags decide,
258
276
  // detection only fills a vacuum.
259
277
  const chosen = opt('--tts-engine', saved?.engine);
260
- const native = chosen || project ? null : detect({ lang: saved?.lang });
278
+ const native = chosen || project ? null : detect({ lang });
261
279
  // Only a NATIVE voice is claimed automatically. It is the one engine that
262
280
  // needs no setup at all — no install, no download, no credential — so using
263
281
  // it silently costs the presenter nothing. piper is deliberately NOT picked
@@ -273,6 +291,8 @@ export function planServices({
273
291
  // picked for its system voice would try to reach Vertex AI instead
274
292
  ...(has('--tts-engine') || saved?.engine || ttsEngine !== 'gemini' ? ['--engine', ttsEngine] : []),
275
293
  ...(cloudVoice ? ['--project', project] : []),
294
+ // the deck's language is the one setting the saved config cannot hold
295
+ ...(langFromDeck ? ['--lang', lang] : []),
276
296
  // every other setting the bridge reads from the saved config itself
277
297
  ];
278
298
  // The SAME readiness check the bridge runs when the deck asks what it may
@@ -283,7 +303,7 @@ export function planServices({
283
303
  const ttsVoice = saved?.voice ?? PIPER_DEFAULT_VOICE;
284
304
  const ttsData = saved?.dataDir ?? piperModelDir(env);
285
305
  const status = engineStatus(ttsEngine, {
286
- env, project, voice: ttsVoice, dataDir: ttsData, lang: saved?.lang,
306
+ env, project, voice: ttsVoice, dataDir: ttsData, lang,
287
307
  // every probe threaded through, `detect` included: these are the injection
288
308
  // points that let planServices be tested on any machine, and a readiness
289
309
  // check reaching for the REAL PATH or the REAL synthesizer would decide a
@@ -353,7 +373,7 @@ export function planServices({
353
373
  entry: CLI,
354
374
  // every setting comes from lipsync.json; Veo, the one that spends
355
375
  // money, only when `setup face --veo` asked for it there
356
- args: ['lipsync', '--port', lipPort],
376
+ args: ['lipsync', '--port', lipPort, ...(deckLanguage ? ['--lang', deckLanguage] : [])],
357
377
  url: `http://127.0.0.1:${lipPort}`,
358
378
  });
359
379
  }
@@ -411,7 +431,7 @@ export async function openMain(args) {
411
431
  return 1;
412
432
  }
413
433
 
414
- let plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig() });
434
+ let plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig(), deckLanguage: langOfDeck(args) });
415
435
  let deck = plan.deck;
416
436
  if (!deck) {
417
437
  console.error('decklight needs a deck: decklight <deck.html>\n');
@@ -440,7 +460,7 @@ export async function openMain(args) {
440
460
  // no-trust mode never commits the deck; the clone's git is what H reads
441
461
  if (!noTrust && !args.includes('--no-git') && !args.includes('--git')) args.push('--git');
442
462
  deck = local;
443
- plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig() });
463
+ plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig(), deckLanguage: langOfDeck(args) });
444
464
  }
445
465
  // no-trust mode names a missing deck itself, the same way for a file, a
446
466
  // container and a --check
@@ -531,7 +551,7 @@ export async function openMain(args) {
531
551
  // could only offer what was on. Init says so in a line; --git-mode
532
552
  // timer is the way to the plain cadence.
533
553
  rl.close();
534
- plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig() });
554
+ plan = planServices({ args, saved: loadTtsConfig(), lipsync: loadLipsyncConfig(), deckLanguage: langOfDeck(args) });
535
555
  } else {
536
556
  console.log(' git: no repository here — pass --git to create one and keep every version of the deck');
537
557
  }
@@ -0,0 +1,257 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * The deck changed on disk under write mode, by a hand this server never saw:
6
+ * the author's editor, git, a tool (PRESENTING_EDITING, outside edits). What
7
+ * changed, said in a few words, and what the pages do about it.
8
+ *
9
+ * Every page used to reload for any change, and the hash kept the slide
10
+ * NUMBER: a change to slide 14 left the author on slide 3, a section put in
11
+ * above moved everyone onto the wrong content, and the reload flashed and
12
+ * remounted the docked panels. So the old and the new bytes are compared slide
13
+ * by slide:
14
+ *
15
+ * - only slides' own markup changed, the same slides in the same order and
16
+ * nothing around them touched: the pages are sent those slides' new markup
17
+ * and swap them in place (`patch`);
18
+ * - anything else reloads, and carries where each slide went (`land`), so a
19
+ * page lands on its content rather than on its number.
20
+ *
21
+ * Pure: the server (cli/edit.mjs) reads the bytes and sends the message.
22
+ */
23
+
24
+ import { slideOpsOf, slideRenumberOf } from './commit-split.mjs';
25
+ import { indexOfCI, sectionChildRanges, splitOpenTag, readAttrs } from '../tools/deck-html.mjs';
26
+
27
+ /** Past this many bytes of new slide markup, a patch is a reload: one message is no place for megabytes of data URIs. */
28
+ export const PATCH_MAX_BYTES = 1_000_000;
29
+
30
+ /**
31
+ * The deck's top-level `<section>`s, its slides, as `{ start, end }` offsets
32
+ * into `html` (end past `</section>`). Script, style and comment bodies are
33
+ * blanked first, offsets kept, so a runtime inlined in the page or a slide that
34
+ * SHOWS markup does not open or close a slide; a section inside a section is
35
+ * part of its slide, as the runtime counts them. Pure.
36
+ */
37
+ export function topSections(html) {
38
+ const src = String(html ?? '');
39
+ const blanked = src.replace(
40
+ /<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>|<!--[\s\S]*?-->/gi,
41
+ (m) => ' '.repeat(m.length),
42
+ );
43
+ const out = [];
44
+ let depth = 0;
45
+ let open = -1;
46
+ for (const m of blanked.matchAll(/<section\b|<\/section\s*>/gi)) {
47
+ if (m[0][1] !== '/') {
48
+ if (depth === 0) open = m.index;
49
+ depth += 1;
50
+ } else if (depth > 0) {
51
+ depth -= 1;
52
+ if (depth === 0) out.push({ start: open, end: m.index + m[0].length });
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+ /** The deck cut into its slides' markup and everything around them (`frame`, each slide a marker). */
59
+ function cut(html) {
60
+ const src = String(html ?? '');
61
+ const ranges = topSections(src);
62
+ const slides = ranges.map((r) => src.slice(r.start, r.end));
63
+ let frame = '';
64
+ let at = 0;
65
+ for (const r of ranges) { frame += `${src.slice(at, r.start)}\u0000`; at = r.end; }
66
+ frame += src.slice(at);
67
+ // the spacing between two slides is not the page's: a slide put in or taken out moves it
68
+ return { slides, frame: frame.replace(/\s*(?:\u0000\s*)+/g, '\u0000') };
69
+ }
70
+
71
+ /** A slide as the alignment compares it: whitespace at line ends ignored (as cli/commit-split.mjs reads slides). */
72
+ const source = (sec) => sec.split('\n').map((l) => l.trim()).join('\n');
73
+
74
+ // What a slide's part is called, by its tag (and a class for an aside or a
75
+ // chart): the definite name for a part that changed or went, the indefinite
76
+ // one for a part that was put in.
77
+ const PARTS = [
78
+ [/^h[12]$/, 'the title', 'a title'],
79
+ [/^h[3-6]$/, 'a heading', 'a heading'],
80
+ [/^ul$/, 'the bullet list', 'a bullet list'],
81
+ [/^ol$/, 'the numbered list', 'a numbered list'],
82
+ [/^(p|span)$/, 'the text', 'some text'],
83
+ [/^(img|picture)$/, 'the picture', 'a picture'],
84
+ [/^svg$/, 'the diagram', 'a diagram'],
85
+ [/^pre$/, 'the code', 'a code block'],
86
+ [/^table$/, 'the table', 'a table'],
87
+ [/^blockquote$/, 'the quote', 'a quote'],
88
+ [/^(video|audio)$/, 'the media', 'a video'],
89
+ [/^script$/, 'the script', 'a script'],
90
+ [/^style$/, 'the style', 'a style'],
91
+ ];
92
+ function partName(tag, markup) {
93
+ if (tag === 'aside') {
94
+ const cls = /^<aside\b[^>]*\bclass\s*=\s*["']([^"']*)["']/i.exec(markup)?.[1] ?? '';
95
+ if (/\bnotes\b/.test(cls)) return ['the notes', 'notes'];
96
+ if (/\bsources\b/.test(cls)) return ['the sources', 'sources'];
97
+ if (/\brehearse\b/.test(cls)) return ['the rehearsal notes', 'rehearsal notes'];
98
+ }
99
+ if (/^<\w+\b[^>]*(\bclass\s*=\s*["'][^"']*\bchart\b|\bdata-chart\b)/i.test(markup)) return ['the chart', 'a chart'];
100
+ if (tag === 'figure' && /<img\b/i.test(markup)) return ['the picture', 'a picture'];
101
+ for (const [re, the, a] of PARTS) if (re.test(tag)) return [the, a];
102
+ return ['the content', 'some content'];
103
+ }
104
+
105
+ /**
106
+ * What changed inside one slide, in a few words ("the bullet list", "the
107
+ * title and the notes", "a picture added"), or '' when it cannot be named (a
108
+ * change only of spacing, or of text between the elements). Each top-level
109
+ * element is matched by its markup: one gone and one come of the same kind is
110
+ * that part changed; the rest were added or removed. Pure.
111
+ */
112
+ export function slidePartsSaid(was, now) {
113
+ const parts = (sec) => {
114
+ try { return sectionChildRanges(sec).map((r) => ({ tag: r.tag, markup: sec.slice(r.start, r.end) })); } catch { return []; }
115
+ };
116
+ const a = parts(was), b = parts(now);
117
+ const said = [];
118
+ const say = (s) => { if (!said.includes(s)) said.push(s); };
119
+ const attrsOf = (sec) => readAttrs(splitOpenTag(sec.replace(/^<section\b/i, '')).attrs);
120
+ const oa = attrsOf(was), ob = attrsOf(now);
121
+ const keys = new Set([...Object.keys(oa), ...Object.keys(ob)]);
122
+ const differs = [...keys].filter((k) => oa[k] !== ob[k]);
123
+ if (differs.includes('data-layout')) say('the layout');
124
+ else if (differs.length) say("the slide's attributes");
125
+ const left = a.filter((p) => !b.some((q) => q.markup.trim() === p.markup.trim()));
126
+ const came = b.filter((q) => !a.some((p) => p.markup.trim() === q.markup.trim()));
127
+ for (const p of left) {
128
+ const [the] = partName(p.tag, p.markup);
129
+ const k = came.findIndex((q) => partName(q.tag, q.markup)[0] === the);
130
+ if (k !== -1) { came.splice(k, 1); say(the); } else say(`${the} removed`);
131
+ }
132
+ for (const q of came) say(`${partName(q.tag, q.markup)[1]} added`);
133
+ if (said.length > 2) return `${said.length} parts`;
134
+ return said.join(' and ');
135
+ }
136
+
137
+ /** "3", "3 and 9", "3, 5 and 9", or how many past four. */
138
+ function numbers(ns) {
139
+ const list = [...ns].sort((x, y) => x - y);
140
+ if (list.length > 4) return null;
141
+ return list.length === 1 ? String(list[0]) : `${list.slice(0, -1).join(', ')} and ${list.at(-1)}`;
142
+ }
143
+ function slidesPhrase(ns, verb) {
144
+ if (!ns.length) return null;
145
+ const listed = numbers(ns);
146
+ if (ns.length === 1) return `slide ${listed} ${verb}`;
147
+ return listed ? `slides ${listed} ${verb}` : `${ns.length} slides ${verb}`;
148
+ }
149
+ /** Clauses joined, at most three of them. */
150
+ function clauses(list) {
151
+ const c = list.filter(Boolean);
152
+ if (c.length > 3) return `${c.slice(0, 3).join(', ')} and more`;
153
+ return c.join(', ');
154
+ }
155
+
156
+ /** What changed around the slides: the head (styles, settings, the theme) or the rest of the page. */
157
+ function frameSaid(before, after) {
158
+ const head = (s) => {
159
+ const i = indexOfCI(s, '<head');
160
+ const j = indexOfCI(s, '</head>');
161
+ return i === -1 || j === -1 ? '' : s.slice(i, j);
162
+ };
163
+ return head(before) !== head(after) ? "the deck's head changed" : 'the deck changed outside its slides';
164
+ }
165
+
166
+ /**
167
+ * An outside edit, old bytes against new: null when nothing a page shows
168
+ * changed (the same bytes, or only the spacing between two slides); else
169
+ *
170
+ * { said, a few plain words: "slide 9 changed: the bullet list",
171
+ * "slide 4 added", "slides 7 and 8 swapped"
172
+ * patch?: { total, slides: [{ slide, html }] },
173
+ * present when the pages can swap the slides in place:
174
+ * the same slides in the same order, nothing around them
175
+ * changed, no script in a changed slide, not too big
176
+ * land: { go, moves, was, total } }
177
+ *
178
+ * `go` is the slide an author goes to (the first slide changed, added or
179
+ * moved, numbered in the new deck; after a removal only, the slide that now
180
+ * stands in the first one's place; null when no slide changed). `moves` is
181
+ * where each old slide went, `[[was, now | null]]` for every one whose number
182
+ * changed or that is gone (slideRenumber's pairs), so a page that is not
183
+ * following the change stays on its content. `was` and `total` are the two
184
+ * slide counts. Pure.
185
+ */
186
+ export function outsideEdit(before, after, { maxPatch = PATCH_MAX_BYTES } = {}) {
187
+ const old = String(before ?? ''), now = String(after ?? '');
188
+ if (old === now) return null;
189
+ const A = cut(old), B = cut(now);
190
+ const a = A.slides.map(source), b = B.slides.map(source);
191
+ const moves = slideRenumberOf(a, b);
192
+ const total = B.slides.length;
193
+ const land = { go: null, moves, was: A.slides.length, total };
194
+ const frameChanged = A.frame !== B.frame;
195
+
196
+ // the same slides, in the same order: each one that differs is that slide edited
197
+ if (!moves.length && A.slides.length === B.slides.length) {
198
+ const touched = [];
199
+ B.slides.forEach((sec, i) => { if (sec !== A.slides[i]) touched.push(i + 1); });
200
+ // only the spacing between slides moved: nothing a page shows changed
201
+ if (!touched.length && !frameChanged) return null;
202
+ land.go = touched[0] ?? null;
203
+ const detail = touched.length === 1 ? slidePartsSaid(A.slides[touched[0] - 1], B.slides[touched[0] - 1]) : '';
204
+ const slides = slidesPhrase(touched, 'changed');
205
+ const said = clauses([frameChanged && frameSaid(old, now), slides && (detail ? `${slides}: ${detail}` : slides)]);
206
+ const html = touched.map((n) => B.slides[n - 1]);
207
+ const inPlace = !frameChanged && touched.length > 0
208
+ && touched.every((n) => !/<script\b|\sdata-markdown\b/i.test(A.slides[n - 1] + B.slides[n - 1]))
209
+ && html.reduce((sum, h) => sum + h.length, 0) <= maxPatch;
210
+ return {
211
+ said: said || 'the deck changed on disk',
212
+ ...(inPlace ? { patch: { total, slides: touched.map((n, i) => ({ slide: n, html: html[i] })) } } : {}),
213
+ land,
214
+ };
215
+ }
216
+
217
+ // Slides went, came or moved: read off the alignment. A removed slide that
218
+ // reappears word for word was moved; one the renumbering still pairs with a
219
+ // slide of the new deck was rewritten in its place, so it changed.
220
+ const ops = slideOpsOf(a, b);
221
+ const to = new Map(moves);
222
+ const target = (was) => (to.has(was) ? to.get(was) : was);
223
+ const pairs = ops.filter((o) => o.kind === 'changed').map((o) => [o.was, o.slide]);
224
+ const moved = [];
225
+ const removed = [];
226
+ const taken = new Set();
227
+ for (const o of ops.filter((x) => x.kind === 'removed')) {
228
+ const n = target(o.was);
229
+ if (n === null) { removed.push(o.was); continue; }
230
+ taken.add(n);
231
+ if (a[o.was - 1] === b[n - 1]) moved.push([o.was, n]); else pairs.push([o.was, n]);
232
+ }
233
+ const changed = pairs.map(([, n]) => n);
234
+ const added = ops.filter((o) => o.kind === 'added' && !taken.has(o.slide)).map((o) => o.slide);
235
+ // a slide moved by one place swapped places with its neighbour
236
+ const movedSaid = moved.map(([w, n]) => (Math.abs(w - n) === 1 ? `slides ${Math.min(w, n)} and ${Math.max(w, n)} swapped` : `slide ${w} moved to ${n}`));
237
+ const detail = pairs.length === 1 && !added.length && !removed.length && !moved.length
238
+ ? slidePartsSaid(A.slides[pairs[0][0] - 1], B.slides[pairs[0][1] - 1]) : '';
239
+ const changedSaid = slidesPhrase(changed, 'changed');
240
+ const said = clauses([
241
+ frameChanged && frameSaid(old, now),
242
+ slidesPhrase(added, 'added'),
243
+ slidesPhrase(removed, 'removed'),
244
+ ...movedSaid,
245
+ changedSaid && (detail ? `${changedSaid}: ${detail}` : changedSaid),
246
+ ]);
247
+ // a swap touched both places; a longer move, the place the slide went to
248
+ const firsts = [...changed, ...added, ...moved.flatMap(([w, n]) => (Math.abs(w - n) === 1 ? [w, n] : [n]))];
249
+ if (firsts.length) land.go = Math.min(...firsts);
250
+ else if (removed.length) {
251
+ // the slide that now stands where the first removed one was
252
+ let n = null;
253
+ for (let k = Math.min(...removed) + 1; k <= A.slides.length && n === null; k++) n = target(k);
254
+ land.go = n ?? (total || null);
255
+ }
256
+ return { said: said || 'the deck changed on disk', land };
257
+ }
package/cli/paste.mjs ADDED
@@ -0,0 +1,92 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * What a paste may put in a deck (PRESENTING_EDITING, the clipboard).
6
+ *
7
+ * A paste is not an edit the author typed: any web page can put markup on
8
+ * the clipboard, a forged Decklight marker included, and markup that runs
9
+ * would run on the local origin that can write the deck. So everything
10
+ * pasted is cleaned here, on the server, before it reaches the file, and
11
+ * what was left out is named so the page can say it:
12
+ *
13
+ * - whole elements that run or embed: <script>, <style>, <iframe>, <frame>,
14
+ * <frameset>, <object>, <embed>, <applet>, <base>, <link>, <meta>, <form>;
15
+ * - every attribute `executableAttributes` (audit.mjs) finds: an `on*=`
16
+ * handler, a `javascript:` or `data:text/html` URL, a `srcdoc`;
17
+ * - a `style` attribute that reaches out (`url(javascript:`, `expression(`).
18
+ *
19
+ * Pictures by absolute http(s) URL stay: the author can already write them.
20
+ */
21
+
22
+ import { executableAttributes } from './audit.mjs';
23
+
24
+ /** The elements a paste never keeps, each with how the page says it was left out. */
25
+ const DROPPED_ELEMENTS = [
26
+ ['script', 'a script'], ['style', 'a style block'], ['iframe', 'a frame'], ['frame', 'a frame'], ['frameset', 'a frame'],
27
+ ['object', 'an embedded object'], ['embed', 'an embedded object'], ['applet', 'an embedded object'],
28
+ ['base', 'a base link'], ['link', 'a linked file'], ['meta', 'a meta tag'], ['form', 'a form'],
29
+ ];
30
+ const VOID = new Set(['embed', 'base', 'link', 'meta', 'frame']);
31
+
32
+ /**
33
+ * `html` with everything that would run taken out. Returns `{ html, dropped }`:
34
+ * `dropped` is what was left out, said once each ("a script", "an onclick
35
+ * handler", "a javascript: link").
36
+ */
37
+ export function sanitizePasted(html) {
38
+ let out = String(html ?? '');
39
+ const said = new Set();
40
+ // comments go first: one could hide a tag from the walk below, and none is content
41
+ out = out.replace(/<!--[\s\S]*?-->/g, '');
42
+ for (const [tag, what] of DROPPED_ELEMENTS) {
43
+ const whole = VOID.has(tag)
44
+ ? new RegExp(`<${tag}\\b[^>]*>`, 'gi')
45
+ : new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}\\s*>|<${tag}\\b[^>]*\\/?>`, 'gi');
46
+ out = out.replace(whole, () => { said.add(what); return ''; });
47
+ }
48
+ // a stray close tag of one of them, left by an element that never opened
49
+ out = out.replace(new RegExp(`<\\/(?:${DROPPED_ELEMENTS.map(([t]) => t).join('|')})\\s*>`, 'gi'), '');
50
+ // attributes that run, last to first so each offset still stands
51
+ const found = executableAttributes(out).sort((a, b) => b.start - a.start);
52
+ for (const f of found) {
53
+ out = out.slice(0, f.start).replace(/\s+$/, '') + out.slice(f.end);
54
+ said.add(f.kind === 'handler' ? `an ${f.attr} handler` : f.kind === 'executable URL' ? `a ${/data:/i.test(f.snippet) ? 'data:' : 'javascript:'} link` : 'an inline document');
55
+ }
56
+ // a style that reaches out of the page
57
+ out = out.replace(/\sstyle\s*=\s*("[^"]*"|'[^']*')/gi, (m, v) => {
58
+ if (!/url\s*\(\s*["']?\s*javascript:|expression\s*\(|-moz-binding|behavior\s*:/i.test(v)) return m;
59
+ said.add('a style that runs code');
60
+ return '';
61
+ });
62
+ return { html: out, dropped: [...said] };
63
+ }
64
+
65
+ /** The relative paths a paste points at (a picture, a background, a video), each once, in order. */
66
+ export function relativeAssets(html) {
67
+ const out = new Set();
68
+ const re = /\s(?:src|poster|href|data-background-image|data-background-video|data-background-poster)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"']+))/gi;
69
+ for (const m of String(html ?? '').matchAll(re)) {
70
+ const v = (m[1] ?? m[2] ?? m[3] ?? '').trim();
71
+ if (!v || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i.test(v)) continue;
72
+ out.add(v.split(/[?#]/)[0]);
73
+ }
74
+ return [...out];
75
+ }
76
+
77
+ /**
78
+ * A slide from the clipboard, as the deck will take it (PRESENTING_EDITING):
79
+ * exactly one `<section>…</section>`, cleaned the way an element is
80
+ * (sanitizePasted), its page ids left behind (`withoutPageIds`, handed in so
81
+ * this file stays free of the editor's). Returns `{ section, dropped }`, or
82
+ * throws a sentence (status 400) for anything else.
83
+ */
84
+ export function pasteSection(markup, withoutPageIds = (x) => x) {
85
+ const { html, dropped } = sanitizePasted(markup);
86
+ const t = html.trim();
87
+ const opens = t.match(/<section\b/gi) ?? [];
88
+ if (!/^<section\b[^>]*>[\s\S]*<\/section>$/i.test(t) || opens.length !== 1) {
89
+ throw Object.assign(new Error('a pasted slide is one <section>, and this is not one'), { status: 400 });
90
+ }
91
+ return { section: withoutPageIds(t), dropped };
92
+ }