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
package/cli/theme.mjs CHANGED
@@ -2,106 +2,67 @@
2
2
  // Copyright 2026 Gilles Philippart
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
- // decklight theme — install and validate themes that came from somewhere else.
5
+ // decklight theme — validate themes that came from somewhere else, and mark
6
+ // which of them a deck travels with.
6
7
  //
7
- // decklight theme check <file|url>
8
- // decklight theme add <file|url> <deck.html> [--name x] [--dry-run]
8
+ // decklight theme gate <file|url>
9
+ // decklight theme add <name@marketplace|file|url> <deck.html> [--name x] [--dry-run]
10
+ // decklight theme remove <name|name@marketplace> <deck.html>
9
11
  //
10
- // The distribution mechanism already half-existed: a theme is ONE portable CSS
11
- // file, `⌃⇧T` already downloads a shareable one, `decklight bundle` already
12
- // embeds whatever the deck carries. What was missing is the last mile in both
13
- // directions — a way to prove a file satisfies the contract before sharing it,
14
- // and a way to put someone else's file into a deck without hand-editing HTML.
12
+ // A theme is ONE portable CSS file, and compatibility with a runtime IS
13
+ // passing that runtime's check: there is no registry of themes and no version
14
+ // number. When the contract grows a token, `check` names exactly what an older
15
+ // theme is missing.
15
16
  //
16
- // There is no registry and no version number. The distribution unit is the
17
- // file — a repo, a gist, a download — and compatibility with a runtime IS
18
- // passing that runtime's check. When the contract grows a token, `check` names
19
- // exactly what an older theme is missing.
17
+ // `add` never puts CSS in the deck (SPEC THEME_DISTRIBUTION). It MARKS a theme:
18
+ // the deck's configuration block gains a reference, `"markedThemes":
19
+ // ["acme@acme-themes"]`, the servers link it from the marketplace on this
20
+ // machine, and `bundle` inlines it at hand-over. A file or a URL has no
21
+ // marketplace to be referenced in, so it is copied into the personal one —
22
+ // `~/.decklight/local/` — and referenced there: `house@local`.
20
23
 
21
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
22
- import { escapeHtml } from '../tools/escape.mjs';
24
+ import { existsSync, readFileSync } from 'node:fs';
25
+ import { writeFileAtomic } from '../tools/atomic-write.mjs';
23
26
  import path, { resolve } from 'node:path';
24
27
  import { argReader, isMain } from '../tools/args.mjs';
25
28
  import { validateTheme, themeNameFrom, validThemeName, REQUIRED } from '../tools/theme-check.mjs';
26
- import { checkoutPath, classifySource, configHome, MarketplaceError, loadRegistry, loadCatalog, resolveEntry} from './marketplace.mjs';
29
+ import { checkoutPath, classifySource, configHome, MarketplaceError, loadRegistry, loadCatalog, resolveEntry, recordInstall } from './marketplace.mjs';
30
+ import { setMarked, addToLocalMarketplace, resolveThemeRef, cacheThemeCss, markedEntries, parseRef, parseShipped, refForDeck } from './theme-refs.mjs';
27
31
 
28
- const USAGE = `usage: decklight theme <check|add> …
32
+ const USAGE = `usage: decklight theme <add|remove|list|gate> …
29
33
 
30
- decklight theme check <file|url>
34
+ The same grammar as font and design-system: add, remove and list what a deck
35
+ references, and gate, the admission check a catalog's CI runs.
36
+
37
+ decklight theme list [<deck.html>]
38
+ with a deck: the themes it marks, shipped and from a marketplace, and the
39
+ one it opens on; without: the themes every registered marketplace offers
40
+ EXAMPLE: decklight theme list talk.html
41
+
42
+ decklight theme gate <file|url>
31
43
  run the SPEC THEMING token contract and the WCAG contrast gates on a theme file
32
- EXAMPLE: decklight theme check nord-deep.css
44
+ EXAMPLE: decklight theme gate nord-deep.css
33
45
 
