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.
Files changed (307) hide show
  1. package/README.md +26 -9
  2. package/bin/cli.mjs +6 -0
  3. package/dist/cli/adapters/antigravity.d.ts +0 -1
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/antigravity.js +2 -1
  6. package/dist/cli/adapters/antigravity.js.map +1 -1
  7. package/dist/cli/adapters/claude-code.d.ts +0 -1
  8. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  9. package/dist/cli/adapters/claude-code.js +0 -1
  10. package/dist/cli/adapters/claude-code.js.map +1 -1
  11. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  12. package/dist/cli/adapters/cursor.js +8 -1
  13. package/dist/cli/adapters/cursor.js.map +1 -1
  14. package/dist/cli/adapters/opencode.d.ts +12 -5
  15. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  16. package/dist/cli/adapters/opencode.js +17 -5
  17. package/dist/cli/adapters/opencode.js.map +1 -1
  18. package/dist/cli/adapters/rules-dir-base.d.ts +12 -1
  19. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  20. package/dist/cli/adapters/rules-dir-base.js +43 -57
  21. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  22. package/dist/cli/adapters/rules-dir-base.test.js +27 -18
  23. package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
  24. package/dist/cli/adapters/single-file-base.d.ts +11 -0
  25. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  26. package/dist/cli/adapters/single-file-base.js +44 -14
  27. package/dist/cli/adapters/single-file-base.js.map +1 -1
  28. package/dist/cli/adapters/vscode.d.ts +2 -1
  29. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  30. package/dist/cli/adapters/vscode.js +2 -1
  31. package/dist/cli/adapters/vscode.js.map +1 -1
  32. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  33. package/dist/cli/adapters/windsurf.js +11 -1
  34. package/dist/cli/adapters/windsurf.js.map +1 -1
  35. package/dist/cli/agent-plugin.d.ts +119 -0
  36. package/dist/cli/agent-plugin.d.ts.map +1 -0
  37. package/dist/cli/agent-plugin.js +449 -0
  38. package/dist/cli/agent-plugin.js.map +1 -0
  39. package/dist/cli/agent-plugin.test.d.ts +2 -0
  40. package/dist/cli/agent-plugin.test.d.ts.map +1 -0
  41. package/dist/cli/agent-plugin.test.js +227 -0
  42. package/dist/cli/agent-plugin.test.js.map +1 -0
  43. package/dist/cli/baseline.d.ts.map +1 -1
  44. package/dist/cli/baseline.js +114 -34
  45. package/dist/cli/baseline.js.map +1 -1
  46. package/dist/cli/ci.d.ts.map +1 -1
  47. package/dist/cli/ci.js +18 -4
  48. package/dist/cli/ci.js.map +1 -1
  49. package/dist/cli/codex-target.test.js +14 -1
  50. package/dist/cli/codex-target.test.js.map +1 -1
  51. package/dist/cli/convoy/gates.d.ts +2 -20
  52. package/dist/cli/convoy/gates.d.ts.map +1 -1
  53. package/dist/cli/convoy/gates.js +3 -111
  54. package/dist/cli/convoy/gates.js.map +1 -1
  55. package/dist/cli/copy.d.ts +0 -8
  56. package/dist/cli/copy.d.ts.map +1 -1
  57. package/dist/cli/copy.js +0 -21
  58. package/dist/cli/copy.js.map +1 -1
  59. package/dist/cli/dispatcher.test.js +2 -2
  60. package/dist/cli/dispatcher.test.js.map +1 -1
  61. package/dist/cli/docs-accuracy.test.js +2 -0
  62. package/dist/cli/docs-accuracy.test.js.map +1 -1
  63. package/dist/cli/doctor.d.ts.map +1 -1
  64. package/dist/cli/doctor.js +2 -0
  65. package/dist/cli/doctor.js.map +1 -1
  66. package/dist/cli/doctor.test.js +2 -2
  67. package/dist/cli/doctor.test.js.map +1 -1
  68. package/dist/cli/explain.d.ts +5 -0
  69. package/dist/cli/explain.d.ts.map +1 -1
  70. package/dist/cli/explain.js +38 -2
  71. package/dist/cli/explain.js.map +1 -1
  72. package/dist/cli/init.test.js +78 -42
  73. package/dist/cli/init.test.js.map +1 -1
  74. package/dist/cli/layers.d.ts +8 -0
  75. package/dist/cli/layers.d.ts.map +1 -1
  76. package/dist/cli/layers.js +130 -13
  77. package/dist/cli/layers.js.map +1 -1
  78. package/dist/cli/layers.test.js +2 -2
  79. package/dist/cli/layers.test.js.map +1 -1
  80. package/dist/cli/legacy-install.test.js +8 -1
  81. package/dist/cli/legacy-install.test.js.map +1 -1
  82. package/dist/cli/lesson-command.test.d.ts +2 -0
  83. package/dist/cli/lesson-command.test.d.ts.map +1 -0
  84. package/dist/cli/lesson-command.test.js +100 -0
  85. package/dist/cli/lesson-command.test.js.map +1 -0
  86. package/dist/cli/lesson.d.ts +0 -9
  87. package/dist/cli/lesson.d.ts.map +1 -1
  88. package/dist/cli/lesson.js +212 -276
  89. package/dist/cli/lesson.js.map +1 -1
  90. package/dist/cli/lessons.d.ts +134 -0
  91. package/dist/cli/lessons.d.ts.map +1 -0
  92. package/dist/cli/lessons.js +493 -0
  93. package/dist/cli/lessons.js.map +1 -0
  94. package/dist/cli/lessons.test.d.ts +2 -0
  95. package/dist/cli/lessons.test.d.ts.map +1 -0
  96. package/dist/cli/lessons.test.js +214 -0
  97. package/dist/cli/lessons.test.js.map +1 -0
  98. package/dist/cli/managed-paths.d.ts.map +1 -1
  99. package/dist/cli/managed-paths.js +3 -1
  100. package/dist/cli/managed-paths.js.map +1 -1
  101. package/dist/cli/mcp-audit.d.ts.map +1 -1
  102. package/dist/cli/mcp-audit.js +2 -0
  103. package/dist/cli/mcp-audit.js.map +1 -1
  104. package/dist/cli/mcp-upgrade.test.js +24 -1
  105. package/dist/cli/mcp-upgrade.test.js.map +1 -1
  106. package/dist/cli/mcp.d.ts.map +1 -1
  107. package/dist/cli/mcp.js +22 -3
  108. package/dist/cli/mcp.js.map +1 -1
  109. package/dist/cli/pack-plugins.d.ts +8 -0
  110. package/dist/cli/pack-plugins.d.ts.map +1 -0
  111. package/dist/cli/pack-plugins.js +70 -0
  112. package/dist/cli/pack-plugins.js.map +1 -0
  113. package/dist/cli/plugin-command.test.d.ts +2 -0
  114. package/dist/cli/plugin-command.test.d.ts.map +1 -0
  115. package/dist/cli/plugin-command.test.js +114 -0
  116. package/dist/cli/plugin-command.test.js.map +1 -0
  117. package/dist/cli/plugin.d.ts +30 -0
  118. package/dist/cli/plugin.d.ts.map +1 -0
  119. package/dist/cli/plugin.js +291 -0
  120. package/dist/cli/plugin.js.map +1 -0
  121. package/dist/cli/promote-command.test.d.ts +2 -0
  122. package/dist/cli/promote-command.test.d.ts.map +1 -0
  123. package/dist/cli/promote-command.test.js +151 -0
  124. package/dist/cli/promote-command.test.js.map +1 -0
  125. package/dist/cli/promote.d.ts +12 -0
  126. package/dist/cli/promote.d.ts.map +1 -0
  127. package/dist/cli/promote.js +364 -0
  128. package/dist/cli/promote.js.map +1 -0
  129. package/dist/cli/secret-scan.d.ts +21 -0
  130. package/dist/cli/secret-scan.d.ts.map +1 -0
  131. package/dist/cli/secret-scan.js +114 -0
  132. package/dist/cli/secret-scan.js.map +1 -0
  133. package/dist/cli/sync-check.d.ts.map +1 -1
  134. package/dist/cli/sync-check.js +9 -0
  135. package/dist/cli/sync-check.js.map +1 -1
  136. package/dist/cli/sync-check.test.js +5 -4
  137. package/dist/cli/sync-check.test.js.map +1 -1
  138. package/dist/cli/team-commands.test.js +14 -2
  139. package/dist/cli/team-commands.test.js.map +1 -1
  140. package/dist/cli/team-sources.test.js +10 -0
  141. package/dist/cli/team-sources.test.js.map +1 -1
  142. package/dist/cli/types.d.ts +1 -1
  143. package/dist/cli/types.d.ts.map +1 -1
  144. package/dist/cli/update.d.ts.map +1 -1
  145. package/dist/cli/update.js +18 -0
  146. package/dist/cli/update.js.map +1 -1
  147. package/dist/cli/windsurf-target.test.d.ts +2 -0
  148. package/dist/cli/windsurf-target.test.d.ts.map +1 -0
  149. package/dist/cli/windsurf-target.test.js +62 -0
  150. package/dist/cli/windsurf-target.test.js.map +1 -0
  151. package/dist/orchestrator/plugins/agent-plugins.test.d.ts +2 -0
  152. package/dist/orchestrator/plugins/agent-plugins.test.d.ts.map +1 -0
  153. package/dist/orchestrator/plugins/agent-plugins.test.js +32 -0
  154. package/dist/orchestrator/plugins/agent-plugins.test.js.map +1 -0
  155. package/dist/orchestrator/plugins/registry.test.d.ts +2 -0
  156. package/dist/orchestrator/plugins/registry.test.d.ts.map +1 -0
  157. package/dist/orchestrator/plugins/registry.test.js +37 -0
  158. package/dist/orchestrator/plugins/registry.test.js.map +1 -0
  159. package/package.json +2 -1
  160. package/src/cli/adapters/antigravity.ts +2 -1
  161. package/src/cli/adapters/claude-code.ts +0 -1
  162. package/src/cli/adapters/cursor.ts +8 -1
  163. package/src/cli/adapters/opencode.ts +18 -6
  164. package/src/cli/adapters/rules-dir-base.test.ts +28 -18
  165. package/src/cli/adapters/rules-dir-base.ts +51 -90
  166. package/src/cli/adapters/single-file-base.ts +53 -14
  167. package/src/cli/adapters/vscode.ts +2 -1
  168. package/src/cli/adapters/windsurf.ts +11 -1
  169. package/src/cli/agent-plugin.test.ts +267 -0
  170. package/src/cli/agent-plugin.ts +469 -0
  171. package/src/cli/baseline.ts +115 -32
  172. package/src/cli/ci.ts +19 -4
  173. package/src/cli/codex-target.test.ts +15 -1
  174. package/src/cli/convoy/gates.ts +9 -142
  175. package/src/cli/copy.ts +0 -25
  176. package/src/cli/dispatcher.test.ts +2 -2
  177. package/src/cli/docs-accuracy.test.ts +2 -0
  178. package/src/cli/doctor.test.ts +2 -2
  179. package/src/cli/doctor.ts +2 -0
  180. package/src/cli/explain.ts +36 -2
  181. package/src/cli/fixtures/lessons-template-1.0.md +70 -0
  182. package/src/cli/init.test.ts +82 -42
  183. package/src/cli/layers.test.ts +2 -2
  184. package/src/cli/layers.ts +144 -14
  185. package/src/cli/legacy-install.test.ts +11 -1
  186. package/src/cli/lesson-command.test.ts +117 -0
  187. package/src/cli/lesson.ts +215 -266
  188. package/src/cli/lessons.test.ts +254 -0
  189. package/src/cli/lessons.ts +540 -0
  190. package/src/cli/managed-paths.ts +3 -1
  191. package/src/cli/mcp-audit.ts +2 -0
  192. package/src/cli/mcp-upgrade.test.ts +26 -1
  193. package/src/cli/mcp.ts +22 -3
  194. package/src/cli/pack-plugins.ts +70 -0
  195. package/src/cli/plugin-command.test.ts +125 -0
  196. package/src/cli/plugin.ts +309 -0
  197. package/src/cli/promote-command.test.ts +170 -0
  198. package/src/cli/promote.ts +371 -0
  199. package/src/cli/secret-scan.ts +154 -0
  200. package/src/cli/sync-check.test.ts +5 -4
  201. package/src/cli/sync-check.ts +9 -0
  202. package/src/cli/team-commands.test.ts +18 -2
  203. package/src/cli/team-sources.test.ts +11 -0
  204. package/src/cli/types.ts +1 -1
  205. package/src/cli/update.ts +20 -0
  206. package/src/cli/windsurf-target.test.ts +70 -0
  207. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  208. package/src/orchestrator/agents/researcher.agent.md +1 -1
  209. package/src/orchestrator/customizations/LESSONS-LEARNED.md +10 -66
  210. package/src/orchestrator/customizations/README.md +2 -1
  211. package/src/orchestrator/customizations/logs/README.md +1 -1
  212. package/src/orchestrator/plugins/agent-plugins.test.ts +34 -0
  213. package/src/orchestrator/plugins/astro/mcp.json +9 -0
  214. package/src/orchestrator/plugins/astro/plugin.json +21 -0
  215. package/src/orchestrator/plugins/chrome-devtools/mcp.json +13 -0
  216. package/src/orchestrator/plugins/chrome-devtools/plugin.json +21 -0
  217. package/src/orchestrator/plugins/cloudflare/mcp.json +9 -0
  218. package/src/orchestrator/plugins/cloudflare/plugin.json +21 -0
  219. package/src/orchestrator/plugins/contentful/mcp.json +13 -0
  220. package/src/orchestrator/plugins/contentful/plugin.json +21 -0
  221. package/src/orchestrator/plugins/convex/mcp.json +15 -0
  222. package/src/orchestrator/plugins/convex/plugin.json +21 -0
  223. package/src/orchestrator/plugins/coolify/mcp.json +13 -0
  224. package/src/orchestrator/plugins/coolify/plugin.json +25 -0
  225. package/src/orchestrator/plugins/cypress/plugin.json +21 -0
  226. package/src/orchestrator/plugins/drizzle/plugin.json +21 -0
  227. package/src/orchestrator/plugins/expo/mcp.json +9 -0
  228. package/src/orchestrator/plugins/expo/plugin.json +21 -0
  229. package/src/orchestrator/plugins/figma/mcp.json +9 -0
  230. package/src/orchestrator/plugins/figma/plugin.json +21 -0
  231. package/src/orchestrator/plugins/hetzner/plugin.json +24 -0
  232. package/src/orchestrator/plugins/jira/mcp.json +9 -0
  233. package/src/orchestrator/plugins/jira/plugin.json +21 -0
  234. package/src/orchestrator/plugins/linear/mcp.json +9 -0
  235. package/src/orchestrator/plugins/linear/plugin.json +21 -0
  236. package/src/orchestrator/plugins/netlify/mcp.json +13 -0
  237. package/src/orchestrator/plugins/netlify/plugin.json +21 -0
  238. package/src/orchestrator/plugins/nextjs/mcp.json +13 -0
  239. package/src/orchestrator/plugins/nextjs/plugin.json +21 -0
  240. package/src/orchestrator/plugins/notion/mcp.json +9 -0
  241. package/src/orchestrator/plugins/notion/plugin.json +21 -0
  242. package/src/orchestrator/plugins/nx/mcp.json +14 -0
  243. package/src/orchestrator/plugins/nx/plugin.json +21 -0
  244. package/src/orchestrator/plugins/playwright/mcp.json +13 -0
  245. package/src/orchestrator/plugins/playwright/plugin.json +21 -0
  246. package/src/orchestrator/plugins/prisma/mcp.json +14 -0
  247. package/src/orchestrator/plugins/prisma/plugin.json +21 -0
  248. package/src/orchestrator/plugins/registry.test.ts +42 -0
  249. package/src/orchestrator/plugins/resend/mcp.json +13 -0
  250. package/src/orchestrator/plugins/resend/plugin.json +24 -0
  251. package/src/orchestrator/plugins/sanity/mcp.json +9 -0
  252. package/src/orchestrator/plugins/sanity/plugin.json +21 -0
  253. package/src/orchestrator/plugins/sentry/mcp.json +12 -0
  254. package/src/orchestrator/plugins/sentry/plugin.json +24 -0
  255. package/src/orchestrator/plugins/slack/mcp.json +13 -0
  256. package/src/orchestrator/plugins/slack/plugin.json +24 -0
  257. package/src/orchestrator/plugins/strapi/mcp.json +13 -0
  258. package/src/orchestrator/plugins/strapi/plugin.json +21 -0
  259. package/src/orchestrator/plugins/stripe/mcp.json +9 -0
  260. package/src/orchestrator/plugins/stripe/plugin.json +21 -0
  261. package/src/orchestrator/plugins/supabase/mcp.json +9 -0
  262. package/src/orchestrator/plugins/supabase/plugin.json +21 -0
  263. package/src/orchestrator/plugins/teams/plugin.json +24 -0
  264. package/src/orchestrator/plugins/trello/mcp.json +13 -0
  265. package/src/orchestrator/plugins/trello/plugin.json +25 -0
  266. package/src/orchestrator/plugins/turborepo/plugin.json +21 -0
  267. package/src/orchestrator/plugins/vercel/mcp.json +9 -0
  268. package/src/orchestrator/plugins/vercel/plugin.json +21 -0
  269. package/src/orchestrator/plugins/vitest/plugin.json +21 -0
  270. package/src/orchestrator/skill-config-links.test.ts +2 -1
  271. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +1 -1
  272. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  273. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  274. package/src/orchestrator/skills/memory-merger/SKILL.md +17 -21
  275. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +44 -23
  276. package/src/orchestrator/skills/self-improvement/SKILL.md +30 -15
  277. /package/src/orchestrator/plugins/astro/{SKILL.md → skills/astro-framework/SKILL.md} +0 -0
  278. /package/src/orchestrator/plugins/chrome-devtools/{SKILL.md → skills/browser-testing/SKILL.md} +0 -0
  279. /package/src/orchestrator/plugins/cloudflare/{SKILL.md → skills/cloudflare-platform/SKILL.md} +0 -0
  280. /package/src/orchestrator/plugins/contentful/{SKILL.md → skills/contentful-cms/SKILL.md} +0 -0
  281. /package/src/orchestrator/plugins/convex/{SKILL.md → skills/convex-database/SKILL.md} +0 -0
  282. /package/src/orchestrator/plugins/coolify/{SKILL.md → skills/coolify-deployment/SKILL.md} +0 -0
  283. /package/src/orchestrator/plugins/cypress/{SKILL.md → skills/cypress-testing/SKILL.md} +0 -0
  284. /package/src/orchestrator/plugins/drizzle/{SKILL.md → skills/drizzle-orm/SKILL.md} +0 -0
  285. /package/src/orchestrator/plugins/expo/{SKILL.md → skills/expo-development/SKILL.md} +0 -0
  286. /package/src/orchestrator/plugins/figma/{SKILL.md → skills/figma-design/SKILL.md} +0 -0
  287. /package/src/orchestrator/plugins/hetzner/{SKILL.md → skills/hetzner-cloud/SKILL.md} +0 -0
  288. /package/src/orchestrator/plugins/jira/{SKILL.md → skills/jira-management/SKILL.md} +0 -0
  289. /package/src/orchestrator/plugins/linear/{SKILL.md → skills/linear-task-management/SKILL.md} +0 -0
  290. /package/src/orchestrator/plugins/netlify/{SKILL.md → skills/netlify-deployment/SKILL.md} +0 -0
  291. /package/src/orchestrator/plugins/nextjs/{SKILL.md → skills/nextjs-framework/SKILL.md} +0 -0
  292. /package/src/orchestrator/plugins/notion/{SKILL.md → skills/notion-knowledge-management/SKILL.md} +0 -0
  293. /package/src/orchestrator/plugins/nx/{SKILL.md → skills/nx-workspace/SKILL.md} +0 -0
  294. /package/src/orchestrator/plugins/playwright/{SKILL.md → skills/playwright-testing/SKILL.md} +0 -0
  295. /package/src/orchestrator/plugins/prisma/{SKILL.md → skills/prisma-database/SKILL.md} +0 -0
  296. /package/src/orchestrator/plugins/resend/{SKILL.md → skills/resend-email/SKILL.md} +0 -0
  297. /package/src/orchestrator/plugins/sanity/{SKILL.md → skills/sanity-cms/SKILL.md} +0 -0
  298. /package/src/orchestrator/plugins/sentry/{SKILL.md → skills/sentry-monitoring/SKILL.md} +0 -0
  299. /package/src/orchestrator/plugins/slack/{SKILL.md → skills/slack-notifications/SKILL.md} +0 -0
  300. /package/src/orchestrator/plugins/strapi/{SKILL.md → skills/strapi-cms/SKILL.md} +0 -0
  301. /package/src/orchestrator/plugins/stripe/{SKILL.md → skills/stripe-payments/SKILL.md} +0 -0
  302. /package/src/orchestrator/plugins/supabase/{SKILL.md → skills/supabase-database/SKILL.md} +0 -0
  303. /package/src/orchestrator/plugins/teams/{SKILL.md → skills/teams-notifications/SKILL.md} +0 -0
  304. /package/src/orchestrator/plugins/trello/{SKILL.md → skills/trello-task-management/SKILL.md} +0 -0
  305. /package/src/orchestrator/plugins/turborepo/{SKILL.md → skills/turborepo-monorepo/SKILL.md} +0 -0
  306. /package/src/orchestrator/plugins/vercel/{SKILL.md → skills/vercel-deployment/SKILL.md} +0 -0
  307. /package/src/orchestrator/plugins/vitest/{SKILL.md → skills/vitest-testing/SKILL.md} +0 -0
