@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.51

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 (134) hide show
  1. package/README.md +1 -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 +4 -1
  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 +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +29 -3
  13. package/agent-docs/plugin-format.md +53 -2
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +86 -1
  20. package/dist/bootstrap.js +161 -2
  21. package/dist/cards.d.ts +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +7 -2
  32. package/dist/connector-auth.js +29 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +120 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +11 -4
  39. package/dist/device-denied-paths.d.ts +14 -0
  40. package/dist/device-denied-paths.js +41 -0
  41. package/dist/device-operation.d.ts +302 -0
  42. package/dist/device-operation.js +292 -0
  43. package/dist/device-protocol.d.ts +490 -0
  44. package/dist/device-protocol.js +1117 -0
  45. package/dist/device-provider.d.ts +472 -0
  46. package/dist/device-provider.js +283 -0
  47. package/dist/extension-point.d.ts +2 -0
  48. package/dist/extension-point.js +6 -2
  49. package/dist/file-preview.d.ts +23 -6
  50. package/dist/git-hosts.d.ts +53 -0
  51. package/dist/git-hosts.js +98 -0
  52. package/dist/hooks.d.ts +125 -20
  53. package/dist/hooks.js +5 -0
  54. package/dist/http-access.d.ts +62 -0
  55. package/dist/http-access.js +12 -0
  56. package/dist/identity.d.ts +38 -9
  57. package/dist/identity.js +21 -1
  58. package/dist/index.d.ts +29 -2
  59. package/dist/index.js +29 -2
  60. package/dist/marketplace.d.ts +26 -0
  61. package/dist/marketplace.js +43 -1
  62. package/dist/model-params.d.ts +41 -22
  63. package/dist/model-params.js +28 -15
  64. package/dist/model.d.ts +206 -71
  65. package/dist/model.js +152 -19
  66. package/dist/net.d.ts +52 -0
  67. package/dist/net.js +34 -0
  68. package/dist/network-classes.d.ts +98 -0
  69. package/dist/network-classes.js +291 -0
  70. package/dist/permissions.d.ts +41 -21
  71. package/dist/permissions.js +101 -42
  72. package/dist/plugin-manifest.d.ts +45 -5
  73. package/dist/plugin-manifest.js +169 -6
  74. package/dist/plugin-package.d.ts +82 -38
  75. package/dist/plugin-package.js +61 -29
  76. package/dist/push.d.ts +75 -0
  77. package/dist/push.js +87 -0
  78. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  79. package/dist/sandbox-linux-runtime-source.js +2318 -0
  80. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  81. package/dist/sandbox-native-runtime-source.js +476 -0
  82. package/dist/sandbox-runtime-source.d.ts +19 -0
  83. package/dist/sandbox-runtime-source.js +28 -0
  84. package/dist/sandbox-write-denies.d.ts +139 -0
  85. package/dist/sandbox-write-denies.js +869 -0
  86. package/dist/secret.d.ts +4 -1
  87. package/dist/secret.js +4 -1
  88. package/dist/setup-check.d.ts +128 -0
  89. package/dist/setup-check.js +142 -0
  90. package/dist/setup-guide-parse.d.ts +135 -0
  91. package/dist/setup-guide-parse.js +413 -0
  92. package/dist/setup-guide-render.d.ts +50 -0
  93. package/dist/setup-guide-render.js +367 -0
  94. package/dist/setup-guide.d.ts +109 -0
  95. package/dist/setup-guide.js +377 -0
  96. package/dist/shell-capabilities.d.ts +231 -0
  97. package/dist/shell-capabilities.js +37 -0
  98. package/dist/shell-environment.d.ts +57 -0
  99. package/dist/shell-environment.js +22 -0
  100. package/dist/skill-invocation.d.ts +4 -3
  101. package/dist/skill-invocation.js +5 -4
  102. package/dist/skill.d.ts +34 -21
  103. package/dist/skill.js +49 -32
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/theme-assets.d.ts +55 -0
  106. package/dist/theme-assets.js +507 -0
  107. package/dist/theme-readability.d.ts +37 -0
  108. package/dist/theme-readability.js +145 -0
  109. package/dist/theme-tokens.generated.d.ts +299 -0
  110. package/dist/theme-tokens.generated.js +184 -0
  111. package/dist/theme.d.ts +190 -0
  112. package/dist/theme.js +471 -0
  113. package/dist/tool.d.ts +69 -26
  114. package/dist/tool.js +29 -9
  115. package/dist/ui-parts.d.ts +23 -0
  116. package/dist/ui-parts.js +348 -0
  117. package/dist/ui-resolve.d.ts +35 -0
  118. package/dist/ui-resolve.js +42 -0
  119. package/dist/ui-slots.d.ts +65 -0
  120. package/dist/ui-slots.js +261 -0
  121. package/dist/ui.d.ts +212 -76
  122. package/dist/ui.js +101 -27
  123. package/dist/url.d.ts +4 -1
  124. package/dist/url.js +4 -1
  125. package/package.json +8 -1
  126. package/schemas/bootstrap-extra.v1.schema.json +172 -0
  127. package/schemas/bootstrap.v1.schema.json +6 -0
  128. package/schemas/connector-template.v1.schema.json +35 -0
  129. package/schemas/marketplace.v1.schema.json +14 -0
  130. package/schemas/plugin.v1.schema.json +117 -3
  131. package/schemas/theme.v1.schema.json +302 -0
  132. package/agent-docs/extension-points/sandbox.md +0 -15
  133. package/dist/sandbox.d.ts +0 -232
  134. package/dist/sandbox.js +0 -120
