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
@@ -1,30 +1,48 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
1
3
  import { createSingleFileAdapter } from './single-file-base.js'
2
4
 
3
5
  /**
4
6
  * Codex CLI adapter.
5
7
  *
6
- * Generates AGENTS.md (root instructions) and .codex/ structure.
8
+ * Generates AGENTS.md (root instructions), the cross-assistant skills
9
+ * directory, and .codex/ structure.
7
10
  *
8
11
  * copilot-instructions.md -> AGENTS.md (combined with instructions/)
9
- * skills/<name>/SKILL.md -> .codex/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved)
12
+ * skills/<name>/SKILL.md -> .agents/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved)
10
13
  * agents/*.agent.md -> .codex/agents/<name>.md
11
14
  * agent-workflows/*.md -> .codex/workflows/<name>.md
12
15
  * prompts/*.prompt.md -> .codex/prompts/<name>.md
13
- * customizations/ -> .codex/customizations/ (scaffolded once)
14
- * mcp.json -> .codex/mcp.json (mcpServers format)
16
+ * MCP servers -> .codex/config.toml ([mcp_servers.<name>] tables)
17
+ *
18
+ * Codex reads a repository's skills only from `.agents/skills/` and its
19
+ * project MCP servers only from `.codex/config.toml`, in a project the user has
20
+ * trusted. Releases before this one wrote `.codex/skills/` and `.codex/mcp.json`,
21
+ * neither of which Codex reads; `sync` removes the first and takes our servers
22
+ * back out of the second.
23
+ *
24
+ * `.agents/skills/` is also where the Antigravity adapter writes skills. Both
25
+ * compile the same skills from the same source, so with both selected each
26
+ * one's output is the other's, and neither sweep removes anything of the other.
15
27
  */
16
28
 
17
29
  export const IDE_ID = 'codex'
18
30
 
