decklight 0.6.0 → 0.7.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 (47) hide show
  1. package/README.md +16 -8
  2. package/SPEC.md +166 -10
  3. package/cli/agents.mjs +52 -2
  4. package/cli/banner.mjs +125 -0
  5. package/cli/bundle.mjs +14 -4
  6. package/cli/{rec.mjs → cast.mjs} +25 -8
  7. package/cli/comments.mjs +389 -0
  8. package/cli/commit-flow.mjs +157 -0
  9. package/cli/commit-message.mjs +125 -0
  10. package/cli/decklight.mjs +88 -25
  11. package/cli/dev.mjs +159 -13
  12. package/cli/edit.mjs +927 -39
  13. package/cli/git-tree.mjs +87 -0
  14. package/cli/git.mjs +22 -0
  15. package/cli/init.mjs +37 -5
  16. package/cli/port-conflict.mjs +187 -16
  17. package/cli/publish.mjs +15 -40
  18. package/cli/record.mjs +154 -0
  19. package/cli/review-remote.mjs +330 -0
  20. package/cli/review-store.mjs +107 -0
  21. package/cli/review-submit.mjs +292 -0
  22. package/cli/review.mjs +361 -0
  23. package/cli/serve.mjs +36 -1
  24. package/cli/skill-content.mjs +3 -1
  25. package/cli/units.mjs +2 -2
  26. package/cli/util.mjs +59 -0
  27. package/dist/build-info.json +1 -0
  28. package/dist/decklight.css +244 -1
  29. package/dist/decklight.js +102 -79
  30. package/dist/decklight.js.map +4 -4
  31. package/docs/architecture.svg +7 -0
  32. package/package.json +2 -1
  33. package/tools/args.mjs +20 -0
  34. package/tools/deck-html.mjs +50 -0
  35. package/tools/elevenlabs-tts.mjs +1 -1
  36. package/tools/lipsync-server.mjs +64 -2
  37. package/tools/lipsync.mjs +40 -24
  38. package/tools/local-voice.mjs +170 -16
  39. package/tools/publish-voices.mjs +78 -18
  40. package/tools/recording-impact.mjs +110 -0
  41. package/tools/review-anchor.mjs +180 -0
  42. package/tools/test-impact.mjs +259 -0
  43. package/tools/tts-engines.mjs +26 -4
  44. package/tools/tts-setup.mjs +1 -1
  45. package/tools/video.mjs +15 -3
  46. package/tools/voiceover-server.mjs +167 -7
  47. package/tools/voiceover.mjs +30 -1
package/cli/dev.mjs CHANGED
@@ -27,6 +27,7 @@ import { existsSync } from 'node:fs';
27
27
  import { fileURLToPath } from 'node:url';
28
28
  import { createInterface } from 'node:readline/promises';
29
29
  import { onPath, detectAgents } from './agents.mjs';
30
+ import { ASK_MESSAGES, planCommitMessages } from './commit-message.mjs';
30
31
  import { validProjectId } from '../tools/gemini-tts.mjs';
31
32
  import {
32
33
  ENGINES as TTS_ENGINES, PIPER_DEFAULT_VOICE, piperModelDir, engineStatus,
@@ -38,6 +39,7 @@ import { detectLocalVoice, OLLAMA_NOTE } from '../tools/local-voice.mjs';
38
39
  import { argReader, isMain } from '../tools/args.mjs';
39
40
  import { isPortOpen, resolvePortConflict } from './port-conflict.mjs';
40
41
  import { leashEnv } from './supervise.mjs';
42
+ import { nextFlushDelay, parseReady, renderBanner } from './banner.mjs';
41
43
 
42
44
  const CLI = fileURLToPath(new URL('./decklight.mjs', import.meta.url));
43
45
  // The deck server's entry since `edit` stopped being a command: its module,
@@ -56,11 +58,11 @@ const USAGE = `usage: decklight author <deck.html> [--port 8788] [--tts-port 878
56
58
  --lipsync-port N lip-sync bridge (visemes + talking head) [8789]
57
59
  --no-tts don't start the voice bridge
58
60
  --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]
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]
62
64
  (no repo + no flag: author ASKS whether to create one)
63
- --commit-every N autocommit cadence in seconds [300]
65
+ --commit-every N cadence in seconds, timer mode only [300]
64
66
  --commit-messages an agent writes the commit subjects instead of the generic
65
67
  "autosave" — reads each commit's diff and amends the subject
66
68
  afterwards, so the commit itself is never delayed or risked.
@@ -137,7 +139,10 @@ export function planServices({
137
139
  args: [deck, '--port', editPort,
138
140
  ...(has('--git') ? ['--git'] : []), ...(has('--no-git') ? ['--no-git'] : []),
139
141
  ...pass('--commit-every'), ...pass('--agent'), ...pass('--git-mode'),
140
- ...(has('--commit-messages') ? ['--commit-messages'] : [])],
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'] : [])],
141
146
  url: `http://127.0.0.1:${editPort}/${deck ?? ''}`,
142
147
  });
