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
@@ -0,0 +1,483 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * `decklight enhance` — the voiceover script, given the audio tags ElevenLabs
6
+ * v4 performs (SPEC `PRESENTING`).
7
+ *
8
+ * The prompt is ElevenLabs' own: the one their best-practices page publishes
9
+ * for having an LLM add audio tags to a script, word for word, with a short
10
+ * decklight addendum saying what else is in these notes — `[click]` beats and
11
+ * `[pause]` holds, which are decklight's, not the model's. The locally
12
+ * installed agent answers it, read-only (`agentAsk`, the argv the commit
13
+ * subjects use): it is asked for text, and it is never let near the file.
14
+ *
15
+ * DECKLIGHT WRITES, NOT THE AGENT. What comes back is checked before a byte
16
+ * of the deck changes: the same words in the same order (tags, capitals and
17
+ * `!`/`?`/`…` are the only things the prompt allows it to add), the same
18
+ * number of `[click]` beats, and no `[pause]` lost. A slide whose answer fails
19
+ * that is left exactly as it was, and says why — an enhancer that could
20
+ * quietly rewrite a talk would be worse than none.
21
+ *
22
+ * One slide per ask, a few at a time: each answer is small enough to check,
23
+ * and one slide's bad answer costs that slide, not the deck.
24
+ *
25
+ * `--spoken` is the other rewrite (KINDS): the notes WRITTEN FOR THE EAR —
26
+ * terse notes turned into sentences a person would say. It rewords, so its
27
+ * check is the deck's structure instead of the words (`spokenProblem`).
28
+ */
29
+
30
+ import { execFile } from 'node:child_process';
31
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
32
+ import { dirname, resolve } from 'node:path';
33
+ import { agentAsk, agentUnavailable, detectAgents } from './agents.mjs';
34
+ import { argReader, firstPositional, isMain } from '../tools/args.mjs';
35
+ import { runMain } from './util.mjs';
36
+ import { NOTES_ASIDE, cleanNotes, readNotes, sectionBodies, isHiddenSection } from '../tools/deck-html.mjs';
37
+ import { canonMarks, captioned, writtenMarks, CLICK_MARK, PAUSE_MARK } from '../tools/sentences.mjs';
38
+ import { notesTextToAside, setSlideNotes } from './edit.mjs';
39
+
40
+ /** Where the prompt below comes from — said in the prompt's own header and in SPEC. */
41
+ export const ENHANCE_SOURCE = 'https://elevenlabs.io/docs/overview/capabilities/text-to-speech/best-practices#prompting-eleven-v4';
42
+
43
+ /**
44
+ * ElevenLabs' prompt for enhancing a script with audio tags, verbatim
45
+ * (ENHANCE_SOURCE). Kept word for word on purpose: it is the prompt their own
46
+ * model is tuned to be prompted with, and a paraphrase would be decklight's
47
+ * guess at it.
48
+ */
49
+ export const ELEVENLABS_ENHANCE_PROMPT = `# Instructions
50
+
51
+ ## 1. Role and Goal
52
+
53
+ You are an AI assistant specializing in enhancing dialogue text for speech generation.
54
+
55
+ Your **PRIMARY GOAL** is to dynamically integrate **audio tags** (e.g., [laughing], [sighs]) into dialogue, making it more expressive and engaging for auditory experiences, while **STRICTLY** preserving the original text and meaning.
56
+
57
+ It is imperative that you follow these system instructions to the fullest.
58
+
59
+ ## 2. Core Directives
60
+
61
+ Follow these directives meticulously to ensure high-quality output.
62
+
63
+ ### Positive Imperatives (DO):
64
+
65
+ * DO integrate **audio tags** from the "Audio Tags" list (or similar contextually appropriate **audio tags**) to add expression, emotion, and realism to the dialogue. These tags MUST describe something auditory.
66
+ * DO ensure that all **audio tags** are contextually appropriate and genuinely enhance the emotion or subtext of the dialogue line they are associated with.
67
+ * DO strive for a diverse range of emotional expressions (e.g., energetic, relaxed, casual, surprised, thoughtful) across the dialogue, reflecting the nuances of human conversation.
68
+ * DO place **audio tags** strategically to maximize impact, typically immediately before the dialogue segment they modify or immediately after. (e.g., [annoyed] This is hard. or This is hard. [sighs]).
69
+ * DO ensure **audio tags** contribute to the enjoyment and engagement of spoken dialogue.
70
+
71
+ ### Negative Imperatives (DO NOT):
72
+
73
+ * DO NOT alter, add, or remove any words from the original dialogue text itself. Your role is to *prepend* **audio tags**, not to *edit* the speech. **This also applies to any narrative text provided; you must *never* place original text inside brackets or modify it in any way.**
74
+ * DO NOT create **audio tags** from existing narrative descriptions. **Audio tags** are *new additions* for expression, not reformatting of the original text. (e.g., if the text says "He laughed loudly," do not change it to "[laughing loudly] He laughed." Instead, add a tag if appropriate, e.g., "He laughed loudly [chuckles].")
75
+ * DO NOT use tags such as [standing], [grinning], [pacing], [music].
76
+ * DO NOT use tags for anything other than the voice such as music or sound effects.
77
+ * DO NOT invent new dialogue lines.
78
+ * DO NOT select **audio tags** that contradict or alter the original meaning or intent of the dialogue.
79
+ * DO NOT introduce or imply any sensitive topics, including but not limited to: politics, religion, child exploitation, profanity, hate speech, or other NSFW content.
80
+
81
+ ## 3. Workflow
82
+
83
+ 1. **Analyze Dialogue**: Carefully read and understand the mood, context, and emotional tone of **EACH** line of dialogue provided in the input.
84
+ 2. **Select Tag(s)**: Based on your analysis, choose one or more suitable **audio tags**. Ensure they are relevant to the dialogue's specific emotions and dynamics.
85
+ 3. **Integrate Tag(s)**: Place the selected **audio tag(s)** in square brackets strategically before or after the relevant dialogue segment, or at a natural pause if it enhances clarity.
86
+ 4. **Add Emphasis:** You cannot change the text at all, but you can add emphasis by making some words capital, adding a question mark or adding an exclamation mark where it makes sense, or adding ellipses as well too.
87
+ 5. **Verify Appropriateness**: Review the enhanced dialogue to confirm:
88
+ * The **audio tag** fits naturally.
89
+ * It enhances meaning without altering it.
90
+ * It adheres to all Core Directives.
91
+
92
+ ## 4. Output Format
93
+
94
+ * Present ONLY the enhanced dialogue text in a conversational format.
95
+ * **Audio tags** **MUST** be enclosed in square brackets (e.g., [laughing]).
96
+ * The output should maintain the narrative flow of the original dialogue.
97
+
98
+ ## 5. Audio Tags (Non-Exhaustive)
99
+
100
+ Use these as a guide. You can infer similar, contextually appropriate **audio tags**.
101
+
102
+ **Directions:**
103
+ * [happy]
104
+ * [sad]
105
+ * [excited]
106
+ * [angry]
107
+ * [whisper]
108
+ * [annoyed]
109
+ * [appalled]
110
+ * [thoughtful]
111
+ * [surprised]
112
+ * *(and similar emotional/delivery directions)*
113
+
114
+ **Non-verbal:**
115
+ * [laughing]
116
+ * [chuckles]
117
+ * [sighs]
118
+ * [clears throat]
119
+ * [short pause]
120
+ * [long pause]
121
+ * [exhales sharply]
122
+ * [inhales deeply]
123
+ * *(and similar non-verbal sounds)*
124
+
125
+ ## 6. Examples of Enhancement
126
+
127
+ **Input**:
128
+ "Are you serious? I can't believe you did that!"
129
+
130
+ **Enhanced Output**:
131
+ "[appalled] Are you serious? [sighs] I can't believe you did that!"
132
+
133
+ ---
134
+
135
+ **Input**:
136
+ "That's amazing, I didn't know you could sing!"
137
+
138
+ **Enhanced Output**:
139
+ "[laughing] That's amazing, [singing] I didn't know you could sing!"
140
+
141
+ ---
142
+
143
+ **Input**:
144
+ "I guess you're right. It's just... difficult."
145
+
146
+ **Enhanced Output**:
147
+ "I guess you're right. [sighs] It's just... [muttering] difficult."
148
+
149
+ # Instructions Summary
150
+
151
+ 1. Add audio tags from the audio tags list. These must describe something auditory but only for the voice.
152
+ 2. Enhance emphasis without altering meaning or text.
153
+ 3. Reply ONLY with the enhanced text.`;
154
+
155
+ /**
156
+ * What these notes are, beyond what ElevenLabs' prompt assumes: one narrator
157
+ * reading a slide's speaker notes, with decklight's own markers in them.
158
+ */
159
+ export const DECKLIGHT_ADDENDUM = `# About this text
160
+
161
+ This is the speaker-notes script of one presentation slide, read aloud by a single narrator — a monologue, not a dialogue between people. It contains markers that belong to the presentation software, not to you:
162
+
163
+ * [click] — on a line of its own: a build step of the slide begins here. Keep every [click] exactly where it is, on its own line, and never add one.
164
+ * [pause] and [long pause] — a hold. Keep every one where it is. You may add [short pause] or [long pause] where a hold helps.
165
+
166
+ Keep the line breaks as they are. Reply with the enhanced script ONLY — no quotes around it, no code fences, no commentary before or after.`;
167
+
168
+ /** The whole ask for one slide's script. */
169
+ export const enhancePrompt = (script) =>
170
+ `${ELEVENLABS_ENHANCE_PROMPT}\n\n${DECKLIGHT_ADDENDUM}\n\n# Script\n\n${script}`;
171
+
172
+ /**
173
+ * A slide's notes as the script the agent is shown — plain text, every marker
174
+ * in its written form, paragraphs a blank line apart and one `[click]` line
175
+ * between beats (the notes editor's own shape). Null for a slide with nothing
176
+ * to say.
177
+ */
178
+ // a paragraph's edges in notes markup — kept as blank lines, as the notes editor keeps them
179
+ const BLOCK_EDGE = /<\/?(?:p|div|li|ul|ol|blockquote|pre|h[1-6]|table|tr)\b[^>]*>|<br\s*\/?>/gi;
180
+
181
+ export function slideScript(asideInner) {
182
+ const beats = readNotes(asideInner ?? '').split(CLICK_MARK).map((b) => b.split(BLOCK_EDGE)
183
+ .map((para) => cleanNotes(para, { marks: true })).filter(Boolean).join('\n\n'));
184
+ const script = writtenMarks(beats.join('\n\n⟨CLICK⟩\n\n')).trim();
185
+ return captioned(canonMarks(script).replaceAll(CLICK_MARK, ' ')) ? script : null;
186
+ }
187
+
188
+ /** What an answer looks like once the agent's packaging is off it: fences, surrounding quotes. */
189
+ export function unwrapAnswer(out) {
190
+ let t = String(out ?? '').trim();
191
+ const fenced = /^```[a-z]*\n([\s\S]*?)\n```$/i.exec(t);
192
+ if (fenced) t = fenced[1].trim();
193
+ if (/^"[\s\S]*"$/.test(t) && !t.slice(1, -1).includes('"')) t = t.slice(1, -1).trim();
194
+ return t;
195
+ }
196
+
197
+ // The words of a beat, as the check compares them: no tags, no markers, no
198
+ // case, no punctuation — the only things the prompt lets the agent change.
199
+ const wordsOf = (beat) => captioned(beat).toLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
200
+ const beatsOf = (text) => canonMarks(text).split(CLICK_MARK);
201
+ const pausesOf = (beat) => beat.split(PAUSE_MARK).length - 1;
202
+
203
+ /**
204
+ * Is `after` the script `before`, only enhanced? Null when it is; otherwise
205
+ * the reason it is not, in words for the person whose notes these are.
206
+ */
207
+ export function enhanceProblem(before, after) {
208
+ if (!after?.trim()) return 'the agent answered nothing';
209
+ const was = beatsOf(before);
210
+ const now = beatsOf(after);
211
+ if (now.length !== was.length) {
212
+ return `the agent changed the [click] beats (${was.length} → ${now.length}) — the builds would drift`;
213
+ }
214
+ for (let k = 0; k < was.length; k++) {
215
+ if (wordsOf(now[k]) !== wordsOf(was[k])) {
216
+ return `the agent changed the words${was.length > 1 ? ` of beat ${k + 1}` : ''} — the prompt allows only tags and emphasis`;
217
+ }
218
+ if (pausesOf(now[k]) < pausesOf(was[k])) return 'the agent dropped a [pause]';
219
+ }
220
+ return null;
221
+ }
222
+
223
+ // ── written for the ear ─────────────────────────────────────────────────────
224
+ // The other rewrite the notes get: terse, written-style notes ("Fluffed a
225
+ // line? Backspace retakes it.") turned into sentences a person would say
226
+ // ("And if you fluff a line, just press Backspace to take it again."). Unlike
227
+ // the tags, this one REWORDS — so its check cannot be "same words". What it
228
+ // guards is what the deck depends on: the [click] beats (the builds), every
229
+ // [pause], no beat emptied, and a length in proportion — an answer twice as
230
+ // long is commentary, not a rewrite.
231
+
232
+ export const SPOKEN_PROMPT = `# Instructions
233
+
234
+ You are rewriting the speaker-notes script of one presentation slide so that it reads as something a person would actually SAY out loud to an audience — writing for the ear, not for the page. A narrator will read your text aloud, word for word.
235
+
236
+ Turn terse, written-style notes — fragments, headline phrasing, bullet-like lists, abbreviations, symbols — into natural spoken sentences:
237
+
238
+ * Full sentences, in the conversational register the presenter would use live, addressing the audience directly where the original does. Connect ideas with the small words speech uses ("so", "and", "which means", "if you …, just …").
239
+ * Keep every fact, instruction, number, name and technical term. Do not add new claims, examples, jokes or opinions, and do not drop any point.
240
+ * Say what a voice cannot read: symbols, arrows, abbreviations and key glyphs become words ("⌘" → "Command", "e.g." → "for example", "→" → "then"), unless the audience needs the exact code identifier.
241
+ * Keep it about as long as it was — a little longer where connecting words are needed, never twice as long.
242
+ * Keep the language of the original.
243
+ * Keep any audio tag in square brackets (such as [thoughtful]) attached to the sentence it belongs to.
244
+
245
+ ## Example
246
+
247
+ Original: Fluffed a line? Backspace retakes it. Escape stops, and every slide you already finished is saved.
248
+
249
+ Rewritten: And if you fluff a line, just press Backspace to take it again. When you press Escape, the recording stops, and every slide you've already finished is saved.`;
250
+
251
+ /** The whole ask for one slide's script, written for the ear. */
252
+ export const spokenPrompt = (script) =>
253
+ `${SPOKEN_PROMPT}\n\n${DECKLIGHT_ADDENDUM.replace('the enhanced script', 'the rewritten script')}\n\n# Script\n\n${script}`;
254
+
255
+ const wordCount = (text) => wordsOf(text).split(' ').filter(Boolean).length;
256
+
257
+ /**
258
+ * Is `after` the script `before`, rewritten for the ear, without breaking what
259
+ * the deck depends on? Null when it is; otherwise the reason, in words.
260
+ */
261
+ export function spokenProblem(before, after) {
262
+ if (!after?.trim()) return 'the agent answered nothing';
263
+ const was = beatsOf(before);
264
+ const now = beatsOf(after);
265
+ if (now.length !== was.length) {
266
+ return `the agent changed the [click] beats (${was.length} → ${now.length}) — the builds would drift`;
267
+ }
268
+ for (let k = 0; k < was.length; k++) {
269
+ if (wordCount(was[k]) && !wordCount(now[k])) return `the agent emptied${was.length > 1 ? ` beat ${k + 1}` : ' the script'}`;
270
+ if (pausesOf(now[k]) < pausesOf(was[k])) return 'the agent dropped a [pause]';
271
+ }
272
+ const ratio = wordCount(after) / Math.max(1, wordCount(before));
273
+ if (ratio > 2.5) return 'the agent\'s answer is far longer than the notes — commentary, not a rewrite';
274
+ if (ratio < 0.5) return 'the agent\'s answer is far shorter than the notes — points were dropped';
275
+ return null;
276
+ }
277
+
278
+ /**
279
+ * The two rewrites the notes get, by name: `tags` (ElevenLabs v4 audio tags,
280
+ * same words) and `spoken` (written for the ear, reworded). Each is a prompt
281
+ * and the check its answer must pass before a byte of the deck changes.
282
+ */
283
+ export const KINDS = {
284
+ tags: { prompt: enhancePrompt, problem: enhanceProblem, done: 'enhanced' },
285
+ spoken: { prompt: spokenPrompt, problem: spokenProblem, done: 'rewritten for the ear' },
286
+ };
287
+ const kindOf = (kind) => KINDS[kind] ?? KINDS.tags;
288
+
289
+ /** Run a read-only agent ask; resolves to its stdout, or null. */
290
+ export function ask(cmd, cwd, timeoutMs) {
291
+ return new Promise((done) => {
292
+ let settled = false;
293
+ const finish = (v) => { if (!settled) { settled = true; done(v); } };
294
+ let child;
295
+ try {
296
+ child = execFile(cmd.bin, cmd.args, { cwd, timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] },
297
+ (err, stdout) => finish(err && !stdout ? null : String(stdout ?? '')));
298
+ } catch { return finish(null); }
299
+ child.on('error', () => finish(null));
300
+ });
301
+ }
302
+
303
+ /** How long one slide's ask may take. */
304
+ export const ENHANCE_TIMEOUT_MS = 120_000;
305
+ /** How many slides are asked about at once. */
306
+ export const ENHANCE_CONCURRENCY = 3;
307
+
308
+ /**
309
+ * The slides of `html` that can be enhanced, as `{ slide, inner, script }`:
310
+ * a visible slide with an `<aside class="notes">` that says something.
311
+ * `only` (1-based slide numbers) narrows it.
312
+ */
313
+ export function enhanceable(html, only = null) {
314
+ const want = only ? new Set(only) : null;
315
+ return sectionBodies(html).flatMap((body, i) => {
316
+ const slide = i + 1;
317
+ if (want && !want.has(slide)) return [];
318
+ if (isHiddenSection(body)) return [];
319
+ const aside = NOTES_ASIDE.exec(body);
320
+ const script = aside ? slideScript(aside[1]) : null;
321
+ return script ? [{ slide, script }] : [];
322
+ });
323
+ }
324
+
325
+ /**
326
+ * One script, enhanced: the agent is asked, its answer unwrapped and checked.
327
+ * Resolves to `{ ok, text }` or `{ ok: false, why }` — the unit every caller
328
+ * shares, from the notes editor's one box to a whole deck.
329
+ */
330
+ export async function enhanceText(script, {
331
+ kind = 'tags', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
332
+ resolveAgent = agentAsk, exec = ask,
333
+ } = {}) {
334
+ const k = kindOf(kind);
335
+ const cmd = resolveAgent(agent, k.prompt(script), { env });
336
+ if (!cmd) return { ok: false, why: agentUnavailable(agent, detectAgents({ env })) };
337
+ const out = await exec(cmd, cwd, timeoutMs);
338
+ if (out == null) return { ok: false, why: 'the agent did not answer in time' };
339
+ const text = unwrapAnswer(out);
340
+ const why = k.problem(script, text);
341
+ return why ? { ok: false, why } : { ok: true, text, changed: text !== script.trim() };
342
+ }
343
+
344
+ /**
345
+ * The answers written into `html`: each slide that passed the check and says
346
+ * something new — and only if its notes still read exactly as they did when
347
+ * the agent was asked. A slide edited in the meantime keeps the edit; the
348
+ * answer was to a script that no longer exists. Returns `{ html, stale }`.
349
+ */
350
+ export function applyEnhanced(html, answers) {
351
+ let out = html;
352
+ const stale = [];
353
+ const bodies = sectionBodies(html);
354
+ for (const a of answers) {
355
+ if (!a.ok || !a.changed) continue;
356
+ const aside = NOTES_ASIDE.exec(bodies[a.slide - 1] ?? '');
357
+ if (!aside || slideScript(aside[1]) !== a.before) { stale.push(a.slide); continue; }
358
+ out = setSlideNotes(out, a.slide, notesTextToAside(a.text));
359
+ }
360
+ return { html: out, stale };
361
+ }
362
+
363
+ /**
364
+ * Ask the agent to enhance `slides` (1-based numbers, or null for every slide
365
+ * with notes) of the deck in `html`. Resolves to `{ html, results, answers }`:
366
+ * the deck with every passing slide rewritten (`applyEnhanced`), one
367
+ * `{ slide, ok, changed, why }` per slide asked about, and the raw answers for
368
+ * a caller that applies them to a newer copy of the deck. Never throws for one
369
+ * slide's failure — only when there is no agent to ask at all.
370
+ */
371
+ export async function enhanceDeck(html, slides = null, {
372
+ kind = 'tags', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
373
+ concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onSlide = () => {},
374
+ } = {}) {
375
+ if (!resolveAgent(agent, 'x', { env })) throw new Error(agentUnavailable(agent, detectAgents({ env })));
376
+ const todo = enhanceable(html, slides);
377
+ const answers = [];
378
+ let next = 0, finished = 0;
379
+ const worker = async () => {
380
+ while (next < todo.length) {
381
+ const { slide, script } = todo[next++];
382
+ const a = await enhanceText(script, { kind, agent, cwd, env, timeoutMs, resolveAgent, exec });
383
+ const r = { slide, ok: a.ok, changed: a.ok && a.text !== script, ...(a.ok ? {} : { why: a.why }) };
384
+ answers.push({ ...r, before: script, text: a.text ?? null });
385
+ onSlide({ ...r, done: ++finished, of: todo.length });
386
+ }
387
+ };
388
+ await Promise.all(Array.from({ length: Math.min(concurrency, todo.length) }, worker));
389
+ answers.sort((a, b) => a.slide - b.slide);
390
+ const results = answers.map(({ before, text, ...r }) => r);
391
+ return { html: applyEnhanced(html, answers).html, results, answers };
392
+ }
393
+
394
+ /** '3', '2-5', '1,4,6-7' → slide numbers; throws on anything else or out of range. */
395
+ export function parseSlides(s, total) {
396
+ const nums = new Set();
397
+ for (const part of String(s).split(',').map((p) => p.trim()).filter(Boolean)) {
398
+ const m = /^(\d+)(?:\s*[-–]\s*(\d+))?$/.exec(part);
399
+ const from = m ? Number(m[1]) : NaN;
400
+ const to = m?.[2] ? Number(m[2]) : from;
401
+ if (!m || from < 1 || to > total || from > to) {
402
+ throw new Error(`--slides ${s} is not slides of this deck (1–${total}; e.g. 3, 2-5 or 1,4)`);
403
+ }
404
+ for (let n = from; n <= to; n++) nums.add(n);
405
+ }
406
+ if (!nums.size) throw new Error('--slides needs a slide number, a-b, or a list');
407
+ return [...nums].sort((a, b) => a - b);
408
+ }
409
+
410
+ const USAGE = `decklight enhance — add ElevenLabs v4 audio tags to the voiceover script
411
+
412
+ Usage:
413
+ decklight enhance <deck.html> --slides <n | a-b | a,b,c> [--agent <name>] [--dry-run]
414
+ decklight enhance <deck.html> --all [--agent <name>] [--dry-run]
415
+ decklight enhance <deck.html> --spoken --slides … | --all write it for the ear instead
416
+
417
+ Asks the AI agent installed on this machine (claude, codex, …) to add audio
418
+ tags — [thoughtful], [sighs], [excited] — to each slide's speaker notes, with
419
+ the prompt ElevenLabs publishes for exactly that:
420
+ ${ENHANCE_SOURCE}
421
+ The agent is asked for text only (read-only); decklight checks every answer
422
+ keeps the same words, [click] beats and [pause]s before it writes the slide,
423
+ and leaves a slide whose answer does not as it was. Tags are performed by
424
+ ElevenLabs v4/v3 and left out by every other voice.
425
+
426
+ --slides the slides to enhance
427
+ --all every slide with notes
428
+ --agent which agent to ask (default: your remembered one, else the first found)
429
+ --dry-run print each enhanced script; write nothing
430
+ --spoken rewrite terse notes as sentences a person would say out loud
431
+ ("Fluffed a line? Backspace retakes it." → "And if you fluff a
432
+ line, just press Backspace to take it again."). This one DOES
433
+ reword; decklight checks the [click] beats and [pause]s survive
434
+ and the length stays in proportion.
435
+
436
+ Note: the notes are sent to that agent, and most agents are cloud services.`;
437
+
438
+ export async function enhanceMain(args = []) {
439
+ if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
440
+ const { opt } = argReader(args);
441
+ const deck = firstPositional(args, ['--slides', '--agent']);
442
+ if (!deck) { console.error(`decklight enhance: needs a deck\n\n${USAGE}`); return 1; }
443
+ const path = resolve(deck);
444
+ if (!existsSync(path)) { console.error(`decklight enhance: no such deck: ${deck}`); return 1; }
445
+ const all = args.includes('--all');
446
+ const which = opt('--slides');
447
+ if (!all && !which) {
448
+ console.error('decklight enhance: say which slides — --slides 3 (or 2-5, or 1,4) — or --all for every slide with notes');
449
+ return 1;
450
+ }
451
+ const html = readFileSync(path, 'utf8');
452
+ let slides = null;
453
+ try { slides = all ? null : parseSlides(which, sectionBodies(html).length); }
454
+ catch (e) { console.error(`decklight enhance: ${e.message}`); return 1; }
455
+ const dry = args.includes('--dry-run');
456
+ const kind = args.includes('--spoken') ? 'spoken' : 'tags';
457
+ const verb = KINDS[kind].done;
458
+ let res;
459
+ try {
460
+ const n = enhanceable(html, slides).length;
461
+ if (!n) { console.log('decklight enhance: no notes to enhance on those slides'); return 0; }
462
+ console.log(`enhance: ${n} slide${n === 1 ? '' : 's'}${kind === 'spoken' ? ', written for the ear' : ''} — asking the agent (read-only), a few at a time…`);
463
+ res = await enhanceDeck(html, slides, {
464
+ kind, agent: opt('--agent') ?? null, cwd: dirname(path),
465
+ onSlide: (r) => console.log(` slide ${r.slide}: ${r.ok ? (r.changed ? verb : 'already as it would be') : `left as it was — ${r.why}`}`
466
+ + ` (${r.done}/${r.of})`),
467
+ });
468
+ } catch (e) { console.error(`decklight enhance: ${e.message}`); return 1; }
469
+ const done = res.results.filter((r) => r.changed);
470
+ if (dry) {
471
+ for (const r of done) {
472
+ const aside = NOTES_ASIDE.exec(sectionBodies(res.html)[r.slide - 1])?.[1] ?? '';
473
+ console.log(`\n── slide ${r.slide} ──\n${slideScript(aside)}`);
474
+ }
475
+ console.log(`\n${done.length} slide${done.length === 1 ? '' : 's'} would change — nothing written (--dry-run)`);
476
+ } else if (done.length) {
477
+ writeFileSync(path, res.html);
478
+ console.log(`wrote ${deck}: ${done.length} slide${done.length === 1 ? '' : 's'} ${verb}`);
479
+ } else console.log('nothing changed');
480
+ return res.results.some((r) => !r.ok) ? 2 : 0;
481
+ }
482
+
483
+ if (isMain(import.meta.url)) process.exit(await runMain('enhance', () => enhanceMain(process.argv.slice(2))));
package/cli/extension.mjs CHANGED
@@ -3,10 +3,10 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  /**
6
- * `decklight extension` — the marketplace admission gate for build-time code
6
+ * `decklight library gate transform` — the marketplace admission gate for build-time code
7
7
  * (MARKETPLACE.md `EXTENSIONS#CHECK`, SPEC `EXTENSIONS_CHECK`).
8
8
  *
9
- * decklight extension check <file> [--type transform]
9
+ * decklight library gate transform <file> [--type transform]
10
10
  *
11
11
  * Validates a bare source FILE, not an installed, catalog-backed unit —
12
12
  * `bundle`, `import` and `publish` run an already-installed transform and
@@ -15,7 +15,7 @@
15
15
  * `transform` entry; a failing check blocks that PR from merging — the
16
16
  * extension's admission to a catalog, never `decklight publish`ing a deck.
17
17
  *
18
- * Named `extension`, not `transform`: `decklight plugin check` already gates
18
+ * Named `extension`, not `transform`: `decklight library gate plugin` already gates
19
19
  * presenter-library plugins (a different risk — a stranger's code on the
20
20
  * presenter's own machine). This is the gate for build-time code
21
21
  * specifically, and `--type` leaves room for an `importer` check later. The
@@ -28,9 +28,9 @@ import { existsSync } from 'node:fs';
28
28
  import { isMain, argReader } from '../tools/args.mjs';
29
29
  import { checkExtension, TYPES } from '../tools/extension-check.mjs';
30
30
 
31
- const USAGE = `usage: decklight extension check <file> [--type transform]
31
+ const USAGE = `usage: decklight library gate transform <file> [--type transform]
32
32
 
33
- decklight extension check <file>
33
+ decklight library gate transform <file>
34
34
  lints the source — refuses fetch(), eval(), XMLHttpRequest or a dynamic
35
35
  import() anywhere in it — then runs it against a randomised fixture in a
36
36
  SEPARATE Node process under the permission model (no filesystem writes,
@@ -40,7 +40,7 @@ const USAGE = `usage: decklight extension check <file> [--type transform]
40
40
  a refusal, so a marketplace's own CI can gate admission on it.
41
41
  On a pass it prints the file's sha256 — the pin the catalog entry carries,
42
42
  which installs are held to (SPEC UNIT_PINNING)
43
- EXAMPLE: decklight extension check grammar-check.mjs
43
+ EXAMPLE: decklight library gate transform grammar-check.mjs
44
44
 
45
45
  --type transform what kind of extension this is (default, and the only
46
46
  kind implemented — the import-adapter contract is frozen
@@ -80,12 +80,12 @@ export function reportLines(name, result) {
80
80
  async function checkMain(args) {
81
81
  const { opt } = argReader(args);
82
82
  const [file] = args.filter((a, i) => !a.startsWith('-') && args[i - 1] !== '--type');
83
- if (!file) { console.error(`decklight extension check: needs a file\n\n${USAGE}`); return 1; }
84
- if (!existsSync(file)) { console.error(`decklight extension check: no such file: ${file}`); return 1; }
83
+ if (!file) { console.error(`decklight library gate transform: needs a file\n\n${USAGE}`); return 1; }
84
+ if (!existsSync(file)) { console.error(`decklight library gate transform: no such file: ${file}`); return 1; }
85
85
 
86
86
  const type = opt('--type') ?? 'transform';
87
87
  if (!TYPES.includes(type)) {
88
- console.error(`decklight extension check: --type ${type} is not implemented`
88
+ console.error(`decklight library gate transform: --type ${type} is not implemented`
89
89
  + ` — this decklight only checks: ${TYPES.join(', ')}`);
90
90
  return 1;
91
91
  }
@@ -101,7 +101,7 @@ export async function extensionMain(args = []) {
101
101
  const rest = args.slice(1);
102
102
  if (rest.includes('--help') || rest.includes('-h')) { console.log(USAGE); return 0; }
103
103
  if (sub === 'check') return checkMain(rest);
104
- console.error(`decklight extension: unknown subcommand "${sub}"\n\n${USAGE}`);
104
+ console.error(`decklight library gate: unknown verb "${sub}"\n\n${USAGE}`);
105
105
  return 1;
106
106
  }
107
107