decklight 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +202 -21
  2. package/README.md +61 -177
  3. package/SPEC.md +20 -8
  4. package/cli/agents.mjs +102 -0
  5. package/cli/bundle.mjs +37 -0
  6. package/cli/decklight.mjs +18 -0
  7. package/cli/dev.mjs +266 -0
  8. package/cli/edit.mjs +230 -17
  9. package/cli/init.mjs +58 -19
  10. package/cli/rec.mjs +7 -0
  11. package/dist/decklight.css +241 -51
  12. package/dist/decklight.js +120 -76
  13. package/dist/decklight.js.map +4 -4
  14. package/package.json +6 -4
  15. package/themes/aliens.css +3 -0
  16. package/themes/apple2.css +3 -0
  17. package/themes/aurora.css +3 -0
  18. package/themes/berry.css +3 -0
  19. package/themes/blade-runner.css +3 -0
  20. package/themes/c64.css +3 -0
  21. package/themes/carbon.css +3 -0
  22. package/themes/citrus.css +3 -0
  23. package/themes/coastal.css +3 -0
  24. package/themes/cosmos.css +3 -0
  25. package/themes/dune.css +3 -0
  26. package/themes/eclipse.css +3 -0
  27. package/themes/ember.css +3 -0
  28. package/themes/fjord.css +3 -0
  29. package/themes/friends.css +3 -0
  30. package/themes/gameboy.css +3 -0
  31. package/themes/genesis.css +3 -0
  32. package/themes/glacier.css +3 -0
  33. package/themes/godfather.css +3 -0
  34. package/themes/graphite.css +3 -0
  35. package/themes/harvest.css +3 -0
  36. package/themes/ibm-modern.css +3 -0
  37. package/themes/ibm-oldschool.css +3 -0
  38. package/themes/ink.css +3 -0
  39. package/themes/latte.css +3 -0
  40. package/themes/linen.css +3 -0
  41. package/themes/meadow.css +3 -0
  42. package/themes/metropolis.css +3 -0
  43. package/themes/miami-vice.css +3 -0
  44. package/themes/midnight.css +3 -0
  45. package/themes/mint.css +3 -0
  46. package/themes/moss.css +3 -0
  47. package/themes/obsidian.css +3 -0
  48. package/themes/orchid.css +3 -0
  49. package/themes/packs.json +2 -1
  50. package/themes/paper.css +3 -0
  51. package/themes/peony.css +3 -0
  52. package/themes/porcelain.css +3 -0
  53. package/themes/pulp-fiction.css +3 -0
  54. package/themes/reveal-beige.css +3 -0
  55. package/themes/reveal-black.css +3 -0
  56. package/themes/reveal-blood.css +3 -0
  57. package/themes/reveal-dracula.css +3 -0
  58. package/themes/reveal-league.css +3 -0
  59. package/themes/reveal-moon.css +3 -0
  60. package/themes/reveal-night.css +3 -0
  61. package/themes/reveal-serif.css +3 -0
  62. package/themes/reveal-simple.css +3 -0
  63. package/themes/reveal-sky.css +3 -0
  64. package/themes/reveal-solarized.css +3 -0
  65. package/themes/reveal-white.css +3 -0
  66. package/themes/sepia.css +3 -0
  67. package/themes/seriph.css +3 -0
  68. package/themes/severance.css +3 -0
  69. package/themes/slate.css +3 -0
  70. package/themes/snes.css +3 -0
  71. package/themes/star-wars.css +3 -0
  72. package/themes/storm.css +3 -0
  73. package/themes/stranger-things.css +3 -0
  74. package/themes/synthwave.css +3 -0
  75. package/themes/terminator.css +3 -0
  76. package/themes/velvet.css +3 -0
  77. package/themes/yamabuki.css +120 -0
  78. package/tools/chrome.mjs +43 -0
  79. package/tools/gemini-tts.mjs +19 -1
  80. package/tools/lipsync-server.mjs +249 -0
  81. package/tools/lipsync.mjs +166 -0
  82. package/tools/publish-site-voices.mjs +3 -0
  83. package/tools/shot.mjs +85 -0
  84. package/tools/tts-engines.mjs +226 -0
  85. package/tools/visemes.mjs +26 -0
  86. package/tools/voiceover-server.mjs +0 -0
  87. package/tools/voiceover.mjs +51 -34
