opencastle 0.38.2 → 1.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 (299) hide show
  1. package/README.md +89 -4
  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 +8 -4
  6. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  7. package/dist/cli/adapters/claude-code.js +13 -7
  8. package/dist/cli/adapters/claude-code.js.map +1 -1
  9. package/dist/cli/adapters/codex.d.ts +1 -1
  10. package/dist/cli/adapters/codex.d.ts.map +1 -1
  11. package/dist/cli/adapters/cursor.d.ts +1 -1
  12. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  13. package/dist/cli/adapters/opencode.d.ts +1 -1
  14. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  15. package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
  16. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  17. package/dist/cli/adapters/rules-dir-base.js +13 -25
  18. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  19. package/dist/cli/adapters/single-file-base.d.ts +8 -1
  20. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  21. package/dist/cli/adapters/single-file-base.js +43 -46
  22. package/dist/cli/adapters/single-file-base.js.map +1 -1
  23. package/dist/cli/adapters/vscode.d.ts +14 -3
  24. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  25. package/dist/cli/adapters/vscode.js +63 -75
  26. package/dist/cli/adapters/vscode.js.map +1 -1
  27. package/dist/cli/adapters/windsurf.d.ts +1 -1
  28. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  29. package/dist/cli/baseline.d.ts +3 -0
  30. package/dist/cli/baseline.d.ts.map +1 -0
  31. package/dist/cli/baseline.js +280 -0
  32. package/dist/cli/baseline.js.map +1 -0
  33. package/dist/cli/ci.d.ts +18 -0
  34. package/dist/cli/ci.d.ts.map +1 -0
  35. package/dist/cli/ci.js +279 -0
  36. package/dist/cli/ci.js.map +1 -0
  37. package/dist/cli/command-namespace.d.ts +91 -0
  38. package/dist/cli/command-namespace.d.ts.map +1 -0
  39. package/dist/cli/command-namespace.js +218 -0
  40. package/dist/cli/command-namespace.js.map +1 -0
  41. package/dist/cli/command-namespace.test.d.ts +2 -0
  42. package/dist/cli/command-namespace.test.d.ts.map +1 -0
  43. package/dist/cli/command-namespace.test.js +356 -0
  44. package/dist/cli/command-namespace.test.js.map +1 -0
  45. package/dist/cli/copy.d.ts +1 -1
  46. package/dist/cli/copy.d.ts.map +1 -1
  47. package/dist/cli/copy.js +3 -2
  48. package/dist/cli/copy.js.map +1 -1
  49. package/dist/cli/dispatcher.test.js +2 -2
  50. package/dist/cli/dispatcher.test.js.map +1 -1
  51. package/dist/cli/docs-accuracy.test.js +5 -0
  52. package/dist/cli/docs-accuracy.test.js.map +1 -1
  53. package/dist/cli/doctor.d.ts +3 -3
  54. package/dist/cli/doctor.d.ts.map +1 -1
  55. package/dist/cli/doctor.js +66 -9
  56. package/dist/cli/doctor.js.map +1 -1
  57. package/dist/cli/doctor.test.js +2 -2
  58. package/dist/cli/doctor.test.js.map +1 -1
  59. package/dist/cli/explain.d.ts +3 -0
  60. package/dist/cli/explain.d.ts.map +1 -0
  61. package/dist/cli/explain.js +222 -0
  62. package/dist/cli/explain.js.map +1 -0
  63. package/dist/cli/fleet.d.ts +30 -0
  64. package/dist/cli/fleet.d.ts.map +1 -0
  65. package/dist/cli/fleet.js +149 -0
  66. package/dist/cli/fleet.js.map +1 -0
  67. package/dist/cli/github-report.d.ts +49 -0
  68. package/dist/cli/github-report.d.ts.map +1 -0
  69. package/dist/cli/github-report.js +161 -0
  70. package/dist/cli/github-report.js.map +1 -0
  71. package/dist/cli/github-report.test.d.ts +2 -0
  72. package/dist/cli/github-report.test.d.ts.map +1 -0
  73. package/dist/cli/github-report.test.js +146 -0
  74. package/dist/cli/github-report.test.js.map +1 -0
  75. package/dist/cli/init.d.ts.map +1 -1
  76. package/dist/cli/init.js +171 -96
  77. package/dist/cli/init.js.map +1 -1
  78. package/dist/cli/init.test.js +35 -29
  79. package/dist/cli/init.test.js.map +1 -1
  80. package/dist/cli/layers.d.ts +152 -0
  81. package/dist/cli/layers.d.ts.map +1 -0
  82. package/dist/cli/layers.js +932 -0
  83. package/dist/cli/layers.js.map +1 -0
  84. package/dist/cli/layers.test.d.ts +2 -0
  85. package/dist/cli/layers.test.d.ts.map +1 -0
  86. package/dist/cli/layers.test.js +483 -0
  87. package/dist/cli/layers.test.js.map +1 -0
  88. package/dist/cli/lock.d.ts +130 -0
  89. package/dist/cli/lock.d.ts.map +1 -0
  90. package/dist/cli/lock.js +320 -0
  91. package/dist/cli/lock.js.map +1 -0
  92. package/dist/cli/managed-paths.d.ts +18 -1
  93. package/dist/cli/managed-paths.d.ts.map +1 -1
  94. package/dist/cli/managed-paths.js +72 -2
  95. package/dist/cli/managed-paths.js.map +1 -1
  96. package/dist/cli/manifest.d.ts.map +1 -1
  97. package/dist/cli/manifest.js +2 -0
  98. package/dist/cli/manifest.js.map +1 -1
  99. package/dist/cli/mcp-audit.d.ts +164 -0
  100. package/dist/cli/mcp-audit.d.ts.map +1 -0
  101. package/dist/cli/mcp-audit.js +504 -0
  102. package/dist/cli/mcp-audit.js.map +1 -0
  103. package/dist/cli/mcp-audit.test.d.ts +2 -0
  104. package/dist/cli/mcp-audit.test.d.ts.map +1 -0
  105. package/dist/cli/mcp-audit.test.js +215 -0
  106. package/dist/cli/mcp-audit.test.js.map +1 -0
  107. package/dist/cli/mcp-upgrade.test.d.ts +2 -0
  108. package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
  109. package/dist/cli/mcp-upgrade.test.js +118 -0
  110. package/dist/cli/mcp-upgrade.test.js.map +1 -0
  111. package/dist/cli/mcp.d.ts +74 -5
  112. package/dist/cli/mcp.d.ts.map +1 -1
  113. package/dist/cli/mcp.js +340 -32
  114. package/dist/cli/mcp.js.map +1 -1
  115. package/dist/cli/policy.d.ts +58 -0
  116. package/dist/cli/policy.d.ts.map +1 -0
  117. package/dist/cli/policy.js +194 -0
  118. package/dist/cli/policy.js.map +1 -0
  119. package/dist/cli/publish-workflow.test.js +55 -1
  120. package/dist/cli/publish-workflow.test.js.map +1 -1
  121. package/dist/cli/remove.d.ts.map +1 -1
  122. package/dist/cli/remove.js +25 -6
  123. package/dist/cli/remove.js.map +1 -1
  124. package/dist/cli/review.d.ts +25 -0
  125. package/dist/cli/review.d.ts.map +1 -0
  126. package/dist/cli/review.js +437 -0
  127. package/dist/cli/review.js.map +1 -0
  128. package/dist/cli/status.d.ts +2 -0
  129. package/dist/cli/status.d.ts.map +1 -1
  130. package/dist/cli/status.js +25 -4
  131. package/dist/cli/status.js.map +1 -1
  132. package/dist/cli/status.test.js +5 -3
  133. package/dist/cli/status.test.js.map +1 -1
  134. package/dist/cli/sync-check.d.ts +16 -1
  135. package/dist/cli/sync-check.d.ts.map +1 -1
  136. package/dist/cli/sync-check.js +241 -17
  137. package/dist/cli/sync-check.js.map +1 -1
  138. package/dist/cli/sync-check.test.js +14 -8
  139. package/dist/cli/sync-check.test.js.map +1 -1
  140. package/dist/cli/sync.d.ts.map +1 -1
  141. package/dist/cli/sync.js +2 -0
  142. package/dist/cli/sync.js.map +1 -1
  143. package/dist/cli/team-ci.test.d.ts +2 -0
  144. package/dist/cli/team-ci.test.d.ts.map +1 -0
  145. package/dist/cli/team-ci.test.js +169 -0
  146. package/dist/cli/team-ci.test.js.map +1 -0
  147. package/dist/cli/team-commands.test.d.ts +2 -0
  148. package/dist/cli/team-commands.test.d.ts.map +1 -0
  149. package/dist/cli/team-commands.test.js +233 -0
  150. package/dist/cli/team-commands.test.js.map +1 -0
  151. package/dist/cli/team-config.d.ts +88 -0
  152. package/dist/cli/team-config.d.ts.map +1 -0
  153. package/dist/cli/team-config.js +261 -0
  154. package/dist/cli/team-config.js.map +1 -0
  155. package/dist/cli/team-health.d.ts +49 -0
  156. package/dist/cli/team-health.d.ts.map +1 -0
  157. package/dist/cli/team-health.js +205 -0
  158. package/dist/cli/team-health.js.map +1 -0
  159. package/dist/cli/team-sources.test.d.ts +2 -0
  160. package/dist/cli/team-sources.test.d.ts.map +1 -0
  161. package/dist/cli/team-sources.test.js +542 -0
  162. package/dist/cli/team-sources.test.js.map +1 -0
  163. package/dist/cli/types.d.ts +48 -2
  164. package/dist/cli/types.d.ts.map +1 -1
  165. package/dist/cli/types.js.map +1 -1
  166. package/dist/cli/update.d.ts.map +1 -1
  167. package/dist/cli/update.js +218 -44
  168. package/dist/cli/update.js.map +1 -1
  169. package/dist/cli/version-range.d.ts +24 -0
  170. package/dist/cli/version-range.d.ts.map +1 -0
  171. package/dist/cli/version-range.js +157 -0
  172. package/dist/cli/version-range.js.map +1 -0
  173. package/dist/cli/website-plugins.test.d.ts +2 -0
  174. package/dist/cli/website-plugins.test.d.ts.map +1 -0
  175. package/dist/cli/website-plugins.test.js +34 -0
  176. package/dist/cli/website-plugins.test.js.map +1 -0
  177. package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
  178. package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
  179. package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
  180. package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
  181. package/dist/orchestrator/plugins/contentful/config.js +11 -1
  182. package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
  183. package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
  184. package/dist/orchestrator/plugins/convex/config.js +11 -1
  185. package/dist/orchestrator/plugins/convex/config.js.map +1 -1
  186. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  187. package/dist/orchestrator/plugins/coolify/config.js +14 -1
  188. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  189. package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
  190. package/dist/orchestrator/plugins/figma/config.js +24 -13
  191. package/dist/orchestrator/plugins/figma/config.js.map +1 -1
  192. package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
  193. package/dist/orchestrator/plugins/linear/config.js +27 -17
  194. package/dist/orchestrator/plugins/linear/config.js.map +1 -1
  195. package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
  196. package/dist/orchestrator/plugins/netlify/config.js +23 -9
  197. package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
  198. package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
  199. package/dist/orchestrator/plugins/nextjs/config.js +11 -1
  200. package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
  201. package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
  202. package/dist/orchestrator/plugins/nx/config.js +11 -1
  203. package/dist/orchestrator/plugins/nx/config.js.map +1 -1
  204. package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
  205. package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
  206. package/dist/orchestrator/plugins/pins.test.js +78 -0
  207. package/dist/orchestrator/plugins/pins.test.js.map +1 -0
  208. package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
  209. package/dist/orchestrator/plugins/playwright/config.js +11 -1
  210. package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
  211. package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
  212. package/dist/orchestrator/plugins/prisma/config.js +17 -2
  213. package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
  214. package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
  215. package/dist/orchestrator/plugins/resend/config.js +17 -1
  216. package/dist/orchestrator/plugins/resend/config.js.map +1 -1
  217. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  218. package/dist/orchestrator/plugins/sentry/config.js +13 -1
  219. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  220. package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
  221. package/dist/orchestrator/plugins/slack/config.js +20 -1
  222. package/dist/orchestrator/plugins/slack/config.js.map +1 -1
  223. package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
  224. package/dist/orchestrator/plugins/strapi/config.js +11 -1
  225. package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
  226. package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
  227. package/dist/orchestrator/plugins/trello/config.js +21 -1
  228. package/dist/orchestrator/plugins/trello/config.js.map +1 -1
  229. package/dist/orchestrator/plugins/types.d.ts +22 -0
  230. package/dist/orchestrator/plugins/types.d.ts.map +1 -1
  231. package/package.json +4 -2
  232. package/src/cli/adapters/claude-code.ts +13 -7
  233. package/src/cli/adapters/rules-dir-base.ts +23 -44
  234. package/src/cli/adapters/single-file-base.ts +65 -50
  235. package/src/cli/adapters/vscode.ts +75 -77
  236. package/src/cli/baseline.ts +289 -0
  237. package/src/cli/ci.ts +289 -0
  238. package/src/cli/command-namespace.test.ts +417 -0
  239. package/src/cli/command-namespace.ts +222 -0
  240. package/src/cli/copy.ts +6 -2
  241. package/src/cli/dispatcher.test.ts +2 -2
  242. package/src/cli/docs-accuracy.test.ts +5 -0
  243. package/src/cli/doctor.test.ts +2 -2
  244. package/src/cli/doctor.ts +92 -6
  245. package/src/cli/explain.ts +222 -0
  246. package/src/cli/fleet.ts +176 -0
  247. package/src/cli/github-report.test.ts +158 -0
  248. package/src/cli/github-report.ts +179 -0
  249. package/src/cli/init.test.ts +36 -31
  250. package/src/cli/init.ts +174 -96
  251. package/src/cli/layers.test.ts +525 -0
  252. package/src/cli/layers.ts +1089 -0
  253. package/src/cli/lock.ts +395 -0
  254. package/src/cli/managed-paths.ts +73 -3
  255. package/src/cli/manifest.ts +2 -0
  256. package/src/cli/mcp-audit.test.ts +259 -0
  257. package/src/cli/mcp-audit.ts +619 -0
  258. package/src/cli/mcp-upgrade.test.ts +135 -0
  259. package/src/cli/mcp.ts +373 -34
  260. package/src/cli/policy.ts +207 -0
  261. package/src/cli/publish-workflow.test.ts +60 -1
  262. package/src/cli/remove.ts +28 -6
  263. package/src/cli/review.ts +457 -0
  264. package/src/cli/status.test.ts +5 -3
  265. package/src/cli/status.ts +29 -4
  266. package/src/cli/sync-check.test.ts +16 -8
  267. package/src/cli/sync-check.ts +264 -17
  268. package/src/cli/sync.ts +2 -0
  269. package/src/cli/team-ci.test.ts +195 -0
  270. package/src/cli/team-commands.test.ts +253 -0
  271. package/src/cli/team-config.ts +289 -0
  272. package/src/cli/team-health.ts +234 -0
  273. package/src/cli/team-sources.test.ts +578 -0
  274. package/src/cli/types.ts +51 -1
  275. package/src/cli/update.ts +229 -44
  276. package/src/cli/version-range.ts +150 -0
  277. package/src/cli/website-plugins.test.ts +41 -0
  278. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  279. package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
  280. package/src/orchestrator/plugins/contentful/config.ts +11 -1
  281. package/src/orchestrator/plugins/convex/config.ts +11 -1
  282. package/src/orchestrator/plugins/coolify/config.ts +14 -1
  283. package/src/orchestrator/plugins/figma/SKILL.md +18 -14
  284. package/src/orchestrator/plugins/figma/config.ts +24 -13
  285. package/src/orchestrator/plugins/linear/SKILL.md +6 -14
  286. package/src/orchestrator/plugins/linear/config.ts +27 -17
  287. package/src/orchestrator/plugins/netlify/config.ts +23 -9
  288. package/src/orchestrator/plugins/nextjs/config.ts +11 -1
  289. package/src/orchestrator/plugins/nx/config.ts +11 -1
  290. package/src/orchestrator/plugins/pins.test.ts +80 -0
  291. package/src/orchestrator/plugins/playwright/config.ts +11 -1
  292. package/src/orchestrator/plugins/prisma/config.ts +17 -2
  293. package/src/orchestrator/plugins/resend/config.ts +17 -1
  294. package/src/orchestrator/plugins/sentry/config.ts +13 -1
  295. package/src/orchestrator/plugins/slack/config.ts +20 -1
  296. package/src/orchestrator/plugins/strapi/config.ts +11 -1
  297. package/src/orchestrator/plugins/trello/config.ts +21 -1
  298. package/src/orchestrator/plugins/types.ts +24 -0
  299. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -4
