opencastle 0.38.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/README.md +81 -1
  2. package/bin/cli.mjs +20 -3
  3. package/dist/cli/adapters/antigravity.d.ts +1 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.d.ts +1 -1
  6. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  7. package/dist/cli/adapters/codex.d.ts +1 -1
  8. package/dist/cli/adapters/codex.d.ts.map +1 -1
  9. package/dist/cli/adapters/cursor.d.ts +1 -1
  10. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  11. package/dist/cli/adapters/opencode.d.ts +1 -1
  12. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  13. package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
  14. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  15. package/dist/cli/adapters/rules-dir-base.js +13 -25
  16. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  17. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  18. package/dist/cli/adapters/single-file-base.js +30 -43
  19. package/dist/cli/adapters/single-file-base.js.map +1 -1
  20. package/dist/cli/adapters/vscode.d.ts +3 -2
  21. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  22. package/dist/cli/adapters/vscode.js +19 -71
  23. package/dist/cli/adapters/vscode.js.map +1 -1
  24. package/dist/cli/adapters/windsurf.d.ts +1 -1
  25. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  26. package/dist/cli/baseline.d.ts +3 -0
  27. package/dist/cli/baseline.d.ts.map +1 -0
  28. package/dist/cli/baseline.js +280 -0
  29. package/dist/cli/baseline.js.map +1 -0
  30. package/dist/cli/ci.d.ts +18 -0
  31. package/dist/cli/ci.d.ts.map +1 -0
  32. package/dist/cli/ci.js +279 -0
  33. package/dist/cli/ci.js.map +1 -0
  34. package/dist/cli/dispatcher.test.js +2 -2
  35. package/dist/cli/dispatcher.test.js.map +1 -1
  36. package/dist/cli/docs-accuracy.test.js +5 -0
  37. package/dist/cli/docs-accuracy.test.js.map +1 -1
  38. package/dist/cli/doctor.d.ts +3 -3
  39. package/dist/cli/doctor.d.ts.map +1 -1
  40. package/dist/cli/doctor.js +66 -9
  41. package/dist/cli/doctor.js.map +1 -1
  42. package/dist/cli/explain.d.ts +3 -0
  43. package/dist/cli/explain.d.ts.map +1 -0
  44. package/dist/cli/explain.js +210 -0
  45. package/dist/cli/explain.js.map +1 -0
  46. package/dist/cli/fleet.d.ts +30 -0
  47. package/dist/cli/fleet.d.ts.map +1 -0
  48. package/dist/cli/fleet.js +149 -0
  49. package/dist/cli/fleet.js.map +1 -0
  50. package/dist/cli/github-report.d.ts +49 -0
  51. package/dist/cli/github-report.d.ts.map +1 -0
  52. package/dist/cli/github-report.js +161 -0
  53. package/dist/cli/github-report.js.map +1 -0
  54. package/dist/cli/github-report.test.d.ts +2 -0
  55. package/dist/cli/github-report.test.d.ts.map +1 -0
  56. package/dist/cli/github-report.test.js +146 -0
  57. package/dist/cli/github-report.test.js.map +1 -0
  58. package/dist/cli/init.d.ts.map +1 -1
  59. package/dist/cli/init.js +135 -94
  60. package/dist/cli/init.js.map +1 -1
  61. package/dist/cli/init.test.js +26 -25
  62. package/dist/cli/init.test.js.map +1 -1
  63. package/dist/cli/layers.d.ts +152 -0
  64. package/dist/cli/layers.d.ts.map +1 -0
  65. package/dist/cli/layers.js +932 -0
  66. package/dist/cli/layers.js.map +1 -0
  67. package/dist/cli/layers.test.d.ts +2 -0
  68. package/dist/cli/layers.test.d.ts.map +1 -0
  69. package/dist/cli/layers.test.js +483 -0
  70. package/dist/cli/layers.test.js.map +1 -0
  71. package/dist/cli/lock.d.ts +130 -0
  72. package/dist/cli/lock.d.ts.map +1 -0
  73. package/dist/cli/lock.js +320 -0
  74. package/dist/cli/lock.js.map +1 -0
  75. package/dist/cli/mcp-audit.d.ts +164 -0
  76. package/dist/cli/mcp-audit.d.ts.map +1 -0
  77. package/dist/cli/mcp-audit.js +504 -0
  78. package/dist/cli/mcp-audit.js.map +1 -0
  79. package/dist/cli/mcp-audit.test.d.ts +2 -0
  80. package/dist/cli/mcp-audit.test.d.ts.map +1 -0
  81. package/dist/cli/mcp-audit.test.js +215 -0
  82. package/dist/cli/mcp-audit.test.js.map +1 -0
  83. package/dist/cli/mcp-upgrade.test.d.ts +2 -0
  84. package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
  85. package/dist/cli/mcp-upgrade.test.js +118 -0
  86. package/dist/cli/mcp-upgrade.test.js.map +1 -0
  87. package/dist/cli/mcp.d.ts +74 -5
  88. package/dist/cli/mcp.d.ts.map +1 -1
  89. package/dist/cli/mcp.js +340 -32
  90. package/dist/cli/mcp.js.map +1 -1
  91. package/dist/cli/policy.d.ts +58 -0
  92. package/dist/cli/policy.d.ts.map +1 -0
  93. package/dist/cli/policy.js +194 -0
  94. package/dist/cli/policy.js.map +1 -0
  95. package/dist/cli/publish-workflow.test.js +55 -1
  96. package/dist/cli/publish-workflow.test.js.map +1 -1
  97. package/dist/cli/remove.d.ts.map +1 -1
  98. package/dist/cli/remove.js +3 -2
  99. package/dist/cli/remove.js.map +1 -1
  100. package/dist/cli/review.d.ts +25 -0
  101. package/dist/cli/review.d.ts.map +1 -0
  102. package/dist/cli/review.js +437 -0
  103. package/dist/cli/review.js.map +1 -0
  104. package/dist/cli/status.d.ts +2 -0
  105. package/dist/cli/status.d.ts.map +1 -1
  106. package/dist/cli/status.js +25 -4
  107. package/dist/cli/status.js.map +1 -1
  108. package/dist/cli/status.test.js +5 -3
  109. package/dist/cli/status.test.js.map +1 -1
  110. package/dist/cli/sync-check.d.ts +16 -1
  111. package/dist/cli/sync-check.d.ts.map +1 -1
  112. package/dist/cli/sync-check.js +219 -13
  113. package/dist/cli/sync-check.js.map +1 -1
  114. package/dist/cli/sync-check.test.js +14 -8
  115. package/dist/cli/sync-check.test.js.map +1 -1
  116. package/dist/cli/sync.d.ts.map +1 -1
  117. package/dist/cli/sync.js +2 -0
  118. package/dist/cli/sync.js.map +1 -1
  119. package/dist/cli/team-ci.test.d.ts +2 -0
  120. package/dist/cli/team-ci.test.d.ts.map +1 -0
  121. package/dist/cli/team-ci.test.js +169 -0
  122. package/dist/cli/team-ci.test.js.map +1 -0
  123. package/dist/cli/team-commands.test.d.ts +2 -0
  124. package/dist/cli/team-commands.test.d.ts.map +1 -0
  125. package/dist/cli/team-commands.test.js +233 -0
  126. package/dist/cli/team-commands.test.js.map +1 -0
  127. package/dist/cli/team-config.d.ts +88 -0
  128. package/dist/cli/team-config.d.ts.map +1 -0
  129. package/dist/cli/team-config.js +261 -0
  130. package/dist/cli/team-config.js.map +1 -0
  131. package/dist/cli/team-health.d.ts +49 -0
  132. package/dist/cli/team-health.d.ts.map +1 -0
  133. package/dist/cli/team-health.js +205 -0
  134. package/dist/cli/team-health.js.map +1 -0
  135. package/dist/cli/team-sources.test.d.ts +2 -0
  136. package/dist/cli/team-sources.test.d.ts.map +1 -0
  137. package/dist/cli/team-sources.test.js +542 -0
  138. package/dist/cli/team-sources.test.js.map +1 -0
  139. package/dist/cli/types.d.ts +16 -2
  140. package/dist/cli/types.d.ts.map +1 -1
  141. package/dist/cli/types.js.map +1 -1
  142. package/dist/cli/update.d.ts.map +1 -1
  143. package/dist/cli/update.js +204 -44
  144. package/dist/cli/update.js.map +1 -1
  145. package/dist/cli/version-range.d.ts +24 -0
  146. package/dist/cli/version-range.d.ts.map +1 -0
  147. package/dist/cli/version-range.js +157 -0
  148. package/dist/cli/version-range.js.map +1 -0
  149. package/dist/cli/website-plugins.test.d.ts +2 -0
  150. package/dist/cli/website-plugins.test.d.ts.map +1 -0
  151. package/dist/cli/website-plugins.test.js +34 -0
  152. package/dist/cli/website-plugins.test.js.map +1 -0
  153. package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
  154. package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
  155. package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
  156. package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
  157. package/dist/orchestrator/plugins/contentful/config.js +11 -1
  158. package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
  159. package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
  160. package/dist/orchestrator/plugins/convex/config.js +11 -1
  161. package/dist/orchestrator/plugins/convex/config.js.map +1 -1
  162. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  163. package/dist/orchestrator/plugins/coolify/config.js +14 -1
  164. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  165. package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
  166. package/dist/orchestrator/plugins/figma/config.js +24 -13
  167. package/dist/orchestrator/plugins/figma/config.js.map +1 -1
  168. package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
  169. package/dist/orchestrator/plugins/linear/config.js +27 -17
  170. package/dist/orchestrator/plugins/linear/config.js.map +1 -1
  171. package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
  172. package/dist/orchestrator/plugins/netlify/config.js +23 -9
  173. package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
  174. package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
  175. package/dist/orchestrator/plugins/nextjs/config.js +11 -1
  176. package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
  177. package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
  178. package/dist/orchestrator/plugins/nx/config.js +11 -1
  179. package/dist/orchestrator/plugins/nx/config.js.map +1 -1
  180. package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
  181. package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
  182. package/dist/orchestrator/plugins/pins.test.js +78 -0
  183. package/dist/orchestrator/plugins/pins.test.js.map +1 -0
  184. package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
  185. package/dist/orchestrator/plugins/playwright/config.js +11 -1
  186. package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
  187. package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
  188. package/dist/orchestrator/plugins/prisma/config.js +17 -2
  189. package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
  190. package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
  191. package/dist/orchestrator/plugins/resend/config.js +17 -1
  192. package/dist/orchestrator/plugins/resend/config.js.map +1 -1
  193. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  194. package/dist/orchestrator/plugins/sentry/config.js +13 -1
  195. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  196. package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
  197. package/dist/orchestrator/plugins/slack/config.js +20 -1
  198. package/dist/orchestrator/plugins/slack/config.js.map +1 -1
  199. package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
  200. package/dist/orchestrator/plugins/strapi/config.js +11 -1
  201. package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
  202. package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
  203. package/dist/orchestrator/plugins/trello/config.js +21 -1
  204. package/dist/orchestrator/plugins/trello/config.js.map +1 -1
  205. package/dist/orchestrator/plugins/types.d.ts +22 -0
  206. package/dist/orchestrator/plugins/types.d.ts.map +1 -1
  207. package/package.json +3 -1
  208. package/src/cli/adapters/rules-dir-base.ts +23 -44
  209. package/src/cli/adapters/single-file-base.ts +43 -46
  210. package/src/cli/adapters/vscode.ts +28 -71
  211. package/src/cli/baseline.ts +289 -0
  212. package/src/cli/ci.ts +289 -0
  213. package/src/cli/dispatcher.test.ts +2 -2
  214. package/src/cli/docs-accuracy.test.ts +5 -0
  215. package/src/cli/doctor.ts +92 -6
  216. package/src/cli/explain.ts +210 -0
  217. package/src/cli/fleet.ts +176 -0
  218. package/src/cli/github-report.test.ts +158 -0
  219. package/src/cli/github-report.ts +179 -0
  220. package/src/cli/init.test.ts +27 -27
  221. package/src/cli/init.ts +135 -93
  222. package/src/cli/layers.test.ts +525 -0
  223. package/src/cli/layers.ts +1089 -0
  224. package/src/cli/lock.ts +395 -0
  225. package/src/cli/mcp-audit.test.ts +259 -0
  226. package/src/cli/mcp-audit.ts +619 -0
  227. package/src/cli/mcp-upgrade.test.ts +135 -0
  228. package/src/cli/mcp.ts +373 -34
  229. package/src/cli/policy.ts +207 -0
  230. package/src/cli/publish-workflow.test.ts +60 -1
  231. package/src/cli/remove.ts +8 -2
  232. package/src/cli/review.ts +457 -0
  233. package/src/cli/status.test.ts +5 -3
  234. package/src/cli/status.ts +29 -4
  235. package/src/cli/sync-check.test.ts +16 -8
  236. package/src/cli/sync-check.ts +245 -14
  237. package/src/cli/sync.ts +2 -0
  238. package/src/cli/team-ci.test.ts +195 -0
  239. package/src/cli/team-commands.test.ts +253 -0
  240. package/src/cli/team-config.ts +289 -0
  241. package/src/cli/team-health.ts +234 -0
  242. package/src/cli/team-sources.test.ts +578 -0
  243. package/src/cli/types.ts +19 -1
  244. package/src/cli/update.ts +217 -44
  245. package/src/cli/version-range.ts +150 -0
  246. package/src/cli/website-plugins.test.ts +41 -0
  247. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  248. package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
  249. package/src/orchestrator/plugins/contentful/config.ts +11 -1
  250. package/src/orchestrator/plugins/convex/config.ts +11 -1
  251. package/src/orchestrator/plugins/coolify/config.ts +14 -1
  252. package/src/orchestrator/plugins/figma/SKILL.md +18 -14
  253. package/src/orchestrator/plugins/figma/config.ts +24 -13
  254. package/src/orchestrator/plugins/linear/SKILL.md +6 -14
  255. package/src/orchestrator/plugins/linear/config.ts +27 -17
  256. package/src/orchestrator/plugins/netlify/config.ts +23 -9
  257. package/src/orchestrator/plugins/nextjs/config.ts +11 -1
  258. package/src/orchestrator/plugins/nx/config.ts +11 -1
  259. package/src/orchestrator/plugins/pins.test.ts +80 -0
  260. package/src/orchestrator/plugins/playwright/config.ts +11 -1
  261. package/src/orchestrator/plugins/prisma/config.ts +17 -2
  262. package/src/orchestrator/plugins/resend/config.ts +17 -1
  263. package/src/orchestrator/plugins/sentry/config.ts +13 -1
  264. package/src/orchestrator/plugins/slack/config.ts +20 -1
  265. package/src/orchestrator/plugins/strapi/config.ts +11 -1
  266. package/src/orchestrator/plugins/trello/config.ts +21 -1
  267. package/src/orchestrator/plugins/types.ts +24 -0
