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
@@ -0,0 +1,179 @@
1
+ import { appendFileSync, existsSync } from 'node:fs'
2
+ import { isAbsolute, relative, resolve, sep } from 'node:path'
3
+ import type { CheckReport, Drift, DriftKind } from './sync-check.js'
4
+ import { LOCK_REL } from './lock.js'
5
+
6
+ /**
7
+ * Drift, told to GitHub in the two forms a pull request shows.
8
+ *
9
+ * `sync --check` in CI used to fail with its findings in the job log, which is
10
+ * three clicks from the pull request that caused them and read by nobody who
11
+ * did not already know to look. GitHub reads two things from a step without any
12
+ * extra action: workflow-command lines on stdout become annotations on the
13
+ * files in the PR, and Markdown appended to `$GITHUB_STEP_SUMMARY` becomes the
14
+ * run's summary page. Both are written here, only when `GITHUB_ACTIONS` says the
15
+ * step is running on GitHub, so a local run and every other CI print exactly
16
+ * what they printed before.
17
+ */
18
+
19
+ /**
20
+ * The detail `sync --check` records when the comparison itself could not run.
21
+ * Its `path` is then an error message, not a file, so it is the one drift that
22
+ * is not pinned to a file.
23
+ */
24
+ export const COMPARISON_FAILED = 'the comparison could not run'
25
+
26
+ const TITLES: Record<DriftKind, string> = {
27
+ changed: 'Generated file differs from its source',
28
+ missing: 'Generated file never committed',
29
+ extra: 'File added inside generated output',
30
+ outdated: 'MCP config that sync would change',
31
+ unreducible: 'Needs a person',
32
+ }
33
+
34
+ function isComparisonFailure(d: Drift): boolean {
35
+ return d.kind === 'unreducible' && d.detail === COMPARISON_FAILED
36
+ }
37
+
38
+ function titleOf(d: Drift): string {
39
+ if (d.origin === 'version') return 'OpenCastle is older than the project'
40
+ return d.origin === 'team' ? 'Team config problem' : TITLES[d.kind]
41
+ }
42
+
43
+ /** What the reader should do, per kind — they do not share a remedy. */
44
+ function explain(d: Drift): string {
45
+ const where = `${d.path} (${d.ide})`
46
+ switch (d.kind) {
47
+ // Not "edited by hand": the same state follows an upgrade nobody recompiled
48
+ // after, and blaming an edit that never happened sends people looking for it.
49
+ case 'changed':
50
+ if (d.path === LOCK_REL) {
51
+ return `${d.path}: the sources changed and nobody has run sync since. Run \`opencastle sync\` and commit the result; \`opencastle review\` explains the change.`
52
+ }
53
+ return `${where} differs from a fresh compile of its source. Run \`opencastle sync\` and commit the result. If the difference is a hand edit you want to keep, move it into .opencastle/ first — sync overwrites generated files.`
54
+ case 'missing':
55
+ return `${where} should exist but does not. Run \`opencastle sync\` and commit the result; generated config is committed like a lockfile.`
56
+ case 'extra':
57
+ return `${where} sits in generated output but no source produces it, so the next \`opencastle sync\` deletes it.`
58
+ case 'outdated':
59
+ return `${where}: ${d.detail ?? 'an MCP server entry sync would change'}. Run \`opencastle sync\` and commit — it touches only entries OpenCastle wrote and nobody edited.`
60
+ case 'unreducible':
61
+ if (isComparisonFailure(d)) return `The comparison could not run: ${d.path}.${d.fix ? ` Fix: ${d.fix}` : ''}`
62
+ return [`${where}: ${d.detail ?? 'needs a person'}`, d.fix && `Fix: ${d.fix}`].filter(Boolean).join('. ')
63
+ }
64
+ }
65
+
66
+ /** Workflow-command message escaping, as the runner decodes it. */
67
+ export function escapeData(text: string): string {
68
+ return text.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A')
69
+ }
70
+
71
+ /** Property values additionally reserve `:` and `,`. */
72
+ export function escapeProperty(text: string): string {
73
+ return escapeData(text).replace(/:/g, '%3A').replace(/,/g, '%2C')
74
+ }
75
+
76
+ /**
77
+ * The path GitHub should annotate: relative to the checkout, forward slashes.
78
+ *
79
+ * `sync --check` reports paths relative to the directory it ran in, and a
80
+ * project in a monorepo runs in a subdirectory — annotating `CLAUDE.md` when
81
+ * the file is `apps/web/CLAUDE.md` pins the comment on nothing.
82
+ */
83
+ export function annotationPath(path: string, projectRoot: string, workspace?: string): string {
84
+ const abs = isAbsolute(path) ? path : resolve(projectRoot, path)
85
+ const base = workspace ? resolve(workspace) : projectRoot
86
+ const rel = relative(base, abs)
87
+ const inside = rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)
88
+ return (inside ? rel : path).split(sep).join('/')
89
+ }
90
+
91
+ /** One `::error` line per drifted file. */
92
+ export function annotations(report: CheckReport, projectRoot: string, workspace?: string): string[] {
93
+ if (!report.installed) {
94
+ return [`::error title=${escapeProperty('OpenCastle is not set up')}::${escapeData('No OpenCastle installation found. Run `npx opencastle init` and commit the result.')}`]
95
+ }
96
+ return report.drift.map((d) => {
97
+ const props = [`title=${escapeProperty(titleOf(d))}`]
98
+ // Every drift names a file — `.gitignore`, a shared AGENTS.md, the manifest
99
+ // — except the one recording that the comparison could not run, whose path
100
+ // is an error message. Keying this on `ide === 'all'` left those real files
101
+ // unpinned.
102
+ // A team problem can sit in a baseline package, which is not a file in the
103
+ // pull request; pinning the annotation there pins it to nothing.
104
+ const pinnable = !isComparisonFailure(d) && ((d.origin !== 'team' && d.origin !== 'version') || existsSync(resolve(projectRoot, d.path)))
105
+ if (pinnable) props.unshift(`file=${escapeProperty(annotationPath(d.path, projectRoot, workspace))}`)
106
+ return `::error ${props.join(',')}::${escapeData(explain(d))}`
107
+ })
108
+ }
109
+
110
+ /** Markdown for the run summary page. */
111
+ export function summaryMarkdown(report: CheckReport): string {
112
+ const heading = '### OpenCastle — generated assistant config\n\n'
113
+ if (!report.installed) {
114
+ return `${heading}❌ No OpenCastle installation found. Run \`npx opencastle init\` and commit the result.\n`
115
+ }
116
+ const failed = report.drift.find(isComparisonFailure)
117
+ if (failed) {
118
+ return `${heading}❌ The comparison could not run: ${failed.path}.${failed.fix ? ` ${failed.fix}.` : ''}\n`
119
+ }
120
+ if (report.drift.length === 0) {
121
+ return (
122
+ `${heading}✅ ${report.checked} generated file${report.checked === 1 ? '' : 's'} match their sources ` +
123
+ `across ${report.ides.length} target${report.ides.length === 1 ? '' : 's'} (${report.ides.join(', ')}).\n`
124
+ )
125
+ }
126
+ const cell = (text: string) => text.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ')
127
+ const rows = report.drift.map(
128
+ (d) => `| \`${cell(d.path)}\` | ${cell(d.ide)} | ${cell(titleOf(d))} | ${cell(explain(d))} |`,
129
+ )
130
+ const fixable = report.drift.some((d) => d.kind !== 'unreducible')
131
+ return (
132
+ `${heading}❌ ${
133
+ report.drift.some((d) => d.origin === 'version')
134
+ ? 'This OpenCastle is older than the one that compiled the project, so nothing was compared'
135
+ : report.drift.every((d) => d.origin === 'team')
136
+ ? `The team's sources have ${report.drift.length === 1 ? 'a problem' : `${report.drift.length} problems`}, so nothing was compared`
137
+ : report.drift.every((d) => d.origin === 'mcp' && d.kind === 'unreducible')
138
+ ? `${report.drift.length} MCP config${report.drift.length === 1 ? ' has' : 's have'} a server only a person can fix`
139
+ : report.drift.length === 1
140
+ ? '1 file differs from its source'
141
+ : `${report.drift.length} files differ from their sources`
142
+ }.\n\n` +
143
+ '| File | Target | What happened | What to do |\n| --- | --- | --- | --- |\n' +
144
+ rows.join('\n') +
145
+ '\n\n' +
146
+ (fixable
147
+ ? 'Run `npx opencastle sync` locally and commit the result.\n'
148
+ : 'No command clears these; see each row.\n')
149
+ )
150
+ }
151
+
152
+ /**
153
+ * Write both forms when running on GitHub Actions.
154
+ *
155
+ * `json` suppresses the annotations: they are stdout lines, and a consumer
156
+ * parsing `--json` output would choke on them. The summary is a file, so it is
157
+ * still written. A summary file we cannot append to is not a reason to change
158
+ * the check's verdict — the verdict is the exit code, and it stands.
159
+ */
160
+ export function reportToGitHub(
161
+ report: CheckReport,
162
+ projectRoot: string,
163
+ options: { json?: boolean; env?: NodeJS.ProcessEnv; write?: (line: string) => void } = {},
164
+ ): void {
165
+ const env = options.env ?? process.env
166
+ if (env.GITHUB_ACTIONS !== 'true') return
167
+ const write = options.write ?? ((line: string) => console.log(line))
168
+ if (!options.json) {
169
+ for (const line of annotations(report, projectRoot, env.GITHUB_WORKSPACE)) write(line)
170
+ }
171
+ const summaryFile = env.GITHUB_STEP_SUMMARY
172
+ if (summaryFile) {
173
+ try {
174
+ appendFileSync(summaryFile, summaryMarkdown(report) + '\n')
175
+ } catch {
176
+ // See above: the exit code is the verdict.
177
+ }
178
+ }
179
+ }
@@ -67,6 +67,13 @@ const STACK_SANITY_LINEAR: StackConfig = {
67
67
  teamTools: ['linear'],
68
68
  }
69
69
 
70
+ /** One remote server and one launched through npx, for the format tests. */
71
+ const STACK_SANITY_PLAYWRIGHT: StackConfig = {
72
+ ides: ['vscode'],
73
+ techTools: ['sanity', 'playwright'],
74
+ teamTools: [],
75
+ }
76
+
70
77
  const STACK_SUPABASE_SLACK: StackConfig = {
71
78
  ides: ['vscode'],
72
79
  techTools: ['supabase'],
@@ -184,13 +191,9 @@ describe('stack-config: getRequiredMcpEnvVars', () => {
184
191
  expect(vars).toHaveLength(0)
185
192
  })
186
193
 
187
- it('returns LINEAR_API_KEY when linear is selected', () => {
194
+ it('asks for no Linear key — Linear’s own server signs in with OAuth', () => {
188
195
  const vars = getRequiredMcpEnvVars(STACK_SANITY_LINEAR)
189
- expect(vars).toEqual(
190
- expect.arrayContaining([
191
- expect.objectContaining({ envVar: 'LINEAR_API_KEY' }),
192
- ])
193
- )
196
+ expect(vars.map((v) => v.envVar)).not.toContain('LINEAR_API_KEY')
194
197
  })
195
198
 
196
199
  it('returns SLACK_MCP_XOXB_TOKEN when slack is selected', () => {
@@ -235,8 +238,7 @@ describe('stack-config: getAgentToolInjections', () => {
235
238
  const injections = getAgentToolInjections(STACK_SANITY_LINEAR)
236
239
  const teamLeadTools = injections.get('team-lead')
237
240
  expect(teamLeadTools).toBeDefined()
238
- expect(teamLeadTools).toContain('linear/create_issue')
239
- expect(teamLeadTools).toContain('linear/list_issues')
241
+ expect(teamLeadTools).toContain('linear/*')
240
242
  })
241
243
 
242
244
  it('injects supabase tools into data-engineer when supabase selected', () => {
@@ -251,7 +253,7 @@ describe('stack-config: getAgentToolInjections', () => {
251
253
  const injections = getAgentToolInjections(STACK_FULL)
252
254
  const teamLeadTools = injections.get('team-lead')!
253
255
  // Linear + Slack tools on team-lead
254
- expect(teamLeadTools).toContain('linear/create_issue')
256
+ expect(teamLeadTools).toContain('linear/*')
255
257
  expect(teamLeadTools).toContain('slack/*')
256
258
  })
257
259
 
@@ -490,9 +492,7 @@ describe('VS Code adapter install', () => {
490
492
  join(tempDir, '.github', 'agents', 'team-lead.agent.md'),
491
493
  'utf8'
492
494
  )
493
- expect(teamLead).toContain("'linear/create_issue'")
494
- expect(teamLead).toContain("'linear/list_issues'")
495
- expect(teamLead).toContain("'linear/update_issue'")
495
+ expect(teamLead).toContain("'linear/*'")
496
496
  })
497
497
 
498
498
  it('does NOT inject tools when no plugins selected', async () => {
@@ -527,12 +527,10 @@ describe('VS Code adapter install', () => {
527
527
  expect(sanityServer.type).toBe('http')
528
528
  expect(sanityServer.url).toBe('https://mcp.sanity.io')
529
529
 
530
- // Linear uses stdio
530
+ // Linear is Linear's own remote server
531
531
  const linearServer = servers.Linear as Record<string, unknown>
532
- expect(linearServer.type).toBe('stdio')
533
- expect(linearServer.command).toBe('npx')
534
- expect(linearServer.args).toContain('-y')
535
- expect(linearServer.args).toContain('@mseep/linear-mcp')
532
+ expect(linearServer.type).toBe('http')
533
+ expect(linearServer.url).toBe('https://mcp.linear.app/mcp')
536
534
  })
537
535
 
538
536
  it('generates empty MCP config when no tools selected', async () => {
@@ -683,7 +681,7 @@ describe('Cursor adapter install', () => {
683
681
 
684
682
  it('generates Cursor MCP config with mcpServers format', async () => {
685
683
  const adapter = await IDE_ADAPTERS['cursor']()
686
- await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
684
+ await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_PLAYWRIGHT, EMPTY_REPO_INFO)
687
685
 
688
686
  const mcpConfig = await readJson<Record<string, unknown>>(
689
687
  join(tempDir, '.cursor', 'mcp.json')
@@ -700,11 +698,11 @@ describe('Cursor adapter install', () => {
700
698
  expect(servers.Sanity.url).toBe('https://mcp.sanity.io')
701
699
  expect(servers.Sanity).not.toHaveProperty('type')
702
700
 
703
- // stdio servers get command + args (no type field)
704
- expect(servers.Linear).toBeDefined()
705
- expect(servers.Linear.command).toBe('npx')
706
- expect(servers.Linear.args).toContain('@mseep/linear-mcp')
707
- expect(servers.Linear).not.toHaveProperty('type')
701
+ // stdio servers get command + args (no type field), pinned
702
+ expect(servers.Playwright).toBeDefined()
703
+ expect(servers.Playwright.command).toBe('npx')
704
+ expect((servers.Playwright.args as string[]).some((a) => /^@playwright\/mcp@\d/.test(a))).toBe(true)
705
+ expect(servers.Playwright).not.toHaveProperty('type')
708
706
  })
709
707
 
710
708
  it('getManagedPaths returns expected Cursor paths', async () => {
@@ -914,7 +912,7 @@ describe('OpenCode adapter install', () => {
914
912
 
915
913
  it('generates OpenCode MCP config with mcp format', async () => {
916
914
  const adapter = await IDE_ADAPTERS['opencode']()
917
- await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
915
+ await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_PLAYWRIGHT, EMPTY_REPO_INFO)
918
916
 
919
917
  const mcpConfig = await readJson<Record<string, unknown>>(
920
918
  join(tempDir, 'opencode.json')
@@ -933,9 +931,11 @@ describe('OpenCode adapter install', () => {
933
931
  expect(mcp.Sanity.url).toBe('https://mcp.sanity.io')
934
932
 
935
933
  // stdio servers → type: 'local', command as array
936
- expect(mcp.Linear).toBeDefined()
937
- expect(mcp.Linear.type).toBe('local')
938
- expect(mcp.Linear.command).toEqual(['npx', '-y', '@mseep/linear-mcp'])
934
+ expect(mcp.Playwright).toBeDefined()
935
+ expect(mcp.Playwright.type).toBe('local')
936
+ const command = mcp.Playwright.command as string[]
937
+ expect(command.slice(0, 2)).toEqual(['npx', '-y'])
938
+ expect(command[2]).toMatch(/^@playwright\/mcp@\d/)
939
939
  })
940
940
 
941
941
  it('workflows do NOT have prefix in opencode adapter', async () => {
package/src/cli/init.ts CHANGED
@@ -5,7 +5,7 @@ import { multiselect, confirm, closePrompts, c } from './prompt.js'
5
5
  import { readManifest, writeManifest, createManifest } from './manifest.js'
6
6
  import { removeDirIfExists, copyDir, getOrchestratorRoot } from './copy.js'
7
7
  import { updateGitignore } from './gitignore.js'
8
- import { getRequiredMcpEnvVars, getCustomizationsTransform } from './stack-config.js'
8
+ import { getCustomizationsTransform } from './stack-config.js'
9
9
  import { getMcpConfigRelPath, stripManagedMcpServers } from './mcp.js'
10
10
  import { getPluginsBySubCategory } from '../orchestrator/plugins/index.js'
11
11
  import type { PluginConfig } from '../orchestrator/plugins/types.js'
@@ -17,6 +17,9 @@ import { bootstrapCustomizations } from './bootstrap.js'
17
17
  import { stripManagedBlock, stripManagedBlockFromFile } from './managed-block.js'
18
18
  import { resolveManagedPaths, declaredManagedPaths } from './managed-paths.js'
19
19
  import { noteUnreadable } from './unreadable-report.js'
20
+ import { resolveSources, materialize, hasErrors, formatIssues, requiredEnvVars } from './layers.js'
21
+ import { buildLock, writeLock, priorTeam } from './lock.js'
22
+ import { parseVersion, compareVersions } from './version-range.js'
20
23
 
21
24
  const INIT_HELP = `
22
25
  opencastle init [options]
@@ -28,6 +31,8 @@ const INIT_HELP = `
28
31
  --customize, --reconfigure Choose IDEs and integrations manually
29
32
  --yes, -y Accept the detected setup without asking
30
33
  --dry-run Preview what would be changed without writing files
34
+ --allow-downgrade Re-run with this OpenCastle even though a newer one
35
+ compiled the project
31
36
  --help, -h Show this help
32
37
  `
33
38
 
@@ -200,6 +205,19 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
200
205
  console.log(`\n 🏰 ${c.bold('OpenCastle')} ${c.dim(`v${pkg.version}`)}`)
201
206
  console.log(` ${c.dim('Compiles your AI assistant config for every assistant you use')}\n`)
202
207
 
208
+ // The same guard `sync` has: re-running `init` over a project a newer
209
+ // release compiled recompiles it with this one, and restamps the manifest.
210
+ if (existing) {
211
+ const mine = parseVersion(pkg.version)
212
+ const theirs = parseVersion(existing.version)
213
+ if (mine && theirs && compareVersions(mine, theirs) < 0 && !args.includes('--allow-downgrade')) {
214
+ console.error(` ${c.red('✗')} This project was compiled by OpenCastle ${existing.version}; this is ${pkg.version}.`)
215
+ console.error(` ${c.dim(`Run npx opencastle@${existing.version} — or pass --allow-downgrade to go back on purpose.`)}\n`)
216
+ closePrompts()
217
+ process.exit(1)
218
+ }
219
+ }
220
+
203
221
  // ── Detect ──────────────────────────────────────────────────────
204
222
  console.log(` ${c.dim('Scanning repository…')}`)
205
223
  const repoInfo = await detectRepoInfo(projectRoot)
@@ -294,6 +312,19 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
294
312
  console.log()
295
313
  }
