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.
- package/README.md +22 -5
- package/bin/cli.mjs +6 -0
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +24 -2
- 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/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 +2 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/init.test.js +36 -24
- 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/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/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 +9 -0
- package/dist/cli/sync-check.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/update.d.ts.map +1 -1
- package/dist/cli/update.js +18 -0
- 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 +2 -1
- package/src/cli/adapters/single-file-base.ts +23 -2
- 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/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 +2 -0
- package/src/cli/fixtures/lessons-template-1.0.md +70 -0
- package/src/cli/init.test.ts +37 -24
- 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/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/secret-scan.ts +154 -0
- package/src/cli/sync-check.ts +9 -0
- package/src/cli/team-commands.test.ts +2 -2
- package/src/cli/update.ts +20 -0
- 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,371 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { homedir } from 'node:os'
|
|
5
|
+
import { basename, dirname, join, relative, resolve } from 'node:path'
|
|
6
|
+
import { parse as parseYaml } from 'yaml'
|
|
7
|
+
import { checkSkill } from './agent-plugin.js'
|
|
8
|
+
import { LESSONS_DIR, newLessonId, readLessons, renderLesson, syncLessons, today, type Lesson } from './lessons.js'
|
|
9
|
+
import { scanForSecrets } from './secret-scan.js'
|
|
10
|
+
import { getOrchestratorRoot } from './copy.js'
|
|
11
|
+
import { c } from './prompt.js'
|
|
12
|
+
import type { CliContext } from './types.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `opencastle promote`: what one person's assistant learned, made the team's.
|
|
16
|
+
*
|
|
17
|
+
* Knowledge starts personal. A developer writes a skill for their own
|
|
18
|
+
* assistant, or the assistant remembers a correction it was given — Claude
|
|
19
|
+
* Code's auto memory keeps those on one machine, in one person's home
|
|
20
|
+
* directory, and no teammate's agent ever sees them. Productboard's Spark
|
|
21
|
+
* draws the same line between personal and workspace skills, and makes the
|
|
22
|
+
* step between them an explicit promotion after the author has tried it.
|
|
23
|
+
*
|
|
24
|
+
* This is that step. A skill is checked against the Agent Skills spec and
|
|
25
|
+
* scanned for credentials, then copied into the team's sources — this
|
|
26
|
+
* repository's `.opencastle/`, or a baseline every repository extends — where
|
|
27
|
+
* the next sync compiles it into every assistant. A memory becomes a lesson
|
|
28
|
+
* file. Either way it lands as a change in the working tree, and the pull
|
|
29
|
+
* request that commits it is where the team says yes.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const HELP = `
|
|
33
|
+
opencastle promote <skill|memory> [name|path] [options]
|
|
34
|
+
|
|
35
|
+
Make what one person's assistant learned the team's: copy it into the
|
|
36
|
+
team's sources, where the next sync compiles it into every assistant.
|
|
37
|
+
|
|
38
|
+
skill <name|path> A skill you use yourself, found by name in your personal
|
|
39
|
+
skill directories (~/.claude/skills, ~/.agents/skills,
|
|
40
|
+
~/.codex/skills, ~/.cursor/skills, ~/.copilot/skills) or
|
|
41
|
+
given as a path. It is checked against the Agent Skills
|
|
42
|
+
spec and for credentials, then copied to
|
|
43
|
+
.opencastle/skills/<name>/ — or with --to, into a
|
|
44
|
+
baseline or Agent Plugin every repository extends.
|
|
45
|
+
memory What Claude Code's auto memory learned in this
|
|
46
|
+
repository — each correction (feedback) and project note
|
|
47
|
+
— written as lessons in .opencastle/lessons/. Memories
|
|
48
|
+
about you, credentials, and ones already promoted are
|
|
49
|
+
left out; your home directory is written as ~.
|
|
50
|
+
|
|
51
|
+
Options:
|
|
52
|
+
--to <dir> skill: a baseline or Agent Plugin directory to put it in
|
|
53
|
+
--from <dir> memory: read memory files from this directory instead
|
|
54
|
+
--force skill: replace a team skill with the same name
|
|
55
|
+
--dry-run Say what would be written, and write nothing
|
|
56
|
+
--help, -h Show this help
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
function fail(message: string): never {
|
|
60
|
+
console.error(` ${c.red('✗')} ${message}`)
|
|
61
|
+
process.exit(1)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function flag(args: string[], name: string): string | undefined {
|
|
65
|
+
const at = args.indexOf(name)
|
|
66
|
+
if (at === -1) return undefined
|
|
67
|
+
const v = args[at + 1]
|
|
68
|
+
if (!v || v.startsWith('--')) fail(`${name} needs a value`)
|
|
69
|
+
return v
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function home(): string {
|
|
73
|
+
return process.env.HOME || homedir()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function tilde(path: string): string {
|
|
77
|
+
const h = home()
|
|
78
|
+
return path === h ? '~' : path.startsWith(`${h}/`) ? `~${path.slice(h.length)}` : path
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function projectRootFrom(cwd: string): string {
|
|
82
|
+
let dir = cwd
|
|
83
|
+
for (;;) {
|
|
84
|
+
if (existsSync(join(dir, '.opencastle'))) return dir
|
|
85
|
+
const parent = dirname(dir)
|
|
86
|
+
if (parent === dir) return cwd
|
|
87
|
+
dir = parent
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Every file under a directory, relative to it. */
|
|
92
|
+
function filesIn(dir: string): string[] {
|
|
93
|
+
const out: string[] = []
|
|
94
|
+
const walk = (d: string, prefix: string): void => {
|
|
95
|
+
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
96
|
+
if (e.isDirectory()) walk(join(d, e.name), `${prefix}${e.name}/`)
|
|
97
|
+
else if (e.isFile()) out.push(`${prefix}${e.name}`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
walk(dir, '')
|
|
101
|
+
return out
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── skill ─────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/** Where assistants keep a person's own skills. */
|
|
107
|
+
export function personalSkillDirs(): string[] {
|
|
108
|
+
const h = home()
|
|
109
|
+
return ['.claude/skills', '.agents/skills', '.codex/skills', '.cursor/skills', '.copilot/skills'].map((d) => join(h, d))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function findSkill(ref: string, cwd: string): string {
|
|
113
|
+
const asPath = resolve(cwd, ref.replace(/^~(?=\/|$)/, home()))
|
|
114
|
+
if (ref.includes('/') || ref.startsWith('.')) {
|
|
115
|
+
if (existsSync(join(asPath, 'SKILL.md'))) return asPath
|
|
116
|
+
fail(`${ref} is not a skill directory — it has no SKILL.md`)
|
|
117
|
+
}
|
|
118
|
+
const found = personalSkillDirs().map((d) => join(d, ref)).filter((d) => existsSync(join(d, 'SKILL.md')))
|
|
119
|
+
if (found.length === 0) {
|
|
120
|
+
fail(`no skill named ${ref} in ${personalSkillDirs().map(tilde).join(', ')} — give its path instead`)
|
|
121
|
+
}
|
|
122
|
+
if (found.length > 1) {
|
|
123
|
+
const differ = new Set(found.map((d) => createHash('sha256').update(readFileSync(join(d, 'SKILL.md'))).digest('hex'))).size > 1
|
|
124
|
+
if (differ) fail(`${ref} is in ${found.map(tilde).join(' and ')}, and they differ — give the path of the one to promote`)
|
|
125
|
+
}
|
|
126
|
+
return found[0]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The `skills/` directory of a baseline or Agent Plugin. */
|
|
130
|
+
function skillsDirOf(target: string): string {
|
|
131
|
+
const pkgFile = join(target, 'package.json')
|
|
132
|
+
if (existsSync(pkgFile)) {
|
|
133
|
+
try {
|
|
134
|
+
const baseline = (JSON.parse(readFileSync(pkgFile, 'utf8')) as { opencastle?: { baseline?: unknown } }).opencastle?.baseline
|
|
135
|
+
if (typeof baseline === 'string') return join(resolve(target, baseline), 'skills')
|
|
136
|
+
} catch {
|
|
137
|
+
// Not ours to judge here; the copy below names the directory it used.
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (existsSync(join(target, 'plugin.json')) || existsSync(join(target, 'config.json'))) return join(target, 'skills')
|
|
141
|
+
fail(`${target} is neither a baseline nor an Agent Plugin — it has no package.json declaring a baseline, no plugin.json and no config.json`)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function promoteSkill(pkgRoot: string, args: string[], dryRun: boolean): void {
|
|
145
|
+
const ref = args.find((a, i) => !a.startsWith('--') && !['--to', '--from'].includes(args[i - 1]))
|
|
146
|
+
if (!ref) fail('promote skill needs the skill — its name, or the path to its directory')
|
|
147
|
+
const cwd = process.cwd()
|
|
148
|
+
const source = findSkill(ref, cwd)
|
|
149
|
+
const name = basename(source)
|
|
150
|
+
|
|
151
|
+
const skill = checkSkill(source)
|
|
152
|
+
if (skill.errors.length > 0) {
|
|
153
|
+
for (const e of skill.errors) console.error(` ${c.red('✗')} ${e.replace(/^skills\//, `${tilde(dirname(source))}/`)}`)
|
|
154
|
+
fail('fix it where it is, then promote it — every assistant that follows the Agent Skills spec would skip it as it stands')
|
|
155
|
+
}
|
|
156
|
+
for (const w of skill.warnings) console.log(` ${c.yellow('!')} ${c.dim(w)}`)
|
|
157
|
+
|
|
158
|
+
for (const rel of filesIn(source)) {
|
|
159
|
+
let text: string
|
|
160
|
+
try {
|
|
161
|
+
text = readFileSync(join(source, rel), 'utf8')
|
|
162
|
+
} catch {
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
const scan = scanForSecrets(text, rel)
|
|
166
|
+
if (!scan.clean) {
|
|
167
|
+
const f = scan.findings[0]
|
|
168
|
+
fail(`${name}/${rel} line ${f.line} holds what looks like a ${f.pattern} — the team's sources are committed, so take it out first`)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const to = flag(args, '--to')
|
|
173
|
+
const projectRoot = projectRootFrom(cwd)
|
|
174
|
+
const destSkills = to ? skillsDirOf(resolve(cwd, to)) : join(projectRoot, '.opencastle', 'skills')
|
|
175
|
+
if (!to && !existsSync(join(projectRoot, '.opencastle'))) fail('no .opencastle/ here — run opencastle init first, or promote it into a baseline with --to <dir>')
|
|
176
|
+
const dest = join(destSkills, name)
|
|
177
|
+
const shown = relative(cwd, dest) || '.'
|
|
178
|
+
if (existsSync(dest) && !args.includes('--force')) {
|
|
179
|
+
fail(`${shown} already exists — compare them, then pass --force to replace it`)
|
|
180
|
+
}
|
|
181
|
+
const core = existsSync(join(getOrchestratorRoot(pkgRoot), 'skills', name))
|
|
182
|
+
|
|
183
|
+
if (dryRun) {
|
|
184
|
+
console.log(` [dry-run] Would copy ${tilde(source)} to ${shown}/ (${filesIn(source).length} file(s))`)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
mkdirSync(destSkills, { recursive: true })
|
|
188
|
+
cpSync(source, dest, { recursive: true, force: true })
|
|
189
|
+
console.log(`\n ${c.green('✓')} Promoted ${c.bold(name)} from ${tilde(source)} to ${shown}/`)
|
|
190
|
+
if (core) console.log(` ${c.yellow('!')} OpenCastle ships a skill of that name; this one replaces it for everyone it reaches`)
|
|
191
|
+
console.log(
|
|
192
|
+
to
|
|
193
|
+
? ` ${c.dim('Next:')} ${c.cyan(`opencastle baseline check ${relative(cwd, resolve(cwd, to)) || '.'}`)}${c.dim(', then publish a new version.')}\n`
|
|
194
|
+
: ` ${c.dim('Next:')} ${c.cyan('opencastle sync')} ${c.dim('compiles it into every assistant; commit it, and the pull request is where the team agrees.')}\n`,
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ── memory ────────────────────────────────────────────────────
|
|
199
|
+
|
|
200
|
+
/** The directory Claude Code's settings point auto memory at, if any of them does. */
|
|
201
|
+
function configuredMemoryDir(projectRoot: string, configDir: string): string | null {
|
|
202
|
+
for (const file of [
|
|
203
|
+
join(projectRoot, '.claude', 'settings.local.json'),
|
|
204
|
+
join(projectRoot, '.claude', 'settings.json'),
|
|
205
|
+
join(configDir, 'settings.json'),
|
|
206
|
+
]) {
|
|
207
|
+
try {
|
|
208
|
+
const value = (JSON.parse(readFileSync(file, 'utf8')) as { autoMemoryDirectory?: unknown }).autoMemoryDirectory
|
|
209
|
+
if (typeof value === 'string' && value) return value.replace(/^~(?=\/|$)/, home())
|
|
210
|
+
} catch {
|
|
211
|
+
// Absent or unreadable: the next one, or the default.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return null
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Where Claude Code keeps this repository's auto memory:
|
|
219
|
+
* `<config>/projects/<repository path, every other character a hyphen>/memory/`.
|
|
220
|
+
* Every worktree of one repository shares it, so the path is the main
|
|
221
|
+
* checkout's, which git names as the common directory's parent.
|
|
222
|
+
*/
|
|
223
|
+
export function claudeMemoryDir(projectRoot: string): string {
|
|
224
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR || join(home(), '.claude')
|
|
225
|
+
const configured = configuredMemoryDir(projectRoot, configDir)
|
|
226
|
+
if (configured) return configured
|
|
227
|
+
let repo = projectRoot
|
|
228
|
+
try {
|
|
229
|
+
const common = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
|
|
230
|
+
cwd: projectRoot,
|
|
231
|
+
encoding: 'utf8',
|
|
232
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
233
|
+
}).trim()
|
|
234
|
+
repo = basename(common) === '.git' ? dirname(common) : projectRoot
|
|
235
|
+
} catch {
|
|
236
|
+
repo = projectRoot
|
|
237
|
+
}
|
|
238
|
+
const slug = process.env.CLAUDE_CODE_PROJECT_DIR_NAME || repo.replace(/[^A-Za-z0-9]/g, '-')
|
|
239
|
+
return join(configDir, 'projects', slug, 'memory')
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface Memory {
|
|
243
|
+
file: string
|
|
244
|
+
name: string
|
|
245
|
+
description?: string
|
|
246
|
+
type?: string
|
|
247
|
+
body: string
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function readMemories(dir: string): Memory[] {
|
|
251
|
+
const out: Memory[] = []
|
|
252
|
+
for (const file of readdirSync(dir).sort()) {
|
|
253
|
+
if (!file.endsWith('.md') || file === 'MEMORY.md') continue
|
|
254
|
+
const abs = join(dir, file)
|
|
255
|
+
if (!statSync(abs).isFile()) continue
|
|
256
|
+
const text = readFileSync(abs, 'utf8').replace(/^\uFEFF/, '')
|
|
257
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
|
|
258
|
+
let meta: Record<string, unknown> = {}
|
|
259
|
+
try {
|
|
260
|
+
meta = m ? ((parseYaml(m[1]) ?? {}) as Record<string, unknown>) : {}
|
|
261
|
+
} catch {
|
|
262
|
+
meta = {}
|
|
263
|
+
}
|
|
264
|
+
const nested = meta.metadata && typeof meta.metadata === 'object' ? (meta.metadata as Record<string, unknown>) : {}
|
|
265
|
+
const type = typeof meta.type === 'string' ? meta.type : typeof nested.type === 'string' ? nested.type : undefined
|
|
266
|
+
out.push({
|
|
267
|
+
file,
|
|
268
|
+
name: typeof meta.name === 'string' ? meta.name : file.replace(/\.md$/, ''),
|
|
269
|
+
description: typeof meta.description === 'string' ? meta.description : undefined,
|
|
270
|
+
type,
|
|
271
|
+
body: (m ? m[2] : text).trim(),
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
return out
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** A title for a memory: its description, else its name read as words. */
|
|
278
|
+
function titleOf(memory: Memory): string {
|
|
279
|
+
const raw = memory.description ?? memory.name.replace(/[-_]+/g, ' ')
|
|
280
|
+
const one = raw.replace(/[\r\n]+/g, ' ').trim()
|
|
281
|
+
return one.charAt(0).toUpperCase() + one.slice(1)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function promoteMemory(args: string[], dryRun: boolean): void {
|
|
285
|
+
const projectRoot = projectRootFrom(process.cwd())
|
|
286
|
+
const customizations = join(projectRoot, '.opencastle')
|
|
287
|
+
if (!existsSync(customizations)) fail('no .opencastle/ here — run opencastle init first')
|
|
288
|
+
const from = flag(args, '--from')
|
|
289
|
+
const dir = from ? resolve(process.cwd(), from.replace(/^~(?=\/|$)/, home())) : claudeMemoryDir(projectRoot)
|
|
290
|
+
if (!existsSync(dir)) {
|
|
291
|
+
fail(`no memory at ${tilde(dir)} — Claude Code keeps it there once it has saved one for this repository; --from <dir> reads another`)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
syncLessons(customizations)
|
|
295
|
+
const { lessons } = readLessons(customizations)
|
|
296
|
+
const promoted = new Set(lessons.map((l) => l.source).filter((s): s is string => Boolean(s)))
|
|
297
|
+
const taken = new Set(lessons.map((l) => l.id))
|
|
298
|
+
const written: string[] = []
|
|
299
|
+
const skipped: Array<[string, string]> = []
|
|
300
|
+
const h = home()
|
|
301
|
+
|
|
302
|
+
for (const memory of readMemories(dir)) {
|
|
303
|
+
if (memory.type && !['feedback', 'project'].includes(memory.type)) {
|
|
304
|
+
skipped.push([memory.file, memory.type === 'user' ? 'about you, not the project' : `a ${memory.type} memory`])
|
|
305
|
+
continue
|
|
306
|
+
}
|
|
307
|
+
if (!memory.body) {
|
|
308
|
+
skipped.push([memory.file, 'empty'])
|
|
309
|
+
continue
|
|
310
|
+
}
|
|
311
|
+
const digest = createHash('sha256').update(memory.body).digest('hex').slice(0, 12)
|
|
312
|
+
const source = `claude-code-memory:${memory.file}#${digest}`
|
|
313
|
+
if (promoted.has(source)) {
|
|
314
|
+
skipped.push([memory.file, 'already a lesson'])
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
// A memory names paths on its author's machine; the team's copy says ~.
|
|
318
|
+
const body = memory.body.split(h).join('~')
|
|
319
|
+
const scan = scanForSecrets(body, memory.file)
|
|
320
|
+
if (!scan.clean) {
|
|
321
|
+
skipped.push([memory.file, `holds what looks like a ${scan.findings[0].pattern} (line ${scan.findings[0].line})`])
|
|
322
|
+
continue
|
|
323
|
+
}
|
|
324
|
+
const title = titleOf(memory)
|
|
325
|
+
const id = newLessonId(title, today(), taken)
|
|
326
|
+
taken.add(id)
|
|
327
|
+
const lesson: Omit<Lesson, 'file'> = {
|
|
328
|
+
id,
|
|
329
|
+
title,
|
|
330
|
+
category: 'general',
|
|
331
|
+
severity: 'medium',
|
|
332
|
+
added: today(),
|
|
333
|
+
citations: [],
|
|
334
|
+
status: 'active',
|
|
335
|
+
source,
|
|
336
|
+
body,
|
|
337
|
+
}
|
|
338
|
+
written.push(`${LESSONS_DIR}/${id}.md`)
|
|
339
|
+
if (!dryRun) {
|
|
340
|
+
mkdirSync(join(customizations, LESSONS_DIR), { recursive: true })
|
|
341
|
+
writeFileSync(join(customizations, LESSONS_DIR, `${id}.md`), renderLesson(lesson))
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (!dryRun && written.length > 0) syncLessons(customizations)
|
|
345
|
+
|
|
346
|
+
console.log(`\n 🏰 ${c.bold('Promote memory')} ${c.dim(`from ${tilde(dir)}`)}\n`)
|
|
347
|
+
if (written.length === 0) console.log(` ${c.dim('Nothing new to promote.')}`)
|
|
348
|
+
for (const w of written) console.log(` ${c.green(dryRun ? '+' : '✓')} ${dryRun ? 'Would write' : 'Wrote'} .opencastle/${w}`)
|
|
349
|
+
for (const [file, why] of skipped) console.log(` ${c.dim(`- ${file}: ${why}`)}`)
|
|
350
|
+
if (written.length > 0 && !dryRun) {
|
|
351
|
+
console.log(
|
|
352
|
+
`\n ${c.dim('Each is category general, severity medium: set them, add --cite where a lesson is about code,')}` +
|
|
353
|
+
`\n ${c.dim('and delete any that are yours alone. The pull request that commits them is where the team agrees.')}\n`,
|
|
354
|
+
)
|
|
355
|
+
} else {
|
|
356
|
+
console.log('')
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export default async function promote({ pkgRoot, args }: CliContext): Promise<void> {
|
|
361
|
+
const [sub, ...rest] = args
|
|
362
|
+
if (!sub || args.includes('--help') || args.includes('-h') || !['skill', 'memory'].includes(sub)) {
|
|
363
|
+
console.log(HELP)
|
|
364
|
+
if (sub && !['skill', 'memory', '--help', '-h'].includes(sub)) process.exit(1)
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
const dryRun = rest.includes('--dry-run')
|
|
368
|
+
if (sub === 'skill') promoteSkill(pkgRoot, rest, dryRun)
|
|
369
|
+
else promoteMemory(rest, dryRun)
|
|
370
|
+
}
|
|
371
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { parse as yamlParse } from 'yaml'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Finding a credential in text before it is written somewhere it is committed
|
|
7
|
+
* or logged.
|
|
8
|
+
*
|
|
9
|
+
* The convoy engine scans every event and artefact it writes with this; lessons
|
|
10
|
+
* are scanned before they are written, because a lesson is committed with the
|
|
11
|
+
* project. It lives outside the engine so the compiler's own commands can use
|
|
12
|
+
* it without depending on the experimental engine.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// ── Secret patterns ───────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
interface SecretPatternEntry {
|
|
18
|
+
name: string
|
|
19
|
+
pattern: RegExp
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const SECRET_PATTERNS: SecretPatternEntry[] = [
|
|
23
|
+
{ name: 'AWS Access Key', pattern: /AKIA[0-9A-Z]{16}/i },
|
|
24
|
+
{
|
|
25
|
+
name: 'AWS Secret Key',
|
|
26
|
+
// eslint-disable-next-line no-useless-escape
|
|
27
|
+
pattern: /(?:aws_secret_access_key|secret_key)\s*[=:]\s*[A-Za-z0-9\/+=]{40}/i,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Generic API Key',
|
|
31
|
+
pattern: /(?:api[_-]?key|apikey)\s*[=:]\s*['"]?[A-Za-z0-9_-]{20,}/i,
|
|
32
|
+
},
|
|
33
|
+
{ name: 'Bearer Token', pattern: /[Bb]earer\s+[A-Za-z0-9\-._~+/]+=*/ },
|
|
34
|
+
{ name: 'Private Key', pattern: /-----BEGIN (?:RSA|EC|OPENSSH) PRIVATE KEY-----/ },
|
|
35
|
+
{
|
|
36
|
+
name: 'Connection String',
|
|
37
|
+
// eslint-disable-next-line no-useless-escape
|
|
38
|
+
pattern: /(?:postgres|mysql|mongodb|redis):\/\/[^\s]+:[^\s]+@/,
|
|
39
|
+
},
|
|
40
|
+
{ name: 'GitHub Token', pattern: /(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36,}/ },
|
|
41
|
+
{
|
|
42
|
+
name: 'Generic Password',
|
|
43
|
+
pattern: /(?:password|passwd|pwd)\s*[=:]\s*['"]?[^\s'"]{8,}/i,
|
|
44
|
+
},
|
|
45
|
+
{ name: 'Slack Token', pattern: /xox[bprs]-[A-Za-z0-9-]{10,}/i },
|
|
46
|
+
{
|
|
47
|
+
name: 'Generic Secret',
|
|
48
|
+
pattern: /(?:secret|token|credential)\s*[=:]\s*['"]?[A-Za-z0-9_-]{16,}/i,
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
// ── Public types ──────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
export interface SecretScanResult {
|
|
55
|
+
clean: boolean
|
|
56
|
+
findings: Array<{ pattern: string; file: string; line: number; snippet: string }>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── Allowlist ─────────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
interface AllowlistEntry {
|
|
62
|
+
pattern?: string
|
|
63
|
+
literal?: string
|
|
64
|
+
reason: string
|
|
65
|
+
paths?: string[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let _allowlist: AllowlistEntry[] | null = null
|
|
69
|
+
|
|
70
|
+
/** The config path used for the allowlist. Override for testing. */
|
|
71
|
+
export let _allowlistConfigPath = join(process.cwd(), '.opencastle', 'secret-scan-config.yml')
|
|
72
|
+
|
|
73
|
+
/** Reset the allowlist cache (for testing). */
|
|
74
|
+
export function _resetAllowlistCache(): void {
|
|
75
|
+
_allowlist = null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Override the allowlist config path and reset cache (for testing). */
|
|
79
|
+
export function _setAllowlistConfigPath(path: string): void {
|
|
80
|
+
_allowlistConfigPath = path
|
|
81
|
+
_allowlist = null
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function loadAllowlist(): AllowlistEntry[] {
|
|
85
|
+
if (_allowlist !== null) return _allowlist
|
|
86
|
+
try {
|
|
87
|
+
if (!existsSync(_allowlistConfigPath)) {
|
|
88
|
+
_allowlist = []
|
|
89
|
+
return _allowlist
|
|
90
|
+
}
|
|
91
|
+
const content = readFileSync(_allowlistConfigPath, 'utf-8')
|
|
92
|
+
const parsed = yamlParse(content) as Record<string, unknown> | null
|
|
93
|
+
if (!parsed || !Array.isArray(parsed['allowlist'])) {
|
|
94
|
+
_allowlist = []
|
|
95
|
+
return _allowlist
|
|
96
|
+
}
|
|
97
|
+
_allowlist = parsed['allowlist'] as AllowlistEntry[]
|
|
98
|
+
return _allowlist
|
|
99
|
+
} catch {
|
|
100
|
+
_allowlist = []
|
|
101
|
+
return _allowlist
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isSuppressed(
|
|
106
|
+
finding: { snippet: string },
|
|
107
|
+
filePath: string,
|
|
108
|
+
allowlist: AllowlistEntry[],
|
|
109
|
+
): boolean {
|
|
110
|
+
for (const entry of allowlist) {
|
|
111
|
+
if (entry.paths && entry.paths.length > 0) {
|
|
112
|
+
if (!entry.paths.some((p) => filePath.includes(p))) continue
|
|
113
|
+
}
|
|
114
|
+
if (entry.literal) {
|
|
115
|
+
if (finding.snippet.includes(entry.literal)) return true
|
|
116
|
+
} else if (entry.pattern) {
|
|
117
|
+
try {
|
|
118
|
+
if (new RegExp(entry.pattern, 'i').test(finding.snippet)) return true
|
|
119
|
+
} catch {
|
|
120
|
+
// Invalid regex in allowlist — skip entry
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── scanForSecrets ────────────────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Scan text content line-by-line for secrets using the default pattern set.
|
|
131
|
+
* Allowlist entries in `.opencastle/secret-scan-config.yml` suppress false positives.
|
|
132
|
+
*/
|
|
133
|
+
export function scanForSecrets(content: string, filePath = ''): SecretScanResult {
|
|
134
|
+
const allowlist = loadAllowlist()
|
|
135
|
+
const lines = content.split('\n')
|
|
136
|
+
const findings: SecretScanResult['findings'] = []
|
|
137
|
+
|
|
138
|
+
for (let i = 0; i < lines.length; i++) {
|
|
139
|
+
const line = lines[i]
|
|
140
|
+
for (const { name, pattern } of SECRET_PATTERNS) {
|
|
141
|
+
if (pattern.test(line)) {
|
|
142
|
+
const snippet = line.length > 100 ? line.slice(0, 97) + '...' : line
|
|
143
|
+
const finding = { pattern: name, file: filePath, line: i + 1, snippet }
|
|
144
|
+
if (!isSuppressed(finding, filePath, allowlist)) {
|
|
145
|
+
findings.push(finding)
|
|
146
|
+
}
|
|
147
|
+
// Only report the first matching pattern per line
|
|
148
|
+
break
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { clean: findings.length === 0, findings }
|
|
154
|
+
}
|
package/src/cli/sync-check.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { IDE_ADAPTERS } from './adapters/index.js'
|
|
|
6
6
|
import { detectRepoInfo, mergeStackIntoRepoInfo } from './detect.js'
|
|
7
7
|
import { getMcpConfigRelPath, expectedTeamEntries, containerKeyFor } from './mcp.js'
|
|
8
8
|
import { parseMcpConfigText } from './mcp-file.js'
|
|
9
|
+
import { lessonsIndexDrift, LESSONS_INDEX } from './lessons.js'
|
|
9
10
|
import { resolveStack, getIncludedMcpServers } from './stack-config.js'
|
|
10
11
|
import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
|
|
11
12
|
import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
|
|
@@ -652,6 +653,14 @@ async function compareProject(
|
|
|
652
653
|
}
|
|
653
654
|
}
|
|
654
655
|
|
|
656
|
+
// The lessons index, compiled from `.opencastle/lessons/` by `sync`. Two
|
|
657
|
+
// branches that each add a lesson merge cleanly; the index they both touched
|
|
658
|
+
// is what this catches, and `sync` rebuilds it.
|
|
659
|
+
{
|
|
660
|
+
const why = lessonsIndexDrift(resolve(projectRoot, '.opencastle'))
|
|
661
|
+
if (why) drift.push({ ide: 'all', path: `.opencastle/${LESSONS_INDEX}`, kind: 'outdated', detail: why, fix: 'opencastle sync' })
|
|
662
|
+
}
|
|
663
|
+
|
|
655
664
|
// A manifest that parses but names no target this release knows is not a
|
|
656
665
|
// clean project — `sync` exits 1 on it. Reporting "0 generated files match
|
|
657
666
|
// their sources across 0 targets" is an assertion that cannot fail, and it
|
|
@@ -219,7 +219,7 @@ describe.skipIf(!built)('a baseline package', () => {
|
|
|
219
219
|
it('scaffolds one that passes its own check', () => {
|
|
220
220
|
expect(run(dir, ['baseline', 'init', 'base', '--name', '@acme/base']).code).toBe(0)
|
|
221
221
|
const pkg = JSON.parse(readFileSync(join(dir, 'base', 'package.json'), 'utf8'))
|
|
222
|
-
expect(pkg.opencastle).toEqual({ baseline: '
|
|
222
|
+
expect(pkg.opencastle).toEqual({ baseline: '.' })
|
|
223
223
|
const check = run(dir, ['baseline', 'check', 'base', '--json'])
|
|
224
224
|
expect(check.code).toBe(0)
|
|
225
225
|
const report = JSON.parse(check.out)
|
|
@@ -248,6 +248,6 @@ describe.skipIf(!built)('a baseline package', () => {
|
|
|
248
248
|
writeFileSync(path, JSON.stringify(pkg))
|
|
249
249
|
const check = run(dir, ['baseline', 'check', 'base'])
|
|
250
250
|
expect(check.code).toBe(1)
|
|
251
|
-
expect(check.out).toContain('
|
|
251
|
+
expect(check.out).toContain('"files" does not include plugin.json, so npm publish would leave it out')
|
|
252
252
|
})
|
|
253
253
|
})
|
package/src/cli/update.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { buildLock, writeLock, LOCK_REL, priorTeam } from './lock.js'
|
|
|
33
33
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
34
34
|
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
35
35
|
import { parseMcpConfigText } from './mcp-file.js'
|
|
36
|
+
import { syncLessons, LESSONS_DIR, LESSONS_INDEX } from './lessons.js'
|
|
36
37
|
|
|
37
38
|
/** The config that replaced a legacy one, for the sentence that reports it. */
|
|
38
39
|
function configBesideLegacy(rel: string, ides: string[]): string {
|
|
@@ -698,6 +699,11 @@ export default async function update({
|
|
|
698
699
|
// ── Migrate legacy log files ────────────────────────────────────
|
|
699
700
|
await migrateLegacyLogs(projectRoot)
|
|
700
701
|
|
|
702
|
+
// ── Lessons: one file each, and the index agents read compiled from them ──
|
|
703
|
+
// Not compiled output of any target — agents read `.opencastle/` directly —
|
|
704
|
+
// but compiled all the same, and `sync --check` holds it to its sources.
|
|
705
|
+
const lessons = syncLessons(resolve(projectRoot, '.opencastle'))
|
|
706
|
+
|
|
701
707
|
// ── Update manifest ─────────────────────────────────────────────
|
|
702
708
|
const before = manifestMeaning(manifest as unknown as Record<string, unknown>)
|
|
703
709
|
manifest.version = pkg.version
|
|
@@ -749,6 +755,20 @@ export default async function update({
|
|
|
749
755
|
if (teamWritten.size > 0) {
|
|
750
756
|
console.log(` ${c.green('✓')} Wrote the team's MCP server(s) as defined: ${[...teamWritten].sort().join(', ')}`)
|
|
751
757
|
}
|
|
758
|
+
if (lessons.migrated > 0) {
|
|
759
|
+
console.log(
|
|
760
|
+
` ${c.green('✓')} Moved ${lessons.migrated} lesson(s) from .opencastle/${LESSONS_INDEX} into .opencastle/${LESSONS_DIR}/, one file each` +
|
|
761
|
+
(lessons.backup ? c.dim(` (the old file is kept as ${lessons.backup})`) : ''),
|
|
762
|
+
)
|
|
763
|
+
} else if (lessons.backup) {
|
|
764
|
+
console.log(` ${c.green('✓')} Replaced .opencastle/${LESSONS_INDEX} with an index of .opencastle/${LESSONS_DIR}/ ${c.dim(`(the old file is kept as ${lessons.backup})`)}`)
|
|
765
|
+
}
|
|
766
|
+
if (lessons.index === 'updated' && lessons.migrated === 0 && !lessons.backup) {
|
|
767
|
+
console.log(` ${c.green('✓')} Updated .opencastle/${LESSONS_INDEX} from .opencastle/${LESSONS_DIR}/`)
|
|
768
|
+
}
|
|
769
|
+
for (const problem of lessons.problems) {
|
|
770
|
+
console.log(` ${c.yellow('!')} Left .opencastle/${problem.split(' ')[0]} out of the lessons index — ${problem.slice(problem.indexOf(' ') + 1)}`)
|
|
771
|
+
}
|
|
752
772
|
for (const rel of legacyDeleted) {
|
|
753
773
|
console.log(` ${c.yellow('-')} Removed ${rel}, which its assistant never read ${c.dim(`(its servers are now in ${configBesideLegacy(rel, ides)})`)}`)
|
|
754
774
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
"hash": "
|
|
2
|
+
"hash": "dcab8e95",
|
|
3
3
|
"configHash": "30f8ea04",
|
|
4
|
-
"lockfileHash": "
|
|
5
|
-
"browserHash": "
|
|
4
|
+
"lockfileHash": "8759a89c",
|
|
5
|
+
"browserHash": "54e2a2ba",
|
|
6
6
|
"optimized": {
|
|
7
7
|
"astro > cssesc": {
|
|
8
8
|
"src": "../../../../../node_modules/cssesc/cssesc.js",
|
|
9
9
|
"file": "astro___cssesc.js",
|
|
10
|
-
"fileHash": "
|
|
10
|
+
"fileHash": "3f540abc",
|
|
11
11
|
"needsInterop": true
|
|
12
12
|
},
|
|
13
13
|
"astro > aria-query": {
|
|
14
14
|
"src": "../../../../../node_modules/aria-query/lib/index.js",
|
|
15
15
|
"file": "astro___aria-query.js",
|
|
16
|
-
"fileHash": "
|
|
16
|
+
"fileHash": "4ca37322",
|
|
17
17
|
"needsInterop": true
|
|
18
18
|
},
|
|
19
19
|
"astro > axobject-query": {
|
|
20
20
|
"src": "../../../../../node_modules/axobject-query/lib/index.js",
|
|
21
21
|
"file": "astro___axobject-query.js",
|
|
22
|
-
"fileHash": "
|
|
22
|
+
"fileHash": "592dc429",
|
|
23
23
|
"needsInterop": true
|
|
24
24
|
}
|
|
25
25
|
},
|
|
@@ -64,7 +64,7 @@ Writing or editing code · running tests and builds · creating tracker issues
|
|
|
64
64
|
- [Question]: Searched [X, Y, Z] — could not determine
|
|
65
65
|
|
|
66
66
|
### Relevant Lessons
|
|
67
|
-
- [
|
|
67
|
+
- [lesson id]: [summary]
|
|
68
68
|
|
|
69
69
|
### Recommendations
|
|
70
70
|
- [Recommendation with rationale]
|