34
- decklight theme add <file|url> <deck.html> [--name <name>] [--dry-run]
35
- validate a theme, then install it into the deck — it then behaves like a
36
- shipped one: in the picker under "Added", reachable by , / . and ?theme=,
37
- and carried by decklight bundle
46
+ decklight theme add <name|name@marketplace|file|url> <deck.html> [--name <name>] [--dry-run]
47
+ validate a theme, then MARK it for the deck: its configuration block gains
48
+ a reference ("markedThemes"), never the CSS. A marked theme is listed by T
49
+ under its marketplace, reachable by , / . and ?theme=, and inlined by
50
+ decklight bundle. A file or url is first copied into your personal
51
+ marketplace (~/.decklight/local) and marked as <name>@local. A theme
52
+ decklight ships is marked by its name, to include it in the bundle
53
+ EXAMPLE: decklight theme add ember talk.html
54
+ EXAMPLE: decklight theme add nord-deep@acme-themes talk.html
38
55
  EXAMPLE: decklight theme add https://gist.../nord-deep.css talk.html
39
56
 
40
- --name <name> install under this name [the file's, minus .css]
57
+ --name <name> a file or url's name in the personal marketplace [its file name]
41
58
  --dry-run validate and report; touch nothing
42
59
 
43
- a theme that does not pass is not installed — a deck cannot be made to carry
44
- something the shipped set would not be allowed to contain`;
45
-
46
- /**
47
- * The <style> block an installed theme becomes, marked so the runtime groups it.
48
- *
49
- * PROVENANCE TRAVELS WITH THE DECK, and it has to: a bundled deck opened on
50
- * another machine has no `~/.decklight/marketplaces.json` to look a catalog up
51
- * in, and the theme picker still has to draw a heading. So whatever the picker
52
- * shows is written here, at install time, or it is not available at all.
53
- *
54
- * Two attributes, because identity and label are different things.
55
- * `data-theme-marketplace` is the manifest's own kebab `name` — stable, and
56
- * what a later dedup or upgrade would key on. `data-theme-source` is the
57
- * catalog's human title, written only when it supplied one, and never derived
58
- * from the name: stripping a prefix off `decklight-confluent` to guess
59
- * "Confluent" breaks the moment a catalog is called `acme-themes`, and it puts
60
- * decklight in the business of inventing names for other people's catalogs.
61
- *
62
- * `data-theme-added` stays on every installed block. Old decks keep working,
63
- * and it remains what the runtime falls back to — the "never decklight's to
64
- * begin with" distinction it was added for is untouched.
65
- */
66
- export function themeStyleBlock(name, css, { marketplace = null, title = null } = {}) {
67
- // </style> inside a theme's own comment would end the block early. Themes
68
- // are CSS and have no business containing one, but a downloaded file is
69
- // somebody else's, and "somebody else's" is exactly when to check.
70
- const safe = css.replace(/<\/(style)/gi, '<\\/$1');
71
- // Both values come out of a manifest somebody else wrote, and they land in a
72
- // double-quoted attribute — so they are escaped, not trusted. A title of
73
- // `"><script>` is the whole reason this is not a template hole.
74
- const from = marketplace ? ` data-theme-marketplace="${escapeHtml(marketplace)}"` : '';
75
- const label = title ? ` data-theme-source="${escapeHtml(title)}"` : '';
76
- return `<style data-theme="${escapeHtml(name)}" data-theme-added${from}${label} media="not all">\n${safe.trim()}\n</style>`;
77
- }
78
-
79
- /** Where an existing block for this name starts and ends, or null. */
80
- export function findThemeBlock(html, name) {
81
- const re = new RegExp(`<style[^>]*\\bdata-theme=["']${name}["'][^>]*>[\\s\\S]*?<\\/style>`, 'i');
82
- const m = re.exec(html);
83
- return m ? { start: m.index, end: m.index + m[0].length, text: m[0] } : null;
84
- }
60
+ decklight theme remove <name|name@marketplace> <deck.html>
61
+ unmark it — the deck stops listing and carrying it; the theme itself stays
62
+ in its marketplace
85
63
 
