decklight 0.2.0 → 0.3.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 (137) hide show
  1. package/README.md +69 -31
  2. package/SPEC.md +855 -80
  3. package/cli/agents.mjs +113 -9
  4. package/cli/associate.mjs +279 -0
  5. package/cli/audit.mjs +424 -0
  6. package/cli/bundle.mjs +174 -46
  7. package/cli/deckfile.mjs +233 -0
  8. package/cli/decklight.mjs +201 -8
  9. package/cli/dev.mjs +244 -55
  10. package/cli/edit.mjs +564 -107
  11. package/cli/extension.mjs +108 -0
  12. package/cli/git.mjs +141 -0
  13. package/cli/import.mjs +398 -0
  14. package/cli/init.mjs +421 -116
  15. package/cli/loader.mjs +263 -0
  16. package/cli/marketplace.mjs +730 -0
  17. package/cli/pdf.mjs +156 -0
  18. package/cli/pkg.mjs +69 -0
  19. package/cli/plugin.mjs +646 -0
  20. package/cli/port-conflict.mjs +94 -0
  21. package/cli/present.mjs +560 -0
  22. package/cli/publish.mjs +342 -0
  23. package/cli/qr.mjs +334 -0
  24. package/cli/rec.mjs +5 -8
  25. package/cli/remote.mjs +149 -0
  26. package/cli/report-bug.mjs +97 -0
  27. package/cli/restore.mjs +174 -0
  28. package/cli/serve.mjs +247 -0
  29. package/cli/sign.mjs +216 -0
  30. package/cli/skill-content.mjs +222 -0
  31. package/cli/skills.mjs +338 -0
  32. package/cli/supervise.mjs +57 -0
  33. package/cli/theme.mjs +201 -0
  34. package/cli/units.mjs +488 -0
  35. package/cli/upgrade.mjs +250 -0
  36. package/cli/util.mjs +90 -0
  37. package/cli/wizard.mjs +432 -0
  38. package/cli/zip.mjs +121 -0
  39. package/dist/decklight.css +716 -29
  40. package/dist/decklight.js +198 -125
  41. package/dist/decklight.js.map +4 -4
  42. package/docs/architecture.svg +1 -1
  43. package/package.json +5 -4
  44. package/themes/README.md +6 -4
  45. package/themes/aurora.css +1 -1
  46. package/themes/berry.css +1 -1
  47. package/themes/carbon.css +1 -1
  48. package/themes/citrus.css +1 -1
  49. package/themes/coastal.css +1 -1
  50. package/themes/cosmos.css +1 -1
  51. package/themes/dune.css +1 -1
  52. package/themes/eclipse.css +1 -1
  53. package/themes/ember.css +1 -1
  54. package/themes/fjord.css +1 -1
  55. package/themes/gallery.html +3 -11
  56. package/themes/glacier.css +1 -1
  57. package/themes/graphite.css +1 -1
  58. package/themes/harvest.css +1 -1
  59. package/themes/ibm-modern.css +1 -1
  60. package/themes/ink.css +1 -1
  61. package/themes/latte.css +1 -1
  62. package/themes/linen.css +1 -1
  63. package/themes/meadow.css +1 -1
  64. package/themes/metropolis.css +1 -1
  65. package/themes/midnight.css +1 -1
  66. package/themes/mint.css +1 -1
  67. package/themes/moss.css +1 -1
  68. package/themes/obsidian.css +1 -1
  69. package/themes/orchid.css +1 -1
  70. package/themes/packs.json +2 -30
  71. package/themes/paper.css +1 -1
  72. package/themes/peony.css +1 -1
  73. package/themes/porcelain.css +1 -1
  74. package/themes/reveal-beige.css +1 -1
  75. package/themes/reveal-black.css +1 -1
  76. package/themes/reveal-blood.css +1 -1
  77. package/themes/reveal-dracula.css +1 -1
  78. package/themes/reveal-league.css +1 -1
  79. package/themes/reveal-moon.css +1 -1
  80. package/themes/reveal-night.css +1 -1
  81. package/themes/reveal-serif.css +1 -1
  82. package/themes/reveal-simple.css +1 -1
  83. package/themes/reveal-sky.css +1 -1
  84. package/themes/reveal-solarized.css +1 -1
  85. package/themes/reveal-white.css +1 -1
  86. package/themes/sepia.css +1 -1
  87. package/themes/seriph.css +1 -1
  88. package/themes/slate.css +1 -1
  89. package/themes/storm.css +1 -1
  90. package/themes/synthwave.css +1 -1
  91. package/themes/velvet.css +1 -1
  92. package/themes/yamabuki.css +1 -1
  93. package/tools/args.mjs +32 -0
  94. package/tools/bridge.mjs +30 -0
  95. package/tools/chrome.mjs +11 -2
  96. package/tools/color.mjs +110 -0
  97. package/tools/deck-html.mjs +138 -0
  98. package/tools/elevenlabs-tts.mjs +248 -0
  99. package/tools/escape.mjs +40 -0
  100. package/tools/extension-check-runner.mjs +41 -0
  101. package/tools/extension-check.mjs +266 -0
  102. package/tools/gemini-tts.mjs +25 -3
  103. package/tools/lipsync-engines.mjs +81 -0
  104. package/tools/lipsync-server.mjs +78 -37
  105. package/tools/lipsync.mjs +36 -21
  106. package/tools/local-voice.mjs +209 -0
  107. package/tools/ooxml.mjs +151 -0
  108. package/tools/pptx.mjs +320 -0
  109. package/tools/publish-site-voices.mjs +2 -1
  110. package/tools/publish-targets.mjs +143 -0
  111. package/tools/publish-voices.mjs +230 -0
  112. package/tools/shot.mjs +91 -47
  113. package/tools/theme-check.mjs +139 -0
  114. package/tools/tts-engines.mjs +270 -41
  115. package/tools/tts-setup.mjs +257 -0
  116. package/tools/veo.mjs +204 -0
  117. package/tools/video.mjs +316 -0
  118. package/tools/voiceover-server.mjs +163 -54
  119. package/tools/voiceover.mjs +24 -7
  120. package/tools/zip.mjs +143 -0
  121. package/docs/demo.svg +0 -124
  122. package/themes/aliens.css +0 -87
  123. package/themes/apple2.css +0 -129
  124. package/themes/blade-runner.css +0 -86
  125. package/themes/c64.css +0 -88
  126. package/themes/friends.css +0 -85
  127. package/themes/gameboy.css +0 -121
  128. package/themes/genesis.css +0 -87
  129. package/themes/godfather.css +0 -85
  130. package/themes/ibm-oldschool.css +0 -87
  131. package/themes/miami-vice.css +0 -87
  132. package/themes/pulp-fiction.css +0 -87
  133. package/themes/severance.css +0 -85
  134. package/themes/snes.css +0 -85
  135. package/themes/star-wars.css +0 -88
  136. package/themes/stranger-things.css +0 -87
  137. package/themes/terminator.css +0 -87
