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
package/cli/git-tree.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Building a git tree without touching the working tree.
|
|
5
|
+
//
|
|
6
|
+
// Lifted out of cli/publish.mjs, which invented this, when `review submit`
|
|
7
|
+
// turned out to need exactly the same thing. It is the mechanism behind every "push something without checking
|
|
8
|
+
// anything out" in decklight: objects land in the repository's database,
|
|
9
|
+
// nothing references them until the push, and neither the working tree, the
|
|
10
|
+
// index nor the checked-out branch ever hears about it.
|
|
11
|
+
//
|
|
12
|
+
// Extracted rather than copied because the one subtle line here — git's tree
|
|
13
|
+
// ordering, which compares a directory as if its name ended in `/` — is exactly
|
|
14
|
+
// the kind of thing two copies diverge on silently. A tree sorted the other way
|
|
15
|
+
// is accepted by `mktree` and then reported by `git fsck`, long after whoever
|
|
16
|
+
// wrote the second copy has moved on.
|
|
17
|
+
//
|
|
18
|
+
// Every function takes the caller's own `git(args, input)` runner, so the cwd,
|
|
19
|
+
// the failure convention and the error wording stay the caller's business.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One tree's entries: `<mode> <type> <sha>\t<name>` per line.
|
|
23
|
+
*
|
|
24
|
+
* `--full-tree` is load-bearing and not a flourish. Plain `git ls-tree <tree>`
|
|
25
|
+
* is implicitly scoped to the CURRENT PATH PREFIX: run from `talks/` it lists
|
|
26
|
+
* `<tree>:talks` rather than the root. Both callers run git in the deck's own
|
|
27
|
+
* directory, so without this a deck in a subdirectory rebuilds the repository's
|
|
28
|
+
* whole tree from that subdirectory's contents — every sibling above it silently
|
|
29
|
+
* deleted in the pushed commit, and no error anywhere.
|
|
30
|
+
*/
|
|
31
|
+
export function lsTree(git, sha) {
|
|
32
|
+
return git(['ls-tree', '--full-tree', sha]).split('\n').filter(Boolean).map((l) => {
|
|
33
|
+
const [meta, name] = l.split('\t');
|
|
34
|
+
const [mode, type, entrySha] = meta.split(/\s+/);
|
|
35
|
+
return { mode, type, sha: entrySha, name };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Write a tree object from entries.
|
|
41
|
+
*
|
|
42
|
+
* The sort is git's own: byte-wise, with a tree's name compared as `name/`.
|
|
43
|
+
* Get it wrong and `mktree` still accepts the tree — `git fsck` is where you
|
|
44
|
+
* find out, which is much later and somewhere else.
|
|
45
|
+
*/
|
|
46
|
+
export function mktree(git, entries) {
|
|
47
|
+
const key = (e) => (e.type === 'tree' ? `${e.name}/` : e.name);
|
|
48
|
+
entries.sort((a, b) => (key(a) < key(b) ? -1 : 1));
|
|
49
|
+
return git(['mktree'], entries.map((e) => `${e.mode} ${e.type} ${e.sha}\t${e.name}\n`).join(''));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A copy of the tree at `treeish` with `blobSha` placed at `pathParts`,
|
|
54
|
+
* building intermediate trees and **keeping every sibling entry**.
|
|
55
|
+
*
|
|
56
|
+
* `treeish` may be a commit — `ls-tree` resolves it — which is why a caller can
|
|
57
|
+
* hand it the parent commit directly. `null`/`undefined` means "nothing there
|
|
58
|
+
* yet", which is how a missing intermediate directory gets created and how an
|
|
59
|
+
* orphan commit's tree is built.
|
|
60
|
+
*/
|
|
61
|
+
export function putBlob(git, treeish, pathParts, blobSha) {
|
|
62
|
+
const entries = treeish ? lsTree(git, treeish) : [];
|
|
63
|
+
const name = pathParts[0];
|
|
64
|
+
const kept = entries.filter((e) => e.name !== name);
|
|
65
|
+
if (pathParts.length === 1) {
|
|
66
|
+
kept.push({ mode: '100644', type: 'blob', sha: blobSha, name });
|
|
67
|
+
} else {
|
|
68
|
+
const sub = entries.find((e) => e.name === name && e.type === 'tree');
|
|
69
|
+
kept.push({ mode: '040000', type: 'tree', sha: putBlob(git, sub?.sha, pathParts.slice(1), blobSha), name });
|
|
70
|
+
}
|
|
71
|
+
return mktree(git, kept);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The commit a remote ref points at, fetched into FETCH_HEAD — or null when
|
|
76
|
+
* the remote has no such ref.
|
|
77
|
+
*
|
|
78
|
+
* The other half of pushing without a checkout: the PARENT, as the REMOTE has
|
|
79
|
+
* it. `ls-remote` first so a missing ref is an answer rather than a fetch
|
|
80
|
+
* error, then a destination-less fetch, so no local ref is created or moved —
|
|
81
|
+
* FETCH_HEAD is a file, not a ref, and nothing in the repository changes.
|
|
82
|
+
*/
|
|
83
|
+
export function remoteHead(git, remote, ref) {
|
|
84
|
+
if (!git(['ls-remote', remote, ref])) return null;
|
|
85
|
+
git(['fetch', '--quiet', remote, ref]);
|
|
86
|
+
return git(['rev-parse', 'FETCH_HEAD']);
|
|
87
|
+
}
|
package/cli/git.mjs
CHANGED
|
@@ -120,7 +120,19 @@ export function commitSubject(raw, fallback) {
|
|
|
120
120
|
return /^-/.test(capped) ? `agent: ${capped}` : capped;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* The sha of the commit `gitAutocommit` last made, or null.
|
|
125
|
+
*
|
|
126
|
+
* Kept beside the commit rather than returned in its place because every
|
|
127
|
+
* existing caller treats the return value as a boolean — "did anything land" —
|
|
128
|
+
* and widening that to an object would put a truthiness question in front of
|
|
129
|
+
* the safety net. `--commit-messages` is the only caller that needs the sha,
|
|
130
|
+
* and it reads it immediately.
|
|
131
|
+
*/
|
|
132
|
+
export let lastCommitSha = null;
|
|
133
|
+
|
|
123
134
|
export function gitAutocommit(deckPath, cwd, message = `decklight: autosave ${basename(deckPath)}`) {
|
|
135
|
+
lastCommitSha = null;
|
|
124
136
|
try {
|
|
125
137
|
if (!git(['status', '--porcelain', '--', deckPath], cwd)) return false;
|
|
126
138
|
git(['add', '--', deckPath], cwd);
|
|
@@ -133,9 +145,367 @@ export function gitAutocommit(deckPath, cwd, message = `decklight: autosave ${ba
|
|
|
133
145
|
git(['-c', 'user.name=decklight', '-c', 'user.email=decklight@localhost',
|
|
134
146
|
'commit', '-m', message, '--', deckPath], cwd);
|
|
135
147
|
}
|
|
148
|
+
try { lastCommitSha = git(['rev-parse', 'HEAD'], cwd); } catch { lastCommitSha = null; }
|
|
136
149
|
return true;
|
|
137
150
|
} catch (e) {
|
|
138
151
|
console.error(` git autocommit failed: ${oneline(e)}`);
|
|
139
152
|
return false;
|
|
140
153
|
}
|
|
141
154
|
}
|
|
155
|
+
|
|
156
|
+
// ── the remote half ────────────────────────────────────────────────────────
|
|
157
|
+
//
|
|
158
|
+
// Everything above is LOCAL: does a repo exist, is the tree dirty, commit it.
|
|
159
|
+
// That was the whole vocabulary, and it is why decklight could commit
|
|
160
|
+
// diligently for a week and never once mention that none of it existed anywhere
|
|
161
|
+
// but this laptop.
|
|
162
|
+
//
|
|
163
|
+
// Two rules govern this section, and both are learned rather than assumed:
|
|
164
|
+
//
|
|
165
|
+
// NEVER A HANG. `GIT_TERMINAL_PROMPT=0` is what cloneMarketplace already uses,
|
|
166
|
+
// and it is HALF the answer: it stops git's own prompts and the https askpass,
|
|
167
|
+
// while an `ssh://` remote will still sit forever on a host-key or passphrase
|
|
168
|
+
// question nobody is there to type. `ssh -oBatchMode=yes` is the other half.
|
|
169
|
+
// Blanking the askpass variables stops a GUI credential window opening behind a
|
|
170
|
+
// headless probe, without disabling real credential HELPERS (osxkeychain,
|
|
171
|
+
// libsecret), which is what makes a private remote work at all.
|
|
172
|
+
//
|
|
173
|
+
// NEVER A FETCH YOU DID NOT ASK FOR. cli/marketplace.mjs already decided this
|
|
174
|
+
// for catalogs — "nothing ever pulls into it, which is what keeps decklight out
|
|
175
|
+
// of the credential-helper trap a background `git pull` walks into" — and the
|
|
176
|
+
// same holds here. Everything the author loop reads (`unpushed`, `@{u}`) is a
|
|
177
|
+
// LOCAL read of remote-tracking refs and needs no network at all. `behind` is
|
|
178
|
+
// therefore as fresh as your last fetch, and saying so is better than fetching
|
|
179
|
+
// behind someone's back.
|
|
180
|
+
//
|
|
181
|
+
// ONE named exception: the review check at `decklight author` startup
|
|
182
|
+
// (cli/review-remote.mjs), which exists precisely because "somebody reviewed
|
|
183
|
+
// your deck" is only useful unasked. It is once, detached, off by three
|
|
184
|
+
// switches that each say why, and nowhere near a SIGINT handler — the shape
|
|
185
|
+
// update-check.mjs established. SPEC REVIEW states the contract; anything
|
|
186
|
+
// else that wants to fetch unasked argues there, not here.
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* `owner/repo` from a GitHub remote URL, or null for anything else.
|
|
190
|
+
*
|
|
191
|
+
* THE one parser — `pagesUrl` (cli/publish.mjs) derives the Pages site from it
|
|
192
|
+
* and `review submit` hands it to `gh --repo`. It lived in both files as the
|
|
193
|
+
* same regex for a while, which is exactly how one copy grows a spelling the
|
|
194
|
+
* other refuses.
|
|
195
|
+
*/
|
|
196
|
+
export function ownerRepo(remoteUrl) {
|
|
197
|
+
const m = (remoteUrl || '').trim().match(
|
|
198
|
+
/^(?:https?:\/\/(?:[^/@]+@)?|git@|ssh:\/\/git@)github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
|
|
199
|
+
);
|
|
200
|
+
return m ? { owner: m[1], repo: m[2] } : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The env every remote-touching git call runs under. See the note above. */
|
|
204
|
+
export function noPromptEnv(env = process.env) {
|
|
205
|
+
const { GIT_ASKPASS, SSH_ASKPASS, ...rest } = env;
|
|
206
|
+
return {
|
|
207
|
+
...rest,
|
|
208
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
209
|
+
GIT_SSH_COMMAND: rest.GIT_SSH_COMMAND ?? 'ssh -oBatchMode=yes -oConnectTimeout=5',
|
|
210
|
+
GCM_INTERACTIVE: 'Never',
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* `git rev-list --left-right --count @{u}...HEAD` → `{ ahead, behind }`.
|
|
216
|
+
*
|
|
217
|
+
* THE LEFT COUNT IS `behind`. With `A...B` the left side is what is reachable
|
|
218
|
+
* from A and not B; A is the upstream, so the left number is what the upstream
|
|
219
|
+
* has and you do not. Getting this backwards is the classic bug in this command
|
|
220
|
+
* — it type-checks, it looks right, and it reports your unpushed work as the
|
|
221
|
+
* other side's — so the parse is its own function with its own test.
|
|
222
|
+
*/
|
|
223
|
+
export function parseAheadBehind(out) {
|
|
224
|
+
const parts = String(out ?? '').trim().split(/\s+/);
|
|
225
|
+
if (parts.length !== 2) return null;
|
|
226
|
+
const [behind, ahead] = parts.map(Number);
|
|
227
|
+
if (!Number.isInteger(behind) || !Number.isInteger(ahead) || behind < 0 || ahead < 0) return null;
|
|
228
|
+
return { ahead, behind };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Which remote to speak of when a command has to name one.
|
|
233
|
+
*
|
|
234
|
+
* Pure, because "several remotes and none called origin" is a real repository
|
|
235
|
+
* and guessing there would put someone's work on the wrong host.
|
|
236
|
+
*/
|
|
237
|
+
export function preferredRemote(names = []) {
|
|
238
|
+
if (!names.length) return { name: null, state: 'none' };
|
|
239
|
+
if (names.includes('origin')) return { name: 'origin', state: 'ok' };
|
|
240
|
+
if (names.length === 1) return { name: names[0], state: 'ok' };
|
|
241
|
+
return { name: null, state: 'ambiguous' };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Why a remote operation failed, as a word.
|
|
246
|
+
*
|
|
247
|
+
* The distinction that matters is `denied` versus `offline`: one means "your
|
|
248
|
+
* credentials do not open this", the other "nothing was reachable", and telling
|
|
249
|
+
* someone to check their network when the answer is a missing key wastes the
|
|
250
|
+
* ten minutes before a talk. `offline` also covers the timeout, because a
|
|
251
|
+
* remote that did not answer inside the bound is indistinguishable from one
|
|
252
|
+
* that is not there — and both are answers rather than hangs.
|
|
253
|
+
*/
|
|
254
|
+
export function classifyRemoteError(e) {
|
|
255
|
+
const text = String(e?.stderr || e?.message || e || '');
|
|
256
|
+
if (e?.signal || /\bETIMEDOUT\b|timed out/i.test(text)) return 'offline';
|
|
257
|
+
if (/could not resolve host|could not resolve hostname|network is unreachable|connection refused|connection timed out|failed to connect|unable to access/i.test(text)) return 'offline';
|
|
258
|
+
if (/authentication failed|permission denied|could not read (username|password)|terminal prompts disabled|access denied|\b403\b/i.test(text)) return 'denied';
|
|
259
|
+
if (/repository not found|does not appear to be a git repository|\b404\b/i.test(text)) return 'gone';
|
|
260
|
+
return 'unknown';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Is this string safe to hand to `git remote add` as a URL?
|
|
265
|
+
*
|
|
266
|
+
* The leading-dash refusal is the point: `git remote add origin
|
|
267
|
+
* --upload-pack=…` is an argument, not a URL, and `git remote add` offers no
|
|
268
|
+
* `--` terminator to hide behind. Same reasoning as commitSubject's dash rule.
|
|
269
|
+
*/
|
|
270
|
+
export function looksLikeGitUrl(s) {
|
|
271
|
+
const v = String(s ?? '').trim();
|
|
272
|
+
if (!v || v.startsWith('-')) return false;
|
|
273
|
+
if (/^(https?|ssh|git|file):\/\//i.test(v)) return true;
|
|
274
|
+
if (/^[\w.-]+@[\w.-]+:[^\s]+$/.test(v)) return true; // scp form: git@host:owner/repo
|
|
275
|
+
return v.startsWith('/'); // a local path is a remote too
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ── the probes, and the one object that answers "where does this stand?" ────
|
|
279
|
+
|
|
280
|
+
/** Is git installed at all? `inGitRepo` swallows ENOENT, so it cannot tell you. */
|
|
281
|
+
export function gitAvailable(cwd = process.cwd(), exec = execFileSync) {
|
|
282
|
+
try { git(['--version'], cwd, exec); return true; } catch { return false; }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Every remote's name, or `[]` — a repository with none is normal, not an error. */
|
|
286
|
+
export function remoteNames(cwd, run = git) {
|
|
287
|
+
try { return run(['remote'], cwd).split('\n').map((s) => s.trim()).filter(Boolean); }
|
|
288
|
+
catch { return []; }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** A remote's URL, for display only. Nothing branches on it. */
|
|
292
|
+
export function remoteUrl(name, cwd, run = git) {
|
|
293
|
+
try { return run(['remote', 'get-url', name], cwd) || null; } catch { return null; }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* What HEAD is: a branch, a detached commit, or nothing committed yet.
|
|
298
|
+
*
|
|
299
|
+
* The order is the correctness. An unborn HEAD (`git init`, nothing committed)
|
|
300
|
+
* has a symbolic-ref but no commit, so asking about the commit first is what
|
|
301
|
+
* distinguishes it from a detached one.
|
|
302
|
+
*/
|
|
303
|
+
export function headState(cwd, run = git) {
|
|
304
|
+
try { run(['rev-parse', '--verify', '--quiet', 'HEAD'], cwd); }
|
|
305
|
+
catch { return { state: 'unborn', branch: null }; }
|
|
306
|
+
try {
|
|
307
|
+
const branch = run(['symbolic-ref', '--short', '-q', 'HEAD'], cwd);
|
|
308
|
+
return branch ? { state: 'ok', branch } : { state: 'detached', branch: null };
|
|
309
|
+
} catch { return { state: 'detached', branch: null }; }
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The branch's upstream (`origin/main`), or null when it tracks nothing. */
|
|
313
|
+
export function upstreamOf(cwd, run = git) {
|
|
314
|
+
try { return run(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], cwd) || null; }
|
|
315
|
+
catch { return null; }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** `{ ahead, behind }` against the upstream, or null. A LOCAL read — no fetch. */
|
|
319
|
+
export function aheadBehind(cwd, run = git) {
|
|
320
|
+
try { return parseAheadBehind(run(['rev-list', '--left-right', '--count', '@{u}...HEAD'], cwd)); }
|
|
321
|
+
catch { return null; }
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Commits that exist on no remote at all — the number the UI should show.
|
|
326
|
+
*
|
|
327
|
+
* Deliberately not `ahead`. This needs NO upstream, so a freshly added remote
|
|
328
|
+
* with nothing pushed still gets a truthful count where `@{u}` would simply
|
|
329
|
+
* fail; with no remotes at all it degrades to "every commit", which is exactly
|
|
330
|
+
* right ("none of this exists anywhere else"); and it is per-commit, so an
|
|
331
|
+
* overlay can mark the rows rather than print a number.
|
|
332
|
+
*/
|
|
333
|
+
export function unpushed(cwd, run = git) {
|
|
334
|
+
try { return run(['rev-list', 'HEAD', '--not', '--remotes'], cwd).split('\n').filter(Boolean); }
|
|
335
|
+
catch { return null; }
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Where this repository stands, as one object. Never throws, never networks.
|
|
340
|
+
*
|
|
341
|
+
* Resolution is ordered and short-circuits, because each state makes the next
|
|
342
|
+
* question meaningless: you cannot be behind a remote you do not have, and you
|
|
343
|
+
* cannot be ahead of an upstream when HEAD is not on a branch.
|
|
344
|
+
*/
|
|
345
|
+
export function remoteState(cwd, { run = git, exec = execFileSync } = {}) {
|
|
346
|
+
const nothing = { remote: null, url: null, branch: null, upstream: null, ahead: null, behind: null, unpushed: null, why: null };
|
|
347
|
+
if (!gitAvailable(cwd, exec)) return { ...nothing, state: 'no-git' };
|
|
348
|
+
if (!inGitRepo(cwd, exec)) return { ...nothing, state: 'no-repo' };
|
|
349
|
+
|
|
350
|
+
const head = headState(cwd, run);
|
|
351
|
+
if (head.state === 'unborn') return { ...nothing, state: 'unborn' };
|
|
352
|
+
|
|
353
|
+
const local = unpushed(cwd, run);
|
|
354
|
+
const base = { ...nothing, branch: head.branch, unpushed: local ? local.length : null };
|
|
355
|
+
if (head.state === 'detached') return { ...base, state: 'detached' };
|
|
356
|
+
|
|
357
|
+
const picked = preferredRemote(remoteNames(cwd, run));
|
|
358
|
+
if (picked.state === 'none') return { ...base, state: 'no-remote' };
|
|
359
|
+
if (picked.state === 'ambiguous') return { ...base, state: 'ambiguous-remote' };
|
|
360
|
+
|
|
361
|
+
const withRemote = { ...base, remote: picked.name, url: remoteUrl(picked.name, cwd, run) };
|
|
362
|
+
const upstream = upstreamOf(cwd, run);
|
|
363
|
+
if (!upstream) return { ...withRemote, state: 'no-upstream' };
|
|
364
|
+
|
|
365
|
+
const counts = aheadBehind(cwd, run);
|
|
366
|
+
if (!counts) return { ...withRemote, upstream, state: 'unreadable', why: 'could not count against the upstream' };
|
|
367
|
+
return { ...withRemote, upstream, ...counts, state: 'ok' };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// ── the words ──────────────────────────────────────────────────────────────
|
|
371
|
+
//
|
|
372
|
+
// Four places tell you about unpushed work — a toast while authoring, a line
|
|
373
|
+
// when author mode exits, the history overlay's footer, and `decklight
|
|
374
|
+
// history` — and they must not disagree. So none of them writes a sentence:
|
|
375
|
+
// they all call one of the three functions below. A wording change is then a
|
|
376
|
+
// diff in one file with a test beside it, rather than four strings that were
|
|
377
|
+
// the same in March.
|
|
378
|
+
|
|
379
|
+
/** The push command that would actually work here, given what is set up. */
|
|
380
|
+
const pushCommand = (s) => (s.state === 'no-upstream'
|
|
381
|
+
? `git push -u ${s.remote} ${s.branch}`
|
|
382
|
+
: 'git push');
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Is there something to nudge about, and how much? `null` for "say nothing".
|
|
386
|
+
*
|
|
387
|
+
* The `ahead === 0` row returning null is the do-not-nag guarantee, and it is
|
|
388
|
+
* stated here rather than at each call site so it cannot be forgotten at one of
|
|
389
|
+
* them. A repository with NO remote also returns null: telling someone to push
|
|
390
|
+
* when there is nowhere to push is noise, and that nudge belongs to `init`.
|
|
391
|
+
*/
|
|
392
|
+
export function pushHint(s) {
|
|
393
|
+
if (!s || ['no-git', 'no-repo', 'unborn', 'unreadable'].includes(s.state)) return null;
|
|
394
|
+
if (s.state === 'detached') return { kind: 'detached', n: 0, text: 'detached HEAD — there is no branch to push' };
|
|
395
|
+
if (s.state === 'no-remote' || s.state === 'ambiguous-remote') return null;
|
|
396
|
+
const n = s.state === 'ok' ? s.ahead : s.unpushed;
|
|
397
|
+
if (!n) return null;
|
|
398
|
+
return { kind: s.state === 'ok' ? 'unpushed' : 'no-upstream', n, text: `↑${n} unpushed — ${pushCommand(s)}` };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The line author mode prints on its way out, or null for a clean exit.
|
|
403
|
+
*
|
|
404
|
+
* This one DOES speak up when there is no remote, unlike `pushHint` — the end
|
|
405
|
+
* of a session is the moment when "this only exists here" is worth knowing, and
|
|
406
|
+
* it is said once rather than every few minutes.
|
|
407
|
+
*/
|
|
408
|
+
export function exitPushLine(s) {
|
|
409
|
+
if (!s) return null;
|
|
410
|
+
if (s.state === 'no-remote' || s.state === 'ambiguous-remote') {
|
|
411
|
+
return s.unpushed
|
|
412
|
+
? ` this deck's history is only on this machine — back it up: git remote add origin <url>`
|
|
413
|
+
: null;
|
|
414
|
+
}
|
|
415
|
+
const hint = pushHint(s);
|
|
416
|
+
if (!hint || !hint.n) return null;
|
|
417
|
+
return ` ↑${hint.n} commit${hint.n === 1 ? '' : 's'} only on this machine — ${pushCommand(s)}`;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The one-line readout `decklight history` and the overlay footer both show. */
|
|
421
|
+
export function remoteLine(s) {
|
|
422
|
+
if (!s) return '';
|
|
423
|
+
switch (s.state) {
|
|
424
|
+
case 'no-git': return 'git is not installed';
|
|
425
|
+
case 'no-repo': return 'not in a git repository';
|
|
426
|
+
case 'unborn': return 'nothing committed yet';
|
|
427
|
+
case 'detached': return `detached HEAD · ${s.unpushed ?? 0} commits here`;
|
|
428
|
+
case 'no-remote': return `${s.branch} · no remote — this history is only on this machine`;
|
|
429
|
+
case 'ambiguous-remote': return `${s.branch} · several remotes, none named origin — push by name`;
|
|
430
|
+
case 'no-upstream': return s.unpushed
|
|
431
|
+
? `${s.branch} → no upstream (${s.remote} exists) · ↑${s.unpushed} never pushed`
|
|
432
|
+
: `${s.branch} → no upstream — ${s.remote} exists but this branch tracks nothing`;
|
|
433
|
+
case 'unreadable': return `${s.branch} → ${s.upstream} · could not be counted`;
|
|
434
|
+
default: {
|
|
435
|
+
const bits = [`${s.branch} → ${s.upstream}`];
|
|
436
|
+
if (s.ahead) bits.push(`↑${s.ahead} unpushed`);
|
|
437
|
+
if (s.behind) bits.push(`↓${s.behind} behind`);
|
|
438
|
+
if (!s.ahead && !s.behind) bits.push('all pushed');
|
|
439
|
+
return bits.join(' · ');
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// ── what else rides along ──────────────────────────────────────────────────
|
|
445
|
+
//
|
|
446
|
+
// A fast-forward updates the WHOLE working tree. If the deck shares a
|
|
447
|
+
// repository with anything else, "update the deck" quietly means "update the
|
|
448
|
+
// source tree, the CI config and the scripts too" — and the person clicking is
|
|
449
|
+
// thinking about a slide.
|
|
450
|
+
//
|
|
451
|
+
// The measure is deliberately what a given change WOULD touch rather than what
|
|
452
|
+
// the repository contains, because that is the number worth interrupting for:
|
|
453
|
+
// a repo that holds only a deck stays silent, and one that holds a product says
|
|
454
|
+
// so with the file names.
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Split a list of paths into the deck's own and everything else.
|
|
458
|
+
*
|
|
459
|
+
* Pure, and the definition of "the deck's own" is the interesting part: the
|
|
460
|
+
* deck file plus anything under the directory it lives in. Themes, images and
|
|
461
|
+
* narration travel WITH a deck and are not a surprise; `src/server.js` is.
|
|
462
|
+
* Paths arrive relative to the repository root, which is how git reports them.
|
|
463
|
+
*/
|
|
464
|
+
export function splitDeckPaths(paths = [], deckRelPath = '') {
|
|
465
|
+
const deck = String(deckRelPath).replace(/^\.\//, '');
|
|
466
|
+
const dir = deck.includes('/') ? `${deck.slice(0, deck.lastIndexOf('/'))}/` : '';
|
|
467
|
+
const own = [];
|
|
468
|
+
const foreign = [];
|
|
469
|
+
for (const p of paths) {
|
|
470
|
+
const rel = String(p).replace(/^\.\//, '');
|
|
471
|
+
if (!rel) continue;
|
|
472
|
+
(rel === deck || (dir && rel.startsWith(dir)) ? own : foreign).push(rel);
|
|
473
|
+
}
|
|
474
|
+
return { own, foreign };
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* What pulling `range` would change, and how much of it is not the deck.
|
|
479
|
+
*
|
|
480
|
+
* `range` is `HEAD..@{u}` for a pull; the same shape answers "what would be
|
|
481
|
+
* pushed" for a range the other way round. Unreadable is `null` — a warning
|
|
482
|
+
* nobody can compute must not become a warning nobody can dismiss.
|
|
483
|
+
*/
|
|
484
|
+
export function foreignChanges(cwd, deckRelPath, range = 'HEAD..@{u}', run = git) {
|
|
485
|
+
let paths;
|
|
486
|
+
try { paths = run(['diff', '--name-only', range], cwd).split('\n').filter(Boolean); }
|
|
487
|
+
catch { return null; }
|
|
488
|
+
const { own, foreign } = splitDeckPaths(paths, deckRelPath);
|
|
489
|
+
return { total: paths.length, own, foreign };
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The warning itself, or null when there is nothing surprising to say.
|
|
494
|
+
*
|
|
495
|
+
* Names three files and counts the rest: a wall of paths is skimmed, and three
|
|
496
|
+
* is enough to recognise what kind of repository this is. The recommendation is
|
|
497
|
+
* the last line because it is the fix, not the finding.
|
|
498
|
+
*/
|
|
499
|
+
export function foreignWarning(changes, { verb = 'pull', scope = 'the whole working tree' } = {}) {
|
|
500
|
+
if (!changes || !changes.foreign.length) return null;
|
|
501
|
+
const { total, foreign } = changes;
|
|
502
|
+
const shown = foreign.slice(0, 3).join(' · ');
|
|
503
|
+
const more = foreign.length > 3 ? ` · … ${foreign.length - 3} more` : '';
|
|
504
|
+
return [
|
|
505
|
+
`this ${verb} would change ${total} file${total === 1 ? '' : 's'}, `
|
|
506
|
+
+ `${foreign.length} of them not the deck:`,
|
|
507
|
+
` ${shown}${more}`,
|
|
508
|
+
`a ${verb} updates ${scope} — if that is not what you want here, keep the deck`
|
|
509
|
+
+ ' in a repository of its own',
|
|
510
|
+
];
|
|
511
|
+
}
|
package/cli/history.mjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Gilles Philippart
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `decklight history <deck.html>` — what decklight committed, and where it
|
|
7
|
+
* stands against the remote.
|
|
8
|
+
*
|
|
9
|
+
* WHY THIS IS NOT `decklight restore`. `restore` already prints this list, and
|
|
10
|
+
* for a while that was the argument against a second command. But its listing
|
|
11
|
+
* is a MEANS: the footer says `Restore one with: …`, and it exits 1 when there
|
|
12
|
+
* is nothing to restore, because it is an action that could not be performed.
|
|
13
|
+
* This is a READOUT. It answers "where does this deck stand", nobody types
|
|
14
|
+
* "restore" to ask that, and it must not fail just because the answer is
|
|
15
|
+
* "nowhere yet" — a readout that exits non-zero on an empty history breaks
|
|
16
|
+
* `decklight history && …` and reads as a malfunction.
|
|
17
|
+
*
|
|
18
|
+
* What it adds over that listing is the half `restore` has no business knowing:
|
|
19
|
+
* which commits exist nowhere but this machine, and what to type about it.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
23
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
24
|
+
import { deckHistory, formatEntry } from './restore.mjs';
|
|
25
|
+
import {
|
|
26
|
+
gitAvailable, inGitRepo, oneline, pushHint, remoteLine, remoteState, unpushed,
|
|
27
|
+
} from './git.mjs';
|
|
28
|
+
import { argReader, isMain } from '../tools/args.mjs';
|
|
29
|
+
|
|
30
|
+
const HELP = `decklight history [deck.html] — the commits behind a deck, and what is unpushed
|
|
31
|
+
|
|
32
|
+
-n <count> how many to show (default 20)
|
|
33
|
+
--all every commit
|
|
34
|
+
--help, -h this
|
|
35
|
+
|
|
36
|
+
A readout, never a write. To go back to one of these: decklight restore <deck> <hash>
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
/** Marks each entry with whether it exists anywhere but here. Pure. */
|
|
40
|
+
export function markPushState(entries, localHashes) {
|
|
41
|
+
const set = localHashes ? new Set(localHashes) : null;
|
|
42
|
+
return entries.map((e) => ({ ...e, pushed: set ? !set.has(e.full) : null }));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The single deck in `dir`, or null when the answer is not single.
|
|
47
|
+
*
|
|
48
|
+
* Nothing else in the CLI infers a deck, so the inference is deliberately
|
|
49
|
+
* narrow: a `.html` file that carries decklight's own runtime marker. A folder
|
|
50
|
+
* with three decks gets a refusal that names them rather than a guess.
|
|
51
|
+
*/
|
|
52
|
+
export function findDeck(dir, read = readFileSync, list = readdirSync) {
|
|
53
|
+
let names;
|
|
54
|
+
try { names = list(dir).filter((f) => /\.html?$/i.test(f)); } catch { return { decks: [] }; }
|
|
55
|
+
const decks = names.filter((f) => {
|
|
56
|
+
try { return /data-decklight-runtime|Decklight\s*\.\s*init/.test(read(join(dir, f), 'utf8')); }
|
|
57
|
+
catch { return false; }
|
|
58
|
+
});
|
|
59
|
+
return { decks };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function historyMain(argv = process.argv.slice(2)) {
|
|
63
|
+
const { opt } = argReader(argv);
|
|
64
|
+
if (argv.includes('--help') || argv.includes('-h')) { process.stdout.write(HELP); return 0; }
|
|
65
|
+
|
|
66
|
+
const cwd = process.cwd();
|
|
67
|
+
let deckArg = argv.find((a) => !a.startsWith('-') && /\.html?$/i.test(a));
|
|
68
|
+
if (!deckArg) {
|
|
69
|
+
const { decks } = findDeck(cwd);
|
|
70
|
+
if (decks.length === 1) [deckArg] = decks;
|
|
71
|
+
else if (!decks.length) {
|
|
72
|
+
console.error('decklight history: name the deck — no decklight deck found in this directory');
|
|
73
|
+
return 1;
|
|
74
|
+
} else {
|
|
75
|
+
console.error(`decklight history: name the deck — this directory has ${decks.length}`
|
|
76
|
+
+ ` (${decks.slice(0, 4).join(', ')}${decks.length > 4 ? ', …' : ''})`);
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const deckPath = resolve(cwd, deckArg);
|
|
82
|
+
const name = basename(deckPath);
|
|
83
|
+
if (!existsSync(deckPath)) { console.error(`decklight history: no such file: ${deckArg}`); return 1; }
|
|
84
|
+
|
|
85
|
+
const root = dirname(deckPath);
|
|
86
|
+
// git missing and "not a repository" are different answers, and inGitRepo
|
|
87
|
+
// swallows the first into the second.
|
|
88
|
+
if (!gitAvailable(root)) {
|
|
89
|
+
console.error('decklight history: git is not installed — decklight\'s durable record needs it');
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
if (!inGitRepo(root)) {
|
|
93
|
+
console.error(`decklight history: ${name} is not in a git repository — there is no history yet`
|
|
94
|
+
+ ' (decklight init --git, or git init)');
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The state comes first because it answers the question that would otherwise
|
|
99
|
+
// look like a failure: in a repository with no commits at all, `git log`
|
|
100
|
+
// exits non-zero ("does not have any commits yet"), and reporting that as a
|
|
101
|
+
// read error would turn the ordinary first minute of a deck's life into an
|
|
102
|
+
// error message.
|
|
103
|
+
const state = remoteState(root);
|
|
104
|
+
if (state.state === 'unborn') {
|
|
105
|
+
console.log(`${name} — nothing committed yet`);
|
|
106
|
+
console.log(' the repository exists; the first commit does not');
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let entries;
|
|
111
|
+
try { entries = deckHistory(deckPath, root); }
|
|
112
|
+
catch (e) { console.error(`decklight history: could not read the history: ${oneline(e)}`); return 1; }
|
|
113
|
+
const marked = markPushState(entries, ['no-remote', 'ambiguous-remote'].includes(state.state)
|
|
114
|
+
? null : unpushed(root));
|
|
115
|
+
|
|
116
|
+
// Not an error: a deck git has never seen is a true and useful answer, and it
|
|
117
|
+
// is the state every new deck starts in.
|
|
118
|
+
if (!marked.length) {
|
|
119
|
+
console.log(`${name} — git has no record of this file yet`);
|
|
120
|
+
console.log(` ${remoteLine(state)}`);
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const all = argv.includes('--all');
|
|
125
|
+
const limit = all ? marked.length : Math.max(1, Number(opt('-n', 20)) || 20);
|
|
126
|
+
const shown = marked.slice(0, limit);
|
|
127
|
+
const pad = Math.max(...shown.map((e) => e.when.length));
|
|
128
|
+
|
|
129
|
+
console.log(`${name} — ${marked.length} commit${marked.length === 1 ? '' : 's'}, newest first\n`);
|
|
130
|
+
for (const e of shown) {
|
|
131
|
+
// The ↑ trails the row rather than leading it, so the hashes still line up
|
|
132
|
+
// and an all-pushed deck reads clean rather than column-padded.
|
|
133
|
+
console.log(` ${formatEntry(e, pad)}${e.pushed === false ? ' ↑' : ''}`);
|
|
134
|
+
}
|
|
135
|
+
if (marked.length > shown.length) console.log(` … ${marked.length - shown.length} more (--all)`);
|
|
136
|
+
|
|
137
|
+
console.log(`\n ${remoteLine(state)}`);
|
|
138
|
+
const hint = pushHint(state);
|
|
139
|
+
if (hint) console.log(` ${hint.text.replace(/^↑\d+ unpushed — /, 'push them with: ')}`);
|
|
140
|
+
console.log(` restore one with: decklight restore ${relative(cwd, deckPath) || name}`
|
|
141
|
+
+ ` ${shown[Math.min(1, shown.length - 1)].hash}`);
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (isMain(import.meta.url)) process.exit(historyMain());
|