decklight 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -9
- package/SPEC.md +239 -17
- package/cli/agents.mjs +97 -2
- package/cli/banner.mjs +125 -0
- package/cli/bundle.mjs +14 -4
- package/cli/{rec.mjs → cast.mjs} +25 -8
- package/cli/comments.mjs +389 -0
- package/cli/commit-flow.mjs +157 -0
- package/cli/commit-message.mjs +475 -0
- package/cli/decklight.mjs +95 -25
- package/cli/dev.mjs +193 -25
- package/cli/edit.mjs +1055 -39
- package/cli/git-tree.mjs +87 -0
- package/cli/git.mjs +370 -0
- package/cli/history.mjs +145 -0
- package/cli/init.mjs +199 -7
- package/cli/marketplace.mjs +123 -17
- package/cli/port-conflict.mjs +228 -22
- package/cli/present.mjs +297 -12
- package/cli/publish.mjs +15 -40
- package/cli/record.mjs +154 -0
- package/cli/restore.mjs +120 -4
- package/cli/review-remote.mjs +330 -0
- package/cli/review-store.mjs +107 -0
- package/cli/review-submit.mjs +292 -0
- package/cli/review.mjs +361 -0
- package/cli/serve.mjs +60 -1
- package/cli/skill-content.mjs +12 -1
- package/cli/theme.mjs +78 -11
- package/cli/units.mjs +2 -2
- package/cli/upstream.mjs +256 -0
- package/cli/util.mjs +59 -0
- package/dist/build-info.json +1 -0
- package/dist/decklight.css +534 -3
- package/dist/decklight.js +102 -76
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +7 -0
- package/package.json +2 -1
- package/tools/args.mjs +20 -0
- package/tools/deck-html.mjs +84 -0
- package/tools/elevenlabs-tts.mjs +1 -1
- package/tools/lipsync-server.mjs +64 -2
- package/tools/lipsync.mjs +40 -24
- package/tools/local-voice.mjs +170 -16
- package/tools/publish-voices.mjs +78 -18
- package/tools/recording-impact.mjs +110 -0
- package/tools/review-anchor.mjs +180 -0
- package/tools/test-impact.mjs +259 -0
- package/tools/tts-engines.mjs +211 -12
- package/tools/tts-setup.mjs +2 -9
- package/tools/video.mjs +56 -12
- package/tools/voiceover-server.mjs +262 -11
- package/tools/voiceover.mjs +32 -13
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Gilles Philippart
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `npm run test:impact` — which tests does THIS change actually need?
|
|
7
|
+
*
|
|
8
|
+
* The suites are not the same shape, and the honest answer differs per suite.
|
|
9
|
+
* Measured on a laptop (2026-08-27, 85 unit files / 19 harnesses):
|
|
10
|
+
*
|
|
11
|
+
* unit `npm test` ~48s wall — 319s of work, run in parallel by node
|
|
12
|
+
* render `npm run verify` ~200s wall — strictly serial, one browser at a time
|
|
13
|
+
*
|
|
14
|
+
* So this script does NOT try to pick unit tests. 38 of the 85 files finish
|
|
15
|
+
* under 0.3s and node already overlaps them 6.6×; selecting a subset would save
|
|
16
|
+
* seconds and risk missing the one file that mattered. The unit suite is cheap
|
|
17
|
+
* enough to always be right, and being right is what a test picker is for.
|
|
18
|
+
*
|
|
19
|
+
* The render harnesses are the opposite: serial, minutes long, and each one
|
|
20
|
+
* pinned to a subsystem you can name. `narration-render` alone is 65s — a third
|
|
21
|
+
* of the suite — and a change to `cli/pdf.mjs` has no business waiting for it.
|
|
22
|
+
* That is the decision worth automating, so that is the only one made here.
|
|
23
|
+
*
|
|
24
|
+
* THE FALLBACK IS THE WHOLE SUITE. A path this map does not recognise selects
|
|
25
|
+
* everything, loudly, and says why. A test picker that guesses "probably
|
|
26
|
+
* nothing" on an unfamiliar path is worse than no picker: it turns an unrun
|
|
27
|
+
* suite into a green line. Same rule as the ingredients label — unchecked is
|
|
28
|
+
* its own answer and never a pass.
|
|
29
|
+
*
|
|
30
|
+
* This is a DEVELOPER shortcut for the edit-run loop, not a CI gate. CI keeps
|
|
31
|
+
* running everything, because the map is a claim about the code and the map can
|
|
32
|
+
* be wrong; the full suite is what notices.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
36
|
+
import path from 'node:path';
|
|
37
|
+
import { fileURLToPath } from 'node:url';
|
|
38
|
+
import { isMain } from './args.mjs';
|
|
39
|
+
|
|
40
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
41
|
+
const repo = path.resolve(here, '..');
|
|
42
|
+
|
|
43
|
+
/** Every harness `verify` knows, in its running order. */
|
|
44
|
+
export const ALL = [
|
|
45
|
+
'render', 'player-render', 'narration-render', 'record-render', 'review-render',
|
|
46
|
+
'character-render', 'engine-render', 'pin-render', 'overflow-render', 'split-render',
|
|
47
|
+
'strict-render', 'shot-render', 'plugin-render', 'extension-check-render',
|
|
48
|
+
'deckfile-render', 'pdf-render', 'import-render', 'contrast', 'palette-rules',
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The two lint harnesses read `themes/` and `tools/`, never the built runtime —
|
|
53
|
+
* so a change to `src/` does not implicate them, and a change to a theme does.
|
|
54
|
+
* Kept as a named set because "every harness except the ones that never open a
|
|
55
|
+
* browser" is the distinction the rules below keep needing.
|
|
56
|
+
*/
|
|
57
|
+
const LINT = ['contrast', 'palette-rules'];
|
|
58
|
+
const BROWSER = ALL.filter((h) => !LINT.includes(h));
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* changed path → the harnesses that could see it.
|
|
62
|
+
*
|
|
63
|
+
* Ordered, first match wins, so the broad "this is core" rules sit at the top.
|
|
64
|
+
* Every entry carries WHY, because the cost of this file being subtly wrong is
|
|
65
|
+
* a harness that stops running and nobody noticing for a month.
|
|
66
|
+
*/
|
|
67
|
+
const RULES = [
|
|
68
|
+
// ── everything the built bundle rests on ────────────────────────────────
|
|
69
|
+
// Each browser harness loads dist/decklight.js, so these reach all of them.
|
|
70
|
+
[/^src\/core\/engine\.js$/, BROWSER, 'the engine every harness boots'],
|
|
71
|
+
[/^src\/core\/overlay\.js$/, BROWSER, 'the overlay contract every dialog registers through'],
|
|
72
|
+
[/^src\/index\.js$/, BROWSER, 'the bundle entry'],
|
|
73
|
+
[/^src\/decklight\.css$/, BROWSER, 'one stylesheet, every rendered deck'],
|
|
74
|
+
[/^build\.mjs$/, ALL, 'the build that produces what the harnesses load'],
|
|
75
|
+
[/^test\/harness\.mjs$/, ALL, 'the shared dump/assert helper'],
|
|
76
|
+
[/^package\.json$/, ALL, 'scripts, deps and packed files'],
|
|
77
|
+
|
|
78
|
+
// ── subsystems, each with a harness that is about it ────────────────────
|
|
79
|
+
[/^src\/core\/narration\.js$/, ['narration-render', 'record-render', 'character-render'],
|
|
80
|
+
'narration drives playback, the recorder and the character overlay'],
|
|
81
|
+
[/^src\/core\/character\.js$/, ['character-render', 'narration-render'], 'the talking head'],
|
|
82
|
+
[/^src\/core\/character-art\.js$/, ['character-render'], 'the head it draws'],
|
|
83
|
+
[/^src\/core\/review\.js$/, ['review-render'], 'the review overlay and its anchor resolver'],
|
|
84
|
+
[/^src\/core\/overflow\.js$/, ['overflow-render', 'pin-render'], 'the overflow guardrail and the pinned-title case'],
|
|
85
|
+
[/^src\/core\/annotate\.js$/, ['engine-render', 'render'], 'ink rides the engine scale'],
|
|
86
|
+
[/^src\/core\/themes\.js$/, ['render', 'contrast'], 'theme picking, and the contrast gate behind it'],
|
|
87
|
+
[/^src\/core\/(editmode|history)\.js$/, ['engine-render'], 'the author surfaces the engine harness drives'],
|
|
88
|
+
[/^src\/core\/hud\.js$/, ['engine-render'], 'clock and progress live on the engine'],
|
|
89
|
+
[/^src\/core\/finder\.js$/, ['engine-render', 'review-render'], 'slide titles: the finder names them, review anchors by them'],
|
|
90
|
+
[/^src\/terminal\//, ['player-render'], 'the cast player'],
|
|
91
|
+
[/^src\/code\//, ['render'], 'code blocks render in the smoke deck'],
|
|
92
|
+
[/^src\/core\//, BROWSER, 'an unmapped core module — assume every harness'],
|
|
93
|
+
|
|
94
|
+
// ── the CLI and tools, each spawned by the harness that tests it ────────
|
|
95
|
+
[/^cli\/audit\.mjs$/, ['strict-render'], 'the ingredients label and --strict stripping'],
|
|
96
|
+
[/^cli\/bundle\.mjs$/, ['strict-render', 'render'], 'bundling, and the deck it produces'],
|
|
97
|
+
[/^cli\/plugin\.mjs$/, ['plugin-render'], 'presenter plugins'],
|
|
98
|
+
[/^cli\/import\.mjs$/, ['import-render'], 'deck import'],
|
|
99
|
+
[/^cli\/deckfile\.mjs$/, ['deckfile-render'], 'the .decklight container'],
|
|
100
|
+
[/^cli\/pdf\.mjs$/, ['pdf-render'], 'PDF export'],
|
|
101
|
+
[/^cli\/(present|shot)\.mjs$/, ['shot-render'], 'present, and the screenshot containment it asserts'],
|
|
102
|
+
[/^cli\/(comments|review-anchor|review-store|review-remote|review-submit)\.mjs$/, ['review-render'],
|
|
103
|
+
'the CLI half of review — the harness cross-checks the browser against it'],
|
|
104
|
+
[/^cli\/(units|marketplace|loader|pin)\.mjs$/, ['pin-render', 'extension-check-render'],
|
|
105
|
+
'unit pinning and the admission check'],
|
|
106
|
+
[/^tools\/extension-check\.mjs$/, ['extension-check-render'], 'the admission gate itself'],
|
|
107
|
+
[/^tools\/(theme-check|color)\.mjs$/, LINT, 'the theme lints'],
|
|
108
|
+
[/^tools\/chrome\.mjs$/, ALL, 'every harness starts a browser through it'],
|
|
109
|
+
[/^tools\/review-anchor\.mjs$/, ['review-render'], 'the anchor resolver both halves share'],
|
|
110
|
+
[/^tools\/(tts-engines|local-voice|voiceover-server|lipsync)\.mjs$/, ['narration-render', 'record-render'],
|
|
111
|
+
'the voice bridge narration talks to'],
|
|
112
|
+
[/^themes\//, ['render', ...LINT], 'a theme, and the gates that read every theme'],
|
|
113
|
+
[/^demo\//, ['render'], 'the smoke deck itself'],
|
|
114
|
+
|
|
115
|
+
// ── things no harness reads ────────────────────────────────────────────
|
|
116
|
+
// Named explicitly rather than left to the fallback, so "nothing" is a
|
|
117
|
+
// decision on the record and not an omission.
|
|
118
|
+
[/^(docs|\.github|\.claude)\//, [], 'not read by any harness'],
|
|
119
|
+
[/^(SPEC|README|CONTRIBUTING|CLAUDE|CHANGELOG)\.md$/, [], 'prose'],
|
|
120
|
+
[/^test\/.*\.test\.mjs$/, [], 'a unit test — the unit suite covers it'],
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
/** Which harnesses a single path implicates, and why. */
|
|
124
|
+
export function forPath(p) {
|
|
125
|
+
for (const [re, harnesses, why] of RULES) {
|
|
126
|
+
if (re.test(p)) return { harnesses, why };
|
|
127
|
+
}
|
|
128
|
+
// A harness fixture is about its own harness; `foo-render.mjs` / `foo.html`.
|
|
129
|
+
const m = /^test\/([a-z-]+?)(?:-render)?\.(?:mjs|html)$/.exec(p);
|
|
130
|
+
if (m) {
|
|
131
|
+
const hit = ALL.find((h) => h === m[1] || h === `${m[1]}-render`);
|
|
132
|
+
if (hit) return { harnesses: [hit], why: 'its own harness' };
|
|
133
|
+
}
|
|
134
|
+
return { harnesses: ALL, why: 'UNMAPPED — falling back to everything' };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What changed: committed against the base, plus whatever is uncommitted. */
|
|
138
|
+
function changedFiles(base) {
|
|
139
|
+
const git = (...a) => {
|
|
140
|
+
try { return execFileSync('git', a, { cwd: repo, encoding: 'utf8' }); } catch { return ''; }
|
|
141
|
+
};
|
|
142
|
+
// A base that does not resolve makes `git diff` fail, and a swallowed failure
|
|
143
|
+
// here would report "nothing changed" — the one answer that must never be
|
|
144
|
+
// wrong. `origin/main` is missing in more checkouts than you would think: a
|
|
145
|
+
// clone whose remote is named something else, or one fetched shallow.
|
|
146
|
+
try {
|
|
147
|
+
execFileSync('git', ['rev-parse', '--verify', `${base}^{commit}`],
|
|
148
|
+
{ cwd: repo, stdio: 'ignore' });
|
|
149
|
+
} catch {
|
|
150
|
+
process.stdout.write(`test:impact: cannot resolve "${base}" — `
|
|
151
|
+
+ `pass --since <ref> with a ref this clone has (or fetch it).\n`);
|
|
152
|
+
process.exit(2);
|
|
153
|
+
}
|
|
154
|
+
const out = new Set();
|
|
155
|
+
// `...` is deliberate: the merge base, so a stale branch does not report
|
|
156
|
+
// every file main moved under it as something this change touched.
|
|
157
|
+
for (const l of git('diff', '--name-only', `${base}...HEAD`).split('\n')) if (l.trim()) out.add(l.trim());
|
|
158
|
+
for (const l of git('status', '--porcelain').split('\n')) {
|
|
159
|
+
const f = l.slice(3).trim();
|
|
160
|
+
if (f) out.add(f.includes(' -> ') ? f.split(' -> ')[1] : f);
|
|
161
|
+
}
|
|
162
|
+
return [...out];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── the command ───────────────────────────────────────────────────────────
|
|
166
|
+
// Guarded so the map above can be imported and asserted (test/test-impact.test.mjs)
|
|
167
|
+
// without this file running a suite as a side effect of being read.
|
|
168
|
+
if (!isMain(import.meta.url)) { /* imported for the map — the CLI below is inert */ } else {
|
|
169
|
+
const args = process.argv.slice(2);
|
|
170
|
+
const run = args.includes('--run');
|
|
171
|
+
const baseArg = args.indexOf('--since');
|
|
172
|
+
const base = baseArg !== -1 ? args[baseArg + 1] : 'origin/main';
|
|
173
|
+
// `i !== baseArg + 1` drops --since's VALUE, and only when --since is present:
|
|
174
|
+
// with no flag `baseArg` is -1 and the guard would silently eat argv[0], which
|
|
175
|
+
// is the first path somebody asked about.
|
|
176
|
+
const paths = args.filter((a, i) => !a.startsWith('--') && !(baseArg !== -1 && i === baseArg + 1));
|
|
177
|
+
|
|
178
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
179
|
+
process.stdout.write(`decklight test:impact — which tests this change needs
|
|
180
|
+
|
|
181
|
+
npm run test:impact what would run, against origin/main
|
|
182
|
+
npm run test:impact -- --run run it
|
|
183
|
+
npm run test:impact -- --since main compare against another ref
|
|
184
|
+
npm run test:impact -- src/core/review.js ask about explicit paths
|
|
185
|
+
|
|
186
|
+
The unit suite ALWAYS runs: it is ~48s and parallel, so picking a subset saves
|
|
187
|
+
little and can be wrong. Only the render harnesses (~200s, serial) are selected.
|
|
188
|
+
An unrecognised path selects every harness. CI always runs everything.
|
|
189
|
+
`);
|
|
190
|
+
process.exit(0);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const files = paths.length ? paths : changedFiles(base);
|
|
194
|
+
if (!files.length) {
|
|
195
|
+
process.stdout.write(`test:impact: nothing changed against ${base} — nothing to run\n`);
|
|
196
|
+
process.exit(0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const picked = new Map(); // harness → the reasons it was picked
|
|
200
|
+
let unmapped = false;
|
|
201
|
+
for (const f of files) {
|
|
202
|
+
const { harnesses, why } = forPath(f);
|
|
203
|
+
if (why.startsWith('UNMAPPED')) unmapped = true;
|
|
204
|
+
for (const h of harnesses) {
|
|
205
|
+
if (!picked.has(h)) picked.set(h, new Set());
|
|
206
|
+
picked.get(h).add(`${f} — ${why}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const selected = ALL.filter((h) => picked.has(h));
|
|
210
|
+
|
|
211
|
+
// Measured on a laptop; a rough shape so the report can say what it saves.
|
|
212
|
+
const COST = {
|
|
213
|
+
'narration-render': 65, 'extension-check-render': 23, 'engine-render': 17, render: 20,
|
|
214
|
+
'pdf-render': 10, 'split-render': 9, 'review-render': 8, 'pin-render': 7, 'record-render': 7,
|
|
215
|
+
'strict-render': 6, 'overflow-render': 6, 'plugin-render': 6, 'deckfile-render': 4,
|
|
216
|
+
'shot-render': 4, 'player-render': 3, 'character-render': 2, 'import-render': 2,
|
|
217
|
+
contrast: 1, 'palette-rules': 1,
|
|
218
|
+
};
|
|
219
|
+
const cost = (list) => list.reduce((n, h) => n + (COST[h] ?? 10), 0);
|
|
220
|
+
|
|
221
|
+
process.stdout.write(`\n─── test:impact ${'─'.repeat(52)}\n`);
|
|
222
|
+
process.stdout.write(`${files.length} changed file${files.length === 1 ? '' : 's'} against ${base}\n\n`);
|
|
223
|
+
for (const f of files.slice(0, 20)) process.stdout.write(` ${f}\n`);
|
|
224
|
+
if (files.length > 20) process.stdout.write(` … and ${files.length - 20} more\n`);
|
|
225
|
+
|
|
226
|
+
process.stdout.write(`\nunit suite ALWAYS — npm test (~48s, parallel)\n`);
|
|
227
|
+
if (!selected.length) {
|
|
228
|
+
process.stdout.write(`render none — nothing changed that a harness reads\n`);
|
|
229
|
+
} else {
|
|
230
|
+
process.stdout.write(`render ${selected.length} of ${ALL.length} harnesses`
|
|
231
|
+
+ ` (~${cost(selected)}s of ~${cost(ALL)}s)\n`);
|
|
232
|
+
for (const h of selected) {
|
|
233
|
+
const [first] = [...picked.get(h)];
|
|
234
|
+
process.stdout.write(` ${h.padEnd(24)} ${first}\n`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (unmapped) {
|
|
238
|
+
process.stdout.write(`\n! an unmapped path selected everything. If that path has a harness that\n`
|
|
239
|
+
+ ` is really about it, add a rule to tools/test-impact.mjs.\n`);
|
|
240
|
+
}
|
|
241
|
+
if (!run) {
|
|
242
|
+
process.stdout.write(`\n(--run to run it; CI still runs everything)\n`);
|
|
243
|
+
process.exit(0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
process.stdout.write(`\n─── npm test ${'─'.repeat(55)}\n`);
|
|
247
|
+
const unit = spawnSync('npm', ['test'], { cwd: repo, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
248
|
+
let bad = unit.status !== 0;
|
|
249
|
+
if (selected.length) {
|
|
250
|
+
const verify = spawnSync('npm', ['run', 'verify'], {
|
|
251
|
+
cwd: repo,
|
|
252
|
+
stdio: 'inherit',
|
|
253
|
+
shell: process.platform === 'win32',
|
|
254
|
+
env: { ...process.env, VERIFY_ONLY: selected.join(',') },
|
|
255
|
+
});
|
|
256
|
+
bad = bad || verify.status !== 0;
|
|
257
|
+
}
|
|
258
|
+
process.exit(bad ? 1 : 0);
|
|
259
|
+
}
|
package/tools/tts-engines.mjs
CHANGED
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
// registered reaches its own voice exactly as it always did.
|
|
44
44
|
|
|
45
45
|
import { execFileSync, spawn } from 'node:child_process';
|
|
46
|
-
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
46
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
47
47
|
import { homedir, tmpdir } from 'node:os';
|
|
48
|
-
import { join } from 'node:path';
|
|
48
|
+
import { delimiter, join } from 'node:path';
|
|
49
49
|
import { createSynth as createGemini, GEMINI_VOICES, gcloudToken, validProjectId, authHeaders } from './gemini-tts.mjs';
|
|
50
50
|
import {
|
|
51
|
-
createSynth as createElevenLabs, apiKey as elevenLabsKey,
|
|
51
|
+
createSynth as createElevenLabs, apiKey as elevenLabsKey, KEY_ENV as ELEVENLABS_KEY_ENV,
|
|
52
52
|
DEFAULT_MODEL as ELEVENLABS_MODEL, V3_MODEL as ELEVENLABS_V3_MODEL,
|
|
53
53
|
} from './elevenlabs-tts.mjs';
|
|
54
|
-
import { detectLocalVoice, sayArgs, sapiArgs } from './local-voice.mjs';
|
|
54
|
+
import { detectLocalVoice, sayArgs, sapiArgs, winrtArgs, TIER_LABEL } from './local-voice.mjs';
|
|
55
55
|
|
|
56
56
|
export const ENGINES = ['gemini', 'chirp', 'piper', 'elevenlabs', 'say', 'sapi'];
|
|
57
57
|
/** The two engines that are already on the machine — nothing to install. */
|
|
@@ -333,10 +333,35 @@ function createPiper({ voice = PIPER_DEFAULT_VOICE, dataDir }) {
|
|
|
333
333
|
* Neither takes a delivery instruction, so both are `stylable: false` and the
|
|
334
334
|
* picker skips the tone step, exactly as it does for piper and ElevenLabs.
|
|
335
335
|
*/
|
|
336
|
-
function createNative({ kind, voice, shell = 'powershell.exe' }) {
|
|
336
|
+
function createNative({ kind, voice, shell = 'powershell.exe', voices = [], api = null }) {
|
|
337
337
|
const bin = kind === 'say' ? 'say' : shell;
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
// on Windows the API decides the voices: WinRT sees the natural ones,
|
|
339
|
+
// System.Speech only the 2006 roster — detectLocalVoice chose, and the
|
|
340
|
+
// synthesis must speak through the same stack that listed the voice
|
|
341
|
+
const build = kind === 'say' ? sayArgs : api === 'winrt' ? winrtArgs : sapiArgs;
|
|
342
|
+
// The roster this machine actually has, for the guard below. Held as names
|
|
343
|
+
// because that is what the player sends and what `say -v` takes.
|
|
344
|
+
const known = new Set(voices.map((v) => v?.name ?? v).filter(Boolean));
|
|
345
|
+
/**
|
|
346
|
+
* `(text, { voice })` — the SECOND argument is the voice for THIS sentence,
|
|
347
|
+
* and it is the whole contract every other engine here implements.
|
|
348
|
+
*
|
|
349
|
+
* This used to be `async (text) =>`, closing over the voice chosen when the
|
|
350
|
+
* bridge started. So the picker offered 184 macOS voices, the log printed
|
|
351
|
+
* whichever one you picked, and all 184 played the same one — the failure was
|
|
352
|
+
* invisible in the logs because the log line quotes the REQUEST.
|
|
353
|
+
*/
|
|
354
|
+
return async (text, { voice: asked } = {}) => {
|
|
355
|
+
const pick = asked || voice;
|
|
356
|
+
// A name this machine cannot say is an ERROR, not a shrug. `say -v Zephyr`
|
|
357
|
+
// exits 0 and quietly produces the SYSTEM DEFAULT voice — so a typo, a
|
|
358
|
+
// stale saved voice, or a roster from another engine all sound like
|
|
359
|
+
// success while giving you somebody else's voice. (PowerShell's
|
|
360
|
+
// SelectVoice already throws on an unknown name; this makes the two agree.)
|
|
361
|
+
if (kind === 'say' && known.size && pick && !known.has(pick)) {
|
|
362
|
+
throw new Error(`no ${kind} voice named ${JSON.stringify(pick)} on this machine`
|
|
363
|
+
+ ` — this bridge speaks ${known.size} others (GET /voices)`);
|
|
364
|
+
}
|
|
340
365
|
// one line: `say` treats newlines as pauses and PowerShell quoting gets
|
|
341
366
|
// harder the moment a string spans lines
|
|
342
367
|
const line = String(text).replace(/\s+/g, ' ').trim();
|
|
@@ -344,7 +369,7 @@ function createNative({ kind, voice, shell = 'powershell.exe' }) {
|
|
|
344
369
|
const dir = mkdtempSync(join(tmpdir(), 'decklight-native-'));
|
|
345
370
|
const file = join(dir, 'out.wav');
|
|
346
371
|
try {
|
|
347
|
-
execFileSync(bin, build(line,
|
|
372
|
+
execFileSync(bin, build(line, pick, file), { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
348
373
|
const wav = readFileSync(file);
|
|
349
374
|
if (!wav.length) throw new Error(`${kind} produced no audio`);
|
|
350
375
|
// `{ wav, usage }`, like every other engine and like this file's own
|
|
@@ -355,7 +380,8 @@ function createNative({ kind, voice, shell = 'powershell.exe' }) {
|
|
|
355
380
|
// behind a door that never opened.
|
|
356
381
|
return {
|
|
357
382
|
wav,
|
|
358
|
-
|
|
383
|
+
// the voice that SPOKE, not the one the bridge booted with
|
|
384
|
+
usage: { model: pick ?? kind, chars: line.length, cost: 0, note: `${line.length} chars · local` },
|
|
359
385
|
};
|
|
360
386
|
} catch (e) {
|
|
361
387
|
throw new Error(`${kind}: ${String(e.stderr ?? e.message).trim().split('\n')[0] || 'synthesis failed'}`);
|
|
@@ -367,6 +393,10 @@ function createNative({ kind, voice, shell = 'powershell.exe' }) {
|
|
|
367
393
|
|
|
368
394
|
export function createEngine({
|
|
369
395
|
engine = 'gemini', project, model, location, voice, dataDir, lang, format, stability, env = process.env,
|
|
396
|
+
// Injected like every other probe in this file, so a native engine can be
|
|
397
|
+
// built — and its voice handling asserted — on a machine that is not the one
|
|
398
|
+
// the test happens to run on.
|
|
399
|
+
detect = detectLocalVoice,
|
|
370
400
|
} = {}) {
|
|
371
401
|
if (!ENGINES.includes(engine)) {
|
|
372
402
|
throw new Error(`unknown engine '${engine}' — use ${ENGINES.join(', ')},`
|
|
@@ -385,14 +415,35 @@ export function createEngine({
|
|
|
385
415
|
};
|
|
386
416
|
}
|
|
387
417
|
if (engine === 'say' || engine === 'sapi') {
|
|
388
|
-
const detected =
|
|
418
|
+
const detected = detect({ lang });
|
|
389
419
|
const pick = voice ?? detected.voices?.[0]?.name;
|
|
390
420
|
if (!pick) throw new Error(detected.why ?? `no ${engine} voices on this machine`);
|
|
421
|
+
// The deck's language decides which voices get quality shelves; the rest
|
|
422
|
+
// share ONE group at the tail — contiguous by construction, because
|
|
423
|
+
// parseSayVoices sorts language first. ~140 of a real Mac's rows are
|
|
424
|
+
// other languages, and shelving them by quality answered a question
|
|
425
|
+
// nobody browsing an English deck was asking.
|
|
426
|
+
const want = (lang ?? 'en').slice(0, 2).toLowerCase();
|
|
427
|
+
const groupOf = (v) => (!Number.isInteger(v.tier) ? undefined
|
|
428
|
+
: (v.locale || '').toLowerCase().startsWith(want) ? TIER_LABEL[v.tier]
|
|
429
|
+
: 'other languages');
|
|
391
430
|
return {
|
|
392
431
|
name: engine, model: pick, needsProject: false, stylable: false,
|
|
393
432
|
cost: 'free · offline · already on this machine',
|
|
394
|
-
|
|
395
|
-
|
|
433
|
+
// [name, flavor, group]: the quality category travels as a STRUCTURED
|
|
434
|
+
// third element (best · good · average) and the picker draws it as a
|
|
435
|
+
// labelled separator over each shelf — the roster mixes this year's
|
|
436
|
+
// neural voices with 1990s robots under names that reveal nothing. The
|
|
437
|
+
// flavor stays the locale alone; repeating the category on every row
|
|
438
|
+
// was the suffix wallpaper the separators replace.
|
|
439
|
+
voices: (detected.voices ?? []).map((v) => [v.name, v.locale || 'system', groupOf(v)]),
|
|
440
|
+
// "download a Siri voice" rides the same channel every engine caveat
|
|
441
|
+
// does: the bridge's startup line and the deck's toast on switching
|
|
442
|
+
...(detected.caveat ? { caveat: detected.caveat } : {}),
|
|
443
|
+
synth: createNative({
|
|
444
|
+
kind: engine, voice: pick, shell: detected.shell, voices: detected.voices ?? [],
|
|
445
|
+
api: detected.api ?? null,
|
|
446
|
+
}),
|
|
396
447
|
};
|
|
397
448
|
}
|
|
398
449
|
if (engine === 'elevenlabs') {
|
|
@@ -440,6 +491,154 @@ export function createEngine({
|
|
|
440
491
|
};
|
|
441
492
|
}
|
|
442
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Is `bin` on PATH? The bare-name probe the readiness check needs.
|
|
496
|
+
*
|
|
497
|
+
* `cli/agents.mjs` has the full version (explicit paths, execute bits); this
|
|
498
|
+
* one is here rather than there because `tools/` cannot import from `cli/`,
|
|
499
|
+
* and `tools/tts-setup.mjs` shares it so the wizard and the readiness check
|
|
500
|
+
* cannot disagree about whether piper is installed.
|
|
501
|
+
*/
|
|
502
|
+
export function binOnPath(bin, env = process.env) {
|
|
503
|
+
const exts = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
504
|
+
return (env.PATH || '').split(delimiter)
|
|
505
|
+
.some((dir) => dir && exts.some((ext) => existsSync(join(dir, bin + ext))));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Can this machine speak with `name` right now, and if not, what is missing?
|
|
510
|
+
*
|
|
511
|
+
* WHY THIS IS NOT `createEngine` THROWING. Two of the six build perfectly well
|
|
512
|
+
* and fail later: `gemini` and `chirp` construct a synth against a project id
|
|
513
|
+
* nobody has checked, so the bridge would come up looking healthy and only die
|
|
514
|
+
* on the first keypress — with a 403 naming a project the presenter never
|
|
515
|
+
* typed. Readiness is a question about the MACHINE (a binary, a model file, a
|
|
516
|
+
* key, a project), and it has to be asked before anything is constructed.
|
|
517
|
+
*
|
|
518
|
+
* WHY IT LIVES HERE. Two callers now ask it: `decklight author`, deciding
|
|
519
|
+
* whether to start the bridge at all, and the bridge itself, listing what the
|
|
520
|
+
* deck may switch to (SPEC `NARRATION`). They must not disagree — a picker
|
|
521
|
+
* offering an engine that `author` would have refused is a picker that lies.
|
|
522
|
+
* So the DECISION is shared and only the presentation differs: `reason` is a
|
|
523
|
+
* code the caller phrases for its own audience.
|
|
524
|
+
*
|
|
525
|
+
* Every probe is injected, so this is testable without a PATH, a filesystem,
|
|
526
|
+
* or a credential.
|
|
527
|
+
*/
|
|
528
|
+
export function engineStatus(name, {
|
|
529
|
+
// `project` defaults from the environment rather than to null: a caller that
|
|
530
|
+
// passes only `env` means "decide from this machine", and answering
|
|
531
|
+
// no-project on a machine whose GOOGLE_CLOUD_PROJECT is right there would be
|
|
532
|
+
// a wrong answer that looks like a correct one. A caller with its own
|
|
533
|
+
// precedence ladder (flags > env > saved config) passes the settled value.
|
|
534
|
+
env = process.env, project = env.GOOGLE_CLOUD_PROJECT ?? null,
|
|
535
|
+
voice = null, dataDir = null, lang = null,
|
|
536
|
+
hasBin = binOnPath, exists = existsSync, detect = detectLocalVoice,
|
|
537
|
+
} = {}) {
|
|
538
|
+
const no = (reason, detail) => ({ name, ready: false, reason, ...detail });
|
|
539
|
+
if (!ENGINES.includes(name)) return no('unknown');
|
|
540
|
+
|
|
541
|
+
if (name === 'piper') {
|
|
542
|
+
if (!hasBin('piper', env)) return no('no-binary');
|
|
543
|
+
const v = voice ?? PIPER_DEFAULT_VOICE;
|
|
544
|
+
const models = dataDir ?? piperModelDir(env);
|
|
545
|
+
if (!exists(piperModelPath(v, models))) return no('no-model', { voice: v, dataDir: models });
|
|
546
|
+
return { name, ready: true, reason: 'ok' };
|
|
547
|
+
}
|
|
548
|
+
if (NATIVE_ENGINES.includes(name)) {
|
|
549
|
+
// A system voice needs no setup at all — but the wrong OS has none, and
|
|
550
|
+
// `say` on a machine with no configured voices is a silent bridge.
|
|
551
|
+
const d = detect({ lang });
|
|
552
|
+
if (d?.engine !== name || !d?.voices?.length) return no('no-native-voice', { why: d?.why });
|
|
553
|
+
return { name, ready: true, reason: 'ok' };
|
|
554
|
+
}
|
|
555
|
+
if (name === 'elevenlabs') {
|
|
556
|
+
return elevenLabsKey(env)?.trim() ? { name, ready: true, reason: 'ok' } : no('no-key');
|
|
557
|
+
}
|
|
558
|
+
// gemini and chirp
|
|
559
|
+
if (!project) return no('no-project');
|
|
560
|
+
if (!validProjectId(project)) return no('bad-project', { project });
|
|
561
|
+
return { name, ready: true, reason: 'ok' };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* A blocker in two short sentences: what is missing, and what fixes it.
|
|
566
|
+
*
|
|
567
|
+
* These are the PICKER's words — one line each, because they are drawn under a
|
|
568
|
+
* greyed row in a deck. `decklight author` phrases the same codes at length
|
|
569
|
+
* (it has a terminal, and it is the place a presenter is still setting up).
|
|
570
|
+
* Both read the same `reason`, so they can be worded for their audience
|
|
571
|
+
* without being able to disagree about the facts.
|
|
572
|
+
*
|
|
573
|
+
* Every fix is something you do in a TERMINAL, and that is deliberate: the
|
|
574
|
+
* deck lists what is missing and never collects it. A key or a project id
|
|
575
|
+
* typed into a web page — even one on loopback — is a different thing from one
|
|
576
|
+
* exported in a shell, and a presented deck is reachable from a phone.
|
|
577
|
+
*/
|
|
578
|
+
export function engineBlocker(status, { env = process.env } = {}) {
|
|
579
|
+
const { reason } = status ?? {};
|
|
580
|
+
if (!reason || reason === 'ok') return null;
|
|
581
|
+
switch (reason) {
|
|
582
|
+
case 'no-binary':
|
|
583
|
+
return { why: 'not installed', fix: 'uv tool install piper-tts' };
|
|
584
|
+
case 'no-model':
|
|
585
|
+
return {
|
|
586
|
+
why: `the voice ${status.voice} is not downloaded (~120 MB, one time)`,
|
|
587
|
+
fix: piperDownloadLine(piperDownloadCmd(status.voice, status.dataDir,
|
|
588
|
+
{ hasBin: (b) => binOnPath(b, env) })),
|
|
589
|
+
};
|
|
590
|
+
case 'no-key':
|
|
591
|
+
return { why: `needs $${ELEVENLABS_KEY_ENV}`, fix: 'export it, then restart decklight author' };
|
|
592
|
+
case 'no-project':
|
|
593
|
+
return {
|
|
594
|
+
why: 'needs a Google Cloud project',
|
|
595
|
+
fix: 'export GOOGLE_CLOUD_PROJECT=<id>, then restart decklight author',
|
|
596
|
+
};
|
|
597
|
+
case 'bad-project':
|
|
598
|
+
// Named rather than generic: this one is nearly always a copy-paste that
|
|
599
|
+
// brought punctuation with it, and seeing the value is the whole fix.
|
|
600
|
+
return { why: `not a GCP project id: ${JSON.stringify(status.project)}`, fix: 'stray punctuation from a copy-paste?' };
|
|
601
|
+
case 'no-native-voice':
|
|
602
|
+
return { why: status.why ?? 'no system voice on this machine', fix: null };
|
|
603
|
+
default:
|
|
604
|
+
return { why: `unknown engine — use ${ENGINES.join(', ')}`, fix: null };
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* What a presenter could switch to, with the price note and the blocker.
|
|
610
|
+
*
|
|
611
|
+
* Order is a RECOMMENDATION and deliberately not `ENGINES` order (which keeps
|
|
612
|
+
* gemini first for history): free and already-on-this-machine first, then the
|
|
613
|
+
* ones with a bill. The native engine is folded to whichever of say/sapi this
|
|
614
|
+
* OS actually has, because "sapi" on a Mac is not a choice, it is noise.
|
|
615
|
+
*
|
|
616
|
+
* `cost` comes from the engine itself where it can be built, so the picker
|
|
617
|
+
* quotes the same sentence the bridge's startup line does rather than a second
|
|
618
|
+
* copy of it. An engine that cannot be built has no cost to quote — it has a
|
|
619
|
+
* blocker, which is what the row shows instead.
|
|
620
|
+
*/
|
|
621
|
+
export function engineMenu(opts = {}) {
|
|
622
|
+
// Settled once, and shared with the construction below: `createEngine` for a
|
|
623
|
+
// cloud engine REFUSES a missing project, so a menu that probed readiness
|
|
624
|
+
// with the environment's project but built with `undefined` would quietly
|
|
625
|
+
// drop the price note off every row it had just called ready.
|
|
626
|
+
const env = opts.env ?? process.env;
|
|
627
|
+
const settled = { ...opts, env, project: opts.project ?? env.GOOGLE_CLOUD_PROJECT ?? null };
|
|
628
|
+
const native = NATIVE_ENGINES.includes(process.platform === 'win32' ? 'sapi' : 'say')
|
|
629
|
+
? (process.platform === 'win32' ? 'sapi' : 'say') : null;
|
|
630
|
+
const order = [native, 'piper', 'chirp', 'gemini', 'elevenlabs'].filter(Boolean);
|
|
631
|
+
return order.map((name) => {
|
|
632
|
+
const status = engineStatus(name, settled);
|
|
633
|
+
let cost;
|
|
634
|
+
// Building it is the only way to learn the price note, and it is cheap —
|
|
635
|
+
// no network, no process. It can still throw (a native engine with no
|
|
636
|
+
// voices), which is not an error here: the row already carries the blocker.
|
|
637
|
+
try { cost = createEngine({ ...settled, engine: name }).cost; } catch { cost = undefined; }
|
|
638
|
+
return { ...status, cost, ...(engineBlocker(status, settled) ?? {}) };
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
|
|
443
642
|
/**
|
|
444
643
|
* The engine for `name`, whether decklight ships it or the machine installed
|
|
445
644
|
* it (SPEC `ENGINE_UNITS`).
|
package/tools/tts-setup.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node
|
|
|
21
21
|
import { homedir, tmpdir } from 'node:os';
|
|
22
22
|
import { delimiter, dirname, join } from 'node:path';
|
|
23
23
|
import {
|
|
24
|
+
binOnPath,
|
|
24
25
|
createEngine, ENGINES, PIPER_DEFAULT_VOICE, piperModelDir,
|
|
25
26
|
piperDownloadCmd, piperDownloadLine,
|
|
26
27
|
} from './tts-engines.mjs';
|
|
@@ -28,7 +29,7 @@ import { gcloudToken, validProjectId } from './gemini-tts.mjs';
|
|
|
28
29
|
import { KEY_ENV as ELEVENLABS_KEY_ENV, apiKey as elevenLabsKey } from './elevenlabs-tts.mjs';
|
|
29
30
|
|
|
30
31
|
// The picker's preview default (SPEC PRESENTING) — the wizard's proof is the same
|
|
31
|
-
// audio the deck's
|
|
32
|
+
// audio the deck's V picker previews.
|
|
32
33
|
export const TEST_SENTENCE = 'Hey, this is Decklight';
|
|
33
34
|
|
|
34
35
|
/** The saved answers live at ~/.config/decklight/tts.json — $XDG_CONFIG_HOME honored. */
|
|
@@ -50,14 +51,6 @@ export function saveTtsConfig(config, env = process.env) {
|
|
|
50
51
|
return file;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
// cli/agents.mjs has the full onPath (explicit paths too); tools/ cannot
|
|
54
|
-
// import from cli/, and the wizard only ever probes bare names.
|
|
55
|
-
function binOnPath(bin, env = process.env) {
|
|
56
|
-
const exts = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
57
|
-
return (env.PATH || '').split(delimiter)
|
|
58
|
-
.some((dir) => dir && exts.some((ext) => existsSync(join(dir, bin + ext))));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
54
|
/** The project gcloud is configured with — the prefill when $GOOGLE_CLOUD_PROJECT is unset. */
|
|
62
55
|
export function gcloudConfigProject() {
|
|
63
56
|
try {
|