decklight 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +61 -3
  3. package/README.md +58 -28
  4. package/SPEC.md +1326 -85
  5. package/cli/agent-review.mjs +5 -4
  6. package/cli/agents.mjs +148 -18
  7. package/cli/bundle-audio.mjs +10 -3
  8. package/cli/bundle-module.mjs +95 -0
  9. package/cli/bundle.mjs +125 -7
  10. package/cli/cast.mjs +86 -19
  11. package/cli/check-fixes.mjs +194 -0
  12. package/cli/check-watch.mjs +151 -0
  13. package/cli/check.mjs +491 -75
  14. package/cli/code-editor.mjs +287 -0
  15. package/cli/commands.mjs +13 -2
  16. package/cli/commit-flow.mjs +7 -3
  17. package/cli/commit-message.mjs +35 -8
  18. package/cli/commit-split.mjs +125 -25
  19. package/cli/deck-refs.mjs +8 -3
  20. package/cli/decklight.mjs +11 -1
  21. package/cli/design-system-edit.mjs +37 -1
  22. package/cli/design-system-refs.mjs +263 -6
  23. package/cli/design-system.mjs +82 -14
  24. package/cli/edit-address.mjs +184 -0
  25. package/cli/edit-git.mjs +23 -6
  26. package/cli/edit-handover.mjs +257 -40
  27. package/cli/edit-look.mjs +293 -6
  28. package/cli/edit-open.mjs +143 -0
  29. package/cli/edit-slides.mjs +1043 -67
  30. package/cli/edit-translate.mjs +243 -0
  31. package/cli/edit.mjs +3680 -319
  32. package/cli/editor-support.mjs +286 -0
  33. package/cli/enhance.mjs +157 -27
  34. package/cli/find-replace.mjs +142 -0
  35. package/cli/fix-review.mjs +368 -0
  36. package/cli/git.mjs +13 -0
  37. package/cli/init.mjs +101 -22
  38. package/cli/keep-awake.mjs +68 -0
  39. package/cli/marketplace-autocheck.mjs +200 -0
  40. package/cli/marketplace.mjs +250 -13
  41. package/cli/migrate-writing.mjs +214 -0
  42. package/cli/narrate.mjs +121 -5
  43. package/cli/open.mjs +53 -15
  44. package/cli/outside-edit.mjs +257 -0
  45. package/cli/paste.mjs +92 -0
  46. package/cli/pdf.mjs +88 -10
  47. package/cli/pptx-export.mjs +10 -5
  48. package/cli/publish.mjs +24 -3
  49. package/cli/record.mjs +86 -15
  50. package/cli/remote.mjs +32 -6
  51. package/cli/rewrite.mjs +265 -0
  52. package/cli/runtime-link.mjs +218 -17
  53. package/cli/serve.mjs +9 -6
  54. package/cli/setup.mjs +2 -2
  55. package/cli/skill-content.mjs +251 -10
  56. package/cli/skills/slide-writing.md +333 -0
  57. package/cli/skills/voiceover.md +423 -0
  58. package/cli/skills.mjs +282 -15
  59. package/cli/starter-full.mjs +353 -0
  60. package/cli/supervise.mjs +14 -0
  61. package/cli/theme-refs.mjs +14 -2
  62. package/cli/theme.mjs +3 -2
  63. package/cli/translate-core.mjs +466 -0
  64. package/cli/translate-files.mjs +149 -0
  65. package/cli/translate.mjs +458 -0
  66. package/cli/units.mjs +75 -7
  67. package/cli/util.mjs +25 -0
  68. package/cli/vocabulary-docs.mjs +138 -0
  69. package/dist/decklight.css +2506 -113
  70. package/dist/decklight.js +385 -175
  71. package/dist/decklight.js.map +4 -4
  72. package/docs/GLOSSARY.md +9 -2
  73. package/docs/WRITING_RESEARCH.md +327 -0
  74. package/package.json +5 -3
  75. package/themes/coastal.css +3 -0
  76. package/themes/metropolis.css +2 -0
  77. package/themes/reveal-blood.css +3 -0
  78. package/themes/reveal-league.css +2 -0
  79. package/themes/reveal-moon.css +2 -0
  80. package/themes/reveal-serif.css +1 -0
  81. package/themes/reveal-sky.css +1 -0
  82. package/themes/reveal-solarized.css +4 -0
  83. package/tools/brand-palette.mjs +6 -1
  84. package/tools/build-groups.mjs +28 -8
  85. package/tools/cdp.mjs +176 -0
  86. package/tools/chart-spec.mjs +242 -0
  87. package/tools/click-match.mjs +70 -0
  88. package/tools/code-options.mjs +174 -0
  89. package/tools/conversation.mjs +49 -0
  90. package/tools/deck-family.mjs +101 -0
  91. package/tools/deck-html.mjs +212 -15
  92. package/tools/design-system-format.mjs +40 -1
  93. package/tools/design-system-migrations.mjs +207 -0
  94. package/tools/diagram-shapes.mjs +221 -0
  95. package/tools/elevenlabs-tts.mjs +62 -53
  96. package/tools/exec.mjs +10 -2
  97. package/tools/face-clip.mjs +96 -0
  98. package/tools/face-layout.mjs +94 -0
  99. package/tools/gemini-tts.mjs +1 -1
  100. package/tools/invisible-in-print.mjs +27 -0
  101. package/tools/lipsync-auto.mjs +197 -0
  102. package/tools/lipsync-config.mjs +16 -0
  103. package/tools/lipsync-engines.mjs +22 -4
  104. package/tools/lipsync-server.mjs +8 -5
  105. package/tools/lipsync.mjs +122 -30
  106. package/tools/local-voice.mjs +1 -1
  107. package/tools/mouth-file.mjs +26 -0
  108. package/tools/mouth.mjs +320 -0
  109. package/tools/narration-manifest.mjs +100 -6
  110. package/tools/narration-synth.mjs +96 -76
  111. package/tools/recording-impact.mjs +16 -1
  112. package/tools/sentences.mjs +7 -1
  113. package/tools/site-clip.mjs +114 -0
  114. package/tools/starters.mjs +402 -0
  115. package/tools/steps.mjs +118 -0
  116. package/tools/take-check.mjs +146 -0
  117. package/tools/template-theme.mjs +3 -1
  118. package/tools/test-impact.mjs +36 -12
  119. package/tools/theme-check.mjs +196 -1
  120. package/tools/tone-cue.mjs +108 -0
  121. package/tools/tts-cache.mjs +9 -3
  122. package/tools/tts-engines.mjs +100 -11
  123. package/tools/video-cache.mjs +93 -0
  124. package/tools/video-live.mjs +349 -0
  125. package/tools/video-options.mjs +11 -0
  126. package/tools/video.mjs +825 -117
  127. package/tools/viseme-fit.mjs +27 -0
  128. package/tools/viseme-match.mjs +77 -0
  129. package/tools/vocabulary.mjs +397 -0
  130. package/tools/voice-renumber.mjs +605 -0
  131. package/tools/voiceover-server.mjs +42 -11
  132. package/tools/voiceover.mjs +48 -20
  133. package/dist/build-info.json +0 -1
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * decklight vscode — help an editor help the author.
7
+ *
8
+ * decklight vscode [dir | deck.html] [--print]
9
+ *
10
+ * Writes a `.vscode/` folder beside the deck: VS Code's HTML custom data, so
11
+ * typing `data-` completes `data-build`, `data-layout` and the rest with
12
+ * their values and a line on each, and a snippets file (a slide, a build
13
+ * list, notes with [click] markers, a diagram, a chart, a comparison slide).
14
+ * `decklight init --vscode` writes the same.
15
+ *
16
+ * GENERATED WHEN WRITTEN, never committed as copies: both files are made from
17
+ * tools/vocabulary.mjs, the one table `decklight check` and the Check deck
18
+ * panel read, at the moment they are written, its words described by
19
+ * cli/vocabulary-docs.mjs (kept out of the runtime bundle). So they say what the installed
20
+ * Decklight reads, and re-running after an upgrade refreshes them.
21
+ *
22
+ * `.vscode/settings.json` is the person's. It is never overwritten: the one
23
+ * key, `html.customData`, is added in place (comments and the rest of the file
24
+ * untouched), or, when it cannot be added safely, the line to add is said.
25
+ *
26
+ * NO JSON SCHEMA FOR THE CONFIGURATION BLOCK. The block lives in a `<script
27
+ * type="application/json">` inside the deck, and VS Code applies a JSON schema
28
+ * to JSON files, not to JSON embedded in HTML: a schema would validate
29
+ * nothing where the author types. `decklight check` (config-json, config-key,
30
+ * config-value) is what reads the block, and the custom data's hover on
31
+ * `data-decklight-config` lists its keys.
32
+ */
33
+
34
+ import fs from 'node:fs';
35
+ import path from 'node:path';
36
+
37
+ import { ATTRIBUTES, CONFIG_KEYS, attributeEntry } from '../tools/vocabulary.mjs';
38
+ import { ATTRIBUTE_DOCS, CONFIG_DOCS } from './vocabulary-docs.mjs';
39
+ import { PKG } from './skill-content.mjs';
40
+ import { isMain } from '../tools/args.mjs';
41
+ import { CommandError, runMain } from './util.mjs';
42
+
43
+ export const DATA_FILE = 'decklight.html-data.json';
44
+ export const SNIPPETS_FILE = 'decklight.code-snippets';
45
+ /** What `html.customData` names: relative to the folder VS Code opened. */
46
+ export const DATA_REF = `./.vscode/${DATA_FILE}`;
47
+
48
+ // ── the custom data ──────────────────────────────────────────────────────────
49
+
50
+ const where = (on) => (!on ? '' : /^[a-z]+$/.test(on) ? `On \`<${on}>\`. ` : `On a ${on}. `);
51
+
52
+ /**
53
+ * VS Code's HTML custom data (version 1.1): every authored attribute as a
54
+ * global attribute, its values when it takes an enumeration, `valueSet: "v"`
55
+ * when it takes none. Global rather than per-tag, so a `data-build` completes
56
+ * on any element, which is where it may go; the description says where an
57
+ * attribute belongs when that matters.
58
+ */
59
+ export function customData() {
60
+ return {
61
+ version: 1.1,
62
+ globalAttributes: ATTRIBUTES.map((a) => {
63
+ const keys = a.name === 'data-decklight-config'
64
+ ? `\n\nKeys:\n${CONFIG_KEYS.map((k) => `- \`${k.name}\`: ${CONFIG_DOCS[k.name]}`).join('\n')}` : '';
65
+ const doc = ATTRIBUTE_DOCS[a.name];
66
+ return {
67
+ name: a.name,
68
+ description: { kind: 'markdown', value: `${where(doc.on)}${doc.desc}${keys}` },
69
+ ...(a.values ? { values: a.values.map((v) => ({ name: v })) }
70
+ : a.bare && !a.number ? { valueSet: 'v' } : {}),
71
+ };
72
+ }),
73
+ };
74
+ }
75
+
76
+ // ── the snippets ─────────────────────────────────────────────────────────────
77
+
78
+ /** `${n|a,b,c|}`: a placeholder that offers the table's values for `name`. */
79
+ const choice = (n, name) => `\${${n}|${attributeEntry(name).values.join(',')}|}`;
80
+
81
+ /**
82
+ * Each snippet's markup, as the reference writes it (SPEC DECK_ANATOMY,
83
+ * BUILDS, SVG_DIAGRAMS, CHARTS, COMPARISON_SLIDES). test/editor-support.test.mjs
84
+ * expands every one into a deck and runs `decklight check` on it.
85
+ */
86
+ export function snippets() {
87
+ const s = (prefix, description, body) => ({ prefix, description, scope: 'html', body: body.split('\n') });
88
+ return {
89
+ 'Decklight slide': s('dl-slide', 'A slide: a title, one point, and what you say over it.', `<section>
90
+ <h2>\${1:The point of this slide}</h2>
91
+ <p>\${2:One thing, said plainly.}</p>
92
+ <aside class="notes">\${3:What you say while it is up.}</aside>
93
+ </section>$0`),
94
+ 'Decklight build list': s('dl-build', 'A list that builds: one item per click.', `<ul data-build="${choice(1, 'data-build')}">
95
+ <li>\${2:First point}</li>
96
+ <li>\${3:Second point}</li>
97
+ <li>\${4:Third point}</li>
98
+ </ul>$0`),
99
+ 'Decklight notes': s('dl-notes', 'Speaker notes with [click] markers: one per build step, words before the first said on arrival.', `<aside class="notes">
100
+ \${1:Said as the slide arrives.}
101
+ [click] \${2:Said as the first build lands.}
102
+ [click] \${3:Said as the second lands.}
103
+ [click] \${4:Said as the third lands.}
104
+ </aside>$0`),
105
+ 'Decklight diagram': s('dl-diagram', 'An SVG diagram in theme colours that draws in: two boxes and the wire that joins them.', `<svg viewBox="0 0 640 220" role="img" aria-label="\${1:Client calls the API}" data-build="draw">
106
+ <defs>
107
+ <marker id="\${2:arrow}" markerWidth="6" markerHeight="4" refX="5" refY="2" orient="auto">
108
+ <polygon points="0 0, 6 2, 0 4" fill="var(--d-stroke)"/>
109
+ </marker>
110
+ </defs>
111
+ <g data-node="\${3:client}">
112
+ <rect x="40" y="70" width="180" height="80" rx="10" fill="var(--d-fill-1)" stroke="var(--d-stroke)" stroke-width="2"/>
113
+ <text x="130" y="117" text-anchor="middle" font-size="22" fill="var(--d-text)">\${4:Client}</text>
114
+ </g>
115
+ <g data-node="\${5:api}">
116
+ <rect x="420" y="70" width="180" height="80" rx="10" fill="var(--d-fill-2)" stroke="var(--d-stroke)" stroke-width="2"/>
117
+ <text x="510" y="117" text-anchor="middle" font-size="22" fill="var(--d-text)">\${6:API}</text>
118
+ </g>
119
+ <line x1="220" y1="110" x2="420" y2="110" data-from="\${3}" data-to="\${5}" data-route="${choice(7, 'data-route')}"
120
+ stroke="var(--d-stroke)" stroke-width="2" marker-end="url(#\${2})"/>
121
+ </svg>$0`),
122
+ 'Decklight chart': s('dl-chart', 'A chart drawn from data, in theme colours, one series per click.', `<div class="chart" data-chart="${choice(1, 'data-chart')}" data-title="\${2:Latency by release}" data-build="draw">
123
+ <script type="application/json">
124
+ { "labels": ["v1", "v2", "v3"],
125
+ "series": [ { "name": "\${3:p50}", "data": [120, 80, 45] },
126
+ { "name": "\${4:p99}", "data": [340, 260, 190] } ] }
127
+ </script>
128
+ </div>$0`),
129
+ 'Decklight comparison slide': s('dl-compare', 'Two columns side by side and a footer under both (COMPARISON_SLIDES).', `<section data-layout="split">
130
+ <h2>\${1:This or that}</h2>
131
+
132
+ <div>
133
+ <h3>\${2:Pros}</h3>
134
+ <ul><li>\${3:One}</li><li>\${4:Two}</li></ul>
135
+ </div>
136
+
137
+ <div>
138
+ <h3>\${5:Cons}</h3>
139
+ <ul><li>\${6:One}</li><li>\${7:Two}</li></ul>
140
+ </div>
141
+
142
+ <p>\${8:A line that applies to both.}</p>
143
+
144
+ <aside class="notes">\${9:Pros first, then the two that bite.}</aside>
145
+ </section>$0`),
146
+ 'Decklight figure': s('dl-figure', 'One large number over its label, counted up as it arrives (DECK_ANATOMY).', `<div class="figure">
147
+ <p data-figure data-count>\${1:94%}</p>
148
+ <p>\${2:of requests never reach the database}</p>
149
+ </div>$0`),
150
+ 'Decklight conversation': s('dl-conversation', 'Turns between a user, an agent and its tools, one a click (DECK_ANATOMY).', `<div class="conversation" data-build>
151
+ <p data-role="user">\${1:Where is my order 4417?}</p>
152
+ <p data-role="agent" data-kind="tool-call">\${2:get_order(4417)}</p>
153
+ <p data-role="tool" data-name="\${3:get_order}">{ "status": "delayed", "eta": "Friday" }</p>
154
+ <p data-role="agent">\${4:It is delayed and should arrive Friday.}</p>
155
+ </div>$0`),
156
+ };
157
+ }
158
+
159
+ /** The snippets file: JSON with a first line saying where it came from. */
160
+ export const snippetsText = () => `// Decklight ${PKG.version} snippets, generated by \`decklight vscode\`: run it again after an upgrade to refresh them.\n`
161
+ + `${JSON.stringify(snippets(), null, 2)}\n`;
162
+
163
+ /**
164
+ * A snippet as it lands with every placeholder taken at its default: the
165
+ * first value of a choice, the words of a `${n:words}`, a bare `${n}` as what
166
+ * its number said first, and `$0` as nothing.
167
+ */
168
+ export function expandSnippet(body) {
169
+ const text = Array.isArray(body) ? body.join('\n') : String(body);
170
+ const said = {};
171
+ const out = text
172
+ .replace(/\$\{(\d+)\|([^|]*)\|\}/g, (_, n, opts) => (said[n] = opts.split(',')[0]))
173
+ .replace(/\$\{(\d+):([^}]*)\}/g, (_, n, words) => (said[n] = words));
174
+ return out.replace(/\$\{(\d+)\}/g, (_, n) => said[n] ?? '').replace(/\$0/g, '');
175
+ }
176
+
177
+ // ── settings.json, merged and never overwritten ─────────────────────────────
178
+
179
+ /**
180
+ * `text` with its comments and its trailing commas blanked to spaces, so it
181
+ * parses as JSON and every offset still points where it did. VS Code reads
182
+ * settings.json as JSON with comments; this reads it the same way.
183
+ */
184
+ export function maskJsonc(text) {
185
+ let out = '';
186
+ for (let i = 0; i < text.length; i++) {
187
+ const c = text[i];
188
+ if (c === '"') {
189
+ const start = i;
190
+ for (i++; i < text.length && text[i] !== '"'; i++) if (text[i] === '\\') i++;
191
+ out += text.slice(start, i + 1);
192
+ } else if (c === '/' && text[i + 1] === '/') {
193
+ const end = text.indexOf('\n', i);
194
+ const stop = end === -1 ? text.length : end;
195
+ out += ' '.repeat(stop - i);
196
+ i = stop - 1;
197
+ } else if (c === '/' && text[i + 1] === '*') {
198
+ const end = text.indexOf('*/', i + 2);
199
+ const stop = end === -1 ? text.length : end + 2;
200
+ out += text.slice(i, stop).replace(/[^\n]/g, ' ');
201
+ i = stop - 1;
202
+ } else out += c;
203
+ }
204
+ return out.replace(/,(\s*[}\]])/g, ' $1');
205
+ }
206
+
207
+ /**
208
+ * `.vscode/settings.json` with `html.customData` naming the data file, as
209
+ * `{ text, did }`: `created` (no file), `added` (the key put in at the top of
210
+ * the object, nothing else touched), `present` (it already names the file:
211
+ * `text` unchanged), or `manual` with `text` null and `say` the line to add,
212
+ * when the file has its own list there or cannot be read as JSON.
213
+ */
214
+ export function mergeSettings(existing, ref = DATA_REF) {
215
+ const line = `"html.customData": ["${ref}"]`;
216
+ if (existing == null || !existing.trim()) return { did: 'created', text: `{\n ${line}\n}\n` };
217
+ const masked = maskJsonc(existing);
218
+ let parsed;
219
+ try { parsed = JSON.parse(masked); } catch { parsed = undefined; }
220
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
221
+ return { did: 'manual', text: null, say: `add ${line} to it (it does not read as a JSON object)` };
222
+ }
223
+ const have = parsed['html.customData'];
224
+ if (have !== undefined) {
225
+ if (Array.isArray(have) && have.includes(ref)) return { did: 'present', text: existing };
226
+ return { did: 'manual', text: null, say: `add "${ref}" to its "html.customData" list` };
227
+ }
228
+ const brace = masked.indexOf('{');
229
+ const empty = !Object.keys(parsed).length;
230
+ const indent = /\n([ \t]+)\S/.exec(existing.slice(brace))?.[1] ?? ' ';
231
+ const text = `${existing.slice(0, brace + 1)}\n${indent}${line}${empty ? '\n' : ','}${existing.slice(brace + 1)}`;
232
+ return { did: 'added', text };
233
+ }
234
+
235
+ // ── writing them ─────────────────────────────────────────────────────────────
236
+
237
+ /**
238
+ * Write the editor support into `<root>/.vscode/`: the data file and the
239
+ * snippets always (they are generated, so a refresh is the point), and the
240
+ * one settings key merged. Returns the lines to say, in order.
241
+ */
242
+ export function writeEditorSupport(root) {
243
+ const dir = path.join(root, '.vscode');
244
+ fs.mkdirSync(dir, { recursive: true });
245
+ fs.writeFileSync(path.join(dir, DATA_FILE), `${JSON.stringify(customData(), null, 2)}\n`);
246
+ fs.writeFileSync(path.join(dir, SNIPPETS_FILE), snippetsText());
247
+ const lines = [`wrote .vscode/${DATA_FILE} and .vscode/${SNIPPETS_FILE} (v${PKG.version}): data-* completions, and dl- snippets`];
248
+ const settings = path.join(dir, 'settings.json');
249
+ const had = fs.existsSync(settings) ? fs.readFileSync(settings, 'utf8') : null;
250
+ const merged = mergeSettings(had);
251
+ if (merged.did === 'created' || merged.did === 'added') fs.writeFileSync(settings, merged.text);
252
+ lines.push({
253
+ created: 'wrote .vscode/settings.json: html.customData points VS Code at the completions',
254
+ added: 'added html.customData to .vscode/settings.json, the rest of it as it was',
255
+ present: '.vscode/settings.json already points VS Code at the completions',
256
+ manual: `.vscode/settings.json is yours and was left as it is: ${merged.say}`,
257
+ }[merged.did]);
258
+ return lines;
259
+ }
260
+
261
+ const USAGE = `usage: decklight vscode [dir | deck.html]
262
+ writes .vscode/ beside the deck, so VS Code helps you write it:
263
+ ${DATA_FILE} typing data- completes data-build, data-layout and
264
+ the rest, with their values and a line on each
265
+ ${SNIPPETS_FILE} dl-slide, dl-build, dl-notes, dl-diagram,
266
+ dl-chart, dl-compare, dl-figure,
267
+ dl-conversation
268
+ settings.json html.customData added, the rest of the file
269
+ kept (a list of your own there: the line to
270
+ add is said)
271
+ Both files are generated from the Decklight installed here: run it again
272
+ after an upgrade. decklight init --vscode writes the same for a new deck.`;
273
+
274
+ export async function vscodeMain(args = []) {
275
+ if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
276
+ const unknown = args.filter((a) => a.startsWith('-'));
277
+ if (unknown.length) throw new CommandError(`unknown option ${unknown[0]}\n\n${USAGE}`);
278
+ const target = path.resolve(args[0] ?? '.');
279
+ if (args.length > 1) throw new CommandError(`one folder or deck at a time\n\n${USAGE}`);
280
+ const root = fs.existsSync(target) && fs.statSync(target).isFile() ? path.dirname(target) : target;
281
+ if (!fs.existsSync(root)) throw new CommandError(`no such folder: ${args[0]}`);
282
+ for (const line of writeEditorSupport(root)) console.log(line);
283
+ return 0;
284
+ }
285
+
286
+ if (isMain(import.meta.url)) process.exitCode = await runMain('vscode', vscodeMain);
package/cli/enhance.mjs CHANGED
@@ -25,17 +25,30 @@
25
25
  * `--spoken` is the other rewrite (KINDS): the notes WRITTEN FOR THE EAR —
