decklight 0.8.1 → 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 +57 -24
  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 +1 -1
  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 +17 -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
@@ -21,6 +21,7 @@ import { execFile } from 'node:child_process';
21
21
  import { promisify } from 'node:util';
22
22
  import { readFileSync, writeFileSync, rmSync, mkdirSync, readdirSync, statSync, renameSync } from 'node:fs';
23
23
  import { resolve, join } from 'node:path';
24
+ import { createHash } from 'node:crypto';
24
25
  import { normalizeRhubarb } from './visemes.mjs';
25
26
 
26
27
  const run = promisify(execFile);
@@ -45,13 +46,215 @@ export async function runRhubarb(rhubarb, { wav, dialogFile, out, timeout } = {}
45
46
  * `smallBatches` when the face is a multi-frame clip — the default batch size
46
47
  * OOMs an 8 GB card ("Image too big to run face detection on GPU").
47
48
  */
48
- export async function runWav2lip(python, { dir, checkpoint, face, wav, out, smallBatches, inherit, timeout } = {}) {
49
+ export async function runWav2lip(python, { dir, checkpoint, face, wav, out, smallBatches, box, inherit, timeout } = {}) {
49
50
  const batches = smallBatches ? ['--face_det_batch_size', '4', '--wav2lip_batch_size', '32'] : [];
51
+ // A known face box (a still's, found once — `faceBox`) skips Wav2Lip's own
52
+ // per-clip detection; its order is top bottom left right.
53
+ const boxArgs = box ? ['--box', String(box.y1), String(box.y2), String(box.x1), String(box.x2)] : [];
50
54
  await run(python, ['inference.py', '--checkpoint_path', resolve(checkpoint),
51
- '--face', face, '--audio', wav, '--outfile', out, ...batches],
55
+ '--face', face, '--audio', wav, '--outfile', out, ...batches, ...boxArgs],
52
56
  { cwd: resolve(dir), ...bufOpts(timeout, inherit) });
53
57
  }
54
58
 
59
+ /** The longest side a portrait is handed to Wav2Lip at — S3FD misses faces in a phone photo at full size. */
60
+ export const STILL_MAX = 1024;
61
+
62
+ /**
63
+ * A portrait as Wav2Lip can use it: at most STILL_MAX tall (a 3088-pixel
64
+ * phone photo is a face S3FD does not find — measured: none at full size,
65
+ * found at half), JPEG, cached by content. Small enough already: the file itself.
66
+ */
67
+ export async function prepareStill(still, cacheDir, { timeout = 60000 } = {}) {
68
+ const { stdout } = await run('ffprobe', ['-v', 'error', '-select_streams', 'v:0',
69
+ '-show_entries', 'stream=width,height', '-of', 'csv=p=0', still], { timeout });
70
+ const [w, h] = String(stdout).trim().split(',').map(Number);
71
+ if (!(Math.max(w, h) > STILL_MAX)) return still;
72
+ const key = createHash('sha256').update(readFileSync(still)).digest('hex').slice(0, 24);
73
+ const out = join(cacheDir, `still-${key}.jpg`);
74
+ try { statSync(out); return out; } catch { /* not yet */ }
75
+ const scale = h >= w ? `scale=-2:${STILL_MAX}` : `scale=${STILL_MAX}:-2`;
76
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', still, '-vf', scale, '-q:v', '2', out], { timeout });
77
+ return out;
78
+ }
79
+
80
+ /**
81
+ * Where the face is in each of `files` (same-size frames), with Wav2Lip's own
82
+ * detector and the Python that has its packages: `{x1, y1, x2, y2}` or null
83
+ * per file. Padded 25 px below the chin (Wav2Lip's `--pads 0 10` leaves a
84
+ * seam across it).
85
+ */
86
+ async function detectFaces(python, { dir, files, timeout }) {
87
+ const code = [
88
+ 'import sys, json, cv2, numpy as np, face_detection',
89
+ "det = face_detection.FaceAlignment(face_detection.LandmarksType._2D, flip_input=False, device='cpu')",
90
+ 'out = []',
91
+ 'for f in sys.argv[1:]:',
92
+ ' r = det.get_detections_for_batch(np.array([cv2.imread(f)]))[0]',
93
+ ' out.append(None if r is None else [int(v) for v in r[:4]])',
94
+ 'print(json.dumps(out))',
95
+ ].join('\n');
96
+ const { stdout } = await run(python, ['-c', code, ...files.map((f) => resolve(f))],
97
+ { cwd: resolve(dir), timeout, maxBuffer: 16 * 1024 * 1024 });
98
+ const found = JSON.parse(String(stdout).trim().split('\n').pop() || '[]');
99
+ return found.map((r) => r && { x1: r[0], y1: r[1], x2: r[2], y2: r[3] + 25 });
100
+ }
101
+
102
+ /**
103
+ * Where the face is in a still — found ONCE and cached. Null when no face is
104
+ * found: Wav2Lip then detects per clip, and the composite is skipped.
105
+ */
106
+ export async function faceBox(python, { dir, still, cacheDir, timeout = 180000 } = {}) {
107
+ const key = createHash('sha256').update(readFileSync(still)).digest('hex').slice(0, 24);
108
+ const out = join(cacheDir, `box-${key}.json`);
109
+ try { return JSON.parse(readFileSync(out, 'utf8')); } catch { /* not yet */ }
110
+ const [box = null] = await detectFaces(python, { dir, files: [still], timeout });
111
+ writeFileSync(out, JSON.stringify(box));
112
+ return box;
113
+ }
114
+
115
+ /**
116
+ * The square a head is cropped to in a `width`×`height` frame: 1.7× the face,
117
+ * the face a little above centre, kept inside the frame. Pure.
118
+ */
119
+ export function squareAround(box, width, height) {
120
+ const fw = box.x2 - box.x1;
121
+ const fh = box.y2 - box.y1;
122
+ const side = Math.min(width, height, Math.round(1.7 * Math.max(fw, fh))) & ~1; // even, for yuv420p
123
+ const cx = (box.x1 + box.x2) / 2;
124
+ const cy = box.y1 + 0.45 * fh;
125
+ const x = Math.max(0, Math.min(width - side, Math.round(cx - side / 2)));
126
+ const y = Math.max(0, Math.min(height - side, Math.round(cy - side / 2)));
127
+ return { x, y, side };
128
+ }
129
+
130
+ /**
131
+ * The still cropped to a SQUARE around the head — what the deck's round
132
+ * overlay shows, so the face fills it instead of sitting small in a whole
133
+ * head-and-shoulders photo (and a smaller frame renders faster). The box comes
134
+ * back moved into the crop. Cached by content and box.
135
+ */
136
+ export async function headCrop(still, box, cacheDir, { width, height, timeout = 60000 } = {}) {
137
+ if (!width || !height) {
138
+ const { stdout } = await run('ffprobe', ['-v', 'error', '-select_streams', 'v:0',
139
+ '-show_entries', 'stream=width,height', '-of', 'csv=p=0', still], { timeout });
140
+ [width, height] = String(stdout).trim().split(',').map(Number);
141
+ }
142
+ const { x, y, side } = squareAround(box, width, height);
143
+ const key = createHash('sha256').update(readFileSync(still)).update(`${x},${y},${side}`).digest('hex').slice(0, 24);
144
+ const out = join(cacheDir, `head-${key}.jpg`);
145
+ try { statSync(out); } catch {
146
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', still, '-vf', `crop=${side}:${side}:${x}:${y}`, '-q:v', '2', out], { timeout });
147
+ }
148
+ return { file: out, box: { x1: box.x1 - x, y1: box.y1 - y, x2: box.x2 - x, y2: box.y2 - y } };
149
+ }
150
+
151
+ /**
152
+ * The mouth, and only the mouth, from Wav2Lip's clip, laid over the SHARP
153
+ * still. Wav2Lip redraws the whole face box at 96 px, so glasses, eyes and
154
+ * skin come back soft and blocky; a feathered ellipse over the mouth and chin
155
+ * — placed from the face box — keeps everything else the photograph.
156
+ * `still` may be a filmed portrait's loop (`prepareClip`) instead: Wav2Lip's
157
+ * frame i is the loop's frame i, both from 0 at 25 fps, so the loop replayed
158
+ * beside it lines up frame for frame.
159
+ */
160
+ export async function mouthComposite(still, talk, box, out, { timeout = 180000 } = {}) {
161
+ const w = box.x2 - box.x1;
162
+ const h = box.y2 - box.y1;
163
+ const cx = Math.round((box.x1 + box.x2) / 2);
164
+ const cy = Math.round(box.y1 + 0.74 * h);
165
+ const rx = Math.round(0.44 * w);
166
+ const ry = Math.round(0.26 * h);
167
+ const mask = `format=gray,geq=lum='if(lt(pow((X-${cx})/${rx},2)+pow((Y-${cy})/${ry},2),1),255,0)',gblur=sigma=18`;
168
+ const source = isClip(still) ? ['-stream_loop', '-1', '-i', still] : ['-loop', '1', '-i', still];
169
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', talk, ...source,
170
+ '-filter_complex',
171
+ `[0:v]format=yuv444p,split[talk][ref];[1:v]format=yuv444p[st];[st][ref]scale2ref[still][sz];[sz]${mask},format=yuv444p[m];`
172
+ // limited range, like every other clip: a JPEG still makes it yuvj420p
173
+ // (full range), which some players decode washed out or not at all
174
+ + '[still][talk][m]maskedmerge,scale=out_range=tv,format=yuv420p[v]',
175
+ '-map', '[v]', '-map', '0:a?', '-shortest', '-c:v', 'libx264', '-crf', '20', '-c:a', 'aac', out], { timeout });
176
+ }
177
+
178
+ /** A portrait given as a video — filmed, not photographed. */
179
+ export const isClip = (file) => /\.(mp4|mov|m4v|webm|mkv)$/i.test(String(file));
180
+
181
+ /** The longest stretch of a filmed portrait used — it plays forward, then back. */
182
+ export const CLIP_MAX_SECONDS = 10;
183
+ const CLIP_FPS = 25;
184
+
185
+ /**
186
+ * One box for a head across a filmed portrait's sampled frames: their union,
187
+ * and whether the head held STILL — every frame has a face, and its centre
188
+ * wanders less than `tol` of the face's width. A steady head's union box can
189
+ * be handed to Wav2Lip for every frame and the mouth composited over the
190
+ * film; a moving one cannot. Pure.
191
+ */
192
+ export function steadyBox(boxes, { tol = 0.1 } = {}) {
193
+ const found = boxes.filter(Boolean);
194
+ if (!found.length) return { box: null, steady: false, found: 0 };
195
+ const box = {
196
+ x1: Math.min(...found.map((b) => b.x1)), y1: Math.min(...found.map((b) => b.y1)),
197
+ x2: Math.max(...found.map((b) => b.x2)), y2: Math.max(...found.map((b) => b.y2)),
198
+ };
199
+ const cx = found.map((b) => (b.x1 + b.x2) / 2);
200
+ const cy = found.map((b) => (b.y1 + b.y2) / 2);
201
+ const width = Math.min(...found.map((b) => b.x2 - b.x1));
202
+ const wander = Math.max(Math.max(...cx) - Math.min(...cx), Math.max(...cy) - Math.min(...cy));
203
+ return { box, steady: found.length === boxes.length && wander <= tol * width, found: found.length };
204
+ }
205
+
206
+ /**
207
+ * A filmed portrait as Wav2Lip can use it, made ONCE and cached by content:
208
+ * - at most CLIP_MAX_SECONDS, 25 fps, no sound, at most STILL_MAX tall;
209
+ * - its face found in one frame a second (`steadyBox`);
210
+ * - cropped square around the head, like a photo;
211
+ * - played forward then backward, so the loop Wav2Lip makes of it for a
212
+ * long sentence never snaps the head back to the start;
213
+ * - its first frame kept as the still the deck shows under the video.
214
+ * Returns `{ loop, still, box, steady, seconds }` — `box` in the crop.
215
+ * Throws when no frame has a face: a film of the back of a head is not a
216
+ * portrait, and saying so beats a Wav2Lip traceback per sentence.
217
+ */
218
+ export async function prepareClip(python, { dir, clip, cacheDir, timeout = 600000 } = {}) {
219
+ const key = createHash('sha256').update('clip-v1|').update(readFileSync(clip)).digest('hex').slice(0, 24);
220
+ const meta = join(cacheDir, `clip-${key}.json`);
221
+ try { return JSON.parse(readFileSync(meta, 'utf8')); } catch { /* not yet */ }
222
+ const work = join(cacheDir, `clip-${key}.tmp.d`);
223
+ rmSync(work, { recursive: true, force: true });
224
+ mkdirSync(work, { recursive: true });
225
+ try {
226
+ const norm = join(work, 'norm.mp4');
227
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', clip, '-t', String(CLIP_MAX_SECONDS), '-an',
228
+ '-vf', `fps=${CLIP_FPS},scale=w='min(iw,${STILL_MAX})':h='min(ih,${STILL_MAX})':force_original_aspect_ratio=decrease,scale=trunc(iw/2)*2:trunc(ih/2)*2`,
229
+ '-c:v', 'libx264', '-crf', '16', '-pix_fmt', 'yuv420p', norm], { timeout });
230
+ const { stdout } = await run('ffprobe', ['-v', 'error', '-select_streams', 'v:0',
231
+ '-show_entries', 'stream=width,height:format=duration', '-of', 'json', norm], { timeout });
232
+ const probe = JSON.parse(String(stdout));
233
+ const { width, height } = probe.streams[0];
234
+ const seconds = Number(probe.format?.duration) || 0;
235
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', norm, '-vf', 'fps=1', '-q:v', '2', join(work, 'f-%03d.jpg')], { timeout });
236
+ const frames = readdirSync(work).filter((f) => /^f-\d+\.jpg$/.test(f)).sort().map((f) => join(work, f));
237
+ const { box, steady, found } = steadyBox(await detectFaces(python, { dir, files: frames, timeout }));
238
+ if (!box) throw new Error(`no face found in ${clip} — film the face toward the camera, evenly lit`);
239
+ const { x, y, side } = squareAround(box, width, height);
240
+ const loop = join(cacheDir, `clip-${key}.mp4`);
241
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', norm, '-filter_complex',
242
+ // the turn-around frame once, not twice — a held frame reads as a hitch
243
+ `[0:v]crop=${side}:${side}:${x}:${y},split[f][b];[b]reverse,trim=start_frame=1,setpts=PTS-STARTPTS[r];[f][r]concat=n=2:v=1:a=0,format=yuv420p[v]`,
244
+ '-map', '[v]', '-r', String(CLIP_FPS), '-c:v', 'libx264', '-crf', '16', '-movflags', '+faststart', loop], { timeout });
245
+ const still = join(cacheDir, `clip-${key}.jpg`);
246
+ await run('ffmpeg', ['-y', '-loglevel', 'error', '-i', loop, '-frames:v', '1', '-q:v', '2', still], { timeout });
247
+ const prepared = {
248
+ loop, still, steady, seconds, faces: `${found}/${frames.length}`,
249
+ box: { x1: box.x1 - x, y1: box.y1 - y, x2: box.x2 - x, y2: box.y2 - y },
250
+ };
251
+ writeFileSync(meta, JSON.stringify(prepared));
252
+ return prepared;
253
+ } finally {
254
+ rmSync(work, { recursive: true, force: true });
255
+ }
256
+ }
257
+
55
258
  /**
56
259
  * SadTalker: `still` + `wav` → mp4 at `out`. It writes `<timestamp>/….mp4`
57
260
  * into `resultDir`; take the newest and move it to `out`. (SadTalker makes its