opencastle 1.5.0 → 1.6.1

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 (204) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/adapters/antigravity.d.ts +1 -1
  3. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  4. package/dist/cli/adapters/claude-code.d.ts +1 -1
  5. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  6. package/dist/cli/adapters/claude-code.js +1 -0
  7. package/dist/cli/adapters/claude-code.js.map +1 -1
  8. package/dist/cli/adapters/codex.d.ts +1 -1
  9. package/dist/cli/adapters/codex.d.ts.map +1 -1
  10. package/dist/cli/adapters/cursor.d.ts +1 -1
  11. package/dist/cli/adapters/cursor.d.ts.map +1 -1
  12. package/dist/cli/adapters/cursor.js +6 -0
  13. package/dist/cli/adapters/cursor.js.map +1 -1
  14. package/dist/cli/adapters/opencode.d.ts +1 -1
  15. package/dist/cli/adapters/opencode.d.ts.map +1 -1
  16. package/dist/cli/adapters/rules-dir-base.d.ts +13 -1
  17. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  18. package/dist/cli/adapters/rules-dir-base.js +37 -18
  19. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  20. package/dist/cli/adapters/rules-dir-base.test.js +34 -0
  21. package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
  22. package/dist/cli/adapters/single-file-base.d.ts +8 -0
  23. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  24. package/dist/cli/adapters/single-file-base.js +48 -22
  25. package/dist/cli/adapters/single-file-base.js.map +1 -1
  26. package/dist/cli/adapters/windsurf.d.ts +1 -1
  27. package/dist/cli/adapters/windsurf.d.ts.map +1 -1
  28. package/dist/cli/bootstrap-on-init.test.js +11 -0
  29. package/dist/cli/bootstrap-on-init.test.js.map +1 -1
  30. package/dist/cli/command-namespace.test.js +17 -0
  31. package/dist/cli/command-namespace.test.js.map +1 -1
  32. package/dist/cli/convoy/engine.d.ts +12 -0
  33. package/dist/cli/convoy/engine.d.ts.map +1 -1
  34. package/dist/cli/convoy/engine.git.test.js +55 -0
  35. package/dist/cli/convoy/engine.git.test.js.map +1 -1
  36. package/dist/cli/convoy/engine.js +39 -1
  37. package/dist/cli/convoy/engine.js.map +1 -1
  38. package/dist/cli/convoy/findings.d.ts +35 -0
  39. package/dist/cli/convoy/findings.d.ts.map +1 -0
  40. package/dist/cli/convoy/findings.js +100 -0
  41. package/dist/cli/convoy/findings.js.map +1 -0
  42. package/dist/cli/convoy/findings.test.d.ts +2 -0
  43. package/dist/cli/convoy/findings.test.d.ts.map +1 -0
  44. package/dist/cli/convoy/findings.test.js +75 -0
  45. package/dist/cli/convoy/findings.test.js.map +1 -0
  46. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  47. package/dist/cli/convoy/isolation.js +2 -1
  48. package/dist/cli/convoy/isolation.js.map +1 -1
  49. package/dist/cli/convoy/worktree.d.ts +5 -0
  50. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  51. package/dist/cli/convoy/worktree.js +12 -0
  52. package/dist/cli/convoy/worktree.js.map +1 -1
  53. package/dist/cli/docs-accuracy.test.js +34 -0
  54. package/dist/cli/docs-accuracy.test.js.map +1 -1
  55. package/dist/cli/doctor.d.ts +11 -0
  56. package/dist/cli/doctor.d.ts.map +1 -1
  57. package/dist/cli/doctor.js +72 -8
  58. package/dist/cli/doctor.js.map +1 -1
  59. package/dist/cli/doctor.test.js +82 -1
  60. package/dist/cli/doctor.test.js.map +1 -1
  61. package/dist/cli/init.d.ts.map +1 -1
  62. package/dist/cli/init.js +58 -53
  63. package/dist/cli/init.js.map +1 -1
  64. package/dist/cli/init.test.js +28 -23
  65. package/dist/cli/init.test.js.map +1 -1
  66. package/dist/cli/layers.d.ts +20 -0
  67. package/dist/cli/layers.d.ts.map +1 -1
  68. package/dist/cli/layers.js +53 -1
  69. package/dist/cli/layers.js.map +1 -1
  70. package/dist/cli/layers.test.js +67 -1
  71. package/dist/cli/layers.test.js.map +1 -1
  72. package/dist/cli/lessons.d.ts +10 -0
  73. package/dist/cli/lessons.d.ts.map +1 -1
  74. package/dist/cli/lessons.js +26 -1
  75. package/dist/cli/lessons.js.map +1 -1
  76. package/dist/cli/lessons.test.js +38 -1
  77. package/dist/cli/lessons.test.js.map +1 -1
  78. package/dist/cli/plan.test.js +10 -8
  79. package/dist/cli/plan.test.js.map +1 -1
  80. package/dist/cli/sync-check.test.js +14 -2
  81. package/dist/cli/sync-check.test.js.map +1 -1
  82. package/dist/cli/types.d.ts +2 -1
  83. package/dist/cli/types.d.ts.map +1 -1
  84. package/dist/cli/types.js.map +1 -1
  85. package/dist/orchestrator/plugins/notion/config.d.ts.map +1 -1
  86. package/dist/orchestrator/plugins/notion/config.js +21 -17
  87. package/dist/orchestrator/plugins/notion/config.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/cli/adapters/claude-code.ts +1 -0
  90. package/src/cli/adapters/cursor.ts +6 -0
  91. package/src/cli/adapters/rules-dir-base.test.ts +41 -0
  92. package/src/cli/adapters/rules-dir-base.ts +47 -19
  93. package/src/cli/adapters/single-file-base.ts +63 -31
  94. package/src/cli/bootstrap-on-init.test.ts +12 -0
  95. package/src/cli/command-namespace.test.ts +17 -0
  96. package/src/cli/convoy/engine.git.test.ts +59 -0
  97. package/src/cli/convoy/engine.ts +44 -0
  98. package/src/cli/convoy/findings.test.ts +86 -0
  99. package/src/cli/convoy/findings.ts +129 -0
  100. package/src/cli/convoy/isolation.ts +2 -1
  101. package/src/cli/convoy/worktree.ts +12 -0
  102. package/src/cli/docs-accuracy.test.ts +42 -0
  103. package/src/cli/doctor.test.ts +101 -1
  104. package/src/cli/doctor.ts +75 -9
  105. package/src/cli/init.test.ts +27 -22
  106. package/src/cli/init.ts +62 -57
  107. package/src/cli/layers.test.ts +72 -1
  108. package/src/cli/layers.ts +52 -1
  109. package/src/cli/lessons.test.ts +48 -0
  110. package/src/cli/lessons.ts +27 -1
  111. package/src/cli/plan.test.ts +10 -8
  112. package/src/cli/sync-check.test.ts +16 -2
  113. package/src/cli/types.ts +2 -1
  114. package/src/orchestrator/agent-workflows/feature-implementation.md +1 -1
  115. package/src/orchestrator/agents/team-lead.agent.md +5 -5
  116. package/src/orchestrator/agents/testing-expert.agent.md +2 -2
  117. package/src/orchestrator/customizations/LESSONS-LEARNED.md +1 -1
  118. package/src/orchestrator/instructions/ai-optimization.instructions.md +6 -23
  119. package/src/orchestrator/instructions/general.instructions.md +22 -95
  120. package/src/orchestrator/plugins/astro/skills/astro-framework/SKILL.md +1 -3
  121. package/src/orchestrator/plugins/chrome-devtools/skills/browser-testing/SKILL.md +3 -5
  122. package/src/orchestrator/plugins/cloudflare/skills/cloudflare-platform/SKILL.md +2 -2
  123. package/src/orchestrator/plugins/contentful/skills/contentful-cms/SKILL.md +1 -1
  124. package/src/orchestrator/plugins/convex/skills/convex-database/SKILL.md +1 -3
  125. package/src/orchestrator/plugins/coolify/skills/coolify-deployment/SKILL.md +1 -1
  126. package/src/orchestrator/plugins/cypress/skills/cypress-testing/SKILL.md +1 -1
  127. package/src/orchestrator/plugins/drizzle/skills/drizzle-orm/SKILL.md +1 -1
  128. package/src/orchestrator/plugins/expo/skills/expo-development/SKILL.md +2 -2
  129. package/src/orchestrator/plugins/figma/skills/figma-design/SKILL.md +1 -3
  130. package/src/orchestrator/plugins/hetzner/skills/hetzner-cloud/SKILL.md +1 -1
  131. package/src/orchestrator/plugins/jira/skills/jira-management/SKILL.md +1 -3
  132. package/src/orchestrator/plugins/linear/skills/linear-task-management/SKILL.md +1 -3
  133. package/src/orchestrator/plugins/netlify/skills/netlify-deployment/SKILL.md +2 -2
  134. package/src/orchestrator/plugins/nextjs/skills/nextjs-framework/SKILL.md +13 -6
  135. package/src/orchestrator/plugins/notion/config.ts +21 -17
  136. package/src/orchestrator/plugins/notion/skills/notion-knowledge-management/SKILL.md +8 -16
  137. package/src/orchestrator/plugins/nx/skills/nx-workspace/SKILL.md +2 -4
  138. package/src/orchestrator/plugins/playwright/skills/playwright-testing/SKILL.md +1 -3
  139. package/src/orchestrator/plugins/prisma/skills/prisma-database/SKILL.md +1 -3
  140. package/src/orchestrator/plugins/resend/skills/resend-email/SKILL.md +2 -2
  141. package/src/orchestrator/plugins/sanity/skills/sanity-cms/SKILL.md +1 -3
  142. package/src/orchestrator/plugins/sentry/skills/sentry-monitoring/SKILL.md +1 -1
  143. package/src/orchestrator/plugins/slack/skills/slack-notifications/SKILL.md +1 -3
  144. package/src/orchestrator/plugins/strapi/skills/strapi-cms/SKILL.md +1 -3
  145. package/src/orchestrator/plugins/stripe/skills/stripe-payments/SKILL.md +4 -4
  146. package/src/orchestrator/plugins/supabase/skills/supabase-database/SKILL.md +3 -5
  147. package/src/orchestrator/plugins/teams/skills/teams-notifications/SKILL.md +1 -3
  148. package/src/orchestrator/plugins/trello/skills/trello-task-management/SKILL.md +1 -1
  149. package/src/orchestrator/plugins/turborepo/skills/turborepo-monorepo/SKILL.md +15 -88
  150. package/src/orchestrator/plugins/vercel/skills/vercel-deployment/SKILL.md +2 -2
  151. package/src/orchestrator/plugins/vitest/skills/vitest-testing/SKILL.md +17 -150
  152. package/src/orchestrator/prompts/assess-complexity.prompt.md +1 -0
  153. package/src/orchestrator/prompts/create-skill.prompt.md +13 -67
  154. package/src/orchestrator/prompts/fix-convoy.prompt.md +1 -0
  155. package/src/orchestrator/prompts/fix-prd.prompt.md +1 -0
  156. package/src/orchestrator/prompts/generate-prd.prompt.md +1 -0
  157. package/src/orchestrator/prompts/resolve-pr-comments.prompt.md +2 -2
  158. package/src/orchestrator/prompts/validate-convoy.prompt.md +1 -0
  159. package/src/orchestrator/prompts/validate-prd.prompt.md +1 -0
  160. package/src/orchestrator/skills/accessibility-standards/REFERENCE.md +17 -12
  161. package/src/orchestrator/skills/accessibility-standards/SKILL.md +1 -1
  162. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -5
  163. package/src/orchestrator/skills/agent-hooks/SKILL.md +8 -6
  164. package/src/orchestrator/skills/api-patterns/SKILL.md +1 -1
  165. package/src/orchestrator/skills/code-commenting/SKILL.md +1 -1
  166. package/src/orchestrator/skills/context-map/REFERENCE.md +0 -2
  167. package/src/orchestrator/skills/context-map/SKILL.md +2 -2
  168. package/src/orchestrator/skills/data-engineering/REFERENCE.md +3 -9
  169. package/src/orchestrator/skills/data-engineering/SKILL.md +9 -16
  170. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  171. package/src/orchestrator/skills/deployment-infrastructure/SKILL.md +4 -4
  172. package/src/orchestrator/skills/documentation-standards/SKILL.md +4 -2
  173. package/src/orchestrator/skills/fast-review/REFERENCE.md +0 -2
  174. package/src/orchestrator/skills/fast-review/SKILL.md +5 -5
  175. package/src/orchestrator/skills/frontend-design/REFERENCE.md +6 -28
  176. package/src/orchestrator/skills/frontend-design/SKILL.md +19 -9
  177. package/src/orchestrator/skills/git-workflow/SKILL.md +1 -1
  178. package/src/orchestrator/skills/memory-merger/SKILL.md +13 -15
  179. package/src/orchestrator/skills/observability-logging/SKILL.md +1 -1
  180. package/src/orchestrator/skills/orchestration-protocols/REFERENCE.md +5 -9
  181. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +6 -6
  182. package/src/orchestrator/skills/panel-majority-vote/REFERENCE.md +0 -4
  183. package/src/orchestrator/skills/panel-majority-vote/SKILL.md +1 -1
  184. package/src/orchestrator/skills/panel-majority-vote/panel-report.template.md +0 -2
  185. package/src/orchestrator/skills/performance-optimization/SKILL.md +2 -2
  186. package/src/orchestrator/skills/project-consistency/SKILL.md +2 -2
  187. package/src/orchestrator/skills/project-consistency/TEMPLATES.md +0 -4
  188. package/src/orchestrator/skills/react-development/SKILL.md +3 -3
  189. package/src/orchestrator/skills/security-hardening/SKILL.md +5 -5
  190. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +0 -2
  191. package/src/orchestrator/skills/self-improvement/SKILL.md +1 -1
  192. package/src/orchestrator/skills/seo-patterns/SKILL.md +1 -1
  193. package/src/orchestrator/skills/session-checkpoints/CHECKPOINT-TEMPLATE.md +0 -2
  194. package/src/orchestrator/skills/session-checkpoints/SKILL.md +1 -1
  195. package/src/orchestrator/skills/team-lead-reference/SKILL.md +1 -1
  196. package/src/orchestrator/skills/technical-writing/SKILL.md +8 -13
  197. package/src/orchestrator/skills/testing-workflow/SKILL.md +6 -6
  198. package/src/orchestrator/skills/typescript-best-practices/SKILL.md +1 -1
  199. package/src/orchestrator/skills/unslop/SKILL.md +1 -1
  200. package/src/orchestrator/skills/validation-gates/REFERENCE.md +6 -31
  201. package/src/orchestrator/skills/validation-gates/SKILL.md +12 -26
  202. package/src/orchestrator/skills/writing-for-agents/SKILL.md +2 -2
  203. package/src/orchestrator/skills/documentation-standards/WRITING-GUIDE.md +0 -39
  204. package/src/orchestrator/skills/frontend-design/COMPONENTS.md +0 -113
