decklight 0.8.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/PLATFORM.md +707 -0
  2. package/README.md +226 -150
  3. package/SPEC.md +803 -888
  4. package/cli/agent-review.mjs +246 -0
  5. package/cli/agents.mjs +35 -9
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +190 -0
  10. package/cli/bundle-module.mjs +95 -0
  11. package/cli/bundle.mjs +439 -35
  12. package/cli/cast.mjs +48 -12
  13. package/cli/check-fixes.mjs +186 -0
  14. package/cli/check.mjs +988 -0
  15. package/cli/clone-deck.mjs +179 -0
  16. package/cli/commands.mjs +345 -0
  17. package/cli/comments.mjs +64 -18
  18. package/cli/commit-flow.mjs +51 -22
  19. package/cli/commit-message.mjs +51 -74
  20. package/cli/commit-split.mjs +601 -0
  21. package/cli/deck-refs.mjs +64 -0
  22. package/cli/deck-routes.mjs +67 -0
  23. package/cli/deckfile.mjs +3 -5
  24. package/cli/decklight.mjs +68 -289
  25. package/cli/design-system-deps.mjs +209 -0
  26. package/cli/design-system-edit.mjs +194 -0
  27. package/cli/design-system-refs.mjs +666 -0
  28. package/cli/design-system.mjs +497 -0
  29. package/cli/doctor.mjs +115 -0
  30. package/cli/edit-git.mjs +353 -0
  31. package/cli/edit-handover.mjs +551 -0
  32. package/cli/edit-look.mjs +631 -0
  33. package/cli/edit-slides.mjs +683 -0
  34. package/cli/edit.mjs +2585 -855
  35. package/cli/enhance.mjs +485 -0
  36. package/cli/extension.mjs +10 -10
  37. package/cli/font-refs.mjs +273 -0
  38. package/cli/font.mjs +246 -0
  39. package/cli/git-tree.mjs +1 -1
  40. package/cli/git.mjs +78 -11
  41. package/cli/import.mjs +56 -10
  42. package/cli/init.mjs +407 -236
  43. package/cli/library.mjs +127 -0
  44. package/cli/loader.mjs +3 -1
  45. package/cli/marketplace-autocheck.mjs +200 -0
  46. package/cli/marketplace.mjs +460 -29
  47. package/cli/narrate.mjs +251 -0
  48. package/cli/open-browser.mjs +63 -0
  49. package/cli/open.mjs +961 -0
  50. package/cli/pdf.mjs +64 -17
  51. package/cli/pkg.mjs +44 -2
  52. package/cli/plugin.mjs +43 -41
  53. package/cli/port-conflict.mjs +53 -23
  54. package/cli/pptx-export.mjs +63 -27
  55. package/cli/publish.mjs +8 -4
  56. package/cli/qr.mjs +1 -1
  57. package/cli/record.mjs +85 -23
  58. package/cli/remote.mjs +43 -17
  59. package/cli/restore.mjs +11 -4
  60. package/cli/review-ref.mjs +125 -0
  61. package/cli/review-remote.mjs +92 -48
  62. package/cli/review-routes.mjs +254 -0
  63. package/cli/review-store.mjs +47 -7
  64. package/cli/review-submit.mjs +47 -57
  65. package/cli/runtime-link.mjs +560 -0
  66. package/cli/serve.mjs +236 -45
  67. package/cli/setup.mjs +112 -0
  68. package/cli/sign.mjs +1 -1
  69. package/cli/skill-content.mjs +229 -35
  70. package/cli/skills.mjs +353 -26
  71. package/cli/start.mjs +110 -0
  72. package/cli/supervise.mjs +6 -6
  73. package/cli/theme-refs.mjs +527 -0
  74. package/cli/theme.mjs +181 -137
  75. package/cli/trust.mjs +83 -0
  76. package/cli/units.mjs +112 -47
  77. package/cli/update-check.mjs +1 -5
  78. package/cli/upgrade.mjs +194 -28
  79. package/cli/upstream.mjs +4 -3
  80. package/cli/util.mjs +4 -4
  81. package/cli/wizard.mjs +6 -6
  82. package/dist/build-info.json +1 -1
  83. package/dist/decklight.css +1533 -59
  84. package/dist/decklight.js +258 -115
  85. package/dist/decklight.js.map +4 -4
  86. package/docs/GLOSSARY.md +141 -0
  87. package/docs/architecture.svg +17 -17
  88. package/package.json +4 -2
  89. package/themes/README.md +9 -8
  90. package/themes/reveal-solarized.css +10 -0
  91. package/tools/args.mjs +20 -0
  92. package/tools/atomic-write.mjs +48 -0
  93. package/tools/brand-palette.mjs +717 -0
  94. package/tools/bridge.mjs +1 -1
  95. package/tools/build-groups.mjs +42 -0
  96. package/tools/color.mjs +48 -0
  97. package/tools/deck-html.mjs +396 -11
  98. package/tools/design-system-format.mjs +778 -0
  99. package/tools/design-system-migrations.mjs +207 -0
  100. package/tools/elevenlabs-tts.mjs +110 -17
  101. package/tools/exec.mjs +11 -3
  102. package/tools/extension-check.mjs +31 -7
  103. package/tools/font-format.mjs +190 -0
  104. package/tools/font-stacks.mjs +24 -0
  105. package/tools/gemini-tts.mjs +3 -0
  106. package/tools/lipsync-config.mjs +103 -0
  107. package/tools/lipsync-engines.mjs +205 -2
  108. package/tools/lipsync-server.mjs +264 -41
  109. package/tools/lipsync.mjs +37 -18
  110. package/tools/local-voice.mjs +32 -42
  111. package/tools/narration-manifest.mjs +270 -0
  112. package/tools/narration-synth.mjs +416 -0
  113. package/tools/pptx.mjs +776 -19
  114. package/tools/publish-targets.mjs +1 -1
  115. package/tools/publish-voices.mjs +3 -3
  116. package/tools/recording-impact.mjs +7 -3
  117. package/tools/render-theme.mjs +33 -0
  118. package/tools/review-anchor.mjs +28 -12
  119. package/tools/semver.mjs +40 -0
  120. package/tools/sentences.mjs +180 -0
  121. package/tools/shot.mjs +14 -7
  122. package/tools/site-clip.mjs +114 -0
  123. package/tools/site-voices.mjs +232 -0
  124. package/tools/template-theme.mjs +1 -1
  125. package/tools/test-impact.mjs +17 -10
  126. package/tools/theme-check.mjs +30 -3
  127. package/tools/tts-cache.mjs +4 -3
  128. package/tools/tts-engines.mjs +38 -20
  129. package/tools/tts-setup.mjs +7 -7
  130. package/tools/video-options.mjs +34 -0
  131. package/tools/video.mjs +530 -54
  132. package/tools/voiceover-server.mjs +185 -104
  133. package/tools/voiceover.mjs +119 -261
  134. package/tools/zip.mjs +1 -1
  135. package/cli/dev.mjs +0 -623
  136. package/cli/present.mjs +0 -853
  137. package/cli/review.mjs +0 -361
  138. package/tools/publish-site-voices.mjs +0 -75
