decklight 0.10.0 → 0.11.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/NOTICE +2 -0
- package/PLATFORM.md +17 -0
- package/README.md +53 -25
- package/SPEC.md +1239 -67
- package/cli/agents.mjs +139 -15
- package/cli/bundle.mjs +68 -2
- package/cli/cast.mjs +45 -14
- package/cli/check-fixes.mjs +12 -4
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +460 -71
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-message.mjs +34 -7
- package/cli/commit-split.mjs +123 -23
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +21 -4
- package/cli/edit-handover.mjs +136 -25
- package/cli/edit-look.mjs +45 -1
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3182 -267
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +148 -20
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/init.mjs +93 -19
- package/cli/keep-awake.mjs +68 -0
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +51 -10
- package/cli/open.mjs +29 -9
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +61 -2
- package/cli/pptx-export.mjs +3 -1
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +19 -8
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +7 -4
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +212 -8
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +36 -13
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2087 -91
- package/dist/decklight.js +367 -203
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +15 -1
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +24 -4
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +772 -127
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- package/dist/build-info.json +0 -1
package/cli/commit-split.mjs
CHANGED
|
@@ -31,9 +31,10 @@ import { execFileSync, execFile } from 'node:child_process';
|
|
|
31
31
|
import { createHash } from 'node:crypto';
|
|
32
32
|
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
33
33
|
import { tmpdir } from 'node:os';
|
|
34
|
-
import { join, resolve as resolvePath } from 'node:path';
|
|
34
|
+
import { basename, join, resolve as resolvePath } from 'node:path';
|
|
35
35
|
import { agentAsk } from './agents.mjs';
|
|
36
|
-
import { ASK_TIMEOUT_MS, ask, deckOutline, deckTitle, reviewSubject } from './commit-message.mjs';
|
|
36
|
+
import { ASK_TIMEOUT_MS, ask, deckOutline, deckTitle, describeWorking, reviewSubject, slideNames } from './commit-message.mjs';
|
|
37
|
+
import { slideNamesPhrase } from '../tools/deck-html.mjs';
|
|
37
38
|
import { GIT_MAX_BUFFER, classifyRemoteError, commitSubject, isIdentityError, noPromptEnv, oneline, remoteState } from './git.mjs';
|
|
38
39
|
|
|
39
40
|
/** Past this many hunks, the hunks of one slide travel together. */
|
|
@@ -96,12 +97,20 @@ const slidesAt = (outline, from, count) => {
|
|
|
96
97
|
return outline.filter((s) => s.from <= last && s.to >= from).map((s) => s.index);
|
|
97
98
|
};
|
|
98
99
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
100
|
+
/**
|
|
101
|
+
* "slide 3", "slides 3-4", "slides 2, 5", or where a change outside any slide
|
|
102
|
+
* is, followed by what the slides are called when `names` (from `slideNames`)
|
|
103
|
+
* says: `slide 3 — "The Freshness Problem"`. The agent grouping the units is
|
|
104
|
+
* asked to name slides by their words, so it has to be shown them: given only
|
|
105
|
+
* the number, it falls back on the number.
|
|
106
|
+
*/
|
|
107
|
+
export function whereLabel(slides, names = []) {
|
|
101
108
|
if (!slides.length) return 'theme or metadata';
|
|
102
|
-
if (slides.length === 1) return `slide ${slides[0]}`;
|
|
103
109
|
const run_ = slides.every((s, i) => i === 0 || s === slides[i - 1] + 1);
|
|
104
|
-
|
|
110
|
+
const at = slides.length === 1 ? `slide ${slides[0]}`
|
|
111
|
+
: run_ ? `slides ${slides[0]}-${slides[slides.length - 1]}` : `slides ${slides.join(', ')}`;
|
|
112
|
+
const called = slideNamesPhrase(slides.map((n) => names[n - 1]));
|
|
113
|
+
return called ? `${at} — ${called}` : at;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
/**
|
|
@@ -143,6 +152,7 @@ export function workingUnits({ cwd, deckRel, also = [] }) {
|
|
|
143
152
|
continue;
|
|
144
153
|
}
|
|
145
154
|
const outline = deckOutline(work);
|
|
155
|
+
const names = slideNames(work);
|
|
146
156
|
let mine = hunks.map((h) => ({
|
|
147
157
|
file: rel, whole: false, hunks: [h],
|
|
148
158
|
slides: slidesAt(outline, h.newStart, h.newCount),
|
|
@@ -161,7 +171,7 @@ export function workingUnits({ cwd, deckRel, also = [] }) {
|
|
|
161
171
|
for (const u of mine) {
|
|
162
172
|
units.push({
|
|
163
173
|
...u,
|
|
164
|
-
where: whereLabel(u.slides),
|
|
174
|
+
where: whereLabel(u.slides, names),
|
|
165
175
|
lines: u.hunks.reduce((n, h) => n + h.oldCount + h.newCount, 0),
|
|
166
176
|
diff: u.hunks.map((h) => h.text.join('\n')).join('\n'),
|
|
167
177
|
});
|
|
@@ -207,13 +217,28 @@ export function planPrompt({ deck, title = null, units, max = 24 * 1024 }) {
|
|
|
207
217
|
].join('\n');
|
|
208
218
|
}
|
|
209
219
|
|
|
210
|
-
/**
|
|
220
|
+
/** One change number, or a range of them: `4`, `1-10`, `1–10`, `1..4`, `1 to 4`. */
|
|
221
|
+
const PLAN_ID = String.raw`\d+(?:\s*(?:-|–|—|\.\.\.?|to)\s*\d+)?`;
|
|
222
|
+
const PLAN_LINE = new RegExp(String.raw`^\s*[-*]?\s*\[?(${PLAN_ID}(?:(?:\s*,\s*|\s+)${PLAN_ID})*)\]?\s*[|:]\s*(.+?)\s*$`);
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* `[{ units: [ids], subject }]` from the agent's lines. Pure. The prompt asks
|
|
226
|
+
* for a comma list, but a model grouping consecutive changes writes a range
|
|
227
|
+
* (#908), so `1-10` and `1, 3-5, 8` read as the numbers they name. A range
|
|
228
|
+
* wider than any deck has changes is not a plan, and is dropped.
|
|
229
|
+
*/
|
|
211
230
|
export function parsePlan(answer) {
|
|
212
231
|
const out = [];
|
|
213
232
|
for (const line of String(answer ?? '').split('\n')) {
|
|
214
|
-
const m =
|
|
233
|
+
const m = PLAN_LINE.exec(line);
|
|
215
234
|
if (!m) continue;
|
|
216
|
-
const ids =
|
|
235
|
+
const ids = [];
|
|
236
|
+
for (const [, a, b] of m[1].matchAll(/(\d+)(?:\s*(?:-|–|—|\.\.\.?|to)\s*(\d+))?/g)) {
|
|
237
|
+
const lo = Math.min(Number(a), Number(b ?? a));
|
|
238
|
+
const hi = Math.max(Number(a), Number(b ?? a));
|
|
239
|
+
if (hi - lo > 1000) continue;
|
|
240
|
+
for (let id = lo; id <= hi; id++) ids.push(id);
|
|
241
|
+
}
|
|
217
242
|
if (ids.length && m[2]) out.push({ units: ids, subject: m[2].replace(/^["'`]|["'`]$/g, '') });
|
|
218
243
|
}
|
|
219
244
|
return out;
|
|
@@ -260,35 +285,50 @@ const addedLines = (f) => {
|
|
|
260
285
|
* sidecar's records say what they are (reviewSubject), so they are one commit
|
|
261
286
|
* of their own with that subject, and a .gitattributes decklight wrote goes
|
|
262
287
|
* with them. Only the deck's hunks are sent to the agent, and only on the
|
|
263
|
-
* click that asked for it. An
|
|
264
|
-
*
|
|
288
|
+
* click that asked for it. An answer with no line `parsePlan` reads is asked
|
|
289
|
+
* again as one subject (describeWorking), the deck as one commit; with still
|
|
290
|
+
* no subject, `unread` carries what the agent said, so the window can tell
|
|
291
|
+
* "couldn't read the answer" from "nothing to say" (#908).
|
|
265
292
|
*/
|
|
266
293
|
export async function planWorking({
|
|
267
294
|
cwd, deckPath, deckRel, also = [], agent = null, env = process.env,
|
|
268
295
|
timeoutMs = ASK_TIMEOUT_MS, exec = ask, resolve = agentAsk, read = readFileSync,
|
|
296
|
+
template = `decklight: autosave ${basename(deckRel)}`, describe = describeWorking,
|
|
269
297
|
}) {
|
|
270
298
|
const work = workingUnits({ cwd, deckRel, also });
|
|
271
299
|
if (!work || !work.units.length) return { work, commits: null };
|
|
272
300
|
const deckUnits = work.units.filter((u) => u.file === deckRel);
|
|
273
301
|
const rest = work.units.filter((u) => u.file !== deckRel);
|
|
274
302
|
const commits = [];
|
|
303
|
+
let unread = null;
|
|
304
|
+
let html = '';
|
|
305
|
+
try { html = read(deckPath, 'utf8'); } catch { /* the title and the names are optional */ }
|
|
275
306
|
if (deckUnits.length) {
|
|
276
307
|
let groups = [];
|
|
277
|
-
let
|
|
278
|
-
try { html = read(deckPath, 'utf8'); } catch { /* the title is optional */ }
|
|
308
|
+
let answer = null;
|
|
279
309
|
const spawned = resolve(agent, planPrompt({ deck: deckRel, title: deckTitle(html), units: deckUnits }), { env });
|
|
280
310
|
if (spawned) {
|
|
281
|
-
let answer = null;
|
|
282
311
|
try { answer = await exec(spawned, cwd, timeoutMs); } catch { answer = null; }
|
|
283
312
|
groups = parsePlan(answer);
|
|
284
313
|
}
|
|
285
|
-
|
|
314
|
+
const deckCommits = normalizePlan(groups, deckUnits).map((g) => ({ subject: g.subject, units: g.units }));
|
|
315
|
+
if (spawned && !groups.length) {
|
|
316
|
+
let subject = null;
|
|
317
|
+
try {
|
|
318
|
+
subject = await describe({
|
|
319
|
+
cwd, deckPath, deckRel, template, agent, env, timeoutMs, exec, resolve, read,
|
|
320
|
+
});
|
|
321
|
+
} catch { subject = null; }
|
|
322
|
+
if (subject) deckCommits[0].subject = subject;
|
|
323
|
+
else unread = { answer: String(answer ?? '').slice(0, 2000) };
|
|
324
|
+
}
|
|
325
|
+
commits.push(...deckCommits);
|
|
286
326
|
}
|
|
287
327
|
if (rest.length) {
|
|
288
|
-
const side = rest.map((u) => reviewSubject(addedLines(work.files[u.file]))).find(Boolean);
|
|
328
|
+
const side = rest.map((u) => reviewSubject(addedLines(work.files[u.file]), { names: slideNames(html) })).find(Boolean);
|
|
289
329
|
commits.push({ subject: side ?? '', units: rest.map((u) => u.id) });
|
|
290
330
|
}
|
|
291
|
-
return { work, commits };
|
|
331
|
+
return { work, commits, unread };
|
|
292
332
|
}
|
|
293
333
|
|
|
294
334
|
/** A unit as the window shows it: no hunk bodies, which can be large. */
|
|
@@ -345,8 +385,23 @@ export function slideChanges(before, after) {
|
|
|
345
385
|
* Pure; 1-based like `state.slide`.
|
|
346
386
|
*/
|
|
347
387
|
export function slideDiff(before, after) {
|
|
348
|
-
const
|
|
349
|
-
const
|
|
388
|
+
const stops = slideOps(before, after).filter((o) => o.kind !== 'same');
|
|
389
|
+
const count = (k) => stops.filter((s) => s.kind === k).length;
|
|
390
|
+
return { changed: count('changed'), added: count('added'), removed: count('removed'), stops };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* slideDiff's stops with the slides that did not change between them, `{
|
|
395
|
+
* kind: 'same', slide, was }`: the whole alignment, every slide of both
|
|
396
|
+
* versions once, in reading order. What a reviewed fix merges by
|
|
397
|
+
* (cli/fix-review.mjs). Pure.
|
|
398
|
+
*/
|
|
399
|
+
export function slideOps(before, after) {
|
|
400
|
+
return slideOpsOf(slideSources(before), slideSources(after));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** slideOps over slides already cut out: each one's source, whitespace at line ends ignored. Pure. */
|
|
404
|
+
export function slideOpsOf(a, b) {
|
|
350
405
|
// LCS over whole slides; decks are tens of slides, so n×m is nothing
|
|
351
406
|
const n = a.length, m = b.length;
|
|
352
407
|
const L = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
@@ -372,15 +427,60 @@ export function slideDiff(before, after) {
|
|
|
372
427
|
};
|
|
373
428
|
let i = 0, j = 0;
|
|
374
429
|
while (i < n && j < m) {
|
|
375
|
-
if (a[i] === b[j]) { close(); i++; j++; }
|
|
430
|
+
if (a[i] === b[j]) { close(); stops.push({ kind: 'same', slide: j + 1, was: i + 1 }); i++; j++; }
|
|
376
431
|
else if (L[i + 1][j] >= L[i][j + 1]) gapOld.push(i++);
|
|
377
432
|
else gapNew.push(j++);
|
|
378
433
|
}
|
|
379
434
|
while (i < n) gapOld.push(i++);
|
|
380
435
|
while (j < m) gapNew.push(j++);
|
|
381
436
|
close();
|
|
382
|
-
|
|
383
|
-
|
|
437
|
+
return stops;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Where each slide of `before` is in `after`, from the alignment of the
|
|
442
|
+
* sections (slideOps): `[[was, now | null]]` for every old slide whose number
|
|
443
|
+
* changed, or that went (null). What the voice folders follow after an edit
|
|
444
|
+
* that rewrote the deck at once — an agent's (#920). Read off the deck, never
|
|
445
|
+
* the audio, so it holds for a stale recording and a slide with no notes.
|
|
446
|
+
*
|
|
447
|
+
* A slide unchanged or edited keeps its alignment. One removed here and added,
|
|
448
|
+
* word for word, there was moved. What is left of one gap — the old and new
|
|
449
|
+
* slides between the same two unchanged ones — pairs up in order: a slide
|
|
450
|
+
* rewritten past recognition is still that slide, its recording kept on it
|
|
451
|
+
* (and flagged stale by its words), not thrown away. The rest went. Pure.
|
|
452
|
+
*/
|
|
453
|
+
export function slideRenumber(before, after) {
|
|
454
|
+
return slideRenumberOf(slideSources(before), slideSources(after));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** slideRenumber over slides already cut out, as slideOpsOf takes them. Pure. */
|
|
458
|
+
export function slideRenumberOf(a, b) {
|
|
459
|
+
const ops = slideOpsOf(a, b);
|
|
460
|
+
const now = new Map();
|
|
461
|
+
const taken = new Set();
|
|
462
|
+
const gaps = [[]];
|
|
463
|
+
for (const o of ops) {
|
|
464
|
+
if (o.kind === 'same') { now.set(o.was, o.slide); gaps.push([]); continue; }
|
|
465
|
+
gaps.at(-1).push(o);
|
|
466
|
+
if (o.kind === 'changed') now.set(o.was, o.slide);
|
|
467
|
+
}
|
|
468
|
+
const added = ops.filter((o) => o.kind === 'added');
|
|
469
|
+
for (const r of ops.filter((o) => o.kind === 'removed')) {
|
|
470
|
+
const to = added.find((o) => !taken.has(o.slide) && a[r.was - 1] === b[o.slide - 1]);
|
|
471
|
+
if (to) { now.set(r.was, to.slide); taken.add(to.slide); }
|
|
472
|
+
}
|
|
473
|
+
for (const g of gaps) {
|
|
474
|
+
const out = g.filter((o) => o.kind === 'removed' && !now.has(o.was));
|
|
475
|
+
const into = g.filter((o) => o.kind === 'added' && !taken.has(o.slide));
|
|
476
|
+
out.forEach((r, i) => { if (into[i]) { now.set(r.was, into[i].slide); taken.add(into[i].slide); } });
|
|
477
|
+
}
|
|
478
|
+
const pairs = [];
|
|
479
|
+
for (let k = 1; k <= a.length; k++) {
|
|
480
|
+
const n = now.get(k) ?? null;
|
|
481
|
+
if (n !== k) pairs.push([k, n]);
|
|
482
|
+
}
|
|
483
|
+
return pairs;
|
|
384
484
|
}
|
|
385
485
|
|
|
386
486
|
/**
|
package/cli/decklight.mjs
CHANGED
|
@@ -159,7 +159,17 @@ try {
|
|
|
159
159
|
process.exitCode = r.status ?? 1;
|
|
160
160
|
} else {
|
|
161
161
|
const mod = await import(new URL(command.module, import.meta.url));
|
|
162
|
-
const
|
|
162
|
+
const renderOption = rest.indexOf('--render');
|
|
163
|
+
const display = cmd === 'video' && renderOption >= 0 && rest[renderOption + 1] === 'live';
|
|
164
|
+
const awake = ['video', 'pdf', 'pptx', 'bundle'].includes(cmd)
|
|
165
|
+
&& !rest.some((arg) => arg === '--help' || arg === '-h')
|
|
166
|
+
? await (await import('./keep-awake.mjs')).keepAwake({ display }) : null;
|
|
167
|
+
let code;
|
|
168
|
+
try {
|
|
169
|
+
code = await mod[command.main](...(command.args ? command.args(rest, cmd) : [rest]));
|
|
170
|
+
} finally {
|
|
171
|
+
await awake?.release();
|
|
172
|
+
}
|
|
163
173
|
// A main that returns a number is naming its exit code; one that returns
|
|
164
174
|
// nothing exits 0 unless it threw. Both conventions exist today, and this
|
|
165
175
|
// is the one place that has to know.
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// come from the deck's design systems as the server resolves them, never
|
|
19
19
|
// from the page; they are handed in, so every transform is testable alone.
|
|
20
20
|
|
|
21
|
-
import { locateSlide, sectionChildRanges, splitOpenTag, readAttrs, writeAttrs, insertSectionsAfter } from '../tools/deck-html.mjs';
|
|
21
|
+
import { locateSlide, sectionChildRanges, splitOpenTag, readAttrs, writeAttrs, insertSectionsAfter, carriedChild } from '../tools/deck-html.mjs';
|
|
22
22
|
|
|
23
23
|
/** Elements a slide carries rather than shows — never assigned to a slot. */
|
|
24
24
|
const CARRIED = new Set(['aside', 'script', 'style']);
|
|
@@ -60,6 +60,31 @@ export function slotWriteProblem(html, slide, index, outerHtml) {
|
|
|
60
60
|
: null;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Why moving element `index` to content position `to` on a design-system
|
|
65
|
+
* slide is refused, or null (PRESENTING_EDITING, Moving). The template puts
|
|
66
|
+
* each element in its slot by its `data-slot`, not by its place in the file,
|
|
67
|
+
* so the only order a move can change is the order of one slot's own
|
|
68
|
+
* elements: a move past another slot's would write a change the slide never
|
|
69
|
+
* shows, and read as a move into that slot that did not happen.
|
|
70
|
+
*/
|
|
71
|
+
export function slotMoveProblem(html, slide, index, to) {
|
|
72
|
+
if (!slideTemplateOf(html, slide)) return null;
|
|
73
|
+
const { parts, idx } = locateSlide(html, slide);
|
|
74
|
+
const seg = parts[idx];
|
|
75
|
+
const content = sectionChildRanges(seg).map((r, raw) => ({ r, raw }))
|
|
76
|
+
.filter(({ r }) => !carriedChild(seg, r))
|
|
77
|
+
.map(({ r, raw }) => ({ raw, slot: openTag(seg.slice(r.start, r.end)).attrs['data-slot'] ?? '' }));
|
|
78
|
+
const from = content.findIndex((c) => c.raw === index);
|
|
79
|
+
if (from < 0 || !Number.isInteger(to) || to < 0 || to >= content.length) return null; // the move's own checks say why
|
|
80
|
+
const mine = content[from].slot;
|
|
81
|
+
const [lo, hi] = from < to ? [from + 1, to] : [to, from - 1];
|
|
82
|
+
const other = content.slice(lo, hi + 1).find((c) => c.slot !== mine);
|
|
83
|
+
if (!other) return null;
|
|
84
|
+
const name = (s) => (s ? `the "${s}" slot` : 'the template\'s default slot');
|
|
85
|
+
return `this element fills ${name(mine)} of the slide's template, and its data-slot, not its place in the file, says where it goes: it moves only among ${name(mine)}'s own elements, not past ${name(other.slot)}'s (to put it in another slot, change its data-slot in Edit content (HTML))`;
|
|
86
|
+
}
|
|
87
|
+
|
|
63
88
|
/** A hint (`"h1,h2"`) as the tags it names. */
|
|
64
89
|
const hintTags = (hint) => String(hint ?? '').toLowerCase().split(/[\s,]+/).filter(Boolean);
|
|
65
90
|
|
|
@@ -132,6 +157,17 @@ export function applySlideTemplate(html, slide, template) {
|
|
|
132
157
|
return { html: parts.join(''), mode, moved, lacking: [...new Set(lacking)] };
|
|
133
158
|
}
|
|
134
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Each of slide `n`'s children in file order, and the slot it names (null for
|
|
162
|
+
* none): what the edit bar's picker (PRESENTING_EDITING) needs to draw a
|
|
163
|
+
* slide put into a template before anything is written. Its index is the one `/deck/edit/element/*`
|
|
164
|
+
* addresses, and the one the page stamps on the element it expanded.
|
|
165
|
+
*/
|
|
166
|
+
export function slideSlots(html, slide) {
|
|
167
|
+
const { parts, idx } = locateSlide(html, slide);
|
|
168
|
+
return sectionChildRanges(parts[idx]).map((r) => openTag(parts[idx].slice(r.start, r.end)).attrs['data-slot'] ?? null);
|
|
169
|
+
}
|
|
170
|
+
|
|
135
171
|
/** A tag a hint suggests for a new slide's slot, or `p`. */
|
|
136
172
|
const tagFor = (hint) => hintTags(hint).find((t) => /^(h[1-6]|p|ul|ol|blockquote|figure|div)$/.test(t)) ?? 'p';
|
|
137
173
|
const titleCase = (name) => name.replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Where a write-mode edit lands in the deck FILE, and how one attribute or
|
|
5
|
+
// one node is changed there (PRESENTING_EDITING). Every element transform in
|
|
6
|
+
// cli/edit.mjs addresses its target the same way, so the way lives here once:
|
|
7
|
+
//
|
|
8
|
+
// a slide's top-level element is its raw index among the `<section>`'s
|
|
9
|
+
// direct children (title included, sectionChildRanges);
|
|
10
|
+
// a node inside one is a `path` of element-child indices below it, counted
|
|
11
|
+
// over the FILE's elements (the live DOM is not the file: the engine adds
|
|
12
|
+
// nodes of its own), plus the `tag` the page saw there. A path the file
|
|
13
|
+
// does not have, or one that lands on another tag, is STALE (a 409), never
|
|
14
|
+
// a guess.
|
|
15
|
+
//
|
|
16
|
+
// Every change is textual: one open tag's attribute rewritten where it
|
|
17
|
+
// stands, or one node's text spliced, so the author's bytes and indentation
|
|
18
|
+
// around it survive.
|
|
19
|
+
|
|
20
|
+
import { locateSlide, sectionChildRanges, elementChildRanges, splitOpenTag } from '../tools/deck-html.mjs';
|
|
21
|
+
import { escapeHtml } from '../tools/escape.mjs';
|
|
22
|
+
|
|
23
|
+
/** The page and the file disagree about what is where: a 409, not a bad request. */
|
|
24
|
+
export const stale = (message) => Object.assign(new Error(message), { code: 'STALE' });
|
|
25
|
+
|
|
26
|
+
/** `path` if it is one (`nested`: below the element, never the element itself), or a 400. */
|
|
27
|
+
export function checkPath(path, { nested = false } = {}) {
|
|
28
|
+
if (!Array.isArray(path) || (nested && !path.length) || path.length > 16 || path.some((n) => !Number.isInteger(n) || n < 0)) throw new Error('bad path');
|
|
29
|
+
return path;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Look up element `index` (raw child position) on slide `slide`, or throw. */
|
|
33
|
+
export function locateElement(html, slide, index) {
|
|
34
|
+
const { parts, idx } = locateSlide(html, slide);
|
|
35
|
+
const seg = parts[idx];
|
|
36
|
+
const ranges = sectionChildRanges(seg);
|
|
37
|
+
const r = ranges[index];
|
|
38
|
+
if (!r) throw new Error(`slide ${slide}: no element at index ${index} (has ${ranges.length})`);
|
|
39
|
+
return { parts, idx, seg, r };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const tagAt = (s) => /^<([a-zA-Z][\w:-]*)/.exec(s)?.[1]?.toLowerCase() ?? null;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The node at `path` below `el` (a slide element's source): its offsets in
|
|
46
|
+
* `el`, its tag, and the nodes on the way down (`el` first, its parent last),
|
|
47
|
+
* so a caller can ask whether it sits in a diagram and what holds it. A path
|
|
48
|
+
* the file does not have, or one that lands on another tag than the page saw,
|
|
49
|
+
* is stale.
|
|
50
|
+
*/
|
|
51
|
+
export function nodeAt(el, path, { slide, index, tag = null }) {
|
|
52
|
+
checkPath(path);
|
|
53
|
+
let start = 0; let end = el.length;
|
|
54
|
+
const chain = [];
|
|
55
|
+
for (const n of path) {
|
|
56
|
+
chain.push({ start, end, tag: tagAt(el.slice(start, end)) });
|
|
57
|
+
const kid = elementChildRanges(el.slice(start, end))[n];
|
|
58
|
+
if (!kid) throw stale(`slide ${slide} #${index}: the file has no element at ${path.join('.')} — the engine drew this one, or the deck changed; reload and try again`);
|
|
59
|
+
end = start + kid.end; start += kid.start;
|
|
60
|
+
}
|
|
61
|
+
const found = tagAt(el.slice(start, end));
|
|
62
|
+
if (tag && found !== String(tag).toLowerCase()) {
|
|
63
|
+
throw stale(`slide ${slide} #${index}: the page found <${tag}> at ${path.join('.') || 'the element'}, the file has <${found}> — reload and try again`);
|
|
64
|
+
}
|
|
65
|
+
const svgAt = chain.map((c) => c.tag).lastIndexOf('svg');
|
|
66
|
+
return { start, end, found, chain, parent: chain.at(-1) ?? null, svg: svgAt < 0 ? null : chain[svgAt], inSvg: svgAt >= 0 };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Slide N's element `index`, open for an edit: `el` is its source, changed
|
|
71
|
+
* through `splice` and `edit`, and `html()` is the deck with it put back.
|
|
72
|
+
*
|
|
73
|
+
* at(path, tag) the node there (nodeAt), offsets into `el` as it is now
|
|
74
|
+
* src(at) that node's source
|
|
75
|
+
* splice(s, e, text) `el` with [s, e) replaced
|
|
76
|
+
* edit(path, tag, fn) that node's open tag made `fn(attrs, at)`, the rest kept
|
|
77
|
+
* lead(at) what stands before the node on its line, read in the
|
|
78
|
+
* slide (the node may be the element itself): only
|
|
79
|
+
* spaces when it begins the line
|
|
80
|
+
*/
|
|
81
|
+
export function openElement(html, slide, index) {
|
|
82
|
+
const { parts, idx, seg, r } = locateElement(html, slide, index);
|
|
83
|
+
const e = {
|
|
84
|
+
el: seg.slice(r.start, r.end),
|
|
85
|
+
at: (path, tag = null) => nodeAt(e.el, path, { slide, index, tag }),
|
|
86
|
+
src: (at) => e.el.slice(at.start, at.end),
|
|
87
|
+
splice(start, end, text) { e.el = e.el.slice(0, start) + text + e.el.slice(end); },
|
|
88
|
+
edit(path, tag, fn) {
|
|
89
|
+
const at = e.at(path, tag);
|
|
90
|
+
const { attrs, close, rest } = splitOpenTag(e.src(at));
|
|
91
|
+
e.splice(at.start, at.end, fn(attrs, at) + close + rest);
|
|
92
|
+
return at;
|
|
93
|
+
},
|
|
94
|
+
lead(at) {
|
|
95
|
+
const abs = r.start + at.start;
|
|
96
|
+
return seg.slice(seg.lastIndexOf('\n', abs - 1) + 1, abs);
|
|
97
|
+
},
|
|
98
|
+
html() { parts[idx] = seg.slice(0, r.start) + e.el + seg.slice(r.end); return parts.join(''); },
|
|
99
|
+
};
|
|
100
|
+
return e;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ── one attribute on an open tag ───────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
/** The text a run of markup reads as: the entities a label or an attribute is likely to carry, decoded. */
|
|
106
|
+
export const decodeText = (s) => String(s).replace(/&(#x[0-9a-f]+|#\d+|amp|lt|gt|quot|apos|nbsp);/gi, (m, e) => {
|
|
107
|
+
const k = e.toLowerCase();
|
|
108
|
+
if (k[0] === '#') return String.fromCodePoint(k[1] === 'x' ? parseInt(k.slice(2), 16) : parseInt(k.slice(1), 10));
|
|
109
|
+
return { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' }[k];
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/** The attributes of an open tag's text (`<rect x="1" …`, no `>`), each with where it stands, so one can be changed in place. */
|
|
113
|
+
export function attrList(attrs) {
|
|
114
|
+
const out = [];
|
|
115
|
+
const head = /^<[a-zA-Z][\w:-]*/.exec(attrs);
|
|
116
|
+
const re = /(\s+)([^\s=/>"']+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s>"']+))?/y;
|
|
117
|
+
re.lastIndex = head ? head[0].length : 0;
|
|
118
|
+
for (let m = re.exec(attrs); m; m = re.exec(attrs)) {
|
|
119
|
+
const raw = m[3] ?? null;
|
|
120
|
+
out.push({ name: m[2].toLowerCase(), written: m[2], lead: m[1], start: m.index, end: re.lastIndex, raw,
|
|
121
|
+
value: raw === null ? '' : /^["']/.test(raw) ? raw.slice(1, -1) : raw });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** What attribute `name` says on an open tag's text, its entities read (`a&b.png` is `a&b.png`), or null. */
|
|
127
|
+
export function attrOf(attrs, name) {
|
|
128
|
+
const a = attrList(attrs).find((x) => x.name === name);
|
|
129
|
+
return a ? decodeText(a.value) : null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* An open tag's text with attribute `name` set to `value` where it stands (its
|
|
134
|
+
* quote and the space before it kept), or added last; null takes it off. The
|
|
135
|
+
* value is escaped the one way every attribute is (escapeHtml: `&`, `<`, `>`
|
|
136
|
+
* and `"`; a `'` too inside single quotes), so what attrOf reads back is what
|
|
137
|
+
* was set: alt text with an ampersand, a name, a number alike. `true` writes
|
|
138
|
+
* the attribute bare (`data-build-stay`, `controls`), its value dropped if it
|
|
139
|
+
* had one, its spelling and the space before it kept.
|
|
140
|
+
*/
|
|
141
|
+
export function withAttr(attrs, name, value) {
|
|
142
|
+
const a = attrList(attrs).find((x) => x.name === name);
|
|
143
|
+
if (value === null) return a ? attrs.slice(0, a.start) + attrs.slice(a.end) : attrs;
|
|
144
|
+
if (value === true) {
|
|
145
|
+
if (a) return attrs.slice(0, a.start) + `${a.lead}${a.written}` + attrs.slice(a.end);
|
|
146
|
+
const tail = /\s*$/.exec(attrs)[0];
|
|
147
|
+
return `${attrs.slice(0, attrs.length - tail.length)} ${name}${tail}`;
|
|
148
|
+
}
|
|
149
|
+
const q = a?.raw?.[0] === "'" ? "'" : '"';
|
|
150
|
+
let v = escapeHtml(value);
|
|
151
|
+
if (q === "'") v = v.replace(/'/g, ''');
|
|
152
|
+
if (a) return attrs.slice(0, a.start) + `${a.lead}${a.written}=${q}${v}${q}` + attrs.slice(a.end);
|
|
153
|
+
const tail = /\s*$/.exec(attrs)[0];
|
|
154
|
+
return `${attrs.slice(0, attrs.length - tail.length)} ${name}="${v}"${tail}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `style` text with `prop` set to `value` (null: taken off) — its old declaration replaced, the rest kept in order. */
|
|
158
|
+
export function withStyleProp(style, prop, value) {
|
|
159
|
+
const kept = String(style ?? '').split(';').map((d) => d.trim()).filter(Boolean)
|
|
160
|
+
.filter((d) => d.slice(0, d.indexOf(':')).trim().toLowerCase() !== prop);
|
|
161
|
+
return (value === null ? kept : [...kept, `${prop}: ${value}`]).join('; ');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** An open tag's text with one declaration of its `style` set (null: taken off), and a `style` left empty gone. */
|
|
165
|
+
export const withStyle = (attrs, prop, value) => withAttr(attrs, 'style', withStyleProp(attrOf(attrs, 'style'), prop, value) || null);
|
|
166
|
+
|
|
167
|
+
// ── one node out ────────────────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* `text` without the nodes at `ranges` (`[[start, end]…]`): each with its line
|
|
171
|
+
* when it stood alone on one, so the file is left without a blank one. The
|
|
172
|
+
* last goes first, so the offsets before it hold.
|
|
173
|
+
*/
|
|
174
|
+
export function withoutNodes(text, ranges) {
|
|
175
|
+
let out = text;
|
|
176
|
+
for (let [s, e] of [...ranges].sort((a, b) => b[0] - a[0])) {
|
|
177
|
+
const lineStart = out.lastIndexOf('\n', s - 1) + 1;
|
|
178
|
+
const nl = out.indexOf('\n', e);
|
|
179
|
+
const lineEnd = nl < 0 ? out.length : nl;
|
|
180
|
+
if (/^[ \t]*$/.test(out.slice(lineStart, s)) && /^[ \t]*$/.test(out.slice(e, lineEnd)) && nl >= 0) { s = lineStart; e = nl + 1; }
|
|
181
|
+
out = out.slice(0, s) + out.slice(e);
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
package/cli/edit-git.mjs
CHANGED
|
@@ -57,6 +57,7 @@ export function registerGitRoutes(routes, {
|
|
|
57
57
|
readDeck, history, broadcast = () => {}, deckPath, deckRel, root,
|
|
58
58
|
gitOn, agentPref, subjectsOff, describer,
|
|
59
59
|
commitState, measureDirty, resetEpisode, alsoNow, alsoRels, attrRel, pendingAttr, clearPendingAttr, dismissNag,
|
|
60
|
+
followOutside = () => null,
|
|
60
61
|
}) {
|
|
61
62
|
// ── committing on the author's word (SPEC PRESENTING) ─────────────────
|
|
62
63
|
// What is uncommitted, right now. The overlay opens on this rather than
|
|
@@ -88,14 +89,23 @@ export function registerGitRoutes(routes, {
|
|
|
88
89
|
// `describeCommit`'s amend is for messages decklight authored, and this
|
|
89
90
|
// one has an author.
|
|
90
91
|
function commitRoute({ body, json }) {
|
|
92
|
+
// An outside agent commits its own edit here, sooner than the file watch
|
|
93
|
+
// may have looked: the voice folders follow its slides first (#954), so
|
|
94
|
+
// the commit is of a deck whose recordings are where its slides are.
|
|
95
|
+
followOutside();
|
|
91
96
|
if (!gitOn()) return json(409, { ok: false, error: 'this session is not committing — open the deck with --git' });
|
|
92
97
|
let msg = '';
|
|
93
98
|
try { msg = String(JSON.parse(body || '{}').message ?? '').trim(); } catch { /* below */ }
|
|
94
99
|
if (!msg) return json(400, { ok: false, error: 'a commit needs a message' });
|
|
95
|
-
|
|
100
|
+
// A blank line starts a BODY, as git writes one: a reviewed fix drafts
|
|
101
|
+
// the slides it rejected there (#907). Without one the message is a
|
|
102
|
+
// subject, its lines run together, as it always was.
|
|
103
|
+
const cut = msg.search(/\n[ \t]*\n/);
|
|
104
|
+
const subject = commitSubject(cut < 0 ? msg : msg.slice(0, cut), `decklight: autosave ${basename(deckPath)}`);
|
|
105
|
+
const text = cut < 0 ? '' : msg.slice(cut).trim().split('\n').map((l) => l.trimEnd()).join('\n').slice(0, 4000);
|
|
96
106
|
// gitAutocommit reports false for "nothing to commit", which is not an
|
|
97
107
|
// error: it is the answer to pressing K twice.
|
|
98
|
-
const made = gitAutocommit(deckPath, root, subject, alsoNow());
|
|
108
|
+
const made = gitAutocommit(deckPath, root, text ? `${subject}\n\n${text}` : subject, alsoNow());
|
|
99
109
|
if (!made) return json(200, { ok: true, committed: false, ...commitState() });
|
|
100
110
|
clearPendingAttr();
|
|
101
111
|
resetEpisode();
|
|
@@ -137,15 +147,22 @@ export function registerGitRoutes(routes, {
|
|
|
137
147
|
if (subjectsOff) {
|
|
138
148
|
return json(403, { ok: false, error: 'commit subjects are off in this session — it was started with --no-commit-messages' });
|
|
139
149
|
}
|
|
140
|
-
const { work, commits } = await planWorking({
|
|
150
|
+
const { work, commits, unread } = await planWorking({
|
|
141
151
|
cwd: root, deckPath, deckRel, also: alsoRels(), agent: agentPref(),
|
|
152
|
+
template: `decklight: autosave ${basename(deckPath)}`,
|
|
142
153
|
});
|
|
143
154
|
if (!work) return json(409, { ok: false, code: 'FIRST', error: 'the first commit is one commit — write its message' });
|
|
144
155
|
if (!commits) return json(200, { ok: true, base: work.base, units: [], commits: [] });
|
|
145
156
|
if (!describer() && work.units.some((u) => u.file === deckRel)) {
|
|
146
157
|
return json(409, { ok: false, error: 'no agent is installed on this machine to write one — decklight doctor lists the ones it can use' });
|
|
147
158
|
}
|
|
148
|
-
|
|
159
|
+
// `unread`: the agent was asked, and neither the plan nor the one-line
|
|
160
|
+
// subject could be read from what it said — not the same as nothing to describe
|
|
161
|
+
if (unread) console.log(` git: couldn't read the agent's plan — ${JSON.stringify(unread.answer.slice(0, 200))}`);
|
|
162
|
+
return json(200, {
|
|
163
|
+
ok: true, base: work.base, units: work.units.map(unitSummary), commits,
|
|
164
|
+
...(unread ? { unread: true, answer: unread.answer } : {}),
|
|
165
|
+
});
|
|
149
166
|
}
|
|
150
167
|
|
|
151
168
|
// The proposed commits, as the author left them: each subject theirs now,
|