opencastle 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +22 -5
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  4. package/dist/cli/adapters/single-file-base.js +24 -2
  5. package/dist/cli/adapters/single-file-base.js.map +1 -1
  6. package/dist/cli/agent-plugin.d.ts +119 -0
  7. package/dist/cli/agent-plugin.d.ts.map +1 -0
  8. package/dist/cli/agent-plugin.js +449 -0
  9. package/dist/cli/agent-plugin.js.map +1 -0
  10. package/dist/cli/agent-plugin.test.d.ts +2 -0
  11. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  12. package/dist/cli/agent-plugin.test.js +227 -0
  13. package/dist/cli/agent-plugin.test.js.map +1 -0
  14. package/dist/cli/baseline.d.ts.map +1 -1
  15. package/dist/cli/baseline.js +99 -26
  16. package/dist/cli/baseline.js.map +1 -1
  17. package/dist/cli/convoy/gates.d.ts +2 -20
  18. package/dist/cli/convoy/gates.d.ts.map +1 -1
  19. package/dist/cli/convoy/gates.js +3 -111
  20. package/dist/cli/convoy/gates.js.map +1 -1
  21. package/dist/cli/copy.d.ts +0 -8
  22. package/dist/cli/copy.d.ts.map +1 -1
  23. package/dist/cli/copy.js +0 -21
  24. package/dist/cli/copy.js.map +1 -1
  25. package/dist/cli/dispatcher.test.js +2 -2
  26. package/dist/cli/dispatcher.test.js.map +1 -1
  27. package/dist/cli/docs-accuracy.test.js +2 -0
  28. package/dist/cli/docs-accuracy.test.js.map +1 -1
  29. package/dist/cli/doctor.d.ts.map +1 -1
  30. package/dist/cli/doctor.js +2 -0
  31. package/dist/cli/doctor.js.map +1 -1
  32. package/dist/cli/init.test.js +36 -24
  33. package/dist/cli/init.test.js.map +1 -1
  34. package/dist/cli/layers.d.ts +8 -0
  35. package/dist/cli/layers.d.ts.map +1 -1
  36. package/dist/cli/layers.js +130 -13
  37. package/dist/cli/layers.js.map +1 -1
  38. package/dist/cli/layers.test.js +2 -2
  39. package/dist/cli/layers.test.js.map +1 -1
  40. package/dist/cli/legacy-install.test.js +8 -1
  41. package/dist/cli/legacy-install.test.js.map +1 -1
  42. package/dist/cli/lesson-command.test.d.ts +2 -0
  43. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  44. package/dist/cli/lesson-command.test.js +100 -0
  45. package/dist/cli/lesson-command.test.js.map +1 -0
  46. package/dist/cli/lesson.d.ts +0 -9
  47. package/dist/cli/lesson.d.ts.map +1 -1
  48. package/dist/cli/lesson.js +212 -276
  49. package/dist/cli/lesson.js.map +1 -1
  50. package/dist/cli/lessons.d.ts +134 -0
  51. package/dist/cli/lessons.d.ts.map +1 -0
  52. package/dist/cli/lessons.js +493 -0
  53. package/dist/cli/lessons.js.map +1 -0
  54. package/dist/cli/lessons.test.d.ts +2 -0
  55. package/dist/cli/lessons.test.d.ts.map +1 -0
  56. package/dist/cli/lessons.test.js +214 -0
  57. package/dist/cli/lessons.test.js.map +1 -0
  58. package/dist/cli/pack-plugins.d.ts +8 -0
  59. package/dist/cli/pack-plugins.d.ts.map +1 -0
  60. package/dist/cli/pack-plugins.js +70 -0
  61. package/dist/cli/pack-plugins.js.map +1 -0
  62. package/dist/cli/plugin-command.test.d.ts +2 -0
  63. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  64. package/dist/cli/plugin-command.test.js +114 -0
  65. package/dist/cli/plugin-command.test.js.map +1 -0
  66. package/dist/cli/plugin.d.ts +30 -0
  67. package/dist/cli/plugin.d.ts.map +1 -0
  68. package/dist/cli/plugin.js +291 -0
  69. package/dist/cli/plugin.js.map +1 -0
  70. package/dist/cli/promote-command.test.d.ts +2 -0
  71. package/dist/cli/promote-command.test.d.ts.map +1 -0
  72. package/dist/cli/promote-command.test.js +151 -0
  73. package/dist/cli/promote-command.test.js.map +1 -0
  74. package/dist/cli/promote.d.ts +12 -0
  75. package/dist/cli/promote.d.ts.map +1 -0
  76. package/dist/cli/promote.js +364 -0
  77. package/dist/cli/promote.js.map +1 -0
  78. package/dist/cli/secret-scan.d.ts +21 -0
  79. package/dist/cli/secret-scan.d.ts.map +1 -0
  80. package/dist/cli/secret-scan.js +114 -0
  81. package/dist/cli/secret-scan.js.map +1 -0
  82. package/dist/cli/sync-check.d.ts.map +1 -1
  83. package/dist/cli/sync-check.js +9 -0
  84. package/dist/cli/sync-check.js.map +1 -1
  85. package/dist/cli/team-commands.test.js +2 -2
  86. package/dist/cli/team-commands.test.js.map +1 -1
  87. package/dist/cli/update.d.ts.map +1 -1
  88. package/dist/cli/update.js +18 -0
  89. package/dist/cli/update.js.map +1 -1
  90. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  91. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  92. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  93. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  94. package/package.json +2 -1
  95. package/src/cli/adapters/single-file-base.ts +23 -2
  96. package/src/cli/agent-plugin.test.ts +267 -0
  97. package/src/cli/agent-plugin.ts +469 -0
  98. package/src/cli/baseline.ts +99 -26
  99. package/src/cli/convoy/gates.ts +9 -142
  100. package/src/cli/copy.ts +0 -25
  101. package/src/cli/dispatcher.test.ts +2 -2
  102. package/src/cli/docs-accuracy.test.ts +2 -0
  103. package/src/cli/doctor.ts +2 -0
  104. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  105. package/src/cli/init.test.ts +37 -24
  106. package/src/cli/layers.test.ts +2 -2
  107. package/src/cli/layers.ts +144 -14
  108. package/src/cli/legacy-install.test.ts +11 -1
  109. package/src/cli/lesson-command.test.ts +117 -0
  110. package/src/cli/lesson.ts +215 -266
  111. package/src/cli/lessons.test.ts +254 -0
  112. package/src/cli/lessons.ts +540 -0
  113. package/src/cli/pack-plugins.ts +70 -0
  114. package/src/cli/plugin-command.test.ts +125 -0
  115. package/src/cli/plugin.ts +309 -0
  116. package/src/cli/promote-command.test.ts +170 -0
  117. package/src/cli/promote.ts +371 -0
  118. package/src/cli/secret-scan.ts +154 -0
  119. package/src/cli/sync-check.ts +9 -0
  120. package/src/cli/team-commands.test.ts +2 -2
  121. package/src/cli/update.ts +20 -0
  122. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  123. package/src/orchestrator/agents/researcher.agent.md +1 -1
  124. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  125. package/src/orchestrator/customizations/README.md +2 -1
  126. package/src/orchestrator/customizations/logs/README.md +1 -1
  127. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  128. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  129. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  130. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  131. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  132. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  133. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  134. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  135. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  136. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  137. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  138. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  139. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  140. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  141. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  142. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  143. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  144. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  145. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  146. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  147. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  148. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  149. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  150. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  151. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  152. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  153. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  154. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  155. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  156. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  157. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  158. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  159. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  160. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  161. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  162. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  163. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  164. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  165. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  166. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  167. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  168. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  169. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  170. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  171. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  172. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  173. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  174. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  175. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  176. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  177. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  178. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  179. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  180. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  181. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  182. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  183. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  184. package/src/orchestrator/skill-config-links.test.ts +2 -1
  185. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  186. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  187. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  188. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  189. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  190. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  191. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  192. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  193. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  194. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  195. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  196. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  197. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  198. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  199. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  200. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  201. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  202. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  203. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  204. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  205. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  206. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  207. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  208. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  209. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  210. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  211. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  212. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  213. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  214. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  215. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  216. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  217. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  218. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  219. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  220. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  221. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
