opencastle 1.1.1 → 1.3.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 +26 -9
- package/bin/cli.mjs +6 -0
- package/dist/cli/adapters/antigravity.d.ts +0 -1
- package/dist/cli/adapters/antigravity.d.ts.map +1 -1
- package/dist/cli/adapters/antigravity.js +2 -1
- package/dist/cli/adapters/antigravity.js.map +1 -1
- package/dist/cli/adapters/claude-code.d.ts +0 -1
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +0 -1
- package/dist/cli/adapters/claude-code.js.map +1 -1
- package/dist/cli/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.js +8 -1
- package/dist/cli/adapters/cursor.js.map +1 -1
- package/dist/cli/adapters/opencode.d.ts +12 -5
- package/dist/cli/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/adapters/opencode.js +17 -5
- package/dist/cli/adapters/opencode.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts +12 -1
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +43 -57
- package/dist/cli/adapters/rules-dir-base.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.test.js +27 -18
- package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts +11 -0
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +44 -14
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +2 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +2 -1
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/adapters/windsurf.d.ts.map +1 -1
- package/dist/cli/adapters/windsurf.js +11 -1
- package/dist/cli/adapters/windsurf.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 +114 -34
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/ci.d.ts.map +1 -1
- package/dist/cli/ci.js +18 -4
- package/dist/cli/ci.js.map +1 -1
- package/dist/cli/codex-target.test.js +14 -1
- package/dist/cli/codex-target.test.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/doctor.test.js +2 -2
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/explain.d.ts +5 -0
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js +38 -2
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/init.test.js +78 -42
- 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 +3 -1
- 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 +2 -0
- package/dist/cli/mcp-audit.js.map +1 -1
- package/dist/cli/mcp-upgrade.test.js +24 -1
- package/dist/cli/mcp-upgrade.test.js.map +1 -1
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +22 -3
- 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/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/sync-check.test.js +5 -4
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/team-commands.test.js +14 -2
- package/dist/cli/team-commands.test.js.map +1 -1
- package/dist/cli/team-sources.test.js +10 -0
- package/dist/cli/team-sources.test.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.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/cli/windsurf-target.test.d.ts +2 -0
- package/dist/cli/windsurf-target.test.d.ts.map +1 -0
- package/dist/cli/windsurf-target.test.js +62 -0
- package/dist/cli/windsurf-target.test.js.map +1 -0
- 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/dist/orchestrator/plugins/registry.test.d.ts +2 -0
- package/dist/orchestrator/plugins/registry.test.d.ts.map +1 -0
- package/dist/orchestrator/plugins/registry.test.js +37 -0
- package/dist/orchestrator/plugins/registry.test.js.map +1 -0
- package/package.json +2 -1
- package/src/cli/adapters/antigravity.ts +2 -1
- package/src/cli/adapters/claude-code.ts +0 -1
- package/src/cli/adapters/cursor.ts +8 -1
- package/src/cli/adapters/opencode.ts +18 -6
- package/src/cli/adapters/rules-dir-base.test.ts +28 -18
- package/src/cli/adapters/rules-dir-base.ts +51 -90
- package/src/cli/adapters/single-file-base.ts +53 -14
- package/src/cli/adapters/vscode.ts +2 -1
- package/src/cli/adapters/windsurf.ts +11 -1
- package/src/cli/agent-plugin.test.ts +267 -0
- package/src/cli/agent-plugin.ts +469 -0
- package/src/cli/baseline.ts +115 -32
- package/src/cli/ci.ts +19 -4
- package/src/cli/codex-target.test.ts +15 -1
- 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.test.ts +2 -2
- package/src/cli/doctor.ts +2 -0
- package/src/cli/explain.ts +36 -2
- package/src/cli/fixtures/lessons-template-1.0.md +70 -0
- package/src/cli/init.test.ts +82 -42
- 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 +3 -1
- package/src/cli/mcp-audit.ts +2 -0
- package/src/cli/mcp-upgrade.test.ts +26 -1
- package/src/cli/mcp.ts +22 -3
- 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.test.ts +5 -4
- package/src/cli/sync-check.ts +9 -0
- package/src/cli/team-commands.test.ts +18 -2
- package/src/cli/team-sources.test.ts +11 -0
- package/src/cli/types.ts +1 -1
- package/src/cli/update.ts +20 -0
- package/src/cli/windsurf-target.test.ts +70 -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/registry.test.ts +42 -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
package/src/cli/lesson.ts
CHANGED
|
@@ -1,71 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stat, writeFile, mkdir } from 'node:fs/promises'
|
|
2
2
|
import { join, dirname } from 'node:path'
|
|
3
3
|
import type { CliContext } from './types.js'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type Severity = (typeof SEVERITIES)[number]
|
|
4
|
+
import { scanForSecrets } from './secret-scan.js'
|
|
5
|
+
import {
|
|
6
|
+
LESSON_CATEGORIES,
|
|
7
|
+
LESSON_SEVERITIES,
|
|
8
|
+
LESSONS_DIR,
|
|
9
|
+
LESSONS_INDEX,
|
|
10
|
+
citationProblem,
|
|
11
|
+
findLesson,
|
|
12
|
+
fingerprintsOf,
|
|
13
|
+
isLessonCategory,
|
|
14
|
+
isLessonSeverity,
|
|
15
|
+
lessonBody,
|
|
16
|
+
newLessonId,
|
|
17
|
+
readLessons,
|
|
18
|
+
renderLesson,
|
|
19
|
+
syncLessons,
|
|
20
|
+
today,
|
|
21
|
+
type Lesson,
|
|
22
|
+
} from './lessons.js'
|
|
24
23
|
|
|
25
24
|
const HELP = `
|
|
26
|
-
opencastle lesson [options]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
opencastle lesson [add] --title <text> --category <cat> --severity <level> --problem <text> [options]
|
|
26
|
+
opencastle lesson verify <id> [--cite <path[:line]>]...
|
|
27
|
+
opencastle lesson archive <id> --into <file>
|
|
28
|
+
|
|
29
|
+
Record what an agent learned the hard way, as a file in .opencastle/lessons/,
|
|
30
|
+
and rewrite the index agents read before they start (.opencastle/${LESSONS_INDEX}).
|
|
31
|
+
|
|
32
|
+
add (the default) Write a new lesson. --title, --category, --severity and
|
|
33
|
+
--problem are required.
|
|
34
|
+
verify <id> Say a lesson still holds: stamps today's date and what
|
|
35
|
+
the cited files hold now, so doctor stops reporting them
|
|
36
|
+
as changed. --cite replaces its citations.
|
|
37
|
+
archive <id> Mark a lesson merged into a skill or instruction file,
|
|
38
|
+
named with --into. It stays on record and leaves the
|
|
39
|
+
list agents read.
|
|
40
|
+
|
|
41
|
+
Options:
|
|
31
42
|
--title <text> Short descriptive title
|
|
32
|
-
--category <cat> One of: ${
|
|
33
|
-
--severity <level> One of:
|
|
43
|
+
--category <cat> One of: ${LESSON_CATEGORIES.join(', ')}
|
|
44
|
+
--severity <level> One of: ${LESSON_SEVERITIES.join(', ')}
|
|
34
45
|
--problem <text> What went wrong
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
--
|
|
38
|
-
--
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
--
|
|
46
|
+
--wrong <text> The approach that was tried and failed
|
|
47
|
+
--correct <text> The approach that works
|
|
48
|
+
--why <text> Root cause
|
|
49
|
+
--cite <path[:line]> Code the lesson is about, relative to the project
|
|
50
|
+
root; repeat for more than one. doctor reports a
|
|
51
|
+
lesson whose cited code changes after it was verified
|
|
52
|
+
--into <file> archive: where the lesson now lives
|
|
53
|
+
--customizations-dir <p> Use this .opencastle directory instead of finding one
|
|
54
|
+
--dry-run Print what would be written, and write nothing
|
|
42
55
|
--help, -h Show this help
|
|
43
56
|
|
|
44
57
|
Examples:
|
|
45
|
-
opencastle lesson \\
|
|
46
|
-
--title "Never call foo without bar" \\
|
|
47
|
-
--category general \\
|
|
48
|
-
--severity high \\
|
|
49
|
-
--problem "foo throws on Node 18 without bar"
|
|
50
|
-
|
|
51
58
|
opencastle lesson \\
|
|
52
59
|
--title "Always quote shell variables" \\
|
|
53
60
|
--category terminal \\
|
|
54
61
|
--severity medium \\
|
|
55
62
|
--problem "Unquoted variables break on paths with spaces" \\
|
|
56
|
-
--wrong 'rm -rf
|
|
57
|
-
--correct 'rm -rf "
|
|
58
|
-
--
|
|
59
|
-
`
|
|
60
|
-
|
|
61
|
-
function isCategory(s: string): s is Category {
|
|
62
|
-
return (CATEGORIES as ReadonlyArray<string>).includes(s)
|
|
63
|
-
}
|
|
63
|
+
--wrong 'rm -rf \\$DIR/old' \\
|
|
64
|
+
--correct 'rm -rf "\\$DIR/old"' \\
|
|
65
|
+
--cite scripts/clean.sh:12
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
opencastle lesson verify 2026-10-02-always-quote-shell-variables
|
|
68
|
+
opencastle lesson archive LES-004 --into .opencastle/skills/git-workflow/SKILL.md
|
|
69
|
+
`
|
|
68
70
|
|
|
71
|
+
/** The `.opencastle/` this lesson belongs to: the override, or the nearest one up from here. */
|
|
69
72
|
async function resolveCustomizationsDir(override: string | null): Promise<string> {
|
|
70
73
|
if (override) return override
|
|
71
74
|
let dir = process.cwd()
|
|
@@ -83,246 +86,192 @@ async function resolveCustomizationsDir(override: string | null): Promise<string
|
|
|
83
86
|
return join(process.cwd(), '.opencastle')
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const last = Math.max(...matches.map((m) => parseInt(m[1], 10)))
|
|
90
|
-
return `LES-${String(last + 1).padStart(3, '0')}`
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function escapeMarkdown(s: string): string {
|
|
94
|
-
return s.replace(/\|/g, '\\|').replace(/[\n\r]/g, ' ')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function formatLesson(opts: {
|
|
98
|
-
id: string
|
|
99
|
-
title: string
|
|
100
|
-
category: Category
|
|
101
|
-
severity: Severity
|
|
102
|
-
date: string
|
|
103
|
-
problem: string
|
|
104
|
-
wrong?: string
|
|
105
|
-
correct?: string
|
|
106
|
-
why?: string
|
|
107
|
-
}): string {
|
|
108
|
-
const title = opts.title.replace(/[\n\r]/g, ' ')
|
|
109
|
-
const lines: string[] = [
|
|
110
|
-
`### ${opts.id}: ${title}`,
|
|
111
|
-
'',
|
|
112
|
-
'| Field | Value |',
|
|
113
|
-
'|-------|-------|',
|
|
114
|
-
`| **Category** | \`${opts.category}\` |`,
|
|
115
|
-
`| **Added** | ${opts.date} |`,
|
|
116
|
-
`| **Severity** | \`${opts.severity}\` |`,
|
|
117
|
-
'',
|
|
118
|
-
`**Problem:** ${escapeMarkdown(opts.problem)}`,
|
|
119
|
-
]
|
|
120
|
-
if (opts.wrong !== undefined) lines.push('', `**Wrong approach:** ${escapeMarkdown(opts.wrong)}`)
|
|
121
|
-
if (opts.correct !== undefined) lines.push('', `**Correct approach:** ${escapeMarkdown(opts.correct)}`)
|
|
122
|
-
if (opts.why !== undefined) lines.push('', `**Why:** ${escapeMarkdown(opts.why)}`)
|
|
123
|
-
return lines.join('\n')
|
|
89
|
+
function fail(message: string): never {
|
|
90
|
+
console.error(` \u2717 ${message}`)
|
|
91
|
+
process.exit(1)
|
|
124
92
|
}
|
|
125
93
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
// Insert block right before the \n## Index sequence
|
|
133
|
-
return content.slice(0, idx) + '\n' + block + '\n' + content.slice(idx)
|
|
94
|
+
interface Parsed {
|
|
95
|
+
positional: string[]
|
|
96
|
+
values: Map<string, string>
|
|
97
|
+
cites: string[]
|
|
98
|
+
dryRun: boolean
|
|
134
99
|
}
|
|
135
100
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
101
|
+
const VALUE_FLAGS = new Set([
|
|
102
|
+
'--title',
|
|
103
|
+
'--category',
|
|
104
|
+
'--severity',
|
|
105
|
+
'--problem',
|
|
106
|
+
'--wrong',
|
|
107
|
+
'--correct',
|
|
108
|
+
'--why',
|
|
109
|
+
'--into',
|
|
110
|
+
'--customizations-dir',
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
function parse(args: string[]): Parsed {
|
|
114
|
+
const out: Parsed = { positional: [], values: new Map(), cites: [], dryRun: false }
|
|
115
|
+
for (let i = 0; i < args.length; i++) {
|
|
116
|
+
const a = args[i]
|
|
117
|
+
if (a === '--dry-run' || a === '--dryRun') {
|
|
118
|
+
out.dryRun = true
|
|
119
|
+
} else if (a === '--cite' || VALUE_FLAGS.has(a)) {
|
|
120
|
+
if (i + 1 >= args.length) fail(`${a} requires a value`)
|
|
121
|
+
const value = args[++i]
|
|
122
|
+
if (!value.trim()) fail(`${a} cannot be empty`)
|
|
123
|
+
if (a === '--cite') out.cites.push(value.trim())
|
|
124
|
+
else out.values.set(a, value)
|
|
125
|
+
} else if (a.startsWith('-')) {
|
|
126
|
+
fail(`unknown option ${a} — run "opencastle lesson --help"`)
|
|
127
|
+
} else {
|
|
128
|
+
out.positional.push(a)
|
|
163
129
|
}
|
|
164
130
|
}
|
|
165
|
-
|
|
166
|
-
return lines.join('\n')
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface LessonInput {
|
|
170
|
-
title: string
|
|
171
|
-
category: string
|
|
172
|
-
severity: string
|
|
173
|
-
problem: string
|
|
174
|
-
wrong?: string
|
|
175
|
-
correct?: string
|
|
176
|
-
why?: string
|
|
131
|
+
return out
|
|
177
132
|
}
|
|
178
133
|
|
|
179
134
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
135
|
+
* A credential written into a lesson is committed with it. Refused, naming the
|
|
136
|
+
* line, the way a convoy refuses one in its own output.
|
|
182
137
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
if (!isSeverity(input.severity)) {
|
|
191
|
-
throw new Error(`Invalid severity "${input.severity}". Must be one of: ${SEVERITIES.join(', ')}`)
|
|
192
|
-
}
|
|
193
|
-
const category = input.category
|
|
194
|
-
const severity = input.severity
|
|
195
|
-
|
|
196
|
-
const resolvedDir = await resolveCustomizationsDir(customizationsDir ?? null)
|
|
197
|
-
const lessonsFile = join(resolvedDir, 'LESSONS-LEARNED.md')
|
|
138
|
+
function refuseSecrets(text: string, where: string): void {
|
|
139
|
+
const scan = scanForSecrets(text, where)
|
|
140
|
+
if (scan.clean) return
|
|
141
|
+
const first = scan.findings[0]
|
|
142
|
+
fail(`${where} would hold what looks like a ${first.pattern} (line ${first.line}) — a lesson is committed, so describe the credential instead of pasting it`)
|
|
143
|
+
}
|
|
198
144
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
throw new Error(`LESSONS-LEARNED.md not found at: ${lessonsFile}`)
|
|
145
|
+
function checkCitations(projectRoot: string, cites: string[]): void {
|
|
146
|
+
for (const cite of cites) {
|
|
147
|
+
const problem = citationProblem(projectRoot, cite)
|
|
148
|
+
if (problem) fail(`--cite: ${problem}`)
|
|
204
149
|
}
|
|
205
|
-
|
|
206
|
-
const id = nextLessonId(content)
|
|
207
|
-
const date = new Date().toISOString().slice(0, 10)
|
|
208
|
-
|
|
209
|
-
const block = formatLesson({
|
|
210
|
-
id,
|
|
211
|
-
title: input.title,
|
|
212
|
-
category,
|
|
213
|
-
severity,
|
|
214
|
-
date,
|
|
215
|
-
problem: input.problem,
|
|
216
|
-
wrong: input.wrong,
|
|
217
|
-
correct: input.correct,
|
|
218
|
-
why: input.why,
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
let updated = insertLesson(content, block)
|
|
222
|
-
updated = updateIndex(updated, category, id)
|
|
223
|
-
|
|
224
|
-
await writeFile(lessonsFile, updated, 'utf8')
|
|
225
|
-
return id
|
|
226
150
|
}
|
|
227
151
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
152
|
+
async function writeLessonFile(dir: string, lesson: Omit<Lesson, 'file'>, file: string, dryRun: boolean): Promise<void> {
|
|
153
|
+
const text = renderLesson(lesson)
|
|
154
|
+
const rel = `${LESSONS_DIR}/${file}`
|
|
155
|
+
refuseSecrets(text, rel)
|
|
156
|
+
if (dryRun) {
|
|
157
|
+
console.log(` [dry-run] Would write .opencastle/${rel}:\n`)
|
|
158
|
+
console.log(text)
|
|
231
159
|
return
|
|
232
160
|
}
|
|
161
|
+
await mkdir(join(dir, LESSONS_DIR), { recursive: true })
|
|
162
|
+
await writeFile(join(dir, LESSONS_DIR, file), text)
|
|
163
|
+
}
|
|
233
164
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
let customizationsDir: string | null = null
|
|
243
|
-
|
|
244
|
-
for (let i = 0; i < args.length; i++) {
|
|
245
|
-
const a = args[i]
|
|
246
|
-
switch (a) {
|
|
247
|
-
case '--title':
|
|
248
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --title requires a value'); process.exit(1) }
|
|
249
|
-
title = args[++i]
|
|
250
|
-
if (!title.trim()) { console.error(' \u2717 --title cannot be empty'); process.exit(1) }
|
|
251
|
-
break
|
|
252
|
-
case '--category':
|
|
253
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --category requires a value'); process.exit(1) }
|
|
254
|
-
category = args[++i]
|
|
255
|
-
if (!category.trim()) { console.error(' \u2717 --category cannot be empty'); process.exit(1) }
|
|
256
|
-
break
|
|
257
|
-
case '--severity':
|
|
258
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --severity requires a value'); process.exit(1) }
|
|
259
|
-
severity = args[++i]
|
|
260
|
-
if (!severity.trim()) { console.error(' \u2717 --severity cannot be empty'); process.exit(1) }
|
|
261
|
-
break
|
|
262
|
-
case '--problem':
|
|
263
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --problem requires a value'); process.exit(1) }
|
|
264
|
-
problem = args[++i]
|
|
265
|
-
if (!problem.trim()) { console.error(' \u2717 --problem cannot be empty'); process.exit(1) }
|
|
266
|
-
break
|
|
267
|
-
case '--wrong':
|
|
268
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --wrong requires a value'); process.exit(1) }
|
|
269
|
-
wrong = args[++i]
|
|
270
|
-
if (!wrong.trim()) { console.error(' \u2717 --wrong cannot be empty'); process.exit(1) }
|
|
271
|
-
break
|
|
272
|
-
case '--correct':
|
|
273
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --correct requires a value'); process.exit(1) }
|
|
274
|
-
correct = args[++i]
|
|
275
|
-
if (!correct.trim()) { console.error(' \u2717 --correct cannot be empty'); process.exit(1) }
|
|
276
|
-
break
|
|
277
|
-
case '--why':
|
|
278
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --why requires a value'); process.exit(1) }
|
|
279
|
-
why = args[++i]
|
|
280
|
-
if (!why.trim()) { console.error(' \u2717 --why cannot be empty'); process.exit(1) }
|
|
281
|
-
break
|
|
282
|
-
case '--customizations-dir':
|
|
283
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --customizations-dir requires a path'); process.exit(1) }
|
|
284
|
-
customizationsDir = args[++i]
|
|
285
|
-
if (!customizationsDir.trim()) { console.error(' \u2717 --customizations-dir cannot be empty'); process.exit(1) }
|
|
286
|
-
break
|
|
287
|
-
}
|
|
165
|
+
/** Rewrite the index, after moving anything still in the old single file. */
|
|
166
|
+
function reindex(dir: string): void {
|
|
167
|
+
const outcome = syncLessons(dir)
|
|
168
|
+
if (outcome.migrated > 0) {
|
|
169
|
+
console.log(
|
|
170
|
+
` Moved ${outcome.migrated} lesson(s) from ${LESSONS_INDEX} into .opencastle/${LESSONS_DIR}/` +
|
|
171
|
+
(outcome.backup ? ` (the old file is kept as ${outcome.backup})` : ''),
|
|
172
|
+
)
|
|
288
173
|
}
|
|
174
|
+
}
|
|
289
175
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
176
|
+
async function add(dir: string, projectRoot: string, p: Parsed): Promise<void> {
|
|
177
|
+
const title = p.values.get('--title')
|
|
178
|
+
const category = p.values.get('--category')
|
|
179
|
+
const severity = p.values.get('--severity')
|
|
180
|
+
const problem = p.values.get('--problem')
|
|
181
|
+
const missing = [
|
|
182
|
+
!title && '--title',
|
|
183
|
+
!category && '--category',
|
|
184
|
+
!severity && '--severity',
|
|
185
|
+
!problem && '--problem',
|
|
186
|
+
].filter(Boolean)
|
|
187
|
+
if (missing.length > 0) fail(`Missing required flags: ${missing.join(', ')}\n Run "opencastle lesson --help" for usage.`)
|
|
188
|
+
if (!isLessonCategory(category!)) fail(`Invalid --category "${category}". Must be one of: ${LESSON_CATEGORIES.join(', ')}`)
|
|
189
|
+
if (!isLessonSeverity(severity!)) fail(`Invalid --severity "${severity}". Must be one of: ${LESSON_SEVERITIES.join(', ')}`)
|
|
190
|
+
checkCitations(projectRoot, p.cites)
|
|
191
|
+
|
|
192
|
+
// Lessons still in the old file keep their numbers, so they are counted
|
|
193
|
+
// among the taken ids before this one is named.
|
|
194
|
+
if (!p.dryRun) reindex(dir)
|
|
195
|
+
const { lessons } = readLessons(dir)
|
|
196
|
+
const date = today()
|
|
197
|
+
const id = newLessonId(title!, date, new Set(lessons.map((l) => l.id)))
|
|
198
|
+
const lesson: Omit<Lesson, 'file'> = {
|
|
199
|
+
id,
|
|
200
|
+
title: title!.replace(/[\r\n]+/g, ' ').trim(),
|
|
201
|
+
category: category!,
|
|
202
|
+
severity: severity!,
|
|
203
|
+
added: date,
|
|
204
|
+
citations: p.cites,
|
|
205
|
+
...(p.cites.length > 0 && { verified: date, fingerprints: fingerprintsOf(projectRoot, p.cites) }),
|
|
206
|
+
status: 'active',
|
|
207
|
+
body: lessonBody({
|
|
208
|
+
problem: problem!,
|
|
209
|
+
wrong: p.values.get('--wrong'),
|
|
210
|
+
correct: p.values.get('--correct'),
|
|
211
|
+
why: p.values.get('--why'),
|
|
212
|
+
}),
|
|
300
213
|
}
|
|
214
|
+
await writeLessonFile(dir, lesson, `${id}.md`, p.dryRun)
|
|
215
|
+
if (p.dryRun) return
|
|
216
|
+
reindex(dir)
|
|
217
|
+
console.log(`${id}: ${lesson.title}`)
|
|
218
|
+
}
|
|
301
219
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
220
|
+
async function verify(dir: string, projectRoot: string, p: Parsed): Promise<void> {
|
|
221
|
+
const [ref] = p.positional
|
|
222
|
+
if (!ref) fail('verify needs the id of a lesson, e.g. opencastle lesson verify LES-004')
|
|
223
|
+
checkCitations(projectRoot, p.cites)
|
|
224
|
+
if (!p.dryRun) reindex(dir)
|
|
225
|
+
const { lessons } = readLessons(dir)
|
|
226
|
+
const lesson = findLesson(lessons, ref)
|
|
227
|
+
if (!lesson) fail(`no lesson ${ref} in .opencastle/${LESSONS_DIR}/`)
|
|
228
|
+
const citations = p.cites.length > 0 ? p.cites : lesson.citations
|
|
229
|
+
for (const cite of citations) {
|
|
230
|
+
const problem = citationProblem(projectRoot, cite)
|
|
231
|
+
if (problem) fail(`${lesson.id} cites ${cite}: ${problem} — pass --cite with where it is now`)
|
|
305
232
|
}
|
|
233
|
+
const updated: Lesson = { ...lesson, citations, verified: today(), fingerprints: fingerprintsOf(projectRoot, citations) }
|
|
234
|
+
await writeLessonFile(dir, updated, lesson.file, p.dryRun)
|
|
235
|
+
if (p.dryRun) return
|
|
236
|
+
reindex(dir)
|
|
237
|
+
console.log(`${lesson.id}: verified ${updated.verified}`)
|
|
238
|
+
}
|
|
306
239
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
240
|
+
async function archive(dir: string, projectRoot: string, p: Parsed): Promise<void> {
|
|
241
|
+
const [ref] = p.positional
|
|
242
|
+
const into = p.values.get('--into')
|
|
243
|
+
if (!ref) fail('archive needs the id of a lesson, e.g. opencastle lesson archive LES-004 --into <file>')
|
|
244
|
+
if (!into) fail('archive needs --into <file>: the skill or instruction file the lesson was merged into')
|
|
245
|
+
const problem = citationProblem(projectRoot, into)
|
|
246
|
+
if (problem) fail(`--into: ${problem}`)
|
|
247
|
+
if (!p.dryRun) reindex(dir)
|
|
248
|
+
const { lessons } = readLessons(dir)
|
|
249
|
+
const lesson = findLesson(lessons, ref)
|
|
250
|
+
if (!lesson) fail(`no lesson ${ref} in .opencastle/${LESSONS_DIR}/`)
|
|
251
|
+
await writeLessonFile(dir, { ...lesson, status: 'archived', mergedInto: into.replace(/^\.\//, '') }, lesson.file, p.dryRun)
|
|
252
|
+
if (p.dryRun) return
|
|
253
|
+
reindex(dir)
|
|
254
|
+
console.log(`${lesson.id}: archived, merged into ${into}`)
|
|
255
|
+
}
|
|
311
256
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
console.log(
|
|
257
|
+
export default async function lesson({ args }: CliContext): Promise<void> {
|
|
258
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
259
|
+
console.log(HELP)
|
|
315
260
|
return
|
|
316
261
|
}
|
|
317
|
-
|
|
262
|
+
const sub = args[0] === 'add' || args[0] === 'verify' || args[0] === 'archive' ? args[0] : 'add'
|
|
263
|
+
const p = parse(args[0] === sub ? args.slice(1) : args)
|
|
264
|
+
const dir = await resolveCustomizationsDir(p.values.get('--customizations-dir') ?? null)
|
|
265
|
+
const projectRoot = dirname(dir)
|
|
318
266
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
console.error(` \u2717 ${(err as Error).message}`)
|
|
326
|
-
process.exit(1)
|
|
267
|
+
await stat(dir)
|
|
268
|
+
} catch {
|
|
269
|
+
fail(`no .opencastle/ directory at ${dir} — run opencastle init first`)
|
|
270
|
+
}
|
|
271
|
+
if (sub === 'add' && p.positional.length > 0) {
|
|
272
|
+
fail(`unexpected argument "${p.positional[0]}" — did you mean opencastle lesson verify or archive?`)
|
|
327
273
|
}
|
|
274
|
+
if (sub === 'add') return add(dir, projectRoot, p)
|
|
275
|
+
if (sub === 'verify') return verify(dir, projectRoot, p)
|
|
276
|
+
return archive(dir, projectRoot, p)
|
|
328
277
|
}
|