@namzu/sdk 69.0.0 → 69.1.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.
Files changed (303) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/skill-grant.d.ts.map +1 -1
  6. package/dist/authorization/skill-grant.js +1 -0
  7. package/dist/authorization/skill-grant.js.map +1 -1
  8. package/dist/bridge/acp/permission.d.ts +10 -0
  9. package/dist/bridge/acp/permission.d.ts.map +1 -1
  10. package/dist/bridge/acp/permission.js.map +1 -1
  11. package/dist/bridge/acp/server.d.ts.map +1 -1
  12. package/dist/bridge/acp/server.js +1 -0
  13. package/dist/bridge/acp/server.js.map +1 -1
  14. package/dist/connector/index.d.ts +2 -2
  15. package/dist/connector/index.d.ts.map +1 -1
  16. package/dist/connector/index.js +1 -1
  17. package/dist/connector/index.js.map +1 -1
  18. package/dist/connector/mcp/client.d.ts +29 -0
  19. package/dist/connector/mcp/client.d.ts.map +1 -1
  20. package/dist/connector/mcp/client.js +59 -2
  21. package/dist/connector/mcp/client.js.map +1 -1
  22. package/dist/connector/mcp/errors.d.ts +7 -0
  23. package/dist/connector/mcp/errors.d.ts.map +1 -1
  24. package/dist/connector/mcp/errors.js +14 -0
  25. package/dist/connector/mcp/errors.js.map +1 -1
  26. package/dist/connector/mcp/index.d.ts +5 -1
  27. package/dist/connector/mcp/index.d.ts.map +1 -1
  28. package/dist/connector/mcp/index.js +3 -1
  29. package/dist/connector/mcp/index.js.map +1 -1
  30. package/dist/connector/mcp/skill-source.d.ts +144 -0
  31. package/dist/connector/mcp/skill-source.d.ts.map +1 -0
  32. package/dist/connector/mcp/skill-source.js +375 -0
  33. package/dist/connector/mcp/skill-source.js.map +1 -0
  34. package/dist/connector/mcp/skills.d.ts +137 -0
  35. package/dist/connector/mcp/skills.d.ts.map +1 -0
  36. package/dist/connector/mcp/skills.js +303 -0
  37. package/dist/connector/mcp/skills.js.map +1 -0
  38. package/dist/network/audit.d.ts +1 -1
  39. package/dist/network/audit.d.ts.map +1 -1
  40. package/dist/network/audit.js +2 -0
  41. package/dist/network/audit.js.map +1 -1
  42. package/dist/network/computer.d.ts +107 -0
  43. package/dist/network/computer.d.ts.map +1 -0
  44. package/dist/network/computer.js +250 -0
  45. package/dist/network/computer.js.map +1 -0
  46. package/dist/network/index.d.ts +2 -0
  47. package/dist/network/index.d.ts.map +1 -1
  48. package/dist/network/index.js +1 -0
  49. package/dist/network/index.js.map +1 -1
  50. package/dist/network/join.d.ts +3 -1
  51. package/dist/network/join.d.ts.map +1 -1
  52. package/dist/network/join.js +6 -3
  53. package/dist/network/join.js.map +1 -1
  54. package/dist/network/roster.d.ts +5 -0
  55. package/dist/network/roster.d.ts.map +1 -1
  56. package/dist/network/roster.js.map +1 -1
  57. package/dist/network/service.d.ts +12 -2
  58. package/dist/network/service.d.ts.map +1 -1
  59. package/dist/network/service.js +377 -52
  60. package/dist/network/service.js.map +1 -1
  61. package/dist/network/store.d.ts +10 -0
  62. package/dist/network/store.d.ts.map +1 -1
  63. package/dist/network/store.js +25 -3
  64. package/dist/network/store.js.map +1 -1
  65. package/dist/network/wire.d.ts +2 -0
  66. package/dist/network/wire.d.ts.map +1 -1
  67. package/dist/network/wire.js +5 -0
  68. package/dist/network/wire.js.map +1 -1
  69. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  70. package/dist/plugin/shell-hook-tool-names.js +1 -0
  71. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  72. package/dist/plugin/shell-hook.d.ts +8 -3
  73. package/dist/plugin/shell-hook.d.ts.map +1 -1
  74. package/dist/plugin/shell-hook.js +132 -7
  75. package/dist/plugin/shell-hook.js.map +1 -1
  76. package/dist/provider/fallback.d.ts.map +1 -1
  77. package/dist/provider/fallback.js +4 -0
  78. package/dist/provider/fallback.js.map +1 -1
  79. package/dist/provider/idle-timeout.d.ts.map +1 -1
  80. package/dist/provider/idle-timeout.js +3 -0
  81. package/dist/provider/idle-timeout.js.map +1 -1
  82. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  83. package/dist/provider/model-window-suffix.js +1 -0
  84. package/dist/provider/model-window-suffix.js.map +1 -1
  85. package/dist/provider/retry.d.ts.map +1 -1
  86. package/dist/provider/retry.js +3 -0
  87. package/dist/provider/retry.js.map +1 -1
  88. package/dist/public-runtime.d.ts +9 -6
  89. package/dist/public-runtime.d.ts.map +1 -1
  90. package/dist/public-runtime.js +11 -4
  91. package/dist/public-runtime.js.map +1 -1
  92. package/dist/public-tools.d.ts +5 -4
  93. package/dist/public-tools.d.ts.map +1 -1
  94. package/dist/public-tools.js +5 -3
  95. package/dist/public-tools.js.map +1 -1
  96. package/dist/public-types.d.ts +3 -1
  97. package/dist/public-types.d.ts.map +1 -1
  98. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  99. package/dist/runtime/query/executor/tool-call-admission.js +10 -1
  100. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  101. package/dist/runtime/query/executor.d.ts +12 -0
  102. package/dist/runtime/query/executor.d.ts.map +1 -1
  103. package/dist/runtime/query/executor.js +43 -9
  104. package/dist/runtime/query/executor.js.map +1 -1
  105. package/dist/runtime/query/index.d.ts +4 -0
  106. package/dist/runtime/query/index.d.ts.map +1 -1
  107. package/dist/runtime/query/index.js +32 -0
  108. package/dist/runtime/query/index.js.map +1 -1
  109. package/dist/runtime/query/review-policy.d.ts +2 -2
  110. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  111. package/dist/runtime/query/review-policy.js +2 -2
  112. package/dist/runtime/query/review-policy.js.map +1 -1
  113. package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
  114. package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
  115. package/dist/runtime/query/shell-line-escalation.js +38 -0
  116. package/dist/runtime/query/shell-line-escalation.js.map +1 -0
  117. package/dist/runtime/query/tooling.d.ts +7 -0
  118. package/dist/runtime/query/tooling.d.ts.map +1 -1
  119. package/dist/runtime/query/tooling.js +2 -0
  120. package/dist/runtime/query/tooling.js.map +1 -1
  121. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  122. package/dist/runtime/query/turn/outcome-ledger.js +11 -0
  123. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  124. package/dist/scheduler/local.d.ts.map +1 -1
  125. package/dist/scheduler/local.js +3 -1
  126. package/dist/scheduler/local.js.map +1 -1
  127. package/dist/skills/index.d.ts +4 -0
  128. package/dist/skills/index.d.ts.map +1 -1
  129. package/dist/skills/index.js +2 -0
  130. package/dist/skills/index.js.map +1 -1
  131. package/dist/skills/inline-shell-host.d.ts +103 -0
  132. package/dist/skills/inline-shell-host.d.ts.map +1 -0
  133. package/dist/skills/inline-shell-host.js +238 -0
  134. package/dist/skills/inline-shell-host.js.map +1 -0
  135. package/dist/skills/inline-shell.d.ts +176 -0
  136. package/dist/skills/inline-shell.d.ts.map +1 -0
  137. package/dist/skills/inline-shell.js +646 -0
  138. package/dist/skills/inline-shell.js.map +1 -0
  139. package/dist/store/index.d.ts +2 -0
  140. package/dist/store/index.d.ts.map +1 -1
  141. package/dist/store/index.js +1 -0
  142. package/dist/store/index.js.map +1 -1
  143. package/dist/store/task/file.d.ts +124 -0
  144. package/dist/store/task/file.d.ts.map +1 -0
  145. package/dist/store/task/file.js +498 -0
  146. package/dist/store/task/file.js.map +1 -0
  147. package/dist/teams/backend.d.ts +28 -0
  148. package/dist/teams/backend.d.ts.map +1 -0
  149. package/dist/teams/backend.js +2 -0
  150. package/dist/teams/backend.js.map +1 -0
  151. package/dist/teams/fs-sync.d.ts +19 -0
  152. package/dist/teams/fs-sync.d.ts.map +1 -0
  153. package/dist/teams/fs-sync.js +81 -0
  154. package/dist/teams/fs-sync.js.map +1 -0
  155. package/dist/teams/index.d.ts +14 -0
  156. package/dist/teams/index.d.ts.map +1 -0
  157. package/dist/teams/index.js +11 -0
  158. package/dist/teams/index.js.map +1 -0
  159. package/dist/teams/names.d.ts +15 -0
  160. package/dist/teams/names.d.ts.map +1 -0
  161. package/dist/teams/names.js +43 -0
  162. package/dist/teams/names.js.map +1 -0
  163. package/dist/teams/store.d.ts +133 -0
  164. package/dist/teams/store.d.ts.map +1 -0
  165. package/dist/teams/store.js +536 -0
  166. package/dist/teams/store.js.map +1 -0
  167. package/dist/teams/types.d.ts +97 -0
  168. package/dist/teams/types.d.ts.map +1 -0
  169. package/dist/teams/types.js +70 -0
  170. package/dist/teams/types.js.map +1 -0
  171. package/dist/tools/admit-facts.d.ts.map +1 -1
  172. package/dist/tools/admit-facts.js +9 -1
  173. package/dist/tools/admit-facts.js.map +1 -1
  174. package/dist/tools/builtins/computer-use.d.ts +56 -2
  175. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  176. package/dist/tools/builtins/computer-use.js +604 -90
  177. package/dist/tools/builtins/computer-use.js.map +1 -1
  178. package/dist/tools/builtins/index.d.ts +1 -1
  179. package/dist/tools/builtins/index.d.ts.map +1 -1
  180. package/dist/tools/builtins/index.js.map +1 -1
  181. package/dist/tools/builtins/skill.d.ts +31 -0
  182. package/dist/tools/builtins/skill.d.ts.map +1 -1
  183. package/dist/tools/builtins/skill.js +232 -88
  184. package/dist/tools/builtins/skill.js.map +1 -1
  185. package/dist/tools/task/create.d.ts.map +1 -1
  186. package/dist/tools/task/create.js +11 -2
  187. package/dist/tools/task/create.js.map +1 -1
  188. package/dist/tools/task/get.d.ts +8 -0
  189. package/dist/tools/task/get.d.ts.map +1 -0
  190. package/dist/tools/task/get.js +51 -0
  191. package/dist/tools/task/get.js.map +1 -0
  192. package/dist/tools/task/index.d.ts +7 -0
  193. package/dist/tools/task/index.d.ts.map +1 -1
  194. package/dist/tools/task/index.js +10 -2
  195. package/dist/tools/task/index.js.map +1 -1
  196. package/dist/tools/task/list.d.ts.map +1 -1
  197. package/dist/tools/task/list.js +10 -2
  198. package/dist/tools/task/list.js.map +1 -1
  199. package/dist/tools/task/number.d.ts +13 -0
  200. package/dist/tools/task/number.d.ts.map +1 -0
  201. package/dist/tools/task/number.js +30 -0
  202. package/dist/tools/task/number.js.map +1 -0
  203. package/dist/tools/task/present.d.ts.map +1 -1
  204. package/dist/tools/task/present.js +17 -3
  205. package/dist/tools/task/present.js.map +1 -1
  206. package/dist/tools/task/update.d.ts +2 -1
  207. package/dist/tools/task/update.d.ts.map +1 -1
  208. package/dist/tools/task/update.js +86 -19
  209. package/dist/tools/task/update.js.map +1 -1
  210. package/dist/types/acp/index.d.ts +10 -0
  211. package/dist/types/acp/index.d.ts.map +1 -1
  212. package/dist/types/agent/base.d.ts +4 -0
  213. package/dist/types/agent/base.d.ts.map +1 -1
  214. package/dist/types/agent/scheduler.d.ts +9 -0
  215. package/dist/types/agent/scheduler.d.ts.map +1 -1
  216. package/dist/types/computer-use/index.d.ts +7 -0
  217. package/dist/types/computer-use/index.d.ts.map +1 -1
  218. package/dist/types/computer-use/index.js.map +1 -1
  219. package/dist/types/connector/mcp.d.ts +10 -0
  220. package/dist/types/connector/mcp.d.ts.map +1 -1
  221. package/dist/types/permission/index.d.ts +20 -0
  222. package/dist/types/permission/index.d.ts.map +1 -1
  223. package/dist/types/permission/index.js +25 -0
  224. package/dist/types/permission/index.js.map +1 -1
  225. package/dist/types/plugin/index.d.ts +47 -3
  226. package/dist/types/plugin/index.d.ts.map +1 -1
  227. package/dist/types/plugin/index.js +4 -0
  228. package/dist/types/plugin/index.js.map +1 -1
  229. package/dist/types/provider/interface.d.ts +6 -0
  230. package/dist/types/provider/interface.d.ts.map +1 -1
  231. package/dist/types/tool/index.d.ts +28 -2
  232. package/dist/types/tool/index.d.ts.map +1 -1
  233. package/dist/types/tool/index.js.map +1 -1
  234. package/dist/types/tool/presentation.d.ts +4 -0
  235. package/dist/types/tool/presentation.d.ts.map +1 -1
  236. package/package.json +1 -1
  237. package/src/agents/QueryAgent.ts +2 -0
  238. package/src/authorization/skill-grant.ts +1 -0
  239. package/src/bridge/acp/permission.ts +11 -1
  240. package/src/bridge/acp/server.ts +1 -0
  241. package/src/connector/index.ts +27 -0
  242. package/src/connector/mcp/client.ts +71 -2
  243. package/src/connector/mcp/errors.ts +14 -0
  244. package/src/connector/mcp/index.ts +36 -0
  245. package/src/connector/mcp/skill-source.ts +499 -0
  246. package/src/connector/mcp/skills.ts +367 -0
  247. package/src/network/audit.ts +2 -0
  248. package/src/network/computer.ts +347 -0
  249. package/src/network/index.ts +20 -0
  250. package/src/network/join.ts +4 -2
  251. package/src/network/roster.ts +5 -0
  252. package/src/network/service.ts +492 -75
  253. package/src/network/store.ts +29 -3
  254. package/src/network/wire.ts +5 -0
  255. package/src/plugin/shell-hook-tool-names.ts +1 -0
  256. package/src/plugin/shell-hook.ts +144 -7
  257. package/src/provider/fallback.ts +4 -0
  258. package/src/provider/idle-timeout.ts +3 -0
  259. package/src/provider/model-window-suffix.ts +1 -0
  260. package/src/provider/retry.ts +3 -0
  261. package/src/public-runtime.ts +99 -0
  262. package/src/public-tools.ts +9 -0
  263. package/src/public-types.ts +28 -0
  264. package/src/runtime/query/executor/tool-call-admission.ts +10 -1
  265. package/src/runtime/query/executor.ts +57 -8
  266. package/src/runtime/query/index.ts +43 -0
  267. package/src/runtime/query/review-policy.ts +7 -1
  268. package/src/runtime/query/shell-line-escalation.ts +49 -0
  269. package/src/runtime/query/tooling.ts +6 -0
  270. package/src/runtime/query/turn/outcome-ledger.ts +11 -0
  271. package/src/scheduler/local.ts +3 -1
  272. package/src/skills/index.ts +43 -0
  273. package/src/skills/inline-shell-host.ts +303 -0
  274. package/src/skills/inline-shell.ts +765 -0
  275. package/src/store/index.ts +8 -0
  276. package/src/store/task/file.ts +641 -0
  277. package/src/teams/backend.ts +29 -0
  278. package/src/teams/fs-sync.ts +91 -0
  279. package/src/teams/index.ts +47 -0
  280. package/src/teams/names.ts +49 -0
  281. package/src/teams/store.ts +607 -0
  282. package/src/teams/types.ts +102 -0
  283. package/src/tools/admit-facts.ts +9 -1
  284. package/src/tools/builtins/computer-use.ts +689 -95
  285. package/src/tools/builtins/index.ts +1 -0
  286. package/src/tools/builtins/skill.ts +291 -95
  287. package/src/tools/task/create.ts +11 -2
  288. package/src/tools/task/get.ts +53 -0
  289. package/src/tools/task/index.ts +14 -2
  290. package/src/tools/task/list.ts +10 -2
  291. package/src/tools/task/number.ts +32 -0
  292. package/src/tools/task/present.ts +18 -3
  293. package/src/tools/task/update.ts +93 -19
  294. package/src/types/acp/index.ts +11 -1
  295. package/src/types/agent/base.ts +6 -0
  296. package/src/types/agent/scheduler.ts +9 -0
  297. package/src/types/computer-use/index.ts +7 -0
  298. package/src/types/connector/mcp.ts +10 -0
  299. package/src/types/permission/index.ts +29 -0
  300. package/src/types/plugin/index.ts +95 -39
  301. package/src/types/provider/interface.ts +7 -0
  302. package/src/types/tool/index.ts +23 -2
  303. 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
+ }
@@ -36,6 +36,8 @@ export const AUDIT_EVENTS = [
36
36
  'network_off',
37
37
  'machine_renamed',
38
38
  'connection_refused',
39
+ 'same_computer_unavailable',
40
+ 'same_computer_mismatch',
39
41
  ] as const
40
42
  export type AuditEventName = (typeof AUDIT_EVENTS)[number]
41
43