decklight 0.8.1 → 0.9.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 (133) hide show
  1. package/PLATFORM.md +666 -0
  2. package/README.md +224 -150
  3. package/SPEC.md +732 -886
  4. package/cli/agent-review.mjs +245 -0
  5. package/cli/agents.mjs +25 -5
  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 +183 -0
  10. package/cli/bundle.mjs +383 -31
  11. package/cli/cast.mjs +7 -7
  12. package/cli/check.mjs +961 -0
  13. package/cli/clone-deck.mjs +179 -0
  14. package/cli/commands.mjs +345 -0
  15. package/cli/comments.mjs +64 -18
  16. package/cli/commit-flow.mjs +44 -19
  17. package/cli/commit-message.mjs +51 -74
  18. package/cli/commit-split.mjs +601 -0
  19. package/cli/deck-refs.mjs +59 -0
  20. package/cli/deck-routes.mjs +67 -0
  21. package/cli/deckfile.mjs +3 -5
  22. package/cli/decklight.mjs +68 -289
  23. package/cli/design-system-deps.mjs +209 -0
  24. package/cli/design-system-edit.mjs +194 -0
  25. package/cli/design-system-refs.mjs +409 -0
  26. package/cli/design-system.mjs +429 -0
  27. package/cli/doctor.mjs +115 -0
  28. package/cli/edit-git.mjs +353 -0
  29. package/cli/edit-handover.mjs +445 -0
  30. package/cli/edit-look.mjs +388 -0
  31. package/cli/edit-slides.mjs +683 -0
  32. package/cli/edit.mjs +2126 -842
  33. package/cli/enhance.mjs +483 -0
  34. package/cli/extension.mjs +10 -10
  35. package/cli/font-refs.mjs +273 -0
  36. package/cli/font.mjs +246 -0
  37. package/cli/git-tree.mjs +1 -1
  38. package/cli/git.mjs +65 -11
  39. package/cli/import.mjs +56 -10
  40. package/cli/init.mjs +400 -234
  41. package/cli/library.mjs +127 -0
  42. package/cli/loader.mjs +3 -1
  43. package/cli/marketplace.mjs +215 -21
  44. package/cli/narrate.mjs +176 -0
  45. package/cli/open-browser.mjs +63 -0
  46. package/cli/open.mjs +943 -0
  47. package/cli/pdf.mjs +41 -13
  48. package/cli/pkg.mjs +44 -2
  49. package/cli/plugin.mjs +43 -41
  50. package/cli/port-conflict.mjs +53 -23
  51. package/cli/pptx-export.mjs +57 -24
  52. package/cli/publish.mjs +8 -4
  53. package/cli/qr.mjs +1 -1
  54. package/cli/record.mjs +14 -12
  55. package/cli/remote.mjs +11 -11
  56. package/cli/restore.mjs +11 -4
  57. package/cli/review-ref.mjs +125 -0
  58. package/cli/review-remote.mjs +92 -48
  59. package/cli/review-routes.mjs +254 -0
  60. package/cli/review-store.mjs +47 -7
  61. package/cli/review-submit.mjs +47 -57
  62. package/cli/runtime-link.mjs +560 -0
  63. package/cli/serve.mjs +235 -44
  64. package/cli/setup.mjs +112 -0
  65. package/cli/sign.mjs +1 -1
  66. package/cli/skill-content.mjs +190 -33
  67. package/cli/skills.mjs +107 -24
  68. package/cli/start.mjs +110 -0
  69. package/cli/supervise.mjs +6 -6
  70. package/cli/theme-refs.mjs +515 -0
  71. package/cli/theme.mjs +181 -137
  72. package/cli/trust.mjs +83 -0
  73. package/cli/units.mjs +39 -42
  74. package/cli/update-check.mjs +1 -5
  75. package/cli/upgrade.mjs +194 -28
  76. package/cli/upstream.mjs +4 -3
  77. package/cli/util.mjs +4 -4
  78. package/cli/wizard.mjs +6 -6
  79. package/dist/build-info.json +1 -1
  80. package/dist/decklight.css +1126 -49
  81. package/dist/decklight.js +212 -115
  82. package/dist/decklight.js.map +4 -4
  83. package/docs/GLOSSARY.md +141 -0
  84. package/docs/architecture.svg +17 -17
  85. package/package.json +4 -2
  86. package/themes/README.md +9 -8
  87. package/themes/reveal-solarized.css +10 -0
  88. package/tools/args.mjs +20 -0
  89. package/tools/atomic-write.mjs +48 -0
  90. package/tools/brand-palette.mjs +717 -0
  91. package/tools/bridge.mjs +1 -1
  92. package/tools/build-groups.mjs +42 -0
  93. package/tools/color.mjs +48 -0
  94. package/tools/deck-html.mjs +396 -11
  95. package/tools/design-system-format.mjs +753 -0
  96. package/tools/elevenlabs-tts.mjs +110 -17
  97. package/tools/exec.mjs +1 -1
  98. package/tools/extension-check.mjs +31 -7
  99. package/tools/font-format.mjs +190 -0
  100. package/tools/font-stacks.mjs +24 -0
  101. package/tools/gemini-tts.mjs +3 -0
  102. package/tools/lipsync-config.mjs +103 -0
  103. package/tools/lipsync-engines.mjs +205 -2
  104. package/tools/lipsync-server.mjs +264 -41
  105. package/tools/lipsync.mjs +37 -18
  106. package/tools/local-voice.mjs +32 -42
  107. package/tools/narration-manifest.mjs +196 -0
  108. package/tools/narration-synth.mjs +416 -0
  109. package/tools/pptx.mjs +776 -19
  110. package/tools/publish-targets.mjs +1 -1
  111. package/tools/publish-voices.mjs +3 -3
  112. package/tools/recording-impact.mjs +7 -3
  113. package/tools/render-theme.mjs +33 -0
  114. package/tools/review-anchor.mjs +28 -12
  115. package/tools/semver.mjs +40 -0
  116. package/tools/sentences.mjs +180 -0
  117. package/tools/shot.mjs +14 -7
  118. package/tools/site-voices.mjs +232 -0
  119. package/tools/template-theme.mjs +1 -1
  120. package/tools/test-impact.mjs +17 -10
  121. package/tools/theme-check.mjs +30 -3
  122. package/tools/tts-cache.mjs +4 -3
  123. package/tools/tts-engines.mjs +38 -20
  124. package/tools/tts-setup.mjs +7 -7
  125. package/tools/video-options.mjs +34 -0
  126. package/tools/video.mjs +461 -48
  127. package/tools/voiceover-server.mjs +185 -104
  128. package/tools/voiceover.mjs +119 -261
  129. package/tools/zip.mjs +1 -1
  130. package/cli/dev.mjs +0 -623
  131. package/cli/present.mjs +0 -853
  132. package/cli/review.mjs +0 -361
  133. package/tools/publish-site-voices.mjs +0 -75
