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
package/src/cli/layers.ts CHANGED
@@ -20,6 +20,7 @@ import { packageLaunch, isPinned } from './mcp-audit.js'
20
20
  import { disallowedBy, hostDisallowedBy, findInlineSecret, emptyPolicy, globMatch, hostOfUrl, hostAllowedBy, type EffectivePolicy } from './policy.js'
21
21
  import { LOCAL_DIRS } from './gitignore.js'
22
22
  import { satisfies, parseVersion, compareVersions } from './version-range.js'
23
+ import { EXTENSION_NAMESPACE, isAgentPlugin, readAgentPlugin, teamServerFor } from './agent-plugin.js'
23
24
  import {
24
25
  CONTENT_KINDS,
25
26
  TEAM_CONFIG_REL,
@@ -61,6 +62,14 @@ export interface Layer {
61
62
  configFile?: string
62
63
  /** A digest of the layer's content, so a baseline that changed without a version bump still shows. */
63
64
  integrity?: string
65
+ /**
66
+ * For a baseline that is an Agent Plugin: the `dev.opencastle/` directory
67
+ * holding everything but skills — instructions, agents, prompts, workflows
68
+ * and `config.json`. Skills stay in the plugin's own `skills/`.
69
+ */
70
+ extensionRoot?: string
71
+ /** Servers that came from a plugin's `mcp.json`, and the file to name for each. */
72
+ serverWhere?: Record<string, string>
64
73
  }
65
74
 
66
75
  export interface ContentItem {
@@ -259,7 +268,7 @@ function scanLayer(layer: Layer, projectRoot: string | null): { items: ContentIt
259
268
  })
260
269
  }
