opencastle 1.1.1 → 1.3.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 (307) hide show
  1. package/README.md +26 -9
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/antigravity.d.ts +0 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/antigravity.js +2 -1
  6. package/dist/cli/adapters/antigravity.js.map +1 -1
  7. package/dist/cli/adapters/claude-code.d.ts +0 -1
  8. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  9. package/dist/cli/adapters/claude-code.js +0 -1
  10. package/dist/cli/adapters/claude-code.js.map +1 -1
  11. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  12. package/dist/cli/adapters/cursor.js +8 -1
  13. package/dist/cli/adapters/cursor.js.map +1 -1
  14. package/dist/cli/adapters/opencode.d.ts +12 -5
  15. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  16. package/dist/cli/adapters/opencode.js +17 -5
  17. package/dist/cli/adapters/opencode.js.map +1 -1
  18. package/dist/cli/adapters/rules-dir-base.d.ts +12 -1
  19. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  20. package/dist/cli/adapters/rules-dir-base.js +43 -57
  21. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  22. package/dist/cli/adapters/rules-dir-base.test.js +27 -18
  23. package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
  24. package/dist/cli/adapters/single-file-base.d.ts +11 -0
  25. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  26. package/dist/cli/adapters/single-file-base.js +44 -14
  27. package/dist/cli/adapters/single-file-base.js.map +1 -1
  28. package/dist/cli/adapters/vscode.d.ts +2 -1
  29. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  30. package/dist/cli/adapters/vscode.js +2 -1
  31. package/dist/cli/adapters/vscode.js.map +1 -1
  32. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  33. package/dist/cli/adapters/windsurf.js +11 -1
  34. package/dist/cli/adapters/windsurf.js.map +1 -1
  35. package/dist/cli/agent-plugin.d.ts +119 -0
  36. package/dist/cli/agent-plugin.d.ts.map +1 -0
  37. package/dist/cli/agent-plugin.js +449 -0
  38. package/dist/cli/agent-plugin.js.map +1 -0
  39. package/dist/cli/agent-plugin.test.d.ts +2 -0
  40. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  41. package/dist/cli/agent-plugin.test.js +227 -0
  42. package/dist/cli/agent-plugin.test.js.map +1 -0
  43. package/dist/cli/baseline.d.ts.map +1 -1
  44. package/dist/cli/baseline.js +114 -34
  45. package/dist/cli/baseline.js.map +1 -1
  46. package/dist/cli/ci.d.ts.map +1 -1
  47. package/dist/cli/ci.js +18 -4
  48. package/dist/cli/ci.js.map +1 -1
  49. package/dist/cli/codex-target.test.js +14 -1
  50. package/dist/cli/codex-target.test.js.map +1 -1
  51. package/dist/cli/convoy/gates.d.ts +2 -20
  52. package/dist/cli/convoy/gates.d.ts.map +1 -1
  53. package/dist/cli/convoy/gates.js +3 -111
  54. package/dist/cli/convoy/gates.js.map +1 -1
  55. package/dist/cli/copy.d.ts +0 -8
  56. package/dist/cli/copy.d.ts.map +1 -1
  57. package/dist/cli/copy.js +0 -21
  58. package/dist/cli/copy.js.map +1 -1
  59. package/dist/cli/dispatcher.test.js +2 -2
  60. package/dist/cli/dispatcher.test.js.map +1 -1
  61. package/dist/cli/docs-accuracy.test.js +2 -0
  62. package/dist/cli/docs-accuracy.test.js.map +1 -1
  63. package/dist/cli/doctor.d.ts.map +1 -1
  64. package/dist/cli/doctor.js +2 -0
  65. package/dist/cli/doctor.js.map +1 -1
  66. package/dist/cli/doctor.test.js +2 -2
  67. package/dist/cli/doctor.test.js.map +1 -1
  68. package/dist/cli/explain.d.ts +5 -0
  69. package/dist/cli/explain.d.ts.map +1 -1
  70. package/dist/cli/explain.js +38 -2
  71. package/dist/cli/explain.js.map +1 -1
  72. package/dist/cli/init.test.js +78 -42
  73. package/dist/cli/init.test.js.map +1 -1
  74. package/dist/cli/layers.d.ts +8 -0
  75. package/dist/cli/layers.d.ts.map +1 -1
  76. package/dist/cli/layers.js +130 -13
  77. package/dist/cli/layers.js.map +1 -1
  78. package/dist/cli/layers.test.js +2 -2
  79. package/dist/cli/layers.test.js.map +1 -1
  80. package/dist/cli/legacy-install.test.js +8 -1
  81. package/dist/cli/legacy-install.test.js.map +1 -1
  82. package/dist/cli/lesson-command.test.d.ts +2 -0
  83. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  84. package/dist/cli/lesson-command.test.js +100 -0
  85. package/dist/cli/lesson-command.test.js.map +1 -0
  86. package/dist/cli/lesson.d.ts +0 -9
  87. package/dist/cli/lesson.d.ts.map +1 -1
  88. package/dist/cli/lesson.js +212 -276
  89. package/dist/cli/lesson.js.map +1 -1
  90. package/dist/cli/lessons.d.ts +134 -0
  91. package/dist/cli/lessons.d.ts.map +1 -0
  92. package/dist/cli/lessons.js +493 -0
  93. package/dist/cli/lessons.js.map +1 -0
  94. package/dist/cli/lessons.test.d.ts +2 -0
  95. package/dist/cli/lessons.test.d.ts.map +1 -0
  96. package/dist/cli/lessons.test.js +214 -0
  97. package/dist/cli/lessons.test.js.map +1 -0
  98. package/dist/cli/managed-paths.d.ts.map +1 -1
  99. package/dist/cli/managed-paths.js +3 -1
  100. package/dist/cli/managed-paths.js.map +1 -1
  101. package/dist/cli/mcp-audit.d.ts.map +1 -1
  102. package/dist/cli/mcp-audit.js +2 -0
  103. package/dist/cli/mcp-audit.js.map +1 -1
  104. package/dist/cli/mcp-upgrade.test.js +24 -1
  105. package/dist/cli/mcp-upgrade.test.js.map +1 -1
  106. package/dist/cli/mcp.d.ts.map +1 -1
  107. package/dist/cli/mcp.js +22 -3
  108. package/dist/cli/mcp.js.map +1 -1
  109. package/dist/cli/pack-plugins.d.ts +8 -0
  110. package/dist/cli/pack-plugins.d.ts.map +1 -0
  111. package/dist/cli/pack-plugins.js +70 -0
  112. package/dist/cli/pack-plugins.js.map +1 -0
  113. package/dist/cli/plugin-command.test.d.ts +2 -0
  114. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  115. package/dist/cli/plugin-command.test.js +114 -0
  116. package/dist/cli/plugin-command.test.js.map +1 -0
  117. package/dist/cli/plugin.d.ts +30 -0
  118. package/dist/cli/plugin.d.ts.map +1 -0
  119. package/dist/cli/plugin.js +291 -0
  120. package/dist/cli/plugin.js.map +1 -0
  121. package/dist/cli/promote-command.test.d.ts +2 -0
  122. package/dist/cli/promote-command.test.d.ts.map +1 -0
  123. package/dist/cli/promote-command.test.js +151 -0
  124. package/dist/cli/promote-command.test.js.map +1 -0
  125. package/dist/cli/promote.d.ts +12 -0
  126. package/dist/cli/promote.d.ts.map +1 -0
  127. package/dist/cli/promote.js +364 -0
  128. package/dist/cli/promote.js.map +1 -0
  129. package/dist/cli/secret-scan.d.ts +21 -0
  130. package/dist/cli/secret-scan.d.ts.map +1 -0
  131. package/dist/cli/secret-scan.js +114 -0
  132. package/dist/cli/secret-scan.js.map +1 -0
  133. package/dist/cli/sync-check.d.ts.map +1 -1
  134. package/dist/cli/sync-check.js +9 -0
  135. package/dist/cli/sync-check.js.map +1 -1
  136. package/dist/cli/sync-check.test.js +5 -4
  137. package/dist/cli/sync-check.test.js.map +1 -1
  138. package/dist/cli/team-commands.test.js +14 -2
  139. package/dist/cli/team-commands.test.js.map +1 -1
  140. package/dist/cli/team-sources.test.js +10 -0
  141. package/dist/cli/team-sources.test.js.map +1 -1
  142. package/dist/cli/types.d.ts +1 -1
  143. package/dist/cli/types.d.ts.map +1 -1
  144. package/dist/cli/update.d.ts.map +1 -1
  145. package/dist/cli/update.js +18 -0
  146. package/dist/cli/update.js.map +1 -1
  147. package/dist/cli/windsurf-target.test.d.ts +2 -0
  148. package/dist/cli/windsurf-target.test.d.ts.map +1 -0
  149. package/dist/cli/windsurf-target.test.js +62 -0
  150. package/dist/cli/windsurf-target.test.js.map +1 -0
  151. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  152. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  153. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  154. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  155. package/dist/orchestrator/plugins/registry.test.d.ts +2 -0
  156. package/dist/orchestrator/plugins/registry.test.d.ts.map +1 -0
  157. package/dist/orchestrator/plugins/registry.test.js +37 -0
  158. package/dist/orchestrator/plugins/registry.test.js.map +1 -0
  159. package/package.json +2 -1
  160. package/src/cli/adapters/antigravity.ts +2 -1
  161. package/src/cli/adapters/claude-code.ts +0 -1
  162. package/src/cli/adapters/cursor.ts +8 -1
  163. package/src/cli/adapters/opencode.ts +18 -6
  164. package/src/cli/adapters/rules-dir-base.test.ts +28 -18
  165. package/src/cli/adapters/rules-dir-base.ts +51 -90
  166. package/src/cli/adapters/single-file-base.ts +53 -14
  167. package/src/cli/adapters/vscode.ts +2 -1
  168. package/src/cli/adapters/windsurf.ts +11 -1
  169. package/src/cli/agent-plugin.test.ts +267 -0
  170. package/src/cli/agent-plugin.ts +469 -0
  171. package/src/cli/baseline.ts +115 -32
  172. package/src/cli/ci.ts +19 -4
  173. package/src/cli/codex-target.test.ts +15 -1
  174. package/src/cli/convoy/gates.ts +9 -142
  175. package/src/cli/copy.ts +0 -25
  176. package/src/cli/dispatcher.test.ts +2 -2
  177. package/src/cli/docs-accuracy.test.ts +2 -0
  178. package/src/cli/doctor.test.ts +2 -2
  179. package/src/cli/doctor.ts +2 -0
  180. package/src/cli/explain.ts +36 -2
  181. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  182. package/src/cli/init.test.ts +82 -42
  183. package/src/cli/layers.test.ts +2 -2
  184. package/src/cli/layers.ts +144 -14
  185. package/src/cli/legacy-install.test.ts +11 -1
  186. package/src/cli/lesson-command.test.ts +117 -0
  187. package/src/cli/lesson.ts +215 -266
  188. package/src/cli/lessons.test.ts +254 -0
  189. package/src/cli/lessons.ts +540 -0
  190. package/src/cli/managed-paths.ts +3 -1
  191. package/src/cli/mcp-audit.ts +2 -0
  192. package/src/cli/mcp-upgrade.test.ts +26 -1
  193. package/src/cli/mcp.ts +22 -3
  194. package/src/cli/pack-plugins.ts +70 -0
  195. package/src/cli/plugin-command.test.ts +125 -0
  196. package/src/cli/plugin.ts +309 -0
  197. package/src/cli/promote-command.test.ts +170 -0
  198. package/src/cli/promote.ts +371 -0
  199. package/src/cli/secret-scan.ts +154 -0
  200. package/src/cli/sync-check.test.ts +5 -4
  201. package/src/cli/sync-check.ts +9 -0
  202. package/src/cli/team-commands.test.ts +18 -2
  203. package/src/cli/team-sources.test.ts +11 -0
  204. package/src/cli/types.ts +1 -1
  205. package/src/cli/update.ts +20 -0
  206. package/src/cli/windsurf-target.test.ts +70 -0
  207. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  208. package/src/orchestrator/agents/researcher.agent.md +1 -1
  209. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  210. package/src/orchestrator/customizations/README.md +2 -1
  211. package/src/orchestrator/customizations/logs/README.md +1 -1
  212. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  213. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  214. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  215. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  216. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  217. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  218. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  219. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  220. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  221. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  222. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  223. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  224. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  225. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  226. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  227. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  228. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  229. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  230. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  231. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  232. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  233. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  234. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  235. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  236. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  237. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  238. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  239. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  240. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  241. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  242. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  243. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  244. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  245. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  246. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  247. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  248. package/src/orchestrator/plugins/registry.test.ts +42 -0
  249. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  250. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  251. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  252. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  253. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  254. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  255. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  256. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  257. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  258. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  259. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  260. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  261. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  262. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  263. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  264. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  265. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  266. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  267. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  268. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  269. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  270. package/src/orchestrator/skill-config-links.test.ts +2 -1
  271. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  272. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  273. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  274. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  275. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  276. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  277. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  278. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  279. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  280. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  281. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  282. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  283. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  284. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  285. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  286. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  287. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  288. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  289. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  290. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  291. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  292. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  293. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  294. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  295. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  296. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  297. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  298. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  299. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  300. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  301. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  302. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  303. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  304. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  305. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  306. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  307. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
