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
@@ -4,8 +4,13 @@ import { tmpdir } from 'node:os'
4
4
  import { readManifest } from './manifest.js'
5
5
  import { IDE_ADAPTERS } from './adapters/index.js'
6
6
  import { detectRepoInfo, mergeStackIntoRepoInfo } from './detect.js'
7
- import { getMcpConfigRelPath } from './mcp.js'
8
- import { resolveStack } from './stack-config.js'
7
+ import { getMcpConfigRelPath, expectedTeamEntries } from './mcp.js'
8
+ import { resolveStack, getIncludedMcpServers } from './stack-config.js'
9
+ import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
10
+ import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
11
+ import { parseVersion, compareVersions } from './version-range.js'
12
+ import { buildLock, serializeLock, LOCK_REL, priorTeam } from './lock.js'
13
+ import { PLUGINS } from '../orchestrator/plugins/index.js'
9
14
  import { gitignoreNeedsRebuild } from './gitignore.js'
10
15
  import {
11
16
  carriesLegacyBody,
@@ -16,6 +21,7 @@ import {
16
21
  diagnoseManagedFile,
17
22
  } from './managed-block.js'
18
23
  import { c } from './prompt.js'
24
+ import { reportToGitHub, COMPARISON_FAILED } from './github-report.js'
19
25
  import type { CliContext, IdeChoice, StackConfig } from './types.js'
20
26
 
21
27
  /**
@@ -29,18 +35,33 @@ import type { CliContext, IdeChoice, StackConfig } from './types.js'
29
35
  */
30
36
 
31
37
  /**
38
+ * `outdated` is an MCP config holding a server entry still exactly as an
39
+ * earlier release wrote it, whose default has since changed — a retired
40
+ * package, an `@latest`, a shape the assistant cannot load. `sync` moves those
41
+ * entries forward and leaves everything else in the file alone.
42
+ *
32
43
  * `unreducible` is the state no command will change: a co-owned file holding
33
44
  * more than one block *and* a marker that pairs with nothing. It is drift, so
34
45
  * CI must fail — but the remedy is a person, and printing "Fix: opencastle
35
46
  * sync" beside it made the check permanently red on a command that by design
36
47
  * refuses to touch the file.
37
48
  */
38
- export type DriftKind = 'missing' | 'changed' | 'extra' | 'unreducible'
49
+ export type DriftKind = 'missing' | 'changed' | 'extra' | 'unreducible' | 'outdated'
39
50
 
40
51
  export interface Drift {
41
52
  ide: string
42
53
  path: string
43
54
  kind: DriftKind
55
+ /**
56
+ * Set on drift the MCP audit found. A broken server only a person can fix is
57
+ * a reason for CI to fail, but not a reason for `sync` to recompile or for
58
+ * the status line to say generated files are stale — neither is true of it.
59
+ *
60
+ * `team` is a problem in the team's own sources — a config that will not
61
+ * parse, a baseline that is not installed, a policy the sources break. The
62
+ * comparison cannot run until it is fixed, and `sync` refuses to compile.
63
+ */
64
+ origin?: 'mcp' | 'team' | 'version'
44
65
  /** The classifier's own words, so the checker and `doctor` cannot diverge. */
45
66
  detail?: string
46
67
  /** What resolves it, per entry — these do not share a remedy. */
@@ -55,6 +76,14 @@ export interface CheckReport {
55
76
  checked: number
56
77
  }
57
78
 
79
+ /** The plugin ids behind server keys, for an `opencastle add` line. */
80
+ function pluginIds(servers: string[]): string[] {
81
+ const ids = Object.values(PLUGINS)
82
+ .filter((p) => p.mcpServerKey && servers.includes(p.mcpServerKey))
83
+ .map((p) => p.id)
84
+ return [...new Set(ids)]
85
+ }
86
+
58
87
  /** Every file under a directory, relative to it, sorted for stable output. */
59
88
  function filesUnder(root: string): string[] {
60
89
  const out: string[] = []
@@ -135,6 +164,7 @@ function comparePath(
135
164
  projectRoot: string,
136
165
  ide: string,
137
166
  drift: Drift[],
167
+ owns?: (_rel: string) => boolean,
138
168
  ): number {
139
169
  const fresh = resolve(freshRoot, managedPath)
140
170
  const actual = resolve(projectRoot, managedPath)
@@ -179,7 +209,11 @@ function comparePath(
179
209
  const expected = new Set(generated)
180
210
  for (const rel of filesUnder(actual)) {
181
211
  if (expected.has(rel)) continue
182
- drift.push({ ide, path: `${managedPath.replace(/\/$/, '')}/${rel}`, kind: 'extra' })
212
+ const shown = `${managedPath.replace(/\/$/, '')}/${rel}`
213
+ // A file the target shares the directory with someone over — their own
214
+ // prompt beside ours in `.github/prompts/` — is not drift.
215
+ if (owns && !owns(shown)) continue
216
+ drift.push({ ide, path: shown, kind: 'extra' })
183
217
  }
184
218
  return checked
185
219
  }
@@ -237,27 +271,133 @@ export async function buildCheckReport(pkgRoot: string, projectRoot: string): Pr
237
271
  const stack: StackConfig = resolveStack({ ...manifest, ides })
238
272
  const repoInfo = manifest.repoInfo ?? mergeStackIntoRepoInfo(await detectRepoInfo(projectRoot), stack)
239
273
 
274
+ // An older OpenCastle than the one that compiled the project cannot say
275
+ // whether the project is right: its output is not the project's. Comparing
276
+ // anyway reported every changed file and prescribed a `sync` that refuses.
277
+ {
278
+ const running = cliVersionOf(pkgRoot)
279
+ const mine = parseVersion(running)
280
+ const theirs = parseVersion(manifest.version)
281
+ if (mine && theirs && compareVersions(mine, theirs) < 0) {
282
+ return {
283
+ installed: true,
284
+ ides,
285
+ checked: 0,
286
+ drift: [
287
+ {
288
+ ide: 'all',
289
+ path: '.opencastle/manifest.json',
290
+ kind: 'unreducible',
291
+ origin: 'version',
292
+ detail: `compiled by OpenCastle ${manifest.version}; this is ${running}, so nothing was compared`,
293
+ fix: `run the project's version — npx opencastle@${manifest.version} sync --check, or add opencastle to devDependencies`,
294
+ },
295
+ ],
296
+ }
297
+ }
298
+ }
299
+
300
+ // The team's layers, resolved exactly as `sync` resolves them. A problem in
301
+ // them — a baseline not installed, a config that does not parse, a server
302
+ // the policy forbids — means there is nothing to compare against: say that,
303
+ // once, instead of reporting every generated file as drifted.
304
+ const resolved = resolveSources({ pkgRoot, projectRoot, stack, repoInfo })
305
+ if (hasErrors(resolved)) {
306
+ return {
307
+ installed: true,
308
+ ides,
309
+ checked: 0,
310
+ drift: resolved.issues
311
+ .filter((i) => i.level === 'error')
312
+ .map((i) => ({
313
+ ide: 'all',
314
+ path: i.where,
315
+ kind: 'unreducible' as const,
316
+ detail: i.message,
317
+ fix: i.fix ?? 'fix it, then run opencastle sync',
318
+ origin: 'team' as const,
319
+ })),
320
+ }
321
+ }
322
+ const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
323
+ try {
324
+ return await compareProject(pkgRoot, projectRoot, ides, stack, repoInfo, source)
325
+ } finally {
326
+ source.dispose()
327
+ }
328
+ }
329
+
330
+ async function compareProject(
331
+ pkgRoot: string,
332
+ projectRoot: string,
333
+ ides: IdeChoice[],
334
+ stack: StackConfig,
335
+ repoInfo: ReturnType<typeof mergeStackIntoRepoInfo>,
336
+ source: CompileSource,
337
+ ): Promise<CheckReport> {
338
+ const { resolved } = source
240
339
  const drift: Drift[] = []
241
340
  let checked = 0
341
+ // The servers a rebuild keeps, so what the MCP audit predicts is what `sync` does.
342
+ const included = getIncludedMcpServers(stack, repoInfo)
242
343
 
243
344
  for (const ide of ides) {
244
345
  const adapter = await IDE_ADAPTERS[ide]()
245
346
  const scratch = mkdtempSync(join(tmpdir(), `opencastle-check-${ide}-`))
246
347
  try {
247
- await adapter.install(pkgRoot, scratch, stack, repoInfo)
348
+ await adapter.install(pkgRoot, scratch, stack, repoInfo, source)
248
349
  // Framework and merged paths are compared. Customizable paths are the
249
350
  // user's by design — reporting those as drift would make the check useless.
250
351
  // Merged paths must be included or the root instruction file, the one file
251
352
  // most likely to be edited by hand, would be the only thing never checked.
252
353
  const managed = adapter.getManagedPaths()
253
354
  for (const managedPath of [...managed.framework, ...(managed.merged ?? [])]) {
254
- checked += comparePath(managedPath, scratch, projectRoot, ide, drift)
355
+ checked += comparePath(managedPath, scratch, projectRoot, ide, drift, adapter.ownsFile
356
+ ? (rel) => adapter.ownsFile!(rel, projectRoot)
357
+ : undefined)
358
+ }
359
+ // Output an earlier release left where this one no longer writes — a
360
+ // stale `/bug-fix` beside `/oc:bug-fix`. The next sync removes it.
361
+ for (const rel of adapter.getLegacyOutputs?.(projectRoot) ?? []) {
362
+ const detail = 'written by a release before the oc: namespace'
363
+ // A legacy prompt inside a compared directory is already reported.
364
+ const seen = drift.find((d) => d.ide === ide && d.path === rel)
365
+ if (seen) seen.detail = detail
366
+ else drift.push({ ide, path: rel, kind: 'extra', detail })
255
367
  }
256
368
  } finally {
257
369
  rmSync(scratch, { recursive: true, force: true })
258
370
  }
259
371
  }
260
372
 
373
+ // The lock: what every assistant is given, as `sync` would record it now.
374
+ // Compared like any generated file, because it is one — a stale lock is a
375
+ // review of something other than what was compiled.
376
+ {
377
+ const expected = serializeLock(buildLock(source, { ides, stack, repoInfo }))
378
+ const abs = resolve(projectRoot, LOCK_REL)
379
+ checked++
380
+ if (!existsSync(abs)) {
381
+ drift.push({ ide: 'all', path: LOCK_REL, kind: 'missing', detail: 'records what every assistant is given; sync writes it' })
382
+ } else {
383
+ let actual: string | null = null
384
+ try {
385
+ actual = normaliseEndings(readFileSync(abs, 'utf8'))
386
+ } catch (err) {
387
+ drift.push({
388
+ ide: 'all',
389
+ path: LOCK_REL,
390
+ kind: 'unreducible',
391
+ detail: `cannot be read — ${(err as Error).message}`,
392
+ fix: 'fix the permissions or delete the file, then run opencastle sync; this one needs a person',
393
+ })
394
+ }
395
+ if (actual !== null && actual !== expected) {
396
+ drift.push({ ide: 'all', path: LOCK_REL, kind: 'changed', detail: 'does not match what the sources compile to' })
397
+ }
398
+ }
399
+ }
400
+
261
401
  // A whole instruction set from an older release, sitting above our block.
262
402
  //
263
403
  // `sameContent` compares the block and finds it correct, so this passed the
@@ -367,11 +507,20 @@ export async function buildCheckReport(pkgRoot: string, projectRoot: string): Pr
367
507
  // split closed for `.gitignore`, on the other customizable path.
368
508
  {
369
509
  const seen = new Set<string>()
510
+ const definedIn = Object.fromEntries([...resolved.servers.values()].map((s) => [s.key, s.where]))
511
+ const teamFor = (ide: IdeChoice): TeamAuditContext => ({
512
+ expected: expectedTeamEntries(source.mcp, ide),
513
+ definedIn,
514
+ retired: source.mcp.retired,
515
+ blocked: resolved.blocked,
516
+ policy: resolved.policy,
517
+ })
370
518
  for (const ide of ides) {
371
519
  const rel = getMcpConfigRelPath(ide as IdeChoice)
372
520
  if (seen.has(rel)) continue
373
521
  seen.add(rel)
374
522
  const abs = resolve(projectRoot, rel)
523
+ const team = teamFor(ide)
375
524
  // `existsSync` is false both for a file that is absent and for one whose
376
525
  // parent we cannot read, and only the first is a reason to skip. Asking
377
526
  // for the stat separates them: an error here is a fault to report, not an
@@ -389,12 +538,20 @@ export async function buildCheckReport(pkgRoot: string, projectRoot: string): Pr
389
538
  detail: `cannot be read — ${(err as Error).message}`,
390
539
  fix: `fix the permissions on ${rel}, then run opencastle sync; this one needs a person`,
391
540
  })
541
+ continue
392
542
  }
393
543
  }
544
+ // No config is fine until the team defines servers every assistant
545
+ // should have: then the file is output `sync` owes.
546
+ const owed = Object.keys(team.expected)
547
+ if (owed.length > 0) {
548
+ drift.push({ ide, path: rel, kind: 'outdated', detail: `the team's servers sync writes: ${owed.join(', ')}`, fix: 'opencastle sync', origin: 'mcp' })
549
+ }
394
550
  continue
395
551
  }
552
+ let parsed: unknown
396
553
  try {
397
- JSON.parse(readFileSync(abs, 'utf8'))
554
+ parsed = JSON.parse(readFileSync(abs, 'utf8'))
398
555
  } catch (err) {
399
556
  drift.push({
400
557
  ide,
@@ -403,6 +560,51 @@ export async function buildCheckReport(pkgRoot: string, projectRoot: string): Pr
403
560
  detail: `cannot be read — ${(err as Error).message}`,
404
561
  fix: `fix or delete ${rel}, then run opencastle sync; this one needs a person`,
405
562
  })
563
+ continue
564
+ }
565
+ // What the servers in it launch, read by the same audit `doctor` runs, so
566
+ // the two cannot disagree: `doctor` failed on a remote server Claude Code
567
+ // never loads while this reported every file matching its source, and CI —
568
+ // the one place a team would see it — stayed green.
569
+ const audit = auditMcpConfig(parsed, ide as IdeChoice, included, team)
570
+ // Everything `sync` would change in the file, in one entry: entries it
571
+ // moves forward, and plugin servers the stack dropped, which it deletes.
572
+ // Leaving the second out let `doctor` say "sync removes it" while this
573
+ // passed and `sync` short-circuited — a remedy that did nothing.
574
+ const teamKeys = new Set(Object.keys(team.expected))
575
+ const container = (parsed as Record<string, unknown> | null)?.[ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers']
576
+ const present = new Set(container && typeof container === 'object' ? Object.keys(container as object) : [])
577
+ const pluginOutdated = audit.outdated.filter((k) => !teamKeys.has(k))
578
+ const teamMissing = audit.outdated.filter((k) => teamKeys.has(k) && !present.has(k))
579
+ const teamDiffers = audit.outdated.filter((k) => teamKeys.has(k) && present.has(k))
580
+ const changes = [
581
+ pluginOutdated.length > 0 ? `still an earlier OpenCastle default: ${pluginOutdated.join(', ')}` : '',
582
+ teamMissing.length > 0 ? `missing the team's servers, which sync adds: ${teamMissing.join(', ')}` : '',
583
+ teamDiffers.length > 0 ? `not as the team config defines them, so sync writes: ${teamDiffers.join(', ')}` : '',
584
+ audit.removed.length > 0
585
+ ? `not in this project's stack, so sync removes: ${audit.removed.join(', ')} ` +
586
+ `(opencastle add ${pluginIds(audit.removed).join(' ')} keeps them)`
587
+ : '',
588
+ audit.blockedByPolicy.length > 0
589
+ ? `sync removes ${audit.blockedByPolicy.map((k) => `${k} (${resolved.blocked.get(k) ?? "refused by the team's MCP policy"})`).join(', ')}`
590
+ : '',
591
+ audit.retired.length > 0 ? `no longer defined by any team layer, so sync removes: ${audit.retired.join(', ')}` : '',
592
+ ].filter(Boolean)
593
+ if (changes.length > 0) {
594
+ drift.push({ ide, path: rel, kind: 'outdated', detail: changes.join('; '), fix: 'opencastle sync', origin: 'mcp' })
595
+ }
596
+ // Failures `sync` will not clear — an entry someone edited, or their own.
597
+ // Unpinned ones are warnings in `doctor` and are not drift here either.
598
+ const stuck = audit.findings.filter((f) => isFailure(f, resolved.policy) && f.sync === 'keeps')
599
+ if (stuck.length > 0) {
600
+ drift.push({
601
+ ide,
602
+ path: rel,
603
+ kind: 'unreducible',
604
+ detail: stuck.map((f) => describeFindingUnder(f, resolved.policy)).join('; '),
605
+ fix: remedyFor(stuck, rel),
606
+ origin: 'mcp',
607
+ })
406
608
  }
407
609
  }
408
610
  }
