opencastle 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +22 -5
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  4. package/dist/cli/adapters/single-file-base.js +24 -2
  5. package/dist/cli/adapters/single-file-base.js.map +1 -1
  6. package/dist/cli/agent-plugin.d.ts +119 -0
  7. package/dist/cli/agent-plugin.d.ts.map +1 -0
  8. package/dist/cli/agent-plugin.js +449 -0
  9. package/dist/cli/agent-plugin.js.map +1 -0
  10. package/dist/cli/agent-plugin.test.d.ts +2 -0
  11. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  12. package/dist/cli/agent-plugin.test.js +227 -0
  13. package/dist/cli/agent-plugin.test.js.map +1 -0
  14. package/dist/cli/baseline.d.ts.map +1 -1
  15. package/dist/cli/baseline.js +99 -26
  16. package/dist/cli/baseline.js.map +1 -1
  17. package/dist/cli/convoy/gates.d.ts +2 -20
  18. package/dist/cli/convoy/gates.d.ts.map +1 -1
  19. package/dist/cli/convoy/gates.js +3 -111
  20. package/dist/cli/convoy/gates.js.map +1 -1
  21. package/dist/cli/copy.d.ts +0 -8
  22. package/dist/cli/copy.d.ts.map +1 -1
  23. package/dist/cli/copy.js +0 -21
  24. package/dist/cli/copy.js.map +1 -1
  25. package/dist/cli/dispatcher.test.js +2 -2
  26. package/dist/cli/dispatcher.test.js.map +1 -1
  27. package/dist/cli/docs-accuracy.test.js +2 -0
  28. package/dist/cli/docs-accuracy.test.js.map +1 -1
  29. package/dist/cli/doctor.d.ts.map +1 -1
  30. package/dist/cli/doctor.js +2 -0
  31. package/dist/cli/doctor.js.map +1 -1
  32. package/dist/cli/init.test.js +36 -24
  33. package/dist/cli/init.test.js.map +1 -1
  34. package/dist/cli/layers.d.ts +8 -0
  35. package/dist/cli/layers.d.ts.map +1 -1
  36. package/dist/cli/layers.js +130 -13
  37. package/dist/cli/layers.js.map +1 -1
  38. package/dist/cli/layers.test.js +2 -2
  39. package/dist/cli/layers.test.js.map +1 -1
  40. package/dist/cli/legacy-install.test.js +8 -1
  41. package/dist/cli/legacy-install.test.js.map +1 -1
  42. package/dist/cli/lesson-command.test.d.ts +2 -0
  43. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  44. package/dist/cli/lesson-command.test.js +100 -0
  45. package/dist/cli/lesson-command.test.js.map +1 -0
  46. package/dist/cli/lesson.d.ts +0 -9
  47. package/dist/cli/lesson.d.ts.map +1 -1
  48. package/dist/cli/lesson.js +212 -276
  49. package/dist/cli/lesson.js.map +1 -1
  50. package/dist/cli/lessons.d.ts +134 -0
  51. package/dist/cli/lessons.d.ts.map +1 -0
  52. package/dist/cli/lessons.js +493 -0
  53. package/dist/cli/lessons.js.map +1 -0
  54. package/dist/cli/lessons.test.d.ts +2 -0
  55. package/dist/cli/lessons.test.d.ts.map +1 -0
  56. package/dist/cli/lessons.test.js +214 -0
  57. package/dist/cli/lessons.test.js.map +1 -0
  58. package/dist/cli/pack-plugins.d.ts +8 -0
  59. package/dist/cli/pack-plugins.d.ts.map +1 -0
  60. package/dist/cli/pack-plugins.js +70 -0
  61. package/dist/cli/pack-plugins.js.map +1 -0
  62. package/dist/cli/plugin-command.test.d.ts +2 -0
  63. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  64. package/dist/cli/plugin-command.test.js +114 -0
  65. package/dist/cli/plugin-command.test.js.map +1 -0
  66. package/dist/cli/plugin.d.ts +30 -0
  67. package/dist/cli/plugin.d.ts.map +1 -0
  68. package/dist/cli/plugin.js +291 -0
  69. package/dist/cli/plugin.js.map +1 -0
  70. package/dist/cli/promote-command.test.d.ts +2 -0
  71. package/dist/cli/promote-command.test.d.ts.map +1 -0
  72. package/dist/cli/promote-command.test.js +151 -0
  73. package/dist/cli/promote-command.test.js.map +1 -0
  74. package/dist/cli/promote.d.ts +12 -0
  75. package/dist/cli/promote.d.ts.map +1 -0
  76. package/dist/cli/promote.js +364 -0
  77. package/dist/cli/promote.js.map +1 -0
  78. package/dist/cli/secret-scan.d.ts +21 -0
  79. package/dist/cli/secret-scan.d.ts.map +1 -0
  80. package/dist/cli/secret-scan.js +114 -0
  81. package/dist/cli/secret-scan.js.map +1 -0
  82. package/dist/cli/sync-check.d.ts.map +1 -1
  83. package/dist/cli/sync-check.js +9 -0
  84. package/dist/cli/sync-check.js.map +1 -1
  85. package/dist/cli/team-commands.test.js +2 -2
  86. package/dist/cli/team-commands.test.js.map +1 -1
  87. package/dist/cli/update.d.ts.map +1 -1
  88. package/dist/cli/update.js +18 -0
  89. package/dist/cli/update.js.map +1 -1
  90. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  91. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  92. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  93. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  94. package/package.json +2 -1
  95. package/src/cli/adapters/single-file-base.ts +23 -2
  96. package/src/cli/agent-plugin.test.ts +267 -0
  97. package/src/cli/agent-plugin.ts +469 -0
  98. package/src/cli/baseline.ts +99 -26
  99. package/src/cli/convoy/gates.ts +9 -142
  100. package/src/cli/copy.ts +0 -25
  101. package/src/cli/dispatcher.test.ts +2 -2
  102. package/src/cli/docs-accuracy.test.ts +2 -0
  103. package/src/cli/doctor.ts +2 -0
  104. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  105. package/src/cli/init.test.ts +37 -24
  106. package/src/cli/layers.test.ts +2 -2
  107. package/src/cli/layers.ts +144 -14
  108. package/src/cli/legacy-install.test.ts +11 -1
  109. package/src/cli/lesson-command.test.ts +117 -0
  110. package/src/cli/lesson.ts +215 -266
  111. package/src/cli/lessons.test.ts +254 -0
  112. package/src/cli/lessons.ts +540 -0
  113. package/src/cli/pack-plugins.ts +70 -0
  114. package/src/cli/plugin-command.test.ts +125 -0
  115. package/src/cli/plugin.ts +309 -0
  116. package/src/cli/promote-command.test.ts +170 -0
  117. package/src/cli/promote.ts +371 -0
  118. package/src/cli/secret-scan.ts +154 -0
  119. package/src/cli/sync-check.ts +9 -0
  120. package/src/cli/team-commands.test.ts +2 -2
  121. package/src/cli/update.ts +20 -0
  122. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  123. package/src/orchestrator/agents/researcher.agent.md +1 -1
  124. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  125. package/src/orchestrator/customizations/README.md +2 -1
  126. package/src/orchestrator/customizations/logs/README.md +1 -1
  127. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  128. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  129. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  130. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  131. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  132. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  133. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  134. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  135. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  136. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  137. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  138. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  139. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  140. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  141. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  142. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  143. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  144. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  145. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  146. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  147. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  148. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  149. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  150. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  151. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  152. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  153. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  154. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  155. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  156. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  157. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  158. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  159. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  160. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  161. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  162. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  163. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  164. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  165. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  166. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  167. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  168. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  169. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  170. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  171. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  172. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  173. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  174. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  175. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  176. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  177. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  178. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  179. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  180. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  181. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  182. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  183. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  184. package/src/orchestrator/skill-config-links.test.ts +2 -1
  185. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  186. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  187. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  188. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  189. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  190. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  191. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  192. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  193. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  194. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  195. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  196. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  197. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  198. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  199. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  200. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  201. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  202. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  203. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  204. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  205. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  206. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  207. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  208. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  209. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  210. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  211. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  212. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  213. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  214. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  215. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  216. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  217. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  218. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  219. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  220. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  221. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: memory-merger