86
- /**
87
- * Put the block in the deck: replacing the theme's previous block if it has
88
- * one (re-adding IS the update path — there is no auto-update), otherwise
89
- * last in <head> so an active added theme wins the cascade over the deck's
90
- * link or inline base theme.
91
- */
92
- export function installTheme(html, name, css, provenance = {}) {
93
- const block = themeStyleBlock(name, css, provenance);
94
- const existing = findThemeBlock(html, name);
95
- if (existing) {
96
- return { html: html.slice(0, existing.start) + block + html.slice(existing.end), replaced: true };
97
- }
98
- const head = /<\/head>/i.exec(html);
99
- if (!head) return { html: null, replaced: false };
100
- return {
101
- html: html.slice(0, head.index) + block + '\n' + html.slice(head.index),
102
- replaced: false,
103
- };
104
- }
64
+ a theme that does not pass is not marked — a deck cannot be made to carry
65
+ something the shipped set would not be allowed to contain`;
105
66
 
106
67
  /**
107
68
  * Where a catalog entry's `source` actually lives.
@@ -124,7 +85,7 @@ export function installTheme(html, name, css, provenance = {}) {
124
85
  * An ABSOLUTE `https://` source is still fetched as written: an entry may
125
86
  * legitimately point at a gist or a release asset outside its own repo.
126
87
  *
127
- * This lives in theme.mjs rather than in the author server on purpose. Reading
88
+ * This lives in theme.mjs rather than in the edit server on purpose. Reading
128
89
  * an ARTIFACT on an explicit install is fine anywhere; fetching a CATALOG is
129
90
  * what `registered, not fetched` forbids on a deck-serving path, and keeping the
130
91
  * two in different files is what keeps the sweep in test/marketplace.test.mjs
