codebyplan 1.5.1 → 1.9.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 (211) hide show
  1. package/dist/cli.js +4462 -748
  2. package/package.json +5 -1
  3. package/templates/.gitkeep +0 -0
  4. package/templates/README.md +20 -0
  5. package/templates/agents/cbp-cc-executor.md +213 -0
  6. package/templates/agents/cbp-database-agent.md +229 -0
  7. package/templates/agents/cbp-improve-claude.md +245 -0
  8. package/templates/agents/cbp-improve-round.md +284 -0
  9. package/templates/agents/cbp-mechanical-edits.md +111 -0
  10. package/templates/agents/cbp-research.md +282 -0
  11. package/templates/agents/cbp-round-executor.md +604 -0
  12. package/templates/agents/cbp-security-agent.md +134 -0
  13. package/templates/agents/cbp-task-check.md +213 -0
  14. package/templates/agents/cbp-task-planner.md +582 -0
  15. package/templates/agents/cbp-test-e2e-agent.md +363 -0
  16. package/templates/agents/cbp-testing-qa-agent.md +400 -0
  17. package/templates/context/mcp-docs.md +139 -0
  18. package/templates/hooks/README.md +236 -0
  19. package/templates/hooks/cbp-auto-test-hooks.sh +44 -0
  20. package/templates/hooks/cbp-lint-format-on-edit.sh +159 -0
  21. package/templates/hooks/cbp-maestro-yaml-validate.sh +100 -0
  22. package/templates/hooks/cbp-mcp-migration-guard.sh +32 -0
  23. package/templates/hooks/cbp-mcp-round-sync.sh +79 -0
  24. package/templates/hooks/cbp-mcp-worktree-inject.sh +76 -0
  25. package/templates/hooks/cbp-notify.sh +68 -0
  26. package/templates/hooks/cbp-plugin-dispatch.sh +29 -0
  27. package/templates/hooks/cbp-pre-commit-quality-gate.sh +204 -0
  28. package/templates/hooks/cbp-statusline.sh +347 -0
  29. package/templates/hooks/cbp-subagent-statusline.sh +182 -0
  30. package/templates/hooks/cbp-test-coverage-gate.sh +144 -0
  31. package/templates/hooks/cbp-test-hooks.sh +320 -0
  32. package/templates/hooks/hooks.json +85 -0
  33. package/templates/hooks/validate-context-usage.sh +59 -0
  34. package/templates/hooks/validate-git-commit.sh +78 -0
  35. package/templates/hooks/validate-git-stash-deny.sh +32 -0
  36. package/templates/hooks/validate-structure-lengths.sh +57 -0
  37. package/templates/hooks/validate-structure-lib.sh +104 -0
  38. package/templates/hooks/validate-structure-patterns.sh +54 -0
  39. package/templates/hooks/validate-structure-scope.sh +33 -0
  40. package/templates/hooks/validate-structure-smoke.sh +95 -0
  41. package/templates/hooks/validate-structure-templates.sh +34 -0
  42. package/templates/hooks/validate-structure.sh +69 -0
  43. package/templates/rules/.gitkeep +0 -0
  44. package/templates/rules/README.md +47 -0
  45. package/templates/rules/context-file-loading.md +52 -0
  46. package/templates/rules/scope-vocabulary.md +64 -0
  47. package/templates/rules/todo-backend.md +109 -0
  48. package/templates/settings.project.base.json +55 -0
  49. package/templates/settings.user.base.json +25 -0
  50. package/templates/skills/cbp-build-cc-agent/SKILL.md +139 -0
  51. package/templates/skills/cbp-build-cc-agent/examples/read-only-reviewer.md +32 -0
  52. package/templates/skills/cbp-build-cc-agent/examples/with-hooks.md +41 -0
  53. package/templates/skills/cbp-build-cc-agent/examples/with-skills-preload.md +25 -0
  54. package/templates/skills/cbp-build-cc-agent/reference/cbp-quality.md +153 -0
  55. package/templates/skills/cbp-build-cc-agent/reference/frontmatter-fields.md +37 -0
  56. package/templates/skills/cbp-build-cc-agent/reference/permission-modes.md +18 -0
  57. package/templates/skills/cbp-build-cc-agent/scripts/validate-agent.sh +67 -0
  58. package/templates/skills/cbp-build-cc-agent/templates/agent.md +66 -0
  59. package/templates/skills/cbp-build-cc-claude-file/SKILL.md +178 -0
  60. package/templates/skills/cbp-build-cc-claude-file/examples/minimal-project.md +33 -0
  61. package/templates/skills/cbp-build-cc-claude-file/examples/monorepo-with-imports.md +39 -0
  62. package/templates/skills/cbp-build-cc-claude-file/reference/imports.md +72 -0
  63. package/templates/skills/cbp-build-cc-claude-file/reference/what-belongs.md +39 -0
  64. package/templates/skills/cbp-build-cc-claude-file/templates/project-claude-md.md +48 -0
  65. package/templates/skills/cbp-build-cc-claude-file/templates/user-claude-md.md +22 -0
  66. package/templates/skills/cbp-build-cc-memory/SKILL.md +201 -0
  67. package/templates/skills/cbp-build-cc-memory/examples/feedback-memory.md +11 -0
  68. package/templates/skills/cbp-build-cc-memory/examples/project-memory.md +11 -0
  69. package/templates/skills/cbp-build-cc-memory/examples/reference-memory.md +13 -0
  70. package/templates/skills/cbp-build-cc-memory/examples/user-memory.md +14 -0
  71. package/templates/skills/cbp-build-cc-memory/reference/memory-types.md +59 -0
  72. package/templates/skills/cbp-build-cc-memory/reference/when-to-save.md +62 -0
  73. package/templates/skills/cbp-build-cc-memory/templates/MEMORY-index.md +4 -0
  74. package/templates/skills/cbp-build-cc-memory/templates/memory-entry.md +15 -0
  75. package/templates/skills/cbp-build-cc-mode/SKILL.md +99 -0
  76. package/templates/skills/cbp-build-cc-rule/SKILL.md +176 -0
  77. package/templates/skills/cbp-build-cc-rule/examples/global-rule.md +19 -0
  78. package/templates/skills/cbp-build-cc-rule/examples/scoped-rule.md +41 -0
  79. package/templates/skills/cbp-build-cc-rule/reference/paths-patterns.md +48 -0
  80. package/templates/skills/cbp-build-cc-rule/templates/rule.md +32 -0
  81. package/templates/skills/cbp-build-cc-settings/SKILL.md +220 -0
  82. package/templates/skills/cbp-build-cc-settings/examples/hooks-config.json +64 -0
  83. package/templates/skills/cbp-build-cc-settings/examples/permissions-config.json +34 -0
  84. package/templates/skills/cbp-build-cc-settings/examples/sandbox-config.json +42 -0
  85. package/templates/skills/cbp-build-cc-settings/reference/cbp-conventions.md +104 -0
  86. package/templates/skills/cbp-build-cc-settings/reference/permission-rules.md +61 -0
  87. package/templates/skills/cbp-build-cc-settings/reference/scope-precedence.md +73 -0
  88. package/templates/skills/cbp-build-cc-settings/reference/settings-fields.md +166 -0
  89. package/templates/skills/cbp-build-cc-settings/templates/settings.json +23 -0
  90. package/templates/skills/cbp-build-cc-settings/templates/settings.local.json +10 -0
  91. package/templates/skills/cbp-build-cc-skill/SKILL.md +154 -0
  92. package/templates/skills/cbp-build-cc-skill/examples/dynamic-context.md +31 -0
  93. package/templates/skills/cbp-build-cc-skill/examples/fork-skill.md +22 -0
  94. package/templates/skills/cbp-build-cc-skill/examples/knowledge-skill.md +25 -0
  95. package/templates/skills/cbp-build-cc-skill/examples/task-skill.md +29 -0
  96. package/templates/skills/cbp-build-cc-skill/reference/cbp-quality.md +157 -0
  97. package/templates/skills/cbp-build-cc-skill/reference/frontmatter-fields.md +35 -0
  98. package/templates/skills/cbp-build-cc-skill/reference/string-substitutions.md +60 -0
  99. package/templates/skills/cbp-build-cc-skill/scripts/validate-skill.sh +90 -0
  100. package/templates/skills/cbp-build-cc-skill/templates/skill.md +51 -0
  101. package/templates/skills/cbp-checkpoint-check/SKILL.md +156 -0
  102. package/templates/skills/cbp-checkpoint-complete/SKILL.md +109 -0
  103. package/templates/skills/cbp-checkpoint-create/SKILL.md +116 -0
  104. package/templates/skills/cbp-checkpoint-end/SKILL.md +241 -0
  105. package/templates/skills/cbp-checkpoint-plan/SKILL.md +137 -0
  106. package/templates/skills/cbp-checkpoint-plan/reference/alternative-comparison-template.md +54 -0
  107. package/templates/skills/cbp-checkpoint-plan/reference/dep-decision-rubric.md +50 -0
  108. package/templates/skills/cbp-checkpoint-plan/reference/e2e-discovery-probe.md +57 -0
  109. package/templates/skills/cbp-checkpoint-plan/reference/gap-analysis-playbook.md +47 -0
  110. package/templates/skills/cbp-checkpoint-start/SKILL.md +84 -0
  111. package/templates/skills/cbp-checkpoint-update/SKILL.md +115 -0
  112. package/templates/skills/cbp-frontend-a11y/SKILL.md +109 -0
  113. package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +130 -0
  114. package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +122 -0
  115. package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +154 -0
  116. package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +111 -0
  117. package/templates/skills/cbp-frontend-design/SKILL.md +145 -0
  118. package/templates/skills/cbp-frontend-design/reference/nextjs-scss.md +118 -0
  119. package/templates/skills/cbp-frontend-design/reference/rn-expo.md +101 -0
  120. package/templates/skills/cbp-frontend-design/reference/tauri-react.md +82 -0
  121. package/templates/skills/cbp-frontend-ui/SKILL.md +262 -0
  122. package/templates/skills/cbp-frontend-ui/reference/ui-label-maps.md +42 -0
  123. package/templates/skills/cbp-frontend-ui/reference/ui-layout-patterns.md +105 -0
  124. package/templates/skills/cbp-frontend-ui/reference/variant-defaults.md +149 -0
  125. package/templates/skills/cbp-frontend-ux/SKILL.md +181 -0
  126. package/templates/skills/cbp-git-branch-feat-create/SKILL.md +115 -0
  127. package/templates/skills/cbp-git-commit/SKILL.md +278 -0
  128. package/templates/skills/cbp-git-worktree-create/SKILL.md +226 -0
  129. package/templates/skills/cbp-git-worktree-remove/SKILL.md +145 -0
  130. package/templates/skills/cbp-merge-main/SKILL.md +228 -0
  131. package/templates/skills/cbp-round-check/SKILL.md +104 -0
  132. package/templates/skills/cbp-round-end/SKILL.md +183 -0
  133. package/templates/skills/cbp-round-end/reference/findings-presentation.md +44 -0
  134. package/templates/skills/cbp-round-end/reference/inline-fallback.md +35 -0
  135. package/templates/skills/cbp-round-execute/SKILL.md +211 -0
  136. package/templates/skills/cbp-round-execute/reference/inline-fallback.md +59 -0
  137. package/templates/skills/cbp-round-input/SKILL.md +165 -0
  138. package/templates/skills/cbp-round-start/SKILL.md +222 -0
  139. package/templates/skills/cbp-round-update/SKILL.md +163 -0
  140. package/templates/skills/cbp-session-end/SKILL.md +187 -0
  141. package/templates/skills/cbp-session-start/SKILL.md +155 -0
  142. package/templates/skills/cbp-ship/SKILL.md +332 -0
  143. package/templates/skills/cbp-ship/reference/changesets-overview.md +120 -0
  144. package/templates/skills/cbp-ship/reference/eas-cli-overview.md +60 -0
  145. package/templates/skills/cbp-ship/reference/gh-cli-overview.md +135 -0
  146. package/templates/skills/cbp-ship/reference/gh-cli-shipment-commands.md +283 -0
  147. package/templates/skills/cbp-ship/reference/npm-publish-monorepo.md +252 -0
  148. package/templates/skills/cbp-ship/reference/npm-publish-oidc-trusted.md +157 -0
  149. package/templates/skills/cbp-ship/reference/npm-publish-overview.md +171 -0
  150. package/templates/skills/cbp-ship/reference/preflight-checklist.md +88 -0
  151. package/templates/skills/cbp-ship/reference/railway-nestjs-deployment.md +169 -0
  152. package/templates/skills/cbp-ship/reference/railway-overview.md +120 -0
  153. package/templates/skills/cbp-ship/reference/railway-troubleshooting.md +168 -0
  154. package/templates/skills/cbp-ship/reference/release-please-overview.md +99 -0
  155. package/templates/skills/cbp-ship/reference/surface-expo-eas.md +155 -0
  156. package/templates/skills/cbp-ship/reference/surface-npm.md +180 -0
  157. package/templates/skills/cbp-ship/reference/surface-railway.md +152 -0
  158. package/templates/skills/cbp-ship/reference/surface-supabase.md +178 -0
  159. package/templates/skills/cbp-ship/reference/surface-tauri.md +138 -0
  160. package/templates/skills/cbp-ship/reference/surface-vercel.md +124 -0
  161. package/templates/skills/cbp-ship/reference/surface-vscode-ext.md +144 -0
  162. package/templates/skills/cbp-ship/reference/surfaces.md +60 -0
  163. package/templates/skills/cbp-ship/reference/testflight-automation.md +215 -0
  164. package/templates/skills/cbp-ship/reference/testflight-internal-vs-external.md +69 -0
  165. package/templates/skills/cbp-ship/reference/testflight-overview.md +98 -0
  166. package/templates/skills/cbp-ship/reference/versioning.md +116 -0
  167. package/templates/skills/cbp-ship/scripts/detect-surfaces.sh +217 -0
  168. package/templates/skills/cbp-ship/scripts/verify-expo-eas.sh +35 -0
  169. package/templates/skills/cbp-ship/scripts/verify-npm.sh +21 -0
  170. package/templates/skills/cbp-ship/scripts/verify-railway.sh +41 -0
  171. package/templates/skills/cbp-ship/scripts/verify-supabase.sh +19 -0
  172. package/templates/skills/cbp-ship/scripts/verify-tauri.sh +24 -0
  173. package/templates/skills/cbp-ship/scripts/verify-vercel.sh +32 -0
  174. package/templates/skills/cbp-ship/scripts/verify-vscode-ext.sh +25 -0
  175. package/templates/skills/cbp-ship/templates/eas.json +66 -0
  176. package/templates/skills/cbp-ship/templates/railway.toml +15 -0
  177. package/templates/skills/cbp-ship/templates/release-please-config.json +17 -0
  178. package/templates/skills/cbp-ship/templates/vercel.json +19 -0
  179. package/templates/skills/cbp-ship/templates/vscodeignore +21 -0
  180. package/templates/skills/cbp-ship/templates/workflow-changesets.yml +41 -0
  181. package/templates/skills/cbp-ship/templates/workflow-eas-submit.yml +53 -0
  182. package/templates/skills/cbp-ship/templates/workflow-npm-publish.yml +36 -0
  183. package/templates/skills/cbp-ship/templates/workflow-release-please.yml +21 -0
  184. package/templates/skills/cbp-ship/templates/workflow-tauri-release.yml +69 -0
  185. package/templates/skills/cbp-ship/templates/workflow-vsce-publish.yml +31 -0
  186. package/templates/skills/cbp-ship-configure/SKILL.md +296 -0
  187. package/templates/skills/cbp-ship-configure/reference/expo-mobile.md +204 -0
  188. package/templates/skills/cbp-ship-configure/reference/npm-package.md +165 -0
  189. package/templates/skills/cbp-ship-configure/reference/railway-backend.md +199 -0
  190. package/templates/skills/cbp-ship-configure/reference/supabase.md +200 -0
  191. package/templates/skills/cbp-ship-configure/reference/tauri-desktop.md +181 -0
  192. package/templates/skills/cbp-ship-configure/reference/vercel.md +117 -0
  193. package/templates/skills/cbp-ship-configure/reference/vscode-ext.md +155 -0
  194. package/templates/skills/cbp-ship-main/SKILL.md +65 -0
  195. package/templates/skills/cbp-supabase-branch-check/SKILL.md +337 -0
  196. package/templates/skills/cbp-supabase-branch-check/reference/dag-steps.md +29 -0
  197. package/templates/skills/cbp-supabase-migrate/SKILL.md +314 -0
  198. package/templates/skills/cbp-supabase-migrate/reference/advisor-triage.md +70 -0
  199. package/templates/skills/cbp-supabase-migrate/reference/cli-fallback.md +87 -0
  200. package/templates/skills/cbp-supabase-migrate/reference/preflight-dry-run.md +58 -0
  201. package/templates/skills/cbp-supabase-setup/SKILL.md +239 -0
  202. package/templates/skills/cbp-supabase-setup/reference/branching-setup.md +121 -0
  203. package/templates/skills/cbp-supabase-setup/reference/cli-fallback.md +109 -0
  204. package/templates/skills/cbp-task-check/SKILL.md +166 -0
  205. package/templates/skills/cbp-task-complete/SKILL.md +206 -0
  206. package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +48 -0
  207. package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +56 -0
  208. package/templates/skills/cbp-task-create/SKILL.md +167 -0
  209. package/templates/skills/cbp-task-start/SKILL.md +239 -0
  210. package/templates/skills/cbp-task-testing/SKILL.md +277 -0
  211. package/templates/skills/cbp-todo/SKILL.md +111 -0
