decklight 0.9.0 → 0.11.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/NOTICE +2 -0
  2. package/PLATFORM.md +61 -3
  3. package/README.md +58 -28
  4. package/SPEC.md +1326 -85
  5. package/cli/agent-review.mjs +5 -4
  6. package/cli/agents.mjs +148 -18
  7. package/cli/bundle-audio.mjs +10 -3
  8. package/cli/bundle-module.mjs +95 -0
  9. package/cli/bundle.mjs +125 -7
  10. package/cli/cast.mjs +86 -19
  11. package/cli/check-fixes.mjs +194 -0
  12. package/cli/check-watch.mjs +151 -0
  13. package/cli/check.mjs +491 -75
  14. package/cli/code-editor.mjs +287 -0
  15. package/cli/commands.mjs +13 -2
  16. package/cli/commit-flow.mjs +7 -3
  17. package/cli/commit-message.mjs +35 -8
  18. package/cli/commit-split.mjs +125 -25
  19. package/cli/deck-refs.mjs +8 -3
  20. package/cli/decklight.mjs +11 -1
  21. package/cli/design-system-edit.mjs +37 -1
  22. package/cli/design-system-refs.mjs +263 -6
  23. package/cli/design-system.mjs +82 -14
  24. package/cli/edit-address.mjs +184 -0
  25. package/cli/edit-git.mjs +23 -6
  26. package/cli/edit-handover.mjs +257 -40
  27. package/cli/edit-look.mjs +293 -6
  28. package/cli/edit-open.mjs +143 -0
  29. package/cli/edit-slides.mjs +1043 -67
  30. package/cli/edit-translate.mjs +243 -0
  31. package/cli/edit.mjs +3680 -319
  32. package/cli/editor-support.mjs +286 -0
  33. package/cli/enhance.mjs +157 -27
  34. package/cli/find-replace.mjs +142 -0
  35. package/cli/fix-review.mjs +368 -0
  36. package/cli/git.mjs +13 -0
  37. package/cli/init.mjs +101 -22
  38. package/cli/keep-awake.mjs +68 -0
  39. package/cli/marketplace-autocheck.mjs +200 -0
  40. package/cli/marketplace.mjs +250 -13
  41. package/cli/migrate-writing.mjs +214 -0
  42. package/cli/narrate.mjs +121 -5
  43. package/cli/open.mjs +53 -15
  44. package/cli/outside-edit.mjs +257 -0
  45. package/cli/paste.mjs +92 -0
  46. package/cli/pdf.mjs +88 -10
  47. package/cli/pptx-export.mjs +10 -5
  48. package/cli/publish.mjs +24 -3
  49. package/cli/record.mjs +86 -15
  50. package/cli/remote.mjs +32 -6
  51. package/cli/rewrite.mjs +265 -0
  52. package/cli/runtime-link.mjs +218 -17
  53. package/cli/serve.mjs +9 -6
  54. package/cli/setup.mjs +2 -2
  55. package/cli/skill-content.mjs +251 -10
  56. package/cli/skills/slide-writing.md +333 -0
  57. package/cli/skills/voiceover.md +423 -0
  58. package/cli/skills.mjs +282 -15
  59. package/cli/starter-full.mjs +353 -0
  60. package/cli/supervise.mjs +14 -0
  61. package/cli/theme-refs.mjs +14 -2
  62. package/cli/theme.mjs +3 -2
  63. package/cli/translate-core.mjs +466 -0
  64. package/cli/translate-files.mjs +149 -0
  65. package/cli/translate.mjs +458 -0
  66. package/cli/units.mjs +75 -7
  67. package/cli/util.mjs +25 -0
  68. package/cli/vocabulary-docs.mjs +138 -0
  69. package/dist/decklight.css +2506 -113
  70. package/dist/decklight.js +385 -175
  71. package/dist/decklight.js.map +4 -4
  72. package/docs/GLOSSARY.md +9 -2
  73. package/docs/WRITING_RESEARCH.md +327 -0
  74. package/package.json +5 -3
  75. package/themes/coastal.css +3 -0
  76. package/themes/metropolis.css +2 -0
  77. package/themes/reveal-blood.css +3 -0
  78. package/themes/reveal-league.css +2 -0
  79. package/themes/reveal-moon.css +2 -0
  80. package/themes/reveal-serif.css +1 -0
  81. package/themes/reveal-sky.css +1 -0
  82. package/themes/reveal-solarized.css +4 -0
  83. package/tools/brand-palette.mjs +6 -1
  84. package/tools/build-groups.mjs +28 -8
  85. package/tools/cdp.mjs +176 -0
  86. package/tools/chart-spec.mjs +242 -0
  87. package/tools/click-match.mjs +70 -0
  88. package/tools/code-options.mjs +174 -0
  89. package/tools/conversation.mjs +49 -0
  90. package/tools/deck-family.mjs +101 -0
  91. package/tools/deck-html.mjs +212 -15
  92. package/tools/design-system-format.mjs +40 -1
  93. package/tools/design-system-migrations.mjs +207 -0
  94. package/tools/diagram-shapes.mjs +221 -0
  95. package/tools/elevenlabs-tts.mjs +62 -53
  96. package/tools/exec.mjs +10 -2
  97. package/tools/face-clip.mjs +96 -0
  98. package/tools/face-layout.mjs +94 -0
  99. package/tools/gemini-tts.mjs +1 -1
  100. package/tools/invisible-in-print.mjs +27 -0
  101. package/tools/lipsync-auto.mjs +197 -0
  102. package/tools/lipsync-config.mjs +16 -0
  103. package/tools/lipsync-engines.mjs +22 -4
  104. package/tools/lipsync-server.mjs +8 -5
  105. package/tools/lipsync.mjs +122 -30
  106. package/tools/local-voice.mjs +1 -1
  107. package/tools/mouth-file.mjs +26 -0
  108. package/tools/mouth.mjs +320 -0
  109. package/tools/narration-manifest.mjs +100 -6
  110. package/tools/narration-synth.mjs +96 -76
  111. package/tools/recording-impact.mjs +16 -1
  112. package/tools/sentences.mjs +7 -1
  113. package/tools/site-clip.mjs +114 -0
  114. package/tools/starters.mjs +402 -0
  115. package/tools/steps.mjs +118 -0
  116. package/tools/take-check.mjs +146 -0
  117. package/tools/template-theme.mjs +3 -1
  118. package/tools/test-impact.mjs +36 -12
  119. package/tools/theme-check.mjs +196 -1
  120. package/tools/tone-cue.mjs +108 -0
  121. package/tools/tts-cache.mjs +9 -3
  122. package/tools/tts-engines.mjs +100 -11
  123. package/tools/video-cache.mjs +93 -0
  124. package/tools/video-live.mjs +349 -0
  125. package/tools/video-options.mjs +11 -0
  126. package/tools/video.mjs +825 -117
  127. package/tools/viseme-fit.mjs +27 -0
  128. package/tools/viseme-match.mjs +77 -0
  129. package/tools/vocabulary.mjs +397 -0
  130. package/tools/voice-renumber.mjs +605 -0
  131. package/tools/voiceover-server.mjs +42 -11
  132. package/tools/voiceover.mjs +48 -20
  133. package/dist/build-info.json +0 -1
