@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31

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 (127) hide show
  1. package/agent-docs/agent-templates.md +15 -3
  2. package/agent-docs/concepts.md +5 -0
  3. package/agent-docs/connector-templates.md +2 -1
  4. package/agent-docs/extension-points/channel.md +1 -1
  5. package/agent-docs/extension-points/config-source.md +1 -1
  6. package/agent-docs/extension-points/connector.md +1 -1
  7. package/agent-docs/extension-points/context.md +15 -0
  8. package/agent-docs/extension-points/counter.md +1 -1
  9. package/agent-docs/extension-points/directory.md +1 -1
  10. package/agent-docs/extension-points/file-preview.md +1 -1
  11. package/agent-docs/extension-points/identity-source.md +1 -1
  12. package/agent-docs/extension-points/model-provider.md +4 -2
  13. package/agent-docs/extension-points/object-store.md +3 -1
  14. package/agent-docs/extension-points/sandbox.md +3 -3
  15. package/agent-docs/extension-points/secret-store.md +1 -1
  16. package/agent-docs/extension-points/web-fetch.md +1 -1
  17. package/agent-docs/extension-points/web-search.md +1 -1
  18. package/agent-docs/extensions.md +29 -4
  19. package/agent-docs/plugin-format.md +43 -3
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +1 -1
  22. package/agent-docs/tool-naming.md +1 -1
  23. package/dist/agent-template.d.ts +15 -6
  24. package/dist/agent-template.js +32 -13
  25. package/dist/bootstrap.d.ts +15 -1
  26. package/dist/bootstrap.js +17 -1
  27. package/dist/cards.d.ts +56 -13
  28. package/dist/cards.js +90 -20
  29. package/dist/channel.d.ts +111 -48
  30. package/dist/channel.js +10 -5
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +22 -0
  36. package/dist/config-ui.js +64 -4
  37. package/dist/connector-auth.d.ts +7 -2
  38. package/dist/connector-auth.js +29 -8
  39. package/dist/connector.d.ts +74 -32
  40. package/dist/context.d.ts +40 -0
  41. package/dist/context.js +2 -0
  42. package/dist/ctx.d.ts +135 -26
  43. package/dist/define-extension.d.ts +26 -12
  44. package/dist/define-extension.js +11 -4
  45. package/dist/device-protocol-v3.d.ts +117 -0
  46. package/dist/device-protocol-v3.js +409 -0
  47. package/dist/device-protocol.d.ts +330 -0
  48. package/dist/device-protocol.js +567 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +5 -2
  51. package/dist/file-preview.d.ts +1 -1
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +111 -21
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +52 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +22 -9
  59. package/dist/index.d.ts +23 -1
  60. package/dist/index.js +24 -1
  61. package/dist/marketplace.d.ts +26 -0
  62. package/dist/marketplace.js +43 -1
  63. package/dist/model-params.d.ts +41 -22
  64. package/dist/model-params.js +28 -15
  65. package/dist/model.d.ts +180 -71
  66. package/dist/model.js +71 -19
  67. package/dist/net.d.ts +52 -0
  68. package/dist/net.js +34 -0
  69. package/dist/permissions.d.ts +42 -20
  70. package/dist/permissions.js +97 -40
  71. package/dist/plugin-manifest.d.ts +45 -5
  72. package/dist/plugin-manifest.js +169 -6
  73. package/dist/plugin-package.d.ts +82 -38
  74. package/dist/plugin-package.js +61 -29
  75. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  76. package/dist/sandbox-linux-runtime-source.js +1886 -0
  77. package/dist/sandbox-native-runtime-source.d.ts +8 -0
  78. package/dist/sandbox-native-runtime-source.js +325 -0
  79. package/dist/sandbox-operation.d.ts +248 -0
  80. package/dist/sandbox-operation.js +245 -0
  81. package/dist/sandbox-runtime-source.d.ts +19 -0
  82. package/dist/sandbox-runtime-source.js +28 -0
  83. package/dist/sandbox-write-denies.d.ts +60 -0
  84. package/dist/sandbox-write-denies.js +630 -0
  85. package/dist/sandbox.d.ts +201 -16
  86. package/dist/sandbox.js +89 -14
  87. package/dist/secret.d.ts +4 -1
  88. package/dist/secret.js +4 -1
  89. package/dist/setup-check.d.ts +115 -0
  90. package/dist/setup-check.js +142 -0
  91. package/dist/setup-guide-parse.d.ts +121 -0
  92. package/dist/setup-guide-parse.js +350 -0
  93. package/dist/setup-guide-render.d.ts +45 -0
  94. package/dist/setup-guide-render.js +351 -0
  95. package/dist/setup-guide.d.ts +94 -0
  96. package/dist/setup-guide.js +336 -0
  97. package/dist/skill-invocation.d.ts +4 -3
  98. package/dist/skill-invocation.js +5 -4
  99. package/dist/skill.d.ts +34 -21
  100. package/dist/skill.js +48 -31
  101. package/dist/storage.d.ts +52 -25
  102. package/dist/theme-assets.d.ts +39 -0
  103. package/dist/theme-assets.js +449 -0
  104. package/dist/theme-readability.d.ts +37 -0
  105. package/dist/theme-readability.js +145 -0
  106. package/dist/theme-tokens.generated.d.ts +279 -0
  107. package/dist/theme-tokens.generated.js +174 -0
  108. package/dist/theme.d.ts +152 -0
  109. package/dist/theme.js +392 -0
  110. package/dist/tool.d.ts +69 -26
  111. package/dist/tool.js +29 -9
  112. package/dist/ui-parts.d.ts +23 -0
  113. package/dist/ui-parts.js +337 -0
  114. package/dist/ui-resolve.d.ts +35 -0
  115. package/dist/ui-resolve.js +42 -0
  116. package/dist/ui-slots.d.ts +53 -0
  117. package/dist/ui-slots.js +238 -0
  118. package/dist/ui.d.ts +191 -79
  119. package/dist/ui.js +101 -27
  120. package/dist/url.d.ts +4 -1
  121. package/dist/url.js +4 -1
  122. package/package.json +7 -1
  123. package/schemas/bootstrap.v1.schema.json +6 -0
  124. package/schemas/connector-template.v1.schema.json +35 -0
  125. package/schemas/marketplace.v1.schema.json +14 -0
  126. package/schemas/plugin.v1.schema.json +115 -3
  127. 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