26
26
  * terse notes turned into sentences a person would say. It rewords, so its
27
27
  * check is the deck's structure instead of the words (`spokenProblem`).
28
+ *
29
+ * `--match-slide` is the third: the notes reworded to agree with what the
30
+ * slide SHOWS, its text runs (cli/rewrite.mjs) sent along. The mirror of the
31
+ * slide-text tool *match the script*; it rewords too, so the same check.
32
+ *
33
+ * `--rewrite` is the plain one: the same meaning, said more clearly. It and
34
+ * the tags and the spoken rewrite can work on a PASSAGE of the notes (the
35
+ * notes card's selection, or one build's part): the agent is shown the whole
36
+ * script with the passage marked and answers the passage alone, which
37
+ * decklight puts back in its place and checks both ways (`enhanceText`).
28
38
  */
29
39
 
30
40
  import { execFile } from 'node:child_process';
31
41
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
32
42
  import { dirname, resolve } from 'node:path';
33
- import { agentAsk, agentUnavailable, detectAgents } from './agents.mjs';
43
+ import { agentAsk, agentUnavailable, applyModelFlags, detectAgents } from './agents.mjs';
34
44
  import { argReader, firstPositional, isMain } from '../tools/args.mjs';
35
45
  import { runMain } from './util.mjs';
