opencastle 0.38.1 → 1.0.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 (289) hide show
  1. package/README.md +81 -1
  2. package/bin/cli.mjs +20 -3
  3. package/dist/cli/adapters/antigravity.d.ts +1 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.d.ts +1 -1
  6. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  7. package/dist/cli/adapters/codex.d.ts +1 -1
  8. package/dist/cli/adapters/codex.d.ts.map +1 -1
  9. package/dist/cli/adapters/cursor.d.ts +1 -1
  10. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  11. package/dist/cli/adapters/opencode.d.ts +1 -1
  12. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  13. package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
  14. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  15. package/dist/cli/adapters/rules-dir-base.js +13 -25
  16. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  17. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  18. package/dist/cli/adapters/single-file-base.js +30 -43
  19. package/dist/cli/adapters/single-file-base.js.map +1 -1
  20. package/dist/cli/adapters/vscode.d.ts +3 -2
  21. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  22. package/dist/cli/adapters/vscode.js +19 -71
  23. package/dist/cli/adapters/vscode.js.map +1 -1
  24. package/dist/cli/adapters/windsurf.d.ts +1 -1
  25. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  26. package/dist/cli/baseline.d.ts +3 -0
  27. package/dist/cli/baseline.d.ts.map +1 -0
  28. package/dist/cli/baseline.js +280 -0
  29. package/dist/cli/baseline.js.map +1 -0
  30. package/dist/cli/bootstrap.d.ts +1 -0
  31. package/dist/cli/bootstrap.d.ts.map +1 -1
  32. package/dist/cli/bootstrap.js +1 -1
  33. package/dist/cli/bootstrap.js.map +1 -1
  34. package/dist/cli/ci.d.ts +18 -0
  35. package/dist/cli/ci.d.ts.map +1 -0
  36. package/dist/cli/ci.js +279 -0
  37. package/dist/cli/ci.js.map +1 -0
  38. package/dist/cli/dispatcher.test.js +2 -2
  39. package/dist/cli/dispatcher.test.js.map +1 -1
  40. package/dist/cli/docs-accuracy.test.js +5 -0
  41. package/dist/cli/docs-accuracy.test.js.map +1 -1
  42. package/dist/cli/doctor.d.ts +3 -3
  43. package/dist/cli/doctor.d.ts.map +1 -1
  44. package/dist/cli/doctor.js +66 -9
  45. package/dist/cli/doctor.js.map +1 -1
  46. package/dist/cli/explain.d.ts +3 -0
  47. package/dist/cli/explain.d.ts.map +1 -0
  48. package/dist/cli/explain.js +210 -0
  49. package/dist/cli/explain.js.map +1 -0
  50. package/dist/cli/fleet.d.ts +30 -0
  51. package/dist/cli/fleet.d.ts.map +1 -0
  52. package/dist/cli/fleet.js +149 -0
  53. package/dist/cli/fleet.js.map +1 -0
  54. package/dist/cli/github-report.d.ts +49 -0
  55. package/dist/cli/github-report.d.ts.map +1 -0
  56. package/dist/cli/github-report.js +161 -0
  57. package/dist/cli/github-report.js.map +1 -0
  58. package/dist/cli/github-report.test.d.ts +2 -0
  59. package/dist/cli/github-report.test.d.ts.map +1 -0
  60. package/dist/cli/github-report.test.js +146 -0
  61. package/dist/cli/github-report.test.js.map +1 -0
  62. package/dist/cli/init.d.ts.map +1 -1
  63. package/dist/cli/init.js +135 -94
  64. package/dist/cli/init.js.map +1 -1
  65. package/dist/cli/init.test.js +26 -25
  66. package/dist/cli/init.test.js.map +1 -1
  67. package/dist/cli/layers.d.ts +152 -0
  68. package/dist/cli/layers.d.ts.map +1 -0
  69. package/dist/cli/layers.js +932 -0
  70. package/dist/cli/layers.js.map +1 -0
  71. package/dist/cli/layers.test.d.ts +2 -0
  72. package/dist/cli/layers.test.d.ts.map +1 -0
  73. package/dist/cli/layers.test.js +483 -0
  74. package/dist/cli/layers.test.js.map +1 -0
  75. package/dist/cli/lock.d.ts +130 -0
  76. package/dist/cli/lock.d.ts.map +1 -0
  77. package/dist/cli/lock.js +320 -0
  78. package/dist/cli/lock.js.map +1 -0
  79. package/dist/cli/mcp-audit.d.ts +164 -0
  80. package/dist/cli/mcp-audit.d.ts.map +1 -0
  81. package/dist/cli/mcp-audit.js +504 -0
  82. package/dist/cli/mcp-audit.js.map +1 -0
  83. package/dist/cli/mcp-audit.test.d.ts +2 -0
  84. package/dist/cli/mcp-audit.test.d.ts.map +1 -0
  85. package/dist/cli/mcp-audit.test.js +215 -0
  86. package/dist/cli/mcp-audit.test.js.map +1 -0
  87. package/dist/cli/mcp-upgrade.test.d.ts +2 -0
  88. package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
  89. package/dist/cli/mcp-upgrade.test.js +118 -0
  90. package/dist/cli/mcp-upgrade.test.js.map +1 -0
  91. package/dist/cli/mcp.d.ts +74 -5
  92. package/dist/cli/mcp.d.ts.map +1 -1
  93. package/dist/cli/mcp.js +340 -32
  94. package/dist/cli/mcp.js.map +1 -1
  95. package/dist/cli/policy.d.ts +58 -0
  96. package/dist/cli/policy.d.ts.map +1 -0
  97. package/dist/cli/policy.js +194 -0
  98. package/dist/cli/policy.js.map +1 -0
  99. package/dist/cli/publish-workflow.test.js +55 -1
  100. package/dist/cli/publish-workflow.test.js.map +1 -1
  101. package/dist/cli/remove.d.ts.map +1 -1
  102. package/dist/cli/remove.js +3 -2
  103. package/dist/cli/remove.js.map +1 -1
  104. package/dist/cli/review.d.ts +25 -0
  105. package/dist/cli/review.d.ts.map +1 -0
  106. package/dist/cli/review.js +437 -0
  107. package/dist/cli/review.js.map +1 -0
  108. package/dist/cli/status.d.ts +2 -0
  109. package/dist/cli/status.d.ts.map +1 -1
  110. package/dist/cli/status.js +25 -4
  111. package/dist/cli/status.js.map +1 -1
  112. package/dist/cli/status.test.js +5 -3
  113. package/dist/cli/status.test.js.map +1 -1
  114. package/dist/cli/sync-check.d.ts +16 -1
  115. package/dist/cli/sync-check.d.ts.map +1 -1
  116. package/dist/cli/sync-check.js +219 -13
  117. package/dist/cli/sync-check.js.map +1 -1
  118. package/dist/cli/sync-check.test.js +14 -8
  119. package/dist/cli/sync-check.test.js.map +1 -1
  120. package/dist/cli/sync.d.ts.map +1 -1
  121. package/dist/cli/sync.js +2 -0
  122. package/dist/cli/sync.js.map +1 -1
  123. package/dist/cli/team-ci.test.d.ts +2 -0
  124. package/dist/cli/team-ci.test.d.ts.map +1 -0
  125. package/dist/cli/team-ci.test.js +169 -0
  126. package/dist/cli/team-ci.test.js.map +1 -0
  127. package/dist/cli/team-commands.test.d.ts +2 -0
  128. package/dist/cli/team-commands.test.d.ts.map +1 -0
  129. package/dist/cli/team-commands.test.js +233 -0
  130. package/dist/cli/team-commands.test.js.map +1 -0
  131. package/dist/cli/team-config.d.ts +88 -0
  132. package/dist/cli/team-config.d.ts.map +1 -0
  133. package/dist/cli/team-config.js +261 -0
  134. package/dist/cli/team-config.js.map +1 -0
  135. package/dist/cli/team-health.d.ts +49 -0
  136. package/dist/cli/team-health.d.ts.map +1 -0
  137. package/dist/cli/team-health.js +205 -0
  138. package/dist/cli/team-health.js.map +1 -0
  139. package/dist/cli/team-sources.test.d.ts +2 -0
  140. package/dist/cli/team-sources.test.d.ts.map +1 -0
  141. package/dist/cli/team-sources.test.js +542 -0
  142. package/dist/cli/team-sources.test.js.map +1 -0
  143. package/dist/cli/types.d.ts +16 -2
  144. package/dist/cli/types.d.ts.map +1 -1
  145. package/dist/cli/types.js.map +1 -1
  146. package/dist/cli/update.d.ts.map +1 -1
  147. package/dist/cli/update.js +204 -44
  148. package/dist/cli/update.js.map +1 -1
  149. package/dist/cli/version-range.d.ts +24 -0
  150. package/dist/cli/version-range.d.ts.map +1 -0
  151. package/dist/cli/version-range.js +157 -0
  152. package/dist/cli/version-range.js.map +1 -0
  153. package/dist/cli/website-plugins.test.d.ts +2 -0
  154. package/dist/cli/website-plugins.test.d.ts.map +1 -0
  155. package/dist/cli/website-plugins.test.js +34 -0
  156. package/dist/cli/website-plugins.test.js.map +1 -0
  157. package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
  158. package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
  159. package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
  160. package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
  161. package/dist/orchestrator/plugins/contentful/config.js +11 -1
  162. package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
  163. package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
  164. package/dist/orchestrator/plugins/convex/config.js +11 -1
  165. package/dist/orchestrator/plugins/convex/config.js.map +1 -1
  166. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  167. package/dist/orchestrator/plugins/coolify/config.js +14 -1
  168. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  169. package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
  170. package/dist/orchestrator/plugins/figma/config.js +24 -13
  171. package/dist/orchestrator/plugins/figma/config.js.map +1 -1
  172. package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
  173. package/dist/orchestrator/plugins/linear/config.js +27 -17
  174. package/dist/orchestrator/plugins/linear/config.js.map +1 -1
  175. package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
  176. package/dist/orchestrator/plugins/netlify/config.js +23 -9
  177. package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
  178. package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
  179. package/dist/orchestrator/plugins/nextjs/config.js +11 -1
  180. package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
  181. package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
  182. package/dist/orchestrator/plugins/nx/config.js +11 -1
  183. package/dist/orchestrator/plugins/nx/config.js.map +1 -1
  184. package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
  185. package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
  186. package/dist/orchestrator/plugins/pins.test.js +78 -0
  187. package/dist/orchestrator/plugins/pins.test.js.map +1 -0
  188. package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
  189. package/dist/orchestrator/plugins/playwright/config.js +11 -1
  190. package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
  191. package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
  192. package/dist/orchestrator/plugins/prisma/config.js +17 -2
  193. package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
  194. package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
  195. package/dist/orchestrator/plugins/resend/config.js +17 -1
  196. package/dist/orchestrator/plugins/resend/config.js.map +1 -1
  197. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  198. package/dist/orchestrator/plugins/sentry/config.js +13 -1
  199. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  200. package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
  201. package/dist/orchestrator/plugins/slack/config.js +20 -1
  202. package/dist/orchestrator/plugins/slack/config.js.map +1 -1
  203. package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
  204. package/dist/orchestrator/plugins/strapi/config.js +11 -1
  205. package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
  206. package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
  207. package/dist/orchestrator/plugins/trello/config.js +21 -1
  208. package/dist/orchestrator/plugins/trello/config.js.map +1 -1
  209. package/dist/orchestrator/plugins/types.d.ts +22 -0
  210. package/dist/orchestrator/plugins/types.d.ts.map +1 -1
  211. package/package.json +3 -1
  212. package/src/cli/adapters/rules-dir-base.ts +23 -44
  213. package/src/cli/adapters/single-file-base.ts +43 -46
  214. package/src/cli/adapters/vscode.ts +28 -71
  215. package/src/cli/baseline.ts +289 -0
  216. package/src/cli/bootstrap.ts +1 -1
  217. package/src/cli/ci.ts +289 -0
  218. package/src/cli/dispatcher.test.ts +2 -2
  219. package/src/cli/docs-accuracy.test.ts +5 -0
  220. package/src/cli/doctor.ts +92 -6
  221. package/src/cli/explain.ts +210 -0
  222. package/src/cli/fleet.ts +176 -0
  223. package/src/cli/github-report.test.ts +158 -0
  224. package/src/cli/github-report.ts +179 -0
  225. package/src/cli/init.test.ts +27 -27
  226. package/src/cli/init.ts +135 -93
  227. package/src/cli/layers.test.ts +525 -0
  228. package/src/cli/layers.ts +1089 -0
  229. package/src/cli/lock.ts +395 -0
  230. package/src/cli/mcp-audit.test.ts +259 -0
  231. package/src/cli/mcp-audit.ts +619 -0
  232. package/src/cli/mcp-upgrade.test.ts +135 -0
  233. package/src/cli/mcp.ts +373 -34
  234. package/src/cli/policy.ts +207 -0
  235. package/src/cli/publish-workflow.test.ts +60 -1
  236. package/src/cli/remove.ts +8 -2
  237. package/src/cli/review.ts +457 -0
  238. package/src/cli/status.test.ts +5 -3
  239. package/src/cli/status.ts +29 -4
  240. package/src/cli/sync-check.test.ts +16 -8
  241. package/src/cli/sync-check.ts +245 -14
  242. package/src/cli/sync.ts +2 -0
  243. package/src/cli/team-ci.test.ts +195 -0
  244. package/src/cli/team-commands.test.ts +253 -0
  245. package/src/cli/team-config.ts +289 -0
  246. package/src/cli/team-health.ts +234 -0
  247. package/src/cli/team-sources.test.ts +578 -0
  248. package/src/cli/types.ts +19 -1
  249. package/src/cli/update.ts +217 -44
  250. package/src/cli/version-range.ts +150 -0
  251. package/src/cli/website-plugins.test.ts +41 -0
  252. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  253. package/src/orchestrator/customizations/README.md +1 -1
  254. package/src/orchestrator/plugins/chrome-devtools/SKILL.md +1 -1
  255. package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
  256. package/src/orchestrator/plugins/contentful/SKILL.md +1 -1
  257. package/src/orchestrator/plugins/contentful/config.ts +11 -1
  258. package/src/orchestrator/plugins/convex/SKILL.md +1 -1
  259. package/src/orchestrator/plugins/convex/config.ts +11 -1
  260. package/src/orchestrator/plugins/coolify/config.ts +14 -1
  261. package/src/orchestrator/plugins/cypress/SKILL.md +1 -1
  262. package/src/orchestrator/plugins/figma/SKILL.md +18 -14
  263. package/src/orchestrator/plugins/figma/config.ts +24 -13
  264. package/src/orchestrator/plugins/jira/SKILL.md +2 -2
  265. package/src/orchestrator/plugins/linear/SKILL.md +6 -14
  266. package/src/orchestrator/plugins/linear/config.ts +27 -17
  267. package/src/orchestrator/plugins/netlify/SKILL.md +1 -1
  268. package/src/orchestrator/plugins/netlify/config.ts +23 -9
  269. package/src/orchestrator/plugins/nextjs/config.ts +11 -1
  270. package/src/orchestrator/plugins/nx/config.ts +11 -1
  271. package/src/orchestrator/plugins/pins.test.ts +80 -0
  272. package/src/orchestrator/plugins/playwright/SKILL.md +1 -1
  273. package/src/orchestrator/plugins/playwright/config.ts +11 -1
  274. package/src/orchestrator/plugins/prisma/SKILL.md +1 -1
  275. package/src/orchestrator/plugins/prisma/config.ts +17 -2
  276. package/src/orchestrator/plugins/resend/config.ts +17 -1
  277. package/src/orchestrator/plugins/sanity/SKILL.md +1 -1
  278. package/src/orchestrator/plugins/sentry/config.ts +13 -1
  279. package/src/orchestrator/plugins/slack/config.ts +20 -1
  280. package/src/orchestrator/plugins/strapi/SKILL.md +1 -1
  281. package/src/orchestrator/plugins/strapi/config.ts +11 -1
  282. package/src/orchestrator/plugins/supabase/SKILL.md +1 -1
  283. package/src/orchestrator/plugins/trello/SKILL.md +1 -1
  284. package/src/orchestrator/plugins/trello/config.ts +21 -1
  285. package/src/orchestrator/plugins/types.ts +24 -0
  286. package/src/orchestrator/plugins/vercel/SKILL.md +1 -1
  287. package/src/orchestrator/plugins/vitest/SKILL.md +1 -1
  288. package/src/orchestrator/skill-config-links.test.ts +30 -0
  289. package/src/orchestrator/skills/git-workflow/SKILL.md +1 -1
