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.
Files changed (139) hide show
  1. package/LICENSE +202 -21
  2. package/README.md +105 -183
  3. package/SPEC.md +861 -74
  4. package/cli/agents.mjs +206 -0
  5. package/cli/associate.mjs +279 -0
  6. package/cli/audit.mjs +424 -0
  7. package/cli/bundle.mjs +210 -45
  8. package/cli/deckfile.mjs +233 -0
  9. package/cli/decklight.mjs +216 -5
  10. package/cli/dev.mjs +455 -0
  11. package/cli/edit.mjs +733 -63
  12. package/cli/extension.mjs +108 -0
  13. package/cli/git.mjs +141 -0
  14. package/cli/import.mjs +398 -0
  15. package/cli/init.mjs +465 -121
  16. package/cli/loader.mjs +263 -0
  17. package/cli/marketplace.mjs +730 -0
  18. package/cli/pdf.mjs +156 -0
  19. package/cli/pkg.mjs +69 -0
  20. package/cli/plugin.mjs +646 -0
  21. package/cli/port-conflict.mjs +94 -0
  22. package/cli/present.mjs +560 -0
  23. package/cli/publish.mjs +342 -0
  24. package/cli/qr.mjs +334 -0
  25. package/cli/rec.mjs +12 -8
  26. package/cli/remote.mjs +149 -0
  27. package/cli/report-bug.mjs +97 -0
  28. package/cli/restore.mjs +174 -0
  29. package/cli/serve.mjs +247 -0
  30. package/cli/sign.mjs +216 -0
  31. package/cli/skill-content.mjs +222 -0
  32. package/cli/skills.mjs +338 -0
  33. package/cli/supervise.mjs +57 -0
  34. package/cli/theme.mjs +201 -0
  35. package/cli/units.mjs +488 -0
  36. package/cli/upgrade.mjs +250 -0
  37. package/cli/util.mjs +90 -0
  38. package/cli/wizard.mjs +432 -0
  39. package/cli/zip.mjs +121 -0
  40. package/dist/decklight.css +949 -72
  41. package/dist/decklight.js +220 -103
  42. package/dist/decklight.js.map +4 -4
  43. package/docs/architecture.svg +1 -1
  44. package/package.json +9 -6
  45. package/themes/README.md +6 -4
  46. package/themes/aurora.css +4 -1
  47. package/themes/berry.css +4 -1
  48. package/themes/carbon.css +4 -1
  49. package/themes/citrus.css +4 -1
  50. package/themes/coastal.css +4 -1
  51. package/themes/cosmos.css +4 -1
  52. package/themes/dune.css +4 -1
  53. package/themes/eclipse.css +4 -1
  54. package/themes/ember.css +4 -1
  55. package/themes/fjord.css +4 -1
  56. package/themes/gallery.html +3 -11
  57. package/themes/glacier.css +4 -1
  58. package/themes/graphite.css +4 -1
  59. package/themes/harvest.css +4 -1
  60. package/themes/ibm-modern.css +4 -1
  61. package/themes/ink.css +4 -1
  62. package/themes/latte.css +4 -1
  63. package/themes/linen.css +4 -1
  64. package/themes/meadow.css +4 -1
  65. package/themes/metropolis.css +4 -1
  66. package/themes/midnight.css +4 -1
  67. package/themes/mint.css +4 -1
  68. package/themes/moss.css +4 -1
  69. package/themes/obsidian.css +4 -1
  70. package/themes/orchid.css +4 -1
  71. package/themes/packs.json +4 -31
  72. package/themes/paper.css +4 -1
  73. package/themes/peony.css +4 -1
  74. package/themes/porcelain.css +4 -1
  75. package/themes/reveal-beige.css +4 -1
  76. package/themes/reveal-black.css +4 -1
  77. package/themes/reveal-blood.css +4 -1
  78. package/themes/reveal-dracula.css +4 -1
  79. package/themes/reveal-league.css +4 -1
  80. package/themes/reveal-moon.css +4 -1
  81. package/themes/reveal-night.css +4 -1
  82. package/themes/reveal-serif.css +4 -1
  83. package/themes/reveal-simple.css +4 -1
  84. package/themes/reveal-sky.css +4 -1
  85. package/themes/reveal-solarized.css +4 -1
  86. package/themes/reveal-white.css +4 -1
  87. package/themes/sepia.css +4 -1
  88. package/themes/seriph.css +4 -1
  89. package/themes/slate.css +4 -1
  90. package/themes/storm.css +4 -1
  91. package/themes/synthwave.css +4 -1
  92. package/themes/velvet.css +4 -1
  93. package/themes/yamabuki.css +120 -0
  94. package/tools/args.mjs +32 -0
  95. package/tools/bridge.mjs +30 -0
  96. package/tools/chrome.mjs +52 -0
  97. package/tools/color.mjs +110 -0
  98. package/tools/deck-html.mjs +138 -0
  99. package/tools/elevenlabs-tts.mjs +248 -0
  100. package/tools/escape.mjs +40 -0
  101. package/tools/extension-check-runner.mjs +41 -0
  102. package/tools/extension-check.mjs +266 -0
  103. package/tools/gemini-tts.mjs +44 -4
  104. package/tools/lipsync-engines.mjs +81 -0
  105. package/tools/lipsync-server.mjs +290 -0
  106. package/tools/lipsync.mjs +181 -0
  107. package/tools/local-voice.mjs +209 -0
  108. package/tools/ooxml.mjs +151 -0
  109. package/tools/pptx.mjs +320 -0
  110. package/tools/publish-site-voices.mjs +5 -1
  111. package/tools/publish-targets.mjs +143 -0
  112. package/tools/publish-voices.mjs +230 -0
  113. package/tools/shot.mjs +129 -0
  114. package/tools/theme-check.mjs +139 -0
  115. package/tools/tts-engines.mjs +455 -0
  116. package/tools/tts-setup.mjs +257 -0
  117. package/tools/veo.mjs +204 -0
  118. package/tools/video.mjs +316 -0
  119. package/tools/visemes.mjs +26 -0
  120. package/tools/voiceover-server.mjs +0 -0
  121. package/tools/voiceover.mjs +73 -39
  122. package/tools/zip.mjs +143 -0
  123. package/docs/demo.svg +0 -124
  124. package/themes/aliens.css +0 -84
  125. package/themes/apple2.css +0 -126
  126. package/themes/blade-runner.css +0 -83
  127. package/themes/c64.css +0 -85
  128. package/themes/friends.css +0 -82
  129. package/themes/gameboy.css +0 -118
  130. package/themes/genesis.css +0 -84
  131. package/themes/godfather.css +0 -82
  132. package/themes/ibm-oldschool.css +0 -84
  133. package/themes/miami-vice.css +0 -84
  134. package/themes/pulp-fiction.css +0 -84
  135. package/themes/severance.css +0 -82
  136. package/themes/snes.css +0 -82
  137. package/themes/star-wars.css +0 -85
  138. package/themes/stranger-things.css +0 -84
  139. package/themes/terminator.css +0 -84