36
46
  import { NOTES_ASIDE, cleanNotes, readNotes, sectionBodies, isHiddenSection } from '../tools/deck-html.mjs';
37
47
  import { canonMarks, captioned, writtenMarks, CLICK_MARK, PAUSE_MARK } from '../tools/sentences.mjs';
38
48
  import { notesTextToAside, setSlideNotes } from './edit.mjs';
49
+ // a cycle (rewrite.mjs reads this file's ask and timeouts), safe because
50
+ // neither module touches the other's bindings while it loads
51
+ import { textRuns } from './rewrite.mjs';
39
52
 
40
53
  /** Where the prompt below comes from — said in the prompt's own header and in SPEC. */
41
54
  export const ENHANCE_SOURCE = 'https://elevenlabs.io/docs/overview/capabilities/text-to-speech/best-practices#prompting-eleven-v4';
@@ -252,6 +265,33 @@ Rewritten: And if you fluff a line, just press Backspace to take it again. When
252
265
  export const spokenPrompt = (script) =>
253
266
  `${SPOKEN_PROMPT}\n\n${DECKLIGHT_ADDENDUM.replace('the enhanced script', 'the rewritten script')}\n\n# Script\n\n${script}`;
254
267
 
268
+ // ── matched to the slide ────────────────────────────────────────────────────
269
+ // The notes reworded to agree with the slide on screen: its terms, names and
270
+ // numbers, the order it shows its points in. The slide's text runs go along
271
+ // under # Slide. It rewords, so it is checked like the spoken rewrite.
272
+
273
+ export const MATCH_SLIDE_PROMPT = `# Instructions
274
+
275
+ You are rewriting the speaker-notes script of one presentation slide so that it agrees with what the slide shows. The slide's own text, the words the audience reads while the presenter speaks, is given under # Slide, one stretch of text per line in reading order.
276
+
277
+ * Use the slide's terms, names and numbers: where the script calls something by another name, or gives a figure the slide gives differently, say it the slide's way.
278
+ * Follow the slide's order of ideas, and speak to every point the slide makes. Where the slide shows something the script never mentions, add a short sentence about it; where the script and the slide disagree, the slide wins.
279
+ * Keep what the script adds beyond the slide (examples, reasons, transitions) unless it contradicts the slide.
280
+ * It stays a script, written for the ear: say the slide's points in sentences, do not read its bullets out word for word.
281
+ * Keep it about as long as it was. Keep the language of the original, and any audio tag in square brackets (such as [thoughtful]) with the sentence it belongs to.
282
+ * Each [click] starts a build: what comes after it is said while the slide's next part appears. Keep the beats about the parts they are about.
283
+ * A script that already agrees with the slide stays exactly as it is.`;
284
+
285
+ /** The whole ask for one slide's script, matched to `slideText` (the slide's runs, one per line). */
286
+ export const matchSlidePrompt = (script, { slideText = '' } = {}) =>
287
+ `${MATCH_SLIDE_PROMPT}\n\n${DECKLIGHT_ADDENDUM.replace('the enhanced script', 'the rewritten script')}\n\n# Slide\n\n${slideText || '(the slide shows no text)'}\n\n# Script\n\n${script}`;
288
+
289
+ /** A section body's visible text, one run per line, as the match-slide prompt shows it. Pure. */
290
+ export function slideTextOf(body) {
291
+ const open = body.indexOf('>');
292
+ return textRuns(open < 0 ? body : body.slice(open + 1)).map((r) => r.text.replace(/\s*\n\s*/g, ' ')).join('\n');
293
+ }
294
+
255
295
  const wordCount = (text) => wordsOf(text).split(' ').filter(Boolean).length;