3
- description: "Reviews mature LESSONS-LEARNED.md entries, rewrites them as permanent rules in skill/instruction files, archives graduated lessons. Use when graduating lessons into skills, promoting validated lessons, updating skills from past learnings, archiving mature lessons, codifying repeated patterns, or cleaning up a crowded LESSONS-LEARNED.md."
3
+ description: "Reviews mature lessons in .opencastle/lessons/, rewrites them as permanent rules in skill/instruction files, archives graduated lessons with opencastle lesson archive. Use when graduating lessons into skills, promoting validated lessons, updating skills from past learnings, archiving mature lessons, codifying repeated patterns, or cleaning up a crowded lessons index."
4
4
  ---
5
5
 
6
6
  # Memory Merger
@@ -12,8 +12,8 @@ Combined signals to identify merge candidates.
12
12
 
13
13
  | Criterion | Signal / Threshold |
14
14
  |-----------|--------------------|
15
- | File size | LESSONS-LEARNED.md > 50 entries |
16
- | Citation count | Cited 3+ times across sessions |
15
+ | Volume | More than 50 lessons in `.opencastle/lessons/` |
16
+ | Reference count | Referenced 3+ times across sessions |
17
17
  | Age | >60 days and still relevant |
18
18
  | Category cluster | 5+ lessons in same category |
