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.
- package/PLATFORM.md +666 -0
- package/README.md +224 -150
- package/SPEC.md +732 -886
- package/cli/agent-review.mjs +245 -0
- package/cli/agents.mjs +25 -5
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +183 -0
- package/cli/bundle.mjs +383 -31
- package/cli/cast.mjs +7 -7
- package/cli/check.mjs +961 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +44 -19
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +59 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +409 -0
- package/cli/design-system.mjs +429 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +445 -0
- package/cli/edit-look.mjs +388 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2126 -842
- package/cli/enhance.mjs +483 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +65 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +400 -234
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace.mjs +215 -21
- package/cli/narrate.mjs +176 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +943 -0
- package/cli/pdf.mjs +41 -13
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +57 -24
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +14 -12
- package/cli/remote.mjs +11 -11
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +235 -44
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +190 -33
- package/cli/skills.mjs +107 -24
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +515 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +39 -42
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1126 -49
- package/dist/decklight.js +212 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +753 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +1 -1
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +196 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +461 -48
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- 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 —
|
|
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
|
|
8
|
-
// decklight theme add
|
|
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
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
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
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
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
|
|
22
|
-
import {
|
|
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 <
|
|
32
|
+
const USAGE = `usage: decklight theme <add|remove|list|gate> …
|
|
29
33
|
|
|
30
|
-
|
|
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
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
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>
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
//
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
let
|
|
208
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
|
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
|
-
|
|
263
|
-
|
|
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 ${
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
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
|
+
}
|