256
296
 
257
297
  /**
@@ -275,26 +315,88 @@ export function spokenProblem(before, after) {
275
315
  return null;
276
316
  }
277
317
 
318
+ // ── rewritten ───────────────────────────────────────────────────────────────
319
+ // The plain rewrite: the same points, worded more clearly and more naturally
320
+ // to say. It rewords, so it is checked like the spoken rewrite.
321
+
322
+ export const REWRITE_PROMPT = `# Instructions
323
+
324
+ You are rewriting the speaker-notes script of one presentation slide so that it says the same thing more clearly and more naturally. A narrator will read your text aloud, word for word.
325
+
326
+ * Keep the meaning: every fact, instruction, number, name and technical term stays, and nothing new is added (no claims, examples, jokes or opinions).
327
+ * Make it clearer and smoother to say: simpler sentences, plain words, better flow from one idea to the next, no repetition.
328
+ * Keep the presenter's voice and register, and the language of the original.
329
+ * Keep it about as long as it was.
330
+ * Keep any audio tag in square brackets (such as [thoughtful]) attached to the sentence it belongs to.`;
331
+
332
+ /** The whole ask for one slide's script, rewritten. */
333
+ export const rewritePrompt = (script) =>
334
+ `${REWRITE_PROMPT}\n\n${DECKLIGHT_ADDENDUM.replace('the enhanced script', 'the rewritten script')}\n\n# Script\n\n${script}`;
335
+
336
+ // ── a passage ───────────────────────────────────────────────────────────────
337
+ // A rewrite of part of the notes: the script goes whole, so the agent sees
338
+ // what the passage sits in, with the passage between two marks no script
339
+ // contains, and the answer is the passage alone.
340
+
341
+ const OPEN = '⟦', CLOSE = '⟧';
342
+ export const PASSAGE_NOTE = `# The passage
343
+
344
+ Change ONLY the passage between ${OPEN} and ${CLOSE} in the script above; everything outside it is context, and stays as it is. Reply with the rewritten passage ONLY, without the ${OPEN} ${CLOSE} marks and without any of the script around it. The passage may start or end mid-sentence: your answer must fit back in its place.`;
345
+
346
+ /** `kind`'s prompt for `script` with `script.slice(from, to)` marked as the passage to change. */
347
+ export function passagePrompt(kind, script, { from, to }, opts = {}) {
348
+ const marked = `${script.slice(0, from)}${OPEN}${script.slice(from, to)}${CLOSE}${script.slice(to)}`;
349
+ return `${kindOf(kind).prompt(marked, opts)}\n\n${PASSAGE_NOTE}`;
350
+ }
351
+
278
352
  /**
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.
353
+ * Where the passage the page asked about sits in the notes as the server
354
+ * reads them: `{ from, to }`, or null when it is not there (once). The page
355
+ * sends its own offsets and the passage's text; the notes it measured them
356
+ * against can differ from the file in whitespace, so the text decides, the
357
+ * offsets only when they still point at it. Pure.
358
+ */
359
+ export function findPassage(script, { from, to, text } = {}) {
360
+ const want = String(text ?? '').trim();
361
+ if (!want) return null;
362
+ if (Number.isInteger(from) && Number.isInteger(to) && script.slice(from, to).trim() === want) {
363
+ const lead = script.slice(from, to).length - script.slice(from, to).trimStart().length;
364
+ return { from: from + lead, to: from + lead + want.length };
365
+ }
366
+ const at = script.indexOf(want);
367
+ if (at < 0 || script.indexOf(want, at + 1) >= 0) return null;
368
+ return { from: at, to: at + want.length };
369
+ }
370
+
371
+ /**
372
+ * The rewrites the notes get, by name: `tags` (ElevenLabs v4 audio tags,
373
+ * same words), `spoken` (written for the ear, reworded) and `match-slide`
374
+ * (reworded to agree with the slide) and `rewrite` (the same meaning, said
375
+ * more clearly). Each is a prompt, the check its answer
376
+ * must pass before a byte of the deck changes, and the words the run and the
377
+ * review say it with.
282
378
  */
