@stigmer/plugin-package 0.1.0-dev.20261017020314.g644422724c27

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 (273) hide show
  1. package/LICENSE +194 -0
  2. package/README.md +72 -0
  3. package/client/archive.d.ts +27 -0
  4. package/client/archive.d.ts.map +1 -0
  5. package/client/archive.js +38 -0
  6. package/client/archive.js.map +1 -0
  7. package/client/builtin.d.ts +37 -0
  8. package/client/builtin.d.ts.map +1 -0
  9. package/client/builtin.js +49 -0
  10. package/client/builtin.js.map +1 -0
  11. package/client/ignore/defaults.d.ts +2 -0
  12. package/client/ignore/defaults.d.ts.map +1 -0
  13. package/client/ignore/defaults.js +140 -0
  14. package/client/ignore/defaults.js.map +1 -0
  15. package/client/ignore/match.d.ts +3 -0
  16. package/client/ignore/match.d.ts.map +1 -0
  17. package/client/ignore/match.js +166 -0
  18. package/client/ignore/match.js.map +1 -0
  19. package/client/ignore/matcher.d.ts +50 -0
  20. package/client/ignore/matcher.d.ts.map +1 -0
  21. package/client/ignore/matcher.js +116 -0
  22. package/client/ignore/matcher.js.map +1 -0
  23. package/client/ignore/pattern.d.ts +13 -0
  24. package/client/ignore/pattern.d.ts.map +1 -0
  25. package/client/ignore/pattern.js +119 -0
  26. package/client/ignore/pattern.js.map +1 -0
  27. package/client/prepare-eval.d.ts +62 -0
  28. package/client/prepare-eval.d.ts.map +1 -0
  29. package/client/prepare-eval.js +60 -0
  30. package/client/prepare-eval.js.map +1 -0
  31. package/client/prepare.d.ts +99 -0
  32. package/client/prepare.d.ts.map +1 -0
  33. package/client/prepare.js +89 -0
  34. package/client/prepare.js.map +1 -0
  35. package/client/presentation.d.ts +19 -0
  36. package/client/presentation.d.ts.map +1 -0
  37. package/client/presentation.js +44 -0
  38. package/client/presentation.js.map +1 -0
  39. package/client/refs.d.ts +76 -0
  40. package/client/refs.d.ts.map +1 -0
  41. package/client/refs.js +123 -0
  42. package/client/refs.js.map +1 -0
  43. package/client/release.d.ts +20 -0
  44. package/client/release.d.ts.map +1 -0
  45. package/client/release.js +28 -0
  46. package/client/release.js.map +1 -0
  47. package/client/reroot.d.ts +21 -0
  48. package/client/reroot.d.ts.map +1 -0
  49. package/client/reroot.js +37 -0
  50. package/client/reroot.js.map +1 -0
  51. package/client/select.d.ts +74 -0
  52. package/client/select.d.ts.map +1 -0
  53. package/client/select.js +121 -0
  54. package/client/select.js.map +1 -0
  55. package/client/vocabulary.d.ts +13 -0
  56. package/client/vocabulary.d.ts.map +1 -0
  57. package/client/vocabulary.js +17 -0
  58. package/client/vocabulary.js.map +1 -0
  59. package/client.d.ts +51 -0
  60. package/client.d.ts.map +1 -0
  61. package/client.js +51 -0
  62. package/client.js.map +1 -0
  63. package/detect.d.ts +83 -0
  64. package/detect.d.ts.map +1 -0
  65. package/detect.js +210 -0
  66. package/detect.js.map +1 -0
  67. package/dialects/claude.d.ts +34 -0
  68. package/dialects/claude.d.ts.map +1 -0
  69. package/dialects/claude.js +84 -0
  70. package/dialects/claude.js.map +1 -0
  71. package/dialects/codex.d.ts +20 -0
  72. package/dialects/codex.d.ts.map +1 -0
  73. package/dialects/codex.js +21 -0
  74. package/dialects/codex.js.map +1 -0
  75. package/dialects/cursor.d.ts +25 -0
  76. package/dialects/cursor.d.ts.map +1 -0
  77. package/dialects/cursor.js +66 -0
  78. package/dialects/cursor.js.map +1 -0
  79. package/dialects/manifest.d.ts +164 -0
  80. package/dialects/manifest.d.ts.map +1 -0
  81. package/dialects/manifest.js +256 -0
  82. package/dialects/manifest.js.map +1 -0
  83. package/dialects/open.d.ts +19 -0
  84. package/dialects/open.d.ts.map +1 -0
  85. package/dialects/open.js +49 -0
  86. package/dialects/open.js.map +1 -0
  87. package/documents.d.ts +58 -0
  88. package/documents.d.ts.map +1 -0
  89. package/documents.js +121 -0
  90. package/documents.js.map +1 -0
  91. package/evals/eval-dir.d.ts +59 -0
  92. package/evals/eval-dir.d.ts.map +1 -0
  93. package/evals/eval-dir.js +84 -0
  94. package/evals/eval-dir.js.map +1 -0
  95. package/evals/fields.d.ts +78 -0
  96. package/evals/fields.d.ts.map +1 -0
  97. package/evals/fields.js +156 -0
  98. package/evals/fields.js.map +1 -0
  99. package/evals/glob.d.ts +40 -0
  100. package/evals/glob.d.ts.map +1 -0
  101. package/evals/glob.js +146 -0
  102. package/evals/glob.js.map +1 -0
  103. package/evals/graders.d.ts +52 -0
  104. package/evals/graders.d.ts.map +1 -0
  105. package/evals/graders.js +279 -0
  106. package/evals/graders.js.map +1 -0
  107. package/evals/markdown.d.ts +24 -0
  108. package/evals/markdown.d.ts.map +1 -0
  109. package/evals/markdown.js +48 -0
  110. package/evals/markdown.js.map +1 -0
  111. package/evals/mocks.d.ts +50 -0
  112. package/evals/mocks.d.ts.map +1 -0
  113. package/evals/mocks.js +182 -0
  114. package/evals/mocks.js.map +1 -0
  115. package/evals/read-eval-suite.d.ts +110 -0
  116. package/evals/read-eval-suite.d.ts.map +1 -0
  117. package/evals/read-eval-suite.js +603 -0
  118. package/evals/read-eval-suite.js.map +1 -0
  119. package/evals/summary.d.ts +61 -0
  120. package/evals/summary.d.ts.map +1 -0
  121. package/evals/summary.js +69 -0
  122. package/evals/summary.js.map +1 -0
  123. package/evals/types.d.ts +203 -0
  124. package/evals/types.d.ts.map +1 -0
  125. package/evals/types.js +21 -0
  126. package/evals/types.js.map +1 -0
  127. package/files.d.ts +135 -0
  128. package/files.d.ts.map +1 -0
  129. package/files.js +209 -0
  130. package/files.js.map +1 -0
  131. package/frontmatter.d.ts +51 -0
  132. package/frontmatter.d.ts.map +1 -0
  133. package/frontmatter.js +61 -0
  134. package/frontmatter.js.map +1 -0
  135. package/index.d.ts +37 -0
  136. package/index.d.ts.map +1 -0
  137. package/index.js +33 -0
  138. package/index.js.map +1 -0
  139. package/marketplace/messages.d.ts +20 -0
  140. package/marketplace/messages.d.ts.map +1 -0
  141. package/marketplace/messages.js +49 -0
  142. package/marketplace/messages.js.map +1 -0
  143. package/marketplace/outcome.d.ts +70 -0
  144. package/marketplace/outcome.d.ts.map +1 -0
  145. package/marketplace/outcome.js +29 -0
  146. package/marketplace/outcome.js.map +1 -0
  147. package/marketplace/read-marketplace.d.ts +52 -0
  148. package/marketplace/read-marketplace.d.ts.map +1 -0
  149. package/marketplace/read-marketplace.js +351 -0
  150. package/marketplace/read-marketplace.js.map +1 -0
  151. package/messages.d.ts +55 -0
  152. package/messages.d.ts.map +1 -0
  153. package/messages.js +167 -0
  154. package/messages.js.map +1 -0
  155. package/normalise/hooks.d.ts +91 -0
  156. package/normalise/hooks.d.ts.map +1 -0
  157. package/normalise/hooks.js +437 -0
  158. package/normalise/hooks.js.map +1 -0
  159. package/normalise/ignored.d.ts +34 -0
  160. package/normalise/ignored.d.ts.map +1 -0
  161. package/normalise/ignored.js +78 -0
  162. package/normalise/ignored.js.map +1 -0
  163. package/normalise/mcp-servers.d.ts +50 -0
  164. package/normalise/mcp-servers.d.ts.map +1 -0
  165. package/normalise/mcp-servers.js +398 -0
  166. package/normalise/mcp-servers.js.map +1 -0
  167. package/normalise/settings.d.ts +32 -0
  168. package/normalise/settings.d.ts.map +1 -0
  169. package/normalise/settings.js +72 -0
  170. package/normalise/settings.js.map +1 -0
  171. package/normalise/skills.d.ts +39 -0
  172. package/normalise/skills.d.ts.map +1 -0
  173. package/normalise/skills.js +135 -0
  174. package/normalise/skills.js.map +1 -0
  175. package/normalise/stigmer-folder.d.ts +17 -0
  176. package/normalise/stigmer-folder.d.ts.map +1 -0
  177. package/normalise/stigmer-folder.js +19 -0
  178. package/normalise/stigmer-folder.js.map +1 -0
  179. package/normalise/sub-agents.d.ts +54 -0
  180. package/normalise/sub-agents.d.ts.map +1 -0
  181. package/normalise/sub-agents.js +219 -0
  182. package/normalise/sub-agents.js.map +1 -0
  183. package/normalise/variables.d.ts +31 -0
  184. package/normalise/variables.d.ts.map +1 -0
  185. package/normalise/variables.js +170 -0
  186. package/normalise/variables.js.map +1 -0
  187. package/outcome.d.ts +59 -0
  188. package/outcome.d.ts.map +1 -0
  189. package/outcome.js +32 -0
  190. package/outcome.js.map +1 -0
  191. package/package.json +47 -0
  192. package/placeholders.d.ts +65 -0
  193. package/placeholders.d.ts.map +1 -0
  194. package/placeholders.js +99 -0
  195. package/placeholders.js.map +1 -0
  196. package/presentation.d.ts +53 -0
  197. package/presentation.d.ts.map +1 -0
  198. package/presentation.js +156 -0
  199. package/presentation.js.map +1 -0
  200. package/read-plugin-package.d.ts +20 -0
  201. package/read-plugin-package.d.ts.map +1 -0
  202. package/read-plugin-package.js +73 -0
  203. package/read-plugin-package.js.map +1 -0
  204. package/src/client/archive.ts +44 -0
  205. package/src/client/builtin.ts +60 -0
  206. package/src/client/ignore/defaults.ts +155 -0
  207. package/src/client/ignore/match.ts +158 -0
  208. package/src/client/ignore/matcher.ts +156 -0
  209. package/src/client/ignore/pattern.ts +132 -0
  210. package/src/client/prepare-eval.ts +92 -0
  211. package/src/client/prepare.ts +160 -0
  212. package/src/client/presentation.ts +47 -0
  213. package/src/client/refs.ts +170 -0
  214. package/src/client/release.ts +29 -0
  215. package/src/client/reroot.ts +35 -0
  216. package/src/client/select.ts +161 -0
  217. package/src/client/vocabulary.ts +19 -0
  218. package/src/client.ts +102 -0
  219. package/src/detect.ts +245 -0
  220. package/src/dialects/claude.ts +102 -0
  221. package/src/dialects/codex.ts +26 -0
  222. package/src/dialects/cursor.ts +77 -0
  223. package/src/dialects/manifest.ts +316 -0
  224. package/src/dialects/open.ts +50 -0
  225. package/src/documents.ts +158 -0
  226. package/src/evals/eval-dir.ts +101 -0
  227. package/src/evals/fields.ts +184 -0
  228. package/src/evals/glob.ts +141 -0
  229. package/src/evals/graders.ts +293 -0
  230. package/src/evals/markdown.ts +56 -0
  231. package/src/evals/mocks.ts +202 -0
  232. package/src/evals/read-eval-suite.ts +713 -0
  233. package/src/evals/summary.ts +100 -0
  234. package/src/evals/types.ts +217 -0
  235. package/src/files.ts +235 -0
  236. package/src/frontmatter.ts +70 -0
  237. package/src/index.ts +129 -0
  238. package/src/marketplace/messages.ts +61 -0
  239. package/src/marketplace/outcome.ts +91 -0
  240. package/src/marketplace/read-marketplace.ts +388 -0
  241. package/src/messages.ts +248 -0
  242. package/src/normalise/hooks.ts +469 -0
  243. package/src/normalise/ignored.ts +79 -0
  244. package/src/normalise/mcp-servers.ts +423 -0
  245. package/src/normalise/settings.ts +81 -0
  246. package/src/normalise/skills.ts +145 -0
  247. package/src/normalise/stigmer-folder.ts +23 -0
  248. package/src/normalise/sub-agents.ts +231 -0
  249. package/src/normalise/variables.ts +181 -0
  250. package/src/outcome.ts +158 -0
  251. package/src/placeholders.ts +110 -0
  252. package/src/presentation.ts +170 -0
  253. package/src/read-plugin-package.ts +80 -0
  254. package/src/testing.ts +347 -0
  255. package/src/tool-names.ts +30 -0
  256. package/src/trim.ts +10 -0
  257. package/src/types.ts +214 -0
  258. package/testing.d.ts +127 -0
  259. package/testing.d.ts.map +1 -0
  260. package/testing.js +266 -0
  261. package/testing.js.map +1 -0
  262. package/tool-names.d.ts +21 -0
  263. package/tool-names.d.ts.map +1 -0
  264. package/tool-names.js +28 -0
  265. package/tool-names.js.map +1 -0
  266. package/trim.d.ts +7 -0
  267. package/trim.d.ts.map +1 -0
  268. package/trim.js +12 -0
  269. package/trim.js.map +1 -0
  270. package/types.d.ts +179 -0
  271. package/types.d.ts.map +1 -0
  272. package/types.js +19 -0
  273. package/types.js.map +1 -0