@@ -182,9 +143,9 @@ export function reportLines(name, result) {
182
143
 
183
144
  async function checkMain(args) {
184
145
  const [source] = args.filter((a) => !a.startsWith('-'));
185
- if (!source) { console.error(`decklight theme check: needs a theme file or url\n\n${USAGE}`); return 1; }
146
+ if (!source) { console.error(`decklight theme gate: needs a theme file or url\n\n${USAGE}`); return 1; }
186
147
  let css;
187
- try { css = await fetchTheme(source); } catch (e) { console.error(`decklight theme check: ${e.message}`); return 1; }
148
+ try { css = await fetchTheme(source); } catch (e) { console.error(`decklight theme gate: ${e.message}`); return 1; }
188
149
  const name = themeNameFrom(source) || 'theme';
189
150
  const result = validateTheme(css);
190
151
  for (const line of reportLines(name, result)) console.log(line);
@@ -199,15 +160,28 @@ async function addMain(args) {
199
160
 
200
161
  const deckPath = resolve(deck);
201
162
  if (!existsSync(deckPath)) { console.error(`decklight theme add: no such deck: ${deck}`); return 1; }
163
+ const home = configHome();
164
+ const fail = (msg) => { console.error(`decklight theme add: ${msg}`); return 1; };
165
+
166
+ // A theme decklight ships is marked by name: nothing to fetch or check, and
167
+ // it is what makes a bundle carry it beside the one the deck opens on.
168
+ if (parseShipped(source) && !existsSync(resolve(source))) {
169
+ const html = readFileSync(deckPath, 'utf8');
170
+ let next;
171
+ try { next = setMarked(html, source, true); }
172
+ catch (e) { if (e instanceof MarketplaceError) return fail(e.message); throw e; }
173
+ if (args.includes('--dry-run')) { console.log(`would ${next.changed ? 'mark' : 'keep'} ${source} in ${deck}`); return 0; }
174
+ if (next.changed) writeFileAtomic(deckPath, next.html);
175
+ console.log(next.changed ? `marked ${source} in ${deck} — it will be part of the bundle` : `${source} is already marked in ${deck}`);
176
+ return 0;
177
+ }
202
178
 
203
- // A marketplace ref (`confluent@decklight-confluent`, or a bare entry name)
204
- // resolves through the registry; a file or a URL is taken as it was typed.
205
- // Without this the CLI could not install from a catalog at all — Browse was
206
- // the only door — and provenance would only ever reach half the decks.
207
- let src = source;
208
- let provenance = {};
209
- let entryName = null;
210
- if (!/^https?:\/\//i.test(source) && !existsSync(resolve(source))) {
179
+ // A marketplace ref (`confluent@decklight-confluent`, or a bare entry name
180
+ // one marketplace alone has) is marked where it is; a file or a URL has no
181
+ // marketplace to be referenced in, so it is copied into the personal one.
182
+ const isFile = /^https?:\/\//i.test(source) || existsSync(resolve(source));
183
+ let name, css, ref, label, remote = null, origin = null, taken = null;
184
+ if (!isFile) {
211
185
  const reg = loadRegistry();
212
186
  const catalogs = {};
213
187
  for (const mkt of Object.keys(reg.marketplaces ?? {})) {
@@ -215,60 +189,128 @@ async function addMain(args) {
215
189
  if (c?.ok) catalogs[mkt] = c.manifest;
216
190
  }
217
191
  let hit;
218
- try { hit = resolveEntry(source, catalogs); }
219
- catch (e) {
220
- console.error(`decklight theme add: ${e.message}`);
221
- return 1;
222
- }
223
- if (hit.entry.type !== 'theme') {
224
- console.error(`decklight theme add: ${hit.qualified} is a ${hit.entry.type}, not a theme`);
225
- return 1;
226
- }
227
- try {
228
- src = resolveSource(hit.entry.source, {
229
- name: hit.marketplace, source: reg.marketplaces[hit.marketplace]?.source,
230
- });
231
- } catch (e) {
232
- console.error(`decklight theme add: ${e.message}`);
192
+ try { hit = resolveEntry(source, catalogs); } catch (e) { return fail(e.message); }
193
+ if (hit.entry.type !== 'theme') return fail(`${hit.qualified} is a ${hit.entry.type}, not a theme`);
194
+ if (opt('--name')) return fail('--name names a file or url; a marketplace theme is marked under its own name');
195
+ const r = resolveThemeRef(hit.qualified, home);
196
+ if (r.file) css = readFileSync(r.file, 'utf8');
197
+ else if (r.remote) {
198
+ // An entry whose bytes live at a URL outside its repo: read once, now,
199
+ // on this explicit act, and kept — every server after this links the
200
+ // kept copy and never the URL.
201
+ try { css = await fetchTheme(r.remote); } catch (e) { return fail(e.message); }
202
+ remote = r;
203
+ } else return fail(r.missing);
204
+ name = hit.entry.name;
205
+ ref = hit.qualified;
206
+ origin = r.source ?? null;
207
+ label = catalogs[hit.marketplace]?.title?.trim() || hit.marketplace;
208
+ taken = { type: 'theme', name: hit.entry.name, marketplace: hit.marketplace, version: hit.entry.version, commit: reg.marketplaces[hit.marketplace]?.commit };
209
+ } else {
210
+ name = opt('--name') ?? themeNameFrom(source);
211
+ if (!validThemeName(name)) {
212
+ console.error(`decklight theme add: "${name}" is not a usable theme name`);
213
+ console.error(' the runtime only resolves names matching [A-Za-z0-9_-]+ — pass --name to choose one');
233
214
  return 1;
234
215
  }
235
- // The catalog's own title, captured HERE because the deck may be opened on
236
- // a machine where this marketplace was never registered.
237
- provenance = { marketplace: hit.marketplace, title: catalogs[hit.marketplace]?.title?.trim() || null };
238
- entryName = hit.entry.name;
216
+ try { css = await fetchTheme(source); } catch (e) { return fail(e.message); }
217
+ ref = `${name}@local`;
218
+ label = 'Local';
239
219
  }
240
220
 
241
- // The name is settled AFTER resolution: `confluent@decklight-confluent` is a
242
- // reference, not a filename, and deriving a theme name from it would refuse
243
- // every marketplace install for containing an `@`.
244
- const name = opt('--name') ?? entryName ?? themeNameFrom(source);
245
- if (!validThemeName(name)) {
246
- console.error(`decklight theme add: "${name}" is not a usable theme name`);
247
- console.error(' the runtime only resolves names matching [A-Za-z0-9_-]+ — pass --name to choose one');
248
- return 1;
249
- }
250
-
251
- let css;
252
- try { css = await fetchTheme(src); } catch (e) { console.error(`decklight theme add: ${e.message}`); return 1; }
253
-
254
221
  const result = validateTheme(css);
255
222
  for (const line of reportLines(name, result)) console.log(line);
256
223
  if (!result.ok) {
257
- console.error(`\ndecklight theme add: ${name} was NOT installed — fix the report above and try again`);
224
+ console.error(`\ndecklight theme add: ${name} was NOT marked — fix the report above and try again`);
258
225
  return 1;
259
226
  }
260
227
 
228
+ // Settled BEFORE anything is written: a name that clashes must not leave a
229
+ // copy in the personal marketplace behind a refusal.
261
230
  const html = readFileSync(deckPath, 'utf8');
262
- const { html: next, replaced } = installTheme(html, name, css, provenance);
263
- if (next === null) { console.error(`decklight theme add: ${deck} has no </head> to install into`); return 1; }
264
-
231
+ if (!isFile) ref = refForDeck(html, name, ref.split("@")[1], origin);
232
+ let next;
233
+ try { next = setMarked(html, ref, true, { source: origin }); }
234
+ catch (e) {
235
+ if (!(e instanceof MarketplaceError)) throw e;
236
+ return fail(e.message + (isFile ? ' — pass --name to choose another' : ''));
237
+ }
265
238
  if (args.includes('--dry-run')) {
266
- console.log(`would ${replaced ? 'replace' : 'install'} ${name} in ${deck} (${(css.length / 1024).toFixed(1)} KB)`);
239
+ console.log(`would ${isFile ? `copy ${source} into your personal marketplace and ` : ''}`
240
+ + `${next.changed ? 'mark' : 'keep'} ${ref} in ${deck}`);
241
+ return 0;
242
+ }
243
+ if (isFile) {
244
+ let out;
245
+ try { out = addToLocalMarketplace(css, name, source, home); }
246
+ catch (e) { if (e instanceof MarketplaceError) return fail(e.message); throw e; }
247
+ if (out.registered) console.log(`registered your personal marketplace "local" — ${out.file.replace(/[\\/]themes[\\/][^\\/]+$/, '')}`);
248
+ console.log(`${out.replaced ? 'replaced' : 'copied'} ${name} → ${out.file}`);
249
+ } else if (remote) {
250
+ cacheThemeCss(home, remote.marketplace, name, css);
251
+ }
252
+ if (next.changed) writeFileAtomic(deckPath, next.html);
253
+ // The version this add took, whether or not the mark was new: re-running
254
+ // `theme add` after a catalog update is how a newer theme is taken (#616).
255
+ // The deck holds a mark, never a version — it is not rewritten for one.
256
+ if (taken) recordInstall(taken, home);
257
+ const v = taken?.version ? ` ${taken.version}` : '';
258
+ console.log(next.changed
259
+ ? `marked ${ref}${v} in ${deck} — press T and look under "${label}"; it will be part of the bundle`
260
+ : `${ref} is already marked in ${deck}${v ? ` — recorded${v} as the version you have` : ''}`);
261
+ return 0;
262
+ }
263
+
264
+ function removeMain(args) {
265
+ const [what, deck] = args.filter((a) => !a.startsWith('-'));
266
+ if (!what || !deck) { console.error(`decklight theme remove: needs a theme and a deck\n\n${USAGE}`); return 1; }
267
+ const deckPath = resolve(deck);
268
+ if (!existsSync(deckPath)) { console.error(`decklight theme remove: no such deck: ${deck}`); return 1; }
269
+ const html = readFileSync(deckPath, 'utf8');
270
+ const marked = markedEntries(html);
271
+ const hit = parseRef(what) ? marked.find((r) => r.ref === what) : marked.find((r) => r.name === what);
272
+ if (!hit) {
273
+ console.error(`decklight theme remove: ${what} is not marked in ${deck}`
274
+ + (marked.length ? ` — it marks ${marked.map((r) => r.ref).join(', ')}` : ' — it marks no themes'));
275
+ return 1;
276
+ }
277
+ let next;
278
+ try { next = setMarked(html, hit.ref, false); }
279
+ catch (e) {
280
+ if (!(e instanceof MarketplaceError)) throw e;
281
+ console.error(`decklight theme remove: ${e.message}`);
282
+ return 1;
283
+ }
284
+ writeFileAtomic(deckPath, next.html);
285
+ console.log(`unmarked ${hit.ref} — it will no longer be part of the bundle`);
286
+ return 0;
287
+ }
288
+
289
+ /** `theme list`, the shape of `font list` and `design-system list`. */
290
+ async function listMain(args) {
291
+ const [deck] = args.filter((a) => !a.startsWith('-'));
292
+ const { markedEntries, markedSources, resolveThemeRef, marketplaceThemes, shippedThemes } = await import('./theme-refs.mjs');
293
+ if (deck) {
294
+ let html;
295
+ try { html = readFileSync(deck, 'utf8'); } catch { console.error(`decklight theme list: no such deck: ${deck}`); return 1; }
296
+ const { configBlock } = await import('./runtime-link.mjs');
297
+ const opensOn = configBlock(html)?.config?.theme ?? 'aurora';
298
+ const entries = markedEntries(html);
299
+ console.log(`${deck} opens on ${opensOn}`);
300
+ if (!entries.length) { console.log(` it marks no theme to carry — decklight theme add <name|name@marketplace> ${deck}`); return 0; }
301
+ const sources = markedSources(html);
302
+ for (const e of entries) {
303
+ if (e.shipped) { console.log(` ${e.name} (shipped)`); continue; }
304
+ const r = resolveThemeRef(e, undefined, { source: sources[e.marketplace] ?? null });
305
+ console.log(` ${e.ref}${r.entry?.version ? ` ${r.entry.version}` : ''}${r.missing ? ` — missing: ${r.missing}` : r.title ? ` — ${r.title}` : ''}`);
306
+ }
267
307
  return 0;
268
308
  }
269
- writeFileSync(deckPath, next);
270
- console.log(`${replaced ? 'replaced' : 'installed'} ${name} in ${deck}`
271
- + ` — press T and look under "Added"${replaced ? '' : ', or open it with ?theme=' + name}`);
309
+ console.log(`shipped: ${shippedThemes().join(', ')}`);
310
+ const { themes, stale } = marketplaceThemes();
311
+ if (!themes.length) console.log('no registered marketplace offers a theme');
312
+ for (const t of themes) console.log(`${t.qualified}${t.title ? ` — ${t.title}` : ''}${t.description ? ` — ${t.description}` : ''}`);
313
+ for (const m of stale) console.log(` ${m}'s cached catalog could not be read — decklight marketplace update ${m}`);
272
314
  return 0;
273
315
  }
274
316
 
@@ -277,9 +319,11 @@ export async function themeMain(args = []) {
277
319
  if (!sub || sub === '--help' || sub === '-h' || sub === 'help') { console.log(USAGE); return sub ? 0 : 1; }
278
320
  const rest = args.slice(1);
279
321
  if (rest.includes('--help') || rest.includes('-h')) { console.log(USAGE); return 0; }
280
- if (sub === 'check') return checkMain(rest);
322
+ if (sub === 'gate' || sub === 'check') return checkMain(rest); // `check` still answers, unadvertised: a catalog's CI may run it
281
323
  if (sub === 'add') return addMain(rest);
282
- console.error(`decklight theme: unknown subcommand "${sub}"\n\n${USAGE}`);
324
+ if (sub === 'remove') return removeMain(rest);
325
+ if (sub === 'list') return listMain(rest);
326
+ console.error(`decklight theme: unknown subcommand "${sub}" — add, remove, list, gate\n\n${USAGE}`);
283
327
  return 1;
284
328
  }
285
329
 
package/cli/trust.mjs ADDED
@@ -0,0 +1,83 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Trust (SPEC PRESENTING): a deck that runs code of its own asks, once, whether
5
+ // its source is trusted. The answer is remembered against the BYTES of that
6
+ // code — every unaccounted script block and every executable attribute the
7
+ // ingredients label names, in file order — so a deck whose script changed
8
+ // asks again, and a deck whose author added nothing executable never asks.
9
+ // Nothing here decides anything: the label finds, the person answers, this
10
+ // remembers.
11
+
12
+ import { createHash } from 'node:crypto';
13
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
14
+ import { join } from 'node:path';
15
+ import { configHome } from './marketplace.mjs';
16
+
17
+ /** The bytes the question is about, hashed: the label's findings, in file order. */
18
+ export function scriptHash(html, report) {
19
+ const found = [...report.unaccounted, ...report.handlers].sort((a, b) => a.start - b.start);
20
+ const h = createHash('sha256');
21
+ for (const f of found) h.update(html.slice(f.start, f.end)).update('\n\0\n');
22
+ return h.digest('hex');
23
+ }
24
+
25
+ export const trustFile = (home = configHome()) => join(home, 'trust.json');
26
+
27
+ function readStore(home) {
28
+ try { return JSON.parse(readFileSync(trustFile(home), 'utf8')); } catch { return {}; }
29
+ }
30
+
31
+ /** Was this deck's script, as it is now, trusted before? */
32
+ export function isTrusted(deckPath, hash, home = configHome()) {
33
+ return readStore(home)[deckPath] === hash;
34
+ }
35
+
36
+ /** Remember the answer, against these bytes. A later change to the script asks again. */
37
+ export function remember(deckPath, hash, home = configHome()) {
38
+ const store = readStore(home);
39
+ store[deckPath] = hash;
40
+ if (!existsSync(home)) mkdirSync(home, { recursive: true });
41
+ writeFileSync(trustFile(home), JSON.stringify(store, null, 2) + '\n');
42
+ }
43
+
44
+ /** Take the answer back. */
45
+ export function forget(deckPath, home = configHome()) {
46
+ const store = readStore(home);
47
+ if (!(deckPath in store)) return false;
48
+ delete store[deckPath];
49
+ writeFileSync(trustFile(home), JSON.stringify(store, null, 2) + '\n');
50
+ return true;
51
+ }
52
+
53
+ const USAGE = `usage: decklight trust list
54
+ decklight trust forget <deck.html>
55
+ the decks whose script you said you trust (SPEC PRESENTING): a yes to the
56
+ question \`decklight <deck>\` asks when a deck runs code of its own, kept
57
+ against the bytes of that code in ${trustFile()}.
58
+ list every deck remembered, with the hash of the script it was said about
59
+ forget D ask again next time D is opened`;
60
+
61
+ export async function trustMain(argv = []) {
62
+ const [verb, deck] = argv.filter((a) => !a.startsWith('-'));
63
+ if (argv.includes('--help') || argv.includes('-h') || !verb) { console.log(USAGE); return 0; }
64
+ if (verb === 'list') {
65
+ const store = readStore(configHome());
66
+ const keys = Object.keys(store);
67
+ if (!keys.length) { console.log('no deck is trusted yet — decklight <deck> asks when one runs code of its own'); return 0; }
68
+ for (const k of keys) console.log(`${k} ${store[k].slice(0, 12)}`);
69
+ return 0;
70
+ }
71
+ if (verb === 'forget') {
72
+ if (!deck) { console.error('decklight trust forget: which deck?'); return 1; }
73
+ const { resolve } = await import('node:path');
74
+ const { realpathSync } = await import('node:fs');
75
+ let key = resolve(deck);
76
+ try { key = realpathSync(key); } catch { /* a deck that is gone is still forgettable by its path */ }
77
+ if (forget(key)) { console.log(`forgot ${key} — the next open asks again`); return 0; }
78
+ console.log(`${key} was not trusted`);
79
+ return 0;
80
+ }
81
+ console.error(`decklight trust: unknown verb "${verb}"\n${USAGE}`);
82
+ return 1;
83
+ }