283
379
  export const KINDS = {
284
- tags: { prompt: enhancePrompt, problem: enhanceProblem, done: 'enhanced' },
285
- spoken: { prompt: spokenPrompt, problem: spokenProblem, done: 'rewritten for the ear' },
380
+ tags: { prompt: enhancePrompt, problem: enhanceProblem, done: 'enhanced', what: 'script: audio tags' },
381
+ spoken: { prompt: spokenPrompt, problem: spokenProblem, done: 'rewritten for the ear', what: 'script: written for the ear', doing: ', written for the ear' },
382
+ 'match-slide': { prompt: matchSlidePrompt, problem: spokenProblem, done: 'matched to the slide', what: 'script: matched to the slide', doing: ', matched to the slide' },
383
+ rewrite: { prompt: rewritePrompt, problem: spokenProblem, done: 'rewritten', what: 'script: rewritten', doing: ', rewritten', passage: true },
286
384
  };
385
+ // the tags and the spoken rewrite work on a passage too; matching the slide
386
+ // reads the whole script against the whole slide, so it never does
387
+ KINDS.tags.passage = true;
388
+ KINDS.spoken.passage = true;
287
389
  const kindOf = (kind) => KINDS[kind] ?? KINDS.tags;
288
390
 
289
- /** Run a read-only agent ask; resolves to its stdout, or null. */
290
- export function ask(cmd, cwd, timeoutMs) {
391
+ /** Run a read-only agent ask; resolves to its stdout, or null — null too when `signal` stops it. */
392
+ export function ask(cmd, cwd, timeoutMs, signal = null) {
291
393
  return new Promise((done) => {
292
394
  let settled = false;
293
395
  const finish = (v) => { if (!settled) { settled = true; done(v); } };
294
396
  let child;
295
397
  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 ?? '')));
398
+ child = execFile(cmd.bin, cmd.args, { cwd, env: cmd.env, timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'], ...(signal ? { signal } : {}) },
399
+ (err, stdout) => finish(err && (!stdout || err.name === 'AbortError') ? null : String(stdout ?? '')));
298
400
  } catch { return finish(null); }
299
401
  child.on('error', () => finish(null));
300
402
  });
