@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.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +4 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +53 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +86 -1
- package/dist/bootstrap.js +161 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +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-operation.d.ts +302 -0
- package/dist/device-operation.js +292 -0
- package/dist/device-protocol.d.ts +490 -0
- package/dist/device-protocol.js +1117 -0
- package/dist/device-provider.d.ts +472 -0
- package/dist/device-provider.js +283 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -2
- package/dist/index.js +29 -2
- 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/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +135 -0
- package/dist/setup-guide-parse.js +413 -0
- package/dist/setup-guide-render.d.ts +50 -0
- package/dist/setup-guide-render.js +367 -0
- package/dist/setup-guide.d.ts +109 -0
- package/dist/setup-guide.js +377 -0
- package/dist/shell-capabilities.d.ts +231 -0
- package/dist/shell-capabilities.js +37 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +22 -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 +49 -32
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +507 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +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-extra.v1.schema.json +172 -0
- 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 +117 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -232
- package/dist/sandbox.js +0 -120
|
@@ -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,22 @@
|
|
|
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
|
+
{ key: "haptics@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2" },
|
|
17
|
+
{ key: "share@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2" },
|
|
18
|
+
{ key: "menu@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2" },
|
|
19
|
+
{ key: "nav@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2" },
|
|
20
|
+
{ key: "profiles@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2" },
|
|
21
|
+
{ key: "push@1", owner: "mobile app spec (2026-11-20-mobile-app-design.md), §5.2 and §9" },
|
|
22
|
+
];
|
|
@@ -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;
|
package/dist/skill.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
*
|
|
5
|
-
* - Agent Skills
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
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
|
|
@@ -19,24 +23,27 @@
|
|
|
19
23
|
* `/skills/<name>@<digest>/` ({@link skillSandboxDir}, {@link skillDigest}).
|
|
20
24
|
*/
|
|
21
25
|
import { createHash } from "node:crypto";
|
|
26
|
+
import { validateSandboxPath } from "./device-provider.js";
|
|
22
27
|
import { readFrontmatter } from "./frontmatter.js";
|
|
23
28
|
import { hasControlChars } from "./model.js";
|
|
24
|
-
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
|
-
/**
|
|
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
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
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:
|
|
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
|
-
*
|
|
95
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
210
|
-
*
|
|
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) {
|
package/dist/storage.d.ts
CHANGED
|
@@ -7,27 +7,34 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** Object storage extension point ref. */
|
|
9
9
|
export declare const OBJECT_STORE_EXTENSION_POINT = "object-store@1";
|
|
10
|
-
/**
|
|
10
|
+
/** Metadata of an object. */
|
|
11
11
|
export interface ObjectHead {
|
|
12
12
|
key: string;
|
|
13
|
-
/**
|
|
13
|
+
/** Size in bytes. */
|
|
14
14
|
size: number;
|
|
15
15
|
contentType: string;
|
|
16
16
|
etag?: string;
|
|
17
|
-
/** ISO 8601
|
|
17
|
+
/** ISO 8601 time. */
|
|
18
18
|
lastModified?: string;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The `object-store@1` implementation (provided by an object-store plugin, e.g. S3-compatible
|
|
22
|
+
* storage).
|
|
23
|
+
*/
|
|
21
24
|
export interface ObjectStore {
|
|
22
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Writes (overwriting a key of the same name); give `size` when `body` is a stream if possible.
|
|
27
|
+
*/
|
|
23
28
|
put(key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
|
|
24
29
|
contentType: string;
|
|
25
30
|
size?: number;
|
|
26
31
|
signal?: AbortSignal;
|
|
27
32
|
}): Promise<ObjectHead>;
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
34
|
+
* Reads; returns null when missing. `range` is a closed byte range; an omitted `end` means read
|
|
35
|
+
* to the end.
|
|
36
|
+
* With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
|
|
37
|
+
* body may be the whole object.
|
|
31
38
|
*/
|
|
32
39
|
get(key: string, opts?: {
|
|
33
40
|
signal?: AbortSignal;
|
|
@@ -39,15 +46,18 @@ export interface ObjectStore {
|
|
|
39
46
|
head: ObjectHead;
|
|
40
47
|
body: ReadableStream<Uint8Array>;
|
|
41
48
|
} | null>;
|
|
42
|
-
/**
|
|
49
|
+
/** Returns null when missing. */
|
|
43
50
|
head(key: string): Promise<ObjectHead | null>;
|
|
44
|
-
/**
|
|
51
|
+
/** Deletes; a missing key also counts as success. */
|
|
45
52
|
delete(key: string): Promise<void>;
|
|
46
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Deletes all objects under a prefix and returns the number deleted (used for org data deletion).
|
|
55
|
+
*/
|
|
47
56
|
deletePrefix(prefix: string): Promise<number>;
|
|
48
57
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
58
|
+
* Lists objects under a prefix with pagination; an omitted `cursor` in the result means there is
|
|
59
|
+
* no next page. When the listing carries no type, `contentType` is an empty string
|
|
60
|
+
* (use `head` to get it when needed).
|
|
51
61
|
*/
|
|
52
62
|
list(prefix: string, opts?: {
|
|
53
63
|
cursor?: string;
|
|
@@ -56,41 +66,58 @@ export interface ObjectStore {
|
|
|
56
66
|
items: ObjectHead[];
|
|
57
67
|
cursor?: string;
|
|
58
68
|
}>;
|
|
59
|
-
/**
|
|
69
|
+
/** Presigned download URL (options in {@link PresignGetOptions}). */
|
|
60
70
|
presignGet(key: string, opts: PresignGetOptions): Promise<string>;
|
|
61
71
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
72
|
+
* Presigned upload: the browser uploads straight to storage following the returned {@link
|
|
73
|
+
* PresignedUpload}. An upload over `maxSize` must be rejected by the **store side**
|
|
74
|
+
* (a presigned PUT cannot limit the size, so S3-compatible implementations use a POST policy with
|
|
75
|
+
* a `content-length-range` condition).
|
|
64
76
|
*/
|
|
65
77
|
presignPut(key: string, opts: {
|
|
66
78
|
contentType: string;
|
|
67
79
|
maxSize: number;
|
|
68
80
|
ttlSeconds: number;
|
|
69
81
|
}): Promise<PresignedUpload>;
|
|
82
|
+
/**
|
|
83
|
+
* The canonical URI of a key in this store: unsigned, stable, no credentials
|
|
84
|
+
* (`s3://bucket/key`). This is an identifier, never a presigned URL: it may be recorded in an
|
|
85
|
+
* event log and shown to a model, so it must stay valid and carry no secret. Optional: a store
|
|
86
|
+
* with no notion of URIs leaves it out and the kernel falls back to its own reference.
|
|
87
|
+
*/
|
|
88
|
+
uri?(key: string): string;
|
|
70
89
|
}
|
|
71
|
-
/**
|
|
90
|
+
/** Options of a presigned download. */
|
|
72
91
|
export interface PresignGetOptions {
|
|
73
92
|
ttlSeconds: number;
|
|
74
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Download file name, goes into `Content-Disposition` (RFC 6266; non-ASCII uses
|
|
95
|
+
* `filename*=UTF-8''…`).
|
|
96
|
+
*/
|
|
75
97
|
downloadName?: string;
|
|
76
98
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
99
|
+
* How the browser opens it: `attachment` (default, download) or `inline` (display in the page).
|
|
100
|
+
* User-uploaded content should use `inline` only for types
|
|
101
|
+
* that do not execute scripts (images, PDF).
|
|
79
102
|
*/
|
|
80
103
|
disposition?: "attachment" | "inline";
|
|
81
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Overrides the response `Content-Type` (e.g. return the verified type rather than the type
|
|
106
|
+
* recorded in storage).
|
|
107
|
+
*/
|
|
82
108
|
responseContentType?: string;
|
|
83
109
|
}
|
|
84
110
|
/**
|
|
85
|
-
*
|
|
86
|
-
* - `PUT
|
|
87
|
-
* - `POST
|
|
88
|
-
*
|
|
111
|
+
* The request method of a presigned upload:
|
|
112
|
+
* - `PUT`: the request body is the file bytes, and the request carries `headers`;
|
|
113
|
+
* - `POST`: a `multipart/form-data` form; first put every item of `fields` in as is, and put the
|
|
114
|
+
* file field `file` **last**;
|
|
115
|
+
* the request carries `headers` (usually empty).
|
|
89
116
|
*/
|
|
90
117
|
export interface PresignedUpload {
|
|
91
118
|
method: "PUT" | "POST";
|
|
92
119
|
url: string;
|
|
93
120
|
headers: Record<string, string>;
|
|
94
|
-
/** `POST
|
|
121
|
+
/** Always present for `POST`: the form fields (including policy and signature). */
|
|
95
122
|
fields?: Record<string, string>;
|
|
96
123
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ParsedTheme } from "./theme.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses a logo SVG (UTF-8, ≤ {@link THEME_LIMITS}`.svgBytes`) with a strict, namespace-aware
|
|
4
|
+
* XML parser and re-serializes it. The root must be an `svg` element in the SVG namespace with a
|
|
5
|
+
* numeric `viewBox`; its `width`, `height` and `class` are dropped. Rejected: a DOCTYPE (and so
|
|
6
|
+
* any entity declaration), processing instructions, a non-UTF-8 encoding, elements outside the
|
|
7
|
+
* SVG allowlist (`script`, `foreignObject`, `style`, …) or in the XHTML namespace, `style` and
|
|
8
|
+
* `on*` attributes, `href` / `xlink:href` not starting with `#`, `javascript:` / `vbscript:` in
|
|
9
|
+
* any value, quotes or a backslash in attribute values, any function other than `url(#id)`, colors
|
|
10
|
+
* (`rgb`, `rgba`, `hsl`, `hsla`) and transforms (`translate`, `rotate`, `scale`, `matrix`,
|
|
11
|
+
* `skewX`, `skewY`), a viewBox longer than 128 characters, and animation of `href`, `style` or event
|
|
12
|
+
* handlers. Comments, the XML declaration and elements / attributes in other namespaces (editor
|
|
13
|
+
* metadata) are dropped; CDATA becomes escaped text. Never throws.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sanitizeThemeSvg(bytes: Uint8Array): {
|
|
16
|
+
svg: string;
|
|
17
|
+
} | {
|
|
18
|
+
error: string;
|
|
19
|
+
};
|
|
20
|
+
/** A woff2 font: the `wOF2` signature and at most {@link THEME_LIMITS}`.fontBytes`. */
|
|
21
|
+
export declare function checkWoff2(bytes: Uint8Array): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A PNG logo: the PNG signature, an `IHDR` first chunk with a height of at least
|
|
24
|
+
* {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most `maxBytes` (default
|
|
25
|
+
* {@link THEME_LIMITS}`.pngBytes`; an app icon allows {@link THEME_LIMITS}`.appIconBytes`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkPng(bytes: Uint8Array, maxBytes?: number): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Every asset a parsed theme names, in order: `fonts.<i>.file`, `logo.mark`, `logo.favicon`,
|
|
30
|
+
* `logo.illustration`, `logo.appIcon`, `logo.appIconMaskable`, `avatars.<i>.file`. `ref` is the
|
|
31
|
+
* path as written (an optional leading `./`). The one list every reader of theme assets uses (the
|
|
32
|
+
* checks, packing, the catalog and delivery), so a file the theme does not name is never read or
|
|
33
|
+
* served.
|
|
34
|
+
*/
|
|
35
|
+
export declare function themeAssetRefs(theme: ParsedTheme): {
|
|
36
|
+
field: string;
|
|
37
|
+
ref: string;
|
|
38
|
+
}[];
|
|
39
|
+
/**
|
|
40
|
+
* Resolves and checks the asset files of a parsed theme ({@link themeAssetRefs}), each by its
|
|
41
|
+
* kind: `fonts[].file` ({@link checkWoff2}); `logo.mark` and `logo.illustration` (`.svg` through
|
|
42
|
+
* {@link sanitizeThemeSvg}, `.png` through {@link checkPng}); `logo.favicon` and `avatars[].file`
|
|
43
|
+
* likewise and square (SVG viewBox or PNG width = height); `logo.appIcon` and
|
|
44
|
+
* `logo.appIconMaskable` PNG only, square, at least {@link THEME_LIMITS}`.appIconMinSize` px and at
|
|
45
|
+
* most {@link THEME_LIMITS}`.appIconBytes`. `files` holds the plugin's files keyed by their path
|
|
46
|
+
* without a leading `./`; the returned `assets` (the sanitized SVG bytes, the other files
|
|
47
|
+
* unchanged) use the same keys. Errors are `<field>: <reason>`, English; the total input size of
|
|
48
|
+
* the theme's distinct assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is
|
|
49
|
+
* per plugin, so a caller reading several themes also checks the sum over all of them (distinct
|
|
50
|
+
* paths).
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateThemeAssets(theme: ParsedTheme, files: Map<string, Uint8Array>): {
|
|
53
|
+
assets: Map<string, Uint8Array>;
|
|
54
|
+
errors: string[];
|
|
55
|
+
};
|