decklight 0.6.0 → 0.8.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 +23 -11
- package/SPEC.md +187 -23
- package/cli/agents.mjs +52 -2
- package/cli/associate.mjs +2 -2
- package/cli/banner.mjs +125 -0
- package/cli/bundle.mjs +15 -5
- 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 +125 -0
- package/cli/decklight.mjs +96 -25
- package/cli/dev.mjs +159 -13
- package/cli/edit.mjs +981 -40
- package/cli/git-tree.mjs +87 -0
- package/cli/git.mjs +22 -0
- package/cli/import.mjs +41 -11
- package/cli/init.mjs +37 -5
- package/cli/pdf.mjs +59 -14
- package/cli/port-conflict.mjs +187 -16
- package/cli/pptx-export.mjs +107 -0
- package/cli/present.mjs +8 -4
- package/cli/publish.mjs +25 -42
- package/cli/record.mjs +154 -0
- 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 +36 -1
- package/cli/skill-content.mjs +4 -1
- package/cli/units.mjs +2 -2
- package/cli/util.mjs +59 -0
- package/dist/build-info.json +1 -0
- package/dist/decklight.css +254 -1
- package/dist/decklight.js +153 -79
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +10 -3
- package/package.json +3 -1
- package/tools/args.mjs +20 -0
- package/tools/bridge.mjs +25 -2
- package/tools/deck-html.mjs +59 -0
- package/tools/elevenlabs-tts.mjs +3 -3
- package/tools/exec.mjs +54 -0
- package/tools/gemini-tts.mjs +4 -4
- package/tools/lipsync-server.mjs +70 -2
- package/tools/lipsync.mjs +46 -30
- package/tools/local-voice.mjs +243 -19
- package/tools/pptx-write.mjs +151 -0
- package/tools/pptx.mjs +82 -2
- package/tools/publish-site-voices.mjs +2 -2
- package/tools/publish-targets.mjs +39 -2
- package/tools/publish-voices.mjs +80 -20
- package/tools/recording-impact.mjs +110 -0
- package/tools/review-anchor.mjs +180 -0
- package/tools/template-theme.mjs +154 -0
- package/tools/test-impact.mjs +266 -0
- package/tools/tts-cache.mjs +191 -0
- package/tools/tts-engines.mjs +85 -8
- package/tools/tts-setup.mjs +4 -3
- package/tools/video.mjs +21 -6
- package/tools/voiceover-server.mjs +163 -17
- package/tools/voiceover.mjs +124 -16
package/cli/port-conflict.mjs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// that child's stdin is closed (piped, not a TTY), so it could never ask.
|
|
15
15
|
|
|
16
16
|
import { createConnection, createServer } from 'node:net';
|
|
17
|
+
import { execFileSync } from 'node:child_process';
|
|
17
18
|
|
|
18
19
|
/** Is something listening on `port`? Port 0 ("OS picks one") never conflicts. */
|
|
19
20
|
export function isPortOpen(port, host = '127.0.0.1', timeout = 400) {
|
|
@@ -38,6 +39,55 @@ export async function identifyEditServer(port, host = '127.0.0.1') {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The same question for a BRIDGE — the voice and lip-sync servers answer
|
|
44
|
+
* `/ping`, not `/edit/ping`, so an edit-server probe reports them as strangers
|
|
45
|
+
* and the offer to take the port over never appears.
|
|
46
|
+
*
|
|
47
|
+
* Returns the same shape the caller already handles: something with a `name`
|
|
48
|
+
* to put in a sentence.
|
|
49
|
+
*/
|
|
50
|
+
export async function identifyBridge(port, host = '127.0.0.1') {
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(`http://${host}:${port}/ping`, { signal: AbortSignal.timeout(800) });
|
|
53
|
+
if (!res.ok) return null;
|
|
54
|
+
const d = await res.json();
|
|
55
|
+
if (!d?.ok) return null;
|
|
56
|
+
// tts answers with an engine, lipsync with its own shape; either way the
|
|
57
|
+
// point is that a decklight bridge is there and can be asked to stop.
|
|
58
|
+
return { ...d, bridge: true, name: d.engine ? `the ${d.engine} voice bridge` : 'a decklight bridge' };
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Who holds this port, when it is NOT one of ours.
|
|
66
|
+
*
|
|
67
|
+
* This file's whole premise was "ask it over HTTP, never guess at a PID — no
|
|
68
|
+
* lsof, no platform split", and that is still right for anything decklight can
|
|
69
|
+
* stop cleanly. But it left the commonest real case mute: a stranger's process
|
|
70
|
+
* on the port produced a bare "using a different port", or — for the bridges,
|
|
71
|
+
* which never called any of this — a raw EADDRINUSE stack trace.
|
|
72
|
+
*
|
|
73
|
+
* So a stranger gets NAMED, best effort, and only to put in a question. `lsof`
|
|
74
|
+
* is macOS/Linux; Windows and a missing lsof simply return null and the caller
|
|
75
|
+
* falls back to moving ports, which is what it did before.
|
|
76
|
+
*/
|
|
77
|
+
export function identifyStranger(port, { exec = null } = {}) {
|
|
78
|
+
if (process.platform === 'win32') return null;
|
|
79
|
+
try {
|
|
80
|
+
const run = exec ?? ((cmd, args) => execFileSync(cmd, args, { encoding: 'utf8', timeout: 2000 }));
|
|
81
|
+
const out = run('lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-F', 'pc']);
|
|
82
|
+
// `-F pc` prints `p<pid>` and `c<command>` on their own lines
|
|
83
|
+
const pid = /^p(\d+)$/m.exec(out)?.[1];
|
|
84
|
+
const command = /^c(.+)$/m.exec(out)?.[1];
|
|
85
|
+
return pid ? { pid: Number(pid), command: command ?? 'an unknown process' } : null;
|
|
86
|
+
} catch {
|
|
87
|
+
return null; // no lsof, no permission, nothing listening — all "we cannot say"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
41
91
|
/** Ask it to stop — it auto-commits and exits, same as its own Ctrl-C. Resolves once the port is free. */
|
|
42
92
|
export async function shutdownEditServer(port, host = '127.0.0.1') {
|
|
43
93
|
try {
|
|
@@ -94,35 +144,156 @@ export async function nextFreePort(port, host = '127.0.0.1', tries = 64) {
|
|
|
94
144
|
/**
|
|
95
145
|
* Pure: what to do about a taken port — testable without a socket or a
|
|
96
146
|
* terminal. Only offers to kill an occupant we can actually identify AND
|
|
97
|
-
* only when something can be asked
|
|
147
|
+
* only when something can be asked.
|
|
148
|
+
*
|
|
149
|
+
* A BRIDGE MAY NEVER MOVE, and that is the whole reason `kind` exists. The
|
|
150
|
+
* two servers fail differently because only one of them gets to announce
|
|
151
|
+
* where it landed:
|
|
152
|
+
*
|
|
153
|
+
* the EDIT server hands its address to a human. It prints the URL it
|
|
154
|
+
* actually bound and you open that one, so bumping costs nothing.
|
|
155
|
+
*
|
|
156
|
+
* a BRIDGE hands its address to nobody. The deck does not discover the
|
|
157
|
+
* bridge, it ASSUMES it: `src/core/narration.js` hardcodes
|
|
158
|
+
* `http://127.0.0.1:8787/tts` (and derives /ping, /engines, /voices from
|
|
159
|
+
* it), `src/core/character.js` hardcodes `:8789`, and the only override is
|
|
160
|
+
* a `liveUrl`/`bridgeUrl` written into the deck itself. author passes
|
|
161
|
+
* `--tts-port` to the bridge process and never tells the deck — it could
|
|
162
|
+
* not tell it anyway, since the deck is served verbatim and is as often
|
|
163
|
+
* opened over `file://`. The two sides agree only because both default to
|
|
164
|
+
* the same literal.
|
|
165
|
+
*
|
|
166
|
+
* So a bridge that bumps is a bridge nobody is talking to: the deck keeps
|
|
167
|
+
* knocking on 8787, reaches whatever squats there, and reports no live voice
|
|
168
|
+
* with nothing on screen to explain it. That is strictly worse than the
|
|
169
|
+
* EADDRINUSE crash this replaced — the crash at least said something. A
|
|
170
|
+
* bridge therefore either takes ITS port, or stands aside for the bridge
|
|
171
|
+
* already serving it (`reuse`), or declines to start and says why
|
|
172
|
+
* (`refuse`).
|
|
98
173
|
*/
|
|
99
|
-
export function planPortConflict({ tty = false, identified = null } = {}) {
|
|
100
|
-
|
|
174
|
+
export function planPortConflict({ tty = false, identified = null, stranger = null, kind = 'edit' } = {}) {
|
|
175
|
+
// What happens with no terminal — and what a DECLINED offer falls back to.
|
|
176
|
+
const fallback = kind !== 'bridge' ? 'bump' // an edit server announces itself
|
|
177
|
+
: identified ? 'reuse' // ours, already answering: use it
|
|
178
|
+
: 'refuse'; // a bridge off its port is a lie
|
|
179
|
+
if (!tty) return fallback; // never kill anything unattended
|
|
180
|
+
if (identified) return 'ask'; // ours: offer a CLEAN shutdown
|
|
181
|
+
if (stranger) return 'ask-stranger'; // somebody else's: offer, never assume
|
|
182
|
+
return fallback; // nothing we can name
|
|
101
183
|
}
|
|
102
184
|
|
|
103
185
|
/**
|
|
104
186
|
* The port is already bound. Work out who's there and either take it over or
|
|
105
|
-
*
|
|
106
|
-
* to ask,
|
|
187
|
+
* step aside. `ask` is `(prompt) => Promise<string>`; its absence means no
|
|
188
|
+
* TTY to ask on, and nothing is ever killed without one.
|
|
189
|
+
*
|
|
190
|
+
* Returns the port to bind, or **null meaning "do not listen at all"** — a
|
|
191
|
+
* bridge whose port is spoken for, which cannot just move (see
|
|
192
|
+
* planPortConflict). `kind: 'edit'` never returns null, so the two existing
|
|
193
|
+
* callers are unaffected.
|
|
107
194
|
*/
|
|
108
|
-
export async function resolvePortConflict(port, {
|
|
109
|
-
|
|
110
|
-
|
|
195
|
+
export async function resolvePortConflict(port, {
|
|
196
|
+
host = '127.0.0.1', ask, log = () => {}, kind = 'edit', stranger = identifyStranger,
|
|
197
|
+
identify = null,
|
|
198
|
+
} = {}) {
|
|
199
|
+
// Ours, whichever kind: an edit server answers /edit/ping, a bridge answers
|
|
200
|
+
// /ping. Asking only the first reported every bridge as a stranger.
|
|
201
|
+
//
|
|
202
|
+
// Injectable for the same reason `stranger` is: this REALLY CONNECTS to the
|
|
203
|
+
// port, so a test naming a plausible number is at the mercy of whatever the
|
|
204
|
+
// developer happens to be running. That is not hypothetical — the refusal
|
|
205
|
+
// test named 8787, and passed everywhere except on a machine with a live
|
|
206
|
+
// voice bridge on it, which is every machine this feature is for.
|
|
207
|
+
const whoIsThere = identify ?? ((p, h) => (kind === 'bridge'
|
|
208
|
+
? identifyBridge(p, h)
|
|
209
|
+
: identifyEditServer(p, h).then((e) => e ?? identifyBridge(p, h))));
|
|
210
|
+
const identified = await whoIsThere(port, host);
|
|
211
|
+
const other = identified ? null : stranger(port);
|
|
212
|
+
const action = planPortConflict({ tty: Boolean(ask), identified, stranger: other, kind });
|
|
111
213
|
|
|
112
|
-
|
|
113
|
-
|
|
214
|
+
// Somebody ELSE's process. decklight cannot ask it to stop the way it asks
|
|
215
|
+
// its own — there is no endpoint to POST to — so the only lever is a signal,
|
|
216
|
+
// and a signal is not something to send on decklight's own judgement: that
|
|
217
|
+
// process may be a dev server with unsaved work in it. Named, offered, and
|
|
218
|
+
// DEFAULTED TO THE HARMLESS ANSWER, so the destructive one is only ever
|
|
219
|
+
// reached by typing it.
|
|
220
|
+
let named = false; // the occupant is worth naming once, not once per branch
|
|
221
|
+
if (action === 'ask-stranger') {
|
|
222
|
+
log(` port ${port} is held by ${other.command} (pid ${other.pid}) — not a decklight server`);
|
|
223
|
+
named = true;
|
|
224
|
+
// The alternative to killing is NOT the same for both kinds, so it must not
|
|
225
|
+
// be worded the same: an edit server moves, a bridge does not get to.
|
|
226
|
+
const or = kind === 'bridge' ? '[c]arry on without this bridge? [k/C]' : 'use a [d]ifferent port? [k/D]';
|
|
227
|
+
const answer = (await ask(` [k]ill pid ${other.pid} and take the port, or ${or} `)).trim().toLowerCase();
|
|
228
|
+
if (answer.startsWith('k')) {
|
|
229
|
+
try {
|
|
230
|
+
process.kill(other.pid, 'SIGTERM');
|
|
231
|
+
for (let i = 0; i < 30 && (await isPortOpen(port, host)); i++) await new Promise((r) => setTimeout(r, 100));
|
|
232
|
+
if (!(await isPortOpen(port, host))) { log(` stopped pid ${other.pid}`); return port; }
|
|
233
|
+
log(' it did not stop in time — using a different port instead');
|
|
234
|
+
} catch (e) {
|
|
235
|
+
log(` could not stop pid ${other.pid} (${e.code ?? e.message}) — using a different port instead`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
} else if (action === 'ask') {
|
|
239
|
+
log(identified.bridge
|
|
240
|
+
? ` port ${port} is already in use — ${identified.name} is running there`
|
|
241
|
+
: ` port ${port} is already in use — decklight is editing "${identified.name}" there`);
|
|
114
242
|
const answer = (await ask(' [k]ill that session and take it over, or use a [d]ifferent port? [k/D] ')).trim().toLowerCase();
|
|
115
243
|
if (answer.startsWith('k')) {
|
|
116
|
-
log(` stopping the session editing "${identified.name}"…`);
|
|
117
|
-
|
|
244
|
+
log(` stopping ${identified.bridge ? identified.name : `the session editing "${identified.name}"`}…`);
|
|
245
|
+
// An edit server is asked to stop, because it has a final autocommit to
|
|
246
|
+
// make and losing that would be losing work. A BRIDGE has no such
|
|
247
|
+
// endpoint and nothing to lose — it is a stateless synthesiser — so it
|
|
248
|
+
// gets a signal, using the pid the stranger lookup finds. Without a pid
|
|
249
|
+
// (Windows, no lsof) there is nothing to do but move ports, which is
|
|
250
|
+
// exactly what happens.
|
|
251
|
+
if (!identified.bridge) {
|
|
252
|
+
if (await shutdownEditServer(port, host)) return port;
|
|
253
|
+
} else {
|
|
254
|
+
const who = stranger(port);
|
|
255
|
+
if (who) {
|
|
256
|
+
try {
|
|
257
|
+
process.kill(who.pid, 'SIGTERM');
|
|
258
|
+
for (let i = 0; i < 30 && (await isPortOpen(port, host)); i++) await new Promise((r) => setTimeout(r, 100));
|
|
259
|
+
if (!(await isPortOpen(port, host))) return port;
|
|
260
|
+
} catch { /* fall through to the bump */ }
|
|
261
|
+
}
|
|
262
|
+
}
|
|
118
263
|
log(" it didn't stop in time — using a different port instead");
|
|
119
264
|
}
|
|
120
|
-
} else {
|
|
121
|
-
log(identified
|
|
122
|
-
? ` port ${port} is already in use — decklight is editing "${identified.name}" there; using a different port`
|
|
123
|
-
: ` port ${port} is already in use; using a different port`);
|
|
124
265
|
}
|
|
125
266
|
|
|
267
|
+
// Whatever was offered was declined, or there was nobody to ask. How that
|
|
268
|
+
// ends is the caller's kind, not this function's mood.
|
|
269
|
+
const ending = planPortConflict({ tty: false, identified, stranger: other, kind });
|
|
270
|
+
|
|
271
|
+
// Ours, and already doing the job. A second bridge would bind a port the
|
|
272
|
+
// deck never calls, so the useful move is to stand aside and say so: null
|
|
273
|
+
// means "do not listen", and the one on `port` serves the deck as before.
|
|
274
|
+
if (ending === 'reuse') {
|
|
275
|
+
log(` port ${port} already has ${identified.name} on it — using that one rather than starting a second`);
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Somebody else's, and a bridge cannot work anywhere but here. Say who has
|
|
280
|
+
// it and both ways out, then decline: author reports the bridge as gone and
|
|
281
|
+
// the deck degrades honestly, which beats a live voice that fails silently.
|
|
282
|
+
if (ending === 'refuse') {
|
|
283
|
+
if (!named) {
|
|
284
|
+
log(other
|
|
285
|
+
? ` port ${port} is held by ${other.command} (pid ${other.pid}) — not a decklight bridge`
|
|
286
|
+
: ` port ${port} is already in use`);
|
|
287
|
+
}
|
|
288
|
+
log(` the deck asks for this bridge on ${port} and nowhere else, so it will not start.`);
|
|
289
|
+
log(` free the port (kill ${other ? other.pid : 'the process holding it'}), or move BOTH sides:`);
|
|
290
|
+
log(` run with --port N and set narration.liveUrl in the deck to match.`);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
log(identified
|
|
295
|
+
? ` port ${port} is already in use — ${identified.bridge ? identified.name : `decklight is editing "${identified.name}"`} there; using a different port`
|
|
296
|
+
: ` port ${port} is already in use; using a different port`);
|
|
126
297
|
const next = await nextFreePort(port + 1, host);
|
|
127
298
|
log(` → using port ${next}`);
|
|
128
299
|
return next;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// decklight pptx — a deck as a PowerPoint file, lossy on purpose.
|
|
5
|
+
//
|
|
6
|
+
// Each slide is rendered by a one-shot headless Chrome at its own 1280×720
|
|
7
|
+
// with every build complete (the mechanism tools/video.mjs and tools/shot.mjs
|
|
8
|
+
// use), and becomes one picture filling one 16:9 page; the speaker notes ride
|
|
9
|
+
// along as real notes. Nothing round-trips — see tools/pptx-write.mjs for why
|
|
10
|
+
// that is the design and not a gap.
|
|
11
|
+
|
|
12
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, statSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { basename, join, relative, resolve, sep } from 'node:path';
|
|
15
|
+
import { chromeBin, chromeArgs } from '../tools/chrome.mjs';
|
|
16
|
+
import { argReader } from '../tools/args.mjs';
|
|
17
|
+
import { run, CODEC_MS } from '../tools/exec.mjs';
|
|
18
|
+
import { NOTES_ASIDE, cleanNotes, sectionBodies } from '../tools/deck-html.mjs';
|
|
19
|
+
import { buildPptx } from '../tools/pptx-write.mjs';
|
|
20
|
+
import { serveForRender } from './present.mjs';
|
|
21
|
+
|
|
22
|
+
const USAGE = `usage: decklight pptx <deck.html> [-o out.pptx] [--theme <name>] [--wait <ms>]
|
|
23
|
+
writes a PowerPoint file: every slide as a picture, rendered at 1280×720 with
|
|
24
|
+
its builds complete, and its speaker notes as real notes
|
|
25
|
+
|
|
26
|
+
-o <file> output path [the deck's, with .pptx]
|
|
27
|
+
--theme <name> export in another theme (rides ?theme=)
|
|
28
|
+
--wait <ms> render budget per slide [1500]
|
|
29
|
+
|
|
30
|
+
Lossy by design: the file OPENS in PowerPoint, Keynote and Slides, and the
|
|
31
|
+
notes are text there — but the slides are pictures. Import it back and you
|
|
32
|
+
get pictures. Decklight is for people who never liked PowerPoint; this is
|
|
33
|
+
for the people around them who still ask for the file.`;
|
|
34
|
+
|
|
35
|
+
/** The deck's path with .pptx in place of .html — or whatever -o said. */
|
|
36
|
+
export const pptxOut = (deckPath, oFlag) => (oFlag ? resolve(oFlag) : resolve(deckPath.replace(/\.html?$/i, '') + '.pptx'));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Speaker notes per slide, as lines. Paragraphs and line breaks become lines,
|
|
40
|
+
* tags fall away, entities come back — the same reading the voiceover and
|
|
41
|
+
* the speaker view give the aside, so what PowerPoint shows is what the
|
|
42
|
+
* presenter saw.
|
|
43
|
+
*/
|
|
44
|
+
export function notesLines(html) {
|
|
45
|
+
return sectionBodies(html).map((sec) => {
|
|
46
|
+
const m = sec.match(NOTES_ASIDE);
|
|
47
|
+
if (!m) return [];
|
|
48
|
+
return m[1].split(/<\/p>|<br\s*\/?>|\n{2,}/i).map((part) => cleanNotes(part)).filter(Boolean);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The deck's <title>, else its file name. */
|
|
53
|
+
const titleOf = (html, file) => cleanNotes(/<title>([\s\S]*?)<\/title>/i.exec(html)?.[1] ?? '') || basename(file).replace(/\.html?$/i, '');
|
|
54
|
+
|
|
55
|
+
async function chromeShot(bin, argv) {
|
|
56
|
+
run(bin, argv, { maxBuffer: 32 * 1024 * 1024, timeout: CODEC_MS, why: 'Chrome did not finish rendering a slide — it is probably waiting on a resource it cannot reach' });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function pptxMain(args = [], { render = chromeShot, log = console.error } = {}) {
|
|
60
|
+
if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
|
|
61
|
+
const { opt } = argReader(args);
|
|
62
|
+
const deck = args.find((a) => !a.startsWith('-') && /\.html?$/i.test(a));
|
|
63
|
+
if (!deck) { log(`decklight pptx: needs a deck\n\n${USAGE}`); return 1; }
|
|
64
|
+
const src = resolve(deck);
|
|
65
|
+
if (!existsSync(src)) { log(`decklight pptx: no such deck: ${deck}`); return 1; }
|
|
66
|
+
const root = process.cwd();
|
|
67
|
+
if (src !== root && !src.startsWith(root + sep)) {
|
|
68
|
+
log(`decklight pptx: the deck must live under the current directory (${root}) — cd there first`);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const out = pptxOut(src, opt('-o'));
|
|
72
|
+
const wait = Number(opt('--wait', 1500));
|
|
73
|
+
const theme = opt('--theme');
|
|
74
|
+
const html = readFileSync(src, 'utf8');
|
|
75
|
+
const notes = notesLines(html);
|
|
76
|
+
const count = notes.length;
|
|
77
|
+
if (!count) { log('decklight pptx: the deck has no <section> slides'); return 1; }
|
|
78
|
+
|
|
79
|
+
// served, not file://, so every relative asset the deck names still resolves
|
|
80
|
+
const inject = (text, file) => (file === src && theme ? text.replace(/(<\/head>)/i, `<link rel="stylesheet" href="themes/${theme}.css">$1`) : text);
|
|
81
|
+
const server = await serveForRender(root, { html: inject });
|
|
82
|
+
const scratch = mkdtempSync(join(tmpdir(), 'decklight-pptx-'));
|
|
83
|
+
const slides = [];
|
|
84
|
+
try {
|
|
85
|
+
const deckPath = '/' + relative(root, src).split(sep).join('/');
|
|
86
|
+
const bin = chromeBin('pptx');
|
|
87
|
+
log(`pptx: rendering ${basename(src)} — ${count} slides at 1280×720, builds complete`);
|
|
88
|
+
for (let n = 1; n <= count; n++) {
|
|
89
|
+
const png = join(scratch, `slide-${n}.png`);
|
|
90
|
+
// /999 lands on the last build step, whatever the slide has
|
|
91
|
+
await render(bin, chromeArgs(
|
|
92
|
+
'--hide-scrollbars', '--window-size=1280,720', `--virtual-time-budget=${wait}`,
|
|
93
|
+
`--screenshot=${png}`, `${server.origin}${deckPath}#/${n}/999`,
|
|
94
|
+
), { n, png });
|
|
95
|
+
if (!existsSync(png) || statSync(png).size === 0) { log(`decklight pptx: slide ${n} did not render — try a longer --wait`); return 1; }
|
|
96
|
+
slides.push({ png: readFileSync(png), notes: notes[n - 1] });
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
await server.close();
|
|
100
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
const bytes = buildPptx(slides, { title: titleOf(html, src) });
|
|
103
|
+
writeFileSync(out, bytes);
|
|
104
|
+
const withNotes = notes.filter((l) => l.length).length;
|
|
105
|
+
console.log(`${out} · ${count} slides as pictures · ${withNotes} with notes · ${Math.round(bytes.length / 1024)} KB`);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
package/cli/present.mjs
CHANGED
|
@@ -34,7 +34,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
34
34
|
import { argReader, isMain } from '../tools/args.mjs';
|
|
35
35
|
import { allowRemote, lanAddress, staticFiles, sseChannel, listenTakingOverIfNeeded, withHeaders, isOwnOrigin } from './serve.mjs';
|
|
36
36
|
import { createRemoteRelay } from './remote.mjs';
|
|
37
|
-
import { corsHeaders } from '../tools/bridge.mjs';
|
|
37
|
+
import { corsHeaders, readBody } from '../tools/bridge.mjs';
|
|
38
38
|
|
|
39
39
|
// The phone is a different origin from the deck (a LAN address, not localhost),
|
|
40
40
|
// so the remote's own endpoints need CORS. Nothing else here does — the deck is
|
|
@@ -749,8 +749,12 @@ export async function presentMain(args, { client } = {}) {
|
|
|
749
749
|
// writes anything — the phone asks the deck to move, it never edits.
|
|
750
750
|
let body = '';
|
|
751
751
|
if (req.method === 'POST') {
|
|
752
|
-
|
|
753
|
-
|
|
752
|
+
// bridge.mjs's reader with the cap this route has always had: the phone
|
|
753
|
+
// remote is the one path reachable from off this machine, and a body
|
|
754
|
+
// past 4 KB is a probe, not a request — the socket is destroyed and the
|
|
755
|
+
// E2BIG never becomes a response
|
|
756
|
+
readBody(req, { max: 4096 }).then((bytes) => {
|
|
757
|
+
body = bytes.toString();
|
|
754
758
|
try {
|
|
755
759
|
if (relay.handle(req, res, url, body)) return;
|
|
756
760
|
} catch {
|
|
@@ -760,7 +764,7 @@ export async function presentMain(args, { client } = {}) {
|
|
|
760
764
|
}
|
|
761
765
|
res.writeHead(405);
|
|
762
766
|
res.end('method not allowed');
|
|
763
|
-
});
|
|
767
|
+
}).catch(() => { /* E2BIG: destroyed above; anything else: the socket is gone */ });
|
|
764
768
|
return;
|
|
765
769
|
}
|
|
766
770
|
if (relay.handle(req, res, url, '')) return;
|
package/cli/publish.mjs
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* decklight publish <deck.html> [--branch gh-pages] [--remote origin]
|
|
9
9
|
* [--no-bundle] [--no-sign] [--path <subdir>]
|
|
10
|
-
* [--target gh-pages|netlify|vercel]
|
|
10
|
+
* [--target gh-pages|netlify|vercel|folder]
|
|
11
|
+
[--out <dir> [--url <public-url>]]
|
|
11
12
|
*
|
|
12
13
|
* Bundles the deck (via `decklight bundle`) to index.html + .nojekyll and
|
|
13
14
|
* pushes them to a gh-pages branch on the remote, then prints the GitHub
|
|
@@ -33,6 +34,8 @@ import path from 'node:path';
|
|
|
33
34
|
import { execFileSync } from 'node:child_process';
|
|
34
35
|
import { makeFail, runMain } from './util.mjs';
|
|
35
36
|
import { isMain } from '../tools/args.mjs';
|
|
37
|
+
import { putBlob, remoteHead } from './git-tree.mjs';
|
|
38
|
+
import { ownerRepo } from './git.mjs';
|
|
36
39
|
import { TARGETS, schemaFor, envVarsFor, envAnswers, deploy } from '../tools/publish-targets.mjs';
|
|
37
40
|
import { checkAnswers } from './wizard.mjs';
|
|
38
41
|
|
|
@@ -47,12 +50,10 @@ const fail = makeFail('publish');
|
|
|
47
50
|
* …/owner/owner.github.io → https://owner.github.io/
|
|
48
51
|
*/
|
|
49
52
|
export function pagesUrl(remoteUrl) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const owner = m[1].toLowerCase();
|
|
55
|
-
const repo = m[2];
|
|
53
|
+
const at = ownerRepo(remoteUrl);
|
|
54
|
+
if (!at) return null;
|
|
55
|
+
const owner = at.owner.toLowerCase();
|
|
56
|
+
const repo = at.repo;
|
|
56
57
|
if (repo.toLowerCase() === `${owner}.github.io`) return `https://${owner}.github.io/`;
|
|
57
58
|
return `https://${owner}.github.io/${repo}/`;
|
|
58
59
|
}
|
|
@@ -87,9 +88,12 @@ Options:
|
|
|
87
88
|
is the file a visitor downloads and forwards
|
|
88
89
|
--path <subdir> publish under a subdirectory of the site (other content
|
|
89
90
|
on the branch is preserved)
|
|
90
|
-
--target <name> gh-pages (default, no credential) | netlify | vercel
|
|
91
|
+
--target <name> gh-pages (default, no credential) | netlify | vercel | folder
|
|
91
92
|
netlify needs NETLIFY_AUTH_TOKEN + NETLIFY_SITE_ID
|
|
92
93
|
vercel needs VERCEL_TOKEN + VERCEL_PROJECT (+ VERCEL_TEAM_ID)
|
|
94
|
+
folder writes the site into --out <dir> (or DECKLIGHT_PUBLISH_DIR)
|
|
95
|
+
for ANY static host — rsync it, S3-sync it, drop it on a share;
|
|
96
|
+
--url <base> (or DECKLIGHT_PUBLISH_URL) is printed as the link
|
|
93
97
|
|
|
94
98
|
Publishing SIGNS by default: Sigstore keyless mints a short-lived certificate
|
|
95
99
|
against an OIDC identity — the ambient token in CI (GitHub Actions
|
|
@@ -117,6 +121,10 @@ for (let i = 0; i < argv.length; i++) {
|
|
|
117
121
|
else if (a === '--deck') deckFile = true;
|
|
118
122
|
else if (a === '--path') subdir = argv[++i];
|
|
119
123
|
else if (a === '--target') target = argv[++i];
|
|
124
|
+
// the folder target's two answers, as flags — a directory is not a secret,
|
|
125
|
+
// and typing it beats exporting an environment variable for a one-off
|
|
126
|
+
else if (a === '--out') process.env.DECKLIGHT_PUBLISH_DIR = argv[++i];
|
|
127
|
+
else if (a === '--url') process.env.DECKLIGHT_PUBLISH_URL = argv[++i];
|
|
120
128
|
else if (!a.startsWith('-') && !deck) deck = a;
|
|
121
129
|
else fail(`unknown argument: ${a}`);
|
|
122
130
|
}
|
|
@@ -255,43 +263,18 @@ if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
|
255
263
|
|
|
256
264
|
// A second publish parents on the branch as the REMOTE has it — fetched
|
|
257
265
|
// 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
|
-
}
|
|
266
|
+
const parent = remoteHead(git, remote, `refs/heads/${branch}`);
|
|
263
267
|
|
|
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
|
-
};
|
|
268
|
+
// The tree builders live in cli/git-tree.mjs now — `review submit` needs the
|
|
269
|
+
// same ones, and neither git's `name/` sort order nor the `--full-tree` scoping
|
|
270
|
+
// bug is a thing to keep two copies of.
|
|
271
|
+
const put = (treeish, parts_, blob) => putBlob(git, treeish, parts_, blob);
|
|
289
272
|
|
|
290
|
-
let tree =
|
|
291
|
-
tree =
|
|
273
|
+
let tree = put(parent, ['.nojekyll'], nojekyllBlob);
|
|
274
|
+
tree = put(tree, [...parts, 'index.html'], pageBlob);
|
|
292
275
|
// Beside the page it covers, under the name a verifier will look for.
|
|
293
|
-
if (sigBlob) tree =
|
|
294
|
-
if (deckBlob) tree =
|
|
276
|
+
if (sigBlob) tree = put(tree, [...parts, 'index.html.sig'], sigBlob);
|
|
277
|
+
if (deckBlob) tree = put(tree, [...parts, 'index.decklight'], deckBlob);
|
|
295
278
|
|
|
296
279
|
const config = (key) => {
|
|
297
280
|
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 (V → Record this deck… → With your voice…): 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 the recorder 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(' V → Record this deck… → With your voice… 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
|
+
}
|