@@ -0,0 +1,423 @@
1
+ /**
2
+ * MCP server entries, from every configuration source, into the two shapes
3
+ * `McpServerSpec` takes.
4
+ *
5
+ * The open format and the vendor dialects differ on strictness and the
6
+ * source's dialect decides: an open `mcp.json` requires `type` and closes
7
+ * each transport's field set (an unknown field refuses the entry), while a
8
+ * vendor `.mcp.json` infers the transport from `command` or `url` and
9
+ * carries fields Stigmer does not read as warnings (Cursor's undocumented
10
+ * `auth` block has its own, because on Stigmer a person signs in to a
11
+ * server at its address). `streamable-http` and `http` are one transport;
12
+ * the legacy `sse` maps to it with a warning, because the runner connects
13
+ * both with Streamable HTTP and its adapter falls back to SSE when the
14
+ * server rejects that.
15
+ *
16
+ * Four refusals are facts about the runner, not preferences: it mounts no
17
+ * plugin files (so a `./`-relative command, any plugin-root placeholder,
18
+ * and any `cwd` can never resolve); it sends a server's `url` as written
19
+ * (so a `${VAR}` there would be sent literally); and it hands a stdio
20
+ * subprocess exactly the variables the spec declares, by name (so an `env`
21
+ * entry is representable only as `KEY: "${KEY}"`).
22
+ *
23
+ * Every `${VAR}` in a header, an argument, an `env` value or an `auth` value
24
+ * is a reference to a value the run's vaults hold, listed on the server's `env`;
25
+ * the variables module declares the undeclared ones. Claude's
26
+ * `${user_config.KEY}` is rewritten to `${KEY}` before anything is scanned.
27
+ */
28
+
29
+ import type { McpConfigSource } from "../dialects/manifest.js";
30
+ import {
31
+ describeValue,
32
+ fields,
33
+ isJsonObject,
34
+ isStringArray,
35
+ isStringRecord,
36
+ type JsonObject,
37
+ parseJsonObject,
38
+ readText,
39
+ } from "../documents.js";
40
+ import type { PluginFileIndex } from "../files.js";
41
+ import { AGENT_PLUGINS_MCP_SCHEMA, type Findings } from "../messages.js";
42
+ import {
43
+ findPluginRootPlaceholder,
44
+ PLUGIN_ROOT_ENV_NAMES,
45
+ referencedVariables,
46
+ rewriteUserConfig,
47
+ singlePlaceholderName,
48
+ VARIABLE_NAME_PATTERN,
49
+ } from "../placeholders.js";
50
+ import type { PluginMcpServer } from "../types.js";
51
+
52
+ const OPEN_CONFIG_FIELDS: ReadonlySet<string> = new Set(["$schema", "mcpServers"]);
53
+ const OPEN_STDIO_FIELDS: ReadonlySet<string> = new Set(["type", "command", "args", "env", "cwd"]);
54
+ const OPEN_HTTP_FIELDS: ReadonlySet<string> = new Set(["type", "url", "headers"]);
55
+ const VENDOR_STDIO_FIELDS: ReadonlySet<string> = new Set(["type", "command", "args", "env", "cwd"]);
56
+ const VENDOR_HTTP_FIELDS: ReadonlySet<string> = new Set(["type", "url", "headers"]);
57
+
58
+ // RFC 9110 token characters, the set a header field name may use.
59
+ const HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
60
+
61
+ type Transport = "stdio" | "http";
62
+
63
+ export interface McpServersResult {
64
+ readonly servers: readonly PluginMcpServer[];
65
+ /**
66
+ * How many entries were refused. The variables stage reads it: a refused
67
+ * server's references are unknown, so "declared but unreferenced" would be
68
+ * a consequence of the refusal rather than advice, and is not warned.
69
+ */
70
+ readonly refused: number;
71
+ }
72
+
73
+ export function normaliseMcpServers(index: PluginFileIndex, sources: readonly McpConfigSource[], findings: Findings): McpServersResult {
74
+ const servers: PluginMcpServer[] = [];
75
+ const seen = new Set<string>();
76
+ let refused = 0;
77
+ for (const source of sources) {
78
+ const entries = readSource(index, source, findings);
79
+ if (entries === undefined) {
80
+ refused++;
81
+ continue;
82
+ }
83
+ for (const [name, raw] of fields(entries.servers)) {
84
+ if (seen.has(name)) {
85
+ findings.error("mcp-server-name-duplicate", { subject: name, path: entries.path });
86
+ refused++;
87
+ continue;
88
+ }
89
+ seen.add(name);
90
+ const server = readServer(name, raw, entries.path, source.dialect === "agent-plugins", findings);
91
+ if (server !== undefined) servers.push(server);
92
+ else refused++;
93
+ }
94
+ }
95
+ return { servers, refused };
96
+ }
97
+
98
+ interface ServerEntries {
99
+ readonly path: string;
100
+ readonly servers: JsonObject;
101
+ }
102
+
103
+ function readSource(index: PluginFileIndex, source: McpConfigSource, findings: Findings): ServerEntries | undefined {
104
+ const open = source.dialect === "agent-plugins";
105
+ if (source.kind === "inline") {
106
+ // An inline value is either the whole configuration shape or the
107
+ // server map itself; both are seen in the wild and both mean one thing.
108
+ const wrapped = isJsonObject(source.servers) ? source.servers["mcpServers"] : undefined;
109
+ const servers = isJsonObject(wrapped) ? wrapped : source.servers;
110
+ if (!isJsonObject(servers)) {
111
+ findings.error("mcp-config-shape", { path: source.manifest });
112
+ return undefined;
113
+ }
114
+ return { path: source.manifest, servers };
115
+ }
116
+
117
+ if (!index.has(source.path)) {
118
+ findings.warn("path-missing", { path: source.manifest, subject: `./${source.path}` });
119
+ return undefined;
120
+ }
121
+ const text = readText(index, source.path, "mcpConfig", findings);
122
+ if (text === undefined) return undefined;
123
+ const object = parseJsonObject(text, source.path, "mcp-config-unreadable", findings);
124
+ if (object === undefined) return undefined;
125
+
126
+ if (open) {
127
+ const schema = object["$schema"];
128
+ if (schema === undefined) {
129
+ findings.error("mcp-config-schema-missing", { path: source.path });
130
+ } else if (schema !== AGENT_PLUGINS_MCP_SCHEMA) {
131
+ findings.error("mcp-config-schema-unsupported", { path: source.path, detail: describeValue(schema) });
132
+ }
133
+ }
134
+ for (const [name] of fields(object)) {
135
+ if (OPEN_CONFIG_FIELDS.has(name)) continue;
136
+ if (open) findings.error("mcp-config-field-unknown", { path: source.path, subject: name });
137
+ else findings.warn("mcp-config-field-ignored", { path: source.path, subject: name });
138
+ }
139
+ const servers = object["mcpServers"];
140
+ if (!isJsonObject(servers)) {
141
+ findings.error("mcp-config-shape", { path: source.path });
142
+ return undefined;
143
+ }
144
+ return { path: source.path, servers };
145
+ }
146
+
147
+ function readServer(name: string, raw: unknown, path: string, open: boolean, findings: Findings): PluginMcpServer | undefined {
148
+ const ctx = { subject: name, path };
149
+ if (!isJsonObject(raw)) {
150
+ findings.error("mcp-server-shape", ctx);
151
+ return undefined;
152
+ }
153
+ const transport = resolveTransport(raw, ctx, open, findings);
154
+ if (transport === undefined) return undefined;
155
+
156
+ const known = transport === "stdio" ? (open ? OPEN_STDIO_FIELDS : VENDOR_STDIO_FIELDS) : open ? OPEN_HTTP_FIELDS : VENDOR_HTTP_FIELDS;
157
+ const references = new Set<string>();
158
+ let valid = true;
159
+ for (const [field, value] of fields(raw)) {
160
+ if (known.has(field)) continue;
161
+ if (open) {
162
+ findings.error("mcp-server-field-unknown", { ...ctx, detail: field });
163
+ valid = false;
164
+ } else if (field === "auth") {
165
+ findings.warn("mcp-server-auth-ignored", ctx);
166
+ for (const text of stringsWithin(value)) collectReferences(text, references);
167
+ } else {
168
+ findings.warn("mcp-server-field-ignored", { ...ctx, detail: field });
169
+ }
170
+ }
171
+ if (!valid) return undefined;
172
+
173
+ return transport === "stdio" ? readStdio(name, raw, ctx, references, findings) : readHttp(name, raw, ctx, references, findings);
174
+ }
175
+
176
+ interface Ctx {
177
+ readonly subject: string;
178
+ readonly path: string;
179
+ }
180
+
181
+ function resolveTransport(raw: JsonObject, ctx: Ctx, open: boolean, findings: Findings): Transport | undefined {
182
+ const type = raw["type"];
183
+ if (type !== undefined && typeof type !== "string") {
184
+ findings.error("mcp-server-field-type", { ...ctx, detail: "type" });
185
+ return undefined;
186
+ }
187
+ if (type === undefined) {
188
+ if (open) {
189
+ findings.error("mcp-server-type-missing", ctx);
190
+ return undefined;
191
+ }
192
+ const hasCommand = raw["command"] !== undefined;
193
+ const hasUrl = raw["url"] !== undefined;
194
+ if (hasCommand && hasUrl) {
195
+ findings.error("mcp-server-type-ambiguous", ctx);
196
+ return undefined;
197
+ }
198
+ if (hasCommand) return "stdio";
199
+ if (hasUrl) return "http";
200
+ findings.error("mcp-server-transport-unknown", ctx);
201
+ return undefined;
202
+ }
203
+ switch (type) {
204
+ case "stdio":
205
+ return "stdio";
206
+ case "streamable-http":
207
+ return "http";
208
+ case "http":
209
+ if (open) {
210
+ findings.error("mcp-server-type-unknown", { ...ctx, detail: type });
211
+ return undefined;
212
+ }
213
+ return "http";
214
+ case "sse":
215
+ findings.warn("mcp-server-sse-mapped", ctx);
216
+ return "http";
217
+ default:
218
+ findings.error("mcp-server-type-unknown", { ...ctx, detail: type });
219
+ return undefined;
220
+ }
221
+ }
222
+
223
+ function readStdio(name: string, raw: JsonObject, ctx: Ctx, references: Set<string>, findings: Findings): PluginMcpServer | undefined {
224
+ let valid = true;
225
+ const fail = (): void => {
226
+ valid = false;
227
+ };
228
+
229
+ const command = raw["command"];
230
+ if (command === undefined) {
231
+ findings.error("mcp-server-command-missing", ctx);
232
+ fail();
233
+ } else if (typeof command !== "string") {
234
+ findings.error("mcp-server-field-type", { ...ctx, detail: "command" });
235
+ fail();
236
+ } else {
237
+ const root = findPluginRootPlaceholder(command);
238
+ if (root !== undefined) {
239
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: root });
240
+ fail();
241
+ } else if (command.startsWith("./")) {
242
+ findings.error("mcp-server-command-relative", { ...ctx, detail: command });
243
+ fail();
244
+ } else if (command === "" || /\s/.test(command) || command.includes("/")) {
245
+ findings.error("mcp-server-command-invalid", ctx);
246
+ fail();
247
+ }
248
+ }
249
+
250
+ const args: string[] = [];
251
+ const rawArgs = raw["args"];
252
+ if (rawArgs !== undefined) {
253
+ if (!isStringArray(rawArgs)) {
254
+ findings.error("mcp-server-field-type", { ...ctx, detail: "args" });
255
+ fail();
256
+ } else {
257
+ for (const arg of rawArgs) {
258
+ const rewritten = rewriteUserConfig(arg);
259
+ const root = findPluginRootPlaceholder(rewritten);
260
+ if (root !== undefined) {
261
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: root });
262
+ fail();
263
+ continue;
264
+ }
265
+ collectReferences(rewritten, references);
266
+ args.push(rewritten);
267
+ }
268
+ }
269
+ }
270
+
271
+ const rawEnv = raw["env"];
272
+ if (rawEnv !== undefined) {
273
+ if (!isStringRecord(rawEnv)) {
274
+ findings.error("mcp-server-field-type", { ...ctx, detail: "env" });
275
+ fail();
276
+ } else {
277
+ for (const [key, value] of Object.entries(rawEnv)) {
278
+ if (PLUGIN_ROOT_ENV_NAMES.has(key)) {
279
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: key });
280
+ fail();
281
+ continue;
282
+ }
283
+ if (!VARIABLE_NAME_PATTERN.test(key)) {
284
+ findings.error("variable-name-invalid", { subject: key, path: ctx.path });
285
+ fail();
286
+ continue;
287
+ }
288
+ const rewritten = rewriteUserConfig(value);
289
+ const root = findPluginRootPlaceholder(rewritten);
290
+ if (root !== undefined) {
291
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: root });
292
+ fail();
293
+ continue;
294
+ }
295
+ const referenced = singlePlaceholderName(rewritten);
296
+ if (referenced === undefined) {
297
+ findings.error("mcp-server-env-literal", { ...ctx, detail: key });
298
+ fail();
299
+ } else if (referenced !== key) {
300
+ findings.error("mcp-server-env-rename", { ...ctx, detail: key });
301
+ fail();
302
+ } else {
303
+ references.add(key);
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ if (raw["cwd"] !== undefined) {
310
+ findings.error("mcp-server-cwd-unsupported", ctx);
311
+ fail();
312
+ }
313
+
314
+ if (!valid || typeof command !== "string") return undefined;
315
+ return { name, transport: "stdio", command, args, env: [...references].sort() };
316
+ }
317
+
318
+ function readHttp(name: string, raw: JsonObject, ctx: Ctx, references: Set<string>, findings: Findings): PluginMcpServer | undefined {
319
+ let valid = true;
320
+ const fail = (): void => {
321
+ valid = false;
322
+ };
323
+
324
+ let url: string | undefined;
325
+ const rawUrl = raw["url"];
326
+ if (rawUrl === undefined) {
327
+ findings.error("mcp-server-url-missing", ctx);
328
+ fail();
329
+ } else if (typeof rawUrl !== "string") {
330
+ findings.error("mcp-server-field-type", { ...ctx, detail: "url" });
331
+ fail();
332
+ } else {
333
+ url = rewriteUserConfig(rawUrl);
334
+ const root = findPluginRootPlaceholder(url);
335
+ if (root !== undefined) {
336
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: root });
337
+ fail();
338
+ } else if (referencedVariables(url).length > 0) {
339
+ findings.error("mcp-server-url-variable", ctx);
340
+ fail();
341
+ } else if (!isAcceptableServerUrl(url)) {
342
+ findings.error("mcp-server-url-invalid", { ...ctx, detail: url });
343
+ fail();
344
+ }
345
+ }
346
+
347
+ // Collected as pairs and materialised with `Object.fromEntries`, which
348
+ // defines own properties: a header literally named `__proto__` (a valid
349
+ // token) must become a key, never a prototype assignment.
350
+ const headers: [string, string][] = [];
351
+ const rawHeaders = raw["headers"];
352
+ if (rawHeaders !== undefined) {
353
+ if (!isStringRecord(rawHeaders)) {
354
+ findings.error("mcp-server-field-type", { ...ctx, detail: "headers" });
355
+ fail();
356
+ } else {
357
+ const lowered = new Set<string>();
358
+ for (const [header, value] of Object.entries(rawHeaders)) {
359
+ if (!HEADER_NAME_PATTERN.test(header)) {
360
+ findings.error("mcp-server-header-invalid", { ...ctx, detail: header });
361
+ fail();
362
+ continue;
363
+ }
364
+ const key = header.toLowerCase();
365
+ if (lowered.has(key)) {
366
+ findings.error("mcp-server-header-duplicate", { ...ctx, detail: header });
367
+ fail();
368
+ continue;
369
+ }
370
+ lowered.add(key);
371
+ const rewritten = rewriteUserConfig(value);
372
+ const root = findPluginRootPlaceholder(rewritten);
373
+ if (root !== undefined) {
374
+ findings.error("mcp-server-plugin-root-reference", { ...ctx, detail: root });
375
+ fail();
376
+ continue;
377
+ }
378
+ collectReferences(rewritten, references);
379
+ headers.push([header, rewritten]);
380
+ }
381
+ }
382
+ }
383
+
384
+ if (!valid || url === undefined) return undefined;
385
+ return { name, transport: "http", url, headers: Object.fromEntries(headers), env: [...references].sort() };
386
+ }
387
+
388
+ /**
389
+ * The open format's URL rule: absolute HTTP(S), no user information, no
390
+ * fragment, HTTPS unless the host is loopback. Applied in every dialect
391
+ * because the runner's `HttpServerConfig.url` must be a URI and a plugin
392
+ * that fails here would fail there. Exported for the server, which holds a
393
+ * server written in an agent to the same rule.
394
+ */
395
+ export function isAcceptableServerUrl(value: string): boolean {
396
+ let url: URL;
397
+ try {
398
+ url = new URL(value);
399
+ } catch {
400
+ return false;
401
+ }
402
+ if (url.username !== "" || url.password !== "" || url.hash !== "") return false;
403
+ if (url.protocol === "https:") return true;
404
+ if (url.protocol !== "http:") return false;
405
+ return isLoopbackHost(url.hostname);
406
+ }
407
+
408
+ function isLoopbackHost(hostname: string): boolean {
409
+ if (hostname === "localhost" || hostname === "[::1]" || hostname === "::1") return true;
410
+ return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname);
411
+ }
412
+
413
+ function collectReferences(text: string, into: Set<string>): void {
414
+ for (const name of referencedVariables(text)) into.add(name);
415
+ }
416
+
417
+ /** Every string nested anywhere in a JSON value (the `auth` block's values). */
418
+ function stringsWithin(value: unknown): readonly string[] {
419
+ if (typeof value === "string") return [rewriteUserConfig(value)];
420
+ if (Array.isArray(value)) return value.flatMap(stringsWithin);
421
+ if (isJsonObject(value)) return Object.values(value).flatMap(stringsWithin);
422
+ return [];
423
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A Claude plugin's settings: which of its agents runs the session's main
3
+ * thread.
4
+ *
5
+ * Claude Code reads a plugin's `settings.json` at the plugin root and the
6
+ * same object inline under the manifest's `settings`, the file winning for
7
+ * a key it sets. Two keys take effect there and every other is dropped:
8
+ * `agent`, which runs the main thread as one of the plugin's agents (its
9
+ * prompt, tool lists and model apply to the whole session), and
10
+ * `subagentStatusLine`, a terminal display Stigmer has no counterpart for.
11
+ * So `agent` is read and every other key is named as not applied
12
+ * (`settings-key-ignored`).
13
+ *
14
+ * `agent` must name one of the plugin's own agents, by its bare name or
15
+ * scoped as `<plugin>:<agent>`; anything else is warned and ignored
16
+ * (`settings-agent-unknown`), since a main agent that is not there names
17
+ * nothing a conversation could run. Only a Claude
18
+ * manifest makes these settings meaningful; without one, `settings.json`
19
+ * stays an ignored component. A `settings.json` that is not a JSON object
20
+ * refuses the plugin, as a broken hooks file does.
21
+ */
22
+
23
+ import { describeValue, fields, isJsonObject, type JsonObject, parseJsonObject, readText } from "../documents.js";
24
+ import type { ManifestSet } from "../detect.js";
25
+ import type { PluginFileIndex } from "../files.js";
26
+ import type { Findings } from "../messages.js";
27
+ import type { PluginSubAgent } from "../types.js";
28
+
29
+ /** The plugin settings file Claude Code reads. */
30
+ export const SETTINGS_FILE = "settings.json";
31
+
32
+ /** True when the package has a Claude manifest, so its settings are read rather than ignored. */
33
+ export function readsSettings(set: ManifestSet): boolean {
34
+ return set.manifests.some((manifest) => manifest.dialect === "claude");
35
+ }
36
+
37
+ /** The main agent's name, or `undefined` when the settings name none (or none that exists). */
38
+ export function normaliseMainAgent(
39
+ index: PluginFileIndex,
40
+ set: ManifestSet,
41
+ subAgents: readonly PluginSubAgent[],
42
+ findings: Findings,
43
+ ): string | undefined {
44
+ const claude = set.manifests.find((manifest) => manifest.dialect === "claude");
45
+ if (claude === undefined) return undefined;
46
+
47
+ const layers: { readonly path: string; readonly object: JsonObject }[] = [];
48
+ if (claude.settings !== undefined) {
49
+ if (!isJsonObject(claude.settings)) {
50
+ findings.error("manifest-field-type", { path: claude.path, subject: "settings", detail: "an object" });
51
+ return undefined;
52
+ }
53
+ layers.push({ path: `${claude.path}#settings`, object: claude.settings });
54
+ }
55
+ if (index.has(SETTINGS_FILE)) {
56
+ const text = readText(index, SETTINGS_FILE, "settings", findings);
57
+ if (text === undefined) return undefined;
58
+ const object = parseJsonObject(text, SETTINGS_FILE, "settings-unreadable", findings);
59
+ if (object === undefined) return undefined;
60
+ layers.push({ path: SETTINGS_FILE, object });
61
+ }
62
+
63
+ // The last layer setting `agent` wins: the file over the inline object.
64
+ let agent: { readonly path: string; readonly value: unknown } | undefined;
65
+ for (const layer of layers) {
66
+ for (const [key, value] of fields(layer.object)) {
67
+ if (key === "agent") agent = { path: layer.path, value };
68
+ else findings.warn("settings-key-ignored", { path: layer.path, subject: key });
69
+ }
70
+ }
71
+ if (agent === undefined) return undefined;
72
+
73
+ const raw = agent.value;
74
+ const prefix = `${set.name ?? ""}:`;
75
+ const name = typeof raw === "string" && raw.startsWith(prefix) ? raw.slice(prefix.length) : raw;
76
+ if (typeof name !== "string" || !subAgents.some((subAgent) => subAgent.name === name)) {
77
+ findings.warn("settings-agent-unknown", { path: agent.path, detail: describeValue(raw) });
78
+ return undefined;
79
+ }
80
+ return name;
81
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Skill discovery and the `SKILL.md` frontmatter check.
3
+ *
4
+ * Discovery follows the union of the dialects' rules: the immediate child
5
+ * directories of `skills/` that hold a `SKILL.md` (the open format's fixed
6
+ * location, no recursion), plus every path a manifest declared (Claude adds
7
+ * to the default; Cursor's value is the default in practice), where a
8
+ * declared path is a skill when it holds `SKILL.md` directly and a directory
9
+ * of skills otherwise, plus Claude's single-skill layout (a root `SKILL.md`
10
+ * with no `skills/` and no declaration). A declared path that names nothing
11
+ * is a warning: Cursor's own tooling does not refuse it, and refusing would
12
+ * turn a stale manifest line into a failed install.
13
+ *
14
+ * The frontmatter check is a discovery check, not the push gate: it asks
15
+ * that the block be present and closed, that it parse, and that `name`
16
+ * satisfy `SKILL_NAME_PATTERN`. A missing `name` falls back to the directory
17
+ * name (Claude's rule) with a warning; the Agent Skills rules Stigmer relaxes
18
+ * (`name` equal to the directory, `description` present) are warnings.
19
+ * Optional frontmatter (`license`, `compatibility`, `metadata`,
20
+ * `allowed-tools`) and vendor keys ride inside the skill untouched, except
21
+ * `hooks`: Claude Code registers a skill's frontmatter hooks once the skill
22
+ * is invoked, for the rest of the session, which Stigmer does not run, so
23
+ * it is named (`skill-hooks-not-run`) rather than carried silently. Every
24
+ * file under the skill directory is listed for the installer's per-skill
25
+ * archive, except an eval suite: the plugin's (`evals/`, or where the
26
+ * manifest's `experimental.evals` moved it, by the suite reader's own rule
27
+ * in `evals/eval-dir.ts`, which refuses a directory overlapping the skills,
28
+ * so only a root skill ever loses the plugin's suite, and names none when
29
+ * the skills lie in `evals/` itself), which a root skill would otherwise
30
+ * carry whole, and a skill's own `evals/`. An agent the skill is mounted
31
+ * for must not read the cases it is graded on. Only `SKILL.md` is ever read.
32
+ */
33
+
34
+ import type { ManifestSet } from "../detect.js";
35
+ import { readText } from "../documents.js";
36
+ import { DEFAULT_EVAL_DIR, DEFAULT_SKILLS_DIR, resolveEvalDir } from "../evals/eval-dir.js";
37
+ import { basename, comparePaths, joinPath, type PluginFileIndex } from "../files.js";
38
+ import { extractFrontmatter, parseFrontmatter, SKILL_NAME_PATTERN } from "../frontmatter.js";
39
+ import type { Findings } from "../messages.js";
40
+ import type { PluginSkill } from "../types.js";
41
+
42
+ export const SKILL_FILE = "SKILL.md";
43
+
44
+ export function normaliseSkills(index: PluginFileIndex, set: ManifestSet, findings: Findings): readonly PluginSkill[] {
45
+ const skills: PluginSkill[] = [];
46
+ const seenNames = new Map<string, string>();
47
+ const resolution = resolveEvalDir(set);
48
+ const suiteDir = resolution.heldBySkills === undefined ? resolution.dir : undefined;
49
+
50
+ for (const dir of discoverSkillDirs(index, set, findings)) {
51
+ const skill = readSkill(index, dir, set, suiteDir, findings);
52
+ if (skill === undefined) continue;
53
+ const previous = seenNames.get(skill.name);
54
+ if (previous !== undefined) {
55
+ findings.error("skill-name-duplicate", { subject: skill.name, path: joinPath(dir, SKILL_FILE) });
56
+ continue;
57
+ }
58
+ seenNames.set(skill.name, dir);
59
+ skills.push(skill);
60
+ }
61
+ return skills;
62
+ }
63
+
64
+ /** Skill directories, deduplicated, in path order; the root skill is `""`. */
65
+ function discoverSkillDirs(index: PluginFileIndex, set: ManifestSet, findings: Findings): readonly string[] {
66
+ const dirs = new Set<string>();
67
+ const addSkillsUnder = (parent: string): void => {
68
+ for (const child of index.childDirectories(parent)) {
69
+ const dir = joinPath(parent, child);
70
+ if (index.has(joinPath(dir, SKILL_FILE))) dirs.add(dir);
71
+ }
72
+ };
73
+
74
+ addSkillsUnder(DEFAULT_SKILLS_DIR);
75
+
76
+ const declared = set.manifests.flatMap((m) => m.skillPaths);
77
+ for (const { path, manifest } of declared) {
78
+ if (index.has(joinPath(path, SKILL_FILE))) {
79
+ dirs.add(path);
80
+ } else if (index.isDirectory(path)) {
81
+ addSkillsUnder(path);
82
+ } else {
83
+ findings.warn("path-missing", { path: manifest, subject: path === "" ? "." : `./${path}` });
84
+ }
85
+ }
86
+
87
+ if (declared.length === 0 && !index.isDirectory(DEFAULT_SKILLS_DIR) && index.has(SKILL_FILE)) {
88
+ dirs.add("");
89
+ }
90
+
91
+ return [...dirs].sort(comparePaths);
92
+ }
93
+
94
+ function readSkill(index: PluginFileIndex, dir: string, set: ManifestSet, suiteDir: string | undefined, findings: Findings): PluginSkill | undefined {
95
+ const path = joinPath(dir, SKILL_FILE);
96
+ const text = readText(index, path, "skillMd", findings);
97
+ if (text === undefined) return undefined;
98
+
99
+ const extracted = extractFrontmatter(text);
100
+ if (!extracted.ok) {
101
+ findings.error(extracted.reason === "missing" ? "skill-frontmatter-missing" : "skill-frontmatter-unclosed", { path });
102
+ return undefined;
103
+ }
104
+ const parsed = parseFrontmatter(extracted.yaml);
105
+ if (!parsed.ok) {
106
+ findings.error("skill-frontmatter-unreadable", { path, detail: parsed.detail });
107
+ return undefined;
108
+ }
109
+
110
+ const directoryName = dir === "" ? (set.name ?? "skill") : basename(dir);
111
+ let name: string;
112
+ if (typeof parsed.fields["name"] === "string" && parsed.fields["name"] !== "") {
113
+ name = parsed.fields["name"];
114
+ } else {
115
+ name = directoryName;
116
+ findings.warn("skill-name-defaulted", { path, subject: name });
117
+ }
118
+ if (!SKILL_NAME_PATTERN.test(name)) {
119
+ findings.error("skill-name-invalid", { path, subject: name });
120
+ return undefined;
121
+ }
122
+ if (dir !== "" && name !== directoryName) {
123
+ findings.warn("skill-name-differs-from-directory", { path, subject: name, detail: directoryName });
124
+ }
125
+
126
+ const description = parsed.fields["description"];
127
+ if (typeof description !== "string" || description === "") {
128
+ findings.warn("skill-description-missing", { path, subject: name });
129
+ }
130
+ if (parsed.fields["hooks"] !== undefined) findings.warn("skill-hooks-not-run", { path, subject: name });
131
+
132
+ return {
133
+ name,
134
+ ...(typeof description === "string" && description !== "" && { description }),
135
+ dir,
136
+ files: withoutEvalSuites(index.filesUnder(dir), dir, suiteDir),
137
+ };
138
+ }
139
+
140
+ /** A skill's files minus the plugin's suite, when it has one, and the skill's own `evals/`. */
141
+ function withoutEvalSuites(files: readonly string[], dir: string, suiteDir: string | undefined): readonly string[] {
142
+ const own = `${joinPath(dir, DEFAULT_EVAL_DIR)}/`;
143
+ const prefixes = suiteDir === undefined ? [own] : [`${suiteDir}/`, own];
144
+ return files.filter((path) => !prefixes.some((prefix) => path.startsWith(prefix)));
145
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Stigmer's own reverse-domain folder, `ai.stigmer/`: read by nothing.
3
+ *
4
+ * The open format gives each client a folder other clients ignore. Stigmer
5
+ * installs a plugin exactly as every other client does, from its skills,
6
+ * agents, hooks and MCP configuration, so a plugin means the same thing
7
+ * wherever it is installed. A plugin that still carries the folder is told
8
+ * so once, as a warning: it installs, without it. The manifest's
9
+ * `extensions["ai.stigmer"]` (presentation.ts) is the format's own host
10
+ * slot and stays read.
11
+ */
12
+
13
+ import type { PluginFileIndex } from "../files.js";
14
+ import type { Findings } from "../messages.js";
15
+
16
+ export const STIGMER_FOLDER = "ai.stigmer";
17
+
18
+ /** Warns once when the plugin carries anything under `ai.stigmer/`. */
19
+ export function warnStigmerFolder(index: PluginFileIndex, findings: Findings): void {
20
+ if (index.filesUnder(STIGMER_FOLDER).length > 0) {
21
+ findings.warn("stigmer-folder-ignored", { path: `${STIGMER_FOLDER}/` });
22
+ }
23
+ }