@@ -21,16 +21,23 @@ import { wavFromPcm } from './gemini-tts.mjs';
21
21
  export const KEY_ENV = 'ELEVENLABS_API_KEY';
22
22
  const API = 'https://api.elevenlabs.io/v1';
23
23
 
24
- // eleven_multilingual_v2 is the quality default and speaks every voice a
25
- // clone produces; --tts-model eleven_turbo_v2_5 trades a little of it for
26
- // latency, which live narration may prefer on a long deck.
27
- export const DEFAULT_MODEL = 'eleven_multilingual_v2';
28
-
29
- // The only ElevenLabs model that reads bracketed audio tags ([excited],
30
- // [whispers], …) as performance direction instead of words to pronounce — v3
31
- // joins the same style channel gemini has always had, opt-in only, because
32
- // every other model would read the brackets aloud (SPEC PRESENTING).
24
+ // eleven_v4 is the default: it reads the audio tags a script is written with
25
+ // ([whispers], [laughs], [long pause]) as direction, follows them more
26
+ // reliably than v3, and answers sooner. --tts-model eleven_v4_turbo trades a
27
+ // little quality for latency; eleven_multilingual_v2 is the pre-tag voice.
28
+ // A track already recorded keeps the model its manifest names — voiceover
29
+ // reads it back — so changing this default re-voices nothing.
30
+ export const DEFAULT_MODEL = 'eleven_v4';
31
+
32
+ // v3 was the first ElevenLabs model to read bracketed audio tags as
33
+ // performance direction instead of words to pronounce; v4 follows them more
34
+ // reliably. Every other model reads the brackets ALOUD, so tags — a deck's
35
+ // own and the style channel gemini has always had — reach only these
36
+ // (SPEC PRESENTING).
33
37
  export const V3_MODEL = 'eleven_v3';
38
+ export const TAG_MODELS = ['eleven_v3', 'eleven_v4', 'eleven_v4_turbo'];
39
+ /** Does this ElevenLabs model act on `[whispers]`-style audio tags? */
40
+ export const readsAudioTags = (model) => TAG_MODELS.includes(model);
34
41
 
35
42
  // v3's stability slider is not the continuous 0–1 knob older models expose —
36
43
  // ElevenLabs documents exactly these three named positions. Creative follows
@@ -83,12 +90,27 @@ export const apiKey = (env = process.env) => env[KEY_ENV]?.trim() || null;
83
90
  * it under twenty stock ones would make the feature technically present and
84
91
  * practically useless. Within a group the API's own order is kept.
85
92
  */