@@ -0,0 +1,469 @@
1
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'
2
+ import { basename, join, relative, sep } from 'node:path'
3
+ import { parse as parseYaml } from 'yaml'
4
+ import type { TeamMcpServer } from './team-config.js'
5
+
6
+ /**
7
+ * Agent Plugins: the portable package format for agent extensions.
8
+ *
9
+ * Agent Plugins 1.0 (agent-plugins.org, under the Agentic AI Foundation) is a
10
+ * directory with a closed `plugin.json` manifest at its root, Agent Skills in
11
+ * `skills/<name>/SKILL.md`, and MCP servers in `mcp.json`. GitHub Copilot, VS
12
+ * Code, Cursor, Codex and Kiro load it as it is. Anything a client adds lives
13
+ * under a reverse-domain namespace — OpenCastle's is `dev.opencastle`, a
14
+ * directory beside `skills/` holding what the standard does not cover yet:
15
+ * instructions, agents, prompts, workflows and the team's policy.
16
+ *
17
+ * That makes an OpenCastle baseline and an Agent Plugin the same thing. A team
18
+ * publishes one package; assistants that read Agent Plugins install it
19
+ * natively, and OpenCastle compiles all of it — the parts the standard covers
20
+ * and the parts it does not — into every assistant, including the ones that do
21
+ * not read Agent Plugins at all.
22
+ *
23
+ * This module reads and checks one, against the published 1.0.0 text; the
24
+ * schemas are the spec's, written as code because a client must not fetch a
25
+ * schema while loading a plugin.
26
+ */
27
+
28
+ export const AGENT_PLUGINS_VERSION = '1.0.0'
29
+ /** Versions whose rules this reads. 1.1.0 is a working draft that changes nothing but the number. */
30
+ const KNOWN_VERSIONS = ['1.0.0', '1.1.0']
31
+ export const pluginSchemaUrl = (v = AGENT_PLUGINS_VERSION): string => `https://agent-plugins.org/schemas/${v}/plugin.schema.json`
32
+ export const mcpSchemaUrl = (v = AGENT_PLUGINS_VERSION): string => `https://agent-plugins.org/schemas/${v}/mcp.schema.json`
33
+
34
+ /** OpenCastle's extension namespace: the `extensions` key and the directory. */
35
+ export const EXTENSION_NAMESPACE = 'dev.opencastle'
36
+
37
+ export interface PluginManifest {
38
+ $schema: string
39
+ name: string
40
+ version?: string
41
+ description?: string
42
+ author?: { name?: string; email?: string; url?: string }
43
+ homepage?: string
44
+ repository?: string
45
+ license?: string
46
+ keywords?: string[]
47
+ extensions?: Record<string, Record<string, unknown>>
48
+ }
49
+
50
+ export type PortableServer =
51
+ | { type: 'stdio'; command: string; args?: string[]; env?: Record<string, string>; cwd?: string }
52
+ | { type: 'streamable-http' | 'sse'; url: string; headers?: Record<string, string> }
53
+
54
+ export interface PluginReport {
55
+ root: string
56
+ manifest?: PluginManifest
57
+ /** The Agent Plugins version it targets. */
58
+ version?: string
59
+ skills: string[]
60
+ servers: Record<string, PortableServer>
61
+ /** Problems that make it, or one of its components, not load in a conformant client. */
62
+ errors: string[]
63
+ /** What a client reports and ignores, and what will surprise someone. */
64
+ warnings: string[]
65
+ }
66
+
67
+ const MANIFEST_FIELDS = ['$schema', 'name', 'version', 'description', 'author', 'homepage', 'repository', 'license', 'keywords', 'extensions']
68
+ export const PLUGIN_NAME = /^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/
69
+
70
+ function isObject(v: unknown): v is Record<string, unknown> {
71
+ return Boolean(v) && typeof v === 'object' && !Array.isArray(v)
72
+ }
73
+
74
+ function isStringMap(v: unknown): v is Record<string, string> {
75
+ return isObject(v) && Object.values(v).every((x) => typeof x === 'string')
76
+ }
77
+
78
+ /** The version a `$schema` names, or null when it is not one this reads. */
79
+ function versionOf(schema: unknown, kind: 'plugin' | 'mcp'): string | null {
80
+ if (typeof schema !== 'string') return null
81
+ const m = new RegExp(`^https://agent-plugins\\.org/schemas/(\\d+\\.\\d+\\.\\d+)/${kind}\\.schema\\.json$`).exec(schema)
82
+ return m && KNOWN_VERSIONS.includes(m[1]) ? m[1] : null
83
+ }
84
+
85
+ function readJson(path: string): { value?: unknown; error?: string } {
86
+ try {
87
+ return { value: JSON.parse(readFileSync(path, 'utf8')) }
88
+ } catch (err) {
89
+ return { error: (err as Error).message }
90
+ }
91
+ }
92
+
93
+ /** Whether `abs`, links followed, is inside `root`. */
94
+ function inside(root: string, abs: string): boolean {
95
+ try {
96
+ const rel = relative(realpathSync(root), realpathSync(abs))
97
+ return rel === '' || (!rel.startsWith('..') && !rel.startsWith(sep) && !/^[A-Za-z]:/.test(rel))
98
+ } catch {
99
+ return false
100
+ }
101
+ }
102
+
103
+ /** True when `dir` holds a `plugin.json` that declares an Agent Plugins version this reads. */
104
+ export function isAgentPlugin(dir: string): boolean {
105
+ const file = join(dir, 'plugin.json')
106
+ if (!existsSync(file)) return false
107
+ const { value } = readJson(file)
108
+ return isObject(value) && versionOf(value.$schema, 'plugin') !== null
109
+ }
110
+
111
+ // ── Agent Skills ─────────────────────────────────────────────
112
+
113
+ const SKILL_FIELDS = new Set(['name', 'description', 'license', 'compatibility', 'metadata', 'allowed-tools'])
114
+ /** Fields assistants add that the spec does not define — said once, not as a fault. */
115
+ const CLIENT_SKILL_FIELDS = new Set([
116
+ 'argument-hint',
117
+ 'user-invocable',
118
+ 'disable-model-invocation',
119
+ 'model',
120
+ 'context',
121
+ 'agent',
122
+ 'hooks',
123
+ 'version',
124
+ ])
125
+ export const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
126
+
127
+ /**
128
+ * One skill directory against the Agent Skills specification
129
+ * (agentskills.io/specification). A client that follows it skips a skill
130
+ * whose name does not match its directory, so that is an error, not style.
131
+ */
132
+ export function checkSkill(dir: string): { name?: string; errors: string[]; warnings: string[] } {
133
+ const where = `skills/${basename(dir)}/SKILL.md`
134
+ const errors: string[] = []
135
+ const warnings: string[] = []
136
+ let text: string
137
+ try {
138
+ text = readFileSync(join(dir, 'SKILL.md'), 'utf8').replace(/^\uFEFF/, '')
139
+ } catch (err) {
140
+ return { errors: [`${where}: cannot be read — ${(err as Error).message}`], warnings }
141
+ }
142
+ const m = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/.exec(text)
143
+ if (!m) return { errors: [`${where}: has no YAML frontmatter, so it has no name or description`], warnings }
144
+ let meta: Record<string, unknown>
145
+ try {
146
+ meta = (parseYaml(m[1]) ?? {}) as Record<string, unknown>
147
+ } catch (err) {
148
+ return { errors: [`${where}: its frontmatter is not valid YAML — ${(err as Error).message}`], warnings }
149
+ }
150
+ const name = meta.name
151
+ if (typeof name !== 'string' || name.length === 0) {
152
+ errors.push(`${where}: has no name`)
153
+ } else {
154
+ if (name.length > 64 || !SKILL_NAME.test(name)) {
155
+ errors.push(`${where}: name "${name}" must be 1–64 lowercase letters, digits and single hyphens, not starting or ending with one`)
156
+ }
157
+ if (name !== basename(dir)) {
158
+ errors.push(`${where}: name "${name}" must match its directory, ${basename(dir)}/ — assistants that follow the spec skip it otherwise`)
159
+ }
160
+ }
161
+ const description = meta.description
162
+ if (typeof description !== 'string' || description.trim().length === 0) {
163
+ errors.push(`${where}: has no description, so no assistant can tell when to load it`)
164
+ } else if (description.length > 1024) {
165
+ errors.push(`${where}: description is ${description.length} characters; the limit is 1024`)
166
+ }
167
+ if (meta.compatibility !== undefined && (typeof meta.compatibility !== 'string' || meta.compatibility.length > 500)) {
168
+ errors.push(`${where}: compatibility must be a string of at most 500 characters`)
169
+ }
170
+ if (meta.metadata !== undefined && !isStringMap(meta.metadata)) {
171
+ errors.push(`${where}: metadata must map strings to strings`)
172
+ }
173
+ const unknown = Object.keys(meta).filter((k) => !SKILL_FIELDS.has(k) && !CLIENT_SKILL_FIELDS.has(k))
174
+ if (unknown.length > 0) {
175
+ warnings.push(`${where}: ${unknown.join(', ')} ${unknown.length === 1 ? 'is not an Agent Skills field' : 'are not Agent Skills fields'}; other assistants ignore ${unknown.length === 1 ? 'it' : 'them'}`)
176
+ }
177
+ const lines = m[2].split('\n').length
178
+ if (lines > 500) warnings.push(`${where}: ${lines} lines; the spec recommends under 500, with detail in files the skill links to`)
179
+ return { name: typeof name === 'string' ? name : undefined, errors, warnings }
180
+ }
181
+
182
+ // ── MCP servers ──────────────────────────────────────────────
183
+
184
+ const LOOPBACK = /^(localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i
185
+
186
+ /** Why one `mcp.json` server entry is invalid, or null. */
187
+ export function serverProblem(key: string, raw: unknown): string | null {
188
+ if (!isObject(raw)) return `server "${key}" is not an object`
189
+ const allowed = (fields: string[]): string | null => {
190
+ const extra = Object.keys(raw).filter((k) => !fields.includes(k))
191
+ return extra.length > 0 ? `server "${key}" has ${extra.join(', ')}, which a ${String(raw.type)} server cannot have` : null
192
+ }
193
+ if (raw.type === 'stdio') {
194
+ const bad = allowed(['type', 'command', 'args', 'env', 'cwd'])
195
+ if (bad) return bad
196
+ if (typeof raw.command !== 'string' || raw.command.length === 0) return `server "${key}" has no command`
197
+ if (/\s/.test(raw.command)) return `server "${key}": command must be one executable, with its arguments in "args" — not "${raw.command}"`
198
+ if (raw.command.includes('${')) return `server "${key}": command is not expanded, so it cannot use \${PLUGIN_ROOT}; write ./path/inside/the/plugin`
199
+ if ((raw.command.includes('/') || raw.command.includes('\\')) && !raw.command.startsWith('./')) {
200
+ return `server "${key}": a command inside the plugin must start with ./, and one on PATH must be a bare name`
201
+ }
202
+ if (raw.command.startsWith('./') && raw.command.split('/').includes('..')) return `server "${key}": command leaves the plugin`
203
+ if (raw.args !== undefined && !(Array.isArray(raw.args) && raw.args.every((a) => typeof a === 'string'))) {
204
+ return `server "${key}": args must be a list of strings`
205
+ }
206
+ if (raw.env !== undefined) {
207
+ if (!isStringMap(raw.env)) return `server "${key}": env must map names to strings`
208
+ const reserved = Object.keys(raw.env).find((n) => n === 'PLUGIN_ROOT' || n === 'PLUGIN_DATA')
209
+ if (reserved) return `server "${key}": env cannot set ${reserved}; the client provides it`
210
+ }
211
+ if (raw.cwd !== undefined) {
212
+ if (typeof raw.cwd !== 'string' || !/^(?:\.\/|\$\{PLUGIN_ROOT\}(?:\/|$)|\$\{PLUGIN_DATA\}(?:\/|$))/.test(raw.cwd)) {
213
+ return `server "${key}": cwd must start with ./, \${PLUGIN_ROOT} or \${PLUGIN_DATA}`
214
+ }
215
+ if (raw.cwd.split('/').includes('..')) return `server "${key}": cwd leaves the plugin`
216
+ }
217
+ return null
218
+ }
219
+ if (raw.type === 'streamable-http' || raw.type === 'sse') {
220
+ const bad = allowed(['type', 'url', 'headers'])
221
+ if (bad) return bad
222
+ if (typeof raw.url !== 'string') return `server "${key}" has no url`
223
+ let url: URL
224
+ try {
225
+ url = new URL(raw.url)
226
+ } catch {
227
+ return `server "${key}": url ${raw.url} is not an absolute URL`
228
+ }
229
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') return `server "${key}": url must be http or https`
230
+ if (url.username || url.password) return `server "${key}": url must not carry a user or password`
231
+ if (url.hash) return `server "${key}": url must not have a fragment`
232
+ if (url.protocol === 'http:' && !LOOPBACK.test(url.hostname)) return `server "${key}": only a loopback server may use http; ${url.hostname} needs https`
233
+ if (raw.headers !== undefined) {
234
+ if (!isStringMap(raw.headers)) return `server "${key}": headers must map names to strings`
235
+ const seen = new Set<string>()
236
+ for (const h of Object.keys(raw.headers)) {
237
+ if (seen.has(h.toLowerCase())) return `server "${key}": header ${h} is given twice`
238
+ seen.add(h.toLowerCase())
239
+ }
240
+ }
241
+ return null
242
+ }
243
+ return `server "${key}": type must be "stdio", "streamable-http" or "sse"`
244
+ }
245
+
246
+ // ── A whole plugin ───────────────────────────────────────────
247
+
248
+ /**
249
+ * Read and check a plugin directory the way a conformant client loads it,
250
+ * reporting what such a client would refuse, skip and ignore.
251
+ */
252
+ export function readAgentPlugin(root: string): PluginReport {
253
+ const report: PluginReport = { root, skills: [], servers: {}, errors: [], warnings: [] }
254
+ const manifestFile = join(root, 'plugin.json')
255
+ if (!existsSync(manifestFile)) {
256
+ report.errors.push('plugin.json: missing — every Agent Plugin has one at its root')
257
+ return report
258
+ }
259
+ if (!inside(root, manifestFile)) {
260
+ report.errors.push('plugin.json: resolves outside the plugin')
261
+ return report
262
+ }
263
+ const { value, error } = readJson(manifestFile)
264
+ if (error !== undefined || !isObject(value)) {
265
+ report.errors.push(`plugin.json: ${error ? `is not valid JSON — ${error}` : 'must be a JSON object'}`)
266
+ return report
267
+ }
268
+ const version = versionOf(value.$schema, 'plugin')
269
+ if (!version) {
270
+ report.errors.push(`plugin.json: "$schema" must be ${pluginSchemaUrl()}`)
271
+ return report
272
+ }
273
+ report.version = version
274
+ const fatal: string[] = []
275
+ if (typeof value.name !== 'string' || value.name.length < 1 || value.name.length > 64 || !PLUGIN_NAME.test(value.name)) {
276
+ fatal.push('"name" must be 1–64 lowercase letters, digits, hyphens and periods, starting and ending with a letter or digit, with no "--" or ".."')
277
+ }
278
+ for (const k of ['version', 'description', 'homepage', 'repository', 'license']) {
279
+ if (value[k] !== undefined && typeof value[k] !== 'string') fatal.push(`"${k}" must be a string`)
280
+ }
281
+ if (value.keywords !== undefined && !(Array.isArray(value.keywords) && value.keywords.every((k) => typeof k === 'string'))) {
282
+ fatal.push('"keywords" must be a list of strings')
283
+ }
284
+ if (value.author !== undefined) {
285
+ if (!isObject(value.author) || Object.keys(value.author).some((k) => !['name', 'email', 'url'].includes(k)) || !isStringMap(value.author)) {
286
+ fatal.push('"author" may hold only name, email and url, each a string')
287
+ }
288
+ }
289
+ if (fatal.length > 0) {
290
+ report.errors.push(...fatal.map((f) => `plugin.json: ${f}`))
291
+ return report
292
+ }
293
+ for (const k of Object.keys(value)) {
294
+ if (!MANIFEST_FIELDS.includes(k)) {
295
+ report.warnings.push(`plugin.json: "${k}" is not an Agent Plugins field; clients ignore it — client data belongs under "extensions"`)
296
+ }
297
+ }
298
+ if (value.extensions !== undefined && (!isObject(value.extensions) || !Object.values(value.extensions).every(isObject))) {
299
+ report.warnings.push('plugin.json: "extensions" must map namespaces to objects; clients ignore it as written')
300
+ }
301
+ if (typeof value.version === 'string' && !/^\d+\.\d+\.\d+(?:[-+].*)?$/.test(value.version)) {
302
+ report.warnings.push(`plugin.json: version "${value.version}" is not semantic versioning, which clients use to offer updates`)
303
+ }
304
+ report.manifest = value as unknown as PluginManifest
305
+
306
+ // Skills: each immediate child of skills/ holding a SKILL.md.
307
+ const skillsDir = join(root, 'skills')
308
+ if (existsSync(skillsDir)) {
309
+ if (!statSync(skillsDir).isDirectory() || !inside(root, skillsDir)) {
310
+ report.errors.push('skills: is not a directory inside the plugin, so no skill loads')
311
+ } else {
312
+ for (const entry of readdirSync(skillsDir).sort()) {
313
+ const dir = join(skillsDir, entry)
314
+ if (!existsSync(join(dir, 'SKILL.md'))) continue
315
+ if (!inside(root, join(dir, 'SKILL.md'))) {
316
+ report.errors.push(`skills/${entry}/SKILL.md: resolves outside the plugin, so it is skipped`)
317
+ continue
318
+ }
319
+ const skill = checkSkill(dir)
320
+ report.errors.push(...skill.errors)
321
+ report.warnings.push(...skill.warnings)
322
+ if (skill.errors.length === 0 && skill.name) report.skills.push(skill.name)
323
+ }
324
+ }
325
+ }
326
+
327
+ // MCP servers: mcp.json, all or nothing at the file, one by one below it.
328
+ const mcpFile = join(root, 'mcp.json')
329
+ if (existsSync(mcpFile)) {
330
+ const mcp = readJson(mcpFile)
331
+ const mcpVersion = isObject(mcp.value) ? versionOf(mcp.value.$schema, 'mcp') : null
332
+ if (mcp.error !== undefined || !isObject(mcp.value)) {
333
+ report.errors.push(`mcp.json: ${mcp.error ? `is not valid JSON — ${mcp.error}` : 'must be a JSON object'}, so no server loads`)
334
+ } else if (!mcpVersion) {
335
+ report.errors.push(`mcp.json: "$schema" must be ${mcpSchemaUrl(version)}, so no server loads`)
336
+ } else if (mcpVersion !== version) {
337
+ report.errors.push(`mcp.json: targets Agent Plugins ${mcpVersion} while plugin.json targets ${version}, so no server loads`)
338
+ } else if (!isObject(mcp.value.mcpServers) || Object.keys(mcp.value).some((k) => k !== '$schema' && k !== 'mcpServers')) {
339
+ report.errors.push('mcp.json: must hold "$schema" and an "mcpServers" object and nothing else, so no server loads')
340
+ } else {
341
+ for (const [key, raw] of Object.entries(mcp.value.mcpServers)) {
342
+ const problem = serverProblem(key, raw)
343
+ if (problem) {
344
+ report.errors.push(`mcp.json: ${problem}, so it is skipped`)
345
+ continue
346
+ }
347
+ report.servers[key] = raw as PortableServer
348
+ const secretish = Object.entries({ ...((raw as { env?: object }).env ?? {}), ...((raw as { headers?: object }).headers ?? {}) })
349
+ for (const [field, val] of secretish) {
350
+ if (typeof val === 'string' && /(?:^|\s)(?:Bearer\s+)?[A-Za-z0-9_\-.]{32,}$/.test(val) && !/^\$\{/.test(val)) {
351
+ report.warnings.push(`mcp.json: server "${key}" sets ${field} to what looks like a credential — mcp.json is published with the plugin`)
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ // Claude Code's manifest, when one is kept beside the portable one.
359
+ const claude = join(root, '.claude-plugin', 'plugin.json')
360
+ if (existsSync(claude)) {
361
+ const c = readJson(claude)
362
+ if (isObject(c.value) && c.value.name !== value.name) {
363
+ report.warnings.push(`.claude-plugin/plugin.json: names the plugin "${String(c.value.name)}" and plugin.json "${String(value.name)}" — Claude Code users and everyone else would install two different names`)
364
+ }
365
+ }
366
+ if (/^(claude|anthropic|anthropics|cc-plugin)(-|$)/.test(String(value.name))) {
367
+ report.warnings.push(`plugin.json: Claude Code reserves names like "${String(value.name)}" for Anthropic's own plugins`)
368
+ }
369
+ return report
370
+ }
371
+
372
+ // ── Claude Code, which reads its own manifest ────────────────
373
+
374
+ /** `${PLUGIN_ROOT}` and `${PLUGIN_DATA}`, in Claude Code's spelling. */
375
+ function claudeVars(s: string): string {
376
+ return s.split('${PLUGIN_ROOT}').join('${CLAUDE_PLUGIN_ROOT}').split('${PLUGIN_DATA}').join('${CLAUDE_PLUGIN_DATA}')
377
+ }
378
+
379
+ /**
380
+ * The `.claude-plugin/plugin.json` Claude Code reads, from the portable
381
+ * manifest. Claude Code does not read a root `plugin.json`; without this a
382
+ * Claude Code user installing the plugin gets it under whatever name the
383
+ * marketplace entry gives it, and no version.
384
+ */
385
+ export function claudeManifestFor(m: PluginManifest): Record<string, unknown> {
386
+ return {
387
+ name: m.name,
388
+ ...(m.version && { version: m.version }),
389
+ ...(m.description && { description: m.description }),
390
+ // Claude Code requires a name in an author.
391
+ ...(m.author?.name && { author: m.author }),
392
+ ...(m.homepage && { homepage: m.homepage }),
393
+ ...(m.repository && { repository: m.repository }),
394
+ ...(m.license && { license: m.license }),
395
+ ...(m.keywords && m.keywords.length > 0 && { keywords: m.keywords }),
396
+ }
397
+ }
398
+
399
+ /**
400
+ * The `.mcp.json` Claude Code reads from a plugin, from the portable
401
+ * `mcp.json`: its own type names, and `${CLAUDE_PLUGIN_ROOT}` where the
402
+ * portable format resolves `./` against the plugin.
403
+ */
404
+ export function claudeMcpFor(servers: Record<string, PortableServer>): { mcpServers: Record<string, unknown> } {
405
+ const out: Record<string, unknown> = {}
406
+ for (const [key, s] of Object.entries(servers)) {
407
+ if (s.type === 'stdio') {
408
+ out[key] = {
409
+ command: s.command.startsWith('./') ? `\${CLAUDE_PLUGIN_ROOT}/${s.command.slice(2)}` : s.command,
410
+ ...(s.args && { args: s.args.map(claudeVars) }),
411
+ ...(s.env && { env: Object.fromEntries(Object.entries(s.env).map(([k, v]) => [k, claudeVars(v)])) }),
412
+ }
413
+ } else {
414
+ out[key] = { type: s.type === 'sse' ? 'sse' : 'http', url: s.url, ...(s.headers && { headers: s.headers }) }
415
+ }
416
+ }
417
+ return { mcpServers: out }
418
+ }
419
+
420
+ // ── A plugin as a team's layer ───────────────────────────────
421
+
422
+ /**
423
+ * One portable server as a team server, for a plugin a project extends.
424
+ *
425
+ * `./` and `${PLUGIN_ROOT}` mean the plugin's directory; compiled into a
426
+ * project's config they become its path from the project root, where every
427
+ * assistant starts a project's servers. `${PLUGIN_DATA}` is a directory only an
428
+ * assistant that installs the plugin itself provides, and legacy SSE is a
429
+ * transport the generated configs do not carry — those servers are left out,
430
+ * with the reason.
431
+ */
432
+ export function teamServerFor(server: PortableServer, pluginPath: string): { server?: TeamMcpServer; skipped?: string } {
433
+ const at = pluginPath === '' || pluginPath === '.' ? '.' : pluginPath.startsWith('.') ? pluginPath : `./${pluginPath}`
434
+ if (server.type !== 'stdio') {
435
+ if (server.type === 'sse') return { skipped: 'uses the legacy SSE transport, which OpenCastle does not compile; install the plugin in an assistant that reads it' }
436
+ return { server: { type: 'http', url: server.url, ...(server.headers && { headers: server.headers }) } }
437
+ }
438
+ const all = [server.command, ...(server.args ?? []), ...Object.values(server.env ?? {}), server.cwd ?? '']
439
+ if (all.some((v) => v.includes('${PLUGIN_DATA}'))) {
440
+ return { skipped: 'uses ${PLUGIN_DATA}, a directory only an assistant that installs the plugin itself provides' }
441
+ }
442
+ if (server.cwd && !/^(?:\.\/?|\$\{PLUGIN_ROOT\}\/?)$/.test(server.cwd)) {
443
+ return { skipped: `runs in ${server.cwd}, and the assistants OpenCastle compiles for start servers in the project directory` }
444
+ }
445
+ const expand = (v: string): string => v.split('${PLUGIN_ROOT}').join(at)
446
+ return {
447
+ server: {
448
+ type: 'stdio',
449
+ command: server.command.startsWith('./') ? `${at}/${server.command.slice(2)}` : server.command,
450
+ ...(server.args && { args: server.args.map(expand) }),
451
+ ...(server.env && { env: Object.fromEntries(Object.entries(server.env).map(([k, v]) => [k, expand(v)])) }),
452
+ },
453
+ }
454
+ }
455
+
456
+ /** A plugin name from a package name: `@acme/ai-standard` → `acme.ai-standard`. */
457
+ export function pluginNameFrom(packageName: string): string {
458
+ const name = packageName
459
+ .toLowerCase()
460
+ .replace(/^@/, '')
461
+ .replace(/\//g, '.')
462
+ .replace(/[^a-z0-9.-]+/g, '-')
463
+ .replace(/-{2,}/g, '-')
464
+ .replace(/\.{2,}/g, '.')
465
+ .replace(/^[.-]+|[.-]+$/g, '')
466
+ .slice(0, 64)
467
+ .replace(/[.-]+$/, '')
468
+ return name || 'plugin'
469
+ }