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,497 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ // decklight design-system — the design-system unit (SPEC DESIGN_SYSTEMS).
6
+ //
7
+ // decklight design-system gate <dir>
8
+ // decklight design-system add|remove <name@marketplace> <deck.html>
9
+ // decklight design-system list [<deck.html>]
10
+ // decklight design-system migrate <name@marketplace> <deck.html>
11
+ // decklight design-system templates <name@marketplace>
12
+ //
13
+ // `check` is the admission gate a catalog's own CI runs, in the mould of
14
+ // `decklight library gate transform` and `decklight theme gate`: a valid package
15
+ // prints what it holds and exits 0; a broken or unsafe one names the file,
16
+ // the line and the rule for every problem, and exits 1. Every rule lives in
17
+ // tools/design-system-format.mjs, which is pure — this file only reads a
18
+ // directory into the shape it takes.
19
+ //
20
+ // A deck depends on a design system by REFERENCE (cli/design-system-refs.mjs):
21
+ // `add` writes `designSystems` (and the shared `themeSources`) into its
22
+ // configuration block, after the package passes `check`; every server serves
23
+ // it from the marketplace checkout. Nothing is ever installed into
24
+ // ~/.decklight/ — the ledger only remembers which version a deck took.
25
+
26
+ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
27
+ import { dirname, join, relative, resolve, sep } from 'node:path';
28
+ import { argReader, isMain } from '../tools/args.mjs';
29
+ import { checkPackage, DESIGN_SYSTEM_API_VERSION, ASSET_EXTENSIONS } from '../tools/design-system-format.mjs';
30
+ import { THEMES_DIR } from './pkg.mjs';
31
+
32
+ const USAGE = `usage: decklight design-system <add|remove|list|templates|apply|migrate|gate> …
33
+
34
+ decklight design-system add <name@marketplace> <deck.html> [--no-recommended] [--apply|--no-apply]
35
+ reference a design system from a deck — after the package passes check;
36
+ the deck gains one entry in its configuration block, never the package.
37
+ The themes and fonts it recommends come with it, in the same edit, each
38
+ through its own gate (--no-recommended: the design system alone). Then
39
+ it offers to APPLY its look — the deck's theme and font — asking on a
40
+ terminal, suggesting --apply otherwise; --apply / --no-apply decide.
41
+ EXAMPLE: decklight design-system add acme@acme-mkt talk.html
42
+
43
+ decklight design-system apply <name@marketplace> <deck.html>
44
+ give a deck the look a design system it uses was drawn for: its first
45
+ recommended theme and font (bringing any that are missing)
46
+
47
+ decklight design-system migrate <name@marketplace> <deck.html>
48
+ move a deck written for an older version onto the one this machine
49
+ serves: the renames its migrations declare (roles, tokens, classes,
50
+ themes — whole names, in the deck and the stylesheets it links), then the
51
+ version the deck records. A removed name with no successor is a
52
+ judgement call: the migration's skill makes it, not this command.
53
+
54
+ decklight design-system remove <name@marketplace> <deck.html>
55
+ drop the reference; the package stays in its marketplace, and so do the
56
+ themes and fonts it brought — other slides may use them (it lists them)
57
+
58
+ decklight design-system list [<deck.html>]
59
+ what a deck references (and the version it took against the catalog's);
60
+ with no deck, every design system the registered marketplaces offer —
61
+ from the cache alone, works on a plane
62
+
63
+ decklight design-system templates <name@marketplace>
64
+ the package's templates and their slots — the names a slide writes
65
+
66
+ decklight design-system gate <dir>
67
+ the marketplace admission gate for a design-system package — its manifest,
68
+ stylesheet, templates and assets, held to the format's rules (SPEC
69
+ DESIGN_SYSTEMS). Prints what the package holds and exits 0, or names the
70
+ file, the line and the rule for every problem and exits 1.
71
+ EXAMPLE: decklight design-system gate systems/acme
72
+
73
+ A design system is a directory:
74
+ design-system.json apiVersion (${DESIGN_SYSTEM_API_VERSION}), name, version (semver), title,
75
+ styles ("design-system.css"), templates ("templates.html")
76
+ + description, tokenPrefix (default "--<name>-"),
77
+ palette [{ group, label, token }] or { colors: { <name>:
78
+ { label, weights: { "100": "#hex" … "1000" } } } } with
79
+ themes [{ name, title, mode, tokens }] (SPEC BRAND_PALETTE),
80
+ recommendedThemes, migrations { "<version>": { skill,
81
+ roles, tokens, classes, themes } } (SPEC DESIGN_SYSTEM_MIGRATIONS)
82
+ design-system.css prefixed tokens and per-template rules; url()s relative to it
83
+ templates.html inert <template data-template="…"> blocks, with data-slot containers
84
+ assets/… ${ASSET_EXTENSIONS.join(' · ')}
85
+
86
+ A deck references a design system rather than copying it; every server
87
+ serves it from the marketplace on this machine, never the network.`;
88
+
89
+ /** Files whose TEXT the rules read; everything else is checked by extension and size. */
90
+ const TEXT = /\.(json|css|html|svg)$/i;
91
+
92
+ /**
93
+ * A package directory as `checkPackage` takes it. Every file under `dir`,
94
+ * by its /-separated relative path. A symlink that resolves outside the
95
+ * package is a problem of its own — nothing a deck is served may come from
96
+ * outside the directory it was admitted as.
97
+ */
98
+ export function readPackage(dir) {
99
+ const root = realpathSync(resolve(dir));
100
+ const files = new Map();
101
+ const escapes = [];
102
+ const walk = (abs) => {
103
+ for (const name of readdirSync(abs).sort()) {
104
+ if (name === '.git') continue;
105
+ const full = join(abs, name);
106
+ const rel = relative(root, full).split(sep).join('/');
107
+ let target = full;
108
+ if (lstatSync(full).isSymbolicLink()) {
109
+ try { target = realpathSync(full); } catch { escapes.push(rel); continue; }
110
+ if (target !== root && !target.startsWith(root + sep)) { escapes.push(rel); continue; }
111
+ }
112
+ const st = statSync(target);
113
+ if (st.isDirectory()) { walk(full); continue; }
114
+ files.set(rel, { size: st.size, ...(TEXT.test(name) ? { text: readFileSync(target, 'utf8') } : {}) });
115
+ }
116
+ };
117
+ walk(root);
118
+ const manifest = files.get('design-system.json')?.text ?? null;
119
+ return { manifest, files, escapes };
120
+ }
121
+
122
+ /** A package, checked — the gate's whole verdict, with symlink escapes folded in. */
123
+ export function checkDir(dir) {
124
+ const { manifest, files, escapes } = readPackage(dir);
125
+ if (manifest === null) {
126
+ return { ok: false, problems: [{ file: 'design-system.json', rule: 'file-missing', msg: 'no design-system.json at the package root — this is not a design system' }], warnings: [], summary: {} };
127
+ }
128
+ // the themes decklight ships: a brand theme may not take one's name, and a
129
+ // recommended one is held to the palette (SPEC BRAND_PALETTE)
130
+ let shippedThemes = [];
131
+ try { shippedThemes = readdirSync(THEMES_DIR).filter((f) => f.endsWith('.css')).map((f) => f.slice(0, -4)); } catch { /* no themes dir: nothing to compare against */ }
132
+ const recommendedThemeCss = {};
133
+ try {
134
+ for (const t of JSON.parse(manifest).recommendedThemes ?? []) {
135
+ const name = String(t).split('@')[0];
136
+ if (shippedThemes.includes(name)) recommendedThemeCss[name] = readFileSync(join(THEMES_DIR, `${name}.css`), 'utf8');
137
+ }
138
+ } catch { /* an unparseable manifest is the check's to report */ }
139
+ const r = checkPackage({ manifest, files, shippedThemes, recommendedThemeCss });
140
+ for (const rel of escapes) {
141
+ r.problems.push({ file: rel, rule: 'file-outside', msg: 'a symlink that resolves outside the package — a design system reaches only its own files' });
142
+ }
143
+ r.ok = r.problems.length === 0;
144
+ // what a server needs from a passing package, read once here: the parsed
145
+ // manifest, and the templates text it inlines into the page
146
+ try { r.manifest = JSON.parse(manifest); } catch { r.manifest = null; }
147
+ r.templatesHtml = typeof r.manifest?.templates === 'string' ? files.get(r.manifest.templates)?.text ?? null : null;
148
+ return r;
149
+ }
150
+
151
+ const where = (p) => `${p.file}${p.line ? ` line ${p.line}` : ''}`;
152
+ const kb = (n) => (n < 1024 * 1024 ? `${Math.max(1, Math.round(n / 1024))} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`);
153
+
154
+ /** The report, as the lines to print. */
155
+ export function reportLines(dir, r) {
156
+ const s = r.summary ?? {};
157
+ const out = [];
158
+ if (!r.ok) {
159
+ out.push(`✘ ${s.name ?? dir} — ${r.problems.length} problem${r.problems.length === 1 ? '' : 's'}, not admitted`);
160
+ for (const p of r.problems) out.push(` ${where(p)}: ${p.msg} [${p.rule}]`);
161
+ } else {
162
+ out.push(`✔ ${s.name} — design system ${s.version}, api ${s.apiVersion}`);
163
+ out.push(` design-system.json ${s.title}${s.palette ? ` — palette of ${s.palette}` : ''}`
164
+ + `${s.recommendedThemes?.length ? ` · recommends ${s.recommendedThemes.join(', ')}` : ''}`);
165
+ out.push(` stylesheet ${s.tokens.length} token${s.tokens.length === 1 ? '' : 's'} (${s.prefix}…)`);
166
+ if (s.baseStyles?.elements?.length) {
167
+ out.push(` base styles ${s.baseStyles.elements.join(', ')} — a slide without a template takes the brand's look for these`);
168
+ }
169
+ const templates = s.templates ?? [];
170
+ out.push(` templates ${templates.length} template${templates.length === 1 ? '' : 's'}${templates.length ? ':' : ''}`);
171
+ for (const l of templates) {
172
+ const slots = l.slots.map((x) => `${x.name}${x.required ? '*' : ''}${x.default ? '†' : ''}`).join(', ');
173
+ out.push(` ${l.id} (${slots || 'no slots'})`);
174
+ }
175
+ if (templates.some((l) => l.slots.length)) out.push(' * required · † takes unslotted content');
176
+ const roles = s.brand?.roles ?? [];
177
+ if (roles.length) {
178
+ const groups = {};
179
+ for (const r of roles) groups[r.group] = (groups[r.group] ?? 0) + 1;
180
+ out.push(` roles ${roles.length} role${roles.length === 1 ? '' : 's'} — ${Object.entries(groups).map(([g, n]) => `${g} ${n}`).join(', ')}`
181
+ + ` · ${Object.keys(s.brand.contract ?? {}).length} contract token${Object.keys(s.brand.contract ?? {}).length === 1 ? '' : 's'} read from them`);
182
+ }
183
+ for (const t of s.brand?.themes ?? []) {
184
+ const via = Object.keys(t.viaRole ?? {}).length;
185
+ out.push(` theme ${t.name} (${t.mode}) — ${t.stated.length} token${t.stated.length === 1 ? '' : 's'} stated${via ? ` (${via} through roles)` : ''}, ${t.chosen.length} chosen from the palette`
186
+ + `${roles.length ? `, every role set` : ''}`);
187
+ }
188
+ for (const m of s.migrations ?? []) {
189
+ out.push(` migration ${m.version} — ${m.renames} rename${m.renames === 1 ? '' : 's'}${m.skill ? ` · skill ${m.skill}` : ''}`);
190
+ }
191
+ const assets = s.assets ?? [];
192
+ const byExt = {};
193
+ for (const a of assets) byExt[a.ext] = (byExt[a.ext] ?? 0) + 1;
194
+ out.push(` assets ${assets.length} file${assets.length === 1 ? '' : 's'}`
195
+ + `${assets.length ? ` — ${Object.entries(byExt).map(([e, n]) => `${n} ${e}`).join(', ')} · ${kb(assets.reduce((t, a) => t + a.size, 0))}` : ''}`);
196
+ }
197
+ // declared overrides of the theme contract, printed on every run — the way a
198
+ // theme's rule-exception: is — so they stay reviewable
199
+ for (const e of r.summary?.exceptions ?? []) out.push(` ds-exception ${e.token}: ${e.reason}`);
200
+ for (const w of r.warnings ?? []) out.push(` ⚠ ${where(w)}: ${w.msg}`);
201
+ // what the engine made up or stood in for, said so a brand reviewer sees it
202
+ for (const n of r.summary?.notes ?? []) out.push(` · ${n.msg} [${n.rule}]`);
203
+ return out;
204
+ }
205
+
206
+ async function checkMain(args) {
207
+ const [dir] = args.filter((a) => !a.startsWith('-'));
208
+ if (!dir) { console.error(`decklight design-system gate: needs a package directory\n\n${USAGE}`); return 1; }
209
+ if (!existsSync(dir)) { console.error(`decklight design-system gate: no such directory: ${dir}`); return 1; }
210
+ if (!statSync(dir).isDirectory()) {
211
+ console.error(`decklight design-system gate: ${dir} is a file — a design system is a directory holding design-system.json`);
212
+ return 1;
213
+ }
214
+ const r = checkDir(dir);
215
+ for (const line of reportLines(dir, r)) console.log(line);
216
+ return r.ok ? 0 : 1;
217
+ }
218
+
219
+ /** The deck path and its text, or a refusal printed as-is. */
220
+ function readDeckArg(cmd, deck) {
221
+ if (!deck) { console.error(`decklight design-system ${cmd}: needs a deck\n\n${USAGE}`); return null; }
222
+ const path = resolve(deck);
223
+ if (!existsSync(path)) { console.error(`decklight design-system ${cmd}: no such deck: ${deck}`); return null; }
224
+ return { path, html: readFileSync(path, 'utf8') };
225
+ }
226
+
227
+ /** The catalogs this machine has fetched, for resolving a bare or qualified name. */
228
+ async function catalogs() {
229
+ const { configHome, loadRegistry, loadCatalog } = await import('./marketplace.mjs');
230
+ const out = {};
231
+ for (const name of Object.keys(loadRegistry(configHome()).marketplaces ?? {})) {
232
+ const c = loadCatalog(name);
233
+ if (c?.ok) out[name] = c.manifest;
234
+ }
235
+ return out;
236
+ }
237
+
238
+ async function addMain(args, on) {
239
+ const cmd = on ? 'add' : 'remove';
240
+ const [ref, deck] = args.filter((a) => !a.startsWith('-'));
241
+ if (!ref) { console.error(`decklight design-system ${cmd}: needs a design system and a deck\n\n${USAGE}`); return 1; }
242
+ const d = readDeckArg(cmd, deck);
243
+ if (!d) return 1;
244
+ const { MarketplaceError, resolveEntry, recordInstall, loadRegistry, configHome } = await import('./marketplace.mjs');
245
+ const { resolveDesignSystemRef, setDesignSystem, designSystemRefs, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
246
+ const { refForDeck, writeFileAtomic } = { ...(await import('./theme-refs.mjs')), ...(await import('../tools/atomic-write.mjs')) };
247
+ try {
248
+ if (!on) {
249
+ // the deck's own spelling of the reference wins, whatever this machine calls it
250
+ const hit = designSystemRefs(d.html).find((r) => r.ref === ref || r.name === ref);
251
+ if (!hit) {
252
+ const has = designSystemRefs(d.html).map((r) => r.ref);
253
+ console.error(`decklight design-system remove: ${ref} is not referenced by ${deck}${has.length ? ` — it uses ${has.join(', ')}` : ' — it uses no design system'}`);
254
+ return 1;
255
+ }
256
+ const out = setDesignSystem(d.html, hit.ref, false);
257
+ if (out.changed) writeFileAtomic(d.path, out.html);
258
+ console.log(out.changed ? `dropped ${hit.ref} from ${deck} — the package stays in its marketplace` : `${hit.ref} was not referenced by ${deck}`);
259
+ // what it brought stays: other slides, or another design system, may use it
260
+ const r = resolveDesignSystemRef(hit);
261
+ const manifest = r.dir ? checkDir(r.dir).manifest : null;
262
+ if (manifest) {
263
+ const { planRecommended } = await import('./design-system-deps.mjs');
264
+ const kept = planRecommended(out.html, { manifest, local: r.local }).items.filter((it) => it.status === 'already');
265
+ if (kept.length) {
266
+ console.log(' still in the deck — the themes and fonts it brought (the deck\'s theme and font are unchanged):');
267
+ for (const it of kept) console.log(` ${it.kind} ${it.ref} — decklight ${it.kind} remove ${it.ref} ${deck}`);
268
+ }
269
+ }
270
+ return 0;
271
+ }
272
+ let qualified = ref;
273
+ try { qualified = resolveEntry(ref, await catalogs()).qualified; } catch (e) { if (!(e instanceof MarketplaceError)) throw e; console.error(`decklight design-system add: ${e.message}`); return 1; }
274
+ const r = resolveDesignSystemRef(qualified);
275
+ if (!r.dir) { console.error(`decklight design-system add: ${r.ref} — ${r.missing}`); return 1; }
276
+ // the gate first: a package that fails leaves the deck byte-for-byte as it was
277
+ const verdict = checkDir(r.dir);
278
+ if (!verdict.ok) {
279
+ for (const line of reportLines(r.dir, verdict)) console.error(line);
280
+ console.error(`\ndecklight design-system add: ${r.ref} was NOT referenced — the package fails the check above`);
281
+ return 1;
282
+ }
283
+ const deckRef = refForDeck(d.html, r.name, r.local, r.source ?? null);
284
+ const out = setDesignSystem(d.html, deckRef, true, { source: r.source ?? null, version: verdict.manifest.version });
285
+ // a deck that already used it and records no version takes this one —
286
+ // unless it still uses names a migration renamed, which `migrate` moves first
287
+ if (!out.changed) out.html = recordVersionIfCurrent(out.html, deckRef, verdict.manifest, dirname(d.path));
288
+ // its themes and fonts, in the SAME string — one write, one edit
289
+ const recommended = !args.includes('--no-recommended');
290
+ const deps = await import('./design-system-deps.mjs');
291
+ const plan = deps.planRecommended(out.html, { manifest: verdict.manifest, local: r.local });
292
+ let html = recommended ? deps.writePlan(out.html, plan) : out.html;
293
+ let look = deps.lookOf(html, recommended ? plan : { ...plan, items: plan.items.filter((it) => it.status === 'already' || it.status === 'stack') });
294
+ const decide = args.includes('--apply') ? true : args.includes('--no-apply') || !recommended ? false : null;
295
+ if (decide && look.differs) html = deps.applyLook(html, look);
296
+ if (html !== d.html) writeFileAtomic(d.path, html);
297
+ const commit = loadRegistry(configHome()).marketplaces?.[r.local]?.commit ?? null;
298
+ recordInstall({ type: 'design-system', name: r.name, marketplace: r.local, version: r.entry.version ?? null, commit });
299
+ if (recommended) for (const inst of deps.plannedInstalls(plan)) recordInstall(inst);
300
+ const v = verdict.summary.version ? ` ${verdict.summary.version}` : '';
301
+ const { deckDesignSystemVersions } = await import('./design-system-refs.mjs');
302
+ const took = deckDesignSystemVersions(html)[deckRef];
303
+ console.log(out.changed
304
+ ? `${deck} now uses ${deckRef}${v} — ${verdict.summary.title}; every server links it from the marketplace on this machine`
305
+ : took ? `${deck} already uses ${deckRef} — written for ${took}${took !== verdict.summary.version ? `; this machine serves ${verdict.summary.version} (decklight design-system migrate ${deckRef} ${deck})` : ''}`
306
+ : `${deck} already uses ${deckRef} — it uses names from before ${verdict.summary.version}: decklight design-system migrate ${deckRef} ${deck}`);
307
+ if (recommended) for (const line of deps.planLines(plan)) console.log(line);
308
+ else if (plan.items.some((it) => it.status === 'add')) {
309
+ console.log(' --no-recommended: not added — what it recommends:');
310
+ for (const it of plan.items.filter((x) => x.status === 'add')) console.log(` ${it.kind} ${it.ref} — decklight ${it.kind} add ${it.ref} ${deck}`);
311
+ }
312
+ if (look.differs) {
313
+ const phrase = deps.lookPhrase(look, plan);
314
+ if (decide) console.log(`applied ${look.title}'s look — ${phrase}`);
315
+ else if (decide === null && process.stdin.isTTY && process.stdout.isTTY) {
316
+ const { createInterface } = await import('node:readline/promises');
317
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
318
+ const answer = (await rl.question(`Apply ${look.title}'s look — ${phrase}? [Y/n] `)).trim().toLowerCase();
319
+ rl.close();
320
+ if (answer === '' || answer === 'y' || answer === 'yes') {
321
+ writeFileAtomic(d.path, deps.applyLook(readFileSync(d.path, 'utf8'), look));
322
+ console.log(`applied — ${phrase}`);
323
+ } else console.log(`kept the deck's look — decklight design-system apply ${deckRef} ${deck} applies it later`);
324
+ } else if (decide === null) {
325
+ console.log(`${look.title} was drawn for ${phrase} — add --apply to switch, or: decklight design-system apply ${deckRef} ${deck}`);
326
+ }
327
+ }
328
+ // a recommendation that could not come is a warning, never a failure: the templates work without it
329
+ return 0;
330
+ } catch (e) {
331
+ if (e instanceof MarketplaceError) { console.error(`decklight design-system ${cmd}: ${e.message}`); return 1; }
332
+ throw e;
333
+ }
334
+ }
335
+
336
+ async function listMain(args) {
337
+ const [deck] = args.filter((a) => !a.startsWith('-'));
338
+ const { marketplaceDesignSystems, designSystemRefs, resolveDesignSystemRef, deckDesignSystemVersions } = await import('./design-system-refs.mjs');
339
+ const { semverCompare } = await import('./marketplace.mjs');
340
+ const { majorOf } = await import('../tools/design-system-migrations.mjs');
341
+ const { markedSources } = await import('./theme-refs.mjs');
342
+ if (deck) {
343
+ const d = readDeckArg('list', deck);
344
+ if (!d) return 1;
345
+ const refs = designSystemRefs(d.html);
346
+ if (!refs.length) { console.log(`${deck} uses no design system — decklight design-system add <name@marketplace> ${deck}`); return 0; }
347
+ const sources = markedSources(d.html);
348
+ // the version the DECK took, against the catalog's — never this machine's
349
+ // ledger, which knows nothing of a deck written elsewhere (SPEC DESIGN_SYSTEM_MIGRATIONS)
350
+ const took = deckDesignSystemVersions(d.html);
351
+ for (const ref of refs) {
352
+ const r = resolveDesignSystemRef(ref, undefined, { source: sources[ref.marketplace] ?? null });
353
+ const had = took[ref.ref] ?? null;
354
+ const now = r.entry?.version ?? null;
355
+ const newer = had && now && semverCompare(now, had) > 0;
356
+ const major = newer && majorOf(had) !== null && majorOf(had) < majorOf(now);
357
+ const ver = newer ? ` ${had} → ${now}${major ? ' (major: migrate)' : ''}` : had ? ` ${had}` : now ? ` ${now} (the deck records no version)` : '';
358
+ console.log(`${ref.ref}${ver}${r.missing ? ` — missing: ${r.missing}` : r.title ? ` — ${r.title}` : ''}`);
359
+ }
360
+ return 0;
361
+ }
362
+ const { systems, stale, unfetched } = marketplaceDesignSystems();
363
+ if (!systems.length) console.log('no registered marketplace offers a design system');
364
+ for (const s of systems) {
365
+ console.log(`${s.qualified}${s.version ? ` ${s.version}` : ''}${s.description ? ` — ${s.description}` : ''}${s.missing ? ` (${s.missing})` : ''}`);
366
+ }
367
+ for (const m of unfetched) console.log(` ${m} has not been fetched yet — decklight marketplace update ${m}`);
368
+ for (const m of stale) console.log(` ${m}'s cached catalog could not be read — decklight marketplace update ${m}`);
369
+ return 0;
370
+ }
371
+
372
+ async function templatesMain(args) {
373
+ const [ref] = args.filter((a) => !a.startsWith('-'));
374
+ if (!ref) { console.error(`decklight design-system templates: needs a design system (name@marketplace)\n\n${USAGE}`); return 1; }
375
+ const { resolveEntry, MarketplaceError } = await import('./marketplace.mjs');
376
+ const { resolveDesignSystemRef, packageVerdict } = await import('./design-system-refs.mjs');
377
+ let qualified = ref;
378
+ try { qualified = resolveEntry(ref, await catalogs()).qualified; } catch (e) { if (!(e instanceof MarketplaceError)) throw e; console.error(`decklight design-system templates: ${e.message}`); return 1; }
379
+ const r = resolveDesignSystemRef(qualified);
380
+ if (!r.dir) { console.error(`decklight design-system templates: ${r.ref} — ${r.missing}`); return 1; }
381
+ const v = packageVerdict(r.dir);
382
+ if (!v.ok) { console.error(`decklight design-system templates: ${r.ref} — ${v.why}`); return 1; }
383
+ console.log(`${r.ref} — ${v.manifest.title} ${v.manifest.version}: ${v.summary.templates.length} template${v.summary.templates.length === 1 ? '' : 's'}`);
384
+ for (const l of v.summary.templates) {
385
+ console.log(` ${v.manifest.name}/${l.id}${l.title && l.title !== l.id ? ` — ${l.title}` : ''}`);
386
+ for (const slot of l.slots) {
387
+ console.log(` ${slot.name}${slot.required ? ' (required)' : ''}${slot.default ? ' (takes unslotted content)' : ''}${slot.hint ? ` — ${slot.hint}` : ''}`);
388
+ }
389
+ }
390
+ console.log(`\n a slide: <section data-template="${v.manifest.name}/<template>"> with children carrying data-slot="<slot>"`);
391
+ return 0;
392
+ }
393
+
394
+ /**
395
+ * `design-system apply`: the look a design system the deck already uses was
396
+ * drawn for — its recommended theme and font, bringing any that are missing,
397
+ * in one edit. Idempotent: a deck already wearing it is left as it is.
398
+ */
399
+ async function applyMain(args) {
400
+ const [ref, deck] = args.filter((a) => !a.startsWith('-'));
401
+ if (!ref) { console.error(`decklight design-system apply: needs a design system and a deck\n\n${USAGE}`); return 1; }
402
+ const d = readDeckArg('apply', deck);
403
+ if (!d) return 1;
404
+ const { designSystemRefs, resolveDesignSystemRef, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
405
+ const { markedSources } = await import('./theme-refs.mjs');
406
+ const { writeFileAtomic } = await import('../tools/atomic-write.mjs');
407
+ const { recordInstall } = await import('./marketplace.mjs');
408
+ const hit = designSystemRefs(d.html).find((r) => r.ref === ref || r.name === ref);
409
+ if (!hit) { console.error(`decklight design-system apply: ${deck} does not use ${ref} — decklight design-system add ${ref} ${deck}`); return 1; }
410
+ const r = resolveDesignSystemRef(hit, undefined, { source: markedSources(d.html)[hit.marketplace] ?? null });
411
+ if (!r.dir) { console.error(`decklight design-system apply: ${hit.ref} — ${r.missing}`); return 1; }
412
+ const verdict = checkDir(r.dir);
413
+ if (!verdict.ok) { console.error(`decklight design-system apply: ${hit.ref} no longer passes its check — decklight design-system gate ${r.dir}`); return 1; }
414
+ const deps = await import('./design-system-deps.mjs');
415
+ const plan = deps.planRecommended(d.html, { manifest: verdict.manifest, local: r.local });
416
+ let html = deps.writePlan(recordVersionIfCurrent(d.html, hit.ref, verdict.manifest, dirname(d.path)), plan);
417
+ const look = deps.lookOf(html, plan);
418
+ // recorded even when the deck is left as it is: one already there may be
419
+ // one the catalog has a newer version of, and the ledger is where that goes
420
+ for (const inst of deps.plannedInstalls(plan)) recordInstall(inst);
421
+ // "already there" is noise here, unless it just recorded a newer version
422
+ const lines = deps.planLines({ ...plan, items: plan.items.filter((it) => it.status !== 'already' || it.recorded) });
423
+ if (!look.theme && !look.font) { console.log(`${hit.ref} recommends no theme or font this deck can apply`); return 0; }
424
+ if (!look.differs && html === d.html) {
425
+ for (const line of lines) console.log(line);
426
+ console.log(`${deck} already wears ${look.title}'s look`);
427
+ return 0;
428
+ }
429
+ html = deps.applyLook(html, look);
430
+ writeFileAtomic(d.path, html);
431
+ for (const line of lines) console.log(line);
432
+ console.log(look.differs ? `applied ${look.title}'s look — ${deps.lookPhrase(look, plan)}` : `${deck} already wore ${look.title}'s look`);
433
+ return 0;
434
+ }
435
+
436
+ /**
437
+ * `design-system migrate` (SPEC DESIGN_SYSTEM_MIGRATIONS): the renames the
438
+ * package declares since the version the deck records, applied as whole
439
+ * names to the deck and to the stylesheets it links beside it, and the
440
+ * recorded version moved to the one this machine serves. Every file is
441
+ * renamed in memory before any is written. What a rename cannot decide — a
442
+ * name removed with no successor — is the migration's skill's, and said.
443
+ */
444
+ async function migrateMain(args) {
445
+ const [ref, deck] = args.filter((a) => !a.startsWith('-'));
446
+ if (!ref) { console.error(`decklight design-system migrate: needs a design system and a deck\n\n${USAGE}`); return 1; }
447
+ const d = readDeckArg('migrate', deck);
448
+ if (!d) return 1;
449
+ const { planMigration, migrationLines } = await import('./design-system-refs.mjs');
450
+ const { writeFileAtomic } = await import('../tools/atomic-write.mjs');
451
+ const plan = planMigration(d.html, dirname(d.path), ref);
452
+ if (plan.error) { console.error(`decklight design-system migrate: ${plan.error.replace(/^the deck/, deck)}`); return 1; }
453
+ if (!plan.changed) { console.log(`${deck} is already on ${plan.ref} ${plan.version} — nothing to migrate`); return 0; }
454
+ for (const x of plan.sheets) writeFileAtomic(x.path, x.text);
455
+ if (plan.html !== d.html) writeFileAtomic(d.path, plan.html);
456
+ const { placedSkill, placeSkill, skillPlaces, skillPlaceAnswer, skillPlaceQuestion } = await import('./skills.mjs');
457
+ const placed = (s) => placedSkill(s);
458
+ for (const line of migrationLines(plan, deck, { placed })) console.log(line);
459
+ // On a terminal, a skill the agent does not have yet is offered, every
460
+ // project first. An agent running this (the edit server's Migrate) has no
461
+ // TTY, and its server asked the author before it started (#893).
462
+ const missing = plan.status.skills.filter((s) => !placed(s));
463
+ if (missing.length && process.stdin.isTTY && process.stdout.isTTY) {
464
+ const { createInterface } = await import('node:readline/promises');
465
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
466
+ try {
467
+ for (const s of missing) {
468
+ const where = skillPlaceAnswer(await rl.question(skillPlaceQuestion(s, skillPlaces(s))));
469
+ if (!where) continue;
470
+ try {
471
+ const { lines } = await placeSkill(s, { global: where === 'global', ref: plan.marketplace ? `${s}@${plan.marketplace}` : s });
472
+ for (const line of lines) console.log(` ${line}`);
473
+ } catch (e) { console.error(` could not install ${s}: ${e.message}`); }
474
+ }
475
+ } finally { rl.close(); }
476
+ }
477
+ return 0;
478
+ }
479
+
480
+ export async function designSystemMain(args = []) {
481
+ const sub = args[0];
482
+ if (!sub || sub === '--help' || sub === '-h' || sub === 'help') { console.log(USAGE); return sub ? 0 : 1; }
483
+ const rest = args.slice(1);
484
+ if (rest.includes('--help') || rest.includes('-h')) { console.log(USAGE); return 0; }
485
+ argReader(rest);
486
+ if (sub === 'gate' || sub === 'check') return checkMain(rest); // `check` still answers, unadvertised: a catalog's CI may run it
487
+ if (sub === 'add') return addMain(rest, true);
488
+ if (sub === 'remove') return addMain(rest, false);
489
+ if (sub === 'list') return listMain(rest);
490
+ if (sub === 'templates') return templatesMain(rest);
491
+ if (sub === 'apply') return applyMain(rest);
492
+ if (sub === 'migrate') return migrateMain(rest);
493
+ console.error(`decklight design-system: unknown subcommand "${sub}" — add, remove, apply, migrate, list, templates, check\n\n${USAGE}`);
494
+ return 1;
495
+ }
496
+
497
+ if (isMain(import.meta.url)) process.exit(await designSystemMain(process.argv.slice(2)));
package/cli/doctor.mjs ADDED
@@ -0,0 +1,115 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * decklight doctor — what this machine can do, and how to make it do the rest.
6
+ *
7
+ * Every optional capability used to announce itself only by failing: you
8
+ * learned Chrome was missing when `pdf` said so, node-pty when `cast` refused,
9
+ * ffmpeg after `video` had rendered every frame. This asks all of it up front,
10
+ * and for each thing missing says two things the refusals never did together —
11
+ * which commands it unlocks, and the one line that installs it.
12
+ *
13
+ * It is an inventory, like the ingredients label: no score, no verdict, exit 0.
14
+ * A machine with none of the optional pieces is a perfectly good machine for
15
+ * writing and presenting a deck, and the output should read that way.
16
+ */
17
+
18
+ import { findChrome } from '../tools/chrome.mjs';
19
+ import { detectAgents, whichBin } from './agents.mjs';
20
+ import { resolves } from './report-bug.mjs';
21
+ import { loadLipsyncConfig, videoSetup, SETUP_HINT } from '../tools/lipsync-config.mjs';
22
+
23
+ /** The package manager's install line for `name`, per platform. */
24
+ export function installLine(name, platform = process.platform) {
25
+ if (platform === 'darwin') return `brew install ${name}`;
26
+ if (platform === 'win32') return `winget install ${name}`;
27
+ return `sudo apt install ${name}`;
28
+ }
29
+
30
+ /**
31
+ * The rows, pure over what was found. Every input is injectable so the table
32
+ * for a machine with nothing on it can be checked from a machine with
33
+ * everything, and the other way round.
34
+ */
35
+ export function diagnose({
36
+ platform = process.platform,
37
+ which = (bin) => whichBin(bin),
38
+ has = resolves,
39
+ chrome = findChrome(),
40
+ agents = detectAgents().map((a) => a.label),
41
+ lipsync = loadLipsyncConfig(),
42
+ videoCheck = (cfg) => videoSetup(cfg),
43
+ } = {}) {
44
+ const bin = (name) => which(name);
45
+ const rows = [];
46
+ const row = (label, found, unlocks, fix) => rows.push({ label, ok: !!found, found: found || null, unlocks, fix });
47
+
48
+ row('Chrome', chrome, 'pdf · pptx · video · screenshots · the headless render checks',
49
+ 'install Google Chrome or Chromium, or point $CHROME at one');
50
+ const ffmpeg = bin('ffmpeg'), ffprobe = bin('ffprobe');
51
+ row('ffmpeg', ffmpeg && ffprobe ? ffmpeg : null, 'video (a narrated mp4 of the deck)',
52
+ installLine('ffmpeg', platform));
53
+ row('git', bin('git'), 'snapshots and commits in write mode · history · restore · publish · review submit',
54
+ installLine('git', platform));
55
+ row('gh', bin('gh'), "init's GitHub remote offer · review submit --pr",
56
+ installLine('gh', platform));
57
+ row('node-pty + js-yaml', has('node-pty') && has('js-yaml') ? 'installed' : null,
58
+ 'cast · refresh (recording a terminal in a real PTY)',
59
+ 'npm install -g decklight --include=optional (node-pty builds a native module: needs a C toolchain)');
60
+ row('sigstore', has('sigstore') ? 'installed' : null, 'bundle --sign · publish (signed by default)',
61
+ 'npm install -g decklight --include=optional');
62
+ row('an AI agent', agents.length ? agents.join(', ') : null,
63
+ 'A in write mode (ask an agent to edit the deck) · agent-written commit subjects',
64
+ 'install one: claude (npm i -g @anthropic-ai/claude-code), codex, gemini, copilot, aider …');
65
+ const local = platform === 'darwin' ? 'say (built in)' : platform === 'win32' ? 'Windows speech (built in)' : null;
66
+ row('a local voice', local ?? (bin('piper') ? 'piper' : null), 'narration with no account and no network',
67
+ 'uv tool install piper-tts (or a cloud engine: decklight setup voice)');
68
+ row('rhubarb', bin('rhubarb'), 'lipsync (mouth shapes for the talking-head character)',
69
+ 'https://github.com/DanielSWolf/rhubarb-lip-sync/releases — put the binary on PATH');
70
+ // Neural video is not a binary on PATH but a checkout, its checkpoint, the
71
+ // Python that has its packages, and a portrait — what `lipsync --save`
72
+ // remembers (tools/lipsync-config.mjs). Read the same way the bridge reads it.
73
+ const video = lipsync && (lipsync.wav2lipDir || lipsync.sadtalkerDir) ? videoCheck(lipsync) : null;
74
+ row('neural video', video?.engines.length ? `${video.engines.join(', ')} · ${(lipsync.portraits ?? []).length} portrait(s)` : null,
75
+ 'the talking-head character with your own face (Wav2Lip or SadTalker, offline)',
76
+ video ? video.problems.join(' · ') || 'set up, but not ready' : `clone Wav2Lip, then: ${SETUP_HINT}`);
77
+ return rows;
78
+ }
79
+
80
+ /** The table, as lines. Marks are text, so a log and a terminal read the same. */
81
+ export function formatDoctor(rows, { color = false } = {}) {
82
+ const GREEN = '\x1b[32m', DIM = '\x1b[2m', RESET = '\x1b[0m';
83
+ const paint = (s, c) => (color ? `${c}${s}${RESET}` : s);
84
+ const width = Math.max(...rows.map((r) => r.label.length)) + 2;
85
+ const lines = ['decklight doctor — what this machine can do', ''];
86
+ for (const r of rows) {
87
+ const mark = r.ok ? paint('ok', GREEN) : paint('--', DIM);
88
+ lines.push(` ${mark} ${r.label.padEnd(width)}${r.ok ? r.found : 'not found'}`);
89
+ lines.push(` ${paint(r.unlocks, DIM)}`);
90
+ if (!r.ok) lines.push(` ${paint('→ ' + r.fix, DIM)}`);
91
+ }
92
+ const missing = rows.filter((r) => !r.ok).length;
93
+ lines.push('');
94
+ lines.push(missing
95
+ ? `${rows.length - missing} of ${rows.length} present. Writing and presenting a deck needs none of the missing ones.`
96
+ : `everything present — every command has what it needs`);
97
+ return lines;
98
+ }
99
+
100
+ const HELP = `decklight doctor — what this machine can do
101
+
102
+ Usage:
103
+ decklight doctor
104
+
105
+ Checks for Chrome, ffmpeg, git, gh, the optional npm dependencies, a coding
106
+ agent, a local voice and rhubarb, and for each one missing says which commands
107
+ it unlocks and the line that installs it. Reads PATH and the filesystem only:
108
+ no network, nothing written, exit 0 either way.`;
109
+
110
+ export async function doctorMain(argv = process.argv.slice(2)) {
111
+ if (argv.includes('--help') || argv.includes('-h')) { console.log(HELP); return 0; }
112
+ const color = !!process.stdout.isTTY && !process.env.NO_COLOR;
113
+ for (const line of formatDoctor(diagnose(), { color })) console.log(line);
114
+ return 0;
115
+ }