decklight 0.5.0 → 0.7.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/README.md +20 -9
- package/SPEC.md +239 -17
- package/cli/agents.mjs +97 -2
- package/cli/banner.mjs +125 -0
- package/cli/bundle.mjs +14 -4
- package/cli/{rec.mjs → cast.mjs} +25 -8
- package/cli/comments.mjs +389 -0
- package/cli/commit-flow.mjs +157 -0
- package/cli/commit-message.mjs +475 -0
- package/cli/decklight.mjs +95 -25
- package/cli/dev.mjs +193 -25
- package/cli/edit.mjs +1055 -39
- package/cli/git-tree.mjs +87 -0
- package/cli/git.mjs +370 -0
- package/cli/history.mjs +145 -0
- package/cli/init.mjs +199 -7
- package/cli/marketplace.mjs +123 -17
- package/cli/port-conflict.mjs +228 -22
- package/cli/present.mjs +297 -12
- package/cli/publish.mjs +15 -40
- package/cli/record.mjs +154 -0
- package/cli/restore.mjs +120 -4
- package/cli/review-remote.mjs +330 -0
- package/cli/review-store.mjs +107 -0
- package/cli/review-submit.mjs +292 -0
- package/cli/review.mjs +361 -0
- package/cli/serve.mjs +60 -1
- package/cli/skill-content.mjs +12 -1
- package/cli/theme.mjs +78 -11
- package/cli/units.mjs +2 -2
- package/cli/upstream.mjs +256 -0
- package/cli/util.mjs +59 -0
- package/dist/build-info.json +1 -0
- package/dist/decklight.css +534 -3
- package/dist/decklight.js +102 -76
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +7 -0
- package/package.json +2 -1
- package/tools/args.mjs +20 -0
- package/tools/deck-html.mjs +84 -0
- package/tools/elevenlabs-tts.mjs +1 -1
- package/tools/lipsync-server.mjs +64 -2
- package/tools/lipsync.mjs +40 -24
- package/tools/local-voice.mjs +170 -16
- package/tools/publish-voices.mjs +78 -18
- package/tools/recording-impact.mjs +110 -0
- package/tools/review-anchor.mjs +180 -0
- package/tools/test-impact.mjs +259 -0
- package/tools/tts-engines.mjs +211 -12
- package/tools/tts-setup.mjs +2 -9
- package/tools/video.mjs +56 -12
- package/tools/voiceover-server.mjs +262 -11
- package/tools/voiceover.mjs +32 -13
package/cli/present.mjs
CHANGED
|
@@ -32,7 +32,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
32
32
|
import { resolve, sep, basename, dirname } from 'node:path';
|
|
33
33
|
import { randomBytes } from 'node:crypto';
|
|
34
34
|
import { argReader, isMain } from '../tools/args.mjs';
|
|
35
|
-
import { allowRemote, lanAddress, staticFiles, sseChannel, listenTakingOverIfNeeded, withHeaders } from './serve.mjs';
|
|
35
|
+
import { allowRemote, lanAddress, staticFiles, sseChannel, listenTakingOverIfNeeded, withHeaders, isOwnOrigin } from './serve.mjs';
|
|
36
36
|
import { createRemoteRelay } from './remote.mjs';
|
|
37
37
|
import { corsHeaders } from '../tools/bridge.mjs';
|
|
38
38
|
|
|
@@ -43,6 +43,10 @@ const CORS = corsHeaders();
|
|
|
43
43
|
import { auditDeck, formatLabel, stripUnaccounted } from './audit.mjs';
|
|
44
44
|
import { loadLibrary, injectChrome } from './plugin.mjs';
|
|
45
45
|
import { verifyFile, verifyBytes, formatSignature, isVerified, UNSIGNED, TAMPERED, VERIFIED } from './sign.mjs';
|
|
46
|
+
import {
|
|
47
|
+
SAFE_CONFIG, canPull, checkUpstream, resolveInterval, resolveUpstream, runGit, upstreamSuppressed,
|
|
48
|
+
} from './upstream.mjs';
|
|
49
|
+
import { oneline } from './git.mjs';
|
|
46
50
|
import { isContainer, readContainer, formatManifest } from './deckfile.mjs';
|
|
47
51
|
|
|
48
52
|
/**
|
|
@@ -122,6 +126,81 @@ export const CSP = [
|
|
|
122
126
|
*/
|
|
123
127
|
export async function serveForRender(root, { html = null } = {}) {
|
|
124
128
|
const files = staticFiles(root, { html });
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Fast-forward, then re-read, re-audit and RE-PRINT.
|
|
132
|
+
*
|
|
133
|
+
* SPEC's condition on live reload under `present` is exactly this: never new
|
|
134
|
+
* bytes under the old verdict. So the label the presenter can see always
|
|
135
|
+
* describes the bytes being served, and the two move together.
|
|
136
|
+
*/
|
|
137
|
+
async function doPull() {
|
|
138
|
+
// Re-checked against a FRESH fetch rather than trusted from the cached
|
|
139
|
+
// status: what was true ten minutes ago is not a licence to check out now.
|
|
140
|
+
const fresh = await refreshUpstream();
|
|
141
|
+
const allowed = canPull(fresh, { offered: pullArmed });
|
|
142
|
+
if (!allowed.ok) return { ok: false, ...allowed, http: allowed.state === 'dirty' ? 409 : 409 };
|
|
143
|
+
|
|
144
|
+
const from = (await runGit(['rev-parse', '--short', 'HEAD'], { cwd: upstream.repoRoot })).stdout;
|
|
145
|
+
console.log(` upstream: PULL requested by the deck — fast-forward only, onto ${upstream.upstream}`);
|
|
146
|
+
const merged = await runGit([...SAFE_CONFIG, '-c', `core.hooksPath=${upstream.repoRoot}/.git/decklight-no-hooks`,
|
|
147
|
+
'merge', '--ff-only', '--no-verify', '@{upstream}'], { cwd: upstream.repoRoot, timeoutMs: 20000 });
|
|
148
|
+
if (!merged.ok) {
|
|
149
|
+
const why = oneline(merged.stderr || merged.err);
|
|
150
|
+
console.log(` upstream: the fast-forward was refused — ${why}`);
|
|
151
|
+
return { ok: false, state: 'not-fast-forward', message: why };
|
|
152
|
+
}
|
|
153
|
+
const to = (await runGit(['rev-parse', '--short', 'HEAD'], { cwd: upstream.repoRoot })).stdout;
|
|
154
|
+
|
|
155
|
+
// An upstream commit must never blank somebody's talk.
|
|
156
|
+
if (!existsSync(deckPath)) {
|
|
157
|
+
console.log(` upstream: fast-forwarded ${from} → ${to}, but the deck is gone from that commit`);
|
|
158
|
+
console.log(' still serving the bytes the label above describes');
|
|
159
|
+
return { ok: false, state: 'deck-gone', to, message: 'the deck is not in that commit — still serving the old bytes' };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const before = deck.payload;
|
|
163
|
+
const next = readAndAudit();
|
|
164
|
+
if (next.payload.equals(before)) {
|
|
165
|
+
console.log(` upstream: fast-forwarded ${from} → ${to} — the deck itself is unchanged`);
|
|
166
|
+
await refreshUpstream();
|
|
167
|
+
return { ok: true, state: 'pulled', from, to, deck: 'unchanged', reload: false, message: `fast-forwarded to ${to} — the deck is unchanged` };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// STRICT RATCHETS: a pull may turn it on and can never turn it off. A deck
|
|
171
|
+
// that could clear its own strict flag by pulling could disarm the one
|
|
172
|
+
// mitigation present applies without being asked.
|
|
173
|
+
const wasStrict = deck.strict;
|
|
174
|
+
deck = { ...next, strict: next.strict || wasStrict };
|
|
175
|
+
const degraded = (next.report.counts.unaccounted > 0 || next.report.counts.handlers > 0)
|
|
176
|
+
&& !(report.counts.unaccounted > 0 || report.counts.handlers > 0);
|
|
177
|
+
|
|
178
|
+
console.log(` upstream: fast-forwarded ${from} → ${to}`);
|
|
179
|
+
console.log(' the deck file changed — re-read and re-audited; the label below replaces the one above');
|
|
180
|
+
for (const line of formatLabel(deck.report)) console.log(line);
|
|
181
|
+
console.log(formatSignature(deck.signature));
|
|
182
|
+
if (deck.strict) {
|
|
183
|
+
console.log(wasStrict && !next.strict
|
|
184
|
+
? ' still serving strict — a pull cannot turn it off'
|
|
185
|
+
: ' serving strict — what could not be accounted for is stripped');
|
|
186
|
+
}
|
|
187
|
+
console.log(' the label above describes what the audience gets when the deck is reloaded');
|
|
188
|
+
await refreshUpstream();
|
|
189
|
+
return {
|
|
190
|
+
ok: true, state: 'pulled', from, to, deck: 'changed',
|
|
191
|
+
strict: deck.strict, degraded,
|
|
192
|
+
findings: { unaccounted: deck.report.counts.unaccounted, handlers: deck.report.counts.handlers },
|
|
193
|
+
// A degraded deck does NOT reload itself: the swap executes nothing (the
|
|
194
|
+
// browser is still showing the old DOM), so the reload can wait for a
|
|
195
|
+
// second confirmation that names what was found.
|
|
196
|
+
reload: !degraded,
|
|
197
|
+
message: degraded
|
|
198
|
+
? `the updated deck runs ${deck.report.counts.unaccounted} unaccounted script block(s) and `
|
|
199
|
+
+ `${deck.report.counts.handlers} inline handler(s) — they are stripped. Reload to show it`
|
|
200
|
+
: `fast-forwarded to ${to}`,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
125
204
|
const server = createServer(withHeaders({ 'content-security-policy': CSP }, (req, res) => {
|
|
126
205
|
let url;
|
|
127
206
|
try { url = new URL(req.url, 'http://127.0.0.1'); }
|
|
@@ -176,6 +255,11 @@ const USAGE = `usage: decklight present <deck.html|deck.decklight> [--port 8790]
|
|
|
176
255
|
an executable attribute — so CI can gate on a deck before it is
|
|
177
256
|
forwarded or published.
|
|
178
257
|
--no-plugins present without your own chrome, whatever is installed.
|
|
258
|
+
--upstream-every N minutes between upstream checks; 0 turns the check off [10]
|
|
259
|
+
--no-upstream never look at the upstream — no git, no network
|
|
260
|
+
--upstream-pull register the update control the deck's H overlay drives.
|
|
261
|
+
OFF by default: with it on, any script in the deck can
|
|
262
|
+
fast-forward the clone the deck was served from.
|
|
179
263
|
|
|
180
264
|
Your presenter plugins (decklight plugin) are layered on at serve time from
|
|
181
265
|
~/.decklight/plugins/ — a timer, a teleprompter, a confidence monitor. They
|
|
@@ -357,8 +441,34 @@ export async function presentMain(args, { client } = {}) {
|
|
|
357
441
|
// no third state where a bad signature means something else — one degrade is
|
|
358
442
|
// one thing to understand at the moment you have no time to understand two.
|
|
359
443
|
const unverified = signature.state !== UNSIGNED && !isVerified(signature);
|
|
360
|
-
|
|
361
|
-
|
|
444
|
+
// MUTABLE from here, because a pull may replace all of it (PRESENT#UPSTREAM).
|
|
445
|
+
// SPEC's condition on live reload is that the audit re-runs and the verdict is
|
|
446
|
+
// re-printed — never new bytes under the old label — so the bytes, the label,
|
|
447
|
+
// the signature and `strict` move together or not at all.
|
|
448
|
+
/** Read the deck, audit it, and decide strict — the startup block, reusable. */
|
|
449
|
+
function readAndAudit() {
|
|
450
|
+
const bytes = isContainer(deckPath) ? readContainer(deckPath).payload : readFileSync(deckPath);
|
|
451
|
+
const rep = auditDeck(bytes.toString('utf8'));
|
|
452
|
+
// The signature is NOT re-verified here: it is a sidecar for the file as
|
|
453
|
+
// published, verifying it costs the network, and a pull that changed the
|
|
454
|
+
// deck has already invalidated whatever the old one attested. The state is
|
|
455
|
+
// carried forward and the label says what it says.
|
|
456
|
+
return {
|
|
457
|
+
payload: bytes,
|
|
458
|
+
report: rep,
|
|
459
|
+
signature,
|
|
460
|
+
strict: args.includes('--strict') || rep.counts.unaccounted > 0 || rep.counts.handlers > 0,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
let deck = {
|
|
465
|
+
payload,
|
|
466
|
+
report,
|
|
467
|
+
signature,
|
|
468
|
+
strict: args.includes('--strict') || report.counts.unaccounted > 0
|
|
469
|
+
|| report.counts.handlers > 0 || unverified,
|
|
470
|
+
};
|
|
471
|
+
const strict = deck.strict;
|
|
362
472
|
|
|
363
473
|
// The rewrite covers every html response, not only the deck: strict that
|
|
364
474
|
// stopped at one file would be walked around by a second page under the same
|
|
@@ -379,7 +489,10 @@ export async function presentMain(args, { client } = {}) {
|
|
|
379
489
|
// With an empty library `injectChrome` returns its input, so this whole
|
|
380
490
|
// paragraph is a no-op and `present` is byte-for-byte the command it was.
|
|
381
491
|
const chrome = args.includes('--no-plugins') ? { plugins: [], refused: [] } : loadLibrary();
|
|
382
|
-
|
|
492
|
+
// Consulted per request rather than decided once: after a pull, `strict` may
|
|
493
|
+
// have RATCHETED ON, and the bytes served have to follow the verdict printed
|
|
494
|
+
// for them.
|
|
495
|
+
const strip = (text) => (deck.strict ? stripUnaccounted(text).html : text);
|
|
383
496
|
|
|
384
497
|
// Only the deck gets chrome. Every OTHER html file under the root still gets
|
|
385
498
|
// the strict rewrite — strict that stopped at one file would be walked
|
|
@@ -388,12 +501,12 @@ export async function presentMain(args, { client } = {}) {
|
|
|
388
501
|
// documents into same-origin iframes). Those same iframes are why the chrome
|
|
389
502
|
// is deck-only: presenter chrome belongs to the document the presenter is
|
|
390
503
|
// looking at, and the shim removes itself if it finds it is framed anyway.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
504
|
+
// Always a function now: `strip` is decided per call, so a pull that turns
|
|
505
|
+
// strict ON must not find the rewrite path was compiled away at startup.
|
|
506
|
+
const rewrite = (text, file) => {
|
|
507
|
+
const out = strip(text);
|
|
508
|
+
return file === deckPath ? injectChrome(out, chrome.plugins) : out;
|
|
509
|
+
};
|
|
397
510
|
// No `index` here: "/" is the deck, and the deck is answered from memory
|
|
398
511
|
// before this handler is consulted — a fallthrough should 404, not reopen
|
|
399
512
|
// the disk read this route exists to avoid.
|
|
@@ -414,8 +527,8 @@ export async function presentMain(args, { client } = {}) {
|
|
|
414
527
|
const servePayload = (req, res) => {
|
|
415
528
|
if (req.method !== 'GET') return false;
|
|
416
529
|
const body = rewrite
|
|
417
|
-
? Buffer.from(rewrite(payload.toString('utf8'), deckPath), 'utf8')
|
|
418
|
-
: payload;
|
|
530
|
+
? Buffer.from(rewrite(deck.payload.toString('utf8'), deckPath), 'utf8')
|
|
531
|
+
: deck.payload;
|
|
419
532
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-cache' });
|
|
420
533
|
res.end(body);
|
|
421
534
|
return true;
|
|
@@ -453,6 +566,114 @@ export async function presentMain(args, { client } = {}) {
|
|
|
453
566
|
// fixed string or first-party content, so no uncovered response was
|
|
454
567
|
// exploitable — but "every response carries the header" is only worth
|
|
455
568
|
// stating if it holds by construction, not by each writeHead remembering.
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Fast-forward, then re-read, re-audit and RE-PRINT.
|
|
572
|
+
*
|
|
573
|
+
* SPEC's condition on live reload under `present` is exactly this: never new
|
|
574
|
+
* bytes under the old verdict. So the label the presenter can see always
|
|
575
|
+
* describes the bytes being served, and the two move together.
|
|
576
|
+
*/
|
|
577
|
+
async function doPull() {
|
|
578
|
+
// Re-checked against a FRESH fetch rather than trusted from the cached
|
|
579
|
+
// status: what was true ten minutes ago is not a licence to check out now.
|
|
580
|
+
const fresh = await refreshUpstream();
|
|
581
|
+
const allowed = canPull(fresh, { offered: pullArmed });
|
|
582
|
+
if (!allowed.ok) return { ok: false, ...allowed, http: allowed.state === 'dirty' ? 409 : 409 };
|
|
583
|
+
|
|
584
|
+
const from = (await runGit(['rev-parse', '--short', 'HEAD'], { cwd: upstream.repoRoot })).stdout;
|
|
585
|
+
console.log(` upstream: PULL requested by the deck — fast-forward only, onto ${upstream.upstream}`);
|
|
586
|
+
const merged = await runGit([...SAFE_CONFIG, '-c', `core.hooksPath=${upstream.repoRoot}/.git/decklight-no-hooks`,
|
|
587
|
+
'merge', '--ff-only', '--no-verify', '@{upstream}'], { cwd: upstream.repoRoot, timeoutMs: 20000 });
|
|
588
|
+
if (!merged.ok) {
|
|
589
|
+
const why = oneline(merged.stderr || merged.err);
|
|
590
|
+
console.log(` upstream: the fast-forward was refused — ${why}`);
|
|
591
|
+
return { ok: false, state: 'not-fast-forward', message: why };
|
|
592
|
+
}
|
|
593
|
+
const to = (await runGit(['rev-parse', '--short', 'HEAD'], { cwd: upstream.repoRoot })).stdout;
|
|
594
|
+
|
|
595
|
+
// An upstream commit must never blank somebody's talk.
|
|
596
|
+
if (!existsSync(deckPath)) {
|
|
597
|
+
console.log(` upstream: fast-forwarded ${from} → ${to}, but the deck is gone from that commit`);
|
|
598
|
+
console.log(' still serving the bytes the label above describes');
|
|
599
|
+
return { ok: false, state: 'deck-gone', to, message: 'the deck is not in that commit — still serving the old bytes' };
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const before = deck.payload;
|
|
603
|
+
const next = readAndAudit();
|
|
604
|
+
if (next.payload.equals(before)) {
|
|
605
|
+
console.log(` upstream: fast-forwarded ${from} → ${to} — the deck itself is unchanged`);
|
|
606
|
+
await refreshUpstream();
|
|
607
|
+
return { ok: true, state: 'pulled', from, to, deck: 'unchanged', reload: false, message: `fast-forwarded to ${to} — the deck is unchanged` };
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// STRICT RATCHETS: a pull may turn it on and can never turn it off. A deck
|
|
611
|
+
// that could clear its own strict flag by pulling could disarm the one
|
|
612
|
+
// mitigation present applies without being asked.
|
|
613
|
+
const wasStrict = deck.strict;
|
|
614
|
+
deck = { ...next, strict: next.strict || wasStrict };
|
|
615
|
+
const degraded = (next.report.counts.unaccounted > 0 || next.report.counts.handlers > 0)
|
|
616
|
+
&& !(report.counts.unaccounted > 0 || report.counts.handlers > 0);
|
|
617
|
+
|
|
618
|
+
console.log(` upstream: fast-forwarded ${from} → ${to}`);
|
|
619
|
+
console.log(' the deck file changed — re-read and re-audited; the label below replaces the one above');
|
|
620
|
+
for (const line of formatLabel(deck.report)) console.log(line);
|
|
621
|
+
console.log(formatSignature(deck.signature));
|
|
622
|
+
if (deck.strict) {
|
|
623
|
+
console.log(wasStrict && !next.strict
|
|
624
|
+
? ' still serving strict — a pull cannot turn it off'
|
|
625
|
+
: ' serving strict — what could not be accounted for is stripped');
|
|
626
|
+
}
|
|
627
|
+
console.log(' the label above describes what the audience gets when the deck is reloaded');
|
|
628
|
+
await refreshUpstream();
|
|
629
|
+
return {
|
|
630
|
+
ok: true, state: 'pulled', from, to, deck: 'changed',
|
|
631
|
+
strict: deck.strict, degraded,
|
|
632
|
+
findings: { unaccounted: deck.report.counts.unaccounted, handlers: deck.report.counts.handlers },
|
|
633
|
+
// A degraded deck does NOT reload itself: the swap executes nothing (the
|
|
634
|
+
// browser is still showing the old DOM), so the reload can wait for a
|
|
635
|
+
// second confirmation that names what was found.
|
|
636
|
+
reload: !degraded,
|
|
637
|
+
message: degraded
|
|
638
|
+
? `the updated deck runs ${deck.report.counts.unaccounted} unaccounted script block(s) and `
|
|
639
|
+
+ `${deck.report.counts.handlers} inline handler(s) — they are stripped. Reload to show it`
|
|
640
|
+
: `fast-forwarded to ${to}`,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// ── the upstream check (PRESENT#UPSTREAM) ─────────────────────────────────
|
|
645
|
+
const suppressed = upstreamSuppressed({ args, env: process.env });
|
|
646
|
+
const upstreamCtx = suppressed ? { state: 'disabled' } : await resolveUpstream(deckPath);
|
|
647
|
+
// Absent unless the deck is a tracked file in a clone with an upstream. This
|
|
648
|
+
// is the whole safety argument: a deck you were emailed is a single file and
|
|
649
|
+
// never reaches any of it.
|
|
650
|
+
const upstream = upstreamCtx.state === 'ok' ? upstreamCtx : null;
|
|
651
|
+
// The PULL is a second, explicit opt-in. Server-side there is no way to tell
|
|
652
|
+
// "the presenter clicked" from "a script in the deck called fetch()" — a
|
|
653
|
+
// page's own script is indistinguishable from its user — so the capability is
|
|
654
|
+
// "a deck served from a clone can update itself from that clone's upstream",
|
|
655
|
+
// which is a thing someone should have typed rather than something the cwd
|
|
656
|
+
// decided. And never with --remote: a phone must not move somebody's repo.
|
|
657
|
+
const pullArmed = Boolean(upstream) && args.includes('--upstream-pull') && !token;
|
|
658
|
+
let upstreamStatus = upstream
|
|
659
|
+
? { state: 'unchecked', branch: upstream.branch, upstream: upstream.upstream, message: 'not checked yet' }
|
|
660
|
+
: { state: upstreamCtx.state, message: suppressed || null };
|
|
661
|
+
let checking = null;
|
|
662
|
+
const intervalMs = resolveInterval(args);
|
|
663
|
+
let lastReported = null;
|
|
664
|
+
const pullOffer = () => (pullArmed
|
|
665
|
+
? { offered: true }
|
|
666
|
+
: { offered: false, reason: !upstream ? upstreamCtx.state : token ? '--remote is on' : 'start with --upstream-pull' });
|
|
667
|
+
|
|
668
|
+
async function refreshUpstream() {
|
|
669
|
+
if (!upstream) return upstreamStatus;
|
|
670
|
+
// Single-flight: a script in a loop must not spawn a hundred fetches.
|
|
671
|
+
if (!checking) {
|
|
672
|
+
checking = checkUpstream(upstream).then((s) => { upstreamStatus = s; checking = null; return s; });
|
|
673
|
+
}
|
|
674
|
+
return checking;
|
|
675
|
+
}
|
|
676
|
+
|
|
456
677
|
const server = createServer(withHeaders({ 'content-security-policy': CSP }, (req, res) => {
|
|
457
678
|
// Loopback always; off-loopback only /remote/* carrying the per-run token,
|
|
458
679
|
// and only when --remote asked for a listener at all. Every other path is
|
|
@@ -487,6 +708,42 @@ export async function presentMain(args, { client } = {}) {
|
|
|
487
708
|
return;
|
|
488
709
|
}
|
|
489
710
|
if (req.method === 'GET' && url.pathname === '/present/events') { decks.add(req, res, CORS); return; }
|
|
711
|
+
// ── the upstream (PRESENT#UPSTREAM) ─────────────────────────────────
|
|
712
|
+
// REGISTERED ONLY when the deck is a tracked file in a clone whose branch
|
|
713
|
+
// tracks something. On a deck you were emailed these are not refused, they
|
|
714
|
+
// do not exist — a POST lands on the same 405 as a POST to anything else,
|
|
715
|
+
// which is the argument the module header already makes about /edit/*.
|
|
716
|
+
//
|
|
717
|
+
// No CORS on either: /present/ping and /present/events carry it because the
|
|
718
|
+
// phone's origin differs, and the phone has no business here in either
|
|
719
|
+
// direction.
|
|
720
|
+
if (upstream && req.method === 'GET' && url.pathname === '/present/upstream') {
|
|
721
|
+
res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-cache' });
|
|
722
|
+
res.end(JSON.stringify({ ok: true, ...upstreamStatus, pull: pullOffer() }));
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (upstream && req.method === 'POST' && url.pathname === '/present/upstream/check') {
|
|
726
|
+
if (!isOwnOrigin(req, actualPort)) { res.writeHead(403); res.end('forbidden'); return; }
|
|
727
|
+
refreshUpstream().then(() => {
|
|
728
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
729
|
+
res.end(JSON.stringify({ ok: true, ...upstreamStatus, pull: pullOffer() }));
|
|
730
|
+
});
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (pullArmed && req.method === 'POST' && url.pathname === '/present/upstream/pull') {
|
|
734
|
+
// The strict gate, not allowEditRequest: `null` is a sandboxed plugin
|
|
735
|
+
// frame's origin, and presenter chrome must not be able to fast-forward
|
|
736
|
+
// the presenter's repository.
|
|
737
|
+
if (!isOwnOrigin(req, actualPort)) { res.writeHead(403); res.end('forbidden'); return; }
|
|
738
|
+
// The body is never read. Not validated — READ. No field of the request
|
|
739
|
+
// reaches git or the filesystem; the repository, the branch and
|
|
740
|
+
// `@{upstream}` are all constants resolved before the server existed.
|
|
741
|
+
doPull().then((out) => {
|
|
742
|
+
res.writeHead(out.ok ? 200 : (out.http ?? 409), { 'content-type': 'application/json' });
|
|
743
|
+
res.end(JSON.stringify(out));
|
|
744
|
+
});
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
490
747
|
// The phone remote: controller, QR, readout channel. These are the only
|
|
491
748
|
// paths allowRemote let through from off this machine, and not one of them
|
|
492
749
|
// writes anything — the phone asks the deck to move, it never edits.
|
|
@@ -526,6 +783,34 @@ export async function presentMain(args, { client } = {}) {
|
|
|
526
783
|
for (const line of formatLabel(report)) console.log(line);
|
|
527
784
|
if (container) console.log(formatManifest(container.manifest));
|
|
528
785
|
console.log(formatSignature(signature));
|
|
786
|
+
// The upstream, said once at startup and then only when it CHANGES. `up to
|
|
787
|
+
// date` every ten minutes for an hour is noise that trains people to stop
|
|
788
|
+
// reading the terminal — which is where the ingredients label lives.
|
|
789
|
+
if (upstream) {
|
|
790
|
+
console.log(` upstream: tracking ${upstream.upstream} — ${intervalMs ? `checking every ${intervalMs / 60000} min` : 'checked when asked'}`
|
|
791
|
+
+ (pullArmed ? ', update control ON (--upstream-pull)' : ''));
|
|
792
|
+
if (!pullArmed && args.includes('--upstream-pull') && token) {
|
|
793
|
+
console.log(' upstream: --remote is on — the update control is off; pull from your own terminal');
|
|
794
|
+
}
|
|
795
|
+
} else if (suppressed) {
|
|
796
|
+
console.log(` upstream: not checked — ${suppressed}`);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// Kicked AFTER the last startup line and never awaited: nothing about this
|
|
800
|
+
// can delay the server coming up or hang a talk on a registry that is down —
|
|
801
|
+
// the cli/update-check.mjs contract, applied to a different remote.
|
|
802
|
+
if (upstream) {
|
|
803
|
+
const tick = () => refreshUpstream().then((st) => {
|
|
804
|
+
if (st.state !== lastReported) {
|
|
805
|
+
lastReported = st.state;
|
|
806
|
+
console.log(` upstream: ${st.message}`);
|
|
807
|
+
}
|
|
808
|
+
}).catch(() => {});
|
|
809
|
+
tick();
|
|
810
|
+
// unref'd so a Ctrl-C exits now rather than after an in-flight fetch.
|
|
811
|
+
// `--upstream-every 0` keeps the manual check and drops only the timer.
|
|
812
|
+
if (intervalMs > 0) setInterval(tick, intervalMs).unref();
|
|
813
|
+
}
|
|
529
814
|
// Reported UNDER the label and never inside it. The label is an inventory of
|
|
530
815
|
// the file; a plugin is not in the file, and folding one into those counts
|
|
531
816
|
// would make the label start describing things the deck does not contain —
|
package/cli/publish.mjs
CHANGED
|
@@ -33,6 +33,8 @@ import path from 'node:path';
|
|
|
33
33
|
import { execFileSync } from 'node:child_process';
|
|
34
34
|
import { makeFail, runMain } from './util.mjs';
|
|
35
35
|
import { isMain } from '../tools/args.mjs';
|
|
36
|
+
import { putBlob, remoteHead } from './git-tree.mjs';
|
|
37
|
+
import { ownerRepo } from './git.mjs';
|
|
36
38
|
import { TARGETS, schemaFor, envVarsFor, envAnswers, deploy } from '../tools/publish-targets.mjs';
|
|
37
39
|
import { checkAnswers } from './wizard.mjs';
|
|
38
40
|
|
|
@@ -47,12 +49,10 @@ const fail = makeFail('publish');
|
|
|
47
49
|
* …/owner/owner.github.io → https://owner.github.io/
|
|
48
50
|
*/
|
|
49
51
|
export function pagesUrl(remoteUrl) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const owner = m[1].toLowerCase();
|
|
55
|
-
const repo = m[2];
|
|
52
|
+
const at = ownerRepo(remoteUrl);
|
|
53
|
+
if (!at) return null;
|
|
54
|
+
const owner = at.owner.toLowerCase();
|
|
55
|
+
const repo = at.repo;
|
|
56
56
|
if (repo.toLowerCase() === `${owner}.github.io`) return `https://${owner}.github.io/`;
|
|
57
57
|
return `https://${owner}.github.io/${repo}/`;
|
|
58
58
|
}
|
|
@@ -255,43 +255,18 @@ if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
|
255
255
|
|
|
256
256
|
// A second publish parents on the branch as the REMOTE has it — fetched
|
|
257
257
|
// fresh, so two machines publishing the same deck append to one history.
|
|
258
|
-
|
|
259
|
-
if (git(['ls-remote', remote, `refs/heads/${branch}`])) {
|
|
260
|
-
git(['fetch', '--quiet', remote, `refs/heads/${branch}`]);
|
|
261
|
-
parent = git(['rev-parse', 'FETCH_HEAD']);
|
|
262
|
-
}
|
|
258
|
+
const parent = remoteHead(git, remote, `refs/heads/${branch}`);
|
|
263
259
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
const mktree = (entries) => {
|
|
270
|
-
// git's tree order: byte-wise, with tree names comparing as "name/"
|
|
271
|
-
const key = (e) => (e.type === 'tree' ? `${e.name}/` : e.name);
|
|
272
|
-
entries.sort((a, b) => (key(a) < key(b) ? -1 : 1));
|
|
273
|
-
return git(['mktree'], entries.map((e) => `${e.mode} ${e.type} ${e.sha}\t${e.name}\n`).join(''));
|
|
274
|
-
};
|
|
275
|
-
// Return a copy of the tree at `treeish` with the blob placed at pathParts,
|
|
276
|
-
// building intermediate trees and keeping every sibling entry.
|
|
277
|
-
const putBlob = (treeish, pathParts, blobSha) => {
|
|
278
|
-
const entries = treeish ? lsTree(treeish) : [];
|
|
279
|
-
const name = pathParts[0];
|
|
280
|
-
const kept = entries.filter((e) => e.name !== name);
|
|
281
|
-
if (pathParts.length === 1) {
|
|
282
|
-
kept.push({ mode: '100644', type: 'blob', sha: blobSha, name });
|
|
283
|
-
} else {
|
|
284
|
-
const sub = entries.find((e) => e.name === name && e.type === 'tree');
|
|
285
|
-
kept.push({ mode: '040000', type: 'tree', sha: putBlob(sub?.sha, pathParts.slice(1), blobSha), name });
|
|
286
|
-
}
|
|
287
|
-
return mktree(kept);
|
|
288
|
-
};
|
|
260
|
+
// The tree builders live in cli/git-tree.mjs now — `review submit` needs the
|
|
261
|
+
// same ones, and neither git's `name/` sort order nor the `--full-tree` scoping
|
|
262
|
+
// bug is a thing to keep two copies of.
|
|
263
|
+
const put = (treeish, parts_, blob) => putBlob(git, treeish, parts_, blob);
|
|
289
264
|
|
|
290
|
-
let tree =
|
|
291
|
-
tree =
|
|
265
|
+
let tree = put(parent, ['.nojekyll'], nojekyllBlob);
|
|
266
|
+
tree = put(tree, [...parts, 'index.html'], pageBlob);
|
|
292
267
|
// Beside the page it covers, under the name a verifier will look for.
|
|
293
|
-
if (sigBlob) tree =
|
|
294
|
-
if (deckBlob) tree =
|
|
268
|
+
if (sigBlob) tree = put(tree, [...parts, 'index.html.sig'], sigBlob);
|
|
269
|
+
if (deckBlob) tree = put(tree, [...parts, 'index.decklight'], deckBlob);
|
|
295
270
|
|
|
296
271
|
const config = (key) => {
|
|
297
272
|
try { return execFileSync('git', ['config', key], { cwd, encoding: 'utf8' }).trim(); }
|
package/cli/record.mjs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Gilles Philippart
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
// decklight record — capture the deck's narration in YOUR voice.
|
|
6
|
+
//
|
|
7
|
+
// decklight record <deck.html> [--port 8788] [--dir voiceover] [--no-open]
|
|
8
|
+
//
|
|
9
|
+
// WHY THIS IS A COMMAND AND NOT JUST A KEY. The recorder itself lives in the
|
|
10
|
+
// deck (⇧R): it has to, because the notes, the builds and the microphone are
|
|
11
|
+
// all in the browser. But a browser will not open a microphone for a page it
|
|
12
|
+
// loaded from `file://` — getUserMedia needs a secure context, and a local file
|
|
13
|
+
// is not one, no matter how many times you click Allow. `http://127.0.0.1` IS
|
|
14
|
+
// one. So this command's whole job is to put the deck on that origin and open
|
|
15
|
+
// it there with the recorder up.
|
|
16
|
+
//
|
|
17
|
+
// The second half of the job is the writing. A recorded take is only useful
|
|
18
|
+
// next to the deck — that is the one place `narration.files` can name and the
|
|
19
|
+
// one place `decklight bundle` looks — and only a server that owns the deck
|
|
20
|
+
// file may write there. That is the edit server, which this runs, in-process:
|
|
21
|
+
// one command, one Ctrl-C, and the files land in the folder the deck already
|
|
22
|
+
// plays from.
|
|
23
|
+
//
|
|
24
|
+
// Deliberately NOT `decklight author`: recording is not editing. Git is off,
|
|
25
|
+
// no bridge is started, nothing is spent. You are reading your own notes aloud.
|
|
26
|
+
|
|
27
|
+
import { editMain } from './edit.mjs';
|
|
28
|
+
import { openUrl } from './init.mjs';
|
|
29
|
+
import { argReader, firstPositional, isMain } from '../tools/args.mjs';
|
|
30
|
+
import { wrongRecorder } from './util.mjs';
|
|
31
|
+
import { exitWhenOrphaned } from './supervise.mjs';
|
|
32
|
+
|
|
33
|
+
const USAGE = `usage: decklight record <deck.html> [--port 8788] [--dir voiceover] [--slides a-b] [--no-open]
|
|
34
|
+
serves the deck over http://127.0.0.1 and opens it with the voice recorder up
|
|
35
|
+
|
|
36
|
+
the deck reads you its notes one ⟨CLICK⟩ beat at a time; → ends a beat, which
|
|
37
|
+
both closes that file and reveals the next build — so your voice paces the
|
|
38
|
+
deck exactly as it will when you present it
|
|
39
|
+
|
|
40
|
+
--port N port to serve on (taken? moves to the next free one) [8788]
|
|
41
|
+
--dir NAME folder to write into, relative to the deck [the deck's own
|
|
42
|
+
narration.files, else voiceover]
|
|
43
|
+
--slides a-b re-record only this range (1-based, inclusive; "7" for one
|
|
44
|
+
slide). Every other slide's files are left untouched, so a
|
|
45
|
+
fluffed beat costs one slide and not the whole deck
|
|
46
|
+
--no-open don't launch a browser — print the URL and wait
|
|
47
|
+
|
|
48
|
+
writes <dir>/slide-NN.wav (the whole slide) and <dir>/slide-NN-KK.wav (one
|
|
49
|
+
per beat); play them back with:
|
|
50
|
+
narration: { files: '<dir>', ext: 'wav', segments: true }
|
|
51
|
+
|
|
52
|
+
a microphone needs a secure context, which is why this serves the deck rather
|
|
53
|
+
than opening the file — and why ⇧R on a file:// deck says so instead of failing
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The folder name the recorder should write into, or null to let the deck
|
|
58
|
+
* decide from its own `narration.files`.
|
|
59
|
+
*
|
|
60
|
+
* Refused here rather than at the server, so a typo costs a message instead of
|
|
61
|
+
* a 400 per beat halfway through a take: the same three shapes the server
|
|
62
|
+
* rejects (absolute, drive-lettered, containing `..`), plus the empty string.
|
|
63
|
+
*/
|
|
64
|
+
export function dirProblem(name) {
|
|
65
|
+
if (name === undefined || name === null) return null;
|
|
66
|
+
if (!name || !name.trim()) return '--dir needs a folder name';
|
|
67
|
+
if (name.length > 200) return '--dir is too long';
|
|
68
|
+
if (/^[/\\]/.test(name) || /^[a-zA-Z]:/.test(name)) {
|
|
69
|
+
return `--dir must be relative to the deck, not an absolute path (${name})`;
|
|
70
|
+
}
|
|
71
|
+
if (name.split(/[/\\]/).includes('..')) {
|
|
72
|
+
return `--dir must stay inside the deck's own directory (${name})`;
|
|
73
|
+
}
|
|
74
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(name)) return `--dir is a folder, not a URL (${name})`;
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The URL to open: the deck, on the server that is running, with `record` set.
|
|
80
|
+
*
|
|
81
|
+
* `?record` rather than a fragment because the runtime reads `location.search`,
|
|
82
|
+
* and rather than a separate page because the deck IS the teleprompter — you
|
|
83
|
+
* record against the slides your audience will see, at the build they will see
|
|
84
|
+
* them at.
|
|
85
|
+
*/
|
|
86
|
+
export function recordUrl(port, deckUrl, dir, slides) {
|
|
87
|
+
const q = ['record',
|
|
88
|
+
...(dir ? [`dir=${encodeURIComponent(dir)}`] : []),
|
|
89
|
+
...(slides ? [`slides=${encodeURIComponent(slides)}`] : [])].join('&');
|
|
90
|
+
return `http://127.0.0.1:${port}${deckUrl}?${q}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `7` or `3-9` → itself; anything else → a message.
|
|
95
|
+
*
|
|
96
|
+
* The deck's own slide count is not known here (the browser has it), so this
|
|
97
|
+
* checks the SHAPE and leaves the bounds to the runtime, which simply records
|
|
98
|
+
* the slides that exist in range. A range past the end records nothing and
|
|
99
|
+
* says so on the card, which is a better answer than a CLI refusing to start.
|
|
100
|
+
*/
|
|
101
|
+
export function slidesProblem(range) {
|
|
102
|
+
if (range === undefined || range === null) return null;
|
|
103
|
+
const m = /^(\d+)(?:-(\d+))?$/.exec(String(range).trim());
|
|
104
|
+
if (!m) return `--slides must be a-b or a single slide number (got "${range}")`;
|
|
105
|
+
const from = Number(m[1]);
|
|
106
|
+
const to = m[2] ? Number(m[2]) : from;
|
|
107
|
+
if (from < 1) return '--slides is 1-based — there is no slide 0';
|
|
108
|
+
if (to < from) return `--slides ${range} ends before it starts`;
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function recordMain(args, { open = openUrl, out = process.stdout, onListen = null } = {}) {
|
|
113
|
+
if (args.includes('--help') || args.includes('-h') || !args.filter((a) => !a.startsWith('-')).length) {
|
|
114
|
+
out.write(USAGE);
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
const { opt } = argReader(args);
|
|
118
|
+
const dir = opt('--dir');
|
|
119
|
+
const slides = opt('--slides');
|
|
120
|
+
for (const bad of [dirProblem(dir), slidesProblem(slides)]) {
|
|
121
|
+
if (bad) { process.stderr.write(`decklight record: ${bad}\n`); return 2; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const deck = firstPositional(args, ['--dir', '--slides', '--port']);
|
|
125
|
+
// Before the server, not after: this used to serve the YAML file, print a
|
|
126
|
+
// URL and open a browser on it, with no error anywhere.
|
|
127
|
+
const mixedUp = wrongRecorder('record', deck);
|
|
128
|
+
if (mixedUp) { process.stderr.write(`decklight record: ${mixedUp}\n`); return 2; }
|
|
129
|
+
let started;
|
|
130
|
+
// `--no-git`, always: recording is not editing, and a take that happens to
|
|
131
|
+
// coincide with the autocommit cadence has no business creating a commit.
|
|
132
|
+
await editMain([deck, '--port', String(opt('--port', 8788)), '--no-git'], {
|
|
133
|
+
// the same seam editMain offers, passed through: this server outlives the
|
|
134
|
+
// call (it is the whole point), so a caller that is not a terminal — a
|
|
135
|
+
// test — needs a handle to close it
|
|
136
|
+
onListen: (info) => { started = info; onListen?.(info); },
|
|
137
|
+
});
|
|
138
|
+
// editMain reports its own reason and sets process.exitCode when the deck is
|
|
139
|
+
// missing or outside the served root — say nothing on top of it.
|
|
140
|
+
if (!started) return process.exitCode ?? 1;
|
|
141
|
+
|
|
142
|
+
const url = recordUrl(started.port, started.deckUrl, dir, slides);
|
|
143
|
+
out.write(`decklight record on ${url}\n`);
|
|
144
|
+
out.write(' ⇧R opens the recorder · → ends a beat and reveals the next build · Esc stops\n');
|
|
145
|
+
out.write(` files land in ${dir ?? "the deck's narration folder"}, next to the deck.`
|
|
146
|
+
+ `${slides ? ` Only slide${/-/.test(slides) ? 's' : ''} ${slides}.` : ''} Ctrl-C when you are done.\n`);
|
|
147
|
+
if (!args.includes('--no-open')) await open(url, { out, what: url });
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (isMain(import.meta.url)) {
|
|
152
|
+
exitWhenOrphaned();
|
|
153
|
+
recordMain(process.argv.slice(2)).then((code) => { if (code) process.exitCode = code; });
|
|
154
|
+
}
|