@@ -485,23 +687,59 @@ function render(report: CheckReport): void {
485
687
  const missing = report.drift.filter((d) => d.kind === 'missing')
486
688
  const changed = report.drift.filter((d) => d.kind === 'changed')
487
689
  const extra = report.drift.filter((d) => d.kind === 'extra')
690
+ const outdated = report.drift.filter((d) => d.kind === 'outdated')
488
691
  const unreducible = report.drift.filter((d) => d.kind === 'unreducible')
489
692
 
490
- console.log(`\n ${c.red('✗')} ${report.drift.length} file(s) differ from their sources.\n`)
693
+ // A broken MCP server nobody generated is not a file that "differs from its
694
+ // source"; say what it is when it is all there is.
695
+ const mcpOnly = report.drift.every((d) => d.origin === 'mcp' && d.kind === 'unreducible')
696
+ const teamOnly = report.drift.every((d) => d.origin === 'team')
697
+ const olderCli = report.drift.some((d) => d.origin === 'version')
698
+ console.log(
699
+ olderCli
700
+ ? `\n ${c.red('✗')} This OpenCastle is older than the one that compiled the project.\n`
701
+ : teamOnly
702
+ ? `\n ${c.red('✗')} The team's sources have ${report.drift.length} problem(s), so nothing could be compared.\n`
703
+ : mcpOnly
704
+ ? `\n ${c.red('✗')} ${report.drift.length} MCP config(s) have a server only a person can fix.\n`
705
+ : `\n ${c.red('✗')} ${report.drift.length} file(s) differ from their sources.\n`,
706
+ )
491
707
 
492
- if (changed.length > 0) {
493
- console.log(` ${c.bold('Edited in place')} ${c.dim('(your change will be lost on the next sync)')}`)
494
- for (const d of changed) console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.ide})`)}`)
708
+ // The lock is not edited by anyone; when it differs, the sources moved and
709
+ // nobody has synced. Filed under "edited in place" it told people they had
710
+ // an edit to lose.
711
+ const lockDrift = [...changed, ...missing].filter((d) => d.path === LOCK_REL)
712
+ const changedFiles = changed.filter((d) => d.path !== LOCK_REL)
713
+ const missingFiles = missing.filter((d) => d.path !== LOCK_REL)
714
+ if (lockDrift.length > 0) {
715
+ console.log(` ${c.bold('Sources changed since the last sync')}`)
716
+ for (const d of lockDrift) console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.detail ?? d.kind})`)}`)
495
717
  console.log('')