package/cli/edit-look.mjs CHANGED
@@ -5,7 +5,10 @@
5
5
  // theme it opens in and whether the picker holds it to its brand's themes,
6
6
  // and the three things a marketplace hands a deck to wear (themes, design
7
7
  // systems, fonts), each listed from the cache and marked or dropped in the
8
- // deck's config block (SPEC THEME_DISTRIBUTION, DESIGN_SYSTEMS, FONTS).
8
+ // deck's config block (SPEC THEME_DISTRIBUTION, DESIGN_SYSTEMS, FONTS) — and
9
+ // the marketplaces themselves (SPEC MARKETPLACES_SCREEN): listed, checked,
10
+ // updated and added, every one of them through the `decklight marketplace`
11
+ // command it would be at a terminal.
9
12
  //
10
13
  // They came out of cli/edit.mjs because they are a family with one shape and
11
14
  // one set of needs. Every one either lists what the cached catalogs offer
@@ -23,9 +26,12 @@
23
26
  // edit.mjs's top-level `await`).
24
27
 
25
28
  import { readFileSync } from 'node:fs';
29
+ import { execFile } from 'node:child_process';
30
+ import { basename, dirname } from 'node:path';
31
+ import { fileURLToPath } from 'node:url';
26
32
 
27
33
  import { oneline } from './git.mjs';
28
- import { setDeckTheme, setDeckBrandThemesOnly } from './runtime-link.mjs';
34
+ import { setDeckTheme, setDeckBrandThemesOnly, setDeckConfig, setDeckTitle, deckSettings } from './runtime-link.mjs';
29
35
 
30
36
  /**
31
37
  * Put the look routes into `routes`, the table cli/edit.mjs dispatches on, and
@@ -40,8 +46,16 @@ import { setDeckTheme, setDeckBrandThemesOnly } from './runtime-link.mjs';
40
46
  * tells the deck watcher that the next write of exactly these bytes updates
41
47
  * the page itself and must not reload it. `quiet` is a setter, not the
42
48
  * variable, because the watcher in editMain reads and clears it.
49
+ * `deckPath` is where a relative marketplace path is read from, and
50
+ * `marketplace(args)` runs `decklight marketplace <args…>` (a test hands in
51
+ * its own); `addMarketplace(spec, ref)` is its `add` (with `--branch ref` when
52
+ * one is given), kept apart because a test of the add door replaces only that.
43
53
  */