@@ -306,7 +408,7 @@ export const ENHANCE_TIMEOUT_MS = 120_000;
306
408
  export const ENHANCE_CONCURRENCY = 3;
307
409
 
308
410
  /**
309
- * The slides of `html` that can be enhanced, as `{ slide, inner, script }`:
411
+ * The slides of `html` that can be enhanced, as `{ slide, script, slideText }`:
310
412
  * a visible slide with an `<aside class="notes">` that says something.
311
413
  * `only` (1-based slide numbers) narrows it.
312
414
  */
@@ -318,7 +420,7 @@ export function enhanceable(html, only = null) {
318
420
  if (isHiddenSection(body)) return [];
319
421
  const aside = NOTES_ASIDE.exec(body);
320
422
  const script = aside ? slideScript(aside[1]) : null;
321
- return script ? [{ slide, script }] : [];
423
+ return script ? [{ slide, script, slideText: slideTextOf(body) }] : [];
322
424
  });
323
425
  }
324
426
 
@@ -326,17 +428,30 @@ export function enhanceable(html, only = null) {
326
428
  * One script, enhanced: the agent is asked, its answer unwrapped and checked.
327
429
  * Resolves to `{ ok, text }` or `{ ok: false, why }` — the unit every caller
328
430
  * shares, from the notes editor's one box to a whole deck.
431
+ *
432
+ * `passage` (`{ from, to }` in `script`, for a kind that takes one) narrows
433
+ * it: the answer is that passage, put back in its place, and checked as a
434
+ * passage (its own beats and pauses) and then as the script it makes.
329
435
  */
330
436
  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,
437
+ kind = 'tags', slideText = '', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
438
+ resolveAgent = agentAsk, exec = ask, signal = null, passage = null,
333
439
  } = {}) {
334
440
  const k = kindOf(kind);
335
- const cmd = resolveAgent(agent, k.prompt(script), { env });
441
+ const part = passage && k.passage ? passage : null;
442
+ const cmd = resolveAgent(agent, part ? passagePrompt(kind, script, part, { slideText }) : k.prompt(script, { slideText }), { env });
336
443
  if (!cmd) return { ok: false, why: agentUnavailable(agent, detectAgents({ env })) };
337
- const out = await exec(cmd, cwd, timeoutMs);
444
+ const out = await exec(cmd, cwd, timeoutMs, signal);
445
+ if (signal?.aborted) return { ok: false, why: 'stopped' };
338
446
  if (out == null) return { ok: false, why: 'the agent did not answer in time' };
339
- const text = unwrapAnswer(out);
447
+ let text = unwrapAnswer(out);
448
+ if (part) {
449
+ const was = script.slice(part.from, part.to);
450
+ const answer = text.replaceAll(OPEN, '').replaceAll(CLOSE, '').trim();
451
+ const why = k.problem(was, answer);
452
+ if (why) return { ok: false, why: `${why} (in the passage)` };
453
+ text = `${script.slice(0, part.from)}${answer}${script.slice(part.to)}`;
454
+ }
340
455
  const why = k.problem(script, text);
341
456
  return why ? { ok: false, why } : { ok: true, text, changed: text !== script.trim() };
342
457
  }
