decklight 0.2.0 → 0.4.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 (137) hide show
  1. package/README.md +69 -31
  2. package/SPEC.md +881 -80
  3. package/cli/agents.mjs +116 -10
  4. package/cli/associate.mjs +286 -0
  5. package/cli/audit.mjs +424 -0
  6. package/cli/bundle.mjs +174 -46
  7. package/cli/deckfile.mjs +233 -0
  8. package/cli/decklight.mjs +201 -8
  9. package/cli/dev.mjs +244 -55
  10. package/cli/edit.mjs +577 -107
  11. package/cli/extension.mjs +108 -0
  12. package/cli/git.mjs +141 -0
  13. package/cli/import.mjs +398 -0
  14. package/cli/init.mjs +421 -116
  15. package/cli/loader.mjs +263 -0
  16. package/cli/marketplace.mjs +911 -0
  17. package/cli/pdf.mjs +156 -0
  18. package/cli/pkg.mjs +69 -0
  19. package/cli/plugin.mjs +654 -0
  20. package/cli/port-conflict.mjs +94 -0
  21. package/cli/present.mjs +564 -0
  22. package/cli/publish.mjs +342 -0
  23. package/cli/qr.mjs +334 -0
  24. package/cli/rec.mjs +5 -8
  25. package/cli/remote.mjs +149 -0
  26. package/cli/report-bug.mjs +97 -0
  27. package/cli/restore.mjs +174 -0
  28. package/cli/serve.mjs +247 -0
  29. package/cli/sign.mjs +216 -0
  30. package/cli/skill-content.mjs +222 -0
  31. package/cli/skills.mjs +338 -0
  32. package/cli/supervise.mjs +57 -0
  33. package/cli/theme.mjs +219 -0
  34. package/cli/units.mjs +500 -0
  35. package/cli/upgrade.mjs +250 -0
  36. package/cli/util.mjs +90 -0
  37. package/cli/wizard.mjs +432 -0
  38. package/cli/zip.mjs +121 -0
  39. package/dist/decklight.css +716 -29
  40. package/dist/decklight.js +198 -125
  41. package/dist/decklight.js.map +4 -4
  42. package/docs/architecture.svg +1 -1
  43. package/package.json +7 -5
  44. package/themes/README.md +6 -4
  45. package/themes/aurora.css +1 -1
  46. package/themes/berry.css +1 -1
  47. package/themes/carbon.css +1 -1
  48. package/themes/citrus.css +1 -1
  49. package/themes/coastal.css +1 -1
  50. package/themes/cosmos.css +1 -1
  51. package/themes/dune.css +1 -1
  52. package/themes/eclipse.css +1 -1
  53. package/themes/ember.css +1 -1
  54. package/themes/fjord.css +1 -1
  55. package/themes/gallery.html +3 -11
  56. package/themes/glacier.css +1 -1
  57. package/themes/graphite.css +1 -1
  58. package/themes/harvest.css +1 -1
  59. package/themes/ibm-modern.css +1 -1
  60. package/themes/ink.css +1 -1
  61. package/themes/latte.css +1 -1
  62. package/themes/linen.css +1 -1
  63. package/themes/meadow.css +1 -1
  64. package/themes/metropolis.css +1 -1
  65. package/themes/midnight.css +1 -1
  66. package/themes/mint.css +1 -1
  67. package/themes/moss.css +1 -1
  68. package/themes/obsidian.css +1 -1
  69. package/themes/orchid.css +1 -1
  70. package/themes/packs.json +2 -30
  71. package/themes/paper.css +1 -1
  72. package/themes/peony.css +1 -1
  73. package/themes/porcelain.css +1 -1
  74. package/themes/reveal-beige.css +1 -1
  75. package/themes/reveal-black.css +1 -1
  76. package/themes/reveal-blood.css +1 -1
  77. package/themes/reveal-dracula.css +1 -1
  78. package/themes/reveal-league.css +1 -1
  79. package/themes/reveal-moon.css +1 -1
  80. package/themes/reveal-night.css +1 -1
  81. package/themes/reveal-serif.css +1 -1
  82. package/themes/reveal-simple.css +1 -1
  83. package/themes/reveal-sky.css +1 -1
  84. package/themes/reveal-solarized.css +1 -1
  85. package/themes/reveal-white.css +1 -1
  86. package/themes/sepia.css +1 -1
  87. package/themes/seriph.css +1 -1
  88. package/themes/slate.css +1 -1
  89. package/themes/storm.css +1 -1
  90. package/themes/synthwave.css +1 -1
  91. package/themes/velvet.css +1 -1
  92. package/themes/yamabuki.css +1 -1
  93. package/tools/args.mjs +32 -0
  94. package/tools/bridge.mjs +30 -0
  95. package/tools/chrome.mjs +46 -11
  96. package/tools/color.mjs +110 -0
  97. package/tools/deck-html.mjs +138 -0
  98. package/tools/elevenlabs-tts.mjs +248 -0
  99. package/tools/escape.mjs +40 -0
  100. package/tools/extension-check-runner.mjs +41 -0
  101. package/tools/extension-check.mjs +266 -0
  102. package/tools/gemini-tts.mjs +25 -3
  103. package/tools/lipsync-engines.mjs +81 -0
  104. package/tools/lipsync-server.mjs +78 -37
  105. package/tools/lipsync.mjs +36 -21
  106. package/tools/local-voice.mjs +209 -0
  107. package/tools/ooxml.mjs +151 -0
  108. package/tools/pptx.mjs +320 -0
  109. package/tools/publish-site-voices.mjs +2 -1
  110. package/tools/publish-targets.mjs +143 -0
  111. package/tools/publish-voices.mjs +230 -0
  112. package/tools/shot.mjs +91 -47
  113. package/tools/theme-check.mjs +144 -0
  114. package/tools/tts-engines.mjs +270 -41
  115. package/tools/tts-setup.mjs +257 -0
  116. package/tools/veo.mjs +204 -0
  117. package/tools/video.mjs +440 -0
  118. package/tools/voiceover-server.mjs +163 -54
  119. package/tools/voiceover.mjs +24 -7
  120. package/tools/zip.mjs +143 -0
  121. package/docs/demo.svg +0 -124
  122. package/themes/aliens.css +0 -87
  123. package/themes/apple2.css +0 -129
  124. package/themes/blade-runner.css +0 -86
  125. package/themes/c64.css +0 -88
  126. package/themes/friends.css +0 -85
  127. package/themes/gameboy.css +0 -121
  128. package/themes/genesis.css +0 -87
  129. package/themes/godfather.css +0 -85
  130. package/themes/ibm-oldschool.css +0 -87
  131. package/themes/miami-vice.css +0 -87
  132. package/themes/pulp-fiction.css +0 -87
  133. package/themes/severance.css +0 -85
  134. package/themes/snes.css +0 -85
  135. package/themes/star-wars.css +0 -88
  136. package/themes/stranger-things.css +0 -87
  137. package/themes/terminator.css +0 -87
