@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90

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.
Files changed (159) hide show
  1. package/README.md +3 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
@@ -0,0 +1,351 @@
1
+ import { gfmToMarkdown } from "mdast-util-gfm";
2
+ import { toMarkdown } from "mdast-util-to-markdown";
3
+ import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACE_INFO, } from "./setup-guide.js";
4
+ import { checkMarkerIndex, fenceTitle, lineSelected, nodeText, normalizeGuideSource, parseGuideMarkdown, preparedGuideText, revertSentinels, SETUP_GUIDE_VARIABLE_RE, scanGuide, } from "./setup-guide-parse.js";
5
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is replaced
6
+ const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g;
7
+ /** What `JSON.stringify` leaves raw but a YAML parser may refuse or read as a line break. */
8
+ const JSON_RAW_RE = /[\u007f-\u009f\u2028\u2029]/g;
9
+ /** U+2060 WORD JOINER: invisible, and breaks a GFM autolink literal where it stands. */
10
+ const WORD_JOINER = "\u2060";
11
+ const AUTOLINKABLE_RE = /https?:\/\/|www\.|\S@\S+\.\S/i;
12
+ const QUOTING_LANGUAGES = new Set(["yaml", "yml", "json"]);
13
+ const clean = (s) => s.replace(CONTROL_RE, " ");
14
+ /** A value as the inside of a JSON / YAML double-quoted string. */
15
+ const quoted = (s) => JSON.stringify(s)
16
+ .slice(1, -1)
17
+ .replace(JSON_RAW_RE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
18
+ /**
19
+ * Text no GFM parser links (spec §7.1): a word joiner after the colon of `scheme://`, inside `www.`
20
+ * and before `@`, the three places where a GFM autolink literal (URL, `www.` domain, email) starts.
21
+ * Applied to every text node outside a link before serializing, so a name such as
22
+ * `https://evil.example` stays text when the web parses the Markdown again, whoever consumes it.
23
+ */
24
+ const breakAutolinks = (s) => s
25
+ .replace(/:(?=\/)/g, `:${WORD_JOINER}`)
26
+ .replace(/(www)\./gi, `$1${WORD_JOINER}.`)
27
+ .replace(/@/g, `${WORD_JOINER}@`);
28
+ /** Merges adjacent text nodes and breaks autolinks in every text node outside a link. */
29
+ function unlinkText(node) {
30
+ if (node.type === "link" || !("children" in node))
31
+ return;
32
+ const children = node.children;
33
+ for (let i = children.length - 1; i > 0; i--) {
34
+ const a = children[i - 1];
35
+ const b = children[i];
36
+ if (a?.type === "text" && b?.type === "text") {
37
+ a.value += b.value;
38
+ children.splice(i, 1);
39
+ }
40
+ }
41
+ for (const c of children) {
42
+ if (c.type === "text")
43
+ c.value = breakAutolinks(c.value);
44
+ else
45
+ unlinkText(c);
46
+ }
47
+ }
48
+ function httpUrl(url, allowHttp) {
49
+ if (!(allowHttp ? /^https?:\/\//i : /^https:\/\//i).test(url))
50
+ return false;
51
+ try {
52
+ new URL(url);
53
+ return true;
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
59
+ /**
60
+ * Renders a guide document for a place, mode and audience (spec §6, §7): sections selected, known
61
+ * variables with a value substituted and escaped for where they stand, unknown and unresolved ones
62
+ * left as written, the tree sanitized (raw HTML as text, images as links or alt text, links only to
63
+ * absolute https URLs or http(s) URLs built from a `url` variable, text kept from being auto-linked)
64
+ * and cut into blocks. Pure and deterministic.
65
+ */
66
+ export function renderSetupGuide(source, input) {
67
+ const info = SETUP_GUIDE_PLACE_INFO[input.place];
68
+ const scan = scanGuide(normalizeGuideSource(source));
69
+ const include = (i) => lineSelected(scan, i, input.mode, input.audience);
70
+ const entries = [];
71
+ const missing = new Set();
72
+ const text = preparedGuideText(scan, include, (t) => t.replace(SETUP_GUIDE_VARIABLE_RE, (whole, name) => {
73
+ const type = Object.hasOwn(info.variables, name) ? info.variables[name] : undefined;
74
+ if (type === undefined)
75
+ return whole;
76
+ const value = Object.hasOwn(input.values, name) ? input.values[name] : undefined;
77
+ if (value === null || value === undefined) {
78
+ missing.add(name);
79
+ return whole;
80
+ }
81
+ entries.push({ name, value, type });
82
+ return `${entries.length - 1}`;
83
+ }));
84
+ const names = entries.map((e) => e.name);
85
+ const revert = (s) => revertSentinels(s, names);
86
+ const tree = parseGuideMarkdown(text);
87
+ const definitions = new Map();
88
+ for (const n of tree.children) {
89
+ if (n.type === "definition")
90
+ definitions.set(n.identifier, n.url);
91
+ }
92
+ const substText = (value, inLink) => {
93
+ const out = [];
94
+ const push = (s) => {
95
+ if (s === "")
96
+ return;
97
+ const last = out.at(-1);
98
+ if (last?.type === "text")
99
+ last.value += s;
100
+ else
101
+ out.push({ type: "text", value: s });
102
+ };
103
+ let at = 0;
104
+ for (const m of value.matchAll(/<(\d+)>|(\d+)/g)) {
105
+ push(value.slice(at, m.index));
106
+ at = m.index + m[0].length;
107
+ const e = entries[Number(m[1] ?? m[2])];
108
+ if (e === undefined)
109
+ continue;
110
+ if (m[1] !== undefined) {
111
+ if (!inLink && e.type === "url" && httpUrl(e.value, true)) {
112
+ out.push({
113
+ type: "link",
114
+ url: e.value,
115
+ children: [{ type: "text", value: clean(e.value) }],
116
+ });
117
+ }
118
+ else
119
+ push(`<${clean(e.value)}>`);
120
+ }
121
+ else if (!inLink && e.type === "url" && httpUrl(e.value, true)) {
122
+ // a url variable in prose is an explicit link: the text around it never re-parses into one
123
+ out.push({
124
+ type: "link",
125
+ url: e.value,
126
+ children: [{ type: "text", value: clean(e.value) }],
127
+ });
128
+ }
129
+ else
130
+ push(clean(e.value));
131
+ }
132
+ push(value.slice(at));
133
+ return out;
134
+ };
135
+ const substCode = (value, lang) => value.replace(/(\d+)/g, (whole, n) => {
136
+ const e = entries[Number(n)];
137
+ if (e === undefined)
138
+ return whole;
139
+ return QUOTING_LANGUAGES.has(lang) ? quoted(e.value) : clean(e.value);
140
+ });
141
+ const substInline = (value) => value.replace(/\uE000(\d+)\uE001/g, (whole, n) => {
142
+ const e = entries[Number(n)];
143
+ return e === undefined ? whole : clean(e.value);
144
+ });
145
+ const finishLink = (url, children) => {
146
+ let href = null;
147
+ const m = /^(?:|%EE%80%80)(\d+)(?:|%EE%80%81)/i.exec(url);
148
+ const rest = m === null ? url : url.slice(m[0].length);
149
+ const restHasSentinel = revert(rest) !== rest;
150
+ if (m !== null) {
151
+ const e = entries[Number(m[1])];
152
+ if (e !== undefined &&
153
+ e.type === "url" &&
154
+ !restHasSentinel &&
155
+ httpUrl(e.value + rest, true)) {
156
+ href = e.value + rest;
157
+ }
158
+ }
159
+ else if (!restHasSentinel && httpUrl(url, false)) {
160
+ href = url;
161
+ }
162
+ if (href === null) {
163
+ // a refused link renders as its text; text the web's GFM parser would link again
164
+ // (an autolink's URL, `www.`, an email address) renders as inline code instead
165
+ const t = children.map((c) => nodeText(c)).join("");
166
+ return AUTOLINKABLE_RE.test(t) ? [{ type: "inlineCode", value: clean(t) }] : children;
167
+ }
168
+ const link = { type: "link", url: href, children };
169
+ return [link];
170
+ };
171
+ const phrasing = (nodes, depth, inLink) => nodes.flatMap((c) => tx(c, depth, false, inLink));
172
+ /** Transforms one node into its sanitized replacement(s). */
173
+ const tx = (node, depth, flow, inLink) => {
174
+ const asText = (value) => {
175
+ const t = substText(value, true);
176
+ if (t.length === 0)
177
+ return [];
178
+ return flow ? [{ type: "paragraph", children: t }] : t;
179
+ };
180
+ if (depth > SETUP_GUIDE_LIMITS.depth)
181
+ return asText(nodeText(node));
182
+ switch (node.type) {
183
+ case "text":
184
+ return substText(node.value, inLink);
185
+ case "html":
186
+ return asText(node.value);
187
+ case "inlineCode":
188
+ return [{ type: "inlineCode", value: substInline(node.value) }];
189
+ case "code": {
190
+ const lang = revert(node.lang ?? "");
191
+ return [
192
+ {
193
+ type: "code",
194
+ lang: lang === "" ? null : lang,
195
+ meta: node.meta === null || node.meta === undefined ? null : revert(node.meta),
196
+ value: substCode(node.value, lang.toLowerCase()),
197
+ },
198
+ ];
199
+ }
200
+ case "link": {
201
+ const children = phrasing(node.children, depth + 1, true);
202
+ return inLink ? children : finishLink(node.url, children);
203
+ }
204
+ case "linkReference": {
205
+ const children = phrasing(node.children, depth + 1, true);
206
+ if (inLink)
207
+ return children;
208
+ return finishLink(definitions.get(node.identifier) ?? "", children);
209
+ }
210
+ case "image":
211
+ case "imageReference": {
212
+ const alt = revert(node.alt ?? "");
213
+ const url = node.type === "image" ? node.url : (definitions.get(node.identifier) ?? "");
214
+ const altText = alt === "" ? [] : [{ type: "text", value: clean(alt) }];
215
+ const out = !inLink && revert(url) === url && httpUrl(url, false)
216
+ ? [
217
+ {
218
+ type: "link",
219
+ url,
220
+ children: altText.length > 0 ? altText : [{ type: "text", value: url }],
221
+ },
222
+ ]
223
+ : altText;
224
+ return flow && out.length > 0 ? [{ type: "paragraph", children: out }] : out;
225
+ }
226
+ case "definition":
227
+ case "footnoteDefinition":
228
+ case "footnoteReference":
229
+ return [];
230
+ case "heading":
231
+ return [
232
+ {
233
+ type: "heading",
234
+ depth: Math.min(Math.max(node.depth, 2), 4),
235
+ children: phrasing(node.children, depth + 1, inLink),
236
+ },
237
+ ];
238
+ case "paragraph":
239
+ return [{ type: "paragraph", children: phrasing(node.children, depth + 1, inLink) }];
240
+ case "emphasis":
241
+ case "strong":
242
+ case "delete":
243
+ return [{ type: node.type, children: phrasing(node.children, depth + 1, inLink) }];
244
+ case "tableCell":
245
+ return [{ type: "tableCell", children: phrasing(node.children, depth + 1, inLink) }];
246
+ case "blockquote":
247
+ return [{ type: "blockquote", children: flowChildren(node.children, depth + 1) }];
248
+ case "listItem":
249
+ return [
250
+ {
251
+ type: "listItem",
252
+ spread: node.spread ?? false,
253
+ checked: node.checked ?? null,
254
+ children: flowChildren(node.children, depth + 1),
255
+ },
256
+ ];
257
+ case "list":
258
+ return [
259
+ {
260
+ type: "list",
261
+ ordered: node.ordered ?? false,
262
+ start: node.start ?? null,
263
+ spread: node.spread ?? false,
264
+ children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
265
+ },
266
+ ];
267
+ case "table":
268
+ return [
269
+ {
270
+ type: "table",
271
+ align: node.align ?? null,
272
+ children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
273
+ },
274
+ ];
275
+ case "tableRow":
276
+ return [
277
+ {
278
+ type: "tableRow",
279
+ children: node.children.flatMap((c) => tx(c, depth + 1, false, inLink)),
280
+ },
281
+ ];
282
+ case "thematicBreak":
283
+ return [{ type: "thematicBreak" }];
284
+ case "break":
285
+ return [{ type: "break" }];
286
+ default:
287
+ return asText(nodeText(node));
288
+ }
289
+ };
290
+ const flowChildren = (nodes, depth) => nodes.flatMap((c) => tx(c, depth, true, false));
291
+ // the title: the leading level-1 heading, lifted out
292
+ let title = "";
293
+ let body = tree.children;
294
+ const first = body[0];
295
+ if (first?.type === "heading" && first.depth === 1) {
296
+ title = phrasing(first.children, 2, false)
297
+ .map((n) => nodeText(n))
298
+ .join("")
299
+ .trim();
300
+ body = body.slice(1);
301
+ }
302
+ const blocks = [];
303
+ let group = [];
304
+ const flush = () => {
305
+ if (group.length === 0)
306
+ return;
307
+ const root = { type: "root", children: group };
308
+ unlinkText(root);
309
+ const md = toMarkdown(root, { extensions: [gfmToMarkdown()], bullet: "-" }).replace(/\n+$/, "");
310
+ if (md.trim() !== "")
311
+ blocks.push({ kind: "markdown", text: md });
312
+ group = [];
313
+ };
314
+ for (const node of body) {
315
+ const c = checkMarkerIndex(node);
316
+ if (c !== undefined) {
317
+ const check = scan.checks[c];
318
+ if (check !== undefined) {
319
+ flush();
320
+ blocks.push({ kind: "check", id: check.id, label: check.label });
321
+ }
322
+ continue;
323
+ }
324
+ if (node.type === "code") {
325
+ flush();
326
+ const lang = revert(node.lang ?? "");
327
+ blocks.push({
328
+ kind: "code",
329
+ language: lang,
330
+ title: fenceTitle(revert(node.meta ?? "")).title,
331
+ text: substCode(node.value, lang.toLowerCase()),
332
+ });
333
+ continue;
334
+ }
335
+ group.push(...tx(node, 1, true, false));
336
+ }
337
+ flush();
338
+ const usedModes = new Set();
339
+ const usedAudiences = new Set();
340
+ for (const s of scan.sections)
341
+ (s.type === "mode" ? usedModes : usedAudiences).add(s.value);
342
+ const checkSource = (id) => id.startsWith("capybara:") ? "kernel" : "plugin";
343
+ return {
344
+ title,
345
+ modes: info.modes.filter((m) => usedModes.has(m)),
346
+ audiences: info.audiences.filter((a) => usedAudiences.has(a)),
347
+ blocks,
348
+ checks: blocks.flatMap((b) => b.kind === "check" ? [{ id: b.id, label: b.label, source: checkSource(b.id) }] : []),
349
+ unresolved: Object.keys(info.variables).filter((n) => missing.has(n)),
350
+ };
351
+ }
@@ -1,94 +1,108 @@
1
1
  /**
2
- * Plugin setup guides (spec `2026-11-08-plugin-setup-guides-design.md`): setup material a plugin
3
- * ships (steps and template files such as Slack's app manifest) that the kernel renders with a
4
- * fixed set of safe, deterministic variables and the web shows where the person needs it. The
5
- * format lives in `plugin.json` `setupGuides` ({@link PluginSetupGuide}); this module holds the
6
- * places, their modes and variables, the limits and the pure renderer.
7
- *
8
- * Placeholders are `{{name}}` (spaces inside the braces allowed) with `name` matching
9
- * `[A-Za-z][A-Za-z0-9]*`. There is no other syntax: no conditionals, loops, filters or escapes. A
10
- * placeholder the place does not define, or one without a value, stays as written.
2
+ * Where a guide is shown. `channel-connection`: "New channel" and the channel detail page;
3
+ * `connector-template`: the pages of a connector template and the connectors made from it;
4
+ * `extension-deployment`: the super admin's page of the extension, whose checks verify the
5
+ * platform deployment config (a push provider's credentials); `device-connection`: the guide of a
6
+ * device provider's connection (how a member connects a machine through it).
11
7
  */
12
- /** Where a guide is shown. `channel-connection`: 新建渠道 and the channel detail page. */
13
- export declare const SETUP_GUIDE_PLACES: readonly ["channel-connection"];
8
+ export declare const SETUP_GUIDE_PLACES: readonly ["channel-connection", "connector-template", "extension-deployment", "device-connection"];
14
9
  export type SetupGuidePlace = (typeof SETUP_GUIDE_PLACES)[number];
10
+ /** Who the rendered text is for: `admin` sets the integration up, `member` uses it. */
11
+ export type SetupGuideAudience = "admin" | "member";
15
12
  /**
16
- * The modes of each place: a step or file with `mode` applies to that mode only.
17
- * `channel-connection`: the connection's `inboundMode`.
13
+ * The type of a variable: `url` values are built by the kernel from deployment settings and ids,
14
+ * `text` values hold whatever a person typed (names), `token` values are ids and enum values.
18
15
  */
19
- export declare const SETUP_GUIDE_MODES: Readonly<Record<SetupGuidePlace, readonly string[]>>;
16
+ export type SetupGuideVariableType = "url" | "text" | "token";
20
17
  /**
21
- * The variables of each place. None is a secret: the kernel fills them from public URLs, names and
22
- * versions only (`publicUrl`, `webhookUrl`, `signInCallbackUrl`, `connectionName`, `orgName`,
23
- * `pluginName`, `pluginVersion`, `mode`).
18
+ * What a place defines: its modes, audiences and variables, and whether its targets record acks.
24
19
  */
25
- export declare const SETUP_GUIDE_VARIABLES: Readonly<Record<SetupGuidePlace, readonly string[]>>;
26
- /** Languages of a template file: the code block's label and how values are escaped. */
27
- export declare const SETUP_GUIDE_LANGUAGES: readonly ["yaml", "json", "text"];
28
- export type SetupGuideLanguage = (typeof SETUP_GUIDE_LANGUAGES)[number];
20
+ export interface SetupGuidePlaceInfo {
21
+ modes: readonly string[];
22
+ audiences: readonly SetupGuideAudience[];
23
+ variables: Readonly<Record<string, SetupGuideVariableType>>;
24
+ drift: boolean;
25
+ /** Whether guides of the place may use check lines (a place with no target has nothing to check). */
26
+ checks: boolean;
27
+ }
28
+ /** The place registry. None of the variables is a secret. */
29
+ export declare const SETUP_GUIDE_PLACE_INFO: Readonly<Record<SetupGuidePlace, SetupGuidePlaceInfo>>;
29
30
  /** Limits of setup guides. */
30
31
  export declare const SETUP_GUIDE_LIMITS: {
31
32
  /** Guides per plugin. */
32
33
  readonly guides: 8;
33
- /** Steps per guide. */
34
- readonly steps: 20;
35
- /** Files per guide. */
36
- readonly files: 8;
37
- /** Characters of a step (each language). */
38
- readonly stepChars: 2000;
39
- /** Characters of a title (each language). */
34
+ /** Connector templates one `connector-template` guide covers. */
35
+ readonly templatesPerGuide: 64;
36
+ /** Bytes per document (each language). */
37
+ readonly docBytes: 65536;
38
+ /** Fenced code blocks per document. */
39
+ readonly codeBlocks: 24;
40
+ /** Check lines per document. */
41
+ readonly checks: 16;
42
+ /** Sections per document. */
43
+ readonly sections: 16;
44
+ /** Characters of the title and of a heading. */
40
45
  readonly titleChars: 100;
41
- /** Bytes of a template file. */
42
- readonly fileBytes: number;
46
+ /** Characters of a check label. */
47
+ readonly checkLabelChars: 80;
48
+ /** Characters of a code fence title. */
49
+ readonly fenceTitleChars: 100;
50
+ /** Markdown nesting depth. */
51
+ readonly depth: 16;
43
52
  };
44
- /** File names a template file may have (checked on the path). */
45
- export declare const SETUP_GUIDE_FILE_RE: RegExp;
46
- /** Localized text: English, optional Chinese (falls back to English). */
47
- export interface SetupGuideText {
48
- en: string;
49
- zh?: string;
50
- }
51
- /** A step: plain text (a backtick pair is shown as inline code), optionally for one mode. */
52
- export interface SetupGuideStep extends SetupGuideText {
53
- mode?: string;
54
- }
55
- /** A template file of a guide. */
56
- export interface SetupGuideFile {
57
- /** `./…` inside the plugin, `.tmpl` / `.yaml` / `.yml` / `.json` / `.txt`. */
58
- path: string;
59
- title: SetupGuideText;
60
- language: SetupGuideLanguage;
61
- mode?: string;
62
- }
63
53
  /** A setup guide in `plugin.json` `setupGuides`. */
64
54
  export interface PluginSetupGuide {
65
- /** `^[a-z0-9][a-z0-9-]{0,63}$`, unique in the plugin. */
55
+ /** `^[a-z0-9][a-z0-9-]{0,63}$`, unique in the plugin; the documents are `guides/<id>.md`. */
66
56
  id: string;
67
57
  place: SetupGuidePlace;
68
- title: SetupGuideText;
69
- steps?: SetupGuideStep[];
70
- files?: SetupGuideFile[];
58
+ /**
59
+ * Only and required for `connector-template`: the plugin's connector template ids the guide is
60
+ * for (one or more, at most {@link SETUP_GUIDE_LIMITS}`.templatesPerGuide`). A template has at
61
+ * most one guide; `{{templateId}}` / `{{templateName}}` render the template the guide is shown
62
+ * for.
63
+ */
64
+ templates?: string[];
71
65
  }
72
- /** The placeholder names a text uses, each once, in order of first use. */
73
- export declare function setupGuidePlaceholders(text: string): string[];
74
- /** The placeholders of a text that the place does not define (the toolchain refuses them). */
75
- export declare function unknownSetupGuidePlaceholders(text: string, place: SetupGuidePlace): string[];
76
- /** The modes a guide's steps and files use, in the place's order (empty: no mode switch). */
77
- export declare function setupGuideModes(guide: PluginSetupGuide): string[];
66
+ /** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
67
+ export declare function setupGuideDocPath(id: string, locale: "en" | "zh"): string;
78
68
  /**
79
- * Renders a guide text: each `{{name}}` with a value in `values` is replaced by it, escaped for
80
- * `language` (`yaml` / `json`: JSON-string-escaped without quotes, so a placeholder inside double
81
- * quotes stays one string; `text`: control characters become spaces). A placeholder whose value is
82
- * null or undefined stays as written and is listed in `unresolved` when `known` holds it; one not
83
- * in `known` stays as written and is not listed. Never runs code; deterministic.
69
+ * Whether a guide document is usable as a file: present, at most
70
+ * {@link SETUP_GUIDE_LIMITS}`.docBytes`, valid UTF-8 without NUL and without U+E000–U+E0FF. The
71
+ * problem (English, naming the path), or undefined. Shared by the packer and the kernel's reader.
84
72
  */
85
- export declare function renderSetupGuideText(text: string, values: Readonly<Record<string, string | null | undefined>>, language: SetupGuideLanguage, known?: readonly string[]): {
86
- text: string;
87
- unresolved: string[];
88
- };
73
+ export declare function setupGuideDocProblem(path: string, data: Uint8Array | undefined): string | undefined;
74
+ /** A problem {@link validateSetupGuide} found. */
75
+ export interface SetupGuideIssue {
76
+ level: "error" | "warning";
77
+ message: string;
78
+ }
89
79
  /**
90
- * Whether a guide's template file is usable: present, at most {@link SETUP_GUIDE_LIMITS}`.fileBytes`,
91
- * valid UTF-8 text without NUL. The problem (English, naming the path), or undefined when it is.
92
- * Shared by the packer and the kernel's package reader.
80
+ * Validates a guide's documents for a place (spec §4.5): title, sections well formed and known to
81
+ * the place, check lines, fence info strings, no indented code, limits, variables known to the place
82
+ * and allowed where they stand (§6.2), language parity of the zh document (§4.3), and, when
83
+ * `pluginChecks` is given, that every plugin check id is declared there (the extension's
84
+ * `permissions.setupChecks`). Messages name the file (`guides/<id>.md` when `id` is given) and line.
85
+ * `allowUnknownVariables` (the kernel's importer) accepts variables the place does not define: they
86
+ * render as written. Pure.
93
87
  */
94
- export declare function setupGuideFileProblem(path: string, data: Uint8Array | undefined): string | undefined;
88
+ export declare function validateSetupGuide(input: {
89
+ place: SetupGuidePlace;
90
+ en: string;
91
+ zh?: string;
92
+ pluginChecks?: readonly string[];
93
+ /** The guide id, to name the files in messages. */
94
+ id?: string;
95
+ allowUnknownVariables?: boolean;
96
+ }): SetupGuideIssue[];
97
+ /**
98
+ * The drift hash of a guide for one mode and audience (spec §11): sha256 (hex) over the place, guide
99
+ * id, mode and audience, then, in document order after section selection, each fenced code block
100
+ * (language and text, title excluded) and each check id of the English document. Variables are not
101
+ * substituted; line endings are normalized. Prose, headings and check labels do not move it.
102
+ */
103
+ export declare function setupGuideHash(enSource: string, input: {
104
+ place: SetupGuidePlace;
105
+ guideId: string;
106
+ mode: string | null;
107
+ audience: SetupGuideAudience;
108
+ }): string;