@@ -0,0 +1,377 @@
1
+ /**
2
+ * Plugin setup guides v2 (spec `2026-11-09-setup-guides-v2-design.md`): Markdown documents a plugin
3
+ * ships (`guides/<id>.md`, optional `guides/<id>.zh.md`) that the kernel renders for a place with a
4
+ * fixed set of safe, deterministic variables, mode and audience sections and live check rows. The
5
+ * declaration lives in `plugin.json` `setupGuides` ({@link PluginSetupGuide}); this module holds the
6
+ * place registry, the limits, the validator and the drift hash. The parser is
7
+ * `setup-guide-parse.ts`, the renderer `setup-guide-render.ts`.
8
+ *
9
+ * Variables are `{{name}}` (spaces inside the braces allowed) with `name` matching
10
+ * `[A-Za-z][A-Za-z0-9]*`. There is no other template syntax.
11
+ */
12
+ import { createHash } from "node:crypto";
13
+ import { analyzeSetupGuide, checkMarkerIndex, ENCODED_SENTINEL_RE, lineSelected, normalizeGuideSource, parseGuideMarkdown, preparedGuideText, SENTINEL_RE, scanGuide, visitGuide, } from "./setup-guide-parse.js";
14
+ /**
15
+ * Where a guide is shown. `channel-connection`: "New channel" and the channel detail page;
16
+ * `connector-template`: the pages of a connector template and the connectors made from it;
17
+ * `extension-deployment`: the super admin's page of the extension, whose checks verify the
18
+ * platform deployment config (a push provider's credentials); `device-connection`: the guide of a
19
+ * device provider's connection (how a member connects a machine through it).
20
+ */
21
+ export const SETUP_GUIDE_PLACES = [
22
+ "channel-connection",
23
+ "connector-template",
24
+ "extension-deployment",
25
+ "device-connection",
26
+ ];
27
+ const COMMON_VARIABLES = {
28
+ publicUrl: "url",
29
+ orgName: "text",
30
+ pluginName: "token",
31
+ pluginVersion: "token",
32
+ mode: "token",
33
+ };
34
+ /** The place registry. None of the variables is a secret. */
35
+ export const SETUP_GUIDE_PLACE_INFO = {
36
+ "channel-connection": {
37
+ modes: ["long_connection", "webhook"],
38
+ audiences: ["admin"],
39
+ variables: {
40
+ ...COMMON_VARIABLES,
41
+ webhookUrl: "url",
42
+ signInCallbackUrl: "url",
43
+ connectionName: "text",
44
+ },
45
+ drift: true,
46
+ shellActions: [],
47
+ },
48
+ "connector-template": {
49
+ modes: [],
50
+ audiences: ["admin", "member"],
51
+ variables: {
52
+ ...COMMON_VARIABLES,
53
+ oauthCallbackUrl: "url",
54
+ signInCallbackUrl: "url",
55
+ templateId: "token",
56
+ templateName: "text",
57
+ connectorName: "text",
58
+ },
59
+ drift: true,
60
+ shellActions: [],
61
+ },
62
+ "extension-deployment": {
63
+ modes: [],
64
+ audiences: ["admin"],
65
+ variables: { ...COMMON_VARIABLES, pluginName: "text" },
66
+ drift: false,
67
+ shellActions: [],
68
+ },
69
+ "device-connection": {
70
+ modes: [],
71
+ audiences: ["member"],
72
+ variables: { publicUrl: "url", orgId: "token", orgName: "text", pluginName: "token" },
73
+ drift: false,
74
+ shellActions: ["connect-this-machine"],
75
+ },
76
+ };
77
+ /** Limits of setup guides. */
78
+ export const SETUP_GUIDE_LIMITS = {
79
+ /** Guides per plugin. */
80
+ guides: 8,
81
+ /** Bytes per document (each language). */
82
+ docBytes: 65536,
83
+ /** Fenced code blocks per document. */
84
+ codeBlocks: 24,
85
+ /** Check lines per document. */
86
+ checks: 16,
87
+ /** Shell action lines per document. */
88
+ shellActions: 4,
89
+ /** Sections per document. */
90
+ sections: 16,
91
+ /** Characters of the title and of a heading. */
92
+ titleChars: 100,
93
+ /** Characters of a check label. */
94
+ checkLabelChars: 80,
95
+ /** Characters of a code fence title. */
96
+ fenceTitleChars: 100,
97
+ /** Markdown nesting depth. */
98
+ depth: 16,
99
+ };
100
+ /** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
101
+ export function setupGuideDocPath(id, locale) {
102
+ return locale === "zh" ? `guides/${id}.zh.md` : `guides/${id}.md`;
103
+ }
104
+ /**
105
+ * Whether a guide document is usable as a file: present, at most
106
+ * {@link SETUP_GUIDE_LIMITS}`.docBytes`, valid UTF-8 without NUL and without U+E000–U+E0FF. The
107
+ * problem (English, naming the path), or undefined. Shared by the packer and the kernel's reader.
108
+ */
109
+ export function setupGuideDocProblem(path, data) {
110
+ if (data === undefined)
111
+ return `${path} not found in the package`;
112
+ if (data.byteLength > SETUP_GUIDE_LIMITS.docBytes) {
113
+ return `${path} is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes`;
114
+ }
115
+ let text;
116
+ try {
117
+ text = new TextDecoder("utf-8", { fatal: true }).decode(data);
118
+ }
119
+ catch {
120
+ return `${path} is not valid UTF-8 text`;
121
+ }
122
+ if (text.includes("\u0000"))
123
+ return `${path} is not a text file (it contains NUL)`;
124
+ if (/[-]/.test(text)) {
125
+ return `${path} contains a private-use character (U+E000–U+E0FF), which guides may not use`;
126
+ }
127
+ return undefined;
128
+ }
129
+ const QUOTING_LANGUAGES = new Set(["yaml", "yml", "json"]);
130
+ const firstUrlSentinel = /^(?:|%EE%80%80)(\d+)(?:|%EE%80%81)/i;
131
+ const hasSentinel = (s) => s !== null &&
132
+ s !== undefined &&
133
+ (new RegExp(SENTINEL_RE.source).test(s) || new RegExp(ENCODED_SENTINEL_RE.source, "i").test(s));
134
+ const sentinelIndexes = (s) => [
135
+ ...[...s.matchAll(SENTINEL_RE)].map((m) => Number(m[1])),
136
+ ...[...s.matchAll(ENCODED_SENTINEL_RE)].map((m) => Number(m[1])),
137
+ ];
138
+ /**
139
+ * Validates a guide's documents for a place (spec §4.5): title, sections well formed and known to
140
+ * the place, check lines, fence info strings, no indented code, limits, variables known to the place
141
+ * and allowed where they stand (§6.2), language parity of the zh document (§4.3), and, when
142
+ * `pluginChecks` is given, that every plugin check id is declared there (the extension's
143
+ * `permissions.setupChecks`). Messages name the file (`guides/<id>.md` when `id` is given) and line.
144
+ * `allowUnknownVariables` (the kernel's importer) accepts variables the place does not define: they
145
+ * render as written. Pure.
146
+ */
147
+ export function validateSetupGuide(input) {
148
+ const info = SETUP_GUIDE_PLACE_INFO[input.place];
149
+ const fileOf = (locale) => input.id !== undefined
150
+ ? setupGuideDocPath(input.id, locale)
151
+ : locale === "en"
152
+ ? "the English document"
153
+ : "the Chinese document";
154
+ const out = [];
155
+ const parsedBy = {};
156
+ const one = (locale, source) => {
157
+ const file = fileOf(locale);
158
+ const push = (i) => out.push({
159
+ level: i.level,
160
+ message: i.line !== undefined ? `${file}:${i.line}: ${i.message}` : `${file}: ${i.message}`,
161
+ });
162
+ const bytes = new TextEncoder().encode(source).byteLength;
163
+ if (bytes > SETUP_GUIDE_LIMITS.docBytes) {
164
+ push({ level: "error", message: `is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes` });
165
+ return;
166
+ }
167
+ const { parsed, scan, tree, uses } = analyzeSetupGuide(source);
168
+ parsedBy[locale] = parsed;
169
+ const issues = [...parsed.issues];
170
+ const err = (line, message, level = "error") => issues.push({ level, ...(line !== undefined && { line }), message });
171
+ for (const s of parsed.sections) {
172
+ if (s.type === "mode" && !info.modes.includes(s.value)) {
173
+ err(s.line, info.modes.length === 0
174
+ ? `place ${input.place} has no modes`
175
+ : `mode "${s.value}" is not one of the modes of place ${input.place}: ${info.modes.join(", ")}`);
176
+ }
177
+ if (s.type === "audience" && !info.audiences.includes(s.value)) {
178
+ err(s.line, `audience "${s.value}" is not one of the audiences of place ${input.place}: ${info.audiences.join(", ")}`);
179
+ }
180
+ }
181
+ for (const a of parsed.shellActions) {
182
+ if (info.shellActions.length === 0) {
183
+ err(a.line, `shell actions are not allowed in place ${input.place}`);
184
+ }
185
+ else if (!info.shellActions.includes(a.action)) {
186
+ err(a.line, `unknown shell action "${a.action}" (known: ${info.shellActions.join(", ")})`);
187
+ }
188
+ }
189
+ if (input.pluginChecks !== undefined) {
190
+ for (const c of parsed.checks) {
191
+ if (c.source === "plugin" && !input.pluginChecks.includes(c.id)) {
192
+ err(c.line, `check ${c.id} is not declared in the extension's permissions.setupChecks`);
193
+ }
194
+ }
195
+ }
196
+ // a check id twice in one rendering
197
+ const dupes = new Set();
198
+ for (const mode of [null, ...info.modes]) {
199
+ for (const audience of info.audiences) {
200
+ const seen = new Set();
201
+ parsed.checks.forEach((c) => {
202
+ if (!lineSelected(scan, c.line - 1, mode, audience))
203
+ return;
204
+ if (seen.has(c.id) && !dupes.has(c.id)) {
205
+ dupes.add(c.id);
206
+ err(c.line, `check ${c.id} appears twice in one rendering of the guide`);
207
+ }
208
+ seen.add(c.id);
209
+ });
210
+ }
211
+ }
212
+ // variables: known to the place, and allowed where they stand
213
+ const reported = new Set();
214
+ for (const u of uses) {
215
+ if (Object.hasOwn(info.variables, u.name) || input.allowUnknownVariables === true)
216
+ continue;
217
+ if (reported.has(u.name))
218
+ continue;
219
+ reported.add(u.name);
220
+ err(u.line, `unknown variable {{${u.name}}} for place ${input.place} (known: ${Object.keys(info.variables).join(", ")})`);
221
+ }
222
+ const typeOf = (n) => {
223
+ const name = uses[n]?.name;
224
+ return name === undefined ? undefined : info.variables[name];
225
+ };
226
+ const nameOf = (n) => `{{${uses[n]?.name ?? "?"}}}`;
227
+ const checkDestination = (url, line) => {
228
+ const all = sentinelIndexes(url);
229
+ if (all.length === 0)
230
+ return;
231
+ const m = firstUrlSentinel.exec(url);
232
+ const ok = m !== null && all.length === 1 && typeOf(Number(m[1])) === "url";
233
+ if (!ok) {
234
+ err(line, `${all.map(nameOf).join(", ")} in a link destination: only a url variable may stand there, at its start`);
235
+ }
236
+ };
237
+ visitGuide(tree, (node) => {
238
+ const line = node.position?.start.line;
239
+ switch (node.type) {
240
+ case "code": {
241
+ const lang = (node.lang ?? "").toLowerCase();
242
+ if (QUOTING_LANGUAGES.has(lang)) {
243
+ // values are JSON-escaped without the quotes: only safe inside a "…" string
244
+ for (const lineText of node.value.split("\n")) {
245
+ for (const m of lineText.matchAll(SENTINEL_RE)) {
246
+ const n = Number(m[1]);
247
+ if (typeOf(n) !== "text")
248
+ continue;
249
+ const before = lineText.slice(0, m.index).replace(/\\./g, "");
250
+ if ((before.match(/"/g)?.length ?? 0) % 2 === 1)
251
+ continue;
252
+ err(line, `the text variable ${nameOf(n)} in a ${lang} code block is not inside double quotes; its value is escaped as a string and may break the block or change its type ("${nameOf(n)}")`, "warning");
253
+ }
254
+ }
255
+ return;
256
+ }
257
+ for (const n of sentinelIndexes(node.value)) {
258
+ if (typeOf(n) === "text") {
259
+ err(line, `the text variable ${nameOf(n)} in a ${lang || "plain"} code block is not quoted; a value with spaces or quotes may break it (use a yaml or json block with "${nameOf(n)}")`, "warning");
260
+ }
261
+ }
262
+ return;
263
+ }
264
+ case "link":
265
+ case "definition":
266
+ checkDestination(node.url, line);
267
+ if (hasSentinel(node.title))
268
+ err(line, "variables are not allowed in a link title");
269
+ return;
270
+ case "image":
271
+ case "imageReference":
272
+ if (hasSentinel(node.alt) ||
273
+ (node.type === "image" && (hasSentinel(node.url) || hasSentinel(node.title)))) {
274
+ err(line, "variables are not allowed in an image");
275
+ }
276
+ return;
277
+ default:
278
+ return;
279
+ }
280
+ });
281
+ issues.sort((a, b) => (a.line ?? 0) - (b.line ?? 0));
282
+ issues.forEach(push);
283
+ };
284
+ one("en", input.en);
285
+ if (input.zh !== undefined)
286
+ one("zh", input.zh);
287
+ const en = parsedBy.en;
288
+ const zh = parsedBy.zh;
289
+ if (en !== undefined && zh !== undefined) {
290
+ const enFile = fileOf("en");
291
+ const zhFile = fileOf("zh");
292
+ const sec = (p) => JSON.stringify(p.sections.map((s) => [s.type, s.value, s.parent]));
293
+ if (sec(en) !== sec(zh)) {
294
+ out.push({
295
+ level: "error",
296
+ message: `${zhFile}: the sections differ from ${enFile}; both languages need the same sections in the same order`,
297
+ });
298
+ }
299
+ const chk = (p) => JSON.stringify(p.checks.map((c) => [c.section, c.id]));
300
+ if (chk(en) !== chk(zh)) {
301
+ out.push({
302
+ level: "error",
303
+ message: `${zhFile}: the checks differ from ${enFile}; both languages need the same check ids in the same sections`,
304
+ });
305
+ }
306
+ const act = (p) => JSON.stringify(p.shellActions.map((a) => [a.section, a.action]));
307
+ if (act(en) !== act(zh)) {
308
+ out.push({
309
+ level: "error",
310
+ message: `${zhFile}: the shell actions differ from ${enFile}; both languages need the same actions in the same sections`,
311
+ });
312
+ }
313
+ if (en.codeBlocks.length !== zh.codeBlocks.length) {
314
+ out.push({
315
+ level: "error",
316
+ message: `${zhFile}: has ${zh.codeBlocks.length} code blocks and ${enFile} has ${en.codeBlocks.length}; code blocks must be identical in every language`,
317
+ });
318
+ }
319
+ else {
320
+ en.codeBlocks.forEach((e, i) => {
321
+ const z = zh.codeBlocks[i];
322
+ if (z === undefined)
323
+ return;
324
+ const n = i + 1;
325
+ const name = `code block ${n}${z.title !== null ? ` ("${z.title}")` : ""}`;
326
+ if (z.section !== e.section) {
327
+ out.push({
328
+ level: "error",
329
+ message: `${zhFile}: ${name} is in another section than ${enFile} block ${n}; code blocks must be identical in every language`,
330
+ });
331
+ return;
332
+ }
333
+ if (z.language === e.language && z.text === e.text)
334
+ return;
335
+ if (z.language !== e.language) {
336
+ out.push({
337
+ level: "error",
338
+ message: `${zhFile}: ${name} is ${z.language || "without a language"} but ${enFile} block ${n} is ${e.language || "without a language"}; code blocks must be identical in every language`,
339
+ });
340
+ return;
341
+ }
342
+ const el = e.text.split("\n");
343
+ const zl = z.text.split("\n");
344
+ let line = 0;
345
+ while (line < el.length && line < zl.length && el[line] === zl[line])
346
+ line++;
347
+ out.push({
348
+ level: "error",
349
+ message: `${zhFile}: ${name} differs from ${enFile} block ${n} at line ${line + 1}; code blocks must be identical in every language`,
350
+ });
351
+ });
352
+ }
353
+ }
354
+ return out;
355
+ }
356
+ /**
357
+ * The drift hash of a guide for one mode and audience (spec §11): sha256 (hex) over the place, guide
358
+ * id, mode and audience, then, in document order after section selection, each fenced code block
359
+ * (language and text, title excluded) and each check id of the English document. Variables are not
360
+ * substituted; line endings are normalized. Prose, headings and check labels do not move it.
361
+ */
362
+ export function setupGuideHash(enSource, input) {
363
+ const scan = scanGuide(normalizeGuideSource(enSource));
364
+ const tree = parseGuideMarkdown(preparedGuideText(scan, (i) => lineSelected(scan, i, input.mode, input.audience)));
365
+ const h = createHash("sha256");
366
+ h.update(`capybara-guide-v2\0${input.place}\0${input.guideId}\0${input.mode ?? ""}\0${input.audience}\0`);
367
+ visitGuide(tree, (node) => {
368
+ if (node.type === "code") {
369
+ h.update(`code\0${node.lang ?? ""}\0${node.value}\0`);
370
+ return;
371
+ }
372
+ const c = checkMarkerIndex(node);
373
+ if (c !== undefined)
374
+ h.update(`check\0${scan.checks[c]?.id ?? ""}\0`);
375
+ });
376
+ return h.digest("hex");
377
+ }
@@ -0,0 +1,231 @@
1
+ import type { PushPlatform } from "./push.js";
2
+ /**
3
+ * Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
4
+ * puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
5
+ * key constants only; `capybara-hq/clients` implements them. A rejected call carries
6
+ * `{ code: ShellCallError }`.
7
+ */
8
+ /** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
9
+ export declare const SHELL_CAPABILITY_KEYS: {
10
+ readonly chrome: "chrome@1";
11
+ readonly device: "device@1";
12
+ readonly notify: "notify@1";
13
+ readonly openExternal: "openExternal@1";
14
+ readonly signIn: "signIn@1";
15
+ readonly haptics: "haptics@1";
16
+ readonly share: "share@1";
17
+ readonly menu: "menu@1";
18
+ readonly nav: "nav@1";
19
+ readonly profiles: "profiles@1";
20
+ readonly push: "push@1";
21
+ };
22
+ export type KeepAwakeMode = "off" | "while-busy" | "connected";
23
+ export type DeviceConnection = "starting" | "online" | "offline" | "draining" | "stopped";
24
+ /** What this machine is to the deployment the shell shows. */
25
+ export type ThisMachineStatus = {
26
+ state: "not_connected";
27
+ } | {
28
+ state: "connected_elsewhere";
29
+ origin: string;
30
+ } | {
31
+ state: "connected";
32
+ deviceId: string;
33
+ orgId: string;
34
+ mode: "os" | "docker";
35
+ connection: DeviceConnection;
36
+ offlineReason?: string;
37
+ serviceInstalled: boolean;
38
+ keepAwake: {
39
+ mode: KeepAwakeMode;
40
+ held: boolean;
41
+ unavailable?: string;
42
+ };
43
+ lastWakeAt?: string;
44
+ };
45
+ /** One operation running on this machine for the deployment. */
46
+ export interface RunningOperationView {
47
+ tag: string;
48
+ conversationId: string | null;
49
+ accountId: string | null;
50
+ isolation: "restricted" | "full";
51
+ startedAt: string;
52
+ }
53
+ /** The `code` of a rejected shell call. */
54
+ export type ShellCallError = "busy" | "no_activation" | "cancelled" | "failed";
55
+ /**
56
+ * A change to this machine's owner ceiling, as `capybara-device ceiling set` takes it
57
+ * (`--outside-sandbox on|off`, `--network open|allowlist`, `--project-reach workspace|os-user`):
58
+ * only the fields to change. A field left out is never touched, so a stale value on the page can
59
+ * never narrow it. A widening needs the shell's native confirmation; a narrowing applies at once.
60
+ */
61
+ export interface DeviceCeilingRequest {
62
+ outsideSandbox?: boolean;
63
+ network?: "open" | "allowlist";
64
+ projectReach?: "workspace" | "os-user";
65
+ }
66
+ /** `device@1`: connect this machine to the deployment as a device. */
67
+ export interface DeviceCapabilityV1 {
68
+ status(): Promise<ThisMachineStatus>;
69
+ onStatus(listener: (s: ThisMachineStatus) => void): () => void;
70
+ running(): Promise<RunningOperationView[]>;
71
+ connect(input: {
72
+ orgId: string;
73
+ deviceId?: string;
74
+ }): Promise<"connected" | "cancelled">;
75
+ pause(): Promise<void>;
76
+ resume(): Promise<"resumed" | "cancelled">;
77
+ disconnect(): Promise<void>;
78
+ requestCeiling(input: DeviceCeilingRequest): Promise<"applied" | "cancelled">;
79
+ setKeepAwake(mode: KeepAwakeMode): Promise<"applied" | "cancelled">;
80
+ }
81
+ /** `notify@1`: a native notification; `path` is the in-app path opened on click. */
82
+ export interface NotifyCapabilityV1 {
83
+ notify(input: {
84
+ title: string;
85
+ body: string;
86
+ path?: string;
87
+ }): Promise<void>;
88
+ }
89
+ /** `openExternal@1`: open a URL in the system browser. */
90
+ export interface OpenExternalCapabilityV1 {
91
+ open(url: string): Promise<void>;
92
+ }
93
+ /** `signIn@1`: sign in through the system browser (desktop client spec §6.5). */
94
+ export interface SignInCapabilityV1 {
95
+ start(): Promise<"signedIn" | "cancelled">;
96
+ }
97
+ /**
98
+ * The page's main color tokens (the computed `--cb-bg`, `--cb-panel`, `--cb-ink`, `--cb-muted`,
99
+ * `--cb-line`, `--cb-accent`, `--cb-on-accent`), each a CSS hex or `rgb()` / `rgba()` color. The
100
+ * shell validates them and uses them only as custom properties of its own pages, never as markup.
101
+ */
102
+ export interface ShellChromeTokens {
103
+ bg: string;
104
+ panel: string;
105
+ ink: string;
106
+ muted: string;
107
+ line: string;
108
+ accent: string;
109
+ onAccent: string;
110
+ }
111
+ /**
112
+ * `chrome@1` (mobile layout spec §9.2): the native chrome (window background, title bar, the
113
+ * shell's own pages) follows the page's theme. `tokens` is sent only when all seven are colors;
114
+ * `singleScheme` is true under a UI theme with one scheme (no light / dark toggle on either side).
115
+ */
116
+ export interface ChromeCapabilityV1 {
117
+ setAppearance(input: {
118
+ scheme: "light" | "dark";
119
+ background: string;
120
+ tokens?: ShellChromeTokens;
121
+ singleScheme?: boolean;
122
+ }): Promise<void>;
123
+ /** The web's first paint is done (mobile app spec §5.2); a shell may leave it out. */
124
+ ready?(): Promise<void>;
125
+ }
126
+ export type HapticKind = "selection" | "light" | "success" | "warning";
127
+ /** `haptics@1`: a haptic impact (mobile app spec §5.2). */
128
+ export interface HapticsCapabilityV1 {
129
+ impact(kind: HapticKind): Promise<void>;
130
+ }
131
+ export interface ShareInputV1 {
132
+ title?: string;
133
+ text?: string;
134
+ url?: string;
135
+ }
136
+ /** `share@1`: the system share sheet; resolves whether shared or dismissed. */
137
+ export interface ShareCapabilityV1 {
138
+ share(input: ShareInputV1): Promise<void>;
139
+ }
140
+ export interface MenuItemV1 {
141
+ id: string;
142
+ label: string;
143
+ destructive?: boolean;
144
+ disabled?: boolean;
145
+ }
146
+ export interface MenuInputV1 {
147
+ title?: string;
148
+ items: MenuItemV1[];
149
+ /** A rect in CSS px from the web view's top-left corner. */
150
+ anchor?: {
151
+ x: number;
152
+ y: number;
153
+ width: number;
154
+ height: number;
155
+ };
156
+ }
157
+ /** `menu@1`: a native menu; resolves the chosen item id, or null when dismissed. */
158
+ export interface MenuCapabilityV1 {
159
+ show(input: MenuInputV1): Promise<string | null>;
160
+ }
161
+ /** The shell validates every input against these (and the web keeps within them). */
162
+ export declare const MOBILE_SHELL_LIMITS: {
163
+ readonly menuItems: 12;
164
+ readonly menuLabel: 64;
165
+ readonly menuTitle: 128;
166
+ readonly shareTitle: 256;
167
+ readonly shareText: 4000;
168
+ readonly url: 2048;
169
+ /** `nav@1`: a section or menu label is 1..32 characters. */
170
+ readonly navLabel: 32;
171
+ /** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
172
+ readonly navCount: 9999;
173
+ };
174
+ /** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
175
+ export declare const MENU_ITEM_ID: RegExp;
176
+ export type NavSectionId = "chats" | "inbox" | "agents" | "schedules";
177
+ /** The strip's sections in display order. */
178
+ export declare const NAV_SECTION_ORDER: readonly NavSectionId[];
179
+ export interface NavBadgeV1 {
180
+ count?: number;
181
+ countMore?: boolean;
182
+ }
183
+ export interface NavItemV1 extends NavBadgeV1 {
184
+ id: NavSectionId;
185
+ label: string;
186
+ }
187
+ export interface NavMenuV1 extends NavBadgeV1 {
188
+ label: string;
189
+ }
190
+ export interface NavStateV1 {
191
+ /** The sections the person sees, in NAV_SECTION_ORDER (a guest has no `schedules`). */
192
+ items: NavItemV1[];
193
+ current: NavSectionId | null;
194
+ /** The strip's menu button, or null for none (non-null while the web's class is compact). */
195
+ menu: NavMenuV1 | null;
196
+ }
197
+ /** `nav@1`: offered only while the window has a strip (mobile app spec §6.1): presence is visibility. */
198
+ export interface NavCapabilityV1 {
199
+ set(state: NavStateV1): Promise<void>;
200
+ onSelect(listener: (id: NavSectionId) => void): () => void;
201
+ onMenu(listener: () => void): () => void;
202
+ }
203
+ /** `profiles@1`: the native profile switcher. */
204
+ export interface ProfilesCapabilityV1 {
205
+ /** Opens the native profile switcher; resolves when it closes, with nothing. */
206
+ show(): Promise<void>;
207
+ }
208
+ export type PushPermission = "granted" | "denied" | "prompt";
209
+ export interface PushStatus {
210
+ permission: PushPermission;
211
+ /** The server-side registration id this install holds, or null. */
212
+ registrationId: string | null;
213
+ /** The OS token differs from the one last registered. */
214
+ tokenChanged: boolean;
215
+ }
216
+ /** What the shell hands the web app to register with the deployment. */
217
+ export interface PushRegistration {
218
+ platform: PushPlatform;
219
+ appId: string;
220
+ provider: string;
221
+ token: string;
222
+ }
223
+ /** `push@1`: native push registration (mobile shells). */
224
+ export interface PushCapabilityV1 {
225
+ status(): Promise<PushStatus>;
226
+ /** User activation only when permission is "prompt"; rejects { code: "cancelled" } when denied. */
227
+ register(): Promise<PushRegistration>;
228
+ /** Tells the shell the deployment's registration id for this install. */
229
+ registered(id: string): Promise<void>;
230
+ unregister(): Promise<void>;
231
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
3
+ * puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
4
+ * key constants only; `capybara-hq/clients` implements them. A rejected call carries
5
+ * `{ code: ShellCallError }`.
6
+ */
7
+ /** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
8
+ export const SHELL_CAPABILITY_KEYS = {
9
+ chrome: "chrome@1",
10
+ device: "device@1",
11
+ notify: "notify@1",
12
+ openExternal: "openExternal@1",
13
+ signIn: "signIn@1",
14
+ haptics: "haptics@1",
15
+ share: "share@1",
16
+ menu: "menu@1",
17
+ nav: "nav@1",
18
+ profiles: "profiles@1",
19
+ push: "push@1",
20
+ };
21
+ /** The shell validates every input against these (and the web keeps within them). */
22
+ export const MOBILE_SHELL_LIMITS = {
23
+ menuItems: 12,
24
+ menuLabel: 64,
25
+ menuTitle: 128,
26
+ shareTitle: 256,
27
+ shareText: 4000,
28
+ url: 2048,
29
+ /** `nav@1`: a section or menu label is 1..32 characters. */
30
+ navLabel: 32,
31
+ /** `nav@1`: a badge count is an integer 0..9999 (`countMore` says there are more). */
32
+ navCount: 9999,
33
+ };
34
+ /** The menu item id pattern, checked on `menu@1.show` (the shell validates every input). */
35
+ export const MENU_ITEM_ID = /^[A-Za-z0-9_.-]{1,64}$/;
36
+ /** The strip's sections in display order. */
37
+ export const NAV_SECTION_ORDER = ["chats", "inbox", "agents", "schedules"];