opencastle 1.1.1 → 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 (221) hide show
  1. package/README.md +22 -5
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  4. package/dist/cli/adapters/single-file-base.js +24 -2
  5. package/dist/cli/adapters/single-file-base.js.map +1 -1
  6. package/dist/cli/agent-plugin.d.ts +119 -0
  7. package/dist/cli/agent-plugin.d.ts.map +1 -0
  8. package/dist/cli/agent-plugin.js +449 -0
  9. package/dist/cli/agent-plugin.js.map +1 -0
  10. package/dist/cli/agent-plugin.test.d.ts +2 -0
  11. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  12. package/dist/cli/agent-plugin.test.js +227 -0
  13. package/dist/cli/agent-plugin.test.js.map +1 -0
  14. package/dist/cli/baseline.d.ts.map +1 -1
  15. package/dist/cli/baseline.js +99 -26
  16. package/dist/cli/baseline.js.map +1 -1
  17. package/dist/cli/convoy/gates.d.ts +2 -20
  18. package/dist/cli/convoy/gates.d.ts.map +1 -1
  19. package/dist/cli/convoy/gates.js +3 -111
  20. package/dist/cli/convoy/gates.js.map +1 -1
  21. package/dist/cli/copy.d.ts +0 -8
  22. package/dist/cli/copy.d.ts.map +1 -1
  23. package/dist/cli/copy.js +0 -21
  24. package/dist/cli/copy.js.map +1 -1
  25. package/dist/cli/dispatcher.test.js +2 -2
  26. package/dist/cli/dispatcher.test.js.map +1 -1
  27. package/dist/cli/docs-accuracy.test.js +2 -0
  28. package/dist/cli/docs-accuracy.test.js.map +1 -1
  29. package/dist/cli/doctor.d.ts.map +1 -1
  30. package/dist/cli/doctor.js +2 -0
  31. package/dist/cli/doctor.js.map +1 -1
  32. package/dist/cli/init.test.js +36 -24
  33. package/dist/cli/init.test.js.map +1 -1
  34. package/dist/cli/layers.d.ts +8 -0
  35. package/dist/cli/layers.d.ts.map +1 -1
  36. package/dist/cli/layers.js +130 -13
  37. package/dist/cli/layers.js.map +1 -1
  38. package/dist/cli/layers.test.js +2 -2
  39. package/dist/cli/layers.test.js.map +1 -1
  40. package/dist/cli/legacy-install.test.js +8 -1
  41. package/dist/cli/legacy-install.test.js.map +1 -1
  42. package/dist/cli/lesson-command.test.d.ts +2 -0
  43. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  44. package/dist/cli/lesson-command.test.js +100 -0
  45. package/dist/cli/lesson-command.test.js.map +1 -0
  46. package/dist/cli/lesson.d.ts +0 -9
  47. package/dist/cli/lesson.d.ts.map +1 -1
  48. package/dist/cli/lesson.js +212 -276
  49. package/dist/cli/lesson.js.map +1 -1
  50. package/dist/cli/lessons.d.ts +134 -0
  51. package/dist/cli/lessons.d.ts.map +1 -0
  52. package/dist/cli/lessons.js +493 -0
  53. package/dist/cli/lessons.js.map +1 -0
  54. package/dist/cli/lessons.test.d.ts +2 -0
  55. package/dist/cli/lessons.test.d.ts.map +1 -0
  56. package/dist/cli/lessons.test.js +214 -0
  57. package/dist/cli/lessons.test.js.map +1 -0
  58. package/dist/cli/pack-plugins.d.ts +8 -0
  59. package/dist/cli/pack-plugins.d.ts.map +1 -0
  60. package/dist/cli/pack-plugins.js +70 -0
  61. package/dist/cli/pack-plugins.js.map +1 -0
  62. package/dist/cli/plugin-command.test.d.ts +2 -0
  63. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  64. package/dist/cli/plugin-command.test.js +114 -0
  65. package/dist/cli/plugin-command.test.js.map +1 -0
  66. package/dist/cli/plugin.d.ts +30 -0
  67. package/dist/cli/plugin.d.ts.map +1 -0
  68. package/dist/cli/plugin.js +291 -0
  69. package/dist/cli/plugin.js.map +1 -0
  70. package/dist/cli/promote-command.test.d.ts +2 -0
  71. package/dist/cli/promote-command.test.d.ts.map +1 -0
  72. package/dist/cli/promote-command.test.js +151 -0
  73. package/dist/cli/promote-command.test.js.map +1 -0
  74. package/dist/cli/promote.d.ts +12 -0
  75. package/dist/cli/promote.d.ts.map +1 -0
  76. package/dist/cli/promote.js +364 -0
  77. package/dist/cli/promote.js.map +1 -0
  78. package/dist/cli/secret-scan.d.ts +21 -0
  79. package/dist/cli/secret-scan.d.ts.map +1 -0
  80. package/dist/cli/secret-scan.js +114 -0
  81. package/dist/cli/secret-scan.js.map +1 -0
  82. package/dist/cli/sync-check.d.ts.map +1 -1
  83. package/dist/cli/sync-check.js +9 -0
  84. package/dist/cli/sync-check.js.map +1 -1
  85. package/dist/cli/team-commands.test.js +2 -2
  86. package/dist/cli/team-commands.test.js.map +1 -1
  87. package/dist/cli/update.d.ts.map +1 -1
  88. package/dist/cli/update.js +18 -0
  89. package/dist/cli/update.js.map +1 -1
  90. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  91. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  92. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  93. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  94. package/package.json +2 -1
  95. package/src/cli/adapters/single-file-base.ts +23 -2
  96. package/src/cli/agent-plugin.test.ts +267 -0
  97. package/src/cli/agent-plugin.ts +469 -0
  98. package/src/cli/baseline.ts +99 -26
  99. package/src/cli/convoy/gates.ts +9 -142
  100. package/src/cli/copy.ts +0 -25
  101. package/src/cli/dispatcher.test.ts +2 -2
  102. package/src/cli/docs-accuracy.test.ts +2 -0
  103. package/src/cli/doctor.ts +2 -0
  104. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  105. package/src/cli/init.test.ts +37 -24
  106. package/src/cli/layers.test.ts +2 -2
  107. package/src/cli/layers.ts +144 -14
  108. package/src/cli/legacy-install.test.ts +11 -1
  109. package/src/cli/lesson-command.test.ts +117 -0
  110. package/src/cli/lesson.ts +215 -266
  111. package/src/cli/lessons.test.ts +254 -0
  112. package/src/cli/lessons.ts +540 -0
  113. package/src/cli/pack-plugins.ts +70 -0
  114. package/src/cli/plugin-command.test.ts +125 -0
  115. package/src/cli/plugin.ts +309 -0
  116. package/src/cli/promote-command.test.ts +170 -0
  117. package/src/cli/promote.ts +371 -0
  118. package/src/cli/secret-scan.ts +154 -0
  119. package/src/cli/sync-check.ts +9 -0
  120. package/src/cli/team-commands.test.ts +2 -2
  121. package/src/cli/update.ts +20 -0
  122. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  123. package/src/orchestrator/agents/researcher.agent.md +1 -1
  124. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  125. package/src/orchestrator/customizations/README.md +2 -1
  126. package/src/orchestrator/customizations/logs/README.md +1 -1
  127. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  128. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  129. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  130. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  131. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  132. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  133. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  134. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  135. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  136. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  137. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  138. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  139. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  140. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  141. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  142. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  143. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  144. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  145. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  146. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  147. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  148. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  149. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  150. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  151. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  152. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  153. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  154. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  155. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  156. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  157. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  158. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  159. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  160. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  161. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  162. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  163. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  164. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  165. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  166. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  167. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  168. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  169. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  170. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  171. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  172. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  173. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  174. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  175. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  176. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  177. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  178. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  179. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  180. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  181. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  182. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  183. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  184. package/src/orchestrator/skill-config-links.test.ts +2 -1
  185. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  186. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  187. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  188. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  189. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  190. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  191. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  192. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  193. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  194. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  195. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  196. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  197. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  198. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  199. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  200. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  201. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  202. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  203. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  204. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  205. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  206. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  207. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  208. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  209. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  210. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  211. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  212. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  213. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  214. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  215. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  216. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  217. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  218. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  219. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  220. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  221. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