261
270
  for (const kind of CONTENT_KINDS) {
262
- const dir = join(layer.root, dirs[kind])
271
+ const dir = join(kind !== 'skills' && layer.extensionRoot ? layer.extensionRoot : layer.root, dirs[kind])
263
272
  for (const entry of listDir(dir, within, skipped)) {
264
273
  if (kind === 'skills') {
265
274
  if (!entry.isDir) continue
@@ -351,6 +360,18 @@ function findPackageDir(name: string, fromDir: string): string | null {
351
360
  }
352
361
  }
353
362
 
363
+ /** Where a package is found under `node_modules`, before any link is followed. */
364
+ function packageLink(name: string, fromDir: string): string | null {
365
+ let dir = fromDir
366
+ for (;;) {
367
+ const candidate = join(dir, 'node_modules', ...name.split('/'))
368
+ if (existsSync(join(candidate, 'package.json'))) return candidate
369
+ const parent = dirname(dir)
370
+ if (parent === dir) return null
371
+ dir = parent
372
+ }
373
+ }
374
+
354
375
  function readLayerConfig(root: string, where: string): { config: TeamConfig; issues: TeamIssue[] } {
355
376
  const file = join(root, LAYER_CONFIG_FILE)
356
377
  if (!existsSync(file)) return { config: {}, issues: [] }
@@ -396,9 +417,13 @@ function loadExtends(
396
417
  let id: string
397
418
  let version: string | undefined
398
419
  let configWhere: string
420
+ // Where the layer is as the project sees it — `node_modules/@acme/x`, not
421
+ // the store path a link resolves to — for paths written into its configs.
422
+ let seenAt: string
399
423
 
400
424
  if (spec.startsWith('./') || spec.startsWith('../')) {
401
425
  root = resolve(fromDir, spec)
426
+ seenAt = root
402
427
  if (!existsSync(root) || !statSync(root).isDirectory()) {
403
428
  fail(`extends "${spec}", which is not a directory (looked in ${display(ctx.projectRoot, root)})`)
404
429
  return
@@ -456,14 +481,19 @@ function loadExtends(
456
481
  return
457
482
  }
458
483
  const decl = pkg.opencastle as { baseline?: unknown } | undefined
459
- if (!decl || typeof decl !== 'object' || !('baseline' in decl) || typeof decl.baseline !== 'string') {
484
+ const declared = decl && typeof decl === 'object' && 'baseline' in decl && typeof decl.baseline === 'string'
485
+ // Any Agent Plugin published to npm can be extended as it is: its skills
486
+ // and portable servers are what a baseline's are.
487
+ if (!declared && !isAgentPlugin(pkgDir)) {
460
488
  fail(
461
- `extends "${spec}", which is not an OpenCastle baseline`,
462
- `a baseline declares itself in its package.json: "opencastle": { "baseline": "." } (opencastle baseline init creates one)`,
489
+ `extends "${spec}", which is neither an OpenCastle baseline nor an Agent Plugin`,
490
+ `a baseline declares itself in its package.json: "opencastle": { "baseline": "." } (opencastle baseline init creates one); an Agent Plugin has a plugin.json at its root`,
463
491
  )
464
492
  return
465
493
  }
466
- root = resolve(pkgDir, decl.baseline)
494
+ root = declared ? resolve(pkgDir, (decl as { baseline: string }).baseline) : pkgDir
495
+ const linked = packageLink(spec, fromDir)
496
+ seenAt = linked ? resolve(linked, relative(pkgDir, root)) : root
467
497
  if (relative(pkgDir, root).startsWith('..') || !existsSync(root)) {
468
498
  fail(`extends "${spec}", whose "opencastle.baseline" points outside the package or at nothing`)
469
499
  return
@@ -489,6 +519,16 @@ function loadExtends(
489
519
  if (ctx.seen.has(real)) return
490
520
  ctx.seen.add(real)
491
521
 
522
+ if (isAgentPlugin(root)) {
523
+ const plugin = loadPluginLayer(root, seenAt, id, declaredIn, ctx)
524
+ if (!plugin) return
525
+ for (const inner of plugin.config.extends ?? []) {
526
+ loadExtends(inner, plugin.extensionRoot, plugin.configFile, [...chain, real], ctx)
527
+ }
528
+ ctx.layers.push({ id, kind: 'baseline', root, version: version ?? plugin.version, integrity: layerIntegrity(root), ...plugin })
529
+ return
530
+ }
531
+
492
532
  const { config, issues } = readLayerConfig(root, configWhere)
493
533
  ctx.issues.push(...issues)
494
534
  for (const inner of config.extends ?? []) {
@@ -497,6 +537,71 @@ function loadExtends(
497
537
  ctx.layers.push({ id, kind: 'baseline', root, version, config, configFile: configWhere, integrity: layerIntegrity(root) })
498
538
  }
499
539
 
540
+ /**
541
+ * A baseline that is an Agent Plugin: its skills in `skills/`, its portable
542
+ * servers in `mcp.json`, and OpenCastle's own content and config in
543
+ * `dev.opencastle/`. Returns null, having said why, for one a conformant
544
+ * client would refuse.
545
+ *
546
+ * A server or skill a client would skip is reported, not fatal, as the
547
+ * standard has it: one bad component does not stop the rest from loading.
548
+ */
549
+ function loadPluginLayer(
550
+ root: string,
551
+ seenAt: string,
552
+ id: string,
553
+ declaredIn: string,
554
+ ctx: ExtendsContext,
555
+ ): { config: TeamConfig; configFile: string; extensionRoot: string; serverWhere: Record<string, string>; version?: string } | null {
556
+ const report = readAgentPlugin(root)
557
+ if (!report.manifest) {
558
+ ctx.issues.push({
559
+ level: 'error',
560
+ where: declaredIn,
561
+ message: `extends ${id}, which is not a valid Agent Plugin: ${report.errors[0] ?? 'its plugin.json cannot be read'}`,
562
+ fix: `run opencastle plugin check on it`,
563
+ })
564
+ return null
565
+ }
566
+ // `skills/x/SKILL.md: name … must match` — the file, then what is wrong with it.
567
+ for (const e of report.errors) {
568
+ const at = e.indexOf(': ')
569
+ ctx.issues.push({ level: 'warning', where: `${id}/${e.slice(0, at)}`, message: e.slice(at + 2) })
570
+ }
571
+ const extensionRoot = join(root, EXTENSION_NAMESPACE)
572
+ const configFile = `${id}/${EXTENSION_NAMESPACE}/${LAYER_CONFIG_FILE}`
573
+ const { config, issues } = readLayerConfig(extensionRoot, configFile)
574
+ ctx.issues.push(...issues)
575
+ const servers: Record<string, TeamMcpServer> = { ...(config.mcpServers ?? {}) }
576
+ const serverWhere: Record<string, string> = {}
577
+ const pluginPath = posix(relative(ctx.projectRoot, seenAt))
578
+ for (const [key, portable] of Object.entries(report.servers)) {
579
+ if (key in servers) {
580
+ ctx.issues.push({
581
+ level: 'error',
582
+ where: `${id}/mcp.json`,
583
+ message: `defines MCP server "${key}", which ${configFile} defines too`,
584
+ fix: 'keep one: mcp.json for a server every assistant can start as it is, config.json for one that needs ${NAME} variables',
585
+ })
586
+ continue
587
+ }
588
+ const { server, skipped } = teamServerFor(portable, pluginPath)
589
+ if (!server) {
590
+ ctx.issues.push({ level: 'warning', where: `${id}/mcp.json`, message: `MCP server "${key}" ${skipped}` })
591
+ continue
592
+ }
593
+ servers[key] = server
594
+ serverWhere[key] = `${id}/mcp.json`
595
+ }
596
+ return {
597
+ config: { ...config, ...(Object.keys(servers).length > 0 && { mcpServers: servers }) },
598
+ configFile,
599
+ extensionRoot,
600
+ serverWhere,
601
+ version: report.manifest.version,
602
+ }
603
+ }
604
+
500
605
  /** `${VAR}`, `${env:VAR}` and `{env:VAR}` all mean the same variable. */
501
606
  export function normaliseRefs(value: string): string {
502
607
  return value.replace(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g, '${$1}').replace(/(?<!\$)\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g, '${$1}')
@@ -563,31 +668,55 @@ export function resolveSources(opts: ResolveOptions): ResolvedSources {
563
668
  items.set(key(item), item)
564
669
  remember(key(item), item)
565
670
  }
566
- // Integration skills: one SKILL.md per included plugin.
671
+ // Integration skills: each integration is an Agent Plugin, and its skill sits
672
+ // where the standard puts one — `skills/<name>/SKILL.md`, named as its
673
+ // directory is. They used to be compiled under the integration's id
674
+ // (`skills/supabase/`) while their frontmatter said `supabase-database`, and
675
+ // an assistant that follows the Agent Skills spec skips a skill whose name
676
+ // does not match its directory.
567
677
  const pluginsRoot = getPluginsRoot(pkgRoot)
568
678
  const includedPlugins = stack ? getIncludedPluginIds(stack) : null
569
679
  for (const entry of listDir(pluginsRoot)) {
570
680
  if (!entry.isDir) continue
571
- const skill = join(pluginsRoot, entry.name, 'SKILL.md')
681
+ const name = PLUGINS[entry.name]?.skillName
682
+ if (!name) continue
683
+ const skill = join(pluginsRoot, entry.name, 'skills', name, 'SKILL.md')
572
684
  if (!existsSync(skill)) continue
573
685
  if (includedPlugins && !includedPlugins.has(entry.name)) {
574
- stackOut.add(`skills/${entry.name}`)
686
+ stackOut.add(`skills/${name}`)
575
687
  continue
576
688
  }
577
- const k = `skills/${entry.name}`
689
+ const k = `skills/${name}`
578
690
  const prev = items.get(k)
579
- const item: ContentItem = { kind: 'skills', name: entry.name, layer: 'opencastle', path: skill, plugin: entry.name, ...(prev && { overrides: prev.layer }) }
691
+ const item: ContentItem = { kind: 'skills', name, layer: 'opencastle', path: skill, plugin: entry.name, ...(prev && { overrides: prev.layer }) }
580
692
  items.set(k, item)
581
693
  remember(k, item)
582
694
  }
695
+ // `skills/supabase`, as a layer wrote it before integration skills took their
696
+ // own names, still means the integration's skill.
697
+ const integrationSkill = (ref: string): string | null => {
698
+ const m = /^skills\/(.+)$/.exec(ref)
699
+ const name = m ? PLUGINS[m[1]]?.skillName : undefined
700
+ return name && name !== m![1] ? `skills/${name}` : null
701
+ }
583
702
 
584
703
  const excluded: ResolvedSources['excluded'] = []
585
704
  for (const layer of layers) {
586
705
  if (layer.kind === 'core') continue
587
706
  const where = layer.configFile ?? layer.id
588
- for (const ref of layer.config.exclude ?? []) {
707
+ for (const written of layer.config.exclude ?? []) {
589
708
  // Servers are excluded where servers are merged, below.
590
- if (ref.startsWith('mcpServers/')) continue
709
+ if (written.startsWith('mcpServers/')) continue
710
+ const renamed = items.has(written) ? null : integrationSkill(written)
711
+ if (renamed) {
712
+ issues.push({
713
+ level: 'warning',
714
+ where,
715
+ message: `excludes ${written}; integration skills are named for what they teach now — this means ${renamed}`,
716
+ fix: `write "${renamed}"`,
717
+ })
718
+ }
719
+ const ref = renamed ?? written
591
720
  const prev = items.get(ref)
592
721
  if (prev) {
593
722
  items.delete(ref)
@@ -735,7 +864,8 @@ export function resolveSources(opts: ResolveOptions): ResolvedSources {
735
864
  excluded.push({ ref, by: layer.id, from: 'mcp' })
736
865
  }
737
866
  for (const [k, raw] of Object.entries(layer.config.mcpServers ?? {})) {
738
- const shape = checkServerShape(k, raw, where)
867
+ const serverWhere = layer.serverWhere?.[k] ?? where
868
+ const shape = checkServerShape(k, raw, serverWhere)
739
869
  if (shape.length > 0) {
740
870
  issues.push(...shape)
741
871
  continue
@@ -749,7 +879,7 @@ export function resolveSources(opts: ResolveOptions): ResolvedSources {
749
879
  headers: Object.fromEntries(Object.entries(raw.headers).map(([n, val]) => [n, normaliseRefs(val)])),
750
880
  }),
751
881
  }
752
- servers.set(k, { key: k, from: layer.id, server, where })
882
+ servers.set(k, { key: k, from: layer.id, server, where: serverWhere })
753
883
  excludedServers.delete(k)
754
884
  }
755
885
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, existsSync, rmSync } from 'node:fs'
13
13
  import { tmpdir } from 'node:os'
14
- import { join, resolve } from 'node:path'
14
+ import { basename, join, resolve } from 'node:path'
15
15
  import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
16
16
 
17
17
  vi.mock('./prompt.js', async () => {
@@ -265,6 +265,13 @@ describe('sync never edits what the user wrote in .opencastle/', () => {
265
265
  const init = (await import('./init.js')).default
266
266
  await init({ pkgRoot, args: ['--yes'] })
267
267
 
268
+ // A lesson an agent recorded is the team's writing too.
269
+ mkdirSync(join(dir, '.opencastle', 'lessons'), { recursive: true })
270
+ writeFileSync(
271
+ join(dir, '.opencastle', 'lessons', 'LES-001-quote-variables.md'),
272
+ '---\nid: "LES-001"\ntitle: "Quote variables"\ncategory: "terminal"\nseverity: "low"\nadded: "2026-01-01"\n---\n\n**Problem:** spaces.\n',
273
+ )
274
+
268
275
  // Sentinel every file, and remember the exact bytes.
269
276
  const before = new Map<string, string>()
270
277
  const walk = (d: string): string[] =>
@@ -273,6 +280,9 @@ describe('sync never edits what the user wrote in .opencastle/', () => {
273
280
  )
274
281
  for (const f of walk(join(dir, '.opencastle'))) {
275
282
  if (!f.endsWith('.md')) continue
283
+ // The lessons index is compiled from `lessons/` — it says so on its
284
+ // first line, and `sync` rewrites it, as it rewrites the lock.
285
+ if (basename(f) === 'LESSONS-LEARNED.md') continue
276
286
  const text = `${readFileSync(f, 'utf8')}\n<!-- SENTINEL -->\n`
277
287
  writeFileSync(f, text)
278
288
  before.set(f, text)
@@ -0,0 +1,117 @@
1
+ /**
2
+ * `opencastle lesson`, as agents call it.
3
+ *
4
+ * The command is hidden from help because people rarely type it — the
5
+ * generated instructions tell agents to. That made it the least exercised
6
+ * writer of a file every agent reads first: it had no test at all, and the
7
+ * skill describing it told agents to check their entry with `tail -1`, which
8
+ * showed the index row, not the entry.
9
+ */
10
+ import { execFileSync, spawnSync } from 'node:child_process'
11
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
12
+ import { tmpdir } from 'node:os'
13
+ import { join, resolve } from 'node:path'
14
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
15
+ import { checkLessons } from './lessons.js'
16
+
17
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
18
+ const cli = join(pkgRoot, 'bin', 'cli.mjs')
19
+ const built = existsSync(join(pkgRoot, 'dist', 'cli', 'lesson.js'))
20
+
21
+ describe.skipIf(!built)('opencastle lesson', () => {
22
+ let project: string
23
+ const sh = (...args: string[]): string =>
24
+ execFileSync('git', args, { cwd: project, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
25
+ const lesson = (...args: string[]) => spawnSync('node', [cli, 'lesson', ...args], { cwd: project, encoding: 'utf8' })
26
+ const files = (): string[] => readdirSync(join(project, '.opencastle', 'lessons')).sort()
27
+ const index = (): string => readFileSync(join(project, '.opencastle', 'LESSONS-LEARNED.md'), 'utf8')
28
+ const base = ['--title', 'Quote shell variables', '--category', 'terminal', '--severity', 'medium', '--problem', 'Paths with spaces break']
29
+
30
+ beforeEach(() => {
31
+ project = mkdtempSync(join(tmpdir(), 'oc-lesson-cmd-'))
32
+ sh('init', '-q')
33
+ sh('config', 'user.email', 't@example.com')
34
+ sh('config', 'user.name', 'T')
35
+ mkdirSync(join(project, '.opencastle'))
36
+ mkdirSync(join(project, 'scripts'))
37
+ writeFileSync(join(project, 'scripts', 'clean.sh'), 'rm -rf "$DIR/old"\n')
38
+ writeFileSync(
39
+ join(project, '.opencastle', 'LESSONS-LEARNED.md'),
40
+ readFileSync(join(import.meta.dirname, 'fixtures', 'lessons-template-1.0.md'), 'utf8'),
41
+ )
42
+ sh('add', '.')
43
+ sh('commit', '-qm', 'init')
44
+ })
45
+ afterEach(() => rmSync(project, { recursive: true, force: true }))
46
+
47
+ it('writes one file, named by date and title, and lists it in the index', () => {
48
+ const out = lesson(...base, '--cite', 'scripts/clean.sh:1')
49
+ expect(out.status).toBe(0)
50
+ const [file] = files()
51
+ expect(file).toMatch(/^\d{4}-\d{2}-\d{2}-quote-shell-variables\.md$/)
52
+ const text = readFileSync(join(project, '.opencastle', 'lessons', file), 'utf8')
53
+ expect(text).toContain('citations:\n - "scripts/clean.sh:1"')
54
+ expect(text).toMatch(/fingerprints:\n scripts\/clean\.sh: "[0-9a-f]{12}"/)
55
+ expect(index()).toContain('**Quote shell variables** — `medium`')
56
+ expect(out.stdout).toContain(file.replace(/\.md$/, ''))
57
+ })
58
+
59
+ it('names two lessons with one title apart, so branches never collide', () => {
60
+ lesson(...base)
61
+ lesson(...base)
62
+ expect(files()).toHaveLength(2)
63
+ expect(files().some((f) => /-quote-shell-variables-2\.md$/.test(f))).toBe(true)
64
+ })
65
+
66
+ it('refuses a citation that does not exist, and writes nothing', () => {
67
+ const out = lesson(...base, '--cite', 'scripts/missing.sh')
68
+ expect(out.status).toBe(1)
69
+ expect(out.stderr).toContain('scripts/missing.sh does not exist')
70
+ expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
71
+ })
72
+
73
+ it('refuses a lesson that would commit a credential', () => {
74
+ const out = lesson(...base, '--correct', 'use AKIAIOSFODNN7EXAMPLE as the key')
75
+ expect(out.status).toBe(1)
76
+ expect(out.stderr).toMatch(/looks like a AWS Access Key/)
77
+ expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
78
+ })
79
+
80
+ it('verify clears what doctor said about changed code', () => {
81
+ lesson(...base, '--cite', 'scripts/clean.sh')
82
+ writeFileSync(join(project, 'scripts', 'clean.sh'), 'rm -rf -- "$DIR/old"\n')
83
+ expect(checkLessons(project).warning).toBe(true)
84
+ const id = files()[0].replace(/\.md$/, '')
85
+ expect(lesson('verify', id).status).toBe(0)
86
+ expect(checkLessons(project).warning).toBeUndefined()
87
+ })
88
+
89
+ it('archive moves a lesson out of the list agents read, and keeps it on record', () => {
90
+ lesson(...base)
91
+ const id = files()[0].replace(/\.md$/, '')
92
+ expect(lesson('archive', id, '--into', 'scripts/clean.sh').status).toBe(0)
93
+ const [active, archived] = index().split('## Archived')
94
+ expect(active).not.toContain('Quote shell variables')
95
+ expect(archived).toContain('**Quote shell variables** → `scripts/clean.sh`')
96
+ })
97
+
98
+ it('moves an old single-file log into lesson files before adding to it', () => {
99
+ writeFileSync(
100
+ join(project, '.opencastle', 'LESSONS-LEARNED.md'),
101
+ '# Lessons Learned\n\n### LES-004: Never push to main\n\n| Field | Value |\n|---|---|\n| **Category** | `git` |\n| **Added** | 2026-03-02 |\n| **Severity** | `high` |\n\n**Problem:** It was pushed.\n',
102
+ )
103
+ const out = lesson(...base)
104
+ expect(out.status).toBe(0)
105
+ expect(out.stdout).toContain('Moved 1 lesson(s)')
106
+ expect(files()).toEqual(expect.arrayContaining(['LES-004-never-push-to-main.md']))
107
+ expect(index()).toContain('## git')
108
+ expect(existsSync(join(project, '.opencastle', 'LESSONS-LEARNED.md.opencastle-backup'))).toBe(true)
109
+ })
110
+
111
+ it('--dry-run prints the lesson and writes nothing', () => {
112
+ const out = lesson(...base, '--dry-run')
113
+ expect(out.status).toBe(0)
114
+ expect(out.stdout).toContain('title: "Quote shell variables"')
115
+ expect(existsSync(join(project, '.opencastle', 'lessons'))).toBe(false)
116
+ })
117
+ })