decklight 0.9.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 +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- 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 +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- 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/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- 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 +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- 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 +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- 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 +825 -117
- 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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Find and replace across a deck (PRESENTING_EDITING): a phrase looked for in
|
|
6
|
+
* the FILE's text, never in the page's DOM, which the engine rewrites (code
|
|
7
|
+
* highlighted into spans, titles pinned, labels namespaced), so what is
|
|
8
|
+
* replaced is exactly what the author wrote.
|
|
9
|
+
*
|
|
10
|
+
* Only the text between tags is read: never a tag, an attribute, a comment, a
|
|
11
|
+
* script or a style. Code (`<pre>`, `<code>`) is left alone unless asked
|
|
12
|
+
* for; the speaker notes (`<aside class="notes">`) are read only when asked
|
|
13
|
+
* for, and other asides (a slide's sources) never. A run's entities are read
|
|
14
|
+
* as the characters they stand for (`Q&A` is found as `Q&A`), and what is
|
|
15
|
+
* written in their place is escaped the one way text is.
|
|
16
|
+
*
|
|
17
|
+
* A match that runs across a tag (`<b>quar</b>ter`) is not found: the panel
|
|
18
|
+
* says so when the page's own text has more matches than the file.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { sectionBodies, slideRange } from '../tools/deck-html.mjs';
|
|
22
|
+
|
|
23
|
+
const MAX_FIND = 200;
|
|
24
|
+
|
|
25
|
+
/** The units of a text run: an entity, or one character; each with what it reads as and where it stands. */
|
|
26
|
+
function unitsOf(run) {
|
|
27
|
+
const out = [];
|
|
28
|
+
const re = /&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]*);|[\s\S]/giu;
|
|
29
|
+
for (let m = re.exec(run); m; m = re.exec(run)) {
|
|
30
|
+
let text = m[0];
|
|
31
|
+
if (m[1]) {
|
|
32
|
+
const k = m[1].toLowerCase();
|
|
33
|
+
if (k[0] === '#') {
|
|
34
|
+
const cp = k[1] === 'x' ? parseInt(k.slice(2), 16) : parseInt(k.slice(1), 10);
|
|
35
|
+
text = Number.isFinite(cp) && cp > 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : m[0];
|
|
36
|
+
} else {
|
|
37
|
+
text = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' }[k] ?? m[0];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
out.push({ start: m.index, end: m.index + m[0].length, text });
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Text as it is written between tags: `&`, `<` and `>` escaped. */
|
|
46
|
+
const escapeText = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The text runs of slide markup `seg` (offsets in `seg`), each `{ start, end,
|
|
50
|
+
* notes }`: what lies between tags, outside what is never read.
|
|
51
|
+
*/
|
|
52
|
+
function textRuns(seg, { notes = false, code = false } = {}) {
|
|
53
|
+
const runs = [];
|
|
54
|
+
// what is skipped whole: comments, scripts, styles, code (unless asked), and asides (the notes read when asked)
|
|
55
|
+
const block = /<!--[\s\S]*?-->|<(script|style|textarea|pre|code|aside)\b([^>]*)>([\s\S]*?)<\/\1\s*>|<[^>]*>/gi;
|
|
56
|
+
let at = 0;
|
|
57
|
+
const text = (from, to, inNotes) => { if (to > from) runs.push({ start: from, end: to, notes: inNotes }); };
|
|
58
|
+
for (let m = block.exec(seg); m; m = block.exec(seg)) {
|
|
59
|
+
text(at, m.index, false);
|
|
60
|
+
at = m.index + m[0].length;
|
|
61
|
+
const tag = m[1]?.toLowerCase();
|
|
62
|
+
if (!tag) continue;
|
|
63
|
+
if ((tag === 'pre' || tag === 'code') && code) {
|
|
64
|
+
// code asked for: its text read as text, its own tags (a highlighted line's spans) skipped
|
|
65
|
+
const innerStart = m.index + m[0].indexOf('>') + 1;
|
|
66
|
+
for (const r of textRuns(m[3], { notes, code })) text(innerStart + r.start, innerStart + r.end, false);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (tag === 'aside' && notes && /\bclass\s*=\s*["'][^"']*\bnotes\b/i.test(m[2])) {
|
|
70
|
+
const innerStart = m.index + m[0].indexOf('>') + 1;
|
|
71
|
+
for (const r of textRuns(m[3], { notes: false, code })) text(innerStart + r.start, innerStart + r.end, true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
text(at, seg.length, false);
|
|
75
|
+
return runs;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The pattern a search is: the phrase as written, any case unless asked, a whole word when asked. */
|
|
79
|
+
function patternOf(find, { caseSensitive = false, wholeWord = false } = {}) {
|
|
80
|
+
const f = String(find ?? '');
|
|
81
|
+
if (!f.trim() || f.length > MAX_FIND || /[\u0000-\u001f]/.test(f)) throw new Error(`a phrase to find is one line of up to ${MAX_FIND} characters`);
|
|
82
|
+
const body = f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
83
|
+
const src = wholeWord ? `(?<![\\p{L}\\p{N}_])${body}(?![\\p{L}\\p{N}_])` : body;
|
|
84
|
+
return new RegExp(src, `gu${caseSensitive ? '' : 'i'}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Every match of `find` in the deck's file, in order: `{ id, slide, notes,
|
|
89
|
+
* start, end, before, text, after }`, `start`/`end` in the file and the three
|
|
90
|
+
* words around it as the slide reads them. `opts`: `{ notes, code,
|
|
91
|
+
* caseSensitive, wholeWord }`.
|
|
92
|
+
*/
|
|
93
|
+
export function findInDeck(html, find, opts = {}) {
|
|
94
|
+
const src = String(html ?? '');
|
|
95
|
+
const re = patternOf(find, opts);
|
|
96
|
+
const total = sectionBodies(src).length;
|
|
97
|
+
const matches = [];
|
|
98
|
+
for (let n = 1; n <= total; n++) {
|
|
99
|
+
let range;
|
|
100
|
+
try { range = slideRange(src, n); } catch { continue; }
|
|
101
|
+
const seg = src.slice(range.start, range.end);
|
|
102
|
+
for (const run of textRuns(seg, opts)) {
|
|
103
|
+
const units = unitsOf(seg.slice(run.start, run.end));
|
|
104
|
+
if (!units.length) continue;
|
|
105
|
+
// the run as it reads, and which unit each character came from
|
|
106
|
+
let read = '';
|
|
107
|
+
const owner = [];
|
|
108
|
+
units.forEach((u, i) => { read += u.text; for (let k = 0; k < u.text.length; k++) owner.push(i); });
|
|
109
|
+
re.lastIndex = 0;
|
|
110
|
+
for (let m = re.exec(read); m; m = re.exec(read)) {
|
|
111
|
+
if (!m[0].length) { re.lastIndex++; continue; }
|
|
112
|
+
const first = units[owner[m.index]];
|
|
113
|
+
const last = units[owner[m.index + m[0].length - 1]];
|
|
114
|
+
const start = range.start + run.start + first.start;
|
|
115
|
+
const end = range.start + run.start + last.end;
|
|
116
|
+
const squash = (s) => s.replace(/\s+/g, ' ');
|
|
117
|
+
matches.push({
|
|
118
|
+
id: `${n}:${start}`, slide: n, notes: run.notes, start, end,
|
|
119
|
+
before: squash(read.slice(Math.max(0, m.index - 30), m.index)).replace(/^\S*\s/, (w) => (m.index > 30 ? '' : w)),
|
|
120
|
+
text: m[0],
|
|
121
|
+
after: squash(read.slice(m.index + m[0].length, m.index + m[0].length + 30)),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return matches;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The deck with `find` replaced by `replace` (escaped as text): every match,
|
|
131
|
+
* or only those whose ids are in `only`. Returns `{ html, count }`.
|
|
132
|
+
*/
|
|
133
|
+
export function replaceInDeck(html, { find, replace, opts = {}, only = null }) {
|
|
134
|
+
const src = String(html ?? '');
|
|
135
|
+
const by = String(replace ?? '');
|
|
136
|
+
if (by.length > MAX_FIND || /[\u0000-\u0008\u000b-\u001f]/.test(by)) throw new Error(`a replacement is up to ${MAX_FIND} characters of text`);
|
|
137
|
+
const want = only ? new Set(only) : null;
|
|
138
|
+
const hits = findInDeck(src, find, opts).filter((m) => !want || want.has(m.id));
|
|
139
|
+
let out = src;
|
|
140
|
+
for (const m of [...hits].reverse()) out = out.slice(0, m.start) + escapeText(by) + out.slice(m.end);
|
|
141
|
+
return { html: out, count: hits.length };
|
|
142
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// A quick fix, reviewed before it lands (SPEC PRESENTING_EDITING, #907).
|
|
5
|
+
//
|
|
6
|
+
// Check deck…'s quick fixes used to land the moment they were made: the
|
|
7
|
+
// agent edited deck.html in place, the page reloaded, the work was committed,
|
|
8
|
+
// and the author met the change afterwards, on whatever slide they happened to
|
|
9
|
+
// be on. Seventy-five findings fixed in one sitting is seventy-five commits
|
|
10
|
+
// nobody looked at. Now a fix is held as a CANDIDATE: the deck on disk stays
|
|
11
|
+
// as it was, nothing is committed, no page reloads, and the review view
|
|
12
|
+
// (src/core/fixreview.js) shows the deck as it is beside the deck as the fix
|
|
13
|
+
// would make it, a slide at a time. What the author approves is merged into
|
|
14
|
+
// the deck as one write and one undo entry; the commit is theirs to make.
|
|
15
|
+
//
|
|
16
|
+
// THE UNIT IS A SLIDE. A slide can be taken from the candidate or left as it
|
|
17
|
+
// is without disturbing its neighbours, which is what makes a partial apply
|
|
18
|
+
// possible at all; the build steps inside a slide are where the view stops to
|
|
19
|
+
// show the change, not something that can be taken half of. What lies outside
|
|
20
|
+
// the slides — the head's styles, the `Decklight.init` config, anything
|
|
21
|
+
// between and after the sections — is one more unit, `head`, taken whole.
|
|
22
|
+
//
|
|
23
|
+
// Keys survive an adjustment: a changed or removed slide is named by its
|
|
24
|
+
// number in the deck AS IT IS (`s4`), which an agent working on the candidate
|
|
25
|
+
// cannot move; an added one by its number in the candidate (`a5`).
|
|
26
|
+
//
|
|
27
|
+
// The routes take their bindings explicitly, like cli/edit-slides.mjs, so a
|
|
28
|
+
// test drives them with a temp deck and no socket.
|
|
29
|
+
|
|
30
|
+
import { deckOutline, slideNames } from './commit-message.mjs';
|
|
31
|
+
import { SLIDES_TAIL, slideNamesPhrase } from '../tools/deck-html.mjs';
|
|
32
|
+
import { slideOps } from './commit-split.mjs';
|
|
33
|
+
import { withBaseHref } from './restore.mjs';
|
|
34
|
+
import { linkRuntime } from './runtime-link.mjs';
|
|
35
|
+
import { linkReferences } from './deck-refs.mjs';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The deck cut at its slides: `{ prefix, slides, gaps, suffix }`, where
|
|
39
|
+
* `prefix + slides[0] + gaps[0] + slides[1] + … + suffix` is the deck again,
|
|
40
|
+
* byte for byte. A slide is whole lines (deckOutline's ranges). Null when two
|
|
41
|
+
* slides share a line, where no cut keeps them apart. Pure.
|
|
42
|
+
*/
|
|
43
|
+
export function deckParts(html) {
|
|
44
|
+
const text = String(html ?? '');
|
|
45
|
+
const outline = deckOutline(text);
|
|
46
|
+
const starts = [0];
|
|
47
|
+
for (let i = 0; i < text.length; i++) if (text[i] === '\n') starts.push(i + 1);
|
|
48
|
+
const lineStart = (n) => starts[n - 1];
|
|
49
|
+
const lineEnd = (n) => (n < starts.length ? starts[n] - 1 : text.length);
|
|
50
|
+
const slides = [], gaps = [];
|
|
51
|
+
let at = 0, prefix = '', lastTo = 0;
|
|
52
|
+
for (const [k, s] of outline.entries()) {
|
|
53
|
+
if (s.from <= lastTo) return null;
|
|
54
|
+
const from = lineStart(s.from), to = lineEnd(s.to);
|
|
55
|
+
if (k === 0) prefix = text.slice(0, from);
|
|
56
|
+
else gaps.push(text.slice(at, from));
|
|
57
|
+
slides.push(text.slice(from, to));
|
|
58
|
+
at = to;
|
|
59
|
+
lastTo = s.to;
|
|
60
|
+
}
|
|
61
|
+
return { prefix: outline.length ? prefix : text, slides, gaps, suffix: outline.length ? text.slice(at) : '' };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** What lies outside the slides, as one comparable string; whitespace between slides is not a change. */
|
|
65
|
+
const headOf = (p) => `${p.prefix}\u0000${p.gaps.map((g) => g.trim()).filter(Boolean).join('\u0000')}\u0000${p.suffix}`;
|
|
66
|
+
|
|
67
|
+
/** What lies outside the slides, as text a person reads: the head, the config, and what follows. */
|
|
68
|
+
const outside = (p) => [p.prefix, ...p.gaps.map((g) => g.trim()).filter(Boolean), p.suffix].join('\n');
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The lines two texts do not share, with the lines they share at either end
|
|
72
|
+
* cut away: `{ before, after }`, each at most `max` lines. What the review
|
|
73
|
+
* shows for a change to the deck's head, where the slides look the same and
|
|
74
|
+
* a bundled deck's head is most of a megabyte. Pure.
|
|
75
|
+
*/
|
|
76
|
+
export function changedLines(a, b, max = 40) {
|
|
77
|
+
const x = String(a).split('\n'), y = String(b).split('\n');
|
|
78
|
+
let i = 0;
|
|
79
|
+
while (i < x.length && i < y.length && x[i] === y[i]) i++;
|
|
80
|
+
let j = 0;
|
|
81
|
+
while (j < x.length - i && j < y.length - i && x[x.length - 1 - j] === y[y.length - 1 - j]) j++;
|
|
82
|
+
const cut = (lines) => {
|
|
83
|
+
const mid = lines.slice(i, lines.length - j);
|
|
84
|
+
return (mid.length > max ? [...mid.slice(0, max), `… ${mid.length - max} more lines`] : mid).join('\n');
|
|
85
|
+
};
|
|
86
|
+
return { before: cut(x), after: cut(y) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A slide's notes as text: the aside's words, a `<br>` or a block a line. Pure. */
|
|
90
|
+
export function notesText(slideSrc) {
|
|
91
|
+
const m = /<aside\b[^>]*class\s*=\s*["'][^"']*\bnotes\b[^"']*["'][^>]*>([\s\S]*?)<\/aside\s*>/i.exec(String(slideSrc ?? ''));
|
|
92
|
+
if (!m) return '';
|
|
93
|
+
return m[1]
|
|
94
|
+
.replace(/<br\s*\/?>/gi, '\n')
|
|
95
|
+
.replace(/<\/(p|div|li)\s*>/gi, '\n')
|
|
96
|
+
.replace(/<[^>]*>/g, '')
|
|
97
|
+
.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/ /g, ' ')
|
|
98
|
+
.replace(/&/g, '&')
|
|
99
|
+
.split('\n').map((l) => l.trim()).join('\n')
|
|
100
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
101
|
+
.trim();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A slide's source with its notes aside taken out, whitespace around the cut set aside. Pure. */
|
|
105
|
+
const sansNotes = (src) => String(src ?? '').replace(/\s*<aside\b[^>]*class\s*=\s*["'][^"']*\bnotes\b[^"']*["'][^>]*>[\s\S]*?<\/aside\s*>\s*/i, '');
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether `a` → `b` changes nothing but punctuation and spacing. The page's
|
|
109
|
+
* own test (src/core/worddiff.js) restated: src/ does not ship. Pure.
|
|
110
|
+
*/
|
|
111
|
+
const punctuationOnly = (a, b) => {
|
|
112
|
+
const bare = (s) => String(s ?? '').replace(/[\s\p{P}\p{S}]+/gu, '');
|
|
113
|
+
return String(a ?? '') !== String(b ?? '') && bare(a) === bare(b);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** A slide's title, as the outline reads it (its first h1/h2), or null. */
|
|
117
|
+
const titleOf = (src) => deckOutline(src)[0]?.heading ?? null;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* What a candidate changes, as the units a review decides on, in reading
|
|
121
|
+
* order: `{ key, kind, slide?, was?, title, notes? }`. `kind` is `head`,
|
|
122
|
+
* `changed`, `added` or `removed`; `slide` numbers the slide in the
|
|
123
|
+
* candidate, `was` in the deck as it is. `notes: { before, after }` when the
|
|
124
|
+
* slide's notes differ; `punctuationOnly` when the slide's source changed
|
|
125
|
+
* only in punctuation and spacing, a change to look at closely. Null when the deck cannot be cut (deckParts). Pure.
|
|
126
|
+
*/
|
|
127
|
+
export function candidateUnits(before, after) {
|
|
128
|
+
const pb = deckParts(before), pa = deckParts(after);
|
|
129
|
+
if (!pb || !pa) return null;
|
|
130
|
+
const units = [];
|
|
131
|
+
if (headOf(pb) !== headOf(pa)) {
|
|
132
|
+
units.push({ key: 'head', kind: 'head', title: 'the deck: styles, config and anything outside the slides', lines: changedLines(outside(pb), outside(pa)) });
|
|
133
|
+
}
|
|
134
|
+
for (const op of slideOps(before, after)) {
|
|
135
|
+
if (op.kind === 'same') continue;
|
|
136
|
+
const was = op.was ? pb.slides[op.was - 1] : null;
|
|
137
|
+
const now = op.slide ? pa.slides[op.slide - 1] : null;
|
|
138
|
+
const unit = {
|
|
139
|
+
key: op.kind === 'added' ? `a${op.slide}` : `s${op.was}`,
|
|
140
|
+
kind: op.kind,
|
|
141
|
+
...(op.slide ? { slide: op.slide } : {}),
|
|
142
|
+
...(op.was ? { was: op.was } : {}),
|
|
143
|
+
title: titleOf(now ?? was) ?? titleOf(was ?? '') ?? null,
|
|
144
|
+
};
|
|
145
|
+
const nb = was === null ? '' : notesText(was), na = now === null ? '' : notesText(now);
|
|
146
|
+
if (nb !== na) unit.notes = { before: nb, after: na };
|
|
147
|
+
// the notes are the whole change: the slide looks the same, and the
|
|
148
|
+
// review reads the two scripts rather than two identical renders
|
|
149
|
+
if (op.kind === 'changed' && unit.notes && sansNotes(was) === sansNotes(now)) unit.notesOnly = true;
|
|
150
|
+
if (op.kind === 'changed' && punctuationOnly(was, now)) unit.punctuationOnly = true;
|
|
151
|
+
units.push(unit);
|
|
152
|
+
}
|
|
153
|
+
return units;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The deck with the units in `take` from the candidate and everything else as
|
|
158
|
+
* it is. Taking every unit is the candidate exactly, taking none the deck
|
|
159
|
+
* exactly; in between, each slide is the version its unit chose, joined by the
|
|
160
|
+
* spacing of the version it came from. Null when either side cannot be cut.
|
|
161
|
+
* Pure.
|
|
162
|
+
*/
|
|
163
|
+
export function mergeCandidate(before, after, take) {
|
|
164
|
+
const want = take instanceof Set ? take : new Set(take ?? []);
|
|
165
|
+
const units = candidateUnits(before, after);
|
|
166
|
+
if (!units) return null;
|
|
167
|
+
if (units.every((u) => want.has(u.key))) return after;
|
|
168
|
+
if (!units.some((u) => want.has(u.key))) return before;
|
|
169
|
+
const pb = deckParts(before), pa = deckParts(after);
|
|
170
|
+
const shell = want.has('head') ? pa : pb;
|
|
171
|
+
// each slide kept, with the spacing that followed it where it came from
|
|
172
|
+
const out = [];
|
|
173
|
+
const from = (p, n) => ({ text: p.slides[n - 1], gap: p.gaps[n - 1] ?? null });
|
|
174
|
+
for (const op of slideOps(before, after)) {
|
|
175
|
+
if (op.kind === 'same') out.push(from(pb, op.was));
|
|
176
|
+
else if (op.kind === 'changed') out.push(want.has(`s${op.was}`) ? from(pa, op.slide) : from(pb, op.was));
|
|
177
|
+
else if (op.kind === 'added') { if (want.has(`a${op.slide}`)) out.push(from(pa, op.slide)); }
|
|
178
|
+
else if (!want.has(`s${op.was}`)) out.push(from(pb, op.was));
|
|
179
|
+
}
|
|
180
|
+
const spacing = pb.gaps[0] ?? pa.gaps[0] ?? '\n';
|
|
181
|
+
return shell.prefix
|
|
182
|
+
+ out.map((s, i) => (i < out.length - 1 ? s.text + (s.gap ?? spacing) : s.text)).join('')
|
|
183
|
+
+ shell.suffix;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Where a unit is, in words: `slide 4`, `slide 5 (added)`, `slide 3 (removed)`, `the deck`. */
|
|
187
|
+
export const unitPlace = (u) => (u.kind === 'head' ? 'the deck'
|
|
188
|
+
: u.kind === 'added' ? `slide ${u.slide} (added)`
|
|
189
|
+
: u.kind === 'removed' ? `slide ${u.was} (removed)` : `slide ${u.slide}`);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The commit a reviewed apply drafts: `{ subject, body }`. The subject names
|
|
193
|
+
* what landed, on the slides it landed on, by their names (`fix: off-role on
|
|
194
|
+
* "Pricing" and "Roadmap"`, `slideNames` of the deck before and after), never
|
|
195
|
+
* their numbers; the body lists what was rejected, with the reviewer's
|
|
196
|
+
* comment, so the history says what the fix did NOT do as well. `what` is
|
|
197
|
+
* `fix: <rule>`, or an agent-review ask's own words. Pure.
|
|
198
|
+
*/
|
|
199
|
+
export function commitDraft(what, units, taken, rejected = [], { before = '', after = '' } = {}) {
|
|
200
|
+
const took = units.filter((u) => taken.has(u.key));
|
|
201
|
+
const now = slideNames(after);
|
|
202
|
+
const then = slideNames(before);
|
|
203
|
+
const named = took.filter((u) => u.kind !== 'head')
|
|
204
|
+
.sort((a, b) => (a.slide ?? a.was) - (b.slide ?? b.was))
|
|
205
|
+
.map((u) => (u.kind === 'removed' ? then[u.was - 1] : now[u.slide - 1]) ?? null);
|
|
206
|
+
const base = String(what || 'fix').replace(SLIDES_TAIL, '');
|
|
207
|
+
const called = slideNamesPhrase(named);
|
|
208
|
+
const subject = called ? `${base} on ${called}` : base;
|
|
209
|
+
const lines = rejected
|
|
210
|
+
.map((r) => { const u = units.find((x) => x.key === r.key); return u ? `- ${unitPlace(u)}${r.comment ? `: ${String(r.comment).replace(/\s+/g, ' ').trim()}` : ''}` : null; })
|
|
211
|
+
.filter(Boolean);
|
|
212
|
+
return { subject, body: lines.length ? `Rejected in review:\n${lines.join('\n')}` : '' };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Put the review's routes into `routes` and hand back the door the fixers
|
|
217
|
+
* use: `hold({ before, after, what, rule?, slide?, agent? })` keeps a fix as
|
|
218
|
+
* THE candidate (one at a time: a new fix replaces one never applied) and
|
|
219
|
+
* answers its summary; `held()` is the candidate or null; `adjusted(id, after)`
|
|
220
|
+
* replaces its deck after an agent adjusted one slide of it.
|
|
221
|
+
*
|
|
222
|
+
* `ctx`: `readDeck()`; `applyEdit(next, before)`, the one undo entry;
|
|
223
|
+
* `broadcast(event, data)`; `saveBefore(what)`, which commits the work that
|
|
224
|
+
* was already outstanding so the fix's own commit is only the fix; and
|
|
225
|
+
* `adjust({ candidate, unit, comment })`, which hands one slide back to the
|
|
226
|
+
* agent and answers `{ ok, agent }` or `{ ok: false, error, code }`.
|
|
227
|
+
*/
|
|
228
|
+
export function registerFixReviewRoutes(routes, {
|
|
229
|
+
readDeck, applyEdit, broadcast = () => {}, saveBefore = () => {}, adjust = null,
|
|
230
|
+
}) {
|
|
231
|
+
let candidate = null; // { id, rev, before, after, what, rule, slide, agent, units, at }
|
|
232
|
+
let seq = 0;
|
|
233
|
+
|
|
234
|
+
const summary = (c) => ({
|
|
235
|
+
id: c.id, rev: c.rev, what: c.what, kind: c.kind, rule: c.rule ?? null, slide: c.slide ?? null, agent: c.agent ?? null,
|
|
236
|
+
units: c.units, left: c.left, adjusting: c.adjusting ?? null,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* `kind` says what made the candidate, for the review's words: a `fix`
|
|
241
|
+
* (Check deck…), a `script` rewrite (the writing tools, PRESENTING_VOICE),
|
|
242
|
+
* or an `ask` (A). `left` lists the slides the job looked at and left as
|
|
243
|
+
* they were, `[{ slide, why }]`: an answer that failed its check, a slide
|
|
244
|
+
* edited while the agent thought. They are not units (nothing changed
|
|
245
|
+
* there), but the review says so rather than leaving the author to guess.
|
|
246
|
+
*/
|
|
247
|
+
function hold({ before, after, what, kind = 'fix', rule = null, slide = null, agent = null, left = [] }) {
|
|
248
|
+
const units = candidateUnits(before, after);
|
|
249
|
+
if (!units) return { ok: false, error: 'this deck puts two slides on one line — a change to it cannot be reviewed slide by slide' };
|
|
250
|
+
candidate = { id: `c${++seq}`, rev: 1, before, after, what, kind, rule, slide, agent, units, left, at: Date.now() };
|
|
251
|
+
console.log(` ${kind}: "${what}" held for review — ${units.length} change${units.length === 1 ? '' : 's'}, nothing written`);
|
|
252
|
+
return { ok: true, ...summary(candidate) };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function adjusted(id, after, key) {
|
|
256
|
+
if (!candidate || candidate.id !== id) return null;
|
|
257
|
+
candidate.adjusting = null;
|
|
258
|
+
const units = after === null ? null : candidateUnits(candidate.before, after);
|
|
259
|
+
if (units) { candidate.after = after; candidate.units = units; candidate.rev += 1; }
|
|
260
|
+
broadcast('candidate', { id, rev: candidate.rev, adjusted: key, ok: !!units });
|
|
261
|
+
return candidate;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const current = (id) => (candidate && candidate.id === id ? candidate : null);
|
|
265
|
+
|
|
266
|
+
function candidateRoute({ url, json }) {
|
|
267
|
+
const id = url.searchParams.get('id');
|
|
268
|
+
if (!candidate || (id && candidate.id !== id)) return json(404, { ok: false, error: 'no fix is waiting for review' });
|
|
269
|
+
return json(200, { ok: true, ...summary(candidate) });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* One side of the candidate as a page, served the way a version in the
|
|
274
|
+
* history is (the `<base>`, the runtime, the references it marks), so the
|
|
275
|
+
* two panes are drawn by the same runtime from the same place.
|
|
276
|
+
*/
|
|
277
|
+
function candidateAtRoute({ res, url, json, CORS }) {
|
|
278
|
+
const c = current(url.searchParams.get('id'));
|
|
279
|
+
if (!c) return json(404, { ok: false, error: 'no such fix waiting for review' });
|
|
280
|
+
const side = url.searchParams.get('side') === 'after' ? c.after : c.before;
|
|
281
|
+
res.writeHead(200, { ...CORS, 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
282
|
+
return res.end(linkReferences(linkRuntime(withBaseHref(side))));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* `POST /deck/edit/candidate/apply { id, take: [key], rejected: [{ key,
|
|
287
|
+
* comment? }] }`: the approved slides from the candidate, everything else as
|
|
288
|
+
* it is, written as ONE undo entry. Refused when the deck moved since the
|
|
289
|
+
* fix was made: the review was of a deck that no longer exists. Nothing is
|
|
290
|
+
* committed here; the answer carries the commit the page offers.
|
|
291
|
+
*/
|
|
292
|
+
function applyRoute({ body, json }) {
|
|
293
|
+
const { id, take = [], rejected = [] } = JSON.parse(body || '{}');
|
|
294
|
+
if (!Array.isArray(take) || !Array.isArray(rejected)) throw new Error('bad payload');
|
|
295
|
+
const c = current(id);
|
|
296
|
+
if (!c) return json(404, { ok: false, error: 'no such fix waiting for review — it was discarded or replaced' });
|
|
297
|
+
if (c.adjusting) return json(409, { ok: false, error: 'the agent is still adjusting it' });
|
|
298
|
+
if (readDeck() !== c.before) {
|
|
299
|
+
return json(409, { ok: false, code: 'MOVED', error: 'the deck changed while the fix was waiting — run the fix again on the deck as it is now' });
|
|
300
|
+
}
|
|
301
|
+
const keys = new Set(c.units.map((u) => u.key));
|
|
302
|
+
const taken = new Set(take.filter((k) => keys.has(k)));
|
|
303
|
+
const said = rejected.filter((r) => r && keys.has(r.key) && !taken.has(r.key))
|
|
304
|
+
.map((r) => ({ key: r.key, comment: typeof r.comment === 'string' ? r.comment.slice(0, 500) : '' }));
|
|
305
|
+
const skipped = c.units.length - taken.size;
|
|
306
|
+
const line = `applied ${taken.size} of ${c.units.length}${said.length ? ` · ${said.length} rejected` : ''}`
|
|
307
|
+
+ (skipped - said.length > 0 ? ` · ${skipped - said.length} left out` : '');
|
|
308
|
+
candidate = null;
|
|
309
|
+
if (!taken.size) {
|
|
310
|
+
console.log(` fix: "${c.what}" — nothing approved, the deck stays as it is`);
|
|
311
|
+
return json(200, { ok: true, changed: false, said: 'nothing approved — the deck is unchanged', applied: 0, of: c.units.length });
|
|
312
|
+
}
|
|
313
|
+
const next = mergeCandidate(c.before, c.after, taken);
|
|
314
|
+
if (next === null) return json(409, { ok: false, error: 'the fix could not be merged slide by slide' });
|
|
315
|
+
saveBefore(c.what);
|
|
316
|
+
const changed = applyEdit(next, c.before);
|
|
317
|
+
const commit = commitDraft(c.what, c.units, taken, said, { before: c.before, after: c.after });
|
|
318
|
+
console.log(` fix: "${c.what}" — ${line}`);
|
|
319
|
+
return json(200, { ok: true, changed, said: line, applied: taken.size, of: c.units.length, rejected: said.length, commit });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function discardRoute({ body, json }) {
|
|
323
|
+
const { id } = JSON.parse(body || '{}');
|
|
324
|
+
const c = current(id);
|
|
325
|
+
if (!c) return json(200, { ok: true, discarded: false });
|
|
326
|
+
candidate = null;
|
|
327
|
+
console.log(` fix: "${c.what}" discarded — the deck stays as it is`);
|
|
328
|
+
return json(200, { ok: true, discarded: true });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* `POST /deck/edit/candidate/adjust { id, key, comment }`: that slide of the
|
|
333
|
+
* candidate back to the agent with the reviewer's words. The answer is
|
|
334
|
+
* immediate; a `candidate` event says when the new version is in.
|
|
335
|
+
*/
|
|
336
|
+
async function adjustRoute({ body, json }) {
|
|
337
|
+
const { id, key, comment } = JSON.parse(body || '{}');
|
|
338
|
+
if (typeof comment !== 'string' || !comment.trim()) return json(400, { ok: false, error: 'say what to change' });
|
|
339
|
+
const c = current(id);
|
|
340
|
+
if (!c) return json(404, { ok: false, error: 'no such fix waiting for review' });
|
|
341
|
+
const unit = c.units.find((u) => u.key === key);
|
|
342
|
+
if (!unit) return json(400, { ok: false, error: 'no such change in this fix' });
|
|
343
|
+
if (unit.kind === 'removed') return json(400, { ok: false, error: 'a removed slide has nothing to adjust — reject it to keep it' });
|
|
344
|
+
if (c.adjusting) return json(409, { ok: false, error: 'the agent is already adjusting it' });
|
|
345
|
+
if (!adjust) return json(409, { ok: false, error: 'no agent CLI on this machine to adjust it' });
|
|
346
|
+
// marked first: the agent may be done (and `adjusted` called) before `adjust` answers
|
|
347
|
+
c.adjusting = key;
|
|
348
|
+
const r = await adjust({ candidate: c, unit, comment: comment.trim().slice(0, 1000) });
|
|
349
|
+
if (!r?.ok) { if (c.adjusting === key) c.adjusting = null; return json(r?.code ?? 409, { ok: false, error: r?.error ?? 'the agent could not be asked' }); }
|
|
350
|
+
return json(200, { ok: true, agent: r.agent, adjusting: c.adjusting });
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
routes.set('GET /deck/edit/candidate', candidateRoute);
|
|
354
|
+
routes.set('GET /deck/edit/candidate/at', candidateAtRoute);
|
|
355
|
+
routes.set('POST /deck/edit/candidate/apply', applyRoute);
|
|
356
|
+
routes.set('POST /deck/edit/candidate/discard', discardRoute);
|
|
357
|
+
routes.set('POST /deck/edit/candidate/adjust', adjustRoute);
|
|
358
|
+
return { hold, held: () => candidate, adjusted };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The ask that adjusts one slide of a held fix: the reviewer's words, the
|
|
363
|
+
* slide, and the instruction to leave the rest alone — the agent works on
|
|
364
|
+
* the candidate, which is in the deck file while it runs.
|
|
365
|
+
*/
|
|
366
|
+
export const adjustPrompt = (unit, comment, what) => `This deck holds a proposed fix ("${what}") that is being reviewed.`
|
|
367
|
+
+ ` On slide ${unit.slide}${unit.title ? ` ("${unit.title}")` : ''}, the reviewer asks for a change to it: ${comment}`
|
|
368
|
+
+ ' Change only that slide, and only as asked; leave every other slide exactly as it is.';
|
package/cli/git.mjs
CHANGED
|
@@ -161,6 +161,19 @@ export function commitSubject(raw, fallback) {
|
|
|
161
161
|
return /^-/.test(capped) ? `agent: ${capped}` : capped;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* The untracked files under `dir` git does not ignore, relative to it, a
|
|
166
|
+
* wholly new directory said once as `name/` — what an agent run may leave
|
|
167
|
+
* beside the deck. Null when git cannot answer.
|
|
168
|
+
*/
|
|
169
|
+
export function untrackedFiles(dir) {
|
|
170
|
+
try {
|
|
171
|
+
const out = execFileSync('git', ['ls-files', '--others', '--exclude-standard', '--directory', '-z', '--', '.'],
|
|
172
|
+
{ cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
173
|
+
return out.split('\0').filter(Boolean).sort();
|
|
174
|
+
} catch { return null; }
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
/**
|
|
165
178
|
* The sha of the commit `gitAutocommit` last made, or null.
|
|
166
179
|
*
|