19
19
  | Severity | Marked `high` or blocking |
@@ -21,19 +21,19 @@ Combined signals to identify merge candidates.
21
21
 
22
22
  ## Workflow (numbered)
23
23
 
24
- 1. Scan LESSONS-LEARNED.md for candidate entries (frequency, severity, age).
24
+ 1. Scan `.opencastle/lessons/` for candidate lessons (frequency, severity, age — `added:` in each file).
25
25
  2. Map each candidate to target file, section.
26
26
  3. Draft exact edit (concise rule or example).
27
27
  4. Apply edit with attribution comment.
28
- 5. Archive migrated lesson in LESSONS-LEARNED.md with merge note.
29
- 6. Update index; run validation checks.
28
+ 5. Archive the lesson with `opencastle lesson archive`.
29
+ 6. Run validation checks.
30
30
 
31
31
  ## Merge Protocol
32
32
 
33
33
  ### 3 — Draft Edit
34
34
 
35
35
  ```
36
- Lesson: LES-XXX — [title]
36
+ Lesson: <id> — [title]
37
37
  Target: [file path]
38
38
  Section: [section name]
39
39
  Edit: [exact text]
@@ -42,30 +42,26 @@ Strategies: add rule, add anti-pattern, add code example, expand existing rule,
42
42
 
43
43
  ### 4 — Apply & Attribute
44
44
 
45
- Edit target file; add `<!-- Merged from LES-XXX -->` attribution inline.
45
+ Edit target file; add `<!-- Merged from <id> -->` attribution inline.
46
46
 
47
47
  ### 5 — Archive
48
48
 
49
- Move merged lessons to `## Archived (Merged)` at the bottom of `LESSONS-LEARNED.md`:
50
-
51
- ```markdown
52
- ### LES-XXX: [title] → Merged to `[target]` on YYYY-MM-DD
49
+ ```sh
50
+ opencastle lesson archive <id> --into <target file>
53
51
  ```
54
52
 
55
- **Never delete lessons** — archive for traceability.
53
+ The lesson keeps its file, is marked archived with where it went, and moves to the index's **Archived** section — out of the list agents read before work. Never edit `LESSONS-LEARNED.md` by hand: it is rewritten from the lesson files.
56
54
 
57
- ### 6 — Update Index
58
-
59
- Update `## Index by Category` in `LESSONS-LEARNED.md` to mark archived lessons.
55
+ **Never delete lessons** — archive for traceability.
60
56
 