package/cli/edit.mjs CHANGED
@@ -1,23 +1,41 @@
1
1
  #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
2
5
  // decklight edit — the live-editing dev server (SPEC §8 edit mode).
3
6
  //
4
- // decklight edit <deck.html> [--port 8788]
7
+ // decklight edit <deck.html> [--port 8788] [--git | --no-git]
8
+ // [--commit-every <seconds>] [--agent <name>]
5
9
  //
6
10
  // Serves the current working directory over localhost (so decks that
7
11
  // reference ../dist and ../themes just work), watches the deck file, and:
8
12
  //
9
- // GET /edit/ping → { ok, deck } (player probes availability)
10
- // GET /edit/events → SSE; a `reload` event fires when the deck changes
13
+ // GET /edit/ping → { ok, deck, undo, redo, git, agents, agentBusy }
14
+ // GET /edit/events → SSE; `reload` on deck change, `agent` job status
11
15
  // POST /edit/notes → { slide, text } rewrite that slide's notes
16
+ // POST /edit/layout → { slide, layout } write data-layout to the file
17
+ // POST /edit/undo → step the deck file back through the edit history
18
+ // POST /edit/redo → step it forward again
19
+ // POST /edit/agent → { prompt, agent? } one-shot AI agent edit
20
+ //
21
+ // Every mutation goes through ONE undo history — snapshots of the whole
22
+ // file, held in memory, capped. Undo/redo is deliberately independent of
23
+ // git: git commits (below) are the durable record, the history is the
24
+ // second-to-second "that ring entry was worse" loop, and neither consumes
25
+ // the other. An agent run snapshots before it starts, so Z takes an
26
+ // agent's edit back exactly like the player's own.
12
27
  //
13
- // The player's E editor posts ⟨CLICK⟩-separated plain text; the server
14
- // rebuilds the <aside class="notes"> (one <p> per segment, escaped) and
15
- // writes the file — the watcher then tells every connected browser to
16
- // reload, and the #/slide/step hash restores the position.
28
+ // Git: with --git (or when the deck already sits in a repository and
29
+ // --no-git wasn't passed) the server auto-commits the deck on a regular
30
+ // basis — every --commit-every seconds when it actually changed, plus a
31
+ // final commit on Ctrl-C. --git also creates the repository when none
32
+ // exists. `decklight dev` asks interactively before passing --git down.
17
33
 
18
34
  import { createServer } from 'node:http';
19
35
  import { readFileSync, writeFileSync, watch, existsSync, statSync } from 'node:fs';
20
36
  import { resolve, extname, sep, basename } from 'node:path';
37
+ import { spawn, execFileSync } from 'node:child_process';
38
+ import { agentCommand, detectAgents } from './agents.mjs';
21
39
 
22
40
  // file://-opened decks probe http://127.0.0.1:8788 directly (origin "null"),
23
41
  // exactly like the tts bridge — so the endpoints are CORS-open. The server
@@ -65,9 +83,93 @@ export function setSlideNotes(html, slide, asideInner) {
65
83
  return parts.join('');
66
84
  }
67
85
 