+ }
@@ -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 `/skills/<skillName>@<digest>` (a qualified `<plugin>:<name>` or a
31
- * digest that is not 12 lowercase hex digits throws a `TypeError`). `args` is trimmed;
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
  /**
@@ -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 `/skills/<skillName>@<digest>` (a qualified `<plugin>:<name>` or a
116
- * digest that is not 12 lowercase hex digits throws a `TypeError`). `args` is trimmed;
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
- /** frontmatter(两条 `---` 之间)的长度上限(字符),超过不做 YAML 解析。 */
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
- /** A skill version's directory in the sandbox: `/skills/<name>@<digest>` ({@link skillDigest}). */
53
- export declare function skillSandboxDir(name: string, digest: string): string;
54
- /** A skill file's path in the sandbox: `/skills/<name>@<digest>/<path>`. */
55
- export declare function skillSandboxPath(name: string, digest: string, path: string): string;
56
- /** {@link parseSkillMd} 成功时的结果。 */
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
- /** frontmatter 之后的 Markdown 正文。 */
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
- * 解析 SKILL.md:开头是 `---` 行包住的 YAML frontmatter,之后是正文。容忍 BOM 与 CRLF(正文里的 CRLF 换成 LF)。
80
- * 返回 name / description / 正文,或全部问题(英文,可直接给模型或管理员看)。
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
- * 根目录必须有 `SKILL.md`;单文件 ≤ {@link SKILL_LIMITS.fileBytes};总量 ≤ {@link SKILL_LIMITS.totalBytes};
88
- * 文件数 ≤ {@link SKILL_LIMITS.maxFiles};路径不能越界(绝对路径、`..`、反斜杠、盘符、控制字符),不能重复
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;
package/dist/skill.js CHANGED
@@ -1,13 +1,17 @@
1
1
  /**
2
- * 技能(Agent Skills 格式)的纯解析与校验函数:内核上传技能包、agent 提议技能改动时都用它们。
2
+ * Pure parsing and validation functions for skills (Agent Skills format): used when the kernel
3
+ * uploads a skill package and when an agent proposes a skill change.
3
4
  *
4
- * 格式依据(2026-10-21 核实):
5
- * - Agent Skills 规范 https://agentskills.io/specification :`name` 必填,1–64 个字符,只能是小写字母、数字与
6
- * 连字符,不能以连字符开头或结尾,不能有连续连字符,须与所在目录同名;`description` 必填,1–1024 个字符;
7
- * 可选 `license`、`compatibility`(1–500 个字符)、`metadata`、`allowed-tools`。
8
- * - Anthropic 文档 https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview :
9
- * `name` 与 `description` 不能含 XML 标签(另有保留词 "anthropic" / "claude",那是 Anthropic 平台自己的规则,
10
- * 这里不采用)。
5
+ * Format sources (verified 2026-10-21):
6
+ * - Agent Skills specification https://agentskills.io/specification : `name` is required, 1–64
7
+ * characters, only lowercase letters, digits and
8
+ * hyphens, must not start or end with a hyphen, no consecutive hyphens, and must match its
9
+ * directory name; `description` is required, 1–1024 characters;
10
+ * optional `license`, `compatibility` (1–500 characters), `metadata`, `allowed-tools`.
11
+ * - Anthropic docs https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview :
12
+ * `name` and `description` must not contain XML tags (there are also reserved words "anthropic" /
13
+ * "claude", which are Anthropic's own platform rules and
14
+ * are not adopted here).
11
15
  *
12
16
  * Choices: the description goes into the model's system prompt, so XML tags are refused as Anthropic
13
17
  * does (no forged prompt structure). Keys outside the specification are allowed and ignored, so
@@ -23,20 +27,23 @@ import { readFrontmatter } from "./frontmatter.js";
23
27
  import { hasControlChars } from "./model.js";
24
28
  import { validateSandboxPath } from "./sandbox.js";
25
29
  import { argumentHintText, SKILL_ARGUMENT_NAME_RE } from "./skill-keys.js";
26
- /** 技能包的上限。 */
30
+ /** Limits of a skill package. */
27
31
  export const SKILL_LIMITS = {
28
32
  nameMaxChars: 64,
29
33
  descriptionMaxChars: 1024,
30
34
  compatibilityMaxChars: 500,
31
- /** 单个文件解压后的上限(字节)。 */
35
+ /** Upper bound of a single file after extraction (bytes). */
32
36
  fileBytes: 10 * 1024 * 1024,
33
- /** 全部文件解压后的总量上限(字节)。 */
37
+ /** Upper bound of the total of all files after extraction (bytes). */
34
38
  totalBytes: 50 * 1024 * 1024,
35
- /** 文件数上限。 */
39
+ /** Upper bound on the number of files. */
36
40
  maxFiles: 1000,
37
- /** 包内相对路径的长度上限(字符)。 */
41
+ /** Upper bound on the length of a relative path inside the package (characters). */
38
42
  pathMaxChars: 512,
39
- /** frontmatter(两条 `---` 之间)的长度上限(字符),超过不做 YAML 解析。 */
43
+ /**
44
+ * Upper bound on the length of the frontmatter (between the two `---` lines) in characters; above
45
+ * it no YAML parsing is done.
46
+ */
40
47
  frontmatterMaxChars: 64 * 1024,
41
48
  };