61
57
  ### Automating the scan
62
58
 
63
59
  ```sh
64
- # Find lessons cited 3+ times across sessions
65
- rg -c "LES-[0-9]+" .opencastle/logs/events.ndjson | awk -F: '$2 >= 3 {print $1}'
60
+ # Lessons referenced 3+ times across sessions (ids are LES-NNN or YYYY-MM-DD-title)
61
+ rg -o '"lessons_added":\[[^]]*\]' .opencastle/logs/events.ndjson | rg -o '"[A-Za-z0-9-]+"' | sort | uniq -c | awk '$1 >= 3'
66
62
 
67
- # Find lessons referenced in recent retries
68
- rg "retry.*LES-[0-9]+" .opencastle/logs/events.ndjson | rg -o "LES-[0-9]+" | sort | uniq -c | sort -rn | head -20
63
+ # Oldest lessons first — candidates once past 60 days
64
+ rg -H '^added:' .opencastle/lessons/ | sort -t'"' -k2 | head -20
69
65
  ```
70
66
 
71
67
  ## Quality Gates (validation checkpoints)
@@ -77,7 +73,7 @@ rg "retry.*LES-[0-9]+" .opencastle/logs/events.ndjson | rg -o "LES-[0-9]+" | sor
77
73
 
78
74
  ## Anti-Patterns
79
75
 
80
- - Merge too eagerly — must meet 3+ citations or 60+ day threshold
76
+ - Merge too eagerly — must meet 3+ references or 60+ day threshold
81
77
  - Copy verbatim — rewrite as rules/guidelines, not incident reports
82
78
  - Merge conflicting lessons — resolve conflict first
83
79
  - Create new files for merged content — merge INTO existing files only
@@ -2,35 +2,56 @@
2
2
 
3
3
  # Lesson Categories & Severity
4
4
 
5
- Use these tables when tagging lessons in `LESSONS-LEARNED.md`.
5
+ The values `opencastle lesson` accepts. Anything else is refused.
6
6
 
7
7
  ## Categories
8
8
 
9
- | Category | When to use |
10
- |----------|------------|
11
- | `bug` | Runtime errors, incorrect behavior, regressions |
12
- | `pattern` | Reusable code or workflow pattern discovered |
13
- | `architecture` | Structural decisions, module boundaries, data flow |
14
- | `tooling` | Build tools, CLI, IDE, MCP, CI/CD issues |
15
- | `testing` | Test strategy, flaky tests, coverage gaps |
16
- | `security` | Auth, RLS, headers, secrets, input validation |
17
- | `performance` | Rendering, bundle size, query optimization |
18
- | `deployment` | Hosting, env vars, caching, rollback |
19
- | `process` | Workflow, delegation, review, orchestration |
20
- | `documentation` | Docs structure, templates, stale content |
9
+ | `--category` | When to use |
10
+ |--------------|-------------|
11
+ | `task-management` | Issue trackers, task status, boards |
12
+ | `jira` | Jira specifically: fields, transitions, JQL |
13
+ | `mcp-tools` | An MCP server's tools, parameters or quirks |
14
+ | `codebase-tool` | Search, refactoring and code-intelligence tools |
15
+ | `terminal` | Shell, quoting, CLI flags, environment |
16
+ | `framework` | The app framework and its build |
17
+ | `cms` | Content models, queries, publishing |
18
+ | `database` | Migrations, policies, queries |
19
+ | `git` | Branches, history, merges, hooks |
20
+ | `deployment` | Hosting, environment variables, caching, rollback |
21
+ | `browser-testing` | Browser automation, screenshots, breakpoints |
22
+ | `general` | Workflow, delegation, review — anything above does not cover |
21
23
 