@@ -0,0 +1,207 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * A design system's declared migrations (SPEC DESIGN_SYSTEM_MIGRATIONS): what
6
+ * a major version renamed, so decklight knows a deck is behind without
7
+ * guessing, says it once, and can apply the renames itself.
8
+ *
9
+ * "migrations": {
10
+ * "6.0.0": {
11
+ * "skill": "acme-migrate",
12
+ * "roles": { "text-diagram-blue": "text-diagram-default" },
13
+ * "tokens": { "--acme-font-size-body-lg": "--acme-font-size-body-xl" },
14
+ * "classes": { "acme-tile--zest": "acme-tile--secondary-3" },
15
+ * "themes": { "acme-devrel": "acme-dark" }
16
+ * }
17
+ * }
18
+ *
19
+ * A key is the version that made the change. Every rename is a WHOLE name:
20
+ * a role id (the slide writes its token, `--<prefix>color-<role>`), a custom
21
+ * property, a class, a theme. Pure — no file is read here; the gate, `check`,
22
+ * the servers and `design-system migrate` hand in the text.
23
+ */
24
+
25
+ import { SEMVER_RE, semverCompare } from './semver.mjs';
26
+
27
+ /** The four kinds of name a migration renames, in the order they are said. */
28
+ export const RENAME_KINDS = ['roles', 'tokens', 'classes', 'themes'];
29
+ const ONE = { roles: 'role', tokens: 'token', classes: 'class', themes: 'theme' };
30
+
31
+ const ID_RE = /^[a-z][a-z0-9-]*$/;
32
+ const SHAPES = {
33
+ roles: [ID_RE, 'a role id (a lowercase word, e.g. "text-heading-main")'],
34
+ tokens: [/^--[A-Za-z0-9_-]+$/, 'a custom property, "--…"'],
35
+ classes: [/^-?[A-Za-z_][A-Za-z0-9_-]*$/, 'a class name, without the dot'],
36
+ themes: [ID_RE, 'a theme name'],
37
+ };
38
+
39
+ const isObj = (v) => v && typeof v === 'object' && !Array.isArray(v);
40
+ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
41
+ /** A name as a whole word of CSS or HTML: not inside a longer identifier. */
42
+ const whole = (name) => new RegExp(`(?<![\\w-])${escapeRe(name)}(?![\\w-])`, 'g');
43
+
44
+ /** The major of a semver version, or null. */
45
+ export const majorOf = (v) => (SEMVER_RE.test(String(v ?? '')) ? Number(String(v).split('.')[0]) : null);
46
+
47
+ /**
48
+ * What is wrong with a manifest's `migrations`, as `[{ msg }]` — its shape
49
+ * only: every key a semver version no later than the package's own, every
50
+ * value `{ skill?, roles?, tokens?, classes?, themes? }` of whole names.
51
+ */
52
+ export function migrationShapeProblems(m) {
53
+ const out = [];
54
+ if (m.migrations === undefined) return out;
55
+ if (!isObj(m.migrations)) return [{ msg: 'migrations must be { "<version>": { "roles": { "<old>": "<new>" }, … } }, one entry per version that renamed something' }];
56
+ for (const [version, mig] of Object.entries(m.migrations)) {
57
+ if (!SEMVER_RE.test(version)) { out.push({ msg: `migrations: "${version}" is not a semver version — key each migration by the version that made it` }); continue; }
58
+ if (SEMVER_RE.test(String(m.version ?? '')) && semverCompare(version, m.version) > 0) {
59
+ out.push({ msg: `migrations: ${version} is later than this package's version ${m.version}` });
60
+ }
61
+ if (!isObj(mig)) { out.push({ msg: `migrations: ${version} must be { "skill"?, "roles"?, "tokens"?, "classes"?, "themes"? }` }); continue; }
62
+ for (const key of Object.keys(mig)) {
63
+ if (key !== 'skill' && !RENAME_KINDS.includes(key)) out.push({ msg: `migrations: ${version} has "${key}" — a migration renames roles, tokens, classes and themes, and may name a skill` });
64
+ }
65
+ if (mig.skill !== undefined && (typeof mig.skill !== 'string' || !ID_RE.test(mig.skill))) {
66
+ out.push({ msg: `migrations: ${version}.skill ${JSON.stringify(mig.skill)} — the name of a marketplace skill (decklight library add skill <name>)` });
67
+ }
68
+ for (const kind of RENAME_KINDS) {
69
+ if (mig[kind] === undefined) continue;
70
+ if (!isObj(mig[kind])) { out.push({ msg: `migrations: ${version}.${kind} must be { "<old>": "<new>" }` }); continue; }
71
+ const [re, what] = SHAPES[kind];
72
+ for (const [from, to] of Object.entries(mig[kind])) {
73
+ if (!re.test(from) || typeof to !== 'string' || !re.test(to)) out.push({ msg: `migrations: ${version}.${kind} "${from}" → ${JSON.stringify(to)} — each side is ${what}` });
74
+ else if (from === to) out.push({ msg: `migrations: ${version}.${kind} renames "${from}" to itself` });
75
+ }
76
+ }
77
+ }
78
+ return out;
79
+ }
80
+
81
+ /** The migrations in version order, each `{ version, skill, roles, tokens, classes, themes }` — only well-formed ones. */
82
+ export function migrationsOf(manifest) {
83
+ const all = isObj(manifest?.migrations) ? manifest.migrations : {};
84
+ return Object.entries(all)
85
+ .filter(([v, mig]) => SEMVER_RE.test(v) && isObj(mig))
86
+ .map(([version, mig]) => ({
87
+ version,
88
+ skill: typeof mig.skill === 'string' ? mig.skill : null,
89
+ ...Object.fromEntries(RENAME_KINDS.map((k) => [k, isObj(mig[k]) ? Object.fromEntries(Object.entries(mig[k]).filter(([, to]) => typeof to === 'string')) : {}])),
90
+ }))
91
+ .sort((a, b) => semverCompare(a.version, b.version));
92
+ }
93
+
94
+ /**
95
+ * The migrations a deck written for `from` has still to take, up to the
96
+ * package's own version: every one after `from`, or every one when the deck
97
+ * records no version.
98
+ */
99
+ export function pendingMigrations(manifest, from = null) {
100
+ return migrationsOf(manifest).filter((m) => (!from || !SEMVER_RE.test(from) || semverCompare(m.version, from) > 0)
101
+ && (!SEMVER_RE.test(String(manifest?.version ?? '')) || semverCompare(m.version, manifest.version) <= 0));
102
+ }
103
+
104
+ /**
105
+ * The renames of several migrations as one map per kind, chains followed: a
106
+ * name renamed in 5.0.0 and its successor again in 6.0.0 goes straight to the
107
+ * last one, so a deck two majors behind is moved in one pass. Each value is
108
+ * `{ to, version }` — the version of the LAST rename on the way.
109
+ */
110
+ export function composeRenames(migrations) {
111
+ const out = Object.fromEntries(RENAME_KINDS.map((k) => [k, {}]));
112
+ for (const m of migrations) {
113
+ for (const kind of RENAME_KINDS) {
114
+ const map = out[kind];
115
+ for (const [from, to] of Object.entries(m[kind])) {
116
+ for (const r of Object.values(map)) if (r.to === from) { r.to = to; r.version = m.version; }
117
+ if (!map[from]) map[from] = { to, version: m.version };
118
+ }
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+
124
+ /** A role id's token, as a slide writes it — the shape `roleToken` gives (SPEC DESIGN_SYSTEM_ROLES). */
125
+ const roleTokenOf = (prefix, id) => `${prefix}color-${id}`;
126
+
127
+ /**
128
+ * Every renamed name the texts still use: `[{ kind, from, to, version, as }]`,
129
+ * `as` the spelling found (a role is found as its token). Classes are looked
130
+ * for in `class` attributes and in CSS selectors, themes as the configured
131
+ * `"theme"`; roles and tokens anywhere, as whole names.
132
+ */
133
+ export function findRenamed(texts, renames, prefix) {
134
+ const found = [];
135
+ const body = [].concat(texts).join('\n');
136
+ const classAttrs = [...body.matchAll(/\bclass\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)].map((m) => ` ${m[1] ?? m[2]} `).join(' ');
137
+ for (const [from, r] of Object.entries(renames.roles ?? {})) {
138
+ const as = roleTokenOf(prefix, from);
139
+ if (whole(as).test(body)) found.push({ kind: 'roles', from, to: r.to, version: r.version, as });
140
+ }
141
+ for (const [from, r] of Object.entries(renames.tokens ?? {})) {
142
+ if (whole(from).test(body)) found.push({ kind: 'tokens', from, to: r.to, version: r.version, as: from });
143
+ }
144
+ for (const [from, r] of Object.entries(renames.classes ?? {})) {
145
+ if (whole(from).test(classAttrs) || new RegExp(`\\.${escapeRe(from)}(?![\\w-])`).test(body)) found.push({ kind: 'classes', from, to: r.to, version: r.version, as: from });
146
+ }
147
+ for (const [from, r] of Object.entries(renames.themes ?? {})) {
148
+ if (new RegExp(`"theme"\\s*:\\s*"${escapeRe(from)}"`).test(body)) found.push({ kind: 'themes', from, to: r.to, version: r.version, as: from });
149
+ }
150
+ return found;
151
+ }
152
+
153
+ /**
154
+ * The renames applied to one text: roles (as tokens) and tokens wherever they
155
+ * stand as whole names, classes in `class` attributes and in selectors, and
156
+ * — when `config` is true, for the deck — the configured `"theme"`. Nothing
157
+ * else changes, byte for byte. Returns `{ text, count }`.
158
+ */
159
+ export function applyRenames(text, renames, prefix, { config = false } = {}) {
160
+ let count = 0;
161
+ let out = String(text);
162
+ const swap = (re, to) => { out = out.replace(re, () => { count++; return to; }); };
163
+ for (const [from, r] of Object.entries(renames.roles ?? {})) swap(whole(roleTokenOf(prefix, from)), roleTokenOf(prefix, r.to));
164
+ for (const [from, r] of Object.entries(renames.tokens ?? {})) swap(whole(from), r.to);
165
+ const classes = Object.entries(renames.classes ?? {});
166
+ if (classes.length) {
167
+ out = out.replace(/(\bclass\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi, (all, lead, dq, sq) => {
168
+ const q = dq !== undefined ? '"' : "'";
169
+ let v = dq ?? sq;
170
+ for (const [from, r] of classes) v = v.replace(whole(from), () => { count++; return r.to; });
171
+ return `${lead}${q}${v}${q}`;
172
+ });
173
+ for (const [from, r] of classes) swap(new RegExp(`\\.${escapeRe(from)}(?![\\w-])`, 'g'), `.${r.to}`);
174
+ }
175
+ if (config) {
176
+ for (const [from, r] of Object.entries(renames.themes ?? {})) {
177
+ out = out.replace(new RegExp(`("theme"\\s*:\\s*")${escapeRe(from)}"`, 'g'), (all, lead) => { count++; return `${lead}${r.to}"`; });
178
+ }
179
+ }
180
+ return { text: out, count };
181
+ }
182
+
183
+ /**
184
+ * The gate's half (DESIGN_SYSTEM_MIGRATIONS): a migration's names, against
185
+ * the package as it now is. Every old name must be gone — a rename that
186
+ * leaves it is not one — and every new name present, unless a later
187
+ * migration renamed it again. `has` is `{ roles, tokens, classes, themes }`,
188
+ * each a Set of what the package defines. Returns `[{ msg }]`.
189
+ */
190
+ export function migrationNameProblems(manifest, has) {
191
+ const out = [];
192
+ const migrations = migrationsOf(manifest);
193
+ migrations.forEach((m, i) => {
194
+ const later = migrations.slice(i + 1);
195
+ for (const kind of RENAME_KINDS) {
196
+ const set = has[kind];
197
+ if (!set) continue;
198
+ for (const [from, to] of Object.entries(m[kind])) {
199
+ if (set.has(from)) out.push({ msg: `migrations: ${m.version} renames ${ONE[kind]} "${from}", which this version still defines — a renamed name is gone from the new version` });
200
+ if (!set.has(to) && !later.some((n) => Object.hasOwn(n[kind], to))) {
201
+ out.push({ msg: `migrations: ${m.version} renames ${ONE[kind]} "${from}" to "${to}", which this version does not define` });
202
+ }
203
+ }
204
+ }
205
+ });
206
+ return out;
207
+ }
@@ -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
@@ -69,11 +69,19 @@ export function run(bin, args, { timeout = NETWORK_MS, why = '', ...opts } = {})
69
69
  *
70
70
  * Use this — never `run` — whenever the process that spawns the child is also
71
71
  * serving it (tools/shot.mjs, tools/video.mjs, cli/pptx-export.mjs).
72
+ *
73
+ * A `signal` stops the child (SIGKILL, like the timeout) and rejects with the
74
+ * AbortError itself, so a caller can tell "stopped" from "hung".
72
75
  */
73
- export function runAsync(bin, args, { timeout = NETWORK_MS, why = '', ...opts } = {}) {
76
+ export function runAsync(bin, args, { timeout = NETWORK_MS, why = '', signal = null, ...opts } = {}) {
74
77
  return new Promise((resolve, reject) => {
75
- execFile(bin, args, { ...opts, timeout, killSignal: 'SIGKILL' }, (e, stdout, stderr) => {
78
+ // execFile throws on `signal: null`, which is what a caller with nothing
79
+ // that could stop it (the command line) passes along
80
+ execFile(bin, args, { ...opts, ...(signal ? { signal } : {}), timeout, killSignal: 'SIGKILL' }, (e, stdout, stderr) => {
76
81
  if (!e) return resolve(stdout);
82
+ // `signal` aborted: somebody STOPPED it (the edit server's stop routes),
83
+ // which is not a hang and must not read as one
84
+ if (e.name === 'AbortError') return reject(e);
77
85
  if (e.killed || e.code === 'ETIMEDOUT' || (e.signal === 'SIGKILL' && e.status == null)) {
78
86
  const err = new Error(`${bin} hung for ${Math.round(timeout / 1000)}s and was killed`
79
87
  + (why ? ` — ${why}` : ''));
@@ -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;