@@ -0,0 +1,164 @@
1
+ import type { IdeChoice } from './types.js';
2
+ import { type EffectivePolicy } from './policy.js';
3
+ /**
4
+ * What a project's MCP config actually launches, read the way a supply-chain
5
+ * review would read it.
6
+ *
7
+ * An MCP server is code an agent runs with the developer's credentials, and the
8
+ * usual way to launch one — `npx -y some-server@latest` — installs whatever was
9
+ * published most recently, on every machine, with no review and no lockfile.
10
+ * `-y` is not even what makes it unattended: npx assumes yes whenever stdin is
11
+ * not a terminal, which is how every assistant starts a server. OWASP lists
12
+ * this as agentic supply-chain risk (ASI04). A team wants the opposite: the same
13
+ * server version on every laptop and in CI, changed in a reviewed diff.
14
+ *
15
+ * Three things are reported, from least to most serious:
16
+ * - a package run without an exact version (`@latest`, a range, or none);
17
+ * - a package that does not exist on npm — the server cannot start, and a name
18
+ * that was unpublished can be registered by anyone;
19
+ * - a remote server in `.mcp.json` with no `"type"`, which Claude Code reads as
20
+ * a stdio server with no command, so it never loads.
21
+ *
22
+ * What it cannot read it says so. An all-clear that counted a container image
23
+ * or an unparsed command line as "pinned" would be the false assurance this
24
+ * exists to replace.
25
+ */
26
+ export type McpProblem = 'unpinned' | 'nonexistent' | 'untyped-remote' | 'inline-secret' | 'not-allowed' | 'host-not-allowed' | 'unexpanded-variable';
27
+ /** What `opencastle sync` will do to an entry. */
28
+ export type SyncEffect = 'replaces' | 'removes' | 'keeps';
29
+ export interface McpFinding {
30
+ server: string;
31
+ problem: McpProblem;
32
+ /** The package spec or URL the finding is about, as written. */
33
+ subject: string;
34
+ /** The package name, for findings about a package. */
35
+ pkg?: string;
36
+ /**
37
+ * `replaces`: still exactly as a release wrote it, so sync moves it forward.
38
+ * `removes`: a plugin's server the project's stack no longer includes.
39
+ * `keeps`: edited since, or never ours — only a person changes it.
40
+ * A remedy that says "run sync" is only true for the first.
41
+ */
42
+ sync: SyncEffect;
43
+ /** The plugin that owns this server key, if one does. */
44
+ plugin?: string;
45
+ /** The team layer that defines this server, if one does — its config file. */
46
+ team?: string;
47
+ /** For `removes`: whose decision the removal is. */
48
+ removal?: 'stack' | 'policy' | 'retired';
49
+ /** For policy findings: the layers whose policy refuses it. */
50
+ refusedBy?: string;
51
+ }
52
+ /**
53
+ * The team's side of the audit: what its layers define, what they retired,
54
+ * and the policy every entry is held to — hand-added ones included.
55
+ */
56
+ export interface TeamAuditContext {
57
+ /** Server entries exactly as `sync` writes them into this target. */
58
+ expected: Record<string, unknown>;
59
+ /** Server key → the config file that defines it. */
60
+ definedIn: Record<string, string>;
61
+ /** Servers a previous sync wrote for the team that no layer defines now. */
62
+ retired: string[];
63
+ /** Integration servers the policy refuses, with why. */
64
+ blocked: Map<string, string>;
65
+ policy: EffectivePolicy;
66
+ }
67
+ export interface McpAudit {
68
+ findings: McpFinding[];
69
+ /** Servers `sync` would move to the current default, problem or not. */
70
+ outdated: string[];
71
+ /** Plugin servers the stack no longer includes, which `sync` deletes. */
72
+ removed: string[];
73
+ /** Integration servers the team's policy refuses, which `sync` deletes. */
74
+ blockedByPolicy: string[];
75
+ /** Team servers no layer defines any more, which `sync` deletes. */
76
+ retired: string[];
77
+ /** Servers whose launch was read and passed. */
78
+ passed: number;
79
+ /** Servers that launch something this audit cannot read, with why. */
80
+ unaudited: Array<{
81
+ server: string;
82
+ why: string;
83
+ }>;
84
+ }
85
+ /**
86
+ * Packages earlier releases of this tool wrote into configs that do not exist
87
+ * on npm. Kept here, by name, because an install from before the fix still has
88
+ * them until its next `sync` — and a hand-copied config has them for good.
89
+ */
90
+ export declare const NONEXISTENT_PACKAGES: Record<string, string>;
91
+ export interface PackageLaunch {
92
+ /** The spec as written, e.g. `@playwright/mcp@0.0.83`. */
93
+ spec: string;
94
+ name: string;
95
+ /** The version part, or null when there is none. */
96
+ version: string | null;
97
+ /**
98
+ * `npx --no` refuses to download anything, so it runs the copy the project
99
+ * already depends on — pinned by the project's own lockfile.
100
+ */
101
+ localOnly: boolean;
102
+ }
103
+ /**
104
+ * The command line with any `cmd /c` wrapper removed.
105
+ *
106
+ * Claude Code's documented form for an npx server on Windows is
107
+ * `"command": "cmd", "args": ["/c", "npx", ...]`. Reading `cmd` as the command
108
+ * meant the package behind it was never audited at all.
109
+ */
110
+ export declare function unwrapShell(command: string, args: string[]): {
111
+ command: string;
112
+ args: string[];
113
+ };
114
+ /**
115
+ * The registry package a command line fetches and runs.
116
+ *
117
+ * `null` when it runs none (a local script), or when the line uses an option
118
+ * this parser does not know — see `auditMcpConfig` for how that is reported.
119
+ */
120
+ export declare function packageLaunch(rawCommand: string, rawArgs: string[]): PackageLaunch | null;
121
+ /** True when the launch always runs the same code. */
122
+ export declare function isPinned(launch: PackageLaunch): boolean;
123
+ /**
124
+ * Read one parsed config. `ide` decides which dialect rules apply; `included`
125
+ * is the set of plugin servers the project's stack includes — the same set a
126
+ * rebuild uses, so what this predicts about `sync` is what `sync` does. Without
127
+ * it, every plugin server present is treated as included.
128
+ *
129
+ * `team` adds what the project's layers decide: the servers they define (which
130
+ * `sync` keeps exactly as defined), the ones they retired, and the policy every
131
+ * entry is held to, including entries nobody generated.
132
+ */
133
+ export declare function auditMcpConfig(config: unknown, ide: IdeChoice, included?: Set<string>, team?: TeamAuditContext): McpAudit;
134
+ /** Whether a finding fails the check, given the policy in force. */
135
+ export declare function isFailure(f: McpFinding, policy?: EffectivePolicy): boolean;
136
+ /** One finding in words, saying so when it fails only because the team requires pinning. */
137
+ export declare function describeFindingUnder(f: McpFinding, policy?: EffectivePolicy): string;
138
+ /** One finding in words. */
139
+ export declare function describeFinding(f: McpFinding): string;
140
+ /**
141
+ * The remedy that works for each finding, joined.
142
+ *
143
+ * Only `sync` can clear what it wrote, and only while nobody has edited it.
144
+ * Saying "run sync" over an entry someone changed would send them to a command
145
+ * that, correctly, will not touch it; and over a server the stack no longer
146
+ * includes it would not fix the entry but delete it.
147
+ */
148
+ export declare function remedyFor(list: McpFinding[], rel: string): string;
149
+ export interface McpAuditResult {
150
+ ok: boolean;
151
+ label: string;
152
+ detail?: string;
153
+ warning?: boolean;
154
+ fix?: string;
155
+ }
156
+ /**
157
+ * The check `doctor` and `status` run for one target's MCP config.
158
+ *
159
+ * A config that is absent or will not parse is not reported here: the MCP
160
+ * configuration check beside this one already owns both of those answers, and
161
+ * saying it twice would print two remedies for one fault.
162
+ */
163
+ export declare function checkMcpSupplyChain(projectRoot: string, ide: IdeChoice, included?: Set<string>, team?: TeamAuditContext): McpAuditResult;
164
+ //# sourceMappingURL=mcp-audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-audit.d.ts","sourceRoot":"","sources":["../../src/cli/mcp-audit.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,504 @@
1
+ import { resolve } from 'node:path';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { PLUGINS } from '../orchestrator/plugins/index.js';
4
+ import { getMcpConfigRelPath, upgradeGeneratedServers, canonicalJson } from './mcp.js';
5
+ import { disallowedBy, hostDisallowedBy, findInlineSecret, hostOfUrl } from './policy.js';
6
+ import { EDITOR_VARIABLES } from './team-config.js';
7
+ /**
8
+ * Packages earlier releases of this tool wrote into configs that do not exist
9
+ * on npm. Kept here, by name, because an install from before the fix still has
10
+ * them until its next `sync` — and a hand-copied config has them for good.
11
+ */
12
+ export const NONEXISTENT_PACKAGES = {
13
+ 'netlify-mcp': 'unpublished from npm in January 2026, so the name can be claimed by anyone',
14
+ '@anthropic/figma-mcp': 'never published on npm',
15
+ '@anthropic/prisma-mcp': 'never published on npm',
16
+ };
17
+ /** Runners that fetch a package from a registry and execute it. */
18
+ const RUNNERS = {
19
+ npx: [],
20
+ npm: ['exec'],
21
+ bunx: [],
22
+ pnpm: ['dlx'],
23
+ yarn: ['dlx'],
24
+ uvx: [],
25
+ pipx: ['run'],
26
+ };
27
+ /** Runners from the Python ecosystem, whose specs pin with `==`. */
28
+ const PYTHON_RUNNERS = new Set(['uvx', 'pipx']);
29
+ /** Container runtimes: they fetch code too, and this audit does not read images. */
30
+ const CONTAINER_RUNTIMES = new Set(['docker', 'podman']);
31
+ /** Flags that take no value, so the next token may be the package. */
32
+ const VALUELESS_FLAGS = new Set(['-y', '--yes', '--no', '--no-install', '-q', '--quiet', '--silent', '--ignore-existing']);
33
+ /** Flags followed by a value that is not the package. */
34
+ const VALUE_FLAGS = {
35
+ default: new Set(['--registry', '--cache', '--userconfig', '--prefix', '--node-options', '--workspace', '-w']),
36
+ uvx: new Set(['--python', '-p', '--with', '--index', '--index-url', '--extra-index-url', '--python-preference']),
37
+ };
38
+ const EXACT_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
39
+ function binName(command) {
40
+ // Split on both separators: a config written on Windows says `C:\tools\npx.cmd`,
41
+ // and `basename` only knows the separator of the machine running the check.
42
+ return (command.split(/[\\/]/).pop() ?? '').replace(/\.(cmd|exe)$/i, '').toLowerCase();
43
+ }
44
+ /**
45
+ * The command line with any `cmd /c` wrapper removed.
46
+ *
47
+ * Claude Code's documented form for an npx server on Windows is
48
+ * `"command": "cmd", "args": ["/c", "npx", ...]`. Reading `cmd` as the command
49
+ * meant the package behind it was never audited at all.
50
+ */
51
+ export function unwrapShell(command, args) {
52
+ if (binName(command) === 'cmd' && args.length >= 2 && /^\/c$/i.test(args[0])) {
53
+ return { command: args[1], args: args.slice(2) };
54
+ }
55
+ return { command, args };
56
+ }
57
+ /**
58
+ * The registry package a command line fetches and runs.
59
+ *
60
+ * `null` when it runs none (a local script), or when the line uses an option
61
+ * this parser does not know — see `auditMcpConfig` for how that is reported.
62
+ */
63
+ export function packageLaunch(rawCommand, rawArgs) {
64
+ const { command, args } = unwrapShell(rawCommand, rawArgs);
65
+ const bin = binName(command);
66
+ const lead = RUNNERS[bin];
67
+ if (!lead)
68
+ return null;
69
+ if (lead.some((word, i) => args[i] !== word))
70
+ return null;
71
+ const rest = args.slice(lead.length);
72
+ const python = PYTHON_RUNNERS.has(bin);
73
+ const valueFlags = python ? VALUE_FLAGS.uvx : VALUE_FLAGS.default;
74
+ // Only flags *before* the package are the runner's. Everything after it is
75
+ // passed to the server, so `npx -y foo@latest --no` is not project-local.
76
+ let localOnly = false;
77
+ let spec;
78
+ for (let i = 0; i < rest.length; i++) {
79
+ const arg = rest[i];
80
+ if (python && (arg === '--from' || arg === '--spec')) {
81
+ spec = rest[i + 1];
82
+ break;
83
+ }
84
+ if (!python && (arg === '-p' || arg === '--package')) {
85
+ spec = rest[i + 1];
86
+ break;
87
+ }
88
+ if (arg.startsWith('--package=') || arg.startsWith('--from=') || arg.startsWith('--spec=')) {
89
+ spec = arg.slice(arg.indexOf('=') + 1);
90
+ break;
91
+ }
92
+ if (arg === '--') {
93
+ spec = rest[i + 1];
94
+ break;
95
+ }
96
+ // `-c` runs a shell string, not a package; nothing here to name.
97
+ if (arg === '-c' || arg === '--call')
98
+ return null;
99
+ if (arg.startsWith('-')) {
100
+ if (VALUELESS_FLAGS.has(arg)) {
101
+ if (arg === '--no' || arg === '--no-install')
102
+ localOnly = true;
103
+ continue;
104
+ }
105
+ if (valueFlags.has(arg)) {
106
+ i++;
107
+ continue;
108
+ }
109
+ if (arg.includes('='))
110
+ continue;
111
+ // An option we do not know may take a value; stop rather than guess.
112
+ return null;
113
+ }
114
+ spec = arg;
115
+ break;
116
+ }
117
+ if (!spec)
118
+ return null;
119
+ // A path, a URL or a git spec is not a registry package, and pinning advice
120
+ // about it would be wrong.
121
+ if (/^(\.|\/|~|file:|git\+|git:|https?:|github:)/.test(spec))
122
+ return null;
123
+ let name = spec;
124
+ let version = null;
125
+ const eq = spec.indexOf('==');
126
+ if (python && eq > 0) {
127
+ name = spec.slice(0, eq);
128
+ version = spec.slice(eq + 2);
129
+ }
130
+ else {
131
+ const at = spec.startsWith('@') ? spec.indexOf('@', 1) : spec.indexOf('@');
132
+ if (at > 0) {
133
+ name = spec.slice(0, at);
134
+ version = spec.slice(at + 1);
135
+ }
136
+ }
137
+ return { spec, name, version, localOnly: (bin === 'npx' || bin === 'npm') && localOnly };
138
+ }
139
+ /** True when the launch always runs the same code. */
140
+ export function isPinned(launch) {
141
+ return launch.localOnly || (launch.version !== null && EXACT_VERSION.test(launch.version));
142
+ }
143
+ /** Every server entry in a parsed MCP config, whatever the target's dialect. */
144
+ function serverEntries(config) {
145
+ if (!config || typeof config !== 'object')
146
+ return [];
147
+ const out = [];
148
+ for (const key of ['servers', 'mcpServers', 'mcp']) {
149
+ const container = config[key];
150
+ if (!container || typeof container !== 'object' || Array.isArray(container))
151
+ continue;
152
+ for (const [name, entry] of Object.entries(container)) {
153
+ if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
154
+ out.push([name, entry]);
155
+ }
156
+ }
157
+ }
158
+ return out;
159
+ }
160
+ /** The command line an entry launches: `command` + `args`, or OpenCode's array. */
161
+ function commandLine(entry) {
162
+ const { command, args } = entry;
163
+ if (Array.isArray(command) && command.length > 0 && command.every((p) => typeof p === 'string')) {
164
+ return { command: command[0], args: command.slice(1) };
165
+ }
166
+ if (typeof command === 'string') {
167
+ const list = Array.isArray(args) ? args.filter((a) => typeof a === 'string') : [];
168
+ return { command, args: list };
169
+ }
170
+ return null;
171
+ }
172
+ /**
173
+ * Read one parsed config. `ide` decides which dialect rules apply; `included`
174
+ * is the set of plugin servers the project's stack includes — the same set a
175
+ * rebuild uses, so what this predicts about `sync` is what `sync` does. Without
176
+ * it, every plugin server present is treated as included.
177
+ *
178
+ * `team` adds what the project's layers decide: the servers they define (which
179
+ * `sync` keeps exactly as defined), the ones they retired, and the policy every
180
+ * entry is held to, including entries nobody generated.
181
+ */
182
+ export function auditMcpConfig(config, ide, included, team) {
183
+ const pluginByKey = new Map(Object.values(PLUGINS)
184
+ .filter((p) => p.mcpServerKey)
185
+ .map((p) => [p.mcpServerKey, p.id]));
186
+ const audit = {
187
+ findings: [],
188
+ outdated: [],
189
+ removed: [],
190
+ blockedByPolicy: [],
191
+ retired: [],
192
+ passed: 0,
193
+ unaudited: [],
194
+ };
195
+ const present = new Set();
196
+ for (const [server, entry] of serverEntries(config)) {
197
+ present.add(server);
198
+ const plugin = pluginByKey.get(server);
199
+ const teamWhere = team?.definedIn[server];
200
+ let sync = 'keeps';
201
+ let removal;
202
+ if (teamWhere && team) {
203
+ // A team server is compiled output: `sync` writes it exactly as the layer
204
+ // defines it, so any difference is one `sync` removes.
205
+ if (canonicalJson(entry) !== canonicalJson(team.expected[server]))
206
+ sync = 'replaces';
207
+ }
208
+ else if (team?.blocked.has(server)) {
209
+ // Refused by the policy or excluded by a layer — whoever wrote the entry,
210
+ // `sync` takes it out, so that is what the audit must say.
211
+ sync = 'removes';
212
+ removal = 'policy';
213
+ }
214
+ else if (team?.retired.includes(server)) {
215
+ sync = 'removes';
216
+ removal = 'retired';
217
+ }
218
+ else if (plugin) {
219
+ if (included && !included.has(server)) {
220
+ sync = 'removes';
221
+ removal = 'stack';
222
+ }
223
+ else if (upgradeGeneratedServers({ [server]: structuredClone(entry) }, ide, new Set([server])).length > 0) {
224
+ sync = 'replaces';
225
+ }
226
+ }
227
+ if (sync === 'replaces')
228
+ audit.outdated.push(server);
229
+ if (removal === 'stack')
230
+ audit.removed.push(server);
231
+ if (removal === 'policy')
232
+ audit.blockedByPolicy.push(server);
233
+ if (removal === 'retired')
234
+ audit.retired.push(server);
235
+ const base = {
236
+ server,
237
+ sync,
238
+ ...(plugin ? { plugin } : {}),
239
+ ...(teamWhere ? { team: teamWhere } : {}),
240
+ ...(removal ? { removal } : {}),
241
+ };
242
+ // Policy, for every entry: a server the team does not allow is a finding
243
+ // wherever it came from — the hand-added ones are the reason to have one.
244
+ let refused = false;
245
+ if (team) {
246
+ const by = disallowedBy(team.policy, server);
247
+ if (by) {
248
+ audit.findings.push({ ...base, problem: 'not-allowed', subject: server, refusedBy: by });
249
+ refused = true;
250
+ }
251
+ const url = typeof entry.url === 'string' ? entry.url : typeof entry.serverUrl === 'string' ? entry.serverUrl : null;
252
+ if (url && !refused) {
253
+ const hostBy = hostDisallowedBy(team.policy, url);
254
+ if (hostBy) {
255
+ // The host, never the URL: its query string may hold a credential.
256
+ audit.findings.push({ ...base, problem: 'host-not-allowed', subject: hostOfUrl(url), refusedBy: hostBy });
257
+ refused = true;
258
+ }
259
+ }
260
+ }
261
+ // `${NAME}` where the assistant expands only its own spelling reaches the
262
+ // server as those characters, in place of the value. Entries sync writes
263
+ // are already right; this is for ones someone edited or added.
264
+ if (sync === 'keeps') {
265
+ const wrong = unexpandedVariable(entry, ide);
266
+ if (wrong)
267
+ audit.findings.push({ ...base, problem: 'unexpanded-variable', subject: wrong });
268
+ }
269
+ // A credential in a committed file is a leak however the server launches.
270
+ const secretAt = findInlineSecret(entry);
271
+ if (secretAt) {
272
+ audit.findings.push({ ...base, problem: 'inline-secret', subject: secretAt });
273
+ refused = true;
274
+ }
275
+ const line = commandLine(entry);
276
+ if (line) {
277
+ const { command, args } = unwrapShell(line.command, line.args);
278
+ const bin = binName(command);
279
+ if (CONTAINER_RUNTIMES.has(bin)) {
280
+ // A digest names exactly one image. A tag — `:latest` or `:1.2` — can be
281
+ // moved, and reading where the image sits among docker's own options is
282
+ // beyond this check, so anything else is reported, not passed.
283
+ if (args.some((a) => /@sha256:[0-9a-f]{64}$/.test(a))) {
284
+ if (!refused)
285
+ audit.passed++;
286
+ }
287
+ else
288
+ audit.unaudited.push({ server, why: 'container image without a digest' });
289
+ continue;
290
+ }
291
+ const launch = packageLaunch(command, args);
292
+ if (!launch) {
293
+ // A runner we could not read is not a pass. A plain command — `node
294
+ // tools/mcp.js` — fetches nothing, and is the project's own code.
295
+ if (RUNNERS[bin])
296
+ audit.unaudited.push({ server, why: `${bin} options this check does not read` });
297
+ else if (!refused)
298
+ audit.passed++;
299
+ continue;
300
+ }
301
+ if (NONEXISTENT_PACKAGES[launch.name]) {
302
+ audit.findings.push({ ...base, problem: 'nonexistent', subject: launch.spec, pkg: launch.name });
303
+ }
304
+ else if (!isPinned(launch)) {
305
+ audit.findings.push({ ...base, problem: 'unpinned', subject: launch.spec, pkg: launch.name });
306
+ }
307
+ else if (!refused) {
308
+ audit.passed++;
309
+ }
310
+ continue;
311
+ }
312
+ if (ide === 'claude-code' && typeof entry.url === 'string' && entry.type === undefined) {
313
+ audit.findings.push({ ...base, problem: 'untyped-remote', subject: entry.url });
314
+ continue;
315
+ }
316
+ if (!refused)
317
+ audit.passed++;
318
+ }
319
+ // A team server missing from the file is one `sync` adds.
320
+ for (const server of Object.keys(team?.expected ?? {})) {
321
+ if (!present.has(server))
322
+ audit.outdated.push(server);
323
+ }
324
+ return audit;
325
+ }
326
+ /** Whether a finding fails the check, given the policy in force. */
327
+ export function isFailure(f, policy) {
328
+ if (f.problem === 'unexpanded-variable')
329
+ return false;
330
+ return f.problem !== 'unpinned' || Boolean(policy?.requirePinned);
331
+ }
332
+ /** How each target that does not expand `${NAME}` spells it instead. */
333
+ const OWN_SPELLING = {
334
+ cursor: (n) => `\${env:${n}}`,
335
+ windsurf: (n) => `\${env:${n}}`,
336
+ opencode: (n) => `{env:${n}}`,
337
+ };
338
+ /** The first `${NAME}` this target would pass through literally, as `NAME → spelling`, or null. */
339
+ function unexpandedVariable(entry, ide) {
340
+ const spell = OWN_SPELLING[ide];
341
+ if (!spell)
342
+ return null;
343
+ const values = [];
344
+ for (const field of ['env', 'environment', 'headers']) {
345
+ const block = entry[field];
346
+ if (block && typeof block === 'object' && !Array.isArray(block))
347
+ values.push(...Object.values(block));
348
+ }
349
+ // A shell expands `${NAME}` in its own script, so a `sh -c` line is fine as is.
350
+ const command = Array.isArray(entry.command) ? entry.command[0] : entry.command;
351
+ const shell = typeof command === 'string' && /(^|[\\/])(sh|bash|zsh|dash|fish)(\.exe)?$/.test(command);
352
+ if (!shell) {
353
+ if (Array.isArray(entry.args))
354
+ values.push(...entry.args);
355
+ if (Array.isArray(entry.command))
356
+ values.push(...entry.command);
357
+ }
358
+ values.push(entry.url, entry.serverUrl);
359
+ for (const v of values) {
360
+ if (typeof v !== 'string')
361
+ continue;
362
+ // Environment variables are conventionally upper case; `${name}` in a
363
+ // server's own template is more likely its business than a variable.
364
+ for (const m of v.matchAll(/\$\{([A-Z_][A-Z0-9_]*)\}/g)) {
365
+ if (!EDITOR_VARIABLES.has(m[1]))
366
+ return `\${${m[1]}} → ${spell(m[1])}`;
367
+ }
368
+ }
369
+ return null;
370
+ }
371
+ /** One finding in words, saying so when it fails only because the team requires pinning. */
372
+ export function describeFindingUnder(f, policy) {
373
+ if (f.problem === 'unpinned' && policy?.requirePinned) {
374
+ return `${f.server}: ${f.subject} is not pinned to an exact version, which ${policy.requirePinned} requires`;
375
+ }
376
+ return describeFinding(f);
377
+ }
378
+ /** One finding in words. */
379
+ export function describeFinding(f) {
380
+ switch (f.problem) {
381
+ case 'nonexistent':
382
+ return `${f.server}: ${f.subject} was ${NONEXISTENT_PACKAGES[f.pkg ?? ''] ?? 'not found on npm'}`;
383
+ case 'untyped-remote':
384
+ return `${f.server}: no "type" — Claude Code reads it as a stdio server, so it never loads`;
385
+ case 'unpinned':
386
+ return `${f.server}: ${f.subject}`;
387
+ case 'inline-secret':
388
+ return `${f.server}: a credential is written into ${f.subject} — it is committed with the file`;
389
+ case 'not-allowed':
390
+ return `${f.server}: not on the MCP allowlist of ${f.refusedBy}`;
391
+ case 'host-not-allowed':
392
+ return `${f.server}: ${f.subject} is not an allowed host for ${f.refusedBy}`;
393
+ case 'unexpanded-variable':
394
+ return `${f.server}: this assistant does not expand ${f.subject.split(' → ')[0]}; it reaches the server as literal text (write ${f.subject.split(' → ')[1]})`;
395
+ }
396
+ }
397
+ /**
398
+ * The remedy that works for each finding, joined.
399
+ *
400
+ * Only `sync` can clear what it wrote, and only while nobody has edited it.
401
+ * Saying "run sync" over an entry someone changed would send them to a command
402
+ * that, correctly, will not touch it; and over a server the stack no longer
403
+ * includes it would not fix the entry but delete it.
404
+ */
405
+ export function remedyFor(list, rel) {
406
+ const names = (pick) => [...new Set(list.filter(pick).map((f) => f.server))].join(', ');
407
+ const parts = [];
408
+ const replaced = names((f) => f.sync === 'replaces' && !f.team);
409
+ const rewritten = names((f) => f.sync === 'replaces' && Boolean(f.team));
410
+ const removed = list.filter((f) => f.sync === 'removes' && (f.removal ?? 'stack') === 'stack');
411
+ const blocked = names((f) => f.sync === 'removes' && f.removal === 'policy');
412
+ const retired = names((f) => f.sync === 'removes' && f.removal === 'retired');
413
+ const edited = names((f) => f.sync === 'keeps' && Boolean(f.plugin) && !f.team);
414
+ const teamSource = list.filter((f) => f.sync === 'keeps' && Boolean(f.team));
415
+ const own = names((f) => f.sync === 'keeps' && !f.plugin && !f.team);
416
+ if (replaced)
417
+ parts.push(`opencastle sync fixes ${replaced} (still as OpenCastle wrote them)`);
418
+ if (rewritten)
419
+ parts.push(`opencastle sync rewrites ${rewritten} as the team config defines them`);
420
+ if (removed.length > 0) {
421
+ const servers = [...new Set(removed.map((f) => f.server))].join(', ');
422
+ const packs = [...new Set(removed.map((f) => f.plugin))].join(' ');
423
+ parts.push(`opencastle sync removes ${servers}, which this project's stack does not include — opencastle add ${packs} keeps it`);
424
+ }
425
+ if (blocked)
426
+ parts.push(`opencastle sync removes ${blocked}, which the team's config excludes or its MCP policy does not allow`);
427
+ if (retired)
428
+ parts.push(`opencastle sync removes ${retired}, which no team layer defines any more`);
429
+ for (const where of new Set(teamSource.map((f) => f.team))) {
430
+ parts.push(`fix ${names((f) => f.team === where && f.sync === 'keeps')} in ${where}, where it is defined`);
431
+ }
432
+ if (edited) {
433
+ parts.push(`${edited} changed since OpenCastle wrote them — fix by hand, or delete the entry and run opencastle sync --force for the current default`);
434
+ }
435
+ if (own)
436
+ parts.push(`fix ${own} by hand in ${rel}`);
437
+ // A credential in a committed file needs more than an edit: it has to leave
438
+ // the file, and if the file was ever pushed, the credential is spent.
439
+ const leaked = names((f) => f.problem === 'inline-secret');
440
+ if (leaked) {
441
+ parts.push(`move the credential in ${leaked} into .env or your shell and reference it as \${NAME}; rotate it if the file was ever committed`);
442
+ }
443
+ return parts.join('; ');
444
+ }
445
+ const LABEL = 'MCP servers load and run pinned code';
446
+ /**
447
+ * The check `doctor` and `status` run for one target's MCP config.
448
+ *
449
+ * A config that is absent or will not parse is not reported here: the MCP
450
+ * configuration check beside this one already owns both of those answers, and
451
+ * saying it twice would print two remedies for one fault.
452
+ */
453
+ export function checkMcpSupplyChain(projectRoot, ide, included, team) {
454
+ const rel = getMcpConfigRelPath(ide);
455
+ const abs = resolve(projectRoot, rel);
456
+ if (!existsSync(abs))
457
+ return { ok: true, label: LABEL, detail: 'no MCP config' };
458
+ let parsed;
459
+ try {
460
+ parsed = JSON.parse(readFileSync(abs, 'utf8'));
461
+ }
462
+ catch {
463
+ return { ok: true, label: LABEL, detail: `${rel} could not be read (reported above)` };
464
+ }
465
+ const audit = auditMcpConfig(parsed, ide, included, team);
466
+ const broken = audit.findings.filter((f) => isFailure(f, team?.policy));
467
+ const warned = audit.findings.filter((f) => !isFailure(f, team?.policy));
468
+ const unpinned = warned.filter((f) => f.problem === 'unpinned');
469
+ const spelled = warned.filter((f) => f.problem === 'unexpanded-variable');
470
+ const unaudited = audit.unaudited.length
471
+ ? `not audited — ${audit.unaudited.map((u) => `${u.server} (${u.why})`).join(', ')}`
472
+ : '';
473
+ const warnings = [
474
+ unpinned.length > 0 ? `not pinned to an exact version — ${unpinned.map(describeFinding).join(', ')}` : '',
475
+ spelled.length > 0 ? spelled.map(describeFinding).join('; ') : '',
476
+ unaudited,
477
+ ].filter(Boolean);
478
+ if (broken.length > 0) {
479
+ // The rest in the same line: a failure used to hide them, so fixing it was
480
+ // followed by a second, surprise round of warnings.
481
+ return {
482
+ ok: false,
483
+ label: LABEL,
484
+ detail: [broken.map((f) => describeFindingUnder(f, team?.policy)).join('; '), ...warnings].join('; also '),
485
+ fix: remedyFor([...broken, ...unpinned], rel),
486
+ };
487
+ }
488
+ if (warnings.length > 0) {
489
+ const fixes = [
490
+ unpinned.length > 0
491
+ ? `${remedyFor(unpinned, rel)} (pin as name@x.y.z; each machine otherwise runs whatever was published last)`
492
+ : '',
493
+ spelled.length > 0 ? `use each assistant's own variable spelling in ${rel}, as shown` : '',
494
+ unaudited ? `check by hand what ${audit.unaudited.map((u) => u.server).join(', ')} launch` : '',
495
+ ].filter(Boolean);
496
+ return { ok: true, warning: true, label: LABEL, detail: warnings.join('; '), fix: fixes.join('; ') };
497
+ }
498
+ return {
499
+ ok: true,
500
+ label: LABEL,
501
+ detail: audit.passed === 0 ? 'no servers configured' : `${audit.passed} server(s): pinned, project-local, remote, or the project's own code`,
502
+ };
503
+ }
504
+ //# sourceMappingURL=mcp-audit.js.map