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
package/src/cli/init.ts CHANGED
@@ -468,7 +468,68 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
468
468
  const unreadable: string[] = []
469
469
  const failedTargets: Array<{ ide: string; message: string }> = []
470
470
 
471
- const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
471
+ // ── Scaffold customizations to .opencastle/ ──────────────────────────────
472
+ // Sampled before the copy below, which creates `.opencastle/agents` itself.
473
+ // Read after it, this was true on every run including the first, so the
474
+ // bootstrap guard downstream never let the project scan execute at all: no
475
+ // tech-stack table, no key commands, not even the project name. Every skill
476
+ // that wanted the package manager hardcoded one instead, because the file
477
+ // that was supposed to record it was never filled in.
478
+ const alreadyScaffolded = existsSync(resolve(projectRoot, '.opencastle', 'agents'))
479
+
480
+ const custSrcDir = resolve(getOrchestratorRoot(pkgRoot), 'customizations')
481
+ if (existsSync(custSrcDir)) {
482
+ const custDestDir = resolve(projectRoot, '.opencastle')
483
+ const custTransform = getCustomizationsTransform(stack)
484
+ // Over an existing `.opencastle/`, the templates bootstrap prunes or renames
485
+ // on the first run — `stack/`, the tracker config — stay as that run left
486
+ // them. Copying them again put back every one it had removed: a project
487
+ // with no CMS got `cms-config.md` and `sanity-config.md` on its second init.
488
+ const prunedOnce = (rel: string) => rel === 'stack' || rel.startsWith('stack/') || rel === 'project/tracker-config.md'
489
+ const sub = await copyDir(custSrcDir, custDestDir, {
490
+ transform: custTransform,
491
+ filter: (_name, srcPath) => !(alreadyScaffolded && prunedOnce(relative(custSrcDir, srcPath).split('\\').join('/'))),
492
+ })
493
+ totalCreated += sub.created.length
494
+ totalSkipped += sub.skipped.length
495
+ }
496
+
497
+ // ── Project scan ────────────────────────────────────────────────
498
+ // Bootstrap only on a first install. Its rename steps write over the target
499
+ // unconditionally, so on a re-run they replaced the user's own
500
+ // `stack/<provider>-config.md` with a blank template — the same hazard removed
501
+ // from `sync` in an earlier round and left standing here, and newly reachable
502
+ // without a prompt because `--yes` is new on this branch.
503
+ console.log(`\n ${c.dim('Configuring project...')}`)
504
+ // Keyed off the directory, not the manifest. `isReinit` alone missed two
505
+ // routes onto the destructive path — `remove --keep-files` (which drops only
506
+ // the manifest, by design) and a manifest with merge-conflict markers, which
507
+ // `readManifest` reports as "no install". Both then ran bootstrap's
508
+ // unconditional renames over a populated `.opencastle/` and replaced the
509
+ // user's own stack notes with a blank template. `alreadyScaffolded` is
510
+ // sampled above, before the scaffold step supplies its own answer.
511
+ const bootstrapResult = isReinit || alreadyScaffolded
512
+ ? { populated: [], removed: [], renamed: [] }
513
+ : await bootstrapCustomizations(projectRoot, combinedRepoInfo, stack)
514
+
515
+ if (bootstrapResult.populated.length > 0) {
516
+ console.log(` ${c.green('✓')} Populated ${c.bold(String(bootstrapResult.populated.length))} config files`)
517
+ }
518
+ if (bootstrapResult.renamed.length > 0) {
519
+ for (const r of bootstrapResult.renamed) {
520
+ console.log(` ${c.dim('→')} Renamed ${r}`)
521
+ }
522
+ }
523
+ if (bootstrapResult.removed.length > 0) {
524
+ console.log(` ${c.dim('→')} Removed ${bootstrapResult.removed.length} unused template(s)`)
525
+ }
526
+
527
+ // Compiled after `.opencastle/` is written, not before: on a first install the
528
+ // project's facts — `project.instructions.md`, which every assistant loads —
529
+ // did not exist yet when the assistants' files were compiled, so the first
530
+ // `sync --check` reported every root file as drifted.
531
+ const scaffolded = resolveSources({ pkgRoot, projectRoot, stack, repoInfo: combinedRepoInfo })
532
+ const source = materialize(hasErrors(scaffolded) ? resolved : scaffolded, pkgRoot, ...priorTeam(projectRoot))
472
533
  try {
473
534
  for (const ide of ides) {
474
535
  const adapter = await IDE_ADAPTERS[ide]()
@@ -612,62 +673,6 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
612
673
  source.dispose()
613
674
  }
614
675
 
615
- // ── Scaffold customizations to .opencastle/ ──────────────────────────────
616
- // Sampled before the copy below, which creates `.opencastle/agents` itself.
617
- // Read after it, this was true on every run including the first, so the
618
- // bootstrap guard downstream never let the project scan execute at all: no
619
- // tech-stack table, no key commands, not even the project name. Every skill
620
- // that wanted the package manager hardcoded one instead, because the file
621
- // that was supposed to record it was never filled in.
622
- const alreadyScaffolded = existsSync(resolve(projectRoot, '.opencastle', 'agents'))
623
-
624
- const custSrcDir = resolve(getOrchestratorRoot(pkgRoot), 'customizations')
625
- if (existsSync(custSrcDir)) {
626
- const custDestDir = resolve(projectRoot, '.opencastle')
627
- const custTransform = getCustomizationsTransform(stack)
628
- // Over an existing `.opencastle/`, the templates bootstrap prunes or renames
629
- // on the first run — `stack/`, the tracker config — stay as that run left
630
- // them. Copying them again put back every one it had removed: a project
631
- // with no CMS got `cms-config.md` and `sanity-config.md` on its second init.
632
- const prunedOnce = (rel: string) => rel === 'stack' || rel.startsWith('stack/') || rel === 'project/tracker-config.md'
633
- const sub = await copyDir(custSrcDir, custDestDir, {
634
- transform: custTransform,
635
- filter: (_name, srcPath) => !(alreadyScaffolded && prunedOnce(relative(custSrcDir, srcPath).split('\\').join('/'))),
636
- })
637
- totalCreated += sub.created.length
638
- totalSkipped += sub.skipped.length
639
- }
640
-
641
- // ── Project scan ────────────────────────────────────────────────
642
- // Bootstrap only on a first install. Its rename steps write over the target
643
- // unconditionally, so on a re-run they replaced the user's own
644
- // `stack/<provider>-config.md` with a blank template — the same hazard removed
645
- // from `sync` in an earlier round and left standing here, and newly reachable
646
- // without a prompt because `--yes` is new on this branch.
647
- console.log(`\n ${c.dim('Configuring project...')}`)
648
- // Keyed off the directory, not the manifest. `isReinit` alone missed two
649
- // routes onto the destructive path — `remove --keep-files` (which drops only
650
- // the manifest, by design) and a manifest with merge-conflict markers, which
651
- // `readManifest` reports as "no install". Both then ran bootstrap's
652
- // unconditional renames over a populated `.opencastle/` and replaced the
653
- // user's own stack notes with a blank template. `alreadyScaffolded` is
654
- // sampled above, before the scaffold step supplies its own answer.
655
- const bootstrapResult = isReinit || alreadyScaffolded
656
- ? { populated: [], removed: [], renamed: [] }
657
- : await bootstrapCustomizations(projectRoot, combinedRepoInfo, stack)
658
-
659
- if (bootstrapResult.populated.length > 0) {
660
- console.log(` ${c.green('✓')} Populated ${c.bold(String(bootstrapResult.populated.length))} config files`)
661
- }
662
- if (bootstrapResult.renamed.length > 0) {
663
- for (const r of bootstrapResult.renamed) {
664
- console.log(` ${c.dim('→')} Renamed ${r}`)
665
- }
666
- }
667
- if (bootstrapResult.removed.length > 0) {
668
- console.log(` ${c.dim('→')} Removed ${bootstrapResult.removed.length} unused template(s)`)
669
- }
670
-
671
676
  // ── Write manifest ──────────────────────────────────────────────
672
677
  const manifest = createManifest(pkg.version, ides[0], ides)
673
678
  manifest.managedPaths = allManagedPaths
@@ -11,7 +11,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync
11
11
  import { tmpdir } from 'node:os'
12
12
  import { join, resolve, dirname } from 'node:path'
13
13
  import { describe, it, expect, beforeEach, afterEach } from 'vitest'
14
- import { resolveSources, materialize, usesTeamSources, requiredEnvVars, hasErrors } from './layers.js'
14
+ import { resolveSources, materialize, usesTeamSources, requiredEnvVars, hasErrors, projectContextText, PROJECT_CONTEXT } from './layers.js'
15
15
  import { parseTeamConfig, stripJsonc, TeamConfigSchema } from './team-config.js'
16
16
  import { satisfies } from './version-range.js'
17
17
  import { findInlineSecret } from './policy.js'
@@ -523,3 +523,74 @@ describe('credential detection, tuned', () => {
523
523
  expect(findInlineSecret({ env: { DB_PASSWORD: 'x9$Kq2mZ7vLp4wN8' } })).toBe('env.DB_PASSWORD')
524
524
  })
525
525
  })