44
- export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, history, broadcast = () => {}, quiet = () => {} }) {
54
+ export function registerLookRoutes(routes, {
55
+ readDeck, applyEdit, writeDeck, history, broadcast = () => {}, quiet = () => {},
56
+ deckPath = null, marketplace = runMarketplace,
57
+ addMarketplace = (spec, ref = null) => marketplace(['add', spec, ...(ref ? ['--branch', ref] : [])]),
58
+ }) {
45
59
  // The deck's theme (PRESENTING): in write mode a pick is the deck's, not
46
60
  // the viewer's — written the way this deck carries it (setDeckTheme), quiet
47
61
  // and in place like a layout pick, with a `theme` event for every other
@@ -83,6 +97,48 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
83
97
  return json(200, { ok: true, changed, inPlace: changed && inPlace === true, ...history.counts() });
84
98
  }
85
99
 
100
+ /**
101
+ * `GET /deck/edit/config`: what Deck settings… shows (PRESENTING_EDITING),
102
+ * read from the file: the page's title, each setting (the default where the
103
+ * file says nothing), and whether this deck's configuration can be
104
+ * rewritten, with the one sentence saying why not.
105
+ */
106
+ function configGetRoute({ json }) {
107
+ return json(200, { ok: true, ...deckSettings(readDeck()) });
108
+ }
109
+ /**
110
+ * `POST /deck/edit/config` `{ set?: { key: value | null }, title? }`: the
111
+ * deck's own settings, saved in the file (setDeckConfig, setDeckTitle), in
112
+ * one edit and one undo. A value back at its default takes the key off. Not
113
+ * quiet: the runtime reads these when the deck loads, so every page reloads.
114
+ * A deck whose configuration is code, or elsewhere, is a 409 saying why.
115
+ */
116
+ function configPostRoute({ body, json }) {
117
+ const { set = null, title } = JSON.parse(body || '{}');
118
+ if (set === null && title === undefined) return json(400, { ok: false, error: 'nothing to set' });
119
+ if (title !== undefined && typeof title !== 'string') return json(400, { ok: false, error: 'a title is text' });
120
+ const before = readDeck();
121
+ const why = deckSettings(before).why;
122
+ if (set && why) return json(409, { ok: false, error: `this deck’s settings cannot be saved here: ${why}` });
123
+ let changed;
124
+ try {
125
+ changed = applyEdit((html) => {
126
+ let out = html;
127
+ if (set) {
128
+ const next = setDeckConfig(out, set);
129
+ if (next === null) throw Object.assign(new Error('this deck’s configuration could not be rewritten in place'), { code: 'UNWRITABLE' });
130
+ out = next;
131
+ }
132
+ if (title !== undefined) out = setDeckTitle(out, title);
133
+ return out;
134
+ });
135
+ } catch (e) {
136
+ return json(e.code === 'UNWRITABLE' ? 409 : 400, { ok: false, error: String(e.message).split('\n')[0] });
137
+ }
138
+ if (changed) console.log(` deck settings: ${[...Object.entries(set ?? {}).map(([k, v]) => `${k}=${JSON.stringify(v)}`), ...(title !== undefined ? [`title=${JSON.stringify(title)}`] : [])].join(', ')}`);
139
+ return json(200, { ok: true, changed, ...deckSettings(readDeck()), ...history.counts() });
140
+ }
141
+
86
142
  // ── marketplace themes, and marking (THEME_BROWSE#UI) ─────────────────
87
143
  // What the overlay lists while authoring: every theme of every registered
88
144
  // marketplace, each saying whether this deck marks it. Cache-only by
@@ -232,7 +288,7 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
232
288
  deckRef = designSystemRefs(before).find((x) => x.ref === ref || x.name === p.name)?.ref ?? ref;
233
289
  }
234
290
  let out;