296
314
 
315
+ // The team's sources, before anything is written. A repository that already
316
+ // carries `.opencastle/config.json` — a clone of a team project being set up
317
+ // again — must compile to the same standard `sync` holds it to, or refuse.
318
+ const resolved = resolveSources({ pkgRoot, projectRoot, stack, repoInfo: combinedRepoInfo })
319
+ if (hasErrors(resolved)) {
320
+ const errors = resolved.issues.filter((i) => i.level === 'error')
321
+ console.error(`\n ${c.red('✗')} The team's sources have ${errors.length} problem(s); nothing was written.\n`)
322
+ for (const line of formatIssues(errors)) console.error(` ${line}`)
323
+ console.error('')
324
+ closePrompts()
325
+ process.exit(1)
326
+ }
327
+
297
328
  // ── Dry run ─────────────────────────────────────────────────────
298
329
  if (dryRun) {
299
330
  for (const ide of ides) {
@@ -396,102 +427,109 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
396
427
  const unreadable: string[] = []
397
428
  const failedTargets: Array<{ ide: string; message: string }> = []
398
429
 
399
- for (const ide of ides) {
400
- const adapter = await IDE_ADAPTERS[ide]()
401
- // Re-running over an existing install recompiles; a first install scaffolds.
402
- //
403
- // `install` is scaffold-once by contract, so re-init left every generated
404
- // file exactly as it found it — and then stamped the manifest with the
405
- // current version. The record said 0.36 while the tree was still 0.30. It
406
- // was recoverable, because `sync --check` compares content and not version
407
- // numbers, but a command that writes a version it did not compile is
408
- // asserting something it has not done.
409
- // One target failing must not abort the others, and must not abort the
410
- // manifest. The loop had no guard, and the manifest is written after it, so
411
- // a second target throwing — an unwritable `.github/copilot-instructions.md`
412
- // is enough — left the first target's 78 files on disk with no manifest at
413
- // all: the front door said "not set up", `sync` said to run `init`, `init`
414
- // failed the same way, and `remove --all` refused to uninstall what it had
415
- // just installed. Single-target installs write the root file first and so
416
- // throw before anything lands, which is why this only showed up with two.
417
- let results: CopyResults
418
- try {
419
- results = isReinit
420
- ? await adapter.update(pkgRoot, projectRoot, stack, combinedRepoInfo)
421
- : await adapter.install(pkgRoot, projectRoot, stack, combinedRepoInfo)
422
- } catch (err) {
423
- failedTargets.push({ ide, message: (err as Error).message })
424
- continue
425
- }
426
- totalCreated += results.created.length
427
- totalSkipped += results.skipped.length
428
- skippedPaths.push(...results.skipped)
429
- for (const file of results.unreadable ?? []) {
430
- noteUnreadable(unreadable, file)
431
- }
430
+ const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
431
+ try {
432
+ for (const ide of ides) {
433
+ const adapter = await IDE_ADAPTERS[ide]()
434
+ // Re-running over an existing install recompiles; a first install scaffolds.
435
+ //
436
+ // `install` is scaffold-once by contract, so re-init left every generated
437
+ // file exactly as it found it — and then stamped the manifest with the
438
+ // current version. The record said 0.36 while the tree was still 0.30. It
439
+ // was recoverable, because `sync --check` compares content and not version
440
+ // numbers, but a command that writes a version it did not compile is
441
+ // asserting something it has not done.
442
+ // One target failing must not abort the others, and must not abort the
443
+ // manifest. The loop had no guard, and the manifest is written after it, so
444
+ // a second target throwing — an unwritable `.github/copilot-instructions.md`
445
+ // is enough — left the first target's 78 files on disk with no manifest at
446
+ // all: the front door said "not set up", `sync` said to run `init`, `init`
447
+ // failed the same way, and `remove --all` refused to uninstall what it had
448
+ // just installed. Single-target installs write the root file first and so
449
+ // throw before anything lands, which is why this only showed up with two.
450
+ let results: CopyResults
451
+ try {
452
+ results = isReinit
453
+ ? await adapter.update(pkgRoot, projectRoot, stack, combinedRepoInfo, source)
454
+ : await adapter.install(pkgRoot, projectRoot, stack, combinedRepoInfo, source)
455
+ } catch (err) {
456
+ failedTargets.push({ ide, message: (err as Error).message })
457
+ continue
458
+ }
459
+ totalCreated += results.created.length
460
+ totalSkipped += results.skipped.length
461
+ skippedPaths.push(...results.skipped)
462
+ for (const file of results.unreadable ?? []) {
463
+ noteUnreadable(unreadable, file)
464
+ }
465
+
466
+ adoptedRoots.push(...(results.adopted ?? []))
467
+ repairedRoots.push(...(results.repaired ?? []))
468
+ damagedRoots.push(...(results.damagedRoots ?? []))
469
+ severedRoots.push(...(results.severedRoots ?? []))
470
+ staleRoots.push(...(results.staleRoots ?? []))
471
+ tornRoots.push(...(results.tornRoots ?? []))
432
472
 
433
- adoptedRoots.push(...(results.adopted ?? []))
434
- repairedRoots.push(...(results.repaired ?? []))
435
- damagedRoots.push(...(results.damagedRoots ?? []))
436
- severedRoots.push(...(results.severedRoots ?? []))
437
- staleRoots.push(...(results.staleRoots ?? []))
438
- tornRoots.push(...(results.tornRoots ?? []))
439
-
440
- const managed = adapter.getManagedPaths()
441
- allManagedPaths.framework.push(...managed.framework)
442
- allManagedPaths.customizable.push(...managed.customizable)
443
- // Deduplicated: opencode and codex share AGENTS.md, so a per-adapter push
444
- // listed it twice — "Merged into your existing …, AGENTS.md, AGENTS.md".
445
- for (const m of managed.merged ?? []) {
446
- if (!allManagedPaths.merged.includes(m)) allManagedPaths.merged.push(m)
473
+ const managed = adapter.getManagedPaths()
474
+ allManagedPaths.framework.push(...managed.framework)
475
+ allManagedPaths.customizable.push(...managed.customizable)
476
+ // Deduplicated: opencode and codex share AGENTS.md, so a per-adapter push
477
+ // listed it twice — "Merged into your existing …, AGENTS.md, AGENTS.md".
478
+ for (const m of managed.merged ?? []) {
479
+ if (!allManagedPaths.merged.includes(m)) allManagedPaths.merged.push(m)
480
+ }
447
481
  }
448
- }
449
482
 
450
- // If all files were skipped (orphaned install — no manifest but files exist)
451
- if (totalCreated === 0 && totalSkipped > 0 && !isReinit) {
452
- console.log(` ${c.yellow('⚠')} Found ${totalSkipped} existing files from a previous installation.`)
453
- // `--yes` is documented as "accept the detected setup without asking", and
454
- // this was the one question it did not cover. On a TTY it still asked.
455
- // `refuse`, because the default here overwrites. A piped run that ran out of
456
- // answers before this question took the destructive branch in silence.
457
- const overwrite =
458
- assumeYes || (await confirm('Overwrite existing files?', true, 'refuse'))
459
- if (overwrite) {
460
- // Recompile in place rather than emptying the tree first.
461
- //
462
- // Deleting every framework path and re-installing was the old shape, and
463
- // it made `init` the one command that could destroy an install by
464
- // failing: an unwritable CLAUDE.md, met after 62 files had already been
465
- // unlinked, left the directories empty and the manifest claiming an
466
- // install. `update` writes the new output before sweeping what has no
467
- // source left, which is the same guarantee `sync` gives.
468
- totalCreated = 0
469
- totalSkipped = 0
470
- for (const ide of ides) {
471
- const adapter = await IDE_ADAPTERS[ide]()
472
- // Guarded like the main loop above, and for the same reason: this one
473
- // was not, so a re-entry over an orphaned install that failed on the
474
- // second target left 91 files on disk with no manifest and every
475
- // command dead-ended — the front door saying "not set up", `sync`
476
- // saying run `init`, `init` failing identically, `remove` refusing.
477
- let results: CopyResults
478
- try {
479
- results = await adapter.update(pkgRoot, projectRoot, stack, combinedRepoInfo)
480
- } catch (err) {
481
- failedTargets.push({ ide, message: (err as Error).message })
482
- continue
483
- }
484
- // `copied` too. Counting only `created` and `skipped` made this path
485
- // report "Created 0 files / Left 29 existing files untouched" over a
486
- // run that had just rewritten 78 of them — the summary asserting the
487
- // opposite of what happened, on the one path that exists to overwrite.
488
- totalCreated += results.created.length + results.copied.length
489
- totalSkipped += results.skipped.length
490
- for (const file of results.unreadable ?? []) {
491
- noteUnreadable(unreadable, file)
483
+ // If all files were skipped (orphaned install — no manifest but files exist)
484
+ if (totalCreated === 0 && totalSkipped > 0 && !isReinit) {
485
+ console.log(` ${c.yellow('⚠')} Found ${totalSkipped} existing files from a previous installation.`)
486
+ // `--yes` is documented as "accept the detected setup without asking", and
487
+ // this was the one question it did not cover. On a TTY it still asked.
488
+ // `refuse`, because the default here overwrites. A piped run that ran out of
489
+ // answers before this question took the destructive branch in silence.
490
+ const overwrite =
491
+ assumeYes || (await confirm('Overwrite existing files?', true, 'refuse'))
492
+ if (overwrite) {
493
+ // Recompile in place rather than emptying the tree first.
494
+ //
495
+ // Deleting every framework path and re-installing was the old shape, and
496
+ // it made `init` the one command that could destroy an install by
497
+ // failing: an unwritable CLAUDE.md, met after 62 files had already been
498
+ // unlinked, left the directories empty and the manifest claiming an
499
+ // install. `update` writes the new output before sweeping what has no
500
+ // source left, which is the same guarantee `sync` gives.
501
+ totalCreated = 0
502
+ totalSkipped = 0
503
+ for (const ide of ides) {
504
+ const adapter = await IDE_ADAPTERS[ide]()
505
+ // Guarded like the main loop above, and for the same reason: this one
506
+ // was not, so a re-entry over an orphaned install that failed on the
507
+ // second target left 91 files on disk with no manifest and every
508
+ // command dead-ended — the front door saying "not set up", `sync`
509
+ // saying run `init`, `init` failing identically, `remove` refusing.
510
+ let results: CopyResults
511
+ try {
512
+ results = await adapter.update(pkgRoot, projectRoot, stack, combinedRepoInfo, source)
513
+ } catch (err) {
514
+ failedTargets.push({ ide, message: (err as Error).message })
515
+ continue
516
+ }
517
+ // `copied` too. Counting only `created` and `skipped` made this path
518
+ // report "Created 0 files / Left 29 existing files untouched" over a
519
+ // run that had just rewritten 78 of them — the summary asserting the
520
+ // opposite of what happened, on the one path that exists to overwrite.
521
+ totalCreated += results.created.length + results.copied.length
522
+ totalSkipped += results.skipped.length
523
+ for (const file of results.unreadable ?? []) {
524
+ noteUnreadable(unreadable, file)
525
+ }
492
526
  }
493
527
  }
494
528
  }
529
+
530
+ await writeLock(projectRoot, buildLock(source, { ides: ides as string[], stack, repoInfo: combinedRepoInfo }))
531
+ } finally {
532
+ source.dispose()
495
533
  }
496
534
 
497
535
  // ── Scaffold customizations to .opencastle/ ──────────────────────────────
@@ -569,12 +607,16 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
569
607
  // install, and resetting it threw away when the project actually adopted the tool.
570
608
  if (existing?.installedAt) manifest.installedAt = existing.installedAt
571
609
  manifest.stack = stack
572
- manifest.repoInfo = combinedRepoInfo
610
+ // Detected again now that the install exists, as `sync` will detect it. The
611
+ // first detection ran before the MCP configs were written, so the record
612
+ // differed from what the next sync saw and that sync rewrote the manifest —
613
+ // a committed file changing on a run that changed nothing about the project.
614
+ manifest.repoInfo = mergeStackIntoRepoInfo(await detectRepoInfo(projectRoot), stack)
573
615
  await writeManifest(projectRoot, manifest)
574
616
 
575
617
  // ── Update .gitignore ───────────────────────────────────────────
576
618
  // Only local artefacts and .env; the generated config is meant to be committed.
577
- const envVars = getRequiredMcpEnvVars(stack, combinedRepoInfo)
619
+ const envVars = requiredEnvVars(resolved, stack, combinedRepoInfo)
578
620
  const gitignoreResult = await updateGitignore(projectRoot)
579
621
 
580
622
  // ── Summary ─────────────────────────────────────────────────────