496
718
  }
497
- if (missing.length > 0) {
719
+ if (changedFiles.length > 0) {
720
+ console.log(` ${c.bold('Differs from a fresh compile')} ${c.dim('(an edit here is lost on the next sync — make it in .opencastle/)')}`)
721
+ for (const d of changedFiles) console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.ide})`)}`)
722
+ console.log('')
723
+ }
724
+ if (missingFiles.length > 0) {
498
725
  console.log(` ${c.bold('Never generated')}`)
499
- for (const d of missing) console.log(` ${c.red('-')} ${d.path} ${c.dim(`(${d.ide})`)}`)
726
+ for (const d of missingFiles) console.log(` ${c.red('-')} ${d.path} ${c.dim(`(${d.ide})`)}`)
500
727
  console.log('')
501
728
  }
502
729
  if (extra.length > 0) {
503
- console.log(` ${c.bold('Added by hand')} ${c.dim('(deleted on the next sync)')}`)
504
- for (const d of extra) console.log(` ${c.red('+')} ${d.path} ${c.dim(`(${d.ide})`)}`)
730
+ console.log(` ${c.bold('Not produced by any source')} ${c.dim('(removed on the next sync)')}`)
731
+ for (const d of extra) console.log(` ${c.red('+')} ${d.path} ${c.dim(`(${d.ide}${d.detail ? ` — ${d.detail}` : ''})`)}`)
732
+ console.log('')
733
+ }
734
+
735
+ if (outdated.length > 0) {
736
+ console.log(
737
+ ` ${c.bold('MCP servers sync would change')} ${c.dim('(integration defaults move forward, team servers are written as defined; entries you added or edited stay yours)')}`,
738
+ )
739
+ for (const d of outdated) {
740
+ console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.ide})`)}`)
741
+ if (d.detail) console.log(` ${c.dim(d.detail)}`)
742
+ }
505
743
  console.log('')
