@capybara-hq/plugin-sdk 0.1.0-rc.4 → 0.1.0-rc.40
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/agent-docs/agent-templates.md +15 -3
- package/agent-docs/concepts.md +13 -3
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +2 -2
- package/agent-docs/extension-points/config-source.md +1 -1
- package/agent-docs/extension-points/connector.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +1 -1
- package/agent-docs/extension-points/directory.md +1 -1
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +1 -1
- package/agent-docs/extension-points/model-provider.md +4 -2
- package/agent-docs/extension-points/object-store.md +3 -1
- package/agent-docs/extension-points/sandbox.md +3 -3
- package/agent-docs/extension-points/secret-store.md +1 -1
- package/agent-docs/extension-points/web-fetch.md +1 -1
- package/agent-docs/extension-points/web-search.md +1 -1
- package/agent-docs/extensions.md +29 -4
- package/agent-docs/plugin-format.md +43 -3
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +1 -1
- package/agent-docs/tool-naming.md +1 -1
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- 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 +7 -2
- package/dist/connector-auth.js +29 -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 +120 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-protocol.d.ts +481 -0
- package/dist/device-protocol.js +1113 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -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 +22 -9
- package/dist/index.d.ts +26 -1
- package/dist/index.js +26 -1
- 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 +41 -21
- package/dist/permissions.js +101 -42
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- 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 +8 -0
- package/dist/sandbox-native-runtime-source.js +465 -0
- package/dist/sandbox-operation.d.ts +284 -0
- package/dist/sandbox-operation.js +262 -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/sandbox.d.ts +190 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/shell-capabilities.d.ts +80 -0
- package/dist/shell-capabilities.js +13 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +16 -0
- package/dist/skill-invocation.d.ts +4 -3
- package/dist/skill-invocation.js +5 -4
- package/dist/skill.d.ts +34 -21
- package/dist/skill.js +48 -31
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +287 -0
- package/dist/theme-tokens.generated.js +176 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +348 -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 +8 -1
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +115 -3
- package/schemas/theme.v1.schema.json +225 -0
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
*/
|
|
18
|
+
export const SETUP_GUIDE_PLACES = ["channel-connection", "connector-template"];
|
|
19
|
+
const COMMON_VARIABLES = {
|
|
20
|
+
publicUrl: "url",
|
|
21
|
+
orgName: "text",
|
|
22
|
+
pluginName: "token",
|
|
23
|
+
pluginVersion: "token",
|
|
24
|
+
mode: "token",
|
|
25
|
+
};
|
|
26
|
+
/** The place registry. None of the variables is a secret. */
|
|
27
|
+
export const SETUP_GUIDE_PLACE_INFO = {
|
|
28
|
+
"channel-connection": {
|
|
29
|
+
modes: ["long_connection", "webhook"],
|
|
30
|
+
audiences: ["admin"],
|
|
31
|
+
variables: {
|
|
32
|
+
...COMMON_VARIABLES,
|
|
33
|
+
webhookUrl: "url",
|
|
34
|
+
signInCallbackUrl: "url",
|
|
35
|
+
connectionName: "text",
|
|
36
|
+
},
|
|
37
|
+
drift: true,
|
|
38
|
+
},
|
|
39
|
+
"connector-template": {
|
|
40
|
+
modes: [],
|
|
41
|
+
audiences: ["admin", "member"],
|
|
42
|
+
variables: {
|
|
43
|
+
...COMMON_VARIABLES,
|
|
44
|
+
oauthCallbackUrl: "url",
|
|
45
|
+
signInCallbackUrl: "url",
|
|
46
|
+
templateId: "token",
|
|
47
|
+
templateName: "text",
|
|
48
|
+
connectorName: "text",
|
|
49
|
+
},
|
|
50
|
+
drift: true,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
/** Limits of setup guides. */
|
|
54
|
+
export const SETUP_GUIDE_LIMITS = {
|
|
55
|
+
/** Guides per plugin. */
|
|
56
|
+
guides: 8,
|
|
57
|
+
/** Bytes per document (each language). */
|
|
58
|
+
docBytes: 65536,
|
|
59
|
+
/** Fenced code blocks per document. */
|
|
60
|
+
codeBlocks: 24,
|
|
61
|
+
/** Check lines per document. */
|
|
62
|
+
checks: 16,
|
|
63
|
+
/** Sections per document. */
|
|
64
|
+
sections: 16,
|
|
65
|
+
/** Characters of the title and of a heading. */
|
|
66
|
+
titleChars: 100,
|
|
67
|
+
/** Characters of a check label. */
|
|
68
|
+
checkLabelChars: 80,
|
|
69
|
+
/** Characters of a code fence title. */
|
|
70
|
+
fenceTitleChars: 100,
|
|
71
|
+
/** Markdown nesting depth. */
|
|
72
|
+
depth: 16,
|
|
73
|
+
};
|
|
74
|
+
/** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
|
|
75
|
+
export function setupGuideDocPath(id, locale) {
|
|
76
|
+
return locale === "zh" ? `guides/${id}.zh.md` : `guides/${id}.md`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether a guide document is usable as a file: present, at most
|
|
80
|
+
* {@link SETUP_GUIDE_LIMITS}`.docBytes`, valid UTF-8 without NUL and without U+E000–U+E0FF. The
|
|
81
|
+
* problem (English, naming the path), or undefined. Shared by the packer and the kernel's reader.
|
|
82
|
+
*/
|
|
83
|
+
export function setupGuideDocProblem(path, data) {
|
|
84
|
+
if (data === undefined)
|
|
85
|
+
return `${path} not found in the package`;
|
|
86
|
+
if (data.byteLength > SETUP_GUIDE_LIMITS.docBytes) {
|
|
87
|
+
return `${path} is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes`;
|
|
88
|
+
}
|
|
89
|
+
let text;
|
|
90
|
+
try {
|
|
91
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(data);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return `${path} is not valid UTF-8 text`;
|
|
95
|
+
}
|
|
96
|
+
if (text.includes("\u0000"))
|
|
97
|
+
return `${path} is not a text file (it contains NUL)`;
|
|
98
|
+
if (/[-]/.test(text)) {
|
|
99
|
+
return `${path} contains a private-use character (U+E000–U+E0FF), which guides may not use`;
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const QUOTING_LANGUAGES = new Set(["yaml", "yml", "json"]);
|
|
104
|
+
const firstUrlSentinel = /^(?:|%EE%80%80)(\d+)(?:|%EE%80%81)/i;
|
|
105
|
+
const hasSentinel = (s) => s !== null &&
|
|
106
|
+
s !== undefined &&
|
|
107
|
+
(new RegExp(SENTINEL_RE.source).test(s) || new RegExp(ENCODED_SENTINEL_RE.source, "i").test(s));
|
|
108
|
+
const sentinelIndexes = (s) => [
|
|
109
|
+
...[...s.matchAll(SENTINEL_RE)].map((m) => Number(m[1])),
|
|
110
|
+
...[...s.matchAll(ENCODED_SENTINEL_RE)].map((m) => Number(m[1])),
|
|
111
|
+
];
|
|
112
|
+
/**
|
|
113
|
+
* Validates a guide's documents for a place (spec §4.5): title, sections well formed and known to
|
|
114
|
+
* the place, check lines, fence info strings, no indented code, limits, variables known to the place
|
|
115
|
+
* and allowed where they stand (§6.2), language parity of the zh document (§4.3), and, when
|
|
116
|
+
* `pluginChecks` is given, that every plugin check id is declared there (the extension's
|
|
117
|
+
* `permissions.setupChecks`). Messages name the file (`guides/<id>.md` when `id` is given) and line.
|
|
118
|
+
* `allowUnknownVariables` (the kernel's importer) accepts variables the place does not define: they
|
|
119
|
+
* render as written. Pure.
|
|
120
|
+
*/
|
|
121
|
+
export function validateSetupGuide(input) {
|
|
122
|
+
const info = SETUP_GUIDE_PLACE_INFO[input.place];
|
|
123
|
+
const fileOf = (locale) => input.id !== undefined
|
|
124
|
+
? setupGuideDocPath(input.id, locale)
|
|
125
|
+
: locale === "en"
|
|
126
|
+
? "the English document"
|
|
127
|
+
: "the Chinese document";
|
|
128
|
+
const out = [];
|
|
129
|
+
const parsedBy = {};
|
|
130
|
+
const one = (locale, source) => {
|
|
131
|
+
const file = fileOf(locale);
|
|
132
|
+
const push = (i) => out.push({
|
|
133
|
+
level: i.level,
|
|
134
|
+
message: i.line !== undefined ? `${file}:${i.line}: ${i.message}` : `${file}: ${i.message}`,
|
|
135
|
+
});
|
|
136
|
+
const bytes = new TextEncoder().encode(source).byteLength;
|
|
137
|
+
if (bytes > SETUP_GUIDE_LIMITS.docBytes) {
|
|
138
|
+
push({ level: "error", message: `is larger than ${SETUP_GUIDE_LIMITS.docBytes} bytes` });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const { parsed, scan, tree, uses } = analyzeSetupGuide(source);
|
|
142
|
+
parsedBy[locale] = parsed;
|
|
143
|
+
const issues = [...parsed.issues];
|
|
144
|
+
const err = (line, message, level = "error") => issues.push({ level, ...(line !== undefined && { line }), message });
|
|
145
|
+
for (const s of parsed.sections) {
|
|
146
|
+
if (s.type === "mode" && !info.modes.includes(s.value)) {
|
|
147
|
+
err(s.line, info.modes.length === 0
|
|
148
|
+
? `place ${input.place} has no modes`
|
|
149
|
+
: `mode "${s.value}" is not one of the modes of place ${input.place}: ${info.modes.join(", ")}`);
|
|
150
|
+
}
|
|
151
|
+
if (s.type === "audience" && !info.audiences.includes(s.value)) {
|
|
152
|
+
err(s.line, `audience "${s.value}" is not one of the audiences of place ${input.place}: ${info.audiences.join(", ")}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (input.pluginChecks !== undefined) {
|
|
156
|
+
for (const c of parsed.checks) {
|
|
157
|
+
if (c.source === "plugin" && !input.pluginChecks.includes(c.id)) {
|
|
158
|
+
err(c.line, `check ${c.id} is not declared in the extension's permissions.setupChecks`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// a check id twice in one rendering
|
|
163
|
+
const dupes = new Set();
|
|
164
|
+
for (const mode of [null, ...info.modes]) {
|
|
165
|
+
for (const audience of info.audiences) {
|
|
166
|
+
const seen = new Set();
|
|
167
|
+
parsed.checks.forEach((c) => {
|
|
168
|
+
if (!lineSelected(scan, c.line - 1, mode, audience))
|
|
169
|
+
return;
|
|
170
|
+
if (seen.has(c.id) && !dupes.has(c.id)) {
|
|
171
|
+
dupes.add(c.id);
|
|
172
|
+
err(c.line, `check ${c.id} appears twice in one rendering of the guide`);
|
|
173
|
+
}
|
|
174
|
+
seen.add(c.id);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// variables: known to the place, and allowed where they stand
|
|
179
|
+
const reported = new Set();
|
|
180
|
+
for (const u of uses) {
|
|
181
|
+
if (Object.hasOwn(info.variables, u.name) || input.allowUnknownVariables === true)
|
|
182
|
+
continue;
|
|
183
|
+
if (reported.has(u.name))
|
|
184
|
+
continue;
|
|
185
|
+
reported.add(u.name);
|
|
186
|
+
err(u.line, `unknown variable {{${u.name}}} for place ${input.place} (known: ${Object.keys(info.variables).join(", ")})`);
|
|
187
|
+
}
|
|
188
|
+
const typeOf = (n) => {
|
|
189
|
+
const name = uses[n]?.name;
|
|
190
|
+
return name === undefined ? undefined : info.variables[name];
|
|
191
|
+
};
|
|
192
|
+
const nameOf = (n) => `{{${uses[n]?.name ?? "?"}}}`;
|
|
193
|
+
const checkDestination = (url, line) => {
|
|
194
|
+
const all = sentinelIndexes(url);
|
|
195
|
+
if (all.length === 0)
|
|
196
|
+
return;
|
|
197
|
+
const m = firstUrlSentinel.exec(url);
|
|
198
|
+
const ok = m !== null && all.length === 1 && typeOf(Number(m[1])) === "url";
|
|
199
|
+
if (!ok) {
|
|
200
|
+
err(line, `${all.map(nameOf).join(", ")} in a link destination: only a url variable may stand there, at its start`);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
visitGuide(tree, (node) => {
|
|
204
|
+
const line = node.position?.start.line;
|
|
205
|
+
switch (node.type) {
|
|
206
|
+
case "code": {
|
|
207
|
+
const lang = (node.lang ?? "").toLowerCase();
|
|
208
|
+
if (QUOTING_LANGUAGES.has(lang)) {
|
|
209
|
+
// values are JSON-escaped without the quotes: only safe inside a "…" string
|
|
210
|
+
for (const lineText of node.value.split("\n")) {
|
|
211
|
+
for (const m of lineText.matchAll(SENTINEL_RE)) {
|
|
212
|
+
const n = Number(m[1]);
|
|
213
|
+
if (typeOf(n) !== "text")
|
|
214
|
+
continue;
|
|
215
|
+
const before = lineText.slice(0, m.index).replace(/\\./g, "");
|
|
216
|
+
if ((before.match(/"/g)?.length ?? 0) % 2 === 1)
|
|
217
|
+
continue;
|
|
218
|
+
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");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
for (const n of sentinelIndexes(node.value)) {
|
|
224
|
+
if (typeOf(n) === "text") {
|
|
225
|
+
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");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
case "link":
|
|
231
|
+
case "definition":
|
|
232
|
+
checkDestination(node.url, line);
|
|
233
|
+
if (hasSentinel(node.title))
|
|
234
|
+
err(line, "variables are not allowed in a link title");
|
|
235
|
+
return;
|
|
236
|
+
case "image":
|
|
237
|
+
case "imageReference":
|
|
238
|
+
if (hasSentinel(node.alt) ||
|
|
239
|
+
(node.type === "image" && (hasSentinel(node.url) || hasSentinel(node.title)))) {
|
|
240
|
+
err(line, "variables are not allowed in an image");
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
default:
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
issues.sort((a, b) => (a.line ?? 0) - (b.line ?? 0));
|
|
248
|
+
issues.forEach(push);
|
|
249
|
+
};
|
|
250
|
+
one("en", input.en);
|
|
251
|
+
if (input.zh !== undefined)
|
|
252
|
+
one("zh", input.zh);
|
|
253
|
+
const en = parsedBy.en;
|
|
254
|
+
const zh = parsedBy.zh;
|
|
255
|
+
if (en !== undefined && zh !== undefined) {
|
|
256
|
+
const enFile = fileOf("en");
|
|
257
|
+
const zhFile = fileOf("zh");
|
|
258
|
+
const sec = (p) => JSON.stringify(p.sections.map((s) => [s.type, s.value, s.parent]));
|
|
259
|
+
if (sec(en) !== sec(zh)) {
|
|
260
|
+
out.push({
|
|
261
|
+
level: "error",
|
|
262
|
+
message: `${zhFile}: the sections differ from ${enFile}; both languages need the same sections in the same order`,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
const chk = (p) => JSON.stringify(p.checks.map((c) => [c.section, c.id]));
|
|
266
|
+
if (chk(en) !== chk(zh)) {
|
|
267
|
+
out.push({
|
|
268
|
+
level: "error",
|
|
269
|
+
message: `${zhFile}: the checks differ from ${enFile}; both languages need the same check ids in the same sections`,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (en.codeBlocks.length !== zh.codeBlocks.length) {
|
|
273
|
+
out.push({
|
|
274
|
+
level: "error",
|
|
275
|
+
message: `${zhFile}: has ${zh.codeBlocks.length} code blocks and ${enFile} has ${en.codeBlocks.length}; code blocks must be identical in every language`,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
en.codeBlocks.forEach((e, i) => {
|
|
280
|
+
const z = zh.codeBlocks[i];
|
|
281
|
+
if (z === undefined)
|
|
282
|
+
return;
|
|
283
|
+
const n = i + 1;
|
|
284
|
+
const name = `code block ${n}${z.title !== null ? ` ("${z.title}")` : ""}`;
|
|
285
|
+
if (z.section !== e.section) {
|
|
286
|
+
out.push({
|
|
287
|
+
level: "error",
|
|
288
|
+
message: `${zhFile}: ${name} is in another section than ${enFile} block ${n}; code blocks must be identical in every language`,
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (z.language === e.language && z.text === e.text)
|
|
293
|
+
return;
|
|
294
|
+
if (z.language !== e.language) {
|
|
295
|
+
out.push({
|
|
296
|
+
level: "error",
|
|
297
|
+
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`,
|
|
298
|
+
});
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const el = e.text.split("\n");
|
|
302
|
+
const zl = z.text.split("\n");
|
|
303
|
+
let line = 0;
|
|
304
|
+
while (line < el.length && line < zl.length && el[line] === zl[line])
|
|
305
|
+
line++;
|
|
306
|
+
out.push({
|
|
307
|
+
level: "error",
|
|
308
|
+
message: `${zhFile}: ${name} differs from ${enFile} block ${n} at line ${line + 1}; code blocks must be identical in every language`,
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The drift hash of a guide for one mode and audience (spec §11): sha256 (hex) over the place, guide
|
|
317
|
+
* id, mode and audience, then, in document order after section selection, each fenced code block
|
|
318
|
+
* (language and text, title excluded) and each check id of the English document. Variables are not
|
|
319
|
+
* substituted; line endings are normalized. Prose, headings and check labels do not move it.
|
|
320
|
+
*/
|
|
321
|
+
export function setupGuideHash(enSource, input) {
|
|
322
|
+
const scan = scanGuide(normalizeGuideSource(enSource));
|
|
323
|
+
const tree = parseGuideMarkdown(preparedGuideText(scan, (i) => lineSelected(scan, i, input.mode, input.audience)));
|
|
324
|
+
const h = createHash("sha256");
|
|
325
|
+
h.update(`capybara-guide-v2\0${input.place}\0${input.guideId}\0${input.mode ?? ""}\0${input.audience}\0`);
|
|
326
|
+
visitGuide(tree, (node) => {
|
|
327
|
+
if (node.type === "code") {
|
|
328
|
+
h.update(`code\0${node.lang ?? ""}\0${node.value}\0`);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const c = checkMarkerIndex(node);
|
|
332
|
+
if (c !== undefined)
|
|
333
|
+
h.update(`check\0${scan.checks[c]?.id ?? ""}\0`);
|
|
334
|
+
});
|
|
335
|
+
return h.digest("hex");
|
|
336
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
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 declare const SHELL_CAPABILITY_KEYS: {
|
|
9
|
+
readonly device: "device@1";
|
|
10
|
+
readonly notify: "notify@1";
|
|
11
|
+
readonly openExternal: "openExternal@1";
|
|
12
|
+
readonly signIn: "signIn@1";
|
|
13
|
+
};
|
|
14
|
+
export type KeepAwakeMode = "off" | "while-busy" | "connected";
|
|
15
|
+
export type DeviceConnection = "starting" | "online" | "offline" | "draining" | "stopped";
|
|
16
|
+
/** What this machine is to the deployment the shell shows. */
|
|
17
|
+
export type ThisMachineStatus = {
|
|
18
|
+
state: "not_connected";
|
|
19
|
+
} | {
|
|
20
|
+
state: "connected_elsewhere";
|
|
21
|
+
origin: string;
|
|
22
|
+
} | {
|
|
23
|
+
state: "connected";
|
|
24
|
+
deviceId: string;
|
|
25
|
+
orgId: string;
|
|
26
|
+
mode: "os" | "docker";
|
|
27
|
+
connection: DeviceConnection;
|
|
28
|
+
offlineReason?: string;
|
|
29
|
+
serviceInstalled: boolean;
|
|
30
|
+
keepAwake: {
|
|
31
|
+
mode: KeepAwakeMode;
|
|
32
|
+
held: boolean;
|
|
33
|
+
unavailable?: string;
|
|
34
|
+
};
|
|
35
|
+
lastWakeAt?: string;
|
|
36
|
+
};
|
|
37
|
+
/** One operation running on this machine for the deployment. */
|
|
38
|
+
export interface RunningOperationView {
|
|
39
|
+
tag: string;
|
|
40
|
+
conversationId: string | null;
|
|
41
|
+
accountId: string | null;
|
|
42
|
+
isolation: "restricted" | "full";
|
|
43
|
+
startedAt: string;
|
|
44
|
+
}
|
|
45
|
+
/** The `code` of a rejected shell call. */
|
|
46
|
+
export type ShellCallError = "busy" | "no_activation" | "cancelled" | "failed";
|
|
47
|
+
/** `device@1`: connect this machine to the deployment as a device. */
|
|
48
|
+
export interface DeviceCapabilityV1 {
|
|
49
|
+
status(): Promise<ThisMachineStatus>;
|
|
50
|
+
onStatus(listener: (s: ThisMachineStatus) => void): () => void;
|
|
51
|
+
running(): Promise<RunningOperationView[]>;
|
|
52
|
+
connect(input: {
|
|
53
|
+
orgId: string;
|
|
54
|
+
deviceId?: string;
|
|
55
|
+
}): Promise<"connected" | "cancelled">;
|
|
56
|
+
pause(): Promise<void>;
|
|
57
|
+
resume(): Promise<"resumed" | "cancelled">;
|
|
58
|
+
disconnect(): Promise<void>;
|
|
59
|
+
requestCeiling(input: {
|
|
60
|
+
fullAccess: boolean;
|
|
61
|
+
projectReach: "workspace" | "os-user";
|
|
62
|
+
}): Promise<"applied" | "cancelled">;
|
|
63
|
+
setKeepAwake(mode: KeepAwakeMode): Promise<"applied" | "cancelled">;
|
|
64
|
+
}
|
|
65
|
+
/** `notify@1`: a native notification; `path` is the in-app path opened on click. */
|
|
66
|
+
export interface NotifyCapabilityV1 {
|
|
67
|
+
notify(input: {
|
|
68
|
+
title: string;
|
|
69
|
+
body: string;
|
|
70
|
+
path?: string;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
/** `openExternal@1`: open a URL in the system browser. */
|
|
74
|
+
export interface OpenExternalCapabilityV1 {
|
|
75
|
+
open(url: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
/** `signIn@1`: sign in through the system browser (desktop client spec §6.5). */
|
|
78
|
+
export interface SignInCapabilityV1 {
|
|
79
|
+
start(): Promise<"signedIn" | "cancelled">;
|
|
80
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
device: "device@1",
|
|
10
|
+
notify: "notify@1",
|
|
11
|
+
openExternal: "openExternal@1",
|
|
12
|
+
signIn: "signIn@1",
|
|
13
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell environment (mobile layout spec §9, desktop client spec): the contract of the global a
|
|
3
|
+
* native shell injects as `window.capybaraShell`, only into the top frame of the deployment's
|
|
4
|
+
* origin. Types and the capability registry only; `capybara-hq/clients` implements it.
|
|
5
|
+
*/
|
|
6
|
+
export interface CapybaraShell {
|
|
7
|
+
/** The envelope version; bumped only on an incompatible change of this shape. */
|
|
8
|
+
readonly version: 1;
|
|
9
|
+
/** Which shell: drives nothing but the shell attributes. */
|
|
10
|
+
readonly kind: "desktop" | "mobile";
|
|
11
|
+
/** The operating system, for platform conventions only (traffic lights, back gesture). */
|
|
12
|
+
readonly platform: "macos" | "windows" | "linux" | "ios" | "android";
|
|
13
|
+
/** The shell's own version, for reports and diagnostics; never parsed for features. */
|
|
14
|
+
readonly shellVersion: string;
|
|
15
|
+
/**
|
|
16
|
+
* CSS px the shell's own chrome covers at each edge of the web view, beyond the OS safe areas
|
|
17
|
+
* (macOS traffic lights with `titleBarStyle: hiddenInset`, a native title bar overlay).
|
|
18
|
+
*/
|
|
19
|
+
readonly insets: {
|
|
20
|
+
top: number;
|
|
21
|
+
right: number;
|
|
22
|
+
bottom: number;
|
|
23
|
+
left: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The rectangle the shell's window controls occupy over the web view, in CSS px from the web
|
|
27
|
+
* view's top-left corner (macOS traffic lights, a Windows caption-button overlay at the right);
|
|
28
|
+
* null when there are none or they are hidden (fullscreen). Modelled on Window Controls
|
|
29
|
+
* Overlay's `titlebar-area-*`. Optional: a shell without overlaid controls omits it.
|
|
30
|
+
*/
|
|
31
|
+
readonly controls?: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
} | null;
|
|
37
|
+
/** Capabilities by `name@major` (as extension points are named, `channel@1`). */
|
|
38
|
+
readonly capabilities: Readonly<Record<string, object>>;
|
|
39
|
+
/**
|
|
40
|
+
* Insets, controls or capabilities changed (fullscreen hides the traffic lights; a capability
|
|
41
|
+
* appears after load). Returns unsubscribe.
|
|
42
|
+
*/
|
|
43
|
+
on(event: "change", listener: () => void): () => void;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
interface Window {
|
|
47
|
+
capybaraShell?: CapybaraShell;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The registry of capability names (mobile layout spec §9.2). A new capability is added here
|
|
52
|
+
* (key, owner) by the spec that defines it; the owner names the spec holding its functions.
|
|
53
|
+
*/
|
|
54
|
+
export declare const SHELL_CAPABILITIES: readonly {
|
|
55
|
+
key: string;
|
|
56
|
+
owner: string;
|
|
57
|
+
}[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell environment (mobile layout spec §9, desktop client spec): the contract of the global a
|
|
3
|
+
* native shell injects as `window.capybaraShell`, only into the top frame of the deployment's
|
|
4
|
+
* origin. Types and the capability registry only; `capybara-hq/clients` implements it.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The registry of capability names (mobile layout spec §9.2). A new capability is added here
|
|
8
|
+
* (key, owner) by the spec that defines it; the owner names the spec holding its functions.
|
|
9
|
+
*/
|
|
10
|
+
export const SHELL_CAPABILITIES = [
|
|
11
|
+
{ key: "device@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
|
|
12
|
+
{ key: "notify@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
|
|
13
|
+
{ key: "openExternal@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
|
|
14
|
+
{ key: "signIn@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md), §6.5" },
|
|
15
|
+
{ key: "chrome@1", owner: "mobile layout spec (2026-11-19-mobile-layout-design.md)" },
|
|
16
|
+
];
|
|
@@ -27,13 +27,14 @@ export declare function parseSkillArguments(args: string): string[];
|
|
|
27
27
|
/**
|
|
28
28
|
* A skill body with its arguments substituted (see the file header), without the wrapper.
|
|
29
29
|
* `skillName` is the resolved skill's bare name and `digest` its version's `skillDigest`:
|
|
30
|
-
* `${CLAUDE_SKILL_DIR}` becomes
|
|
31
|
-
*
|
|
30
|
+
* `${CLAUDE_SKILL_DIR}` becomes `<skillsRoot>/<skillName>@<digest>` (`skillsRoot`: the instance's
|
|
31
|
+
* skills root, default `/skills`; a qualified `<plugin>:<name>` or a digest that is not 12
|
|
32
|
+
* lowercase hex digits throws a `TypeError`). `args` is trimmed;
|
|
32
33
|
* more than {@link SKILL_INVOCATION_LIMITS.argumentsMaxChars} characters throw a `RangeError`, and
|
|
33
34
|
* so does a result longer than {@link SKILL_INVOCATION_LIMITS.renderedMaxChars} (checked while
|
|
34
35
|
* substituting, before the long string is built).
|
|
35
36
|
*/
|
|
36
|
-
export declare function renderSkillBody(body: string, invocation: SkillInvocation, args: string, skillName: string, digest: string): string;
|
|
37
|
+
export declare function renderSkillBody(body: string, invocation: SkillInvocation, args: string, skillName: string, digest: string, skillsRoot?: string): string;
|
|
37
38
|
/** Input of {@link renderSkillInvocation}. */
|
|
38
39
|
export interface RenderSkillInvocationInput {
|
|
39
40
|
/**
|
package/dist/skill-invocation.js
CHANGED
|
@@ -112,16 +112,17 @@ const tooLong = () => new RangeError(`the rendered skill must be at most ${SKILL
|
|
|
112
112
|
/**
|
|
113
113
|
* A skill body with its arguments substituted (see the file header), without the wrapper.
|
|
114
114
|
* `skillName` is the resolved skill's bare name and `digest` its version's `skillDigest`:
|
|
115
|
-
* `${CLAUDE_SKILL_DIR}` becomes
|
|
116
|
-
*
|
|
115
|
+
* `${CLAUDE_SKILL_DIR}` becomes `<skillsRoot>/<skillName>@<digest>` (`skillsRoot`: the instance's
|
|
116
|
+
* skills root, default `/skills`; a qualified `<plugin>:<name>` or a digest that is not 12
|
|
117
|
+
* lowercase hex digits throws a `TypeError`). `args` is trimmed;
|
|
117
118
|
* more than {@link SKILL_INVOCATION_LIMITS.argumentsMaxChars} characters throw a `RangeError`, and
|
|
118
119
|
* so does a result longer than {@link SKILL_INVOCATION_LIMITS.renderedMaxChars} (checked while
|
|
119
120
|
* substituting, before the long string is built).
|
|
120
121
|
*/
|
|
121
|
-
export function renderSkillBody(body, invocation, args, skillName, digest) {
|
|
122
|
+
export function renderSkillBody(body, invocation, args, skillName, digest, skillsRoot = SKILLS_SANDBOX_ROOT) {
|
|
122
123
|
checkSkillName(skillName);
|
|
123
124
|
checkDigest(digest);
|
|
124
|
-
const dir = skillSandboxDir(skillName, digest);
|
|
125
|
+
const dir = skillSandboxDir(skillName, digest, skillsRoot);
|
|
125
126
|
const all = trimmedArgs(args);
|
|
126
127
|
const values = parseSkillArguments(all);
|
|
127
128
|
const named = invocation.arguments ?? [];
|
package/dist/skill.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Limits of a skill package. */
|
|
2
2
|
export declare const SKILL_LIMITS: {
|
|
3
3
|
readonly nameMaxChars: 64;
|
|
4
4
|
readonly descriptionMaxChars: 1024;
|
|
5
5
|
readonly compatibilityMaxChars: 500;
|
|
6
|
-
/**
|
|
6
|
+
/** Upper bound of a single file after extraction (bytes). */
|
|
7
7
|
readonly fileBytes: number;
|
|
8
|
-
/**
|
|
8
|
+
/** Upper bound of the total of all files after extraction (bytes). */
|
|
9
9
|
readonly totalBytes: number;
|
|
10
|
-
/**
|
|
10
|
+
/** Upper bound on the number of files. */
|
|
11
11
|
readonly maxFiles: 1000;
|
|
12
|
-
/**
|
|
12
|
+
/** Upper bound on the length of a relative path inside the package (characters). */
|
|
13
13
|
readonly pathMaxChars: 512;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Upper bound on the length of the frontmatter (between the two `---` lines) in characters; above
|
|
16
|
+
* it no YAML parsing is done.
|
|
17
|
+
*/
|
|
15
18
|
readonly frontmatterMaxChars: number;
|
|
16
19
|
};
|
|
17
20
|
/** Limits of the invocation keys of a SKILL.md (see `SkillInvocation`). */
|
|
@@ -28,14 +31,14 @@ export declare const SKILL_INVOCATION_LIMITS: {
|
|
|
28
31
|
*/
|
|
29
32
|
readonly renderedMaxChars: 200000;
|
|
30
33
|
};
|
|
31
|
-
/**
|
|
34
|
+
/** The skill entry file (package root, case-sensitive). */
|
|
32
35
|
export declare const SKILL_ENTRY_FILE = "SKILL.md";
|
|
33
36
|
/**
|
|
34
37
|
* The sandbox root for skills: each skill version is copied (read-only to commands) to
|
|
35
38
|
* `/skills/<name>@<digest>/` ({@link skillSandboxDir}).
|
|
36
39
|
*/
|
|
37
40
|
export declare const SKILLS_SANDBOX_ROOT = "/skills";
|
|
38
|
-
/**
|
|
41
|
+
/** Whether it is a valid skill name (see the specification at the top of the file). */
|
|
39
42
|
export declare function isSkillName(s: unknown): s is string;
|
|
40
43
|
/**
|
|
41
44
|
* The digest of a skill version's file manifest: the first 12 hex digits of the sha256 of its
|
|
@@ -49,16 +52,19 @@ export declare function skillDigest(files: {
|
|
|
49
52
|
size: number;
|
|
50
53
|
sha256: string;
|
|
51
54
|
}[]): string;
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* A skill version's directory in the sandbox: `<root>/<name>@<digest>` ({@link skillDigest});
|
|
57
|
+
* `root` is the instance's skills root (`SandboxRoots.skills`, default `/skills`).
|
|
58
|
+
*/
|
|
59
|
+
export declare function skillSandboxDir(name: string, digest: string, root?: string): string;
|
|
60
|
+
/** A skill file's path in the sandbox: `<root>/<name>@<digest>/<path>` ({@link skillSandboxDir}). */
|
|
61
|
+
export declare function skillSandboxPath(name: string, digest: string, path: string, root?: string): string;
|
|
62
|
+
/** The result of a successful {@link parseSkillMd}. */
|
|
57
63
|
export interface ParsedSkillMd {
|
|
58
64
|
name: string;
|
|
59
|
-
/**
|
|
65
|
+
/** Trimmed of leading and trailing whitespace. */
|
|
60
66
|
description: string;
|
|
61
|
-
/**
|
|
67
|
+
/** The Markdown body after the frontmatter. */
|
|
62
68
|
body: string;
|
|
63
69
|
/**
|
|
64
70
|
* The parsed YAML frontmatter mapping: every key, values unchanged (e.g. Claude Code's
|
|
@@ -76,17 +82,24 @@ export interface ParseSkillMdOptions {
|
|
|
76
82
|
invocationKeys?: boolean;
|
|
77
83
|
}
|
|
78
84
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
85
|
+
* Parses SKILL.md: it starts with YAML frontmatter wrapped in `---` lines, followed by the body.
|
|
86
|
+
* Tolerates BOM and CRLF (CRLF in the body becomes LF).
|
|
87
|
+
* Returns name / description / body, or all problems (in English, directly showable to a model or
|
|
88
|
+
* an admin).
|
|
81
89
|
*/
|
|
82
90
|
export declare function parseSkillMd(text: string, options?: ParseSkillMdOptions): ParsedSkillMd | {
|
|
83
91
|
errors: string[];
|
|
84
92
|
};
|
|
85
93
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
94
|
+
* Validates a skill package's file list (paths relative to the package root, files only, no
|
|
95
|
+
* directory entries):
|
|
96
|
+
* the root must have `SKILL.md`; single file ≤ {@link SKILL_LIMITS.fileBytes}; total ≤ {@link
|
|
97
|
+
* SKILL_LIMITS.totalBytes};
|
|
98
|
+
* file count ≤ {@link SKILL_LIMITS.maxFiles}; paths must not escape (absolute paths, `..`,
|
|
99
|
+
* backslashes, drive letters, control characters), must not repeat
|
|
100
|
+
* (differing only in case also counts as repeating: they would overwrite each other on
|
|
101
|
+
* case-insensitive file systems), and a file must not share a name with a directory. Returns the
|
|
102
|
+
* list of problems; an empty array means valid.
|
|
90
103
|
*/
|
|
91
104
|
export declare function validateSkillPackage(files: {
|
|
92
105
|
path: string;
|