526
+
527
+ describe("the project's facts, always loaded", () => {
528
+ let project: string
529
+ beforeEach(() => {
530
+ project = mkdtempSync(join(tmpdir(), 'layers-facts-'))
531
+ mkdirSync(join(project, '.opencastle'), { recursive: true })
532
+ })
533
+ afterEach(() => {
534
+ rmSync(project, { recursive: true, force: true })
535
+ })
536
+
537
+ const write = (text: string) => writeFileSync(join(project, '.opencastle', 'project.instructions.md'), text)
538
+ const resolveHere = () => resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
539
+
540
+ it('compiles .opencastle/project.instructions.md as an instruction every assistant loads', () => {
541
+ write('# Project Context\n\n**demo** — a demo app\n\n## Key Commands\n\n```bash\npnpm test\n```\n')
542
+ const r = resolveHere()
543
+ expect(r.items.get(`instructions/${PROJECT_CONTEXT}`)?.layer).toBe('project')
544
+ const src = materialize(r, pkgRoot)
545
+ try {
546
+ const compiled = readFileSync(join(src.root, 'instructions', `${PROJECT_CONTEXT}.instructions.md`), 'utf8')
547
+ expect(compiled).toContain('**demo** — a demo app')
548
+ expect(compiled).toContain("applyTo: '**'")
549
+ } finally {
550
+ src.dispose()
551
+ }
552
+ })
553
+
554
+ it('leaves out a file that is still the template: there is nothing to load', () => {
555
+ write('```instructions\n# Project Context\n\n<!-- populated by init -->\n\n## Tech Stack\n\n| Layer | Technology |\n|---|---|\n| | |\n\n## Routes\n\n<!-- routes -->\n```\n')
556
+ expect(resolveHere().items.has(`instructions/${PROJECT_CONTEXT}`)).toBe(false)
557
+ })
558
+
559
+ it('keeps what is filled in and drops comments, empty rows and sections, and the to-do list', () => {
560
+ const text = projectContextText([
561
+ '# Project Context',
562
+ '',
563
+ '<!-- Written by init. -->',
564
+ '',
565
+ '## Tech Stack',
566
+ '',
567
+ '| Layer | Technology |',
568
+ '|---|---|',
569
+ '| Framework | Next.js |',
570
+ '| | |',
571
+ '',
572
+ '## Apps',
573
+ '',
574
+ '| App | URL |',
575
+ '|---|---|',
576
+ '| | |',
577
+ '',
578
+ '## Routes',
579
+ '',
580
+ '<!-- none yet -->',
581
+ '',
582
+ '## Still to describe',
583
+ '',
584
+ '- Architecture',
585
+ ].join('\n'))
586
+ expect(text).toBe('# Project Context\n\n## Tech Stack\n\n| Layer | Technology |\n|---|---|\n| Framework | Next.js |\n')
587
+ })
588
+
589
+ it('takes the team\'s own instruction of that name over the file', () => {
590
+ write('# Project Context\n\nFROM THE FILE\n')
591
+ mkdirSync(join(project, '.opencastle', 'instructions'), { recursive: true })
592
+ writeFileSync(join(project, '.opencastle', 'instructions', `${PROJECT_CONTEXT}.md`), 'FROM THE TEAM\n')
593
+ const item = resolveHere().items.get(`instructions/${PROJECT_CONTEXT}`)!
594
+ expect(item.path.endsWith(join('instructions', `${PROJECT_CONTEXT}.md`))).toBe(true)
595
+ })
596
+ })
package/src/cli/layers.ts CHANGED
@@ -119,6 +119,48 @@ const LAYER_DIR: Record<ContentKind, string> = {
119
119
  }