86
+ // the same ring the player cycles — the file is the source of truth now
87
+ export const LAYOUTS = ['auto', 'centered', 'pinned', 'top', 'split', 'split-flip'];
88
+
89
+ /** Set (or, for 'auto', remove) slide N's data-layout attribute in the deck html. */
90
+ export function setSlideLayout(html, slide, name) {
91
+ if (!LAYOUTS.includes(name)) throw new Error(`unknown layout "${name}"`);
92
+ const parts = html.split(/(<section\b)/);
93
+ const idx = 2 * slide;
94
+ if (!parts[idx]) throw new Error(`no slide ${slide} (deck has ${(parts.length - 1) / 2})`);
95
+ const seg = parts[idx];
96
+ const gt = seg.indexOf('>');
97
+ if (gt < 0) throw new Error(`slide ${slide}: malformed <section> tag`);
98
+ let head = seg.slice(0, gt).replace(/\s+data-layout=("[^"]*"|'[^']*')/, '');
99
+ if (name !== 'auto') head += ` data-layout="${name}"`;
100
+ parts[idx] = head + seg.slice(gt);
101
+ return parts.join('');
102
+ }
103
+
104
+ /**
105
+ * The edit history: whole-file snapshots, in memory, capped. record() the
106
+ * content a mutation is about to replace; undo()/redo() take the CURRENT
107
+ * file content (which may include edits made outside the server — those
108
+ * land on the opposite stack, so nothing is silently lost) and return what
109
+ * to write, or null when the stack is empty.
110
+ */
111
+ export function createHistory(limit = 200) {
112
+ const past = [];
113
+ const future = [];
114
+ return {
115
+ record(before) {
116
+ past.push(before);
117
+ if (past.length > limit) past.shift();
118
+ future.length = 0;
119
+ },
120
+ undo(current) {
121
+ if (!past.length) return null;
122
+ future.push(current);
123
+ return past.pop();
124
+ },
125
+ redo(current) {
126
+ if (!future.length) return null;
127
+ past.push(current);
128
+ return future.pop();
129
+ },
130
+ counts() { return { undo: past.length, redo: future.length }; },
131
+ };
132
+ }
133
+
134
+ // ── git: the durable record (the history above is the fast loop) ──────────
135
+ const git = (gitArgs, cwd) =>
136
+ execFileSync('git', gitArgs, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
137
+
138
+ export function inGitRepo(dir) {
139
+ try { return git(['rev-parse', '--is-inside-work-tree'], dir) === 'true'; } catch { return false; }
140
+ }
141
+
142
+ /** Commit the deck if it changed. Returns true when a commit was made. */
143
+ export function gitAutocommit(deckPath, cwd, message = `decklight: autosave ${basename(deckPath)}`) {
144
+ try {
145
+ if (!git(['status', '--porcelain', '--', deckPath], cwd)) return false;
146
+ git(['add', '--', deckPath], cwd);
147
+ try {
148
+ git(['commit', '-m', message, '--', deckPath], cwd);
149
+ } catch (e) {
150
+ // a fresh machine has no git identity — commit anyway rather than
151
+ // silently dropping the safety net, without touching global config
152
+ if (!/user\.(name|email)|tell me who you are/i.test(String(e.stderr || e))) throw e;
153
+ git(['-c', 'user.name=decklight', '-c', 'user.email=decklight@localhost',
154
+ 'commit', '-m', message, '--', deckPath], cwd);
155
+ }
156
+ return true;
157
+ } catch (e) {
158
+ console.error(` git autocommit failed: ${String(e.stderr || e.message || e).slice(0, 160)}`);
159
+ return false;
160
+ }
161
+ }
162
+
68
163
  export async function editMain(args) {
69
164
  if (args.includes('--help') || args.includes('-h') || !args.filter((a) => !a.startsWith('-')).length) {
70
- console.log('usage: decklight edit <deck.html> [--port 8788]\n serves the cwd, live-reloads the deck on change, and accepts notes edits from the player (E)');
165
+ console.log(`usage: decklight edit <deck.html> [--port 8788] [--git | --no-git]
166
+ [--commit-every <seconds>] [--agent <name>]
167
+ serves the cwd, live-reloads the deck on change, and accepts edits from the
168
+ player: notes (E), per-slide layout (L/⇧L), undo/redo (Z/⇧Z), agent asks (A)
169
+ --git auto-commit the deck on a regular basis (creates the repo if needed)
170
+ --no-git never touch git (default outside a repository)
171
+ --commit-every N autocommit cadence in seconds [300]
172
+ --agent <name> preferred AI agent for A (default: first one detected)`);
71
173
  return;
72
174
  }
73
175
  const opt = (flag, dflt) => { const i = args.indexOf(flag); return i >= 0 ? args[i + 1] : dflt; };
@@ -77,10 +179,55 @@ export async function editMain(args) {
77
179
  if (!existsSync(deckPath)) { console.error(`deck not found: ${deckPath}`); process.exitCode = 1; return; }
78
180
  if (!deckPath.startsWith(root + sep)) { console.error('deck must live under the current directory'); process.exitCode = 1; return; }
79
181
  const deckUrl = '/' + deckPath.slice(root.length + 1).split(sep).join('/');
182
+ const deckRel = deckUrl.slice(1);
183
+
184
+ const history = createHistory();
185
+ const readDeck = () => readFileSync(deckPath, 'utf8');
186
+ // one door for every mutation: snapshot, then write — so Z always works
187
+ const applyEdit = (next, before = readDeck()) => {
188
+ if (next === before) return false;
189
+ history.record(before);
190
+ writeFileSync(deckPath, next);
191
+ return true;
192
+ };
193
+
194
+ // ── git autocommit — the durable record, independent of undo/redo ──────
195
+ const noGit = args.includes('--no-git');
196
+ const wantGit = args.includes('--git');
197
+ const commitEvery = Math.max(5, Number(opt('--commit-every', 300)) || 300);
198
+ let gitOn = false;
199
+ if (!noGit && (wantGit || inGitRepo(root))) {
200
+ if (!inGitRepo(root)) {
201
+ try {
202
+ git(['init'], root);
203
+ console.log(` git: initialized a repository in ${root}`);
204
+ } catch (e) {
205
+ console.error(` git init failed: ${String(e.stderr || e.message || e).slice(0, 160)}`);
206
+ }
207
+ }
208
+ if (inGitRepo(root)) {
209
+ gitOn = true;
210
+ gitAutocommit(deckPath, root, `decklight: start editing ${basename(deckPath)}`);
211
+ setInterval(() => gitAutocommit(deckPath, root), commitEvery * 1000).unref();
212
+ console.log(` git: auto-committing ${deckRel} every ${commitEvery}s (and on Ctrl-C)`);
213
+ }
214
+ }
215
+ const finalCommit = () => { if (gitOn) gitAutocommit(deckPath, root, `decklight: stop editing ${basename(deckPath)}`); };
216
+ process.on('SIGINT', () => { finalCommit(); process.exit(0); });
217
+ process.on('SIGTERM', () => { finalCommit(); process.exit(0); });
218
+
219
+ // ── AI agents — one-shot editing tasks from the player (A) ─────────────
220
+ const agentPref = opt('--agent');
221
+ const agents = detectAgents();
222
+ let agentJob = null; // { name, prompt, startedAt } — strictly one at a time
223
+ if (agents.length) console.log(` agents: ${agents.map((a) => a.name).join(', ')} — “Ask agent” (A) is live`);
80
224
 
81
225
  // ── live reload: watch the deck, broadcast SSE (debounced — editors fire
82
226
  // multiple fs events per save) ─────────────────────────────────────────
83
227
  const clients = new Set();
228
+ const broadcast = (event, data) => {
229
+ for (const res of clients) res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
230
+ };
84
231
  let pending = null;
85
232
  watch(deckPath, () => {
86
233
  clearTimeout(pending);
@@ -90,13 +237,54 @@ export async function editMain(args) {
90
237
  }, 150);
91
238
  });
92
239
 
240
+ function runAgent(prompt, name) {
241
+ const cmd = agentCommand(name || agentPref, prompt, deckRel);
242
+ if (!cmd) return null;
243
+ const before = readDeck();
244
+ agentJob = { agent: cmd.name, label: cmd.label, prompt, startedAt: Date.now() };
245
+ broadcast('agent', { state: 'start', ...agentJob });
246
+ console.log(` agent: ${cmd.name} ← "${prompt.slice(0, 80)}"`);
247
+ const child = spawn(cmd.bin, cmd.args, { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
248
+ let tail = '';
249
+ const keep = (chunk) => { tail = (tail + chunk).slice(-4000); };
250
+ child.stdout.on('data', keep);
251
+ child.stderr.on('data', keep);
252
+ const timeout = setTimeout(() => child.kill('SIGTERM'), 10 * 60 * 1000);
253
+ child.on('error', (e) => {
254
+ clearTimeout(timeout);
255
+ agentJob = null;
256
+ broadcast('agent', { state: 'done', agent: cmd.name, ok: false, changed: false, error: String(e.message || e) });
257
+ });
258
+ child.on('exit', (code) => {
259
+ clearTimeout(timeout);
260
+ const after = readDeck();
261
+ const changed = after !== before;
262
+ if (changed) history.record(before); // Z takes the agent's edit back
263
+ agentJob = null;
264
+ broadcast('agent', {
265
+ state: 'done', agent: cmd.name, ok: code === 0, changed, code,
266
+ tail: tail.trim().split('\n').slice(-6).join('\n').slice(-600),
267
+ });
268
+ console.log(` agent: ${cmd.name} exited (${code}) — deck ${changed ? 'changed' : 'unchanged'}`);
269
+ });
270
+ return cmd;
271
+ }
272
+
93
273
  const server = createServer(async (req, res) => {
94
274
  try {
95
275
  const url = new URL(req.url, 'http://x');
276
+ const json = (code, obj) => {
277
+ res.writeHead(code, { ...CORS, 'content-type': 'application/json' });
278
+ res.end(JSON.stringify(obj));
279
+ };
96
280
  if (req.method === 'OPTIONS') { res.writeHead(204, CORS); return res.end(); }
97
281
  if (req.method === 'GET' && url.pathname === '/edit/ping') {
98
- res.writeHead(200, { ...CORS, 'content-type': 'application/json' });
99
- return res.end(JSON.stringify({ ok: true, deck: deckUrl, name: basename(deckPath) }));
282
+ return json(200, {
283
+ ok: true, deck: deckUrl, name: basename(deckPath),
284
+ ...history.counts(), git: gitOn,
285
+ agents: agents.map((a) => ({ name: a.name, label: a.label })),
286
+ agentBusy: agentJob && { agent: agentJob.agent, prompt: agentJob.prompt, startedAt: agentJob.startedAt },
287
+ });
100
288
  }
101
289
  if (req.method === 'GET' && url.pathname === '/edit/events') {
102
290
  res.writeHead(200, { ...CORS, 'content-type': 'text/event-stream', 'cache-control': 'no-cache', connection: 'keep-alive' });
@@ -105,16 +293,40 @@ export async function editMain(args) {
105
293
  req.on('close', () => clients.delete(res));
106
294
  return;
107
295
  }
108
- if (req.method === 'POST' && url.pathname === '/edit/notes') {
109
- let body = '';
296
+ if (req.method === 'POST' && /^\/edit\/(undo|redo)$/.test(url.pathname)) {
297
+ const dir = url.pathname.endsWith('undo') ? 'undo' : 'redo';
298
+ const cur = readDeck();
299
+ const content = history[dir](cur);
300
+ if (content === null) return json(409, { ok: false, error: `nothing to ${dir}`, ...history.counts() });
301
+ writeFileSync(deckPath, content);
302
+ console.log(` ${dir} → ${JSON.stringify(history.counts())}`);
303
+ return json(200, { ok: true, ...history.counts() });
304
+ }
305
+ let body = '';
306
+ if (req.method === 'POST') {
110
307
  for await (const chunk of req) { body += chunk; if (body.length > 1e6) throw new Error('too large'); }
308
+ }
309
+ if (req.method === 'POST' && url.pathname === '/edit/notes') {
111
310
  const { slide, text } = JSON.parse(body);
112
311
  if (!Number.isInteger(slide) || slide < 1 || typeof text !== 'string') throw new Error('bad payload');
113
- const html = readFileSync(deckPath, 'utf8');
114
- writeFileSync(deckPath, setSlideNotes(html, slide, notesTextToAside(text)));
312
+ applyEdit(setSlideNotes(readDeck(), slide, notesTextToAside(text)));
115
313
  console.log(` notes saved: slide ${slide} (${text.length} chars)`);
116
- res.writeHead(200, { ...CORS, 'content-type': 'application/json' });
117
- return res.end(JSON.stringify({ ok: true }));
314
+ return json(200, { ok: true, ...history.counts() });
315
+ }
316
+ if (req.method === 'POST' && url.pathname === '/edit/layout') {
317
+ const { slide, layout } = JSON.parse(body);
318
+ if (!Number.isInteger(slide) || slide < 1 || typeof layout !== 'string') throw new Error('bad payload');
319
+ const changed = applyEdit(setSlideLayout(readDeck(), slide, layout));
320
+ if (changed) console.log(` layout saved: slide ${slide} → ${layout}`);
321
+ return json(200, { ok: true, changed, ...history.counts() });
322
+ }
323
+ if (req.method === 'POST' && url.pathname === '/edit/agent') {
324
+ const { prompt, agent } = JSON.parse(body);
325
+ if (typeof prompt !== 'string' || !prompt.trim()) throw new Error('bad payload');
326
+ if (agentJob) return json(409, { ok: false, error: `${agentJob.agent} is already running` });
327
+ const cmd = runAgent(prompt.trim(), agent);
328
+ if (!cmd) return json(400, { ok: false, error: agent ? `agent "${agent}" not detected` : 'no agent CLI detected (claude, codex, bob, …)' });
329
+ return json(200, { ok: true, agent: cmd.name, label: cmd.label });
118
330
  }
119
331
  // ── static files from the cwd ────────────────────────────────────
120
332
  if (req.method === 'GET') {
@@ -135,7 +347,8 @@ export async function editMain(args) {
135
347
  });
136
348
 
137
349
  server.listen(port, '127.0.0.1', () => {
138
- console.log(`decklight edit on http://127.0.0.1:${port}${deckUrl} — E edits notes, saves reload the deck. Ctrl-C stops`);
350
+ const actual = server.address().port;
351
+ console.log(`decklight edit on http://127.0.0.1:${actual}${deckUrl} — E notes, L layouts, Z undo, A agent. Ctrl-C stops`);
139
352
  });
140
353
  }
141
354
 
package/cli/init.mjs CHANGED
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
2
5
  /**
3
6
  * decklight init — scaffold a starter deck, plus an agent skill so Claude
4
7
  * Code (and any AGENTS.md-reading agent) knows the authoring contract
5
8
  * without a web search or a guess from Reveal.js memory.
6
9
  *
7
- * decklight init ["My Deck"] [-o deck.html] [--dir path] [--force] [--no-skill]
10
+ * decklight init ["My Deck"] [-o deck.html] [--dir path] [--themes …] [--force] [--no-skill]
8
11
  *
9
- * The deck is fully self-contained (runtime + theme inlined, like
10
- * `decklight bundle` produces) — double-click it, it presents, no sibling
11
- * files. The skill is regenerated every run (it's derived, not authored
12
- * content) so re-running after an upgrade refreshes it; the deck file is
13
- * only touched with --force.
12
+ * The deck is fully self-contained (runtime + every theme inlined, like
13
+ * `decklight bundle --themes all` produces) — double-click it, it presents,
14
+ * no sibling files, and the in-deck picker is fully stocked. Pass --themes to
15
+ * ship a narrower set. The skill is regenerated every run (it's derived, not
16
+ * authored content) so re-running after an upgrade refreshes it; the deck
17
+ * file is only touched with --force.
14
18
  */
15
19
 
16
20
  import fs from 'node:fs';
@@ -28,11 +32,38 @@ function fail(msg) {
28
32
 
29
33
  const scriptSafe = (s) => s.replace(/<\/script/gi, '<\\/script').replace(/<!--/g, '<\\u0021--');
30
34
 
35
+ // aurora is the deck's starting look; init ships every theme by default so the
36
+ // in-deck picker (/ → themes) is fully stocked, unless --themes narrows it.
31
37
  const STARTER_THEME = 'aurora';
38
+ const THEMES_DIR = path.join(PKG_ROOT, 'themes');
39
+
40
+ // 'all' → every shipped theme; otherwise a comma list of names (validated).
41
+ function resolveThemes(sel) {
42
+ if (sel === 'all') {
43
+ return fs.readdirSync(THEMES_DIR)
44
+ .filter((f) => f.endsWith('.css'))
45
+ .map((f) => f.slice(0, -4))
46
+ .sort();
47
+ }
48
+ const names = sel.split(',').map((s) => s.trim()).filter(Boolean);
49
+ if (!names.length) fail('--themes: no theme names given');
50
+ for (const n of names) {
51
+ if (!fs.existsSync(path.join(THEMES_DIR, `${n}.css`))) {
52
+ fail(`--themes: theme not found: ${n} (see themes/ for the full list)`);
53
+ }
54
+ }
55
+ return names;
56
+ }
32
57
 
33
- function starterDeck(title) {
58
+ function starterDeck(title, themeNames, activeTheme) {
34
59
  const css = fs.readFileSync(path.join(PKG_ROOT, 'dist/decklight.css'), 'utf8');
35
- const theme = fs.readFileSync(path.join(PKG_ROOT, 'themes', `${STARTER_THEME}.css`), 'utf8');
60
+ // one <style data-theme> per theme; only the active one applies (the rest
61
+ // carry media="not all", which the runtime's inline-theme mode toggles).
62
+ const themeBlocks = themeNames.map((name) => {
63
+ const theme = fs.readFileSync(path.join(THEMES_DIR, `${name}.css`), 'utf8');
64
+ const media = name === activeTheme ? '' : ' media="not all"';
65
+ return ` <style data-theme="${name}"${media}>\n${theme}\n </style>`;
66
+ }).join('\n');
36
67
  return `<!doctype html>
37
68
  <html lang="en">
38
69
  <head>
@@ -41,9 +72,7 @@ function starterDeck(title) {
41
72
  <style>
42
73
  ${css}
43
74
  </style>
44
- <style data-theme="${STARTER_THEME}">
45
- ${theme}
46
- </style>
75
+ ${themeBlocks}
47
76
  </head>
48
77
  <body>
49
78
  <div class="decklight">
@@ -148,13 +177,17 @@ export async function initMain(argv = process.argv.slice(2)) {
148
177
  process.stdout.write(`decklight init — scaffold a starter deck + agent skill
149
178
 
150
179
  Usage:
151
- decklight init ["Deck Title"] [-o deck.html] [--dir path] [--force] [--no-skill]
180
+ decklight init ["Deck Title"] [-o deck.html] [--dir path] [--themes …] [--force] [--no-skill]
152
181
 
153
182
  Options:
154
- -o <file> deck output path (default: deck.html)
155
- --dir <path> target directory (default: current directory)
156
- --force overwrite an existing deck file (default: refuses)
157
- --no-skill skip .claude/skills/decklight/ and AGENTS.md
183
+ -o <file> deck output path (default: deck.html)
184
+ --dir <path> target directory (default: current directory)
185
+ --themes <sel> which themes to inline into the deck:
186
+ all every shipped theme (default)
187
+ name,name,… an explicit list (aurora stays active when
188
+ included, else the first listed)
189
+ --force overwrite an existing deck file (default: refuses)
190
+ --no-skill skip .claude/skills/decklight/ and AGENTS.md
158
191
 
159
192
  Always writes/refreshes the skill files (they're generated from the
160
193
  installed version's SPEC.md, so re-running after an upgrade updates them)
@@ -163,18 +196,21 @@ unless --no-skill is given. The deck file is only touched with --force.
163
196
  process.exit(0);
164
197
  }
165
198
 
166
- let title = null, outFile = 'deck.html', dir = '.', force = false, withSkill = true;
199
+ let title = null, outFile = 'deck.html', dir = '.', force = false, withSkill = true, themesSel = 'all';
167
200
  const args = [...argv];
168
201
  for (let i = 0; i < args.length; i++) {
169
202
  const a = args[i];
170
203
  if (a === '-o') outFile = args[++i];
171
204
  else if (a === '--dir') dir = args[++i];
205
+ else if (a === '--themes') themesSel = args[++i];
172
206
  else if (a === '--force') force = true;
173
207
  else if (a === '--no-skill') withSkill = false;
174
208
  else if (!a.startsWith('-')) title = title ?? a;
175
209
  else fail(`unknown argument: ${a}`);
176
210
  }
177
211
  title = title || 'My Deck';
212
+ const themeNames = resolveThemes(themesSel);
213
+ const activeTheme = themeNames.includes(STARTER_THEME) ? STARTER_THEME : themeNames[0];
178
214
 
179
215
  const root = path.resolve(dir);
180
216
  fs.mkdirSync(root, { recursive: true });
@@ -183,8 +219,11 @@ unless --no-skill is given. The deck file is only touched with --force.
183
219
  if (fs.existsSync(deckPath) && !force) {
184
220
  fail(`${path.relative('.', deckPath) || outFile} already exists — pass --force to overwrite`);
185
221
  }
186
- fs.writeFileSync(deckPath, starterDeck(title));
187
- process.stdout.write(`created ${path.relative('.', deckPath) || outFile}\n`);
222
+ fs.writeFileSync(deckPath, starterDeck(title, themeNames, activeTheme));
223
+ const themeNote = themeNames.length === 1
224
+ ? `theme: ${themeNames[0]}`
225
+ : `${themeNames.length} themes, ${activeTheme} active`;
226
+ process.stdout.write(`created ${path.relative('.', deckPath) || outFile} (${themeNote})\n`);
188
227
 
189
228
  if (!withSkill) return;
190
229
 
package/cli/rec.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
2
5
  /**
3
6
  * decklight-rec — record truthful terminal casts for Decklight decks (SPEC §7.1/§7.2).
4
7
  *
@@ -104,6 +107,10 @@ function shellArgs(shellPath) {
104
107
  function setupLine(shellBase) {
105
108
  const common = `stty -echo; printf '${GS_OCTAL}DECKLIGHT-READY${GS_OCTAL}\\n'`;
106
109
  if (shellBase === 'zsh') return `unsetopt zle prompt_cr prompt_sp banghist 2>/dev/null; PS1=''; PROMPT=''; PS2=''; PROMPT2=''; ${common}\n`;
110
+ // bash: readline wraps each command in bracketed-paste markers
111
+ // (\e[?2004h/l) that would pollute the cast — turn them off, as zsh's
112
+ // `unsetopt zle` does implicitly.
113
+ if (shellBase === 'bash') return `bind 'set enable-bracketed-paste off' 2>/dev/null; PS1=''; PS2=''; ${common}\n`;
107
114
  return `PS1=''; PS2=''; ${common}\n`;
108
115
  }
109
116