93
+ /**
94
+ * The languages a voice speaks, as two-letter codes (`['en', 'fr']`): what
95
+ * ElevenLabs verified it for, and the language its labels name. The picker
96
+ * filters on these (`lang:es`), and opens on the deck's own language, so a
97
+ * deck translated to Spanish offers the voices that sound Spanish first.
98
+ */
99
+ export function voiceLangs(v) {
100
+ const codes = [
101
+ ...(v?.verified_languages ?? []).map((l) => l?.language ?? l?.locale),
102
+ v?.labels?.language, v?.labels?.locale, v?.language, v?.locale,
103
+ ];
104
+ return [...new Set(codes.filter(Boolean).map((c) => String(c).toLowerCase().split(/[-_]/)[0]).filter((c) => /^[a-z]{2,3}$/.test(c)))];
105
+ }
106
+
86
107
  export function shapeVoices(json) {
87
108
  const rank = { cloned: 0, professional: 1, generated: 2, premade: 3 };
88
109
  return (json?.voices ?? [])
89
110
  .map((v, i) => ({
90
111
  name: String(v.name ?? '').trim() || v.voice_id,
91
112
  id: v.voice_id,
113
+ langs: voiceLangs(v),
92
114
  // `category` is ElevenLabs' own word for where a voice came from, and
93
115
  // "cloned" is exactly the label that makes yours findable at a glance
94
116
  flavor: v.category === 'premade'
@@ -100,22 +122,54 @@ export function shapeVoices(json) {
100
122
  .sort((a, b) => a.order[0] - b.order[0] || a.order[1] - b.order[1]);
101
123
  }
102
124
 
125
+ /**
126
+ * The ElevenLabs voice LIBRARY (GET /v1/shared-voices) as the picker lists it:
127
+ * voices other people share, searchable by language — where the native
128
+ * Spanish or Portuguese voice for a translated deck is, when the account's
129
+ * own are English. `preview` is ElevenLabs' own sample (free to play);
130
+ * `owner` + `id` are what adding one to the account takes.
131
+ */
132
+ export function shapeLibrary(json) {
133
+ return (json?.voices ?? []).filter((v) => v?.voice_id && v?.public_owner_id).map((v) => ({
134
+ owner: v.public_owner_id,
135
+ id: v.voice_id,
136
+ name: String(v.name ?? '').trim() || v.voice_id,
137
+ // "young · female · british · narrative_story" — what a stranger's voice is, in its own labels
138
+ flavor: [v.age, v.gender, v.accent, v.use_case ?? v.descriptive].filter(Boolean).join(' · ').replace(/_/g, ' '),
139
+ description: String(v.description ?? '').trim().slice(0, 200),
140
+ langs: voiceLangs(v),
141
+ preview: v.preview_url ?? null,
142
+ }));
143
+ }
144
+
103
145
  /**
104
146
  * Which voice the player meant. It sends a NAME — that is what it persists per
105
147
  * deck and what a human recognises — but a raw voice_id is accepted too, so an
106
148
  * id pasted from the ElevenLabs dashboard works without a lookup. Matching is
107
149
  * case- and space-insensitive because the name came from a text field.
150
+ *
151
+ * The premade voices carry a tagline after the name ("Chris - Charming,
152
+ * Down-to-Earth"), and nobody types the tagline: the name before " - " is
153
+ * the voice's name too, when exactly one voice answers to it. Two that do
154
+ * (a cloned "Chris" beside the premade one) is nobody's guess to make, so
155
+ * that is no match, and the refusal lists them.
108
156
  */
109
157
  export function pickVoice(roster, requested) {
110
158
  if (!roster.length) return null;
111
159
  if (!requested) return roster[0];
160
+ const squash = (t) => String(t).trim().toLowerCase().replace(/\s+/g, '');
112
161
  const want = String(requested).trim().toLowerCase();
113
- return roster.find((v) => v.id === requested)
162
+ const exact = roster.find((v) => v.id === requested)
114
163
  ?? roster.find((v) => v.name.toLowerCase() === want)
115
- ?? roster.find((v) => v.name.toLowerCase().replace(/\s+/g, '') === want.replace(/\s+/g, ''))
116
- ?? null;
164
+ ?? roster.find((v) => squash(v.name) === squash(want));
165
+ if (exact) return exact;
166
+ const byShortName = roster.filter((v) => squash(shortName(v.name)) === squash(want));
167
+ return byShortName.length === 1 ? byShortName[0] : null;
117
168
  }
118
169
 
170
+ /** "Chris - Charming, Down-to-Earth" → "Chris": the name before the tagline's " - ". */
171
+ export const shortName = (name) => String(name).split(/\s+-\s+/)[0].trim();
172
+
119
173
  /**
120
174
  * Turn an API failure into a sentence that names the way out. The two that
121
175
  * actually happen are a key that isn't one (401) and PCM on a tier that does
@@ -182,6 +236,45 @@ export function createSynth({
182
236
  return roster;
183
237
  }
184
238
 
239
+ /**
240
+ * Search the voice library — `language` a two-letter code, `search` free
241
+ * text. Reading it costs nothing and changes nothing.
242
+ */
243
+ async function searchLibrary({ language, search, page = 0, pageSize = 30 } = {}) {
244
+ const q = new URLSearchParams({ page_size: String(pageSize), page: String(page) });
245
+ if (language) q.set('language', language);
246
+ if (search) q.set('search', search);
247
+ const res = await fetchImpl(`${API}/shared-voices?${q}`, { headers });
248
+ if (!res.ok) throw new Error(synthError(res.status, await res.text(), { format }));
249
+ const j = await res.json();
250
+ return { voices: shapeLibrary(j), hasMore: j.has_more === true };
251
+ }
252
+ /**
253
+ * Add a library voice to the account (POST /v1/voices/add/{owner}/{id}) —
254
+ * the one call here that CHANGES the account, and only ever on the
255
+ * presenter's own ⏎. The roster is fetched afresh after, so it is offered
256
+ * at once.
257
+ */
258
+ async function addLibraryVoice({ owner, id, name }) {
259
+ if (!owner || !id || !name) throw new Error('adding a library voice needs its owner, id and name');
260
+ const res = await fetchImpl(`${API}/voices/add/${encodeURIComponent(owner)}/${encodeURIComponent(id)}`, {
261
+ method: 'POST',
262
+ headers: { ...headers, 'content-type': 'application/json' },
263
+ body: JSON.stringify({ new_name: name }),
264
+ });
265
+ if (!res.ok) {
266
+ const text = await res.text();
267
+ // a plan's voice slots are the one limit a presenter will meet here
268
+ if (/voice_limit|limit_reached|maximum/i.test(text)) {
269
+ throw new Error('your ElevenLabs plan has no free voice slot — remove a voice at elevenlabs.io/app/voice-lab, then try again');
270
+ }
271
+ throw new Error(synthError(res.status, text, { format }));
272
+ }
273
+ const j = await res.json().catch(() => ({}));
274
+ roster = null; // the next listVoices() asks again, and finds it
275
+ return { id: j.voice_id ?? id, name };
276
+ }
277
+
185
278
  async function call(text, voice) {
186
279
  const payload = { text, model_id: model };
187
280
  // Unasked, the account's own voice settings are left alone — sending a
@@ -212,10 +305,10 @@ export function createSynth({
212
305
  throw new Error(`no ElevenLabs voice named ${JSON.stringify(voice)} on this key — have: `
213
306
  + list.map((v) => v.name).join(', '));
214
307
  }
215
- // Audio tags are a v3-only delivery channel (SPEC PRESENTING). Sent to any
216
- // other model the brackets are read aloud as words, so a tone is NEVER
217
- // attached unless this is the model that can act on it.
218
- const tag = model === V3_MODEL ? styleTag(style) : '';
308
+ // Audio tags reach only the models that act on them (SPEC PRESENTING).
309
+ // Sent to any other model the brackets are read aloud as words, so a tone
310
+ // is NEVER attached unless this is a model that can act on it.
311
+ const tag = readsAudioTags(model) ? styleTag(style) : '';
219
312
  const sent = tag ? `${tag} ${text}` : text;
220
313
  let lastErr;
221
314
  for (let attempt = 0; attempt < 3; attempt++) {
@@ -244,5 +337,5 @@ export function createSynth({
244
337
  throw lastErr;
245
338
  }
246
339
  synth.mimeType = format === 'pcm' ? 'audio/wav' : 'audio/mpeg';
247
- return { listVoices, synth };
340
+ return { listVoices, synth, searchLibrary, addLibraryVoice };
248
341
  }
package/tools/exec.mjs CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * #431 found a `say` with 0.31s of CPU after eight minutes, blocked in macOS's
8
8
  * speech server, and an execFileSync above it with no timeout — so
9
- * `decklight voiceover` waited with it, silently. That was one call of forty-
9
+ * `decklight narrate` waited with it, silently. That was one call of forty-
10
10
  * three. The others are the same shape with different daemons behind them:
11
11
  * gcloud waiting on a login that expired, gh waiting on the network, ffmpeg
12
12
  * spinning on a file that is not what its extension says, Chrome waiting on
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  // The marketplace admission gate for build-time code (MARKETPLACE.md
5
- // EXTENSIONS#CHECK, SPEC EXTENSIONS_CHECK) — what `decklight extension check`
5
+ // EXTENSIONS#CHECK, SPEC EXTENSIONS_CHECK) — what `decklight library gate transform`
6
6
  // runs. Lives under tools/, which ships, for the reason tools/theme-check.mjs
7
7
  // already gives: test/ does not, so a marketplace's own CI needs this
8
8
  // reachable from the installed package, not from a suite that never travels.
@@ -77,9 +77,29 @@ export const TYPES = ['transform'];
77
77
  export const artifactSha256 = (file) =>
78
78
  createHash('sha256').update(readFileSync(file)).digest('hex');
79
79
 
80
- /** How long the submission gets, in each of its two executions (the transform
81
- * run and the headless load of its output), before a hard kill. */
82
- export const CHECK_TIMEOUT_MS = 15_000;
80
+ /** How long the submission's OWN RUN gets before a hard kill. Pure Node, and
81
+ * the submission is the only thing on this clock: a transform that has not
82
+ * returned in fifteen seconds is not coming back. */
83
+ export const CHECK_TIMEOUT_MS = Number(process.env.DECKLIGHT_CHECK_TIMEOUT_MS) || 15_000;
84
+
85
+ /**
86
+ * The headless load's kill — separate, and raisable, because this clock pays
87
+ * for something the submission did not do: LAUNCHING A BROWSER.
88
+ *
89
+ * It is still load-bearing. `--virtual-time-budget` bounds Chrome's own clock,
90
+ * not the real one, so a synchronous `alert()` in the output blocks the render
91
+ * loop outside virtual time entirely and only a wall clock catches it. But the
92
+ * same wall clock also has to cover a cold Chrome start, and that varies by
93
+ * machine in a way the submission has no part in: a shared Windows CI runner
94
+ * doing a full `verify` in 564s against 224s on a laptop refused this project's
95
+ * OWN baseline transform — the one that exists to pass — for "blocking the
96
+ * page". An admission gate that accuses a clean submission of hanging, because
97
+ * the checking machine was busy, is worse than one that takes a minute to
98
+ * reject a hostile one. So slow machines raise it (`DECKLIGHT_CHECK_LOAD_MS`),
99
+ * exactly as they already raise `VERIFY_TIMEOUT_MS`, and the default is
100
+ * unchanged for anyone running `decklight library gate transform` by hand.
101
+ */
102
+ export const LOAD_TIMEOUT_MS = Number(process.env.DECKLIGHT_CHECK_LOAD_MS) || CHECK_TIMEOUT_MS;
83
103
 
84
104
  /** What the runner's verdict on stdout follows — AFTER whatever the transform
85
105
  * itself printed, so the parent reads past the LAST occurrence and a forged
@@ -95,7 +115,7 @@ export const RESULT_DELIM = '\n__decklight_extension_check_result__';
95
115
  export function makeFixture() {
96
116
  const nonce = randomBytes(8).toString('hex');
97
117
  return `<!doctype html>\n<html><head><title>check ${nonce}</title></head>`
98
- + `<body><section><h2>Check ${nonce}</h2><p>decklight extension check ${nonce}</p></section></body></html>\n`;
118
+ + `<body><section><h2>Check ${nonce}</h2><p>decklight library gate transform ${nonce}</p></section></body></html>\n`;
99
119
  }
100
120
 
101
121
  /**
@@ -215,7 +235,7 @@ function headlessLoad(html) {
215
235
  '--virtual-time-budget=2000', '--dump-dom', `file://${file}`,
216
236
  ), {
217
237
  encoding: 'utf8', maxBuffer: 8 * 1024 * 1024,
218
- timeout: CHECK_TIMEOUT_MS, killSignal: 'SIGKILL',
238
+ timeout: LOAD_TIMEOUT_MS, killSignal: 'SIGKILL',
219
239
  stdio: ['ignore', 'pipe', 'ignore'],
220
240
  });
221
241
  } finally {
@@ -248,7 +268,11 @@ export async function checkExtension(file, { type = 'transform' } = {}) {
248
268
  dumped = headlessLoad(run.html);
249
269
  } catch (e) {
250
270
  if (e.signal || e.code === 'ETIMEDOUT') {
251
- return { ok: false, phase: 'output', error: 'the headless load did not finish within 15s and was killed —'
271
+ // the budget, not a literal: this message used to say "15s" while the
272
+ // number beside it was a constant, so raising one would have made the
273
+ // refusal lie about why it fired
274
+ return { ok: false, phase: 'output', error: 'the headless load did not finish within'
275
+ + ` ${Math.round(LOAD_TIMEOUT_MS / 1000)}s and was killed —`
252
276
  + ' the output must never block the page (a synchronous alert()/confirm()/prompt(), or an infinite loop)' };
253
277
  }
254
278
  throw e;
@@ -0,0 +1,190 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // The font package format, and the rules it is held to (SPEC FONTS). A font
5
+ // is what a theme NAMES and cannot carry: a theme's --font-body is a list of
6
+ // family names, and the files behind a name that is not on the machine come
7
+ // from somewhere else — a Google Fonts @import that needs the network, or
8
+ // nothing. A font package carries the faces themselves, by reference from a
9
+ // marketplace, so a deck (and its bundle) has them wherever it is opened.
10
+ //
11
+ // <name>/
12
+ // font.json apiVersion, name, version, title, family, fallback,
13
+ // license, faces [{ file, weight, style }] (+ description, role)
14
+ // *.woff2 the faces — woff2 or woff, nothing else that runs or loads
15
+ // OFL.txt … the licence the manifest names: a hand-over redistributes
16
+ // the font, so a package without one is refused
17
+ //
18
+ // PURE: texts and a file list in, never a path. `decklight font gate` is a
19
+ // thin main over it, and the same rules run again wherever a package is
20
+ // served — and `fontFaceCss` is the one place an @font-face rule is written,
21
+ // for the servers and for bundle alike.
22
+
23
+ import { SEMVER_RE } from './semver.mjs';
24
+ import { NAME_RE, packagePathProblem } from './design-system-format.mjs';
25
+
26
+ /** The font-package contract's own version — additive only, like DESIGN_SYSTEM_API_VERSION. */
27
+ export const FONT_API_VERSION = 1;
28
+
29
+ /** What a face may be. The magic bytes are checked too: an extension is a claim. */
30
+ export const FACE_EXTENSIONS = ['woff2', 'woff'];
31
+ const MAGIC = { woff2: 'wOF2', woff: 'wOFF' };
32
+
33
+ /** Past this, a face is a warning — every deck that uses it, and every bundle, carries it. */
34
+ export const FACE_WARN_BYTES = 512 * 1024;
35
+
36
+ /** A family name as a stylesheet will quote it: letters, digits, spaces, _ and -. */
37
+ export const FAMILY_RE = /^[A-Za-z0-9][A-Za-z0-9 _-]{0,63}$/;
38
+ /** A fallback stack: family names (quoted or not), commas, spaces — nothing that could close a rule. */
39
+ const FALLBACK_RE = /^[A-Za-z0-9 ,'"_-]{1,200}$/;
40
+ const GENERIC = /(^|,)\s*(serif|sans-serif|monospace|cursive|fantasy|system-ui|ui-serif|ui-sans-serif|ui-monospace|ui-rounded|math|emoji)\s*$/;
41
+ export const ROLES = ['body', 'heading', 'mono', 'any'];
42
+
43
+ const lineAt = (text, index) => text.slice(0, index).split('\n').length;
44
+ const keyLine = (raw, key) => {
45
+ const i = raw.indexOf(`"${key}"`);
46
+ return i < 0 ? 1 : lineAt(raw, i);
47
+ };
48
+ const ext = (path) => (/\.([A-Za-z0-9]+)$/.exec(path)?.[1] ?? '').toLowerCase();
49
+ /** Top-level papers that are part of a package without being faces. */
50
+ const isPapers = (p) => /^(readme|license|licence|changelog|notice|ofl|authors|fontlog)([._-][\w.-]*)?(\.(md|txt))?$/i.test(p);
51
+
52
+ /** A weight as CSS takes it: a number 1–1000, or a variable font's "lo hi" range. */
53
+ function weightProblem(w) {
54
+ if (Number.isInteger(w)) return w >= 1 && w <= 1000 ? null : 'is outside 1–1000';
55
+ if (typeof w === 'string' && /^\d{1,4} \d{1,4}$/.test(w)) {
56
+ const [lo, hi] = w.split(' ').map(Number);
57
+ return lo >= 1 && hi <= 1000 && lo < hi ? null : 'must be "lo hi" with 1 ≤ lo < hi ≤ 1000';
58
+ }
59
+ return 'must be a number (400) or a variable font\'s range ("100 900")';
60
+ }
61
+
62
+ /**
63
+ * `font.json`, parsed and shaped: `{ manifest, problems }`, `manifest` null
64
+ * when the JSON itself does not parse.
65
+ */
66
+ export function readFontManifest(raw) {
67
+ const problems = [];
68
+ const file = 'font.json';
69
+ const at = (rule, key, msg) => problems.push({ file, line: keyLine(raw, key), rule, msg });
70
+ let m;
71
+ try { m = JSON.parse(raw); } catch (e) {
72
+ const pos = /position (\d+)/.exec(e.message)?.[1];
73
+ problems.push({ file, line: pos ? lineAt(raw, Number(pos)) : 1, rule: 'manifest-json', msg: `not valid JSON — ${e.message}` });
74
+ return { manifest: null, problems };
75
+ }
76
+ if (!m || typeof m !== 'object' || Array.isArray(m)) {
77
+ problems.push({ file, line: 1, rule: 'manifest-json', msg: 'must be a JSON object' });
78
+ return { manifest: null, problems };
79
+ }
80
+ if (!Number.isInteger(m.apiVersion) || m.apiVersion < 1) at('manifest-field', 'apiVersion', 'apiVersion must be a positive integer — the font format version this package needs');
81
+ else if (m.apiVersion > FONT_API_VERSION) at('api-too-new', 'apiVersion', `apiVersion ${m.apiVersion} needs a newer decklight — this one reads fonts up to ${FONT_API_VERSION}`);
82
+ if (typeof m.name !== 'string' || !NAME_RE.test(m.name)) at('manifest-field', 'name', `name ${JSON.stringify(m.name)} — a lowercase word: letters, digits and -, starting with a letter`);
83
+ if (typeof m.version !== 'string' || !SEMVER_RE.test(m.version)) at('manifest-field', 'version', `version ${JSON.stringify(m.version)} — a semver version, major.minor.patch (e.g. "4.1.0"), no leading v`);
84
+ if (typeof m.title !== 'string' || !m.title.trim()) at('manifest-field', 'title', 'title must be the font\'s human name, e.g. "Inter"');
85
+ if (typeof m.family !== 'string' || !FAMILY_RE.test(m.family)) {
86
+ at('manifest-field', 'family', `family ${JSON.stringify(m.family)} — the CSS family name a theme writes in --font-body: letters, digits, spaces, _ and -`);
87
+ }
88
+ if (typeof m.fallback !== 'string' || !FALLBACK_RE.test(m.fallback)) {
89
+ at('manifest-field', 'fallback', `fallback ${JSON.stringify(m.fallback)} — the stack used until the face loads, e.g. "system-ui, sans-serif": names, commas and quotes only`);
90
+ } else if (!GENERIC.test(m.fallback)) {
91
+ at('manifest-field', 'fallback', `fallback "${m.fallback}" must end in a generic family (sans-serif, serif, monospace, system-ui, …) — the one name every machine has`);
92
+ }
93
+ if (typeof m.license !== 'string') at('manifest-field', 'license', 'license must name the licence file in the package, e.g. "OFL.txt" — a font is licensed, and a deck that carries it redistributes it');
94
+ else {
95
+ const why = packagePathProblem(m.license);
96
+ if (why) at('file-outside', 'license', `license "${m.license}" ${why}`);
97
+ }
98
+ if (m.description !== undefined && typeof m.description !== 'string') at('manifest-field', 'description', 'description must be a string');
99
+ if (m.role !== undefined && !ROLES.includes(m.role)) at('manifest-field', 'role', `role must be one of ${ROLES.join(', ')} — what the font is drawn for`);
100
+ if (!Array.isArray(m.faces) || !m.faces.length) at('manifest-field', 'faces', 'faces must be a non-empty array of { file, weight, style }');
101
+ else {
102
+ const seen = new Set();
103
+ m.faces.forEach((f, i) => {
104
+ if (!f || typeof f !== 'object') { at('manifest-field', 'faces', `faces[${i}] must be { file, weight, style }`); return; }
105
+ if (typeof f.file !== 'string') at('manifest-field', 'faces', `faces[${i}].file must name a .woff2 or .woff in the package`);
106
+ else {
107
+ const why = packagePathProblem(f.file);
108
+ if (why) at('file-outside', 'faces', `faces[${i}].file "${f.file}" ${why}`);
109
+ else if (!FACE_EXTENSIONS.includes(ext(f.file))) at('face-extension', 'faces', `faces[${i}].file "${f.file}" — a face is ${FACE_EXTENSIONS.join(' or ')}`);
110
+ }
111
+ const wp = weightProblem(f.weight ?? 400);
112
+ if (wp) at('manifest-field', 'faces', `faces[${i}].weight ${JSON.stringify(f.weight)} ${wp}`);
113
+ const style = f.style ?? 'normal';
114
+ if (!['normal', 'italic'].includes(style)) at('manifest-field', 'faces', `faces[${i}].style must be "normal" or "italic"`);
115
+ const key = `${f.weight ?? 400}/${style}`;
116
+ if (seen.has(key)) at('face-twice', 'faces', `faces[${i}] is weight ${f.weight ?? 400} ${style} again — one file per weight and style`);
117
+ seen.add(key);
118
+ });
119
+ }
120
+ return { manifest: m, problems };
121
+ }
122
+
123
+ /**
124
+ * The admission gate over a package in memory: `{ manifest, files: Map<path,
125
+ * { size, head?, text? }> }` — `head` the first bytes as a latin1 string, for
126
+ * the magic check. Returns `{ ok, problems, warnings, summary }`.
127
+ */
128
+ export function checkFontPackage(pkg) {
129
+ const files = pkg.files ?? new Map();
130
+ const { manifest, problems } = readFontManifest(String(pkg.manifest ?? ''));
131
+ const warnings = [];
132
+ const summary = {};
133
+ if (!manifest) return { ok: false, problems, warnings, summary };
134
+ Object.assign(summary, {
135
+ name: manifest.name, version: manifest.version, apiVersion: manifest.apiVersion, title: manifest.title,
136
+ family: manifest.family, fallback: manifest.fallback, role: manifest.role ?? 'any', license: manifest.license,
137
+ });
138
+ if (typeof manifest.license === 'string' && !packagePathProblem(manifest.license)) {
139
+ const lic = files.get(manifest.license);
140
+ if (!lic) problems.push({ file: 'font.json', line: keyLine(String(pkg.manifest), 'license'), rule: 'license-missing', msg: `license names ${manifest.license}, which is not in the package — a font travels with its licence or not at all` });
141
+ else if (!lic.size) problems.push({ file: manifest.license, rule: 'license-missing', msg: 'the licence file is empty' });
142
+ }
143
+ const faces = [];
144
+ const named = new Set();
145
+ for (const [i, f] of (Array.isArray(manifest.faces) ? manifest.faces : []).entries()) {
146
+ if (!f || typeof f.file !== 'string' || packagePathProblem(f.file) || !FACE_EXTENSIONS.includes(ext(f.file))) continue;
147
+ named.add(f.file);
148
+ const got = files.get(f.file);
149
+ if (!got) { problems.push({ file: 'font.json', line: keyLine(String(pkg.manifest), 'faces'), rule: 'file-missing', msg: `faces[${i}].file ${f.file} is not in the package` }); continue; }
150
+ if (typeof got.head === 'string' && !got.head.startsWith(MAGIC[ext(f.file)])) {
151
+ problems.push({ file: f.file, rule: 'face-not-a-font', msg: `${f.file} is not a ${ext(f.file)} file — its first bytes are not "${MAGIC[ext(f.file)]}"` });
152
+ }
153
+ if ((got.size ?? 0) > FACE_WARN_BYTES) {
154
+ warnings.push({ file: f.file, rule: 'face-size', msg: `${Math.round(got.size / 1024)} KB — over the ${FACE_WARN_BYTES / 1024} KB a face should weigh; every deck and bundle that uses it carries it (subset it, or ship woff2)` });
155
+ }
156
+ faces.push({ file: f.file, weight: f.weight ?? 400, style: f.style ?? 'normal', size: got.size ?? 0 });
157
+ }
158
+ // anything else in the package: papers are fine, and so is nothing else
159
+ for (const path of files.keys()) {
160
+ if (path === 'font.json' || path === manifest.license || named.has(path)) continue;
161
+ if (path.split('/').some((seg) => seg.startsWith('.'))) continue;
162
+ if (!path.includes('/') && isPapers(path)) continue;
163
+ if (FACE_EXTENSIONS.includes(ext(path))) {
164
+ warnings.push({ file: path, rule: 'face-unused', msg: 'a face font.json does not list — it is never served' });
165
+ continue;
166
+ }
167
+ problems.push({ file: path, rule: 'file-kind', msg: `.${ext(path) || '(none)'} has no place in a font package — font.json, its faces (${FACE_EXTENSIONS.join(', ')}) and its licence` });
168
+ }
169
+ summary.faces = faces;
170
+ summary.bytes = faces.reduce((t, f) => t + f.size, 0);
171
+ return { ok: problems.length === 0, problems, warnings, summary };
172
+ }
173
+
174
+ /** The family and its fallback as a theme token would hold them: `'Inter', system-ui, sans-serif`. */
175
+ export const fontStack = (m) => `'${m.family}', ${m.fallback}`;
176
+
177
+ /**
178
+ * The @font-face rules for a package, one per face, each `src` from
179
+ * `urlFor(file, face)` — a served path, or a bundle's data: URI. The family
180
+ * and every value were held to the manifest's rules, so nothing here can
181
+ * close the rule it sits in. `font-display: swap`: the fallback shows at once
182
+ * and the face replaces it — a slide is never blank while a font loads.
183
+ */
184
+ export function fontFaceCss(manifest, urlFor) {
185
+ return (manifest.faces ?? []).map((f) => {
186
+ const format = ext(f.file) === 'woff2' ? 'woff2' : 'woff';
187
+ return `@font-face { font-family: '${manifest.family}'; src: url("${urlFor(f.file, f)}") format("${format}");`
188
+ + ` font-weight: ${f.weight ?? 400}; font-style: ${f.style ?? 'normal'}; font-display: swap; }`;
189
+ }).join('\n');
190
+ }
@@ -0,0 +1,24 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // The font picker's stacks (SPEC PRESENTING, FONTS): families every machine
5
+ // already has, by kind. Here, not in src/core/fonts.js, because the CLI names
6
+ // them too — a design system may recommend `humanist`, and `design-system
7
+ // add` applies it — and cli/ never imports from src/.
8
+
9
+ /** The stacks, in cycle order. Their ORDER is the old pref's meaning (an index) — append, never reorder. */
10
+ export const STACKS = [
11
+ ['theme default', null],
12
+ ['system sans', "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"],
13
+ ['rounded', "ui-rounded, 'SF Pro Rounded', 'Hiragino Maru Gothic ProN', Quicksand, Comfortaa, 'Arial Rounded MT Bold', Calibri, sans-serif"],
14
+ ['humanist', "Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif"],
15
+ ['geometric', "'Avenir Next', Avenir, Montserrat, Corbel, 'URW Gothic', source-sans-pro, sans-serif"],
16
+ ['classical serif', "'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif"],
17
+ ['transitional serif', "Charter, 'Bitstream Charter', 'Sitka Text', Cambria, Georgia, serif"],
18
+ ['slab serif', "Rockwell, 'Rockwell Nova', 'Roboto Slab', 'DejaVu Serif', 'Sitka Small', serif"],
19
+ ['monospace', "'SF Mono', SFMono-Regular, ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace"],
20
+ ];
21
+
22
+
23
+ /** The stack labels — what a deck's `font` default or a recommendation may name. */
24
+ export const STACK_LABELS = STACKS.map(([label]) => label);
@@ -121,6 +121,9 @@ export function createSynth({ project, ttsModel, location } = {}) {
121
121
  const res = await fetch(url, {
122
122
  method: 'POST',
123
123
  headers: authHeaders(token, project),
124
+ // bounded like every other call the bridge makes: a request Vertex never
125
+ // answers used to leave the player's /speak pending for good
126
+ signal: AbortSignal.timeout(NETWORK_MS),
124
127
  body: JSON.stringify({
125
128
  contents: [{ role: 'user', parts: [{ text }] }],
126
129
  generationConfig: {
@@ -0,0 +1,103 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * The talking-head setup, remembered (SPEC PRESENTING, character).
6
+ *
7
+ * Neural video needs four things decklight cannot find on its own: a Wav2Lip
8
+ * (or SadTalker) checkout, its checkpoint, the Python that has its packages,
9
+ * and a portrait. Passing them as flags to every `decklight <deck>` is how
10
+ * nobody ends up using the feature — so `decklight setup face …` writes
11
+ * them here once, the way the voice setup lives in `tts.json`, and the
12
+ * lip-sync bridge, `open` and `doctor` all read the same file.
13
+ *
14
+ * `~/.config/decklight/lipsync.json` ($XDG_CONFIG_HOME honored):
15
+ * { wav2lipDir, wav2lipCkpt, sadtalkerDir, python, portraits: ["name=path", …] }
16
+ */
17
+
18
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
19
+ import { homedir } from 'node:os';
20
+ import { basename, dirname, extname, join, resolve } from 'node:path';
21
+
22
+ export function lipsyncConfigPath(env = process.env) {
23
+ const base = env.XDG_CONFIG_HOME || join(env.HOME || homedir(), '.config');
24
+ return join(base, 'decklight', 'lipsync.json');
25
+ }
26
+
27
+ /** Where a portrait filmed from the deck is kept, beside lipsync.json. */
28
+ export function portraitsDir(env = process.env) {
29
+ return join(dirname(lipsyncConfigPath(env)), 'portraits');
30
+ }
31
+
32
+ /**
33
+ * `config` with portrait `name` pointing at `file` — replacing one of that
34
+ * name, else added — and the bridge's own `setup` (Wav2Lip, its checkpoint,
35
+ * its Python) filled in where the saved file has none, so a portrait filmed
36
+ * on a bridge started with flags still works on the next plain `open`. Pure.
37
+ */
38
+ export function withPortrait(config, name, file, setup = {}) {
39
+ const next = { ...(config ?? {}) };
40
+ for (const k of ['wav2lipDir', 'wav2lipCkpt', 'sadtalkerDir', 'python']) {
41
+ if (next[k] == null && setup[k] != null) next[k] = setup[k];
42
+ }
43
+ const kept = (next.portraits ?? []).filter((spec) => parsePortrait(spec)[0] !== name);
44
+ next.portraits = [...kept, `${name}=${file}`];
45
+ return next;
46
+ }
47
+
48
+ /** The saved setup, or null — a missing or unreadable file is "not set up", not an error. */
49
+ export function loadLipsyncConfig(env = process.env) {
50
+ try { return JSON.parse(readFileSync(lipsyncConfigPath(env), 'utf8')); }
51
+ catch { return null; }
52
+ }
53
+
54
+ export function saveLipsyncConfig(config, env = process.env) {
55
+ const file = lipsyncConfigPath(env);
56
+ mkdirSync(dirname(file), { recursive: true });
57
+ writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
58
+ return file;
59
+ }
60
+
61
+ /** `alice=face.png` → ['alice', '/abs/face.png']; a bare path is named by its basename. */
62
+ export function parsePortrait(spec) {
63
+ const at = String(spec).indexOf('=');
64
+ const file = resolve(at > 0 ? spec.slice(at + 1) : spec);
65
+ const name = at > 0 ? spec.slice(0, at) : basename(file, extname(file));
66
+ return [name, file];
67
+ }
68
+
69
+ /**
70
+ * What neural video can use, and what stands in the way — ONE answer, so the
71
+ * bridge's startup line, the deck's character row and `doctor` never disagree.
72
+ * `setup` is the flags-over-saved view: `{ wav2lipDir, wav2lipCkpt,
73
+ * sadtalkerDir, python, portraits: [spec] }`. Returns
74
+ * `{ engines: ['wav2lip'?, 'sadtalker'?], problems: [sentence…] }`.
75
+ */
76
+ export function videoSetup(setup, { exists = existsSync } = {}) {
77
+ const engines = [];
78
+ const problems = [];
79
+ const portraits = (setup?.portraits ?? []).map(parsePortrait);
80
+ const missingPortraits = portraits.filter(([, f]) => !exists(f)).map(([n, f]) => `${n} (${f})`);
81
+ if (missingPortraits.length) problems.push(`portrait not found: ${missingPortraits.join(', ')}`);
82
+ const havePortrait = portraits.some(([, f]) => exists(f));
83
+ const { wav2lipDir, wav2lipCkpt, sadtalkerDir } = setup ?? {};
84
+ if (wav2lipDir) {
85
+ if (!exists(join(wav2lipDir, 'inference.py'))) problems.push(`no Wav2Lip checkout at ${wav2lipDir} (inference.py is missing)`);
86
+ else if (!wav2lipCkpt) problems.push('Wav2Lip needs its checkpoint: --wav2lip-ckpt <wav2lip_gan.pth>');
87
+ else if (!exists(wav2lipCkpt)) problems.push(`Wav2Lip checkpoint not found: ${wav2lipCkpt}`);
88
+ else if (havePortrait) engines.push('wav2lip');
89
+ }
90
+ if (sadtalkerDir) {
91
+ if (!exists(join(sadtalkerDir, 'inference.py'))) problems.push(`no SadTalker checkout at ${sadtalkerDir} (inference.py is missing)`);
92
+ else if (havePortrait) engines.push('sadtalker');
93
+ }
94
+ if ((wav2lipDir || sadtalkerDir) && !havePortrait && !missingPortraits.length) {
95
+ problems.push('no portrait — add one: --portrait me=photo.jpg (a head-and-shoulders photo, or a short video of you: me=clip.mp4)');
96
+ }
97
+ if (setup?.python && setup.python.includes('/') && !exists(setup.python)) problems.push(`python not found: ${setup.python}`);
98
+ return { engines, problems };
99
+ }
100
+
101
+ /** The one command that sets neural video up — said wherever it is missing. */
102
+ export const SETUP_HINT = 'decklight setup face --wav2lip-dir <Wav2Lip checkout> --wav2lip-ckpt <wav2lip_gan.pth>'
103
+ + ' --python <its venv python> --portrait me=<photo.jpg>';