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