decklight 0.8.0 → 0.9.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 (133) hide show
  1. package/PLATFORM.md +666 -0
  2. package/README.md +224 -150
  3. package/SPEC.md +732 -886
  4. package/cli/agent-review.mjs +245 -0
  5. package/cli/agents.mjs +25 -5
  6. package/cli/associate.mjs +12 -12
  7. package/cli/audit.mjs +42 -10
  8. package/cli/banner.mjs +41 -17
  9. package/cli/bundle-audio.mjs +183 -0
  10. package/cli/bundle.mjs +383 -31
  11. package/cli/cast.mjs +7 -7
  12. package/cli/check.mjs +961 -0
  13. package/cli/clone-deck.mjs +179 -0
  14. package/cli/commands.mjs +345 -0
  15. package/cli/comments.mjs +64 -18
  16. package/cli/commit-flow.mjs +44 -19
  17. package/cli/commit-message.mjs +51 -74
  18. package/cli/commit-split.mjs +601 -0
  19. package/cli/deck-refs.mjs +59 -0
  20. package/cli/deck-routes.mjs +67 -0
  21. package/cli/deckfile.mjs +3 -5
  22. package/cli/decklight.mjs +68 -289
  23. package/cli/design-system-deps.mjs +209 -0
  24. package/cli/design-system-edit.mjs +194 -0
  25. package/cli/design-system-refs.mjs +409 -0
  26. package/cli/design-system.mjs +429 -0
  27. package/cli/doctor.mjs +115 -0
  28. package/cli/edit-git.mjs +353 -0
  29. package/cli/edit-handover.mjs +445 -0
  30. package/cli/edit-look.mjs +388 -0
  31. package/cli/edit-slides.mjs +683 -0
  32. package/cli/edit.mjs +2126 -842
  33. package/cli/enhance.mjs +483 -0
  34. package/cli/extension.mjs +10 -10
  35. package/cli/font-refs.mjs +273 -0
  36. package/cli/font.mjs +246 -0
  37. package/cli/git-tree.mjs +1 -1
  38. package/cli/git.mjs +65 -11
  39. package/cli/import.mjs +56 -10
  40. package/cli/init.mjs +400 -234
  41. package/cli/library.mjs +127 -0
  42. package/cli/loader.mjs +3 -1
  43. package/cli/marketplace.mjs +215 -21
  44. package/cli/narrate.mjs +176 -0
  45. package/cli/open-browser.mjs +63 -0
  46. package/cli/open.mjs +943 -0
  47. package/cli/pdf.mjs +41 -13
  48. package/cli/pkg.mjs +44 -2
  49. package/cli/plugin.mjs +43 -41
  50. package/cli/port-conflict.mjs +53 -23
  51. package/cli/pptx-export.mjs +71 -26
  52. package/cli/publish.mjs +8 -4
  53. package/cli/qr.mjs +1 -1
  54. package/cli/record.mjs +14 -12
  55. package/cli/remote.mjs +11 -11
  56. package/cli/restore.mjs +11 -4
  57. package/cli/review-ref.mjs +125 -0
  58. package/cli/review-remote.mjs +92 -48
  59. package/cli/review-routes.mjs +254 -0
  60. package/cli/review-store.mjs +47 -7
  61. package/cli/review-submit.mjs +47 -57
  62. package/cli/runtime-link.mjs +560 -0
  63. package/cli/serve.mjs +235 -44
  64. package/cli/setup.mjs +112 -0
  65. package/cli/sign.mjs +1 -1
  66. package/cli/skill-content.mjs +190 -33
  67. package/cli/skills.mjs +107 -24
  68. package/cli/start.mjs +110 -0
  69. package/cli/supervise.mjs +6 -6
  70. package/cli/theme-refs.mjs +515 -0
  71. package/cli/theme.mjs +181 -137
  72. package/cli/trust.mjs +83 -0
  73. package/cli/units.mjs +39 -42
  74. package/cli/update-check.mjs +1 -5
  75. package/cli/upgrade.mjs +194 -28
  76. package/cli/upstream.mjs +4 -3
  77. package/cli/util.mjs +4 -4
  78. package/cli/wizard.mjs +6 -6
  79. package/dist/build-info.json +1 -1
  80. package/dist/decklight.css +1126 -49
  81. package/dist/decklight.js +212 -115
  82. package/dist/decklight.js.map +4 -4
  83. package/docs/GLOSSARY.md +141 -0
  84. package/docs/architecture.svg +17 -17
  85. package/package.json +4 -2
  86. package/themes/README.md +9 -8
  87. package/themes/reveal-solarized.css +10 -0
  88. package/tools/args.mjs +20 -0
  89. package/tools/atomic-write.mjs +48 -0
  90. package/tools/brand-palette.mjs +717 -0
  91. package/tools/bridge.mjs +1 -1
  92. package/tools/build-groups.mjs +42 -0
  93. package/tools/color.mjs +48 -0
  94. package/tools/deck-html.mjs +396 -11
  95. package/tools/design-system-format.mjs +753 -0
  96. package/tools/elevenlabs-tts.mjs +110 -17
  97. package/tools/exec.mjs +35 -2
  98. package/tools/extension-check.mjs +31 -7
  99. package/tools/font-format.mjs +190 -0
  100. package/tools/font-stacks.mjs +24 -0
  101. package/tools/gemini-tts.mjs +3 -0
  102. package/tools/lipsync-config.mjs +103 -0
  103. package/tools/lipsync-engines.mjs +205 -2
  104. package/tools/lipsync-server.mjs +264 -41
  105. package/tools/lipsync.mjs +37 -18
  106. package/tools/local-voice.mjs +32 -42
  107. package/tools/narration-manifest.mjs +196 -0
  108. package/tools/narration-synth.mjs +416 -0
  109. package/tools/pptx.mjs +776 -19
  110. package/tools/publish-targets.mjs +1 -1
  111. package/tools/publish-voices.mjs +3 -3
  112. package/tools/recording-impact.mjs +7 -3
  113. package/tools/render-theme.mjs +33 -0
  114. package/tools/review-anchor.mjs +28 -12
  115. package/tools/semver.mjs +40 -0
  116. package/tools/sentences.mjs +180 -0
  117. package/tools/shot.mjs +14 -7
  118. package/tools/site-voices.mjs +232 -0
  119. package/tools/template-theme.mjs +1 -1
  120. package/tools/test-impact.mjs +19 -10
  121. package/tools/theme-check.mjs +30 -3
  122. package/tools/tts-cache.mjs +4 -3
  123. package/tools/tts-engines.mjs +38 -20
  124. package/tools/tts-setup.mjs +7 -7
  125. package/tools/video-options.mjs +34 -0
  126. package/tools/video.mjs +461 -48
  127. package/tools/voiceover-server.mjs +185 -104
  128. package/tools/voiceover.mjs +119 -261
  129. package/tools/zip.mjs +1 -1
  130. package/cli/dev.mjs +0 -623
  131. package/cli/present.mjs +0 -853
  132. package/cli/review.mjs +0 -361
  133. package/tools/publish-site-voices.mjs +0 -75