120
120
  const CORE_DIR: Record<ContentKind, string> = { ...LAYER_DIR, workflows: 'agent-workflows' }
121
121
 
122
+ /**
123
+ * The project's facts — what `init` read from the code into
124
+ * `.opencastle/project.instructions.md` — compiled as an always-loaded
125
+ * instruction of this name.
126
+ *
127
+ * The general instructions used to say "read `.opencastle/project.instructions.md`
128
+ * before planning", and an agent read it when it decided to: Claude Code's own
129
+ * docs say a file named in words is seen only if the model opens it, and
130
+ * OpenSpec dropped its `project.md` for the same reason. The commands, the
131
+ * stack and the structure are the first thing every assistant's guidance says
132
+ * belongs in the always-loaded file.
133
+ */
134
+ export const PROJECT_CONTEXT = 'project-context'
135
+ const PROJECT_FACTS_FILE = 'project.instructions.md'
136
+
137
+ /**
138
+ * What of the project's facts is worth loading every session: no HTML
139
+ * comments, no empty table rows or sections — what an install from before
140
+ * 1.5 left as a template — and not the "Still to describe" list, which is a
141
+ * note for people. Empty when nothing is left.
142
+ */
143
+ export function projectContextText(raw: string): string {
144
+ let text = raw.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n')
145
+ // Templates before 1.5 wrapped the whole file in a code fence.
146
+ const fenced = /^\s*(`{3,})(?:instructions|markdown|md)?\n([\s\S]*?)\n\1\s*$/.exec(text)
147
+ if (fenced) text = fenced[2]
148
+ text = text.replace(/<!--[\s\S]*?-->/g, '')
149
+ // Rows whose every cell is empty, then tables with no rows left.
150
+ text = text.replace(/^\|(?:\s*\|)+\s*$\n?/gm, '')
151
+ text = text.replace(/^\|[^\n]*\|\n\|(?:[ \t]*:?-{3,}:?[ \t]*\|)+[ \t]*(?:\n(?!\|)|(?![\s\S]))/gm, '')
152
+ const sections = text.split(/\n(?=#{2,3} )/)
153
+ const kept = sections.filter((section, i) => {
154
+ if (i === 0) return true
155
+ const [heading, ...body] = section.split('\n')
156
+ if (/^#{2,3} Still to describe\s*$/.test(heading)) return false
157
+ return body.join('\n').trim().length > 0
158
+ })
159
+ text = kept.join('\n').replace(/\n{3,}/g, '\n\n').trim()
160
+ // A title and nothing under it is not worth a line of context.
161
+ return /^#[^\n]*$/.test(text) || text === '' ? '' : text + '\n'
162
+ }
163
+
122
164
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
123
165
  const PACKAGE_NAME = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/
124
166
 
@@ -299,6 +341,13 @@ function scanLayer(layer: Layer, projectRoot: string | null): { items: ContentIt
299
341
  items.push({ kind, name, layer: layer.id, path: join(dir, entry.name), ...(within && { within }) })
300
342
  }
301
343
  }
344
+ if (layer.kind === 'project') {
345
+ const facts = join(layer.root, PROJECT_FACTS_FILE)
346
+ const taken = items.some((i) => i.kind === 'instructions' && i.name === PROJECT_CONTEXT)
347
+ if (!taken && existsSync(facts) && projectContextText(readFileSync(facts, 'utf8')) !== '') {
348
+ items.push({ kind: 'instructions', name: PROJECT_CONTEXT, layer: layer.id, path: facts })
349
+ }
350
+ }
302
351
  return { items, issues }
303
352
  }
304
353
 
@@ -1113,7 +1162,9 @@ export function materialize(
1113
1162
  continue
1114
1163
  }
1115
1164
  const buf = readFileSync(item.path)
1116
- writeFileSync(dest, team ? normaliseTeamText(item.kind, item.name, buf.toString('utf8')) : buf)
1165
+ const facts = item.layer === 'project' && item.kind === 'instructions' && item.name === PROJECT_CONTEXT
1166
+ const text = facts ? projectContextText(buf.toString('utf8')) : buf.toString('utf8')
1167
+ writeFileSync(dest, team ? normaliseTeamText(item.kind, item.name, text) : buf)
1117
1168
  }
1118
1169
  } catch (err) {
1119
1170
  rmSync(root, { recursive: true, force: true })
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os'
3
3
  import { join, resolve } from 'node:path'
4
4
  import { describe, it, expect, beforeEach, afterEach } from 'vitest'
5
5
  import {
6
+ INDEX_BUDGET_TOKENS,
6
7
  INDEX_MARKER,
7
8
  checkLessons,
8
9
  citedPath,
@@ -252,3 +253,50 @@ describe('citations against the code', () => {
252
253
  expect(readLessons(dir).lessons).toHaveLength(1)
253
254
  })
254
255
  })
256
+
257
+ describe('the size of the index', () => {
258
+ let project: string
259
+
260
+ beforeEach(() => {
261
+ project = mkdtempSync(join(tmpdir(), 'oc-lessons-size-'))
262
+ mkdirSync(join(project, '.opencastle', 'lessons'), { recursive: true })
263
+ })
264
+
265
+ afterEach(() => rmSync(project, { recursive: true, force: true }))
266
+
267
+ function record(count: number, status: Lesson['status'] = 'active'): void {
268
+ const dir = join(project, '.opencastle')
269
+ for (let i = 0; i < count; i++) {
270
+ const id = `2026-10-02-${status}-lesson-${String(i).padStart(3, '0')}`
271
+ writeFileSync(
272
+ join(dir, 'lessons', `${id}.md`),
273
+ renderLesson(lesson({ id, title: `A lesson about one more quirk of the build, number ${i}`, status })),
274
+ )
275
+ }
276
+ syncLessons(dir)
277
+ }
278
+
279
+ it('says nothing about a few dozen lessons', () => {
280
+ record(20)
281
+ const result = checkLessons(project)
282
+ expect(result.warning).toBeUndefined()
283
+ expect(result.detail).toBe('20 lesson(s)')
284
+ })
285
+
286
+ it('suggests merging when the index outgrows its budget', () => {
287
+ record(80)
288
+ const result = checkLessons(project)
289
+ expect(result.warning).toBe(true)
290
+ expect(result.detail).toMatch(/^80 active lessons, ~\d+ tokens in the index agents read before every task$/)
291
+ expect(Number(/~(\d+)/.exec(result.detail ?? '')?.[1])).toBeGreaterThan(INDEX_BUDGET_TOKENS)
292
+ expect(result.fix).toContain('opencastle lesson archive')
293
+ })
294
+
295
+ it('does not count archived lessons against it — archiving cannot shrink them', () => {
296
+ record(80, 'archived')
297
+ record(1)
298
+ const result = checkLessons(project)
299
+ expect(result.warning).toBeUndefined()
300
+ expect(result.detail).toBe('1 lesson(s)')
301
+ })
302
+ })
@@ -235,7 +235,9 @@ export function renderIndex(lessons: Lesson[]): string {
235
235
  'tool quirk, a convention written down nowhere else. **Read this before you',
236
236
  'start work**, then open the lessons that match your task.',
237
237
  '',
238
- 'Each lesson is a file in [`lessons/`](lessons/). Add one with',
238
+ // A path, not a link: the folder is created with the first lesson, and a
239
+ // link to it led nowhere until then.
240
+ 'Each lesson is a file in `.opencastle/lessons/`. Add one with',
239
241
  '`opencastle lesson --title ... --category ... --severity ... --problem ...`',
240
242
  '(and `--cite <path>` for the code it is about). Do not edit this index:',
241
243
  'it is rewritten from those files by every `opencastle sync`.',
@@ -488,6 +490,17 @@ export function staleCitations(projectRoot: string, lessons: Lesson[]): StaleCit
488
490
  }
489
491
 
490
492
  /** The check `doctor` runs on a project's lessons. */
493
+ /**
494
+ * What the index may cost before doctor suggests pruning it, in tokens.
495
+ *
496
+ * Agents read the index before every task, so each active lesson is paid for
497
+ * on every task, by every agent, whatever the task is. Around forty one-line
498
+ * entries reach this. Past it, the lessons that recur belong in the skill or
499
+ * instruction file they are about — read only by the agents that need them —
500
+ * which is what `archive --into` records.
501
+ */
502
+ export const INDEX_BUDGET_TOKENS = 2000
503
+
491
504
  export function checkLessons(projectRoot: string): {
492
505
  ok: boolean
493
506
  label: string
@@ -531,6 +544,19 @@ export function checkLessons(projectRoot: string): {
531
544
  'with --cite <path> for a file that moved — or retire it with opencastle lesson archive <id> --into <file>',
532
545
  }
533
546
  }
547
+ // Active lessons only: archiving is the remedy, and it does not shrink the
548
+ // archived list. The lock's chars/4 estimate, inline, so this module stays
549
+ // free of the compiler.
550
+ const indexTokens = Math.ceil(renderIndex(active).length / 4)
551
+ if (indexTokens > INDEX_BUDGET_TOKENS) {
552
+ return {
553
+ ok: true,
554
+ warning: true,
555
+ label,
556
+ detail: `${active.length} active lessons, ~${indexTokens} tokens in the index agents read before every task`,
557
+ fix: 'merge the lessons that recur into the skill or instruction file they are about, then opencastle lesson archive <id> --into <file>',
558
+ }
559
+ }
534
560
  const cited = active.filter((l) => l.citations.length > 0).length
535
561
  return {
536
562
  ok: true,
@@ -30,21 +30,23 @@ describe('fillTemplate', () => {
30
30
  })
31
31
  })
32
32
 
33
+ // `pipeline`: only the CLI runs it. generate-convoy is the exception, as the
34
+ // Team Lead also plans in the editor by its rules.
33
35
  const PLANNER = {
34
- 'generate-prd': { output: 'prd', context: false },
35
- 'validate-prd': { output: 'validation', context: false },
36
- 'fix-prd': { output: 'prd', context: true },
37
- 'assess-complexity': { output: 'json', context: true },
38
- 'generate-convoy': { output: 'json', context: true },
39
- 'validate-convoy': { output: 'validation', context: false },
40
- 'fix-convoy': { output: 'json', context: true },
36
+ 'generate-prd': { output: 'prd', context: false, pipeline: true },
37
+ 'validate-prd': { output: 'validation', context: false, pipeline: true },
38
+ 'fix-prd': { output: 'prd', context: true, pipeline: true },
39
+ 'assess-complexity': { output: 'json', context: true, pipeline: true },
40
+ 'generate-convoy': { output: 'json', context: true, pipeline: false },
41
+ 'validate-convoy': { output: 'validation', context: false, pipeline: true },
42
+ 'fix-convoy': { output: 'json', context: true, pipeline: true },
41
43
  } as const
42
44
 
43
45
  describe('the planner templates', () => {
44
46
  it.each(Object.entries(PLANNER))('%s keeps its frontmatter and fills each input once', (name, expected) => {
45
47
  const text = readFileSync(templatePath(pkgRoot, name), 'utf8')
46
48
  const fm = parseFrontmatter(text)
47
- expect(Object.keys(fm).sort()).toEqual(['agent', 'description', 'output'])
49
+ expect(Object.keys(fm).sort()).toEqual(['agent', 'description', 'output', ...(expected.pipeline ? ['pipeline'] : [])])
48
50
  expect(fm.output).toBe(expected.output)
49
51
 
50
52
  // Exactly one slot per input, and no other mention that a fill could reach.
@@ -123,10 +123,24 @@ describe('drift detection', () => {
123
123
  // change behavior, so it must never count as drift.
124
124
  const custom = join(projectRoot, '.opencastle')
125
125
  mkdirSync(custom, { recursive: true })
126
- writeFileSync(join(custom, 'project.instructions.md'), 'my own rules\n')
126
+ writeFileSync(join(custom, 'KNOWN-ISSUES.md'), 'my own notes\n')
127
127
 
128
128
  const report = await buildCheckReport(pkgRoot, projectRoot)
129
- expect(report.drift.filter((d) => d.path.startsWith('.opencastle'))).toEqual([])
129
+ expect(report.drift).toEqual([])
130
+ })
131
+
132
+ it('asks for a sync when the project facts every assistant loads change, never blaming the facts', async () => {
133
+ await install()
134
+ // project.instructions.md is the user's, and it is compiled into the
135
+ // always-loaded instructions: an edit is not drift of the file, but the
136
+ // compiled files no longer carry it until `sync` runs.
137
+ const custom = join(projectRoot, '.opencastle')
138
+ mkdirSync(custom, { recursive: true })
139
+ writeFileSync(join(custom, 'project.instructions.md'), '# Project Context\n\nDeploys with `make ship`.\n')
140
+
141
+ const report = await buildCheckReport(pkgRoot, projectRoot)
142
+ expect(report.drift.length).toBeGreaterThan(0)
143
+ expect(report.drift.map((d) => d.path)).not.toContain('.opencastle/project.instructions.md')
130
144
  })
131
145
 
132
146
  it('ignores unrelated files in the project', async () => {
package/src/cli/types.ts CHANGED
@@ -220,7 +220,8 @@ export interface IdeAdapter {
220
220
  _source?: CompileSource,
221
221
  ): Promise<CopyResults>;
222
222
  getManagedPaths(): ManagedPaths;
223
- getDoctorChecks(): DoctorCheck[];
223
+ /** `ides`: every assistant the project is set up for, when a check depends on the others. */
224
+ getDoctorChecks(_ides?: readonly IdeChoice[]): DoctorCheck[];
224
225
  /**
225
226
  * Files an earlier release wrote under a name this one no longer uses —
226
227
  * `/bug-fix` before it became `/oc:bug-fix` — present on disk now, relative to
@@ -183,7 +183,7 @@ If there are no open questions, explicitly state: "No open questions — plan is
183
183
 
184
184
  ### Exit Criteria (per track)
185
185
 
186
- - [ ] 95% test coverage on new code
186
+ - [ ] New code meets the coverage threshold in the project's test config
187
187
  - [ ] Browser screenshots at all breakpoints
188
188
  - [ ] Security audit passes (or panel review scheduled)
189
189
  - [ ] Documentation updated
@@ -40,9 +40,9 @@ Load on-demand **only when the phase is reached**.
40
40
  |-------|---------|
41
41
  | **team-lead-reference** | Session start — model routing, registry, pre-delegation, cost, DLQ, deepen-plan |
42
42
  | **session-checkpoints** | Session resume or checkpoint save |
43
- | **agent-hooks** | Step 3 — delegation prompt templates |
43
+ | **agent-hooks** | Session start/end, pre- and post-delegation checklists |
44
44
  | **task-management** | Step 2 — tracker conventions |
45
- | **decomposition** | Step 2–3 — dependency resolution, delegation specs |
45
+ | **decomposition** | Step 2–3 — dependency resolution, delegation spec templates |
46
46
  | **orchestration-protocols** | Step 4+ — steering, background agents, health-checks, escalation |
47
47
  | **context-map** | Step 2, 5+ files affected |
48
48
  | **validation-gates** | Step 4 — deterministic checks, browser testing, regression |
@@ -63,7 +63,7 @@ Developer | UI/UX Expert | Content Engineer | Data Engineer | Testing Expert | S
63
63
  **⛔ Hard gates:**
64
64
  - Log delegation record immediately after each return/spawn — **observability-logging** (`--mechanism sub-agent` or `--mechanism background`).
65
65
  - `tier` from the agent registry only; `model` is the one the assistant actually ran, when it says.
66
- - Empty/off-topic: retry max 3 → DLQ. Log failures (`--outcome failed`).
66
+ - Retries and escalation (FAIL, empty/off-topic output, DLQ): **fast-review**'s Handle Verdict table. Log failures (`--outcome failed`).
67
67
 
68
68
  **Partitioning:** Parallel agents never touch the same files. **Budget:** Target 5–7/session; 8 → warn; 9 → checkpoint; 10+ → STOP. **Pre-Delegation:** (1) Tracker issue, (2) clean partition, (3) dependencies Done, (4) file paths + criteria, (5) self-improvement reminder.
69
69
 
@@ -81,9 +81,9 @@ Developer | UI/UX Expert | Content Engineer | Data Engineer | Testing Expert | S
81
81
 
82
82
  **Step 2 — Decompose & Track:** No issue, no code. Break into single-responsibility units with Fibonacci scores (1–13). Map dependencies, file ownership, tracker issues with acceptance criteria. 5+ files → **context-map**. Consider deepen-plan (**team-lead-reference**).
83
83
 
84
- **Step 3 — Prompts:** Every delegation: issue ID, objective, file paths, acceptance criteria, patterns, self-improvement reminder. Score 5+ → load **decomposition**.
84
+ **Step 3 — Prompts:** Every delegation: issue ID, objective, file paths, acceptance criteria, patterns, self-improvement reminder — the Compact Delegation Envelope in **team-lead-reference**. Score 5+ → full delegation spec from **decomposition**.
85
85
 
86
- **Step 4 — Execute:** Per task: move → In Progress → delegate → log delegation ⛔ → monitor → verify (partition, lint/test/build, fast review PASS, UI browser-verified, high-stakes → panel, issues tracked, lessons captured) → log review ⛔ → Done. FAIL → re-delegate (max 3 → DLQ). Auto-PASS: research/docs-only, or ≤10 lines/≤2 files with gates passing.
86
+ **Step 4 — Execute:** Per task: move → In Progress → delegate → log delegation ⛔ → monitor → verify (partition, lint/test/build, fast review PASS, UI browser-verified, high-stakes → panel, issues tracked, lessons captured) → log review ⛔ → Done. FAIL → **fast-review**'s Handle Verdict table. Auto-PASS: research/docs-only, or ≤10 lines/≤2 files with gates passing.
87
87
 
88
88
  **Step 5 — Deliver:** Follow the workflow template's Delivery phase. Verify all Done → build/lint/test → commit feature branch → `GH_PAGER=cat gh pr create` — do NOT merge → link PR → clean checkpoint → call **Reviewer**.
89
89
 
@@ -17,7 +17,7 @@ Resolve skills via `.opencastle/agents/skill-matrix.json`.
17
17
  ## Rules
18
18
 
19
19
  1. **RED → GREEN → REFACTOR for every feature and fix.** The failing test comes before the production code.
20
- 2. **95% minimum coverage on all new code.**
20
+ 2. **New code meets the coverage threshold in the project's test config.**
21
21
  3. **Run the full suite before returning**, not only the tests you touched.
22
22
  4. **Never add a test-only method or hook to production code.** Refactor the interface instead.
23
23
  5. **Never assert on mock behavior.** Mock external APIs only, never internal modules.
@@ -32,7 +32,7 @@ Every suite covers: Initial State · User Interactions · State Transitions · E
32
32
 
33
33
  ## Verification
34
34
 
35
- All scenarios pass · 95% coverage · 3 consecutive green runs · browser-validated at every breakpoint · naming conventions followed
35
+ All scenarios pass · coverage threshold met · 3 consecutive green runs · browser-validated at every breakpoint · naming conventions followed
36
36
 
37
37
  ## Out of Scope
38
38
 
@@ -6,7 +6,7 @@ What agents on this project learned the hard way: a command that failed, a
6
6
  tool quirk, a convention written down nowhere else. **Read this before you
7
7
  start work**, then open the lessons that match your task.
8
8
 
9
- Each lesson is a file in [`lessons/`](lessons/). Add one with
9
+ Each lesson is a file in `.opencastle/lessons/`. Add one with
10
10
  `opencastle lesson --title ... --category ... --severity ... --problem ...`
11
11
  (and `--cite <path>` for the code it is about). Do not edit this index:
12
12
  it is rewritten from those files by every `opencastle sync`.
@@ -7,28 +7,11 @@ applyTo: '**'
7
7
 
8
8
  # AI Optimization
9
9
 
10
- Batch independent operations, gather context before acting, and avoid redundant tool calls.
11
-
12
- ## Key Rules
13
-
14
- - **Batch independent reads** — parallelize file reads, searches, and error checks in a single call instead of sequentially
15
- - **Don't batch dependent ops** — if step B needs step A's output, run them sequentially
16
- - **Gather context first** — read and search before editing; don't act on assumptions
17
- - **Read strategically** — prefer large ranges (500–2000 lines) over many micro-reads; use `grep_search` to locate, then read targeted ranges
18
- - **Combine searches** — use regex alternation (`word1|word2|word3`) instead of separate searches
19
- - **Don't re-read** — if a file or sub-agent result is already in context, use it directly
20
- - **Verify once per phase** — run tests/lint/errors after a batch of edits, not after each individual change
21
- - **Scale planning to complexity** — trivial (1–2 files) → act directly; large (10+ files) → full decomposition
22
- - **Trust sub-agent results** — don't re-search or re-read what a sub-agent already returned
23
- - **Include file paths in delegation prompts** — saves the sub-agent from wasting context on discovery
24
-
25
- ## Anti-Patterns
26
-
27
- 1. **Micro-reads** — reading tiny file sections repeatedly
28
- 2. **Sequential searches** — running independent searches one at a time
29
- 3. **Premature actions** — editing before gathering sufficient context
30
- 4. **Over-checking** — validating after every tiny change instead of batching
31
- 5. **Re-gathering delegated context** — re-reading files a sub-agent already analyzed
32
- 6. **Over-planning** — full decomposition for a 2-file fix
10
+ - **Batch what is independent** — reads, searches and checks that do not depend on each other go in one turn; what depends on an earlier result waits for it.
11
+ - **Read in large ranges** — search to locate, then read the range you need, not many small slices of one file.
12
+ - **Do not re-read** — a file or a sub-agent's result already in context is used as it is.
13
+ - **Verify once per phase** — run tests, lint and build after a batch of edits, not after each one.
14
+ - **Scale planning to the change** — one or two files: act; ten or more: decompose first.
15
+ - **Hand over what you know** — a delegation prompt names the files and facts the agent would otherwise rediscover.
33
16
 
34
17
  <!-- End of AI Optimization Instructions -->