@@ -0,0 +1,129 @@
1
+ /**
2
+ * What workers found outside their task: lessons for the next agent, and bugs.
3
+ *
4
+ * A worker may not write under `.opencastle/` — several run at once, and each
5
+ * such edit is a change outside its task that review sends back — so it was
6
+ * told to put a lesson or an issue "in your answer instead". Nothing read the
7
+ * answer for them, and every one was lost. Workers now mark them on a line of
8
+ * their own; the engine reads them back from each finished task's stored
9
+ * output when the run ends, so a resumed run loses none either.
10
+ */
11
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
12
+ import { join } from 'node:path'
13
+ import { scanForSecrets } from '../secret-scan.js'
14
+ import {
15
+ LESSONS_DIR,
16
+ LESSONS_INDEX,
17
+ isLessonCategory,
18
+ lessonBody,
19
+ newLessonId,
20
+ readLessons,
21
+ renderLesson,
22
+ syncLessons,
23
+ today,
24
+ } from '../lessons.js'
25
+
26
+ export interface ReportedLesson {
27
+ taskId: string
28
+ category: string
29
+ title: string
30
+ detail: string
31
+ }
32
+
33
+ export interface ReportedIssue {
34
+ taskId: string
35
+ text: string
36
+ }
37
+
38
+ export interface Findings {
39
+ lessons: ReportedLesson[]
40
+ issues: ReportedIssue[]
41
+ }
42
+
43
+ /** A marker on a line of its own, optionally a list item or in bold. */
44
+ const LESSON = /^[ \t]*(?:[-*][ \t]+)?\**\[LESSON(?:[ \t:]+([a-z-]+))?\]\**[ \t]*(.+)$/gm
45
+ const ISSUE = /^[ \t]*(?:[-*][ \t]+)?\**\[ISSUE\]\**[ \t]*(.+)$/gm
46
+
47
+ /** The lesson and issue lines in one worker's answer. */
48
+ export function extractFindings(taskId: string, output: string): Findings {
49
+ const lessons: ReportedLesson[] = []
50
+ for (const m of output.matchAll(LESSON)) {
51
+ const text = m[2].trim()
52
+ // `<what to do> — <why>`: the first half names the lesson in the index.
53
+ const split = /\s+(?:—|--|–)\s+/.exec(text)
54
+ const title = (split ? text.slice(0, split.index) : text).replace(/[.:]$/, '').trim()
55
+ if (!title) continue
56
+ const category = m[1] && isLessonCategory(m[1]) ? m[1] : 'general'
57
+ lessons.push({ taskId, category, title, detail: text })
58
+ }
59
+ const issues = [...output.matchAll(ISSUE)].map((m) => ({ taskId, text: m[1].trim() })).filter((i) => i.text)
60
+ return { lessons, issues }
61
+ }
62
+
63
+ /** Every finding across the tasks, a lesson reported twice kept once. */
64
+ export function collectFindings(tasks: Array<{ id: string; output: string | null }>): Findings {
65
+ const lessons: ReportedLesson[] = []
66
+ const issues: ReportedIssue[] = []
67
+ const seen = new Set<string>()
68
+ for (const t of tasks) {
69
+ const found = extractFindings(t.id, t.output ?? '')
70
+ for (const l of found.lessons) {
71
+ const key = l.title.toLowerCase()
72
+ if (seen.has(key)) continue
73
+ seen.add(key)
74
+ lessons.push(l)
75
+ }
76
+ issues.push(...found.issues)
77
+ }
78
+ return { lessons, issues }
79
+ }
80
+
81
+ /** What `recordLessons` changes, for the commit that adds them: the files and the index. */
82
+ export const LESSON_PATHS = [`.opencastle/${LESSONS_DIR}`, `.opencastle/${LESSONS_INDEX}`]
83
+
84
+ /**
85
+ * Write each lesson as a file under `<customizationsDir>/lessons/` and rewrite
86
+ * the index. Skips one an active lesson already has the title of — a resumed
87
+ * run reads the same answers again — and one that looks like it holds a
88
+ * credential, since lessons are committed. Nothing is written when there is no
89
+ * `.opencastle/` to write to.
90
+ */
91
+ export function recordLessons(
92
+ customizationsDir: string,
93
+ lessons: ReportedLesson[],
94
+ convoyId: string,
95
+ ): Array<{ id: string; title: string }> {
96
+ if (lessons.length === 0 || !existsSync(customizationsDir)) return []
97
+ const existing = readLessons(customizationsDir).lessons
98
+ const titles = new Set(existing.filter((l) => l.status === 'active').map((l) => l.title.toLowerCase()))
99
+ const taken = new Set(existing.map((l) => l.id))
100
+ const date = today()
101
+ const written: Array<{ id: string; title: string }> = []
102
+ for (const r of lessons) {
103
+ if (titles.has(r.title.toLowerCase())) continue
104
+ const id = newLessonId(r.title, date, taken)
105
+ const text = renderLesson({
106
+ id,
107
+ title: r.title,
108
+ category: r.category,
109
+ // Nobody has checked a worker's lesson yet: `medium` until the person
110
+ // reviewing the branch says otherwise.
111
+ severity: 'medium',
112
+ added: date,
113
+ citations: [],
114
+ status: 'active',
115
+ source: `convoy ${convoyId}, task ${r.taskId}`,
116
+ body: lessonBody({ problem: r.detail }),
117
+ })
118
+ if (!scanForSecrets(text, `${LESSONS_DIR}/${id}.md`).clean) continue
119
+ mkdirSync(join(customizationsDir, LESSONS_DIR), { recursive: true })
120
+ writeFileSync(join(customizationsDir, LESSONS_DIR, `${id}.md`), text)
121
+ taken.add(id)
122
+ titles.add(r.title.toLowerCase())
123
+ written.push({ id, title: r.title })
124
+ }
125
+ // Also moves an old single-file log into lesson files, which is why the
126
+ // commit takes the whole folder and not only the files written here.
127
+ if (written.length > 0) syncLessons(customizationsDir)
128
+ return written
129
+ }
@@ -1,6 +1,7 @@
1
1
  import { normalizePath, pathsOverlap } from './partition.js'
