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.
- package/PLATFORM.md +707 -0
- package/README.md +226 -150
- package/SPEC.md +803 -888
- package/cli/agent-review.mjs +246 -0
- package/cli/agents.mjs +35 -9
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +190 -0
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +439 -35
- package/cli/cast.mjs +48 -12
- package/cli/check-fixes.mjs +186 -0
- package/cli/check.mjs +988 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +51 -22
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +64 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +666 -0
- package/cli/design-system.mjs +497 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +551 -0
- package/cli/edit-look.mjs +631 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2585 -855
- package/cli/enhance.mjs +485 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +78 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +407 -236
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +460 -29
- package/cli/narrate.mjs +251 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +961 -0
- package/cli/pdf.mjs +64 -17
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +63 -27
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +85 -23
- package/cli/remote.mjs +43 -17
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +236 -45
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +229 -35
- package/cli/skills.mjs +353 -26
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +527 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +112 -47
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1533 -59
- package/dist/decklight.js +258 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +778 -0
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +11 -3
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +270 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-clip.mjs +114 -0
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +530 -54
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- package/tools/publish-site-voices.mjs +0 -75
package/cli/library.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* decklight library — everything installed into YOUR library, one grammar.
|
|
6
|
+
*
|
|
7
|
+
* decklight library add <kind> <name[@marketplace]>
|
|
8
|
+
* decklight library remove <kind> <name>
|
|
9
|
+
* decklight library list [kind]
|
|
10
|
+
* decklight library gate <kind> <path> (the marketplace admission gate)
|
|
11
|
+
*
|
|
12
|
+
* It used to be seven top-level commands, one per kind (`importer`,
|
|
13
|
+
* `transform`, `engine`, `voice`, `agent`, `plugin`, `extension`) plus the
|
|
14
|
+
* unit half of `skills`, each with its own spelling of add, list and remove
|
|
15
|
+
* (ROADMAP section 4). The implementations stay where they were: the unit
|
|
16
|
+
* kinds are one function over UNIT_TYPES (units.mjs), a plugin is its own
|
|
17
|
+
* module (plugin.mjs), and the transform gate is extension.mjs. This file is
|
|
18
|
+
* only the grammar in front of them.
|
|
19
|
+
*
|
|
20
|
+
* `library` and not a bare `decklight add`: `theme add`, `font add` and
|
|
21
|
+
* `design-system add` put a reference INTO A DECK, and a top-level `add` that
|
|
22
|
+
* installs into the library instead would read as the same act.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { UNIT_TYPES } from './units.mjs';
|
|
26
|
+
import { runMain } from './util.mjs';
|
|
27
|
+
import { isMain } from '../tools/args.mjs';
|
|
28
|
+
|
|
29
|
+
const UNIT_KINDS = Object.keys(UNIT_TYPES);
|
|
30
|
+
export const KINDS = [...UNIT_KINDS, 'plugin'];
|
|
31
|
+
// `gate` is the marketplace admission gate; `check` still answers for it,
|
|
32
|
+
// unadvertised, because a catalog's CI may already run it. Bare `decklight
|
|
33
|
+
// check` is the deck lint, and the word now has that one meaning.
|
|
34
|
+
export const VERBS = ['add', 'remove', 'list', 'gate', 'check'];
|
|
35
|
+
/** The kinds a marketplace can gate admission on before an entry is listed. */
|
|
36
|
+
const CHECKABLE = { plugin: 'a plugin directory, or an installed plugin\'s name', transform: 'a build-time transform\'s .mjs file' };
|
|
37
|
+
|
|
38
|
+
export const USAGE = `usage: decklight library <add|remove|list|check> <kind> …
|
|
39
|
+
|
|
40
|
+
Your library: what this machine installs from a marketplace, into
|
|
41
|
+
~/.decklight/, for your own use. Nothing here travels inside a deck.
|
|
42
|
+
|
|
43
|
+
decklight library add <kind> <name[@marketplace]>
|
|
44
|
+
install a unit from a registered marketplace (decklight marketplace add …)
|
|
45
|
+
EXAMPLE: decklight library add plugin timer
|
|
46
|
+
EXAMPLE: decklight library add engine azure-tts
|
|
47
|
+
EXAMPLE: decklight library add voice narrator-anna (a reference, never a model)
|
|
48
|
+
|
|
49
|
+
decklight library remove <kind> <name>
|
|
50
|
+
decklight library list [kind] every kind when none is named
|
|
51
|
+
|
|
52
|
+
decklight library gate <kind> <path>
|
|
53
|
+
the admission gate a marketplace's CI runs before listing an entry;
|
|
54
|
+
exits non-zero on a refusal
|
|
55
|
+
EXAMPLE: decklight library gate transform grammar-check.mjs
|
|
56
|
+
EXAMPLE: decklight library gate plugin plugins/timer
|
|
57
|
+
|
|
58
|
+
kinds
|
|
59
|
+
plugin presenter chrome for your machine; every deck you open shows it
|
|
60
|
+
skill an agent skill (Markdown)
|
|
61
|
+
importer an import adapter, for a format decklight cannot read itself
|
|
62
|
+
transform build-time Node code that runs during bundle, never in a deck
|
|
63
|
+
engine a speech engine the built-in ones do not cover
|
|
64
|
+
voice a marketplace voice for the picker
|
|
65
|
+
agent a descriptor of how to run a coding agent headlessly, for A
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The library form of a command typed the old way, for "did you mean":
|
|
70
|
+
* `plugin add timer` → `library add plugin timer`, `extension check t.mjs` →
|
|
71
|
+
* `library gate transform t.mjs`, `engines` → `library list engine`.
|
|
72
|
+
* Pure, so the suggestion can be tested without running anything.
|
|
73
|
+
*/
|
|
74
|
+
export function libraryForm(cmd, rest = []) {
|
|
75
|
+
const word = String(cmd ?? '').toLowerCase();
|
|
76
|
+
const kind = word === 'extension' ? 'transform' : word.replace(/s$/, '');
|
|
77
|
+
const [verb, ...more] = rest;
|
|
78
|
+
if (!KINDS.includes(kind)) return ['library', ...rest];
|
|
79
|
+
if (VERBS.includes(verb)) return ['library', verb, kind, ...more];
|
|
80
|
+
return ['library', 'list', kind, ...rest];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function refuse(msg) {
|
|
84
|
+
console.error(`decklight library: ${msg}\n\n${USAGE}`);
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function libraryMain(args = []) {
|
|
89
|
+
const [verb, kind, ...rest] = args;
|
|
90
|
+
if (!verb || verb === '--help' || verb === '-h' || verb === 'help') { console.log(USAGE); return verb ? 0 : 1; }
|
|
91
|
+
if (!VERBS.includes(verb)) return refuse(`unknown verb "${verb}" — add, remove, list or gate`);
|
|
92
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
93
|
+
// a kind named: that kind's own usage, its examples and what uses it
|
|
94
|
+
if (KINDS.includes(kind)) return kind === 'plugin' ? pluginRun(['--help']) : unitRun(kind, ['--help']);
|
|
95
|
+
console.log(USAGE);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (verb === 'list' && !kind) {
|
|
100
|
+
let code = 0;
|
|
101
|
+
for (const k of UNIT_KINDS) code = Math.max(code, await unitRun(k, ['list']) ?? 0);
|
|
102
|
+
code = Math.max(code, await pluginRun(['list']) ?? 0);
|
|
103
|
+
return code;
|
|
104
|
+
}
|
|
105
|
+
if (!kind) return refuse(`${verb} needs a kind: ${KINDS.join(', ')}`);
|
|
106
|
+
if (!KINDS.includes(kind)) return refuse(`unknown kind "${kind}": ${KINDS.join(', ')}`);
|
|
107
|
+
|
|
108
|
+
if (verb === 'gate' || verb === 'check') {
|
|
109
|
+
if (!CHECKABLE[kind]) return refuse(`there is no admission gate for a ${kind} — only for ${Object.keys(CHECKABLE).join(' and ')}`);
|
|
110
|
+
if (kind === 'plugin') return pluginRun(['check', ...rest]);
|
|
111
|
+
const { extensionMain } = await import('./extension.mjs');
|
|
112
|
+
return extensionMain(['check', ...rest, '--type', 'transform']);
|
|
113
|
+
}
|
|
114
|
+
return kind === 'plugin' ? pluginRun([verb, ...rest]) : unitRun(kind, [verb, ...rest]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function unitRun(kind, args) {
|
|
118
|
+
const { unitMain } = await import('./units.mjs');
|
|
119
|
+
return unitMain(kind, args);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function pluginRun(args) {
|
|
123
|
+
const { pluginMain } = await import('./plugin.mjs');
|
|
124
|
+
return pluginMain(args);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isMain(import.meta.url)) process.exitCode = await runMain('library', libraryMain);
|
package/cli/loader.mjs
CHANGED
|
@@ -66,7 +66,7 @@ function resolveCodeUnit(type, name, ceiling, home) {
|
|
|
66
66
|
const unit = findUnit(type, name, home);
|
|
67
67
|
if (!unit) {
|
|
68
68
|
throw new LoaderError(`no ${type} "${name}" installed`
|
|
69
|
-
+ ` (decklight ${type}
|
|
69
|
+
+ ` (decklight library add ${type} ${name}, decklight library list ${type})`);
|
|
70
70
|
}
|
|
71
71
|
const t = UNIT_TYPES[type];
|
|
72
72
|
const modulePath = t.single ? unit.path : join(unit.path, t.files[0]);
|
|
@@ -247,6 +247,8 @@ export async function loadEngineAt(modulePath, label, opts = {}) {
|
|
|
247
247
|
name: typeof engine.name === 'string' && engine.name ? engine.name : label,
|
|
248
248
|
voices: Array.isArray(engine.voices) ? engine.voices : [],
|
|
249
249
|
stylable: engine.stylable === true,
|
|
250
|
+
// one that reads `[whispers]`-style audio tags says so; any other has them taken out
|
|
251
|
+
audioTags: engine.audioTags === true,
|
|
250
252
|
};
|
|
251
253
|
}
|
|
252
254
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* "Check for updates when decklight starts" (SPEC MARKETPLACES_SCREEN): the
|
|
6
|
+
* one way a marketplace check runs without somebody pressing C.
|
|
7
|
+
*
|
|
8
|
+
* Opening a screen is not consent to reach the network, so the check never
|
|
9
|
+
* ran by itself. This is the consent: a per-machine switch, off until the
|
|
10
|
+
* author turns it on (O on the screen, `decklight marketplace auto-check on`),
|
|
11
|
+
* kept in the registry beside the marketplaces it is about. While it is on,
|
|
12
|
+
* an edit server that starts runs the same `decklight marketplace outdated
|
|
13
|
+
* --json` that C runs (`git ls-remote`, nothing fetched, nothing written but
|
|
14
|
+
* the answer), at most once in a window, never on the critical path: the
|
|
15
|
+
* server starts and serves without waiting, the shape of cli/update-check.mjs.
|
|
16
|
+
*
|
|
17
|
+
* The answer is RECORDED (`~/.decklight/marketplace-check.json`): when it was
|
|
18
|
+
* asked, each marketplace's state, and which offers the author dismissed, by
|
|
19
|
+
* the commit they were offered. The screen's list starts from it, and the
|
|
20
|
+
* deck offers what it found once, in a toast that names what the open deck
|
|
21
|
+
* uses from a marketplace that moved. It only ever offers: an update is still
|
|
22
|
+
* the author's, because it re-clones with their credentials and changes what
|
|
23
|
+
* every deck on the machine is served.
|
|
24
|
+
*
|
|
25
|
+
* Every function takes the config home, so a test points it at a temp one.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { readFileSync, mkdirSync } from 'node:fs';
|
|
29
|
+
import { join } from 'node:path';
|
|
30
|
+
import { writeFileAtomic } from '../tools/atomic-write.mjs';
|
|
31
|
+
import { configHome, loadRegistry, saveRegistry } from './marketplace.mjs';
|
|
32
|
+
|
|
33
|
+
/** How long a recorded answer stands before a starting server asks again: a session's restarts ask once. */
|
|
34
|
+
export const AUTO_CHECK_WINDOW_MS = 12 * 60 * 60 * 1000;
|
|
35
|
+
|
|
36
|
+
export const checkRecordPath = (home = configHome()) => join(home, 'marketplace-check.json');
|
|
37
|
+
|
|
38
|
+
/** Is the switch on? An unreadable registry is a no: nothing runs that was not asked for. */
|
|
39
|
+
export function autoCheckOn(home = configHome()) {
|
|
40
|
+
try { return loadRegistry(home).autoCheck === true; } catch { return false; }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Has the screen already asked, once, whether to turn it on? */
|
|
44
|
+
export function autoCheckOffered(home = configHome()) {
|
|
45
|
+
try { return loadRegistry(home).autoCheckOffered === true; } catch { return true; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Turn it on or off — and turning it either way means the question was answered. */
|
|
49
|
+
export function setAutoCheck(on, home = configHome()) {
|
|
50
|
+
const reg = loadRegistry(home);
|
|
51
|
+
reg.autoCheck = !!on;
|
|
52
|
+
reg.autoCheckOffered = true;
|
|
53
|
+
saveRegistry(reg, home);
|
|
54
|
+
return reg.autoCheck;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The screen asked once; it does not ask again. */
|
|
58
|
+
export function markAutoCheckOffered(home = configHome()) {
|
|
59
|
+
const reg = loadRegistry(home);
|
|
60
|
+
if (reg.autoCheckOffered === true) return false;
|
|
61
|
+
reg.autoCheckOffered = true;
|
|
62
|
+
saveRegistry(reg, home);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The recorded answer — `{ checkedAt, marketplaces, dismissed }` — or null when there is none. */
|
|
67
|
+
export function readCheckRecord(home = configHome()) {
|
|
68
|
+
try {
|
|
69
|
+
const r = JSON.parse(readFileSync(checkRecordPath(home), 'utf8'));
|
|
70
|
+
if (!Number.isFinite(r?.checkedAt) || !Array.isArray(r?.marketplaces)) return null;
|
|
71
|
+
return { checkedAt: r.checkedAt, marketplaces: r.marketplaces, dismissed: r.dismissed && typeof r.dismissed === 'object' ? r.dismissed : {} };
|
|
72
|
+
} catch { return null; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function writeRecord(rec, home) {
|
|
76
|
+
mkdirSync(home, { recursive: true });
|
|
77
|
+
writeFileAtomic(checkRecordPath(home), `${JSON.stringify(rec, null, 2)}\n`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Record what `outdated` answered. `all` is a check of every marketplace,
|
|
82
|
+
* which is what the window measures; one marketplace's answer is folded into
|
|
83
|
+
* the record without moving it. Dismissals are kept, and one for a
|
|
84
|
+
* marketplace no longer registered goes with it.
|
|
85
|
+
*/
|
|
86
|
+
export function recordCheck(results, home = configHome(), { all = true, now = Date.now() } = {}) {
|
|
87
|
+
const prev = readCheckRecord(home);
|
|
88
|
+
const rows = new Map((all ? [] : prev?.marketplaces ?? []).map((r) => [r.name, r]));
|
|
89
|
+
for (const r of results) rows.set(r.name, r);
|
|
90
|
+
const marketplaces = [...rows.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
91
|
+
const names = new Set(marketplaces.map((r) => r.name));
|
|
92
|
+
const dismissed = Object.fromEntries(Object.entries(prev?.dismissed ?? {}).filter(([n]) => names.has(n)));
|
|
93
|
+
const rec = { checkedAt: all || !prev ? now : prev.checkedAt, marketplaces, dismissed };
|
|
94
|
+
writeRecord(rec, home);
|
|
95
|
+
return rec;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** An update took a marketplace to `commit`: the record says so, and nothing is offered for it any more. */
|
|
99
|
+
export function noteUpdated(name, commit = null, home = configHome()) {
|
|
100
|
+
const rec = readCheckRecord(home);
|
|
101
|
+
const row = rec?.marketplaces.find((r) => r.name === name);
|
|
102
|
+
if (!row) return false;
|
|
103
|
+
Object.assign(row, { state: 'current', commit: commit ?? row.commit ?? null, remote: commit ?? row.remote ?? null, error: null });
|
|
104
|
+
writeRecord(rec, home);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The commit an offer is for — what Dismiss remembers. A local directory has none, so it is "changed on disk". */
|
|
109
|
+
const offerKey = (r) => r.remote ?? 'changed-on-disk';
|
|
110
|
+
|
|
111
|
+
/** Dismiss the offer for `name` at what it was offered at: the same commit is not offered again. */
|
|
112
|
+
export function dismissOffer(name, remote = null, home = configHome()) {
|
|
113
|
+
const rec = readCheckRecord(home);
|
|
114
|
+
if (!rec) return false;
|
|
115
|
+
const row = rec.marketplaces.find((r) => r.name === name);
|
|
116
|
+
rec.dismissed[name] = remote ?? (row ? offerKey(row) : 'changed-on-disk');
|
|
117
|
+
writeRecord(rec, home);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Should a starting server ask? Only with the switch on, and once in the window. */
|
|
122
|
+
export function autoCheckDue(home = configHome(), now = Date.now()) {
|
|
123
|
+
if (!autoCheckOn(home)) return false;
|
|
124
|
+
const rec = readCheckRecord(home);
|
|
125
|
+
return !rec || now - rec.checkedAt >= AUTO_CHECK_WINDOW_MS;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** "checked 3 min ago: 1 of 3 out of date" — the screen's summary line, and the server's startup one. */
|
|
129
|
+
export function checkSummary(rec, now = Date.now()) {
|
|
130
|
+
if (!rec) return null;
|
|
131
|
+
const s = Math.max(0, (now - rec.checkedAt) / 1000);
|
|
132
|
+
const ago = s < 60 ? 'just now' : s < 3600 ? `${Math.round(s / 60)} min ago` : s < 86400 ? `${Math.round(s / 3600)} h ago` : `${Math.round(s / 86400)} days ago`;
|
|
133
|
+
const behind = rec.marketplaces.filter((r) => r.state === 'behind' || r.state === 'unfetched').length;
|
|
134
|
+
return `checked ${ago}: ${behind ? `${behind} of ${rec.marketplaces.length} out of date` : 'all up to date'}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What the deck offers from the record: every marketplace found BEHIND (one
|
|
139
|
+
* never fetched is not an update to something you have) whose offer was not
|
|
140
|
+
* dismissed at this commit, with what the open deck uses from it. A check
|
|
141
|
+
* asks where a ref points and reads no catalog, so it cannot say which
|
|
142
|
+
* versions the update brings; what it can say is which of this deck's design
|
|
143
|
+
* systems, themes and fonts come from there. Nothing while the switch is off.
|
|
144
|
+
*/
|
|
145
|
+
export async function autoCheckOffers(html = null, home = configHome()) {
|
|
146
|
+
if (!autoCheckOn(home)) return [];
|
|
147
|
+
const rec = readCheckRecord(home);
|
|
148
|
+
if (!rec) return [];
|
|
149
|
+
const uses = html ? await deckUses(html) : new Map();
|
|
150
|
+
return rec.marketplaces
|
|
151
|
+
.filter((r) => r.state === 'behind' && rec.dismissed[r.name] !== offerKey(r))
|
|
152
|
+
.map((r) => {
|
|
153
|
+
const used = uses.get(r.name) ?? [];
|
|
154
|
+
return { name: r.name, commit: r.commit ?? null, remote: offerKey(r), local: !!r.local, uses: used, text: offerText(r, used) };
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** "decklight-confluent has an update: this deck uses confluent-developer (design system) from it". */
|
|
159
|
+
export function offerText(r, uses = []) {
|
|
160
|
+
const what = r.local ? 'has changed on disk' : 'has an update';
|
|
161
|
+
if (!uses.length) return `${r.name} ${what}`;
|
|
162
|
+
return `${r.name} ${what}: this deck uses ${uses.map((u) => `${u.name} (${u.kind})`).join(', ')} from it`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Marketplace name → `[{ name, kind }]`, what the deck references from each. */
|
|
166
|
+
async function deckUses(html) {
|
|
167
|
+
const [{ designSystemRefs }, { markedRefs }, { fontRefs }] = await Promise.all([
|
|
168
|
+
import('./design-system-refs.mjs'), import('./theme-refs.mjs'), import('./font-refs.mjs'),
|
|
169
|
+
]);
|
|
170
|
+
const out = new Map();
|
|
171
|
+
const add = (refs, kind) => {
|
|
172
|
+
for (const r of refs) {
|
|
173
|
+
if (!out.has(r.marketplace)) out.set(r.marketplace, []);
|
|
174
|
+
out.get(r.marketplace).push({ name: r.name, kind });
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
add(designSystemRefs(html), 'design system');
|
|
179
|
+
add(markedRefs(html), 'theme');
|
|
180
|
+
add(fontRefs(html), 'font');
|
|
181
|
+
} catch { /* a block that does not parse uses nothing */ }
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The starting server's check: when it is due, `run(['outdated', '--json'])`
|
|
187
|
+
* (the command C runs, as a child) and record the answer. Resolves to the
|
|
188
|
+
* record, or null when nothing ran or it failed — silently, either way: an
|
|
189
|
+
* unreachable source is a row on the screen, never a word at startup.
|
|
190
|
+
*/
|
|
191
|
+
export async function runAutoCheck({ run, home = configHome(), now = Date.now() } = {}) {
|
|
192
|
+
if (!autoCheckDue(home, now)) return null;
|
|
193
|
+
try {
|
|
194
|
+
const out = await run(['outdated', '--json']);
|
|
195
|
+
if (!out?.ok) return null;
|
|
196
|
+
const parsed = JSON.parse(out.stdout);
|
|
197
|
+
// the command recorded it too; recording it again keeps the dismissals either way
|
|
198
|
+
return recordCheck(parsed.marketplaces ?? [], home, { now });
|
|
199
|
+
} catch { return null; }
|
|
200
|
+
}
|