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
@@ -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
+
package/src/cli/remove.ts CHANGED
@@ -7,10 +7,12 @@ import { removeGitignoreBlock, predictGitignoreStrip, LOCAL_DIRS } from './gitig
7
7
  import { confirm, select, closePrompts, c } from './prompt.js'
8
8
  import { stripManagedBlockFromFile, predictStripFile } from './managed-block.js'
9
9
  import { resolveManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
10
- import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip } from './mcp.js'
10
+ import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
11
11
  import { priorTeam } from './lock.js'
12
12
  import { IDE_ADAPTERS } from './adapters/index.js'
13
13
  import type { CliContext, IdeChoice } from './types.js'
14
+ import { whyLeftAlone } from './unreadable-report.js'
15
+ import { parseMcpConfigText } from './mcp-file.js'
14
16
 
15
17
  /**
16
18
  * Removal, with the destructive choice made explicit rather than encoded in the
@@ -104,7 +106,7 @@ async function previewCoOwned(
104
106
  let keepsSomething = true
105
107
  let tookAnything = false
106
108
  try {
107
- const parsed = JSON.parse(await readFile(abs, 'utf8')) as Record<string, unknown>
109
+ const parsed = parseMcpConfigText(await readFile(abs, 'utf8'), p)
108
110
  // Captured before the predicate runs — it edits `parsed` in place.
109
111
  const untouched = JSON.stringify(parsed)
110
112
  keepsSomething = willKeepSomethingAfterStrip(parsed, ideFor.get(p), ...priorTeam(projectRoot))
@@ -212,7 +214,14 @@ export default async function remove({ args }: CliContext): Promise<void> {
212
214
  (id): id is IdeChoice => Boolean(id) && id in IDE_ADAPTERS,
213
215
  )
214
216
  const mcpOwner = new Map(ides.map((ide) => [getMcpConfigRelPath(ide), ide]))
215
- const mcpPaths = new Set(mcpOwner.keys())
217
+ // A config an earlier release wrote where its assistant never looked is ours
218
+ // to take back too. It has no owner in `mcpOwner` on purpose: it is in the
219
+ // shape it was written in, so the preview reads it as any config.
220
+ const legacyMcp = ides.flatMap((ide) => {
221
+ const rel = LEGACY_MCP_CONFIGS[ide]
222
+ return rel && existsSync(resolve(projectRoot, rel)) ? [rel] : []
223
+ })
224
+ const mcpPaths = new Set([...mcpOwner.keys(), ...legacyMcp])
216
225
  // An install from before this field existed records nothing, and absence means
217
226
  // "unknown" — which is treated as "not ours to delete".
218
227
  const createdConfigs = new Set(manifest.createdConfigs ?? [])
@@ -379,6 +388,13 @@ export default async function remove({ args }: CliContext): Promise<void> {
379
388
  else if (outcome === 'unreadable') unreadable.push(getMcpConfigRelPath(ide))
380
389
  const mcpParent = dirname(resolve(projectRoot, getMcpConfigRelPath(ide)))
381
390
  if (mcpParent !== projectRoot) parents.add(mcpParent)
391
+ const legacyRel = LEGACY_MCP_CONFIGS[ide]
392
+ if (legacyRel) {
393
+ const legacy = await retireLegacyMcpConfig(projectRoot, ide, createdConfigs.has(legacyRel), ...priorTeam(projectRoot))
394
+ if (legacy === 'deleted') removed++
395
+ else if (legacy === 'stripped') stripped++
396
+ else if (legacy === 'unreadable') unreadable.push(legacyRel)
397
+ }
382
398
  }
383
399
 
384
400
  // The containers our own directories lived in. `.claude/agents/`, `skills/`
@@ -457,7 +473,7 @@ export default async function remove({ args }: CliContext): Promise<void> {
457
473
  const [name, why] = entry.split('\u0000')
458
474
  console.log(
459
475
  ` ${c.yellow('!')} Left ${name} alone — ` +
460
- (why === 'unreadable' ? 'it could not be read.' : 'it is not valid JSON.'),
476
+ whyLeftAlone(name, why),
461
477
  )
462
478
  }
463
479
  if (keptDir) {
@@ -0,0 +1,154 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+ import { parse as yamlParse } from 'yaml'
4
+
5
+ /**
6
+ * Finding a credential in text before it is written somewhere it is committed
7
+ * or logged.
8
+ *
9
+ * The convoy engine scans every event and artefact it writes with this; lessons
10
+ * are scanned before they are written, because a lesson is committed with the
11
+ * project. It lives outside the engine so the compiler's own commands can use
12
+ * it without depending on the experimental engine.
13
+ */
14
+
15
+ // ── Secret patterns ───────────────────────────────────────────────────────────
16
+
17
+ interface SecretPatternEntry {
18
+ name: string
19
+ pattern: RegExp
20
+ }
21
+
22
+ const SECRET_PATTERNS: SecretPatternEntry[] = [
23
+ { name: 'AWS Access Key', pattern: /AKIA[0-9A-Z]{16}/i },
24
+ {
25
+ name: 'AWS Secret Key',
26
+ // eslint-disable-next-line no-useless-escape
27
+ pattern: /(?:aws_secret_access_key|secret_key)\s*[=:]\s*[A-Za-z0-9\/+=]{40}/i,
28
+ },
29
+ {
30
+ name: 'Generic API Key',
31
+ pattern: /(?:api[_-]?key|apikey)\s*[=:]\s*['"]?[A-Za-z0-9_-]{20,}/i,
32
+ },
33
+ { name: 'Bearer Token', pattern: /[Bb]earer\s+[A-Za-z0-9\-._~+/]+=*/ },
34
+ { name: 'Private Key', pattern: /-----BEGIN (?:RSA|EC|OPENSSH) PRIVATE KEY-----/ },
35
+ {
36
+ name: 'Connection String',
37
+ // eslint-disable-next-line no-useless-escape
38
+ pattern: /(?:postgres|mysql|mongodb|redis):\/\/[^\s]+:[^\s]+@/,
39
+ },
40
+ { name: 'GitHub Token', pattern: /(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36,}/ },
41
+ {
42
+ name: 'Generic Password',
43
+ pattern: /(?:password|passwd|pwd)\s*[=:]\s*['"]?[^\s'"]{8,}/i,
44
+ },
45
+ { name: 'Slack Token', pattern: /xox[bprs]-[A-Za-z0-9-]{10,}/i },
46
+ {
47
+ name: 'Generic Secret',
48
+ pattern: /(?:secret|token|credential)\s*[=:]\s*['"]?[A-Za-z0-9_-]{16,}/i,
49
+ },
50
+ ]
51
+
52
+ // ── Public types ──────────────────────────────────────────────────────────────
53
+
54
+ export interface SecretScanResult {
55
+ clean: boolean
56
+ findings: Array<{ pattern: string; file: string; line: number; snippet: string }>
57
+ }
58
+
59
+ // ── Allowlist ─────────────────────────────────────────────────────────────────
60
+
61
+ interface AllowlistEntry {
62
+ pattern?: string
63
+ literal?: string
64
+ reason: string
65
+ paths?: string[]
66
+ }
67
+
68
+ let _allowlist: AllowlistEntry[] | null = null
69
+
70
+ /** The config path used for the allowlist. Override for testing. */
71
+ export let _allowlistConfigPath = join(process.cwd(), '.opencastle', 'secret-scan-config.yml')
72
+
73
+ /** Reset the allowlist cache (for testing). */
74
+ export function _resetAllowlistCache(): void {
75
+ _allowlist = null
76
+ }
77
+
78
+ /** Override the allowlist config path and reset cache (for testing). */
79
+ export function _setAllowlistConfigPath(path: string): void {
80
+ _allowlistConfigPath = path
81
+ _allowlist = null
82
+ }
83
+
84
+ function loadAllowlist(): AllowlistEntry[] {
85
+ if (_allowlist !== null) return _allowlist
86
+ try {
87
+ if (!existsSync(_allowlistConfigPath)) {
88
+ _allowlist = []
89
+ return _allowlist
90
+ }
91
+ const content = readFileSync(_allowlistConfigPath, 'utf-8')
92
+ const parsed = yamlParse(content) as Record<string, unknown> | null
93
+ if (!parsed || !Array.isArray(parsed['allowlist'])) {
94
+ _allowlist = []
95
+ return _allowlist
96
+ }
97
+ _allowlist = parsed['allowlist'] as AllowlistEntry[]
98
+ return _allowlist
99
+ } catch {
100
+ _allowlist = []
101
+ return _allowlist
102
+ }
103
+ }
104
+
105
+ function isSuppressed(
106
+ finding: { snippet: string },
107
+ filePath: string,
108
+ allowlist: AllowlistEntry[],
109
+ ): boolean {
110
+ for (const entry of allowlist) {
111
+ if (entry.paths && entry.paths.length > 0) {
112
+ if (!entry.paths.some((p) => filePath.includes(p))) continue
113
+ }
114
+ if (entry.literal) {
115
+ if (finding.snippet.includes(entry.literal)) return true
116
+ } else if (entry.pattern) {
117
+ try {
118
+ if (new RegExp(entry.pattern, 'i').test(finding.snippet)) return true
119
+ } catch {
120
+ // Invalid regex in allowlist — skip entry
121
+ }
122
+ }
123
+ }
124
+ return false
125
+ }
126
+
127
+ // ── scanForSecrets ────────────────────────────────────────────────────────────
128
+
129
+ /**
130
+ * Scan text content line-by-line for secrets using the default pattern set.
131
+ * Allowlist entries in `.opencastle/secret-scan-config.yml` suppress false positives.
132
+ */
133
+ export function scanForSecrets(content: string, filePath = ''): SecretScanResult {
134
+ const allowlist = loadAllowlist()
135
+ const lines = content.split('\n')
136
+ const findings: SecretScanResult['findings'] = []
137
+
138
+ for (let i = 0; i < lines.length; i++) {
139
+ const line = lines[i]
140
+ for (const { name, pattern } of SECRET_PATTERNS) {
141
+ if (pattern.test(line)) {
142
+ const snippet = line.length > 100 ? line.slice(0, 97) + '...' : line
143
+ const finding = { pattern: name, file: filePath, line: i + 1, snippet }
144
+ if (!isSuppressed(finding, filePath, allowlist)) {
145
+ findings.push(finding)
146
+ }
147
+ // Only report the first matching pattern per line
148
+ break
149
+ }
150
+ }
151
+ }
152
+
153
+ return { clean: findings.length === 0, findings }
154
+ }
@@ -213,10 +213,10 @@ describe('two targets that share a root file', () => {
213
213
  const text = readFileSync(join(projectRoot, 'AGENTS.md'), 'utf8')
214
214
  expect(text).toContain('shared by more than one assistant')
215
215
  expect(text).toContain('.opencode/skills/')
216
- expect(text).not.toContain('.codex/skills/')
216
+ expect(text).toContain('`.codex/`, `.agents/skills/`')
217
217
  // Both assistants still get their own files.
218
218
  expect(existsSync(join(projectRoot, '.opencode', 'skills'))).toBe(true)
219
- expect(existsSync(join(projectRoot, '.codex', 'skills'))).toBe(true)
219
+ expect(existsSync(join(projectRoot, '.agents', 'skills'))).toBe(true)
220
220
  })
221
221
  })
222
222
 
@@ -4,7 +4,9 @@ import { tmpdir } from 'node:os'
4
4
  import { readManifest } from './manifest.js'
5
5
  import { IDE_ADAPTERS } from './adapters/index.js'
6
6
  import { detectRepoInfo, mergeStackIntoRepoInfo } from './detect.js'
7
- import { getMcpConfigRelPath, expectedTeamEntries } from './mcp.js'
7
+ import { getMcpConfigRelPath, expectedTeamEntries, containerKeyFor } from './mcp.js'
8
+ import { parseMcpConfigText } from './mcp-file.js'
9
+ import { lessonsIndexDrift, LESSONS_INDEX } from './lessons.js'
8
10
  import { resolveStack, getIncludedMcpServers } from './stack-config.js'
9
11
  import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
10
12
  import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
@@ -551,7 +553,7 @@ async function compareProject(
551
553
  }
552
554
  let parsed: unknown
553
555
  try {
554
- parsed = JSON.parse(readFileSync(abs, 'utf8'))
556
+ parsed = parseMcpConfigText(readFileSync(abs, 'utf8'), rel)
555
557
  } catch (err) {
556
558
  drift.push({
557
559
  ide,
@@ -572,7 +574,7 @@ async function compareProject(
572
574
  // Leaving the second out let `doctor` say "sync removes it" while this
573
575
  // passed and `sync` short-circuited — a remedy that did nothing.
574
576
  const teamKeys = new Set(Object.keys(team.expected))
575
- const container = (parsed as Record<string, unknown> | null)?.[ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers']
577
+ const container = (parsed as Record<string, unknown> | null)?.[containerKeyFor(ide as IdeChoice)]
576
578
  const present = new Set(container && typeof container === 'object' ? Object.keys(container as object) : [])
577
579
  const pluginOutdated = audit.outdated.filter((k) => !teamKeys.has(k))
578
580
  const teamMissing = audit.outdated.filter((k) => teamKeys.has(k) && !present.has(k))
@@ -651,6 +653,14 @@ async function compareProject(
651
653
  }
652
654
  }
653
655
 
656
+ // The lessons index, compiled from `.opencastle/lessons/` by `sync`. Two
657
+ // branches that each add a lesson merge cleanly; the index they both touched
658
+ // is what this catches, and `sync` rebuilds it.
659
+ {
660
+ const why = lessonsIndexDrift(resolve(projectRoot, '.opencastle'))
661
+ if (why) drift.push({ ide: 'all', path: `.opencastle/${LESSONS_INDEX}`, kind: 'outdated', detail: why, fix: 'opencastle sync' })
662
+ }
663
+
654
664
  // A manifest that parses but names no target this release knows is not a
655
665
  // clean project — `sync` exits 1 on it. Reporting "0 generated files match
656
666
  // their sources across 0 targets" is an assertion that cannot fail, and it
@@ -219,7 +219,7 @@ describe.skipIf(!built)('a baseline package', () => {
219
219
  it('scaffolds one that passes its own check', () => {
220
220
  expect(run(dir, ['baseline', 'init', 'base', '--name', '@acme/base']).code).toBe(0)
221
221
  const pkg = JSON.parse(readFileSync(join(dir, 'base', 'package.json'), 'utf8'))
222
- expect(pkg.opencastle).toEqual({ baseline: 'layer' })
222
+ expect(pkg.opencastle).toEqual({ baseline: '.' })
223
223
  const check = run(dir, ['baseline', 'check', 'base', '--json'])
224
224
  expect(check.code).toBe(0)
225
225
  const report = JSON.parse(check.out)
@@ -248,6 +248,6 @@ describe.skipIf(!built)('a baseline package', () => {
248
248
  writeFileSync(path, JSON.stringify(pkg))
249
249
  const check = run(dir, ['baseline', 'check', 'base'])
250
250
  expect(check.code).toBe(1)
251
- expect(check.out).toContain('npm publish would ship a baseline with nothing in it')
251
+ expect(check.out).toContain('"files" does not include plugin.json, so npm publish would leave it out')
252
252
  })
253
253
  })