decklight 0.8.1 → 0.10.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 (138) hide show
  1. package/PLATFORM.md +707 -0
  2. package/README.md +226 -150
  3. package/SPEC.md +803 -888
  4. package/cli/agent-review.mjs +246 -0
  5. package/cli/agents.mjs +35 -9
  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 +190 -0
  10. package/cli/bundle-module.mjs +95 -0
  11. package/cli/bundle.mjs +439 -35
  12. package/cli/cast.mjs +48 -12
  13. package/cli/check-fixes.mjs +186 -0
  14. package/cli/check.mjs +988 -0
  15. package/cli/clone-deck.mjs +179 -0
  16. package/cli/commands.mjs +345 -0
  17. package/cli/comments.mjs +64 -18
  18. package/cli/commit-flow.mjs +51 -22
  19. package/cli/commit-message.mjs +51 -74
  20. package/cli/commit-split.mjs +601 -0
  21. package/cli/deck-refs.mjs +64 -0
  22. package/cli/deck-routes.mjs +67 -0
  23. package/cli/deckfile.mjs +3 -5
  24. package/cli/decklight.mjs +68 -289
  25. package/cli/design-system-deps.mjs +209 -0
  26. package/cli/design-system-edit.mjs +194 -0
  27. package/cli/design-system-refs.mjs +666 -0
  28. package/cli/design-system.mjs +497 -0
  29. package/cli/doctor.mjs +115 -0
  30. package/cli/edit-git.mjs +353 -0
  31. package/cli/edit-handover.mjs +551 -0
  32. package/cli/edit-look.mjs +631 -0
  33. package/cli/edit-slides.mjs +683 -0
  34. package/cli/edit.mjs +2585 -855
  35. package/cli/enhance.mjs +485 -0
  36. package/cli/extension.mjs +10 -10
  37. package/cli/font-refs.mjs +273 -0
  38. package/cli/font.mjs +246 -0
  39. package/cli/git-tree.mjs +1 -1
  40. package/cli/git.mjs +78 -11
  41. package/cli/import.mjs +56 -10
  42. package/cli/init.mjs +407 -236
  43. package/cli/library.mjs +127 -0
  44. package/cli/loader.mjs +3 -1
  45. package/cli/marketplace-autocheck.mjs +200 -0
  46. package/cli/marketplace.mjs +460 -29
  47. package/cli/narrate.mjs +251 -0
  48. package/cli/open-browser.mjs +63 -0
  49. package/cli/open.mjs +961 -0
  50. package/cli/pdf.mjs +64 -17
  51. package/cli/pkg.mjs +44 -2
  52. package/cli/plugin.mjs +43 -41
  53. package/cli/port-conflict.mjs +53 -23
  54. package/cli/pptx-export.mjs +63 -27
  55. package/cli/publish.mjs +8 -4
  56. package/cli/qr.mjs +1 -1
  57. package/cli/record.mjs +85 -23
  58. package/cli/remote.mjs +43 -17
  59. package/cli/restore.mjs +11 -4
  60. package/cli/review-ref.mjs +125 -0
  61. package/cli/review-remote.mjs +92 -48
  62. package/cli/review-routes.mjs +254 -0
  63. package/cli/review-store.mjs +47 -7
  64. package/cli/review-submit.mjs +47 -57
  65. package/cli/runtime-link.mjs +560 -0
  66. package/cli/serve.mjs +236 -45
  67. package/cli/setup.mjs +112 -0
  68. package/cli/sign.mjs +1 -1
  69. package/cli/skill-content.mjs +229 -35
  70. package/cli/skills.mjs +353 -26
  71. package/cli/start.mjs +110 -0
  72. package/cli/supervise.mjs +6 -6
  73. package/cli/theme-refs.mjs +527 -0
  74. package/cli/theme.mjs +181 -137
  75. package/cli/trust.mjs +83 -0
  76. package/cli/units.mjs +112 -47
  77. package/cli/update-check.mjs +1 -5
  78. package/cli/upgrade.mjs +194 -28
  79. package/cli/upstream.mjs +4 -3
  80. package/cli/util.mjs +4 -4
  81. package/cli/wizard.mjs +6 -6
  82. package/dist/build-info.json +1 -1
  83. package/dist/decklight.css +1533 -59
  84. package/dist/decklight.js +258 -115
  85. package/dist/decklight.js.map +4 -4
  86. package/docs/GLOSSARY.md +141 -0
  87. package/docs/architecture.svg +17 -17
  88. package/package.json +4 -2
  89. package/themes/README.md +9 -8
  90. package/themes/reveal-solarized.css +10 -0
  91. package/tools/args.mjs +20 -0
  92. package/tools/atomic-write.mjs +48 -0
  93. package/tools/brand-palette.mjs +717 -0
  94. package/tools/bridge.mjs +1 -1
  95. package/tools/build-groups.mjs +42 -0
  96. package/tools/color.mjs +48 -0
  97. package/tools/deck-html.mjs +396 -11
  98. package/tools/design-system-format.mjs +778 -0
  99. package/tools/design-system-migrations.mjs +207 -0
  100. package/tools/elevenlabs-tts.mjs +110 -17
  101. package/tools/exec.mjs +11 -3
  102. package/tools/extension-check.mjs +31 -7
  103. package/tools/font-format.mjs +190 -0
  104. package/tools/font-stacks.mjs +24 -0
  105. package/tools/gemini-tts.mjs +3 -0
  106. package/tools/lipsync-config.mjs +103 -0
  107. package/tools/lipsync-engines.mjs +205 -2
  108. package/tools/lipsync-server.mjs +264 -41
  109. package/tools/lipsync.mjs +37 -18
  110. package/tools/local-voice.mjs +32 -42
  111. package/tools/narration-manifest.mjs +270 -0
  112. package/tools/narration-synth.mjs +416 -0
  113. package/tools/pptx.mjs +776 -19
  114. package/tools/publish-targets.mjs +1 -1
  115. package/tools/publish-voices.mjs +3 -3
  116. package/tools/recording-impact.mjs +7 -3
  117. package/tools/render-theme.mjs +33 -0
  118. package/tools/review-anchor.mjs +28 -12
  119. package/tools/semver.mjs +40 -0
  120. package/tools/sentences.mjs +180 -0
  121. package/tools/shot.mjs +14 -7
  122. package/tools/site-clip.mjs +114 -0
  123. package/tools/site-voices.mjs +232 -0
  124. package/tools/template-theme.mjs +1 -1
  125. package/tools/test-impact.mjs +17 -10
  126. package/tools/theme-check.mjs +30 -3
  127. package/tools/tts-cache.mjs +4 -3
  128. package/tools/tts-engines.mjs +38 -20
  129. package/tools/tts-setup.mjs +7 -7
  130. package/tools/video-options.mjs +34 -0
  131. package/tools/video.mjs +530 -54
  132. package/tools/voiceover-server.mjs +185 -104
  133. package/tools/voiceover.mjs +119 -261
  134. package/tools/zip.mjs +1 -1
  135. package/cli/dev.mjs +0 -623
  136. package/cli/present.mjs +0 -853
  137. package/cli/review.mjs +0 -361
  138. package/tools/publish-site-voices.mjs +0 -75