506
744
  }
507
745
 
@@ -525,7 +763,12 @@ function render(report: CheckReport): void {
525
763
  // Only when something here is actually fixable by it. `sync` was printed
526
764
  // unconditionally, so a file the writer refuses to touch produced a red check
527
765
  // recommending the command that refuses — CI red forever on a no-op.
528
- if (report.drift.length > unreducible.length) {
766
+ if (report.drift.length > unreducible.length && unreducible.length > 0) {
767
+ // Both kinds: `sync` alone may not clear the rest — the lock, for one, is
768
+ // held back while an MCP config cannot be read.
769
+ console.log(` ${c.bold('Fix:')} ${c.dim('the ones that need a person first, then')} ${c.cyan('opencastle sync')}`)
770
+ console.log(` ${c.dim('To keep an edit, move it into .opencastle/ instead — that directory is yours.')}\n`)
771
+ } else if (report.drift.length > unreducible.length) {
529
772
  console.log(` ${c.bold('Fix:')} ${c.cyan('opencastle sync')}`)
530
773
  console.log(` ${c.dim('To keep an edit, move it into .opencastle/ instead — that directory is yours.')}\n`)
531
774
  } else {
@@ -553,13 +796,14 @@ export async function runCheck({ pkgRoot, args }: CliContext): Promise<void> {
553
796
  ide: 'all',
554
797
  path: (err as Error).message,
555
798
  kind: 'unreducible',
556
- detail: 'the comparison could not run',
799
+ detail: COMPARISON_FAILED,
557
800
  fix: 'fix the path named above, then run opencastle sync; this one needs a person',
558
801
  },
559
802
  ],
560
803
  }
561
804
  if (args.includes('--json')) console.log(JSON.stringify(failure, null, 2))
562
805
  else render(failure)
806
+ reportToGitHub(failure, process.cwd(), { json: args.includes('--json') })
563
807
  process.exit(1)
564
808
  }
