decklight 0.1.0 → 0.3.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/LICENSE +202 -21
- package/README.md +105 -183
- package/SPEC.md +861 -74
- package/cli/agents.mjs +206 -0
- package/cli/associate.mjs +279 -0
- package/cli/audit.mjs +424 -0
- package/cli/bundle.mjs +210 -45
- package/cli/deckfile.mjs +233 -0
- package/cli/decklight.mjs +216 -5
- package/cli/dev.mjs +455 -0
- package/cli/edit.mjs +733 -63
- package/cli/extension.mjs +108 -0
- package/cli/git.mjs +141 -0
- package/cli/import.mjs +398 -0
- package/cli/init.mjs +465 -121
- package/cli/loader.mjs +263 -0
- package/cli/marketplace.mjs +730 -0
- package/cli/pdf.mjs +156 -0
- package/cli/pkg.mjs +69 -0
- package/cli/plugin.mjs +646 -0
- package/cli/port-conflict.mjs +94 -0
- package/cli/present.mjs +560 -0
- package/cli/publish.mjs +342 -0
- package/cli/qr.mjs +334 -0
- package/cli/rec.mjs +12 -8
- package/cli/remote.mjs +149 -0
- package/cli/report-bug.mjs +97 -0
- package/cli/restore.mjs +174 -0
- package/cli/serve.mjs +247 -0
- package/cli/sign.mjs +216 -0
- package/cli/skill-content.mjs +222 -0
- package/cli/skills.mjs +338 -0
- package/cli/supervise.mjs +57 -0
- package/cli/theme.mjs +201 -0
- package/cli/units.mjs +488 -0
- package/cli/upgrade.mjs +250 -0
- package/cli/util.mjs +90 -0
- package/cli/wizard.mjs +432 -0
- package/cli/zip.mjs +121 -0
- package/dist/decklight.css +949 -72
- package/dist/decklight.js +220 -103
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +1 -1
- package/package.json +9 -6
- package/themes/README.md +6 -4
- package/themes/aurora.css +4 -1
- package/themes/berry.css +4 -1
- package/themes/carbon.css +4 -1
- package/themes/citrus.css +4 -1
- package/themes/coastal.css +4 -1
- package/themes/cosmos.css +4 -1
- package/themes/dune.css +4 -1
- package/themes/eclipse.css +4 -1
- package/themes/ember.css +4 -1
- package/themes/fjord.css +4 -1
- package/themes/gallery.html +3 -11
- package/themes/glacier.css +4 -1
- package/themes/graphite.css +4 -1
- package/themes/harvest.css +4 -1
- package/themes/ibm-modern.css +4 -1
- package/themes/ink.css +4 -1
- package/themes/latte.css +4 -1
- package/themes/linen.css +4 -1
- package/themes/meadow.css +4 -1
- package/themes/metropolis.css +4 -1
- package/themes/midnight.css +4 -1
- package/themes/mint.css +4 -1
- package/themes/moss.css +4 -1
- package/themes/obsidian.css +4 -1
- package/themes/orchid.css +4 -1
- package/themes/packs.json +4 -31
- package/themes/paper.css +4 -1
- package/themes/peony.css +4 -1
- package/themes/porcelain.css +4 -1
- package/themes/reveal-beige.css +4 -1
- package/themes/reveal-black.css +4 -1
- package/themes/reveal-blood.css +4 -1
- package/themes/reveal-dracula.css +4 -1
- package/themes/reveal-league.css +4 -1
- package/themes/reveal-moon.css +4 -1
- package/themes/reveal-night.css +4 -1
- package/themes/reveal-serif.css +4 -1
- package/themes/reveal-simple.css +4 -1
- package/themes/reveal-sky.css +4 -1
- package/themes/reveal-solarized.css +4 -1
- package/themes/reveal-white.css +4 -1
- package/themes/sepia.css +4 -1
- package/themes/seriph.css +4 -1
- package/themes/slate.css +4 -1
- package/themes/storm.css +4 -1
- package/themes/synthwave.css +4 -1
- package/themes/velvet.css +4 -1
- package/themes/yamabuki.css +120 -0
- package/tools/args.mjs +32 -0
- package/tools/bridge.mjs +30 -0
- package/tools/chrome.mjs +52 -0
- package/tools/color.mjs +110 -0
- package/tools/deck-html.mjs +138 -0
- package/tools/elevenlabs-tts.mjs +248 -0
- package/tools/escape.mjs +40 -0
- package/tools/extension-check-runner.mjs +41 -0
- package/tools/extension-check.mjs +266 -0
- package/tools/gemini-tts.mjs +44 -4
- package/tools/lipsync-engines.mjs +81 -0
- package/tools/lipsync-server.mjs +290 -0
- package/tools/lipsync.mjs +181 -0
- package/tools/local-voice.mjs +209 -0
- package/tools/ooxml.mjs +151 -0
- package/tools/pptx.mjs +320 -0
- package/tools/publish-site-voices.mjs +5 -1
- package/tools/publish-targets.mjs +143 -0
- package/tools/publish-voices.mjs +230 -0
- package/tools/shot.mjs +129 -0
- package/tools/theme-check.mjs +139 -0
- package/tools/tts-engines.mjs +455 -0
- package/tools/tts-setup.mjs +257 -0
- package/tools/veo.mjs +204 -0
- package/tools/video.mjs +316 -0
- package/tools/visemes.mjs +26 -0
- package/tools/voiceover-server.mjs +0 -0
- package/tools/voiceover.mjs +73 -39
- package/tools/zip.mjs +143 -0
- package/docs/demo.svg +0 -124
- package/themes/aliens.css +0 -84
- package/themes/apple2.css +0 -126
- package/themes/blade-runner.css +0 -83
- package/themes/c64.css +0 -85
- package/themes/friends.css +0 -82
- package/themes/gameboy.css +0 -118
- package/themes/genesis.css +0 -84
- package/themes/godfather.css +0 -82
- package/themes/ibm-oldschool.css +0 -84
- package/themes/miami-vice.css +0 -84
- package/themes/pulp-fiction.css +0 -84
- package/themes/severance.css +0 -82
- package/themes/snes.css +0 -82
- package/themes/star-wars.css +0 -85
- package/themes/stranger-things.css +0 -84
- package/themes/terminator.css +0 -84
package/cli/init.mjs
CHANGED
|
@@ -1,49 +1,299 @@
|
|
|
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] [--
|
|
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.
|
|
21
|
+
*
|
|
22
|
+
* The deck is fully self-contained (runtime + every theme inlined, like
|
|
23
|
+
* `decklight bundle --themes all` produces) — double-click it, it presents,
|
|
24
|
+
* no sibling files, and the in-deck picker is fully stocked. Pass --themes to
|
|
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
|
|
28
|
+
* authored content) so re-running after an upgrade refreshes it; the deck
|
|
29
|
+
* file is only touched with --force.
|
|
8
30
|
*
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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).
|
|
14
37
|
*/
|
|
15
38
|
|
|
16
39
|
import fs from 'node:fs';
|
|
17
40
|
import path from 'node:path';
|
|
18
|
-
import {
|
|
41
|
+
import { pathToFileURL } from 'node:url';
|
|
42
|
+
import { spawn, execFileSync } from 'node:child_process';
|
|
43
|
+
import { createInterface } from 'node:readline/promises';
|
|
19
44
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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';
|
|
23
55
|
|
|
24
|
-
|
|
25
|
-
process.stderr.write(`decklight init: ${msg}\n`);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
56
|
+
const fail = makeFail('init');
|
|
28
57
|
|
|
29
|
-
|
|
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;
|
|
74
|
+
}
|
|
30
75
|
|
|
76
|
+
// aurora is the deck's starting look; init ships every theme by default so the
|
|
77
|
+
// in-deck picker (/ → themes) is fully stocked, unless --themes narrows it.
|
|
31
78
|
const STARTER_THEME = 'aurora';
|
|
32
79
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
80
|
+
// 'all' → every shipped theme; otherwise a comma list of names (validated).
|
|
81
|
+
function resolveThemes(sel) {
|
|
82
|
+
if (sel === 'all') {
|
|
83
|
+
return fs.readdirSync(THEMES_DIR)
|
|
84
|
+
.filter((f) => f.endsWith('.css'))
|
|
85
|
+
.map((f) => f.slice(0, -4))
|
|
86
|
+
.sort();
|
|
87
|
+
}
|
|
88
|
+
const names = sel.split(',').map((s) => s.trim()).filter(Boolean);
|
|
89
|
+
if (!names.length) fail('--themes: no theme names given');
|
|
90
|
+
for (const n of names) {
|
|
91
|
+
if (!fs.existsSync(path.join(THEMES_DIR, `${n}.css`))) {
|
|
92
|
+
fail(`--themes: theme not found: ${n} (see themes/ for the full list)`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return names;
|
|
96
|
+
}
|
|
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
|
+
|
|
278
|
+
function starterDeck(title, themeNames, activeTheme) {
|
|
279
|
+
title = escapeHtml(title); // a prompt invites &, < and quotes
|
|
280
|
+
const css = runtimeCss();
|
|
281
|
+
// one <style data-theme> per theme; only the active one applies (the rest
|
|
282
|
+
// carry media="not all", which the runtime's inline-theme mode toggles).
|
|
283
|
+
const themeBlocks = themeNames.map((name) => {
|
|
284
|
+
const theme = themeCss(name);
|
|
285
|
+
const media = name === activeTheme ? '' : ' media="not all"';
|
|
286
|
+
return ` <style data-theme="${name}"${media}>\n${theme}\n </style>`;
|
|
287
|
+
}).join('\n');
|
|
36
288
|
return `<!doctype html>
|
|
37
289
|
<html lang="en">
|
|
38
290
|
<head>
|
|
39
291
|
<meta charset="utf-8">
|
|
40
292
|
<title>${title}</title>
|
|
41
|
-
<style>
|
|
293
|
+
<style data-decklight-runtime="css">
|
|
42
294
|
${css}
|
|
43
295
|
</style>
|
|
44
|
-
|
|
45
|
-
${theme}
|
|
46
|
-
</style>
|
|
296
|
+
${themeBlocks}
|
|
47
297
|
</head>
|
|
48
298
|
<body>
|
|
49
299
|
<div class="decklight">
|
|
@@ -73,143 +323,237 @@ ${theme}
|
|
|
73
323
|
</section>
|
|
74
324
|
|
|
75
325
|
</div>
|
|
76
|
-
<script
|
|
326
|
+
<script data-decklight-runtime="js">${runtimeJs()}</script>
|
|
77
327
|
<script>Decklight.init({});</script>
|
|
78
328
|
</body>
|
|
79
329
|
</html>
|
|
80
330
|
`;
|
|
81
331
|
}
|
|
82
332
|
|
|
83
|
-
function
|
|
84
|
-
const spec = fs.readFileSync(path.join(PKG_ROOT, 'SPEC.md'), 'utf8');
|
|
85
|
-
const cut = spec.indexOf('\n## 10. Repository layout & tooling');
|
|
86
|
-
return (cut > 0 ? spec.slice(0, cut) : spec).trimEnd() + '\n';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function skillMd() {
|
|
90
|
-
return `---
|
|
91
|
-
name: decklight
|
|
92
|
-
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.
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
Decklight decks are one HTML file: no build step, no bundler, no server to
|
|
96
|
-
author. A deck is \`<div class="decklight">\` containing \`<section>\` slides;
|
|
97
|
-
the runtime is one JS file + one CSS file + one theme CSS file.
|
|
98
|
-
|
|
99
|
-
**Full authoring contract**: read [reference.md](reference.md) in this same
|
|
100
|
-
skill directory before authoring or editing a slide — it covers builds,
|
|
101
|
-
speaker notes segmentation (⟨CLICK⟩), SVG diagrams, theming, motion, code
|
|
102
|
-
blocks, terminal recordings, narration, and the public JS API. It's sliced
|
|
103
|
-
straight from Decklight's SPEC.md (v${PKG.version}), so it won't drift from
|
|
104
|
-
the installed runtime's actual behavior — trust it over prior training.
|
|
105
|
-
|
|
106
|
-
**Minimal skeleton** (see \`deck.html\` in this project for a worked example
|
|
107
|
-
with a build and notes already wired):
|
|
108
|
-
|
|
109
|
-
\`\`\`html
|
|
110
|
-
<div class="decklight">
|
|
111
|
-
<section>
|
|
112
|
-
<h1>Title</h1>
|
|
113
|
-
<aside class="notes"><p>What you'd say on this slide.</p></aside>
|
|
114
|
-
</section>
|
|
115
|
-
</div>
|
|
116
|
-
\`\`\`
|
|
117
|
-
|
|
118
|
-
**CLI** (\`npx decklight <command>\`, no install needed):
|
|
119
|
-
- \`decklight edit deck.html\` — serve with live reload; **E** in the browser edits speaker notes back into the file
|
|
120
|
-
- \`decklight rec script.term.yaml\` — record a truthful terminal cast in a real PTY, for \`<div class="terminal">\`
|
|
121
|
-
- \`decklight bundle deck.html --themes all\` — flatten into one self-contained file to hand off or publish
|
|
122
|
-
- \`decklight tts\` — live voice bridge so the deck can narrate itself on the fly
|
|
123
|
-
- \`decklight init\` — regenerate this skill after upgrading Decklight (deck file untouched unless \`--force\`)
|
|
124
|
-
|
|
125
|
-
Speaker notes drive both live narration and the transcript/caption
|
|
126
|
-
features, so write them even for decks that will only ever be read: split
|
|
127
|
-
multi-beat notes with a bare \`⟨CLICK⟩\` line so narration and build steps
|
|
128
|
-
stay in sync (§8 in the reference).
|
|
129
|
-
`;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const AGENTS_MARKER = '<!-- decklight:skill -->';
|
|
133
|
-
|
|
134
|
-
function agentsSection() {
|
|
135
|
-
return `${AGENTS_MARKER}
|
|
136
|
-
## Decklight decks
|
|
137
|
-
|
|
138
|
-
This project contains a Decklight presentation (a single-file HTML deck —
|
|
139
|
-
see \`.claude/skills/decklight/reference.md\` for the full authoring
|
|
140
|
-
contract: builds, notes, SVG diagrams, themes, terminals, narration).
|
|
141
|
-
Read that file before adding or editing slides.
|
|
142
|
-
${AGENTS_MARKER}
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function initMain(argv = process.argv.slice(2)) {
|
|
333
|
+
export async function initMain(argv = process.argv.slice(2), { hasBin = onPath, env = process.env } = {}) {
|
|
147
334
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
148
335
|
process.stdout.write(`decklight init — scaffold a starter deck + agent skill
|
|
149
336
|
|
|
150
337
|
Usage:
|
|
151
|
-
decklight init ["Deck Title"] [-o deck.html] [--dir path] [--
|
|
338
|
+
decklight init ["Deck Title"] [-o deck.html] [--dir path] [--themes …]
|
|
339
|
+
[--from <template>] [--git | --no-git] [--open] [--force]
|
|
340
|
+
[--no-skill | --global-skill]
|
|
152
341
|
|
|
153
342
|
Options:
|
|
154
|
-
-o <file>
|
|
155
|
-
--dir <path>
|
|
156
|
-
--
|
|
157
|
-
|
|
343
|
+
-o <file> deck output path (default: deck.html)
|
|
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.
|
|
352
|
+
--themes <sel> which themes to inline into the deck:
|
|
353
|
+
all every shipped theme (default)
|
|
354
|
+
name,name,… an explicit list (aurora stays active when
|
|
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)
|
|
362
|
+
--force overwrite an existing deck file (default: refuses)
|
|
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.
|
|
158
377
|
|
|
159
378
|
Always writes/refreshes the skill files (they're generated from the
|
|
160
379
|
installed version's SPEC.md, so re-running after an upgrade updates them)
|
|
161
380
|
unless --no-skill is given. The deck file is only touched with --force.
|
|
162
381
|
`);
|
|
163
|
-
|
|
382
|
+
return 0;
|
|
164
383
|
}
|
|
165
384
|
|
|
166
|
-
let title = null, outFile = 'deck.html', dir = '.', force = false,
|
|
385
|
+
let title = null, outFile = 'deck.html', dir = '.', force = false, themesSel = 'all', openAfter = false;
|
|
386
|
+
let from = null;
|
|
167
387
|
const args = [...argv];
|
|
168
388
|
for (let i = 0; i < args.length; i++) {
|
|
169
389
|
const a = args[i];
|
|
170
390
|
if (a === '-o') outFile = args[++i];
|
|
171
391
|
else if (a === '--dir') dir = args[++i];
|
|
392
|
+
else if (a === '--from') from = args[++i];
|
|
393
|
+
else if (a === '--themes') themesSel = args[++i];
|
|
172
394
|
else if (a === '--force') force = true;
|
|
173
|
-
else if (a === '--
|
|
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
|
|
174
398
|
else if (!a.startsWith('-')) title = title ?? a;
|
|
175
399
|
else fail(`unknown argument: ${a}`);
|
|
176
400
|
}
|
|
177
|
-
|
|
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);
|
|
440
|
+
const activeTheme = themeNames.includes(STARTER_THEME) ? STARTER_THEME : themeNames[0];
|
|
178
441
|
|
|
179
442
|
const root = path.resolve(dir);
|
|
180
443
|
fs.mkdirSync(root, { recursive: true });
|
|
181
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
|
+
|
|
182
449
|
const deckPath = path.resolve(root, outFile);
|
|
183
450
|
if (fs.existsSync(deckPath) && !force) {
|
|
184
|
-
|
|
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`);
|
|
185
462
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const agentsPath = path.join(root, 'AGENTS.md');
|
|
198
|
-
const section = agentsSection();
|
|
199
|
-
if (!fs.existsSync(agentsPath)) {
|
|
200
|
-
fs.writeFileSync(agentsPath, `# Agent notes\n\n${section}`);
|
|
201
|
-
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}`;
|
|
202
473
|
} else {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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');
|
|
208
515
|
} else {
|
|
209
|
-
fs.
|
|
210
|
-
|
|
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
|
+
}
|
|
211
525
|
}
|
|
212
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();
|
|
213
557
|
}
|
|
214
558
|
|
|
215
|
-
if (import.meta.url
|
|
559
|
+
if (isMain(import.meta.url)) process.exitCode = await runMain('init', initMain);
|