package/cli/dev.mjs DELETED
@@ -1,623 +0,0 @@
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 { ASK_MESSAGES, planCommitMessages } from './commit-message.mjs';
31
- import { validProjectId } from '../tools/gemini-tts.mjs';
32
- import {
33
- ENGINES as TTS_ENGINES, PIPER_DEFAULT_VOICE, piperModelDir, engineStatus,
34
- piperDownloadCmd, piperDownloadLine,
35
- } from '../tools/tts-engines.mjs';
36
- import { KEY_ENV as ELEVENLABS_KEY_ENV } from '../tools/elevenlabs-tts.mjs';
37
- import { loadTtsConfig, runSetupWizard } from '../tools/tts-setup.mjs';
38
- import { detectLocalVoice, OLLAMA_NOTE } from '../tools/local-voice.mjs';
39
- import { argReader, isMain } from '../tools/args.mjs';
40
- import { isPortOpen, resolvePortConflict } from './port-conflict.mjs';
41
- import { leashEnv } from './supervise.mjs';
42
- import { nextFlushDelay, parseReady, renderBanner } from './banner.mjs';
43
-
44
- const CLI = fileURLToPath(new URL('./decklight.mjs', import.meta.url));
45
- // The deck server's entry since `edit` stopped being a command: its module,
46
- // run directly. The dispatcher would refuse `edit` out loud.
47
- const EDIT = fileURLToPath(new URL('./edit.mjs', import.meta.url));
48
-
49
- const USAGE = `usage: decklight author <deck.html> [--port 8788] [--tts-port 8787] [--lipsync-port 8789]
50
- [--tts-engine gemini|chirp|piper|elevenlabs] [--project <id>] [--no-tts]
51
- [--git | --no-git] [--commit-every <s>] [--agent <name>]
52
- brings up the edit server plus every bridge this machine can run, under one Ctrl-C
53
-
54
- --port N edit server (live reload + edit write-back) [8788]
55
- (taken already? author offers to take over that session
56
- on a TTY, or moves to the next free port otherwise)
57
- --tts-port N live voice bridge [8787]
58
- --lipsync-port N lip-sync bridge (visemes + talking head) [8789]
59
- --no-tts don't start the voice bridge
60
- --no-lipsync don't start the lip-sync bridge
61
- --git / --no-git keep the deck in git (snapshot + K commits) / never touch git
62
- --git-mode M when to commit: agent (one per agent edit, and whenever you
63
- press K), timer (the old five-minute cadence), off [agent]
64
- (no repo + no flag: author ASKS whether to create one)
65
- --commit-every N cadence in seconds, timer mode only [300]
66
- --commit-messages an agent writes the commit subjects instead of the generic
67
- "autosave" — reads each commit's diff and amends the subject
68
- afterwards, so the commit itself is never delayed or risked.
69
- Opt-in: it sends the deck's diffs to the agent, and most
70
- agent CLIs are cloud-backed.
71
- --agent <name> preferred AI agent for A (default: first detected)
72
-
73
- every server binds 127.0.0.1; for a phone remote: decklight present --remote
74
-
75
- --tts-engine E gemini Vertex AI, best delivery, honors a style — no free tier [default]
76
- chirp Cloud TTS Chirp 3: HD — same voices, ~1s, 1M chars/month free
77
- piper local, offline, unlimited, no project needed
78
- elevenlabs your own account's voices, the ones you cloned first
79
- in the picker — needs $ELEVENLABS_API_KEY
80
- (nothing configured? on a terminal author offers a one-time
81
- guided setup; decklight tts --setup re-runs it)
82
-
83
- tts flags --project <id> (or $GOOGLE_CLOUD_PROJECT; gemini/chirp only),
84
- --tts-model, --location, --voice, --data-dir, --lang,
85
- --tts-format pcm|mp3 (elevenlabs),
86
- --tts-stability creative|natural|robust (elevenlabs eleven_v3 only)
87
- lipsync flags --rhubarb <bin>, --portrait <name=img.png>…, --wav2lip-dir,
88
- --wav2lip-ckpt, --sadtalker-dir, --python, --cache-dir,
89
- --veo (animate the portrait once through Vertex — BILLED),
90
- --veo-project, --veo-model, --veo-seconds, --veo-face-y
91
- (all passed straight through — see decklight tts --help / lipsync --help)`;
92
-
93
- // flags that take a value (so the deck argument can be found past them)
94
- const VALUE_FLAGS = new Set([
95
- '--port', '--tts-port', '--lipsync-port', '--tts-engine', '--project', '--tts-model',
96
- '--location', '--voice', '--data-dir', '--lang', '--tts-format', '--tts-stability',
97
- '--rhubarb', '--portrait', '--wav2lip-dir', '--wav2lip-ckpt', '--sadtalker-dir',
98
- '--python', '--cache-dir', '--commit-every', '--agent', '--git-mode',
99
- '--veo-project', '--veo-model', '--veo-seconds', '--veo-prompt', '--veo-location', '--veo-face-y',
100
- ]);
101
-
102
- /**
103
- * Decide what to bring up, WITHOUT starting anything — the whole capability
104
- * policy in one pure function, so it can be tested without binding a port.
105
- * `saved` is the machine-level tts config (~/.config/decklight/tts.json,
106
- * written by the setup wizard) — injected, not read here, so the plan stays
107
- * pure; precedence is flags > environment > saved config > built-in default.
108
- * Returns { deck, run: [{name, tag, entry, args, url}], skip: [{name, why}],
109
- * agents: [names the machine can run] } — `entry` is the script to spawn:
110
- * the bridges go through the dispatcher, the edit server (no longer a
111
- * command there) runs its own module.
112
- */
113
- export function planServices({
114
- args = [], env = process.env, hasBin = onPath, saved = null,
115
- detect = detectLocalVoice, ollama = false, exists = existsSync,
116
- } = {}) {
117
- const { opt, opts } = argReader(args);
118
- const has = (flag) => args.includes(flag);
119
- const pass = (flag) => (opt(flag) !== undefined ? [flag, opt(flag)] : []);
120
-
121
- // first bare token is the deck — step over flags that consume a value, so
122
- // `author --port 8788 deck.html` doesn't mistake "8788" for the deck
123
- let deck;
124
- for (let i = 0; i < args.length; i++) {
125
- const a = args[i];
126
- if (a.startsWith('-')) { if (VALUE_FLAGS.has(a)) i++; continue; }
127
- deck = a;
128
- break;
129
- }
130
-
131
- const run = [];
132
- const skip = [];
133
-
134
- const editPort = opt('--port', '8788');
135
- run.push({
136
- name: 'edit',
137
- tag: 'deck',
138
- entry: EDIT,
139
- args: [deck, '--port', editPort,
140
- ...(has('--git') ? ['--git'] : []), ...(has('--no-git') ? ['--no-git'] : []),
141
- ...pass('--commit-every'), ...pass('--agent'), ...pass('--git-mode'),
142
- // BOTH directions travel: the first-run question can answer no, and a no
143
- // that did not reach the server would be a question asked and ignored.
144
- ...(has('--commit-messages') ? ['--commit-messages'] : []),
145
- ...(has('--no-commit-messages') ? ['--no-commit-messages'] : [])],
146
- url: `http://127.0.0.1:${editPort}/${deck ?? ''}`,
147
- });
148
-
149
- // live voice — an engine that would exit for want of a credential should not
150
- // be started at all: the Google ones need a project, ElevenLabs needs a key,
151
- // and piper needs neither, only the binary
152
- const ttsPort = opt('--tts-port', '8787');
153
- const project = opt('--project', env.GOOGLE_CLOUD_PROJECT ?? saved?.project);
154
-
155
- // Nothing chosen, nothing saved, no cloud credential: rather than default to
156
- // an engine that will be skipped for want of a project, ask the machine what
157
- // it can already say. Every desktop OS ships a synthesizer, and on current
158
- // ones it is neural — free, offline, and nothing to download. An explicit
159
- // --tts-engine, a saved engine, or a project all win over this: flags decide,
160
- // detection only fills a vacuum.
161
- const chosen = opt('--tts-engine', saved?.engine);
162
- const native = chosen || project ? null : detect({ lang: opt('--lang') });
163
- // Only a NATIVE voice is claimed automatically. It is the one engine that
164
- // needs no setup at all — no install, no download, no credential — so using
165
- // it silently costs the presenter nothing. piper is deliberately NOT picked
166
- // here even when it is on PATH: it needs a toolchain and a ~120 MB model, and
167
- // choosing it behind the user's back would skip the first-run wizard that
168
- // exists to make (and save) exactly that choice.
169
- const ttsEngine = chosen ?? native?.engine ?? 'gemini';
170
- const cloudVoice = ttsEngine === 'gemini' || ttsEngine === 'chirp';
171
- const ttsArgs = () => [
172
- 'tts', '--port', ttsPort,
173
- // also when DETECTION chose the engine: without this the bridge would be
174
- // started with no --engine and fall back to its own default, so a machine
175
- // picked for its system voice would try to reach Vertex AI instead
176
- ...(has('--tts-engine') || saved?.engine || ttsEngine !== 'gemini' ? ['--engine', ttsEngine] : []),
177
- ...(cloudVoice ? ['--project', project] : []),
178
- ...pass('--tts-model'), ...pass('--location'),
179
- ...pass('--voice'), ...pass('--data-dir'), ...pass('--lang'), ...pass('--tts-format'),
180
- ...pass('--tts-stability'),
181
- ];
182
- // The SAME readiness check the bridge runs when the deck asks what it may
183
- // switch to (SPEC NARRATION). Sharing the decision is the point: a picker
184
- // that offered an engine `author` would have refused to start is a picker
185
- // that lies. Only the phrasing differs — here there is a terminal, a
186
- // presenter still setting things up, and room for the whole answer.
187
- const ttsVoice = opt('--voice', saved?.voice ?? PIPER_DEFAULT_VOICE);
188
- const ttsData = opt('--data-dir', piperModelDir(env));
189
- const status = engineStatus(ttsEngine, {
190
- env, project, voice: ttsVoice, dataDir: ttsData, lang: opt('--lang'),
191
- // every probe threaded through, `detect` included: these are the injection
192
- // points that let planServices be tested on any machine, and a readiness
193
- // check reaching for the REAL PATH or the REAL synthesizer would decide a
194
- // test's answer from the host it happened to run on
195
- hasBin, exists, detect,
196
- });
197
- if (has('--no-tts')) {
198
- skip.push({ name: 'voice', why: 'disabled with --no-tts' });
199
- } else if (status.reason === 'unknown') {
200
- skip.push({ name: 'voice', why: `unknown --tts-engine '${ttsEngine}' — use ${TTS_ENGINES.join(', ')}` });
201
- } else if (status.reason === 'no-binary') {
202
- skip.push({ name: 'voice', why: 'piper not on PATH — install it (uv tool install piper-tts)' });
203
- } else if (status.reason === 'no-model') {
204
- // piper is installed but has no voice to speak with. The bridge would come
205
- // up looking healthy and fail on the first sentence — a keypress into
206
- // silence — so it is caught here, where the fix can be offered instead.
207
- const download = piperDownloadCmd(ttsVoice, ttsData, { hasBin: (b) => hasBin(b, env) });
208
- skip.push({
209
- name: 'voice',
210
- why: `the piper voice ${ttsVoice} is not in ${ttsData} (~120 MB, one time)`
211
- + ` — ${piperDownloadLine(download)}`,
212
- download, // author offers to run this on a TTY; nothing is ever pulled silently
213
- });
214
- } else if (status.reason === 'no-key') {
215
- // The key never lands in the saved config, so the environment is the only
216
- // place it can come from — say that, and where to make one.
217
- skip.push({ name: 'voice', why: `elevenlabs needs $${ELEVENLABS_KEY_ENV} — create a key at https://elevenlabs.io/app/settings/api-keys and export it` });
218
- } else if (status.reason === 'no-project') {
219
- skip.push({
220
- name: 'voice',
221
- why: `${ttsEngine} needs a GCP project — pass --project <id> or set GOOGLE_CLOUD_PROJECT`
222
- + (native?.why ? `\n this machine has no system voice either: ${native.why}` : '')
223
- + (native?.suggest ? `\n ${native.suggest}` : ' — or use --tts-engine piper')
224
- // Ollama is the thing a local-AI user assumes covers this. It does not,
225
- // and being told why beats concluding decklight ignores their stack.
226
- + (ollama ? `\n ${OLLAMA_NOTE}` : ''),
227
- });
228
- } else if (status.reason === 'bad-project') {
229
- // caught here rather than at the first narration: the bridge would start,
230
- // look healthy, and only fail on a keypress — with a 403 naming a project
231
- // nobody typed
232
- skip.push({ name: 'voice', why: `not a GCP project id: ${JSON.stringify(project)} — stray punctuation from a copy-paste?` });
233
- } else if (status.reason === 'no-native-voice') {
234
- // New with the shared check: `--tts-engine say` on a machine whose OS has
235
- // no synthesizer used to start a bridge that failed on the first keypress.
236
- skip.push({ name: 'voice', why: `${ttsEngine}: ${status.why ?? 'no system voice on this machine'}` });
237
- } else {
238
- run.push({ name: 'tts', tag: 'voice', entry: CLI, args: ttsArgs(), url: `http://127.0.0.1:${ttsPort}` });
239
- }
240
-
241
- // lip-sync — starts degraded (it probes its own engines), so only bother when
242
- // something it can actually use is present
243
- const lipPort = opt('--lipsync-port', '8789');
244
- const rhubarb = opt('--rhubarb', 'rhubarb');
245
- const configured = has('--rhubarb') || has('--portrait') || has('--wav2lip-dir') || has('--sadtalker-dir');
246
- if (has('--no-lipsync')) {
247
- skip.push({ name: 'lip-sync', why: 'disabled with --no-lipsync' });
248
- } else if (!configured && !hasBin(rhubarb, env)) {
249
- skip.push({ name: 'lip-sync', why: 'rhubarb not on PATH — install it, or pass --rhubarb/--portrait' });
250
- } else {
251
- run.push({
252
- name: 'lipsync',
253
- tag: 'lips',
254
- entry: CLI,
255
- args: [
256
- 'lipsync', '--port', lipPort,
257
- ...(has('--rhubarb') ? ['--rhubarb', rhubarb] : []),
258
- ...opts('--portrait').flatMap((p) => ['--portrait', p]),
259
- ...pass('--wav2lip-dir'), ...pass('--wav2lip-ckpt'),
260
- ...pass('--sadtalker-dir'), ...pass('--python'), ...pass('--cache-dir'),
261
- // --veo animates the portrait through Vertex (once, then cached) so the
262
- // narrator moves while you author; it is the one bridge flag that spends
263
- // money, so it is opt-in here exactly as it is on `decklight lipsync`
264
- ...(has('--veo') ? ['--veo'] : []),
265
- ...pass('--veo-project'), ...pass('--veo-model'),
266
- ...pass('--veo-seconds'), ...pass('--veo-prompt'), ...pass('--veo-location'),
267
- ...pass('--veo-face-y'),
268
- ],
269
- url: `http://127.0.0.1:${lipPort}`,
270
- });
271
- }
272
-
273
- // Reported, not passed through. The phone remote moved to `present`
274
- // (PRESENT#REMOTE), and a flag that quietly did nothing would leave someone
275
- // holding a phone that never connects. devMain is what prints and exits —
276
- // the plan stays pure so a test can ask what it decided.
277
- const gone = ['--remote', '--host'].filter((f) => args.some((a) => a === f || a.startsWith(f + '=')));
278
- return { deck, run, skip, gone, agents: detectAgents({ env, hasBin }).map((a) => a.name) };
279
- }
280
-
281
- /**
282
- * Should author OFFER the tts setup wizard instead of just printing the skip
283
- * line? Only when the skip is the fixable kind — no engine configured, no
284
- * project to run the default cloud engine with — never when a flag chose the
285
- * outcome (--no-tts, an unknown engine, a malformed --project: the user's
286
- * hand is on the wheel, and the skip line already names the fix).
287
- */
288
- /** The voice is skipped only for want of a model, and we know how to fetch it. */
289
- export const voiceModelOffer = (plan) => {
290
- const s = plan.skip.find((x) => x.name === 'voice');
291
- return s?.download ? s : null;
292
- };
293
-
294
- export const voiceSetupOffer = (plan) => {
295
- const s = plan.skip.find((x) => x.name === 'voice');
296
- return s && /needs a GCP project/.test(s.why) ? s : null;
297
- };
298
-
299
- // inGitRepo lives in git.mjs now; re-exported so importers (and the tests) keep
300
- // finding it where dev grew it.
301
- export { inGitRepo } from './git.mjs';
302
- import { inGitRepo } from './git.mjs';
303
-
304
- const COLORS = { deck: '\x1b[36m', voice: '\x1b[35m', lips: '\x1b[33m' };
305
- const DIM = '\x1b[2m';
306
- const RESET = '\x1b[0m';
307
-
308
- export async function devMain(args) {
309
- if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return; }
310
-
311
- let plan = planServices({ args, saved: loadTtsConfig() });
312
- if (plan.gone.length) {
313
- console.error(`decklight author no longer takes ${plan.gone.join(' or ')} — the phone remote moved to \`decklight present\`.`);
314
- console.error(' A clicker used to cost you an editing server on the LAN: /edit/notes, /edit/layout and');
315
- console.error(' /edit/agent were reachable from the same run you were not watching. present has no edit');
316
- console.error(' surface to widen, so that is where it lives.');
317
- console.error(`\n decklight present ${plan.deck ?? '<deck.html>'} --remote`);
318
- process.exitCode = 2;
319
- return;
320
- }
321
- const deck = plan.deck;
322
- if (!deck) {
323
- console.error('decklight author needs a deck: decklight author <deck.html>\n');
324
- console.error(USAGE);
325
- process.exitCode = 1;
326
- return;
327
- }
328
- if (!existsSync(deck)) {
329
- console.error(`decklight author: no such deck: ${deck}`);
330
- process.exitCode = 1;
331
- return;
332
- }
333
-
334
- // No repo, no flag: offer one. A repo is where the regular autocommits go —
335
- // the durable record behind the player's fast undo/redo loop. Only a TTY
336
- // can be asked; headless runs stay git-less until --git says otherwise.
337
- if (!args.includes('--git') && !args.includes('--no-git') && !inGitRepo(process.cwd())) {
338
- if (process.stdin.isTTY && process.stdout.isTTY) {
339
- const rl = createInterface({ input: process.stdin, output: process.stdout });
340
- const answer = await rl.question(' no git repository here — create one and auto-commit the deck as you edit? [Y/n] ');
341
- const yes = !/^n/i.test(answer.trim());
342
- args = [...args, yes ? '--git' : '--no-git'];
343
- // Only while we are ALREADY setting git up, and only when an agent could
344
- // actually drive edits, offer the boundary that suits agent work. A
345
- // session in an existing repository gains no new question — that is the
346
- // one thing this must not cost, so `--git-mode agent` is how you reach it
347
- // there.
348
- if (yes && !args.includes('--git-mode') && detectAgents().length) {
349
- const mode = await rl.question(" commit once per agent edit, with the agent's own message, instead of on a timer? [y/N] ");
350
- if (/^y/i.test(mode.trim())) args = [...args, '--git-mode', 'agent'];
351
- }
352
- // The other half of what those commits say. Same moment, same reason as
353
- // init's: the repository is being created right now, so this is when the
354
- // commits it governs start existing. Default yes — but still a question,
355
- // because the answer sends the deck's diffs to an agent.
356
- if (yes) {
357
- const msgs = planCommitMessages({
358
- args, tty: true, agents: detectAgents().length, creatingRepo: true,
359
- stored: null, // the repo does not exist yet, so nothing is stored
360
- });
361
- if (msgs.action === 'ask') {
362
- const a = (await rl.question(ASK_MESSAGES)).trim();
363
- if (!/^n/i.test(a)) args = [...args, '--commit-messages'];
364
- else args = [...args, '--no-commit-messages'];
365
- }
366
- }
367
- rl.close();
368
- plan = planServices({ args, saved: loadTtsConfig() });
369
- } else {
370
- console.log(' git: no repository here — pass --git to create one and auto-commit the deck');
371
- }
372
- }
373
- // piper is installed and chosen, but its voice model is not on disk. The
374
- // download is ~120 MB, so it is ASKED FOR, never silent — and only on a TTY,
375
- // so CI and pipes keep the skip line exactly as it was. Accepting re-plans,
376
- // so the bridge joins `run` and comes up in this same session.
377
- {
378
- const offer = voiceModelOffer(plan);
379
- if (offer && process.stdin.isTTY && process.stdout.isTTY) {
380
- const rl = createInterface({ input: process.stdin, output: process.stdout });
381
- try {
382
- console.log(` ${offer.why}`);
383
- const answer = await rl.question(' download it now? [Y/n] ');
384
- if (!/^n/i.test(answer.trim())) {
385
- const { bin, args: dlArgs } = offer.download;
386
- const r = spawnSync(bin, dlArgs, { stdio: 'inherit' });
387
- if (r.status === 0) plan = planServices({ args });
388
- else console.log(' download failed — the voice stays skipped');
389
- }
390
- } finally { rl.close(); }
391
- }
392
- }
393
- // The voice would be skipped for the one reason setup can fix: nothing is
394
- // configured. Offer the guided setup (TTY only — headless runs keep the
395
- // skip line exactly as it was); a completed setup re-plans, so the bridge
396
- // joins `run` and comes up in this same session.
397
- if (voiceSetupOffer(plan) && process.stdin.isTTY && process.stdout.isTTY) {
398
- const rl = createInterface({ input: process.stdin, output: process.stdout });
399
- try {
400
- const answer = await rl.question(' no voice engine configured — set up live narration now? (V in the deck uses it) [Y/n] ');
401
- if (!/^n/i.test(answer.trim())) {
402
- const result = await runSetupWizard({ ask: (q) => rl.question(q) });
403
- if (result) {
404
- // the wizard's test synthesis may hold a resident engine (piper);
405
- // author runs the bridge as its own child process, so let it go
406
- result.engine.synth.close?.();
407
- plan = planServices({ args, saved: result.config });
408
- }
409
- }
410
- } finally { rl.close(); }
411
- }
412
- // The edit port might already be held — often an earlier decklight session
413
- // left running. Resolved here, with author's OWN stdin, because the edit
414
- // child below is spawned with its stdin piped (not a terminal) and could
415
- // never ask on its own.
416
- const editSvc = plan.run.find((s) => s.name === 'edit');
417
- if (editSvc) {
418
- const portIdx = editSvc.args.indexOf('--port');
419
- const editPort = Number(editSvc.args[portIdx + 1]);
420
- if (await isPortOpen(editPort)) {
421
- const askTty = process.stdin.isTTY && process.stdout.isTTY;
422
- let rl;
423
- const ask = askTty ? (q) => (rl ??= createInterface({ input: process.stdin, output: process.stdout })).question(q) : undefined;
424
- const freshPort = await resolvePortConflict(editPort, { ask, log: console.log });
425
- rl?.close();
426
- editSvc.args[portIdx + 1] = String(freshPort);
427
- editSvc.url = `http://127.0.0.1:${freshPort}/${deck}`;
428
- }
429
- }
430
- const { run, skip, agents } = plan;
431
-
432
- const tty = process.stdout.isTTY;
433
- const paint = (tag) => (tty ? `${COLORS[tag] ?? ''}${tag.padEnd(5)}${RESET}` : `${tag.padEnd(5)}`);
434
- const note = (s) => (tty ? `${DIM}${s}${RESET}` : s);
435
-
436
- const children = new Map();
437
- let shuttingDown = false;
438
-
439
- // ── the startup banner ────────────────────────────────────────────────────
440
- // Children report a row and author prints all of them at once, so the URL is
441
- // last no matter which server woke up first (cli/banner.mjs says why).
442
- //
443
- // WHEN to print is the only hard part. Waiting for every service is wrong —
444
- // one that never comes up would hold the URL hostage — and printing on the
445
- // first fact is wrong too, since the rest arrive milliseconds later. So:
446
- // settle after a short quiet gap, with a hard cap in case a child is slow or
447
- // silent. The review check is the late one on purpose (edit.mjs fires it
448
- // detached, after listening), and GRACE is sized for it; if it misses, it
449
- // prints under the banner as its own row rather than delaying the URL.
450
- // The cap is generous because it is the LAST resort, not the schedule: in the
451
- // normal case every service reports and the banner goes out on the grace
452
- // timer, well inside a second. The cap only matters when a child is silent,
453
- // and then waiting is the right thing anyway — that row is missing from the
454
- // banner either way, and a fast wrong banner is not better than a slow right
455
- // one by four seconds.
456
- const BANNER_CAP_MS = 5000;
457
- const BANNER_GRACE_MS = 350;
458
- const banner = {
459
- done: false, held: [], rows: new Map(),
460
- url: editSvc?.url ?? null, keys: null, timer: null, start: Date.now(),
461
- // Who still owes us a row. The voice bridge enumerates the machine's
462
- // voices before it can say what it is, which takes longer than any grace
463
- // window worth having — so the banner waits on NAMES, not on a clock.
464
- waiting: new Set(run.map((svc) => svc.tag)),
465
- };
466
-
467
- const bannerRow = (key, text) => ` ${tty ? `${DIM}${key}${RESET}` : key} ${text}`;
468
-
469
- /**
470
- * A line from author itself. Held while the banner is still being assembled,
471
- * so nothing — an error included — can land above the URL; printed straight
472
- * away once it is out.
473
- */
474
- function say(line) {
475
- // Never a caller's choice. It was one, and the caller that passed its own
476
- // answer got it wrong in the one case that mattered: the LAST service to
477
- // exit computed "nobody is waiting" and printed straight away, while the
478
- // flush timer it had just armed was still mid-flight — so its line landed
479
- // above the banner it was supposed to sit under.
480
- if (banner.done) process.stderr.write(`${line}\n`);
481
- else banner.held.push(line);
482
- }
483
-
484
- function flushBanner() {
485
- if (banner.done) return;
486
- banner.done = true;
487
- clearTimeout(banner.timer);
488
- // Held output goes FIRST, and the banner closes. Everything in here is a
489
- // child explaining itself — a bridge saying why it stood aside, a service
490
- // saying why it exited — and an explanation belongs before the summary it
491
- // explains. It also keeps the promise that matters: whatever was said on
492
- // the way up, the deck's url is still the last line on screen.
493
- for (const l of banner.held) process.stdout.write(`${l}\n`);
494
- banner.held.length = 0;
495
- if (banner.url) {
496
- const rows = [...banner.rows].map(([key, text]) => ({ key, text }));
497
- for (const l of renderBanner({ deck, url: banner.url, keys: banner.keys, rows, color: tty })) {
498
- process.stdout.write(`${l}\n`);
499
- }
500
- }
501
- }
502
-
503
- /**
504
- * A service has said its piece. Print once nobody is still owed, and keep a
505
- * short grace after that for the genuinely late — the review check fires
506
- * detached, after the deck server is already listening.
507
- */
508
- function settle(tag) {
509
- banner.waiting.delete(tag);
510
- const delay = nextFlushDelay({
511
- waiting: banner.waiting.size,
512
- elapsed: Date.now() - banner.start,
513
- cap: BANNER_CAP_MS,
514
- grace: BANNER_GRACE_MS,
515
- });
516
- if (delay === null) return;
517
- clearTimeout(banner.timer);
518
- banner.timer = setTimeout(flushBanner, delay);
519
- banner.timer.unref?.();
520
- }
521
-
522
- function collect(tag, fact) {
523
- if (fact.url) banner.url = fact.url;
524
- if (fact.keys) banner.keys = fact.keys;
525
- if (!fact.key || !fact.text) { if (fact.url) settle(tag); return; }
526
- if (banner.done) {
527
- // Arrived after the banner went out — still worth saying, in the shape
528
- // it would have had, rather than swallowed for being late.
529
- process.stdout.write(`${bannerRow(fact.key, fact.text)}\n`);
530
- return;
531
- }
532
- // Two facts can share a key — `git` is both "commits on your word" and
533
- // "claude writes the subjects", reported by different parts of the child.
534
- // They join into one row rather than the later one erasing the earlier.
535
- const had = banner.rows.get(fact.key);
536
- banner.rows.set(fact.key, had && had !== fact.text ? `${had} · ${fact.text}` : fact.text);
537
- settle(tag);
538
- }
539
- // Even if no child ever reports, the URL must still appear.
540
- banner.timer = setTimeout(flushBanner, BANNER_CAP_MS);
541
- banner.timer.unref?.();
542
-
543
- // Children write their own startup/progress lines; prefix each so three
544
- // servers in one terminal stay readable.
545
- const pipe = (stream, tag, out) => {
546
- let buf = '';
547
- stream.setEncoding('utf8');
548
- stream.on('data', (chunk) => {
549
- buf += chunk;
550
- const lines = buf.split('\n');
551
- buf = lines.pop() ?? '';
552
- for (const line of lines) {
553
- // A startup FACT is for the banner, never for the terminal — it is the
554
- // child saying "here is my row", not "here is a line to show someone".
555
- const fact = parseReady(line);
556
- if (fact) { collect(tag, fact); continue; }
557
- // Anything else is ordinary output. Before the banner it is held back
558
- // so nothing lands above the URL; after, it streams as it always did.
559
- if (!banner.done) banner.held.push(`${paint(tag)} ${line}`);
560
- else out.write(`${paint(tag)} ${line}\n`);
561
- }
562
- });
563
- };
564
-
565
- for (const svc of run) {
566
- // stdin is a pipe author never writes to — it is the leash (see supervise.mjs).
567
- // Holding it open is what tells the child we are still here; losing it is
568
- // how the child finds out we are not, even when we were SIGKILLed and
569
- // never reached shutdown() below.
570
- const child = spawn(process.execPath, [svc.entry, ...svc.args], {
571
- stdio: ['pipe', 'pipe', 'pipe'],
572
- // DECKLIGHT_BANNER is how a child knows its startup lines belong to
573
- // somebody else's banner. Unset — `decklight edit`, `decklight tts` run
574
- // straight — and it prints exactly what it always printed.
575
- env: { ...leashEnv(), DECKLIGHT_BANNER: '1' },
576
- });
577
- children.set(svc.name, child);
578
- pipe(child.stdout, svc.tag, process.stdout);
579
- pipe(child.stderr, svc.tag, process.stderr);
580
-
581
- child.on('exit', (code) => {
582
- children.delete(svc.name);
583
- if (shuttingDown) return;
584
- // It owes no row now — a dead process is never going to report one, and
585
- // the banner must not sit on the URL waiting for it. This is the common
586
- // case, not a pathological one: a voice bridge that stands aside because
587
- // another already serves its port exits 0, seconds into startup.
588
- if (svc.name === 'edit') {
589
- // the deck server is the one service author cannot run without
590
- say(`${paint(svc.tag)} exited (${code}) — stopping decklight author`);
591
- flushBanner();
592
- shutdown(code ?? 1);
593
- } else {
594
- say(`${paint(svc.tag)} exited (${code}) — carrying on without it; the deck degrades on its own`);
595
- settle(svc.tag); // settle() does the delete and the "is anyone left" itself
596
- }
597
- });
598
- }
599
-
600
- // author's own facts join the children's rather than printing above them.
601
- // `Ctrl-C stops everything` is gone: the banner's key line already says it,
602
- // and saying it twice was most of why this block read as a wall.
603
- if (skip.length) banner.rows.set('skipped', skip.map((s) => `${s.name} — ${s.why}`).join(' · '));
604
- // Only when there are none — otherwise the edit child names them, and its
605
- // row (which knows which is preferred and which is installed) wins.
606
- if (!agents.length) banner.rows.set('agents', 'none — install claude, codex, or bob to ask one from the deck (A)');
607
-
608
- function shutdown(code = 0) {
609
- if (shuttingDown) return;
610
- shuttingDown = true;
611
- for (const child of children.values()) child.kill('SIGTERM');
612
- // give them a beat to close their listeners, then go
613
- setTimeout(() => {
614
- for (const child of children.values()) child.kill('SIGKILL');
615
- process.exit(code);
616
- }, 500).unref();
617
- }
618
-
619
- process.on('SIGINT', () => shutdown(0));
620
- process.on('SIGTERM', () => shutdown(0));
621
- }
622
-
623
- if (isMain(import.meta.url)) devMain(process.argv.slice(2));