42
49
  /** Limits of the invocation keys of a SKILL.md (see `SkillInvocation`). */
@@ -53,7 +60,7 @@ export const SKILL_INVOCATION_LIMITS = {
53
60
  */
54
61
  renderedMaxChars: 200_000,
55
62
  };
56
- /** 技能入口文件(包根目录,大小写敏感)。 */
63
+ /** The skill entry file (package root, case-sensitive). */
57
64
  export const SKILL_ENTRY_FILE = "SKILL.md";
58
65
  /**
59
66
  * The sandbox root for skills: each skill version is copied (read-only to commands) to
@@ -63,7 +70,7 @@ export const SKILLS_SANDBOX_ROOT = "/skills";
63
70
  const NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
64
71
  const XML_TAG_RE = /<\/?[A-Za-z][^<>]*>/;
65
72
  const DRIVE_RE = /^[A-Za-z]:/;
66
- /** 是否为合法的技能名(见文件头的规范说明)。 */
73
+ /** Whether it is a valid skill name (see the specification at the top of the file). */
67
74
  export function isSkillName(s) {
68
75
  return typeof s === "string" && s.length <= SKILL_LIMITS.nameMaxChars && NAME_RE.test(s);
69
76
  }
@@ -81,18 +88,23 @@ export function skillDigest(files) {
81
88
  .join("");
82
89
  return createHash("sha256").update(lines).digest("hex").slice(0, 12);
83
90
  }
