@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +7 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +52 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +15 -2
- package/dist/connector-auth.js +97 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +132 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +12 -5
- package/dist/device-denied-paths.d.ts +18 -0
- package/dist/device-denied-paths.js +84 -0
- package/dist/device-operation.d.ts +333 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +500 -0
- package/dist/device-provider.js +302 -0
- package/dist/dial-in.d.ts +176 -0
- package/dist/dial-in.js +115 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +29 -3
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +54 -22
- package/dist/permissions.js +119 -43
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +174 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +108 -0
- package/dist/setup-guide.js +367 -0
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +99 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +122 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
2
|
+
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
3
|
+
import { gfm } from "micromark-extension-gfm";
|
|
4
|
+
import { SETUP_CHECK_ID_RE } from "./setup-check.js";
|
|
5
|
+
/** Limits the parser enforces (equal to the matching entries of `SETUP_GUIDE_LIMITS`). */
|
|
6
|
+
const LIMITS = {
|
|
7
|
+
codeBlocks: 24,
|
|
8
|
+
checks: 16,
|
|
9
|
+
sections: 16,
|
|
10
|
+
titleChars: 100,
|
|
11
|
+
checkLabelChars: 80,
|
|
12
|
+
fenceTitleChars: 100,
|
|
13
|
+
depth: 16,
|
|
14
|
+
};
|
|
15
|
+
/** `{{name}}`, spaces inside the braces allowed. */
|
|
16
|
+
export const SETUP_GUIDE_VARIABLE_RE = /\{\{\s*([A-Za-z][A-Za-z0-9]*)\s*\}\}/g;
|
|
17
|
+
// The plugin check id is the registration's (`ctx.setup.check`), so a guide can name only ids an
|
|
18
|
+
// extension can register; a kernel check is `capybara:` and the same id shape.
|
|
19
|
+
const PLUGIN_CHECK_RE = SETUP_CHECK_ID_RE;
|
|
20
|
+
const KERNEL_CHECK_RE = new RegExp(`^capybara:${SETUP_CHECK_ID_RE.source.slice(1)}`);
|
|
21
|
+
/** The private-use range the renderer reserves for its sentinels; refused in sources. */
|
|
22
|
+
export const SETUP_GUIDE_RESERVED_RE = /[-]/;
|
|
23
|
+
const FENCE_OPEN_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
24
|
+
const FENCE_CLOSE_RE = /^ {0,3}(`{3,}|~{3,})[ \t]*$/;
|
|
25
|
+
const SECTION_RE = /^(mode|audience)[ \t]+(\S+)$/;
|
|
26
|
+
const CHECK_LINE_RE = /^::check[ \t]+(\S+)(?:[ \t]+(.*?))?[ \t]*$/;
|
|
27
|
+
const FENCE_TITLE_RE = /^title="([^"]*)"$/;
|
|
28
|
+
/** Variable sentinel: `<n>`, n indexing the occurrences. */
|
|
29
|
+
export const SENTINEL_RE = /(\d+)/g;
|
|
30
|
+
/** The same sentinel percent-encoded, as micromark leaves it in a link destination. */
|
|
31
|
+
export const ENCODED_SENTINEL_RE = /%EE%80%80(\d+)%EE%80%81/gi;
|
|
32
|
+
const CHECK_MARKER_RE = /^(\d+)$/;
|
|
33
|
+
/** LF line endings. */
|
|
34
|
+
export function normalizeGuideSource(source) {
|
|
35
|
+
return source.replace(/\r\n?/g, "\n");
|
|
36
|
+
}
|
|
37
|
+
/** @internal Classifies the lines of a (normalized) document. */
|
|
38
|
+
export function scanGuide(source) {
|
|
39
|
+
const lines = source.split("\n");
|
|
40
|
+
const kinds = [];
|
|
41
|
+
const stacks = [];
|
|
42
|
+
const checkAt = new Map();
|
|
43
|
+
const sections = [];
|
|
44
|
+
const checks = [];
|
|
45
|
+
const issues = [];
|
|
46
|
+
const err = (line, message) => issues.push({ level: "error", line, message });
|
|
47
|
+
const stack = [];
|
|
48
|
+
let fence = null;
|
|
49
|
+
lines.forEach((text, i) => {
|
|
50
|
+
const line = i + 1;
|
|
51
|
+
stacks.push([...stack]);
|
|
52
|
+
if (fence !== null) {
|
|
53
|
+
kinds.push("fence");
|
|
54
|
+
const c = FENCE_CLOSE_RE.exec(text);
|
|
55
|
+
if (c !== null &&
|
|
56
|
+
c[1][0] === fence.char &&
|
|
57
|
+
c[1].length >= fence.len) {
|
|
58
|
+
fence = null;
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const f = FENCE_OPEN_RE.exec(text);
|
|
63
|
+
if (f !== null) {
|
|
64
|
+
const seq = f[2];
|
|
65
|
+
if (!(seq[0] === "`" && f[3].includes("`"))) {
|
|
66
|
+
kinds.push("fence");
|
|
67
|
+
fence = { char: seq[0], len: seq.length };
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (text.startsWith(":::")) {
|
|
72
|
+
const rest = text.slice(3).trim();
|
|
73
|
+
if (rest === "") {
|
|
74
|
+
const open = stack.pop();
|
|
75
|
+
if (open === undefined) {
|
|
76
|
+
err(line, "`:::` closes no section");
|
|
77
|
+
kinds.push("text");
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
kinds.push("section-close");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const m = SECTION_RE.exec(rest);
|
|
84
|
+
if (m === null) {
|
|
85
|
+
err(line, `"${text}" is not a section line; use "::: mode <mode>", "::: audience <audience>" or ":::"`);
|
|
86
|
+
kinds.push("text");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (text.includes("{{"))
|
|
90
|
+
err(line, "directive lines hold no variables");
|
|
91
|
+
const type = m[1];
|
|
92
|
+
const parentIndex = stack.at(-1);
|
|
93
|
+
if (parentIndex !== undefined) {
|
|
94
|
+
const parent = sections[parentIndex];
|
|
95
|
+
if (!(stack.length === 1 && parent.type === "audience" && type === "mode")) {
|
|
96
|
+
err(line, `sections do not nest (only a mode section inside an audience section); close the section of line ${parent.line} first`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
sections.push({ type, value: m[2], line, parent: parentIndex ?? null });
|
|
100
|
+
stack.push(sections.length - 1);
|
|
101
|
+
kinds.push("section-open");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (/^::check(?:\s|$)/.test(text)) {
|
|
105
|
+
const m = CHECK_LINE_RE.exec(text);
|
|
106
|
+
if (m === null) {
|
|
107
|
+
err(line, "a check line is `::check <check-id> <label>`");
|
|
108
|
+
kinds.push("text");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const id = m[1];
|
|
112
|
+
const label = (m[2] ?? "").trim();
|
|
113
|
+
if (!PLUGIN_CHECK_RE.test(id) && !KERNEL_CHECK_RE.test(id)) {
|
|
114
|
+
err(line, `check id "${id}" must match ^[a-z0-9][a-z0-9-]{0,47}$ (a plugin check) or capybara:<id> (a kernel check)`);
|
|
115
|
+
}
|
|
116
|
+
if (label === "")
|
|
117
|
+
err(line, `check ${id} needs a label: \`::check ${id} <label>\``);
|
|
118
|
+
else if ([...label].length > LIMITS.checkLabelChars) {
|
|
119
|
+
err(line, `the label of check ${id} is longer than ${LIMITS.checkLabelChars} characters`);
|
|
120
|
+
}
|
|
121
|
+
if (text.includes("{{"))
|
|
122
|
+
err(line, "directive lines hold no variables (check labels are plain text)");
|
|
123
|
+
checks.push({
|
|
124
|
+
id,
|
|
125
|
+
label,
|
|
126
|
+
source: id.startsWith("capybara:") ? "kernel" : "plugin",
|
|
127
|
+
line,
|
|
128
|
+
section: stack.at(-1) ?? null,
|
|
129
|
+
});
|
|
130
|
+
checkAt.set(i, checks.length - 1);
|
|
131
|
+
kinds.push("check");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
kinds.push("text");
|
|
135
|
+
});
|
|
136
|
+
for (const open of stack) {
|
|
137
|
+
const s = sections[open];
|
|
138
|
+
err(s.line, `the section "::: ${s.type} ${s.value}" opened at line ${s.line} is not closed`);
|
|
139
|
+
}
|
|
140
|
+
return { lines, kinds, stacks, checkAt, sections, checks, issues };
|
|
141
|
+
}
|
|
142
|
+
/** @internal Whether line `i` is in the sections of `mode` and `audience`. */
|
|
143
|
+
export function lineSelected(scan, i, mode, audience) {
|
|
144
|
+
for (const s of scan.stacks[i]) {
|
|
145
|
+
const sec = scan.sections[s];
|
|
146
|
+
if (sec.type === "mode" ? sec.value !== mode : sec.value !== audience)
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @internal The Markdown the parser sees, line for line: unselected and directive lines blank, check
|
|
153
|
+
* lines as marker headings, other lines through `subst`.
|
|
154
|
+
*/
|
|
155
|
+
export function preparedGuideText(scan, include, subst = (t) => t) {
|
|
156
|
+
return scan.lines
|
|
157
|
+
.map((text, i) => {
|
|
158
|
+
if (!include(i))
|
|
159
|
+
return "";
|
|
160
|
+
const kind = scan.kinds[i];
|
|
161
|
+
if (kind === "section-open" || kind === "section-close")
|
|
162
|
+
return "";
|
|
163
|
+
if (kind === "check")
|
|
164
|
+
return `###### ${scan.checkAt.get(i)}`;
|
|
165
|
+
return subst(text, i);
|
|
166
|
+
})
|
|
167
|
+
.join("\n");
|
|
168
|
+
}
|
|
169
|
+
/** @internal Parses Markdown (CommonMark + GFM) to mdast. */
|
|
170
|
+
export function parseGuideMarkdown(text) {
|
|
171
|
+
return fromMarkdown(text, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] });
|
|
172
|
+
}
|
|
173
|
+
/** @internal The check index of a marker heading, or undefined. */
|
|
174
|
+
export function checkMarkerIndex(node) {
|
|
175
|
+
if (node.type !== "heading" || node.depth !== 6 || node.children.length !== 1)
|
|
176
|
+
return undefined;
|
|
177
|
+
const t = node.children[0];
|
|
178
|
+
if (t?.type !== "text")
|
|
179
|
+
return undefined;
|
|
180
|
+
const m = CHECK_MARKER_RE.exec(t.value);
|
|
181
|
+
return m === null ? undefined : Number(m[1]);
|
|
182
|
+
}
|
|
183
|
+
/** @internal The plain text of a node (values and image alts, joined). */
|
|
184
|
+
export function nodeText(node) {
|
|
185
|
+
if ("value" in node)
|
|
186
|
+
return node.value;
|
|
187
|
+
if (node.type === "image" || node.type === "imageReference")
|
|
188
|
+
return node.alt ?? "";
|
|
189
|
+
if ("children" in node)
|
|
190
|
+
return node.children.map(nodeText).join("");
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
/** @internal Visits nodes depth first in document order, with their depth (root's children = 1). */
|
|
194
|
+
export function visitGuide(node, fn, depth = 0, parent = null) {
|
|
195
|
+
if (depth > 0)
|
|
196
|
+
fn(node, depth, parent);
|
|
197
|
+
if ("children" in node) {
|
|
198
|
+
for (const c of node.children)
|
|
199
|
+
visitGuide(c, fn, depth + 1, node);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** @internal The title of a fence info string's meta: `{ title }`, or `{ bad }` for other text. */
|
|
203
|
+
export function fenceTitle(meta) {
|
|
204
|
+
if (meta === null || meta === undefined || meta.trim() === "")
|
|
205
|
+
return { title: null };
|
|
206
|
+
const m = FENCE_TITLE_RE.exec(meta.trim());
|
|
207
|
+
return m === null ? { title: null, bad: meta.trim() } : { title: m[1] };
|
|
208
|
+
}
|
|
209
|
+
/** @internal Replaces the sentinels (plain or percent-encoded) of `s` with `{{name}}`. */
|
|
210
|
+
export function revertSentinels(s, names) {
|
|
211
|
+
const back = (whole, n) => {
|
|
212
|
+
const name = names[Number(n)];
|
|
213
|
+
return name === undefined ? whole : `{{${name}}}`;
|
|
214
|
+
};
|
|
215
|
+
return s.replace(SENTINEL_RE, back).replace(ENCODED_SENTINEL_RE, back);
|
|
216
|
+
}
|
|
217
|
+
/** @internal Scans and parses a document with every section and every variable as a sentinel. */
|
|
218
|
+
export function analyzeSetupGuide(source) {
|
|
219
|
+
const src = normalizeGuideSource(source);
|
|
220
|
+
const scan = scanGuide(src);
|
|
221
|
+
const issues = [...scan.issues];
|
|
222
|
+
const err = (line, message) => issues.push({ level: "error", ...(line !== undefined && { line }), message });
|
|
223
|
+
scan.lines.forEach((text, i) => {
|
|
224
|
+
if (text.includes("\u0000"))
|
|
225
|
+
err(i + 1, "the document contains NUL");
|
|
226
|
+
if (SETUP_GUIDE_RESERVED_RE.test(text)) {
|
|
227
|
+
err(i + 1, "the document contains a private-use character (U+E000–U+E0FF), which guides may not use");
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const uses = [];
|
|
231
|
+
const text = preparedGuideText(scan, () => true, (t, i) => t.replace(SETUP_GUIDE_VARIABLE_RE, (_w, name) => {
|
|
232
|
+
uses.push({ name, line: i + 1 });
|
|
233
|
+
return `${uses.length - 1}`;
|
|
234
|
+
}));
|
|
235
|
+
const names = uses.map((u) => u.name);
|
|
236
|
+
const tree = parseGuideMarkdown(text);
|
|
237
|
+
const lineOf = (n) => n.position?.start.line;
|
|
238
|
+
const sectionOf = (line) => line === undefined ? null : (scan.stacks[line - 1]?.at(-1) ?? null);
|
|
239
|
+
// the title
|
|
240
|
+
let title = null;
|
|
241
|
+
const firstLine = scan.lines.findIndex((l) => l.trim() !== "");
|
|
242
|
+
const first = tree.children[0];
|
|
243
|
+
if (first?.type === "heading" &&
|
|
244
|
+
first.depth === 1 &&
|
|
245
|
+
lineOf(first) === firstLine + 1 &&
|
|
246
|
+
/^ {0,3}#(?:[ \t]|$)/.test(scan.lines[firstLine] ?? "")) {
|
|
247
|
+
title = revertSentinels(nodeText(first), names).trim();
|
|
248
|
+
if (title === "")
|
|
249
|
+
err(lineOf(first), "the title (the level-1 heading) is empty");
|
|
250
|
+
if ([...title].length > LIMITS.titleChars) {
|
|
251
|
+
err(lineOf(first), `the title is longer than ${LIMITS.titleChars} characters`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
err(firstLine >= 0 ? firstLine + 1 : 1, "the document must start with a level-1 heading (# Title)");
|
|
256
|
+
}
|
|
257
|
+
const codeBlocks = [];
|
|
258
|
+
let deepest = 0;
|
|
259
|
+
let deepLine;
|
|
260
|
+
visitGuide(tree, (node, depth) => {
|
|
261
|
+
if (depth > deepest) {
|
|
262
|
+
deepest = depth;
|
|
263
|
+
deepLine = lineOf(node);
|
|
264
|
+
}
|
|
265
|
+
const line = lineOf(node);
|
|
266
|
+
if (node.type === "heading") {
|
|
267
|
+
if (checkMarkerIndex(node) !== undefined)
|
|
268
|
+
return;
|
|
269
|
+
if (node === first && title !== null)
|
|
270
|
+
return;
|
|
271
|
+
if (node.depth === 1) {
|
|
272
|
+
err(line, "only the title may be a level-1 heading; use ## to #### for the structure");
|
|
273
|
+
}
|
|
274
|
+
else if (node.depth > 4) {
|
|
275
|
+
err(line, "headings go from ## to ####");
|
|
276
|
+
}
|
|
277
|
+
if ([...revertSentinels(nodeText(node), names).trim()].length > LIMITS.titleChars) {
|
|
278
|
+
err(line, `a heading is longer than ${LIMITS.titleChars} characters`);
|
|
279
|
+
}
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (node.type !== "code")
|
|
283
|
+
return;
|
|
284
|
+
const start = node.position?.start.offset ?? 0;
|
|
285
|
+
const fenced = /^[ \t]*(?:```|~~~)/.test(text.slice(start, start + 64));
|
|
286
|
+
if (!fenced) {
|
|
287
|
+
err(line, "indented code is not allowed; use a fenced code block with a language");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const lang = node.lang ?? "";
|
|
291
|
+
const meta = node.meta ?? "";
|
|
292
|
+
if (/\d+/.test(lang + meta)) {
|
|
293
|
+
err(line, "variables are not allowed in a fence info string");
|
|
294
|
+
}
|
|
295
|
+
if (lang === "")
|
|
296
|
+
err(line, "a code block needs a language (```yaml, ```json, ```sh, ...)");
|
|
297
|
+
const t = fenceTitle(revertSentinels(meta, names));
|
|
298
|
+
if (t.bad !== undefined) {
|
|
299
|
+
err(line, `unexpected text in the info string ("${t.bad}"); only title="…" may follow the language`);
|
|
300
|
+
}
|
|
301
|
+
if (t.title !== null && [...t.title].length > LIMITS.fenceTitleChars) {
|
|
302
|
+
err(line, `a code block title is longer than ${LIMITS.fenceTitleChars} characters`);
|
|
303
|
+
}
|
|
304
|
+
codeBlocks.push({
|
|
305
|
+
language: revertSentinels(lang, names),
|
|
306
|
+
title: t.title,
|
|
307
|
+
text: revertSentinels(node.value, names),
|
|
308
|
+
line: line ?? 0,
|
|
309
|
+
section: sectionOf(line),
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
// a check line swallowed by an HTML block is no block of its own: its row would be missing
|
|
313
|
+
const placed = new Set();
|
|
314
|
+
for (const n of tree.children) {
|
|
315
|
+
const c = checkMarkerIndex(n);
|
|
316
|
+
if (c !== undefined)
|
|
317
|
+
placed.add(c);
|
|
318
|
+
}
|
|
319
|
+
scan.checks.forEach((c, i) => {
|
|
320
|
+
if (!placed.has(i)) {
|
|
321
|
+
err(c.line, `check ${c.id} is inside raw HTML and would not show; end the HTML with a blank line before the check line`);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
if (deepest > LIMITS.depth)
|
|
325
|
+
err(deepLine, `content is nested deeper than ${LIMITS.depth} levels`);
|
|
326
|
+
if (codeBlocks.length > LIMITS.codeBlocks) {
|
|
327
|
+
err(undefined, `the document has ${codeBlocks.length} code blocks; at most ${LIMITS.codeBlocks}`);
|
|
328
|
+
}
|
|
329
|
+
if (scan.checks.length > LIMITS.checks) {
|
|
330
|
+
err(undefined, `the document has ${scan.checks.length} check lines; at most ${LIMITS.checks}`);
|
|
331
|
+
}
|
|
332
|
+
if (scan.sections.length > LIMITS.sections) {
|
|
333
|
+
err(undefined, `the document has ${scan.sections.length} sections; at most ${LIMITS.sections}`);
|
|
334
|
+
}
|
|
335
|
+
issues.sort((a, b) => (a.line ?? 0) - (b.line ?? 0));
|
|
336
|
+
return {
|
|
337
|
+
parsed: {
|
|
338
|
+
title,
|
|
339
|
+
sections: scan.sections,
|
|
340
|
+
checks: scan.checks,
|
|
341
|
+
codeBlocks,
|
|
342
|
+
issues,
|
|
343
|
+
},
|
|
344
|
+
scan,
|
|
345
|
+
tree,
|
|
346
|
+
uses,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Parses a setup guide document into its title, sections, check lines and fenced code blocks, with
|
|
351
|
+
* the structural problems found (missing title, nesting, malformed directive lines, indented code,
|
|
352
|
+
* fence info strings, limits). Place-dependent rules are `validateSetupGuide`'s. Pure.
|
|
353
|
+
*/
|
|
354
|
+
export function parseSetupGuide(source) {
|
|
355
|
+
return analyzeSetupGuide(source).parsed;
|
|
356
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type SetupGuideAudience, type SetupGuidePlace } from "./setup-guide.js";
|
|
2
|
+
/** A block of a rendered guide: sanitized Markdown, a code block or a check row. */
|
|
3
|
+
export type SetupGuideBlock = {
|
|
4
|
+
kind: "markdown";
|
|
5
|
+
text: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "code";
|
|
8
|
+
language: string;
|
|
9
|
+
title: string | null;
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "check";
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
};
|
|
16
|
+
/** A guide document rendered for one mode, audience and set of values. */
|
|
17
|
+
export interface RenderedSetupGuideDoc {
|
|
18
|
+
title: string;
|
|
19
|
+
/** The modes the document's sections use, in the place's order (empty: no mode switch). */
|
|
20
|
+
modes: string[];
|
|
21
|
+
/** The audiences the document has sections for, in the place's order. */
|
|
22
|
+
audiences: SetupGuideAudience[];
|
|
23
|
+
blocks: SetupGuideBlock[];
|
|
24
|
+
/** The check rows, in document order. */
|
|
25
|
+
checks: {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
source: "plugin" | "kernel";
|
|
29
|
+
}[];
|
|
30
|
+
/** Known variables without a value that the rendered text uses, in the place's order. */
|
|
31
|
+
unresolved: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Renders a guide document for a place, mode and audience (spec §6, §7): sections selected, known
|
|
35
|
+
* variables with a value substituted and escaped for where they stand, unknown and unresolved ones
|
|
36
|
+
* left as written, the tree sanitized (raw HTML as text, images as links or alt text, links only to
|
|
37
|
+
* absolute https URLs or http(s) URLs built from a `url` variable, text kept from being auto-linked)
|
|
38
|
+
* and cut into blocks. Pure and deterministic.
|
|
39
|
+
*/
|
|
40
|
+
export declare function renderSetupGuide(source: string, input: {
|
|
41
|
+
place: SetupGuidePlace;
|
|
42
|
+
mode: string | null;
|
|
43
|
+
audience: SetupGuideAudience;
|
|
44
|
+
values: Readonly<Record<string, string | null | undefined>>;
|
|
45
|
+
}): RenderedSetupGuideDoc;
|