package/cli/skills.mjs CHANGED
@@ -33,8 +33,11 @@ import { makeFail, runMain } from './util.mjs';
33
33
  import { isMain } from '../tools/args.mjs';
34
34
  import { zipSync } from './zip.mjs';
35
35
  import {
36
- PKG, AGENTS_MARKER, agentsSection, claudeSkillMd, referenceDoc, reportBugSkillMd,
36
+ PKG, AGENTS_MARKER, agentsSection, claudeSkillMd, homePath, referenceDoc, reportBugSkillMd, skillVersionOf,
37
37
  } from './skill-content.mjs';
38
+ import { semverCompare } from '../tools/semver.mjs';
39
+ import { librarySkills } from './units.mjs';
40
+ import { configHome } from './marketplace.mjs';
38
41
 
39
42
  // The reference doc, relative to whatever dir carries it. Skills keep their
40
43
  // own copy next to SKILL.md; AGENTS.md agents keep one under .decklight/.
@@ -74,7 +77,7 @@ const HELP = `decklight skills — install the Decklight authoring skill for AI
74
77
 
75
78
  Usage:
76
79
  decklight skills [agent…] [--dir path | --global] [--all] [--force]
77
- decklight skills add|list|remove <name> marketplace skills
80
+ decklight library add skill|list|remove <name> marketplace skills
78
81
 
79
82
  Agents:
80
83
  ${Object.entries(TARGETS).map(([k, t]) => ` ${k.padEnd(9)} ${t.label}`).join('\n')}
@@ -102,10 +105,12 @@ and IBM Bob get a marked section in AGENTS.md. Both point at a reference
102
105
  sliced from this version's SPEC.md, so the contract never drifts from the
103
106
  installed runtime.
104
107
 
105
- Marketplace skills (decklight skills add <name>) are a different thing and
108
+ Marketplace skills (decklight library add skill <name>) are a different thing and
106
109
  live somewhere else — ~/.decklight/skills/ — so they sit ALONGSIDE the
107
110
  authoring skill above and never replace it. The command above always writes
108
- the authoring skill; nothing installed from a catalog changes that.
111
+ the authoring skill; nothing installed from a catalog changes that. It does
112
+ hand them on: each is copied into .claude/skills/<name>/ when missing (never
113
+ over one already there) and listed in the AGENTS.md section.
109
114
  `;
110
115
 
111
116
  /** The agents found on PATH, in roster order (empty when none is). */
@@ -131,20 +136,42 @@ export function display(file) {
131
136
  return file;
132
137
  }
133
138
 