22
24
  ## Severity
23
25
 
24
- | Severity | Criteria |
25
- |----------|---------|
26
- | `critical` | Blocks all work or causes data loss |
27
- | `high` | Blocks a task or causes significant rework |
28
- | `medium` | Causes friction or minor rework |
29
- | `low` | Nice-to-know; minor efficiency improvement |
26
+ | `--severity` | Criteria |
27
+ |--------------|----------|
28
+ | `high` | Blocks a task, loses data, or causes significant rework |
29
+ | `medium` | Wastes five minutes or more |
30
+ | `low` | Nice to know; minor efficiency improvement |
30
31
 
31
- ## Tagging Format
32
+ ## What a lesson file looks like
32
33
 
34
+ `opencastle lesson` writes `.opencastle/lessons/<id>.md`:
35
+
36
+ ```markdown
37
+ ---
38
+ id: "2026-10-02-always-quote-shell-variables"
39
+ title: "Always quote shell variables"
40
+ category: "terminal"
41
+ severity: "medium"
42
+ added: "2026-10-02"
43
+ citations:
44
+ - "scripts/clean.sh:12"
45
+ verified: "2026-10-02"
46
+ fingerprints:
47
+ scripts/clean.sh: "3f2a9c1b7d4e"
48
+ ---
49
+
50
+ **Problem:** Unquoted variables break on paths with spaces.
51
+
52
+ **Wrong approach:** `rm -rf $DIR/old`
53
+
54
+ **Correct approach:** `rm -rf "$DIR/old"`
33
55
  ```
34
- ### LES-XXX: <title>
35
- **Category:** <category> | **Severity:** <severity> | **Date:** YYYY-MM-DD
36
- ```
56
+
57
+ Lessons recorded before this format keep their `LES-NNN` ids.
@@ -1,56 +1,71 @@
1
1
  ---
2
2
  name: self-improvement
3
- description: "Appends new entries to LESSONS-LEARNED.md via opencastle lesson CLI; searches past lessons for matching errors; proposes skill updates when retry patterns exceed thresholds. Use when consulting or updating LESSONS-LEARNED.md, after task failures, when capturing retrospective insights, or when a retry succeeds."
3
+ description: "Records lessons with the opencastle lesson CLI, one file each in .opencastle/lessons/; searches past lessons for matching errors; re-verifies lessons whose cited code changed; proposes skill updates when retry patterns exceed thresholds. Use when consulting or updating lessons, after task failures, when capturing retrospective insights, when a retry succeeds, or when doctor reports a lesson's citation changed."
4
4
  ---
5
5
 
6
6
  # Self-Improvement Protocol
7
7
 
8
8
  ## Core Rule
9
9
 
10
- **Retry with different approach and it works → document lesson immediately.** File: `.opencastle/LESSONS-LEARNED.md`
10
+ **Retry with different approach and it works → record a lesson immediately.** Lessons live in `.opencastle/lessons/`, one Markdown file each; `.opencastle/LESSONS-LEARNED.md` is the index of them every agent reads first.
11
11
 
12
12
  ## Writing a Lesson
13
13
 
14
- > **⛔ HARD GATE — Use the CLI. Do NOT edit LESSONS-LEARNED.md directly.**
14
+ > **⛔ HARD GATE — Use the CLI. Never write in `LESSONS-LEARNED.md`: it is rewritten from `lessons/` by every sync.**
15
15
 
16
16
  ```sh
17
17
  opencastle lesson --title "Short descriptive title" --category general --severity high \
18
18
  --problem "What was observed" --wrong "Failing approach" --correct "Working solution" \