package/cli/agents.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright 2026 Gilles Philippart
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- // The AI-agent roster for `decklight dev` — which coding agents this machine
4
+ // The AI-agent roster for `decklight author` — which coding agents this machine
5
5
  // can run, and how to hand one a single editing task without a TTY.
6
6
  //
7
7
  // Every entry is a one-shot, non-interactive invocation: the agent gets the
@@ -14,8 +14,17 @@
14
14
  // of its headless mode). Order is preference order — the first detected
15
15
  // agent is the default when the player doesn't name one.
16
16
 
17
- import { existsSync } from 'node:fs';
18
- import { delimiter, join } from 'node:path';
17
+ // The roster is EXTENSIBLE the same way (SPEC AGENT_UNITS): an agent unit is a
18
+ // reference — a JSON descriptor naming a binary you already installed and the
19
+ // argv of its headless mode — never code decklight downloads and runs. That is
20
+ // what keeps this list open without putting it in UNIT_PINNING's risk class:
21
+ // the three shapes below (`-p …`, `exec --full-auto …`, `run -t …`) are a
22
+ // small, closed vocabulary, and a template expresses all of them.
23
+
24
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
25
+ import { delimiter, dirname, join } from 'node:path';
26
+ import { configHome } from './marketplace.mjs';
27
+ import { listUnits } from './units.mjs';
19
28
 