2
2
  import type { ConvoyStore } from './store.js'
3
3
  import { listArtifacts, type ArtifactRef } from './artifacts.js'
4
+ import { LESSON_CATEGORIES } from '../lessons.js'
4
5
 
5
6
  // ── Interfaces ────────────────────────────────────────────────────────────────
6
7
 
@@ -72,7 +73,7 @@ export function buildSharedContext(opts: {
72
73
  '## Rules',
73
74
  '- Do your task and nothing else. Change only the files your task lists; if it needs a change elsewhere, say so in your answer instead of making it.',
74
75
  '- Leave committing to the convoy. It commits your work when you finish.',
75
- "- Follow the project's own conventions and instruction files, with one exception: do not edit anything under `.opencastle/` (KNOWN-ISSUES.md, LESSONS-LEARNED.md, logs) even where those instructions ask you to. Several agents run at once, and each such edit is a change outside your task that review sends back. Put an issue or a lesson you found in your answer instead.",
76
+ `- Follow the project's own conventions and instruction files, with one exception: do not edit anything under \`.opencastle/\` (KNOWN-ISSUES.md, LESSONS-LEARNED.md, logs) even where those instructions ask you to. Several agents run at once, and each such edit is a change outside your task that review sends back. Report what you found in your answer instead, each on a line of its own: \`[LESSON <category>] <what to do> — <why>\` for what the next agent on this project should know before starting (a command that failed and the one that worked, a tool quirk, a convention written down nowhere else), with <category> one of ${LESSON_CATEGORIES.join(', ')}; and \`[ISSUE] <file or area>: <what is wrong>\` for a bug outside your task. The convoy records them.`,
76
77
  `- For long output (a report, a data dump), write it to a file under ${opts.artifactsDir}<your task id>/ and mention it in your answer as \`[ARTIFACT: <file name>] <one-line summary>\`.`,
77
78
  ].join('\n')
78
79
  }