565
809
 
@@ -568,6 +812,9 @@ export async function runCheck({ pkgRoot, args }: CliContext): Promise<void> {
568
812
  } else {
569
813
  render(report)
570
814
  }
815
+ // On GitHub Actions only: annotations on the files in the pull request, and a
816
+ // table on the run's summary page. Everywhere else this is a no-op.
817
+ reportToGitHub(report, process.cwd(), { json: args.includes('--json') })
571
818
 
572
819
  if (!report.installed || report.drift.length > 0) process.exit(1)
573
820
  }
package/src/cli/sync.ts CHANGED
@@ -20,6 +20,8 @@ const SYNC_HELP = `
20
20
  --check Report drift and exit non-zero; writes nothing (for CI)
21
21
  --dry-run Preview what would change
22
22
  --force Sync even when versions match
23
+ --allow-downgrade Recompile with this OpenCastle even though a newer one
24
+ compiled the project
23
25
  --reconfigure Re-run IDE and stack selection
24
26
  --yes Skip the confirmation prompt
25
27
  --json Machine-readable output (with --check)
@@ -0,0 +1,195 @@
1
+ /**
2
+ * The team-facing paths, driven through the CLI the way a person and a CI job
3
+ * would drive them.
4
+ *
5
+ * Two promises are checked end to end here because each one failed in
6
+ * development in a way unit tests did not see: `doctor` prescribed `sync` for a
7
+ * stale MCP server and `sync` then reported nothing to do; and drift has to show
8
+ * up where a pull request's author will read it, not only in a job log.
9
+ */
10
+ import { mkdtempSync, writeFileSync, readFileSync, rmSync, existsSync, appendFileSync } from 'node:fs'
11
+ import { tmpdir } from 'node:os'
12
+ import { join, resolve } from 'node:path'
13
+ import { execFileSync } from 'node:child_process'
14
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
15
+
16
+ const repoRoot = resolve(import.meta.dirname, '..', '..')
17
+ const cli = join(repoRoot, 'bin', 'cli.mjs')
18
+ const built = existsSync(join(repoRoot, 'dist', 'cli', 'doctor.js'))
19
+
20
+ function run(dir: string, args: string[], env: NodeJS.ProcessEnv = {}): { code: number; out: string } {
21
+ // GitHub's own variables are stripped, so a run of this suite inside Actions
22
+ // does not report to the job it is running in.
23
+ const base = { ...process.env }
24
+ for (const k of Object.keys(base)) if (k.startsWith('GITHUB_')) delete base[k]
25
+ try {
26
+ const out = execFileSync('node', [cli, ...args], {
27
+ cwd: dir,
28
+ encoding: 'utf8',
29
+ stdio: ['ignore', 'pipe', 'pipe'],
30
+ env: { ...base, ...env },
31
+ })
32
+ return { code: 0, out }
33
+ } catch (err) {
34
+ const e = err as { status?: number; stdout?: string; stderr?: string }
35
+ return { code: e.status ?? 1, out: `${e.stdout ?? ''}${e.stderr ?? ''}` }
36
+ }
37
+ }
38
+
39
+ describe.skipIf(!built)('a stale MCP default is fixed by the command doctor names', () => {
40
+ let dir: string
41
+ beforeEach(() => {
42
+ dir = mkdtempSync(join(tmpdir(), 'team-mcp-'))
43
+ execFileSync('git', ['init', '-q'], { cwd: dir })
44
+ writeFileSync(join(dir, 'CLAUDE.md'), '# Ours\n')
45
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ dependencies: { '@supabase/supabase-js': '^2.0.0' } }))
46
+ expect(run(dir, ['init', '--yes']).code).toBe(0)
47
+ })
48
+ afterEach(() => {
49
+ rmSync(dir, { recursive: true, force: true })
50
+ })
51
+
52
+ it('doctor and CI both fail on it, sync at the same version fixes it, both pass', () => {
53
+ // What every release before this one wrote into .mcp.json for Supabase.
54
+ writeFileSync(
55
+ join(dir, '.mcp.json'),
56
+ JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp' } } }, null, 2) + '\n',
57
+ )
58
+
59
+ const before = run(dir, ['doctor'])
60
+ expect(before.code).toBe(1)
61
+ expect(before.out).toContain('opencastle sync fixes Supabase')
62
+ // The check a team runs in CI must not be green over what doctor fails.
63
+ const check = run(dir, ['sync', '--check'])
64
+ expect(check.code).toBe(1)
65
+ expect(check.out).toContain('still an earlier OpenCastle default: Supabase')
66
+
67
+ const sync = run(dir, ['sync', '--yes'])
68
+ expect(sync.code).toBe(0)
69
+ expect(sync.out).toContain('Moved 1 MCP server(s) to the current default: Supabase')
70
+
71
+ const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
72
+ expect(config.mcpServers.Supabase).toEqual({ type: 'http', url: 'https://mcp.supabase.com/mcp' })
73
+ expect(run(dir, ['doctor']).code).toBe(0)
74
+ expect(run(dir, ['sync', '--check']).code).toBe(0)
75
+ })
76
+
77
+ it('an edited entry: the remedy doctor names brings back the current default', () => {
78
+ // Edited since OpenCastle wrote it, so sync must leave it — and doctor must
79
+ // not say otherwise.
80
+ writeFileSync(
81
+ join(dir, '.mcp.json'),
82
+ JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp', note: 'ours' } } }, null, 2) + '\n',
83
+ )
84
+ const doctor = run(dir, ['doctor'])
85
+ expect(doctor.code).toBe(1)
86
+ expect(doctor.out).toContain('delete the entry and run opencastle sync --force')
87
+ expect(run(dir, ['sync', '--check']).code).toBe(1)
88
+
89
+ // Follow it literally.
90
+ const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
91
+ delete config.mcpServers.Supabase
92
+ writeFileSync(join(dir, '.mcp.json'), JSON.stringify(config, null, 2) + '\n')
93
+ expect(run(dir, ['sync', '--force', '--yes']).code).toBe(0)
94
+ const after = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
95
+ expect(after.mcpServers.Supabase).toEqual({ type: 'http', url: 'https://mcp.supabase.com/mcp' })
96
+ expect(run(dir, ['doctor']).code).toBe(0)
97
+ })
98
+
99
+ it('a plugin server the stack dropped: doctor, CI and sync agree it goes', () => {
100
+ // An old Figma default in a project whose stack has no Figma.
101
+ const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
102
+ config.mcpServers.Figma = {
103
+ command: 'npx',
104
+ args: ['-y', '@anthropic/figma-mcp@latest'],
105
+ env: { FIGMA_ACCESS_TOKEN: '${FIGMA_ACCESS_TOKEN}' },
106
+ }
107
+ writeFileSync(join(dir, '.mcp.json'), JSON.stringify(config, null, 2) + '\n')
108
+
109
+ const doctor = run(dir, ['doctor'])
110
+ expect(doctor.code).toBe(1)
111
+ expect(doctor.out).toContain('opencastle sync removes Figma')
112
+ const check = run(dir, ['sync', '--check'])
113
+ expect(check.code).toBe(1)
114
+ expect(check.out).toContain('so sync removes: Figma')
115
+
116
+ const sync = run(dir, ['sync', '--yes'])
117
+ expect(sync.out).toContain('Removed 1 MCP server(s)')
118
+ expect(JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8')).mcpServers.Figma).toBeUndefined()
119
+ expect(run(dir, ['doctor']).code).toBe(0)
120
+ expect(run(dir, ['sync', '--check']).code).toBe(0)
121
+ })
122
+
123
+ it('a broken server of the user’s own fails CI, and sync leaves the repo alone', () => {
124
+ const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
125
+ config.mcpServers.context7 = { url: 'https://mcp.context7.com/mcp' }
126
+ writeFileSync(join(dir, '.mcp.json'), JSON.stringify(config, null, 2) + '\n')
127
+
128
+ const check = run(dir, ['sync', '--check'])
129
+ expect(check.code).toBe(1)
130
+ expect(check.out).toContain('only a person can fix')
131
+ expect(check.out).toContain('fix context7 by hand')
132
+
133
+ // Recompiling cannot fix it, so sync must not rewrite committed files for it.
134
+ const manifest = join(dir, '.opencastle', 'manifest.json')
135
+ const before = readFileSync(manifest, 'utf8')
136
+ const sync = run(dir, ['sync', '--yes'])
137
+ expect(sync.out).toContain('Everything matches its sources')
138
+ expect(readFileSync(manifest, 'utf8')).toBe(before)
139
+
140
+ // And the front door does not call it stale output.
141
+ expect(run(dir, []).out).not.toContain('no longer match their sources')
142
+ })
143
+
144
+ it('leaves a server someone wrote, and says so', () => {
145
+ const own = { command: 'npx', args: ['-y', 'our-internal-mcp'] }
146
+ const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
147
+ config.mcpServers.Ours = own
148
+ writeFileSync(join(dir, '.mcp.json'), JSON.stringify(config, null, 2) + '\n')
149
+
150
+ const doctor = run(dir, ['doctor'])
151
+ expect(doctor.code).toBe(0)
152
+ expect(doctor.out).toContain('fix Ours by hand')
153
+
154
+ run(dir, ['sync', '--yes'])
155
+ expect(JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8')).mcpServers.Ours).toEqual(own)
156
+ })
157
+ })
158
+
159
+ describe.skipIf(!built)('sync --check on GitHub Actions', () => {
160
+ let dir: string
161
+ beforeEach(() => {
162
+ dir = mkdtempSync(join(tmpdir(), 'team-ci-'))
163
+ execFileSync('git', ['init', '-q'], { cwd: dir })
164
+ writeFileSync(join(dir, 'CLAUDE.md'), '# Ours\n')
165
+ expect(run(dir, ['init', '--yes']).code).toBe(0)
166
+ })
167
+ afterEach(() => {
168
+ rmSync(dir, { recursive: true, force: true })
169
+ })
170
+
171
+ it('annotates the drifted file and writes the run summary', () => {
172
+ const agent = join(dir, '.claude', 'agents', 'developer.agent.md')
173
+ expect(existsSync(agent)).toBe(true)
174
+ appendFileSync(agent, '\nedited in place\n')
175
+ const summary = join(dir, 'summary.md')
176
+
177
+ const r = run(dir, ['sync', '--check'], { GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: summary, GITHUB_WORKSPACE: dir })
178
+ expect(r.code).toBe(1)
179
+ expect(r.out).toMatch(/::error file=\.claude\/agents\/developer\.agent\.md,title=Generated file differs from its source::/)
180
+ expect(readFileSync(summary, 'utf8')).toContain('`.claude/agents/developer.agent.md`')
181
+ })
182
+
183
+ it('keeps --json parseable', () => {
184
+ const r = run(dir, ['sync', '--check', '--json'], { GITHUB_ACTIONS: 'true' })
185
+ expect(r.code).toBe(0)
186
+ expect(() => JSON.parse(r.out)).not.toThrow()
187
+ })
188
+
189
+ it('prints no workflow commands anywhere else', () => {
190
+ appendFileSync(join(dir, '.claude', 'agents', 'developer.agent.md'), '\nedited\n')
191
+ const r = run(dir, ['sync', '--check'])
192
+ expect(r.code).toBe(1)
193
+ expect(r.out).not.toContain('::error')
194
+ })
195
+ })