@@ -0,0 +1,254 @@
1
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { join, resolve } from 'node:path'
4
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
5
+ import {
6
+ INDEX_MARKER,
7
+ checkLessons,
8
+ citedPath,
9
+ fingerprintsOf,
10
+ lessonsIndexDrift,
11
+ newLessonId,
12
+ parseLegacyLessons,
13
+ parseLesson,
14
+ readLessons,
15
+ renderIndex,
16
+ renderLesson,
17
+ slugOf,
18
+ staleCitations,
19
+ syncLessons,
20
+ type Lesson,
21
+ } from './lessons.js'
22
+
23
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
24
+
25
+ /** The shape agents actually left the old file in: entries after the index, odd categories, a stray fence. */
26
+ const LEGACY = `\`\`\`\`markdown
27
+ # Lessons Learned
28
+
29
+ Intro the team wrote.
30
+
31
+ ### LES-001: Observability logging is mandatory
32
+
33
+ | Field | Value |
34
+ |-------|-------|
35
+ | **Category** | \`general\` |
36
+ | **Added** | 2026-03-01 |
37
+ | **Severity** | \`high\` (blocks work) |
38
+
39
+ **Problem:** Nothing was logged.
40
+
41
+ **Correct approach:** Log every session.
42
+
43
+ ---
44
+
45
+ ### LES-002: Writing files via terminal fails when content contains \`!\`
46
+
47
+ | Field | Value |
48
+ |-------|-------|
49
+ | **Category** | \`tooling\` |
50
+ | **Added** | 2026-03-16 |
51
+ | **Severity** | \`high\` (blocks file creation) |
52
+
53
+ **Problem:** zsh history expansion.
54
+
55
+ **Wrong approach:**
56
+ - heredocs
57
+
58
+ ## Index by Category
59
+
60
+ | Category | Lessons |
61
+ |----------|---------|
62
+ | \`general\` | LES-001, LES-002 |
63
+
64
+ \`\`\`\`
65
+
66
+ ### LES-007: Use N/A for tracker_issue when no tracker is configured
67
+
68
+ | Field | Value |
69
+ |-------|-------|
70
+ | **Category** | \`general\` |
71
+ | **Added** | 2026-03-05 |
72
+ | **Severity** | \`medium\` (wastes 5+ min) |
73
+
74
+ **Problem:** TAS-PENDING everywhere.
75
+ `
76
+
77
+ function lesson(over: Partial<Lesson> = {}): Lesson {
78
+ return {
79
+ id: '2026-10-02-quote-shell-variables',
80
+ title: 'Always quote shell variables',
81
+ category: 'terminal',
82
+ severity: 'medium',
83
+ added: '2026-10-02',
84
+ citations: [],
85
+ status: 'active',
86
+ body: '**Problem:** Paths with spaces break.',
87
+ file: '2026-10-02-quote-shell-variables.md',
88
+ ...over,
89
+ }
90
+ }
91
+
92
+ describe('naming a lesson', () => {
93
+ it('slugs a title to lowercase words, under 50 characters', () => {
94
+ expect(slugOf('Always quote $SHELL variables — even in CI!')).toBe('always-quote-shell-variables-even-in-ci')
95
+ expect(slugOf('a'.repeat(80))).toBe('lesson')
96
+ expect(slugOf('Café au lait')).toBe('cafe-au-lait')
97
+ })
98
+
99
+ it('gives two lessons with the same title on the same day different ids', () => {
100
+ const taken = new Set(['2026-10-02-quote-shell-variables'])
101
+ expect(newLessonId('Quote shell variables', '2026-10-02', taken)).toBe('2026-10-02-quote-shell-variables-2')
102
+ })
103
+ })
104
+
105
+ describe('a lesson file', () => {
106
+ it('round-trips through its frontmatter, keeping dates as strings', () => {
107
+ const l = lesson({ citations: ['scripts/a.sh:12'], verified: '2026-10-02', fingerprints: { 'scripts/a.sh': '0123456789ab' } })
108
+ const parsed = parseLesson(renderLesson(l), l.file)
109
+ expect(parsed).toEqual(l)
110
+ })
111
+
112
+ it('names what is wrong with a file that is not a lesson', () => {
113
+ expect(parseLesson('just text', 'x.md')).toBe('has no frontmatter')
114
+ expect(parseLesson('---\nid: x\n---\nbody', 'x.md')).toBe('has no title')
115
+ })
116
+
117
+ it('cites a path, with or without a line', () => {
118
+ expect(citedPath('src/a.ts:12')).toBe('src/a.ts')
119
+ expect(citedPath('./src/a.ts#L3-L9')).toBe('src/a.ts')
120
+ expect(citedPath('src/a.ts')).toBe('src/a.ts')
121
+ })
122
+ })
123
+
124
+ describe('the old single-file log', () => {
125
+ it('reads every entry wherever it sits, with what it says', () => {
126
+ const found = parseLegacyLessons(LEGACY)
127
+ expect(found.map((l) => l.id)).toEqual(['LES-001', 'LES-002', 'LES-007'])
128
+ expect(found[1]).toMatchObject({ category: 'tooling', severity: 'high', added: '2026-03-16' })
129
+ expect(found[0].body).toBe('**Problem:** Nothing was logged.\n\n**Correct approach:** Log every session.')
130
+ expect(found[1].body).toContain('- heredocs')
131
+ expect(found[1].body).not.toContain('````')
132
+ })
133
+ })
134
+
135
+ describe('syncing lessons', () => {
136
+ let dir: string
137
+ beforeEach(() => {
138
+ dir = mkdtempSync(join(tmpdir(), 'oc-lessons-'))
139
+ })
140
+ afterEach(() => rmSync(dir, { recursive: true, force: true }))
141
+
142
+ it('moves an old log into one file per lesson, keeps a backup, and indexes them', () => {
143
+ writeFileSync(join(dir, 'LESSONS-LEARNED.md'), LEGACY)
144
+ const out = syncLessons(dir)
145
+ expect(out.migrated).toBe(3)
146
+ expect(out.backup).toMatch(/LESSONS-LEARNED\.md\.opencastle-backup$/)
147
+ expect(readFileSync(join(dir, 'LESSONS-LEARNED.md.opencastle-backup'), 'utf8')).toBe(LEGACY)
148
+ expect(readdirSync(join(dir, 'lessons')).sort()).toEqual([
149
+ 'LES-001-observability-logging-is-mandatory.md',
150
+ 'LES-002-writing-files-via-terminal-fails-when-content.md',
151
+ 'LES-007-use-n-a-for-tracker-issue-when-no-tracker-is.md',
152
+ ])
153
+ const index = readFileSync(join(dir, 'LESSONS-LEARNED.md'), 'utf8')
154
+ expect(index.startsWith(INDEX_MARKER)).toBe(true)
155
+ expect(index).toContain('## tooling')
156
+ expect(lessonsIndexDrift(dir)).toBeNull()
157
+ })
158
+
159
+ it('does it once: a second sync changes nothing', () => {
160
+ writeFileSync(join(dir, 'LESSONS-LEARNED.md'), LEGACY)
161
+ syncLessons(dir)
162
+ const before = readFileSync(join(dir, 'LESSONS-LEARNED.md'), 'utf8')
163
+ expect(syncLessons(dir)).toMatchObject({ migrated: 0, index: 'unchanged' })
164
+ expect(readFileSync(join(dir, 'LESSONS-LEARNED.md'), 'utf8')).toBe(before)
165
+ })
166
+
167
+ it('replaces an untouched template without a backup', () => {
168
+ // As 1.0.0 shipped it, kept as a fixture: CI's shallow clone has no history to read it from.
169
+ const template = readFileSync(join(import.meta.dirname, 'fixtures', 'lessons-template-1.0.md'), 'utf8')
170
+ writeFileSync(join(dir, 'LESSONS-LEARNED.md'), template)
171
+ const out = syncLessons(dir)
172
+ expect(out).toMatchObject({ migrated: 0, index: 'updated' })
173
+ expect(out.backup).toBeUndefined()
174
+ expect(existsSync(join(dir, 'LESSONS-LEARNED.md.opencastle-backup'))).toBe(false)
175
+ })
176
+
177
+ it('leaves a project that removed the index alone', () => {
178
+ expect(syncLessons(dir).index).toBe('absent')
179
+ expect(existsSync(join(dir, 'LESSONS-LEARNED.md'))).toBe(false)
180
+ })
181
+
182
+ it('reports an index a merge left behind, and sync rebuilds it', () => {
183
+ writeFileSync(join(dir, 'LESSONS-LEARNED.md'), renderIndex([]))
184
+ mkdirSync(join(dir, 'lessons'))
185
+ writeFileSync(join(dir, 'lessons', 'a.md'), renderLesson(lesson()))
186
+ expect(lessonsIndexDrift(dir)).toMatch(/does not list/)
187
+ syncLessons(dir)
188
+ expect(lessonsIndexDrift(dir)).toBeNull()
189
+ expect(readFileSync(join(dir, 'LESSONS-LEARNED.md'), 'utf8')).toContain('Always quote shell variables')
190
+ })
191
+
192
+ it('lists archived lessons apart, with where they went', () => {
193
+ const index = renderIndex([lesson(), lesson({ id: 'b', file: 'b.md', title: 'Old', status: 'archived', mergedInto: 'skills/x/SKILL.md' })])
194
+ expect(index).toMatch(/## Archived[\s\S]*\*\*Old\*\* → `skills\/x\/SKILL\.md`/)
195
+ expect(index.split('## Archived')[0]).not.toContain('**Old**')
196
+ })
197
+ })
198
+
199
+ describe('the shipped template', () => {
200
+ it('is the index of no lessons, exactly as sync writes it', () => {
201
+ const shipped = readFileSync(join(pkgRoot, 'src', 'orchestrator', 'customizations', 'LESSONS-LEARNED.md'), 'utf8')
202
+ expect(shipped).toBe(renderIndex([]))
203
+ })
204
+ })
205
+
206
+ describe('citations against the code', () => {
207
+ let project: string
208
+ beforeEach(() => {
209
+ project = mkdtempSync(join(tmpdir(), 'oc-cite-'))
210
+ mkdirSync(join(project, 'src'))
211
+ writeFileSync(join(project, 'src', 'a.ts'), 'export const a = 1\n')
212
+ writeFileSync(join(project, 'src', 'b.ts'), 'export const b = 1\n')
213
+ })
214
+ afterEach(() => rmSync(project, { recursive: true, force: true }))
215
+
216
+ const verifiedNow = (citations: string[], over: Partial<Lesson> = {}): Lesson =>
217
+ lesson({ citations, verified: '2026-10-01', fingerprints: fingerprintsOf(project, citations), ...over })
218
+
219
+ it('says nothing while the cited code is as it was verified', () => {
220
+ expect(staleCitations(project, [verifiedNow(['src/a.ts:1'])])).toEqual([])
221
+ })
222
+
223
+ it('names a cited file that changed since, and one that is gone', () => {
224
+ const l = verifiedNow(['src/a.ts:1', 'src/b.ts'])
225
+ writeFileSync(join(project, 'src', 'a.ts'), 'export const a = 2\n')
226
+ rmSync(join(project, 'src', 'b.ts'))
227
+ expect(staleCitations(project, [l]).map((s) => `${s.citation}:${s.why}`)).toEqual(['src/a.ts:1:changed', 'src/b.ts:missing'])
228
+ })
229
+
230
+ it('does not read a checkout with CRLF line endings as a change', () => {
231
+ const l = verifiedNow(['src/a.ts'])
232
+ writeFileSync(join(project, 'src', 'a.ts'), 'export const a = 1\r\n')
233
+ expect(staleCitations(project, [l])).toEqual([])
234
+ })
235
+
236
+ it('checks a citation with no fingerprint for existence only', () => {
237
+ writeFileSync(join(project, 'src', 'a.ts'), 'anything\n')
238
+ expect(staleCitations(project, [lesson({ citations: ['src/a.ts'] })])).toEqual([])
239
+ })
240
+
241
+ it('doctor warns with the lesson, the citation and the command that clears it', () => {
242
+ const dir = join(project, '.opencastle')
243
+ mkdirSync(join(dir, 'lessons'), { recursive: true })
244
+ writeFileSync(join(dir, 'lessons', 'a.md'), renderLesson(verifiedNow(['src/a.ts'], { id: 'a' })))
245
+ syncLessons(dir)
246
+ expect(checkLessons(project).warning).toBeUndefined()
247
+ writeFileSync(join(project, 'src', 'a.ts'), 'export const a = 3\n')
248
+ const result = checkLessons(project)
249
+ expect(result.warning).toBe(true)
250
+ expect(result.detail).toBe('a cites src/a.ts, which has changed since it was verified on 2026-10-01')
251
+ expect(result.fix).toContain('opencastle lesson verify a')
252
+ expect(readLessons(dir).lessons).toHaveLength(1)
253
+ })
254
+ })