@@ -160,6 +160,18 @@ export async function commitAllIn(cwd: string, message: string): Promise<boolean
160
160
  return true
161
161
  }
162
162
 
163
+ /**
164
+ * `commitAllIn`, for the named paths only: what the convoy wrote itself, not
165
+ * whatever a gate left in the checkout.
166
+ */
167
+ export async function commitPathsIn(cwd: string, paths: string[], message: string): Promise<boolean> {
168
+ await git(['add', '--', ...paths], cwd)
169
+ const staged = await git(['diff', '--cached', '--name-only', '--', ...paths], cwd)
170
+ if (!staged.trim()) return false
171
+ await gitWithIdentity(['commit', '-q', '--no-verify', '-m', message, '--', ...paths], cwd)
172
+ return true
173
+ }
174
+
163
175
  /** `git merge` with the convoy's fallback identity. */
164
176
  export async function mergeIn(cwd: string, args: string[]): Promise<string> {
165
177
  return gitWithIdentity(['merge', ...args], cwd)
@@ -236,6 +236,48 @@ describe('shipped content instructs only commands that exist', () => {
236
236
  .map((x) => `${x.rel}: ${x.hit}`)
237
237
  expect(offenders).toEqual([])
238
238
  })
239
+
240
+ // Other people's tools, held to a positive list the way our own commands are.
241
+ // `npx npm-dedupe` (no such package), `rg --type tsx` (ripgrep has no such
242
+ // type; `ts` covers .tsx) and `npx email dev` (the `email` binary is in
243
+ // `react-email`, which the skill never installed) each shipped to every user
244
+ // because nothing asked whether they run. A package joins this list once
245
+ // `npm view <name> bin` shows the binary the content calls, or once the skill
246
+ // that calls it says to install it.
247
+ const NPX_PACKAGES = new Set([
248
+ 'opencastle', 'nx', 'playwright', 'cypress', 'jest', 'eslint', 'prisma', 'convex', 'expo',
249
+ 'create-expo-module', 'react-email', 'source-map-explorer', 'markdown-link-check',
250
+ 'license-checker', '@arethetypeswrong/cli', '@sentry/wizard', '@delorenj/mcp-server-trello',
251
+ ])
252
+ /** ripgrep's own names, from `rg --type-list` — the ones a skill could want. */
253
+ const RG_TYPES = new Set([
254
+ 'ts', 'typescript', 'js', 'json', 'css', 'html', 'md', 'markdown', 'py', 'python', 'go', 'rust',
255
+ 'java', 'kotlin', 'swift', 'ruby', 'php', 'sh', 'sql', 'yaml', 'toml', 'svelte', 'vue', 'graphql',
256
+ 'docker', 'c', 'cpp', 'csharp',
257
+ ])
258
+ const npxPackages = (text: string): string[] =>
259
+ [...text.matchAll(/\bnpx (?:-y |--yes )?((?:@[a-z0-9-]+\/)?[a-z0-9][a-z0-9._-]*)/g)].map((m) => m[1])
260
+ const rgTypes = (text: string): string[] =>
261
+ [...text.matchAll(/\brg\b[^`\n|]*?\s(?:--type(?:-not)?[ =]|-[tT] ?)([a-z]+)/g)].map((m) => m[1])
262
+
263
+ it('reads the package and the ripgrep type from the lines that shipped broken', () => {
264
+ expect(npxPackages('Preview locally with `npx email dev`.')).toEqual(['email'])
265
+ expect(npxPackages('`npx -y @sentry/wizard@latest -i nextjs`')).toEqual(['@sentry/wizard'])
266
+ expect(rgTypes('`rg -n "useEffect" --type tsx src/`')).toEqual(['tsx'])
267
+ expect(rgTypes('`rg -tts "x" src-tests/`')).toEqual(['ts'])
268
+ })
269
+
270
+ it('runs through npx only packages someone has checked', () => {
271
+ const offenders = instructionFiles.flatMap((f) =>
272
+ npxPackages(f.text).filter((p) => !NPX_PACKAGES.has(p)).map((p) => `${f.rel}: npx ${p}`))
273
+ expect(offenders).toEqual([])
274
+ })
275
+
276
+ it('filters ripgrep only by types ripgrep has', () => {
277
+ const offenders = instructionFiles.flatMap((f) =>
278
+ rgTypes(f.text).filter((t) => !RG_TYPES.has(t)).map((t) => `${f.rel}: rg --type ${t}`))
279
+ expect(offenders).toEqual([])
280
+ })
239
281
  })
240
282
 
241
283
  /**
@@ -3,7 +3,8 @@ import { mkdtempSync, realpathSync } from 'node:fs'
3
3
  import { mkdirSync, writeFileSync, rmSync } from 'node:fs'
4
4
  import { join } from 'node:path'
5
5
  import { tmpdir } from 'node:os'
6
- import { runDoctorCheck, checkMcpFromPaths } from './doctor.js'
6
+ import { runDoctorCheck, checkMcpFromPaths, checkProjectContext, checkSkillMatrix } from './doctor.js'
7
+ import { LOCKFILE_VERSION } from './lock.js'
7
8
  import { IDE_ADAPTERS } from './adapters/index.js'
8
9
  import type { DoctorCheck } from './types.js'
9
10
 
@@ -172,6 +173,105 @@ describe('checkMcpFromPaths', () => {
172
173
  })
173
174
  })
174
175
 
176
+ // ── checkProjectContext ───────────────────────────────────────
177
+
178
+ describe('checkProjectContext', () => {
179
+ let tmpDir: string
180
+
181
+ beforeEach(() => {
182
+ tmpDir = makeTempDir()
183
+ mkdirSync(join(tmpDir, '.opencastle', 'stack'), { recursive: true })
184
+ })
185
+
186
+ afterEach(() => {
187
+ rmSync(tmpDir, { recursive: true, force: true })
188
+ })
189
+
190
+ const facts = (text: string) => writeFileSync(join(tmpDir, '.opencastle', 'project.instructions.md'), text)
191
+
192
+ it('warns when the file is missing, and says how to write it', async () => {
193
+ const result = await checkProjectContext(tmpDir)
194
+ expect(result.warning).toBe(true)
195
+ expect(result.fix).toContain('bootstrap-customizations')
196
+ })
197
+
198
+ it('warns when the file is still the template', async () => {
199
+ facts('# Project Context\n\n| Layer | Technology |\n|---|---|\n| | |\n\n| Path | Purpose |\n|---|---|\n| | |\n\nTODO: verify the dev port\n')
200
+ const result = await checkProjectContext(tmpDir)
201
+ expect(result.ok).toBe(true)
202
+ expect(result.warning).toBe(true)
203
+ expect(result.detail).toContain('still the template')
204
+ })
205
+
206
+ it('counts what is left to describe across the facts and the stack files, without warning', async () => {
207
+ facts('# Project Context\n\n## Commands\n\n| Task | Command |\n|---|---|\n| Test | `npm test` |\n\n## Still to describe\n\n- Deploy target\n- Dev ports\n')
208
+ writeFileSync(join(tmpDir, '.opencastle', 'stack', 'testing.md'), '# Testing\n\n## Still to describe\n\n- E2E setup\n\n## Notes\n\n- not counted\n')
209
+ const result = await checkProjectContext(tmpDir)
210
+ expect(result.warning).toBeFalsy()
211
+ expect(result.detail).toContain('3 still to describe')
212
+ })
213
+
214
+ it('reports a fully written file as written', async () => {
215
+ facts('# Project Context\n\n## Commands\n\n| Task | Command |\n|---|---|\n| Test | `npm test` |\n')
216
+ const result = await checkProjectContext(tmpDir)
217
+ expect(result).toMatchObject({ ok: true, detail: 'written' })
218
+ expect(result.warning).toBeFalsy()
219
+ })
220
+ })
221
+
222
+ // ── checkSkillMatrix ──────────────────────────────────────────
223
+
224
+ describe('checkSkillMatrix', () => {
225
+ let tmpDir: string
226
+
227
+ beforeEach(() => {
228
+ tmpDir = makeTempDir()
229
+ mkdirSync(join(tmpDir, '.opencastle', 'agents'), { recursive: true })
230
+ })
231
+
232
+ afterEach(() => {
233
+ rmSync(tmpDir, { recursive: true, force: true })
234
+ })
235
+
236
+ const matrix = (bindings: Record<string, { entries: Array<{ skill: string }> }>) =>
237
+ writeFileSync(join(tmpDir, '.opencastle', 'agents', 'skill-matrix.json'), JSON.stringify({ bindings }))
238
+ const lock = (skills: string[]) =>
239
+ writeFileSync(join(tmpDir, '.opencastle', 'lock.json'), JSON.stringify({
240
+ lockfileVersion: LOCKFILE_VERSION,
241
+ opencastle: '0.0.0',
242
+ targets: [],
243
+ integrations: [],
244
+ layers: [],
245
+ content: Object.fromEntries(skills.map((s) => [`skills/${s}`, { sha: '000000000000' }])),
246
+ mcp: {},
247
+ context: { tokens: 0 },
248
+ }))
249
+
250
+ it('does not warn about slots this stack has nothing for', async () => {
251
+ matrix({ cms: { entries: [] }, payments: { entries: [] }, framework: { entries: [{ skill: 'nextjs-patterns' }] } })
252
+ lock(['nextjs-patterns'])
253
+ const result = await checkSkillMatrix(tmpDir)
254
+ expect(result.warning).toBeFalsy()
255
+ expect(result.detail).toContain('1 of 3 capability slots bound')
256
+ })
257
+
258
+ it('warns about a slot bound to a skill that is not compiled', async () => {
259
+ matrix({ framework: { entries: [{ skill: 'nextjs-patterns' }] }, cms: { entries: [{ skill: 'sanity-cms' }] } })
260
+ lock(['nextjs-patterns'])
261
+ const result = await checkSkillMatrix(tmpDir)
262
+ expect(result.ok).toBe(true)
263
+ expect(result.warning).toBe(true)
264
+ expect(result.detail).toContain('cms → sanity-cms')
265
+ expect(result.detail).not.toContain('nextjs-patterns')
266
+ })
267
+
268
+ it('says nothing about bindings when there is no lock to compare against', async () => {
269
+ matrix({ cms: { entries: [{ skill: 'sanity-cms' }] } })
270
+ const result = await checkSkillMatrix(tmpDir)
271
+ expect(result.warning).toBeFalsy()
272
+ })
273
+ })
274
+
175
275
  // ── adapter getDoctorChecks ───────────────────────────────────
176
276
 
177
277
  describe('vscode adapter getDoctorChecks', () => {
package/src/cli/doctor.ts CHANGED
@@ -31,6 +31,7 @@ import { cliVersionOf, requiredEnvVars } from './layers.js';
31
31
  import type { CliContext, DoctorCheck, IdeChoice, Manifest } from './types.js';
32
32
  import { IDE_LABELS } from './types.js';
33
33
  import { c } from './prompt.js';
34
+ import { readLock } from './lock.js';
34
35
 
35
36
  // ── Styled output helpers ─────────────────────────────────────
36
37
 
@@ -158,7 +159,51 @@ async function checkCustomizations(projectRoot: string): Promise<CheckResult> {
158
159
  return { ok: true, label: 'Customizations directory', detail: `${files.length} entries` };
159
160
  }
160
161
 
161
- async function checkSkillMatrix(projectRoot: string): Promise<CheckResult> {
162
+ /**
163
+ * Whether the project's facts say anything yet.
164
+ *
165
+ * Every skill that needs this project's commands, routes or models reads them
166
+ * from `.opencastle/`. A file that is still a template — empty table rows,
167
+ * `TODO: verify` markers, as installs before 1.5 left them — gives them
168
+ * nothing, and nothing said so. One written from the code may still list what
169
+ * it could not read under "Still to describe"; that is normal, and counted.
170
+ */
171
+ export async function checkProjectContext(projectRoot: string): Promise<CheckResult> {
172
+ const dir = resolve(projectRoot, '.opencastle');
173
+ const facts = resolve(dir, 'project.instructions.md');
174
+ const bootstrap = 'have an agent fill it in from the code: /oc:bootstrap-customizations, or the bootstrap-customizations prompt';
175
+ if (!existsSync(facts)) {
176
+ return { ok: true, warning: true, label: 'Project context', detail: '.opencastle/project.instructions.md not found', fix: bootstrap };
177
+ }
178
+ const stack = resolve(dir, 'stack');
179
+ const stackFiles = existsSync(stack) ? (await readdir(stack).catch(() => [])).filter((f) => f.endsWith('.md')) : [];
180
+ const files = [facts, ...stackFiles.map((f) => resolve(stack, f))];
181
+ let placeholders = 0;
182
+ let toDescribe = 0;
183
+ for (const file of files) {
184
+ const text = await readFile(file, 'utf8').catch(() => '');
185
+ placeholders += (text.match(/^\|(?:\s*\|)+\s*$/gm) ?? []).length + (text.match(/TODO: verify/g) ?? []).length;
186
+ // `(?![\s\S])`, not `$`: under the `m` flag `$` ends the first line.
187
+ const list = /^## Still to describe\s*\n([\s\S]*?)(?=\n## |(?![\s\S]))/m.exec(text)?.[1] ?? '';
188
+ toDescribe += (list.match(/^- /gm) ?? []).length;
189
+ }
190
+ if (placeholders >= 3) {
191
+ return {
192
+ ok: true,
193
+ warning: true,
194
+ label: 'Project context',
195
+ detail: `still the template: ${placeholders} empty rows or "TODO: verify" markers in .opencastle/`,
196
+ fix: bootstrap,
197
+ };
198
+ }
199
+ return {
200
+ ok: true,
201
+ label: 'Project context',
202
+ detail: toDescribe > 0 ? `written; ${toDescribe} still to describe — ${bootstrap}` : 'written',
203
+ };
204
+ }
205
+
206
+ export async function checkSkillMatrix(projectRoot: string): Promise<CheckResult> {
162
207
  const path = resolve(projectRoot, '.opencastle', 'agents', 'skill-matrix.json');
163
208
  if (!existsSync(path)) {
164
209
  // "Not found" only if the directory holding it can actually be looked in.
@@ -202,14 +247,34 @@ async function checkSkillMatrix(projectRoot: string): Promise<CheckResult> {
202
247
  }
203
248
  try {
204
249
  const data = JSON.parse(content);
205
- const bindings = data.bindings ?? {};
206
- const emptySlots = Object.entries(bindings).filter(
207
- ([, slot]) => !Array.isArray((slot as { entries?: unknown[] }).entries) || ((slot as { entries: unknown[] }).entries).length === 0
250
+ const bindings = (data.bindings ?? {}) as Record<string, { entries?: Array<{ skill?: string }> }>;
251
+ const slots = Object.entries(bindings);
252
+ const bound = slots.filter(([, slot]) => Array.isArray(slot.entries) && slot.entries.length > 0);
253
+ // A slot with nothing bound is a domain this stack has nothing special in —
254
+ // no CMS, no payments. That is the normal state of most slots, and warning
255
+ // about it on every fresh install taught people to ignore the warnings. A
256
+ // slot bound to a skill that was not compiled is the real fault.
257
+ const compiled = new Set(
258
+ Object.keys(readLock(projectRoot)?.content ?? {})
259
+ .filter((ref) => ref.startsWith('skills/'))
260
+ .map((ref) => ref.slice('skills/'.length)),
208
261
  );
209
- if (emptySlots.length > 0) {
210
- return { ok: true, label: 'Skill matrix', detail: `${emptySlots.length} unresolved capability slot(s)`, warning: true };
262
+ // No lock, nothing to compare against: say nothing rather than call every
263
+ // binding missing.
264
+ const missing = compiled.size === 0 ? [] : bound.flatMap(([name, slot]) =>
265
+ (slot.entries ?? []).filter((e) => e.skill && !compiled.has(e.skill)).map((e) => `${name} → ${e.skill}`));
266
+ if (missing.length > 0) {
267
+ return {
268
+ ok: true,
269
+ warning: true,
270
+ label: 'Skill matrix',
271
+ detail: `bound to skills that are not compiled: ${missing.join(', ')}`,
272
+ // No command named here: the claims check runs the last one doctor
273
+ // prints, and a warning must not stand in for a failure's remedy.
274
+ fix: 'remove those entries from .opencastle/agents/skill-matrix.json, or put back the integration that provided them',
275
+ };
211
276
  }
212
- return { ok: true, label: 'Skill matrix', detail: 'All capability slots populated' };
277
+ return { ok: true, label: 'Skill matrix', detail: `${bound.length} of ${slots.length} capability slots bound; the rest have nothing in this stack` };
213
278
  } catch {
214
279
  return {
215
280
  ok: false,
@@ -902,7 +967,7 @@ export async function runAdapterChecks(
902
967
  const loader = IDE_ADAPTERS[ide];
903
968
  if (!loader) continue;
904
969
  const adapter = await loader();
905
- for (const check of adapter.getDoctorChecks()) {
970
+ for (const check of adapter.getDoctorChecks(ides as IdeChoice[])) {
906
971
  try {
907
972
  out.push(await runDoctorCheck(projectRoot, check));
908
973
  } catch (err) {
@@ -946,6 +1011,7 @@ export async function runSharedChecks(
946
1011
  const results = [
947
1012
  checkManifest(manifest),
948
1013
  await checkCustomizations(projectRoot),
1014
+ await checkProjectContext(projectRoot),
949
1015
  await checkSkillMatrix(projectRoot),
950
1016
  await checkLogs(projectRoot),
951
1017
  await checkMcpEnvVars(projectRoot, manifest, state),
@@ -1038,7 +1104,7 @@ export default async function doctor({ pkgRoot, args }: CliContext): Promise<voi
1038
1104
  const loader = IDE_ADAPTERS[ide];
1039
1105
  if (!loader) continue;
1040
1106
  const adapter = await loader();
1041
- const doctorChecks = adapter.getDoctorChecks();
1107
+ const doctorChecks = adapter.getDoctorChecks(ides as IdeChoice[]);
1042
1108
  const managedPaths = adapter.getManagedPaths();
1043
1109
 
1044
1110
  const checkResults = await Promise.all(
@@ -267,13 +267,13 @@ describe('stack-config: getAgentToolInjections', () => {
267
267
 
268
268
  const teamLeadTools = injections.get('team-lead')
269
269
  expect(teamLeadTools).toBeDefined()
270
- expect(teamLeadTools).toContain('Notion/search')
271
- expect(teamLeadTools).toContain('Notion/query_database')
270
+ expect(teamLeadTools).toContain('Notion/notion-search')
271
+ expect(teamLeadTools).toContain('Notion/notion-query-data-sources')
272
272
 
273
273
  const architectTools = injections.get('architect')
274
274
  expect(architectTools).toBeDefined()
275
- expect(architectTools).toContain('Notion/create_page')
276
- expect(architectTools).toContain('Notion/update_page')
275
+ expect(architectTools).toContain('Notion/notion-create-pages')
276
+ expect(architectTools).toContain('Notion/notion-update-page')
277
277
  })
278
278
  })
279
279
 
@@ -765,39 +765,44 @@ describe('Claude Code adapter install', () => {
765
765
  expect(content).toContain('.claude/agents/')
766
766
  })
767
767
 
768
- it('CLAUDE.md lists all non-excluded agents', async () => {
768
+ // Claude Code lists its subagents and skills itself, from `.claude/agents/`
769
+ // and `.claude/skills/`. CLAUDE.md repeated both — about 3k tokens loaded
770
+ // twice in every session — so what is compiled is checked where it is read.
771
+ it('compiles the agents the stack keeps as subagents, and does not list them again in CLAUDE.md', async () => {
769
772
  const adapter = await IDE_ADAPTERS['claude-code']()
770
773
  await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
771
774
 
775
+ const agents = await readdir(join(tempDir, '.claude', 'agents'))
776
+ expect(agents).toContain('developer.agent.md')
777
+ expect(agents).toContain('team-lead.agent.md')
778
+ expect(agents).not.toContain('content-engineer.agent.md')
779
+ expect(agents).not.toContain('data-engineer.agent.md')
772
780
  const content = await readFile(join(tempDir, 'CLAUDE.md'), 'utf8')
773
- expect(content).toContain('## Agent Definitions')
774
- expect(content).toContain('**Developer**')
775
- expect(content).toContain('**Team Lead (OpenCastle)**')
776
- // Should NOT list excluded agents
777
- expect(content).not.toContain('**Content Engineer**')
778
- expect(content).not.toContain('**Data Engineer**')
781
+ expect(content).not.toContain('## Agent Definitions')
782
+ expect(content).not.toContain('**Developer**')
779
783
  })
780
784
 
781
- it('CLAUDE.md includes content engineer when CMS selected', async () => {
785
+ it('compiles the content engineer when a CMS is selected', async () => {
782
786
  const adapter = await IDE_ADAPTERS['claude-code']()
783
787
  await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
784
788
 
785
- const content = await readFile(join(tempDir, 'CLAUDE.md'), 'utf8')
786
- expect(content).toContain('**Content Engineer**')
787
- expect(content).not.toContain('**Data Engineer**')
789
+ const agents = await readdir(join(tempDir, '.claude', 'agents'))
790
+ expect(agents).toContain('content-engineer.agent.md')
791
+ expect(agents).not.toContain('data-engineer.agent.md')
788
792
  })
789
793
 
790
- it('CLAUDE.md lists available skills (including selected plugins)', async () => {
794
+ it('compiles the selected skills, and does not list them again in CLAUDE.md', async () => {
791
795
  const adapter = await IDE_ADAPTERS['claude-code']()
792
796
  await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
793
797
 
798
+ const skills = await readdir(join(tempDir, '.claude', 'skills'))
799
+ expect(skills).toContain('self-improvement')
800
+ expect(skills).toContain('sanity-cms')
801
+ expect(skills).toContain('linear-task-management')
802
+ expect(skills).not.toContain('supabase-database')
794
803
  const content = await readFile(join(tempDir, 'CLAUDE.md'), 'utf8')
795
- expect(content).toContain('## Available Skills')
796
- expect(content).toContain('**self-improvement**')
797
- expect(content).toContain('**sanity-cms**')
798
- expect(content).toContain('**linear-task-management**')
799
- // Unselected plugin skills should NOT appear in skill index
800
- expect(content).not.toContain('**supabase-database**')
804
+ expect(content).not.toContain('## Available Skills')
805
+ expect(content).toContain('listed by the assistant itself')
801
806
  })
802
807
 
803
808
  it('writes agent files in .claude/agents/ with only the frontmatter Claude Code reads', async () => {