20
29
  export const AGENTS = [
21
30
  {
@@ -68,6 +77,46 @@ export const AGENTS = [
68
77
  },
69
78
  ];
70
79
 
80
+ /**
81
+ * Fill an installed agent's argv template (SPEC `AGENT_UNITS`).
82
+ *
83
+ * The whole vocabulary: `{prompt}` and `{deck}`, each substituted into ONE
84
+ * argv element. Never a shell string — the result is spawned as an argv
85
+ * array, so an agent name or a deck path containing a space, a quote or a
86
+ * semicolon is an argument and can never become a command.
87
+ */
88
+ export function expandArgs(template, prompt, deck) {
89
+ return template.map((a) => String(a)
90
+ .replaceAll('{prompt}', prompt)
91
+ .replaceAll('{deck}', deck ?? ''));
92
+ }
93
+
94
+ /**
95
+ * Agents installed as units, as roster entries shaped like the built-ins.
96
+ *
97
+ * Read from the library, never the network — the same offline guarantee every
98
+ * other `findUnit`/`listUnits` lookup keeps. An installed descriptor that is
99
+ * malformed is SKIPPED rather than thrown on: a broken third-party entry must
100
+ * not take `A` down for the built-in agents beside it.
101
+ */
102
+ export function installedAgents(home = configHome()) {
103
+ const out = [];
104
+ for (const unit of listUnits('agent', home)) {
105
+ try {
106
+ const d = JSON.parse(readFileSync(unit.path, 'utf8'));
107
+ if (typeof d.bin !== 'string' || !Array.isArray(d.args)) continue;
108
+ out.push({
109
+ name: unit.name,
110
+ label: typeof d.label === 'string' && d.label ? d.label : unit.name,
111
+ bin: d.bin,
112
+ installed: true,
113
+ args: (prompt, deck) => expandArgs(d.args, prompt, deck),
114
+ });
115
+ } catch { /* a descriptor we cannot read is one agent, not the roster */ }
116
+ }
117
+ return out;
118
+ }
119
+
71
120
  /** Is `bin` runnable — an explicit path that exists, or a name on $PATH? */
72
121
  export function onPath(bin, env = process.env) {
73
122
  if (!bin) return false;
@@ -80,9 +129,58 @@ export function onPath(bin, env = process.env) {
80
129
  return false;
81
130
  }
82
131
 
83
- /** The subset of AGENTS this machine can actually run, in preference order. */
84
- export function detectAgents({ env = process.env, hasBin = onPath } = {}) {
85
- return AGENTS.filter((a) => hasBin(a.bin, env));
132
+ /**
133
+ * Every agent this machine can actually run, in preference order.
134
+ *
135
+ * Built-ins first, then installed units (SPEC `AGENT_UNITS`) — a unit whose
136
+ * name collides with a built-in is dropped rather than shadowing it, because
137
+ * silently replacing how `claude` is invoked is not something a catalog
138
+ * should be able to do to a machine.
139
+ */
140
+ export function detectAgents({ env = process.env, hasBin = onPath, home } = {}) {
141
+ const builtIn = AGENTS.filter((a) => hasBin(a.bin, env));
142
+ const known = new Set(AGENTS.map((a) => a.name));
143
+ const extra = installedAgents(home).filter((a) => !known.has(a.name) && hasBin(a.bin, env));
144
+ return [...builtIn, ...extra];
145
+ }
146
+
147
+ // ── the remembered preference (#125) ───────────────────────────────────────
148
+
149
+ /** Where the preferred agent is remembered — beside the unit library. */
150
+ export const agentConfigPath = (home = configHome()) => join(home, 'agent.json');
151
+
152
+ /** The remembered agent's name, or null. A missing file is first-run. */
153
+ export function preferredAgent(home = configHome()) {
154
+ try {
155
+ const saved = JSON.parse(readFileSync(agentConfigPath(home), 'utf8'));
156
+ return typeof saved?.preferred === 'string' ? saved.preferred : null;
157
+ } catch { return null; }
158
+ }
159
+
160
+ /** Remember `name` as the agent `A` reaches for; `null` forgets it. */
161
+ export function setPreferredAgent(name, home = configHome()) {
162
+ const file = agentConfigPath(home);
163
+ mkdirSync(dirname(file), { recursive: true });
164
+ writeFileSync(file, `${JSON.stringify({ preferred: name ?? null }, null, 2)}\n`);
165
+ return file;
166
+ }
167
+
168
+ /**
169
+ * Why `name` cannot be run, as a line naming the way out (#125).
170
+ *
171
+ * Never a silent fallback to a different agent: which agent edits your deck
172
+ * is not a substitutable detail, and one that quietly changed under a
173
+ * remembered preference would be the worst version of this feature.
174
+ */
175
+ export function agentUnavailable(name, roster, home = configHome()) {
176
+ const have = roster.length
177
+ ? `available here: ${roster.map((a) => a.name).join(', ')}`
178
+ : 'no agent CLI is detected on this machine';
179
+ if (!name) return `${have} — install one (claude, codex, bob, …), or: decklight agent add <name>`;
180
+ const known = AGENTS.some((a) => a.name === name) || installedAgents(home).some((a) => a.name === name);
181
+ return known
182
+ ? `"${name}" is known but its command is not on PATH — install it, or pick another (${have})`
183
+ : `no agent named "${name}" — ${have}; a marketplace can teach decklight a new one: decklight agent add ${name}`;
86
184
  }
87
185
 
88
186
  /**
@@ -91,9 +189,15 @@ export function detectAgents({ env = process.env, hasBin = onPath } = {}) {
91
189
  * file it should edit. Returns { bin, args, label } or null when the agent
92
190
  * isn't available.
93
191
  */
94
- export function agentCommand(name, instruction, deck, { env = process.env, hasBin = onPath } = {}) {
95
- const roster = detectAgents({ env, hasBin });
96
- const agent = name ? roster.find((a) => a.name === name) : roster[0];
192
+ export function agentCommand(name, instruction, deck, { env = process.env, hasBin = onPath, home } = {}) {
193
+ const roster = detectAgents({ env, hasBin, home });
194
+ // Precedence, matching how every other saved choice resolves (PRESENTING):
195
+ // an explicit name > the remembered preference > the first detected agent.
196
+ // A remembered agent that is NOT available falls through to null rather
197
+ // than to roster[0] — `agentUnavailable` then says which one is missing,
198
+ // because a different agent silently editing your deck is worse than none.
199
+ const wanted = name ?? preferredAgent(home);
200
+ const agent = wanted ? roster.find((a) => a.name === wanted) : roster[0];
97
201
  if (!agent) return null;
98
202
  const prompt = `Edit the Decklight deck file "${deck}" — a single-file HTML presentation ` +
99
203
  '(one top-level <section> per slide; see SPEC.md or the decklight skill if present). ' +
@@ -0,0 +1,279 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026 Gilles Philippart
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * `decklight associate` — make a double-clicked `.decklight` open in `present`
7
+ * (MARKETPLACE.md DECK_FILE#ASSOC).
8
+ *
9
+ * Without this, the container's whole point leaks away: the person who receives
10
+ * a deck double-clicks it, the OS has no idea what it is, and they end up
11
+ * either renaming it to `.html` (which works — the container degrades on
12
+ * purpose — but skips every check) or looking at a download dialog. The file
13
+ * association is what makes `present` the default way in rather than the way in
14
+ * for people who already read the docs.
15
+ *
16
+ * Three platforms, three unrelated mechanisms, and the honest summary is that
17
+ * they are the fiddly part of this feature:
18
+ *
19
+ * - **Linux** — a `.desktop` entry plus a shared-MIME-info XML declaring
20
+ * `application/vnd.decklight`, both under `~/.local/share`, then the two
21
+ * database refreshers if they exist. Fully wired here.
22
+ * - **macOS** — a UTI has to be *exported by an application bundle*; there is
23
+ * no per-user "declare a type" file. So a minimal `Decklight.app` is written
24
+ * (a directory with an `Info.plist` and a shell launcher) whose plist exports
25
+ * `io.decklight.deck` and claims the extension. `lsregister` is asked to
26
+ * notice it.
27
+ * - **Windows** — `reg add` under `HKCU\\Software\\Classes`, which needs no
28
+ * administrator and is what per-user file associations actually are.
29
+ *
30
+ * Every writer prints the paths it touched, and `--uninstall` removes exactly
31
+ * those. Nothing is written outside the user's own home.
32
+ */
33
+
34
+ import { writeFileSync, mkdirSync, rmSync, existsSync, chmodSync } from 'node:fs';
35
+ import { execFileSync } from 'node:child_process';
36
+ import { homedir, platform } from 'node:os';
37
+ import path from 'node:path';
38
+ import { fileURLToPath } from 'node:url';
39
+ import { isMain } from '../tools/args.mjs';
40
+ import { DECK_EXT } from './deckfile.mjs';
41
+
42
+ export const MIME_TYPE = 'application/vnd.decklight';
43
+ export const UTI = 'io.decklight.deck';
44
+
45
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
46
+ const CLI = path.join(HERE, 'decklight.mjs');
47
+
48
+ const USAGE = `usage: decklight associate [--uninstall] [--print]
49
+
50
+ wires a double-clicked ${DECK_EXT} file to \`decklight present\`, so a deck
51
+ someone sent you opens verified instead of raw in a browser.
52
+
53
+ --uninstall remove what this command installed
54
+ --print show what would be written, and where; write nothing
55
+
56
+ Per-user only: everything lands under your home directory and no step needs
57
+ administrator rights. What gets written depends on the platform —
58
+ linux ~/.local/share/applications/decklight.desktop
59
+ ~/.local/share/mime/packages/decklight.xml
60
+ darwin ~/Applications/Decklight.app (a minimal bundle: a UTI can only be
61
+ exported by an application, so there has to be one)
62
+ win32 HKCU\\Software\\Classes\\${DECK_EXT} and \\Decklight.Deck
63
+
64
+ A ${DECK_EXT} renamed to .html still opens in a plain browser whether or not
65
+ this ran — the container degrades to the deck it wraps by design. The
66
+ association buys the verified path, not the only path.`;
67
+
68
+ // ── linux ──────────────────────────────────────────────────────────────────
69
+
70
+ /**
71
+ * The launcher runs the CLI through the same node that is running now.
72
+ * `%f` (single local file) rather than `%F`: present takes one deck, and a
73
+ * multi-select that silently presented the first would be worse than one that
74
+ * opens two windows.
75
+ */
76
+ export function linuxFiles(home = homedir(), node = process.execPath, cli = CLI) {
77
+ return [
78
+ {
79
+ path: path.join(home, '.local/share/applications/decklight.desktop'),
80
+ text: `[Desktop Entry]
81
+ Type=Application
82
+ Name=Decklight
83
+ Comment=Play a Decklight deck, verified and read-only
84
+ Exec=${node} ${cli} present %f
85
+ Terminal=true
86
+ NoDisplay=true
87
+ MimeType=${MIME_TYPE};
88
+ Categories=Office;Presentation;
89
+ `,
90
+ },
91
+ {
92
+ path: path.join(home, '.local/share/mime/packages/decklight.xml'),
93
+ text: `<?xml version="1.0" encoding="UTF-8"?>
94
+ <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
95
+ <mime-type type="${MIME_TYPE}">
96
+ <comment>Decklight presentation</comment>
97
+ <glob pattern="*${DECK_EXT}"/>
98
+ <!-- The payload is HTML, so a magic match would collide with text/html;
99
+ the extension is the only unambiguous signal a container has. -->
100
+ <sub-class-of type="text/html"/>
101
+ </mime-type>
102
+ </mime-info>
103
+ `,
104
+ },
105
+ ];
106
+ }
107
+
108
+ // ── macOS ──────────────────────────────────────────────────────────────────
109
+
110
+ export function darwinFiles(home = homedir(), node = process.execPath, cli = CLI) {
111
+ const app = path.join(home, 'Applications/Decklight.app');
112
+ return [
113
+ {
114
+ path: path.join(app, 'Contents/Info.plist'),
115
+ text: `<?xml version="1.0" encoding="UTF-8"?>
116
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
117
+ <plist version="1.0">
118
+ <dict>
119
+ <key>CFBundleIdentifier</key><string>${UTI}.app</string>
120
+ <key>CFBundleName</key><string>Decklight</string>
121
+ <key>CFBundleExecutable</key><string>decklight</string>
122
+ <key>CFBundlePackageType</key><string>APPL</string>
123
+ <key>LSMinimumSystemVersion</key><string>10.13</string>
124
+ <key>UTExportedTypeDeclarations</key>
125
+ <array><dict>
126
+ <key>UTTypeIdentifier</key><string>${UTI}</string>
127
+ <key>UTTypeDescription</key><string>Decklight presentation</string>
128
+ <key>UTTypeConformsTo</key><array><string>public.html</string></array>
129
+ <key>UTTypeTagSpecification</key>
130
+ <dict>
131
+ <key>public.filename-extension</key><array><string>${DECK_EXT.slice(1)}</string></array>
132
+ <key>public.mime-type</key><array><string>${MIME_TYPE}</string></array>
133
+ </dict>
134
+ </dict></array>
135
+ <key>CFBundleDocumentTypes</key>
136
+ <array><dict>
137
+ <key>CFBundleTypeName</key><string>Decklight presentation</string>
138
+ <key>CFBundleTypeRole</key><string>Viewer</string>
139
+ <key>LSHandlerRank</key><string>Owner</string>
140
+ <key>LSItemContentTypes</key><array><string>${UTI}</string></array>
141
+ </dict></array>
142
+ </dict>
143
+ </plist>
144
+ `,
145
+ },
146
+ {
147
+ path: path.join(app, 'Contents/MacOS/decklight'),
148
+ mode: 0o755,
149
+ // Through Terminal, because present is a server that prints the label and
150
+ // then keeps running: launching it with no visible output would leave
151
+ // someone staring at a bouncing icon while the thing they need to read
152
+ // scrolls past in a log nobody opens.
153
+ //
154
+ // The deck path is the filename of a file someone *sent*, and this
155
+ // script runs before `present` checks a byte — so it must never be
156
+ // spliced into the `do script` text, where a quote in the name becomes
157
+ // shell. It rides as an osascript argument the whole way and is quoted
158
+ // by AppleScript's `quoted form of` at the last moment. The install
159
+ // paths are ours, baked as AppleScript string literals via
160
+ // JSON.stringify, the same escaping the Keynote import script uses.
161
+ text: `#!/bin/sh
162
+ # Generated by \`decklight associate\`. Opens the double-clicked deck in
163
+ # \`decklight present\`, in a Terminal window so its output is readable.
164
+ # The deck path stays an argument the whole way down (Finder → $1 →
165
+ # osascript argv → quoted form of): a filename is data, never code.
166
+ deck="$1"
167
+ [ -n "$deck" ] || exit 0
168
+ dir=$(dirname "$deck")
169
+ osascript - "$dir" "$deck" <<'DECKLIGHT_LAUNCH'
170
+ on run argv
171
+ set cmd to "cd " & quoted form of item 1 of argv & " && " & quoted form of ${JSON.stringify(node)} & " " & quoted form of ${JSON.stringify(cli)} & " present " & quoted form of item 2 of argv
172
+ tell application "Terminal" to do script cmd
173
+ tell application "Terminal" to activate
174
+ end run
175
+ DECKLIGHT_LAUNCH
176
+ `,
177
+ },
178
+ ];
179
+ }
180
+
181
+ // ── windows ────────────────────────────────────────────────────────────────
182
+
183
+ /** The registry writes, as argv arrays — printable, and testable without a registry. */
184
+ export function windowsCommands(node = process.execPath, cli = CLI) {
185
+ const key = 'HKCU\\Software\\Classes';
186
+ return [
187
+ ['reg', 'add', `${key}\\${DECK_EXT}`, '/ve', '/d', 'Decklight.Deck', '/f'],
188
+ ['reg', 'add', `${key}\\${DECK_EXT}`, '/v', 'Content Type', '/d', MIME_TYPE, '/f'],
189
+ ['reg', 'add', `${key}\\Decklight.Deck`, '/ve', '/d', 'Decklight presentation', '/f'],
190
+ ['reg', 'add', `${key}\\Decklight.Deck\\shell\\open\\command`, '/ve', '/d',
191
+ `"${node}" "${cli}" present "%1"`, '/f'],
192
+ ];
193
+ }
194
+
195
+ const windowsUninstall = () => [
196
+ ['reg', 'delete', `HKCU\\Software\\Classes\\${DECK_EXT}`, '/f'],
197
+ ['reg', 'delete', 'HKCU\\Software\\Classes\\Decklight.Deck', '/f'],
198
+ ];
199
+
200
+ // ── the command ────────────────────────────────────────────────────────────
201
+
202
+ /** Refresh a desktop database if the tool is there; never fail over its absence. */
203
+ function refresh(argv) {
204
+ try { execFileSync(argv[0], argv.slice(1), { stdio: 'ignore' }); return true; }
205
+ catch { return false; }
206
+ }
207
+
208
+ export function planFor(os = platform()) {
209
+ if (os === 'linux') return { files: linuxFiles(), commands: [], os };
210
+ if (os === 'darwin') return { files: darwinFiles(), commands: [], os };
211
+ if (os === 'win32') return { files: [], commands: windowsCommands(), os };
212
+ return { files: [], commands: [], os, unsupported: true };
213
+ }
214
+
215
+ export async function associateMain(args = process.argv.slice(2)) {
216
+ if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
217
+ const uninstall = args.includes('--uninstall');
218
+ const dryRun = args.includes('--print');
219
+ const plan = planFor();
220
+
221
+ if (plan.unsupported) {
222
+ console.error(`decklight associate: no file-association mechanism is wired for ${plan.os}`);
223
+ return 1;
224
+ }
225
+
226
+ if (dryRun) {
227
+ for (const f of plan.files) console.log(`would write ${f.path}`);
228
+ for (const c of plan.commands) console.log(`would run ${c.join(' ')}`);
229
+ return 0;
230
+ }
231
+
232
+ if (uninstall) {
233
+ for (const f of plan.files) {
234
+ // The macOS bundle is a directory this command created wholesale, so it
235
+ // goes wholesale; the two Linux files go individually.
236
+ const target = f.path.includes('Decklight.app') ? f.path.replace(/(Decklight\.app).*/, '$1') : f.path;
237
+ if (existsSync(target)) { rmSync(target, { recursive: true, force: true }); console.log(`removed ${target}`); }
238
+ }
239
+ for (const c of (plan.os === 'win32' ? windowsUninstall() : [])) refresh(c);
240
+ if (plan.os === 'linux') {
241
+ refresh(['update-mime-database', path.join(homedir(), '.local/share/mime')]);
242
+ refresh(['update-desktop-database', path.join(homedir(), '.local/share/applications')]);
243
+ }
244
+ console.log('the association is gone; a .decklight is an unknown file again');
245
+ return 0;
246
+ }
247
+
248
+ for (const f of plan.files) {
249
+ mkdirSync(path.dirname(f.path), { recursive: true });
250
+ writeFileSync(f.path, f.text);
251
+ if (f.mode) chmodSync(f.path, f.mode);
252
+ console.log(`wrote ${f.path}`);
253
+ }
254
+ for (const c of plan.commands) {
255
+ if (!refresh(c)) { console.error(`failed: ${c.join(' ')}`); return 1; }
256
+ console.log(`ran ${c.join(' ')}`);
257
+ }
258
+
259
+ if (plan.os === 'linux') {
260
+ const mime = refresh(['update-mime-database', path.join(homedir(), '.local/share/mime')]);
261
+ const desk = refresh(['update-desktop-database', path.join(homedir(), '.local/share/applications')]);
262
+ // Said plainly rather than swallowed: the files are correct either way, but
263
+ // without the refresh the desktop will not notice them until it is
264
+ // restarted, and a silent no-op here reads as a broken feature.
265
+ if (!mime || !desk) {
266
+ console.log('note: update-mime-database/update-desktop-database not found — the files are in place, '
267
+ + 'but your desktop may not pick them up until it restarts');
268
+ }
269
+ }
270
+ if (plan.os === 'darwin') {
271
+ refresh(['/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister',
272
+ '-f', path.join(homedir(), 'Applications/Decklight.app')]);
273
+ }
274
+
275
+ console.log(`double-clicking a ${DECK_EXT} now opens: decklight present`);
276
+ return 0;
277
+ }
278
+
279
+ if (isMain(import.meta.url)) process.exitCode = await associateMain();