19
- --why "Root cause"
19
+ --why "Root cause" --cite src/lib/payments.ts:42
20
20
  ```
21
21
 
22
- Required: `--title`, `--category`, `--severity`, `--problem` · Optional: `--wrong`, `--correct`, `--why`
22
+ Required: `--title`, `--category`, `--severity`, `--problem` · Optional: `--wrong`, `--correct`, `--why`, `--cite` (repeatable)
23
23
 
24
- After writing: if lesson reveals gap in skill/instruction file, update that file too (prevents pitfall at source).
24
+ `--cite` names the code the lesson is about, relative to the project root. When that code changes, `doctor` says the lesson may no longer hold — cite whenever the lesson is about a specific file.
25
+
26
+ The command prints the new lesson's id (`2026-10-02-short-descriptive-title`). It refuses a lesson that would commit a credential, and a citation that does not exist.
27
+
28
+ After writing: if the lesson reveals a gap in a skill or instruction file, update that file too (prevents the pitfall at source).
25
29
 
26
30
  ## Workflow
27
31
 
28
- 1. Search LESSONS-LEARNED.md for matching entries or similar errors.
32
+ 1. Search past lessons for matching entries or similar errors (below).
29
33
  2. Attempt task with conservative flags/options informed by lessons.
30
34
  3. On failure: retry with modified approach (up to threshold); capture error details, context.
31
- 4. On success: run `opencastle lesson` to record working approach.
32
- 5. Verify: `tail -1 .opencastle/LESSONS-LEARNED.md` — confirm entry has title, category, severity. If malformed → re-run with corrected flags.
33
- 6. If lesson indicates needed skill/instruction update: draft change; propose a PR.
35
+ 4. On success: run `opencastle lesson` to record the working approach.
36
+ 5. Verify: the command printed an id, and `.opencastle/lessons/<id>.md` holds the title, category and severity you gave. If malformed → fix the flags and run it again, then delete the bad file.
37
+ 6. If the lesson indicates a needed skill/instruction update: draft the change; propose a PR.
34
38
 
35
- Quick search example:
39
+ Search the lessons themselves, not the index — the index has titles only:
36
40
 
37
41
  ```bash
38
- rg "missing CRON_SECRET" .opencastle/LESSONS-LEARNED.md || true
42
+ rg -i "CRON_SECRET" .opencastle/lessons/ || true
39
43
  ```
40
44
 
45
+ ## When code a lesson cites has changed
46
+
47
+ `doctor` names it: `<id> cites <file>, which has changed since it was verified`. Read the lesson against the code now:
48
+
49
+ | Still true? | Run |
50
+ |-------------|-----|
51
+ | Yes, file unchanged in substance | `opencastle lesson verify <id>` |
52
+ | Yes, but the code moved | `opencastle lesson verify <id> --cite <new/path.ts>` |
53
+ | No longer applies | `opencastle lesson archive <id> --into <file that now covers it>` |
54
+
41
55
  ## Categories & Severity
42
56
 
43
- Valid `--category` and `--severity` values, tagging format: [LESSON-CATEGORIES.md](LESSON-CATEGORIES.md).
57
+ Valid `--category` and `--severity` values: [LESSON-CATEGORIES.md](LESSON-CATEGORIES.md).
44
58
 
45
59
  ## Quality Rules
46
60
 
47
61
  - Include exact error messages, commands, tool parameters
48
62
  - Always fill both `--wrong` and `--correct` — the contrast is what makes the lesson usable
49
- - One lesson per entry; code blocks mandatory for commands
63
+ - One lesson per command; code blocks mandatory for commands
64
+ - Never paste a token, key or password — describe it ("the Stripe test key in `.env`")
50
65
 
51
66
  ## Anti-Patterns
52
67
 
53
- Never duplicate an existing lesson · Never defer logging to end of session
68
+ Never duplicate an existing lesson · Never defer recording to end of session · Never edit `LESSONS-LEARNED.md` by hand
54
69
 
55
70
  ## Agent Memory
56
71