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.
- package/PLATFORM.md +707 -0
- package/README.md +226 -150
- package/SPEC.md +803 -888
- package/cli/agent-review.mjs +246 -0
- package/cli/agents.mjs +35 -9
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +190 -0
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +439 -35
- package/cli/cast.mjs +48 -12
- package/cli/check-fixes.mjs +186 -0
- package/cli/check.mjs +988 -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 +51 -22
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +64 -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 +666 -0
- package/cli/design-system.mjs +497 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +551 -0
- package/cli/edit-look.mjs +631 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2585 -855
- package/cli/enhance.mjs +485 -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 +78 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +407 -236
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +460 -29
- package/cli/narrate.mjs +251 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +961 -0
- package/cli/pdf.mjs +64 -17
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +63 -27
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +85 -23
- package/cli/remote.mjs +43 -17
- 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 +236 -45
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +229 -35
- package/cli/skills.mjs +353 -26
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +527 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +112 -47
- 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 +1533 -59
- package/dist/decklight.js +258 -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 +778 -0
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +11 -3
- 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 +270 -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-clip.mjs +114 -0
- 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 +530 -54
- 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/serve.mjs
CHANGED
|
@@ -5,21 +5,26 @@
|
|
|
5
5
|
// an editing endpoint: the loopback/token security classifier, static file
|
|
6
6
|
// serving with a traversal guard, SSE fan-out, and port binding with takeover.
|
|
7
7
|
//
|
|
8
|
-
// Extracted from edit.mjs
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
8
|
+
// Extracted from edit.mjs when `--no-trust` was a server of its own; now it
|
|
9
|
+
// is a mode of the one server (PRESENTING), and this is still the core both
|
|
10
|
+
// modes stand on, plus the policy the no-trust mode puts on every response
|
|
11
|
+
// and the tiny server the render tools run behind. Nothing in this module
|
|
12
|
+
// writes a file.
|
|
12
13
|
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
14
|
+
import { createServer } from 'node:http';
|
|
15
|
+
import { readFileSync, existsSync, statSync, createReadStream } from 'node:fs';
|
|
16
|
+
import { resolve, extname, sep, dirname, basename } from 'node:path';
|
|
15
17
|
import { timingSafeEqual } from 'node:crypto';
|
|
16
18
|
import { networkInterfaces } from 'node:os';
|
|
17
19
|
import { createInterface } from 'node:readline/promises';
|
|
18
20
|
import { resolvePortConflict } from './port-conflict.mjs';
|
|
21
|
+
import { packageAsset } from './pkg.mjs';
|
|
22
|
+
import { linkRuntime } from './runtime-link.mjs';
|
|
23
|
+
import { linkReferences, namespacedKind, fallbackReferenceAsset } from './deck-refs.mjs';
|
|
19
24
|
|
|
20
25
|
// ── remote access: the security seam for the phone remote (#39) ────────────
|
|
21
26
|
// --remote widens the LISTENER, never the editing surface: off-loopback,
|
|
22
|
-
// only /remote/* answers, and only with the per-run token; every /edit/*
|
|
27
|
+
// only /deck/remote/* answers, and only with the per-run token; every /deck/edit/*
|
|
23
28
|
// mutation (and the static files) refuses non-loopback callers
|
|
24
29
|
// unconditionally, flag or no flag.
|
|
25
30
|
|
|
@@ -52,8 +57,8 @@ export function isLoopbackOrigin(origin) {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* The CSRF gate for the
|
|
56
|
-
* is the user's OWN browser: while `decklight
|
|
60
|
+
* The CSRF gate for the edit server's `/deck/edit/*` surface (#222). The attacker
|
|
61
|
+
* is the user's OWN browser: while `decklight <deck>` runs, any page in any tab
|
|
57
62
|
* can `fetch()` loopback, and a permissive `access-control-allow-origin` is no
|
|
58
63
|
* defense — a "simple" `text/plain` POST is sent with NO preflight, so the
|
|
59
64
|
* agent has already run by the time the browser consults CORS on the way back.
|
|
@@ -90,8 +95,8 @@ export function allowEditRequest(req) {
|
|
|
90
95
|
* asked for. Pinning the port refuses another loopback dev server's page too,
|
|
91
96
|
* which the edit gate admits by design.
|
|
92
97
|
*
|
|
93
|
-
* Used by the one route in `
|
|
94
|
-
* `/edit/*`, where the server exists to be written to and a curl from the
|
|
98
|
+
* Used by the one route in `--no-trust` that ACTS. The looser gate is right for
|
|
99
|
+
* `/deck/edit/*`, where the server exists to be written to and a curl from the
|
|
95
100
|
* author's own machine is a feature; it is wrong here.
|
|
96
101
|
*/
|
|
97
102
|
export function isOwnOrigin(req, port) {
|
|
@@ -106,9 +111,9 @@ export function isOwnOrigin(req, port) {
|
|
|
106
111
|
|
|
107
112
|
/**
|
|
108
113
|
* Pure request classifier: may this request be answered at all?
|
|
109
|
-
* Loopback: always. Off-loopback: only /remote/* paths carrying the per-run
|
|
114
|
+
* Loopback: always. Off-loopback: only /deck/remote/* paths carrying the per-run
|
|
110
115
|
* token (?t= query or x-decklight-token header) — everything else, all
|
|
111
|
-
* /edit/* mutations included, is refused regardless of any token. `token`
|
|
116
|
+
* /deck/edit/* mutations included, is refused regardless of any token. `token`
|
|
112
117
|
* is null when --remote is off, which refuses every off-loopback request
|
|
113
118
|
* (defense in depth behind the 127.0.0.1 binding).
|
|
114
119
|
*/
|
|
@@ -117,14 +122,14 @@ export function allowRemote(req, token) {
|
|
|
117
122
|
if (!token) return false;
|
|
118
123
|
let url;
|
|
119
124
|
try { url = new URL(req.url, 'http://x'); } catch { return false; }
|
|
120
|
-
// new URL() normalizes dot segments, so /remote/../edit/notes is /edit/notes
|
|
121
|
-
if (url.pathname !== '/remote' && !url.pathname.startsWith('/remote/')) return false;
|
|
125
|
+
// new URL() normalizes dot segments, so /deck/remote/../deck/edit/slide/notes is /deck/edit/slide/notes
|
|
126
|
+
if (url.pathname !== '/deck/remote' && !url.pathname.startsWith('/deck/remote/')) return false;
|
|
122
127
|
const sent = Buffer.from(String(url.searchParams.get('t') ?? req.headers?.['x-decklight-token'] ?? ''));
|
|
123
128
|
const want = Buffer.from(token);
|
|
124
129
|
return sent.length === want.length && timingSafeEqual(sent, want);
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
/** The machine's LAN address — what the printed /remote?t= URL should carry. */
|
|
132
|
+
/** The machine's LAN address — what the printed /deck/remote?t= URL should carry. */
|
|
128
133
|
export function lanAddress(interfaces = networkInterfaces()) {
|
|
129
134
|
for (const addrs of Object.values(interfaces)) {
|
|
130
135
|
for (const a of addrs ?? []) {
|
|
@@ -155,7 +160,7 @@ export { escapeHtml } from '../tools/escape.mjs';
|
|
|
155
160
|
* the deck, its assets, error pages, JSON, SSE, all of it. They are set
|
|
156
161
|
* before the handler runs, and writeHead merges them under any headers a
|
|
157
162
|
* route names itself, so a route can sharpen one but can never lose one by
|
|
158
|
-
* not mentioning it. This is the seam the
|
|
163
|
+
* not mentioning it. This is the seam the no-trust mode's
|
|
159
164
|
* Content-Security-Policy arrives through (PRESENT): "every response
|
|
160
165
|
* carries the header" holds by construction here, instead of by every
|
|
161
166
|
* writeHead in every route remembering.
|
|
@@ -167,13 +172,32 @@ export function withHeaders(headers, handler) {
|
|
|
167
172
|
};
|
|
168
173
|
}
|
|
169
174
|
|
|
175
|
+
/**
|
|
176
|
+
* The one byte range `header` asks for out of a body of `size`, or null when a
|
|
177
|
+
* full 200 answers it.
|
|
178
|
+
*
|
|
179
|
+
* One range, which is all a media element ever sends. Malformed and multipart
|
|
180
|
+
* ranges read as null and fall through to the plain 200 — RFC 7233 allows
|
|
181
|
+
* ignoring Range entirely, so partial support must never invent a 416 for a
|
|
182
|
+
* request a full response satisfies. `satisfiable` marks the one case that must
|
|
183
|
+
* be refused instead: a range that starts past the end of the body.
|
|
184
|
+
*/
|
|
185
|
+
function rangeOf(header, size) {
|
|
186
|
+
const m = /^bytes=(\d*)-(\d*)$/.exec(header ?? '');
|
|
187
|
+
if (!m || !(m[1] || m[2])) return null;
|
|
188
|
+
const start = m[1] ? Number(m[1]) : Math.max(0, size - Number(m[2]));
|
|
189
|
+
const end = m[1] && m[2] ? Math.min(Number(m[2]), size - 1) : size - 1;
|
|
190
|
+
return { start, end, satisfiable: start <= end && start < size };
|
|
191
|
+
}
|
|
192
|
+
|
|
170
193
|
/**
|
|
171
194
|
* Static files under `root`, GET only: traversal-guarded, MIME-typed,
|
|
172
195
|
* no-cache. `index` is the path "/" serves (the deck). Returns whether the
|
|
173
196
|
* request was handled.
|
|
174
197
|
*
|
|
175
198
|
* `html` rewrites the text of every text/html response on its way out and
|
|
176
|
-
* leaves every other type alone
|
|
199
|
+
* leaves every other type alone; after it, a deck that carries no runtime
|
|
200
|
+
* (#520) has the installed one referenced into its text (`linkRuntime`). It is how `--no-trust --strict` (NO_TRUST#STRICT)
|
|
177
201
|
* serves a deck with the unaccounted blocks removed while the file on disk
|
|
178
202
|
* stays exactly as it arrived: the transform sits between the read and the
|
|
179
203
|
* write, so there is no point in this path where the modified bytes could be
|
|
@@ -185,29 +209,59 @@ export function withHeaders(headers, handler) {
|
|
|
185
209
|
* read same-origin it can also send anywhere.
|
|
186
210
|
*
|
|
187
211
|
* `knownTypesOnly` additionally refuses every extension the MIME table does
|
|
188
|
-
* not name. `
|
|
212
|
+
* not name. `--no-trust` passes it: the table is the set of types a deck can
|
|
189
213
|
* actually use, and a file beside a travelled deck that is none of them —
|
|
190
214
|
* `id_rsa`, a `.pem`, a database — is only ever fetched to be exfiltrated.
|
|
191
|
-
* The
|
|
215
|
+
* The edit server does not, so an author's exotic asset still serves as
|
|
192
216
|
* octet-stream from their own machine.
|
|
217
|
+
*
|
|
218
|
+
* The runtime a deck LINKS (#517) — `decklight.js`, `decklight.css`,
|
|
219
|
+
* `themes/<name>.css` — is answered from the installed package when the deck
|
|
220
|
+
* ships no such file, and also when the reference reaches outside `root`
|
|
221
|
+
* (`../dist/decklight.js`, the shape every source deck in this repository
|
|
222
|
+
* uses): the deck gets decklight's own file, never anything of the caller's.
|
|
223
|
+
* A copy that IS on disk beside the deck wins, so an author pinning their
|
|
224
|
+
* own build is honoured. The themes a deck MARKS from a marketplace
|
|
225
|
+
* (`markedThemes`, SPEC THEME_DISTRIBUTION) are answered the same way, at
|
|
226
|
+
* `decklight-theme/<marketplace>/<name>.css`, from the marketplace's files on
|
|
227
|
+
* this machine and never the network. Nothing else escapes root or answers
|
|
228
|
+
* for a missing path — a probe still learns nothing from a 404.
|
|
193
229
|
*/
|
|
194
230
|
export function staticFiles(root, { index = '/index.html', html: rewriteHtml = null, knownTypesOnly = false } = {}) {
|
|
195
231
|
return (req, res, url) => {
|
|
196
232
|
if (req.method !== 'GET') return false;
|
|
197
233
|
const rel = url.pathname === '/' ? index : decodeURIComponent(url.pathname);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
234
|
+
let file = resolve(root, '.' + rel);
|
|
235
|
+
let type;
|
|
236
|
+
let extra = {};
|
|
237
|
+
const dotted = rel.split('/').some((s) => s.startsWith('.'));
|
|
238
|
+
// A referenced design system's or font's files (deck-refs.mjs) — somebody
|
|
239
|
+
// else's package, so its namespace is TERMINAL: it is answered from the
|
|
240
|
+
// package or not at all, and every refusal is the same plain 404.
|
|
241
|
+
const owner = namespacedKind(rel);
|
|
242
|
+
if (owner) {
|
|
243
|
+
const asset = !dotted && owner.asset(rel);
|
|
244
|
+
if (!asset) { res.writeHead(404); res.end('not found'); return true; }
|
|
245
|
+
file = asset.file; type = asset.type; extra = asset.headers;
|
|
246
|
+
} else {
|
|
247
|
+
const escapes = !file.startsWith(root + sep) && file !== root;
|
|
248
|
+
if (escapes || !existsSync(file)) {
|
|
249
|
+
const asset = !dotted && (packageAsset(rel) ?? fallbackReferenceAsset(rel));
|
|
250
|
+
if (asset) { file = asset.file; type = asset.type; }
|
|
251
|
+
else if (escapes) { res.writeHead(403); res.end('forbidden'); return true; }
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const stat = existsSync(file) ? statSync(file) : null;
|
|
255
|
+
if (!stat?.isFile()) { res.writeHead(404); res.end('not found'); return true; }
|
|
201
256
|
// Policy refusals come AFTER the existence check on purpose: a path that
|
|
202
257
|
// is not there stays a plain 404, indistinguishable from any other unknown
|
|
203
|
-
// path — a probe for /
|
|
204
|
-
|
|
205
|
-
if (
|
|
258
|
+
// path — a probe for /deck/ping must not learn anything from the answer.
|
|
259
|
+
type ??= MIME[extname(file).toLowerCase()];
|
|
260
|
+
if (dotted || (knownTypesOnly && !type)) {
|
|
206
261
|
res.writeHead(403); res.end('forbidden'); return true;
|
|
207
262
|
}
|
|
208
|
-
let body = readFileSync(file);
|
|
209
|
-
if (rewriteHtml && type === MIME['.html']) body = Buffer.from(rewriteHtml(body.toString('utf8'), file), 'utf8');
|
|
210
263
|
const headers = {
|
|
264
|
+
...extra,
|
|
211
265
|
'content-type': type ?? 'application/octet-stream',
|
|
212
266
|
'cache-control': 'no-cache',
|
|
213
267
|
// Media elements are the reason both of these exist. A browser asks for
|
|
@@ -218,32 +272,71 @@ export function staticFiles(root, { index = '/index.html', html: rewriteHtml = n
|
|
|
218
272
|
// outright, which surfaced as "no narration for slide 1" pointing at a
|
|
219
273
|
// file that was sitting right there.
|
|
220
274
|
'accept-ranges': 'bytes',
|
|
221
|
-
'content-length': body.length,
|
|
222
275
|
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
276
|
+
|
|
277
|
+
// A page's bytes are not the file's: the caller's rewrite (`--strict`,
|
|
278
|
+
// NO_TRUST#STRICT; a render's driver) runs on the text on its way out, and
|
|
279
|
+
// then a deck that carries no runtime — a deck as data (#520) — gets the
|
|
280
|
+
// engine, its stylesheet and its theme referenced (`linkRuntime`, which
|
|
281
|
+
// leaves every other document exactly as it was). So its length and its
|
|
282
|
+
// ranges have to be measured on what was SENT, which means holding it. It
|
|
283
|
+
// is a page; everything else streams below.
|
|
284
|
+
if (type === MIME['.html']) {
|
|
285
|
+
const text = readFileSync(file).toString('utf8');
|
|
286
|
+
const body = Buffer.from(linkReferences(linkRuntime(rewriteHtml ? rewriteHtml(text, file) : text), { dir: dirname(file), deck: basename(file) }), 'utf8');
|
|
287
|
+
const want = rangeOf(req.headers.range, body.length);
|
|
288
|
+
if (want && !want.satisfiable) {
|
|
289
|
+
res.writeHead(416, { 'content-range': `bytes */${body.length}` });
|
|
290
|
+
res.end();
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
if (want) {
|
|
294
|
+
const slice = body.subarray(want.start, want.end + 1);
|
|
233
295
|
res.writeHead(206, {
|
|
234
296
|
...headers,
|
|
235
297
|
'content-length': slice.length,
|
|
236
|
-
'content-range': `bytes ${start}-${end}/${body.length}`,
|
|
298
|
+
'content-range': `bytes ${want.start}-${want.end}/${body.length}`,
|
|
237
299
|
});
|
|
238
300
|
res.end(slice);
|
|
239
301
|
return true;
|
|
240
302
|
}
|
|
241
|
-
res.writeHead(
|
|
303
|
+
res.writeHead(200, { ...headers, 'content-length': body.length });
|
|
304
|
+
res.end(body);
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Every other type is STREAMED, and the length math comes off the stat
|
|
309
|
+
// rather than a buffer. A deck's background video is a 200 MB file that a
|
|
310
|
+
// browser fetches in a long march of small ranges, and reading all of it
|
|
311
|
+
// synchronously to answer each one froze the event loop — the SSE reload
|
|
312
|
+
// channel and the next request included — once per seek.
|
|
313
|
+
const size = stat.size;
|
|
314
|
+
const want = rangeOf(req.headers.range, size);
|
|
315
|
+
if (want && !want.satisfiable) {
|
|
316
|
+
res.writeHead(416, { 'content-range': `bytes */${size}` });
|
|
242
317
|
res.end();
|
|
243
318
|
return true;
|
|
244
319
|
}
|
|
245
|
-
|
|
246
|
-
|
|
320
|
+
const start = want ? want.start : 0;
|
|
321
|
+
const end = want ? want.end : size - 1;
|
|
322
|
+
res.writeHead(want ? 206 : 200, {
|
|
323
|
+
...headers,
|
|
324
|
+
'content-length': end - start + 1,
|
|
325
|
+
...(want ? { 'content-range': `bytes ${start}-${end}/${size}` } : {}),
|
|
326
|
+
});
|
|
327
|
+
if (end < start) { res.end(); return true; } // an empty file: nothing to open
|
|
328
|
+
const stream = createReadStream(file, { start, end });
|
|
329
|
+
// A viewer who seeks away, closes the tab or reloads abandons the response
|
|
330
|
+
// mid-body. Without this the read runs to the end of the range into a
|
|
331
|
+
// socket nobody is holding, and the descriptor goes with it.
|
|
332
|
+
res.on('close', () => stream.destroy());
|
|
333
|
+
stream.on('error', () => {
|
|
334
|
+
// The headers are already out, so there is no status left to report a
|
|
335
|
+
// failed read with and writeHead would throw on top of it. Cutting the
|
|
336
|
+
// connection is what tells the client the body it was promised is short.
|
|
337
|
+
res.destroy();
|
|
338
|
+
});
|
|
339
|
+
stream.pipe(res);
|
|
247
340
|
return true;
|
|
248
341
|
};
|
|
249
342
|
}
|
|
@@ -251,7 +344,7 @@ export function staticFiles(root, { index = '/index.html', html: rewriteHtml = n
|
|
|
251
344
|
/**
|
|
252
345
|
* One SSE fan-out. add() takes a response over (headers, greeting comment,
|
|
253
346
|
* cleanup on close) and returns it; broadcast() sends a named event to every
|
|
254
|
-
* subscriber; raw() sends bytes as-is (the deck's unnamed `data: reload`
|
|
347
|
+
* subscriber; raw() sends bytes as-is (the deck's unnamed `data: {"reload": …}`
|
|
255
348
|
* message predates named events and stays byte-identical).
|
|
256
349
|
*/
|
|
257
350
|
export function sseChannel() {
|
|
@@ -290,7 +383,13 @@ export async function listenTakingOverIfNeeded(server, port, host = '127.0.0.1')
|
|
|
290
383
|
try {
|
|
291
384
|
return await new Promise((res, rej) => {
|
|
292
385
|
const onError = (e) => { server.off('listening', onListening); rej(e); };
|
|
293
|
-
const onListening = () => {
|
|
386
|
+
const onListening = () => {
|
|
387
|
+
server.off('error', onError);
|
|
388
|
+
// the bind race is over, but a server with no 'error' listener
|
|
389
|
+
// turns the next one into an uncaught exception
|
|
390
|
+
server.on('error', (e) => console.error(`server error: ${e.message}`));
|
|
391
|
+
res(server.address().port);
|
|
392
|
+
};
|
|
294
393
|
server.once('error', onError);
|
|
295
394
|
server.once('listening', onListening);
|
|
296
395
|
server.listen(port, host);
|
|
@@ -304,3 +403,95 @@ export async function listenTakingOverIfNeeded(server, port, host = '127.0.0.1')
|
|
|
304
403
|
rl?.close();
|
|
305
404
|
}
|
|
306
405
|
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* The no-trust mode's policy (PRESENTING), and honestly what it is worth.
|
|
409
|
+
*
|
|
410
|
+
* `script-src` has to carry `'unsafe-inline'`: a bundled deck IS inline script
|
|
411
|
+
* (the runtime is inlined by `decklight bundle`) and even a source deck calls
|
|
412
|
+
* `Decklight.init()` from an inline block. So this header does not stop a deck from running
|
|
413
|
+
* script — that is what NO_TRUST#AUDIT names and NO_TRUST#STRICT strips, and
|
|
414
|
+
* claiming otherwise here would manufacture confidence the mechanism cannot
|
|
415
|
+
* back.
|
|
416
|
+
*
|
|
417
|
+
* What it does stop is what a hostile deck would want to DO with that script:
|
|
418
|
+
* `default-src 'none'` denies every fetch destination not listed below,
|
|
419
|
+
* `object-src` kills plugin embedding, `base-uri` stops relative-URL
|
|
420
|
+
* hijacking, and `form-action 'none'` means a credential form pasted into a
|
|
421
|
+
* deck has nowhere to post. Exfiltration is narrowed to `https:` rather than
|
|
422
|
+
* closed, because that is where SPEC'd narration lives (below).
|
|
423
|
+
*
|
|
424
|
+
* Each opening is a SPEC'd feature, not a convenience:
|
|
425
|
+
* - `media-src https:` — a recorded track's `dir` may be an absolute URL, and
|
|
426
|
+
* background video stays external by design (PRESENTING). `blob:` is the
|
|
427
|
+
* stitched/`createObjectURL` audio path.
|
|
428
|
+
* - `connect-src https:` — manifest tracks fetch `manifest.signed.json` from a
|
|
429
|
+
* bucket; a presigned URL's origin is not knowable ahead of time, so it
|
|
430
|
+
* cannot be pinned to an allowlist here.
|
|
431
|
+
* - `frame-src`/`frame-ancestors 'self'` — the theme picker, the slide finder
|
|
432
|
+
* and the speaker view all boot the deck into same-origin iframes. `'none'`
|
|
433
|
+
* would break the picker preview; `'self'` still refuses embedding by
|
|
434
|
+
* another site.
|
|
435
|
+
* - `style-src 'unsafe-inline'` — themes are inline `<style data-theme>`
|
|
436
|
+
* blocks and the engine writes inline custom properties (`--pin-y`).
|
|
437
|
+
*
|
|
438
|
+
* The bridges sit on the deck's own origin (`/deck/tts`, `/deck/lipsync/`), so
|
|
439
|
+
* `'self'` would let a deck reach them; the server refuses those families in
|
|
440
|
+
* no-trust mode instead (MARKETPLACE.md ENGINES: engines never come up outside
|
|
441
|
+
* write mode — a deck you were emailed asking to reach a local service is the
|
|
442
|
+
* shape of a probe). Recorded narration needs no bridge and is unaffected.
|
|
443
|
+
*/
|
|
444
|
+
export const CSP = [
|
|
445
|
+
"default-src 'none'",
|
|
446
|
+
"script-src 'self' 'unsafe-inline'",
|
|
447
|
+
"style-src 'self' 'unsafe-inline'",
|
|
448
|
+
"img-src 'self' data: blob: https:",
|
|
449
|
+
"media-src 'self' data: blob: https:",
|
|
450
|
+
"font-src 'self' data:",
|
|
451
|
+
"connect-src 'self' https:",
|
|
452
|
+
"frame-src 'self'",
|
|
453
|
+
"frame-ancestors 'self'",
|
|
454
|
+
"base-uri 'none'",
|
|
455
|
+
"form-action 'none'",
|
|
456
|
+
"object-src 'none'",
|
|
457
|
+
].join('; ');
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Serve files under `root` over http://127.0.0.1 with the CSP on EVERY
|
|
461
|
+
* response, for the render tools (`tools/shot.mjs`, `tools/video.mjs`).
|
|
462
|
+
*
|
|
463
|
+
* It is the serving core with the audit/strict/deck/remote/edit surface
|
|
464
|
+
* stripped off: `withHeaders` for the policy, `staticFiles` for a
|
|
465
|
+
* traversal-guarded GET, an ephemeral loopback port. A deck screenshotted or
|
|
466
|
+
* filmed BEFORE anyone presents it therefore runs under the same policy
|
|
467
|
+
* no-trust mode gives it — instead of over `file://` with
|
|
468
|
+
* `--allow-file-access-from-files`, the flag that let a deck's own JS read any
|
|
469
|
+
* local file it could name and ship it anywhere (#229). An http origin cannot
|
|
470
|
+
* read `file://` at all, and the CSP bounds where the rest can reach; a read is
|
|
471
|
+
* confined to what `staticFiles` will serve under `root`.
|
|
472
|
+
*
|
|
473
|
+
* `html` rewrites the text of every text/html response on its way out (shot
|
|
474
|
+
* injects its driver and `--theme` link there, in memory — no temp file). The
|
|
475
|
+
* server must be driven with an ASYNC Chrome (execFile, not execFileSync): a
|
|
476
|
+
* synchronous child blocks the event loop, and this in-process server would
|
|
477
|
+
* never answer the browser it launched.
|
|
478
|
+
*
|
|
479
|
+
* Returns `{ origin, close }` — `origin` is `http://127.0.0.1:<port>`, `close`
|
|
480
|
+
* resolves when the listener is shut.
|
|
481
|
+
*/
|
|
482
|
+
export async function serveForRender(root, { html = null } = {}) {
|
|
483
|
+
const files = staticFiles(root, { html });
|
|
484
|
+
|
|
485
|
+
const server = createServer(withHeaders({ 'content-security-policy': CSP }, (req, res) => {
|
|
486
|
+
let url;
|
|
487
|
+
try { url = new URL(req.url, 'http://127.0.0.1'); }
|
|
488
|
+
catch { res.writeHead(400); res.end('bad request'); return; }
|
|
489
|
+
if (files(req, res, url)) return;
|
|
490
|
+
res.writeHead(405); res.end('method not allowed');
|
|
491
|
+
}));
|
|
492
|
+
const port = await listenTakingOverIfNeeded(server, 0, '127.0.0.1');
|
|
493
|
+
return {
|
|
494
|
+
origin: `http://127.0.0.1:${port}`,
|
|
495
|
+
close: () => new Promise((r) => server.close(r)),
|
|
496
|
+
};
|
|
497
|
+
}
|
package/cli/setup.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* decklight setup — set up this machine's voice and face, once.
|
|
6
|
+
*
|
|
7
|
+
* decklight setup voice the guided engine setup (was `tts --setup`)
|
|
8
|
+
* decklight setup face <flags> remember a talking head (was `lipsync … --save`)
|
|
9
|
+
*
|
|
10
|
+
* The voice bridge and the lip-sync bridge are things `decklight <deck>`
|
|
11
|
+
* starts, so they stopped being commands a person types (ROADMAP section 4):
|
|
12
|
+
* `tts` and `lipsync` still run, because write mode spawns them and a deck
|
|
13
|
+
* opened from a file still talks to a bridge run on its own, but they are out
|
|
14
|
+
* of the help. What a person does type is the one-time setup, and it is a
|
|
15
|
+
* setup: it saves the answers and stops, rather than going on to serve.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { createInterface } from 'node:readline/promises';
|
|
19
|
+
import { isMain } from '../tools/args.mjs';
|
|
20
|
+
import { runMain } from './util.mjs';
|
|
21
|
+
|
|
22
|
+
export const USAGE = `usage: decklight setup <voice | face> …
|
|
23
|
+
|
|
24
|
+
decklight setup voice
|
|
25
|
+
the guided setup for live narration: which engine (a system voice,
|
|
26
|
+
piper, chirp, gemini, elevenlabs), what it needs, and one test sentence.
|
|
27
|
+
The answers are saved; decklight <deck> uses them from then on.
|
|
28
|
+
Run it again to change engine or voice.
|
|
29
|
+
|
|
30
|
+
decklight setup voice [--engine E] [--voice V] [--project P] [--model M]
|
|
31
|
+
[--location L] [--lang en-US] [--format pcm|mp3]
|
|
32
|
+
[--stability creative|natural|robust] [--data-dir D]
|
|
33
|
+
save exactly these, no questions: what used to be a flag on every
|
|
34
|
+
decklight <deck> run. A new --engine drops the old engine's voice,
|
|
35
|
+
model, format, stability and data dir.
|
|
36
|
+
EXAMPLE: decklight setup voice --engine elevenlabs --model eleven_v3 --stability natural
|
|
37
|
+
|
|
38
|
+
decklight setup face --portrait me=<photo.jpg | clip.mp4> [--wav2lip-dir <checkout>
|
|
39
|
+
--wav2lip-ckpt <wav2lip_gan.pth>] [--sadtalker-dir <checkout>]
|
|
40
|
+
[--python <its venv python>]
|
|
41
|
+
remember a talking head for the narrator (V → Character): the portrait
|
|
42
|
+
and the local lip-sync models. Saved; decklight <deck> starts the
|
|
43
|
+
lip-sync bridge with it. A clip can also be filmed in the deck.
|
|
44
|
+
Also saved when given: --cache-dir, --rhubarb, and --veo (animate the
|
|
45
|
+
portrait through Vertex: BILLED once per portrait, then cached; --no-veo
|
|
46
|
+
turns it off) with --veo-project, --veo-model, --veo-seconds,
|
|
47
|
+
--veo-prompt, --veo-location, --veo-face-y.
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
// `setup voice` flag → tts.json key. The settings tied to one engine are
|
|
51
|
+
// dropped when the engine changes, as the guided setup's answers are.
|
|
52
|
+
const VOICE_FLAGS = { '--engine': 'engine', '--voice': 'voice', '--project': 'project', '--model': 'model',
|
|
53
|
+
'--location': 'location', '--lang': 'lang', '--format': 'format', '--stability': 'stability', '--data-dir': 'dataDir' };
|
|
54
|
+
const ENGINE_BOUND = ['voice', 'model', 'format', 'stability', 'dataDir'];
|
|
55
|
+
|
|
56
|
+
/** The voice settings given as flags, or null when none were (the guided setup runs). Pure. */
|
|
57
|
+
export function voiceSettings(args = []) {
|
|
58
|
+
const out = {};
|
|
59
|
+
for (let i = 0; i < args.length; i++) {
|
|
60
|
+
const key = VOICE_FLAGS[args[i]];
|
|
61
|
+
if (key && args[i + 1] !== undefined && !args[i + 1].startsWith('--')) out[key] = args[++i];
|
|
62
|
+
}
|
|
63
|
+
return Object.keys(out).length ? out : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function setupMain(args = []) {
|
|
67
|
+
const [what, ...rest] = args;
|
|
68
|
+
if (!what || what === '--help' || what === '-h' || what === 'help') { console.log(USAGE); return what ? 0 : 1; }
|
|
69
|
+
if (what === 'voice') {
|
|
70
|
+
if (rest.includes('--help') || rest.includes('-h')) { console.log(USAGE); return 0; }
|
|
71
|
+
// Flags: save them as given, no questions. This is where a setting that
|
|
72
|
+
// used to be a flag on `decklight <deck>` every run is now given once.
|
|
73
|
+
const given = voiceSettings(rest);
|
|
74
|
+
if (given) {
|
|
75
|
+
const { loadTtsConfig, saveTtsConfig } = await import('../tools/tts-setup.mjs');
|
|
76
|
+
const was = loadTtsConfig() ?? {};
|
|
77
|
+
// engine-specific settings (voice, model, format, data dir, stability)
|
|
78
|
+
// belong to the engine they were given for: a new engine starts clean
|
|
79
|
+
const keepEngineBound = !given.engine || given.engine === was.engine;
|
|
80
|
+
const base = keepEngineBound ? was
|
|
81
|
+
: Object.fromEntries(Object.entries(was).filter(([k]) => !ENGINE_BOUND.includes(k)));
|
|
82
|
+
const file = saveTtsConfig({ ...base, ...given });
|
|
83
|
+
console.log(`saved to ${file}: ${Object.entries(given).map(([k, v]) => `${k} ${v}`).join(', ')}`);
|
|
84
|
+
console.log(' decklight <deck> uses it from now on (V in the deck)');
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
if (!(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
88
|
+
console.error('decklight setup voice: needs a terminal to ask its questions on');
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
const { runSetupWizard, loadTtsConfig } = await import('../tools/tts-setup.mjs');
|
|
92
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
93
|
+
try {
|
|
94
|
+
const done = await runSetupWizard({ ask: (q) => rl.question(q), prefill: loadTtsConfig() ?? {} });
|
|
95
|
+
if (!done) return 1;
|
|
96
|
+
// the wizard's test sentence may hold a resident engine (piper): let it go
|
|
97
|
+
done.engine?.synth?.close?.();
|
|
98
|
+
console.log(' decklight <deck> uses it from now on (V in the deck)');
|
|
99
|
+
return 0;
|
|
100
|
+
} finally { rl.close(); }
|
|
101
|
+
}
|
|
102
|
+
if (what === 'face') {
|
|
103
|
+
if (rest.includes('--help') || rest.includes('-h') || !rest.length) { console.log(USAGE); return rest.length ? 0 : 1; }
|
|
104
|
+
const { lipsyncMain } = await import('../tools/lipsync-server.mjs');
|
|
105
|
+
await lipsyncMain([...rest.filter((a) => a !== '--save'), '--save']);
|
|
106
|
+
return process.exitCode ?? 0;
|
|
107
|
+
}
|
|
108
|
+
console.error(`decklight setup: "${what}" is not something to set up — voice or face\n\n${USAGE}`);
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (isMain(import.meta.url)) process.exitCode = await runMain('setup', setupMain);
|
package/cli/sign.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export const INSTALL_HINT = 'run: npm install sigstore';
|
|
|
49
49
|
/**
|
|
50
50
|
* The sigstore client, or null when it is not installed.
|
|
51
51
|
*
|
|
52
|
-
* Lazy on purpose: an import at module load would make `
|
|
52
|
+
* Lazy on purpose: an import at module load would make `--no-trust` — which needs
|
|
53
53
|
* this only when a sidecar exists — pay for it on every start, and would make
|
|
54
54
|
* the whole CLI unloadable on an install that skipped optional dependencies.
|
|
55
55
|
*/
|