package/cli/dev.mjs ADDED
@@ -0,0 +1,455 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ // decklight author — one command for the whole authoring loop: the edit
6
+ // server plus whichever optional bridges this machine can actually run.
7
+ // (`decklight dev` is its permanent hidden alias, from before the rename.)
8
+ //
9
+ // decklight author <deck.html> [--port 8788] [--tts-port 8787] [--lipsync-port 8789]
10
+ // [--project <id>] [--rhubarb <bin>] [--portrait <name=img.png>]…
11
+ // [--no-tts] [--no-lipsync]
12
+ //
13
+ // The bridges keep their OWN PROCESSES on their own ports, exactly as if you
14
+ // had started them by hand — author only owns their lifetime, so one Ctrl-C
15
+ // stops everything. That split is the point: the edit server needs nothing (no
16
+ // credentials, no cost), tts holds Google credentials and spends money per
17
+ // call, lipsync pins a GPU. Folding them into one process would let a Wav2Lip
18
+ // crash or an expired token take down the server you are editing through.
19
+ //
20
+ // A bridge whose prerequisites are missing is SKIPPED with the reason and the
21
+ // fix, never a hard failure: `decklight author deck.html` on a bare machine
22
+ // still gives you live reload and notes editing, and the player degrades on
23
+ // its own (each bridge is probed via /ping).
24
+
25
+ import { spawn, spawnSync } from 'node:child_process';
26
+ import { existsSync } from 'node:fs';
27
+ import { fileURLToPath } from 'node:url';
28
+ import { createInterface } from 'node:readline/promises';
29
+ import { onPath, detectAgents } from './agents.mjs';
30
+ import { validProjectId } from '../tools/gemini-tts.mjs';
31
+ import {
32
+ ENGINES as TTS_ENGINES, PIPER_DEFAULT_VOICE, piperModelDir, piperModelPath,
33
+ piperDownloadCmd, piperDownloadLine,
34
+ } from '../tools/tts-engines.mjs';
35
+ import { KEY_ENV as ELEVENLABS_KEY_ENV } from '../tools/elevenlabs-tts.mjs';
36
+ import { loadTtsConfig, runSetupWizard } from '../tools/tts-setup.mjs';
37
+ import { detectLocalVoice, OLLAMA_NOTE } from '../tools/local-voice.mjs';
38
+ import { argReader, isMain } from '../tools/args.mjs';
39
+ import { isPortOpen, resolvePortConflict } from './port-conflict.mjs';
40
+ import { leashEnv } from './supervise.mjs';
41
+
42
+ const CLI = fileURLToPath(new URL('./decklight.mjs', import.meta.url));
43
+ // The deck server's entry since `edit` stopped being a command: its module,
44
+ // run directly. The dispatcher would refuse `edit` out loud.
45
+ const EDIT = fileURLToPath(new URL('./edit.mjs', import.meta.url));
46
+
47
+ const USAGE = `usage: decklight author <deck.html> [--port 8788] [--tts-port 8787] [--lipsync-port 8789]
48
+ [--tts-engine gemini|chirp|piper|elevenlabs] [--project <id>] [--no-tts]
49
+ [--git | --no-git] [--commit-every <s>] [--agent <name>]
50
+ brings up the edit server plus every bridge this machine can run, under one Ctrl-C
51
+
52
+ --port N edit server (live reload + edit write-back) [8788]
53
+ (taken already? author offers to take over that session
54
+ on a TTY, or moves to the next free port otherwise)
55
+ --tts-port N live voice bridge [8787]
56
+ --lipsync-port N lip-sync bridge (visemes + talking head) [8789]
57
+ --no-tts don't start the voice bridge
58
+ --no-lipsync don't start the lip-sync bridge
59
+ --git / --no-git auto-commit the deck on a cadence / never touch git
60
+ --git-mode M when to commit: timer (a cadence), agent (one commit per
61
+ agent edit, with the agent's own message), off [timer]
62
+ (no repo + no flag: author ASKS whether to create one)
63
+ --commit-every N autocommit cadence in seconds [300]
64
+ --agent <name> preferred AI agent for A (default: first detected)
65
+
66
+ every server binds 127.0.0.1; for a phone remote: decklight present --remote
67
+
68
+ --tts-engine E gemini Vertex AI, best delivery, honors a style — no free tier [default]
69
+ chirp Cloud TTS Chirp 3: HD — same voices, ~1s, 1M chars/month free
70
+ piper local, offline, unlimited, no project needed
71
+ elevenlabs your own account's voices, the ones you cloned first
72
+ in the picker — needs $ELEVENLABS_API_KEY
73
+ (nothing configured? on a terminal author offers a one-time
74
+ guided setup; decklight tts --setup re-runs it)
75
+
76
+ tts flags --project <id> (or $GOOGLE_CLOUD_PROJECT; gemini/chirp only),
77
+ --tts-model, --location, --voice, --data-dir, --lang,
78
+ --tts-format pcm|mp3 (elevenlabs),
79
+ --tts-stability creative|natural|robust (elevenlabs eleven_v3 only)
80
+ lipsync flags --rhubarb <bin>, --portrait <name=img.png>…, --wav2lip-dir,
81
+ --wav2lip-ckpt, --sadtalker-dir, --python, --cache-dir,
82
+ --veo (animate the portrait once through Vertex — BILLED),
83
+ --veo-project, --veo-model, --veo-seconds, --veo-face-y
84
+ (all passed straight through — see decklight tts --help / lipsync --help)`;
85
+
86
+ // flags that take a value (so the deck argument can be found past them)
87
+ const VALUE_FLAGS = new Set([
88
+ '--port', '--tts-port', '--lipsync-port', '--tts-engine', '--project', '--tts-model',
89
+ '--location', '--voice', '--data-dir', '--lang', '--tts-format', '--tts-stability',
90
+ '--rhubarb', '--portrait', '--wav2lip-dir', '--wav2lip-ckpt', '--sadtalker-dir',
91
+ '--python', '--cache-dir', '--commit-every', '--agent', '--git-mode',
92
+ '--veo-project', '--veo-model', '--veo-seconds', '--veo-prompt', '--veo-location', '--veo-face-y',
93
+ ]);
94
+
95
+ /**
96
+ * Decide what to bring up, WITHOUT starting anything — the whole capability
97
+ * policy in one pure function, so it can be tested without binding a port.
98
+ * `saved` is the machine-level tts config (~/.config/decklight/tts.json,
99
+ * written by the setup wizard) — injected, not read here, so the plan stays
100
+ * pure; precedence is flags > environment > saved config > built-in default.
101
+ * Returns { deck, run: [{name, tag, entry, args, url}], skip: [{name, why}],
102
+ * agents: [names the machine can run] } — `entry` is the script to spawn:
103
+ * the bridges go through the dispatcher, the edit server (no longer a
104
+ * command there) runs its own module.
105
+ */
106
+ export function planServices({
107
+ args = [], env = process.env, hasBin = onPath, saved = null,
108
+ detect = detectLocalVoice, ollama = false, exists = existsSync,
109
+ } = {}) {
110
+ const { opt, opts } = argReader(args);
111
+ const has = (flag) => args.includes(flag);
112
+ const pass = (flag) => (opt(flag) !== undefined ? [flag, opt(flag)] : []);
113
+
114
+ // first bare token is the deck — step over flags that consume a value, so
115
+ // `author --port 8788 deck.html` doesn't mistake "8788" for the deck
116
+ let deck;
117
+ for (let i = 0; i < args.length; i++) {
118
+ const a = args[i];
119
+ if (a.startsWith('-')) { if (VALUE_FLAGS.has(a)) i++; continue; }
120
+ deck = a;
121
+ break;
122
+ }
123
+
124
+ const run = [];
125
+ const skip = [];
126
+
127
+ const editPort = opt('--port', '8788');
128
+ run.push({
129
+ name: 'edit',
130
+ tag: 'deck',
131
+ entry: EDIT,
132
+ args: [deck, '--port', editPort,
133
+ ...(has('--git') ? ['--git'] : []), ...(has('--no-git') ? ['--no-git'] : []),
134
+ ...pass('--commit-every'), ...pass('--agent'), ...pass('--git-mode')],
135
+ url: `http://127.0.0.1:${editPort}/${deck ?? ''}`,
136
+ });
137
+
138
+ // live voice — an engine that would exit for want of a credential should not
139
+ // be started at all: the Google ones need a project, ElevenLabs needs a key,
140
+ // and piper needs neither, only the binary
141
+ const ttsPort = opt('--tts-port', '8787');
142
+ const project = opt('--project', env.GOOGLE_CLOUD_PROJECT ?? saved?.project);
143
+
144
+ // Nothing chosen, nothing saved, no cloud credential: rather than default to
145
+ // an engine that will be skipped for want of a project, ask the machine what
146
+ // it can already say. Every desktop OS ships a synthesizer, and on current
147
+ // ones it is neural — free, offline, and nothing to download. An explicit
148
+ // --tts-engine, a saved engine, or a project all win over this: flags decide,
149
+ // detection only fills a vacuum.
150
+ const chosen = opt('--tts-engine', saved?.engine);
151
+ const native = chosen || project ? null : detect({ lang: opt('--lang') });
152
+ // Only a NATIVE voice is claimed automatically. It is the one engine that
153
+ // needs no setup at all — no install, no download, no credential — so using
154
+ // it silently costs the presenter nothing. piper is deliberately NOT picked
155
+ // here even when it is on PATH: it needs a toolchain and a ~120 MB model, and
156
+ // choosing it behind the user's back would skip the first-run wizard that
157
+ // exists to make (and save) exactly that choice.
158
+ const ttsEngine = chosen ?? native?.engine ?? 'gemini';
159
+ const cloudVoice = ttsEngine === 'gemini' || ttsEngine === 'chirp';
160
+ const ttsArgs = () => [
161
+ 'tts', '--port', ttsPort,
162
+ // also when DETECTION chose the engine: without this the bridge would be
163
+ // started with no --engine and fall back to its own default, so a machine
164
+ // picked for its system voice would try to reach Vertex AI instead
165
+ ...(has('--tts-engine') || saved?.engine || ttsEngine !== 'gemini' ? ['--engine', ttsEngine] : []),
166
+ ...(cloudVoice ? ['--project', project] : []),
167
+ ...pass('--tts-model'), ...pass('--location'),
168
+ ...pass('--voice'), ...pass('--data-dir'), ...pass('--lang'), ...pass('--tts-format'),
169
+ ...pass('--tts-stability'),
170
+ ];
171
+ if (has('--no-tts')) {
172
+ skip.push({ name: 'voice', why: 'disabled with --no-tts' });
173
+ } else if (!TTS_ENGINES.includes(ttsEngine)) {
174
+ skip.push({ name: 'voice', why: `unknown --tts-engine '${ttsEngine}' — use ${TTS_ENGINES.join(', ')}` });
175
+ } else if (ttsEngine === 'piper' && !hasBin('piper', env)) {
176
+ skip.push({ name: 'voice', why: 'piper not on PATH — install it (uv tool install piper-tts)' });
177
+ } else if (ttsEngine === 'piper' && !exists(piperModelPath(
178
+ opt('--voice', saved?.voice ?? PIPER_DEFAULT_VOICE), opt('--data-dir', piperModelDir(env))))) {
179
+ // piper is installed but has no voice to speak with. The bridge would come
180
+ // up looking healthy and fail on the first sentence — a keypress into
181
+ // silence — so it is caught here, where the fix can be offered instead.
182
+ const voice = opt('--voice', saved?.voice ?? PIPER_DEFAULT_VOICE);
183
+ const models = opt('--data-dir', piperModelDir(env));
184
+ const download = piperDownloadCmd(voice, models, { hasBin: (b) => hasBin(b, env) });
185
+ skip.push({
186
+ name: 'voice',
187
+ why: `the piper voice ${voice} is not in ${models} (~120 MB, one time)`
188
+ + ` — ${piperDownloadLine(download)}`,
189
+ download, // author offers to run this on a TTY; nothing is ever pulled silently
190
+ });
191
+ } else if (ttsEngine === 'elevenlabs' && !env[ELEVENLABS_KEY_ENV]?.trim()) {
192
+ // The key never lands in the saved config, so the environment is the only
193
+ // place it can come from — say that, and where to make one.
194
+ skip.push({ name: 'voice', why: `elevenlabs needs $${ELEVENLABS_KEY_ENV} — create a key at https://elevenlabs.io/app/settings/api-keys and export it` });
195
+ } else if (cloudVoice && !project) {
196
+ skip.push({
197
+ name: 'voice',
198
+ why: `${ttsEngine} needs a GCP project — pass --project <id> or set GOOGLE_CLOUD_PROJECT`
199
+ + (native?.why ? `\n this machine has no system voice either: ${native.why}` : '')
200
+ + (native?.suggest ? `\n ${native.suggest}` : ' — or use --tts-engine piper')
201
+ // Ollama is the thing a local-AI user assumes covers this. It does not,
202
+ // and being told why beats concluding decklight ignores their stack.
203
+ + (ollama ? `\n ${OLLAMA_NOTE}` : ''),
204
+ });
205
+ } else if (cloudVoice && !validProjectId(project)) {
206
+ // caught here rather than at the first narration: the bridge would start,
207
+ // look healthy, and only fail on a keypress — with a 403 naming a project
208
+ // nobody typed
209
+ skip.push({ name: 'voice', why: `not a GCP project id: ${JSON.stringify(project)} — stray punctuation from a copy-paste?` });
210
+ } else {
211
+ run.push({ name: 'tts', tag: 'voice', entry: CLI, args: ttsArgs(), url: `http://127.0.0.1:${ttsPort}` });
212
+ }
213
+
214
+ // lip-sync — starts degraded (it probes its own engines), so only bother when
215
+ // something it can actually use is present
216
+ const lipPort = opt('--lipsync-port', '8789');
217
+ const rhubarb = opt('--rhubarb', 'rhubarb');
218
+ const configured = has('--rhubarb') || has('--portrait') || has('--wav2lip-dir') || has('--sadtalker-dir');
219
+ if (has('--no-lipsync')) {
220
+ skip.push({ name: 'lip-sync', why: 'disabled with --no-lipsync' });
221
+ } else if (!configured && !hasBin(rhubarb, env)) {
222
+ skip.push({ name: 'lip-sync', why: 'rhubarb not on PATH — install it, or pass --rhubarb/--portrait' });
223
+ } else {
224
+ run.push({
225
+ name: 'lipsync',
226
+ tag: 'lips',
227
+ entry: CLI,
228
+ args: [
229
+ 'lipsync', '--port', lipPort,
230
+ ...(has('--rhubarb') ? ['--rhubarb', rhubarb] : []),
231
+ ...opts('--portrait').flatMap((p) => ['--portrait', p]),
232
+ ...pass('--wav2lip-dir'), ...pass('--wav2lip-ckpt'),
233
+ ...pass('--sadtalker-dir'), ...pass('--python'), ...pass('--cache-dir'),
234
+ // --veo animates the portrait through Vertex (once, then cached) so the
235
+ // narrator moves while you author; it is the one bridge flag that spends
236
+ // money, so it is opt-in here exactly as it is on `decklight lipsync`
237
+ ...(has('--veo') ? ['--veo'] : []),
238
+ ...pass('--veo-project'), ...pass('--veo-model'),
239
+ ...pass('--veo-seconds'), ...pass('--veo-prompt'), ...pass('--veo-location'),
240
+ ...pass('--veo-face-y'),
241
+ ],
242
+ url: `http://127.0.0.1:${lipPort}`,
243
+ });
244
+ }
245
+
246
+ // Reported, not passed through. The phone remote moved to `present`
247
+ // (PRESENT#REMOTE), and a flag that quietly did nothing would leave someone
248
+ // holding a phone that never connects. devMain is what prints and exits —
249
+ // the plan stays pure so a test can ask what it decided.
250
+ const gone = ['--remote', '--host'].filter((f) => args.some((a) => a === f || a.startsWith(f + '=')));
251
+ return { deck, run, skip, gone, agents: detectAgents({ env, hasBin }).map((a) => a.name) };
252
+ }
253
+
254
+ /**
255
+ * Should author OFFER the tts setup wizard instead of just printing the skip
256
+ * line? Only when the skip is the fixable kind — no engine configured, no
257
+ * project to run the default cloud engine with — never when a flag chose the
258
+ * outcome (--no-tts, an unknown engine, a malformed --project: the user's
259
+ * hand is on the wheel, and the skip line already names the fix).
260
+ */
261
+ /** The voice is skipped only for want of a model, and we know how to fetch it. */
262
+ export const voiceModelOffer = (plan) => {
263
+ const s = plan.skip.find((x) => x.name === 'voice');
264
+ return s?.download ? s : null;
265
+ };
266
+
267
+ export const voiceSetupOffer = (plan) => {
268
+ const s = plan.skip.find((x) => x.name === 'voice');
269
+ return s && /needs a GCP project/.test(s.why) ? s : null;
270
+ };
271
+
272
+ // inGitRepo lives in git.mjs now; re-exported so importers (and the tests) keep
273
+ // finding it where dev grew it.
274
+ export { inGitRepo } from './git.mjs';
275
+ import { inGitRepo } from './git.mjs';
276
+
277
+ const COLORS = { deck: '\x1b[36m', voice: '\x1b[35m', lips: '\x1b[33m' };
278
+ const DIM = '\x1b[2m';
279
+ const RESET = '\x1b[0m';
280
+
281
+ export async function devMain(args) {
282
+ if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return; }
283
+
284
+ let plan = planServices({ args, saved: loadTtsConfig() });
285
+ if (plan.gone.length) {
286
+ console.error(`decklight author no longer takes ${plan.gone.join(' or ')} — the phone remote moved to \`decklight present\`.`);
287
+ console.error(' A clicker used to cost you an editing server on the LAN: /edit/notes, /edit/layout and');
288
+ console.error(' /edit/agent were reachable from the same run you were not watching. present has no edit');
289
+ console.error(' surface to widen, so that is where it lives.');
290
+ console.error(`\n decklight present ${plan.deck ?? '<deck.html>'} --remote`);
291
+ process.exitCode = 2;
292
+ return;
293
+ }
294
+ const deck = plan.deck;
295
+ if (!deck) {
296
+ console.error('decklight author needs a deck: decklight author <deck.html>\n');
297
+ console.error(USAGE);
298
+ process.exitCode = 1;
299
+ return;
300
+ }
301
+ if (!existsSync(deck)) {
302
+ console.error(`decklight author: no such deck: ${deck}`);
303
+ process.exitCode = 1;
304
+ return;
305
+ }
306
+
307
+ // No repo, no flag: offer one. A repo is where the regular autocommits go —
308
+ // the durable record behind the player's fast undo/redo loop. Only a TTY
309
+ // can be asked; headless runs stay git-less until --git says otherwise.
310
+ if (!args.includes('--git') && !args.includes('--no-git') && !inGitRepo(process.cwd())) {
311
+ if (process.stdin.isTTY && process.stdout.isTTY) {
312
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
313
+ const answer = await rl.question(' no git repository here — create one and auto-commit the deck as you edit? [Y/n] ');
314
+ const yes = !/^n/i.test(answer.trim());
315
+ args = [...args, yes ? '--git' : '--no-git'];
316
+ // Only while we are ALREADY setting git up, and only when an agent could
317
+ // actually drive edits, offer the boundary that suits agent work. A
318
+ // session in an existing repository gains no new question — that is the
319
+ // one thing this must not cost, so `--git-mode agent` is how you reach it
320
+ // there.
321
+ if (yes && !args.includes('--git-mode') && detectAgents().length) {
322
+ const mode = await rl.question(" commit once per agent edit, with the agent's own message, instead of on a timer? [y/N] ");
323
+ if (/^y/i.test(mode.trim())) args = [...args, '--git-mode', 'agent'];
324
+ }
325
+ rl.close();
326
+ plan = planServices({ args, saved: loadTtsConfig() });
327
+ } else {
328
+ console.log(' git: no repository here — pass --git to create one and auto-commit the deck');
329
+ }
330
+ }
331
+ // piper is installed and chosen, but its voice model is not on disk. The
332
+ // download is ~120 MB, so it is ASKED FOR, never silent — and only on a TTY,
333
+ // so CI and pipes keep the skip line exactly as it was. Accepting re-plans,
334
+ // so the bridge joins `run` and comes up in this same session.
335
+ {
336
+ const offer = voiceModelOffer(plan);
337
+ if (offer && process.stdin.isTTY && process.stdout.isTTY) {
338
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
339
+ try {
340
+ console.log(` ${offer.why}`);
341
+ const answer = await rl.question(' download it now? [Y/n] ');
342
+ if (!/^n/i.test(answer.trim())) {
343
+ const { bin, args: dlArgs } = offer.download;
344
+ const r = spawnSync(bin, dlArgs, { stdio: 'inherit' });
345
+ if (r.status === 0) plan = planServices({ args });
346
+ else console.log(' download failed — the voice stays skipped');
347
+ }
348
+ } finally { rl.close(); }
349
+ }
350
+ }
351
+ // The voice would be skipped for the one reason setup can fix: nothing is
352
+ // configured. Offer the guided setup (TTY only — headless runs keep the
353
+ // skip line exactly as it was); a completed setup re-plans, so the bridge
354
+ // joins `run` and comes up in this same session.
355
+ if (voiceSetupOffer(plan) && process.stdin.isTTY && process.stdout.isTTY) {
356
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
357
+ try {
358
+ const answer = await rl.question(' no voice engine configured — set up live narration now? (V / N in the deck use it) [Y/n] ');
359
+ if (!/^n/i.test(answer.trim())) {
360
+ const result = await runSetupWizard({ ask: (q) => rl.question(q) });
361
+ if (result) {
362
+ // the wizard's test synthesis may hold a resident engine (piper);
363
+ // author runs the bridge as its own child process, so let it go
364
+ result.engine.synth.close?.();
365
+ plan = planServices({ args, saved: result.config });
366
+ }
367
+ }
368
+ } finally { rl.close(); }
369
+ }
370
+ // The edit port might already be held — often an earlier decklight session
371
+ // left running. Resolved here, with author's OWN stdin, because the edit
372
+ // child below is spawned with its stdin piped (not a terminal) and could
373
+ // never ask on its own.
374
+ const editSvc = plan.run.find((s) => s.name === 'edit');
375
+ if (editSvc) {
376
+ const portIdx = editSvc.args.indexOf('--port');
377
+ const editPort = Number(editSvc.args[portIdx + 1]);
378
+ if (await isPortOpen(editPort)) {
379
+ const askTty = process.stdin.isTTY && process.stdout.isTTY;
380
+ let rl;
381
+ const ask = askTty ? (q) => (rl ??= createInterface({ input: process.stdin, output: process.stdout })).question(q) : undefined;
382
+ const freshPort = await resolvePortConflict(editPort, { ask, log: console.log });
383
+ rl?.close();
384
+ editSvc.args[portIdx + 1] = String(freshPort);
385
+ editSvc.url = `http://127.0.0.1:${freshPort}/${deck}`;
386
+ }
387
+ }
388
+ const { run, skip, agents } = plan;
389
+
390
+ const tty = process.stdout.isTTY;
391
+ const paint = (tag) => (tty ? `${COLORS[tag] ?? ''}${tag.padEnd(5)}${RESET}` : `${tag.padEnd(5)}`);
392
+ const note = (s) => (tty ? `${DIM}${s}${RESET}` : s);
393
+
394
+ const children = new Map();
395
+ let shuttingDown = false;
396
+
397
+ // Children write their own startup/progress lines; prefix each so three
398
+ // servers in one terminal stay readable.
399
+ const pipe = (stream, tag, out) => {
400
+ let buf = '';
401
+ stream.setEncoding('utf8');
402
+ stream.on('data', (chunk) => {
403
+ buf += chunk;
404
+ const lines = buf.split('\n');
405
+ buf = lines.pop() ?? '';
406
+ for (const line of lines) out.write(`${paint(tag)} ${line}\n`);
407
+ });
408
+ };
409
+
410
+ for (const svc of run) {
411
+ // stdin is a pipe author never writes to — it is the leash (see supervise.mjs).
412
+ // Holding it open is what tells the child we are still here; losing it is
413
+ // how the child finds out we are not, even when we were SIGKILLed and
414
+ // never reached shutdown() below.
415
+ const child = spawn(process.execPath, [svc.entry, ...svc.args], {
416
+ stdio: ['pipe', 'pipe', 'pipe'],
417
+ env: leashEnv(),
418
+ });
419
+ children.set(svc.name, child);
420
+ pipe(child.stdout, svc.tag, process.stdout);
421
+ pipe(child.stderr, svc.tag, process.stderr);
422
+
423
+ child.on('exit', (code) => {
424
+ children.delete(svc.name);
425
+ if (shuttingDown) return;
426
+ if (svc.name === 'edit') {
427
+ // the deck server is the one service author cannot run without
428
+ console.error(`${paint(svc.tag)} exited (${code}) — stopping decklight author`);
429
+ shutdown(code ?? 1);
430
+ } else {
431
+ console.error(`${paint(svc.tag)} exited (${code}) — carrying on without it; the deck degrades on its own`);
432
+ }
433
+ });
434
+ }
435
+
436
+ for (const s of skip) console.log(note(` ${s.name.padEnd(8)} skipped — ${s.why}`));
437
+ if (!agents.length) console.log(note(' agents none detected — install claude, codex, or bob to ask an agent from the deck (A)'));
438
+ console.log(note(' Ctrl-C stops everything.\n'));
439
+
440
+ function shutdown(code = 0) {
441
+ if (shuttingDown) return;
442
+ shuttingDown = true;
443
+ for (const child of children.values()) child.kill('SIGTERM');
444
+ // give them a beat to close their listeners, then go
445
+ setTimeout(() => {
446
+ for (const child of children.values()) child.kill('SIGKILL');
447
+ process.exit(code);
448
+ }, 500).unref();
449
+ }
450
+
451
+ process.on('SIGINT', () => shutdown(0));
452
+ process.on('SIGTERM', () => shutdown(0));
453
+ }
454
+
455
+ if (isMain(import.meta.url)) devMain(process.argv.slice(2));