134
- /** Write a file, refusing to clobber an existing one without --force. */
135
- function writeIfAbsent(file, content, force) {
139
+ /**
140
+ * Is the skill text on disk older than the one this build would write?
141
+ * A file with no stamp predates the stamp (0.9.0) and counts as older.
142
+ */
143
+ function staleSkill(file, content) {
144
+ const mine = skillVersionOf(content);
145
+ if (!mine) return false;
146
+ let theirs = null;
147
+ try { theirs = skillVersionOf(fs.readFileSync(file, 'utf8')); } catch { return false; }
148
+ return theirs === null || (semverCompare(theirs, mine) ?? -1) < 0;
149
+ }
150
+
151
+ /**
152
+ * Write a file. An existing one is refreshed when it is OLDER than this build
153
+ * (the files are derived content, and an agent reading an old contract is
154
+ * the failure this exists to prevent) or when `refresh` says its sibling was;
155
+ * one that is already this version is left alone (null) without --force, and
156
+ * the command fails only when NOTHING needed writing — a current install
157
+ * asked for again, which is what --force is for.
158
+ */
159
+ function writeIfAbsent(file, content, force, { refresh = null } = {}) {
136
160
  if (fs.existsSync(file) && !force) {
137
- fail(`${display(file)} already exists — pass --force to overwrite`);
161
+ const stale = refresh ?? staleSkill(file, content);
162
+ if (!stale) return null;
138
163
  }
139
164
  fs.mkdirSync(path.dirname(file), { recursive: true });
140
165
  fs.writeFileSync(file, content);
141
166
  return file;
142
167
  }
168
+ /** `display` of a write, or nothing for a file left alone. */
169
+ const wrote = (file) => (file ? display(file) : null);
143
170
 
144
171
  /** Add/refresh the marked Decklight block in the AGENTS.md under `dir`. */
145
172
  function mergeAgentsMd(dir, refHref) {
146
173
  const agentsPath = path.join(dir, 'AGENTS.md');
147
- const section = agentsSection(refHref);
174
+ const section = agentsSection(refHref, { librarySkills: librarySkills() });
148
175
  if (!fs.existsSync(agentsPath)) {
149
176
  fs.mkdirSync(dir, { recursive: true });
150
177
  fs.writeFileSync(agentsPath, `# Agent notes\n\n${section}`);
@@ -162,8 +189,11 @@ function mergeAgentsMd(dir, refHref) {
162
189
 
163
190
  /** Write Claude's self-contained skill (SKILL.md + reference) into skillDir. */
164
191
  function installClaudeSkill(skillDir, force, written) {
165
- written.push(display(writeIfAbsent(path.join(skillDir, 'SKILL.md'), claudeSkillMd(SKILL_REF), force)));
166
- written.push(display(writeIfAbsent(path.join(skillDir, SKILL_REF), referenceDoc(), force)));
192
+ const skill = path.join(skillDir, 'SKILL.md');
193
+ // the reference carries no stamp of its own: it follows the SKILL.md beside it
194
+ const refresh = fs.existsSync(skill) ? staleSkill(skill, claudeSkillMd(SKILL_REF)) : null;
195
+ written.push(wrote(writeIfAbsent(skill, claudeSkillMd(SKILL_REF), force)));
196
+ written.push(wrote(writeIfAbsent(path.join(skillDir, SKILL_REF), referenceDoc(), force, { refresh })));
167
197
  }
168
198
 
169
199
  /**
@@ -173,7 +203,183 @@ function installClaudeSkill(skillDir, force, written) {
173
203
  */
174
204
  function installReportBugSkill(skillsRoot, force, written) {
175
205
  const dir = path.join(skillsRoot, 'decklight-report-bug');
176
- written.push(display(writeIfAbsent(path.join(dir, 'SKILL.md'), reportBugSkillMd(), force)));
206
+ written.push(wrote(writeIfAbsent(path.join(dir, 'SKILL.md'), reportBugSkillMd(), force)));
207
+ }
208
+
209
+ // --- marketplace skills, handed on to the agents (#880) ----------------------
210
+ //
211
+ // A library skill lives in ~/.decklight/skills/, which no agent reads. Claude
212
+ // indexes one skill per directory under .claude/skills/, so each is COPIED
213
+ // there (a copy, not a link: a symlink is a privilege on Windows, and a copy
214
+ // is what `unzip -d ~/.claude/skills/` would leave too); an AGENTS.md agent
215
+ // reads only its file, so the section lists them (`agentsSection`). A copy
216
+ // carries LIBRARY_MARK, and only a marked directory is ever replaced or
217
+ // removed: a skill the user wrote that happens to share a name is theirs.
218
+
219
+ const LIBRARY_MARK = '.decklight-library';
220
+
221
+ /**
222
+ * Copy one library skill under `skillsRoot`. `update` replaces a copy already
223
+ * there (what `library add` does, to take a new version); without it an
224
+ * existing copy is kept as it is (what a `decklight skills` re-run does).
225
+ */
226
+ function copyLibrarySkill(skill, skillsRoot, { update }) {
227
+ const dest = path.join(skillsRoot, skill.name);
228
+ if (fs.existsSync(dest)) {
229
+ if (!fs.existsSync(path.join(dest, LIBRARY_MARK))) {
230
+ return `left ${display(dest)} alone — a skill of that name that the library did not put there`;
231
+ }
232
+ if (!update) return null;
233
+ fs.rmSync(dest, { recursive: true, force: true });
234
+ }
235
+ fs.cpSync(skill.path, dest, { recursive: true });
236
+ fs.writeFileSync(path.join(dest, LIBRARY_MARK),
237
+ `copied from ${homePath(skill.path)} by decklight library add skill; decklight library remove skill ${skill.name} removes it\n`);
238
+ return `copied ${skill.name} from your library to ${display(dest)}`;
239
+ }
240
+
241
+ /**
242
+ * Bring the library skills under one Claude skills root up to the library:
243
+ * add the missing ones, drop the copies whose skill was removed from it.
244
+ * Never overwrites a copy — the authoring install re-run keeps them as they are.
245
+ */
246
+ export function syncLibrarySkills(skillsRoot, written) {
247
+ const skills = librarySkills();
248
+ for (const skill of skills) written.push(copyLibrarySkill(skill, skillsRoot, { update: false }));
249
+ if (!fs.existsSync(skillsRoot)) return;
250
+ const have = new Set(skills.map((s) => s.name));
251
+ for (const name of fs.readdirSync(skillsRoot)) {
252
+ const dir = path.join(skillsRoot, name);
253
+ if (have.has(name) || !fs.existsSync(path.join(dir, LIBRARY_MARK))) continue;
254
+ fs.rmSync(dir, { recursive: true, force: true });
255
+ written.push(`removed ${display(dir)} — no longer in your library`);
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Refresh every Decklight AGENTS.md section this command can find — the
261
+ * project's under `dir` and each agent's global one — so its list of library
262
+ * skills matches the library. Only a file already carrying the section is
263
+ * touched: this never creates an AGENTS.md nobody asked for.
264
+ */
265
+ function refreshAgentsSections({ dir = '.', env = process.env } = {}) {
266
+ const out = [];
267
+ const marked = (d) => {
268
+ try { return fs.readFileSync(path.join(d, 'AGENTS.md'), 'utf8').includes(AGENTS_MARKER); } catch { return false; }
269
+ };
270
+ const root = path.resolve(dir);
271
+ if (marked(root)) out.push(mergeAgentsMd(root, fs.existsSync(path.join(root, CLAUDE_REF)) ? CLAUDE_REF : SHARED_REF));
272
+ for (const t of Object.values(TARGETS)) {
273
+ const home = t.home(env);
274
+ if (t.kind === 'agents' && marked(home)) out.push(mergeAgentsMd(home, SHARED_REF));
275
+ }
276
+ return [...new Set(out)];
277
+ }
278
+
279
+ /** Claude's skills root for a scope: the project's, or its config home's. */
280
+ const claudeSkillsRoot = ({ dir = '.', global = false, env = process.env }) =>
281
+ (global ? path.join(TARGETS.claude.home(env), 'skills') : path.join(path.resolve(dir), '.claude', 'skills'));
282
+
283
+ /**
284
+ * `library add skill <name>` hands the installed skill to the agents: a copy
285
+ * in Claude's skills (the project's, or with `global` its config home's), and
286
+ * a line in every AGENTS.md section. Returns the lines to print.
287
+ */
288
+ export function placeLibrarySkill(name, { dir = '.', global = false, dirNamed = false, env = process.env } = {}) {
289
+ const skill = librarySkills().find((s) => s.name === name);
290
+ if (!skill) return [];
291
+ const out = [];
292
+ // a project is a directory that already has an agent setup, or one named with
293
+ // --dir: run from ~ or a scratch folder, a stray .claude/ helps nobody
294
+ if (global || dirNamed || agentProject(dir)) out.push(copyLibrarySkill(skill, claudeSkillsRoot({ dir, global, env }), { update: true }));
295
+ out.push(...refreshAgentsSections({ dir, env }));
296
+ if (!out.filter(Boolean).length) {
297
+ out.push(`not handed to an agent yet — ${display(path.resolve(dir))} has no .claude/ or Decklight AGENTS.md:`
298
+ + ` decklight skills in a project, or --dir <project> / --global`);
299
+ }
300
+ return out.filter(Boolean);
301
+ }
302
+
303
+ /**
304
+ * Where an agent already loads skill `name` from, or null: Claude's skills,
305
+ * its config home's (every project) before the project's under `dir`. A skill
306
+ * that is only in the library or a marketplace checkout is on no agent's
307
+ * path yet, and whatever needs it offers to put it there (#893).
308
+ */
309
+ export function placedSkill(name, { dir = '.', env = process.env } = {}) {
310
+ for (const global of [true, false]) {
311
+ const file = path.join(claudeSkillsRoot({ dir, global, env }), name, 'SKILL.md');
312
+ if (fs.existsSync(file)) return { scope: global ? 'global' : 'project', file };
313
+ }
314
+ return null;
315
+ }
316
+
317
+ /** The two places an offer to install skill `name` names, as the author reads them. */
318
+ export function skillPlaces(name, { dir = '.', env = process.env } = {}) {
319
+ return {
320
+ global: display(path.join(claudeSkillsRoot({ global: true, env }), name)),
321
+ project: display(path.join(claudeSkillsRoot({ dir, env }), name)),
322
+ };
323
+ }
324
+
325
+ /**
326
+ * The answer to that offer on a terminal: Enter (or g) is every project, the
327
+ * one recommended; p is this project only; anything else is not now (null).
328
+ */
329
+ export function skillPlaceAnswer(text) {
330
+ const a = String(text ?? '').trim().toLowerCase();
331
+ if (a === '' || a.startsWith('g') || a.startsWith('y')) return 'global';
332
+ return a.startsWith('p') ? 'project' : null;
333
+ }
334
+
335
+ /** The question that offer asks on a terminal. */
336
+ export const skillPlaceQuestion = (name, at) => `Install the ${name} skill for your agent?`
337
+ + ` [G] every project, ${at.global} (recommended) · [p] this project only, ${at.project} · [n] not now: `;
338
+
339
+ /**
340
+ * Put skill `name` where the agent loads skills, as an offer was answered:
341
+ * `global` (Claude's config home, every project) or the project under `dir`.
342
+ * Not in the library yet, it is installed there first from `ref`, its
343
+ * catalog entry. Returns `{ file, lines }`: the SKILL.md the agent now
344
+ * finds, and what was done, to print.
345
+ */
346
+ export async function placeSkill(name, { global = true, dir = '.', ref = name, env = process.env, home } = {}) {
347
+ const lines = [];
348
+ if (!librarySkills(home).some((s) => s.name === name)) {
349
+ const { installUnit } = await import('./units.mjs');
350
+ const done = await installUnit('skill', ref, home);
351
+ lines.push(`installed ${done.name}${done.entry.version ? ` ${done.entry.version}` : ''} from ${done.qualified}`);
352
+ }
353
+ const skill = librarySkills(home).find((s) => s.name === name);
354
+ if (skill) {
355
+ lines.push(copyLibrarySkill(skill, claudeSkillsRoot({ dir, global, env }), { update: true }));
356
+ lines.push(...refreshAgentsSections({ dir, env }));
357
+ }
358
+ return { file: placedSkill(name, { dir, env })?.file ?? null, lines: lines.filter(Boolean) };
359
+ }
360
+
361
+ /** Does `dir` already have an agent setup: a `.claude/`, or an AGENTS.md with the Decklight section? */
362
+ function agentProject(dir) {
363
+ const root = path.resolve(dir);
364
+ if (fs.existsSync(path.join(root, '.claude'))) return true;
365
+ try { return fs.readFileSync(path.join(root, 'AGENTS.md'), 'utf8').includes(AGENTS_MARKER); } catch { return false; }
366
+ }
367
+
368
+ /**
369
+ * `library remove skill <name>` takes it back from the same places: the
370
+ * copy in this project's and in Claude's global skills (both, whatever scope
371
+ * it was added with — only a marked copy is ours), and its AGENTS.md lines.
372
+ */
373
+ export function unplaceLibrarySkill(name, { dir = '.', env = process.env } = {}) {
374
+ const out = [];
375
+ for (const global of [false, true]) {
376
+ const copy = path.join(claudeSkillsRoot({ dir, global, env }), name);
377
+ if (!fs.existsSync(path.join(copy, LIBRARY_MARK))) continue;
378
+ fs.rmSync(copy, { recursive: true, force: true });
379
+ out.push(`removed ${display(copy)}`);
380
+ }
381
+ out.push(...refreshAgentsSections({ dir, env }));
382
+ return out;
177
383
  }
178
384
 
179
385
  // --- project scope: one repo, one shared AGENTS.md for every agent ----------
@@ -190,15 +396,16 @@ function installProject(targets, dir, force) {
190
396
  const skillsRoot = path.join(root, '.claude', 'skills');
191
397
  installClaudeSkill(path.join(skillsRoot, 'decklight'), force, written);
192
398
  installReportBugSkill(skillsRoot, force, written);
399
+ syncLibrarySkills(skillsRoot, written);
193
400
  }
194
401
  if (mdAgents.length) {
195
402
  // one reference copy: Claude's skill dir when Claude is also a target,
196
403
  // else a standalone .decklight/ copy the AGENTS.md agents point at.
197
404
  const refHref = wantsClaude ? CLAUDE_REF : SHARED_REF;
198
- if (!wantsClaude) written.push(display(writeIfAbsent(path.join(root, SHARED_REF), referenceDoc(), force)));
405
+ if (!wantsClaude) written.push(wrote(writeIfAbsent(path.join(root, SHARED_REF), referenceDoc(), force)));
199
406
  written.push(mergeAgentsMd(root, refHref));
200
407
  }
201
- return written;
408
+ return written.filter(Boolean);
202
409
  }
203
410
 
204
411
  // --- global scope: each agent self-contained in its own config home ---------
@@ -211,12 +418,70 @@ function installGlobal(targets, env, force) {
211
418
  if (t.kind === 'skill') {
212
419
  installClaudeSkill(path.join(home, 'skills', 'decklight'), force, written);
213
420
  installReportBugSkill(path.join(home, 'skills'), force, written);
421
+ syncLibrarySkills(path.join(home, 'skills'), written);
214
422
  } else {
215
- written.push(display(writeIfAbsent(path.join(home, SHARED_REF), referenceDoc(), force)));
423
+ written.push(wrote(writeIfAbsent(path.join(home, SHARED_REF), referenceDoc(), force)));
216
424
  written.push(mergeAgentsMd(home, SHARED_REF));
217
425
  }
218
426
  }
219
- return written;
427
+ return written.filter(Boolean);
428
+ }
429
+
430
+ // --- what is on this machine, against this build ------------------------------
431
+
432
+ /**
433
+ * The skill files older than this install, where `decklight <deck>` looks
434
+ * before it serves (PRESENTING): the project's, under `dir` (Claude's
435
+ * `.claude/skills/decklight/SKILL.md`, and an AGENTS.md carrying the marked
436
+ * section), and every agent's global home, whether or not that agent is on
437
+ * PATH today: a file that was installed is a file something reads. A stamp
438
+ * older than this build, or missing (before 0.9.0), is stale. Each entry is
439
+ * `{ scope: 'project' | 'global', target, file, version }`.
440
+ */
441
+ export function staleSkills({ dir = '.', env = process.env } = {}) {
442
+ const out = [];
443
+ const look = (scope, target, file, kind) => {
444
+ if (!fs.existsSync(file)) return;
445
+ let text = '';
446
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return; }
447
+ if (kind === 'agents' && !text.includes(AGENTS_MARKER)) return;
448
+ const version = skillVersionOf(text);
449
+ if (version === null || (semverCompare(version, PKG.version) ?? -1) < 0) out.push({ scope, target, file, version });
450
+ };
451
+ const root = path.resolve(dir);
452
+ look('project', 'claude', path.join(root, '.claude', 'skills', 'decklight', 'SKILL.md'), 'skill');
453
+ look('project', 'agents', path.join(root, 'AGENTS.md'), 'agents');
454
+ for (const [key, t] of Object.entries(TARGETS)) {
455
+ const home = t.home(env);
456
+ if (t.kind === 'skill') look('global', key, path.join(home, 'skills', 'decklight', 'SKILL.md'), 'skill');
457
+ else look('global', key, path.join(home, 'AGENTS.md'), 'agents');
458
+ }
459
+ return out;
460
+ }
461
+
462
+ /**
463
+ * Bring the files `staleSkills` named up to this build, and nothing else: a
464
+ * project whose AGENTS.md is stale gets its section refreshed, not a Claude
465
+ * skill it never had. The same writers as `decklight skills`, so a refresh
466
+ * from the prompt and one from the command cannot differ. Returns the lines
467
+ * the command would print, one per file written.
468
+ */
469
+ export function refreshSkills(stale, { dir = '.', env = process.env } = {}) {
470
+ const written = [];
471
+ const root = path.resolve(dir);
472
+ const project = stale.filter((s) => s.scope === 'project');
473
+ if (project.some((s) => s.target === 'claude')) {
474
+ installClaudeSkill(path.join(root, '.claude', 'skills', 'decklight'), false, written);
475
+ installReportBugSkill(path.join(root, '.claude', 'skills'), false, written);
476
+ }
477
+ if (project.some((s) => s.target === 'agents')) {
478
+ const hasClaude = fs.existsSync(path.join(root, CLAUDE_REF));
479
+ if (!hasClaude) written.push(wrote(writeIfAbsent(path.join(root, SHARED_REF), referenceDoc(), false)));
480
+ written.push(mergeAgentsMd(root, hasClaude ? CLAUDE_REF : SHARED_REF));
481
+ }
482
+ const globals = [...new Set(stale.filter((s) => s.scope === 'global').map((s) => s.target))];
483
+ if (globals.length) written.push(...installGlobal(Object.keys(TARGETS).filter((k) => globals.includes(k)), env, false));
484
+ return written.filter(Boolean);
220
485
  }
221
486
 
222
487
  /**
@@ -233,6 +498,68 @@ export function installGlobalSkill(targets, { env = process.env, force = false,
233
498
  for (const w of written) out.write(` ${w}\n`);
234
499
  }
235
500
 
501
+ // --- before an agent job: is Decklight's skill where this agent reads it? ----
502
+
503
+ /**
504
+ * Where Decklight's own skill reaches the agent `key` (an agents.mjs name),
505
+ * its config home's before the project's under `dir`: `{ scope, file }`, or
506
+ * null when it reaches it from neither. An agent decklight has no install
507
+ * for (not in TARGETS) is never offered one, so it reads as having it.
508
+ */
509
+ export function placedDecklightSkill(key, { dir = '.', env = process.env } = {}) {
510
+ const t = TARGETS[key];
511
+ if (!t) return { scope: 'none', file: null };
512
+ const at = (file) => {
513
+ if (!fs.existsSync(file)) return false;
514
+ if (t.kind === 'skill') return true;
515
+ try { return fs.readFileSync(file, 'utf8').includes(AGENTS_MARKER); } catch { return false; }
516
+ };
517
+ const global = t.kind === 'skill' ? path.join(t.home(env), 'skills', 'decklight', 'SKILL.md') : path.join(t.home(env), 'AGENTS.md');
518
+ if (at(global)) return { scope: 'global', file: global };
519
+ const root = path.resolve(dir);
520
+ const project = t.kind === 'skill' ? path.join(root, '.claude', 'skills', 'decklight', 'SKILL.md') : path.join(root, 'AGENTS.md');
521
+ return at(project) ? { scope: 'project', file: project } : null;
522
+ }
523
+
524
+ /** The two places an offer of Decklight's skill to agent `key` names, as the author reads them. */
525
+ export function decklightSkillPlaces(key, { dir = '.', env = process.env } = {}) {
526
+ const t = TARGETS[key];
527
+ const root = path.resolve(dir);
528
+ return t.kind === 'skill'
529
+ ? { global: display(path.join(t.home(env), 'skills', 'decklight')), project: display(path.join(root, '.claude', 'skills', 'decklight')) }
530
+ : { global: display(path.join(t.home(env), 'AGENTS.md')), project: display(path.join(root, 'AGENTS.md')) };
531
+ }
532
+
533
+ /**
534
+ * Install Decklight's skill for agent `key`, as an offer was answered: in its
535
+ * config home (`global`, every project) or the project under `dir`. The same
536
+ * writers as `decklight skills [--global]`. Returns the lines it would print.
537
+ */
538
+ export function installDecklightSkill(key, { global = true, dir = '.', env = process.env } = {}) {
539
+ return global ? installGlobal([key], env, false) : installProject([key], dir, false);
540
+ }
541
+
542
+ // A no to that offer, remembered per project and agent: the next ask goes
543
+ // ahead without asking again, and `decklight skills` is still the way in.
544
+ const declinedFile = (env) => path.join(configHome(env), 'skill-offer-declined.json');
545
+ const readDeclined = (env) => { try { return JSON.parse(fs.readFileSync(declinedFile(env), 'utf8')); } catch { return {}; } };
546
+
547
+ /** Did the author turn down Decklight's skill for agent `key` in the project under `dir`? */
548
+ export function skillOfferDeclined(key, { dir = '.', env = process.env } = {}) {
549
+ return (readDeclined(env)[path.resolve(dir)] ?? []).includes(key);
550
+ }
551
+
552
+ /** Remember that no. */
553
+ export function declineSkillOffer(key, { dir = '.', env = process.env } = {}) {
554
+ const all = readDeclined(env);
555
+ const root = path.resolve(dir);
556
+ all[root] = [...new Set([...(all[root] ?? []), key])];
557
+ try {
558
+ fs.mkdirSync(configHome(env), { recursive: true });
559
+ fs.writeFileSync(declinedFile(env), `${JSON.stringify(all, null, 2)}\n`);
560
+ } catch { /* not remembered: asked again next time */ }
561
+ }
562
+
236
563
  /**
237
564
  * The account-level distribution artifact (#80): the same two files a project
238
565
  * install writes, in a standard archive you upload once instead of committing
@@ -251,22 +578,17 @@ export function packSkill() {
251
578
  }
252
579
 
253
580
  /**
254
- * `add`, `list` and `remove` are marketplace skills (`UNITS#REST`); every
255
- * other positional is an agent name. They share this command because they
256
- * are the same subject — a skill — and a separate `decklight skill` beside
257
- * `decklight skills` would be a footgun that reads as a typo either way.
258
- *
259
- * Unambiguous in practice: the agent roster is a closed set of nouns
260
- * (`claude`, `codex`, …) and these are verbs, so no name can be both. A
261
- * future agent called "list" would collide, and the roster is ours.
581
+ * `add`, `list` and `remove` were marketplace skills (`UNITS#REST`) and lived
582
+ * here; they are `decklight library <verb> skill` now, with every other kind
583
+ * of unit. Said by name rather than read as an agent called "add": the
584
+ * roster is a closed set of nouns and these are verbs.
262
585
  */
263
586
  const UNIT_SUBCOMMANDS = new Set(['add', 'list', 'remove']);
264
587
 
265
588
  export async function skillsMain(argv = process.argv.slice(2), { hasBin = onPath, env = process.env } = {}) {
266
589
  if (UNIT_SUBCOMMANDS.has(argv[0])) {
267
- const { unitMain } = await import('./units.mjs');
268
- const code = await unitMain('skill', argv);
269
- if (code) process.exitCode = code;
590
+ console.error(`decklight skills ${argv[0]}: marketplace skills are in your library — decklight library ${argv[0]} skill ${argv.slice(1).join(' ')}`.trimEnd());
591
+ process.exitCode = 1;
270
592
  return;
271
593
  }
272
594
  if (argv.includes('--help') || argv.includes('-h')) {
@@ -327,6 +649,11 @@ export async function skillsMain(argv = process.argv.slice(2), { hasBin = onPath
327
649
  const targets = Object.keys(TARGETS).filter((k) => selected.includes(k));
328
650
 
329
651
  const written = global ? installGlobal(targets, env, force) : installProject(targets, dir ?? '.', force);
652
+ // Every file was already this version: nothing to do, said as a refusal so a
653
+ // script that expected a write learns it did not happen — --force rewrites.
654
+ if (!written.some((w) => !/^refreshed the Decklight section/.test(w) || force)) {
655
+ fail(`the Decklight skill is already this version (${PKG.version}) — pass --force to overwrite`);
656
+ }
330
657
 
331
658
  const where = global ? 'globally' : `in ${display(path.resolve(dir ?? '.'))}`;
332
659
  process.stdout.write(
package/cli/start.mjs ADDED
@@ -0,0 +1,110 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * A bare `decklight`, on a terminal.
6
+ *
7
+ * It used to print forty commands. The person who types nothing but the
8
+ * program's name is asking "what now?", and the answer depends on where they
9
+ * are standing: a directory with no deck wants one started, a directory with
10
+ * one deck wants it opened, a directory with several wants a choice. Each is
11
+ * a question with a default, and every answer lands in a command that already
12
+ * exists — this file starts nothing of its own.
13
+ *
14
+ * Off a terminal there is nobody to ask, and the dispatcher prints the short
15
+ * help instead of ever reaching this.
16
+ */
17
+
18
+ import { createInterface } from 'node:readline/promises';
19
+ import { findDeck } from './history.mjs';
20
+ import { shortHelp } from './commands.mjs';
21
+
22
+ /** What a bare `decklight` should do here — pure over what the directory holds. */
23
+ export function planStart({ decks = [], tty = false } = {}) {
24
+ if (!tty) return { action: 'help' };
25
+ if (!decks.length) return { action: 'offer-init' };
26
+ if (decks.length === 1) return { action: 'offer-open', deck: decks[0] };
27
+ return { action: 'choose', decks };
28
+ }
29
+
30
+ /**
31
+ * Which way in an `[Enter/n/q]` answer picks. Enter is write mode — the deck
32
+ * in front of you is far more often one you are working on than one you were
33
+ * sent; `n` opens it without trust.
34
+ */
35
+ export function pickVerb(answer) {
36
+ const a = String(answer ?? '').trim().toLowerCase();
37
+ if (!a || a.startsWith('e') || a.startsWith('w') || a.startsWith('o')) return 'write';
38
+ if (a.startsWith('n')) return 'no-trust';
39
+ return null;
40
+ }
41
+
42
+ /** Which of `decks` a numbered answer names; Enter is the first, nonsense is null. */
43
+ export function pickDeck(answer, decks) {
44
+ const a = String(answer ?? '').trim();
45
+ if (!a) return decks[0] ?? null;
46
+ const n = Number(a);
47
+ if (Number.isInteger(n) && n >= 1 && n <= decks.length) return decks[n - 1];
48
+ return decks.find((d) => d === a || d.toLowerCase() === a.toLowerCase()) ?? null;
49
+ }
50
+
51
+ export async function startMain(argv = [], {
52
+ cwd = process.cwd(),
53
+ tty = Boolean(process.stdin.isTTY && process.stdout.isTTY),
54
+ out = process.stdout,
55
+ ask = null,
56
+ run = {},
57
+ } = {}) {
58
+ if (argv.includes('--help') || argv.includes('-h')) {
59
+ out.write(shortHelp());
60
+ return 0;
61
+ }
62
+ const plan = planStart({ decks: findDeck(cwd).decks, tty });
63
+ if (plan.action === 'help') { out.write(shortHelp()); return 0; }
64
+
65
+ // one readline for every question; EOF anywhere is "no", never a hang
66
+ const rl = ask ? null : createInterface({ input: process.stdin, output: process.stdout });
67
+ let gone = false;
68
+ rl?.once('close', () => { gone = true; });
69
+ const question = async (q) => {
70
+ if (ask) return String(await ask(q) ?? '');
71
+ if (gone) return null;
72
+ return new Promise((res) => {
73
+ rl.once('close', () => res(null));
74
+ rl.question(q).then(res, () => res(null));
75
+ });
76
+ };
77
+ const yes = (a, dflt = true) => (a === null ? false : !a.trim() ? dflt : /^y/i.test(a.trim()));
78
+ const launch = {
79
+ init: run.init ?? (async (args) => (await import('./init.mjs')).initMain(args)),
80
+ write: run.write ?? (async (args) => (await import('./open.mjs')).openMain(args)),
81
+ 'no-trust': run['no-trust'] ?? (async (args) => (await import('./open.mjs')).openMain(args)),
82
+ };
83
+
84
+ try {
85
+ if (plan.action === 'offer-init') {
86
+ const a = await question('no decklight deck in this directory — start one here? [Y/n] ');
87
+ if (!yes(a)) { out.write(`\n${shortHelp()}`); return 0; }
88
+ rl?.close();
89
+ return (await launch.init([])) ?? 0;
90
+ }
91
+
92
+ let deck = plan.deck;
93
+ if (plan.action === 'choose') {
94
+ out.write(`${plan.decks.length} decks here:\n`);
95
+ plan.decks.forEach((d, i) => out.write(` ${i + 1}) ${d}\n`));
96
+ const a = await question(`which one? [1] `);
97
+ deck = a === null ? null : pickDeck(a, plan.decks);
98
+ if (!deck) { out.write('nothing opened\n'); return 0; }
99
+ } else {
100
+ out.write(`found ${deck}\n`);
101
+ }
102
+ const a = await question(' open it — live reload, edits from the browser, an AI agent on A n) without trust — its code stripped, nothing changes it\n [Enter/n/q] ');
103
+ const verb = a === null ? null : pickVerb(a);
104
+ if (!verb) { out.write('nothing opened\n'); return 0; }
105
+ rl?.close();
106
+ return (await launch[verb](verb === 'write' ? [deck, '--open'] : [deck, '--no-trust'])) ?? 0;
107
+ } finally {
108
+ rl?.close();
109
+ }
110
+ }
package/cli/supervise.mjs CHANGED
@@ -4,22 +4,22 @@
4
4
  /**
5
5
  * Outliving your parent is the one way a decklight server leaks.
6
6
  *
7
- * `author` runs the deck server and the bridges as child processes and reaps
7
+ * `open` runs the deck server and the bridges as child processes and reaps
8
8
  * them on its way out — but only for the signals it can catch. SIGKILL it (a
9
- * test harness, the OOM killer, an impatient `kill -9`) and author vanishes
9
+ * test harness, the OOM killer, an impatient `kill -9`) and `open` vanishes
10
10
  * with no chance to pass the signal on: the servers are reparented to init and
11
- * go on holding their ports, and the next `decklight author` finds a port
11
+ * go on holding their ports, and the next `decklight <deck>` finds a port
12
12
  * taken by something nobody remembers starting.
13
13
  *
14
- * The fix is a channel the OS closes for us. author opens a pipe to each
14
+ * The fix is a channel the OS closes for us. `open` opens a pipe to each
15
15
  * child's stdin and never writes a byte to it; the child reads it and exits at
16
- * EOF. However author dies, the write end dies with it and every child hears
16
+ * EOF. However `open` dies, the write end dies with it and every child hears
17
17
  * about it at once — no polling, no pid to watch, no signal to catch, and
18
18
  * nothing for a dying parent to remember to do.
19
19
  *
20
20
  * Opt-in, because stdin means something else to a server you started
21
21
  * yourself: `node cli/edit.mjs deck.html < /dev/null` would EOF immediately,
22
- * and a terminal never EOFs at all. author sets LEASH in the child's
22
+ * and a terminal never EOFs at all. `open` sets LEASH in the child's
23
23
  * environment; only then does anything here read stdin.
24
24
  */
25
25