@@ -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
+ })
@@ -0,0 +1,309 @@
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { basename, dirname, join, relative, resolve } from 'node:path'
3
+ import {
4
+ AGENT_PLUGINS_VERSION,
5
+ EXTENSION_NAMESPACE,
6
+ claudeManifestFor,
7
+ claudeMcpFor,
8
+ isAgentPlugin,
9
+ pluginNameFrom,
10
+ readAgentPlugin,
11
+ type PluginReport,
12
+ } from './agent-plugin.js'
13
+ import { c } from './prompt.js'
14
+ import type { CliContext } from './types.js'
15
+
16
+ /**
17
+ * `opencastle plugin`: check, complete and list Agent Plugins.
18
+ *
19
+ * The standard leaves two things to each client: Claude Code reads its own
20
+ * manifest (`.claude-plugin/plugin.json`) and its own MCP file (`.mcp.json`),
21
+ * and every client indexes a marketplace in its own file. Keeping those by hand
22
+ * is three copies of one fact, which is the drift this tool exists to stop —
23
+ * so they are compiled from the portable files and checked in CI like any
24
+ * other generated output.
25
+ */
26
+
27
+ const HELP = `
28
+ opencastle plugin <check|build|index> [dir] [options]
29
+
30
+ Agent Plugins 1.0 is the open package format for skills and MCP servers
31
+ (agent-plugins.org): plugin.json, skills/<name>/SKILL.md and mcp.json.
32
+ GitHub Copilot, VS Code, Cursor, Codex and Kiro install one as it is.
33
+
34
+ check [dir] Check a plugin the way a conformant client loads it: the
35
+ manifest, every skill against the Agent Skills spec, every
36
+ MCP server, and that Claude Code's files match the portable ones.
37
+ build [dir] Write Claude Code's .claude-plugin/plugin.json and .mcp.json
38
+ from plugin.json and mcp.json. Claude Code reads only those.
39
+ index [dir] Write the marketplace files for every plugin under plugins/:
40
+ .claude-plugin/marketplace.json (Claude Code, Copilot CLI),
41
+ .cursor-plugin/marketplace.json (Cursor) and
42
+ .agents/plugins/marketplace.json (Codex).
43
+
44
+ Options:
45
+ --check build and index: change nothing; exit 1 if a file is out of date
46
+ --name <name> index: the marketplace name (default: from package.json or the directory)
47
+ --owner <name> index: who maintains it (default: from package.json)
48
+ --json check: machine-readable output
49
+ --help, -h Show this help
50
+ `
51
+
52
+ function json(value: unknown): string {
53
+ return JSON.stringify(value, null, 2) + '\n'
54
+ }
55
+
56
+ function readJsonFile(path: string): Record<string, unknown> | null {
57
+ try {
58
+ const v = JSON.parse(readFileSync(path, 'utf8'))
59
+ return v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : null
60
+ } catch {
61
+ return null
62
+ }
63
+ }
64
+
65
+ // ── build ─────────────────────────────────────────────────────
66
+
67
+ /**
68
+ * What Claude Code's two files should hold, as path → text, or `null` for a
69
+ * file that should not exist.
70
+ *
71
+ * `.claude-plugin/plugin.json` is co-owned: the portable fields are compiled
72
+ * in, and anything only Claude Code reads — `userConfig`, `hooks`, `agents`,
73
+ * inline `mcpServers` — is the author's and kept. `.mcp.json` is compiled
74
+ * whole from `mcp.json` when the plugin has portable servers; a server only
75
+ * Claude Code should start belongs inline in the manifest.
76
+ */
77
+ export function claudeFiles(root: string, report: PluginReport): Record<string, string | null> {
78
+ if (!report.manifest) return {}
79
+ const manifestPath = join(root, '.claude-plugin', 'plugin.json')
80
+ const existing = readJsonFile(manifestPath) ?? {}
81
+ const generated = claudeManifestFor(report.manifest)
82
+ const portable = ['name', 'version', 'description', 'author', 'homepage', 'repository', 'license', 'keywords']
83
+ const kept = Object.fromEntries(Object.entries(existing).filter(([k]) => !portable.includes(k)))
84
+ const files: Record<string, string | null> = { '.claude-plugin/plugin.json': json({ ...generated, ...kept }) }
85
+ // With no portable servers there is nothing to compile, and a `.mcp.json`
86
+ // already there is one the author wrote for Claude Code alone.
87
+ if (Object.keys(report.servers).length > 0) files['.mcp.json'] = json(claudeMcpFor(report.servers))
88
+ return files
89
+ }
90
+
91
+ /** Write (or with `check`, compare) a set of generated files. Returns the ones that differ. */
92
+ function apply(root: string, files: Record<string, string | null>, check: boolean): string[] {
93
+ const changed: string[] = []
94
+ for (const [rel, text] of Object.entries(files)) {
95
+ const abs = join(root, rel)
96
+ const current = existsSync(abs) ? readFileSync(abs, 'utf8') : null
97
+ if (current === text) continue
98
+ changed.push(rel)
99
+ if (check) continue
100
+ if (text === null) rmSync(abs, { force: true })
101
+ else {
102
+ mkdirSync(dirname(abs), { recursive: true })
103
+ writeFileSync(abs, text)
104
+ }
105
+ }
106
+ return changed
107
+ }
108
+
109
+ // ── index ─────────────────────────────────────────────────────
110
+
111
+ interface Listed {
112
+ dir: string
113
+ name: string
114
+ description?: string
115
+ claude: boolean
116
+ }
117
+
118
+ function marketplaceIdentity(root: string, nameFlag?: string, ownerFlag?: string): { name: string; owner: string; description: string } {
119
+ const pkg = readJsonFile(join(root, 'package.json')) ?? {}
120
+ const pkgName = typeof pkg.name === 'string' ? pkg.name : undefined
121
+ const author = pkg.author
122
+ const authorName = typeof author === 'string' ? author.replace(/\s*[<(].*$/, '') : author && typeof author === 'object' ? (author as { name?: string }).name : undefined
123
+ const name = nameFlag ?? pluginNameFrom(pkgName ?? basename(resolve(root)))
124
+ return {
125
+ name,
126
+ owner: ownerFlag ?? authorName ?? name,
127
+ description: typeof pkg.description === 'string' ? pkg.description : `Agent Plugins from ${name}`,
128
+ }
129
+ }
130
+
131
+ /** The three marketplace files for the plugins under `plugins/`. */
132
+ export function marketplaceFiles(
133
+ plugins: Listed[],
134
+ identity: { name: string; owner: string; description: string },
135
+ ): Record<string, string> {
136
+ const entries = plugins.map((p) => ({
137
+ name: p.name,
138
+ source: `./plugins/${p.dir}`,
139
+ ...(p.description && { description: p.description }),
140
+ }))
141
+ // One shape both read: Cursor's schema is a strict subset of Claude Code's.
142
+ const shared = json({
143
+ name: identity.name,
144
+ owner: { name: identity.owner },
145
+ metadata: { description: identity.description },
146
+ plugins: entries,
147
+ })
148
+ const codex = json({
149
+ name: identity.name,
150
+ interface: { displayName: identity.name },
151
+ plugins: plugins.map((p) => ({
152
+ name: p.name,
153
+ source: { source: 'local', path: `./plugins/${p.dir}` },
154
+ policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },
155
+ })),
156
+ })
157
+ return {
158
+ '.claude-plugin/marketplace.json': shared,
159
+ '.cursor-plugin/marketplace.json': shared,
160
+ '.agents/plugins/marketplace.json': codex,
161
+ }
162
+ }
163
+
164
+ function listPlugins(root: string): { plugins: Listed[]; problems: string[] } {
165
+ const dir = join(root, 'plugins')
166
+ const plugins: Listed[] = []
167
+ const problems: string[] = []
168
+ if (!existsSync(dir)) return { plugins, problems: [`${relative(process.cwd(), dir) || 'plugins'}/ does not exist — a marketplace lists plugins/<name>/`] }
169
+ for (const entry of readdirSync(dir).sort()) {
170
+ const at = join(dir, entry)
171
+ if (!existsSync(join(at, 'plugin.json'))) continue
172
+ if (!isAgentPlugin(at)) {
173
+ problems.push(`plugins/${entry}: plugin.json does not declare an Agent Plugins version — run opencastle plugin check plugins/${entry}`)
174
+ continue
175
+ }
176
+ const report = readAgentPlugin(at)
177
+ if (!report.manifest) {
178
+ problems.push(`plugins/${entry}: ${report.errors[0]}`)
179
+ continue
180
+ }
181
+ plugins.push({
182
+ dir: entry,
183
+ name: report.manifest.name,
184
+ description: report.manifest.description,
185
+ claude: existsSync(join(at, '.claude-plugin', 'plugin.json')),
186
+ })
187
+ }
188
+ const names = new Map<string, string>()
189
+ for (const p of plugins) {
190
+ const other = names.get(p.name)
191
+ if (other) problems.push(`plugins/${p.dir} and plugins/${other} are both named "${p.name}"; a marketplace lists a name once`)
192
+ names.set(p.name, p.dir)
193
+ }
194
+ return { plugins, problems }
195
+ }
196
+
197
+ // ── command ───────────────────────────────────────────────────
198
+
199
+ function flagValue(args: string[], flag: string): string | undefined {
200
+ const at = args.indexOf(flag)
201
+ if (at === -1) return undefined
202
+ const v = args[at + 1]
203
+ if (!v || v.startsWith('--')) {
204
+ console.error(` ${c.red('✗')} ${flag} needs a value`)
205
+ process.exit(1)
206
+ }
207
+ return v
208
+ }
209
+
210
+ function printReport(dir: string, report: PluginReport, claudeStale: string[]): void {
211
+ const m = report.manifest
212
+ console.log(`\n 🏰 ${c.bold('Agent Plugin')} ${m?.name ?? dir}${m?.version ? c.dim(` ${m.version}`) : ''}${report.version ? c.dim(` · Agent Plugins ${report.version}`) : ''}\n`)
213
+ if (m) {
214
+ console.log(` Skills: ${report.skills.length > 0 ? report.skills.join(', ') : c.dim('none')}`)
215
+ console.log(` MCP servers: ${Object.keys(report.servers).length > 0 ? Object.keys(report.servers).join(', ') : c.dim('none')}`)
216
+ if (existsSync(join(report.root, EXTENSION_NAMESPACE))) {
217
+ console.log(` ${EXTENSION_NAMESPACE}/: ${c.dim('OpenCastle content — check it with opencastle baseline check')}`)
218
+ }
219
+ }
220
+ for (const e of report.errors) console.log(` ${c.red('✗')} ${e}`)
221
+ for (const s of claudeStale) console.log(` ${c.red('✗')} ${s} does not match plugin.json and mcp.json ${c.dim('— run opencastle plugin build')}`)
222
+ for (const w of report.warnings) console.log(` ${c.yellow('!')} ${c.dim(w)}`)
223
+ if (report.errors.length === 0 && claudeStale.length === 0) {
224
+ console.log(`\n ${c.green('✓')} Loads in GitHub Copilot, VS Code, Cursor, Codex and Kiro as it is` +
225
+ (existsSync(join(report.root, '.claude-plugin', 'plugin.json')) ? ', and in Claude Code.\n' : `.\n ${c.dim('Run opencastle plugin build to add the files Claude Code reads.')}\n`))
226
+ } else {
227
+ console.log(`\n ${c.red(`${report.errors.length + claudeStale.length} problem(s) to fix.`)}\n`)
228
+ }
229
+ }
230
+
231
+ /** Claude Code's files that exist and no longer match the portable ones. */
232
+ export function staleClaudeFiles(root: string, report: PluginReport): string[] {
233
+ if (!existsSync(join(root, '.claude-plugin', 'plugin.json')) && !existsSync(join(root, '.mcp.json'))) return []
234
+ return apply(root, claudeFiles(root, report), true)
235
+ }
236
+
237
+ export default async function plugin({ args }: CliContext): Promise<void> {
238
+ const [sub, ...rest] = args
239
+ if (!sub || args.includes('--help') || args.includes('-h') || !['check', 'build', 'index'].includes(sub)) {
240
+ console.log(HELP)
241
+ if (sub && !['check', 'build', 'index', '--help', '-h'].includes(sub)) process.exit(1)
242
+ return
243
+ }
244
+ const valued = new Set(['--name', '--owner'])
245
+ const positional = rest.filter((a, i) => !a.startsWith('--') && !valued.has(rest[i - 1]))
246
+ const dir = positional[0] ?? '.'
247
+ const root = resolve(dir)
248
+ const check = rest.includes('--check')
249
+
250
+ if (sub === 'check') {
251
+ const report = readAgentPlugin(root)
252
+ const stale = report.manifest ? staleClaudeFiles(root, report) : []
253
+ if (rest.includes('--json')) {
254
+ console.log(json({ ...report, root: dir, claudeOutOfDate: stale, spec: AGENT_PLUGINS_VERSION }))
255
+ } else {
256
+ printReport(dir, report, stale)
257
+ }
258
+ if (report.errors.length > 0 || stale.length > 0) process.exit(1)
259
+ return
260
+ }
261
+
262
+ if (sub === 'build') {
263
+ const report = readAgentPlugin(root)
264
+ if (!report.manifest) {
265
+ for (const e of report.errors) console.error(` ${c.red('✗')} ${e}`)
266
+ process.exit(1)
267
+ }
268
+ const changed = apply(root, claudeFiles(root, report), check)
269
+ if (check) {
270
+ if (changed.length > 0) {
271
+ for (const f of changed) console.error(` ${c.red('✗')} ${f} does not match plugin.json and mcp.json — run opencastle plugin build`)
272
+ process.exit(1)
273
+ }
274
+ console.log(` ${c.green('✓')} Claude Code's files match plugin.json and mcp.json`)
275
+ return
276
+ }
277
+ console.log(changed.length > 0 ? ` ${c.green('✓')} Wrote ${changed.join(', ')}` : ` ${c.green('✓')} Claude Code's files were already up to date`)
278
+ return
279
+ }
280
+
281
+ // index
282
+ const { plugins, problems } = listPlugins(root)
283
+ for (const p of problems) console.error(` ${c.red('✗')} ${p}`)
284
+ if (problems.length > 0) process.exit(1)
285
+ if (plugins.length === 0) {
286
+ console.error(` ${c.red('✗')} no Agent Plugin under ${dir}/plugins/ — each is a directory with a plugin.json`)
287
+ process.exit(1)
288
+ }
289
+ const identity = marketplaceIdentity(root, flagValue(rest, '--name'), flagValue(rest, '--owner'))
290
+ const changed = apply(root, marketplaceFiles(plugins, identity), check)
291
+ const noClaude = plugins.filter((p) => !p.claude)
292
+ if (check) {
293
+ if (changed.length > 0) {
294
+ for (const f of changed) console.error(` ${c.red('✗')} ${f} does not list the plugins under plugins/ — run opencastle plugin index`)
295
+ process.exit(1)
296
+ }
297
+ console.log(` ${c.green('✓')} The marketplace files list all ${plugins.length} plugin(s)`)
298
+ return
299
+ }
300
+ console.log(
301
+ changed.length > 0
302
+ ? ` ${c.green('✓')} Listed ${plugins.length} plugin(s) in ${changed.join(', ')}`
303
+ : ` ${c.green('✓')} The marketplace files already list all ${plugins.length} plugin(s)`,
304
+ )
305
+ if (noClaude.length > 0) {
306
+ console.log(` ${c.yellow('!')} ${noClaude.map((p) => `plugins/${p.dir}`).join(', ')} ${c.dim('— Claude Code needs .claude-plugin/plugin.json; run opencastle plugin build in each')}`)
307
+ }
308
+ console.log(` ${c.dim(`Add it: claude plugin marketplace add <owner>/<repo>, copilot plugin marketplace add <owner>/<repo>, codex plugin marketplace add <owner>/<repo>; in Cursor, Dashboard → Plugins → Team Marketplaces → Import.`)}`)
309
+ }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * `opencastle promote`, through the built CLI, with a home directory and a
3
+ * Claude Code config directory of the test's own.
4
+ */
5
+ import { execFileSync, spawnSync } from 'node:child_process'
6
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
7
+ import { tmpdir } from 'node:os'
8
+ import { dirname, join, resolve } from 'node:path'
9
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
10
+ import { claudeMemoryDir } from './promote.js'
11
+
12
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
13
+ const cli = join(pkgRoot, 'bin', 'cli.mjs')
14
+ const built = existsSync(join(pkgRoot, 'dist', 'cli', 'promote.js'))
15
+
16
+ function write(root: string, files: Record<string, string>): void {
17
+ for (const [rel, text] of Object.entries(files)) {
18
+ mkdirSync(dirname(join(root, rel)), { recursive: true })
19
+ writeFileSync(join(root, rel), text)
20
+ }
21
+ }
22
+
23
+ const skill = (name: string, body = 'Do the thing well.'): string =>
24
+ `---\nname: ${name}\ndescription: "How we deploy. Use when releasing or rolling back."\n---\n\n# ${name}\n\n${body}\n`
25
+
26
+ const memory = (name: string, type: string, body: string): string =>
27
+ `---\nname: ${name}\ndescription: "${name.replace(/-/g, ' ')}"\nmetadata:\n node_type: memory\n type: ${type}\n originSessionId: a50c8b40-9d31-4f2e-b2d6-c56e14021622\n---\n\n${body}\n`
28
+
29
+ describe.skipIf(!built)('opencastle promote', () => {
30
+ let root: string
31
+ let home: string
32
+ let config: string
33
+ let project: string
34
+ const env = (): NodeJS.ProcessEnv => ({ ...process.env, HOME: home, CLAUDE_CONFIG_DIR: config })
35
+ const run = (cwd: string, ...args: string[]) => {
36
+ const r = spawnSync('node', [cli, ...args], { cwd, encoding: 'utf8', env: env() })
37
+ // eslint-disable-next-line no-control-regex
38
+ const plain = (t: string): string => t.replace(/\x1b\[[0-9;]*m/g, '')
39
+ return { status: r.status, stdout: plain(r.stdout), stderr: plain(r.stderr) }
40
+ }
41
+
42
+ beforeEach(() => {
43
+ root = mkdtempSync(join(tmpdir(), 'oc-promote-'))
44
+ home = join(root, 'home')
45
+ config = join(home, '.claude')
46
+ project = join(root, 'app')
47
+ mkdirSync(home, { recursive: true })
48
+ write(project, { 'CLAUDE.md': '# App\n' })
49
+ execFileSync('git', ['init', '-q'], { cwd: project })
50
+ expect(run(project, 'init', '--yes').status).toBe(0)
51
+ })
52
+ afterEach(() => rmSync(root, { recursive: true, force: true }))
53
+
54
+ describe('skill', () => {
55
+ it('copies a personal skill into the team’s sources, and sync gives it to every assistant', () => {
56
+ write(home, { '.claude/skills/deploy-runbook/SKILL.md': skill('deploy-runbook'), '.claude/skills/deploy-runbook/scripts/rollback.sh': '#!/bin/sh\n' })
57
+ const out = run(project, 'promote', 'skill', 'deploy-runbook')
58
+ expect(out.status, out.stderr).toBe(0)
59
+ expect(out.stdout).toContain('Promoted deploy-runbook from ~/.claude/skills/deploy-runbook')
60
+ expect(readdirSync(join(project, '.opencastle', 'skills', 'deploy-runbook')).sort()).toEqual(['SKILL.md', 'scripts'])
61
+ expect(run(project, 'sync', '--yes').status).toBe(0)
62
+ expect(existsSync(join(project, '.claude', 'skills', 'deploy-runbook', 'scripts', 'rollback.sh'))).toBe(true)
63
+ })
64
+
65
+ it('finds one in the shared .agents/skills/ too', () => {
66
+ write(home, { '.agents/skills/deploy-runbook/SKILL.md': skill('deploy-runbook') })
67
+ expect(run(project, 'promote', 'skill', 'deploy-runbook').status).toBe(0)
68
+ })
69
+
70
+ it('refuses one an assistant following the Agent Skills spec would skip', () => {
71
+ write(home, { '.claude/skills/deploy/SKILL.md': skill('deploy-runbook') })
72
+ const out = run(project, 'promote', 'skill', 'deploy')
73
+ expect(out.status).toBe(1)
74
+ expect(out.stderr).toContain('must match its directory, deploy/')
75
+ expect(existsSync(join(project, '.opencastle', 'skills', 'deploy'))).toBe(false)
76
+ })
77
+
78
+ it('refuses one that would commit a credential', () => {
79
+ write(home, { '.claude/skills/deploy-runbook/SKILL.md': skill('deploy-runbook', 'Use key AKIAIOSFODNN7EXAMPLE.') })
80
+ const out = run(project, 'promote', 'skill', 'deploy-runbook')
81
+ expect(out.status).toBe(1)
82
+ expect(out.stderr).toContain('looks like a AWS Access Key')
83
+ })
84
+
85
+ it('will not replace a team skill unless told to', () => {
86
+ write(home, { '.claude/skills/deploy-runbook/SKILL.md': skill('deploy-runbook', 'new') })
87
+ write(project, { '.opencastle/skills/deploy-runbook/SKILL.md': skill('deploy-runbook', 'old') })
88
+ expect(run(project, 'promote', 'skill', 'deploy-runbook').stderr).toContain('already exists')
89
+ expect(run(project, 'promote', 'skill', 'deploy-runbook', '--force').status).toBe(0)
90
+ expect(readFileSync(join(project, '.opencastle', 'skills', 'deploy-runbook', 'SKILL.md'), 'utf8')).toContain('new')
91
+ })
92
+
93
+ it('promotes into a baseline every repository extends, which still checks clean', () => {
94
+ expect(run(root, 'baseline', 'init', 'standard', '--name', '@acme/standard').status).toBe(0)
95
+ write(home, { '.claude/skills/deploy-runbook/SKILL.md': skill('deploy-runbook') })
96
+ const out = run(project, 'promote', 'skill', 'deploy-runbook', '--to', '../standard')
97
+ expect(out.status, out.stderr).toBe(0)
98
+ expect(existsSync(join(root, 'standard', 'skills', 'deploy-runbook', 'SKILL.md'))).toBe(true)
99
+ expect(out.stdout).toContain('opencastle baseline check')
100
+ expect(run(root, 'plugin', 'check', 'standard').status).toBe(0)
101
+ })
102
+
103
+ it('--dry-run writes nothing', () => {
104
+ write(home, { '.claude/skills/deploy-runbook/SKILL.md': skill('deploy-runbook') })
105
+ expect(run(project, 'promote', 'skill', 'deploy-runbook', '--dry-run').stdout).toContain('[dry-run] Would copy')
106
+ expect(existsSync(join(project, '.opencastle', 'skills', 'deploy-runbook'))).toBe(false)
107
+ })
108
+ })
109
+
110
+ describe('memory', () => {
111
+ const memoryDir = (): string => {
112
+ const saved = { HOME: process.env.HOME, CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR }
113
+ process.env.HOME = home
114
+ process.env.CLAUDE_CONFIG_DIR = config
115
+ try {
116
+ return claudeMemoryDir(project)
117
+ } finally {
118
+ process.env.HOME = saved.HOME
119
+ process.env.CLAUDE_CONFIG_DIR = saved.CLAUDE_CONFIG_DIR
120
+ }
121
+ }
122
+
123
+ it('finds this repository’s auto memory where Claude Code keeps it', () => {
124
+ expect(memoryDir()).toMatch(new RegExp(`${config.replace(/[/.]/g, '\\$&')}/projects/-.*-app/memory$`))
125
+ })
126
+
127
+ it('turns corrections and project notes into lessons, and leaves out the rest', () => {
128
+ write(memoryDir(), {
129
+ 'MEMORY.md': '- [Never commit to main](never-commit-to-main.md)\n',
130
+ 'never-commit-to-main.md': memory('never-commit-to-main', 'feedback', `Always branch.\n\n**Why:** ${home}/notes said so.`),
131
+ 'release-freeze.md': memory('release-freeze', 'project', 'No merges after Thursday until the 12th.'),
132
+ 'user-role.md': memory('user-role', 'user', 'A senior engineer who prefers terse answers.'),
133
+ 'leaked.md': memory('leaked', 'feedback', 'The key is AKIAIOSFODNN7EXAMPLE.'),
134
+ })
135
+ const out = run(project, 'promote', 'memory')
136
+ expect(out.status, out.stderr).toBe(0)
137
+ const files = readdirSync(join(project, '.opencastle', 'lessons'))
138
+ expect(files).toHaveLength(2)
139
+ const text = files.map((f) => readFileSync(join(project, '.opencastle', 'lessons', f), 'utf8')).join('\n')
140
+ expect(text).toContain('title: "Never commit to main"')
141
+ expect(text).toContain('**Why:** ~/notes said so.')
142
+ expect(text).not.toContain(home)
143
+ expect(text).not.toContain('originSessionId')
144
+ expect(text).toMatch(/source: "claude-code-memory:never-commit-to-main\.md#[0-9a-f]{12}"/)
145
+ expect(out.stdout).toContain('user-role.md: about you, not the project')
146
+ expect(out.stdout).toMatch(/leaked\.md: holds what looks like a AWS Access Key/)
147
+ expect(readFileSync(join(project, '.opencastle', 'LESSONS-LEARNED.md'), 'utf8')).toContain('**Release freeze**')
148
+
149
+ const again = run(project, 'promote', 'memory')
150
+ expect(again.stdout).toContain('Nothing new to promote.')
151
+ expect(again.stdout).toContain('never-commit-to-main.md: already a lesson')
152
+ expect(run(project, 'sync', '--check').status).toBe(0)
153
+ })
154
+
155
+ it('reads where autoMemoryDirectory points', () => {
156
+ const custom = join(home, 'my-memory')
157
+ write(project, { '.claude/settings.local.json': JSON.stringify({ autoMemoryDirectory: '~/my-memory' }) })
158
+ write(custom, { 'a.md': memory('quote-paths', 'feedback', 'Quote paths with spaces.') })
159
+ const out = run(project, 'promote', 'memory')
160
+ expect(out.status, out.stderr).toBe(0)
161
+ expect(out.stdout).toContain('from ~/my-memory')
162
+ })
163
+
164
+ it('says where it looked when there is none', () => {
165
+ const out = run(project, 'promote', 'memory')
166
+ expect(out.status).toBe(1)
167
+ expect(out.stderr).toMatch(/no memory at ~\/\.claude\/projects\/.*\/memory/)
168
+ })
169
+ })
170
+ })