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,475 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `--commit-messages` — an agent writes the subject decklight would otherwise
|
|
6
|
+
* template (SPEC `PRESENTING`).
|
|
7
|
+
*
|
|
8
|
+
* The wall of `decklight: autosave deck.html` is the problem. It is what the
|
|
9
|
+
* cadence has to say when nobody told it what changed, and after an afternoon
|
|
10
|
+
* the H overlay is a column of the same sentence with no way to see what
|
|
11
|
+
* happened when. An agent reading the diff can say `tighten the four-variables
|
|
12
|
+
* build to one line per idea` instead.
|
|
13
|
+
*
|
|
14
|
+
* THE COMMIT LANDS FIRST, ALWAYS. Autocommit exists so a crash cannot cost you
|
|
15
|
+
* an afternoon, and nothing here is allowed to weaken that: decklight commits
|
|
16
|
+
* with its own template exactly as before, and the agent's subject arrives
|
|
17
|
+
* afterwards as an amend. So a slow agent, a wedged agent, a missing agent, an
|
|
18
|
+
* agent that answers a paragraph of prose — every one of those costs a
|
|
19
|
+
* generically-worded commit, never a lost one.
|
|
20
|
+
*
|
|
21
|
+
* That ordering is also why the amend is safe. It rewrites one message, on the
|
|
22
|
+
* tip commit, seconds old, that nothing has been built on: the guard refuses
|
|
23
|
+
* the moment HEAD has moved or the commit has reached a remote.
|
|
24
|
+
*
|
|
25
|
+
* OPT-IN, and the reason is not cost. A diff of your deck goes to whichever
|
|
26
|
+
* agent CLI is installed, and most of them are cloud-backed. decklight does not
|
|
27
|
+
* infer that permission from what happens to be on PATH — the same rule
|
|
28
|
+
* `lipsync --veo` follows for the one part of it that leaves the machine.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { execFile } from 'node:child_process';
|
|
32
|
+
import { readFileSync } from 'node:fs';
|
|
33
|
+
import { basename, relative } from 'node:path';
|
|
34
|
+
import { agentAsk } from './agents.mjs';
|
|
35
|
+
import { commitSubject, git } from './git.mjs';
|
|
36
|
+
|
|
37
|
+
/** How much diff the agent is shown. */
|
|
38
|
+
export const MAX_DIFF = 24 * 1024;
|
|
39
|
+
|
|
40
|
+
/** How long it may take before the commit keeps the message it already has. */
|
|
41
|
+
export const ASK_TIMEOUT_MS = 45_000;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The change a commit made to the deck, trimmed to something worth sending.
|
|
45
|
+
*
|
|
46
|
+
* `--unified=1` and a byte cap, because the unit here is a single-file HTML
|
|
47
|
+
* deck: swapping a theme rewrites a 70 KB `<style>` block, and a bundled deck
|
|
48
|
+
* carries its whole runtime inline. An unbounded diff would be most of a
|
|
49
|
+
* megabyte of machine-generated CSS with the author's two edited sentences
|
|
50
|
+
* somewhere inside it — slower, more expensive, and harder to summarise than
|
|
51
|
+
* the same diff cut off.
|
|
52
|
+
*
|
|
53
|
+
* Truncation is SAID rather than hidden: an agent that knows it is seeing part
|
|
54
|
+
* of a change writes a subject about the part it saw, instead of a confident
|
|
55
|
+
* one about a change it never read.
|
|
56
|
+
*/
|
|
57
|
+
export function changeDiff(cwd, sha, deckRel, { max = MAX_DIFF, run = git } = {}) {
|
|
58
|
+
const out = run(['show', '--format=', '--unified=1', sha, '--', deckRel], cwd) ?? '';
|
|
59
|
+
if (out.length <= max) return { diff: out, truncated: false };
|
|
60
|
+
return { diff: out.slice(0, max), truncated: true };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** How many slide headings the prompt lists before it says "and N more". */
|
|
64
|
+
export const MAX_SLIDES_NAMED = 6;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The NEW-file line ranges a diff touches. Pure.
|
|
68
|
+
*
|
|
69
|
+
* Only the `+` side: the question is what the deck says now, and a heading
|
|
70
|
+
* looked up in the version that no longer exists would name the slide a line
|
|
71
|
+
* used to be on.
|
|
72
|
+
*/
|
|
73
|
+
export function parseHunks(diff) {
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const m of String(diff ?? '').matchAll(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/gm)) {
|
|
76
|
+
const start = Number(m[1]);
|
|
77
|
+
const count = m[2] === undefined ? 1 : Number(m[2]);
|
|
78
|
+
if (Number.isFinite(start) && Number.isFinite(count)) out.push({ start, count });
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The deck's slides as `{ index, heading, from, to }`, by line. Pure.
|
|
85
|
+
*
|
|
86
|
+
* A depth counter rather than a regex over the whole document, because a slide
|
|
87
|
+
* may contain a nested `<section>` and only the top-level ones are slides —
|
|
88
|
+
* the same rule the runtime applies when it counts them.
|
|
89
|
+
*/
|
|
90
|
+
export function deckOutline(html) {
|
|
91
|
+
const lines = String(html ?? '').split('\n');
|
|
92
|
+
const slides = [];
|
|
93
|
+
let depth = 0;
|
|
94
|
+
let open = null;
|
|
95
|
+
lines.forEach((line, i) => {
|
|
96
|
+
const opens = (line.match(/<section\b/gi) ?? []).length;
|
|
97
|
+
const closes = (line.match(/<\/section\s*>/gi) ?? []).length;
|
|
98
|
+
for (let k = 0; k < opens; k++) {
|
|
99
|
+
if (depth === 0) open = { index: slides.length + 1, heading: null, from: i + 1, to: i + 1 };
|
|
100
|
+
depth += 1;
|
|
101
|
+
}
|
|
102
|
+
if (open && !open.heading) {
|
|
103
|
+
const h = /<h[12][^>]*>([\s\S]*?)<\/h[12]>/i.exec(line);
|
|
104
|
+
if (h) open.heading = h[1].replace(/<[^>]*>/g, '').replace(/\s+/g, ' ').trim() || null;
|
|
105
|
+
}
|
|
106
|
+
for (let k = 0; k < closes; k++) {
|
|
107
|
+
depth = Math.max(0, depth - 1);
|
|
108
|
+
if (depth === 0 && open) { open.to = i + 1; slides.push(open); open = null; }
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (open) { open.to = lines.length; slides.push(open); }
|
|
112
|
+
return slides;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Which slides a diff touched, in order. Pure.
|
|
117
|
+
*
|
|
118
|
+
* This is the context the agent could not otherwise have. `--unified=1` shows
|
|
119
|
+
* it the changed line and one line either side, and git's own hunk header is
|
|
120
|
+
* worse than nothing on a deck — the function-context heuristic picks the last
|
|
121
|
+
* thing that looked like a definition, which in a single-file deck is a CSS
|
|
122
|
+
* selector from the inlined stylesheet thousands of lines above. A real run
|
|
123
|
+
* offered `mtable.tml-small mtd {` for an edit to a slide's table, and the
|
|
124
|
+
* agent, with nothing better, invented a framing the deck never had.
|
|
125
|
+
*
|
|
126
|
+
* An empty result is itself an answer, and a useful one: the change is in the
|
|
127
|
+
* theme, the runtime or the metadata rather than in anything the audience
|
|
128
|
+
* sees, and a subject about "the slides" would be fiction.
|
|
129
|
+
*/
|
|
130
|
+
export function changedSlides(html, diff) {
|
|
131
|
+
const slides = deckOutline(html);
|
|
132
|
+
if (!slides.length) return [];
|
|
133
|
+
const hit = new Set();
|
|
134
|
+
for (const { start, count } of parseHunks(diff)) {
|
|
135
|
+
const last = start + Math.max(count, 1) - 1;
|
|
136
|
+
for (const s of slides) if (s.from <= last && s.to >= start) hit.add(s.index);
|
|
137
|
+
}
|
|
138
|
+
return slides.filter((s) => hit.has(s.index));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** `<title>` — what the deck calls itself. */
|
|
142
|
+
export function deckTitle(html) {
|
|
143
|
+
const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(String(html ?? ''));
|
|
144
|
+
return m ? m[1].replace(/\s+/g, ' ').trim() || null : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The deck as it stood at `sha`, for the two questions above. Best effort:
|
|
149
|
+
* without it the prompt simply carries less context, which is where this
|
|
150
|
+
* feature started.
|
|
151
|
+
*/
|
|
152
|
+
export function deckAtCommit(cwd, sha, deckRel, { run = git } = {}) {
|
|
153
|
+
try { return run(['show', `${sha}:./${deckRel}`], cwd) ?? ''; } catch { return ''; }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* What the agent is asked. Pure, so the wording is reviewable without an agent.
|
|
158
|
+
*
|
|
159
|
+
* Every constraint here exists because of how the answer is used: it goes
|
|
160
|
+
* straight into `git commit --amend -m`, so it has to be ONE line, short
|
|
161
|
+
* enough to survive `commitSubject`'s 72-character cap unmangled, and free of
|
|
162
|
+
* the conversational framing every CLI adds by default. Asking for the bare
|
|
163
|
+
* line is worth more than parsing one out afterwards.
|
|
164
|
+
*/
|
|
165
|
+
export function messagePrompt({ deck, diff, truncated, template, title = null, slides = [] }) {
|
|
166
|
+
// WHERE the change is, before WHAT it is. Without this the agent sees the
|
|
167
|
+
// changed line and one line either side of it — enough to say a row was
|
|
168
|
+
// added to a table, not enough to know which talk the table is in, and an
|
|
169
|
+
// agent with a gap will fill it. It did: a row added to a brewing deck's
|
|
170
|
+
// troubleshooting table came back as "the espresso troubleshooting table",
|
|
171
|
+
// a word that appears nowhere in the deck.
|
|
172
|
+
const named = slides.slice(0, MAX_SLIDES_NAMED)
|
|
173
|
+
.map((s) => ` slide ${s.index}${s.heading ? ` — "${s.heading}"` : ' (no heading)'}`);
|
|
174
|
+
const more = slides.length - named.length;
|
|
175
|
+
const where = slides.length
|
|
176
|
+
? ['The change is on:', ...named, ...(more > 0 ? [` …and ${more} more`] : [])]
|
|
177
|
+
// Not a shrug: a change outside every <section> is the theme, the runtime
|
|
178
|
+
// or the metadata, and a subject about "the slides" would be fiction.
|
|
179
|
+
: ['This change touches NO slide — it is in the theme, the inlined runtime,',
|
|
180
|
+
'or the deck\'s metadata. Say that, rather than describing slide content.'];
|
|
181
|
+
return [
|
|
182
|
+
`Write the git commit subject for this change to "${deck}", a Decklight deck`,
|
|
183
|
+
'(a single-file HTML presentation; one top-level <section> per slide).',
|
|
184
|
+
'',
|
|
185
|
+
...(title ? [`The deck is titled "${title}".`] : []),
|
|
186
|
+
...where,
|
|
187
|
+
'',
|
|
188
|
+
'Rules:',
|
|
189
|
+
'- ONE line. No body, no preamble, no quotes, no markdown, no trailing period.',
|
|
190
|
+
'- At most 72 characters.',
|
|
191
|
+
'- Say what changed and why it matters to the talk, not which lines moved.',
|
|
192
|
+
' "cut the pour-over slide down to one claim" — not "edit deck.html".',
|
|
193
|
+
'- Describe the slides, not the HTML: a reader of this log is looking for a',
|
|
194
|
+
' moment in the deck, not a diff.',
|
|
195
|
+
'- Name a slide by its own words, never by its number: "the troubleshooting',
|
|
196
|
+
' table" beats "slide 4", which stops being true the moment one is inserted.',
|
|
197
|
+
'- Reply with the subject line and nothing else.',
|
|
198
|
+
'',
|
|
199
|
+
truncated
|
|
200
|
+
? 'The diff below is TRUNCATED — describe only what you can see in it.'
|
|
201
|
+
: 'The diff:',
|
|
202
|
+
'',
|
|
203
|
+
diff,
|
|
204
|
+
'',
|
|
205
|
+
`If the diff says nothing useful, reply with exactly: ${template}`,
|
|
206
|
+
].join('\n');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The subject inside whatever the CLI printed.
|
|
211
|
+
*
|
|
212
|
+
* Agents are chatty and inconsistently so: some answer the bare line, some wrap
|
|
213
|
+
* it in a code fence, some open with "Here's the commit message:". The rule is
|
|
214
|
+
* the LAST non-empty line that is not obviously framing — last, because the
|
|
215
|
+
* preamble comes first and the answer comes last, and because a CLI's own
|
|
216
|
+
* trailing banner is stripped by the same filters that catch the preamble.
|
|
217
|
+
*
|
|
218
|
+
* Deliberately not clever. Anything this does not recognise falls through to
|
|
219
|
+
* the caller's fallback, which is the templated subject the commit already has
|
|
220
|
+
* — a wrong-but-confident subject is worse than a generic one.
|
|
221
|
+
*/
|
|
222
|
+
export function subjectFrom(raw) {
|
|
223
|
+
const lines = String(raw ?? '')
|
|
224
|
+
.split('\n')
|
|
225
|
+
.map((l) => l.replace(/^\s*[-*>]\s+/, '').trim())
|
|
226
|
+
.filter(Boolean)
|
|
227
|
+
// fences, banners, and the "here is your answer" line every CLI has
|
|
228
|
+
.filter((l) => !/^```/.test(l))
|
|
229
|
+
.filter((l) => !/^(here'?s?|sure|okay|certainly|the commit|commit message)\b/i.test(l))
|
|
230
|
+
.filter((l) => !/^\[?(info|warn|error|debug)\]?[: ]/i.test(l));
|
|
231
|
+
const last = lines[lines.length - 1];
|
|
232
|
+
if (!last) return null;
|
|
233
|
+
// strip surrounding quotes/backticks an agent added around the line itself
|
|
234
|
+
const bare = last.replace(/^["'`]+|["'`]+$/g, '').replace(/\.$/, '').trim();
|
|
235
|
+
return bare || null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Is `sha` still the tip, and still only here?
|
|
240
|
+
*
|
|
241
|
+
* The two conditions that make amending a message a formatting change rather
|
|
242
|
+
* than a rewrite of history. If a commit landed in between — the agent flow's
|
|
243
|
+
* own commit, a restore, a second cadence tick — the message we were about to
|
|
244
|
+
* fix belongs to a commit that is no longer the one we are on, and rewriting
|
|
245
|
+
* anything below the tip is not something this feature is allowed to do.
|
|
246
|
+
*/
|
|
247
|
+
export function amendable(cwd, sha, { run = git } = {}) {
|
|
248
|
+
try {
|
|
249
|
+
if (run(['rev-parse', 'HEAD'], cwd) !== sha) return false;
|
|
250
|
+
// `--remotes` needs no upstream, and answers for a repo with no remote at
|
|
251
|
+
// all — where nothing is pushed and every commit is fair game.
|
|
252
|
+
return (run(['branch', '--remotes', '--contains', sha], cwd) ?? '') === '';
|
|
253
|
+
} catch { return false; }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Replace the tip's subject, leaving its tree, author and date alone. */
|
|
257
|
+
export function amendSubject(cwd, sha, subject, { run = git } = {}) {
|
|
258
|
+
if (!amendable(cwd, sha, { run })) return false;
|
|
259
|
+
try {
|
|
260
|
+
run(['commit', '--amend', '--only', '--no-edit', '-m', subject], cwd);
|
|
261
|
+
return true;
|
|
262
|
+
} catch { return false; }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Run the agent and resolve its stdout, or null. Never rejects. */
|
|
266
|
+
function ask(cmd, cwd, timeoutMs) {
|
|
267
|
+
return new Promise((resolve) => {
|
|
268
|
+
let done = false;
|
|
269
|
+
const finish = (v) => { if (!done) { done = true; resolve(v); } };
|
|
270
|
+
let child;
|
|
271
|
+
try {
|
|
272
|
+
child = execFile(cmd.bin, cmd.args, {
|
|
273
|
+
cwd,
|
|
274
|
+
timeout: timeoutMs,
|
|
275
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
276
|
+
// The agent is being asked a question about a diff it is given in the
|
|
277
|
+
// prompt; it needs no input and a CLI that waits on one would otherwise
|
|
278
|
+
// hang until the timeout.
|
|
279
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
280
|
+
}, (err, stdout) => finish(err && !stdout ? null : String(stdout ?? '')));
|
|
281
|
+
} catch { return finish(null); }
|
|
282
|
+
child.on('error', () => finish(null));
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Give commit `sha` a subject an agent wrote. Resolves to the new subject, or
|
|
288
|
+
* null when anything at all did not work out.
|
|
289
|
+
*
|
|
290
|
+
* Asynchronous and unawaited by design — see the note at the top of the file.
|
|
291
|
+
* The caller has already committed.
|
|
292
|
+
*/
|
|
293
|
+
export async function describeCommit({
|
|
294
|
+
cwd, sha, deckPath, template, agent = null,
|
|
295
|
+
env = process.env, timeoutMs = ASK_TIMEOUT_MS, run = git, exec = ask,
|
|
296
|
+
// Injected alongside `exec`, and it has to be: a caller that supplies the
|
|
297
|
+
// RUNNER is not asking whether this machine happens to have an agent CLI on
|
|
298
|
+
// PATH. Leaving this one un-injectable made the tests pass here and fail on
|
|
299
|
+
// CI — for the honest reason that CI installs no agent, so the resolver said
|
|
300
|
+
// no before the fake runner was ever reached.
|
|
301
|
+
resolve = agentAsk,
|
|
302
|
+
} = {}) {
|
|
303
|
+
const deck = basename(deckPath);
|
|
304
|
+
const cmd = resolve(agent, 'x', { env });
|
|
305
|
+
if (!cmd) return null;
|
|
306
|
+
// Checked BEFORE the agent is spawned as well as after: a commit that has
|
|
307
|
+
// already been superseded is one whose message nobody will ever see, and
|
|
308
|
+
// paying an agent to describe it would be the feature's own busywork.
|
|
309
|
+
if (!amendable(cwd, sha, { run })) return null;
|
|
310
|
+
|
|
311
|
+
const rel = relative(cwd, deckPath) || deck;
|
|
312
|
+
let diff;
|
|
313
|
+
try { diff = changeDiff(cwd, sha, rel, { run }); }
|
|
314
|
+
catch { return null; }
|
|
315
|
+
if (!diff.diff.trim()) return null;
|
|
316
|
+
|
|
317
|
+
// The deck AT the commit, not on disk: the working tree may have moved on
|
|
318
|
+
// while the agent was being asked, and a heading read from it would name a
|
|
319
|
+
// slide the commit does not contain.
|
|
320
|
+
const html = deckAtCommit(cwd, sha, rel, { run });
|
|
321
|
+
const prompt = messagePrompt({
|
|
322
|
+
deck, template, ...diff,
|
|
323
|
+
title: deckTitle(html),
|
|
324
|
+
slides: changedSlides(html, diff.diff),
|
|
325
|
+
});
|
|
326
|
+
const spawned = resolve(agent, prompt, { env });
|
|
327
|
+
if (!spawned) return null;
|
|
328
|
+
// Caught, not propagated. This is called unawaited from the commit path, so
|
|
329
|
+
// a rejection here would be an unhandled one — and the whole contract is that
|
|
330
|
+
// a misbehaving agent costs a generic subject, never anything louder.
|
|
331
|
+
let out;
|
|
332
|
+
try { out = await exec(spawned, cwd, timeoutMs); }
|
|
333
|
+
catch { return null; }
|
|
334
|
+
if (out == null) return null;
|
|
335
|
+
|
|
336
|
+
const found = subjectFrom(out);
|
|
337
|
+
if (!found) return null;
|
|
338
|
+
const subject = commitSubject(found, template);
|
|
339
|
+
// The agent echoing the template back (the prompt's own escape hatch) is a
|
|
340
|
+
// successful answer meaning "nothing worth saying" — and amending a message
|
|
341
|
+
// to itself is a rewrite for no reason.
|
|
342
|
+
if (subject === template) return null;
|
|
343
|
+
return amendSubject(cwd, sha, subject, { run }) ? subject : null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* A subject for work that is NOT COMMITTED YET — what the commit overlay's
|
|
348
|
+
* "write one for me" button asks for.
|
|
349
|
+
*
|
|
350
|
+
* The same prompt, the same read-only argv, the same cap and the same stated
|
|
351
|
+
* truncation as `describeCommit`; three things differ, and each is because
|
|
352
|
+
* there is no commit yet:
|
|
353
|
+
*
|
|
354
|
+
* the diff is `git diff HEAD` rather than `git show <sha>`;
|
|
355
|
+
* the deck is read FROM DISK, because the working tree is the subject here
|
|
356
|
+
* (in describeCommit reading from disk would name a slide the commit does
|
|
357
|
+
* not contain — here it is the only honest source);
|
|
358
|
+
* nothing is amended. It returns the sentence and the caller decides — a
|
|
359
|
+
* person is looking at a text box, and putting words in it is the most
|
|
360
|
+
* this is allowed to do.
|
|
361
|
+
*
|
|
362
|
+
* Returns null for every failure, exactly like its sibling: no agent, nothing
|
|
363
|
+
* changed, a timeout, an answer that was not a subject. The overlay then shows
|
|
364
|
+
* an empty box, which is the state it was in anyway.
|
|
365
|
+
*/
|
|
366
|
+
export async function describeWorking({
|
|
367
|
+
cwd, deckPath, deckRel, template, agent = null,
|
|
368
|
+
env = process.env, timeoutMs = ASK_TIMEOUT_MS, run = git, exec = ask,
|
|
369
|
+
resolve = agentAsk, read = null,
|
|
370
|
+
} = {}) {
|
|
371
|
+
const deck = basename(deckPath);
|
|
372
|
+
const cmd = resolve(agent, 'x', { env });
|
|
373
|
+
if (!cmd) return null;
|
|
374
|
+
const rel = deckRel || relative(cwd, deckPath) || deck;
|
|
375
|
+
|
|
376
|
+
let out_;
|
|
377
|
+
try { out_ = run(['diff', '--unified=1', 'HEAD', '--', rel], cwd) ?? ''; }
|
|
378
|
+
catch { return null; }
|
|
379
|
+
if (!out_.trim()) return null;
|
|
380
|
+
const truncated = out_.length > MAX_DIFF;
|
|
381
|
+
const diff = truncated ? out_.slice(0, MAX_DIFF) : out_;
|
|
382
|
+
|
|
383
|
+
let html = '';
|
|
384
|
+
try { html = (read ?? readFileSync)(deckPath, 'utf8'); } catch { /* headings are optional */ }
|
|
385
|
+
const prompt = messagePrompt({
|
|
386
|
+
deck, template, diff, truncated,
|
|
387
|
+
title: deckTitle(html),
|
|
388
|
+
slides: changedSlides(html, diff),
|
|
389
|
+
});
|
|
390
|
+
const spawned = resolve(agent, prompt, { env });
|
|
391
|
+
if (!spawned) return null;
|
|
392
|
+
let answer;
|
|
393
|
+
try { answer = await exec(spawned, cwd, timeoutMs); }
|
|
394
|
+
catch { return null; }
|
|
395
|
+
if (answer == null) return null;
|
|
396
|
+
const found = subjectFrom(answer);
|
|
397
|
+
if (!found) return null;
|
|
398
|
+
const subject = commitSubject(found, template);
|
|
399
|
+
return subject === template ? null : subject;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** The startup line: what is on, who does it, and what leaves the machine. */
|
|
403
|
+
export function messagesLine(agentName) {
|
|
404
|
+
return agentName
|
|
405
|
+
? `git: ${agentName} writes the commit subjects — the deck's diffs are sent to it`
|
|
406
|
+
: 'git: --commit-messages needs an agent on PATH — subjects stay generic';
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Where the answer lives: git's own config, in the repository it is about.
|
|
411
|
+
*
|
|
412
|
+
* The setting only means anything when there IS a repository — it describes
|
|
413
|
+
* what happens to that repository's commits — so git config is where it
|
|
414
|
+
* belongs rather than a file decklight invents. It is per-repo, it survives,
|
|
415
|
+
* and it is inspectable and reversible with the tool the user already knows:
|
|
416
|
+
* `git config decklight.commit-messages false`.
|
|
417
|
+
*/
|
|
418
|
+
export const PREF_KEY = 'decklight.commit-messages';
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* The stored answer: true, false, or null when nobody has been asked yet.
|
|
422
|
+
*
|
|
423
|
+
* `git config --get` EXITS 1 for a key that is not set, and `git()` throws on a
|
|
424
|
+
* non-zero exit — so the unset case, which is every first run, arrives here as
|
|
425
|
+
* an exception rather than an empty string. Unreadable and unset are the same
|
|
426
|
+
* answer: nobody has said, so ask (or stay off).
|
|
427
|
+
*/
|
|
428
|
+
export function storedPref(cwd, { run = git } = {}) {
|
|
429
|
+
let v = '';
|
|
430
|
+
try { v = (run(['config', '--get', PREF_KEY], cwd) ?? '').trim(); } catch { return null; }
|
|
431
|
+
return v === 'true' ? true : v === 'false' ? false : null;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Remember the answer, so the next session does not ask again.
|
|
436
|
+
*
|
|
437
|
+
* Never fatal: this is a convenience, and a repository that refuses the write
|
|
438
|
+
* (a read-only config, a worktree in a strange state) should cost the user a
|
|
439
|
+
* repeated question, not a failed startup.
|
|
440
|
+
*/
|
|
441
|
+
export function rememberPref(cwd, on, { run = git } = {}) {
|
|
442
|
+
try { run(['config', PREF_KEY, on ? 'true' : 'false'], cwd); return true; } catch { return false; }
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Whether to ask, and what the answer already is.
|
|
447
|
+
*
|
|
448
|
+
* Asked ONCE, at the moment a repository is created — the same moment the
|
|
449
|
+
* autocommit itself is offered, because that is when the commits this governs
|
|
450
|
+
* come into existence. An existing repository is never interrupted to be asked
|
|
451
|
+
* a new question; it uses the flag.
|
|
452
|
+
*
|
|
453
|
+
* The default is YES, and that is a defensible default only because it is a
|
|
454
|
+
* QUESTION. The permission is still explicitly given by a person who was told
|
|
455
|
+
* what leaves the machine — decklight still never infers it from what happens
|
|
456
|
+
* to be on PATH, which is the rule `lipsync --veo` follows. So: no agent
|
|
457
|
+
* installed, or no TTY to answer, means no question and no feature.
|
|
458
|
+
*/
|
|
459
|
+
export function planCommitMessages({
|
|
460
|
+
args = [], tty = false, agents = 0, creatingRepo = false, stored = null,
|
|
461
|
+
} = {}) {
|
|
462
|
+
if (args.includes('--no-commit-messages')) return { action: 'off' };
|
|
463
|
+
if (args.includes('--commit-messages')) return { action: 'on' };
|
|
464
|
+
if (stored !== null) return { action: stored ? 'on' : 'off' };
|
|
465
|
+
// Nothing to drive it, nothing to write the subjects with: the feature is
|
|
466
|
+
// unavailable, and offering it would be offering a switch wired to nothing.
|
|
467
|
+
if (!agents) return { action: 'skip' };
|
|
468
|
+
if (!creatingRepo) return { action: 'skip' };
|
|
469
|
+
return { action: tty ? 'ask' : 'skip' };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** The question, worded so the cost is on screen before the answer is given. */
|
|
473
|
+
export const ASK_MESSAGES =
|
|
474
|
+
' let an agent write your commit subjects instead of "autosave"?'
|
|
475
|
+
+ ' (sends the deck\'s diffs to it) [Y/n] ';
|