143
148
 
@@ -344,6 +349,21 @@ export async function devMain(args) {
344
349
  const mode = await rl.question(" commit once per agent edit, with the agent's own message, instead of on a timer? [y/N] ");
345
350
  if (/^y/i.test(mode.trim())) args = [...args, '--git-mode', 'agent'];
346
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
+ }
347
367
  rl.close();
348
368
  plan = planServices({ args, saved: loadTtsConfig() });
349
369
  } else {
@@ -377,7 +397,7 @@ export async function devMain(args) {
377
397
  if (voiceSetupOffer(plan) && process.stdin.isTTY && process.stdout.isTTY) {
378
398
  const rl = createInterface({ input: process.stdin, output: process.stdout });
379
399
  try {
380
- const answer = await rl.question(' no voice engine configured — set up live narration now? (V / N in the deck use it) [Y/n] ');
400
+ const answer = await rl.question(' no voice engine configured — set up live narration now? (V in the deck uses it) [Y/n] ');
381
401
  if (!/^n/i.test(answer.trim())) {
382
402
  const result = await runSetupWizard({ ask: (q) => rl.question(q) });
383
403
  if (result) {
@@ -416,6 +436,110 @@ export async function devMain(args) {
416
436
  const children = new Map();
417
437
  let shuttingDown = false;
418
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
+
419
543
  // Children write their own startup/progress lines; prefix each so three
420
544
  // servers in one terminal stay readable.
421
545
  const pipe = (stream, tag, out) => {
@@ -425,7 +549,16 @@ export async function devMain(args) {
425
549
  buf += chunk;
426
550
  const lines = buf.split('\n');
427
551
  buf = lines.pop() ?? '';
428
- for (const line of lines) out.write(`${paint(tag)} ${line}\n`);
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
+ }
429
562
  });
430
563
  };
431
564
 
@@ -436,7 +569,10 @@ export async function devMain(args) {
436
569
  // never reached shutdown() below.
437
570
  const child = spawn(process.execPath, [svc.entry, ...svc.args], {
438
571
  stdio: ['pipe', 'pipe', 'pipe'],
439
- env: leashEnv(),
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' },
440
576
  });
441
577
  children.set(svc.name, child);
442
578
  pipe(child.stdout, svc.tag, process.stdout);
@@ -445,19 +581,29 @@ export async function devMain(args) {
445
581
  child.on('exit', (code) => {
446
582
  children.delete(svc.name);
447
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.
448
588
  if (svc.name === 'edit') {
449
589
  // the deck server is the one service author cannot run without
450
- console.error(`${paint(svc.tag)} exited (${code}) — stopping decklight author`);
590
+ say(`${paint(svc.tag)} exited (${code}) — stopping decklight author`);
591
+ flushBanner();
451
592
  shutdown(code ?? 1);
452
593
  } else {
453
- console.error(`${paint(svc.tag)} exited (${code}) — carrying on without it; the deck degrades on its own`);
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
454
596
  }
455
597
  });
456
598
  }
457
599
 
458
- for (const s of skip) console.log(note(` ${s.name.padEnd(8)} skipped — ${s.why}`));
459
- if (!agents.length) console.log(note(' agents none detected — install claude, codex, or bob to ask an agent from the deck (A)'));
460
- console.log(note(' Ctrl-C stops everything.\n'));
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)');
461
607
 
462
608
  function shutdown(code = 0) {
463
609
  if (shuttingDown) return;