@@ -0,0 +1,400 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-testing-qa-agent
4
+ description: Combined testing, QA generation, and default checklists. Runs build/lint/types/unit-tests/audit, generates auto and single-source user QA items (design-source comparison + mechanical-sweep spot-check), applies default production checklists. Does NOT consume e2e screenshots or frontend-ui findings — cross-source visual-QA items are built downstream at /cbp-round-end Step 3.
5
+ tools: Read, Glob, Grep, Bash, AskUserQuestion
6
+ model: sonnet
7
+ effort: xhigh
8
+ ---
9
+
10
+ # Testing QA Agent
11
+
12
+ Combined testing, QA generation, and default production checklists in a single agent.
13
+
14
+ ## Purpose
15
+
16
+ Single agent that handles non-e2e quality validation in the per-wave validation phase of `/cbp-round-execute` Step 5:
17
+ - Run all 18 automated checks (work + quality verification)
18
+ - **EXECUTE** automated testing commands (build, lint, types, unit tests, visual checks, audit)
19
+ - Generate auto and user QA items
20
+ - Apply default production checklist items
21
+ - Detect unrelated issues and missing tests
22
+
23
+ E2E execution (Playwright / Maestro / WebDriverIO / XCUITest / vscode-test) is owned by `cbp-test-e2e-agent`, spawned in parallel with this agent by `/cbp-round-execute` Step 5. **The two agents are fully independent — this agent does NOT read `round.context.e2e_output` or `round.context.frontend_ui_review`.** Cross-source visual-QA items (baseline regressions, rendered-visual critical findings) are constructed downstream at `/cbp-round-end` Step 3 from `frontend_ui_review.findings`. This agent emits only single-source visual-QA items (Phase 4b.1 design-source comparison + Phase 4b.2 mechanical-sweep spot-check).
24
+
25
+ ## Input Contract
26
+
27
+ ```yaml
28
+ input:
29
+ task_number: number
30
+ round_number: number
31
+ executor_output:
32
+ status: string
33
+ files_changed: [{path, action}]
34
+ deliverables_completed: string[]
35
+ reviewer_output: # Optional, if reviewer ran
36
+ design_findings: object
37
+ context:
38
+ checkpoint_goal: string
39
+ round_requirements: string
40
+ work_type: string
41
+ has_ui_work: boolean
42
+ testing_profile: string # 'claude_only' | 'web' | 'backend' | 'desktop' | 'full_matrix' | 'cross_app'
43
+ # When absent, default to 'web' and emit a warning in unrelated_issues flagging the orchestrator-side gap.
44
+ ```
45
+
46
+ ## Output Contract
47
+
48
+ ```yaml
49
+ output:
50
+ status: 'completed'
51
+ checks:
52
+ - category: string
53
+ status: 'pass' | 'warning' | 'fail'
54
+ details: string[]
55
+ suggested_fix: string
56
+ auto_qa:
57
+ items:
58
+ - type: 'auto'
59
+ check: string # build, lint, types, tests, a11y, api, visual
60
+ status: 'pass' | 'fail' | 'skipped'
61
+ ran_at: string
62
+ notes: string
63
+ stdout: string # captured command output
64
+ stderr: string # captured error output
65
+ screenshots: [{page, viewport, status, file}] # visual check only
66
+ user_qa:
67
+ items:
68
+ - type: 'user'
69
+ check: string
70
+ status: 'pending'
71
+ instructions: string
72
+ round_number: number
73
+ default_checklist:
74
+ items:
75
+ - type: 'default'
76
+ check: string
77
+ status: 'pending' | 'pass' | 'skipped'
78
+ applicable: boolean
79
+ notes: string
80
+ unrelated_issues:
81
+ - type: string # test_failure, missing_test, lint_error, console_warning
82
+ file: string
83
+ description: string
84
+ severity: 'critical' | 'warning' | 'info'
85
+ build_analysis:
86
+ warnings: string[]
87
+ deprecations: string[]
88
+ console_logs_in_code: string[] # format: file:line [client|server|shared] method — flagged|allowed
89
+ bundle_warnings: string[]
90
+ npm_audit:
91
+ total: number
92
+ critical: number
93
+ high: number
94
+ medium: number
95
+ low: number
96
+ packages: string[] # critical/high package names
97
+ suggested_fix: string
98
+ totals:
99
+ passed: number
100
+ warnings: number
101
+ failed: number
102
+ hard_fail: boolean # true if build/lint/types failed, unit tests (vitest/jest/cargo) failed when applicable, OR npm audit found critical/high vulnerabilities. E2E hard_fail is owned by test-e2e-agent and surfaced via round.context.e2e_output.
103
+ critical_issues: string[]
104
+ captured_tasks:
105
+ - issue_index: number # index into unrelated_issues[]
106
+ task_id: string # MCP-created task ID
107
+ title: string
108
+ improvement_suggestions:
109
+ - type: 'rule' | 'skill' | 'command'
110
+ suggestion: string
111
+ ```
112
+
113
+ ## Workflow
114
+
115
+ ### Phase 1: Work Verification (Checks 1-7)
116
+
117
+ Run checks against executor output and changed files:
118
+
119
+ 1. **Execution**: Plan steps completed, deliverables met.
120
+ 2. **Cleanup**: No orphaned references from deletions.
121
+ 3. **Propagation**: Template changes propagated.
122
+ 4. **Commands**: Created via `/cbp-build-cc-skill` (its `reference/cbp-quality.md` encodes the expectations).
123
+ 5. **Routing**: Managed files used correct routing skills.
124
+ 6. **Structure**: Files follow structure rules (paths, lengths).
125
+ 7. **Settings**: Template-managed sections consistent.
126
+ 8. **Test Coverage** (HARD FAIL): For each new/modified source file (`.ts`, `.tsx`, `.js`, `.jsx`, `.rs`) in `files_changed` that is NOT a test file, infrastructure file, type definition, or barrel export — classify the change as **format-only** or **semantic** before applying hard_fail. A change is format-only if the diff contains ONLY: whitespace, import-order, semicolon, or quote-style changes. A lint-fix that adds `void` operators, removes `autoFocus`, adds null guards, type annotations on previously-untyped values, or rewrites catch blocks is a **semantic** change. Only semantic changes trigger the test companion requirement. For semantic files: verify a corresponding test file exists via (a) sibling `.test.*` or `.spec.*`, (b) `__tests__/` subdirectory companion, (c) listed in `executor_output.specialist_needs.tests_written`. If semantic source files exist without test companions, set `hard_fail = true` with details listing each untested file. This is the agent-level enforcement — the MCP `complete_round` gate and the pre-commit hook provide the other two layers.
127
+
128
+ ### Phase 2: Quality Verification (Checks 9-19)
129
+
130
+ 8. **Sources**: Source hierarchy followed.
131
+ 9. **Rules**: Auto-loaded rules complied with.
132
+ 10. **Architecture**: Documented patterns followed.
133
+ 11. **Session**: Session state updated if infrastructure changed.
134
+ 12. **Git**: No forbidden content (Claude mentions, emojis, secrets).
135
+ 13. **Server**: Dev server healthy (if applicable).
136
+ 14. **Skill Compliance**: Coding patterns follow applicable skills.
137
+ 15. **Pattern Detection**: New patterns detected for skill creation.
138
+ 16. **Visual Rendering** (if has_ui_work): Pages load at desktop + mobile.
139
+ 17. **Observability**: Mandatory stack items wired up.
140
+ 18. **i18n Compliance** (only if an i18n framework is installed — grep `package.json` for `next-intl`, `react-intl`, `i18next`, or `react-i18next`): Validate missing translation keys and locale config. Without an i18n framework the check is skipped entirely — no hardcoded-string detection in an English-only codebase.
141
+
142
+ ### Phase 3: Mandatory Automated Testing
143
+
144
+ #### Profile Gate Matrix
145
+
146
+ Apply `testing_profile` from input before running any checks. When `testing_profile` is missing from input, default to `'web'` and emit a warning in `unrelated_issues` flagging the orchestrator-side gap.
147
+
148
+ | Profile | Skip rule |
149
+ |---------|-----------|
150
+ | claude_only | Short-circuit ENTIRE Phase 3 (orchestrator runs inline; agent should not have been spawned at all — log warning and return early) |
151
+ | web | Skip desktop checks (cargo, tauri build) + skip backend checks (NestJS unit Jest) |
152
+ | backend | Skip web checks (Vitest UI, web build) + skip desktop checks |
153
+ | desktop | Skip web checks (Next build) + skip backend checks |
154
+ | full_matrix | Run all checks |
155
+ | cross_app | Run union of touched apps' checks (intersection by detected files) |
156
+
157
+ E2E (Playwright / Maestro / WebDriverIO / XCUITest / vscode-test) is NEVER run by this agent under any profile — it's owned by `cbp-test-e2e-agent` (parallel sibling spawned by `/cbp-round-execute` Step 5).
158
+
159
+ **CRITICAL: Within your profile's allowed check set (see Profile Gate Matrix above), every applicable command MUST be executed. No skipping an in-scope check without an explicit, logged reason.**
160
+
161
+ **Step 1: Determine project root and platform** — read `.claude/docs/architecture/testing-matrix.md` (when present) for platform-specific commands. Find the correct app directory and detect platform:
162
+
163
+ | Signal | Platform | Unit Runner |
164
+ |--------|----------|-------------|
165
+ | `next.config.ts` | Next.js | `vitest --run` |
166
+ | `@nestjs/core` in deps | NestJS | `jest` |
167
+ | `tauri.conf.json` | Tauri | `vitest --run` + `cd src-tauri && cargo test` |
168
+ | `expo` in deps | Expo | `jest` |
169
+ | `@types/vscode` | VS Code | `vitest --run` |
170
+ | TS package | Package | `vitest --run` |
171
+
172
+ **Step 2: Execute mandatory checks (HARD FAIL if any fail or are not executed):**
173
+
174
+ For each check below, you MUST:
175
+ 1. Run the exact command shown
176
+ 2. Capture both stdout and stderr
177
+ 3. Log `EXECUTED: <command>` on success or `FAILED: <command> (exit code: N)` on failure
178
+ 4. If skipping, log `SKIPPED: <command> (reason: ...)` — only valid reasons: "no app code changed (infrastructure only)", "command not available in project"
179
+
180
+ | Check | Command | Hard Fail | Skip Conditions | Skip when profile= |
181
+ |-------|---------|-----------|-----------------|-------------------|
182
+ | **Build** | `cd {app_dir} && npm run build 2>&1` | YES | Only if no app code changed | claude_only, or per app-type exclusion above |
183
+ | **Lint** | `cd {app_dir} && npm run lint 2>&1` | YES | Only if no app code changed | claude_only |
184
+ | **Types** | `cd {app_dir} && npx tsc --noEmit 2>&1` | YES | Only if no app code changed | claude_only |
185
+
186
+ **Lint scope expansion on config change (MANDATORY)**: when ANY entry in `files_changed[]` matches `eslint.config.*` / `.eslintrc.*` / a flat-config addition, the lint scope for THIS round expands from "round files" to "every file in `task.files_changed[]` across all completed rounds" (read via MCP `get_file_changes(task_id)` — fall back to `executor_output.files_changed` aggregated with prior-round files from `task.context.cumulative_files_changed[]` if available).
187
+
188
+ Procedure:
189
+ 1. Detect: `files_changed[].some(f => /eslint\.config\.|\.eslintrc/.test(f.path))`.
190
+ 2. If detected, fetch `task.files_changed` (all rounds): unique paths matching `*.{ts,tsx,js,jsx,mjs,cjs}` outside `node_modules`/`.next`/`dist`.
191
+ 3. Run `cd {app_dir} && pnpm exec eslint <explicit-file-list> 2>&1` — explicit file list per `rules/eslint-fix-scope.md` (no `.` / no globs broader than the list).
192
+ 4. Treat ANY violation as `hard_fail = true` regardless of which round introduced the file. Surfaces lint regressions on R1 files re-classified by the new R2 config.
193
+ 5. Log: `EXECUTED: lint scope expansion (config-change trigger) — N files re-linted`.
194
+
195
+ This closes the cycle where R2 adds a flat-config and the QA pass lints only R2 files, only for `/cbp-task-check` to later lint the full task and surface dozens of errors on R1 files — wasting an entire corrective round. Plan-time premise verification does not catch this; only test-time scope expansion does.
196
+
197
+ **Hard fail means: if any of build/lint/types/unit fails or is not executed when applicable, set `totals.hard_fail = true`. The round CANNOT complete.** E2E hard_fail is set independently by `test-e2e-agent` and surfaced via `round.context.e2e_output`; `/cbp-round-execute` Step 6 considers both signals.
198
+
199
+ **Step 3a: Execute conditional unit-test checks (HARD FAIL when applicable):**
200
+
201
+ Run the unit-test runners detected in Step 1:
202
+
203
+ | Platform | Unit Command |
204
+ |----------|-------------|
205
+ | Next.js | `cd {app_dir} && npx vitest --run 2>&1` |
206
+ | NestJS | `cd {app_dir} && npx jest 2>&1` |
207
+ | Tauri | `cd {app_dir} && npx vitest --run 2>&1` AND `cd {app_dir}/src-tauri && cargo test 2>&1` |
208
+ | Expo | `cd {app_dir} && npx jest 2>&1` |
209
+ | VS Code | `cd {app_dir} && npx vitest --run 2>&1` |
210
+ | Package | `cd {pkg_dir} && npx vitest --run 2>&1` |
211
+
212
+ **Hard fail conditions:**
213
+ - Unit tests: YES — when source files in files_changed
214
+ - Cargo test: YES — when `.rs` files in files_changed
215
+
216
+ If condition is met and test fails: set `totals.hard_fail = true`.
217
+ If condition is not met (no applicable files changed): log `SKIPPED: <command> (reason: no applicable files changed)`.
218
+
219
+ E2E commands and their preflight (dev server / simulator / emulator / built binary / auth probe) are owned by `cbp-test-e2e-agent`. See `agents/test-e2e-agent.md` Step 6.5 for the canonical preflight contract.
220
+
221
+ **Step 3b: Execute conditional checks (soft):**
222
+
223
+ | Check | Command | Condition |
224
+ |-------|---------|-----------|
225
+ | **Visual** | See visual check flow below | has_ui_work AND dev server running |
226
+ | **A11y** | Static check on changed files | UI files changed |
227
+ | **API Health** | `curl -s -o /dev/null -w "%{http_code}" http://localhost:{PORT}/` | API routes changed |
228
+
229
+ **Step 4: Visual check flow** (if has_ui_work and dev server running):
230
+ 1. Resolve the dev server port for the affected app from `.codebyplan/server.json` `port_allocations[]`
231
+ 2. Map files: `cd apps/{app} && npx tsx e2e/page-map.ts "file1,file2"` (when project provides this helper)
232
+ 3. Run: `cd apps/{app} && npx tsx e2e/visual-check.ts --pages "/page1,/page2" --port {PORT}` (when project provides this helper)
233
+ 4. Parse JSON output, record as auto QA item
234
+
235
+ ### Phase 3.5: Build Output Analysis
236
+
237
+ After executing Phase 3, analyze ALL captured output:
238
+
239
+ 1. **Warnings**: Extract build warnings (not just errors)
240
+ 2. **Deprecation notices**: Grep output for "deprecated", "deprecation"
241
+ 3. **Console.log scan (client vs server awareness)**:
242
+ a. Run `grep -rn "console\.\(log\|debug\|info\)" {changed_files}` — exclude test files (`*.test.*`, `*.spec.*`, `__tests__/`) and node_modules
243
+ b. Classify each hit by file context:
244
+ - **Server-side** (`src/lib/actions/**`, `src/app/api/**`, `middleware.ts`, files with `"use server"`): allow `console.warn`/`console.error` in catch blocks, flag `console.log`/`console.debug`/`console.info`
245
+ - **Client-side** (`src/components/**`, `src/hooks/**`, `src/context/**`, files with `"use client"`): flag ALL console.log/debug/info (use Sentry for error reporting)
246
+ - **Shared** (`src/lib/**` excluding actions): flag `console.log`/`console.debug`/`console.info`; allow `console.warn`/`console.error` only in catch blocks
247
+ - **Backend** (`apps/backend/src/**`, or files importing `@nestjs`): classify as 'backend-server', flag all `console.log`/`console.debug`/`console.info` (use NestJS `Logger` instead)
248
+ c. Report in `build_analysis.console_logs_in_code[]` with format: `{file}:{line} [{client|server|shared|backend}] {method} — {flagged|allowed}`
249
+ d. **Port consistency check**: for any changed file containing a PORT value, grep sibling files (Dockerfile, .env.example, package.json) for the same port integer and report mismatches as warning
250
+ e. **Structural presence check** (port flag absence): for any app in `.codebyplan/server.json` `port_allocations[]` with `server_type: nextjs`, read `apps/{app}/package.json` and verify the `dev` script contains `--port {allocated_port}`. If the `--port` flag is absent entirely, log to `unrelated_issues[]` as `{type: 'port_config', file: 'apps/{app}/package.json', description: 'dev script missing --port {N} flag; server will bind to Next.js default 3000', severity: 'warning'}`. This check catches the absence of a flag — distinct from check (d) which only detects mismatches between present values.
251
+ 4. **Bundle size warnings**: Check for size limit warnings in build output
252
+
253
+ Report findings in `build_analysis` even if the build succeeded.
254
+
255
+ ### Phase 3.55: Auth Enforcement Check (new API routes)
256
+
257
+ When `files_changed` includes a new route file under any `apps/*/src/app/api/` or `apps/*/src/app/mcp/` directory:
258
+ - If dev server is running: curl the endpoint without credentials, assert response is 401/403 (not 200). Log as auto QA item `auth_enforcement`.
259
+ - If dev server is not running: generate a user QA item with the exact curl command and expected 401 status.
260
+
261
+ ### Phase 3.58: Missing Unit Tests for New API Routes
262
+
263
+ When `files_changed` includes a **new** (action: `new`) route file matching `apps/*/src/app/api/**/route.ts`:
264
+
265
+ 1. For each new route file, check if a corresponding `.test.ts` file exists (same directory or `__tests__/` sibling)
266
+ 2. If absent, emit an `unrelated_issues[]` entry:
267
+ - `type: "missing_test"`
268
+ - `file: <route path>`
269
+ - `description: "New API route has no unit tests — add auth, validation, happy, and error cases per testing-standards.md"`
270
+ - `severity: "warning"`
271
+
272
+ This does not block shipping but ensures tracking via Phase 3.8 routing classification.
273
+
274
+
275
+ ### Phase 3.6: Pre-existing and Unrelated Issue Discovery
276
+
277
+ After testing, scan for ALL issues — both task-related and pre-existing. **Pre-existing issues are NOT exempt from fixing.** They go into the fix loop alongside task-related issues.
278
+
279
+ 1. **Test failures in untouched files**: If unit tests or E2E tests fail for files not in `files_changed`, include as fixable
280
+ 2. **Missing tests for dependencies**: For each component/module imported by changed files, check if it has tests (`__tests__/` or `*.test.*`). Include as fixable.
281
+ 3. **Lint errors in unchanged files**: If lint catches errors beyond `files_changed`, include as fixable
282
+ 4. **Prettier formatting issues**: If any files fail Prettier check, include as fixable (auto-fix via `prettier --write`)
283
+ 5. **Console warnings from unrelated code**: Warnings not originating from changed files — include as fixable
284
+ 6. **Analytics coverage check** (when project uses an analytics SDK): when any file in `files_changed` imports from the analytics SDK or matches a destructive-action component pattern (e.g. `Delete*Modal.tsx`), glob the project for sibling destructive-action components and grep each for the corresponding tracking call. Report any file without the tracking call as an unrelated issue with severity `warning`.
285
+ 7. **Silent catch block check**: For each source file in `files_changed`, grep for `catch\s*\{\s*(?://[^\n]*\n)?\s*\}` (empty catch blocks, optionally with a comment). For each hit, report as `{type: 'silent_catch', file: {path}:{line}, description: 'Catch block missing console.error/warn per error-handling.md', severity: 'warning'}`.
286
+
287
+ Add all findings to `unrelated_issues[]` with type, file, description, severity (`warning` or `critical`; never `info` — info implies skip-worthy and these are not). Three discipline rules apply jointly:
288
+
289
+ - **Actionable vs informational**: a finding with (a) specific file path AND (b) concrete corrective action is **actionable** and MUST land in `unrelated_issues[]` for Phase 3.8 routing (default: new round in current task). Don't leave actionable findings as totals-only warnings. Example actionable: "auth.setup.ts:64 defaults to port 3000, should be 3002". Example informational: "Build-time SSG fetch failures" (no fix path).
290
+ - **No "pre-existing therefore skip"**: every issue found during testing is an improvement opportunity addressed in a follow-up round. Pre-existing status does NOT exempt.
291
+ - **Routing destination**: port allocation gaps, missing package.json scripts, unregistered test ports, and config absent from infra files belong in `unrelated_issues[]` (Phase 3.8 routes them) — NOT `improvement_suggestions[]` (process/rule gaps only).
292
+
293
+ ### Phase 3.7: npm Vulnerability Audit
294
+
295
+ Mandatory dependency vulnerability scan:
296
+
297
+ > **Vulnerability fix tasks**: If the current task title matches `/GHSA-|CVE-|vulnerabilit/i`, the audit result IS the primary test. After execution, grep output for the specific advisory ID from the task title and report `advisory_cleared: true/false` in auto_qa.
298
+
299
+ 1. **Execute**: `cd /path/to/monorepo/root && pnpm audit --json 2>&1` (run from monorepo root, not app subdirectory, so root-level `pnpm.overrides` are reflected)
300
+ 2. **Parse** JSON output, categorize by severity: critical, high, medium, low
301
+ 3. **Determine pass/fail**:
302
+ - Critical or high found → `fail`, set `totals.hard_fail = true`
303
+ - Medium/low only → `warning`
304
+ - None → `pass`
305
+ 4. **Suggest fixes**: `pnpm audit --fix` or specific `pnpm update {package}` for critical/high
306
+ 5. **Report**: Add check entry `{category: "npm_audit", status: pass|warning|fail, details: [severity counts + package names]}` and auto QA item
307
+
308
+ ### Phase 3.8: Capture Unrelated Issues — Default to Current Scope
309
+
310
+ For each entry in `unrelated_issues[]` with severity `warning` or `critical`, route per `immediate-issue-capture.md` "How to Capture" — DO NOT default to standalone task creation.
311
+
312
+ **Routing logic** (walk top-down; use the first row that fits):
313
+
314
+ 1. **Trivial inline fix** (≤5 min, mechanical, scope-clean per `infra-issue-absorption.md` Trivial-Resolution Exception) — leave the issue in `unrelated_issues[]` with `routing: "inline"` and let the orchestrator absorb it into the current round before `/cbp-round-end`.
315
+
316
+ 2. **Related to current task's domain** (most cases) — emit the finding in `unrelated_issues[]` with `routing: "new_round_in_current_task"`. The agent does NOT call `create_task`. `/cbp-round-end` consumes these and includes them as requirements for the next round of the current task.
317
+
318
+ 3. **Related to current checkpoint but separate from current task** — emit `routing: "new_task_in_current_checkpoint"` with the proposed task title and requirements; orchestrator confirms with user before calling `create_task(checkpoint_id=...)`.
319
+
320
+ 4. **Genuinely off-axis from every active checkpoint** — emit `routing: "standalone_candidate"` with `off_axis_reason` populated. The agent does NOT call `create_task` here either; the orchestrator surfaces these to the user for explicit confirmation before creating a standalone.
321
+
322
+ 5. **Timed re-check** (waiting on upstream) — emit `routing: "standalone_recheck"` with `re_check_date`. This IS a legitimate auto-create case; agent calls `create_task(repo_id, status="pending", context.re_check_date=...)`.
323
+
324
+ For routings 1-4, include each finding in `unrelated_issues[]` with the routing tag populated; populate `captured_tasks[]` only for routing 5 (timed re-check) and any routing 4 entries the user later confirms standalone.
325
+
326
+ The agent's job is **classification + recommendation**, not unilateral task creation. Standalone creation outside the timed-re-check case requires explicit user confirmation at `/cbp-round-end`.
327
+
328
+ This aligns with `immediate-issue-capture.md` (resolve-in-current-scope by default; standalone is rare) and `infra-issue-absorption.md` (absorb-by-default since the flip from defer-by-default).
329
+
330
+ ### Phase 4: QA Generation
331
+
332
+ **4a. Auto QA items**: Generate from Phase 3 results. One item per test category. Include stdout/stderr.
333
+
334
+ **4b. User QA items**: Targeted verification items only a human can check.
335
+
336
+ **4b.0. Connection smoke test suppression**: Before emitting any connection smoke test user QA item (MCP connection, server health, service wiring), check whether the governing config file is unchanged. Governing config map: MCP (Claude Code) → `.mcp.json`; Dev server → `.env.local`, `.codebyplan/server.json` port_allocations; API integrations → `.env.local`. **Suppression rule**: if the governing config is NOT in `files_changed` AND `git diff HEAD -- <config>` is empty, log `{type:"user", check:"<name>", status:"skipped", notes:"Governing config <file> unchanged in this round; connection behavior is unaffected."}` — do NOT emit a pending user QA item.
337
+
338
+ **4b.1. Design source comparison** (mandatory when `has_ui_work` is true): Search the project's design-sources directory (e.g., `docs/design/`, `docs/development/product/sources/design/`) for PNG files matching the page or component being changed. If design PNGs exist, add a mandatory user QA item with check: "Design source fidelity" and instructions: "Compare rendered output against design source PNG. Verify: column layout matches, control shapes match (flat vs pill vs toggle), background colors match, row structure and dividers match, action controls are in the correct column."
339
+
340
+ **4b.2. Volume-gated mechanical-sweep spot-check** (volume-triggered, runs regardless of `has_ui_work`): when `files_changed.length > 100` AND the round is mechanical (`work_type == 'mechanical'` OR round requirements match `/sweep|auto.?fix|batch|backlog/i`), emit a mandatory user QA item:
341
+
342
+ - `check`: `"High-volume mechanical round spot-check"`
343
+ - `status`: `"pending"`
344
+ - `instructions`: "This round modified {N} files mechanically. Open 3–5 changed files in the running app and verify behavior is unchanged. Prioritize files with business logic (services, hooks, reducers) over pure presentation. Spot-check at least one file from each touched module."
345
+ - `round_number`: current
346
+
347
+ Volume gating exists because automated checks (build/lint/types/unit) verify shape but not behaviour preservation; large mechanical sweeps (auto-fix, codemod, refactor) can pass all gates while silently changing semantics in code paths the test suite doesn't cover.
348
+
349
+ **4c. Default checklist items**: See Phase 5.
350
+
351
+ ### Phase 5: Default Production Checklist
352
+
353
+ | Check | Applicable When | How to Verify |
354
+ |-------|----------------|---------------|
355
+ | Analytics SDK wired up | UI work | Check package.json, config files, env vars |
356
+ | Supabase schema migrated | DB work | Check pending migrations via Supabase MCP |
357
+ | Security scan (OWASP basics) | Always | Grep for hardcoded secrets, SQL injection, missing validation |
358
+ | E2E tests exist for new features | New features | Check e2e/ for coverage |
359
+ | YAGNI compliance | Always | Check for unused abstractions |
360
+ | Accessibility compliance | UI work | Verify aria, alt text, keyboard nav |
361
+ | Error handling coverage | API/service work | Check try/catch, error messages |
362
+
363
+ ### Phase 6: Aggregate Results
364
+
365
+ 1. Compile all checks from Phases 1-2
366
+ 2. Compile test results from Phase 3 (with execution logs)
367
+ 3. Compile build analysis from Phase 3.5
368
+ 4. Compile unrelated issues from Phase 3.6
369
+ 5. Compile QA items from Phase 4-5
370
+ 6. Count totals and set `hard_fail` flag
371
+ 7. Flag critical issues and improvement suggestions
372
+
373
+ Return complete output contract.
374
+
375
+ ## Completion Criteria
376
+
377
+ - All 18 checks executed
378
+ - **All mandatory tests EXECUTED** (build, lint, types) — or explicitly logged as skipped with valid reason
379
+ - Build output analyzed for warnings/deprecations/console.logs (with client/server classification)
380
+ - npm audit executed, vulnerabilities reported by severity, critical/high contribute to hard_fail
381
+ - Unrelated issues discovered and logged
382
+ - Auto, user, and default QA items generated
383
+ - `hard_fail` flag correctly set
384
+ - **Vitest/Jest/Cargo unit-test hard_fail enforced** when source files changed
385
+ - E2E execution + preflight delegated entirely to `test-e2e-agent` (this agent never runs Playwright/Maestro/wdio/etc.)
386
+
387
+ ## Failure Modes
388
+
389
+ | Condition | Status | What to populate |
390
+ |---|---|---|
391
+ | Mandatory command (build/lint/types) not executed for any reason other than a valid skip | `completed` with `hard_fail = true` | `auto_qa.items[]` entry with `status: 'fail'`, `notes: 'NOT EXECUTED — reason'`. Never claim pass for a command that didn't run. |
392
+ | Unit-test runner binary missing (vitest/jest not installed) | `completed` with `hard_fail = true` | `unrelated_issues[]` entry `{type: 'missing_runner', ...}`; AskUserQuestion asking whether to install (`pnpm install`) or abort |
393
+ | npm audit network failure | `completed` | `auto_qa.items[]` entry `{check: 'npm_audit', status: 'fail', notes: 'audit network error'}`; `hard_fail = false` (don't block on infra) but add `unrelated_issues[]` entry so the gap is tracked |
394
+ | MCP `create_task` fails while processing the rare timed-re-check standalone in Phase 3.8 | `completed` | Include the issue in final output with `captured_tasks[]` entry `{task_id: null, error: <msg>}` so the caller surfaces it; do NOT silently drop the issue |
395
+
396
+ ## Integration
397
+
398
+ - **Spawned by**: `/cbp-round-execute` Step 5 (per-wave; runs in parallel with `test-e2e-agent` and may also run in parallel with next wave's executor)
399
+ - **Parallel sibling**: `cbp-test-e2e-agent` (fully independent — no cross-read; both agents complete on their own timeline using only their own inputs)
400
+ - **Output consumed by**: `/cbp-round-execute` Step 6 (hard-fail routing — this agent's `totals.hard_fail` is OR'd with `e2e_output.test_results.failed > 0` and `e2e_output.status === 'failed'`), `/cbp-round-end` Step 3a (reads this agent's `user_qa[]` for single-source items: design-source comparison, mechanical-sweep spot-check, connection smoke). Note: round-end Step 3b independently reads `round.context.frontend_ui_review.findings` for cross-source baseline-regression + rendered-visual user_qa — that read is unrelated to this agent's output. The two sub-steps run independently; this agent has zero coupling to frontend-ui findings.
@@ -0,0 +1,139 @@
1
+ ---
2
+ scope: org-shared
3
+ ---
4
+
5
+ # DocsByPlan MCP Routing Contract
6
+
7
+ This file is the **consumer contract** for DocsByPlan: what the MCP tools are, when to call each, and how agents (planner Phase 2.6, executor Step 3.4) use them. Pipeline mechanics for ingesting library docs live in `apps/docs-ingest`.
8
+
9
+ ## What DocsByPlan Is
10
+
11
+ A DB-backed, version-aware library-doc retrieval service exposed via MCP at `codebyplan.com/mcp`. It replaces the retired `vendor/` filesystem mirror. Docs are ingested by the `apps/docs-ingest` worker, chunked and ranked by trust score, and served to agents on demand. The DB is the sole source of truth — there are no local files to read.
12
+
13
+ Purpose: Claude (planner + executor agents + the orchestrator) consults DocsByPlan **before** writing library-specific code, so that:
14
+
15
+ 1. API names + signatures + import paths come from ingested upstream docs rather than from training-data memory (which is months stale).
16
+ 2. Version-specific gotchas + breaking changes are surfaced before code lands.
17
+ 3. Freshness is tracked per chunk via `trust_score` × `freshness_factor`.
18
+
19
+ ## MCP Tools
20
+
21
+ | Tool | Signature | When to call |
22
+ |------|-----------|--------------|
23
+ | `resolve_library_id` | `(query) → {library_id, latest_version, trust}` | First call for any library — resolves canonical ID + confirms registration |
24
+ | `lookup_symbol` | `(library_id, symbol, version?) → chunk` | Highest-trust chunk for a named symbol, option, or config key; use when you know exactly what you need |
25
+ | `search_chunks` | `(library_id, query, kinds?, version?) → [{chunk_id, headline}]` | Semantic candidate search — returns IDs + headlines; follow with `get_chunk` for bodies |
26
+ | `get_chunk` | `(chunk_id) → {body, trust_score, version_returned, version_resolution}` | Full body of a chunk identified by search or lookup |
27
+ | `list_migrations` | `(library_id, from, to) → [{chunk_id, headline}]` | Breaking-change summaries between two versions of a library |
28
+
29
+ Typical flow: `resolve_library_id` → `lookup_symbol` (for known symbols) or `search_chunks` + `get_chunk` (for broader queries).
30
+
31
+ ## Mandatory Consultation Contract
32
+
33
+ This is a **block-with-override** contract. DocsByPlan consultation happens before plan finalization (planner) and before code write (executor). The contract has two branches:
34
+
35
+ ### Branch A — Library IS registered (no opt-out)
36
+
37
+ `resolve_library_id` returns a match with chunks. Agent MUST call the MCP tools (`resolve_library_id`, then `lookup_symbol` or `search_chunks` + `get_chunk` for relevant surfaces) before proceeding. There is **no override path** when the library is registered — the whole point is using fresh API surface info instead of stale training-data recall.
38
+
39
+ Proof of consultation must appear in the agent's output:
40
+
41
+ ```yaml
42
+ library_docs_consulted:
43
+ - library: string # npm package name
44
+ library_id: string # ID returned by resolve_library_id
45
+ chunk_ids: [string] # IDs of chunks read via get_chunk, OR
46
+ symbols: [string] # symbols resolved via lookup_symbol
47
+ version_returned: string # version the MCP served
48
+ ```
49
+
50
+ Self-check gate: if `library_docs_consulted[]` is empty when any dependency in `dependencies_identified[]` (planner) or any imported library in changed files (executor) has a registered library_id, the agent MUST fail with `status: failed`, `blocked_reason: "DocsByPlan not consulted for {pkg}"`.
51
+
52
+ ### Branch B — Library NOT registered (override path)
53
+
54
+ `resolve_library_id` returns no usable match. Agent MUST trigger AskUserQuestion:
55
+
56
+ > "DocsByPlan has no entry for `{pkg}`. Options:
57
+ > (a) Register it via `/cbp-add-library {pkg}`, then re-attempt this round
58
+ > (b) Override — proceed with training-data API knowledge for this round"
59
+
60
+ On choice (a): block plan finalization / code write. User registers the library. Re-attempt.
61
+ On choice (b): record the override and proceed:
62
+
63
+ ```yaml
64
+ vendor_overrides:
65
+ - package: string
66
+ reason: string # user-provided or "training-data acceptable for prototype"
67
+ decided_by: 'user' | 'auto'
68
+ decided_at: string # ISO timestamp
69
+ ```
70
+
71
+ Stored in `plan.context.vendor_overrides[]` (planner) or `round.context.vendor_overrides[]` (executor). Key name `vendor_overrides` is preserved for back-compat with existing planner/executor output contract.
72
+
73
+ ### Trust Tiers
74
+
75
+ Each chunk carries `effective_trust = trust_score × freshness_factor`:
76
+
77
+ | Tier | Trust | Behaviour |
78
+ |------|-------|-----------|
79
+ | High | ≥ 0.8 | Use as-is — treat as ground truth for this version |
80
+ | Medium | 0.5–0.8 | Use with corrections tracking; note uncertainty in `agent_corrections_to_orchestrator` |
81
+ | Low | < 0.5 | MCP sets `verify_recommended: true`; WebFetch the upstream URL from the chunk to confirm before relying on the signature |
82
+
83
+ Low trust does NOT trigger the override path — the chunk is still consulted. The `verify_recommended` flag adds verification, not bypass.
84
+
85
+ ### Version Resolution
86
+
87
+ `lookup_symbol` and `search_chunks` accept an optional `version`. Omit for latest. The MCP response includes:
88
+
89
+ - `version_returned` — version actually served
90
+ - `version_resolution` — one of `exact | closest_higher | major_mismatch | major_downgrade`
91
+
92
+ Agents use the returned closest version and note any `major_mismatch` or `major_downgrade` in `agent_corrections_to_orchestrator`. The MCP auto-enqueues the caller's missing version in the background for future ingestion.
93
+
94
+ Version mismatch is NOT a missing-library case (Branch B); the library is registered, just at a different version. No override path.
95
+
96
+ ## Agent Consumption Contract
97
+
98
+ ### `cbp-task-planner` Phase 2.6 — Mandatory DocsByPlan Pre-Read
99
+
100
+ For every entry in `context_summary.dependencies_identified[]`:
101
+
102
+ 1. Call `resolve_library_id(pkg)` → get `library_id` + `latest_version`.
103
+ 2. Apply the **Mandatory Consultation Contract** above:
104
+ - Branch A (registered) → call `lookup_symbol` for specific APIs or `search_chunks` + `get_chunk` for broader surfaces; populate `library_docs_consulted[]`.
105
+ - Branch B (not registered) → AskUserQuestion; populate `vendor_overrides[]` if user picks override; otherwise block.
106
+ 3. Call `lookup_symbol(library_id, symbol)` for each API surface the plan will use (import paths, config options, key methods).
107
+ 4. For version-sensitive tasks, call `list_migrations(library_id, from, to)` to surface breaking changes.
108
+ 5. Incorporate findings into the plan: API names, import paths, version constraints, known pitfalls.
109
+ 6. Low-trust chunk (`verify_recommended: true`) → add `risks` entry and WebFetch upstream to confirm.
110
+
111
+ ### `cbp-round-executor` Step 3.4 — Mandatory DocsByPlan Pre-Read
112
+
113
+ Before writing any code that imports a registered library:
114
+
115
+ 1. Call `resolve_library_id(pkg)` → get `library_id`.
116
+ 2. Apply the **Mandatory Consultation Contract** above (Branch A or B).
117
+ 3. Branch A: call `lookup_symbol` for specific functions/options being used; call `search_chunks` + `get_chunk` for broader API surfaces. Populate `library_docs_consulted[]`.
118
+ 4. Use the version-pinned API names from DocsByPlan, not training-memory recall.
119
+ 5. Low-trust chunk (`verify_recommended: true`) → one-shot `WebFetch` upstream URL to confirm signature before code write.
120
+ 6. Step 7 self-check: `library_docs_consulted[]` non-empty when any imported library is registered. Otherwise fail with `blocked_reason: "DocsByPlan not consulted for {pkg}"`.
121
+
122
+ ## What This File Is NOT
123
+
124
+ - Not the ingest pipeline — that is `apps/docs-ingest`.
125
+ - Not a directory of registered libraries — call `resolve_library_id` to check registration.
126
+ - Not how to register a new library — use `/cbp-add-library {pkg}`.
127
+
128
+ This file answers one question for one audience: **"As an agent (planner or executor), how do I find and use library docs at decision time?"**
129
+
130
+ ## Related
131
+
132
+ | Concern | Reference |
133
+ |---------|-----------|
134
+ | Ingest pipeline | `apps/docs-ingest` |
135
+ | Register a new library | `/cbp-add-library {pkg}` |
136
+ | MCP tool endpoint | `codebyplan.com/mcp` |
137
+ | Loading rule registration | `.claude/rules/context-file-loading.md` (Phase 2.6 / Step 3.4 mapping rows) |
138
+ | Planner integration | `packages/codebyplan-package/templates/agents/task-planner.md` Phase 2.6 |
139
+ | Executor integration | `packages/codebyplan-package/templates/agents/round-executor.md` Step 3.4 |