package/cli/init.mjs CHANGED
@@ -7,35 +7,75 @@
7
7
  * Code (and any AGENTS.md-reading agent) knows the authoring contract
8
8
  * without a web search or a guess from Reveal.js memory.
9
9
  *
10
- * decklight init ["My Deck"] [-o deck.html] [--dir path] [--themes …] [--force] [--no-skill]
10
+ * decklight init ["My Deck"] [-o deck.html] [--dir path] [--themes …]
11
+ * [--from <template>] [--git | --no-git] [--open] [--force]
12
+ * [--no-skill | --global-skill]
13
+ *
14
+ * Run bare in a terminal it asks one question — the deck's title — with
15
+ * "My Deck" as the default; a title argument (or a non-TTY run) never prompts.
16
+ * A terminal run is also asked where the skill should live: the project
17
+ * (today's install, the default) or globally in each PATH-detected agent's
18
+ * config home — the same files `decklight skills --global` installs.
19
+ * --global-skill preselects global, --no-skill skips skill and question,
20
+ * and a non-TTY run keeps the project install without asking.
11
21
  *
12
22
  * The deck is fully self-contained (runtime + every theme inlined, like
13
23
  * `decklight bundle --themes all` produces) — double-click it, it presents,
14
24
  * 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
25
+ * ship a narrower set. The runtime blocks are marked data-decklight-runtime
26
+ * so `decklight upgrade` can swap them for a newer installed version later.
27
+ * The skill is regenerated every run (it's derived, not
16
28
  * authored content) so re-running after an upgrade refreshes it; the deck
17
29
  * file is only touched with --force.
30
+ *
31
+ * init ends like the start of an authoring session: outside a repository it
32
+ * offers `git init` (the same question `decklight author` asks, at the natural
33
+ * moment — the repo starts with the shared starter .gitignore), prints an
34
+ * accent-colored epilogue — the deck's file:// URL and the `decklight author`
35
+ * line, which is the command that starts editing. `--open` launches the deck
36
+ * in the default browser (the file IS the presentation).
18
37
  */
19
38
 
20
39
  import fs from 'node:fs';
21
40
  import path from 'node:path';
22
- import { fileURLToPath } from 'node:url';
23
-
24
- const here = path.dirname(fileURLToPath(import.meta.url));
25
- const PKG_ROOT = path.resolve(here, '..');
26
- const PKG = JSON.parse(fs.readFileSync(path.join(PKG_ROOT, 'package.json'), 'utf8'));
41
+ import { pathToFileURL } from 'node:url';
42
+ import { spawn, execFileSync } from 'node:child_process';
43
+ import { createInterface } from 'node:readline/promises';
44
+
45
+ import {
46
+ PKG, PKG_ROOT, AGENTS_MARKER, agentsSection, claudeSkillMd, referenceDoc,
47
+ } from './skill-content.mjs';
48
+ import { THEMES_DIR, themeCss, runtimeCss, runtimeJs } from './pkg.mjs';
49
+ import { TARGETS, detectedTargets, installGlobalSkill, display } from './skills.mjs';
50
+ import { onPath } from './agents.mjs';
51
+ import { escapeHtml } from './edit.mjs';
52
+ import { inGitRepo, createRepo, isIdentityError, oneline } from './git.mjs';
53
+ import { makeFail, runMain } from './util.mjs';
54
+ import { isMain } from '../tools/args.mjs';
55
+
56
+ const fail = makeFail('init');
27
57
 
28
- function fail(msg) {
29
- process.stderr.write(`decklight init: ${msg}\n`);
30
- process.exit(1);
58
+ /**
59
+ * Is this HTML a decklight deck, and which runtime does it carry?
60
+ * Keys on the markers init itself writes — the `class="decklight"` stage div
61
+ * plus the `Decklight.init(` call — and reads the version from the bundle's
62
+ * `/*! Decklight vX.Y.Z … ` banner (stamped by build.mjs; minification makes
63
+ * the exported const unfindable).
64
+ *
65
+ * @returns the runtime version string; `null` for a decklight deck whose
66
+ * version can't be extracted; `undefined` for a non-deck.
67
+ */
68
+ export function deckRuntimeVersion(html) {
69
+ const isDeck = /<[a-z][^>]*\bclass=["'](?:[^"']*\s)?decklight(?:\s[^"']*)?["']/i.test(html)
70
+ && /Decklight\.init\s*\(/.test(html);
71
+ if (!isDeck) return undefined;
72
+ const banner = /\/\*!\s*Decklight v(\d+\.\d+\.\d+[^\s*]*)/.exec(html);
73
+ return banner ? banner[1] : null;
31
74
  }
32
75
 
33
- const scriptSafe = (s) => s.replace(/<\/script/gi, '<\\/script').replace(/<!--/g, '<\\u0021--');
34
-
35
76
  // aurora is the deck's starting look; init ships every theme by default so the
36
77
  // in-deck picker (/ → themes) is fully stocked, unless --themes narrows it.
37
78
  const STARTER_THEME = 'aurora';
38
- const THEMES_DIR = path.join(PKG_ROOT, 'themes');
39
79
 
40
80
  // 'all' → every shipped theme; otherwise a comma list of names (validated).
41
81
  function resolveThemes(sel) {
@@ -55,12 +95,193 @@ function resolveThemes(sel) {
55
95
  return names;
56
96
  }
57
97
 
98
+ /**
99
+ * The deck body for `--from <template>`: an installed template, or a refusal
100
+ * that names how to install one (`UNITS#REST`).
101
+ *
102
+ * It **refuses rather than fetching**, and that is the point of the flag's
103
+ * design. `init` scaffolds; installing is a separate, explicit act, exactly as
104
+ * it is for `theme add` and `plugin add`. The alternative — resolve the name
105
+ * in a catalog and download it right here — would make the one command people
106
+ * run first into a command that reaches the network, and would do it on the
107
+ * machine least likely to have been asked. So an uninstalled name is met with
108
+ * the install line, and a name nothing offers is met with that instead.
109
+ *
110
+ * The lookup is cache-only, so this stays as offline as `init` has always been.
111
+ */
112
+ export function templateDeck(name, { home, listInstalled, offered } = {}) {
113
+ const found = listInstalled(name, home);
114
+ if (found) return { ok: true, html: fs.readFileSync(found.path, 'utf8') };
115
+
116
+ // Returns the refusal rather than exiting, the way planGit and planSkill
117
+ // return a decision — the caller acts. A helper that ends the process is a
118
+ // helper that can only be tested by starting one.
119
+ const any = offered(home);
120
+ const candidate = any.find((e) => e.name === name);
121
+ if (candidate) {
122
+ return { ok: false, message: `no template "${name}" installed — a registered marketplace offers it:\n`
123
+ + ` decklight template add ${candidate.qualified}\n`
124
+ + ' then run this again. Installing is its own step on purpose: init does not\n'
125
+ + ' reach the network, and a scaffold command should not start now.' };
126
+ }
127
+ return { ok: false, message: `no template "${name}" installed, and no registered marketplace offers one`
128
+ + (any.length ? `\n available: ${any.map((e) => e.qualified).join(', ')}` : '')
129
+ + '\n decklight template list — what is installed and what is offered'
130
+ + '\n decklight marketplace add <owner/repo> — register a catalog to install from' };
131
+ }
132
+
133
+ /**
134
+ * Put the title into a template's `<title>` and first `<h1>`, and nothing else.
135
+ *
136
+ * A template is someone's deck, so this is deliberately the smallest possible
137
+ * edit: two substitutions that are true of every deck, rather than a
138
+ * templating language that would make a template a program. Neither is
139
+ * required — a template that wants its own title keeps it by not having an
140
+ * `<h1>`, and the deck still scaffolds.
141
+ */
142
+ export function titleTemplate(html, title) {
143
+ const safe = escapeHtml(title);
144
+ // A function replacement, not a string one: a title is user input and may
145
+ // contain `$&` or `$1`, which a string replacement would expand into the
146
+ // matched text instead of printing.
147
+ const put = (_m, open, _inner, close) => open + safe + close;
148
+ return html
149
+ .replace(/(<title>)([\s\S]*?)(<\/title>)/i, put)
150
+ .replace(/(<h1[^>]*>)([\s\S]*?)(<\/h1>)/i, put);
151
+ }
152
+
153
+ // No title argument: ask on a TTY (the one thing every run would have passed
154
+ // had the author known), scaffold the default silently everywhere else.
155
+ export async function resolveTitle(arg, { isTTY = false, ask } = {}) {
156
+ if (arg != null) return arg || 'My Deck';
157
+ if (!isTTY) return 'My Deck';
158
+ const answer = (await ask('deck title [My Deck]: ')).trim();
159
+ return answer || 'My Deck';
160
+ }
161
+
162
+ // ── git: offer the repository at the natural moment ─────────────────────────
163
+ // The same policy `decklight author` applies later, decided here as a pure
164
+ // function so the table (--git / --no-git / TTY / repo-present) is testable
165
+ // without a repository or a terminal.
166
+ export function planGit({ args = [], tty = false, inRepo = false } = {}) {
167
+ if (args.includes('--no-git')) return { action: 'skip' };
168
+ if (args.includes('--git')) return { action: inRepo ? 'skip' : 'create' };
169
+ if (inRepo) return { action: 'skip' };
170
+ return { action: tty ? 'ask' : 'hint' };
171
+ }
172
+
173
+ // ── the skill scope: project by default, global as a proposition ────────────
174
+ // The same shape as planGit: a pure decision table over flags and the TTY
175
+ // gate. --no-skill skips skill AND question, --global-skill preselects the
176
+ // global install (skills.mjs's machinery), a bare terminal run is asked, and
177
+ // a headless run keeps today's project install byte-for-byte.
178
+ export function planSkill({ args = [], tty = false } = {}) {
179
+ if (args.includes('--no-skill')) return { action: 'skip' };
180
+ if (args.includes('--global-skill')) return { action: 'global' };
181
+ return { action: tty ? 'ask' : 'project' };
182
+ }
183
+
184
+ /**
185
+ * Create the repository (via the shared createRepo seam, so it starts with
186
+ * the starter .gitignore) and commit everything init just wrote. The deck is
187
+ * the product: every failure is reported as a one-line note, never an exit.
188
+ * No Signed-off-by and no identity fallback — the commit is the player's, so
189
+ * a machine with no identity leaves the files staged and says so.
190
+ */
191
+ export function initRepo(root, { exec = execFileSync, mkRepo = createRepo } = {}) {
192
+ const git = (a) => exec('git', a, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
193
+ let seeded = false;
194
+ try { seeded = mkRepo(root); } catch (e) { return ` git: init failed — ${oneline(e)}`; }
195
+ const created = `repository created${seeded ? ' (with a starter .gitignore)' : ''}`;
196
+ try { git(['add', '-A']); } catch (e) { return ` git: add failed — ${oneline(e)}`; }
197
+ try {
198
+ git(['commit', '-m', 'decklight init']);
199
+ return ` git: ${created}, everything committed`;
200
+ } catch (e) {
201
+ if (isIdentityError(e)) {
202
+ return ` git: ${created}; no identity configured — files staged, commit once git config user.name/user.email is set`;
203
+ }
204
+ return ` git: commit failed — ${oneline(e)} (the files are staged)`;
205
+ }
206
+ }
207
+
208
+ // ── epilogue: the player's next action, one click or one paste away ─────────
209
+ const ACCENT = '\x1b[36m';
210
+ const DIM = '\x1b[2m';
211
+ const RESET = '\x1b[0m';
212
+
213
+ /** OSC 8 hyperlink — progressive enhancement: the URL is always the text. */
214
+ const osc8 = (url) => `\x1b]8;;${url}\x1b\\${url}\x1b]8;;\x1b\\`;
215
+
216
+ /**
217
+ * The colored "next steps" block init ends with. Pure: every environment
218
+ * input is a parameter. Escape codes (color AND the OSC 8 link) appear only
219
+ * on a TTY without NO_COLOR — piped output is plain text, and the raw URL is
220
+ * always present so copy-paste works everywhere.
221
+ */
222
+ export function epilogue({ deckPath, tty = false, noColor = false }) {
223
+ const color = tty && !noColor;
224
+ const a = (s) => (color ? `${ACCENT}${s}${RESET}` : s);
225
+ const url = pathToFileURL(deckPath).href;
226
+ const deck = path.relative('.', deckPath) || deckPath;
227
+ return [
228
+ '',
229
+ ` ${a('open to present')} ${color ? osc8(url) : url}`,
230
+ ` ${a('start editing')} decklight author ${deck}`,
231
+ '',
232
+ ].join('\n') + '\n';
233
+ }
234
+
235
+ // ── --open: hand the deck's file:// URL to the platform launcher ────────────
236
+
237
+ /**
238
+ * Platform → launcher invocation for a URL, as pure data so it can be tested
239
+ * without spawning anything. macOS ships `open`; Windows goes through cmd's
240
+ * `start` builtin (the empty '' fills the window-title slot, or the URL would
241
+ * become the title); everything else gets freedesktop's xdg-open. Zero new
242
+ * dependencies by design.
243
+ */
244
+ export function openCommand(platform, url) {
245
+ if (platform === 'darwin') return { cmd: 'open', args: [url] };
246
+ if (platform === 'win32') return { cmd: 'cmd', args: ['/c', 'start', '', url] };
247
+ return { cmd: 'xdg-open', args: [url] };
248
+ }
249
+
250
+ /**
251
+ * Launch the default browser on the deck's file:// URL — the deck is
252
+ * self-contained, so the file IS the presentation. Spawned detached with
253
+ * stdio ignored (the dev.mjs idiom) so init exits promptly. A machine that
254
+ * cannot launch (headless, no xdg-open) gets one dim line and a normal exit:
255
+ * the deck was created, which is the product.
256
+ */
257
+ export async function openDeck(deckPath, { platform = process.platform, spawnFn = spawn, out = process.stdout } = {}) {
258
+ const url = pathToFileURL(deckPath).href;
259
+ const { cmd, args } = openCommand(platform, url);
260
+ const rel = path.relative('.', deckPath) || deckPath;
261
+ const dim = (s) => (out.isTTY && !process.env.NO_COLOR ? `${DIM}${s}${RESET}` : s);
262
+ const skipped = (err) =>
263
+ out.write(dim(`--open: could not launch a browser (${cmd}: ${err.code ?? err.message}) — open ${rel} yourself\n`));
264
+ await new Promise((resolve) => {
265
+ let child;
266
+ try {
267
+ child = spawnFn(cmd, args, { stdio: 'ignore', detached: true });
268
+ } catch (err) { skipped(err); resolve(); return; }
269
+ child.once('error', (err) => { skipped(err); resolve(); });
270
+ child.once('spawn', () => {
271
+ child.unref();
272
+ out.write(`opening ${rel} in your default browser\n`);
273
+ resolve();
274
+ });
275
+ });
276
+ }
277
+
58
278
  function starterDeck(title, themeNames, activeTheme) {
59
- const css = fs.readFileSync(path.join(PKG_ROOT, 'dist/decklight.css'), 'utf8');
279
+ title = escapeHtml(title); // a prompt invites &, < and quotes
280
+ const css = runtimeCss();
60
281
  // one <style data-theme> per theme; only the active one applies (the rest
61
282
  // carry media="not all", which the runtime's inline-theme mode toggles).
62
283
  const themeBlocks = themeNames.map((name) => {
63
- const theme = fs.readFileSync(path.join(THEMES_DIR, `${name}.css`), 'utf8');
284
+ const theme = themeCss(name);
64
285
  const media = name === activeTheme ? '' : ' media="not all"';
65
286
  return ` <style data-theme="${name}"${media}>\n${theme}\n </style>`;
66
287
  }).join('\n');
@@ -69,7 +290,7 @@ function starterDeck(title, themeNames, activeTheme) {
69
290
  <head>
70
291
  <meta charset="utf-8">
71
292
  <title>${title}</title>
72
- <style>
293
+ <style data-decklight-runtime="css">
73
294
  ${css}
74
295
  </style>
75
296
  ${themeBlocks}
@@ -102,153 +323,237 @@ ${themeBlocks}
102
323
  </section>
103
324
 
104
325
  </div>
105
- <script>${scriptSafe(fs.readFileSync(path.join(PKG_ROOT, 'dist/decklight.js'), 'utf8').replace(/\/\/# sourceMappingURL=.*$/m, ''))}</script>
326
+ <script data-decklight-runtime="js">${runtimeJs()}</script>
106
327
  <script>Decklight.init({});</script>
107
328
  </body>
108
329
  </html>
109
330
  `;
110
331
  }
111
332
 
112
- function specSlice() {
113
- const spec = fs.readFileSync(path.join(PKG_ROOT, 'SPEC.md'), 'utf8');
114
- const cut = spec.indexOf('\n## 10. Repository layout & tooling');
115
- return (cut > 0 ? spec.slice(0, cut) : spec).trimEnd() + '\n';
116
- }
117
-
118
- function skillMd() {
119
- return `---
120
- name: decklight
121
- description: Author and edit Decklight presentations — single-file HTML decks with Keynote-style builds, theme-aware SVG diagrams, 61 built-in themes, truthful terminal recordings, and live TTS narration. Use whenever creating or editing a Decklight deck (a .html file with a <div class="decklight"> of <section> slides) in this project.
122
- ---
123
-
124
- Decklight decks are one HTML file: no build step, no bundler, no server to
125
- author. A deck is \`<div class="decklight">\` containing \`<section>\` slides;
126
- the runtime is one JS file + one CSS file + one theme CSS file.
127
-
128
- **Full authoring contract**: read [reference.md](reference.md) in this same
129
- skill directory before authoring or editing a slide — it covers builds,
130
- speaker notes segmentation (⟨CLICK⟩), SVG diagrams, theming, motion, code
131
- blocks, terminal recordings, narration, and the public JS API. It's sliced
132
- straight from Decklight's SPEC.md (v${PKG.version}), so it won't drift from
133
- the installed runtime's actual behavior — trust it over prior training.
134
-
135
- **Minimal skeleton** (see \`deck.html\` in this project for a worked example
136
- with a build and notes already wired):
137
-
138
- \`\`\`html
139
- <div class="decklight">
140
- <section>
141
- <h1>Title</h1>
142
- <aside class="notes"><p>What you'd say on this slide.</p></aside>
143
- </section>
144
- </div>
145
- \`\`\`
146
-
147
- **CLI** (\`npx decklight <command>\`, no install needed):
148
- - \`decklight edit deck.html\` — serve with live reload; **E** in the browser edits speaker notes back into the file
149
- - \`decklight rec script.term.yaml\` — record a truthful terminal cast in a real PTY, for \`<div class="terminal">\`
150
- - \`decklight bundle deck.html --themes all\` — flatten into one self-contained file to hand off or publish
151
- - \`decklight tts\` — live voice bridge so the deck can narrate itself on the fly
152
- - \`decklight init\` — regenerate this skill after upgrading Decklight (deck file untouched unless \`--force\`)
153
-
154
- Speaker notes drive both live narration and the transcript/caption
155
- features, so write them even for decks that will only ever be read: split
156
- multi-beat notes with a bare \`⟨CLICK⟩\` line so narration and build steps
157
- stay in sync (§8 in the reference).
158
- `;
159
- }
160
-
161
- const AGENTS_MARKER = '<!-- decklight:skill -->';
162
-
163
- function agentsSection() {
164
- return `${AGENTS_MARKER}
165
- ## Decklight decks
166
-
167
- This project contains a Decklight presentation (a single-file HTML deck —
168
- see \`.claude/skills/decklight/reference.md\` for the full authoring
169
- contract: builds, notes, SVG diagrams, themes, terminals, narration).
170
- Read that file before adding or editing slides.
171
- ${AGENTS_MARKER}
172
- `;
173
- }
174
-
175
- export async function initMain(argv = process.argv.slice(2)) {
333
+ export async function initMain(argv = process.argv.slice(2), { hasBin = onPath, env = process.env } = {}) {
176
334
  if (argv.includes('--help') || argv.includes('-h')) {
177
335
  process.stdout.write(`decklight init — scaffold a starter deck + agent skill
178
336
 
179
337
  Usage:
180
- decklight init ["Deck Title"] [-o deck.html] [--dir path] [--themes …] [--force] [--no-skill]
338
+ decklight init ["Deck Title"] [-o deck.html] [--dir path] [--themes …]
339
+ [--from <template>] [--git | --no-git] [--open] [--force]
340
+ [--no-skill | --global-skill]
181
341
 
182
342
  Options:
183
343
  -o <file> deck output path (default: deck.html)
184
344
  --dir <path> target directory (default: current directory)
345
+ --from <name> scaffold from an installed deck template instead of the
346
+ starter deck (decklight template list). The title argument
347
+ replaces the template's <title> and first <h1>; everything
348
+ else is the template's. Not installed? init names the
349
+ install command rather than fetching — installing is its own
350
+ step, and init does not reach the network.
351
+ Cannot be combined with --themes: a template brings its own.
185
352
  --themes <sel> which themes to inline into the deck:
186
353
  all every shipped theme (default)
187
354
  name,name,… an explicit list (aurora stays active when
188
355
  included, else the first listed)
356
+ --git create a git repository (with a starter .gitignore) and
357
+ commit everything init wrote
358
+ (outside a repo + no flag: init ASKS on a TTY)
359
+ --no-git never touch git
360
+ --open open the scaffolded deck in your default browser
361
+ (the deck is self-contained — the file is the presentation)
189
362
  --force overwrite an existing deck file (default: refuses)
190
- --no-skill skip .claude/skills/decklight/ and AGENTS.md
363
+ --no-skill skip the agent skill entirely (project and global), and the
364
+ where-should-it-go question with it
365
+ --global-skill install the agent skill globally — into each PATH-detected
366
+ agent's config home (~/.claude, ~/.codex, …), exactly what
367
+ \`decklight skills --global\` installs — instead of into the
368
+ project; suppresses the question
369
+
370
+ Without a title argument, a terminal run asks for one (empty keeps "My Deck");
371
+ non-interactive runs scaffold "My Deck" without asking.
372
+
373
+ A terminal run is also asked where the skill should go ("where should the
374
+ skill go? [P/g]"): project — .claude/skills/decklight/ + AGENTS.md next to
375
+ the deck (Enter keeps it) — or global, each detected agent's config home.
376
+ Non-interactive runs keep the project install without asking.
191
377
 
192
378
  Always writes/refreshes the skill files (they're generated from the
193
379
  installed version's SPEC.md, so re-running after an upgrade updates them)
194
380
  unless --no-skill is given. The deck file is only touched with --force.
195
381
  `);
196
- process.exit(0);
382
+ return 0;
197
383
  }
198
384
 
199
- let title = null, outFile = 'deck.html', dir = '.', force = false, withSkill = true, themesSel = 'all';
385
+ let title = null, outFile = 'deck.html', dir = '.', force = false, themesSel = 'all', openAfter = false;
386
+ let from = null;
200
387
  const args = [...argv];
201
388
  for (let i = 0; i < args.length; i++) {
202
389
  const a = args[i];
203
390
  if (a === '-o') outFile = args[++i];
204
391
  else if (a === '--dir') dir = args[++i];
392
+ else if (a === '--from') from = args[++i];
205
393
  else if (a === '--themes') themesSel = args[++i];
206
394
  else if (a === '--force') force = true;
207
- else if (a === '--no-skill') withSkill = false;
395
+ else if (a === '--open') openAfter = true;
396
+ else if (a === '--no-skill' || a === '--global-skill') ; // consumed by planSkill below
397
+ else if (a === '--git' || a === '--no-git') ; // consumed by planGit below
208
398
  else if (!a.startsWith('-')) title = title ?? a;
209
399
  else fail(`unknown argument: ${a}`);
210
400
  }
211
- title = title || 'My Deck';
212
- const themeNames = resolveThemes(themesSel);
401
+ if (argv.includes('--no-skill') && argv.includes('--global-skill')) {
402
+ fail('--no-skill and --global-skill are mutually exclusive');
403
+ }
404
+
405
+ // ONE readline interface for every question this run asks (title, git,
406
+ // handoff). Lines arriving BETWEEN questions (answers typed ahead) are
407
+ // buffered — readline drops them otherwise — and EOF/Ctrl-D at any prompt
408
+ // keeps the default / declines, never throws.
409
+ const tty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
410
+ const rl = tty ? createInterface({ input: process.stdin, output: process.stdout }) : null;
411
+ const typedAhead = [];
412
+ rl?.on('line', (l) => typedAhead.push(l)); // only fires with no question pending
413
+ let stdinGone = false;
414
+ rl?.once('close', () => { stdinGone = true; });
415
+ const question = (q) => {
416
+ if (typedAhead.length) {
417
+ const answer = typedAhead.shift();
418
+ process.stdout.write(q + answer + '\n'); // the transcript still records the decision
419
+ return Promise.resolve(answer);
420
+ }
421
+ if (!rl || stdinGone) return Promise.resolve('');
422
+ // rl.question's promise never settles when the input ends mid-question
423
+ // (observed on Node 20), so the close event doubles as the empty answer
424
+ return new Promise((res) => {
425
+ rl.once('close', () => res(''));
426
+ rl.question(q).then(res, () => res(''));
427
+ });
428
+ };
429
+ const askYes = async (q) => !/^n/i.test((await question(q)).trim());
430
+
431
+ if (from && themesSel !== 'all') {
432
+ // A template carries its own themes — it is a whole deck, not a body to
433
+ // dress. Silently ignoring --themes would be the kind of no-op that gets
434
+ // reported as a bug six months later.
435
+ fail('--from and --themes are mutually exclusive — a template brings its own themes');
436
+ }
437
+
438
+ title = await resolveTitle(title, { isTTY: tty, ask: question });
439
+ const themeNames = resolveThemes(from ? 'all' : themesSel);
213
440
  const activeTheme = themeNames.includes(STARTER_THEME) ? STARTER_THEME : themeNames[0];
214
441
 
215
442
  const root = path.resolve(dir);
216
443
  fs.mkdirSync(root, { recursive: true });
217
444
 
445
+ // status lines are dim so the epilogue's accent reads as THE next step
446
+ const color = !!process.stdout.isTTY && !process.env.NO_COLOR;
447
+ const note = (s) => process.stdout.write(color ? `${DIM}${s}${RESET}\n` : `${s}\n`);
448
+
218
449
  const deckPath = path.resolve(root, outFile);
219
450
  if (fs.existsSync(deckPath) && !force) {
220
- fail(`${path.relative('.', deckPath) || outFile} already exists — pass --force to overwrite`);
451
+ const rel = path.relative('.', deckPath) || outFile;
452
+ // a collision with a decklight deck almost always means "refresh my deck's
453
+ // runtime", not "destroy my slides" — lead with upgrade, not --force
454
+ const deckVer = deckRuntimeVersion(fs.readFileSync(deckPath, 'utf8'));
455
+ if (deckVer !== undefined) {
456
+ const versions = deckVer ? ` (deck has runtime ${deckVer}, installed is ${PKG.version})` : '';
457
+ fail(`${rel} is already a decklight deck${versions}
458
+ run \`decklight upgrade ${rel}\` to refresh its runtime and keep your slides,
459
+ or pass --force to replace it with a fresh starter deck`);
460
+ }
461
+ fail(`${rel} already exists — pass --force to overwrite`);
221
462
  }
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`);
227
-
228
- if (!withSkill) return;
229
-
230
- const skillDir = path.join(root, '.claude', 'skills', 'decklight');
231
- fs.mkdirSync(skillDir, { recursive: true });
232
- fs.writeFileSync(path.join(skillDir, 'SKILL.md'), skillMd());
233
- fs.writeFileSync(path.join(skillDir, 'reference.md'), specSlice());
234
- process.stdout.write(`wrote .claude/skills/decklight/{SKILL.md,reference.md} (v${PKG.version})\n`);
235
-
236
- const agentsPath = path.join(root, 'AGENTS.md');
237
- const section = agentsSection();
238
- if (!fs.existsSync(agentsPath)) {
239
- fs.writeFileSync(agentsPath, `# Agent notes\n\n${section}`);
240
- process.stdout.write('created AGENTS.md\n');
463
+ let body, themeNote;
464
+ if (from) {
465
+ const { findUnit, catalogEntriesOfType } = await import('./units.mjs');
466
+ const found = templateDeck(from, {
467
+ listInstalled: (name, home) => findUnit('template', name, home),
468
+ offered: (home) => catalogEntriesOfType('template', home),
469
+ });
470
+ if (!found.ok) fail(found.message);
471
+ body = titleTemplate(found.html, title);
472
+ themeNote = `from template ${from}`;
241
473
  } else {
242
- const existing = fs.readFileSync(agentsPath, 'utf8');
243
- const markerRe = new RegExp(`${AGENTS_MARKER}[\\s\\S]*?${AGENTS_MARKER}\\n?`);
244
- if (markerRe.test(existing)) {
245
- fs.writeFileSync(agentsPath, existing.replace(markerRe, section));
246
- process.stdout.write('refreshed the Decklight section in AGENTS.md\n');
474
+ body = starterDeck(title, themeNames, activeTheme);
475
+ themeNote = themeNames.length === 1
476
+ ? `theme: ${themeNames[0]}`
477
+ : `${themeNames.length} themes, ${activeTheme} active`;
478
+ }
479
+ fs.writeFileSync(deckPath, body);
480
+ note(`created ${path.relative('.', deckPath) || outFile} (${themeNote})`);
481
+
482
+ // ── the skill — project scope by default, global as a proposition ────────
483
+ let skill = planSkill({ args: argv, tty }).action;
484
+ if (skill === 'ask' || skill === 'global') {
485
+ // global targets the PATH-detected set, exactly like bare `decklight
486
+ // skills`; nothing detected falls back to Claude — init's existing bias
487
+ const detected = detectedTargets(hasBin);
488
+ const targets = detected.length ? detected : ['claude'];
489
+ if (skill === 'ask') {
490
+ const projDir = path.relative('.', path.join(root, '.claude', 'skills', 'decklight')) || '.';
491
+ const homes = targets.map((k) => display(TARGETS[k].home(env))).join(', ');
492
+ note(' the agent skill teaches AI coding agents how to author this deck. two scopes:');
493
+ note(` project (p) ${projDir}/ + AGENTS.md — this directory only`);
494
+ note(` global (g) ${homes} — every project (${targets.map((k) => TARGETS[k].label).join(', ')})`);
495
+ skill = /^g/i.test((await question(' where should the skill go? [P/g] ')).trim())
496
+ ? 'global' : 'project';
497
+ }
498
+ // the skill is derived content (same rationale as the project refresh
499
+ // below), so init forces past skills' clobber guard on a re-run
500
+ if (skill === 'global') installGlobalSkill(targets, { env, force: true, detected: detected.length > 0 });
501
+ }
502
+
503
+ if (skill === 'project') {
504
+ const skillDir = path.join(root, '.claude', 'skills', 'decklight');
505
+ fs.mkdirSync(skillDir, { recursive: true });
506
+ fs.writeFileSync(path.join(skillDir, 'SKILL.md'), claudeSkillMd());
507
+ fs.writeFileSync(path.join(skillDir, 'reference.md'), referenceDoc());
508
+ note(`wrote .claude/skills/decklight/{SKILL.md,reference.md} (v${PKG.version})`);
509
+
510
+ const agentsPath = path.join(root, 'AGENTS.md');
511
+ const section = agentsSection();
512
+ if (!fs.existsSync(agentsPath)) {
513
+ fs.writeFileSync(agentsPath, `# Agent notes\n\n${section}`);
514
+ note('created AGENTS.md');
247
515
  } else {
248
- fs.writeFileSync(agentsPath, existing.replace(/\n*$/, '\n\n') + section);
249
- process.stdout.write('appended a Decklight section to AGENTS.md\n');
516
+ const existing = fs.readFileSync(agentsPath, 'utf8');
517
+ const markerRe = new RegExp(`${AGENTS_MARKER}[\\s\\S]*?${AGENTS_MARKER}\\n?`);
518
+ if (markerRe.test(existing)) {
519
+ fs.writeFileSync(agentsPath, existing.replace(markerRe, section));
520
+ note('refreshed the Decklight section in AGENTS.md');
521
+ } else {
522
+ fs.writeFileSync(agentsPath, existing.replace(/\n*$/, '\n\n') + section);
523
+ note('appended a Decklight section to AGENTS.md');
524
+ }
250
525
  }
251
526
  }
527
+
528
+ // ── the git offer — dev's question, asked at the natural moment ──────────
529
+ const plan = planGit({ args: argv, tty, inRepo: inGitRepo(root) });
530
+ let { action } = plan;
531
+ if (action === 'ask') {
532
+ action = (await askYes(' create a git repository so your edits are auto-committed? [Y/n] '))
533
+ ? 'create' : 'skip';
534
+ }
535
+ if (action === 'create') {
536
+ note(initRepo(root));
537
+ // Stated, not asked: the mode is already the default, so a fifth prompt
538
+ // would only offer what is on. The line names the flag that turns it off.
539
+ note(" commits land one per agent edit, with the agent's own message"
540
+ + ' (--git-mode timer for a plain cadence)');
541
+ }
542
+ else if (action === 'hint') note(' git: no repository here — pass --git to create one and auto-commit the deck');
543
+
544
+ process.stdout.write(epilogue({ deckPath, tty: !!process.stdout.isTTY, noColor: !!process.env.NO_COLOR }));
545
+
546
+ // last of the writes, so every "created/wrote" line is on screen before the
547
+ // browser steals focus; opens the deck FILE, not a served URL — the deck is
548
+ // self-contained by design
549
+ if (openAfter) await openDeck(deckPath);
550
+
551
+ // No handoff. init scaffolds and gets out of the way: the epilogue above
552
+ // prints `decklight author <deck>` under "start editing", and that command IS
553
+ // the handoff. Starting a server for you means init does not return until
554
+ // you stop it — you cannot look at what it made, or read the lines it just
555
+ // printed, without first killing something.
556
+ rl?.close();
252
557
  }
253
558
 
254
- if (import.meta.url === `file://${process.argv[1]}`) await initMain();
559
+ if (isMain(import.meta.url)) process.exitCode = await runMain('init', initMain);