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
@@ -39,9 +39,9 @@ const HIDDEN = extractKeys('HIDDEN')
39
39
  const REPLACED = extractKeys('REPLACED')
40
40
 
41
41
  describe('visible command surface', () => {
42
- it('exposes exactly the six product commands plus the convoy namespace', () => {
42
+ it('exposes the six product commands, the five team commands, and the convoy namespace', () => {
43
43
  expect(new Set(VISIBLE)).toEqual(
44
- new Set(['init', 'sync', 'add', 'doctor', 'remove', 'convoy']),
44
+ new Set(['init', 'sync', 'add', 'doctor', 'remove', 'explain', 'review', 'ci', 'baseline', 'fleet', 'convoy']),
45
45
  )
46
46
  })
47
47
 
@@ -556,6 +556,11 @@ describe('declared flags are flags the parser reads', () => {
556
556
  convoy: ['convoy-cmd.ts'],
557
557
  log: ['log.ts'],
558
558
  lesson: ['lesson.ts'],
559
+ review: ['review.ts'],
560
+ explain: ['explain.ts'],
561
+ ci: ['ci.ts'],
562
+ baseline: ['baseline.ts'],
563
+ fleet: ['fleet.ts'],
559
564
  }
560
565
  // Read by the entrypoint for every command, not by the modules.
561
566
  const HANDLED_BY_BIN = new Set(['--help', '--version', '--debug'])
@@ -205,8 +205,8 @@ describe('claude-code adapter getDoctorChecks', () => {
205
205
  expect(checks.find((c) => c.path === 'CLAUDE.md')?.type).toBe('file')
206
206
  expect(checks.find((c) => c.path === '.claude/agents/')).toBeDefined()
207
207
  expect(checks.find((c) => c.path === '.claude/skills/')).toBeDefined()
208
- // claude-code: prompts and workflows share 'commands' dir
209
- expect(checks.find((c) => c.path === '.claude/commands/')).toBeDefined()
208
+ // claude-code: prompts and workflows share the namespaced commands dir
209
+ expect(checks.find((c) => c.path === '.claude/commands/oc/')).toBeDefined()
210
210
  expect(checks.find((c) => c.label === 'Commands directory')).toBeDefined()
211
211
  })
212
212
  })
package/src/cli/doctor.ts CHANGED
@@ -2,7 +2,7 @@ import { resolve } from 'node:path';
2
2
  import { readdir, readFile } from 'node:fs/promises';
3
3
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
4
4
  import { readManifest } from './manifest.js';
5
- import { getRequiredMcpEnvVars, resolveStack, isEnvVarSatisfied } from './stack-config.js';
5
+ import { getRequiredMcpEnvVars, resolveStack, isEnvVarSatisfied, getIncludedMcpServers } from './stack-config.js';
6
6
  import { IDE_ADAPTERS, VALID_IDES } from './adapters/index.js';
7
7
  import { resolveManagedPaths, ROOT_INSTRUCTION_FILES } from './managed-paths.js';
8
8
  import {
@@ -15,6 +15,17 @@ import {
15
15
  type FileDiagnosis,
16
16
  } from './managed-block.js';
17
17
  import { UnreadableConfigError } from './types.js';
18
+ import { checkMcpSupplyChain } from './mcp-audit.js';
19
+ import {
20
+ teamStateFor,
21
+ teamAuditContext,
22
+ checkTeamSources,
23
+ checkContextBudget,
24
+ checkReferences,
25
+ checkVersionSkew,
26
+ type TeamState,
27
+ } from './team-health.js';
28
+ import { cliVersionOf, requiredEnvVars } from './layers.js';
18
29
  import type { CliContext, DoctorCheck, IdeChoice, Manifest } from './types.js';
19
30
  import { IDE_LABELS } from './types.js';
20
31
 
@@ -234,6 +245,7 @@ async function checkLogs(projectRoot: string): Promise<CheckResult> {
234
245
  async function checkMcpEnvVars(
235
246
  projectRoot: string,
236
247
  manifest: Manifest | null,
248
+ team?: TeamState,
237
249
  ): Promise<CheckResult> {
238
250
  if (!manifest?.stack) {
239
251
  return { ok: true, label: 'MCP environment variables', detail: 'No stack config (skipped)' };
@@ -241,7 +253,9 @@ async function checkMcpEnvVars(
241
253
  // Through the resolver: a v1 manifest stores `{ cms, db }` with no
242
254
  // `techTools`, and handing that straight on threw "stack.techTools is not
243
255
  // iterable" — a crash where a diagnosis was the whole point of the command.
244
- const required = getRequiredMcpEnvVars(resolveStack(manifest), manifest.repoInfo);
256
+ // The servers actually written: less the ones the team's policy refused,
257
+ // plus every variable the team's own servers refer to.
258
+ const required = requiredEnvVars(team?.resolved, resolveStack(manifest), manifest.repoInfo);
245
259
  if (required.length === 0) {
246
260
  return { ok: true, label: 'MCP environment variables', detail: 'No env vars required' };
247
261
  }
@@ -473,13 +487,53 @@ export function checkMcpFromPaths(projectRoot: string, mcpPaths: string[]): Chec
473
487
  return { ok: true, label: 'MCP configuration', detail: `${found.length} MCP config(s)` };
474
488
  }
475
489
 
490
+ /**
491
+ * The plugin servers this project's stack includes — the set a rebuild keeps.
492
+ * The MCP audit needs it to say truthfully what `sync` will do to an entry.
493
+ */
494
+ function includedServers(manifest: Manifest): Set<string> {
495
+ return getIncludedMcpServers(resolveStack(manifest), manifest.repoInfo);
496
+ }
497
+
498
+ /**
499
+ * The team's resolved sources, or the failure to resolve them as a check.
500
+ * Resolution reports problems as issues rather than throwing, so a throw here
501
+ * is a fault in reading the project itself.
502
+ */
503
+ function teamStateOrFailure(
504
+ pkgRoot: string | undefined,
505
+ projectRoot: string,
506
+ manifest: Manifest | null,
507
+ ): { state?: TeamState; failure?: CheckResult } {
508
+ if (!pkgRoot || !manifest) return {};
509
+ try {
510
+ return { state: teamStateFor(pkgRoot, projectRoot, manifest) };
511
+ } catch (err) {
512
+ return {
513
+ failure: {
514
+ ok: false,
515
+ label: 'Team sources',
516
+ detail: `could not be read — ${(err as Error).message}`,
517
+ fix: 'fix the path named above; this one needs a person',
518
+ },
519
+ };
520
+ }
521
+ }
522
+
476
523
  // ── Main doctor command ───────────────────────────────────────
477
524
 
478
525
  const DOCTOR_HELP = `
479
526
  opencastle doctor [options]
480
527
 
481
528
  Validate your OpenCastle setup — checks manifest, customizations, skills,
482
- logs, MCP configuration, and IDE-specific rules.
529
+ logs, MCP configuration, and IDE-specific rules. MCP servers are audited too:
530
+ a package run without an exact version, one that no longer exists on npm, a
531
+ remote server Claude Code cannot load, a credential written into the file, or
532
+ a server the team's policy does not allow.
533
+
534
+ Team sources are checked as well: .opencastle/config.json and the baselines
535
+ it extends resolve, how much context every assistant loads up front, and
536
+ whether the team's instructions still name scripts and paths that exist.
483
537
 
484
538
  Options:
485
539
  --help, -h Show this help
@@ -833,8 +887,10 @@ function checkRootFileClassification(manifest: Manifest | null): CheckResult {
833
887
  export async function runAdapterChecks(
834
888
  projectRoot: string,
835
889
  manifest: Manifest | null,
890
+ pkgRoot?: string,
836
891
  ): Promise<CheckResult[]> {
837
892
  if (!manifest) return [];
893
+ const { state } = teamStateOrFailure(pkgRoot, projectRoot, manifest);
838
894
  const ides = manifest.ides?.length ? manifest.ides : manifest.ide ? [manifest.ide] : [];
839
895
  const out: CheckResult[] = [];
840
896
  for (const ide of ides) {
@@ -854,6 +910,14 @@ export async function runAdapterChecks(
854
910
  }
855
911
  const mcpPaths = adapter.getManagedPaths().customizable.filter((p) => !p.endsWith('/'));
856
912
  out.push(checkMcpFromPaths(projectRoot, mcpPaths));
913
+ out.push(
914
+ checkMcpSupplyChain(
915
+ projectRoot,
916
+ ide as IdeChoice,
917
+ includedServers(manifest),
918
+ state ? teamAuditContext(state, ide as IdeChoice) : undefined,
919
+ ),
920
+ );
857
921
  }
858
922
  return out;
859
923
  }
@@ -861,18 +925,31 @@ export async function runAdapterChecks(
861
925
  export async function runSharedChecks(
862
926
  projectRoot: string,
863
927
  manifest: Manifest | null,
928
+ pkgRoot?: string,
864
929
  ): Promise<CheckResult[]> {
930
+ const { state, failure } = teamStateOrFailure(pkgRoot, projectRoot, manifest);
931
+ const team: CheckResult[] = failure
932
+ ? [failure]
933
+ : state && manifest && pkgRoot
934
+ ? [
935
+ checkTeamSources(state),
936
+ checkContextBudget(pkgRoot, state),
937
+ checkReferences(state, projectRoot),
938
+ checkVersionSkew(cliVersionOf(pkgRoot), manifest),
939
+ ]
940
+ : [];
865
941
  const results = [
866
942
  checkManifest(manifest),
867
943
  await checkCustomizations(projectRoot),
868
944
  await checkSkillMatrix(projectRoot),
869
945
  await checkLogs(projectRoot),
870
- await checkMcpEnvVars(projectRoot, manifest),
946
+ await checkMcpEnvVars(projectRoot, manifest, state),
871
947
  await checkDotEnv(projectRoot, manifest),
872
948
  await checkGitignoredOutput(projectRoot, manifest),
873
949
  await checkGitignoreBlock(projectRoot),
874
950
  await checkTornBlocks(projectRoot, manifest),
875
951
  checkRootFileClassification(manifest),
952
+ ...team,
876
953
  ];
877
954
 
878
955
  // With no manifest there is nothing for `sync` to sync.
@@ -896,7 +973,7 @@ export async function runSharedChecks(
896
973
  return results;
897
974
  }
898
975
 
899
- export default async function doctor({ args }: CliContext): Promise<void> {
976
+ export default async function doctor({ pkgRoot, args }: CliContext): Promise<void> {
900
977
  if (args.includes('--help') || args.includes('-h')) {
901
978
  console.log(DOCTOR_HELP)
902
979
  return
@@ -942,13 +1019,14 @@ export default async function doctor({ args }: CliContext): Promise<void> {
942
1019
  : 'fix the JSON by hand — a merge conflict, most likely',
943
1020
  },
944
1021
  ]
945
- : await runSharedChecks(projectRoot, manifest);
1022
+ : await runSharedChecks(projectRoot, manifest, pkgRoot);
946
1023
 
947
1024
  // IDE-specific checks derived from each adapter
948
1025
  type IdeGroup = { label: string; results: CheckResult[] };
949
1026
  const ideGroups: IdeGroup[] = [];
950
1027
 
951
1028
  if (manifest) {
1029
+ const { state } = teamStateOrFailure(pkgRoot, projectRoot, manifest);
952
1030
  const ides = manifest.ides ?? (manifest.ide ? [manifest.ide] : []);
953
1031
  for (const ide of ides) {
954
1032
  const loader = IDE_ADAPTERS[ide];
@@ -964,6 +1042,14 @@ export default async function doctor({ args }: CliContext): Promise<void> {
964
1042
  // MCP config check — non-directory entries in the adapter's customizable paths
965
1043
  const mcpPaths = managedPaths.customizable.filter((p) => !p.endsWith('/'));
966
1044
  checkResults.push(checkMcpFromPaths(projectRoot, mcpPaths));
1045
+ checkResults.push(
1046
+ checkMcpSupplyChain(
1047
+ projectRoot,
1048
+ ide as IdeChoice,
1049
+ includedServers(manifest),
1050
+ state ? teamAuditContext(state, ide as IdeChoice) : undefined,
1051
+ ),
1052
+ );
967
1053
 
968
1054
  ideGroups.push({
969
1055
  label: IDE_LABELS[ide as IdeChoice] ?? ide,
@@ -0,0 +1,222 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
3
+ import { readManifest } from './manifest.js'
4
+ import { resolveStack, isEnvVarSatisfied } from './stack-config.js'
5
+ import { resolveSources, materialize, hasErrors, formatIssues, requiredEnvVars, refuseOlderCli } from './layers.js'
6
+ import { buildLock, type Lock, priorTeam } from './lock.js'
7
+ import { IDE_ADAPTERS } from './adapters/index.js'
8
+ import { PLUGINS } from '../orchestrator/plugins/index.js'
9
+ import { c } from './prompt.js'
10
+ import { IDE_LABELS, type CliContext, type IdeChoice } from './types.js'
11
+ import { COMMAND_NAMESPACE } from './command-namespace.js'
12
+
13
+ /**
14
+ * `opencastle explain`: what a new teammate's assistant is given here, and
15
+ * what they have to do for all of it to work.
16
+ *
17
+ * Onboarding onto a repository's AI setup used to mean reading generated
18
+ * files in whichever format your assistant uses and guessing which of them
19
+ * mattered. This answers it from the same resolution `sync` compiles: what is
20
+ * always loaded and what that costs, which skills exist and when they load,
21
+ * where the team's own content comes from, which MCP servers every assistant
22
+ * can start — and which of those still need a variable set or a sign-in.
23
+ */
24
+
25
+ const HELP = `
26
+ opencastle explain [options]
27
+
28
+ Show what every assistant in this repository is given, where each piece comes
29
+ from (OpenCastle, a baseline, or this project), and what you still need to
30
+ set up — environment variables and sign-ins for the MCP servers.
31
+
32
+ Options:
33
+ --all List OpenCastle's own skills and agents too, not only the team's
34
+ --json Machine-readable output
35
+ --help, -h Show this help
36
+ `
37
+
38
+ interface ExplainReport {
39
+ targets: Array<{ id: string; label: string; files: string[] }>
40
+ lock: Lock
41
+ setup: Array<{ server: string; need: string; ok: boolean; how: string }>
42
+ notes: string[]
43
+ }
44
+
45
+ function by(from: string): string {
46
+ if (from === 'opencastle') return 'OpenCastle'
47
+ if (from.startsWith('plugin:')) return `${from.slice(7)} integration`
48
+ return from === 'project' ? 'this project' : from
49
+ }
50
+
51
+ async function build(pkgRoot: string, projectRoot: string): Promise<ExplainReport> {
52
+ const manifest = await readManifest(projectRoot)
53
+ if (!manifest) throw new Error('OpenCastle is not set up here — run opencastle init')
54
+ refuseOlderCli(pkgRoot, manifest.version)
55
+ const ides = (manifest.ides?.length ? manifest.ides : [manifest.ide]).filter((i): i is string => Boolean(i) && i in IDE_ADAPTERS)
56
+ const stack = resolveStack({ ...manifest, ides })
57
+ const resolved = resolveSources({ pkgRoot, projectRoot, stack, repoInfo: manifest.repoInfo })
58
+ if (hasErrors(resolved)) {
59
+ throw new Error(`the team's sources do not resolve:\n${formatIssues(resolved.issues.filter((i) => i.level === 'error')).join('\n')}`)
60
+ }
61
+ const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
62
+ let lock: Lock
63
+ try {
64
+ lock = buildLock(source, { ides, stack, repoInfo: manifest.repoInfo })
65
+ } finally {
66
+ source.dispose()
67
+ }
68
+
69
+ const targets: ExplainReport['targets'] = []
70
+ for (const ide of ides) {
71
+ const adapter = await IDE_ADAPTERS[ide]()
72
+ const paths = adapter.getManagedPaths()
73
+ targets.push({
74
+ id: ide,
75
+ label: IDE_LABELS[ide as IdeChoice] ?? ide,
76
+ files: [...(paths.merged ?? []), ...paths.framework, ...paths.customizable.filter((p) => !p.endsWith('/'))],
77
+ })
78
+ }
79
+
80
+ const envFile = existsSync(resolve(projectRoot, '.env')) ? readFileSync(resolve(projectRoot, '.env'), 'utf8') : ''
81
+ const setup: ExplainReport['setup'] = []
82
+ for (const req of requiredEnvVars(resolved, stack, manifest.repoInfo)) {
83
+ setup.push({
84
+ server: req.server,
85
+ need: req.envVar,
86
+ ok: isEnvVarSatisfied(req.envVar, envFile),
87
+ how: req.hint,
88
+ })
89
+ }
90
+ for (const [key, s] of Object.entries(lock.mcp)) {
91
+ if (s.auth === 'oauth') {
92
+ setup.push({ server: key, need: 'sign-in', ok: true, how: 'your assistant opens a browser to sign in the first time it starts the server' })
93
+ }
94
+ }
95
+ const notes = resolved.issues.filter((i) => i.level === 'warning').map((i) => `${i.where}: ${i.message}`)
96
+ return { targets, lock, setup, notes }
97
+ }
98
+
99
+ function render(report: ExplainReport, all: boolean): void {
100
+ const { lock } = report
101
+ const out = (s = ''): void => console.log(s)
102
+ out(`\n 🏰 ${c.bold('What the AI assistants in this repository are given')}\n`)
103
+
104
+ const layers = lock.layers.map((l) => (l.kind === 'core' ? `OpenCastle ${l.version}` : l.kind === 'project' ? 'this project' : `${l.id}${l.version ? ` ${l.version}` : ''}`))
105
+ out(` ${c.bold('Layers')} ${layers.join(c.dim(' → '))} ${c.dim('(later layers add to and override earlier ones)')}`)
106
+ out(` ${c.bold('Targets')} ${report.targets.map((t) => t.label).join(', ')}`)
107
+ out('')
108
+
109
+ const entries = Object.entries(lock.content)
110
+ const ofKind = (kind: string) => entries.filter(([ref]) => ref.startsWith(`${kind}/`))
111
+ const required = new Set(lock.policy?.require ?? [])
112
+ const tag = (ref: string, from: string, overrides?: string): string => {
113
+ const bits = [by(from)]
114
+ if (overrides) bits.push(`replaces ${by(overrides)}'s`)
115
+ if (required.has(ref)) bits.push('required')
116
+ return c.dim(`(${bits.join(', ')})`)
117
+ }
118
+
119
+ out(` ${c.bold('Always loaded')} ${c.dim(`— ~${lock.context.tokens} tokens before every task: instructions ~${lock.context.instructions}, the skill and agent index ~${lock.context.index}`)}`)
120
+ for (const [ref, item] of ofKind('instructions')) {
121
+ out(` ${c.dim('•')} ${ref.slice(13)} ${c.dim(`~${item.tokens ?? 0} tokens`)} ${tag(ref, item.from, item.overrides)}`)
122
+ }
123
+ if (lock.policy?.contextBudget) out(` ${c.dim(`budget: ${lock.policy.contextBudget} tokens`)}`)
124
+ out('')
125
+
126
+ // Where a prompt is a command someone types, and under which name.
127
+ const hasClaude = report.targets.some((t) => t.id === 'claude-code')
128
+ const typedIn = [
129
+ ...(hasClaude ? ['Claude Code'] : []),
130
+ ...(report.targets.some((t) => t.id === 'vscode') ? ['Copilot'] : []),
131
+ ]
132
+ for (const kind of ['skills', 'agents', 'prompts', 'workflows'] as const) {
133
+ const items = ofKind(kind)
134
+ if (items.length === 0) continue
135
+ const team = items.filter(([, i]) => i.from !== 'opencastle' && !i.from.startsWith('plugin:'))
136
+ const integrations = items.filter(([, i]) => i.from.startsWith('plugin:'))
137
+ const core = items.filter(([, i]) => i.from === 'opencastle')
138
+ const title = {
139
+ skills: 'Skills — loaded when a task matches the description',
140
+ agents: 'Agents — personas to delegate to',
141
+ prompts: typedIn.length > 0 ? `Commands — /${COMMAND_NAMESPACE}:<name> in ${typedIn.join(' and ')}` : 'Prompts',
142
+ workflows: hasClaude ? `Workflows — /${COMMAND_NAMESPACE}:workflow-<name> in Claude Code` : 'Workflows',
143
+ }[kind]
144
+ out(` ${c.bold(title)} ${c.dim(`(${items.length})`)}`)
145
+ for (const [ref, item] of [...team, ...integrations, ...(all ? core : [])]) {
146
+ const name = ref.slice(kind.length + 1)
147
+ out(` ${c.dim('•')} ${c.bold(name)} ${tag(ref, item.from, item.overrides)}${item.description ? `\n ${c.dim(item.description)}` : ''}`)
148
+ }
149
+ if (!all && core.length > 0) {
150
+ out(` ${c.dim('•')} ${c.dim(`and ${core.length} from OpenCastle: ${core.map(([r]) => r.slice(kind.length + 1)).join(', ')}`)}`)
151
+ }
152
+ out('')
153
+ }
154
+ if (lock.excluded) {
155
+ out(` ${c.bold('Left out')}`)
156
+ for (const [ref, who] of Object.entries(lock.excluded)) out(` ${c.dim('•')} ${ref} ${c.dim(`(excluded by ${by(who)})`)}`)
157
+ out('')
158
+ }
159
+
160
+ const servers = Object.entries(lock.mcp)
161
+ out(` ${c.bold('MCP servers')} ${c.dim(`— tools every assistant can start (${servers.length})`)}`)
162
+ for (const [key, s] of servers) {
163
+ const what = s.transport === 'http' ? `remote: ${s.launch}` : `runs: ${s.launch}`
164
+ const plugin = s.from.startsWith('plugin:') ? PLUGINS[s.from.slice(7)] : undefined
165
+ out(` ${c.dim('•')} ${c.bold(key)} ${c.dim(`(${by(s.from)})`)}\n ${c.dim(what)}${plugin?.officialDocs ? `\n ${c.dim(`docs: ${plugin.officialDocs}`)}` : ''}`)
166
+ }
167
+ if (lock.blocked) {
168
+ for (const [key, why] of Object.entries(lock.blocked)) out(` ${c.yellow('–')} ${key} ${c.dim(`not written: ${why}`)}`)
169
+ }
170
+ out('')
171
+
172
+ if (lock.policy) {
173
+ out(` ${c.bold("The team's policy")}`)
174
+ const p = lock.policy
175
+ // Per layer: a server must be on every list, so a union would overstate it.
176
+ if (p.allow) {
177
+ out(` ${c.dim('•')} MCP servers must be on every one of these allowlists:`)
178
+ for (const [who, list] of Object.entries(p.allow)) out(` ${c.dim(`${by(who)}:`)} ${list.join(', ')}`)
179
+ }
180
+ if (p.remoteHosts) {
181
+ out(` ${c.dim('•')} Remote servers may only reach hosts every one of these allows:`)
182
+ for (const [who, list] of Object.entries(p.remoteHosts)) out(` ${c.dim(`${by(who)}:`)} ${list.join(', ')}`)
183
+ }
184
+ if (p.requirePinned) out(` ${c.dim('•')} Every local server must be pinned to an exact version (${p.requirePinned})`)
185
+ if (p.require) out(` ${c.dim('•')} Required everywhere: ${p.require.join(', ')}`)
186
+ if (p.opencastle) out(` ${c.dim('•')} OpenCastle version: ${Object.values(p.opencastle).join(' and ')}`)
187
+ out('')
188
+ }
189
+
190
+ out(` ${c.bold('Your setup')}`)
191
+ if (report.setup.length === 0) out(` ${c.green('✓')} Nothing to set up — every server works without a variable or a sign-in.`)
192
+ for (const s of report.setup) {
193
+ if (s.need === 'sign-in') out(` ${c.cyan('→')} ${s.server}: ${s.how}`)
194
+ else out(` ${s.ok ? c.green('✓') : c.red('✗')} ${s.need} ${c.dim(`— ${s.how}${s.ok ? '' : '; set it in .env or your shell'}`)}`)
195
+ }
196
+ out('')
197
+ for (const t of report.targets) out(` ${c.dim(`${t.label}: ${t.files.join(', ')}`)}`)
198
+ if (report.notes.length > 0) {
199
+ out('')
200
+ for (const n of report.notes) out(` ${c.yellow('!')} ${c.dim(n)}`)
201
+ }
202
+ out('')
203
+ }
204
+
205
+ export default async function explain({ pkgRoot, args }: CliContext): Promise<void> {
206
+ if (args.includes('--help') || args.includes('-h')) {
207
+ console.log(HELP)
208
+ return
209
+ }
210
+ let report: ExplainReport
211
+ try {
212
+ report = await build(pkgRoot, process.cwd())
213
+ } catch (err) {
214
+ console.error(`\n ${c.red('✗')} Cannot explain: ${(err as Error).message}\n`)
215
+ process.exit(1)
216
+ }
217
+ if (args.includes('--json')) {
218
+ console.log(JSON.stringify(report, null, 2))
219
+ return
220
+ }
221
+ render(report, args.includes('--all'))
222
+ }
@@ -0,0 +1,176 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { basename, join, resolve } from 'node:path'
3
+ import { readLock, LOCK_REL, type Lock } from './lock.js'
4
+ import { parseVersion, compareVersions } from './version-range.js'
5
+ import { c } from './prompt.js'
6
+ import type { CliContext } from './types.js'
7
+
8
+ /**
9
+ * `opencastle fleet`: many repositories, one view.
10
+ *
11
+ * A platform team that publishes a baseline needs to know where it has landed:
12
+ * which repositories run which version, which are behind, and whether the same
13
+ * MCP server runs at five different versions across the organisation. Every
14
+ * repository's committed lock already says all of this, so the answer is a
15
+ * read of files — no install, no network, no access to anyone's machine.
16
+ */
17
+
18
+ const HELP = `
19
+ opencastle fleet <dir...> [options]
20
+
21
+ Read the committed .opencastle/lock.json of each repository given and show
22
+ which OpenCastle and baseline versions they run, which lag behind the newest,
23
+ and which MCP servers run at more than one version across them.
24
+
25
+ Options:
26
+ --json Machine-readable output
27
+ --help, -h Show this help
28
+
29
+ Example: opencastle fleet ~/src/*
30
+ `
31
+
32
+ interface RepoRow {
33
+ repo: string
34
+ path: string
35
+ lock: Lock | null
36
+ /** A lock is there but this release cannot read it — written by a newer one, or edited. */
37
+ unreadable?: boolean
38
+ }
39
+
40
+ export interface FleetReport {
41
+ repos: Array<{
42
+ repo: string
43
+ opencastle?: string
44
+ baselines: Record<string, string>
45
+ targets: string[]
46
+ mcpServers: number
47
+ contextTokens?: number
48
+ lock: boolean
49
+ unreadable?: boolean
50
+ }>
51
+ /** Per baseline or OpenCastle itself: version → repositories. */
52
+ versions: Record<string, Record<string, string[]>>
53
+ /** MCP servers launched at more than one version or address. */
54
+ spread: Record<string, Record<string, string[]>>
55
+ withoutLock: string[]
56
+ }
57
+
58
+ function repoName(dir: string): string {
59
+ try {
60
+ const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { name?: string }
61
+ if (pkg.name) return pkg.name
62
+ } catch {
63
+ // Not a package; the directory name will do.
64
+ }
65
+ return basename(dir)
66
+ }
67
+
68
+ export function buildFleet(rows: RepoRow[]): FleetReport {
69
+ const report: FleetReport = { repos: [], versions: {}, spread: {}, withoutLock: [] }
70
+ const note = (bucket: Record<string, Record<string, string[]>>, key: string, value: string, repo: string): void => {
71
+ ;((bucket[key] ??= {})[value] ??= []).push(repo)
72
+ }
73
+ for (const { repo, lock, unreadable } of rows) {
74
+ if (!lock) {
75
+ report.withoutLock.push(repo)
76
+ report.repos.push({ repo, baselines: {}, targets: [], mcpServers: 0, lock: false, ...(unreadable && { unreadable: true }) })
77
+ continue
78
+ }
79
+ const baselines: Record<string, string> = {}
80
+ for (const l of lock.layers) {
81
+ if (l.kind === 'baseline') baselines[l.id] = l.version ?? '?'
82
+ }
83
+ report.repos.push({
84
+ repo,
85
+ opencastle: lock.opencastle,
86
+ baselines,
87
+ targets: lock.targets,
88
+ mcpServers: Object.keys(lock.mcp).length,
89
+ contextTokens: lock.context?.tokens,
90
+ lock: true,
91
+ })
92
+ note(report.versions, 'opencastle', lock.opencastle, repo)
93
+ for (const [id, v] of Object.entries(baselines)) note(report.versions, id, v, repo)
94
+ for (const [key, s] of Object.entries(lock.mcp)) note(report.spread, key, s.launch, repo)
95
+ }
96
+ for (const key of Object.keys(report.spread)) {
97
+ if (Object.keys(report.spread[key]).length < 2) delete report.spread[key]
98
+ }
99
+ return report
100
+ }
101
+
102
+ function newest(versions: string[]): string | undefined {
103
+ return [...versions].sort((a, b) => {
104
+ const pa = parseVersion(a)
105
+ const pb = parseVersion(b)
106
+ if (!pa || !pb) return a < b ? -1 : 1
107
+ return compareVersions(pa, pb)
108
+ }).pop()
109
+ }
110
+
111
+ function render(report: FleetReport): void {
112
+ const out = (s = ''): void => console.log(s)
113
+ out(`\n 🏰 ${c.bold('Fleet')} ${c.dim(`— ${report.repos.length} repositories`)}\n`)
114
+ const width = Math.max(10, ...report.repos.map((r) => r.repo.length))
115
+ for (const r of report.repos) {
116
+ if (!r.lock) {
117
+ out(
118
+ ` ${c.yellow('!')} ${r.repo.padEnd(width)} ${c.dim(
119
+ r.unreadable ? 'a lock this release cannot read — written by a newer OpenCastle, or edited by hand' : 'no lock — not synced with a release that writes one',
120
+ )}`,
121
+ )
122
+ continue
123
+ }
124
+ const bl = Object.entries(r.baselines).map(([id, v]) => `${id}@${v}`).join(', ')
125
+ out(
126
+ ` ${c.dim('•')} ${r.repo.padEnd(width)} opencastle ${r.opencastle} ${bl || c.dim('no baseline')} ` +
127
+ c.dim(`${r.targets.length} target(s), ${r.mcpServers} MCP server(s), ~${r.contextTokens ?? '?'} tokens up front`),
128
+ )
129
+ }
130
+ out('')
131
+ for (const [what, byVersion] of Object.entries(report.versions)) {
132
+ const versions = Object.keys(byVersion)
133
+ const top = newest(versions)
134
+ const behind = versions.filter((v) => v !== top).flatMap((v) => byVersion[v])
135
+ const line = versions
136
+ .sort()
137
+ .map((v) => `${v} (${byVersion[v].length})`)
138
+ .join(', ')
139
+ out(` ${c.bold(what)}: ${line}${behind.length > 0 ? c.yellow(` — ${behind.length} behind ${top}: ${behind.join(', ')}`) : c.green(' — all on one version')}`)
140
+ }
141
+ const spread = Object.entries(report.spread)
142
+ if (spread.length > 0) {
143
+ out('')
144
+ out(` ${c.bold('MCP servers running differently across repositories')}`)
145
+ for (const [key, byLaunch] of spread) {
146
+ out(` ${c.yellow('~')} ${key}`)
147
+ for (const [launch, repos] of Object.entries(byLaunch)) out(` ${c.dim(`${launch} — ${repos.join(', ')}`)}`)
148
+ }
149
+ }
150
+ out('')
151
+ }
152
+
153
+ export default async function fleet({ args }: CliContext): Promise<void> {
154
+ if (args.includes('--help') || args.includes('-h')) {
155
+ console.log(HELP)
156
+ return
157
+ }
158
+ const dirs = args.filter((a) => !a.startsWith('--'))
159
+ if (dirs.length === 0) {
160
+ console.log(HELP)
161
+ process.exit(1)
162
+ }
163
+ const rows: RepoRow[] = []
164
+ for (const dir of dirs) {
165
+ const abs = resolve(dir)
166
+ if (!existsSync(join(abs, '.opencastle'))) continue
167
+ rows.push({ repo: repoName(abs), path: abs, lock: readLock(abs), unreadable: existsSync(join(abs, LOCK_REL)) && !readLock(abs) })
168
+ }
169
+ if (rows.length === 0) {
170
+ console.error(`\n ${c.red('✗')} None of those directories uses OpenCastle (no .opencastle/ in any).\n`)
171
+ process.exit(1)
172
+ }
173
+ const report = buildFleet(rows)
174
+ if (args.includes('--json')) console.log(JSON.stringify(report, null, 2))
175
+ else render(report)
176
+ }