235
- try { out = setDesignSystem(before, deckRef, on, { source }); }
291
+ try { out = setDesignSystem(before, deckRef, on, { source, version: manifest?.version ?? null }); }
236
292
  catch (e) {
237
293
  if (e instanceof MarketplaceError) return json(409, { ok: false, error: e.message });
238
294
  throw e;
@@ -272,7 +328,7 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
272
328
  */
273
329
  async function designSystemApplyRoute({ body, json }) {
274
330
  const req = JSON.parse(body || '{}');
275
- const { designSystemRefs, resolveDesignSystemRef } = await import('./design-system-refs.mjs');
331
+ const { designSystemRefs, resolveDesignSystemRef, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
276
332
  const { markedSources, parseRef } = await import('./theme-refs.mjs');
277
333
  const { checkDir } = await import('./design-system.mjs');
278
334
  const { recordInstall } = await import('./marketplace.mjs');
@@ -286,7 +342,8 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
286
342
  const verdict = checkDir(r.dir);
287
343
  if (!verdict.ok) return json(409, { ok: false, error: `${hit.ref} no longer passes its check` });
288
344
  const plan = deps.planRecommended(before, { manifest: verdict.manifest, local: r.local });
289
- let html = deps.writePlan(before, plan);
345
+ // a deck that records no version takes this one, as `design-system apply` does (SPEC DESIGN_SYSTEM_MIGRATIONS)
346
+ let html = deps.writePlan(recordVersionIfCurrent(before, hit.ref, verdict.manifest, deckPath ? dirname(deckPath) : process.cwd()), plan);
290
347
  const look = deps.lookOf(html, plan);
291
348
  if (look.differs) html = deps.applyLook(html, look);
292
349
  look.phrase = deps.lookPhrase(look, plan);
@@ -374,8 +431,188 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
374
431
  const themeAddRoute = ({ body, json }) =>
375
432
  themeMarkRoute({ body: JSON.stringify({ ref: JSON.parse(body || '{}').ref, marked: true }), json });
376
433
 
434
+ /**
435
+ * `POST /deck/edit/marketplace/add` `{ spec, ref?, confirm? }`: register a
436
+ * marketplace from inside the deck (SPEC MARKETPLACES_SCREEN, PLATFORM
437
+ * MARKETPLACE_REGISTRY). `ref` is the command's `--branch`, a branch or a
438
+ * tag to pin the catalog to. Two steps, like publish. Without `confirm` it says
439
+ * what it is about to do (`planAdd`: which URL it would clone, or which
440
+ * directory it would read) and touches nothing. With it, it runs
441
+ * `decklight marketplace add` itself, as a child process: the same command,
442
+ * so the registry cannot tell the two doors apart, and a clone that takes
443
+ * thirty seconds holds up nobody but the person who asked for it. A relative
444
+ * path is the deck's directory's, and is registered absolute. Nothing in
445
+ * the deck changes, so there is no undo entry and no reload: the pickers ask
446
+ * again, and find it.
447
+ */
448
+ async function marketplaceAddRoute({ body, json }) {
449
+ const req = JSON.parse(body || '{}');
450
+ if (req.ref != null && typeof req.ref !== 'string') return json(400, { ok: false, error: '--branch takes a branch or tag name' });
451
+ const { planAdd, loadRegistry, loadCatalog, MarketplaceError, configHome } = await import('./marketplace.mjs');
452
+ let plan;
453
+ try { plan = planAdd(req.spec, { ref: req.ref?.trim() || null, base: deckPath ? dirname(deckPath) : process.cwd(), home: configHome() }); }
454
+ catch (e) {
455
+ if (e instanceof MarketplaceError) return json(400, { ok: false, error: e.message });
456
+ throw e;
457
+ }
458
+ if (req.confirm !== true) return json(200, { ok: true, confirm: true, plan });
459
+ const out = await addMarketplace(plan.spec, plan.ref);
460
+ if (!out.ok) return json(409, { ok: false, error: out.error, plan });
461
+ const reg = loadRegistry(configHome()).marketplaces ?? {};
462
+ const name = Object.keys(reg).find((n) => reg[n].source === plan.spec) ?? null;
463
+ const cat = name ? loadCatalog(name, configHome()) : null;
464
+ const counts = {};
465
+ for (const e of cat?.ok ? cat.manifest.entries ?? [] : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
466
+ console.log(` marketplace: ${plan.registered ? 'refreshed' : 'registered'} ${name ?? plan.spec} from ${plan.spec}`);
467
+ return json(200, { ok: true, name, spec: plan.spec, refreshed: !!plan.registered, counts, said: out.said });
468
+ }
469
+
470
+ /**
471
+ * `GET /deck/edit/marketplaces`: every registered marketplace, from the
472
+ * registry and the cache alone (SPEC MARKETPLACES_SCREEN) — what
473
+ * `marketplace list` says, as data. Per marketplace: where it comes from
474
+ * and at which ref and commit, whether it was ever fetched (`state`), what
475
+ * its catalog offers per kind (`counts`), what its last update changed
476
+ * (`changes`, as `update` recorded it), and which installs the catalog now
477
+ * has newer (`newer`). No network: whether a source has MOVED is
478
+ * `/deck/edit/marketplace/check`'s question, asked only when somebody asks.
479
+ */
480
+ async function marketplacesRoute({ json }) {
481
+ const { loadRegistry, loadCatalog, newerThanInstalled, classifySource, configHome, MarketplaceError } = await import('./marketplace.mjs');
482
+ let reg;
483
+ try { reg = loadRegistry(configHome()).marketplaces ?? {}; } catch (e) {
484
+ if (e instanceof MarketplaceError) return json(409, { ok: false, error: e.message });
485
+ throw e;
486
+ }
487
+ const newer = newerThanInstalled(configHome());
488
+ const marketplaces = Object.keys(reg).sort().map((name) => {
489
+ const m = reg[name];
490
+ const cat = loadCatalog(name, configHome());
491
+ const counts = {};
492
+ for (const e of cat?.ok ? cat.manifest.entries : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
493
+ return {
494
+ name, source: m.source, ref: m.ref ?? null, commit: m.commit ?? null, firstParty: !!m.firstParty,
495
+ local: classifySource(m.source).kind === 'local',
496
+ state: cat === null ? 'unfetched' : cat.ok ? 'fetched' : 'unreadable',
497
+ description: cat?.ok ? cat.manifest.description ?? null : null,
498
+ counts, changes: m.changes ?? null,
499
+ newer: newer.filter((n) => n.qualified.endsWith(`@${name}`)),
500
+ };
501
+ });
502
+ // the last check's answer, whoever asked (C, the command line, or the
503
+ // auto-check a starting server ran), so the list says it without a C;
504
+ // and whether that auto-check is on, and if not, whether to ask once
505
+ const { readCheckRecord, autoCheckOn, autoCheckOffered } = await import('./marketplace-autocheck.mjs');
506
+ const rec = readCheckRecord(configHome());
507
+ const on = autoCheckOn(configHome());
508
+ return json(200, {
509
+ ok: true, marketplaces, cacheOnly: true,
510
+ checked: rec ? { at: new Date(rec.checkedAt).toISOString(), marketplaces: rec.marketplaces } : null,
511
+ autoCheck: { on, ask: !on && !autoCheckOffered(configHome()) },
512
+ });
513
+ }
514
+
515
+ /**
516
+ * `GET /deck/edit/marketplace/auto-check`: what the auto-check found that
517
+ * the open deck should offer (SPEC MARKETPLACES_SCREEN) — every marketplace
518
+ * the last check found behind, not dismissed at that commit, with what this
519
+ * deck uses from it. Read from the record; asks nothing. Empty while the
520
+ * switch is off.
521
+ */
522
+ async function autoCheckGetRoute({ json }) {
523
+ const { configHome } = await import('./marketplace.mjs');
524
+ const { readCheckRecord, autoCheckOn, autoCheckOffers } = await import('./marketplace-autocheck.mjs');
525
+ let html = null;
526
+ try { html = readDeck(); } catch { /* no deck to say what it uses */ }
527
+ const rec = readCheckRecord(configHome());
528
+ return json(200, {
529
+ ok: true, on: autoCheckOn(configHome()),
530
+ checkedAt: rec ? new Date(rec.checkedAt).toISOString() : null,
531
+ offers: await autoCheckOffers(html, configHome()),
532
+ });
533
+ }
534
+
535
+ /**
536
+ * `POST /deck/edit/marketplace/auto-check` `{ on } | { asked: true } |
537
+ * { dismiss, remote }`: turn the auto-check on or off (O on the screen; the
538
+ * file `decklight marketplace auto-check` writes), say the screen has asked
539
+ * its one question, or dismiss an offer at the commit it was made for.
540
+ * Turning it on is the consent, so a check that is due runs then, in the
541
+ * background, and the pages are told when its answer lands.
542
+ */
543
+ async function autoCheckPostRoute({ body, json }) {
544
+ const req = JSON.parse(body || '{}');
545
+ const { configHome } = await import('./marketplace.mjs');
546
+ const ac = await import('./marketplace-autocheck.mjs');
547
+ if (typeof req.dismiss === 'string') {
548
+ if (!/^\w[\w-]*$/.test(req.dismiss)) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
549
+ ac.dismissOffer(req.dismiss, typeof req.remote === 'string' ? req.remote : null, configHome());
550
+ return json(200, { ok: true, dismissed: req.dismiss });
551
+ }
552
+ if (req.asked === true) { ac.markAutoCheckOffered(configHome()); return json(200, { ok: true }); }
553
+ if (typeof req.on !== 'boolean') return json(400, { ok: false, error: 'on is true or false' });
554
+ const on = ac.setAutoCheck(req.on, configHome());
555
+ console.log(` marketplaces: auto-check ${on ? 'on' : 'off'}`);
556
+ if (on) autoCheckInBackground({ run: marketplace, broadcast });
557
+ return json(200, { ok: true, on });
558
+ }
559
+
560
+ /**
561
+ * `POST /deck/edit/marketplace/check` `{ name? }`: which marketplaces are
562
+ * behind their source — `decklight marketplace outdated --json`, run as a
563
+ * child like `add`. It ASKS each remote where its ref points (`git
564
+ * ls-remote`, the caller's credentials) and fetches nothing, so it is one
565
+ * explicit press, not a confirm; it never runs on its own.
566
+ */
567
+ async function marketplaceCheckRoute({ body, json }) {
568
+ const req = JSON.parse(body || '{}');
569
+ if (req.name != null && !/^\w[\w-]*$/.test(String(req.name))) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
570
+ const out = await marketplace(['outdated', '--json', ...(req.name ? [String(req.name)] : [])]);
571
+ if (!out.ok) return json(409, { ok: false, error: out.error });
572
+ let parsed;
573
+ try { parsed = JSON.parse(out.stdout); } catch { return json(500, { ok: false, error: 'decklight marketplace outdated answered something that is not JSON' }); }
574
+ return json(200, { ok: true, marketplaces: parsed.marketplaces ?? [] });
575
+ }
576
+
577
+ /**
578
+ * `POST /deck/edit/marketplace/update` `{ name }`: `decklight marketplace
579
+ * update <name>`, run as a child — the same re-clone, at the same pinned
580
+ * ref, with the same refusals; a failed one leaves the cache and checkout
581
+ * as they were. Answers with what the update changed (the `changes` the
582
+ * command recorded: added, removed, versions moved) and which installs the
583
+ * catalog now has newer, with the command that takes each — the screen's
584
+ * what's new — and `behind`, the design systems the open deck is now
585
+ * behind (`deckBehind`), which the screen offers to migrate. Nothing in
586
+ * the deck changes, so no undo entry and no reload.
587
+ */
588
+ async function marketplaceUpdateRoute({ body, json }) {
589
+ const req = JSON.parse(body || '{}');
590
+ const name = typeof req.name === 'string' ? req.name : '';
591
+ if (!/^\w[\w-]*$/.test(name)) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
592
+ const { loadRegistry, loadCatalog, newerThanInstalled, configHome } = await import('./marketplace.mjs');
593
+ if (!loadRegistry(configHome()).marketplaces?.[name]) return json(404, { ok: false, error: `no marketplace "${name}" is registered` });
594
+ const out = await marketplace(['update', name]);
595
+ if (!out.ok) return json(409, { ok: false, error: out.error });
596
+ const m = loadRegistry(configHome()).marketplaces?.[name] ?? {};
597
+ const cat = loadCatalog(name, configHome());
598
+ const counts = {};
599
+ for (const e of cat?.ok ? cat.manifest.entries : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
600
+ console.log(` marketplace: updated ${name}${m.commit ? ` (${m.commit.slice(0, 7)})` : ''}`);
601
+ // What the update means for the deck that is open (SPEC
602
+ // DESIGN_SYSTEM_MIGRATIONS): the design systems it is now behind, read
603
+ // as `check` reads them — the page offers Migrate without a reload.
604
+ const { withMigrationHint, deckBehind } = await import('./design-system-refs.mjs');
605
+ const newer = newerThanInstalled(configHome(), name).map((n) => withMigrationHint(n, configHome()));
606
+ let behind = [];
607
+ try { if (deckPath) behind = deckBehind(readDeck(), dirname(deckPath), configHome(), { deck: basename(deckPath) }); } catch { /* the deck unreadable: nothing to offer */ }
608
+ for (const b of behind) console.log(` design system: ${b.ref} — ${b.message}`);
609
+ return json(200, { ok: true, name, commit: m.commit ?? null, changes: m.changes ?? null, counts, newer, behind, said: out.said });
610
+ }
611
+
377
612
  routes.set('POST /deck/edit/theme', themeRoute);
378
613
  routes.set('POST /deck/edit/brand-themes', brandThemesRoute);
614
+ routes.set('GET /deck/edit/config', configGetRoute);
615
+ routes.set('POST /deck/edit/config', configPostRoute);
379
616
  routes.set('GET /deck/edit/theme/browse', themeBrowseRoute);
380
617
  routes.set('POST /deck/edit/theme/add', themeAddRoute);
381
618
  routes.set('POST /deck/edit/theme/mark', themeMarkRoute);
@@ -384,5 +621,55 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
384
621
  routes.set('POST /deck/edit/design-system/apply', designSystemApplyRoute);
385
622
  routes.set('GET /deck/edit/font/browse', fontBrowseRoute);
386
623
  routes.set('POST /deck/edit/font/mark', fontMarkRoute);
624
+ routes.set('POST /deck/edit/marketplace/add', marketplaceAddRoute);
625
+ routes.set('GET /deck/edit/marketplaces', marketplacesRoute);
626
+ routes.set('POST /deck/edit/marketplace/check', marketplaceCheckRoute);
627
+ routes.set('POST /deck/edit/marketplace/update', marketplaceUpdateRoute);
628
+ routes.set('GET /deck/edit/marketplace/auto-check', autoCheckGetRoute);
629
+ routes.set('POST /deck/edit/marketplace/auto-check', autoCheckPostRoute);
387
630
  return routes;
388
631
  }
632
+
633
+ /**
634
+ * The auto-check, if it is due (SPEC MARKETPLACES_SCREEN): `run` is
635
+ * `decklight marketplace <args…>`, and `broadcast` tells every page when the
636
+ * answer lands, so the deck offers it without a reload. Never awaited by a
637
+ * caller that matters, and silent on failure: resolves to the record, or null.
638
+ * The edit server calls it once as it starts; turning the switch on calls it too.
639
+ */
640
+ export function autoCheckInBackground({ run = runMarketplace, broadcast = () => {} } = {}) {
641
+ return import('./marketplace-autocheck.mjs')
642
+ .then(({ runAutoCheck, checkSummary }) => runAutoCheck({ run }).then((rec) => {
643
+ if (!rec) return null;
644
+ broadcast('marketplaces', { checkedAt: rec.checkedAt, summary: checkSummary(rec) });
645
+ return rec;
646
+ }))
647
+ .catch(() => null);
648
+ }
649
+
650
+ const CLI = fileURLToPath(new URL('./decklight.mjs', import.meta.url));
651
+
652
+ /**
653
+ * Run `decklight marketplace <args…>` and say how it went: `{ ok, said,
654
+ * stdout }` with the command's own first line, or `{ ok: false, error }` with
655
+ * what it printed on the way out, prefix dropped. git is told never to prompt
656
+ * (the command does that too; a server has no terminal to prompt on), and the
657
+ * update notice is the command line's business, not this sentence's.
658
+ */
659
+ export function runMarketplace(args, { timeoutMs = 120000 } = {}) {
660
+ return new Promise((done) => {
661
+ execFile(process.execPath, [CLI, 'marketplace', ...args], {
662
+ encoding: 'utf8', timeout: timeoutMs,
663
+ // no version banner: the server already said which version this is,
664
+ // and on stderr it would open every refusal read back from there
665
+ env: { ...process.env, GIT_TERMINAL_PROMPT: '0', DECKLIGHT_NO_UPDATE_CHECK: '1', DECKLIGHT_BANNER: '1' },
666
+ }, (err, stdout, stderr) => {
667
+ if (!err) return done({ ok: true, said: String(stdout).trim().split('\n')[0] ?? '', stdout: String(stdout) });
668
+ const said = String(stderr).trim().replace(new RegExp(`^decklight marketplace ${args[0]}: `), '');
669
+ done({ ok: false, error: said || (err.killed ? `gave up after ${Math.round(timeoutMs / 1000)}s` : oneline(err)) });
670
+ });
671
+ });
672
+ }
673
+
674
+ /** `decklight marketplace add <spec>` — the add door's one command. */
675
+ export const runMarketplaceAdd = (spec, opts) => runMarketplace(['add', spec], opts);
@@ -0,0 +1,143 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Open in your editor (PRESENTING_EDITING): from a slide or an element on
5
+ // screen to its place in the deck FILE, in the author's code editor.
6
+ //
7
+ // GET /deck/edit/editor the saved choice and what this machine offers
8
+ // POST /deck/edit/editor { editor, template? }: remember the choice
9
+ // POST /deck/edit/open { slide, index?, path?, tag? }: open the deck
10
+ // at that slide's <section>, or at that element
11
+ //
12
+ // The address is the one every element route takes (cli/edit-address.mjs):
13
+ // a slide, an element's raw index among the section's children, and for a
14
+ // node inside it the file's `path` below it and the `tag` the page saw. The
15
+ // line and column come from the file's own offsets, so a path the file does
16
+ // not have is stale (409), never a guess.
17
+ //
18
+ // Nothing of the request reaches the command but the line and the column,
19
+ // numbers the server computed itself. The program is the author's saved
20
+ // choice, the file is always the deck being served, and it is started as an
21
+ // argument array without a shell (cli/code-editor.mjs). The two POSTs answer
22
+ // this server's own page only (isOwnOrigin): a plugin's sandboxed frame or
23
+ // another loopback page cannot set a command, nor start one.
24
+
25
+ import { locateSlide } from '../tools/deck-html.mjs';
26
+ import { locateElement, nodeAt, checkPath } from './edit-address.mjs';
27
+ import { detectEditors, loadEditorChoice, saveEditorChoice, checkChoice, choiceLabel, editorCommand, launchEditor } from './code-editor.mjs';
28
+
29
+ /** Line and column (both from 1) of `offset` in `text`: columns count characters, a tab one. */
30
+ export function lineColumn(text, offset) {
31
+ const before = text.slice(0, offset);
32
+ const lineStart = before.lastIndexOf('\n') + 1;
33
+ return { line: (before.match(/\n/g)?.length ?? 0) + 1, column: [...before.slice(lineStart)].length + 1 };
34
+ }
35
+
36
+ /**
37
+ * Where an address starts in the deck file: `{ offset, line, column }` of
38
+ * slide `slide`'s `<section`, or with `index` of that element's open tag, or
39
+ * with `path` of the node there. A slide or an index the file does not have
40
+ * throws; a path it does not have, or a tag that is not the page's, is STALE.
41
+ */
42
+ export function sourcePosition(html, { slide, index = null, path = null, tag = null }) {
43
+ const { parts, idx } = locateSlide(html, slide);
44
+ // parts: [preamble, '<section', body1, '<section', body2, …]
45
+ const sectionAt = parts.slice(0, idx - 1).join('').length;
46
+ if (index === null) return { offset: sectionAt, ...lineColumn(html, sectionAt) };
47
+ const { seg, r } = locateElement(html, slide, index);
48
+ const bodyAt = sectionAt + parts[idx - 1].length;
49
+ const el = seg.slice(r.start, r.end);
50
+ const at = nodeAt(el, path ? checkPath(path) : [], { slide, index, tag });
51
+ const offset = bodyAt + r.start + at.start;
52
+ return { offset, ...lineColumn(html, offset) };
53
+ }
54
+
55
+ /**
56
+ * The three routes, given what they need of the edit server: the deck's
57
+ * text and path, the gate that says a request is this server's own page,
58
+ * and (for the tests) the environment the editor is looked up in and the
59
+ * spawner that starts it.
60
+ */
61
+ export function registerOpenRoutes(routes, {
62
+ readDeck, deckPath, ownOrigin, env = process.env, spawn, platform = process.platform, exists, log = console.log,
63
+ }) {
64
+ const where = { env, platform, ...(exists ? { exists } : {}) };
65
+ const state = () => {
66
+ const chosen = loadEditorChoice(env);
67
+ return {
68
+ chosen: chosen ? { ...chosen, label: choiceLabel(chosen, { env }) } : null,
69
+ editors: detectEditors(where),
70
+ };
71
+ };
72
+ const refuseForeign = (req, json) => {
73
+ if (ownOrigin(req)) return false;
74
+ json(403, { ok: false, error: 'only this deck\'s own page can open your editor' });
75
+ return true;
76
+ };
77
+
78
+ /** `GET /deck/edit/editor`: what is chosen, and what the chooser lists. */
79
+ function editorStateRoute({ json }) {
80
+ return json(200, { ok: true, ...state() });
81
+ }
82
+
83
+ /** `POST /deck/edit/editor` `{ editor, template? }`: remember it; `{ editor: null }` forgets it. */
84
+ function editorSaveRoute({ req, body, json }) {
85
+ if (refuseForeign(req, json)) return;
86
+ const asked = JSON.parse(body || '{}');
87
+ if (asked?.editor === null) {
88
+ saveEditorChoice(null, env);
89
+ log(' editor: choice forgotten');
90
+ return json(200, { ok: true, ...state() });
91
+ }
92
+ let choice;
93
+ try { choice = checkChoice(asked); } catch (e) { return json(400, { ok: false, error: String(e.message || e) }); }
94
+ // a named editor this machine does not have is not a choice to keep
95
+ const offered = detectEditors(where).find((e) => e.id === choice.editor);
96
+ if (!offered) return json(400, { ok: false, error: `${choiceLabel(choice, { env })} is not on this machine` });
97
+ if (offered.blocked) return json(400, { ok: false, error: offered.blocked });
98
+ saveEditorChoice(choice, env);
99
+ log(` editor: ${choiceLabel(choice, { env })} remembered`);
100
+ return json(200, { ok: true, ...state() });
101
+ }
102
+
103
+ /**
104
+ * `POST /deck/edit/open` `{ slide, index?, path?, tag? }`: the deck opened
105
+ * in the saved editor at that place. 409 for an address the file does not
106
+ * have (stale, like the other element routes); 428 with `choose: true`
107
+ * before an editor is chosen; 422 with `reason` when the chosen one cannot
108
+ * be started from here (not installed, a terminal editor).
109
+ */
110
+ async function openRoute({ req, body, json }) {
111
+ if (refuseForeign(req, json)) return;
112
+ const { slide, index = null, path = null, tag = null } = JSON.parse(body || '{}');
113
+ if (!Number.isInteger(slide) || slide < 1 || (index !== null && (!Number.isInteger(index) || index < 0))
114
+ || (path !== null && !Array.isArray(path)) || (path !== null && index === null) || (tag !== null && typeof tag !== 'string')) {
115
+ return json(400, { ok: false, error: 'bad payload' });
116
+ }
117
+ let pos;
118
+ try {
119
+ pos = sourcePosition(readDeck(), { slide, index, path, tag });
120
+ } catch (e) {
121
+ if (e.code === 'STALE' || /^no slide \d|no element at index/.test(e.message)) {
122
+ return json(409, { ok: false, stale: true, error: String(e.message || e).split('\n')[0] });
123
+ }
124
+ if (e.message === 'bad path') return json(400, { ok: false, error: 'bad payload' });
125
+ throw e;
126
+ }
127
+ const choice = loadEditorChoice(env);
128
+ if (!choice) return json(428, { ok: false, choose: true, error: 'choose your code editor first', ...state() });
129
+ const cmd = editorCommand(choice, { file: deckPath, line: pos.line, column: pos.column }, where);
130
+ if (!cmd.ok) return json(422, { ok: false, reason: cmd.reason, error: cmd.error, ...state() });
131
+ const started = await launchEditor(cmd, { baseEnv: env, ...(spawn ? { spawn } : {}) });
132
+ if (!started.ok) {
133
+ return json(422, { ok: false, reason: 'missing', error: `${cmd.label} did not start: ${started.error}`, ...state() });
134
+ }
135
+ log(` editor: slide ${slide}${index === null ? '' : ` #${index}${path?.length ? ` › ${path.join('.')}` : ''}`} opened in ${cmd.label} at line ${pos.line}`);
136
+ return json(200, { ok: true, line: pos.line, column: pos.column, editor: cmd.label });
137
+ }
138
+
139
+ routes.set('GET /deck/edit/editor', editorStateRoute);
140
+ routes.set('POST /deck/edit/editor', editorSaveRoute);
141
+ routes.set('POST /deck/edit/open', openRoute);
142
+ return routes;
143
+ }