@caelo-cms/shared 0.10.52 → 0.10.53
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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/markup-structure.d.ts +79 -0
- package/dist/markup-structure.d.ts.map +1 -0
- package/dist/markup-structure.js +274 -0
- package/dist/markup-structure.js.map +1 -0
- package/dist/media.d.ts +24 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +35 -0
- package/dist/media.js.map +1 -1
- package/dist/preview-compose.d.ts +4 -3
- package/dist/preview-compose.d.ts.map +1 -1
- package/dist/preview-compose.js +2 -1
- package/dist/preview-compose.js.map +1 -1
- package/dist/publish-live-parity.d.ts +18 -0
- package/dist/publish-live-parity.d.ts.map +1 -0
- package/dist/publish-live-parity.js +21 -0
- package/dist/publish-live-parity.js.map +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/markup-structure.test.ts +184 -0
- package/src/markup-structure.ts +304 -0
- package/src/media.ts +43 -0
- package/src/preview-compose.ts +6 -4
- package/src/publish-live-parity.ts +25 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Issue #820 — structural fingerprints of HTML, for telling "this markup is
|
|
5
|
+
* a reusable pattern that already exists elsewhere" from one-off content.
|
|
6
|
+
*
|
|
7
|
+
* Free HTML (a step chain, a comparison table, a timeline pasted into a
|
|
8
|
+
* richtext value, or minted as a one-off module per page) is cheap to
|
|
9
|
+
* write and expensive to keep: every copy is edited separately, the copies
|
|
10
|
+
* drift, and the pattern's CSS has to live in the layout where it ships on
|
|
11
|
+
* every page. The fix is to make the second copy a module. This file gives
|
|
12
|
+
* the write-time guard and the core `structure` quality check one shared
|
|
13
|
+
* notion of "the same markup":
|
|
14
|
+
*
|
|
15
|
+
* - A node's SIGNATURE is its tag plus sorted class tokens plus the
|
|
16
|
+
* signatures of its distinct children (first-occurrence order). Text,
|
|
17
|
+
* attribute values and repetition are ignored, so a 5-step chain and a
|
|
18
|
+
* 7-step chain with different copy are the same pattern.
|
|
19
|
+
* - A subtree QUALIFIES as a pattern when it is big enough to be a
|
|
20
|
+
* component (MIN_PATTERN_NODES distinct nodes over MIN_PATTERN_DEPTH
|
|
21
|
+
* levels) and carries at least one class. Prose converted from Markdown
|
|
22
|
+
* (`<ul><li><a>`, plain tables) has no classes and never qualifies; an
|
|
23
|
+
* authored component always has them.
|
|
24
|
+
* - SIMILARITY is the Jaccard index over parent→child edges, for near
|
|
25
|
+
* matches that are not exact (a pattern with one extra element).
|
|
26
|
+
*
|
|
27
|
+
* The site importer's boilerplate walker (site-importer/boilerplate.ts)
|
|
28
|
+
* stays separate on purpose: it streams byte ranges, hashes text into a
|
|
29
|
+
* content signature, and its signatures are persisted and replayed
|
|
30
|
+
* (#424), so its output must stay byte-stable.
|
|
31
|
+
*
|
|
32
|
+
* Every walk is bounded (MAX_NODES) so an adversarial body cannot blow it up.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { Parser } from "htmlparser2";
|
|
36
|
+
|
|
37
|
+
/** One element of parsed markup. Text is dropped; it never matters here. */
|
|
38
|
+
export interface MarkupNode {
|
|
39
|
+
readonly tag: string;
|
|
40
|
+
readonly classes: readonly string[];
|
|
41
|
+
/** The `data-caelo-module-id` the composer stamps on every module root. */
|
|
42
|
+
readonly moduleId: string | null;
|
|
43
|
+
readonly children: MarkupNode[];
|
|
44
|
+
readonly parent: MarkupNode | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Most elements one parse keeps; the rest of the document is ignored. */
|
|
48
|
+
export const MAX_NODES = 50_000;
|
|
49
|
+
/** A pattern has at least this many distinct nodes… */
|
|
50
|
+
export const MIN_PATTERN_NODES = 4;
|
|
51
|
+
/** …spread over at least this many levels (root, child, grandchild). */
|
|
52
|
+
export const MIN_PATTERN_DEPTH = 3;
|
|
53
|
+
/** Jaccard similarity at or above which two patterns are "near" matches. */
|
|
54
|
+
export const NEAR_MATCH_THRESHOLD = 0.8;
|
|
55
|
+
|
|
56
|
+
/** Elements whose inside is not markup structure (icons, raw text). */
|
|
57
|
+
const LEAF_TAGS = new Set(["svg", "math", "script", "style", "noscript", "iframe"]);
|
|
58
|
+
|
|
59
|
+
/** Parse markup into a forest of element nodes. */
|
|
60
|
+
export function parseMarkup(html: string): MarkupNode[] {
|
|
61
|
+
const roots: MarkupNode[] = [];
|
|
62
|
+
const stack: (MarkupNode | null)[] = [];
|
|
63
|
+
let count = 0;
|
|
64
|
+
let leafDepth = 0;
|
|
65
|
+
const parser = new Parser(
|
|
66
|
+
{
|
|
67
|
+
onopentag(name, attribs) {
|
|
68
|
+
if (leafDepth > 0 || count >= MAX_NODES) {
|
|
69
|
+
stack.push(null);
|
|
70
|
+
if (leafDepth > 0) leafDepth++;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const tag = name.toLowerCase();
|
|
74
|
+
const parent = findOpen(stack);
|
|
75
|
+
const node: MarkupNode = {
|
|
76
|
+
tag,
|
|
77
|
+
classes: splitClasses(attribs.class),
|
|
78
|
+
moduleId: attribs["data-caelo-module-id"] ?? null,
|
|
79
|
+
children: [],
|
|
80
|
+
parent,
|
|
81
|
+
};
|
|
82
|
+
count++;
|
|
83
|
+
if (parent) parent.children.push(node);
|
|
84
|
+
else roots.push(node);
|
|
85
|
+
stack.push(node);
|
|
86
|
+
if (LEAF_TAGS.has(tag)) leafDepth = 1;
|
|
87
|
+
},
|
|
88
|
+
onclosetag() {
|
|
89
|
+
stack.pop();
|
|
90
|
+
if (leafDepth > 0) leafDepth--;
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{ decodeEntities: true, lowerCaseTags: true },
|
|
94
|
+
);
|
|
95
|
+
parser.write(html);
|
|
96
|
+
parser.end();
|
|
97
|
+
return roots;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function findOpen(stack: readonly (MarkupNode | null)[]): MarkupNode | null {
|
|
101
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
102
|
+
const n = stack[i];
|
|
103
|
+
if (n) return n;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function splitClasses(raw: string | undefined): string[] {
|
|
109
|
+
if (!raw) return [];
|
|
110
|
+
return [...new Set(raw.split(/\s+/).filter((c) => c.length > 0))].sort();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Remove Mustache tags (`{{x}}`, `{{{x}}}`, `{{#s}}`, `{{/s}}`, `{{>p}}`)
|
|
115
|
+
* from a module template so it parses as the markup it renders: a section
|
|
116
|
+
* body stays once, a placeholder becomes empty.
|
|
117
|
+
*/
|
|
118
|
+
export function stripMustache(template: string): string {
|
|
119
|
+
return stripDelimited(stripDelimited(template, 3), 2);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Removes every `{`×n + non-`}` run + `}`×n span, leftmost first — the
|
|
124
|
+
* same result as `replace(/\{{n}[^}]*\}{n}/g, "")`, in linear time. The
|
|
125
|
+
* regex form backtracks quadratically on long `{{{{…` runs in module HTML
|
|
126
|
+
* (CodeQL js/polynomial-redos); here, when the first `}` after an opener
|
|
127
|
+
* does not start the closer, no opener before that `}` can match either
|
|
128
|
+
* (they all hit the same `}`), so the scan resumes there.
|
|
129
|
+
*/
|
|
130
|
+
function stripDelimited(text: string, n: number): string {
|
|
131
|
+
const opener = "{".repeat(n);
|
|
132
|
+
const closer = "}".repeat(n);
|
|
133
|
+
let out = "";
|
|
134
|
+
let i = 0;
|
|
135
|
+
while (i < text.length) {
|
|
136
|
+
const open = text.indexOf(opener, i);
|
|
137
|
+
if (open < 0) break;
|
|
138
|
+
const brace = text.indexOf("}", open + n);
|
|
139
|
+
if (brace < 0) break;
|
|
140
|
+
if (text.startsWith(closer, brace)) {
|
|
141
|
+
out += text.slice(i, open);
|
|
142
|
+
i = brace + n;
|
|
143
|
+
} else {
|
|
144
|
+
out += text.slice(i, brace);
|
|
145
|
+
i = brace;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return out + text.slice(i);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The node's key without its children: `div.card.card--wide`. */
|
|
152
|
+
export function nodeKey(n: Pick<MarkupNode, "tag" | "classes">): string {
|
|
153
|
+
return n.classes.length === 0 ? n.tag : `${n.tag}.${n.classes.join(".")}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Structural facts about one subtree. */
|
|
157
|
+
export interface SubtreeShape {
|
|
158
|
+
/** Repetition- and text-independent structural signature. */
|
|
159
|
+
readonly signature: string;
|
|
160
|
+
/** Distinct nodes after repetition collapse. */
|
|
161
|
+
readonly nodeCount: number;
|
|
162
|
+
/** Levels, the subtree root counting as 1. */
|
|
163
|
+
readonly depth: number;
|
|
164
|
+
/** Whether any node in it carries a class. */
|
|
165
|
+
readonly hasClass: boolean;
|
|
166
|
+
/** Parent→child edges, for near-match similarity. */
|
|
167
|
+
readonly edges: ReadonlySet<string>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Compute the shapes of a subtree and all its descendants in one pass.
|
|
172
|
+
* Nested module roots are opaque: their own module owns them.
|
|
173
|
+
*/
|
|
174
|
+
export function shapeTree(root: MarkupNode, out = new Map<MarkupNode, SubtreeShape>()) {
|
|
175
|
+
const visit = (n: MarkupNode): SubtreeShape => {
|
|
176
|
+
const seen = new Set<string>();
|
|
177
|
+
const parts: string[] = [];
|
|
178
|
+
let nodeCount = 1;
|
|
179
|
+
let depth = 1;
|
|
180
|
+
let hasClass = n.classes.length > 0;
|
|
181
|
+
const edges = new Set<string>();
|
|
182
|
+
const key = nodeKey(n);
|
|
183
|
+
for (const c of n.children) {
|
|
184
|
+
if (c.moduleId !== null) continue;
|
|
185
|
+
const s = visit(c);
|
|
186
|
+
if (seen.has(s.signature)) continue;
|
|
187
|
+
seen.add(s.signature);
|
|
188
|
+
parts.push(s.signature);
|
|
189
|
+
nodeCount += s.nodeCount;
|
|
190
|
+
depth = Math.max(depth, s.depth + 1);
|
|
191
|
+
hasClass ||= s.hasClass;
|
|
192
|
+
edges.add(`${key}>${nodeKey(c)}`);
|
|
193
|
+
for (const e of s.edges) edges.add(e);
|
|
194
|
+
}
|
|
195
|
+
const shape: SubtreeShape = {
|
|
196
|
+
signature: parts.length === 0 ? key : `${key}(${parts.join(",")})`,
|
|
197
|
+
nodeCount,
|
|
198
|
+
depth,
|
|
199
|
+
hasClass,
|
|
200
|
+
edges,
|
|
201
|
+
};
|
|
202
|
+
out.set(n, shape);
|
|
203
|
+
return shape;
|
|
204
|
+
};
|
|
205
|
+
visit(root);
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Whether a subtree is big and specific enough to count as a pattern. */
|
|
210
|
+
export function isPattern(shape: SubtreeShape): boolean {
|
|
211
|
+
return shape.hasClass && shape.nodeCount >= MIN_PATTERN_NODES && shape.depth >= MIN_PATTERN_DEPTH;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Jaccard similarity of two shapes' edge sets, 0…1. */
|
|
215
|
+
export function shapeSimilarity(a: SubtreeShape, b: SubtreeShape): number {
|
|
216
|
+
if (a.signature === b.signature) return 1;
|
|
217
|
+
let shared = 0;
|
|
218
|
+
for (const e of a.edges) if (b.edges.has(e)) shared++;
|
|
219
|
+
const union = a.edges.size + b.edges.size - shared;
|
|
220
|
+
return union === 0 ? 0 : shared / union;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A qualifying pattern found in a piece of markup. */
|
|
224
|
+
export interface FoundPattern {
|
|
225
|
+
readonly node: MarkupNode;
|
|
226
|
+
readonly shape: SubtreeShape;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The outermost qualifying patterns in a forest: a pattern inside a bigger
|
|
231
|
+
* pattern is part of it and not reported on its own.
|
|
232
|
+
*/
|
|
233
|
+
export function outermostPatterns(roots: readonly MarkupNode[]): FoundPattern[] {
|
|
234
|
+
const found: FoundPattern[] = [];
|
|
235
|
+
const walk = (n: MarkupNode, shapes: Map<MarkupNode, SubtreeShape>) => {
|
|
236
|
+
const shape = shapes.get(n);
|
|
237
|
+
if (shape && isPattern(shape)) {
|
|
238
|
+
found.push({ node: n, shape });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
for (const c of n.children) if (c.moduleId === null) walk(c, shapes);
|
|
242
|
+
};
|
|
243
|
+
for (const r of roots) walk(r, shapeTree(r));
|
|
244
|
+
return found;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The shape of a whole module template (its first element), or null. */
|
|
248
|
+
export function templateShape(templateHtml: string): SubtreeShape | null {
|
|
249
|
+
const root = parseMarkup(stripMustache(templateHtml))[0];
|
|
250
|
+
return root ? (shapeTree(root).get(root) ?? null) : null;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The parts of a rendered module that did NOT come from its template: the
|
|
255
|
+
* markup field values injected (richtext, text). The rendered tree is
|
|
256
|
+
* walked in step with the template tree; a rendered child that no template
|
|
257
|
+
* child can account for (same tag, template's classes all present) starts
|
|
258
|
+
* a free region. List sections still match, because every iteration of a
|
|
259
|
+
* section renders the same template child.
|
|
260
|
+
*
|
|
261
|
+
* @returns the free region roots, or null when the rendered root does not
|
|
262
|
+
* match the template root at all (a module the composer renders from
|
|
263
|
+
* other data, such as a navigation menu) — nothing can be attributed then.
|
|
264
|
+
*/
|
|
265
|
+
export function freeRegions(
|
|
266
|
+
rendered: MarkupNode,
|
|
267
|
+
templateRoots: readonly MarkupNode[],
|
|
268
|
+
): MarkupNode[] | null {
|
|
269
|
+
const tRoot = templateRoots[0];
|
|
270
|
+
if (!tRoot || !accounts(tRoot, rendered)) return null;
|
|
271
|
+
const free: MarkupNode[] = [];
|
|
272
|
+
const walk = (r: MarkupNode, t: MarkupNode) => {
|
|
273
|
+
for (const c of r.children) {
|
|
274
|
+
if (c.moduleId !== null) continue;
|
|
275
|
+
const match = t.children.find((tc) => accounts(tc, c));
|
|
276
|
+
if (match) walk(c, match);
|
|
277
|
+
else free.push(c);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
walk(rendered, tRoot);
|
|
281
|
+
return free;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function accounts(template: MarkupNode, rendered: MarkupNode): boolean {
|
|
285
|
+
return (
|
|
286
|
+
template.tag === rendered.tag && template.classes.every((k) => rendered.classes.includes(k))
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Every module root (`data-caelo-module-id`) in a forest, nested ones included. */
|
|
291
|
+
export function moduleRoots(roots: readonly MarkupNode[]): MarkupNode[] {
|
|
292
|
+
const out: MarkupNode[] = [];
|
|
293
|
+
const walk = (n: MarkupNode) => {
|
|
294
|
+
if (n.moduleId !== null) out.push(n);
|
|
295
|
+
for (const c of n.children) walk(c);
|
|
296
|
+
};
|
|
297
|
+
for (const r of roots) walk(r);
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** A short operator-readable name for a pattern: its root key, e.g. `div.chain`. */
|
|
302
|
+
export function patternLabel(p: Pick<MarkupNode, "tag" | "classes">): string {
|
|
303
|
+
return nodeKey(p);
|
|
304
|
+
}
|
package/src/media.ts
CHANGED
|
@@ -123,6 +123,49 @@ export function buildMediaUrl(slug: string, variant: MediaVariantTag | string):
|
|
|
123
123
|
: `${MEDIA_URL_PREFIX}/${slug}/${variant}`;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* The favicon rendition of a raster image bound to the theme's favicon
|
|
128
|
+
* slot: a square PNG, `FAVICON_VARIANT_PX` on each side. Browsers show a
|
|
129
|
+
* favicon at 16-32 CSS px (64 covers 2x screens). The `orig` of a raster
|
|
130
|
+
* favicon is often an AI-generated 1024 px PNG of 1-2 MB, and the browser
|
|
131
|
+
* fetches the `<link rel="icon">` while the page loads: under Lighthouse's
|
|
132
|
+
* throttled network that download pushed LCP from 0.9 s to 4.7 s on an
|
|
133
|
+
* otherwise perfect page (real-AI run 39038927234). Created when the
|
|
134
|
+
* favicon is bound (`themes.set_asset`), not on every upload.
|
|
135
|
+
*/
|
|
136
|
+
export const FAVICON_VARIANT = "icon-64";
|
|
137
|
+
|
|
138
|
+
/** Edge length in px of {@link FAVICON_VARIANT}. */
|
|
139
|
+
export const FAVICON_VARIANT_PX = 64;
|
|
140
|
+
|
|
141
|
+
/** Raster mimes: the ones the image pipeline decodes (sharp) and resizes. */
|
|
142
|
+
const RASTER_IMAGE_MIMES: ReadonlySet<string> = new Set([
|
|
143
|
+
"image/jpeg",
|
|
144
|
+
"image/png",
|
|
145
|
+
"image/webp",
|
|
146
|
+
"image/avif",
|
|
147
|
+
"image/gif",
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
/** Whether `mime` is a raster image the pipeline can decode and resize. */
|
|
151
|
+
export function isRasterImageMime(mime: string): boolean {
|
|
152
|
+
return RASTER_IMAGE_MIMES.has(mime);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The URL + content type the `<link rel="icon">` of a bound favicon uses.
|
|
157
|
+
* A raster favicon ships its {@link FAVICON_VARIANT} PNG; ICO and SVG are
|
|
158
|
+
* favicon formats already and ship as uploaded (`orig`).
|
|
159
|
+
*/
|
|
160
|
+
export function themeFaviconRendition(
|
|
161
|
+
slug: string,
|
|
162
|
+
mime: string,
|
|
163
|
+
): { readonly url: string; readonly mime: string } {
|
|
164
|
+
return isRasterImageMime(mime)
|
|
165
|
+
? { url: buildMediaUrl(slug, FAVICON_VARIANT), mime: "image/png" }
|
|
166
|
+
: { url: buildMediaUrl(slug, "orig"), mime };
|
|
167
|
+
}
|
|
168
|
+
|
|
126
169
|
/**
|
|
127
170
|
* Turn a human/asset label into a URL-safe media slug: lowercase ascii,
|
|
128
171
|
* kebab-case, extension + junk stripped, capped at 60 chars. NOT
|
package/src/preview-compose.ts
CHANGED
|
@@ -108,9 +108,10 @@ export interface ComposeThemeAsset {
|
|
|
108
108
|
readonly mediaId: string;
|
|
109
109
|
readonly url: string;
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
112
|
-
* `orig`
|
|
113
|
-
*
|
|
111
|
+
* Content type of the bytes the URL serves: `media_assets.mime` for the
|
|
112
|
+
* `orig` URL, `image/png` for a raster favicon's rendition (see
|
|
113
|
+
* `themeFaviconRendition`). Carried so `<head>` metadata that declares
|
|
114
|
+
* a type (`<link rel="icon" type=…>`) states the real one.
|
|
114
115
|
*/
|
|
115
116
|
readonly mime: string;
|
|
116
117
|
}
|
|
@@ -239,7 +240,8 @@ export function fontsHeadFragment(fonts: ComposeFonts | undefined): string | nul
|
|
|
239
240
|
* regardless of which layout or chrome modules the page uses, so the
|
|
240
241
|
* composer emits it from the theme binding instead of relying on a
|
|
241
242
|
* module to carry the tag. The href is the media URL as composed
|
|
242
|
-
* (`/_caelo/media/<slug
|
|
243
|
+
* (`/_caelo/media/<slug>/icon-64` for a raster favicon, the `orig` URL
|
|
244
|
+
* for ICO/SVG — see `themeFaviconRendition`); the static generator's media pass rewrites
|
|
243
245
|
* it to the published `/_assets/<slug>.<hash>.<ext>` and copies the bytes, the
|
|
244
246
|
* same as any other media reference. Returns null when no theme is
|
|
245
247
|
* threaded or no favicon is bound (nothing to declare; browsers fall
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #834 / #835 — the wording Publish live's parity refusal shares between
|
|
5
|
+
* the server that writes it (admin-core `build-parity.ts`) and the Live
|
|
6
|
+
* edit toolbar that renders it. The toolbar truncates long errors, so it
|
|
7
|
+
* recognises a parity refusal by its prefix and shows the next step
|
|
8
|
+
* ("Stage again") as its own, untruncated hint next to the button.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Every parity refusal starts with this. */
|
|
12
|
+
export const PARITY_REFUSAL_PREFIX = "Publish live stopped:";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The next step every parity refusal ends with. Operators use the
|
|
16
|
+
* toolbar's "Stage again" button next to Publish live; the AI re-stages
|
|
17
|
+
* with its tools.
|
|
18
|
+
*/
|
|
19
|
+
export const RESTAGE_NEXT_STEP =
|
|
20
|
+
'Next step: Stage again (the "Stage again" button next to Publish live, or stage_changes / deploy_staging in chat), check staging, then Publish live.';
|
|
21
|
+
|
|
22
|
+
/** True when `message` is a Publish-live parity refusal. */
|
|
23
|
+
export function isParityRefusal(message: string): boolean {
|
|
24
|
+
return message.startsWith(PARITY_REFUSAL_PREFIX);
|
|
25
|
+
}
|