84
- /** A skill version's directory in the sandbox: `/skills/<name>@<digest>` ({@link skillDigest}). */
85
- export function skillSandboxDir(name, digest) {
86
- return `${SKILLS_SANDBOX_ROOT}/${name}@${digest}`;
91
+ /**
92
+ * A skill version's directory in the sandbox: `<root>/<name>@<digest>` ({@link skillDigest});
93
+ * `root` is the instance's skills root (`SandboxRoots.skills`, default `/skills`).
94
+ */
95
+ export function skillSandboxDir(name, digest, root = SKILLS_SANDBOX_ROOT) {
96
+ return `${root}/${name}@${digest}`;
87
97
  }
88
- /** A skill file's path in the sandbox: `/skills/<name>@<digest>/<path>`. */
89
- export function skillSandboxPath(name, digest, path) {
90
- return `${skillSandboxDir(name, digest)}/${path}`;
98
+ /** A skill file's path in the sandbox: `<root>/<name>@<digest>/<path>` ({@link skillSandboxDir}). */
99
+ export function skillSandboxPath(name, digest, path, root = SKILLS_SANDBOX_ROOT) {
100
+ return `${skillSandboxDir(name, digest, root)}/${path}`;
91
101
  }
92
102
  const chars = (s) => [...s].length;
93
103
  /**
94
- * 解析 SKILL.md:开头是 `---` 行包住的 YAML frontmatter,之后是正文。容忍 BOM 与 CRLF(正文里的 CRLF 换成 LF)。
95
- * 返回 name / description / 正文,或全部问题(英文,可直接给模型或管理员看)。
104
+ * Parses SKILL.md: it starts with YAML frontmatter wrapped in `---` lines, followed by the body.
105
+ * Tolerates BOM and CRLF (CRLF in the body becomes LF).
106
+ * Returns name / description / body, or all problems (in English, directly showable to a model or
107
+ * an admin).
96
108
  */
97
109
  export function parseSkillMd(text, options = {}) {
98
110
  const read = readFrontmatter(text, "SKILL.md", SKILL_LIMITS.frontmatterMaxChars);
@@ -175,9 +187,9 @@ function invocationKeyErrors(fm) {
175
187
  }
176
188
  return errors;
177
189
  }
178
- /** 给人看的路径:含控制字符时用 JSON 转义。 */
190
+ /** A path for humans to read: JSON-escaped when it contains control characters. */
179
191
  const show = (p) => (hasControlChars(p) || p === "" ? JSON.stringify(p) : p);
180
- /** 单个相对路径的问题(第一个),合法时为 null。 */
192
+ /** The problem of a single relative path (the first one), null when valid. */
181
193
  function pathProblem(p) {
182
194
  if (typeof p !== "string" || p === "")
183
195
  return "path must be a non-empty string";
@@ -200,15 +212,20 @@ function pathProblem(p) {
200
212
  if (seg === "." || seg === "..")
201
213
  return "path must not contain '.' or '..' segments";
202
214
  }
203
- // 再按沙箱路径规则核一遍(百分号编码的 `..` 等)
215
+ // Then check again against the sandbox path rules (percent-encoded `..` etc.)
204
216
  const errs = validateSandboxPath(skillSandboxPath("skill", "000000000000", p));
205
217
  return errs[0] ?? null;
206
218
  }
207
219
  /**
208
- * 校验技能包的文件清单(路径相对于包根目录,只含文件、不含目录项):
209
- * 根目录必须有 `SKILL.md`;单文件 ≤ {@link SKILL_LIMITS.fileBytes};总量 ≤ {@link SKILL_LIMITS.totalBytes};
210
- * 文件数 ≤ {@link SKILL_LIMITS.maxFiles};路径不能越界(绝对路径、`..`、反斜杠、盘符、控制字符),不能重复
211
- * (只差大小写也算重复:大小写不敏感的文件系统上会互相覆盖),文件不能与目录同名。返回问题列表,空数组表示合法。
220
+ * Validates a skill package's file list (paths relative to the package root, files only, no
221
+ * directory entries):
222
+ * the root must have `SKILL.md`; single file ≤ {@link SKILL_LIMITS.fileBytes}; total ≤ {@link
223
+ * SKILL_LIMITS.totalBytes};
224
+ * file count ≤ {@link SKILL_LIMITS.maxFiles}; paths must not escape (absolute paths, `..`,
225
+ * backslashes, drive letters, control characters), must not repeat
226
+ * (differing only in case also counts as repeating: they would overwrite each other on
227
+ * case-insensitive file systems), and a file must not share a name with a directory. Returns the
228
+ * list of problems; an empty array means valid.
212
229
  */
213
230
  export function validateSkillPackage(files) {
214
231
  if (files.length > SKILL_LIMITS.maxFiles) {