package/src/cli/ci.ts ADDED
@@ -0,0 +1,289 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import { mkdir, writeFile, appendFile } from 'node:fs/promises'
4
+ import { basename, dirname, join, relative, sep } from 'node:path'
5
+ import { readManifest } from './manifest.js'
6
+ import { cliVersionOf, resolveSources } from './layers.js'
7
+ import { resolveStack } from './stack-config.js'
8
+ import { LOCK_REL } from './lock.js'
9
+ import { TEAM_CONFIG_REL } from './team-config.js'
10
+ import { c } from './prompt.js'
11
+ import type { CliContext } from './types.js'
12
+
13
+ /**
14
+ * `opencastle ci`: the checks a team needs, in the team's CI, in one command.
15
+ *
16
+ * `sync --check` has always been the gate; wiring it up was left to each team,
17
+ * and most never did — which is how generated config drifts. This writes a
18
+ * workflow that installs the project's dependencies (baselines come from
19
+ * there), runs the project's own OpenCastle version, fails on drift, and on a
20
+ * pull request writes what the change does to the assistants beside it. With
21
+ * `--owners`, CODEOWNERS routes every change to what assistants are given —
22
+ * all of which moves `.opencastle/lock.json` — to the people who own it.
23
+ */
24
+
25
+ const HELP = `
26
+ opencastle ci [options]
27
+
28
+ Write a GitHub Actions workflow that fails a pull request when generated
29
+ assistant config differs from its sources or breaks the team's policy, and
30
+ adds a summary of what the change does to every assistant.
31
+
32
+ Options:
33
+ --owners <team> Also route changes to .opencastle/lock.json and
34
+ .opencastle/config.json to these reviewers in CODEOWNERS
35
+ (e.g. @acme/platform)
36
+ --force Replace an existing workflow file
37
+ --dry-run Print what would be written, and write nothing
38
+ --help, -h Show this help
39
+ `
40
+
41
+ type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'
42
+
43
+ function git(cwd: string, args: string[]): string | null {
44
+ try {
45
+ return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
46
+ } catch {
47
+ return null
48
+ }
49
+ }
50
+
51
+ function packageManagerOf(root: string): PackageManager {
52
+ if (existsSync(join(root, 'pnpm-lock.yaml'))) return 'pnpm'
53
+ if (existsSync(join(root, 'yarn.lock'))) return 'yarn'
54
+ if (existsSync(join(root, 'bun.lockb')) || existsSync(join(root, 'bun.lock'))) return 'bun'
55
+ return 'npm'
56
+ }
57
+
58
+ interface Plan {
59
+ workflowPath: string
60
+ workflow: string
61
+ codeowners?: { path: string; block: string }
62
+ pinned: boolean
63
+ }
64
+
65
+ /** The lockfile lives at the project, or — in a workspace — above it. */
66
+ function findUp(start: string, names: string[], stop: string): string | null {
67
+ let dir = start
68
+ for (;;) {
69
+ if (names.some((n) => existsSync(join(dir, n)))) return dir
70
+ if (dir === stop) return null
71
+ const parent = dirname(dir)
72
+ if (parent === dir) return null
73
+ dir = parent
74
+ }
75
+ }
76
+
77
+ /**
78
+ * `extraPaths`: directories outside the project the check depends on — a
79
+ * baseline kept elsewhere in the repository, whose change must run it too.
80
+ */
81
+ export function planCi(projectRoot: string, cliVersion: string, owners?: string, extraPaths: string[] = []): Plan {
82
+ const repoRoot = git(projectRoot, ['rev-parse', '--show-toplevel']) ?? projectRoot
83
+ const prefix = (git(projectRoot, ['rev-parse', '--show-prefix']) ?? '').replace(/\/$/, '')
84
+ const branch = (git(projectRoot, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']) ?? 'origin/main').replace(/^origin\//, '')
85
+
86
+ const installRoot =
87
+ findUp(projectRoot, ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lockb', 'bun.lock'], repoRoot) ??
88
+ (existsSync(join(projectRoot, 'package.json')) ? projectRoot : null)
89
+ const pm = installRoot ? packageManagerOf(installRoot) : 'npm'
90
+
91
+ let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> } = {}
92
+ try {
93
+ pkg = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'))
94
+ } catch {
95
+ pkg = {}
96
+ }
97
+ // The project's own copy when it has one: then every laptop and CI run the
98
+ // version its lockfile pins, and nobody's global install decides the output.
99
+ const pinned = Boolean(pkg.devDependencies?.opencastle ?? pkg.dependencies?.opencastle)
100
+ const run = pinned
101
+ ? pm === 'pnpm'
102
+ ? 'pnpm exec opencastle'
103
+ : pm === 'yarn'
104
+ ? 'yarn opencastle'
105
+ : 'npx --no opencastle'
106
+ : `npx -y opencastle@${cliVersion}`
107
+
108
+ const install: string[] = []
109
+ let installRel = ''
110
+ if (installRoot) {
111
+ installRel = installRoot === repoRoot ? '' : installRoot.slice(repoRoot.length + 1).split('\\').join('/')
112
+ // Always explicit in a subdirectory project: the job's default directory is
113
+ // the project, and a lockfile at the repository root installs from there —
114
+ // `npm ci` in a subdirectory that is not a workspace finds no lockfile.
115
+ const at = prefix || installRel ? `\n working-directory: ${installRel || '.'}` : ''
116
+ // The workspace root's `packageManager`, or the project's own.
117
+ let manager = ''
118
+ for (const dir of [installRoot, projectRoot]) {
119
+ try {
120
+ manager = (JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { packageManager?: string }).packageManager ?? ''
121
+ } catch {
122
+ manager = ''
123
+ }
124
+ if (manager) break
125
+ }
126
+ if (pm === 'pnpm') {
127
+ // The action needs a version, from `packageManager` or here.
128
+ install.push(' - uses: pnpm/action-setup@v4')
129
+ if (!manager.startsWith('pnpm@')) install.push(' with:', ' version: 10 # match the pnpm your lockfile was written with')
130
+ install.push(` - run: pnpm install --frozen-lockfile${at}`)
131
+ } else if (pm === 'yarn') {
132
+ // Yarn 1 ignores --immutable; --frozen-lockfile is its spelling.
133
+ const classic = !manager.startsWith('yarn@') || manager.startsWith('yarn@1')
134
+ install.push(' - run: corepack enable', ` - run: yarn install ${classic ? '--frozen-lockfile' : '--immutable'}${at}`)
135
+ } else if (pm === 'bun') {
136
+ install.push(' - uses: oven-sh/setup-bun@v2', ` - run: bun install --frozen-lockfile${at}`)
137
+ } else {
138
+ install.push(` - run: ${existsSync(join(installRoot, 'package-lock.json')) ? 'npm ci' : 'npm install'}${at}`)
139
+ }
140
+ }
141
+
142
+ const name = prefix ? `opencastle-${basename(prefix)}` : 'opencastle'
143
+ const workflowPath = join(repoRoot, '.github', 'workflows', `${name}.yml`)
144
+ // A subdirectory project runs only when something it depends on changes:
145
+ // its own files, the lockfile a baseline upgrade moves, and this workflow.
146
+ const paths = prefix
147
+ ? [
148
+ `${prefix}/**`,
149
+ ...(installRel !== prefix ? [installRel ? `${installRel}/package.json` : 'package.json'] : []),
150
+ ...['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb']
151
+ .filter((f) => installRoot && existsSync(join(installRoot, f)))
152
+ .map((f) => (installRel ? `${installRel}/${f}` : f)),
153
+ ...extraPaths.map((p) => `${p}/**`),
154
+ `.github/workflows/${name}.yml`,
155
+ ]
156
+ : []
157
+ const pathFilter = paths.length > 0 ? [` paths: [${[...new Set(paths)].map((p) => `'${p}'`).join(', ')}]`] : []
158
+ const lines = [
159
+ '# Written by `opencastle ci`. Fails a pull request when the AI assistant config',
160
+ "# every developer gets differs from its sources or breaks the team's policy,",
161
+ '# and summarises what the change does to the assistants.',
162
+ `name: AI assistant config${prefix ? ` (${prefix})` : ''}`,
163
+ '',
164
+ 'on:',
165
+ ' pull_request:',
166
+ ...pathFilter,
167
+ ' push:',
168
+ ` branches: [${branch}]`,
169
+ ...pathFilter,
170
+ '',
171
+ 'permissions:',
172
+ ' contents: read',
173
+ '',
174
+ 'jobs:',
175
+ ' opencastle:',
176
+ ' runs-on: ubuntu-latest',
177
+ ...(prefix ? [' defaults:', ' run:', ` working-directory: ${prefix}`] : []),
178
+ ' steps:',
179
+ ' # Pin actions to a commit SHA if your organisation requires it.',
180
+ ' - uses: actions/checkout@v4',
181
+ ' with:',
182
+ ' fetch-depth: 0',
183
+ ' - uses: actions/setup-node@v4',
184
+ ' with:',
185
+ ' node-version: 22',
186
+ ...install,
187
+ ' - name: Generated config matches its sources and policy',
188
+ ` run: ${run} sync --check`,
189
+ ' - name: What this pull request changes',
190
+ " if: github.event_name == 'pull_request'",
191
+ ` run: ${run} review --base origin/\${{ github.base_ref }}`,
192
+ '',
193
+ ]
194
+
195
+ const plan: Plan = { workflowPath, workflow: lines.join('\n'), pinned }
196
+ if (owners) {
197
+ const at = prefix ? `/${prefix}/` : '/'
198
+ // GitHub reads the first CODEOWNERS it finds — .github/, then the root,
199
+ // then docs/ — and ignores the rest. Creating .github/CODEOWNERS beside an
200
+ // existing one would switch every other ownership rule off.
201
+ const existing = ['.github/CODEOWNERS', 'CODEOWNERS', 'docs/CODEOWNERS'].map((p) => join(repoRoot, p)).find((p) => existsSync(p))
202
+ plan.codeowners = {
203
+ path: existing ?? join(repoRoot, '.github', 'CODEOWNERS'),
204
+ block: [
205
+ '',
206
+ '# What every AI assistant is given (opencastle ci). Every change to it moves',
207
+ '# the lock, so these two lines route all of them to the owners.',
208
+ `${at}${LOCK_REL} ${owners}`,
209
+ `${at}${TEAM_CONFIG_REL} ${owners}`,
210
+ '',
211
+ ].join('\n'),
212
+ }
213
+ }
214
+ return plan
215
+ }
216
+
217
+ export default async function ci({ pkgRoot, args }: CliContext): Promise<void> {
218
+ if (args.includes('--help') || args.includes('-h')) {
219
+ console.log(HELP)
220
+ return
221
+ }
222
+ const projectRoot = process.cwd()
223
+ const ownersAt = args.indexOf('--owners')
224
+ const owners = ownersAt !== -1 ? args[ownersAt + 1] : undefined
225
+ if (ownersAt !== -1 && (!owners || owners.startsWith('--'))) {
226
+ console.error(` ${c.red('✗')} --owners needs a team or user, e.g. --owners @acme/platform`)
227
+ process.exit(1)
228
+ }
229
+ if (!(await readManifest(projectRoot))) {
230
+ console.error(`\n ${c.red('✗')} OpenCastle is not set up here — run opencastle init first.\n`)
231
+ process.exit(1)
232
+ }
233
+
234
+ const manifest = await readManifest(projectRoot)
235
+ const manifestVersion = manifest?.version
236
+ // Baselines kept elsewhere in this repository: a change there must run the check.
237
+ const repoRoot = git(projectRoot, ['rev-parse', '--show-toplevel']) ?? projectRoot
238
+ const extra: string[] = []
239
+ try {
240
+ const resolved = resolveSources({ pkgRoot, projectRoot, stack: resolveStack(manifest!), repoInfo: manifest?.repoInfo })
241
+ for (const l of resolved.layers) {
242
+ if (l.kind !== 'baseline' || l.root.includes(`${sep}node_modules${sep}`)) continue
243
+ const rel = relative(repoRoot, l.root)
244
+ if (rel && !rel.startsWith('..') && relative(projectRoot, l.root).startsWith('..')) extra.push(rel.split(sep).join('/'))
245
+ }
246
+ } catch {
247
+ // The workflow is still right without them; sync --check will name the problem.
248
+ }
249
+ const plan = planCi(projectRoot, manifestVersion ?? cliVersionOf(pkgRoot), owners, extra)
250
+ const rel = (p: string): string => p.slice((git(projectRoot, ['rev-parse', '--show-toplevel']) ?? projectRoot).length + 1)
251
+
252
+ if (args.includes('--dry-run')) {
253
+ console.log(`\n ${c.dim(`[dry-run] ${rel(plan.workflowPath)}:`)}\n`)
254
+ console.log(plan.workflow.split('\n').map((l) => ` ${l}`).join('\n'))
255
+ if (plan.codeowners) {
256
+ console.log(` ${c.dim(`[dry-run] appended to ${rel(plan.codeowners.path)}:`)}`)
257
+ console.log(plan.codeowners.block.split('\n').map((l) => ` ${l}`).join('\n'))
258
+ }
259
+ console.log(` ${c.dim('No files were written.')}\n`)
260
+ return
261
+ }
262
+
263
+ if (existsSync(plan.workflowPath) && !args.includes('--force')) {
264
+ console.error(`\n ${c.red('✗')} ${rel(plan.workflowPath)} already exists. Pass --force to replace it.\n`)
265
+ process.exit(1)
266
+ }
267
+ await mkdir(dirname(plan.workflowPath), { recursive: true })
268
+ await writeFile(plan.workflowPath, plan.workflow)
269
+ console.log(`\n ${c.green('✓')} Wrote ${rel(plan.workflowPath)}`)
270
+
271
+ if (plan.codeowners) {
272
+ const existing = existsSync(plan.codeowners.path) ? readFileSync(plan.codeowners.path, 'utf8') : ''
273
+ const lockLine = plan.codeowners.block.split('\n').find((l) => l.includes(LOCK_REL)) ?? ''
274
+ if (existing.includes(lockLine.split(' ')[0])) {
275
+ console.log(` ${c.dim(`${rel(plan.codeowners.path)} already routes ${LOCK_REL}; left as it is`)}`)
276
+ } else {
277
+ await mkdir(dirname(plan.codeowners.path), { recursive: true })
278
+ await appendFile(plan.codeowners.path, plan.codeowners.block)
279
+ console.log(` ${c.green('✓')} Added ${owners} as owners of the lock and the team config in ${rel(plan.codeowners.path)}`)
280
+ }
281
+ }
282
+ if (!plan.pinned) {
283
+ console.log(
284
+ ` ${c.yellow('!')} ${c.dim('OpenCastle is not in devDependencies, so CI pins the version that compiled this project.')}`,
285
+ )
286
+ console.log(` ${c.dim('Add it (npm i -D opencastle) so laptops and CI run one version, then re-run with --force.')}`)
287
+ }
288
+ console.log(` ${c.dim('Commit it; the next pull request gets the check and a summary of what it changes.')}\n`)
289
+ }
@@ -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'])
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,