opencastle 1.1.0 → 1.2.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 (276) hide show
  1. package/README.md +23 -6
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/codex.d.ts +19 -6
  4. package/dist/cli/adapters/codex.d.ts.map +1 -1
  5. package/dist/cli/adapters/codex.js +24 -7
  6. package/dist/cli/adapters/codex.js.map +1 -1
  7. package/dist/cli/adapters/single-file-base.d.ts +7 -0
  8. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  9. package/dist/cli/adapters/single-file-base.js +59 -22
  10. package/dist/cli/adapters/single-file-base.js.map +1 -1
  11. package/dist/cli/agent-plugin.d.ts +119 -0
  12. package/dist/cli/agent-plugin.d.ts.map +1 -0
  13. package/dist/cli/agent-plugin.js +449 -0
  14. package/dist/cli/agent-plugin.js.map +1 -0
  15. package/dist/cli/agent-plugin.test.d.ts +2 -0
  16. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  17. package/dist/cli/agent-plugin.test.js +227 -0
  18. package/dist/cli/agent-plugin.test.js.map +1 -0
  19. package/dist/cli/baseline.d.ts.map +1 -1
  20. package/dist/cli/baseline.js +99 -26
  21. package/dist/cli/baseline.js.map +1 -1
  22. package/dist/cli/codex-target.test.d.ts +2 -0
  23. package/dist/cli/codex-target.test.d.ts.map +1 -0
  24. package/dist/cli/codex-target.test.js +154 -0
  25. package/dist/cli/codex-target.test.js.map +1 -0
  26. package/dist/cli/convoy/gates.d.ts +2 -20
  27. package/dist/cli/convoy/gates.d.ts.map +1 -1
  28. package/dist/cli/convoy/gates.js +3 -111
  29. package/dist/cli/convoy/gates.js.map +1 -1
  30. package/dist/cli/copy.d.ts +0 -8
  31. package/dist/cli/copy.d.ts.map +1 -1
  32. package/dist/cli/copy.js +0 -21
  33. package/dist/cli/copy.js.map +1 -1
  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 +2 -0
  37. package/dist/cli/docs-accuracy.test.js.map +1 -1
  38. package/dist/cli/doctor.d.ts.map +1 -1
  39. package/dist/cli/doctor.js +4 -1
  40. package/dist/cli/doctor.js.map +1 -1
  41. package/dist/cli/init.d.ts.map +1 -1
  42. package/dist/cli/init.js +5 -4
  43. package/dist/cli/init.js.map +1 -1
  44. package/dist/cli/init.test.js +58 -34
  45. package/dist/cli/init.test.js.map +1 -1
  46. package/dist/cli/layers.d.ts +8 -0
  47. package/dist/cli/layers.d.ts.map +1 -1
  48. package/dist/cli/layers.js +130 -13
  49. package/dist/cli/layers.js.map +1 -1
  50. package/dist/cli/layers.test.js +2 -2
  51. package/dist/cli/layers.test.js.map +1 -1
  52. package/dist/cli/legacy-install.test.js +8 -1
  53. package/dist/cli/legacy-install.test.js.map +1 -1
  54. package/dist/cli/lesson-command.test.d.ts +2 -0
  55. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  56. package/dist/cli/lesson-command.test.js +100 -0
  57. package/dist/cli/lesson-command.test.js.map +1 -0
  58. package/dist/cli/lesson.d.ts +0 -9
  59. package/dist/cli/lesson.d.ts.map +1 -1
  60. package/dist/cli/lesson.js +212 -276
  61. package/dist/cli/lesson.js.map +1 -1
  62. package/dist/cli/lessons.d.ts +134 -0
  63. package/dist/cli/lessons.d.ts.map +1 -0
  64. package/dist/cli/lessons.js +493 -0
  65. package/dist/cli/lessons.js.map +1 -0
  66. package/dist/cli/lessons.test.d.ts +2 -0
  67. package/dist/cli/lessons.test.d.ts.map +1 -0
  68. package/dist/cli/lessons.test.js +214 -0
  69. package/dist/cli/lessons.test.js.map +1 -0
  70. package/dist/cli/managed-paths.d.ts.map +1 -1
  71. package/dist/cli/managed-paths.js +2 -0
  72. package/dist/cli/managed-paths.js.map +1 -1
  73. package/dist/cli/mcp-audit.d.ts.map +1 -1
  74. package/dist/cli/mcp-audit.js +7 -3
  75. package/dist/cli/mcp-audit.js.map +1 -1
  76. package/dist/cli/mcp-file.d.ts +37 -0
  77. package/dist/cli/mcp-file.d.ts.map +1 -0
  78. package/dist/cli/mcp-file.js +291 -0
  79. package/dist/cli/mcp-file.js.map +1 -0
  80. package/dist/cli/mcp-file.test.d.ts +2 -0
  81. package/dist/cli/mcp-file.test.d.ts.map +1 -0
  82. package/dist/cli/mcp-file.test.js +121 -0
  83. package/dist/cli/mcp-file.test.js.map +1 -0
  84. package/dist/cli/mcp.d.ts +15 -0
  85. package/dist/cli/mcp.d.ts.map +1 -1
  86. package/dist/cli/mcp.js +123 -56
  87. package/dist/cli/mcp.js.map +1 -1
  88. package/dist/cli/pack-plugins.d.ts +8 -0
  89. package/dist/cli/pack-plugins.d.ts.map +1 -0
  90. package/dist/cli/pack-plugins.js +70 -0
  91. package/dist/cli/pack-plugins.js.map +1 -0
  92. package/dist/cli/plugin-command.test.d.ts +2 -0
  93. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  94. package/dist/cli/plugin-command.test.js +114 -0
  95. package/dist/cli/plugin-command.test.js.map +1 -0
  96. package/dist/cli/plugin.d.ts +30 -0
  97. package/dist/cli/plugin.d.ts.map +1 -0
  98. package/dist/cli/plugin.js +291 -0
  99. package/dist/cli/plugin.js.map +1 -0
  100. package/dist/cli/promote-command.test.d.ts +2 -0
  101. package/dist/cli/promote-command.test.d.ts.map +1 -0
  102. package/dist/cli/promote-command.test.js +151 -0
  103. package/dist/cli/promote-command.test.js.map +1 -0
  104. package/dist/cli/promote.d.ts +12 -0
  105. package/dist/cli/promote.d.ts.map +1 -0
  106. package/dist/cli/promote.js +364 -0
  107. package/dist/cli/promote.js.map +1 -0
  108. package/dist/cli/remove.d.ts.map +1 -1
  109. package/dist/cli/remove.js +23 -4
  110. package/dist/cli/remove.js.map +1 -1
  111. package/dist/cli/secret-scan.d.ts +21 -0
  112. package/dist/cli/secret-scan.d.ts.map +1 -0
  113. package/dist/cli/secret-scan.js +114 -0
  114. package/dist/cli/secret-scan.js.map +1 -0
  115. package/dist/cli/sync-check.d.ts.map +1 -1
  116. package/dist/cli/sync-check.js +13 -3
  117. package/dist/cli/sync-check.js.map +1 -1
  118. package/dist/cli/sync-check.test.js +2 -2
  119. package/dist/cli/sync-check.test.js.map +1 -1
  120. package/dist/cli/team-commands.test.js +2 -2
  121. package/dist/cli/team-commands.test.js.map +1 -1
  122. package/dist/cli/types.d.ts +5 -2
  123. package/dist/cli/types.d.ts.map +1 -1
  124. package/dist/cli/types.js +3 -0
  125. package/dist/cli/types.js.map +1 -1
  126. package/dist/cli/unreadable-report.d.ts +7 -0
  127. package/dist/cli/unreadable-report.d.ts.map +1 -1
  128. package/dist/cli/unreadable-report.js +14 -0
  129. package/dist/cli/unreadable-report.js.map +1 -1
  130. package/dist/cli/update.d.ts.map +1 -1
  131. package/dist/cli/update.js +73 -5
  132. package/dist/cli/update.js.map +1 -1
  133. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  134. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  135. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  136. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  137. package/package.json +3 -1
  138. package/src/cli/adapters/codex.ts +25 -7
  139. package/src/cli/adapters/single-file-base.ts +69 -26
  140. package/src/cli/agent-plugin.test.ts +267 -0
  141. package/src/cli/agent-plugin.ts +469 -0
  142. package/src/cli/baseline.ts +99 -26
  143. package/src/cli/codex-target.test.ts +178 -0
  144. package/src/cli/convoy/gates.ts +9 -142
  145. package/src/cli/copy.ts +0 -25
  146. package/src/cli/dispatcher.test.ts +2 -2
  147. package/src/cli/docs-accuracy.test.ts +2 -0
  148. package/src/cli/doctor.ts +5 -2
  149. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  150. package/src/cli/init.test.ts +59 -34
  151. package/src/cli/init.ts +5 -4
  152. package/src/cli/layers.test.ts +2 -2
  153. package/src/cli/layers.ts +144 -14
  154. package/src/cli/legacy-install.test.ts +11 -1
  155. package/src/cli/lesson-command.test.ts +117 -0
  156. package/src/cli/lesson.ts +215 -266
  157. package/src/cli/lessons.test.ts +254 -0
  158. package/src/cli/lessons.ts +540 -0
  159. package/src/cli/managed-paths.ts +2 -0
  160. package/src/cli/mcp-audit.ts +7 -3
  161. package/src/cli/mcp-file.test.ts +138 -0
  162. package/src/cli/mcp-file.ts +302 -0
  163. package/src/cli/mcp.ts +130 -60
  164. package/src/cli/pack-plugins.ts +70 -0
  165. package/src/cli/plugin-command.test.ts +125 -0
  166. package/src/cli/plugin.ts +309 -0
  167. package/src/cli/promote-command.test.ts +170 -0
  168. package/src/cli/promote.ts +371 -0
  169. package/src/cli/remove.ts +20 -4
  170. package/src/cli/secret-scan.ts +154 -0
  171. package/src/cli/sync-check.test.ts +2 -2
  172. package/src/cli/sync-check.ts +13 -3
  173. package/src/cli/team-commands.test.ts +2 -2
  174. package/src/cli/types.ts +5 -2
  175. package/src/cli/unreadable-report.ts +14 -0
  176. package/src/cli/update.ts +81 -5
  177. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  178. package/src/orchestrator/agents/researcher.agent.md +1 -1
  179. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  180. package/src/orchestrator/customizations/README.md +2 -1
  181. package/src/orchestrator/customizations/logs/README.md +1 -1
  182. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  183. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  184. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  185. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  186. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  187. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  188. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  189. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  190. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  191. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  192. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  193. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  194. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  195. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  196. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  197. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  198. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  199. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  200. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  201. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  202. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  203. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  204. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  205. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  206. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  207. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  208. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  209. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  210. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  211. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  212. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  213. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  214. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  215. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  216. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  217. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  218. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  219. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  220. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  221. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  222. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  223. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  224. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  225. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  226. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  227. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  228. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  229. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  230. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  231. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  232. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  233. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  234. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  235. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  236. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  237. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  238. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  239. package/src/orchestrator/skill-config-links.test.ts +2 -1
  240. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  241. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  242. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  243. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  244. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  245. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  246. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  247. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  248. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  249. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  250. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  251. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  252. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  253. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  254. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  255. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  256. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  257. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  258. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  259. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  260. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  261. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  262. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  263. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  264. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  265. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  266. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  267. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  268. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  269. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  270. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  271. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  272. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  273. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  274. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  275. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  276. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
