@namzu/sdk 69.0.0 → 69.2.0
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/CHANGELOG.md +68 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +2 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +10 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +1 -0
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +29 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +59 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/errors.d.ts +7 -0
- package/dist/connector/mcp/errors.d.ts.map +1 -1
- package/dist/connector/mcp/errors.js +14 -0
- package/dist/connector/mcp/errors.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +5 -1
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +3 -1
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/skill-source.d.ts +144 -0
- package/dist/connector/mcp/skill-source.d.ts.map +1 -0
- package/dist/connector/mcp/skill-source.js +375 -0
- package/dist/connector/mcp/skill-source.js.map +1 -0
- package/dist/connector/mcp/skills.d.ts +137 -0
- package/dist/connector/mcp/skills.d.ts.map +1 -0
- package/dist/connector/mcp/skills.js +303 -0
- package/dist/connector/mcp/skills.js.map +1 -0
- package/dist/network/audit.d.ts +1 -1
- package/dist/network/audit.d.ts.map +1 -1
- package/dist/network/audit.js +2 -0
- package/dist/network/audit.js.map +1 -1
- package/dist/network/computer.d.ts +107 -0
- package/dist/network/computer.d.ts.map +1 -0
- package/dist/network/computer.js +250 -0
- package/dist/network/computer.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -0
- package/dist/network/index.js.map +1 -1
- package/dist/network/join.d.ts +3 -1
- package/dist/network/join.d.ts.map +1 -1
- package/dist/network/join.js +6 -3
- package/dist/network/join.js.map +1 -1
- package/dist/network/roster.d.ts +5 -0
- package/dist/network/roster.d.ts.map +1 -1
- package/dist/network/roster.js.map +1 -1
- package/dist/network/service.d.ts +12 -2
- package/dist/network/service.d.ts.map +1 -1
- package/dist/network/service.js +377 -52
- package/dist/network/service.js.map +1 -1
- package/dist/network/store.d.ts +10 -0
- package/dist/network/store.d.ts.map +1 -1
- package/dist/network/store.js +25 -3
- package/dist/network/store.js.map +1 -1
- package/dist/network/wire.d.ts +2 -0
- package/dist/network/wire.d.ts.map +1 -1
- package/dist/network/wire.js +5 -0
- package/dist/network/wire.js.map +1 -1
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +7 -1
- package/dist/persona/assembler.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +8 -3
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +132 -7
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +4 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +3 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +1 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +3 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +11 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +7 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +9 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +10 -1
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +12 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +43 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +4 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +32 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +2 -2
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +2 -2
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
- package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
- package/dist/runtime/query/shell-line-escalation.js +38 -0
- package/dist/runtime/query/shell-line-escalation.js.map +1 -0
- package/dist/runtime/query/tooling.d.ts +7 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +2 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +11 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +3 -1
- package/dist/scheduler/local.js.map +1 -1
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +2 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +103 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -0
- package/dist/skills/inline-shell-host.js +238 -0
- package/dist/skills/inline-shell-host.js.map +1 -0
- package/dist/skills/inline-shell.d.ts +176 -0
- package/dist/skills/inline-shell.d.ts.map +1 -0
- package/dist/skills/inline-shell.js +646 -0
- package/dist/skills/inline-shell.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/task/file.d.ts +124 -0
- package/dist/store/task/file.d.ts.map +1 -0
- package/dist/store/task/file.js +498 -0
- package/dist/store/task/file.js.map +1 -0
- package/dist/teams/backend.d.ts +28 -0
- package/dist/teams/backend.d.ts.map +1 -0
- package/dist/teams/backend.js +2 -0
- package/dist/teams/backend.js.map +1 -0
- package/dist/teams/fs-sync.d.ts +19 -0
- package/dist/teams/fs-sync.d.ts.map +1 -0
- package/dist/teams/fs-sync.js +81 -0
- package/dist/teams/fs-sync.js.map +1 -0
- package/dist/teams/index.d.ts +14 -0
- package/dist/teams/index.d.ts.map +1 -0
- package/dist/teams/index.js +11 -0
- package/dist/teams/index.js.map +1 -0
- package/dist/teams/names.d.ts +15 -0
- package/dist/teams/names.d.ts.map +1 -0
- package/dist/teams/names.js +43 -0
- package/dist/teams/names.js.map +1 -0
- package/dist/teams/store.d.ts +133 -0
- package/dist/teams/store.d.ts.map +1 -0
- package/dist/teams/store.js +536 -0
- package/dist/teams/store.js.map +1 -0
- package/dist/teams/types.d.ts +97 -0
- package/dist/teams/types.d.ts.map +1 -0
- package/dist/teams/types.js +70 -0
- package/dist/teams/types.js.map +1 -0
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +9 -1
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/atomic-write-file.d.ts +19 -3
- package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
- package/dist/tools/builtins/atomic-write-file.js +56 -3
- package/dist/tools/builtins/atomic-write-file.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +56 -2
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +604 -90
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +31 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +232 -88
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +11 -2
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/task/get.d.ts +8 -0
- package/dist/tools/task/get.d.ts.map +1 -0
- package/dist/tools/task/get.js +51 -0
- package/dist/tools/task/get.js.map +1 -0
- package/dist/tools/task/index.d.ts +7 -0
- package/dist/tools/task/index.d.ts.map +1 -1
- package/dist/tools/task/index.js +10 -2
- package/dist/tools/task/index.js.map +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js +10 -2
- package/dist/tools/task/list.js.map +1 -1
- package/dist/tools/task/number.d.ts +13 -0
- package/dist/tools/task/number.d.ts.map +1 -0
- package/dist/tools/task/number.js +30 -0
- package/dist/tools/task/number.js.map +1 -0
- package/dist/tools/task/present.d.ts.map +1 -1
- package/dist/tools/task/present.js +17 -3
- package/dist/tools/task/present.js.map +1 -1
- package/dist/tools/task/update.d.ts +2 -1
- package/dist/tools/task/update.d.ts.map +1 -1
- package/dist/tools/task/update.js +86 -19
- package/dist/tools/task/update.js.map +1 -1
- package/dist/types/acp/index.d.ts +10 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/agent/base.d.ts +4 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +9 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +7 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +10 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/permission/index.d.ts +20 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +25 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +47 -3
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +4 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/interface.d.ts +6 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/skills/index.d.ts +7 -0
- package/dist/types/skills/index.d.ts.map +1 -1
- package/dist/types/skills/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +28 -2
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +4 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +2 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/bridge/acp/permission.ts +11 -1
- package/src/bridge/acp/server.ts +1 -0
- package/src/connector/index.ts +27 -0
- package/src/connector/mcp/client.ts +71 -2
- package/src/connector/mcp/errors.ts +14 -0
- package/src/connector/mcp/index.ts +36 -0
- package/src/connector/mcp/skill-source.ts +499 -0
- package/src/connector/mcp/skills.ts +367 -0
- package/src/network/audit.ts +2 -0
- package/src/network/computer.ts +347 -0
- package/src/network/index.ts +20 -0
- package/src/network/join.ts +4 -2
- package/src/network/roster.ts +5 -0
- package/src/network/service.ts +492 -75
- package/src/network/store.ts +29 -3
- package/src/network/wire.ts +5 -0
- package/src/persona/assembler.ts +7 -1
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +144 -7
- package/src/provider/fallback.ts +4 -0
- package/src/provider/idle-timeout.ts +3 -0
- package/src/provider/model-window-suffix.ts +1 -0
- package/src/provider/retry.ts +3 -0
- package/src/public-runtime.ts +99 -0
- package/src/public-tools.ts +15 -0
- package/src/public-types.ts +28 -0
- package/src/runtime/query/executor/tool-call-admission.ts +10 -1
- package/src/runtime/query/executor.ts +57 -8
- package/src/runtime/query/index.ts +43 -0
- package/src/runtime/query/review-policy.ts +7 -1
- package/src/runtime/query/shell-line-escalation.ts +49 -0
- package/src/runtime/query/tooling.ts +6 -0
- package/src/runtime/query/turn/outcome-ledger.ts +11 -0
- package/src/scheduler/local.ts +3 -1
- package/src/skills/index.ts +43 -0
- package/src/skills/inline-shell-host.ts +303 -0
- package/src/skills/inline-shell.ts +765 -0
- package/src/store/index.ts +8 -0
- package/src/store/task/file.ts +641 -0
- package/src/teams/backend.ts +29 -0
- package/src/teams/fs-sync.ts +91 -0
- package/src/teams/index.ts +47 -0
- package/src/teams/names.ts +49 -0
- package/src/teams/store.ts +607 -0
- package/src/teams/types.ts +102 -0
- package/src/tools/admit-facts.ts +9 -1
- package/src/tools/builtins/atomic-write-file.ts +73 -5
- package/src/tools/builtins/computer-use.ts +689 -95
- package/src/tools/builtins/index.ts +1 -0
- package/src/tools/builtins/skill.ts +291 -95
- package/src/tools/task/create.ts +11 -2
- package/src/tools/task/get.ts +53 -0
- package/src/tools/task/index.ts +14 -2
- package/src/tools/task/list.ts +10 -2
- package/src/tools/task/number.ts +32 -0
- package/src/tools/task/present.ts +18 -3
- package/src/tools/task/update.ts +93 -19
- package/src/types/acp/index.ts +11 -1
- package/src/types/agent/base.ts +6 -0
- package/src/types/agent/scheduler.ts +9 -0
- package/src/types/computer-use/index.ts +7 -0
- package/src/types/connector/mcp.ts +10 -0
- package/src/types/permission/index.ts +29 -0
- package/src/types/plugin/index.ts +95 -39
- package/src/types/provider/interface.ts +7 -0
- package/src/types/skills/index.ts +8 -0
- package/src/types/tool/index.ts +23 -2
- package/src/types/tool/presentation.ts +2 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills a server offers, as the wire carries them.
|
|
3
|
+
*
|
|
4
|
+
* A server that declares the `io.modelcontextprotocol/skills` extension
|
|
5
|
+
* answers `skills/list` (paged by `cursor`) with entries naming a
|
|
6
|
+
* `SKILL.md` and, optionally, the files beside it. Everything in an entry is
|
|
7
|
+
* the SERVER's text: this module is the gate every entry passes before
|
|
8
|
+
* anything else reads it. It is pure (no I/O, no clock), so every refusal is
|
|
9
|
+
* a reason code a test can name.
|
|
10
|
+
*
|
|
11
|
+
* Limits are enforced before any body is read, so a hostile listing cannot
|
|
12
|
+
* cost memory or prompt budget beyond the caps below.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The extension's identifier, in both the client's and the server's `extensions`. */
|
|
16
|
+
export const MCP_SKILLS_EXTENSION = 'io.modelcontextprotocol/skills'
|
|
17
|
+
|
|
18
|
+
/** The file every skill is read from, at the end of its entry's `uri`. */
|
|
19
|
+
export const MCP_SKILL_FILE = 'SKILL.md'
|
|
20
|
+
|
|
21
|
+
export const MCP_SKILL_LIMITS = Object.freeze({
|
|
22
|
+
/** Skills kept per server; further valid entries are dropped. */
|
|
23
|
+
maxSkills: 100,
|
|
24
|
+
/** `skills/list` pages read per refresh. */
|
|
25
|
+
maxPages: 20,
|
|
26
|
+
/** Serialized size of everything one server listed, in bytes. */
|
|
27
|
+
maxListingBytes: 512 * 1024,
|
|
28
|
+
/** Files one skill may declare, `SKILL.md` included. */
|
|
29
|
+
maxFiles: 512,
|
|
30
|
+
/** Declared bytes of all of one skill's files. */
|
|
31
|
+
maxTotalBytes: 16 * 1024 * 1024,
|
|
32
|
+
/** Declared bytes of `SKILL.md`. */
|
|
33
|
+
maxSkillMdBytes: 1024 * 1024,
|
|
34
|
+
/** Bytes of one entry's `uri`. */
|
|
35
|
+
maxUriBytes: 2048,
|
|
36
|
+
/** Characters of a skill name. */
|
|
37
|
+
maxNameChars: 64,
|
|
38
|
+
/** Serialized size of one entry's frontmatter, in bytes. */
|
|
39
|
+
maxFrontmatterBytes: 32 * 1024,
|
|
40
|
+
/** Nesting of a frontmatter value. */
|
|
41
|
+
maxFrontmatterDepth: 6,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
/** Why an entry, or a skill name, was not taken. Stable: logged and tested by code. */
|
|
45
|
+
export type McpSkillRefusal =
|
|
46
|
+
| 'invalid_entry'
|
|
47
|
+
| 'unparseable_uri'
|
|
48
|
+
| 'uri_too_long'
|
|
49
|
+
| 'unshowable_uri'
|
|
50
|
+
| 'placeholder_uri'
|
|
51
|
+
| 'invalid_name'
|
|
52
|
+
| 'name_mismatch'
|
|
53
|
+
| 'invalid_frontmatter'
|
|
54
|
+
| 'invalid_manifest'
|
|
55
|
+
| 'too_many_resources'
|
|
56
|
+
| 'too_large'
|
|
57
|
+
| 'skill_md_too_large'
|
|
58
|
+
| 'dynamic_declined'
|
|
59
|
+
| 'duplicate_uri'
|
|
60
|
+
| 'duplicate_name'
|
|
61
|
+
| 'too_many_skills'
|
|
62
|
+
| 'past_list_bytes'
|
|
63
|
+
|
|
64
|
+
export interface McpSkillFile {
|
|
65
|
+
readonly uri: string
|
|
66
|
+
/** `sha256:` and 64 lower-case hex digits. */
|
|
67
|
+
readonly digest: string
|
|
68
|
+
readonly size: number
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** An entry that passed {@link validateMcpSkillEntry}. */
|
|
72
|
+
export interface McpSkillEntry {
|
|
73
|
+
/** The address of `SKILL.md`. */
|
|
74
|
+
readonly uri: string
|
|
75
|
+
/** The address without `/SKILL.md`: what every file of the skill sits under. */
|
|
76
|
+
readonly root: string
|
|
77
|
+
/** The last segment of {@link root}, which the frontmatter `name` equals. */
|
|
78
|
+
readonly name: string
|
|
79
|
+
readonly description: string
|
|
80
|
+
/** The frontmatter as listed: the only copy the body is later compared with. */
|
|
81
|
+
readonly frontmatter: Readonly<Record<string, unknown>>
|
|
82
|
+
/** `SKILL.md`'s listed digest and size. */
|
|
83
|
+
readonly digest: string
|
|
84
|
+
readonly size: number
|
|
85
|
+
readonly files: readonly McpSkillFile[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type McpSkillEntryVerdict =
|
|
89
|
+
| { readonly ok: true; readonly entry: McpSkillEntry }
|
|
90
|
+
| { readonly ok: false; readonly reason: McpSkillRefusal }
|
|
91
|
+
|
|
92
|
+
const NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
93
|
+
/** Characters a qualified skill name may use: path segments of letters, digits, `.`, `_` and `-`. */
|
|
94
|
+
const QUALIFIER_PATTERN = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/
|
|
95
|
+
const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/
|
|
96
|
+
/** Control characters, quotes and angle brackets: text that cannot be shown or quoted safely. */
|
|
97
|
+
const UNSHOWABLE =
|
|
98
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: matching control characters is the point
|
|
99
|
+
/[\u0000-\u001f\u007f-\u009f"'<>\\\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff]/u
|
|
100
|
+
|
|
101
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
102
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function byteLength(text: string): number {
|
|
106
|
+
return new TextEncoder().encode(text).length
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function nesting(value: unknown, depth: number, limit: number): boolean {
|
|
110
|
+
if (depth > limit) return false
|
|
111
|
+
if (Array.isArray(value)) return value.every((item) => nesting(item, depth + 1, limit))
|
|
112
|
+
if (isRecord(value)) return Object.values(value).every((item) => nesting(item, depth + 1, limit))
|
|
113
|
+
return true
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sizeOf(value: unknown): number | undefined {
|
|
117
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Check one `skills/list` entry. Accepts nothing it cannot fully explain.
|
|
122
|
+
*
|
|
123
|
+
* The URI must end in `/SKILL.md`, carry no `$` (placeholders use it), show
|
|
124
|
+
* no characters that cannot be quoted, and survive normalisation unchanged.
|
|
125
|
+
* Its last directory segment is the skill's name and the frontmatter `name`
|
|
126
|
+
* must equal it. The file list must hold `SKILL.md` exactly once and only
|
|
127
|
+
* files under the skill's root; `"dynamic"` is declined because there is no
|
|
128
|
+
* list to check a body against.
|
|
129
|
+
*/
|
|
130
|
+
export function validateMcpSkillEntry(raw: unknown): McpSkillEntryVerdict {
|
|
131
|
+
const refuse = (reason: McpSkillRefusal): McpSkillEntryVerdict => ({ ok: false, reason })
|
|
132
|
+
if (!isRecord(raw)) return refuse('invalid_entry')
|
|
133
|
+
const uri = raw.uri
|
|
134
|
+
if (typeof uri !== 'string' || uri.length === 0) return refuse('invalid_entry')
|
|
135
|
+
if (byteLength(uri) > MCP_SKILL_LIMITS.maxUriBytes) return refuse('uri_too_long')
|
|
136
|
+
if (uri.includes('$')) return refuse('placeholder_uri')
|
|
137
|
+
if (UNSHOWABLE.test(uri) || uri.normalize('NFKC') !== uri) return refuse('unshowable_uri')
|
|
138
|
+
try {
|
|
139
|
+
new URL(uri)
|
|
140
|
+
} catch {
|
|
141
|
+
return refuse('unparseable_uri')
|
|
142
|
+
}
|
|
143
|
+
const suffix = `/${MCP_SKILL_FILE}`
|
|
144
|
+
if (!uri.endsWith(suffix) || uri.length === suffix.length) return refuse('invalid_entry')
|
|
145
|
+
const root = uri.slice(0, -suffix.length)
|
|
146
|
+
const name = root.slice(root.lastIndexOf('/') + 1)
|
|
147
|
+
if (
|
|
148
|
+
name.length === 0 ||
|
|
149
|
+
name.length > MCP_SKILL_LIMITS.maxNameChars ||
|
|
150
|
+
!NAME_PATTERN.test(name)
|
|
151
|
+
) {
|
|
152
|
+
return refuse('invalid_name')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const frontmatter = raw.frontmatter
|
|
156
|
+
if (!isRecord(frontmatter)) return refuse('invalid_frontmatter')
|
|
157
|
+
if (
|
|
158
|
+
byteLength(JSON.stringify(frontmatter)) > MCP_SKILL_LIMITS.maxFrontmatterBytes ||
|
|
159
|
+
!nesting(frontmatter, 0, MCP_SKILL_LIMITS.maxFrontmatterDepth)
|
|
160
|
+
) {
|
|
161
|
+
return refuse('invalid_frontmatter')
|
|
162
|
+
}
|
|
163
|
+
if (typeof frontmatter.name !== 'string' || frontmatter.name.length === 0) {
|
|
164
|
+
return refuse('invalid_frontmatter')
|
|
165
|
+
}
|
|
166
|
+
if (typeof frontmatter.description !== 'string') return refuse('invalid_frontmatter')
|
|
167
|
+
if (frontmatter.name !== name) return refuse('name_mismatch')
|
|
168
|
+
|
|
169
|
+
const resources = raw.resources
|
|
170
|
+
if (resources === 'dynamic') return refuse('dynamic_declined')
|
|
171
|
+
if (!Array.isArray(resources)) return refuse('invalid_manifest')
|
|
172
|
+
if (resources.length > MCP_SKILL_LIMITS.maxFiles) return refuse('too_many_resources')
|
|
173
|
+
const files: McpSkillFile[] = []
|
|
174
|
+
const seen = new Set<string>()
|
|
175
|
+
let total = 0
|
|
176
|
+
let skillMd: McpSkillFile | undefined
|
|
177
|
+
for (const item of resources) {
|
|
178
|
+
if (!isRecord(item)) return refuse('invalid_manifest')
|
|
179
|
+
const { uri: fileUri, digest } = item
|
|
180
|
+
const size = sizeOf(item.size)
|
|
181
|
+
if (typeof fileUri !== 'string' || typeof digest !== 'string' || size === undefined) {
|
|
182
|
+
return refuse('invalid_manifest')
|
|
183
|
+
}
|
|
184
|
+
if (!DIGEST_PATTERN.test(digest)) return refuse('invalid_manifest')
|
|
185
|
+
if (!fileUri.startsWith(`${root}/`) || fileUri.length === root.length + 1) {
|
|
186
|
+
return refuse('invalid_manifest')
|
|
187
|
+
}
|
|
188
|
+
if (
|
|
189
|
+
fileUri
|
|
190
|
+
.slice(root.length + 1)
|
|
191
|
+
.split('/')
|
|
192
|
+
.some((part) => part === '' || part === '..' || part === '.')
|
|
193
|
+
) {
|
|
194
|
+
return refuse('invalid_manifest')
|
|
195
|
+
}
|
|
196
|
+
if (seen.has(fileUri)) return refuse('invalid_manifest')
|
|
197
|
+
seen.add(fileUri)
|
|
198
|
+
total += size
|
|
199
|
+
const file: McpSkillFile = { uri: fileUri, digest, size }
|
|
200
|
+
files.push(file)
|
|
201
|
+
if (fileUri === uri) skillMd = file
|
|
202
|
+
}
|
|
203
|
+
if (!skillMd) return refuse('invalid_manifest')
|
|
204
|
+
if (skillMd.size > MCP_SKILL_LIMITS.maxSkillMdBytes) return refuse('skill_md_too_large')
|
|
205
|
+
if (total > MCP_SKILL_LIMITS.maxTotalBytes) return refuse('too_large')
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
ok: true,
|
|
209
|
+
entry: {
|
|
210
|
+
uri,
|
|
211
|
+
root,
|
|
212
|
+
name,
|
|
213
|
+
description: frontmatter.description,
|
|
214
|
+
frontmatter,
|
|
215
|
+
digest: skillMd.digest,
|
|
216
|
+
size: skillMd.size,
|
|
217
|
+
files,
|
|
218
|
+
},
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface McpSkillAdmission {
|
|
223
|
+
readonly accepted: readonly McpSkillEntry[]
|
|
224
|
+
/** One per entry not taken; `uri` only when the entry had a usable one. */
|
|
225
|
+
readonly refused: readonly { readonly uri?: string; readonly reason: McpSkillRefusal }[]
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Check a whole listing: each entry, then the limits that need the rest.
|
|
230
|
+
*
|
|
231
|
+
* Duplicates (same URI, same name) keep the first. Entries past the listing
|
|
232
|
+
* byte cap or past the skill cap are dropped, in listed order.
|
|
233
|
+
*/
|
|
234
|
+
export function admitMcpSkillEntries(listed: readonly unknown[]): McpSkillAdmission {
|
|
235
|
+
const accepted: McpSkillEntry[] = []
|
|
236
|
+
const refused: { uri?: string; reason: McpSkillRefusal }[] = []
|
|
237
|
+
const uris = new Set<string>()
|
|
238
|
+
let bytes = 0
|
|
239
|
+
for (const raw of listed) {
|
|
240
|
+
const uri = isRecord(raw) && typeof raw.uri === 'string' ? raw.uri.slice(0, 200) : undefined
|
|
241
|
+
const note = (reason: McpSkillRefusal): void => {
|
|
242
|
+
refused.push(uri === undefined ? { reason } : { uri, reason })
|
|
243
|
+
}
|
|
244
|
+
let size: number
|
|
245
|
+
try {
|
|
246
|
+
size = byteLength(JSON.stringify(raw) ?? '')
|
|
247
|
+
} catch {
|
|
248
|
+
note('invalid_entry')
|
|
249
|
+
continue
|
|
250
|
+
}
|
|
251
|
+
bytes += size
|
|
252
|
+
if (bytes > MCP_SKILL_LIMITS.maxListingBytes) {
|
|
253
|
+
note('past_list_bytes')
|
|
254
|
+
continue
|
|
255
|
+
}
|
|
256
|
+
const verdict = validateMcpSkillEntry(raw)
|
|
257
|
+
if (!verdict.ok) {
|
|
258
|
+
note(verdict.reason)
|
|
259
|
+
continue
|
|
260
|
+
}
|
|
261
|
+
if (uris.has(verdict.entry.uri)) {
|
|
262
|
+
note('duplicate_uri')
|
|
263
|
+
continue
|
|
264
|
+
}
|
|
265
|
+
if (accepted.length >= MCP_SKILL_LIMITS.maxSkills) {
|
|
266
|
+
note('too_many_skills')
|
|
267
|
+
continue
|
|
268
|
+
}
|
|
269
|
+
uris.add(verdict.entry.uri)
|
|
270
|
+
accepted.push(verdict.entry)
|
|
271
|
+
}
|
|
272
|
+
return { accepted, refused }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Why a server's name cannot prefix skill names, or `undefined` when it can.
|
|
277
|
+
*
|
|
278
|
+
* The name appears in `server:skill`, in the manifest and in permission
|
|
279
|
+
* rules, so it must not hold what would break those: `$`, `:`, quotes,
|
|
280
|
+
* angle brackets, control or invisible characters, or text that changes
|
|
281
|
+
* under normalisation.
|
|
282
|
+
*/
|
|
283
|
+
export function mcpSkillServerNameProblem(serverName: string): string | undefined {
|
|
284
|
+
if (serverName.length === 0) return 'the server name is empty'
|
|
285
|
+
if (/[$:]/.test(serverName)) return 'the server name holds "$" or ":"'
|
|
286
|
+
if (UNSHOWABLE.test(serverName) || serverName.normalize('NFKC') !== serverName) {
|
|
287
|
+
return 'the server name holds a quote, bracket, control or hidden character'
|
|
288
|
+
}
|
|
289
|
+
return undefined
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** One skill with the name the person and the model see. */
|
|
293
|
+
export interface McpNamedSkill {
|
|
294
|
+
readonly name: string
|
|
295
|
+
readonly entry: McpSkillEntry
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** `where the entry sits`: the path after the authority, and the authority with it. */
|
|
299
|
+
function qualifiers(entry: McpSkillEntry): readonly string[] {
|
|
300
|
+
const rest = entry.root.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '')
|
|
301
|
+
const slash = rest.indexOf('/')
|
|
302
|
+
const authority = slash < 0 ? rest : rest.slice(0, slash)
|
|
303
|
+
const path = slash < 0 ? '' : rest.slice(slash + 1)
|
|
304
|
+
const forms = [
|
|
305
|
+
entry.name,
|
|
306
|
+
...(path ? [path] : []),
|
|
307
|
+
authority && path ? `${authority}/${path}` : rest,
|
|
308
|
+
]
|
|
309
|
+
// A name is typed in a `/` menu and matched by `Skill(...)` rules, so a
|
|
310
|
+
// qualified form keeps to characters neither syntax treats as its own.
|
|
311
|
+
return forms.filter((form) => QUALIFIER_PATTERN.test(form))
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Give each accepted entry its `server:skill` name.
|
|
316
|
+
*
|
|
317
|
+
* The bare name when free; on a duplicate within the server, the directory
|
|
318
|
+
* path, then the authority and path, taking the first not already used. An
|
|
319
|
+
* entry with no free form is refused as `duplicate_name`. A name another
|
|
320
|
+
* source already holds (`taken`: other servers' skills, local skills) is
|
|
321
|
+
* never taken: that entry is refused as `duplicate_name` too, so a server
|
|
322
|
+
* can neither replace nor shadow anything.
|
|
323
|
+
*/
|
|
324
|
+
export function nameMcpSkills(
|
|
325
|
+
serverName: string,
|
|
326
|
+
entries: readonly McpSkillEntry[],
|
|
327
|
+
taken: ReadonlySet<string> = new Set(),
|
|
328
|
+
): {
|
|
329
|
+
readonly named: readonly McpNamedSkill[]
|
|
330
|
+
readonly refused: readonly { readonly uri: string; readonly reason: McpSkillRefusal }[]
|
|
331
|
+
/** Entries that got a qualified form because the bare name was used. */
|
|
332
|
+
readonly qualified: readonly { readonly uri: string; readonly name: string }[]
|
|
333
|
+
} {
|
|
334
|
+
const used = new Set<string>()
|
|
335
|
+
const named: McpNamedSkill[] = []
|
|
336
|
+
const refused: { uri: string; reason: McpSkillRefusal }[] = []
|
|
337
|
+
const qualified: { uri: string; name: string }[] = []
|
|
338
|
+
for (const entry of entries) {
|
|
339
|
+
const forms = qualifiers(entry).map((form) => `${serverName}:${form}`)
|
|
340
|
+
const pick = forms.find((form) => !used.has(form) && !taken.has(form))
|
|
341
|
+
if (pick === undefined) {
|
|
342
|
+
refused.push({ uri: entry.uri, reason: 'duplicate_name' })
|
|
343
|
+
continue
|
|
344
|
+
}
|
|
345
|
+
// A taken bare name is the other source's to keep; do not slip in
|
|
346
|
+
// under a longer spelling of the same skill.
|
|
347
|
+
if (taken.has(forms[0] as string) && !used.has(forms[0] as string)) {
|
|
348
|
+
refused.push({ uri: entry.uri, reason: 'duplicate_name' })
|
|
349
|
+
continue
|
|
350
|
+
}
|
|
351
|
+
used.add(pick)
|
|
352
|
+
named.push({ name: pick, entry })
|
|
353
|
+
if (pick !== forms[0]) qualified.push({ uri: entry.uri, name: pick })
|
|
354
|
+
}
|
|
355
|
+
return { named, refused, qualified }
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The one line that says how many skills were not loaded and why, or `undefined` when all were. */
|
|
359
|
+
export function summarizeMcpSkillRefusals(
|
|
360
|
+
refused: readonly { readonly reason: McpSkillRefusal }[],
|
|
361
|
+
): string | undefined {
|
|
362
|
+
if (refused.length === 0) return undefined
|
|
363
|
+
const counts = new Map<McpSkillRefusal, number>()
|
|
364
|
+
for (const item of refused) counts.set(item.reason, (counts.get(item.reason) ?? 0) + 1)
|
|
365
|
+
const parts = [...counts.entries()].map(([reason, count]) => `${reason} ${count}`)
|
|
366
|
+
return `${refused.length} skill${refused.length === 1 ? '' : 's'} not loaded (${parts.join(', ')})`
|
|
367
|
+
}
|
package/src/network/audit.ts
CHANGED