19
- const { install, update, getManagedPaths, getDoctorChecks } = createSingleFileAdapter({
31
+ /** What releases before `.agents/skills/` wrote, relative to the project root. */
32
+ export const LEGACY_CODEX_SKILLS = '.codex/skills/'
33
+ export const LEGACY_CODEX_MCP = '.codex/mcp.json'
34
+
35
+ const { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs } = createSingleFileAdapter({
20
36
  rootFile: 'AGENTS.md',
21
37
  dotDir: '.codex',
22
- mcpConfigPath: '.codex/mcp.json',
38
+ skillsDir: '.agents/skills',
39
+ mcpConfigPath: '.codex/config.toml',
23
40
  mcpFormat: 'codex',
24
41
  promptsDir: 'prompts',
25
42
  workflowsDir: 'workflows',
26
43
  workflowPrefix: '',
27
44
  frameworkDirs: ['agents', 'skills', 'prompts', 'workflows'],
45
+ legacyOutputs: (projectRoot) => (existsSync(resolve(projectRoot, LEGACY_CODEX_SKILLS)) ? [LEGACY_CODEX_SKILLS] : []),
28
46
  })
29
47
 
30
- export { install, update, getManagedPaths, getDoctorChecks }
48
+ export { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs }
@@ -1,6 +1,6 @@
1
- import { resolve, basename, relative, sep } from 'node:path'
1
+ import { resolve, basename, dirname, relative, sep } from 'node:path'
2
2
  import { mkdir, writeFile, readdir, readFile, rm, rename } from 'node:fs/promises'
3
- import { existsSync, readdirSync, realpathSync } from 'node:fs'
3
+ import { existsSync, readdirSync, realpathSync, rmdirSync } from 'node:fs'
4
4
  import { writeManagedBlock, recordMerge } from '../managed-block.js'
5
5
  import { TIERS, TIER_IDS, isTier, tierForAgent, type Tier } from '../tiers.js'
6
6
  import { mergeCopyResults, copyDir } from '../copy.js'
@@ -31,6 +31,13 @@ export interface SingleFileAdapterConfig {
31
31
  workflowPrefix: string
32
32
  /** Framework subdirectories (under dotDir) to remove during update */
33
33
  frameworkDirs: string[]
34
+ /**
35
+ * Where skills go, relative to the project root, when the assistant does not
36
+ * read them from `<dotDir>/skills/`. Codex CLI reads a repository's skills
37
+ * only from `.agents/skills/`, the cross-assistant location; the
38
+ * `.codex/skills/` this wrote was never loaded.
39
+ */
40
+ skillsDir?: string
34
41
  /**
35
42
  * Output an earlier release wrote outside today's framework directories,
36
43
  * present on disk now, relative to the project root. Removed on update.
@@ -63,23 +70,34 @@ export interface SingleFileAdapterConfig {
63
70
  * first selected owner's directory. Both trees are still installed; the index
64
71
  * names one of them, and says so.
65
72
  */
66
- const SHARED_ROOT_OWNERS: Record<string, Array<{ ide: string; dotDir: string }>> = {
73
+ const SHARED_ROOT_OWNERS: Record<string, Array<{ ide: string; dotDir: string; skillsDir: string }>> = {
67
74
  'AGENTS.md': [
68
- { ide: 'opencode', dotDir: '.opencode' },
69
- { ide: 'codex', dotDir: '.codex' },
75
+ { ide: 'opencode', dotDir: '.opencode', skillsDir: '.opencode/skills' },
76
+ { ide: 'codex', dotDir: '.codex', skillsDir: '.agents/skills' },
70
77
  ],
71
78
  }
72
79
 
73
- /** The directory the shared root file should point at, given what is selected. */
80
+ /** Where an adapter writes skills, relative to the project root. */
81
+ function skillsDirOf(config: SingleFileAdapterConfig): string {
82
+ return config.skillsDir ?? `${config.dotDir}/skills`
83
+ }
84
+
85
+ /**
86
+ * The directories the shared root file should point at, given what is
87
+ * selected, and the other places the same content is installed.
88
+ */
74
89
  function referenceDir(config: SingleFileAdapterConfig, stack?: StackConfig): {
75
90
  dir: string
91
+ skills: string
76
92
  sharedWith: string[]
77
93
  } {
78
94
  const owners = SHARED_ROOT_OWNERS[config.rootFile] ?? []
79
95
  const selected = new Set<string>(stack?.ides ?? [])
80
96
  const present = owners.filter((o) => selected.has(o.ide))
81
- if (present.length < 2) return { dir: config.dotDir, sharedWith: [] }
82
- return { dir: present[0].dotDir, sharedWith: present.map((o) => o.dotDir) }
97
+ if (present.length < 2) return { dir: config.dotDir, skills: skillsDirOf(config), sharedWith: [] }
98
+ const [first, ...rest] = present
99
+ const elsewhere = rest.flatMap((o) => (o.skillsDir.startsWith(`${o.dotDir}/`) ? [o.dotDir] : [o.dotDir, o.skillsDir]))
100
+ return { dir: first.dotDir, skills: first.skillsDir, sharedWith: elsewhere }
83
101
  }
84
102
 
85
103
  /**
@@ -201,18 +219,17 @@ export function createSingleFileAdapter(
201
219
  // Always built: the content goes into a managed block, so a file the user
202
220
  // already owns keeps its content and gains the generated section.
203
221
  const rootPath = resolve(projectRoot, config.rootFile)
204
- const { dir: refDir, sharedWith } = referenceDir(config, stack)
222
+ const { dir: refDir, skills: refSkills, sharedWith } = referenceDir(config, stack)
205
223
  {
206
224
  const sections: string[] = []
207
225
 
208
226
  sections.push(
209
227
  '# Project Instructions\n\n' +
210
228
  'All conventions, architecture, and project context are embedded below. ' +
211
- `Skills are in \`${refDir}/skills/\` — read them when a task matches. ` +
229
+ `Skills are in \`${refSkills}/\` — read them when a task matches. ` +
212
230
  `Agent definitions are in \`${refDir}/agents/\` — read the relevant file when adopting a persona.` +
213
- (sharedWith.length > 1
231
+ (sharedWith.length > 0
214
232
  ? `\n\nThis file is shared by more than one assistant. The same content is also installed under ${sharedWith
215
- .filter((d) => d !== refDir)
216
233
  .map((d) => `\`${d}/\``)
217
234
  .join(', ')}.`
218
235
  : '')
@@ -277,7 +294,7 @@ export function createSingleFileAdapter(
277
294
  await readdir(skillsDir, { withFileTypes: true })
278
295
  ).filter((e) => e.isDirectory())
279
296
  const skillRef = (name: string): string =>
280
- `${refDir}/skills/${name}/SKILL.md`
297
+ `${refSkills}/${name}/SKILL.md`
281
298
  // Integration skills are listed after the rest, as they always were:
282
299
  // reordering the index would change every root file on upgrade for
283
300
  // no reason anyone could see in the diff.
@@ -324,12 +341,12 @@ export function createSingleFileAdapter(
324
341
  }
325
342
  }
326
343
 
327
- // 3. Skills → dotDir/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved).
344
+ // 3. Skills → <skillsDir>/<name>/SKILL.md (+ sibling resources, frontmatter preserved).
328
345
  // Matches the SKILL.md-per-folder format used by Claude Code, OpenCode, Codex,
329
346
  // and Antigravity — agents discover skills via the description: frontmatter field.
330
347
  const skillsDir = resolve(srcRoot, 'skills')
331
348
  if (existsSync(skillsDir)) {
332
- const destSkills = resolve(dotDirPath, 'skills')
349
+ const destSkills = resolve(projectRoot, skillsDirOf(config))
333
350
  await mkdir(destSkills, { recursive: true })
334
351
  const subdirs = (
335
352
  await readdir(skillsDir, { withFileTypes: true })
@@ -416,23 +433,19 @@ export function createSingleFileAdapter(
416
433
  source?: CompileSource,
417
434
  ): Promise<CopyResults> {
418
435
  const results: CopyResults = { copied: [], skipped: [], created: [] }
419
- const dotDirPath = resolve(projectRoot, config.dotDir)
420
436
 
421
437
  // 1. Leave the root file in place. install() rewrites only the managed
422
438
  // block inside it, so deleting it here would destroy whatever the user
423
439
  // wrote around that block.
424
440
 
425
441
  // 2. Note what is there now, so step 4 can say what it removed.
426
- const sweptDirs = config.frameworkDirs
427
- .map((dir) => resolve(dotDirPath, dir))
442
+ const sweptDirs = frameworkRoots()
443
+ .map((dir) => resolve(projectRoot, dir))
428
444
  .filter((dirPath) => existsSync(dirPath))
429
445
  const before = new Map<string, string>()
430
446
  for (const dirPath of sweptDirs) {
431
447
  for (const rel of filesUnderDir(dirPath)) {
432
- before.set(
433
- resolve(dirPath, rel),
434
- `${config.dotDir}/${relative(dotDirPath, dirPath).split(sep).join('/')}/${rel}`,
435
- )
448
+ before.set(resolve(dirPath, rel), `${relative(projectRoot, dirPath).split(sep).join('/')}/${rel}`)
436
449
  }
437
450
  }
438
451
 
@@ -459,18 +472,25 @@ export function createSingleFileAdapter(
459
472
  // deletion was silent and the categories looked right.
460
473
  const written = new Set<string>(installResult.visited ?? [])
461
474
  for (const dirPath of sweptDirs) {
475
+ const emptied = new Set<string>()
462
476
  for (const rel of filesUnderDir(dirPath)) {
463
477
  const abs = resolve(dirPath, rel)
464
478
  if (await reconcileCase(abs, written)) continue
465
479
  ;(results.deleted ??= []).push(before.get(abs) ?? rel)
466
480
  await rm(abs, { force: true })
481
+ emptied.add(dirname(abs))
467
482
  }
483
+ // A skill whose last file went leaves its folder, and an assistant that
484
+ // scans the directory sees a skill with no SKILL.md. Only folders this
485
+ // sweep emptied: an empty directory standing where a generated file
486
+ // belongs is a fault for a person, and every check names it as one.
487
+ pruneEmptied(dirPath, emptied)
468
488
  }
469
489
  // What an earlier release put where this one no longer writes — the
470
490
  // un-namespaced commands at the top of `.claude/commands/`. Asked after the
471
491
  // recompile, so a failure there leaves the old commands working.
472
492
  for (const rel of getLegacyOutputs(projectRoot)) {
473
- await rm(resolve(projectRoot, rel), { force: true })
493
+ await rm(resolve(projectRoot, rel), { force: true, recursive: rel.endsWith('/') })
474
494
  ;(results.deleted ??= []).push(rel)
475
495
  }
476
496
  // Pass the three categories through as they came back. Folding `created`
@@ -505,11 +525,20 @@ export function createSingleFileAdapter(
505
525
  return config.legacyOutputs?.(projectRoot) ?? []
506
526
  }
507
527
 
508
- function getManagedPaths(): ManagedPaths {
528
+ /**
529
+ * Every directory this adapter generates whole, relative to the project
530
+ * root and without a trailing slash: its framework directories under
531
+ * `dotDir`, with skills wherever `skillsDir` puts them.
532
+ */
533
+ function frameworkRoots(): string[] {
509
534
  // Deduplicate dirs (e.g. promptsDir === workflowsDir for claude-code's 'commands')
510
535
  const dirs = new Set(['agents', 'skills', ...config.frameworkDirs])
536
+ return Array.from(dirs).map((d) => (d === 'skills' ? skillsDirOf(config) : `${config.dotDir}/${d}`))
537
+ }
538
+
539
+ function getManagedPaths(): ManagedPaths {
511
540
  return {
512
- framework: Array.from(dirs).map((d) => `${config.dotDir}/${d}/`),
541
+ framework: frameworkRoots().map((d) => `${d}/`),
513
542
  merged: [config.rootFile],
514
543
  customizable: ['.opencastle/', config.mcpConfigPath],
515
544
  }
@@ -519,7 +548,7 @@ export function createSingleFileAdapter(
519
548
  const checks: DoctorCheck[] = [
520
549
  { label: 'Root instructions file', path: config.rootFile, type: 'file' },
521
550
  { label: 'Agent definitions', path: `${config.dotDir}/agents/`, type: 'dir', countContents: true, countFilter: '.md' },
522
- { label: 'Skills directory', path: `${config.dotDir}/skills/`, type: 'dir', countContents: true },
551
+ { label: 'Skills directory', path: `${skillsDirOf(config)}/`, type: 'dir', countContents: true },
523
552
  ]
524
553
  if (config.promptsDir === config.workflowsDir) {
525
554
  checks.push({ label: 'Commands directory', path: `${config.dotDir}/${config.promptsDir}/`, type: 'dir', countContents: true })
@@ -533,6 +562,20 @@ export function createSingleFileAdapter(
533
562
  return { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs }
534
563
  }
535
564
 
565
+ /** Remove each of `dirs` that is now empty, and its parents up to `root`, which stays. */
566
+ function pruneEmptied(root: string, dirs: Set<string>): void {
567
+ for (const start of [...dirs].sort((a, b) => b.length - a.length)) {
568
+ for (let dir = start; dir !== root && dir.startsWith(root); dir = dirname(dir)) {
569
+ try {
570
+ if (readdirSync(dir).length > 0) break
571
+ rmdirSync(dir)
572
+ } catch {
573
+ break
574
+ }
575
+ }
576
+ }
577
+ }
578
+
536
579
  /** Every file under a directory, relative to it. */
537
580
  function filesUnderDir(root: string): string[] {
538
581
  const out: string[] = []
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Agent Plugins 1.0, as a conformant client reads one — and as a team's
3
+ * baseline, compiled into every assistant.
4
+ *
5
+ * The spec's own examples are used where it gives them, so a reading that
6
+ * drifts from the published text fails here first.
7
+ */
8
+ import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs'
9
+ import { tmpdir } from 'node:os'
10
+ import { join, resolve, dirname } from 'node:path'
11
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
12
+ import {
13
+ checkSkill,
14
+ claudeMcpFor,
15
+ isAgentPlugin,
16
+ mcpSchemaUrl,
17
+ pluginNameFrom,
18
+ pluginSchemaUrl,
19
+ readAgentPlugin,
20
+ serverProblem,
21
+ teamServerFor,
22
+ } from './agent-plugin.js'
23
+ import { resolveSources, materialize, hasErrors } from './layers.js'
24
+ import type { StackConfig } from './types.js'
25
+
26
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
27
+ const noTools: StackConfig = { ides: ['claude-code'], techTools: [], teamTools: [] }
28
+
29
+ function write(root: string, files: Record<string, string>): void {
30
+ for (const [rel, text] of Object.entries(files)) {
31
+ const abs = join(root, rel)
32
+ mkdirSync(dirname(abs), { recursive: true })
33
+ writeFileSync(abs, text)
34
+ }
35
+ }
36
+
37
+ const skill = (name: string, description = `${name} does a thing. Use when it matters.`): string =>
38
+ `---\nname: ${name}\ndescription: "${description}"\n---\n\n# ${name}\n`
39
+
40
+ const manifest = (extra: Record<string, unknown> = {}): string =>
41
+ JSON.stringify({ $schema: pluginSchemaUrl(), name: 'acme.standard', version: '1.2.0', ...extra })
42
+
43
+ const mcp = (servers: Record<string, unknown>): string => JSON.stringify({ $schema: mcpSchemaUrl(), mcpServers: servers })
44
+
45
+ describe('reading a plugin', () => {
46
+ let dir: string
47
+ beforeEach(() => {
48
+ dir = mkdtempSync(join(tmpdir(), 'oc-ap-'))
49
+ })
50
+ afterEach(() => rmSync(dir, { recursive: true, force: true }))
51
+
52
+ it('loads the spec’s layout: manifest, skills and servers', () => {
53
+ write(dir, {
54
+ 'plugin.json': manifest(),
55
+ 'skills/summarize/SKILL.md': skill('summarize'),
56
+ 'skills/summarize/references/checklist.md': '- one\n',
57
+ 'skills/notes.txt': 'not a skill',
58
+ 'mcp.json': mcp({
59
+ 'local-validator': { type: 'stdio', command: './bin/validator', args: ['--data', '${PLUGIN_DATA}/validator'], env: { CONFIG: '${PLUGIN_ROOT}/config.json' }, cwd: '${PLUGIN_ROOT}' },
60
+ 'deployment-api': { type: 'streamable-http', url: 'https://deploy.example.com/mcp', headers: { 'X-Tenant': 'public-tenant' } },
61
+ 'legacy-events': { type: 'sse', url: 'https://legacy.example.com/sse' },
62
+ }),
63
+ })
64
+ const r = readAgentPlugin(dir)
65
+ expect(r.errors).toEqual([])
66
+ expect(r.warnings).toEqual([])
67
+ expect(r.version).toBe('1.0.0')
68
+ expect(r.skills).toEqual(['summarize'])
69
+ expect(Object.keys(r.servers)).toEqual(['local-validator', 'deployment-api', 'legacy-events'])
70
+ expect(isAgentPlugin(dir)).toBe(true)
71
+ })
72
+
73
+ it('refuses a manifest a client must reject, and names the field', () => {
74
+ for (const [bad, said] of [
75
+ [{ name: 'My-Plugin' }, '"name" must be'],
76
+ [{ name: 'has--double' }, '"name" must be'],
77
+ [{ version: 2 }, '"version" must be a string'],
78
+ [{ author: { name: 'A', team: 'B' } }, '"author" may hold only'],
79
+ [{ keywords: 'x' }, '"keywords" must be a list'],
80
+ ] as const) {
81
+ write(dir, { 'plugin.json': manifest(bad) })
82
+ const r = readAgentPlugin(dir)
83
+ expect(r.manifest).toBeUndefined()
84
+ expect(r.errors.join('\n')).toContain(said)
85
+ }
86
+ write(dir, { 'plugin.json': JSON.stringify({ $schema: 'https://example.com/x.json', name: 'a' }) })
87
+ expect(readAgentPlugin(dir).errors[0]).toContain('"$schema" must be')
88
+ expect(isAgentPlugin(dir)).toBe(false)
89
+ })
90
+
91
+ it('reports and ignores an unknown field, as a client must', () => {
92
+ write(dir, { 'plugin.json': manifest({ logo: 'x.png', commands: [] }) })
93
+ const r = readAgentPlugin(dir)
94
+ expect(r.errors).toEqual([])
95
+ expect(r.manifest?.name).toBe('acme.standard')
96
+ expect(r.warnings.join('\n')).toMatch(/"logo" is not an Agent Plugins field[\s\S]*"commands"/)
97
+ })
98
+
99
+ it('accepts the 1.1.0 draft, which changes only the number', () => {
100
+ write(dir, {
101
+ 'plugin.json': JSON.stringify({ $schema: pluginSchemaUrl('1.1.0'), name: 'a' }),
102
+ 'mcp.json': JSON.stringify({ $schema: mcpSchemaUrl('1.0.0'), mcpServers: {} }),
103
+ })
104
+ const r = readAgentPlugin(dir)
105
+ expect(r.version).toBe('1.1.0')
106
+ expect(r.errors).toEqual(['mcp.json: targets Agent Plugins 1.0.0 while plugin.json targets 1.1.0, so no server loads'])
107
+ })
108
+
109
+ it('skips one bad server and keeps the rest', () => {
110
+ write(dir, {
111
+ 'plugin.json': manifest(),
112
+ 'mcp.json': mcp({ bad: { type: 'stdio', command: 'npx -y thing' }, good: { type: 'stdio', command: 'npx', args: ['-y', 'thing@1.0.0'] } }),
113
+ })
114
+ const r = readAgentPlugin(dir)
115
+ expect(Object.keys(r.servers)).toEqual(['good'])
116
+ expect(r.errors[0]).toContain('command must be one executable')
117
+ })
118
+ })
119
+
120
+ describe('a server entry', () => {
121
+ it.each([
122
+ [{ type: 'stdio', command: '../bin/server' }, 'must start with ./'],
123
+ [{ type: 'stdio', command: 'node', cwd: 'data' }, 'cwd must start with'],
124
+ [{ type: 'stdio', command: 'node', env: { PLUGIN_ROOT: '/x' } }, 'cannot set PLUGIN_ROOT'],
125
+ [{ type: 'stdio', command: '${PLUGIN_ROOT}/bin/x' }, 'command is not expanded'],
126
+ [{ type: 'streamable-http', url: 'http://api.example.com/mcp' }, 'needs https'],
127
+ [{ type: 'streamable-http', url: 'https://user:pw@api.example.com/mcp' }, 'user or password'],
128
+ [{ type: 'streamable-http', url: 'https://api.example.com/mcp#x' }, 'fragment'],
129
+ [{ type: 'streamable-http', url: 'https://a.example.com', headers: { 'X-A': '1', 'x-a': '2' } }, 'given twice'],
130
+ [{ type: 'streamable-http', url: 'https://a.example.com', command: 'x' }, 'cannot have'],
131
+ [{ type: 'websocket', url: 'wss://a' }, 'type must be'],
132
+ ])('refuses %j', (raw, said) => {
133
+ expect(serverProblem('s', raw)).toContain(said)
134
+ })
135
+
136
+ it('lets a loopback server use plain http', () => {
137
+ expect(serverProblem('s', { type: 'streamable-http', url: 'http://127.0.0.1:3845/mcp' })).toBeNull()
138
+ expect(serverProblem('s', { type: 'streamable-http', url: 'http://localhost:3845/mcp' })).toBeNull()
139
+ })
140
+ })
141
+
142
+ describe('a skill, against the Agent Skills spec', () => {
143
+ let dir: string
144
+ beforeEach(() => {
145
+ dir = mkdtempSync(join(tmpdir(), 'oc-skill-'))
146
+ })
147
+ afterEach(() => rmSync(dir, { recursive: true, force: true }))
148
+
149
+ it('must be named as its directory', () => {
150
+ write(dir, { 'deploy/SKILL.md': skill('deploy-runbook') })
151
+ expect(checkSkill(join(dir, 'deploy')).errors[0]).toContain('must match its directory, deploy/')
152
+ })
153
+
154
+ it('needs a description of at most 1024 characters', () => {
155
+ write(dir, { 'a/SKILL.md': skill('a', 'x'.repeat(1025)), 'b/SKILL.md': '---\nname: b\n---\n' })
156
+ expect(checkSkill(join(dir, 'a')).errors[0]).toContain('1025 characters')
157
+ expect(checkSkill(join(dir, 'b')).errors[0]).toContain('has no description')
158
+ })
159
+
160
+ it('names fields the spec does not define, and lets assistant ones pass', () => {
161
+ write(dir, { 'a/SKILL.md': '---\nname: a\ndescription: "Does a. Use when a."\nuser-invocable: true\napplyTo: "**"\n---\n' })
162
+ const r = checkSkill(join(dir, 'a'))
163
+ expect(r.errors).toEqual([])
164
+ expect(r.warnings).toEqual(['skills/a/SKILL.md: applyTo is not an Agent Skills field; other assistants ignore it'])
165
+ })
166
+ })
167
+
168
+ describe('Claude Code’s copies', () => {
169
+ it('resolves ./ and the plugin variables in Claude Code’s spelling', () => {
170
+ expect(
171
+ claudeMcpFor({
172
+ local: { type: 'stdio', command: './bin/server', args: ['${PLUGIN_ROOT}/a', '${PLUGIN_DATA}/b'] },
173
+ remote: { type: 'streamable-http', url: 'https://x.example.com/mcp' },
174
+ old: { type: 'sse', url: 'https://y.example.com/sse' },
175
+ }),
176
+ ).toEqual({
177
+ mcpServers: {
178
+ local: { command: '${CLAUDE_PLUGIN_ROOT}/bin/server', args: ['${CLAUDE_PLUGIN_ROOT}/a', '${CLAUDE_PLUGIN_DATA}/b'] },
179
+ remote: { type: 'http', url: 'https://x.example.com/mcp' },
180
+ old: { type: 'sse', url: 'https://y.example.com/sse' },
181
+ },
182
+ })
183
+ })
184
+ })
185
+
186
+ describe('naming', () => {
187
+ it('makes a plugin name from a package name', () => {
188
+ expect(pluginNameFrom('@acme/ai-standard')).toBe('acme.ai-standard')
189
+ expect(pluginNameFrom('My Plugin!')).toBe('my-plugin')
190
+ })
191
+ })
192
+
193
+ describe('a plugin as a team’s baseline', () => {
194
+ let project: string
195
+ beforeEach(() => {
196
+ project = mkdtempSync(join(tmpdir(), 'oc-ap-layer-'))
197
+ })
198
+ afterEach(() => rmSync(project, { recursive: true, force: true }))
199
+
200
+ const plugin = (root: string, files: Record<string, string> = {}): void =>
201
+ write(join(project, root), {
202
+ 'plugin.json': manifest(),
203
+ 'skills/secure-coding/SKILL.md': skill('secure-coding'),
204
+ 'mcp.json': mcp({
205
+ docs: { type: 'streamable-http', url: 'https://docs.acme.example/mcp' },
206
+ lint: { type: 'stdio', command: './bin/lint', args: ['--config', '${PLUGIN_ROOT}/lint.json'] },
207
+ cache: { type: 'stdio', command: 'node', args: ['${PLUGIN_DATA}/x.js'] },
208
+ }),
209
+ 'dev.opencastle/instructions/standards.md': '# Standards\n\nBe kind.\n',
210
+ 'dev.opencastle/config.json': JSON.stringify({ policy: { contextBudget: 9000 } }),
211
+ ...files,
212
+ })
213
+
214
+ it('compiles its skills, its portable servers and its OpenCastle layer', () => {
215
+ plugin('standard')
216
+ write(project, { '.opencastle/config.json': JSON.stringify({ extends: ['../standard'] }) })
217
+ const r = resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
218
+ expect(hasErrors(r)).toBe(false)
219
+ expect(r.items.get('skills/secure-coding')?.layer).toBe('standard')
220
+ expect(r.items.get('instructions/standards')?.layer).toBe('standard')
221
+ expect(r.policy.contextBudget).toEqual({ tokens: 9000, by: 'standard' })
222
+ expect(r.servers.get('docs')).toMatchObject({ server: { type: 'http', url: 'https://docs.acme.example/mcp' }, where: 'standard/mcp.json' })
223
+ expect(r.servers.get('lint')?.server).toEqual({ type: 'stdio', command: './standard/bin/lint', args: ['--config', './standard/lint.json'] })
224
+ expect(r.servers.has('cache')).toBe(false)
225
+ expect(r.issues.map((i) => i.message).join('\n')).toContain('MCP server "cache" uses ${PLUGIN_DATA}')
226
+ const src = materialize(r, pkgRoot)
227
+ try {
228
+ expect(readFileSync(join(src.root, 'skills', 'secure-coding', 'SKILL.md'), 'utf8')).toContain('secure-coding')
229
+ } finally {
230
+ src.dispose()
231
+ }
232
+ })
233
+
234
+ it('extends one published to npm as it is, with no OpenCastle declaration', () => {
235
+ plugin('node_modules/@acme/standard', { 'package.json': JSON.stringify({ name: '@acme/standard', version: '1.2.0' }) })
236
+ write(project, { '.opencastle/config.json': JSON.stringify({ extends: ['@acme/standard'] }) })
237
+ const r = resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
238
+ expect(hasErrors(r)).toBe(false)
239
+ expect(r.layers.find((l) => l.id === '@acme/standard')?.version).toBe('1.2.0')
240
+ expect(r.servers.get('lint')?.server).toMatchObject({ command: './node_modules/@acme/standard/bin/lint' })
241
+ })
242
+
243
+ it('refuses a server defined in both mcp.json and config.json', () => {
244
+ plugin('standard', {
245
+ 'dev.opencastle/config.json': JSON.stringify({ mcpServers: { docs: { url: 'https://docs.acme.example/mcp' } } }),
246
+ })
247
+ write(project, { '.opencastle/config.json': JSON.stringify({ extends: ['../standard'] }) })
248
+ const r = resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
249
+ expect(r.issues.find((i) => i.level === 'error')?.message).toBe('defines MCP server "docs", which standard/dev.opencastle/config.json defines too')
250
+ })
251
+
252
+ it('refuses one a conformant client would reject', () => {
253
+ write(join(project, 'broken'), { 'plugin.json': JSON.stringify({ $schema: pluginSchemaUrl(), name: 'Bad Name' }) })
254
+ write(project, { '.opencastle/config.json': JSON.stringify({ extends: ['../broken'] }) })
255
+ const r = resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
256
+ expect(hasErrors(r)).toBe(true)
257
+ expect(r.issues[0].message).toContain('which is not a valid Agent Plugin: plugin.json: "name" must be')
258
+ })
259
+
260
+ it('compiles a portable server the way a team server is compiled', () => {
261
+ expect(teamServerFor({ type: 'stdio', command: 'npx', args: ['-y', 'x@1.0.0'] }, 'node_modules/x')).toEqual({
262
+ server: { type: 'stdio', command: 'npx', args: ['-y', 'x@1.0.0'] },
263
+ })
264
+ expect(teamServerFor({ type: 'sse', url: 'https://a.example.com/sse' }, 'x').skipped).toContain('legacy SSE')
265
+ expect(teamServerFor({ type: 'stdio', command: 'node', cwd: './data' }, 'x').skipped).toContain('runs in ./data')
266
+ })
267
+ })