@@ -366,20 +481,24 @@ export function applyEnhanced(html, answers) {
366
481
  * the deck with every passing slide rewritten (`applyEnhanced`), one
367
482
  * `{ slide, ok, changed, why }` per slide asked about, and the raw answers for
368
483
  * 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.
484
+ * slide's failure — only when there is no agent to ask at all. `signal` stops
485
+ * it: the asks in flight are killed and no slide after them is asked about.
370
486
  */
371
487
  export async function enhanceDeck(html, slides = null, {
372
488
  kind = 'tags', agent = null, cwd = process.cwd(), env = process.env, timeoutMs = ENHANCE_TIMEOUT_MS,
373
- concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onSlide = () => {},
489
+ concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onSlide = () => {}, signal = null,
490
+ passage = null,
374
491
  } = {}) {
375
492
  if (!resolveAgent(agent, 'x', { env })) throw new Error(agentUnavailable(agent, detectAgents({ env })));
376
493
  const todo = enhanceable(html, slides);
494
+ // a passage is of ONE slide's notes, as they read when it was found
495
+ if (passage && todo.length !== 1) throw new Error('a passage is part of one slide\'s notes');
377
496
  const answers = [];
378
497
  let next = 0, finished = 0;
379
498
  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 });
499
+ while (next < todo.length && !signal?.aborted) {
500
+ const { slide, script, slideText } = todo[next++];
501
+ const a = await enhanceText(script, { kind, slideText, agent, cwd, env, timeoutMs, resolveAgent, exec, signal, passage });
383
502
  const r = { slide, ok: a.ok, changed: a.ok && a.text !== script, ...(a.ok ? {} : { why: a.why }) };
384
503
  answers.push({ ...r, before: script, text: a.text ?? null });
385
504
  onSlide({ ...r, done: ++finished, of: todo.length });
@@ -410,9 +529,11 @@ export function parseSlides(s, total) {
410
529
  const USAGE = `decklight enhance — add ElevenLabs v4 audio tags to the voiceover script
411
530
 
412
531
  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]
532
+ decklight enhance <deck.html> --slides <n | a-b | a,b,c> [--agent <name>] [--agent-model <id>] [--dry-run]
533
+ decklight enhance <deck.html> --all [--agent <name>] [--agent-model <id>] [--dry-run]
415
534
  decklight enhance <deck.html> --spoken --slides … | --all write it for the ear instead
535
+ decklight enhance <deck.html> --match-slide --slides … | --all match it to the slide instead
536
+ decklight enhance <deck.html> --rewrite --slides … | --all say the same thing more clearly instead
416
537
 
417
538
  Asks the AI agent installed on this machine (claude, codex, …) to add audio
418
539
  tags — [thoughtful], [sighs], [excited] — to each slide's speaker notes, with
@@ -426,19 +547,27 @@ ElevenLabs v4/v3 and left out by every other voice.
426
547
  --slides the slides to enhance
427
548
  --all every slide with notes
428
549
  --agent which agent to ask (default: your remembered one, else the first found)
550
+ --agent-model the model it answers on, this run only (also --agent-ask-model,
551
+ DECKLIGHT_AGENT_MODEL; default: the remembered one, else its own)
429
552
  --dry-run print each enhanced script; write nothing
430
553
  --spoken rewrite terse notes as sentences a person would say out loud
431
554
  ("Fluffed a line? Backspace retakes it." → "And if you fluff a
432
555
  line, just press Backspace to take it again."). This one DOES
433
556
  reword; decklight checks the [click] beats and [pause]s survive
434
557
  and the length stays in proportion.
558
+ --match-slide reword the notes to agree with what the slide shows: its
559
+ terms, names and numbers, its order, every point it makes. The
560
+ slide's text is sent along; checked like --spoken.
561
+ --rewrite the same meaning, worded more clearly and more naturally to
562
+ say; nothing added, nothing dropped. Checked like --spoken.
435
563
 
436
564
  Note: the notes are sent to that agent, and most agents are cloud services.`;
437
565
 
438
566
  export async function enhanceMain(args = []) {
439
567
  if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
440
568
  const { opt } = argReader(args);
441
- const deck = firstPositional(args, ['--slides', '--agent']);
569
+ applyModelFlags(opt);
570
+ const deck = firstPositional(args, ['--slides', '--agent', '--agent-model', '--agent-ask-model']);
442
571
  if (!deck) { console.error(`decklight enhance: needs a deck\n\n${USAGE}`); return 1; }
443
572
  const path = resolve(deck);
444
573
  if (!existsSync(path)) { console.error(`decklight enhance: no such deck: ${deck}`); return 1; }
@@ -453,13 +582,14 @@ export async function enhanceMain(args = []) {
453
582
  try { slides = all ? null : parseSlides(which, sectionBodies(html).length); }
454
583
  catch (e) { console.error(`decklight enhance: ${e.message}`); return 1; }
455
584
  const dry = args.includes('--dry-run');
456
- const kind = args.includes('--spoken') ? 'spoken' : 'tags';
585
+ const kind = args.includes('--match-slide') ? 'match-slide' : args.includes('--rewrite') ? 'rewrite'
586
+ : args.includes('--spoken') ? 'spoken' : 'tags';
457
587
  const verb = KINDS[kind].done;
458
588
  let res;
459
589
  try {
460
590
  const n = enhanceable(html, slides).length;
461
591
  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…`);
592
+ console.log(`enhance: ${n} slide${n === 1 ? '' : 's'}${KINDS[kind].doing ?? ''} — asking the agent (read-only), a few at a time…`);
463
593
  res = await enhanceDeck(html, slides, {
464
594
  kind, agent: opt('--agent') ?? null, cwd: dirname(path),
465
595
  onSlide: (r) => console.log(` slide ${r.slide}: ${r.ok ? (r.changed ? verb : 'already as it would be') : `left as it was — ${r.why}`}`