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
@@ -194,11 +194,12 @@ const order = (a, b) => a.slide - b.slide || ruleRank(a.rule) - ruleRank(b.rule)
194
194
  * Review the deck in `html`: batches of `REVIEW_BATCH` slides, a few at a
195
195
  * time, each through a read-only ask. Resolves to `{ findings, failed }`,
196
196
  * `failed` being `[{ slides, why }]` for a batch that timed out or answered
197
- * nothing usable. Throws only when there is no agent to ask at all.
197
+ * nothing usable. Throws only when there is no agent to ask at all. `signal`
198
+ * stops it: the asks in flight are killed and no batch after them is asked.
198
199
  */
199
200
  export async function reviewDeck(html, {
200
201
  agent = null, cwd = process.cwd(), env = process.env, timeoutMs = REVIEW_TIMEOUT_MS,
201
- concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onBatch = () => {},
202
+ concurrency = ENHANCE_CONCURRENCY, resolveAgent = agentAsk, exec = ask, onBatch = () => {}, signal = null,
202
203
  } = {}) {
203
204
  if (!resolveAgent(agent, 'x', { env })) throw new Error(agentUnavailable(agent, detectAgents({ env })));
204
205
  const slides = reviewSlides(html);
@@ -209,10 +210,10 @@ export async function reviewDeck(html, {
209
210
  const failed = [];
210
211
  let next = 0, done = 0;
211
212
  const worker = async () => {
212
- while (next < batches.length) {
213
+ while (next < batches.length && !signal?.aborted) {
213
214
  const batch = batches[next++];
214
215
  const cmd = resolveAgent(agent, reviewPrompt(batch, outline), { env });
215
- const out = cmd ? await exec(cmd, cwd, timeoutMs) : null;
216
+ const out = cmd ? await exec(cmd, cwd, timeoutMs, signal) : null;
216
217
  const r = out == null ? { why: 'the agent did not answer in time' } : parseReview(out, batch);
217
218
  if (r.findings) findings.push(...r.findings);
218
219
  else failed.push({ slides: batch.map((s) => s.slide), why: r.why });
package/cli/agents.mjs CHANGED
@@ -25,6 +25,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
25
25
  import path, { dirname, join } from 'node:path';
26
26
  import { configHome } from './marketplace.mjs';
27
27
  import { listUnits } from './units.mjs';
28
+ import { unleashedEnv } from './supervise.mjs';
28
29
 
29
30
  export const AGENTS = [
30
31
  {
@@ -35,17 +36,29 @@ export const AGENTS = [
35
36
  // call is a line — so the deck's chip can say WHAT the agent is doing
36
37
  // instead of only how long it has been doing it.
37
38
  // --allowedTools: acceptEdits covers the file, not the shell, and the
38
- // skill asks the agent to render the deck (`npx decklight pdf …`) to
39
+ // skill asks the agent to render the deck (`npx decklight@latest pdf …`) to
39
40
  // check nothing overflows before it is done. Only decklight's own CLI
40
- // is allowed; everything else still needs a permission it has no TTY
41
- // to ask for, which is the point.
42
- args: (prompt) => ['-p', prompt, '--permission-mode', 'acceptEdits',
43
- '--allowedTools', 'Bash(npx decklight:*)', 'Bash(decklight:*)',
41
+ // is allowed, in each form the skill and AGENTS.md name (a rule is a
42
+ // prefix, so `npx decklight` does not cover `npx decklight@latest`,
43
+ // #901); everything else still needs a permission it has no TTY to ask
44
+ // for, which is the point.
45
+ // --add-dir: claude reads only inside the project unless told, and a
46
+ // migration's skill lives in a marketplace checkout under ~/.decklight
47
+ // (#893): each folder a job must read is named, and nothing more.
48
+ args: (prompt, deck, { dirs = [] } = {}) => ['-p', prompt, '--permission-mode', 'acceptEdits',
49
+ '--allowedTools', 'Bash(npx decklight:*)', 'Bash(npx decklight@latest:*)', 'Bash(decklight:*)',
50
+ ...dirs.flatMap((d) => ['--add-dir', d]),
44
51
  '--output-format', 'stream-json', '--verbose'],
45
52
  stream: 'claude-json',
46
53
  // no --permission-mode: an ASK is read-only by construction, and a
47
54
  // commit-message call has no business being able to edit the deck.
48
55
  ask: (prompt) => ['-p', prompt],
56
+ // How each CLI takes a model (#918): appended after the rest, which every
57
+ // parser here accepts. `model: null` is a CLI with no flag for it, said
58
+ // as such rather than a setting quietly dropped.
59
+ model: (id) => ['--model', id],
60
+ // what the card's model field offers; any other id can still be typed
61
+ models: ['opus', 'sonnet', 'haiku'],
49
62
  },
50
63
  {
51
64
  name: 'codex', label: 'Codex CLI', bin: 'codex',
@@ -53,6 +66,7 @@ export const AGENTS = [
53
66
  // the workspace sandbox while allowing file writes.
54
67
  args: (prompt) => ['exec', '--full-auto', prompt],
55
68
  ask: (prompt) => ['exec', '--sandbox', 'read-only', prompt],
69
+ model: (id) => ['-m', id],
56
70
  },
57
71
  {
58
72
  name: 'bob', label: 'IBM Bob', bin: 'bob',
@@ -60,26 +74,33 @@ export const AGENTS = [
60
74
  // it from hanging on the license prompt when there is no TTY.
61
75
  args: (prompt) => ['-p', prompt, '--accept-license'],
62
76
  ask: (prompt) => ['-p', prompt, '--accept-license'],
77
+ model: null,
63
78
  },
64
79
  {
65
80
  name: 'gemini', label: 'Gemini CLI', bin: 'gemini',
66
81
  args: (prompt) => ['--yolo', '-p', prompt],
67
82
  ask: (prompt) => ['-p', prompt],
83
+ model: (id) => ['-m', id],
68
84
  },
69
85
  {
70
86
  name: 'copilot', label: 'GitHub Copilot CLI', bin: 'copilot',
71
87
  args: (prompt) => ['-p', prompt, '--allow-all-tools'],
72
88
  ask: (prompt) => ['-p', prompt],
89
+ model: (id) => ['--model', id],
73
90
  },
74
91
  {
75
92
  name: 'opencode', label: 'OpenCode', bin: 'opencode',
76
93
  args: (prompt) => ['run', prompt],
77
94
  ask: (prompt) => ['run', prompt],
95
+ // provider/model, e.g. anthropic/claude-sonnet-4
96
+ model: (id) => ['-m', id],
78
97
  },
79
98
  {
80
99
  name: 'goose', label: 'Goose', bin: 'goose',
81
100
  args: (prompt) => ['run', '-t', prompt],
82
101
  ask: (prompt) => ['run', '-t', prompt],
102
+ // goose reads its model from its own config (GOOSE_MODEL), not argv
103
+ model: null,
83
104
  },
84
105
  {
85
106
  name: 'aider', label: 'Aider', bin: 'aider',
@@ -88,16 +109,19 @@ export const AGENTS = [
88
109
  args: (prompt, deck) => ['--yes-always', '--no-auto-commits', '--message', prompt, deck],
89
110
  // no deck on the command line either: aider edits what it is given
90
111
  ask: (prompt) => ['--yes-always', '--no-auto-commits', '--message', prompt],
112
+ model: (id) => ['--model', id],
91
113
  },
92
114
  {
93
115
  name: 'cursor', label: 'Cursor CLI', bin: 'cursor-agent',
94
116
  args: (prompt) => ['-p', prompt, '--force'],
95
117
  ask: (prompt) => ['-p', prompt],
118
+ model: (id) => ['--model', id],
96
119
  },
97
120
  {
98
121
  name: 'qwen', label: 'Qwen Code', bin: 'qwen',
99
122
  args: (prompt) => ['--yolo', '-p', prompt],
100
123
  ask: (prompt) => ['-p', prompt],
124
+ model: (id) => ['-m', id],
101
125
  },
102
126
  ];
103
127
 
@@ -135,6 +159,9 @@ export function installedAgents(home = configHome()) {
135
159
  bin: d.bin,
136
160
  installed: true,
137
161
  args: (prompt, deck) => expandArgs(d.args, prompt, deck),
162
+ // optional: `"model": ["--model", "{model}"]`, a template like `args`
163
+ model: Array.isArray(d.model) && d.model.every((a) => typeof a === 'string')
164
+ ? (id) => d.model.map((a) => a.replaceAll('{model}', id)) : null,
138
165
  });
139
166
  } catch { /* a descriptor we cannot read is one agent, not the roster */ }
140
167
  }
@@ -263,22 +290,106 @@ export function detectAgents({ env = process.env, hasBin = canRun, home } = {})
263
290
  /** Where the preferred agent is remembered — beside the unit library. */
264
291
  export const agentConfigPath = (home = configHome()) => join(home, 'agent.json');
265
292
 
266
- /** The remembered agent's name, or null. A missing file is first-run. */
267
- export function preferredAgent(home = configHome()) {
293
+ /** What agent.json holds, `{}` when there is none (first run) or it is unreadable. */
294
+ function readAgentConfig(home) {
268
295
  try {
269
296
  const saved = JSON.parse(readFileSync(agentConfigPath(home), 'utf8'));
270
- return typeof saved?.preferred === 'string' ? saved.preferred : null;
271
- } catch { return null; }
297
+ return saved && typeof saved === 'object' && !Array.isArray(saved) ? saved : {};
298
+ } catch { return {}; }
272
299
  }
273
300
 
274
- /** Remember `name` as the agent `A` reaches for; `null` forgets it. */
275
- export function setPreferredAgent(name, home = configHome()) {
301
+ /** Write agent.json; each setter changes its own key and keeps the others. */
302
+ function writeAgentConfig(change, home) {
276
303
  const file = agentConfigPath(home);
277
304
  mkdirSync(dirname(file), { recursive: true });
278
- writeFileSync(file, `${JSON.stringify({ preferred: name ?? null }, null, 2)}\n`);
305
+ writeFileSync(file, `${JSON.stringify({ ...readAgentConfig(home), ...change }, null, 2)}\n`);
279
306
  return file;
280
307
  }
281
308
 
309
+ /** The remembered agent's name, or null. A missing file is first-run. */
310
+ export function preferredAgent(home = configHome()) {
311
+ const saved = readAgentConfig(home);
312
+ return typeof saved.preferred === 'string' ? saved.preferred : null;
313
+ }
314
+
315
+ /** Remember `name` as the agent `A` reaches for; `null` forgets it. */
316
+ export function setPreferredAgent(name, home = configHome()) {
317
+ return writeAgentConfig({ preferred: name ?? null }, home);
318
+ }
319
+
320
+ // ── the model it runs on (#918) ─────────────────────────────────────────────
321
+ // Decklight's own choice, for decklight's runs only: passed as the agent's
322
+ // model flag, so the user's own default (`"model"` in ~/.claude/settings.json)
323
+ // stays what a plain `claude` opens on. Nothing set means no flag at all, and
324
+ // the agent's own default applies exactly as it always did.
325
+
326
+ /** The two kinds of run: an edit (`args`) and a question (`ask`). */
327
+ const MODEL_KEYS = { edit: 'models', ask: 'askModels' };
328
+ /** The per-run override for each kind; `--agent-model` and `--agent-ask-model` set them. */
329
+ export const MODEL_ENV = { edit: 'DECKLIGHT_AGENT_MODEL', ask: 'DECKLIGHT_AGENT_ASK_MODEL' };
330
+
331
+ const modelId = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
332
+
333
+ /** The models remembered for `name`: `{ edit, ask }`, each an id or null. */
334
+ export function rememberedModels(name, home = configHome()) {
335
+ const saved = readAgentConfig(home);
336
+ const pick = (key) => modelId(saved[key]?.[name]);
337
+ return { edit: pick(MODEL_KEYS.edit), ask: pick(MODEL_KEYS.ask) };
338
+ }
339
+
340
+ /** Remember `model` for `name`'s `task` (edit | ask); `null` forgets it. */
341
+ export function setAgentModel(name, model, { task = 'edit', home = configHome() } = {}) {
342
+ const key = MODEL_KEYS[task];
343
+ if (!key) throw new Error(`no such task: ${task}`);
344
+ const all = { ...(readAgentConfig(home)[key] ?? {}) };
345
+ const id = modelId(model);
346
+ if (id) all[name] = id; else delete all[name];
347
+ return writeAgentConfig({ [key]: all }, home);
348
+ }
349
+
350
+ /**
351
+ * Which model `name` runs `task` on, and where that came from: `{ model,
352
+ * source }`, `source` one of 'run' (the flag or env var), 'saved' or null.
353
+ *
354
+ * The same precedence as the agent itself — this run's choice, then the
355
+ * remembered one, then the agent's own default — with one step more for a
356
+ * question: its own setting first, then the edit's, so `--agent-model haiku`
357
+ * alone moves a run's commit subjects too. A run's choice of either kind beats
358
+ * a remembered one of either kind: it was made later, for this run.
359
+ */
360
+ export function agentModel(name, { task = 'edit', env = process.env, home = configHome() } = {}) {
361
+ const saved = rememberedModels(name, home);
362
+ const order = task === 'ask'
363
+ ? [[env[MODEL_ENV.ask], 'run'], [env[MODEL_ENV.edit], 'run'], [saved.ask, 'saved'], [saved.edit, 'saved']]
364
+ : [[env[MODEL_ENV.edit], 'run'], [saved.edit, 'saved']];
365
+ for (const [v, source] of order) if (modelId(v)) return { model: modelId(v), source };
366
+ return { model: null, source: null };
367
+ }
368
+
369
+ /**
370
+ * The argv tail that puts `agent` on its model, and what the run reports:
371
+ * `{ flag, model, unsupported }`. An agent whose CLI takes no model flag gets
372
+ * no flag and says which model it could not take, so the caller can show the
373
+ * setting as unavailable instead of pretending it applied.
374
+ */
375
+ function modelFlag(agent, task, { env, home, model }) {
376
+ const id = model !== undefined ? modelId(model) : agentModel(agent.name, { task, env, home }).model;
377
+ if (!id) return { flag: [], model: null, unsupported: null };
378
+ if (typeof agent.model !== 'function') return { flag: [], model: null, unsupported: id };
379
+ return { flag: agent.model(id), model: id, unsupported: null };
380
+ }
381
+
382
+ /** Put `--agent-model` / `--agent-ask-model` into `env` for every agent this process starts. */
383
+ export function applyModelFlags(opt, env = process.env) {
384
+ for (const [task, flag] of [['edit', '--agent-model'], ['ask', '--agent-ask-model']]) {
385
+ const v = opt(flag);
386
+ if (typeof v === 'string' && v.trim()) env[MODEL_ENV[task]] = v.trim();
387
+ }
388
+ }
389
+
390
+ /** Can `agent` be told a model at all? */
391
+ export const takesModel = (agent) => typeof agent?.model === 'function';
392
+
282
393
  /**
283
394
  * Why `name` cannot be run, as a line naming the way out (#125).
284
395
  *
@@ -310,8 +421,10 @@ export function agentUnavailable(name, roster, home = configHome(),
310
421
  /**
311
422
  * The exact spawn for one editing task: `name` picks the agent (or the first
312
423
  * detected one when omitted), `instruction` is the user's ask, `deck` the
313
- * file it should edit. Returns { bin, args, label } or null when the agent
314
- * isn't available.
424
+ * file it should edit, `dirs` folders outside the project it must be able to
425
+ * read (an agent that confines its reads to the project is given them; one
426
+ * whose sandbox already reads anywhere ignores them). Returns { bin, args,
427
+ * label } or null when the agent isn't available.
315
428
  */
316
429
  /**
317
430
  * The same agent, asked a QUESTION rather than told to edit (SPEC `PRESENTING`).
@@ -329,26 +442,30 @@ export function agentUnavailable(name, roster, home = configHome(),
329
442
  * whose unit declares one template and cannot be asked for a second — noted
330
443
  * rather than hidden, since it is the one path here that stays writable.
331
444
  */
332
- export function agentAsk(name, prompt, { env = process.env, hasBin = canRun, home, spec = spawnSpec } = {}) {
445
+ export function agentAsk(name, prompt, { env = process.env, hasBin = canRun, home, spec = spawnSpec, model } = {}) {
333
446
  const roster = detectAgents({ env, hasBin, home });
334
447
  const wanted = name ?? preferredAgent(home);
335
448
  const agent = wanted ? roster.find((a) => a.name === wanted) : roster[0];
336
449
  if (!agent) return null;
337
450
  const how = spec(agent.bin, { env }) ?? { bin: agent.bin, prefix: [] };
338
451
  const build = agent.ask ?? agent.args;
452
+ const m = modelFlag(agent, 'ask', { env, home, model });
339
453
  return {
340
454
  bin: how.bin,
341
- args: [...how.prefix, ...build(prompt)],
455
+ args: [...how.prefix, ...build(prompt), ...m.flag],
342
456
  label: agent.label,
343
457
  name: agent.name,
458
+ model: m.model,
459
+ modelUnsupported: m.unsupported,
344
460
  readOnly: !!agent.ask,
461
+ env: unleashedEnv(env),
345
462
  };
346
463
  }
347
464
 
348
465
  /** 1 → first, 2 → second … for a sentence an agent reads. */
349
466
  const ordinal = (n) => (n === 1 ? 'first' : n === 2 ? 'second' : n === 3 ? 'third' : `${n}th`);
350
467
 
351
- export function agentCommand(name, instruction, deck, { env = process.env, hasBin = canRun, home, spec = spawnSpec, slide = null } = {}) {
468
+ export function agentCommand(name, instruction, deck, { env = process.env, hasBin = canRun, home, spec = spawnSpec, slide = null, dirs = [], model } = {}) {
352
469
  const roster = detectAgents({ env, hasBin, home });
353
470
  // Precedence, matching how every other saved choice resolves (PRESENTING):
354
471
  // an explicit name > the remembered preference > the first detected agent.
@@ -377,21 +494,34 @@ export function agentCommand(name, instruction, deck, { env = process.env, hasBi
377
494
  // mode). The skill tells an agent that opened the deck on its own to call
378
495
  // the commit route; one started by A must not, or the edit lands twice.
379
496
  'decklight started you and will commit your edit itself when you finish, under your summary: do not call the commit route. ' +
497
+ // The summary is the commit subject, and the slide number above is the
498
+ // likeliest word in it. A number stops being true when a slide is
499
+ // inserted above it, and `git log` then points at the wrong slide.
500
+ 'In that summary, name a slide by its title, or by a few words describing it when it has none, never by its number. ' +
380
501
  `Apply this change, editing the file in place: ${instruction}`;
381
502
  // The spawn spec, not the bare name: on Windows an npm-installed agent is a
382
503
  // batch shim, and `prefix` is the script node has to be handed for the
383
504
  // arguments below to stay arguments (#307). On POSIX it is empty and this is
384
505
  // the same command it always was.
385
506
  const how = spec(agent.bin, { env }) ?? { bin: agent.bin, prefix: [] };
507
+ // the model (#918): `model` given wins, else this run's, else the remembered one
508
+ const m = modelFlag(agent, 'edit', { env, home, model });
386
509
  return {
387
510
  bin: how.bin,
388
- args: [...how.prefix, ...agent.args(prompt, deck)],
511
+ args: [...how.prefix, ...agent.args(prompt, deck, { dirs }), ...m.flag],
389
512
  label: agent.label,
390
513
  name: agent.name,
514
+ // the model it was told to run on, or null for its own default; and one
515
+ // it was set to but cannot take (no model flag), for the caller to say so
516
+ model: m.model,
517
+ modelUnsupported: m.unsupported,
391
518
  // which stream dialect stdout speaks, if any — the server's activity
392
519
  // parser keys off it, and agents without one still get the generic
393
520
  // last-line clue
394
521
  stream: agent.stream ?? null,
522
+ // what to spawn it with: the server's environment minus `open`'s leash,
523
+ // or every decklight command the agent runs exits at once (#901)
524
+ env: unleashedEnv(env),
395
525
  };
396
526
  }
397
527
 
@@ -24,6 +24,7 @@ import os from 'node:os';
24
24
  import path from 'node:path';
25
25
  import { configuredTrackDirs } from './edit.mjs';
26
26
  import { runAsync, CODEC_MS, PROBE_MS } from '../tools/exec.mjs';
27
+ import { renumber, sliceManifest } from './bundle-module.mjs';
27
28
 
28
29
  export const AUDIO_CHOICES = ['original', 'aac', 'opus'];
29
30
 
@@ -56,8 +57,10 @@ export const sizeLabel = (n) => (n < 1048576 ? `${(n / 1024).toFixed(1)} KB` : `
56
57
  * `file` entries. `found` maps the URL the runtime plays to the file;
57
58
  * `folders` reads "voices/ (12), cloud/ (3)"; `remote` counts manifest entries
58
59
  * with a `url` of their own (a bucket's, often signed), which stay there.
60
+ * With `mod` (`bundle --module`, cli/bundle-module.mjs) only that chapter's
61
+ * files are found, each under the slide number it has in the chapter.
59
62
  */
60
- export function narrationAudio(html, deckDir) {
63
+ export function narrationAudio(html, deckDir, mod = null) {
61
64
  const found = new Map();
62
65
  const where = new Map();
63
66
  const add = (key, abs) => {
@@ -70,7 +73,11 @@ export function narrationAudio(html, deckDir) {
70
73
  if (ABSOLUTE.test(d)) continue; // a public bucket's prefix: nothing on this disk
71
74
  const abs = path.resolve(deckDir, d);
72
75
  if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) continue;
73
- for (const f of fs.readdirSync(abs).sort()) if (AUDIO_FILE.test(f)) add(`${d.replace(/\/+$/, '')}/${f}`, path.join(abs, f));
76
+ for (const f of fs.readdirSync(abs).sort()) {
77
+ if (!AUDIO_FILE.test(f)) continue;
78
+ const as = renumber(f, mod);
79
+ if (as) add(`${d.replace(/\/+$/, '')}/${as}`, path.join(abs, f));
80
+ }
74
81
  }
75
82
  let remote = 0;
76
83
  // `manifest: '…'` in a boot call, `"manifest": "…"` in a configuration block
@@ -80,7 +87,7 @@ export function narrationAudio(html, deckDir) {
80
87
  try { data = JSON.parse(fs.readFileSync(abs, 'utf8')); } catch { continue; }
81
88
  const clean = rel.replace(/[?#].*$/, '');
82
89
  const base = clean.slice(0, clean.lastIndexOf('/') + 1); // voicetrack.js manifestBase
83
- const entries = (data?.slides ?? []).flatMap((e) => (e ? [e, ...(e.segments ?? []).filter(Boolean)] : []));
90
+ const entries = (sliceManifest(data, mod)?.slides ?? []).flatMap((e) => (e ? [e, ...(e.segments ?? []).filter(Boolean)] : []));
84
91
  for (const e of entries) {
85
92
  if (e.url) { remote++; continue; }
86
93
  if (typeof e.file !== 'string' || ABSOLUTE.test(e.file)) continue;
@@ -0,0 +1,95 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // One chapter of a deck as a bundle of its own (`bundle --module`, SPEC
5
+ // PRESENTING): the sections from a `data-module` marker up to the next one,
6
+ // and the narration that goes with them.
7
+ //
8
+ // The narration is the part that needs care. A track's files are named by
9
+ // slide number (`slide-07-02.wav`, `slide-07.visemes.json`) and a manifest is
10
+ // indexed by it (`slides[6]`), because the runtime builds those names from the
11
+ // slide it is on, counting from 1. Cut a chapter out and its slides are
12
+ // numbered from 1 again, so every name is moved down by the chapter's offset
13
+ // and anything outside the chapter is left out. Nothing is re-voiced: the
14
+ // clips are the same bytes under the number the bundle will ask for.
15
+
16
+ /** The top-level `<section>`s inside `[contentStart, contentEnd)`, depth-aware. */
17
+ function sectionSpans(html, contentStart, contentEnd) {
18
+ const spans = [];
19
+ const re = /<section\b[^>]*>|<\/section\s*>/gi;
20
+ re.lastIndex = contentStart;
21
+ let depth = 0, open = -1, m;
22
+ while ((m = re.exec(html)) && m.index < contentEnd) {
23
+ if (m[0][1] === '/') {
24
+ if (depth > 0 && --depth === 0) spans.push({ start: open, end: m.index + m[0].length, tag: html.slice(open, html.indexOf('>', open) + 1) });
25
+ } else if (depth++ === 0) open = m.index;
26
+ }
27
+ return spans;
28
+ }
29
+
30
+ const unescapeAttr = (s) => s.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
31
+
32
+ /**
33
+ * The deck's chapters, in order: `{ n, title, offset, count }`, where `offset`
34
+ * is how many slides come before the chapter and `count` how many it holds.
35
+ * Slides before the first marker belong to no chapter.
36
+ */
37
+ export function deckModules(html, bounds) {
38
+ const spans = sectionSpans(html, bounds.contentStart, bounds.contentEnd);
39
+ const out = [];
40
+ spans.forEach((s, i) => {
41
+ const m = s.tag.match(/\bdata-module\s*=\s*(?:"([^"]*)"|'([^']*)')/i);
42
+ if (!m) return;
43
+ if (out.length) out[out.length - 1].count = i - out[out.length - 1].offset;
44
+ out.push({ n: out.length + 1, title: unescapeAttr(m[1] ?? m[2]).trim(), offset: i, count: spans.length - i });
45
+ });
46
+ return { modules: out, spans };
47
+ }
48
+
49
+ /**
50
+ * The chapter `want` names: its number (1-based) or its title, case and
51
+ * surrounding space ignored. Throws an Error with a sentence that lists the
52
+ * chapters when nothing matches, or says there are none.
53
+ */
54
+ export function pickModule(modules, want) {
55
+ if (!modules.length) {
56
+ throw new Error('--module: this deck has no chapters — a chapter starts at a <section data-module="…">');
57
+ }
58
+ const key = String(want).trim();
59
+ const byNumber = /^\d+$/.test(key) ? modules[Number(key) - 1] : null;
60
+ const hit = byNumber ?? modules.find((m) => m.title.toLowerCase() === key.toLowerCase());
61
+ if (hit) return hit;
62
+ throw new Error(`--module: no chapter "${key}" in this deck — its chapters are:\n`
63
+ + modules.map((m) => ` ${m.n} ${m.title} (${m.count === 1 ? '1 slide' : `${m.count} slides`})`).join('\n'));
64
+ }
65
+
66
+ /** The deck with only `mod`'s sections left inside the container. */
67
+ export function sliceModule(html, bounds, spans, mod) {
68
+ const keep = spans.slice(mod.offset, mod.offset + mod.count);
69
+ const inner = keep.map((s) => html.slice(s.start, s.end)).join('\n\n ');
70
+ return html.slice(0, bounds.contentStart) + '\n\n ' + inner + '\n\n ' + html.slice(bounds.contentEnd);
71
+ }
72
+
73
+ /**
74
+ * A track file's name moved into the chapter: `slide-07-02.wav` with an
75
+ * offset of 4 is `slide-03-02.wav`, and a slide outside the chapter is null.
76
+ * Works on a bare stem (`slide-07`) and on a path (`voices/slide-07.m4a`).
77
+ * With no `mod` the name is returned as it is.
78
+ */
79
+ export function renumber(name, mod) {
80
+ if (!mod) return name;
81
+ const m = name.match(/^(.*?\bslide-)(\d+)((?:-\d+)?(?:\..*)?)$/);
82
+ if (!m) return name;
83
+ const n = Number(m[2]) - mod.offset;
84
+ if (n < 1 || n > mod.count) return null;
85
+ return `${m[1]}${String(n).padStart(Math.max(2, m[2].length), '0')}${m[3]}`;
86
+ }
87
+
88
+ /** A manifest's `slides` cut to the chapter (entry k is slide k + 1). */
89
+ export function sliceManifest(data, mod) {
90
+ if (!mod || !Array.isArray(data?.slides)) return data;
91
+ return { ...data, slides: data.slides.slice(mod.offset, mod.offset + mod.count) };
92
+ }
93
+
94
+ /** "Foundations" → "foundations", for the default file name. */
95
+ export const slug = (s) => s.toLowerCase().normalize('NFKD').replace(/[^\w\s-]/g, '').trim().replace(/[\s_]+/g, '-').replace(/-+/g, '-') || 'module';