package/src/cli/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {} from 'node:child_process';
2
+ import type { CompileSource } from './layers.js';
2
3
 
3
4
  // ── Stack selection types ──────────────────────────────────────
4
5
 
@@ -100,12 +101,17 @@ export interface CopyResults {
100
101
  * an earlier version" is simply false.
101
102
  */
102
103
  tornRoots?: string[];
104
+ /** Team MCP servers the scaffold wrote, and servers it took out, by key. */
105
+ mcpTeamWritten?: string[];
106
+ mcpTeamRemoved?: string[];
103
107
  }
104
108
 
105
109
  /** Options for the copyDir utility. */
106
110
  export interface CopyDirOptions {
107
111
  overwrite?: boolean;
108
112
  filter?: (_name: string, _srcPath: string) => boolean;
113
+ /** The name a file is installed under, given its source name. Directories keep theirs. */
114
+ rename?: (_name: string) => string;
109
115
  transform?: (
110
116
  _content: string,
111
117
  _srcPath: string
@@ -153,6 +159,13 @@ export interface Manifest {
153
159
  * "unknown", which is treated as "not ours to delete".
154
160
  */
155
161
  createdConfigs?: string[];
162
+ /**
163
+ * The namespace this install's commands are compiled under — `oc`. Absent on
164
+ * a project a release before the namespace compiled, which is how `sync`
165
+ * knows to look for the un-namespaced commands it left (`/bug-fix` beside
166
+ * `/oc:bug-fix`), and how it knows to stop looking afterwards.
167
+ */
168
+ commandNamespace?: string;
156
169
  stack?: StackConfig;
157
170
  repoInfo?: RepoInfo;
158
171
  }
@@ -187,15 +200,50 @@ export interface DoctorCheck {
187
200
 
188
201
  /** IDE adapter interface (init/update commands). */
189
202
  export interface IdeAdapter {
190
- install(_pkgRoot: string, _projectRoot: string, _stack?: StackConfig, _repoInfo?: RepoInfo): Promise<CopyResults>;
203
+ /**
204
+ * `_source` is the merged content to compile — OpenCastle's own, the
205
+ * baselines the project extends, and its `.opencastle/`. Without one an
206
+ * adapter compiles OpenCastle's content for the stack, and nothing else.
207
+ */
208
+ install(
209
+ _pkgRoot: string,
210
+ _projectRoot: string,
211
+ _stack?: StackConfig,
212
+ _repoInfo?: RepoInfo,
213
+ _source?: CompileSource,
214
+ ): Promise<CopyResults>;
191
215
  update(
192
216
  _pkgRoot: string,
193
217
  _projectRoot: string,
194
218
  _stack?: StackConfig,
195
219
  _repoInfo?: RepoInfo,
220
+ _source?: CompileSource,
196
221
  ): Promise<CopyResults>;
197
222
  getManagedPaths(): ManagedPaths;
198
223
  getDoctorChecks(): DoctorCheck[];
224
+ /**
225
+ * Files an earlier release wrote under a name this one no longer uses —
226
+ * `/bug-fix` before it became `/oc:bug-fix` — present on disk now, relative to
227
+ * the project root with forward slashes. `sync` removes them, `sync --check`
228
+ * reports them, `remove` takes them with the rest, and `init` reads them as a
229
+ * previous installation. Absent when a target has never renamed its output.
230
+ */
231
+ getLegacyOutputs?(_projectRoot: string): string[];
232
+ /**
233
+ * Framework directories this target shares with the user — `.github/prompts/`,
234
+ * which VS Code reads only at its top, so OpenCastle's `oc.` files and a
235
+ * person's own sit side by side. `remove` and a dropped target's cleanup take
236
+ * only what `ownsFile` claims there; every other framework directory is
237
+ * removed whole.
238
+ */
239
+ getSharedDirs?(): string[];
240
+ /**
241
+ * Whether a file under one of this target's framework directories is one it
242
+ * wrote. Sweeps and drift leave a file that answers no alone. Absent means
243
+ * every file there is the target's. `_rel` is relative to the project root,
244
+ * with forward slashes.
245
+ */
246
+ ownsFile?(_rel: string, _projectRoot: string): boolean;
199
247
  }
200
248
 
201
249
  /** Select prompt option. */
@@ -211,6 +259,8 @@ export interface SelectOption {
211
259
  export interface ScaffoldResult {
212
260
  path: string;
213
261
  action: 'created' | 'skipped';
262
+ /** Team servers written, and team or refused servers taken out. */
263
+ team?: { written: string[]; removed: string[] };
214
264
  }
215
265
 
216
266
  /** IDE display labels. */
package/src/cli/update.ts CHANGED
@@ -8,7 +8,6 @@ import { TECH_PLUGINS, TEAM_PLUGINS } from '../orchestrator/plugins/index.js'
8
8
  import { IDE_ADAPTERS, VALID_IDES } from './adapters/index.js'
9
9
  import { getOrchestratorRoot } from './copy.js'
10
10
  import {
11
- getRequiredMcpEnvVars,
12
11
  updateSkillMatrixFile,
13
12
  resolveStack,
14
13
  getCustomizationsTransform,
@@ -21,6 +20,41 @@ import { detectRepoInfo, mergeStackIntoRepoInfo, buildDetectedToolsSet } from '.
21
20
  import type { CliContext, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
22
21
  import { UnreadableConfigError } from './types.js'
23
22
  import { noteUnreadable } from './unreadable-report.js'
23
+ import {
24
+ resolveSources,
25
+ materialize,
26
+ hasErrors,
27
+ usesTeamSources,
28
+ formatIssues,
29
+ requiredEnvVars,
30
+ type ResolvedSources,
31
+ } from './layers.js'
32
+ import { buildLock, writeLock, LOCK_REL, priorTeam } from './lock.js'
33
+ import { parseVersion, compareVersions } from './version-range.js'
34
+ import { COMMAND_NAMESPACE } from './command-namespace.js'
35
+
36
+ /** Print what is wrong with the team's sources, and that nothing was written. */
37
+ function reportTeamIssues(resolved: ResolvedSources): void {
38
+ const errors = resolved.issues.filter((i) => i.level === 'error')
39
+ console.error(
40
+ `\n ${c.red('✗')} The team's sources have ${errors.length} problem(s); nothing was compiled.\n`,
41
+ )
42
+ for (const line of formatIssues(errors)) console.error(` ${line.startsWith(' ') ? c.dim(line) : line}`)
43
+ console.error('')
44
+ }
45
+
46
+ /**
47
+ * The manifest without the field that changes on every write.
48
+ *
49
+ * `updatedAt` changed on every sync, so two branches that both synced always
50
+ * conflicted on the manifest — in the one file every command reads first,
51
+ * where a conflict makes every command stop. Written only when something it
52
+ * records has actually changed.
53
+ */
54
+ function manifestMeaning(m: Record<string, unknown>): string {
55
+ const { updatedAt: _u, installedAt: _i, ...rest } = m
56
+ return JSON.stringify(rest)
57
+ }
24
58
 
25
59
  const UPDATE_HELP = `
26
60
  opencastle update [options]
@@ -31,6 +65,8 @@ const UPDATE_HELP = `
31
65
  Options:
32
66
  --dry-run Preview what would be changed without writing files
33
67
  --force Force update even if versions match
68
+ --allow-downgrade Recompile with this OpenCastle even though a newer one
69
+ compiled the project
34
70
  --reconfigure Re-run IDE and stack selection
35
71
  --help, -h Show this help
36
72
  `
@@ -136,6 +172,44 @@ export default async function update({
136
172
  await readFile(resolve(pkgRoot, 'package.json'), 'utf8')
137
173
  ) as { version: string }
138
174
 
175
+ // An older OpenCastle than the one that compiled the project would replace
176
+ // newer output with older, and the next teammate's sync would put it back —
177
+ // a pull request war nobody chose. Refused unless asked for by name: not by
178
+ // `--force`, which the tool's own remedies prescribe for other reasons, and
179
+ // which a teammate on an old CLI would otherwise run into a downgrade.
180
+ {
181
+ const mine = parseVersion(pkg.version)
182
+ const theirs = parseVersion(manifest.version)
183
+ if (mine && theirs && compareVersions(mine, theirs) < 0) {
184
+ if (!args.includes('--allow-downgrade')) {
185
+ console.error(
186
+ `\n ${c.red('✗')} This project was compiled by OpenCastle ${manifest.version}; this is ${pkg.version}.`,
187
+ )
188
+ console.error(` ${c.dim('Syncing would replace newer generated files with older ones. Run the project\'s version —')}`)
189
+ console.error(` ${c.dim(`npx opencastle@${manifest.version} sync, or add it to devDependencies so everyone runs one —`)}`)
190
+ console.error(` ${c.dim('or pass --allow-downgrade to go back to this version on purpose.')}\n`)
191
+ process.exit(1)
192
+ }
193
+ console.log(` ${c.yellow('!')} Downgrading this project from OpenCastle ${manifest.version} to ${pkg.version}, as asked.`)
194
+ }
195
+ }
196
+
197
+ // The team's sources, checked before anything is written. A baseline that is
198
+ // not installed or a server the policy forbids is a compile error: better no
199
+ // output than output that quietly leaves the team's standard out.
200
+ {
201
+ const early = resolveSources({
202
+ pkgRoot,
203
+ projectRoot,
204
+ stack: resolveStack({ ...manifest, ides }),
205
+ repoInfo: manifest.repoInfo,
206
+ })
207
+ if (hasErrors(early)) {
208
+ reportTeamIssues(early)
209
+ process.exit(1)
210
+ }
211
+ }
212
+
139
213
  // ── Recreate the local-only directories ─────────────────────────
140
214
  // Deliberately gitignored, so a fresh clone has none of them, and only `init`
141
215
  // used to create them: `doctor` failed on every clone and told the user to run
@@ -197,10 +271,16 @@ export default async function update({
197
271
  } catch {
198
272
  return true
199
273
  }
274
+ // The drift report also counts an MCP server entry still exactly as an
275
+ // earlier release wrote it, whose default has since changed. `doctor`
276
+ // prescribes this command for those — a package missing from npm, a remote
277
+ // server Claude Code cannot load — so the short-circuit must see them.
200
278
  try {
201
279
  const { buildCheckReport } = await import('./sync-check.js')
202
280
  const report = await buildCheckReport(pkgRoot, projectRoot)
203
- return report.drift.length > 0
281
+ // Not a broken MCP server only a person can fix: recompiling cannot clear
282
+ // it, and doing so on every run rewrote the committed manifest for nothing.
283
+ return report.drift.some((d) => !(d.origin === 'mcp' && d.kind === 'unreducible'))
204
284
  } catch {
205
285
  // If the comparison itself fails, err towards doing the work.
206
286
  return true
@@ -379,6 +459,14 @@ export default async function update({
379
459
  for (const p of preview.framework) {
380
460
  console.log(` ${c.yellow('↻')} ${p}`)
381
461
  }
462
+ // Named here because they are deleted, not updated: commands an earlier
463
+ // release wrote before the `oc:` namespace.
464
+ const legacy: string[] = []
465
+ for (const ide of ides) legacy.push(...((await IDE_ADAPTERS[ide]()).getLegacyOutputs?.(projectRoot) ?? []))
466
+ if (legacy.length > 0) {
467
+ console.log(`\n ${c.dim('[dry-run]')} Files from before the oc: namespace that would be removed:\n`)
468
+ for (const p of legacy) console.log(` ${c.red('-')} ${p}`)
469
+ }
382
470
  if (preview.merged.length > 0) {
383
471
  console.log(`\n ${c.dim('[dry-run]')} Files where only the managed block changes:\n`)
384
472
  for (const p of preview.merged) {
@@ -454,54 +542,93 @@ export default async function update({
454
542
  const staleRoots: string[] = []
455
543
  const tornRoots: string[] = []
456
544
  const sweptFiles: string[] = []
457
- for (const ide of ides) {
458
- const adapter = await IDE_ADAPTERS[ide]()
459
- // `repoInfo` matters here: `scaffoldMcpConfigInto` uses it to decide which
460
- // servers belong in the config. The parameter was threaded through all
461
- // three adapters and then not passed from the one place `sync` calls them,
462
- // so every sync scaffolded MCP as though the repository had been detected
463
- // as nothing at all — a property enforced everywhere except at the call.
464
- const results = await adapter.update(pkgRoot, projectRoot, newStack, repoInfo)
465
- totalCopied += results.copied.length
466
- totalCreated += results.created.length
467
- adoptedRoots.push(...(results.adopted ?? []))
468
- repairedRoots.push(...(results.repaired ?? []))
469
- damagedRoots.push(...(results.damagedRoots ?? []))
470
- severedRoots.push(...(results.severedRoots ?? []))
471
- staleRoots.push(...(results.staleRoots ?? []))
472
- tornRoots.push(...(results.tornRoots ?? []))
473
- sweptFiles.push(...(results.deleted ?? []))
474
- // The adapters skip a config they cannot parse instead of throwing; the
475
- // report below is the only place the user learns which file to fix.
476
- for (const file of results.unreadable ?? []) {
477
- noteUnreadable(unreadable, file)
478
- }
545
+ // The merged sources — OpenCastle's content, the baselines, the project's
546
+ // own — resolved once more with the final stack, so a reconfigure is honoured.
547
+ const resolved = resolveSources({ pkgRoot, projectRoot, stack: newStack, repoInfo })
548
+ if (hasErrors(resolved)) {
549
+ reportTeamIssues(resolved)
550
+ closePrompts()
551
+ process.exit(1)
479
552
  }
480
-
481
553
  // Deduplicated, and re-sorted by what the adapters declare today — two targets
482
554
  // that share AGENTS.md used to record it twice, and a manifest from before
483
555
  // root files were co-owned still files them under `framework`.
484
556
  const allManagedPaths = await resolveManagedPaths({ ...manifest, ides })
485
-
486
- // The skill matrix and the MCP config are compiled output like everything else,
487
- // so they are regenerated whenever we recompile. Gating them on `stackChanged`
488
- // — a flag only ever set inside the interactive reconfigure branch — meant
489
- // `opencastle add supabase` edited the manifest, recompiled, and left the skill
490
- // matrix and MCP config describing the stack from before the pack was added.
491
- if (newStack) {
557
+ const teamWritten = new Set<string>()
558
+ const teamRemoved = new Set<string>()
559
+ const upgradedServers = new Set<string>()
560
+ const removedServers = new Set<string>()
561
+ let lockWritten = false
562
+ let lockHeld = false
563
+ const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
564
+ try {
492
565
  for (const ide of ides) {
493
- for (const step of [
494
- () => updateSkillMatrixFile(projectRoot, ide, newStack),
495
- () => rebuildMcpConfig(projectRoot, ide as IdeChoice, newStack, repoInfo),
496
- ]) {
497
- try {
498
- await step()
499
- } catch (err) {
500
- if (!(err instanceof UnreadableConfigError)) throw err
501
- noteUnreadable(unreadable, err.file)
566
+ const adapter = await IDE_ADAPTERS[ide]()
567
+ // `repoInfo` matters here: `scaffoldMcpConfigInto` uses it to decide which
568
+ // servers belong in the config. The parameter was threaded through all
569
+ // three adapters and then not passed from the one place `sync` calls them,
570
+ // so every sync scaffolded MCP as though the repository had been detected
571
+ // as nothing at all — a property enforced everywhere except at the call.
572
+ const results = await adapter.update(pkgRoot, projectRoot, newStack, repoInfo, source)
573
+ totalCopied += results.copied.length
574
+ totalCreated += results.created.length
575
+ adoptedRoots.push(...(results.adopted ?? []))
576
+ repairedRoots.push(...(results.repaired ?? []))
577
+ damagedRoots.push(...(results.damagedRoots ?? []))
578
+ severedRoots.push(...(results.severedRoots ?? []))
579
+ staleRoots.push(...(results.staleRoots ?? []))
580
+ tornRoots.push(...(results.tornRoots ?? []))
581
+ sweptFiles.push(...(results.deleted ?? []))
582
+ for (const key of results.mcpTeamWritten ?? []) teamWritten.add(key)
583
+ for (const key of results.mcpTeamRemoved ?? []) teamRemoved.add(key)
584
+ // The adapters skip a config they cannot parse instead of throwing; the
585
+ // report below is the only place the user learns which file to fix.
586
+ for (const file of results.unreadable ?? []) {
587
+ noteUnreadable(unreadable, file)
588
+ }
589
+ }
590
+
591
+ // The skill matrix and the MCP config are compiled output like everything else,
592
+ // so they are regenerated whenever we recompile. Gating them on `stackChanged`
593
+ // — a flag only ever set inside the interactive reconfigure branch — meant
594
+ // `opencastle add supabase` edited the manifest, recompiled, and left the skill
595
+ // matrix and MCP config describing the stack from before the pack was added.
596
+ if (newStack) {
597
+ for (const ide of ides) {
598
+ for (const step of [
599
+ () => updateSkillMatrixFile(projectRoot, ide, newStack),
600
+ async () => {
601
+ const outcome = await rebuildMcpConfig(projectRoot, ide as IdeChoice, newStack, repoInfo, source.mcp)
602
+ for (const key of outcome.upgraded) upgradedServers.add(key)
603
+ for (const key of outcome.removed) removedServers.add(key)
604
+ for (const key of outcome.teamWritten) teamWritten.add(key)
605
+ for (const key of outcome.teamRemoved) teamRemoved.add(key)
606
+ },
607
+ ]) {
608
+ try {
609
+ await step()
610
+ } catch (err) {
611
+ if (!(err instanceof UnreadableConfigError)) throw err
612
+ noteUnreadable(unreadable, err.file)
613
+ }
502
614
  }
503
615
  }
504
616
  }
617
+
618
+ // What every assistant is now given, for review. Written last, from the
619
+ // same source the targets were compiled from — and not at all while an MCP
620
+ // config could not be read. The lock is how the next sync knows which team
621
+ // servers to take back out; recording a retirement before every config has
622
+ // had the server removed would leave it in the unreadable one for good,
623
+ // with every check green.
624
+ const mcpPaths = new Set(ides.map((i) => getMcpConfigRelPath(i as IdeChoice)))
625
+ lockHeld = unreadable.some((u) => {
626
+ const name = u.split('\u0000')[0]
627
+ return mcpPaths.has((isAbsolute(name) ? relative(projectRoot, name) : name).replace(/\\/g, '/'))
628
+ })
629
+ if (!lockHeld) lockWritten = await writeLock(projectRoot, buildLock(source, { ides, stack: newStack, repoInfo }))
630
+ } finally {
631
+ source.dispose()
505
632
  }
506
633
 
507
634
  // ── Restore any missing .opencastle/ scaffolding ────────────────
@@ -529,13 +656,19 @@ export default async function update({
529
656
  await migrateLegacyLogs(projectRoot)
530
657
 
531
658
  // ── Update manifest ─────────────────────────────────────────────
659
+ const before = manifestMeaning(manifest as unknown as Record<string, unknown>)
532
660
  manifest.version = pkg.version
533
661
  manifest.ides = ides
534
- manifest.updatedAt = new Date().toISOString()
535
662
  manifest.managedPaths = allManagedPaths
663
+ // After the compile above, which has removed any un-namespaced commands an
664
+ // earlier release left: from here on the old names are free again.
665
+ manifest.commandNamespace = COMMAND_NAMESPACE
536
666
  manifest.stack = newStack
537
667
  manifest.repoInfo = mergeStackIntoRepoInfo(repoInfo, newStack)
538
- await writeManifest(projectRoot, manifest)
668
+ if (manifestMeaning(manifest as unknown as Record<string, unknown>) !== before) {
669
+ manifest.updatedAt = new Date().toISOString()
670
+ await writeManifest(projectRoot, manifest)
671
+ }
539
672
 
540
673
  // ── Results ─────────────────────────────────────────────────────
541
674
  console.log(
@@ -550,6 +683,58 @@ export default async function update({
550
683
  console.log(` ${c.green('✓')} Updated skill matrix`)
551
684
  console.log(` ${c.green('✓')} Rebuilt MCP config`)
552
685
  }
686
+ // Said, because it changes a file the user commits: an entry we generated has
687
+ // moved to a new default (a pinned version, a server that exists, a shape the
688
+ // assistant can load), and the diff should not come as a surprise in review.
689
+ if (upgradedServers.size > 0) {
690
+ console.log(
691
+ ` ${c.green('✓')} Moved ${upgradedServers.size} MCP server(s) to the current default: ` +
692
+ [...upgradedServers].sort().join(', '),
693
+ )
694
+ }
695
+ if (removedServers.size > 0) {
696
+ console.log(
697
+ ` ${c.yellow('-')} Removed ${removedServers.size} MCP server(s) this project's stack no longer includes: ` +
698
+ [...removedServers].sort().join(', ') +
699
+ c.dim(' (opencastle add <pack> brings one back)'),
700
+ )
701
+ }
702
+ if (teamWritten.size > 0) {
703
+ console.log(` ${c.green('✓')} Wrote the team's MCP server(s) as defined: ${[...teamWritten].sort().join(', ')}`)
704
+ }
705
+ if (teamRemoved.size > 0) {
706
+ console.log(
707
+ ` ${c.yellow('-')} Removed ${teamRemoved.size} MCP server(s) the team's layers retired or its policy does not allow: ` +
708
+ [...teamRemoved].sort().join(', '),
709
+ )
710
+ }
711
+ if (usesTeamSources(resolved)) {
712
+ const baselines = resolved.layers.filter((l) => l.kind === 'baseline')
713
+ const own = [...resolved.items.values()].filter((i) => i.layer !== 'opencastle').length
714
+ console.log(
715
+ ` ${c.green('✓')} Compiled ${baselines.length > 0 ? `${baselines.map((b) => `${b.id}${b.version ? ` ${b.version}` : ''}`).join(', ')} and ` : ''}` +
716
+ `this project's own sources${own > 0 ? ` (${own} item${own === 1 ? '' : 's'})` : ''}`,
717
+ )
718
+ }
719
+ if (lockWritten) {
720
+ console.log(` ${c.green('✓')} Updated ${LOCK_REL} ${c.dim('(opencastle review explains the change)')}`)
721
+ }
722
+ if (lockHeld) {
723
+ console.log(` ${c.yellow('!')} Left ${LOCK_REL} as it was until every MCP config can be read — fix the file named below and sync again.`)
724
+ }
725
+ // An integration the stack includes but the policy refuses is left out on
726
+ // purpose; saying nothing made `add stripe` look like it had worked.
727
+ if (resolved.blocked.size > 0) {
728
+ console.log(` ${c.yellow('-')} Left out ${resolved.blocked.size} MCP server(s):`)
729
+ for (const [key, why] of [...resolved.blocked].sort(([a], [b]) => (a < b ? -1 : 1))) {
730
+ console.log(` ${key} ${c.dim(`— ${why}`)}`)
731
+ }
732
+ }
733
+ const teamWarnings = resolved.issues.filter((i) => i.level === 'warning')
734
+ if (teamWarnings.length > 0) {
735
+ console.log(`\n ${c.yellow('!')} ${teamWarnings.length} note(s) about the team's sources:`)
736
+ for (const line of formatIssues(teamWarnings)) console.log(` ${c.dim(line)}`)
737
+ }
553
738
  for (const file of unreadable) {
554
739
  const [abs, why] = file.split('\u0000')
555
740
  // Reported project-relative, whichever layer recorded it. `copyDir` works in
@@ -662,7 +847,7 @@ export default async function update({
662
847
  // The old diff-against-previous-stack version was inside the `stackChanged`
663
848
  // gate, so `opencastle add sentry` never mentioned the token it now needs.
664
849
  if (newStack) {
665
- const envVars = getRequiredMcpEnvVars(newStack, repoInfo)
850
+ const envVars = requiredEnvVars(resolved, newStack, repoInfo)
666
851
  const envFile = await readFile(resolve(projectRoot, '.env'), 'utf8').catch(() => '')
667
852
  const missing = envVars.filter(({ envVar }) => !isEnvVarSatisfied(envVar, envFile))
668
853
  if (missing.length > 0) {
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Just enough semver to answer one question: does the running OpenCastle
3
+ * satisfy the range a team pinned in `.opencastle/config.json`?
4
+ *
5
+ * A team whose members run different OpenCastle versions gets a pull request
6
+ * war: each `sync` rewrites the generated files to its own release's output and
7
+ * the next person's `sync` rewrites them back. The version belongs to the
8
+ * project, like any other tool's, so the project can say which one it wants.
9
+ *
10
+ * Supported: exact (`0.36.0`), `^`, `~`, x-ranges (`0.36.x`, `0.x`, `*`),
11
+ * comparators (`>=0.36.0 <0.38.0`) and `||` alternatives. Prereleases compare
12
+ * by their dotted identifiers. That covers every range npm users write for a
13
+ * CLI; anything else is reported as unparseable rather than guessed at.
14
+ */
15
+
16
+ type Version = [number, number, number, string[]]
17
+
18
+ const VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/
19
+
20
+ export function parseVersion(text: string): Version | null {
21
+ const m = VERSION.exec(text.trim())
22
+ if (!m) return null
23
+ return [Number(m[1]), Number(m[2]), Number(m[3]), m[4] ? m[4].split('.') : []]
24
+ }
25
+
26
+ function comparePre(a: string[], b: string[]): number {
27
+ // A release outranks any of its prereleases.
28
+ if (a.length === 0 || b.length === 0) return a.length === b.length ? 0 : a.length === 0 ? 1 : -1
29
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
30
+ if (a[i] === undefined) return -1
31
+ if (b[i] === undefined) return 1
32
+ const an = /^\d+$/.test(a[i])
33
+ const bn = /^\d+$/.test(b[i])
34
+ if (an && bn) {
35
+ const d = Number(a[i]) - Number(b[i])
36
+ if (d !== 0) return d < 0 ? -1 : 1
37
+ } else if (an !== bn) {
38
+ return an ? -1 : 1
39
+ } else if (a[i] !== b[i]) {
40
+ return a[i] < b[i] ? -1 : 1
41
+ }
42
+ }
43
+ return 0
44
+ }
45
+
46
+ export function compareVersions(a: Version, b: Version): number {
47
+ for (let i = 0; i < 3; i++) {
48
+ const d = (a[i] as number) - (b[i] as number)
49
+ if (d !== 0) return d < 0 ? -1 : 1
50
+ }
51
+ return comparePre(a[3], b[3])
52
+ }
53
+
54
+ type Comparator = { op: '>=' | '>' | '<=' | '<' | '='; version: Version }
55
+
56
+ /** `1`, `1.2`, `1.x`, `1.2.*` → the parts given, with wildcards as null. */
57
+ function partial(text: string): [number | null, number | null, number | null, string[]] | null {
58
+ const m = /^v?(\d+|x|X|\*)(?:\.(\d+|x|X|\*))?(?:\.(\d+|x|X|\*))?(?:-([0-9A-Za-z.-]+))?$/.exec(text)
59
+ if (!m) return null
60
+ const num = (s: string | undefined): number | null =>
61
+ s === undefined || /^[xX*]$/.test(s) ? null : Number(s)
62
+ return [num(m[1]), num(m[2]), num(m[3]), m[4] ? m[4].split('.') : []]
63
+ }
64
+
65
+ function v(major: number, minor: number, patch: number, pre: string[] = []): Version {
66
+ return [major, minor, patch, pre]
67
+ }
68
+
69
+ /** One space-separated term of a range, as comparators. Null when unreadable. */
70
+ function term(raw: string): Comparator[] | null {
71
+ if (raw === '*' || raw === 'x' || raw === 'X' || raw === '') return []
72
+ const op = /^(\^|~|>=|<=|>|<|=)?(.*)$/.exec(raw)
73
+ if (!op) return null
74
+ const sign = op[1] ?? ''
75
+ const p = partial(op[2])
76
+ if (!p) return null
77
+ const [ma, mi, pa, pre] = p
78
+ if (ma === null) return sign === '' || sign === '=' || sign === '>=' ? [] : null
79
+
80
+ if (sign === '^') {
81
+ const lo = v(ma, mi ?? 0, pa ?? 0, pre)
82
+ let hi: Version
83
+ if (ma > 0 || mi === null) hi = v(ma + 1, 0, 0, ['0'])
84
+ else if (mi > 0 || pa === null) hi = v(0, mi + 1, 0, ['0'])
85
+ else hi = v(0, 0, pa + 1, ['0'])
86
+ return [{ op: '>=', version: lo }, { op: '<', version: hi }]
87
+ }
88
+ if (sign === '~') {
89
+ const lo = v(ma, mi ?? 0, pa ?? 0, pre)
90
+ const hi = mi === null ? v(ma + 1, 0, 0, ['0']) : v(ma, mi + 1, 0, ['0'])
91
+ return [{ op: '>=', version: lo }, { op: '<', version: hi }]
92
+ }
93
+ if (sign === '' || sign === '=') {
94
+ if (mi === null) return [{ op: '>=', version: v(ma, 0, 0) }, { op: '<', version: v(ma + 1, 0, 0, ['0']) }]
95
+ if (pa === null) return [{ op: '>=', version: v(ma, mi, 0) }, { op: '<', version: v(ma, mi + 1, 0, ['0']) }]
96
+ return [{ op: '=', version: v(ma, mi, pa, pre) }]
97
+ }
98
+ // Comparators with a partial version: `>=1.2` means `>=1.2.0`, `<1.2` means `<1.2.0`,
99
+ // `>1.2` means `>=1.3.0`, `<=1.2` means `<1.3.0`.
100
+ if (sign === '>=' || sign === '<') {
101
+ return [{ op: sign, version: v(ma, mi ?? 0, pa ?? 0, pre) }]
102
+ }
103
+ if (pa !== null && mi !== null) return [{ op: sign as Comparator['op'], version: v(ma, mi, pa, pre) }]
104
+ const next = mi === null ? v(ma + 1, 0, 0) : v(ma, mi + 1, 0)
105
+ return [{ op: sign === '>' ? '>=' : '<', version: next }]
106
+ }
107
+
108
+ function test(version: Version, c: Comparator): boolean {
109
+ const d = compareVersions(version, c.version)
110
+ switch (c.op) {
111
+ case '>=': return d >= 0
112
+ case '>': return d > 0
113
+ case '<=': return d <= 0
114
+ case '<': return d < 0
115
+ case '=': return d === 0
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Does `version` satisfy `range`? `null` when either cannot be read — the
121
+ * caller says so instead of treating an unreadable range as a pass or a fail.
122
+ */
123
+ export function satisfies(version: string, range: string): boolean | null {
124
+ const ver = parseVersion(version)
125
+ if (!ver) return null
126
+ let any = false
127
+ for (const alt of range.split('||')) {
128
+ // `1.2.3 - 2.0.0` hyphen ranges.
129
+ const hyphen = /^\s*(\S+)\s+-\s+(\S+)\s*$/.exec(alt)
130
+ // `>= 1.2.0`, written with a space, is one comparator.
131
+ const joined = alt.trim().replace(/(>=|<=|>|<|=|\^|~)\s+/g, '$1')
132
+ const parts = hyphen ? [`>=${hyphen[1]}`, `<=${hyphen[2]}`] : joined.split(/\s+/)
133
+ const comparators: Comparator[] = []
134
+ for (const part of parts) {
135
+ const t = term(part)
136
+ if (t === null) return null
137
+ comparators.push(...t)
138
+ }
139
+ // A prerelease only satisfies a range that names a prerelease of the same
140
+ // version, as npm has it — `^0.36.0` must not accept `0.37.0-rc.1`.
141
+ if (ver[3].length > 0) {
142
+ const allowed = comparators.some(
143
+ (c) => c.version[3].length > 0 && c.version[0] === ver[0] && c.version[1] === ver[1] && c.version[2] === ver[2],
144
+ )
145
+ if (!allowed) continue
146
+ }
147
+ if (comparators.every((c) => test(ver, c))) any = true
148
+ }
149
+ return any
150
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The plugin guide takes its MCP configs from the plugin sources.
3
+ *
4
+ * It used to carry hand-copied JSON, and when the sources were pinned and three
5
+ * packages that do not exist were replaced, sixteen cards kept the old configs —
6
+ * `@latest`, and the dead packages — because nothing tied them to the code. The
7
+ * page now renders each snippet from `PLUGINS`; these tests keep it that way.
8
+ */
9
+ import { readFileSync } from 'node:fs'
10
+ import { join, resolve } from 'node:path'
11
+ import { describe, it, expect } from 'vitest'
12
+ import { PLUGINS } from '../orchestrator/plugins/index.js'
13
+
14
+ const page = readFileSync(
15
+ join(resolve(import.meta.dirname, '..', '..'), 'website', 'src', 'pages', 'docs', 'plugins.astro'),
16
+ 'utf8',
17
+ )
18
+ const rendered = [...page.matchAll(/mcpSnippet\('([\w-]+)'\)/g)].map((m) => m[1])
19
+ const withServer = Object.values(PLUGINS).filter((p) => p.mcpServerKey && p.mcpConfig)
20
+
21
+ describe('the plugin guide', () => {
22
+ it('writes no MCP config by hand', () => {
23
+ expect(page.match(/"(?:command|args|url|type)"\s*:/g) ?? []).toEqual([])
24
+ })
25
+
26
+ it('renders only servers that exist', () => {
27
+ const ids = new Set(withServer.map((p) => p.id))
28
+ expect(rendered.filter((id) => !ids.has(id))).toEqual([])
29
+ })
30
+
31
+ it('shows every server a plugin ships', () => {
32
+ const shown = new Set(rendered)
33
+ expect(withServer.map((p) => p.id).filter((id) => !shown.has(id))).toEqual([])
34
+ })
35
+
36
+ it('names no package that is not on npm', () => {
37
+ for (const dead of ['@anthropic/figma-mcp', '@anthropic/prisma-mcp', '@mseep/linear-mcp', '>netlify-mcp<']) {
38
+ expect(page).not.toContain(dead)
39
+ }
40
+ })
41
+ })