@@ -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
+ })
@@ -0,0 +1,371 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { execFileSync } from 'node:child_process'
3
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
4
+ import { homedir } from 'node:os'
5
+ import { basename, dirname, join, relative, resolve } from 'node:path'
6
+ import { parse as parseYaml } from 'yaml'
7
+ import { checkSkill } from './agent-plugin.js'
8
+ import { LESSONS_DIR, newLessonId, readLessons, renderLesson, syncLessons, today, type Lesson } from './lessons.js'
9
+ import { scanForSecrets } from './secret-scan.js'
10
+ import { getOrchestratorRoot } from './copy.js'
11
+ import { c } from './prompt.js'
12
+ import type { CliContext } from './types.js'
13
+
14
+ /**
15
+ * `opencastle promote`: what one person's assistant learned, made the team's.
16
+ *
17
+ * Knowledge starts personal. A developer writes a skill for their own
18
+ * assistant, or the assistant remembers a correction it was given — Claude
19
+ * Code's auto memory keeps those on one machine, in one person's home
20
+ * directory, and no teammate's agent ever sees them. Productboard's Spark
21
+ * draws the same line between personal and workspace skills, and makes the
22
+ * step between them an explicit promotion after the author has tried it.
23
+ *
24
+ * This is that step. A skill is checked against the Agent Skills spec and
25
+ * scanned for credentials, then copied into the team's sources — this
26
+ * repository's `.opencastle/`, or a baseline every repository extends — where
27
+ * the next sync compiles it into every assistant. A memory becomes a lesson
28
+ * file. Either way it lands as a change in the working tree, and the pull
29
+ * request that commits it is where the team says yes.
30
+ */
31
+
32
+ const HELP = `
33
+ opencastle promote <skill|memory> [name|path] [options]
34
+
35
+ Make what one person's assistant learned the team's: copy it into the
36
+ team's sources, where the next sync compiles it into every assistant.
37
+
38
+ skill <name|path> A skill you use yourself, found by name in your personal
39
+ skill directories (~/.claude/skills, ~/.agents/skills,
40
+ ~/.codex/skills, ~/.cursor/skills, ~/.copilot/skills) or
41
+ given as a path. It is checked against the Agent Skills
42
+ spec and for credentials, then copied to
43
+ .opencastle/skills/<name>/ — or with --to, into a
44
+ baseline or Agent Plugin every repository extends.
45
+ memory What Claude Code's auto memory learned in this
46
+ repository — each correction (feedback) and project note
47
+ — written as lessons in .opencastle/lessons/. Memories
48
+ about you, credentials, and ones already promoted are
49
+ left out; your home directory is written as ~.
50
+
51
+ Options:
52
+ --to <dir> skill: a baseline or Agent Plugin directory to put it in
53
+ --from <dir> memory: read memory files from this directory instead
54
+ --force skill: replace a team skill with the same name
55
+ --dry-run Say what would be written, and write nothing
56
+ --help, -h Show this help
57
+ `
58
+
59
+ function fail(message: string): never {
60
+ console.error(` ${c.red('✗')} ${message}`)
61
+ process.exit(1)
62
+ }
63
+
64
+ function flag(args: string[], name: string): string | undefined {
65
+ const at = args.indexOf(name)
66
+ if (at === -1) return undefined
67
+ const v = args[at + 1]
68
+ if (!v || v.startsWith('--')) fail(`${name} needs a value`)
69
+ return v
70
+ }
71
+
72
+ function home(): string {
73
+ return process.env.HOME || homedir()
74
+ }
75
+
76
+ function tilde(path: string): string {
77
+ const h = home()
78
+ return path === h ? '~' : path.startsWith(`${h}/`) ? `~${path.slice(h.length)}` : path
79
+ }
80
+
81
+ function projectRootFrom(cwd: string): string {
82
+ let dir = cwd
83
+ for (;;) {
84
+ if (existsSync(join(dir, '.opencastle'))) return dir
85
+ const parent = dirname(dir)
86
+ if (parent === dir) return cwd
87
+ dir = parent
88
+ }
89
+ }
90
+
91
+ /** Every file under a directory, relative to it. */
92
+ function filesIn(dir: string): string[] {
93
+ const out: string[] = []
94
+ const walk = (d: string, prefix: string): void => {
95
+ for (const e of readdirSync(d, { withFileTypes: true })) {
96
+ if (e.isDirectory()) walk(join(d, e.name), `${prefix}${e.name}/`)
97
+ else if (e.isFile()) out.push(`${prefix}${e.name}`)
98
+ }
99
+ }
100
+ walk(dir, '')
101
+ return out
102
+ }
103
+
104
+ // ── skill ─────────────────────────────────────────────────────
105
+
106
+ /** Where assistants keep a person's own skills. */
107
+ export function personalSkillDirs(): string[] {
108
+ const h = home()
109
+ return ['.claude/skills', '.agents/skills', '.codex/skills', '.cursor/skills', '.copilot/skills'].map((d) => join(h, d))
110
+ }
111
+
112
+ function findSkill(ref: string, cwd: string): string {
113
+ const asPath = resolve(cwd, ref.replace(/^~(?=\/|$)/, home()))
114
+ if (ref.includes('/') || ref.startsWith('.')) {
115
+ if (existsSync(join(asPath, 'SKILL.md'))) return asPath
116
+ fail(`${ref} is not a skill directory — it has no SKILL.md`)
117
+ }
118
+ const found = personalSkillDirs().map((d) => join(d, ref)).filter((d) => existsSync(join(d, 'SKILL.md')))
119
+ if (found.length === 0) {
120
+ fail(`no skill named ${ref} in ${personalSkillDirs().map(tilde).join(', ')} — give its path instead`)
121
+ }
122
+ if (found.length > 1) {
123
+ const differ = new Set(found.map((d) => createHash('sha256').update(readFileSync(join(d, 'SKILL.md'))).digest('hex'))).size > 1
124
+ if (differ) fail(`${ref} is in ${found.map(tilde).join(' and ')}, and they differ — give the path of the one to promote`)
125
+ }
126
+ return found[0]
127
+ }
128
+
129
+ /** The `skills/` directory of a baseline or Agent Plugin. */
130
+ function skillsDirOf(target: string): string {
131
+ const pkgFile = join(target, 'package.json')
132
+ if (existsSync(pkgFile)) {
133
+ try {
134
+ const baseline = (JSON.parse(readFileSync(pkgFile, 'utf8')) as { opencastle?: { baseline?: unknown } }).opencastle?.baseline
135
+ if (typeof baseline === 'string') return join(resolve(target, baseline), 'skills')
136
+ } catch {
137
+ // Not ours to judge here; the copy below names the directory it used.
138
+ }
139
+ }
140
+ if (existsSync(join(target, 'plugin.json')) || existsSync(join(target, 'config.json'))) return join(target, 'skills')
141
+ fail(`${target} is neither a baseline nor an Agent Plugin — it has no package.json declaring a baseline, no plugin.json and no config.json`)
142
+ }
143
+
144
+ function promoteSkill(pkgRoot: string, args: string[], dryRun: boolean): void {
145
+ const ref = args.find((a, i) => !a.startsWith('--') && !['--to', '--from'].includes(args[i - 1]))
146
+ if (!ref) fail('promote skill needs the skill — its name, or the path to its directory')
147
+ const cwd = process.cwd()
148
+ const source = findSkill(ref, cwd)
149
+ const name = basename(source)
150
+
151
+ const skill = checkSkill(source)
152
+ if (skill.errors.length > 0) {
153
+ for (const e of skill.errors) console.error(` ${c.red('✗')} ${e.replace(/^skills\//, `${tilde(dirname(source))}/`)}`)
154
+ fail('fix it where it is, then promote it — every assistant that follows the Agent Skills spec would skip it as it stands')
155
+ }
156
+ for (const w of skill.warnings) console.log(` ${c.yellow('!')} ${c.dim(w)}`)
157
+
158
+ for (const rel of filesIn(source)) {
159
+ let text: string
160
+ try {
161
+ text = readFileSync(join(source, rel), 'utf8')
162
+ } catch {
163
+ continue
164
+ }
165
+ const scan = scanForSecrets(text, rel)
166
+ if (!scan.clean) {
167
+ const f = scan.findings[0]
168
+ fail(`${name}/${rel} line ${f.line} holds what looks like a ${f.pattern} — the team's sources are committed, so take it out first`)
169
+ }
170
+ }
171
+
172
+ const to = flag(args, '--to')
173
+ const projectRoot = projectRootFrom(cwd)
174
+ const destSkills = to ? skillsDirOf(resolve(cwd, to)) : join(projectRoot, '.opencastle', 'skills')
175
+ if (!to && !existsSync(join(projectRoot, '.opencastle'))) fail('no .opencastle/ here — run opencastle init first, or promote it into a baseline with --to <dir>')
176
+ const dest = join(destSkills, name)
177
+ const shown = relative(cwd, dest) || '.'
178
+ if (existsSync(dest) && !args.includes('--force')) {
179
+ fail(`${shown} already exists — compare them, then pass --force to replace it`)
180
+ }
181
+ const core = existsSync(join(getOrchestratorRoot(pkgRoot), 'skills', name))
182
+
183
+ if (dryRun) {
184
+ console.log(` [dry-run] Would copy ${tilde(source)} to ${shown}/ (${filesIn(source).length} file(s))`)
185
+ return
186
+ }
187
+ mkdirSync(destSkills, { recursive: true })
188
+ cpSync(source, dest, { recursive: true, force: true })
189
+ console.log(`\n ${c.green('✓')} Promoted ${c.bold(name)} from ${tilde(source)} to ${shown}/`)
190
+ if (core) console.log(` ${c.yellow('!')} OpenCastle ships a skill of that name; this one replaces it for everyone it reaches`)
191
+ console.log(
192
+ to
193
+ ? ` ${c.dim('Next:')} ${c.cyan(`opencastle baseline check ${relative(cwd, resolve(cwd, to)) || '.'}`)}${c.dim(', then publish a new version.')}\n`
194
+ : ` ${c.dim('Next:')} ${c.cyan('opencastle sync')} ${c.dim('compiles it into every assistant; commit it, and the pull request is where the team agrees.')}\n`,
195
+ )
196
+ }
197
+
198
+ // ── memory ────────────────────────────────────────────────────
199
+
200
+ /** The directory Claude Code's settings point auto memory at, if any of them does. */
201
+ function configuredMemoryDir(projectRoot: string, configDir: string): string | null {
202
+ for (const file of [
203
+ join(projectRoot, '.claude', 'settings.local.json'),
204
+ join(projectRoot, '.claude', 'settings.json'),
205
+ join(configDir, 'settings.json'),
206
+ ]) {
207
+ try {
208
+ const value = (JSON.parse(readFileSync(file, 'utf8')) as { autoMemoryDirectory?: unknown }).autoMemoryDirectory
209
+ if (typeof value === 'string' && value) return value.replace(/^~(?=\/|$)/, home())
210
+ } catch {
211
+ // Absent or unreadable: the next one, or the default.
212
+ }
213
+ }
214
+ return null
215
+ }
216
+
217
+ /**
218
+ * Where Claude Code keeps this repository's auto memory:
219
+ * `<config>/projects/<repository path, every other character a hyphen>/memory/`.
220
+ * Every worktree of one repository shares it, so the path is the main
221
+ * checkout's, which git names as the common directory's parent.
222
+ */
223
+ export function claudeMemoryDir(projectRoot: string): string {
224
+ const configDir = process.env.CLAUDE_CONFIG_DIR || join(home(), '.claude')
225
+ const configured = configuredMemoryDir(projectRoot, configDir)
226
+ if (configured) return configured
227
+ let repo = projectRoot
228
+ try {
229
+ const common = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
230
+ cwd: projectRoot,
231
+ encoding: 'utf8',
232
+ stdio: ['ignore', 'pipe', 'ignore'],
233
+ }).trim()
234
+ repo = basename(common) === '.git' ? dirname(common) : projectRoot
235
+ } catch {
236
+ repo = projectRoot
237
+ }
238
+ const slug = process.env.CLAUDE_CODE_PROJECT_DIR_NAME || repo.replace(/[^A-Za-z0-9]/g, '-')
239
+ return join(configDir, 'projects', slug, 'memory')
240
+ }
241
+
242
+ interface Memory {
243
+ file: string
244
+ name: string
245
+ description?: string
246
+ type?: string
247
+ body: string
248
+ }
249
+
250
+ function readMemories(dir: string): Memory[] {
251
+ const out: Memory[] = []
252
+ for (const file of readdirSync(dir).sort()) {
253
+ if (!file.endsWith('.md') || file === 'MEMORY.md') continue
254
+ const abs = join(dir, file)
255
+ if (!statSync(abs).isFile()) continue
256
+ const text = readFileSync(abs, 'utf8').replace(/^\uFEFF/, '')
257
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
258
+ let meta: Record<string, unknown> = {}
259
+ try {
260
+ meta = m ? ((parseYaml(m[1]) ?? {}) as Record<string, unknown>) : {}
261
+ } catch {
262
+ meta = {}
263
+ }
264
+ const nested = meta.metadata && typeof meta.metadata === 'object' ? (meta.metadata as Record<string, unknown>) : {}
265
+ const type = typeof meta.type === 'string' ? meta.type : typeof nested.type === 'string' ? nested.type : undefined
266
+ out.push({
267
+ file,
268
+ name: typeof meta.name === 'string' ? meta.name : file.replace(/\.md$/, ''),
269
+ description: typeof meta.description === 'string' ? meta.description : undefined,
270
+ type,
271
+ body: (m ? m[2] : text).trim(),
272
+ })
273
+ }
274
+ return out
275
+ }
276
+
277
+ /** A title for a memory: its description, else its name read as words. */
278
+ function titleOf(memory: Memory): string {
279
+ const raw = memory.description ?? memory.name.replace(/[-_]+/g, ' ')
280
+ const one = raw.replace(/[\r\n]+/g, ' ').trim()
281
+ return one.charAt(0).toUpperCase() + one.slice(1)
282
+ }
283
+
284
+ function promoteMemory(args: string[], dryRun: boolean): void {
285
+ const projectRoot = projectRootFrom(process.cwd())
286
+ const customizations = join(projectRoot, '.opencastle')
287
+ if (!existsSync(customizations)) fail('no .opencastle/ here — run opencastle init first')
288
+ const from = flag(args, '--from')
289
+ const dir = from ? resolve(process.cwd(), from.replace(/^~(?=\/|$)/, home())) : claudeMemoryDir(projectRoot)
290
+ if (!existsSync(dir)) {
291
+ fail(`no memory at ${tilde(dir)} — Claude Code keeps it there once it has saved one for this repository; --from <dir> reads another`)
292
+ }
293
+
294
+ syncLessons(customizations)
295
+ const { lessons } = readLessons(customizations)
296
+ const promoted = new Set(lessons.map((l) => l.source).filter((s): s is string => Boolean(s)))
297
+ const taken = new Set(lessons.map((l) => l.id))
298
+ const written: string[] = []
299
+ const skipped: Array<[string, string]> = []
300
+ const h = home()
301
+
302
+ for (const memory of readMemories(dir)) {
303
+ if (memory.type && !['feedback', 'project'].includes(memory.type)) {
304
+ skipped.push([memory.file, memory.type === 'user' ? 'about you, not the project' : `a ${memory.type} memory`])
305
+ continue
306
+ }
307
+ if (!memory.body) {
308
+ skipped.push([memory.file, 'empty'])
309
+ continue
310
+ }
311
+ const digest = createHash('sha256').update(memory.body).digest('hex').slice(0, 12)
312
+ const source = `claude-code-memory:${memory.file}#${digest}`
313
+ if (promoted.has(source)) {
314
+ skipped.push([memory.file, 'already a lesson'])
315
+ continue
316
+ }
317
+ // A memory names paths on its author's machine; the team's copy says ~.
318
+ const body = memory.body.split(h).join('~')
319
+ const scan = scanForSecrets(body, memory.file)
320
+ if (!scan.clean) {
321
+ skipped.push([memory.file, `holds what looks like a ${scan.findings[0].pattern} (line ${scan.findings[0].line})`])
322
+ continue
323
+ }
324
+ const title = titleOf(memory)
325
+ const id = newLessonId(title, today(), taken)
326
+ taken.add(id)
327
+ const lesson: Omit<Lesson, 'file'> = {
328
+ id,
329
+ title,
330
+ category: 'general',
331
+ severity: 'medium',
332
+ added: today(),
333
+ citations: [],
334
+ status: 'active',
335
+ source,
336
+ body,
337
+ }
338
+ written.push(`${LESSONS_DIR}/${id}.md`)
339
+ if (!dryRun) {
340
+ mkdirSync(join(customizations, LESSONS_DIR), { recursive: true })
341
+ writeFileSync(join(customizations, LESSONS_DIR, `${id}.md`), renderLesson(lesson))
342
+ }
343
+ }
344
+ if (!dryRun && written.length > 0) syncLessons(customizations)
345
+
346
+ console.log(`\n 🏰 ${c.bold('Promote memory')} ${c.dim(`from ${tilde(dir)}`)}\n`)
347
+ if (written.length === 0) console.log(` ${c.dim('Nothing new to promote.')}`)
348
+ for (const w of written) console.log(` ${c.green(dryRun ? '+' : '✓')} ${dryRun ? 'Would write' : 'Wrote'} .opencastle/${w}`)
349
+ for (const [file, why] of skipped) console.log(` ${c.dim(`- ${file}: ${why}`)}`)
350
+ if (written.length > 0 && !dryRun) {
351
+ console.log(
352
+ `\n ${c.dim('Each is category general, severity medium: set them, add --cite where a lesson is about code,')}` +
353
+ `\n ${c.dim('and delete any that are yours alone. The pull request that commits them is where the team agrees.')}\n`,
354
+ )
355
+ } else {
356
+ console.log('')
357
+ }
358
+ }
359
+
360
+ export default async function promote({ pkgRoot, args }: CliContext): Promise<void> {
361
+ const [sub, ...rest] = args
362
+ if (!sub || args.includes('--help') || args.includes('-h') || !['skill', 'memory'].includes(sub)) {
363
+ console.log(HELP)
364
+ if (sub && !['skill', 'memory', '--help', '-h'].includes(sub)) process.exit(1)
365
+ return
366
+ }
367
+ const dryRun = rest.includes('--dry-run')
368
+ if (sub === 'skill') promoteSkill(pkgRoot, rest, dryRun)
369
+ else promoteMemory(rest, dryRun)
370
+ }
371
+