package/src/cli/mcp.ts CHANGED
@@ -8,6 +8,7 @@ import type { McpInput, McpServerConfig, EnvVarRequirement } from '../orchestrat
8
8
  import type { ScaffoldResult, StackConfig, RepoInfo, IdeChoice, CopyResults } from './types.js';
9
9
  import type { TeamMcpPlan } from './layers.js';
10
10
  import { EDITOR_VARIABLES, type TeamMcpServer } from './team-config.js';
11
+ import { parseMcpConfigText, serialiseMcpConfig, TomlEditError } from './mcp-file.js';
11
12
 
12
13
  // ── IDE-specific MCP format transformation ────────────────────
13
14
 
@@ -63,6 +64,12 @@ function editorVariableFor(ide: IdeChoice, name: string, original: string): stri
63
64
  return original;
64
65
  }
65
66
 
67
+ /** The variable a value is wholly a reference to — `${NAME}` and nothing else — or null. */
68
+ function wholeReference(value: string): string | null {
69
+ const m = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(value);
70
+ return m && !EDITOR_VARIABLES.has(m[1]) ? m[1] : null;
71
+ }
72
+
66
73
  /** Rewrite every `${NAME}` in a value into the target's own spelling. */
67
74
  function rewriteRefs(value: string, ide: IdeChoice): string {
68
75
  return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, name: string) =>
@@ -87,7 +94,6 @@ function transformMcpForIde(
87
94
  case 'cursor':
88
95
  case 'claude-code':
89
96
  case 'windsurf':
90
- case 'codex':
91
97
  case 'antigravity': {
92
98
  // mcpServers format — no 'type' field
93
99
  const mcpServers: Record<string, unknown> = {};
@@ -115,6 +121,53 @@ function transformMcpForIde(
115
121
  return { mcpServers };
116
122
  }
117
123
 
124
+ case 'codex': {
125
+ // Codex CLI reads `[mcp_servers.<name>]` tables in `.codex/config.toml`
126
+ // and expands no variables anywhere in them. What it offers instead is
127
+ // structural: `env_vars` forwards a variable from the environment Codex
128
+ // was started in, `bearer_token_env_var` sends `Authorization: Bearer`
129
+ // with one, and `env_http_headers` sets a header to one. A reference that
130
+ // is exactly one of those shapes is written as it; anything else is left
131
+ // as written, and `doctor` says so.
132
+ const mcp_servers: Record<string, unknown> = {};
133
+ for (const [name, server] of Object.entries(servers)) {
134
+ if (server.type === 'stdio') {
135
+ const env: Record<string, string> = {};
136
+ const envVars: string[] = [];
137
+ for (const [key, value] of Object.entries(server.env ?? {})) {
138
+ if (wholeReference(value) === key) envVars.push(key);
139
+ else env[key] = value;
140
+ }
141
+ mcp_servers[name] = {
142
+ command: server.command,
143
+ ...(server.args && { args: server.args }),
144
+ ...(Object.keys(env).length > 0 && { env }),
145
+ ...(envVars.length > 0 && { env_vars: envVars }),
146
+ };
147
+ } else if (server.type === 'http') {
148
+ const url = (server.url ?? '').replace(/\$\{input:\w+\}/g, 'REPLACE_ME');
149
+ const literal: Record<string, string> = {};
150
+ const fromEnv: Record<string, string> = {};
151
+ let bearer: string | undefined;
152
+ for (const [header, value] of Object.entries(server.headers ?? {})) {
153
+ const token = /^Bearer\s+(\$\{[A-Za-z_][A-Za-z0-9_]*\})$/.exec(value);
154
+ const bearerVar = header.toLowerCase() === 'authorization' && token ? wholeReference(token[1]) : null;
155
+ const whole = wholeReference(value);
156
+ if (bearerVar) bearer = bearerVar;
157
+ else if (whole) fromEnv[header] = whole;
158
+ else literal[header] = value;
159
+ }
160
+ mcp_servers[name] = {
161
+ url,
162
+ ...(bearer && { bearer_token_env_var: bearer }),
163
+ ...(Object.keys(literal).length > 0 && { http_headers: literal }),
164
+ ...(Object.keys(fromEnv).length > 0 && { env_http_headers: fromEnv }),
165
+ };
166
+ }
167
+ }
168
+ return { mcp_servers };
169
+ }
170
+
118
171
  case 'opencode': {
119
172
  // OpenCode format — type: "local"/"remote", command as array
120
173
  const mcp: Record<string, unknown> = {};
@@ -149,41 +202,6 @@ function transformMcpForIde(
149
202
  }
150
203
  }
151
204
 
152
- /**
153
- * The indentation a file already uses, so merging into it does not restyle it.
154
- *
155
- * `JSON.stringify(x, null, 2)` re-indented every co-owned config we touched. A
156
- * hand-written tab-indented `opencode.json` — OpenCode's entire project config —
157
- * came back two-space indented from a merge that added one key, and never came back
158
- * from the uninstall at all: 111 bytes in, 114 out, for a strip that took nothing
159
- * of theirs. Byte fidelity is a claim this tool makes about co-owned files, and a
160
- * JSON config is one of those.
161
- *
162
- * Read from the first indented line, which is what every formatter agrees on.
163
- * Falls back to two spaces for a file we are creating or one written on a single
164
- * line, which is what this always did.
165
- */
166
- function indentOf(text: string): string | number {
167
- const m = /\n([ \t]+)\S/.exec(text);
168
- if (m) return m[1].includes('\t') ? '\t' : m[1].length;
169
- // A config written on one line has no indentation, and expanding it to three is
170
- // as much a restyle as collapsing it would be. `0` is what `JSON.stringify` takes
171
- // for "no whitespace".
172
- return text.trim().includes('\n') ? 2 : 0;
173
- }
174
-
175
- /**
176
- * Re-serialise a config the way the file was already written.
177
- *
178
- * Indentation and line endings both, because `JSON.stringify` emits `\n` whatever
179
- * it was handed and a CRLF config came back LF from a merge that added one key.
180
- * The same rule `.gitignore` follows: a CRLF file stays CRLF.
181
- */
182
- function serialiseLike(original: string, value: unknown): string {
183
- const text = JSON.stringify(value, null, indentOf(original)) + '\n';
184
- return /\r\n/.test(original) ? text.replace(/\n/g, '\r\n') : text;
185
- }
186
-
187
205
  /**
188
206
  * One plugin's server as the VS Code–format config, with the env vars other
189
207
  * targets need spelled out — they have no `envFile`.
@@ -206,7 +224,8 @@ function serverFor(
206
224
  return serverConfig;
207
225
  }
208
226
 
209
- function containerKeyFor(ide: IdeChoice): string {
227
+ export function containerKeyFor(ide: IdeChoice): string {
228
+ if (ide === 'codex') return 'mcp_servers';
210
229
  return ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers';
211
230
  }
212
231
 
@@ -418,6 +437,20 @@ export function upgradeGeneratedServers(
418
437
  return upgraded;
419
438
  }
420
439
 
440
+ /**
441
+ * The text to write, or the same refusal an unparseable config gets when a
442
+ * TOML config is laid out in a way that cannot be changed line by line —
443
+ * named and left alone, never rewritten wholesale.
444
+ */
445
+ function serialiseOrRefuse(before: string | null, value: Record<string, unknown>, rel: string): string {
446
+ try {
447
+ return serialiseMcpConfig(before, value, rel);
448
+ } catch (err) {
449
+ if (err instanceof TomlEditError) throw new UnreadableConfigError(rel, 'uneditable');
450
+ throw err;
451
+ }
452
+ }
453
+
421
454
  /**
422
455
  * Scaffold or merge the MCP server config into the target project.
423
456
  *
@@ -487,17 +520,12 @@ export async function scaffoldMcpConfig(
487
520
  }
488
521
  let existing: Record<string, unknown>;
489
522
  try {
490
- existing = JSON.parse(existingContent) as Record<string, unknown>;
523
+ existing = parseMcpConfigText(existingContent, destRelPath);
491
524
  } catch {
492
525
  throw new UnreadableConfigError(destRelPath);
493
526
  }
494
527
 
495
- // Determine the server container key for this IDE
496
- const containerKey = resolvedIde === 'opencode'
497
- ? 'mcp'
498
- : resolvedIde === 'vscode'
499
- ? 'servers'
500
- : 'mcpServers';
528
+ const containerKey = containerKeyFor(resolvedIde);
501
529
 
502
530
  if (!existing[containerKey]) {
503
531
  existing[containerKey] = {};
@@ -539,13 +567,13 @@ export async function scaffoldMcpConfig(
539
567
  return { path: destPath, action: 'skipped', team: teamChanges };
540
568
  }
541
569
 
542
- await writeFile(destPath, serialiseLike(existingContent, existing));
570
+ await writeFile(destPath, serialiseOrRefuse(existingContent, existing, destRelPath));
543
571
  return { path: destPath, action: 'created', team: teamChanges };
544
572
  }
545
573
 
546
574
  const teamChanges = applyTeamPlan(output, resolvedIde, team);
547
575
  await mkdir(dirname(destPath), { recursive: true });
548
- await writeFile(destPath, JSON.stringify(output, null, 2) + '\n');
576
+ await writeFile(destPath, serialiseOrRefuse(null, output, destRelPath));
549
577
 
550
578
  return { path: destPath, action: 'created', team: teamChanges };
551
579
  }
@@ -568,7 +596,7 @@ export function getMcpConfigRelPath(ide: IdeChoice): string {
568
596
  case 'windsurf':
569
597
  return '.windsurf/mcp.json';
570
598
  case 'codex':
571
- return '.codex/mcp.json';
599
+ return '.codex/config.toml';
572
600
  case 'antigravity':
573
601
  return '.agents/mcp_config.json';
574
602
  }
@@ -611,9 +639,7 @@ export async function scaffoldMcpConfigInto(
611
639
  if (result.team?.removed.length) (results.mcpTeamRemoved ??= []).push(...result.team.removed);
612
640
  } catch (err) {
613
641
  if (!(err instanceof UnreadableConfigError)) throw err;
614
- (results.unreadable ??= []).push(
615
- err.reason === 'unreadable' ? `${err.file}\u0000unreadable` : err.file,
616
- );
642
+ (results.unreadable ??= []).push(err.reason === 'unparseable' ? err.file : `${err.file}\u0000${err.reason}`);
617
643
  }
618
644
  }
619
645
 
@@ -641,8 +667,8 @@ export function willKeepSomethingAfterStrip(
641
667
  teamInputs: string[] = [],
642
668
  ): boolean {
643
669
  const containerKeys = ide
644
- ? [ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers']
645
- : ['mcp', 'servers', 'mcpServers']
670
+ ? [containerKeyFor(ide)]
671
+ : ['mcp', 'servers', 'mcpServers', 'mcp_servers']
646
672
 
647
673
  const ourServerKeys = new Set([
648
674
  ...Object.values(PLUGINS)
@@ -680,7 +706,47 @@ export async function stripManagedMcpServers(
680
706
  teamKeys: string[] = [],
681
707
  teamInputs: string[] = [],
682
708
  ): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
683
- const destPath = resolve(projectRoot, getMcpConfigRelPath(ide));
709
+ return stripConfigAt(projectRoot, getMcpConfigRelPath(ide), ide, createdByUs, teamKeys, teamInputs);
710
+ }
711
+
712
+ /**
713
+ * MCP configs a release before this one wrote where the assistant never looks.
714
+ *
715
+ * Codex CLI reads project servers only from `.codex/config.toml`; the
716
+ * `.codex/mcp.json` OpenCastle wrote for it was never loaded, so every server
717
+ * in it was one Codex did not have.
718
+ */
719
+ export const LEGACY_MCP_CONFIGS: Partial<Record<IdeChoice, string>> = {
720
+ codex: '.codex/mcp.json',
721
+ };
722
+
723
+ /**
724
+ * Take our servers back out of a target's legacy MCP config, and delete it if
725
+ * we created it and nothing of the user's is left. Anything they added stays —
726
+ * it never reached the assistant either, and `sync` says where it belongs.
727
+ */
728
+ export async function retireLegacyMcpConfig(
729
+ projectRoot: string,
730
+ ide: IdeChoice,
731
+ createdByUs = false,
732
+ teamKeys: string[] = [],
733
+ teamInputs: string[] = [],
734
+ ): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
735
+ const rel = LEGACY_MCP_CONFIGS[ide];
736
+ if (!rel) return 'absent';
737
+ // No `ide`: the legacy file is in the shape it was written in, not today's.
738
+ return stripConfigAt(projectRoot, rel, undefined, createdByUs, teamKeys, teamInputs);
739
+ }
740
+
741
+ async function stripConfigAt(
742
+ projectRoot: string,
743
+ rel: string,
744
+ ide: IdeChoice | undefined,
745
+ createdByUs: boolean,
746
+ teamKeys: string[],
747
+ teamInputs: string[],
748
+ ): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
749
+ const destPath = resolve(projectRoot, rel);
684
750
  if (!existsSync(destPath)) return 'absent';
685
751
 
686
752
  let before: string;
@@ -691,7 +757,7 @@ export async function stripManagedMcpServers(
691
757
  }
692
758
  let parsed: Record<string, unknown>;
693
759
  try {
694
- parsed = JSON.parse(before) as Record<string, unknown>;
760
+ parsed = parseMcpConfigText(before, rel);
695
761
  } catch {
696
762
  // Not ours to repair. Leaving it alone beats deleting something unreadable,
697
763
  // but 'stripped' would have removal report "kept your content in N file(s)"
@@ -734,7 +800,12 @@ export async function stripManagedMcpServers(
734
800
 
735
801
  // The file's own indentation, not ours. Taking our servers out of a
736
802
  // tab-indented config used to restyle every line of it.
737
- await writeFile(destPath, serialiseLike(before, parsed));
803
+ try {
804
+ await writeFile(destPath, serialiseMcpConfig(before, parsed, rel));
805
+ } catch (err) {
806
+ if (err instanceof TomlEditError) return 'unreadable';
807
+ throw err;
808
+ }
738
809
  return 'stripped';
739
810
  }
740
811
 
@@ -778,12 +849,11 @@ export async function rebuildMcpConfig(
778
849
  }
779
850
  let existing: Record<string, unknown>;
780
851
  try {
781
- existing = JSON.parse(before) as Record<string, unknown>;
852
+ existing = parseMcpConfigText(before, destRelPath);
782
853
  } catch {
783
854
  throw new UnreadableConfigError(destRelPath);
784
855
  }
785
- const containerKey =
786
- ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers';
856
+ const containerKey = containerKeyFor(ide);
787
857
 
788
858
  const existingServers = (existing[containerKey] ?? {}) as Record<string, unknown>;
789
859
 
@@ -868,11 +938,11 @@ export async function rebuildMcpConfig(
868
938
  // policies, and the user's formatting lost to the stricter of them.
869
939
  let unchanged = false;
870
940
  try {
871
- unchanged = JSON.stringify(JSON.parse(before)) === JSON.stringify(existing);
941
+ unchanged = JSON.stringify(parseMcpConfigText(before, destRelPath)) === JSON.stringify(existing);
872
942
  } catch {
873
943
  unchanged = false;
874
944
  }
875
- if (!unchanged) await writeFile(destPath, serialiseLike(before, existing));
945
+ if (!unchanged) await writeFile(destPath, serialiseOrRefuse(before, existing, destRelPath));
876
946
 
877
947
  // Re-scaffold: merges new plugin servers into the cleaned config, and writes
878
948
  // the team's servers exactly as its layers define them.
@@ -0,0 +1,70 @@
1
+ import type { PluginConfig } from '../orchestrator/plugins/types.js'
2
+ import { EXTENSION_NAMESPACE, mcpSchemaUrl, pluginSchemaUrl } from './agent-plugin.js'
3
+
4
+ /**
5
+ * Each integration as an Agent Plugin: `plugin.json` and `mcp.json` beside its
6
+ * `skills/<name>/SKILL.md`, compiled from the integration's `config.ts`.
7
+ *
8
+ * `config.ts` stays the source: it carries what only OpenCastle reads —
9
+ * detection, the agents whose tools a server extends, earlier defaults to
10
+ * migrate from. That goes under `extensions["dev.opencastle"]`, the namespace
11
+ * the standard gives a client for its own data, and the portable part is what
12
+ * any client loads. `npm run plugins:build` writes the files and a test holds
13
+ * them to `config.ts`, as the website's snippets are held to it.
14
+ */
15
+
16
+ const REPOSITORY = 'https://github.com/monkilabs/opencastle'
17
+
18
+ /** An integration's `mcp.json` value, or null when its server cannot be written portably. */
19
+ export function packMcp(p: PluginConfig): Record<string, unknown> | null {
20
+ const cfg = p.mcpConfig
21
+ if (!cfg || !p.mcpServerKey) return null
22
+ let server: Record<string, unknown>
23
+ if (cfg.type === 'http') {
24
+ // A URL with a value only the user can supply — a tenant id — is not a
25
+ // portable server; the extension data says what it needs.
26
+ if (!cfg.url || cfg.url.includes('${')) return null
27
+ server = { type: 'streamable-http', url: cfg.url }
28
+ } else {
29
+ if (!cfg.command || [cfg.command, ...(cfg.args ?? [])].some((a) => a.includes('${'))) return null
30
+ // No `env`: the standard has no way to name a secret yet, so a server that
31
+ // needs a token reads it from the environment the assistant runs in, and
32
+ // the extension data lists which.
33
+ server = { type: 'stdio', command: cfg.command, ...(cfg.args && cfg.args.length > 0 && { args: cfg.args }) }
34
+ }
35
+ return { $schema: mcpSchemaUrl(), mcpServers: { [p.mcpServerKey]: server } }
36
+ }
37
+
38
+ /** An integration's `plugin.json` value. */
39
+ export function packManifest(p: PluginConfig): Record<string, unknown> {
40
+ const mcp = packMcp(p)
41
+ const what = p.mcpServerKey ? (mcp ? 'skill and MCP server' : 'skill (its MCP server needs per-user setup)') : 'skill'
42
+ return {
43
+ $schema: pluginSchemaUrl(),
44
+ name: p.id,
45
+ description: `${p.name} ${what} for AI coding assistants: ${p.hint.replace(/\.$/, '')}.`,
46
+ homepage: p.docsUrl ?? 'https://www.opencastle.dev/docs/plugins',
47
+ repository: REPOSITORY,
48
+ license: 'MIT',
49
+ keywords: [p.category, p.subCategory],
50
+ extensions: {
51
+ [EXTENSION_NAMESPACE]: {
52
+ label: p.label,
53
+ category: p.category,
54
+ subCategory: p.subCategory,
55
+ authType: p.authType,
56
+ ...(p.envVars.length > 0 && { env: p.envVars.map((e) => e.name) }),
57
+ ...(p.mcpInputs && p.mcpInputs.length > 0 && { inputs: p.mcpInputs.map((i) => i.id) }),
58
+ ...(p.officialDocs && { officialDocs: p.officialDocs }),
59
+ },
60
+ },
61
+ }
62
+ }
63
+
64
+ /** Every file an integration's directory holds besides `config.ts` and its skill, as path → text. */
65
+ export function packFiles(p: PluginConfig): Record<string, string> {
66
+ const files: Record<string, string> = { 'plugin.json': JSON.stringify(packManifest(p), null, 2) + '\n' }
67
+ const mcp = packMcp(p)
68
+ if (mcp) files['mcp.json'] = JSON.stringify(mcp, null, 2) + '\n'
69
+ return files
70
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * `opencastle plugin` and an Agent Plugin baseline, through the built CLI.
3
+ */
4
+ import { execFileSync, spawnSync } from 'node:child_process'
5
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
6
+ import { tmpdir } from 'node:os'
7
+ import { dirname, join, resolve } from 'node:path'
8
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
9
+ import { mcpSchemaUrl, pluginSchemaUrl } from './agent-plugin.js'
10
+
11
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
12
+ const cli = join(pkgRoot, 'bin', 'cli.mjs')
13
+ const built = existsSync(join(pkgRoot, 'dist', 'cli', 'plugin.js'))
14
+
15
+ function write(root: string, files: Record<string, string>): void {
16
+ for (const [rel, text] of Object.entries(files)) {
17
+ mkdirSync(dirname(join(root, rel)), { recursive: true })
18
+ writeFileSync(join(root, rel), text)
19
+ }
20
+ }
21
+
22
+ const readJson = (path: string): Record<string, unknown> => JSON.parse(readFileSync(path, 'utf8'))
23
+
24
+ describe.skipIf(!built)('opencastle plugin', () => {
25
+ let dir: string
26
+ const run = (cwd: string, ...args: string[]) => spawnSync('node', [cli, ...args], { cwd, encoding: 'utf8' })
27
+ beforeEach(() => {
28
+ dir = mkdtempSync(join(tmpdir(), 'oc-plugin-cmd-'))
29
+ })
30
+ afterEach(() => rmSync(dir, { recursive: true, force: true }))
31
+
32
+ it('a scaffolded baseline is a plugin every assistant loads, Claude Code included', () => {
33
+ expect(run(dir, 'baseline', 'init', 'base', '--name', '@acme/base').status).toBe(0)
34
+ const out = run(dir, 'plugin', 'check', 'base')
35
+ expect(out.status).toBe(0)
36
+ expect(out.stdout).toContain('Loads in GitHub Copilot, VS Code, Cursor, Codex and Kiro as it is, and in Claude Code.')
37
+ expect(readJson(join(dir, 'base', 'plugin.json'))).toMatchObject({ $schema: pluginSchemaUrl(), name: 'acme.base' })
38
+ expect(run(dir, 'baseline', 'check', 'base').status).toBe(0)
39
+ })
40
+
41
+ it('build keeps Claude Code’s files in step with the portable ones, and keeps what only Claude Code reads', () => {
42
+ run(dir, 'baseline', 'init', 'base', '--name', '@acme/base')
43
+ const base = join(dir, 'base')
44
+ write(base, {
45
+ 'mcp.json': JSON.stringify({ $schema: mcpSchemaUrl(), mcpServers: { docs: { type: 'streamable-http', url: 'https://docs.acme.example/mcp' } } }),
46
+ // The scaffold's example policy allows four servers; a team adding one allows it.
47
+ 'dev.opencastle/config.json': JSON.stringify({ policy: { mcp: { allow: ['docs'], remoteHosts: ['docs.acme.example'] } } }),
48
+ })
49
+ const claude = join(base, '.claude-plugin', 'plugin.json')
50
+ writeFileSync(claude, JSON.stringify({ ...readJson(claude), userConfig: { region: { type: 'string', title: 'Region', description: 'Where' } } }))
51
+
52
+ const stale = run(dir, 'plugin', 'check', 'base')
53
+ expect(stale.status).toBe(1)
54
+ expect(stale.stdout).toContain('.mcp.json does not match plugin.json and mcp.json')
55
+ expect(run(dir, 'plugin', 'build', 'base', '--check').status).toBe(1)
56
+
57
+ expect(run(dir, 'plugin', 'build', 'base').status).toBe(0)
58
+ expect(readJson(join(base, '.mcp.json'))).toEqual({ mcpServers: { docs: { type: 'http', url: 'https://docs.acme.example/mcp' } } })
59
+ expect(readJson(claude)).toMatchObject({ name: 'acme.base', version: '0.1.0', userConfig: { region: { title: 'Region' } } })
60
+ expect(run(dir, 'plugin', 'check', 'base').status).toBe(0)
61
+ expect(run(dir, 'baseline', 'check', 'base').status).toBe(0)
62
+ })
63
+
64
+ it('index lists every plugin for Claude Code and Copilot, Cursor and Codex', () => {
65
+ const plugin = (name: string): Record<string, string> => ({
66
+ [`plugins/${name}/plugin.json`]: JSON.stringify({ $schema: pluginSchemaUrl(), name, description: `The ${name} plugin` }),
67
+ })
68
+ write(dir, { 'package.json': JSON.stringify({ name: '@acme/agent-plugins', author: 'Acme Platform <p@acme.example>' }), ...plugin('deploy'), ...plugin('review') })
69
+ const out = run(dir, 'plugin', 'index')
70
+ expect(out.status).toBe(0)
71
+ const shared = {
72
+ name: 'acme.agent-plugins',
73
+ owner: { name: 'Acme Platform' },
74
+ metadata: { description: 'Agent Plugins from acme.agent-plugins' },
75
+ plugins: [
76
+ { name: 'deploy', source: './plugins/deploy', description: 'The deploy plugin' },
77
+ { name: 'review', source: './plugins/review', description: 'The review plugin' },
78
+ ],
79
+ }
80
+ expect(readJson(join(dir, '.claude-plugin', 'marketplace.json'))).toEqual(shared)
81
+ expect(readJson(join(dir, '.cursor-plugin', 'marketplace.json'))).toEqual(shared)
82
+ expect(readJson(join(dir, '.agents', 'plugins', 'marketplace.json'))).toMatchObject({
83
+ name: 'acme.agent-plugins',
84
+ plugins: [{ name: 'deploy', source: { source: 'local', path: './plugins/deploy' }, policy: { installation: 'AVAILABLE' } }, { name: 'review' }],
85
+ })
86
+ expect(out.stdout).toContain('Claude Code needs .claude-plugin/plugin.json')
87
+ expect(run(dir, 'plugin', 'index', '--check').status).toBe(0)
88
+
89
+ write(dir, plugin('release'))
90
+ const behind = run(dir, 'plugin', 'index', '--check')
91
+ expect(behind.status).toBe(1)
92
+ expect(behind.stderr).toContain('.claude-plugin/marketplace.json does not list the plugins under plugins/')
93
+ })
94
+
95
+ it('index refuses two plugins with one name', () => {
96
+ write(dir, {
97
+ 'plugins/a/plugin.json': JSON.stringify({ $schema: pluginSchemaUrl(), name: 'same' }),
98
+ 'plugins/b/plugin.json': JSON.stringify({ $schema: pluginSchemaUrl(), name: 'same' }),
99
+ })
100
+ const out = run(dir, 'plugin', 'index')
101
+ expect(out.status).toBe(1)
102
+ expect(out.stderr).toContain('are both named "same"')
103
+ })
104
+
105
+ it('a project extending the plugin gets its skill and server in every assistant', () => {
106
+ run(dir, 'baseline', 'init', 'base', '--name', '@acme/base')
107
+ write(join(dir, 'base'), {
108
+ 'mcp.json': JSON.stringify({ $schema: mcpSchemaUrl(), mcpServers: { docs: { type: 'streamable-http', url: 'https://docs.acme.example/mcp' } } }),
109
+ // The scaffold's example policy allows four servers; a team adding one allows it.
110
+ 'dev.opencastle/config.json': JSON.stringify({ policy: { mcp: { allow: ['docs'], remoteHosts: ['docs.acme.example'] } } }),
111
+ })
112
+ const project = join(dir, 'app')
113
+ write(project, {
114
+ 'CLAUDE.md': '# App\n',
115
+ '.opencastle/config.json': JSON.stringify({ extends: ['../../base'] }),
116
+ })
117
+ execFileSync('git', ['init', '-q'], { cwd: project })
118
+ const init = run(project, 'init', '--yes')
119
+ expect(init.status, init.stdout + init.stderr).toBe(0)
120
+ expect(existsSync(join(project, '.claude', 'skills', 'code-review', 'SKILL.md'))).toBe(true)
121
+ expect(readFileSync(join(project, 'CLAUDE.md'), 'utf8')).toContain('Engineering standards')
122
+ expect(readJson(join(project, '.mcp.json'))).toMatchObject({ mcpServers: { docs: { type: 'http', url: 'https://docs.acme.example/mcp' } } })
123
+ expect(run(project, 'sync', '--check').status).toBe(0)
124
+ })
125
+ })