buildanything 1.7.1 → 2.0.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 (633) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +9 -3
  3. package/CHANGELOG.md +112 -0
  4. package/README.md +2 -2
  5. package/agents/a11y-architect.md +166 -0
  6. package/agents/business-model.md +80 -29
  7. package/agents/code-architect.md +75 -0
  8. package/agents/code-reviewer.md +255 -0
  9. package/agents/code-simplifier.md +64 -0
  10. package/agents/design-brand-guardian.md +293 -53
  11. package/agents/design-critic.md +139 -0
  12. package/agents/design-inclusive-visuals-specialist.md +6 -19
  13. package/agents/design-ui-designer.md +335 -56
  14. package/agents/design-ux-architect.md +403 -55
  15. package/agents/design-ux-researcher.md +264 -49
  16. package/agents/engineering-ai-engineer.md +26 -36
  17. package/agents/engineering-backend-architect.md +185 -36
  18. package/agents/engineering-data-engineer.md +225 -43
  19. package/agents/engineering-devops-automator.md +227 -74
  20. package/agents/engineering-frontend-developer.md +210 -34
  21. package/agents/engineering-mobile-app-builder.md +6 -1
  22. package/agents/engineering-rapid-prototyper.md +30 -9
  23. package/agents/engineering-security-engineer.md +263 -61
  24. package/agents/engineering-senior-developer.md +128 -19
  25. package/agents/engineering-sre.md +84 -0
  26. package/agents/engineering-technical-writer.md +285 -41
  27. package/agents/feature-intel.md +110 -0
  28. package/agents/ios-app-review-guardian.md +66 -0
  29. package/agents/ios-foundation-models-specialist.md +64 -0
  30. package/agents/ios-storekit-specialist.md +59 -0
  31. package/agents/ios-swift-architect.md +129 -0
  32. package/agents/ios-swift-search.md +137 -0
  33. package/agents/ios-swift-ui-design.md +136 -0
  34. package/agents/marketing-app-store-optimizer.md +246 -64
  35. package/agents/planner.md +216 -0
  36. package/agents/pr-test-analyzer.md +63 -0
  37. package/agents/product-feedback-synthesizer.md +8 -2
  38. package/agents/refactor-cleaner.md +102 -0
  39. package/agents/security-reviewer.md +128 -0
  40. package/agents/silent-failure-hunter.md +54 -0
  41. package/agents/swift-build-resolver.md +119 -0
  42. package/agents/swift-reviewer.md +112 -0
  43. package/agents/tech-feasibility.md +21 -1
  44. package/agents/testing-api-tester.md +236 -59
  45. package/agents/testing-evidence-collector.md +26 -1
  46. package/agents/testing-performance-benchmarker.md +21 -1
  47. package/agents/testing-reality-checker.md +6 -1
  48. package/agents/visual-research.md +116 -0
  49. package/bin/adapters/cycle-counter-tool.ts +155 -0
  50. package/bin/adapters/scribe-tool.ts +71 -0
  51. package/bin/adapters/state-save-tool.ts +130 -0
  52. package/bin/adapters/write-lease-tool.ts +127 -0
  53. package/bin/buildanything-runtime.js +15 -0
  54. package/bin/buildanything-runtime.ts +328 -0
  55. package/bin/setup.js +83 -8
  56. package/commands/add-feature.md +2 -0
  57. package/commands/build.md +752 -332
  58. package/commands/fix.md +65 -0
  59. package/commands/self-check.md +121 -0
  60. package/commands/setup.md +114 -0
  61. package/commands/ux-review.md +63 -0
  62. package/commands/verify.md +69 -0
  63. package/docs/migration/agents.yaml +729 -0
  64. package/docs/migration/phase-graph.yaml +1088 -0
  65. package/docs/migration/sdk-host-compat.md +18 -0
  66. package/hooks/compile-writer-owner-cache.ts +171 -0
  67. package/hooks/hooks.json +36 -0
  68. package/hooks/pre-tool-use +19 -0
  69. package/hooks/pre-tool-use.ts +776 -0
  70. package/hooks/record-mode-transitions.ts +178 -0
  71. package/hooks/session-start +89 -2
  72. package/hooks/subagent-start +17 -0
  73. package/hooks/subagent-start.ts +471 -0
  74. package/hooks/subagent-stop +17 -0
  75. package/hooks/subagent-stop.ts +153 -0
  76. package/package.json +28 -5
  77. package/protocols/architecture-schema.md +171 -0
  78. package/protocols/build-fix.md +52 -0
  79. package/protocols/cleanup.md +54 -0
  80. package/protocols/decision-log.md +131 -0
  81. package/protocols/eval-harness.md +61 -0
  82. package/protocols/fake-data-detector.md +64 -0
  83. package/protocols/ios-context.md +234 -0
  84. package/protocols/ios-frameworks-map.md +323 -0
  85. package/protocols/ios-phase-branches.md +337 -0
  86. package/protocols/ios-preflight.md +27 -0
  87. package/protocols/launch-readiness.md +258 -0
  88. package/protocols/metric-loop.md +153 -0
  89. package/protocols/smoke-test.md +118 -0
  90. package/protocols/state-schema.json +388 -0
  91. package/protocols/state-schema.md +172 -0
  92. package/protocols/verify.md +127 -0
  93. package/protocols/visual-dna.md +185 -0
  94. package/protocols/web-phase-branches.md +351 -0
  95. package/skills/ios/_VENDORED.md +62 -0
  96. package/skills/ios/activitykit/LICENSE +131 -0
  97. package/skills/ios/activitykit/SKILL.md +505 -0
  98. package/skills/ios/activitykit/references/activitykit-patterns.md +868 -0
  99. package/skills/ios/app-intents/LICENSE +131 -0
  100. package/skills/ios/app-intents/SKILL.md +494 -0
  101. package/skills/ios/app-intents/references/appintents-advanced.md +1076 -0
  102. package/skills/ios/app-store-connect-metadata/SKILL.md +148 -0
  103. package/skills/ios/apple-on-device-ai/LICENSE +131 -0
  104. package/skills/ios/apple-on-device-ai/SKILL.md +505 -0
  105. package/skills/ios/apple-on-device-ai/references/coreml-conversion.md +425 -0
  106. package/skills/ios/apple-on-device-ai/references/coreml-optimization.md +344 -0
  107. package/skills/ios/apple-on-device-ai/references/foundation-models.md +508 -0
  108. package/skills/ios/apple-on-device-ai/references/mlx-swift.md +285 -0
  109. package/skills/ios/asc-privacy-manifest/SKILL.md +350 -0
  110. package/skills/ios/hig-components-content/SKILL.md +86 -0
  111. package/skills/ios/hig-components-content/references/activity-views.md +79 -0
  112. package/skills/ios/hig-components-content/references/charts.md +180 -0
  113. package/skills/ios/hig-components-content/references/collections.md +48 -0
  114. package/skills/ios/hig-components-content/references/color-wells.md +42 -0
  115. package/skills/ios/hig-components-content/references/image-views.md +82 -0
  116. package/skills/ios/hig-components-content/references/image-wells.md +34 -0
  117. package/skills/ios/hig-components-content/references/lockups.md +78 -0
  118. package/skills/ios/hig-components-content/references/web-views.md +36 -0
  119. package/skills/ios/hig-components-controls/SKILL.md +88 -0
  120. package/skills/ios/hig-components-controls/references/combo-boxes.md +40 -0
  121. package/skills/ios/hig-components-controls/references/controls.md +112 -0
  122. package/skills/ios/hig-components-controls/references/gauges.md +74 -0
  123. package/skills/ios/hig-components-controls/references/labels.md +92 -0
  124. package/skills/ios/hig-components-controls/references/pickers.md +128 -0
  125. package/skills/ios/hig-components-controls/references/rating-indicators.md +38 -0
  126. package/skills/ios/hig-components-controls/references/segmented-controls.md +94 -0
  127. package/skills/ios/hig-components-controls/references/sliders.md +92 -0
  128. package/skills/ios/hig-components-controls/references/steppers.md +40 -0
  129. package/skills/ios/hig-components-controls/references/text-fields.md +88 -0
  130. package/skills/ios/hig-components-controls/references/text-views.md +56 -0
  131. package/skills/ios/hig-components-controls/references/toggles.md +127 -0
  132. package/skills/ios/hig-components-controls/references/token-fields.md +48 -0
  133. package/skills/ios/hig-components-controls/references/virtual-keyboards.md +156 -0
  134. package/skills/ios/hig-components-dialogs/SKILL.md +76 -0
  135. package/skills/ios/hig-components-dialogs/references/action-sheets.md +74 -0
  136. package/skills/ios/hig-components-dialogs/references/alerts.md +158 -0
  137. package/skills/ios/hig-components-dialogs/references/digit-entry-views.md +32 -0
  138. package/skills/ios/hig-components-dialogs/references/popovers.md +81 -0
  139. package/skills/ios/hig-components-dialogs/references/sheets.md +157 -0
  140. package/skills/ios/hig-components-layout/SKILL.md +99 -0
  141. package/skills/ios/hig-components-layout/references/boxes.md +48 -0
  142. package/skills/ios/hig-components-layout/references/column-views.md +44 -0
  143. package/skills/ios/hig-components-layout/references/lists-and-tables.md +99 -0
  144. package/skills/ios/hig-components-layout/references/ornaments.md +56 -0
  145. package/skills/ios/hig-components-layout/references/outline-views.md +64 -0
  146. package/skills/ios/hig-components-layout/references/panels.md +75 -0
  147. package/skills/ios/hig-components-layout/references/scroll-views.md +123 -0
  148. package/skills/ios/hig-components-layout/references/sidebars.md +109 -0
  149. package/skills/ios/hig-components-layout/references/split-views.md +110 -0
  150. package/skills/ios/hig-components-layout/references/tab-bars.md +173 -0
  151. package/skills/ios/hig-components-layout/references/tab-views.md +68 -0
  152. package/skills/ios/hig-components-layout/references/windows.md +188 -0
  153. package/skills/ios/hig-components-menus/SKILL.md +81 -0
  154. package/skills/ios/hig-components-menus/references/action-button.md +61 -0
  155. package/skills/ios/hig-components-menus/references/buttons.md +261 -0
  156. package/skills/ios/hig-components-menus/references/context-menus.md +105 -0
  157. package/skills/ios/hig-components-menus/references/disclosure-controls.md +84 -0
  158. package/skills/ios/hig-components-menus/references/dock-menus.md +40 -0
  159. package/skills/ios/hig-components-menus/references/edit-menus.md +88 -0
  160. package/skills/ios/hig-components-menus/references/menus.md +171 -0
  161. package/skills/ios/hig-components-menus/references/pop-up-buttons.md +70 -0
  162. package/skills/ios/hig-components-menus/references/pull-down-buttons.md +77 -0
  163. package/skills/ios/hig-components-menus/references/the-menu-bar.md +303 -0
  164. package/skills/ios/hig-components-menus/references/toolbars.md +256 -0
  165. package/skills/ios/hig-components-search/SKILL.md +68 -0
  166. package/skills/ios/hig-components-search/references/page-controls.md +120 -0
  167. package/skills/ios/hig-components-search/references/path-controls.md +40 -0
  168. package/skills/ios/hig-components-search/references/search-fields.md +189 -0
  169. package/skills/ios/hig-components-status/SKILL.md +80 -0
  170. package/skills/ios/hig-components-status/references/activity-rings.md +105 -0
  171. package/skills/ios/hig-components-status/references/progress-indicators.md +116 -0
  172. package/skills/ios/hig-components-status/references/status-bars.md +38 -0
  173. package/skills/ios/hig-components-system/SKILL.md +88 -0
  174. package/skills/ios/hig-components-system/references/app-clips.md +387 -0
  175. package/skills/ios/hig-components-system/references/app-shortcuts.md +114 -0
  176. package/skills/ios/hig-components-system/references/complications.md +425 -0
  177. package/skills/ios/hig-components-system/references/home-screen-quick-actions.md +42 -0
  178. package/skills/ios/hig-components-system/references/live-activities.md +442 -0
  179. package/skills/ios/hig-components-system/references/notifications.md +153 -0
  180. package/skills/ios/hig-components-system/references/top-shelf.md +135 -0
  181. package/skills/ios/hig-components-system/references/watch-faces.md +40 -0
  182. package/skills/ios/hig-components-system/references/widgets.md +517 -0
  183. package/skills/ios/hig-foundations/SKILL.md +98 -0
  184. package/skills/ios/hig-foundations/references/accessibility.md +291 -0
  185. package/skills/ios/hig-foundations/references/app-icons.md +210 -0
  186. package/skills/ios/hig-foundations/references/branding.md +44 -0
  187. package/skills/ios/hig-foundations/references/color.md +274 -0
  188. package/skills/ios/hig-foundations/references/dark-mode.md +116 -0
  189. package/skills/ios/hig-foundations/references/icons.md +263 -0
  190. package/skills/ios/hig-foundations/references/images.md +176 -0
  191. package/skills/ios/hig-foundations/references/immersive-experiences.md +174 -0
  192. package/skills/ios/hig-foundations/references/inclusion.md +189 -0
  193. package/skills/ios/hig-foundations/references/layout.md +425 -0
  194. package/skills/ios/hig-foundations/references/materials.md +238 -0
  195. package/skills/ios/hig-foundations/references/motion.md +103 -0
  196. package/skills/ios/hig-foundations/references/privacy.md +231 -0
  197. package/skills/ios/hig-foundations/references/right-to-left.md +206 -0
  198. package/skills/ios/hig-foundations/references/sf-symbols.md +310 -0
  199. package/skills/ios/hig-foundations/references/spatial-layout.md +142 -0
  200. package/skills/ios/hig-foundations/references/typography.md +1146 -0
  201. package/skills/ios/hig-foundations/references/writing.md +91 -0
  202. package/skills/ios/hig-inputs/SKILL.md +94 -0
  203. package/skills/ios/hig-inputs/references/apple-pencil-and-scribble.md +148 -0
  204. package/skills/ios/hig-inputs/references/camera-control.md +107 -0
  205. package/skills/ios/hig-inputs/references/digital-crown.md +83 -0
  206. package/skills/ios/hig-inputs/references/eyes.md +120 -0
  207. package/skills/ios/hig-inputs/references/focus-and-selection.md +120 -0
  208. package/skills/ios/hig-inputs/references/game-controls.md +156 -0
  209. package/skills/ios/hig-inputs/references/gestures.md +208 -0
  210. package/skills/ios/hig-inputs/references/gyro-and-accelerometer.md +40 -0
  211. package/skills/ios/hig-inputs/references/keyboards.md +234 -0
  212. package/skills/ios/hig-inputs/references/nearby-interactions.md +70 -0
  213. package/skills/ios/hig-inputs/references/pointing-devices.md +237 -0
  214. package/skills/ios/hig-inputs/references/remotes.md +67 -0
  215. package/skills/ios/hig-inputs/references/spatial-interactions.md +70 -0
  216. package/skills/ios/hig-patterns/SKILL.md +104 -0
  217. package/skills/ios/hig-patterns/references/charting-data.md +81 -0
  218. package/skills/ios/hig-patterns/references/collaboration-and-sharing.md +86 -0
  219. package/skills/ios/hig-patterns/references/drag-and-drop.md +134 -0
  220. package/skills/ios/hig-patterns/references/entering-data.md +69 -0
  221. package/skills/ios/hig-patterns/references/feedback.md +67 -0
  222. package/skills/ios/hig-patterns/references/file-management.md +135 -0
  223. package/skills/ios/hig-patterns/references/going-full-screen.md +79 -0
  224. package/skills/ios/hig-patterns/references/launching.md +81 -0
  225. package/skills/ios/hig-patterns/references/live-viewing-apps.md +79 -0
  226. package/skills/ios/hig-patterns/references/loading.md +59 -0
  227. package/skills/ios/hig-patterns/references/managing-accounts.md +107 -0
  228. package/skills/ios/hig-patterns/references/managing-notifications.md +99 -0
  229. package/skills/ios/hig-patterns/references/modality.md +82 -0
  230. package/skills/ios/hig-patterns/references/multitasking.md +131 -0
  231. package/skills/ios/hig-patterns/references/offering-help.md +117 -0
  232. package/skills/ios/hig-patterns/references/onboarding.md +69 -0
  233. package/skills/ios/hig-patterns/references/playing-audio.md +124 -0
  234. package/skills/ios/hig-patterns/references/playing-haptics.md +280 -0
  235. package/skills/ios/hig-patterns/references/playing-video.md +180 -0
  236. package/skills/ios/hig-patterns/references/printing.md +50 -0
  237. package/skills/ios/hig-patterns/references/ratings-and-reviews.md +48 -0
  238. package/skills/ios/hig-patterns/references/searching.md +70 -0
  239. package/skills/ios/hig-patterns/references/settings.md +84 -0
  240. package/skills/ios/hig-patterns/references/undo-and-redo.md +58 -0
  241. package/skills/ios/hig-patterns/references/workouts.md +76 -0
  242. package/skills/ios/hig-platforms/SKILL.md +84 -0
  243. package/skills/ios/hig-platforms/references/designing-for-games.md +159 -0
  244. package/skills/ios/hig-platforms/references/designing-for-ios.md +66 -0
  245. package/skills/ios/hig-platforms/references/designing-for-ipados.md +64 -0
  246. package/skills/ios/hig-platforms/references/designing-for-macos.md +70 -0
  247. package/skills/ios/hig-platforms/references/designing-for-tvos.md +68 -0
  248. package/skills/ios/hig-platforms/references/designing-for-visionos.md +85 -0
  249. package/skills/ios/hig-platforms/references/designing-for-watchos.md +74 -0
  250. package/skills/ios/hig-project-context/SKILL.md +133 -0
  251. package/skills/ios/hig-technologies/SKILL.md +107 -0
  252. package/skills/ios/hig-technologies/references/airplay.md +125 -0
  253. package/skills/ios/hig-technologies/references/always-on.md +62 -0
  254. package/skills/ios/hig-technologies/references/apple-pay.md +441 -0
  255. package/skills/ios/hig-technologies/references/augmented-reality.md +247 -0
  256. package/skills/ios/hig-technologies/references/carekit.md +224 -0
  257. package/skills/ios/hig-technologies/references/carplay.md +119 -0
  258. package/skills/ios/hig-technologies/references/game-center.md +343 -0
  259. package/skills/ios/hig-technologies/references/generative-ai.md +110 -0
  260. package/skills/ios/hig-technologies/references/healthkit.md +120 -0
  261. package/skills/ios/hig-technologies/references/homekit.md +343 -0
  262. package/skills/ios/hig-technologies/references/icloud.md +52 -0
  263. package/skills/ios/hig-technologies/references/id-verifier.md +73 -0
  264. package/skills/ios/hig-technologies/references/imessage-apps-and-stickers.md +105 -0
  265. package/skills/ios/hig-technologies/references/in-app-purchase.md +263 -0
  266. package/skills/ios/hig-technologies/references/live-photos.md +54 -0
  267. package/skills/ios/hig-technologies/references/mac-catalyst.md +216 -0
  268. package/skills/ios/hig-technologies/references/machine-learning.md +394 -0
  269. package/skills/ios/hig-technologies/references/maps.md +221 -0
  270. package/skills/ios/hig-technologies/references/nfc.md +51 -0
  271. package/skills/ios/hig-technologies/references/photo-editing.md +40 -0
  272. package/skills/ios/hig-technologies/references/researchkit.md +134 -0
  273. package/skills/ios/hig-technologies/references/shareplay.md +142 -0
  274. package/skills/ios/hig-technologies/references/shazamkit.md +47 -0
  275. package/skills/ios/hig-technologies/references/sign-in-with-apple.md +288 -0
  276. package/skills/ios/hig-technologies/references/siri.md +523 -0
  277. package/skills/ios/hig-technologies/references/tap-to-pay-on-iphone.md +208 -0
  278. package/skills/ios/hig-technologies/references/voiceover.md +90 -0
  279. package/skills/ios/hig-technologies/references/wallet.md +420 -0
  280. package/skills/ios/ios-26-platform/SKILL.md +53 -0
  281. package/skills/ios/ios-26-platform/references/automatic-adoption.md +161 -0
  282. package/skills/ios/ios-26-platform/references/backward-compat.md +238 -0
  283. package/skills/ios/ios-26-platform/references/liquid-glass.md +255 -0
  284. package/skills/ios/ios-26-platform/references/swiftui-apis.md +277 -0
  285. package/skills/ios/ios-26-platform/references/toolbar-navigation.md +250 -0
  286. package/skills/ios/ios-bootstrap/SKILL.md +107 -0
  287. package/skills/ios/ios-bootstrap/references/apple-docs-mcp-config.md +28 -0
  288. package/skills/ios/ios-bootstrap/references/new-project-dialog.md +41 -0
  289. package/skills/ios/ios-bootstrap/references/xcode-mcp-config.md +29 -0
  290. package/skills/ios/ios-debugger-agent/LICENSE +21 -0
  291. package/skills/ios/ios-debugger-agent/SKILL.md +58 -0
  292. package/skills/ios/ios-debugger-agent/agents/openai.yaml +4 -0
  293. package/skills/ios/ios-entitlements-generator/SKILL.md +47 -0
  294. package/skills/ios/ios-info-plist-hardening/SKILL.md +130 -0
  295. package/skills/ios/ios-maestro-flow-author/SKILL.md +68 -0
  296. package/skills/ios/ios-maestro-flow-author/references/input-and-scroll.yaml +17 -0
  297. package/skills/ios/ios-maestro-flow-author/references/modal-and-dismiss.yaml +14 -0
  298. package/skills/ios/ios-maestro-flow-author/references/onboarding-flow.yaml +16 -0
  299. package/skills/ios/ios-maestro-flow-author/references/tab-navigation.yaml +13 -0
  300. package/skills/ios/ios-maestro-flow-author/references/tap-and-assert.yaml +9 -0
  301. package/skills/ios/swift-accessibility/LICENSE +21 -0
  302. package/skills/ios/swift-accessibility/SKILL.md +371 -0
  303. package/skills/ios/swift-accessibility/examples/before-after-appkit.md +446 -0
  304. package/skills/ios/swift-accessibility/examples/before-after-swiftui.md +441 -0
  305. package/skills/ios/swift-accessibility/examples/before-after-uikit.md +464 -0
  306. package/skills/ios/swift-accessibility/references/assistive-access.md +441 -0
  307. package/skills/ios/swift-accessibility/references/display-settings.md +491 -0
  308. package/skills/ios/swift-accessibility/references/dynamic-type.md +420 -0
  309. package/skills/ios/swift-accessibility/references/media-accessibility.md +421 -0
  310. package/skills/ios/swift-accessibility/references/motor-input.md +393 -0
  311. package/skills/ios/swift-accessibility/references/nutrition-labels.md +362 -0
  312. package/skills/ios/swift-accessibility/references/platform-specifics.md +515 -0
  313. package/skills/ios/swift-accessibility/references/semantic-structure.md +585 -0
  314. package/skills/ios/swift-accessibility/references/testing-auditing.md +507 -0
  315. package/skills/ios/swift-accessibility/references/voice-control.md +317 -0
  316. package/skills/ios/swift-accessibility/references/voiceover-swiftui.md +584 -0
  317. package/skills/ios/swift-accessibility/references/voiceover-uikit.md +519 -0
  318. package/skills/ios/swift-accessibility/references/wcag-mapping.md +167 -0
  319. package/skills/ios/swift-accessibility/resources/audit-template.swift +128 -0
  320. package/skills/ios/swift-accessibility/resources/qa-checklist.md +258 -0
  321. package/skills/ios/swift-actor-persistence/SKILL.md +143 -0
  322. package/skills/ios/swift-concurrency/LICENSE +21 -0
  323. package/skills/ios/swift-concurrency/SKILL.md +171 -0
  324. package/skills/ios/swift-concurrency/references/_index.md +50 -0
  325. package/skills/ios/swift-concurrency/references/actors.md +660 -0
  326. package/skills/ios/swift-concurrency/references/async-algorithms.md +847 -0
  327. package/skills/ios/swift-concurrency/references/async-await-basics.md +266 -0
  328. package/skills/ios/swift-concurrency/references/async-sequences.md +710 -0
  329. package/skills/ios/swift-concurrency/references/core-data.md +560 -0
  330. package/skills/ios/swift-concurrency/references/glossary.md +135 -0
  331. package/skills/ios/swift-concurrency/references/linting.md +155 -0
  332. package/skills/ios/swift-concurrency/references/memory-management.md +569 -0
  333. package/skills/ios/swift-concurrency/references/migration.md +1104 -0
  334. package/skills/ios/swift-concurrency/references/performance.md +593 -0
  335. package/skills/ios/swift-concurrency/references/sendable.md +598 -0
  336. package/skills/ios/swift-concurrency/references/tasks.md +636 -0
  337. package/skills/ios/swift-concurrency/references/testing.md +592 -0
  338. package/skills/ios/swift-concurrency/references/threading.md +495 -0
  339. package/skills/ios/swift-concurrency-6-2/SKILL.md +216 -0
  340. package/skills/ios/swift-protocol-di-testing/SKILL.md +190 -0
  341. package/skills/ios/swift-security-expert/LICENSE +21 -0
  342. package/skills/ios/swift-security-expert/SKILL.md +470 -0
  343. package/skills/ios/swift-security-expert/references/biometric-authentication.md +565 -0
  344. package/skills/ios/swift-security-expert/references/certificate-trust.md +592 -0
  345. package/skills/ios/swift-security-expert/references/common-anti-patterns.md +690 -0
  346. package/skills/ios/swift-security-expert/references/compliance-owasp-mapping.md +537 -0
  347. package/skills/ios/swift-security-expert/references/credential-storage-patterns.md +721 -0
  348. package/skills/ios/swift-security-expert/references/cryptokit-public-key.md +505 -0
  349. package/skills/ios/swift-security-expert/references/cryptokit-symmetric.md +497 -0
  350. package/skills/ios/swift-security-expert/references/keychain-access-control.md +508 -0
  351. package/skills/ios/swift-security-expert/references/keychain-fundamentals.md +596 -0
  352. package/skills/ios/swift-security-expert/references/keychain-item-classes.md +476 -0
  353. package/skills/ios/swift-security-expert/references/keychain-sharing.md +458 -0
  354. package/skills/ios/swift-security-expert/references/migration-legacy-stores.md +727 -0
  355. package/skills/ios/swift-security-expert/references/secure-enclave.md +539 -0
  356. package/skills/ios/swift-security-expert/references/testing-security-code.md +781 -0
  357. package/skills/ios/swift-testing-expert/LICENSE +21 -0
  358. package/skills/ios/swift-testing-expert/SKILL.md +79 -0
  359. package/skills/ios/swift-testing-expert/references/_index.md +12 -0
  360. package/skills/ios/swift-testing-expert/references/async-testing-and-waiting.md +127 -0
  361. package/skills/ios/swift-testing-expert/references/expectations.md +145 -0
  362. package/skills/ios/swift-testing-expert/references/fundamentals.md +141 -0
  363. package/skills/ios/swift-testing-expert/references/migration-from-xctest.md +127 -0
  364. package/skills/ios/swift-testing-expert/references/parallelization-and-isolation.md +95 -0
  365. package/skills/ios/swift-testing-expert/references/parameterized-testing.md +284 -0
  366. package/skills/ios/swift-testing-expert/references/performance-and-best-practices.md +187 -0
  367. package/skills/ios/swift-testing-expert/references/traits-and-tags.md +114 -0
  368. package/skills/ios/swift-testing-expert/references/xcode-workflows.md +70 -0
  369. package/skills/ios/swiftdata-pro/LICENSE +21 -0
  370. package/skills/ios/swiftdata-pro/SKILL.md +102 -0
  371. package/skills/ios/swiftdata-pro/agents/openai.yaml +10 -0
  372. package/skills/ios/swiftdata-pro/assets/swiftdata-pro-icon.png +0 -0
  373. package/skills/ios/swiftdata-pro/assets/swiftdata-pro-icon.svg +29 -0
  374. package/skills/ios/swiftdata-pro/references/class-inheritance.md +104 -0
  375. package/skills/ios/swiftdata-pro/references/cloudkit.md +10 -0
  376. package/skills/ios/swiftdata-pro/references/core-rules.md +20 -0
  377. package/skills/ios/swiftdata-pro/references/indexing.md +27 -0
  378. package/skills/ios/swiftdata-pro/references/predicates.md +73 -0
  379. package/skills/ios/swiftui-design-principles/AGENTS.md +21 -0
  380. package/skills/ios/swiftui-design-principles/LICENSE +21 -0
  381. package/skills/ios/swiftui-design-principles/README.md +41 -0
  382. package/skills/ios/swiftui-design-principles/SKILL.md +605 -0
  383. package/skills/ios/swiftui-design-principles/metadata.json +10 -0
  384. package/skills/ios/swiftui-design-tokens/SKILL.md +475 -0
  385. package/skills/ios/swiftui-liquid-glass/LICENSE +21 -0
  386. package/skills/ios/swiftui-liquid-glass/SKILL.md +95 -0
  387. package/skills/ios/swiftui-liquid-glass/agents/openai.yaml +4 -0
  388. package/skills/ios/swiftui-liquid-glass/references/liquid-glass.md +280 -0
  389. package/skills/ios/swiftui-performance-audit/LICENSE +21 -0
  390. package/skills/ios/swiftui-performance-audit/SKILL.md +111 -0
  391. package/skills/ios/swiftui-performance-audit/agents/openai.yaml +4 -0
  392. package/skills/ios/swiftui-performance-audit/references/code-smells.md +150 -0
  393. package/skills/ios/swiftui-performance-audit/references/demystify-swiftui-performance-wwdc23.md +46 -0
  394. package/skills/ios/swiftui-performance-audit/references/optimizing-swiftui-performance-instruments.md +29 -0
  395. package/skills/ios/swiftui-performance-audit/references/profiling-intake.md +44 -0
  396. package/skills/ios/swiftui-performance-audit/references/report-template.md +47 -0
  397. package/skills/ios/swiftui-performance-audit/references/understanding-hangs-in-your-app.md +33 -0
  398. package/skills/ios/swiftui-performance-audit/references/understanding-improving-swiftui-performance.md +52 -0
  399. package/skills/ios/swiftui-pro/LICENSE +21 -0
  400. package/skills/ios/swiftui-pro/SKILL.md +108 -0
  401. package/skills/ios/swiftui-pro/agents/openai.yaml +10 -0
  402. package/skills/ios/swiftui-pro/assets/swiftui-pro-icon.png +0 -0
  403. package/skills/ios/swiftui-pro/assets/swiftui-pro-icon.svg +29 -0
  404. package/skills/ios/swiftui-pro/references/accessibility.md +13 -0
  405. package/skills/ios/swiftui-pro/references/api.md +39 -0
  406. package/skills/ios/swiftui-pro/references/data.md +43 -0
  407. package/skills/ios/swiftui-pro/references/design.md +31 -0
  408. package/skills/ios/swiftui-pro/references/hygiene.md +9 -0
  409. package/skills/ios/swiftui-pro/references/navigation.md +14 -0
  410. package/skills/ios/swiftui-pro/references/performance.md +46 -0
  411. package/skills/ios/swiftui-pro/references/swift.md +56 -0
  412. package/skills/ios/swiftui-pro/references/views.md +35 -0
  413. package/skills/ios/swiftui-ui-patterns/LICENSE +21 -0
  414. package/skills/ios/swiftui-ui-patterns/SKILL.md +100 -0
  415. package/skills/ios/swiftui-ui-patterns/agents/openai.yaml +4 -0
  416. package/skills/ios/swiftui-ui-patterns/references/app-wiring.md +201 -0
  417. package/skills/ios/swiftui-ui-patterns/references/async-state.md +96 -0
  418. package/skills/ios/swiftui-ui-patterns/references/components-index.md +50 -0
  419. package/skills/ios/swiftui-ui-patterns/references/controls.md +57 -0
  420. package/skills/ios/swiftui-ui-patterns/references/deeplinks.md +66 -0
  421. package/skills/ios/swiftui-ui-patterns/references/focus.md +90 -0
  422. package/skills/ios/swiftui-ui-patterns/references/form.md +97 -0
  423. package/skills/ios/swiftui-ui-patterns/references/grids.md +71 -0
  424. package/skills/ios/swiftui-ui-patterns/references/haptics.md +71 -0
  425. package/skills/ios/swiftui-ui-patterns/references/input-toolbar.md +51 -0
  426. package/skills/ios/swiftui-ui-patterns/references/lightweight-clients.md +93 -0
  427. package/skills/ios/swiftui-ui-patterns/references/list.md +86 -0
  428. package/skills/ios/swiftui-ui-patterns/references/loading-placeholders.md +38 -0
  429. package/skills/ios/swiftui-ui-patterns/references/macos-settings.md +71 -0
  430. package/skills/ios/swiftui-ui-patterns/references/matched-transitions.md +59 -0
  431. package/skills/ios/swiftui-ui-patterns/references/media.md +73 -0
  432. package/skills/ios/swiftui-ui-patterns/references/menu-bar.md +101 -0
  433. package/skills/ios/swiftui-ui-patterns/references/navigationstack.md +159 -0
  434. package/skills/ios/swiftui-ui-patterns/references/overlay.md +45 -0
  435. package/skills/ios/swiftui-ui-patterns/references/performance.md +62 -0
  436. package/skills/ios/swiftui-ui-patterns/references/previews.md +48 -0
  437. package/skills/ios/swiftui-ui-patterns/references/scroll-reveal.md +133 -0
  438. package/skills/ios/swiftui-ui-patterns/references/scrollview.md +87 -0
  439. package/skills/ios/swiftui-ui-patterns/references/searchable.md +71 -0
  440. package/skills/ios/swiftui-ui-patterns/references/sheets.md +155 -0
  441. package/skills/ios/swiftui-ui-patterns/references/split-views.md +72 -0
  442. package/skills/ios/swiftui-ui-patterns/references/tabview.md +114 -0
  443. package/skills/ios/swiftui-ui-patterns/references/theming.md +71 -0
  444. package/skills/ios/swiftui-ui-patterns/references/title-menus.md +93 -0
  445. package/skills/ios/swiftui-ui-patterns/references/top-bar.md +49 -0
  446. package/skills/ios/swiftui-view-refactor/LICENSE +21 -0
  447. package/skills/ios/swiftui-view-refactor/SKILL.md +207 -0
  448. package/skills/ios/swiftui-view-refactor/agents/openai.yaml +4 -0
  449. package/skills/ios/swiftui-view-refactor/references/mv-patterns.md +161 -0
  450. package/skills/ios/widgetkit/LICENSE +131 -0
  451. package/skills/ios/widgetkit/SKILL.md +502 -0
  452. package/skills/ios/widgetkit/references/widgetkit-advanced.md +871 -0
  453. package/skills/ios/writing-for-interfaces/SKILL.md +75 -0
  454. package/skills/web/accessibility/SKILL.md +146 -0
  455. package/skills/web/aceternity-ui/SKILL.md +719 -0
  456. package/skills/web/aceternity-ui/metadata.json +10 -0
  457. package/skills/web/api-design/SKILL.md +523 -0
  458. package/skills/web/chart-accessibility/SKILL.md +332 -0
  459. package/skills/web/composition-patterns/AGENTS.md +946 -0
  460. package/skills/web/composition-patterns/README.md +60 -0
  461. package/skills/web/composition-patterns/SKILL.md +89 -0
  462. package/skills/web/composition-patterns/metadata.json +11 -0
  463. package/skills/web/composition-patterns/rules/_sections.md +29 -0
  464. package/skills/web/composition-patterns/rules/_template.md +24 -0
  465. package/skills/web/composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  466. package/skills/web/composition-patterns/rules/architecture-compound-components.md +112 -0
  467. package/skills/web/composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  468. package/skills/web/composition-patterns/rules/patterns-explicit-variants.md +100 -0
  469. package/skills/web/composition-patterns/rules/react19-no-forwardref.md +42 -0
  470. package/skills/web/composition-patterns/rules/state-context-interface.md +191 -0
  471. package/skills/web/composition-patterns/rules/state-decouple-implementation.md +113 -0
  472. package/skills/web/composition-patterns/rules/state-lift-state.md +125 -0
  473. package/skills/web/cost-aware-llm-pipeline/SKILL.md +183 -0
  474. package/skills/web/database-migrations/SKILL.md +429 -0
  475. package/skills/web/deployment-patterns/SKILL.md +427 -0
  476. package/skills/web/docker-patterns/SKILL.md +364 -0
  477. package/skills/web/e2e-testing/SKILL.md +326 -0
  478. package/skills/web/lighthouse-ci/SKILL.md +361 -0
  479. package/skills/web/mcp-server-patterns/SKILL.md +69 -0
  480. package/skills/web/next-best-practices/SKILL.md +153 -0
  481. package/skills/web/next-best-practices/async-patterns.md +87 -0
  482. package/skills/web/next-best-practices/bundling.md +180 -0
  483. package/skills/web/next-best-practices/data-patterns.md +297 -0
  484. package/skills/web/next-best-practices/debug-tricks.md +105 -0
  485. package/skills/web/next-best-practices/directives.md +73 -0
  486. package/skills/web/next-best-practices/error-handling.md +227 -0
  487. package/skills/web/next-best-practices/file-conventions.md +140 -0
  488. package/skills/web/next-best-practices/font.md +245 -0
  489. package/skills/web/next-best-practices/functions.md +108 -0
  490. package/skills/web/next-best-practices/hydration-error.md +91 -0
  491. package/skills/web/next-best-practices/image.md +173 -0
  492. package/skills/web/next-best-practices/metadata.md +301 -0
  493. package/skills/web/next-best-practices/parallel-routes.md +287 -0
  494. package/skills/web/next-best-practices/route-handlers.md +146 -0
  495. package/skills/web/next-best-practices/rsc-boundaries.md +159 -0
  496. package/skills/web/next-best-practices/runtime-selection.md +39 -0
  497. package/skills/web/next-best-practices/scripts.md +141 -0
  498. package/skills/web/next-best-practices/self-hosting.md +371 -0
  499. package/skills/web/next-best-practices/suspense-boundaries.md +67 -0
  500. package/skills/web/next-cache-components/SKILL.md +411 -0
  501. package/skills/web/postgres-best-practices/SKILL.md +14 -0
  502. package/skills/web/postgres-best-practices/references/schema-design.md +9 -0
  503. package/skills/web/react-best-practices/AGENTS.md +3810 -0
  504. package/skills/web/react-best-practices/README.md +123 -0
  505. package/skills/web/react-best-practices/SKILL.md +149 -0
  506. package/skills/web/react-best-practices/metadata.json +15 -0
  507. package/skills/web/react-best-practices/rules/_sections.md +46 -0
  508. package/skills/web/react-best-practices/rules/_template.md +28 -0
  509. package/skills/web/react-best-practices/rules/advanced-effect-event-deps.md +56 -0
  510. package/skills/web/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  511. package/skills/web/react-best-practices/rules/advanced-init-once.md +42 -0
  512. package/skills/web/react-best-practices/rules/advanced-use-latest.md +39 -0
  513. package/skills/web/react-best-practices/rules/async-api-routes.md +38 -0
  514. package/skills/web/react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
  515. package/skills/web/react-best-practices/rules/async-defer-await.md +82 -0
  516. package/skills/web/react-best-practices/rules/async-dependencies.md +51 -0
  517. package/skills/web/react-best-practices/rules/async-parallel.md +28 -0
  518. package/skills/web/react-best-practices/rules/async-suspense-boundaries.md +99 -0
  519. package/skills/web/react-best-practices/rules/bundle-analyzable-paths.md +63 -0
  520. package/skills/web/react-best-practices/rules/bundle-barrel-imports.md +60 -0
  521. package/skills/web/react-best-practices/rules/bundle-conditional.md +31 -0
  522. package/skills/web/react-best-practices/rules/bundle-defer-third-party.md +49 -0
  523. package/skills/web/react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  524. package/skills/web/react-best-practices/rules/bundle-preload.md +50 -0
  525. package/skills/web/react-best-practices/rules/client-event-listeners.md +74 -0
  526. package/skills/web/react-best-practices/rules/client-localstorage-schema.md +71 -0
  527. package/skills/web/react-best-practices/rules/client-passive-event-listeners.md +48 -0
  528. package/skills/web/react-best-practices/rules/client-swr-dedup.md +56 -0
  529. package/skills/web/react-best-practices/rules/js-batch-dom-css.md +107 -0
  530. package/skills/web/react-best-practices/rules/js-cache-function-results.md +80 -0
  531. package/skills/web/react-best-practices/rules/js-cache-property-access.md +28 -0
  532. package/skills/web/react-best-practices/rules/js-cache-storage.md +70 -0
  533. package/skills/web/react-best-practices/rules/js-combine-iterations.md +32 -0
  534. package/skills/web/react-best-practices/rules/js-early-exit.md +50 -0
  535. package/skills/web/react-best-practices/rules/js-flatmap-filter.md +60 -0
  536. package/skills/web/react-best-practices/rules/js-hoist-regexp.md +45 -0
  537. package/skills/web/react-best-practices/rules/js-index-maps.md +37 -0
  538. package/skills/web/react-best-practices/rules/js-length-check-first.md +49 -0
  539. package/skills/web/react-best-practices/rules/js-min-max-loop.md +82 -0
  540. package/skills/web/react-best-practices/rules/js-request-idle-callback.md +105 -0
  541. package/skills/web/react-best-practices/rules/js-set-map-lookups.md +24 -0
  542. package/skills/web/react-best-practices/rules/js-tosorted-immutable.md +57 -0
  543. package/skills/web/react-best-practices/rules/rendering-activity.md +26 -0
  544. package/skills/web/react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  545. package/skills/web/react-best-practices/rules/rendering-conditional-render.md +40 -0
  546. package/skills/web/react-best-practices/rules/rendering-content-visibility.md +38 -0
  547. package/skills/web/react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  548. package/skills/web/react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  549. package/skills/web/react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
  550. package/skills/web/react-best-practices/rules/rendering-resource-hints.md +85 -0
  551. package/skills/web/react-best-practices/rules/rendering-script-defer-async.md +68 -0
  552. package/skills/web/react-best-practices/rules/rendering-svg-precision.md +28 -0
  553. package/skills/web/react-best-practices/rules/rendering-usetransition-loading.md +75 -0
  554. package/skills/web/react-best-practices/rules/rerender-defer-reads.md +39 -0
  555. package/skills/web/react-best-practices/rules/rerender-dependencies.md +45 -0
  556. package/skills/web/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  557. package/skills/web/react-best-practices/rules/rerender-derived-state.md +29 -0
  558. package/skills/web/react-best-practices/rules/rerender-functional-setstate.md +74 -0
  559. package/skills/web/react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  560. package/skills/web/react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
  561. package/skills/web/react-best-practices/rules/rerender-memo.md +44 -0
  562. package/skills/web/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  563. package/skills/web/react-best-practices/rules/rerender-no-inline-components.md +82 -0
  564. package/skills/web/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  565. package/skills/web/react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
  566. package/skills/web/react-best-practices/rules/rerender-transitions.md +40 -0
  567. package/skills/web/react-best-practices/rules/rerender-use-deferred-value.md +59 -0
  568. package/skills/web/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  569. package/skills/web/react-best-practices/rules/server-after-nonblocking.md +73 -0
  570. package/skills/web/react-best-practices/rules/server-auth-actions.md +96 -0
  571. package/skills/web/react-best-practices/rules/server-cache-lru.md +41 -0
  572. package/skills/web/react-best-practices/rules/server-cache-react.md +76 -0
  573. package/skills/web/react-best-practices/rules/server-dedup-props.md +65 -0
  574. package/skills/web/react-best-practices/rules/server-hoist-static-io.md +149 -0
  575. package/skills/web/react-best-practices/rules/server-no-shared-module-state.md +50 -0
  576. package/skills/web/react-best-practices/rules/server-parallel-fetching.md +83 -0
  577. package/skills/web/react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
  578. package/skills/web/react-best-practices/rules/server-serialization.md +38 -0
  579. package/skills/web/seo/SKILL.md +154 -0
  580. package/skills/web/web-design-guidelines/SKILL.md +39 -0
  581. package/skills/web/zap-scan-config/SKILL.md +444 -0
  582. package/skills/web/zap-scan-config/assets/.gitkeep +9 -0
  583. package/skills/web/zap-scan-config/assets/github_action.yml +207 -0
  584. package/skills/web/zap-scan-config/assets/gitlab_ci.yml +226 -0
  585. package/skills/web/zap-scan-config/assets/zap_automation.yaml +196 -0
  586. package/skills/web/zap-scan-config/assets/zap_context.xml +192 -0
  587. package/skills/web/zap-scan-config/references/EXAMPLE.md +40 -0
  588. package/skills/web/zap-scan-config/references/api_testing_guide.md +475 -0
  589. package/skills/web/zap-scan-config/references/authentication_guide.md +431 -0
  590. package/skills/web/zap-scan-config/references/false_positive_handling.md +427 -0
  591. package/skills/web/zap-scan-config/references/owasp_mapping.md +255 -0
  592. package/src/lrr/aggregator.ts +80 -0
  593. package/src/orchestrator/hooks/context-header.ts +95 -0
  594. package/src/orchestrator/hooks/token-accounting-emitter.ts +77 -0
  595. package/src/orchestrator/hooks/token-accounting.ts +101 -0
  596. package/src/orchestrator/mcp/cycle-counter.ts +129 -0
  597. package/src/orchestrator/mcp/scribe.ts +283 -0
  598. package/src/orchestrator/mcp/state-save.ts +149 -0
  599. package/src/orchestrator/mcp/write-lease.ts +167 -0
  600. package/src/orchestrator/phase4-shared-context.ts +41 -0
  601. package/src/orchestrator/schemas/backward-edge.ts +46 -0
  602. package/agents/agentic-identity-trust.md +0 -121
  603. package/agents/data-consolidation-agent.md +0 -39
  604. package/agents/design-image-prompt-engineer.md +0 -105
  605. package/agents/design-visual-storyteller.md +0 -147
  606. package/agents/design-whimsy-injector.md +0 -89
  607. package/agents/engineering-autonomous-optimization-architect.md +0 -105
  608. package/agents/market-intel.md +0 -35
  609. package/agents/marketing-instagram-curator.md +0 -111
  610. package/agents/marketing-reddit-community-builder.md +0 -121
  611. package/agents/marketing-social-media-strategist.md +0 -74
  612. package/agents/marketing-tiktok-strategist.md +0 -123
  613. package/agents/marketing-twitter-engager.md +0 -124
  614. package/agents/marketing-wechat-official-account.md +0 -143
  615. package/agents/marketing-xiaohongshu-specialist.md +0 -136
  616. package/agents/marketing-zhihu-strategist.md +0 -160
  617. package/agents/product-behavioral-nudge-engine.md +0 -78
  618. package/agents/project-management-experiment-tracker.md +0 -102
  619. package/agents/report-distribution-agent.md +0 -43
  620. package/agents/risk-analysis.md +0 -45
  621. package/agents/sales-data-extraction-agent.md +0 -46
  622. package/agents/specialized-cultural-intelligence-strategist.md +0 -65
  623. package/agents/specialized-developer-advocate.md +0 -146
  624. package/agents/support-analytics-reporter.md +0 -133
  625. package/agents/support-executive-summary-generator.md +0 -64
  626. package/agents/support-finance-tracker.md +0 -145
  627. package/agents/support-legal-compliance-checker.md +0 -129
  628. package/agents/support-support-responder.md +0 -91
  629. package/agents/testing-accessibility-auditor.md +0 -110
  630. package/agents/testing-test-results-analyzer.md +0 -97
  631. package/agents/testing-tool-evaluator.md +0 -76
  632. package/agents/testing-workflow-optimizer.md +0 -99
  633. package/agents/user-research.md +0 -40
package/commands/build.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Full product build pipeline — orchestrates specialist agents through brainstorming, research, architecture, implementation, testing, hardening, and shipping"
2
+ description: "Full product build pipeline — orchestrates specialist agents through brainstorming, research, architecture, design, implementation, audit, launch review, and ship"
3
3
  argument-hint: "Describe what to build, or path to a design doc. --autonomous for unattended mode. --resume to continue a previous build."
4
4
  ---
5
5
 
@@ -13,45 +13,105 @@ Every step below tells you to call the Agent tool. DO IT. Do not role-play as th
13
13
  For implementation agents, set mode: "bypassPermissions".
14
14
  For parallel work, put multiple Agent tool calls in ONE message.
15
15
 
16
- Exception: Brainstorming (Phase 1, Step 1.1) is a direct conversation with the user you ask questions and process answers yourself. This is the ONE phase where you work directly, not through agents.
16
+ Exception: Brainstorming in Phase 1 Step 1.0 and Step 1.3 uses an INTERNAL Brainstorm Facilitator rolethe orchestrator relays between the facilitator sub-agent and the user, never role-plays the agent itself.
17
17
  </HARD-GATE>
18
18
 
19
+ <HARD-GATE>
20
+ SUBAGENT_TYPE REQUIRED.
21
+
22
+ Every Agent tool call MUST include a `subagent_type` field unless the dispatch is explicitly marked INTERNAL (inline role-string). INTERNAL dispatches are listed in `docs/plans/agent-dispatch-audit.md` — they are orchestrator helpers (Brainstorm Facilitator, Research Synthesizer, Design Doc Writer, Prereq Collector, Task DAG Validator, Refs Indexer, Briefing Officer, Dogfood runner, Fake-Data Detector, PM chapter, LRR Aggregator, Completion Report, Verify scaffolding dispatcher).
23
+
24
+ Missing `subagent_type` on a non-INTERNAL dispatch is a HARD-GATE violation. The orchestrator rejects dispatches that don't name a specific agent. If you catch yourself typing `description: "..."` without a `subagent_type:` line alongside it, STOP and look up the right agent from the dispatch audit.
25
+ </HARD-GATE>
26
+
27
+ <HARD-GATE>
28
+ ARTIFACT WRITER-OWNER RULE.
29
+
30
+ Every shared artifact has ONE concurrent writer at any instant. The writer-owner table in `docs/plans/orchestration-proposed-state.md` §6 defines which phase writes which file. Before any file write, the orchestrator verifies the current phase is the rightful writer. Non-owning phase writes are a HARD-GATE violation. For parallel-batch phases (e.g., Phase 4), intra-phase dispatches MUST NOT race on the same file — writes either target disjoint per-dispatch filenames OR route through an orchestrator-scribe handler (see `decisions.jsonl` handling below).
31
+
32
+ Live downstream docs (read across Phase 3+):
33
+ - `CLAUDE.md` — P1 writer (then auto-loaded into every subagent)
34
+ - `design-doc.md` (PRD) — P1 writer
35
+ - `architecture.md` — P2 writer
36
+ - `sprint-tasks.md` — P2 writer
37
+ - `quality-targets.json` — P2 writer
38
+ - `visual-design-spec.md` — P3 writer (web) / `ios-design-board.md` P3 writer (iOS)
39
+ - `refs.json` — P2 writer + P3 writer (P3 extends after visual spec lands)
40
+ - `decisions.jsonl` — orchestrator-scribe ONLY via `scribe_decision` MCP tool (subagents return `deviation_row` objects; the orchestrator forwards each row through the MCP, which owns ID allocation and atomic append)
41
+ - `learnings.jsonl` — P5, P7 writers
42
+ - `evidence/*.json` — P5 writer (P4 contributes per-task, P6/P7 readers)
43
+ - `lrr/*.json` — P6 writer (1 per chapter + Aggregator)
44
+ - `lrr-aggregate.json` — P6 writer (Aggregator only)
45
+
46
+ Phase-internal scaffolding (lives in `docs/plans/phase1-scratch/` after Gate 1, never read by P3+):
47
+ - `idea-draft.md`, `feature-intel.md`, `tech-feasibility.md`, `ux-research.md`, `business-model.md`, `findings-digest.md`, `suggested-questions.md`, `user-decisions.md`, `prereqs.json`
48
+
49
+ Phase 4 implementers never reference Phase 1 raw research files. They are SPENT after Phase 2 dispatch.
50
+ </HARD-GATE>
51
+
52
+ > **Default-deny (Stage 2+):** Once Stage 2 of the SDK migration activates, any `Write|Edit` tool call targeting a path absent from this table will be denied by the `PreToolUse` hook with message `"path not in writer-owner table — please add to phase-graph.yaml or route through scribe MCP"`. This is a pre-announcement; actual hook wiring ships in Task 2.1.3.
53
+
54
+ <HARD-GATE>
55
+ CONTEXT HEADER — RENDER ONCE, HOIST AS STABLE PREFIX.
56
+
57
+ Every phase uses a CONTEXT header prepended to dispatch prompts. The orchestrator MUST render this header ONCE at the start of each phase by reading `.build-state.json` (and `visual-dna.md` for web, Phase 4+) and resolving all values into concrete strings. The rendered header is then reused verbatim for every dispatch in that phase.
58
+
59
+ DO NOT paste `{read from .build-state.json}` placeholders into dispatch prompts. DO NOT re-read state files per dispatch. The values do not change within a phase.
60
+
61
+ **Canonical template** (orchestrator resolves before first dispatch of each phase):
62
+ ```
63
+ CONTEXT:
64
+ project_type: <resolved value>
65
+ phase: <current phase number>
66
+ dna: <resolved from docs/plans/visual-dna.md — INCLUDE only if project_type=web AND phase >= 4>
67
+ ios_features: <resolved from .build-state.json — INCLUDE only if project_type=ios>
68
+
69
+ TASK:
70
+ ```
71
+
72
+ **Rendering procedure** (run once per phase boundary):
73
+ 1. Read `docs/plans/.build-state.json`. Extract `project_type`, `ios_features`.
74
+ 2. If `project_type=web` AND phase >= 4: read `docs/plans/visual-dna.md` and extract the DNA summary (first 5 lines or the `## Summary` section). Otherwise omit the `dna` field.
75
+ 3. If `project_type=ios`: include `ios_features`. Otherwise omit.
76
+ 4. Substitute all values into the template above. Store the result as `rendered_context_header`.
77
+ 5. For every dispatch in this phase, prepend `rendered_context_header` — do NOT re-read or re-interpolate.
78
+
79
+ This keeps the prefix stable across parallel batches (enabling KV-cache reuse) and eliminates redundant state-file reads (~300K–1M tokens saved per build).
80
+ </HARD-GATE>
81
+
82
+ ## SSOT Rule (machine-readable form is authoritative)
83
+
84
+ For every HARD-GATE promoted to code in Stages 2–5, the machine-readable form (`phase-graph.yaml`, `decisions.schema.json`, `state-schema.md`) is AUTHORITATIVE at runtime. Prose in `commands/build.md` and `protocols/*.md` is a narrative view of the machine-readable form. Prose edits without corresponding machine-readable edits are build-breaking PRs enforced by `eval/lint_phase_graph.py` in CI.
85
+
19
86
  ### Orchestrator Discipline
20
87
 
21
88
  Your context window is precious. Protect it.
22
89
 
23
- **You are a DISPATCHER, not a DOER.** Your job is: read state → decide next step → compose agent prompt → dispatch → process result → decide next step.
90
+ **You are a DISPATCHER, not a DOER.** Your job is: read state → decide next step → compose agent prompt → dispatch → process compact return → decide next step.
24
91
 
25
92
  **Two types of agents — handle their results differently:**
26
93
 
27
94
  | Agent Type | Examples | What you keep |
28
95
  |-----------|----------|---------------|
29
- | **Research/analysis** | Market research, tech feasibility, architecture design, audits, measurement | **Full output** — their response IS the deliverable. You need it to synthesize, compare, and make decisions. Save to `docs/plans/` when applicable. |
30
- | **Implementation** | Code writing, fixes, cleanup, verification, scaffolding | **Summary only** — their work product lives in the codebase. Keep: what was done, files changed, test results, pass/fail. Discard: code snippets, full build logs, lint output. |
31
-
32
- **After implementation agents return:**
33
- 1. Extract: what was built, files changed, test pass/fail, any blockers
34
- 2. Record in `docs/plans/.build-state.md` under the current phase
35
- 3. The code is in the repo — you don't need it in your context
36
-
37
- **After research/analysis agents return:**
38
- 1. Read and use the full output — this is your decision-making input
39
- 2. Save the output to the appropriate file in `docs/plans/` (research brief, architecture doc, etc.)
40
- 3. Once saved to disk, you can reference the file later instead of holding it all in context
96
+ | **Research/analysis** | Architecture design, audits, measurement, chapter verdicts | **Compact return only** — save full output to `docs/plans/`, keep the filename + headline verdict in context. Phase 1 research goes through the Research Synthesizer the orchestrator never reads raw research. |
97
+ | **Implementation** | Code writing, fixes, cleanup, verification, scaffolding | **Summary only** — their work product lives in the codebase. Keep: what was done, files changed, test results, pass/fail. Discard: code snippets, full build logs. |
41
98
 
42
99
  **Never do these yourself:**
43
- - Read source code files to understand implementation details — spawn an Explore agent
100
+ - Read source code files to understand implementation details — spawn an INTERNAL inline exploration agent (see Step 2.1)
44
101
  - Write or edit code — spawn an implementation agent
45
102
  - Debug failures — spawn a fix agent with the error message
103
+ - Read raw Phase 1 research files — the Research Synthesizer (Step 1.2) reads them; you only read the digest
46
104
 
47
105
  If you catch yourself typing code or reading source files: STOP. You are wasting context. Spawn an agent.
48
106
 
49
- **Dispatch Counter:** Track agent dispatches in `docs/plans/.build-state.md` under `## Dispatch Counter`:
50
- - `dispatches_since_save: [N]`
51
- - `last_save: [Phase.Step]`
52
- Increment after each agent returns (parallel dispatch of 4 agents = +4). Reset to 0 after each compaction save.
107
+ **Dispatch Counter:** Track agent dispatches in `docs/plans/.build-state.json` (source of truth) under the `dispatch_count` and `last_save_phase` fields:
108
+ - `dispatch_count: [N]`
109
+ - `last_save_phase: [Phase.Step]`
110
+ Increment after each agent returns (parallel dispatch of 6 agents = +6). Reset to 0 after each compaction save. The rendered markdown view (`.build-state.md`) is regenerated from the JSON on every update — never edit the markdown directly.
53
111
 
54
- **Compaction checkpoint format:** At every phase boundary, check `dispatches_since_save` in `docs/plans/.build-state.md`. If >= 8: save ALL state (current phase, task statuses, metric loop scores, decisions) to `docs/plans/.build-state.md`. Reset `dispatches_since_save` to 0. TodoWrite does NOT survive compaction — rebuild it from this state file on resume.
112
+ **Compaction checkpoint format:** At every phase boundary, check `dispatch_count` in `docs/plans/.build-state.json`. If >= 8: save ALL state (current phase, task statuses, metric loop scores, decisions) to `docs/plans/.build-state.json` and regenerate `.build-state.md` as the rendered view. Reset `dispatch_count` to 0. TodoWrite does NOT survive compaction — rebuild it from the JSON state file on resume. See `protocols/state-schema.md` for the full schema and rendering contract.
113
+
114
+ **Cumulative-cost banner at phase boundaries:** When announcing a phase transition (e.g. "Phase N complete — proceeding to Phase N+1"), prefix the message with `[Cost so far: $X.XX • Y tokens]`. Source the values from the last-appended entry in `docs/plans/build-log.md`'s token-accounting lines (fields `cumulative_usd=...` plus the sum of `input_tokens=...` + `output_tokens=...`), written by `src/orchestrator/hooks/token-accounting.ts` (see module for exact schema). If the build-log has no token-accounting entries yet, omit the prefix rather than guessing.
55
115
 
56
116
  Input: $ARGUMENTS
57
117
 
@@ -59,608 +119,968 @@ Input: $ARGUMENTS
59
119
 
60
120
  If the input contains `--autonomous` or `--auto`, this build runs **unattended**. The user will not be present to approve quality gates. In autonomous mode:
61
121
  - Quality gates auto-approve. Do NOT pause and wait for user input.
62
- - Brainstorming runs in autonomous mode (see protocol).
122
+ - Brainstorming runs in autonomous mode (Brainstorm Facilitator synthesizes directly from build request + available context).
63
123
  - Metric loops that stall accept at >= 60% of target, skip below that.
64
- - Log every decision to `docs/plans/build-log.md` so the user can review later.
65
124
 
66
125
  If `--autonomous` is NOT present, all quality gates require user approval as described below.
67
126
 
68
127
  When combining `--resume` with `--autonomous`: the current invocation's flags take precedence over saved state. If you resume a previously interactive build with `--autonomous`, it continues in autonomous mode.
69
128
 
70
- ### Metric Loop
129
+ ### Always-On Build Log
130
+
131
+ `docs/plans/build-log.md` is written in **BOTH interactive and autonomous mode**. Every phase transition writes a one-line entry with the shape: `{timestamp, phase, step, action, outcome}`. Append to this file at EVERY phase boundary, EVERY LRR chapter dispatch, EVERY metric-loop iteration, and EVERY quality gate decision. In autonomous mode, ALSO log every auto-approval decision here so the user can review later.
132
+
133
+ ### Metric Loop (callable service)
71
134
 
72
- Every phase uses a **metric-driven iteration loop** to drive quality. Read the full protocol at `protocols/metric-loop.md`. Critical rules (survive compaction):
135
+ Every phase can invoke the **metric-driven iteration loop** as a service to drive quality. Read the full protocol at `protocols/metric-loop.md`. Called by Phase 3 (Design Critic loop), Phase 4 (per-task quality), Phase 5 (metric fix loop on failing audits), Phase 7 (documentation quality). Critical rules (survive compaction):
73
136
 
74
- 1. YOU define a metric for this phase based on context (what you're building, what matters). The metric is NOT predefined.
75
- 2. Spawn a **measurement agent** to score the artifact 0-100. Read its full output — it's analysis.
76
- 3. Pick the ONE highest-impact issue. Spawn a separate **fix agent** with ONLY that issue + file paths.
137
+ 1. YOU define a metric for this phase based on context. The metric is NOT predefined.
138
+ 2. Spawn a **measurement/critic agent** to score the artifact 0-100. Read its compact return.
139
+ 3. Pick the ONE highest-impact issue. Spawn a separate **fix/generator agent** with ONLY that issue + file paths.
77
140
  4. Re-measure. Repeat until: target met, stalled (2 consecutive delta <= 0), or max iterations.
78
- 5. Track all scores in `docs/plans/.build-state.md` — this is your lifeline across compaction.
141
+ 5. Track all scores in `docs/plans/.build-state.json` — this is your lifeline across compaction.
79
142
 
80
143
  <HARD-GATE>
81
144
  METRIC LOOP NON-NEGOTIABLES:
82
- - Measurement agent and fix agent are SEPARATE Agent tool calls — never share context (author-bias elimination).
145
+ - Measurement/critic agent and fix/generator agent are SEPARATE Agent tool calls — never share context (author-bias elimination).
83
146
  - Fix agent gets ONLY the top issue + file paths + acceptance criteria. NOT the full measurement findings.
84
147
  - One fix per iteration. Measure impact before fixing the next thing.
85
148
  - Each measurement is fresh — don't accumulate findings across iterations.
86
149
  </HARD-GATE>
87
150
 
88
- ### Handoff Documents
151
+ ### Verify Protocol (callable service)
152
+
153
+ The 7-check verification gate is called by Phase 2 (architecture check), Phase 4 (per task), Phase 5 (audit), and Phase 7 (pre-ship). Full protocol at `protocols/verify.md`. Phase-internal — dispatched as INTERNAL inline role-string "Verify scaffolding" with agent running 7 checks sequentially: Build → Type-Check → Lint → Test → Security → Diff Review → Artifacts.
154
+
155
+ ### Decision Log (callable service)
156
+
157
+ `docs/plans/decisions.jsonl` — append-only, ORCHESTRATOR-SCRIBE ONLY via the `scribe_decision` MCP tool. Subagents return `deviation_row` objects in their structured result; the orchestrator forwards each row through `scribe_decision`, which allocates `D-{phase}-<seq>` IDs and atomically appends. The orchestrator MUST NOT Write or Edit this file directly. Row-producing phases: Phase 1 synthesis (3 rows), Phase 2 architecture synthesis (4 rows), Phase 4 implementers (only on deviation). Readers: Phase 0 resume handler, Phase 5 Reality Checker, Phase 6 LRR Aggregator (the ⭐⭐ backward-routing read). Schema at `protocols/decision-log.md`. Dispatch flow: see Phase 4 "Orchestrator-scribe dispatch" section.
89
158
 
90
- When spawning agents in sequence (e.g., architect → implementer → reviewer), pass **scoped handoffs** — not the full architecture dump. Each agent receives only what it needs:
159
+ ### Learnings (callable service)
91
160
 
92
- 1. **Relevant architecture section** the specific part of architecture.md that applies to this agent's task
93
- 2. **Previous agent's output** — what the upstream agent produced (if any)
94
- 3. **Acceptance criteria** — what "done" looks like for THIS agent
161
+ `docs/plans/learnings.jsonl` append-only cross-run learnings store. Writers: Phase 5 reality sweep, Phase 7. Readers: Phase 0 Learnings Loader (Step 0.1d) and Phase 5 reality sweep.
95
162
 
96
- For implementation agents (Phase 5+): Do NOT paste the entire Design Document or Architecture Document. Extract the relevant sections only. For research and architecture agents (Phases 1-2): pass the full document — these agents need complete context to do their analysis.
163
+ ### Refs-Not-Pastes Rule
164
+
165
+ For Phase 3+ agents, the orchestrator passes REFS to live downstream docs (`design-doc.md`, `architecture.md`, `visual-design-spec.md`, `sprint-tasks.md`, `quality-targets.json`, `decisions.jsonl`) — NOT pasted content. The orchestrator reads `docs/plans/refs.json` (produced by the Phase 2 Refs Indexer), resolves the task topic against the flat anchor index, and passes a short ref list to the agent. The agent uses the Read tool to pull refs it needs. This keeps orchestrator context lean and lets the agent widen its view on demand. Phase 1-2 agents still receive full documents because the architecture anchors don't exist yet.
166
+
167
+ **refs.json mutation invalidates sprint-context hash (Stage 6 / task 6.3.2).** Any orchestrator update to `docs/plans/refs.json` (Phase 2 Refs Indexer initial write, Phase 3 extension after `visual-design-spec.md` lands, or any subsequent correction) MUST be IMMEDIATELY followed by a `state_save` call that sets `.build-state.json.current_sprint_context_hash = null`. This invalidates the cached Phase 4 sprint-scoped shared-context block so the next subagent dispatch re-renders with fresh references. See `src/orchestrator/phase4-shared-context.ts#shouldInvalidate` for how the hash is consulted at render time. Skipping this invalidation causes Phase 4 implementers to read stale anchor indices — a silent correctness failure.
97
168
 
98
169
  ### Complexity Routing (Advisory)
99
170
 
100
171
  Tag agent prompts with `[COMPLEXITY: S/M/L]` based on task size from `docs/plans/sprint-tasks.md`. This is advisory — the tag documents intent for future model routing support.
101
172
 
173
+ ### Mode-Specific Tool Stacks
174
+
175
+ Mode-specific tool stacks, per-phase branches, and persona rules live in separate files. Load ONE based on `project_type`:
176
+ - iOS: `protocols/ios-phase-branches.md` (includes iOS Mode Tool Stack)
177
+ - Web: `protocols/web-phase-branches.md` (web defaults)
178
+
179
+ ### Backward Edges — Routing Fix
180
+
181
+ When a later phase finds a problem whose root cause lives earlier, control flows BACKWARD to the authoring phase. The orchestrator codifies these edges so problems are fixed where they were introduced, not patched locally.
182
+
183
+ ```
184
+ PROBLEM FOUND AT ROUTES BACK TO
185
+ ─────────────────────────────────────────────────────────────────
186
+ Gate 1 (human says "no") → Phase 1 Step 1.0 with feedback
187
+ Gate 2 (human says "no") → Phase 2 with feedback
188
+ Phase 5 Audit (code issue) → Phase 4 target task
189
+ Phase 5 Audit (design issue) → Phase 3 target step
190
+ Phase 5 Audit (spec issue) → Phase 2 re-architect
191
+ Phase 6 LRR BLOCK (⭐⭐) → Aggregator reads decisions.jsonl
192
+ by related_decision_id →
193
+ authoring phase → re-open
194
+ Phase 6 LRR NEEDS_WORK (code) → Phase 4 target task
195
+ Phase 6 LRR NEEDS_WORK (struct) → Phase 2 or Phase 3
196
+ ```
197
+
198
+ The ⭐⭐ star rule: when the LRR Aggregator receives a BLOCK verdict, it reads the `related_decision_id` on the blocker, looks up that row in `decisions.jsonl`, finds which phase authored the decision (the `decided_by` field), and re-opens that phase with the finding as input. Infrastructure already exists (decision IDs, author tracking) — wired here.
199
+
200
+ **Re-entry halt rule (Stage 4 A7).** Before dispatching any backward routing (LRR BLOCK → Phase N re-open, Reality Checker BLOCK → Phase M re-entry, Gate "no" → Phase 1/2 re-entry, etc.), check `.build-state.json.backward_routing_count` AND the per-target-phase variant `.build-state.json.backward_routing_count_by_target_phase[<N>]`. If the new (post-increment) value of EITHER counter for the target phase would exceed `max_cycles` (currently 2, from `phase-graph.yaml:routing.max_cycles`) — i.e., on the attempted third backward iteration — the orchestrator MUST halt and escalate to the user instead of dispatching. The Stage 4 `cycle_counter_check` MCP is the authoritative enforcer at runtime — it increments atomically and returns `escalate_to_user` once the new value exceeds `max_cycles`. This prose documents the behavior for the markdown-mode rollback path and for human readers.
201
+
202
+ **Phase-entry `in_flight_backward_edge` clear (Stage 4 A3 / task 4.3.3).** On the FIRST `state_save` after any phase entry — whether forward progression or backward-edge re-entry — the orchestrator MUST explicitly set `.build-state.json.in_flight_backward_edge = null`. This is the "successful landing" signal that closes the atomic crash-seam opened by `cycle_counter_check` (which writes `in_flight_backward_edge` in the same atomic state_save that increments the counter). If the runtime crashes between edge dispatch and landing, `--resume` in `bin/buildanything-runtime.ts` observes a stale `in_flight_backward_edge` (age > 60s) and decrements the counter (see task 4.3.4). See `src/orchestrator/mcp/cycle-counter.ts#clearInFlightEdge` for the runtime primitive.
203
+
102
204
  ---
103
205
 
104
- ## Phase 0: Context & Pre-Flight
206
+ ## Phase 0: Pre-flight (state read only)
207
+
208
+ Phase 0 is thin. No agent dispatch. No human input. Instant. The orchestrator reads state files and applies universal checks.
105
209
 
106
210
  **Resuming?** If the input contains `--resume` OR if context was just compacted (SessionStart hook fired with active state):
107
- 1. Read `docs/plans/.build-state.md` — verify it exists and has a Resume Point section.
108
- If `docs/plans/.build-state.md` does not exist or has no Resume Point, warn the user: 'No previous build state found. Starting fresh.' Then proceed to Step 0.1 as a new build.
211
+ 1. Read `docs/plans/.build-state.json` (source of truth) — verify it exists and has a `resume_point` field. Fall back to reading `docs/plans/.build-state.md` (rendered view) if the JSON file is missing but the markdown exists (graceful migration path from pre-W1-2 builds).
212
+ If neither exists, OR neither has a Resume Point, warn the user: 'No previous build state found. Starting fresh.' Then proceed to Step 0.1 as a new build.
109
213
  2. Re-read this file and all protocol files in `protocols/`.
110
- 3. Re-read `docs/plans/sprint-tasks.md`, `docs/plans/architecture.md`, and `CLAUDE.md`.
111
- 4. Rebuild TodoWrite from the state file (TodoWrite does NOT survive compaction or session breaks).
112
- 5. Reset `dispatches_since_save` to 0 (fresh context window).
113
- 6. Resume from the saved phase and step. Skip Phase 0.
214
+ 3. Re-read live downstream docs: `docs/plans/sprint-tasks.md`, `docs/plans/architecture.md`, `docs/plans/design-doc.md`, `docs/plans/visual-design-spec.md` (if exists), `CLAUDE.md`.
215
+ 4. Read `docs/plans/decisions.jsonl` if it exists (top 5 most recent rows, filtered to the current phase and upstream phases). Pass short row fields + `ref` anchors into Phase 0 rehydration context — not the full row prose. See `protocols/decision-log.md`.
216
+ 5. Rebuild TodoWrite from the state file (TodoWrite does NOT survive compaction or session breaks).
217
+ 6. Reset `dispatches_since_save` to 0 (fresh context window).
218
+ 7. Resume from the saved phase and step. Skip Phase 0.
114
219
 
115
220
  ### Step 0.1 — Read the Room
116
221
 
117
- Before doing anything, scan for existing context:
222
+ Scan for existing context:
118
223
 
119
224
  - Check if the input is a file path (e.g., `docs/plans/brainstorm.md`). If so, read it.
120
225
  - Check if `docs/plans/` or `docs/briefs/` exist with prior brainstorming, design docs, decision briefs, or research. Read them.
121
226
  - Check if there's existing code in the project. If so, this is an enhancement, not greenfield.
122
227
  - Check the conversation history — has the user been discussing this idea already?
123
- - Check if `docs/plans/learnings.md` exists from a previous build. If so, read it. Apply relevant PATTERNS to agent prompt design, avoid listed PITFALLs, use HEURISTICS when applicable.
124
228
 
125
229
  **Classify what you found:**
126
230
 
127
231
  | Context Level | What You Have | What Happens |
128
232
  |---|---|---|
129
233
  | **Full design** | Design doc with decisions, scope, tech stack, data models | Skip Phase 1. Feed design into Phase 2. |
130
- | **Decision brief** | An idea-sweep brief with verdicts and MVP definition | Phase 1 skips research (Step 1.2). Brainstorming refines the brief into a design. |
234
+ | **Decision brief** | An idea-sweep brief with verdicts and MVP definition | Phase 1 skips Step 1.1 research (already done). Brainstorming refines the brief into a design. |
131
235
  | **Partial context** | Some notes, conversation, rough sketch | Phase 1 runs fully. Feed context into brainstorming + research. |
132
236
  | **Raw idea** | One-line build request, no prior work | Phase 1 runs fully from scratch. |
133
237
 
134
- ### Step 0.2Human Prerequisites Checklist
238
+ ### Step 0.1bProject Type Classification (iOS vs Web)
135
239
 
136
- Identify everything that requires HUMAN action before going heads-down:
240
+ Scan the build request AND any context from Step 0.1 for iOS signals. Keywords: **iOS, iPhone, iPad, SwiftUI, Swift, App Store, TestFlight, Xcode, Apple, Liquid Glass, watchOS, visionOS, SwiftData, HIG**.
137
241
 
138
- - **API keys & secrets** — External services the project integrates with. List each key needed.
139
- - **Database setup** — Supabase, Postgres, etc. User needs to create it and provide credentials.
140
- - **Repository** Git repo on GitHub? Public or private?
141
- - **Deployment** Vercel, Railway, Fly.io? User needs to connect.
142
- - **MCP servers** Playwright for visual testing, database access, etc.
143
- - **Local tooling** — Docker, specific runtimes, etc.
242
+ | Signal | Action |
243
+ |---|---|
244
+ | iOS keywords present in prompt | Confirm with user: "This looks like an iOS app — confirm? [y/n]" |
245
+ | User confirms OR says iOS during brainstorming | Set `project_type: ios` in `docs/plans/.build-state.json` (regenerate markdown view) |
246
+ | `.xcodeproj` / `Package.swift` / `*.swift` files in existing codebase | Set `project_type: ios` automatically |
247
+ | No iOS signals, no Swift files | Default `project_type: web` |
144
248
 
145
- Present the checklist:
249
+ **Autonomous mode:** skip the confirmation prompt. If iOS keywords are present, set `project_type: ios` and log the inference to `docs/plans/build-log.md`.
146
250
 
147
- ```
148
- BEFORE I GO HEADS-DOWN, please set up:
251
+ **Conditional branch-file load:**
252
+ - `project_type=ios`: load `protocols/ios-phase-branches.md` AND `protocols/ios-context.md`. Reference `protocols/ios-frameworks-map.md` by path only.
253
+ - `project_type=web`: load `protocols/web-phase-branches.md`.
254
+ - Load only ONE branch file.
255
+
256
+ Record the classification in `docs/plans/.build-state.json` as the top-level `project_type` field. Regenerate `.build-state.md` after the write. This field survives compaction and gates every branching block below.
257
+
258
+ **Mode-specific additions to Phase 0:** See `protocols/ios-phase-branches.md` §Phase 0 additions (iOS only).
259
+
260
+ ### Step 0.1d — Learnings Loader (PITFALL replay)
149
261
 
150
- [ ] [Service] API key add as [KEY_NAME] to .env
151
- [ ] [Database] → add connection URL to .env
152
- [ ] GitHub repo → share the URL
153
- [ ] [Deployment service] connected (optional)
262
+ Read `docs/plans/learnings.jsonl` (cross-run learnings store). If the project-local file does not exist, fall back to `~/.claude/buildanything/learnings.jsonl`. If neither exists, proceed with an empty active-learnings file and skip the rest of this step.
154
263
 
155
- Once done, say "ready" and I'll start building.
264
+ If a learnings file exists:
265
+ 1. Parse each line as a JSON row with the schema written at Phase 5 reality sweep: `{run_id, timestamp, project_type, phase_where_learning_surfaced, metric, top_issue, fix_applied, score_delta, pattern_type}`.
266
+ 2. Filter entries where `project_type` matches the current build's classification.
267
+ 3. Rank the filtered entries by composite score: prefer entries matching expected `pattern_type` (PITFALL > PATTERN > HEURISTIC), then by `phase_where_learning_surfaced` (earlier phases first), then by `score_delta` magnitude.
268
+ 4. Select the top 3 most relevant entries.
269
+ 5. Write them to `docs/plans/.active-learnings.md` as a short markdown section downstream agents inject into their prompts. Format:
270
+
271
+ ```markdown
272
+ ## Prior Learnings (top 3 relevant)
273
+
274
+ - **PITFALL (phase 4.x, iOS):** [top_issue] — fix: [fix_applied]
275
+ - **PATTERN (phase 5.x, web):** [top_issue] — fix: [fix_applied]
276
+ - **HEURISTIC (phase 4.x, iOS):** [top_issue] — fix: [fix_applied]
156
277
  ```
157
278
 
158
- <HARD-GATE>
159
- Interactive mode: DO NOT proceed until the user confirms prerequisites (or says to skip).
160
- Autonomous mode: Log checklist to `docs/plans/build-log.md`. Create `.env.example` with required keys. Proceed — log missing keys as blockers if hit during build.
161
- </HARD-GATE>
279
+ Phase 4 implementer dispatch reads `.active-learnings.md` and injects its contents into every implementer prompt under a `## Prior Learnings` section. This is how learnings from build N flow into build N+1.
162
280
 
163
- ### Step 0.3 — Initialize
281
+ ### Step 0.2 — Initialize
164
282
 
165
283
  0. Create `docs/plans/` directory if it doesn't exist (greenfield projects won't have it).
166
284
  1. Create a TodoWrite checklist with Phases 0-7.
167
- 2. Create `docs/plans/.build-state.md` as a single write with ALL of the following: phase and step (`Phase: 0 Starting`), input (`[build request]`), context level (`[classification]`), prerequisites (`[status]`), dispatch counter (`dispatches_since_save: 0, last_save: Phase 0`), and a `## Resume Point` section with: phase, step, autonomous mode flag, completed tasks (none), git branch name.
285
+ 2. Write `docs/plans/.build-state.json` per the schema in `protocols/state-schema.md`. Required top-level fields: `project_type`, `phase`, `step`, `input`, `context_level`, `prerequisites`, `dispatch_count`, `last_save_phase`, `autonomous`, `session_id`, `session_started`, `completed_tasks[]`, `metric_loop_scores[]`, `decisions_next_id` (object keyed by phase number see Phase 4 orchestrator-scribe handler), `resume_point { phase, step, completed_tasks, git_branch }`. Then regenerate `docs/plans/.build-state.md` from the JSON as a **read-only rendered view**.
168
286
  3. Go to Phase 1 (or Phase 2 if context level is "Full design").
169
287
 
288
+ **NO prereq collection in Phase 0.** Stack isn't decided yet. Prereqs move to Step 1.5, after Gate 1. Asking for creds before the stack is picked means asking for wrong creds or re-asking on rejection.
289
+
290
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
291
+
292
+ ---
293
+
294
+ ## Phase -1: iOS Bootstrap (iOS-only, greenfield only)
295
+
296
+ **If `project_type=ios` AND no `.xcodeproj` exists:** follow `protocols/ios-phase-branches.md` §Phase -1 — iOS Bootstrap. Otherwise skip entirely.
297
+
298
+ iOS structural changes are out of scope for this orchestrator migration (per proposed-state §7).
299
+
300
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
301
+
170
302
  ---
171
303
 
172
- ## Phase 1: Brainstorm & Research
304
+ ## Phase 1: Discover BRAINSTORM ↔ RESEARCH loop
173
305
 
174
- **Goal**: Turn the raw idea into a validated Design Document grounded in research. This ensures Phase 2 architects receive a design, not a guess.
306
+ **Goal**: Turn the raw idea into a validated Design Document (the PRD) grounded in research. This ensures Phase 2 architects receive a PRD, not a guess.
175
307
 
176
308
  **Skip if** Step 0.1 classified context as "Full design" — go straight to Phase 2.
177
309
 
178
- ### Step 1.1 Brainstorming
310
+ **Orchestrator discipline in Phase 1**: Dispatch → wait → read compact return → dispatch next. No synthesis. No reasoning. No raw artifact reads. Keep it thin. The Research Synthesizer (Step 1.2) is the only agent that reads raw research files.
179
311
 
180
- Follow the Brainstorm Protocol (`protocols/brainstorm.md`).
312
+ **Mode-specific branch:**
313
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 1 (iOS skill bundle, ios-swift-architect, App Store/TestFlight/iOS 26 research angles).
314
+ - `project_type=web`: no additional branch instructions.
181
315
 
182
- In interactive mode: this is a conversation. Ask questions one at a time, propose approaches with trade-offs, let the user decide. Output: Design Document saved to `docs/plans/`.
316
+ ### Step 1.0 INITIAL BRAINSTORM
183
317
 
184
- In autonomous mode: synthesize a design document directly using the build request and available context. Pick pragmatic defaults. Log rationale to `docs/plans/build-log.md`.
318
+ Dispatch the Brainstorm Facilitator as an INTERNAL inline role-string — NO `subagent_type`. The facilitator drives a conversation to capture the raw idea: what it is, who it's for, what problem it solves, hard constraints.
185
319
 
186
- ### Step 1.2 Parallel Research (5 agents, ONE message)
320
+ Call the Agent tool — description: "Initial brainstorm" — INTERNAL inline role-string — prompt: "You are the Brainstorm Facilitator (round 1). Your job is to drive a conversation with the user to capture the raw idea. Ask questions one at a time in plain language. Topics to cover: WHAT is being built (product/feature), WHO it's for (persona), WHAT problem it solves, HARD CONSTRAINTS (budget, timeline, platform, integrations). Keep it to 4-8 questions. Write the raw idea to `docs/plans/phase1-scratch/idea-draft.md` with a header and a section per topic. Orchestrator relays your questions to the user and relays the user's answers back to you."
321
+
322
+ **Autonomous mode:** facilitator synthesizes directly from build request + available context without asking questions. Logs rationale to `docs/plans/build-log.md`.
323
+
324
+ **Returns:** `docs/plans/phase1-scratch/idea-draft.md`
325
+
326
+ ### Step 1.1 — RESEARCH (TEAM of 4 parallel agents, ONE message)
187
327
 
188
328
  Skip if context level is "Decision brief" (research already done).
189
329
 
190
- Call the Agent tool 5 times in a single message. Pass each agent the build request AND the Design Document draft.
330
+ Call the Agent tool 4 times in a single message. Each gets the build request + `docs/plans/phase1-scratch/idea-draft.md`. Each writes its own output file. Raw files are NOT read by the orchestrator in Step 1.2 — a separate Research Synthesizer reads them. They ARE routed by domain to Phase 2 architects (hybrid routing — see Phase 2 Step 2.2).
191
331
 
192
- 1. Description: "Market research" Prompt: "Research market size (TAM/SAM/SOM), competitive landscape (5-10 players), timing, and market structure for: [build request]. Design context: [paste design doc]. Report with a Market Verdict: GREEN/AMBER/RED."
332
+ **CONTEXT header:** Render `rendered_context_header` for phase 1 per the canonical template (see CONTEXT HEADER HARD-GATE above). Prepend to every Phase 1 research prompt below.
193
333
 
194
- 2. Description: "Tech feasibility" — Prompt: "Evaluate hard technical problems (Solved/Hard/Unsolved), build-vs-buy decisions, MVP scope, and stack validation for: [build request]. Design context: [paste design doc]. Verify APIs and libraries from the design exist and are maintained. Report with a Technical Verdict."
334
+ 1. Description: "Feature intel" — subagent_type: `feature-intel` Prompt: "[CONTEXT header above] Extract competitor feature matrix for: [build request]. Idea draft: read docs/plans/phase1-scratch/idea-draft.md with your Read tool. Walk 5-10 rivals. Return must-haves (features present in >=80% of rivals table stakes) + stand-outs (features unique to individual rivals — differentiation opportunities), sorted by competitor. Save to `docs/plans/phase1-scratch/feature-intel.md`."
195
335
 
196
- 3. Description: "User research" — Prompt: "Analyze target persona, jobs-to-be-done, current alternatives, and behavioral barriers to adoption for: [build request]. Design context: [paste design doc]. Report with a User Verdict."
336
+ 2. Description: "Tech feasibility" — subagent_type: `tech-feasibility` — Prompt: "[CONTEXT header above] Evaluate hard technical problems (Solved/Hard/Unsolved), build-vs-buy decisions, MVP scope, stack validation for: [build request]. Idea draft: read docs/plans/phase1-scratch/idea-draft.md with your Read tool. Verify APIs and libraries from the draft exist and are maintained. Save to `docs/plans/phase1-scratch/tech-feasibility.md`. Report with a Technical Verdict."
197
337
 
198
- 4. Description: "Business model" — Prompt: "Evaluate revenue models, unit economics, growth loops, and first-1000-users strategy for: [build request]. Design context: [paste design doc]. Report with a Business Verdict."
338
+ 3. Description: "UX research" — subagent_type: `design-ux-researcher` — Prompt: "[CONTEXT header above] Analyze target persona, jobs-to-be-done, current alternatives, and behavioral barriers for: [build request]. Idea draft: read docs/plans/phase1-scratch/idea-draft.md with your Read tool. Save to `docs/plans/phase1-scratch/ux-research.md`. Report with a User Verdict."
199
339
 
200
- 5. Description: "Risk analysis" — Prompt: "Adversarial review: regulatory risk, security concerns, dependency risks, competitive response, top 3 failure modes for: [build request]. Design context: [paste design doc]. Report with a Risk Verdict."
340
+ 4. Description: "Business model" — subagent_type: `business-model` — Prompt: "[CONTEXT header above] Light-touch revenue/channels/unit-economics analysis for: [build request]. Idea draft: read docs/plans/phase1-scratch/idea-draft.md with your Read tool. Surface product-impact conclusions only — which features the business model requires, which channels gate the feature set. Do not write full financial modeling. Save to `docs/plans/phase1-scratch/business-model.md`."
201
341
 
202
- After all 5 return, synthesize a **Research Brief** with a verdict table. Save to `docs/plans/research-brief.md`.
342
+ ### Step 1.2 RESEARCH DIGEST (context protection)
203
343
 
204
- ### Step 1.3 Design Refinement
344
+ Dispatch the Research Synthesizer as an INTERNAL inline role-string — NO `subagent_type`. The synthesizer reads all 4 raw research files IN ITS OWN context, synthesizes, and returns a compact digest + dynamic questions. The orchestrator never loads the raw files. Saves ~3-5K tokens of orchestrator context per build.
205
345
 
206
- Read the Design Document and Research Brief together. Check for contradictions:
346
+ Call the Agent tool description: "Research digest" — INTERNAL inline role-string — prompt: "You are the Research Synthesizer. Read these 4 raw research files with your own Read tool:
347
+ - `docs/plans/phase1-scratch/feature-intel.md`
348
+ - `docs/plans/phase1-scratch/tech-feasibility.md`
349
+ - `docs/plans/phase1-scratch/ux-research.md`
350
+ - `docs/plans/phase1-scratch/business-model.md`
207
351
 
208
- - Tech-feasibility flagged "Unsolved" hard problem simplify or flag as risk
209
- - Risk-analysis returned RED add mitigation or descope
210
- - User-research says "no validated demand" → flag as pivot point
211
- - Business-model says "no moat" → note for speed-to-market priority
352
+ Synthesize a compact findings digest (~500 words, no padding) covering:
353
+ - Feature landscape summary (must-haves, stand-outs, gaps)
354
+ - Technical verdict with hard-problem callouts
355
+ - Persona + JTBD highlights
356
+ - Business-model implications for product scope
212
357
 
213
- Update the Design Document with corrections. Save final version.
358
+ Then generate a DYNAMIC list of 4-8 brainstorm questions tuned to what actually surfaced — not a fixed script. Example: if tech-feasibility found an unsolved problem, surface a scope question. If UX research says persona is time-poor, surface a flow-simplification question.
214
359
 
215
- ### Step 1.4 — Write CLAUDE.md
360
+ Write:
361
+ 1. `docs/plans/phase1-scratch/findings-digest.md` (~500 words)
362
+ 2. `docs/plans/phase1-scratch/suggested-questions.md` (4-8 dynamic questions)
216
363
 
217
- Create (or overwrite) the project's `CLAUDE.md`. This is the product brain — every agent spawned during the build reads it automatically. Write it from the Design Document and Research Brief. It must give any agent enough context to make smart product, UX, and technical decisions without needing the full design doc.
364
+ Return a compact summary to the orchestrator. The orchestrator does NOT read the raw files."
218
365
 
219
- <HARD-GATE>
220
- CLAUDE.md must be under 200 lines. It is not a wiki, not a conventions doc, not a dump of everything you know. It is the minimum context an agent needs to make correct decisions about this specific product.
221
- </HARD-GATE>
366
+ ### Step 1.3 — INFORMED BRAINSTORM
367
+
368
+ Dispatch the Brainstorm Facilitator (round 2) as an INTERNAL inline role-string. This is a dynamic conversation — questions adapt to what research surfaced, not a fixed script. User makes product decisions WITH research in hand.
369
+
370
+ Call the Agent tool — description: "Informed brainstorm" — INTERNAL inline role-string — prompt: "You are the Brainstorm Facilitator (round 2). Read `docs/plans/phase1-scratch/findings-digest.md` + `docs/plans/phase1-scratch/suggested-questions.md` via the Read tool. Drive a DYNAMIC conversation with the user using those questions — adapt based on answers, don't run a fixed script. Topics to cover (wording is dynamic, tuned to what surfaced):
371
+ - Which must-have features to include vs. cut
372
+ - Which stand-out features for differentiation
373
+ - Any persona / JTBD adjustments
374
+ - Does business model suggest specific features (e.g., freemium needs a free tier UI)
375
+
376
+ Orchestrator relays your questions to the user and relays answers back. Write decisions to `docs/plans/phase1-scratch/user-decisions.md`."
377
+
378
+ **Autonomous mode:** facilitator picks pragmatic defaults from the digest without asking questions. Logs rationale to `docs/plans/build-log.md`.
379
+
380
+ ### Step 1.4 — DESIGN DOC + CLAUDE.md
381
+
382
+ Dispatch the Design Doc Writer as an INTERNAL inline role-string. Writes TWO outputs. The design doc is explicitly named **THE PRD** — the authoritative product document read by every Phase 2-7 agent via `refs.json` anchors, no full pastes.
383
+
384
+ Call the Agent tool — description: "Design doc and CLAUDE.md" — INTERNAL inline role-string — prompt: "You are the Design Doc Writer. Read with your own Read tool:
385
+ - `docs/plans/phase1-scratch/idea-draft.md`
386
+ - `docs/plans/phase1-scratch/findings-digest.md`
387
+ - `docs/plans/phase1-scratch/user-decisions.md`
222
388
 
223
- Structure:
389
+ Write TWO outputs.
390
+
391
+ OUTPUT 1 — `docs/plans/design-doc.md` — **THE PRD** (authoritative product document). Header MUST begin with `# [Product Name] — PRD`. Structure:
392
+ - Product — what it is, core value prop, success criteria
393
+ - User — persona, JTBD, hard constraints
394
+ - Scope — MVP features (must-haves + chosen stand-outs), explicit Out-of-Scope boundary
395
+ - Tech Stack — chosen stack with 1-line rationale
396
+ - Data Model — shape of core entities
397
+ - Decisions — links to `decisions.jsonl` rows
398
+
399
+ This doc is read by all Phase 2-7 agents via `refs.json` anchors. Section headers should be stable (don't rename them later) so anchors survive.
400
+
401
+ OUTPUT 2 — `CLAUDE.md` (project root, NOT `docs/plans/`). <200-line product brain, auto-loaded into every spawned subagent context by Claude Code. The orchestrator NEVER pastes it. Structure:
224
402
 
225
403
  ```
226
404
  ## Product
227
405
  [1-3 sentences: what this is, core value prop, what success looks like]
228
406
 
229
407
  ## User
230
- [Primary persona: who they are, what they care about, pain points,
231
- technical sophistication. This drives every UX decision.]
408
+ [Primary persona: who they are, what they care about, pain points, technical sophistication]
232
409
 
233
410
  ## Tech Stack
234
- [Stack choices with 1-line rationale for each. Framework, DB, auth,
235
- key libraries, deployment target.]
411
+ [Stack choices with 1-line rationale for each]
236
412
 
237
413
  ## Scope
238
- [What's in MVP vs. deferred. Hard boundaries. This prevents agents
239
- from building features that aren't scoped.]
414
+ [What's in MVP vs. deferred. Hard boundaries.]
240
415
 
241
416
  ## Rules
242
- [Project-specific hard rules derived from the product and user context.
243
- Examples: "All data must be real-time — no simulated/fake data",
244
- "User must be able to pause/stop any automated process at any time",
245
- "Every interactive element must have visible feedback within 200ms".
246
- Only include rules this specific project needs — not generic best practices.]
417
+ [Project-specific hard rules derived from the product and user context.]
247
418
  ```
248
419
 
249
- Keep it product-focused. An implementation agent reading this should understand WHO the user is and WHAT matters enough to make the right call when the handoff prompt doesn't cover an edge case.
420
+ <HARD-GATE>
421
+ CLAUDE.md must be under 200 lines. Not a wiki, not a conventions doc, not a dump of everything. Minimum context an agent needs to make correct decisions about this specific product.
422
+ </HARD-GATE>
423
+
424
+ Return 3 decision rows in your structured result under a `phase_1_decisions` field — one each for tech stack, data model, and scope boundary. Each row shape: `{phase: 1, author: \"architect\", type: \"tech-stack\" | \"data-model\" | \"scope-boundary\", summary, rationale, related_files: [\"docs/plans/design-doc.md\"]}`. The orchestrator forwards each row through the `scribe_decision` MCP tool (see Phase 4 "Orchestrator-scribe dispatch"). DO NOT write `decisions.jsonl` directly."
425
+
426
+ **Writes:** `docs/plans/design-doc.md` (PRD), `CLAUDE.md`. Decision rows flow through the orchestrator's `scribe_decision` MCP calls.
427
+
428
+ **Post-Step 1.4 — CLAUDE.md size enforcement (mechanical check):**
429
+ After the Design Doc Writer returns, run `wc -l < CLAUDE.md` and capture the line count. If the count exceeds 200 lines:
430
+ 1. FAIL the step. Log to `docs/plans/build-log.md`: `"CLAUDE.md size violation: {count} lines (limit: 200)"`.
431
+ 2. Re-dispatch the Design Doc Writer with this additional instruction prepended: `"CLAUDE.md EXCEEDED 200 LINES ({count} lines). Rewrite CLAUDE.md to ≤200 lines. Cut aggressively — keep only what a subagent needs to make correct product decisions. No conventions, no wiki content, no boilerplate."`.
432
+ 3. Max 2 retries. If still over 200 after 2 retries, HARD-FAIL and surface to user: `"CLAUDE.md is {count} lines after 2 rewrites. Please manually trim to ≤200 lines before proceeding — this file is auto-loaded into every subagent and bloat here multiplies across all Phases 2-7 dispatches."`.
250
433
 
251
434
  ### Quality Gate 1
252
435
 
253
- **Autonomous:** Log design and research paths to `docs/plans/build-log.md`. If 2+ RED verdicts, log warning. Proceed.
436
+ **Interactive:** Present Design Doc summary + Research Digest findings to user. Ask: "Approve this design, or adjust?"
437
+
438
+ <HARD-GATE>
439
+ Gate 1 rejection path is codified:
440
+ - On NO → loop back to Phase 1 Step 1.0 with user feedback passed back to Brainstorm Facilitator (round 1 re-invocation).
441
+ - On YES → proceed to Step 1.5.
442
+ - DO NOT PROCEED without user approval in interactive mode.
443
+ </HARD-GATE>
444
+
445
+ **Autonomous:** Log design-doc path + digest path to `docs/plans/build-log.md`. Auto-approve. Proceed.
254
446
 
255
- **Interactive:** Present Design Document summary + Research Brief verdict table. Ask: "Approve this design, or want to adjust?" <HARD-GATE>DO NOT PROCEED without user approval.</HARD-GATE>
447
+ Update TodoWrite and `.build-state.json`.
256
448
 
257
- Update TodoWrite and `docs/plans/.build-state.md`.
449
+ ### Step 1.5 — PREREQ COLLECTOR (post-Gate 1)
258
450
 
259
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
451
+ Dispatch the Prereq Collector as an INTERNAL inline role-string. Reads `design-doc.md` to determine which credentials are actually needed for the chosen stack. Asks the user ONLY for stack-specific creds.
452
+
453
+ Call the Agent tool — description: "Prereq collection" — INTERNAL inline role-string — prompt: "You are the Prereq Collector. Read `docs/plans/design-doc.md` with your own Read tool — focus on the Tech Stack section. Determine which credentials the chosen stack actually needs (do NOT ask for a generic laundry list — ask ONLY for what this stack uses).
454
+
455
+ Example: 'You chose Next.js + Supabase + Vercel — I need your Supabase URL, Supabase anon key, and Vercel auth token.' Skip anything the stack doesn't use.
456
+
457
+ Output: `docs/plans/phase1-scratch/prereqs.json` with shape `{supabase_url, supabase_anon_key, ...}`. Ask the user once. If they don't have a credential, mark it as `null` and note in the JSON that Phase 4 will surface it as a blocker if hit."
458
+
459
+ **Autonomous mode:** Create `.env.example` with required keys. Proceed. Log missing keys as blockers if hit during build.
460
+
461
+ **Why here:** at Phase 0 we don't yet know the stack (it's decided in Step 1.3). Asking for creds before Gate 1 means asking for wrong creds or re-asking on rejection.
462
+
463
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
260
464
 
261
465
  ---
262
466
 
263
- ## Phase 2: Architecture & Planning
467
+ ## Phase 2: Plan / Architect — TEAM of 6 + sequence
264
468
 
265
- **Goal**: Convert the validated Design Document into a concrete architecture and ordered task list. Every agent receives the Design Document not just the build request.
469
+ **Goal**: Convert the PRD into a concrete architecture and ordered task list with explicit dependencies. Every architect receives the PRD (design-doc.md) + the Research Digest + its domain's raw research file (hybrid routing).
266
470
 
267
- ### Step 2.1 — Explore (existing codebase only)
471
+ **Mode-specific branch:**
472
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 2 (replaces Backend/Frontend dispatch with SwiftUI/SwiftData/Concurrency/iOS security; adds Feature Flag Resolution at end of phase).
473
+ - `project_type=web`: no additional branch instructions.
268
474
 
269
- If existing code, call the Agent tool description: "Explore codebase" — prompt: "Explore this codebase. Map architecture layers, file conventions, testing patterns, existing features. Report findings."
475
+ ### Step 2.1 — Explore existing codebase (only if existing code)
476
+
477
+ If existing code, call the Agent tool — description: "Explore codebase" — INTERNAL inline role-string — prompt: "Explore existing codebase. Map architecture layers, file conventions, testing patterns, existing features, integration points. Return a compact summary suitable for architects to consume — not a full dump."
270
478
 
271
479
  If greenfield, skip to Step 2.2.
272
480
 
273
- ### Step 2.2 — Architecture Design (4 agents in parallel, ONE message)
481
+ ### Step 2.2 — Architecture Design (TEAM of 6 architects coordinating via SendMessage)
482
+
483
+ The 6 architects design as a TEAM — not 6 isolated subagents. Cross-domain contract boundaries (Backend↔Frontend on API shape, Security↔Backend on auth, A11y↔Frontend on component patterns, Performance↔Backend+Data on query shapes) are caught at design time via peer SendMessage, not absorbed silently by a downstream stitcher.
484
+
485
+ **On re-entry from LRR backward routing:** If Phase 2 is being re-opened via the re-entry dispatch template (Step 6.3), skip team creation if the original `phase-2-architects` team is still live from this build; otherwise recreate it. Pass the re-entry payload (`{blocking_finding, prior_output: "docs/plans/architecture.md", decision_row}`) into the dispatch prompt of the architect(s) whose domain matches `decision_row.author` — only those architects re-run, not all 6. The re-dispatched architect revises its `docs/plans/phase-2-contracts/<name>.md` in place, SendMessages peers on any contract boundary it now changes, and the synthesizer re-runs once to re-stitch `architecture.md`. Do NOT redo unaffected domains.
274
486
 
275
- Read the Design Document and Research Brief. Pass both to every agent.
487
+ **Step 2.2a Create the team.**
276
488
 
277
- Call the Agent tool 4 times in a single message:
489
+ Call `TeamCreate` with `team_name: "phase-2-architects"`. This team scopes the SendMessage channel for the 6 architects below. Capture the team id in `.build-state.json` for teardown.
278
490
 
279
- 1. Description: "Backend architecture" Prompt: "Design system architecture. DESIGN DOC: [paste]. RESEARCH: [paste tech + risk sections]. Include services, data models, API contracts, database schema. Be specific. Respect tech stack and constraints from the design doc."
491
+ **Step 2.2bDispatch 6 architects as teammates (ONE message).**
280
492
 
281
- 2. Description: "Frontend architecture" Prompt: "Design frontend architecture. DESIGN DOC: [paste]. RESEARCH: [paste user research section]. Include component hierarchy, layout, responsive strategy, state management. Align UX with the user persona from research."
493
+ Call the Agent tool 6 times in a single message. Each call passes `team_name: "phase-2-architects"` and a unique `name` (listed below). Each architect receives: `docs/plans/design-doc.md` (PRD) + `docs/plans/phase1-scratch/findings-digest.md` + ITS DOMAIN'S RAW RESEARCH FILE (hybrid routing) + the team roster + cross-check pairings + the per-architect output file path.
282
494
 
283
- 3. Description: "Security architecture" Prompt: "Security review. DESIGN DOC: [paste]. RESEARCH: [paste risk section]. Cover auth model, input validation, secrets management, threat model. Address any regulatory risks flagged in research."
495
+ Shared brief appended to every architect prompt:
284
496
 
285
- 4. Description: "Implementation blueprint" — Prompt: "Implementation blueprint. DESIGN DOC: [paste]. Include specific files to create/modify, build sequence, dependency order. Scope to MVP boundary from design doc."
497
+ ```
498
+ TEAM: phase-2-architects
499
+ ROSTER:
500
+ - backend-architect (owns services, API contracts, DB schema)
501
+ - frontend-architect (owns component hierarchy, state mgmt, routing)
502
+ - data-engineer (owns ETL/ELT, schema versioning, query patterns)
503
+ - security-engineer (owns auth model, input validation, threat model)
504
+ - accessibility-auditor (owns WCAG 2.2 AA constraints on component/nav choice)
505
+ - performance-benchmarker (owns quality-targets.json, bundle + latency budgets)
506
+
507
+ CROSS-CHECK PAIRINGS (mandatory — if your design touches one of these boundaries, SendMessage the peer before you finalize):
508
+ - Backend ↔ Frontend on API contract shape (REST vs GraphQL, request/response schemas, error envelope)
509
+ - Security ↔ Backend on auth flow (token storage, refresh, session model, authz gates)
510
+ - Accessibility ↔ Frontend on component patterns (primitives, focus management, landmark structure)
511
+ - Performance ↔ Backend+Data on query shapes (N+1 risk, indexing strategy, bundle impact of data layer choices)
512
+
513
+ COORDINATION RULES:
514
+ - Plain text in your output file is INVISIBLE to teammates. If a contract boundary intersects another architect's domain, you MUST `SendMessage` to that peer using the exact `name` from the roster above. Do not assume they will read your file.
515
+ - If a peer SendMessage challenges a decision you have written, revise your output file and SendMessage back with the resolution — do not silently ignore.
516
+ - Idle (exit) only after: (1) your initial read + draft is complete, AND (2) all cross-check pairings touching your domain have either been resolved via SendMessage or confirmed non-intersecting.
517
+
518
+ OUTPUT:
519
+ Write your findings to `docs/plans/phase-2-contracts/<your-name>.md` (e.g., `docs/plans/phase-2-contracts/backend-architect.md`). This file is the authoritative record of your post-debate position — include both your initial decisions AND any revisions driven by peer SendMessage.
520
+ ```
286
521
 
287
- After all 4 return, YOU synthesize into one Architecture Document. Save to `docs/plans/architecture.md`.
522
+ Per-architect dispatches:
288
523
 
289
- ### Step 2.3 Metric Loop: Architecture Quality
524
+ **CONTEXT header:** Render `rendered_context_header` for phase 2 per the canonical template (see CONTEXT HEADER HARD-GATE above). Prepend to every Phase 2 architect prompt below.
290
525
 
291
- Run the Metric Loop Protocol (`protocols/metric-loop.md`) on the Architecture Document. Define a metric based on: coverage of design doc requirements, specificity, consistency between agents, and **simplicity** — is this the simplest architecture that meets the requirements? Could any service, abstraction, or dependency be eliminated without losing functionality? Penalize over-engineering (microservices for a simple app, Kubernetes for a static site, complex state management for a 3-page app). Max 3 iterations.
292
526
 
293
- ### Step 2.4Sprint Planning
527
+ 1. Description: "Backend architecture" — subagent_type: `engineering-backend-architect` — team_name: `phase-2-architects` — name: `backend-architect` — Prompt: "[CONTEXT header above] Design system architecture. Read these files via your Read tool before starting do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\n - YOUR DOMAIN RAW: `docs/plans/phase1-scratch/tech-feasibility.md`, `docs/plans/phase1-scratch/feature-intel.md`\nInclude services, data models, API contracts, database schema, integration points. Respect stack choices from PRD.\n\n[paste shared team brief above]"
294
528
 
295
- Follow the Planning Protocol (`protocols/planning.md`). Use 2 sequential Agent tool calls:
529
+ 2. Description: "Frontend architecture" — subagent_type: `engineering-frontend-developer` — team_name: `phase-2-architects` — name: `frontend-architect` — Prompt: "[CONTEXT header above] Design frontend architecture. Read these files via your Read tool before starting — do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\n - YOUR DOMAIN RAW: `docs/plans/phase1-scratch/ux-research.md`, `docs/plans/phase1-scratch/feature-intel.md`\nInclude component hierarchy, layout strategy, responsive approach, state management, routing. Align UX with the persona from research.\n\n[paste shared team brief above]"
296
530
 
297
- Call the Agent tool — description: "Sprint breakdown" — prompt: "Break this architecture into ordered, atomic tasks. Each task needs: description, acceptance criteria, dependencies, size (S/M/L). Include a `**Behavioral Test:**` field for every task that has UI a concrete interaction test: 'Navigate to [page], click [element], verify [expected outcome]'. API-only tasks should have curl-based acceptance tests instead. ARCHITECTURE: [paste]. DESIGN DOC: [paste]. Scope to MVP only."
531
+ 3. Description: "Data engineering" — subagent_type: `engineering-data-engineer` team_name: `phase-2-architects` name: `data-engineer` Prompt: "[CONTEXT header above] Design data architecture. Read these files via your Read tool before starting do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\n - YOUR DOMAIN RAW: `docs/plans/phase1-scratch/tech-feasibility.md`\nInclude ETL/ELT patterns, schema versioning, query patterns, indexing strategy, data lineage, migration plan.\n\n[paste shared team brief above]"
298
532
 
299
- Then call the Agent tooldescription: "Validate task list"prompt: "Validate this task list: [paste]. Check scope is realistic, no missing tasks, descriptions specific enough for a developer agent to execute, all tasks within MVP boundary."
533
+ 4. Description: "Security architecture" subagent_type: `engineering-security-engineer` team_name: `phase-2-architects` name: `security-engineer` Prompt: "[CONTEXT header above] Security review. Read these files via your Read tool before starting — do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\nCover auth model, input validation, secrets management, threat model, dependency hygiene. Note: no raw research file routed digest only (security architecture is a cross-cutting concern).\n\n[paste shared team brief above]"
300
534
 
301
- Save to `docs/plans/sprint-tasks.md`.
535
+ 5. Description: "A11y constraints" — subagent_type: `a11y-architect` — team_name: `phase-2-architects` — name: `accessibility-auditor` — Prompt: "[CONTEXT header above] Accessibility-driven architecture constraints. Read these files via your Read tool before starting — do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\n - YOUR DOMAIN RAW: `docs/plans/phase1-scratch/ux-research.md`\nIdentify WCAG 2.2 AA requirements that affect component choice, navigation structure, form patterns, focus management, landmark regions.\n\n[paste shared team brief above]"
536
+
537
+ 6. Description: "Performance constraints" — subagent_type: `testing-performance-benchmarker` — team_name: `phase-2-architects` — name: `performance-benchmarker` — Prompt: "[CONTEXT header above] Define quality targets for this build. Read these files via your Read tool before starting — do NOT expect pasted content:\n - PRD: `docs/plans/design-doc.md`\n - DIGEST: `docs/plans/phase1-scratch/findings-digest.md`\n - YOUR DOMAIN RAW: `docs/plans/phase1-scratch/tech-feasibility.md`\nWrite `docs/plans/quality-targets.json` covering bundle budget, LCP, TTI, API p95, Lighthouse scores. Use per-Scope budgets from `orchestration-proposed-state.md` §11: Marketing 500KB / Product 300KB / Dashboard 400KB / Internal 200KB gzipped.\n\n[paste shared team brief above]"
538
+
539
+ **Step 2.2c — Wait for all 6 teammates to idle**, then proceed to synthesis. The `docs/plans/phase-2-contracts/*.md` files now contain post-debate positions (initial draft plus any SendMessage-driven revisions). The orchestrator does NOT read these files — the synthesizer below does.
540
+
541
+ After all 6 teammates are idle, the 4 raw research files are **SPENT**. They sit on disk for audit but no downstream phase reads them — they are NOT in the `refs.json` index. The orchestrator MOVES them to `docs/plans/phase1-scratch/` if not already there, to make the distinction physically obvious.
542
+
543
+ **Step 2.2d — Team teardown.** After the synthesizer dispatch at Step 2.3 returns, call `TeamDelete` on `phase-2-architects` to clean up the team channel.
544
+
545
+ ### Step 2.3 — Sequence: Implementation Blueprint → Sprint Breakdown → DAG Validator → Refs Indexer
546
+
547
+ Four sequential dispatches.
548
+
549
+ **CONTEXT header:** Reuse `rendered_context_header` from phase 2 (already rendered above). Prepend to Step 2.3 synthesizer + sprint-breakdown prompts.
550
+
551
+ 1. Description: "Implementation blueprint" — subagent_type: `code-architect` — Prompt: "[CONTEXT header above] Implementation blueprint. Read the PRD via your Read tool: `docs/plans/design-doc.md`. Read all 6 post-debate architect positions via your own Read tool from `docs/plans/phase-2-contracts/`:\n - `backend-architect.md`\n - `frontend-architect.md`\n - `data-engineer.md`\n - `security-engineer.md`\n - `accessibility-auditor.md`\n - `performance-benchmarker.md`\n\nThese files are the authoritative team positions AFTER any SendMessage-driven revisions — the architects already cross-checked each other's contract boundaries, so you can stitch without re-debating. Your job is to assemble, not adjudicate. Include specific files to create/modify, build sequence, dependency order. Write `docs/plans/architecture.md` with stable section anchors per `protocols/architecture-schema.md`. Required top-level sections: Overview, Frontend, Backend, Data Model, Security, Infrastructure, MVP Scope, Out of Scope. Scope to MVP boundary from the PRD."
552
+
553
+ 2. Description: "Sprint breakdown" — subagent_type: `planner` — Prompt: "[CONTEXT header above] Break this architecture into ordered, atomic tasks. Each task needs: description, acceptance criteria, **dependencies** (list of task IDs this depends on), size (S/M/L), **Behavioral Test** field for every UI task (concrete interaction: 'Navigate to [page], click [element], verify [outcome]') or curl-based acceptance test for API tasks. Read these files via your Read tool before starting:\n - ARCHITECTURE: `docs/plans/architecture.md`\n - PRD: `docs/plans/design-doc.md`\nScope to MVP only. Save to `docs/plans/sprint-tasks.md`. Dependencies field is load-bearing — Phase 4 uses it to batch independent tasks in parallel."
554
+
555
+ 3. Description: "Task DAG validator" — INTERNAL inline role-string — Prompt: "You are the Task DAG Validator. Read `docs/plans/sprint-tasks.md`. Validate for DAG correctness:
556
+ - No circular dependencies
557
+ - All referenced task IDs in the Dependencies field exist
558
+ - Sizing is consistent (S/M/L)
559
+ - Dependencies match the architecture document (don't depend on a task that builds a component you don't need)
560
+ - Every UI task has a Behavioral Test field; every API task has a curl-based test
561
+ Report any violations. If clean, return PASS. If violations, return a list of fix requests — Sprint Breakdown re-dispatches once with the fix list."
562
+
563
+ 4. Description: "Refs indexer" — INTERNAL inline role-string — Prompt: "You are the Refs Indexer. Generate `docs/plans/refs.json` covering ALL live downstream docs:
564
+ - `docs/plans/design-doc.md` (PRD)
565
+ - `docs/plans/architecture.md`
566
+ - `docs/plans/sprint-tasks.md`
567
+ - `docs/plans/quality-targets.json`
568
+ - `docs/plans/visual-design-spec.md` (if it exists yet — Phase 3 extends refs.json after it writes this file)
569
+
570
+ For each doc, extract section anchors into a flat index. Schema: `[{\"anchor\": \"design-doc.md#persona\", \"topic\": \"user persona\", \"file_path\": \"docs/plans/design-doc.md\"}, ...]`. This index is consumed by the Phase 4 Briefing Officer for per-task context maps. Do NOT include Phase 1 scratch files — they are SPENT."
571
+
572
+ **Architecture Metric Loop (callable service):** Run the Metric Loop Protocol (`protocols/metric-loop.md`) on `architecture.md`. Define a metric: coverage of PRD requirements, specificity, consistency across the 6 architects, and **simplicity** — is this the simplest architecture that meets the requirements? Could any service, abstraction, or dependency be eliminated? Penalize over-engineering. Max 3 iterations.
573
+
574
+ **Architecture decisions:** The Implementation Blueprint synthesizer returns 4 `deviation_row` objects (or a `phase_2_decisions` array of row objects) in its structured result — one per cross-cutting Phase 2 decision (API contract, persistence layer, auth model, framework choice). The orchestrator forwards each row through the `scribe_decision` MCP tool (see Phase 4 "Orchestrator-scribe dispatch"); the MCP allocates `D-2-<seq>` IDs and atomically appends to `docs/plans/decisions.jsonl`. Author = `architect`. Each row carries a `ref` anchor pointing into `architecture.md` per `protocols/decision-log.md`. Total: 4 rows.
575
+
576
+ **Writes:** `docs/plans/architecture.md`, `docs/plans/sprint-tasks.md`, `docs/plans/quality-targets.json`, `docs/plans/refs.json`. Decision rows (4) flow through the orchestrator's `scribe_decision` MCP calls.
302
577
 
303
578
  ### Quality Gate 2
304
579
 
305
- **Autonomous:** Log to `docs/plans/build-log.md`. Proceed.
580
+ **Interactive:** Present Architecture + Sprint Task List (with dependency graph). Ask: "Approve to start designing + building, or flag changes?"
581
+
582
+ <HARD-GATE>
583
+ Gate 2 rejection path is codified:
584
+ - On NO → loop back to Phase 2 with user feedback.
585
+ - On YES → proceed to Phase 3.
586
+ - DO NOT PROCEED without user approval in interactive mode.
587
+ - Also codifies the LRR BLOCK backward edge: `LRR BLOCK authoring=Phase 2 → back to Phase 2`. The ⭐⭐ star rule routes BLOCK findings via Aggregator decisions.jsonl `decided_by` lookup; if `decided_by == architect`, the build re-opens Phase 2 with the finding as input.
588
+ </HARD-GATE>
589
+
590
+ **Autonomous:** Log to `docs/plans/build-log.md`. Auto-approve. Proceed.
306
591
 
307
- **Interactive:** Present Architecture + Sprint Task List. Ask: "Approve to start building, or flag changes?" <HARD-GATE>DO NOT PROCEED without user approval.</HARD-GATE>
592
+ Update TodoWrite and `.build-state.json`.
308
593
 
309
- Update TodoWrite and `docs/plans/.build-state.md`.
594
+ **iOS feature flag resolution:** if `project_type=ios`, resolve `ios_features` before leaving Phase 2 per `protocols/ios-phase-branches.md` §Phase 2 → Feature Flag Resolution.
310
595
 
311
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
596
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
312
597
 
313
598
  ---
314
599
 
315
- ## Phase 3: Design & Visual Identity
600
+ ## Phase 3: Design (DNA-first SEQUENCE)
601
+
602
+ **Goal**: Lock Visual DNA first, then research against it, then compose from library, then spec, then implement, then critique, then a11y.
316
603
 
317
- **Goal**: Transform architecture into a research-backed visual design system, proven with Playwright screenshots. Fully autonomousagents research, decide, and iterate without user input.
604
+ **NOTE:** Runs AFTER Phase 2. Cannot parallelizedesign decisions depend on architecture outcomes.
318
605
 
319
606
  **Skip if** the project has no user-facing frontend (CLI tools, pure APIs, backend services).
320
607
 
321
608
  <HARD-GATE>
322
- UI/UX IS THE PRODUCT. This phase is a full peer to Architecture and Build — not a footnote, not an afterthought, not a "nice to have." Do NOT skip, compress, or rush this phase for any reason. The agents must research real competitors and award-winning sites, make deliberate visual choices backed by that research, build a living style guide with every component rendered and interactive, and iterate with Playwright-verified visual QA before a single line of product code is written.
609
+ UI/UX IS THE PRODUCT. This phase is a full peer to Architecture and Build — not a footnote, not an afterthought. Do NOT skip, compress, or rush this phase for any reason.
323
610
 
324
- Phase 4 (Foundation) WILL NOT START without `docs/plans/visual-design-spec.md`. If it does not exist, return here.
611
+ Phase 4 WILL NOT START without `docs/plans/visual-design-spec.md` (web) or `docs/plans/ios-design-board.md` (iOS). If the artifact does not exist, return here.
325
612
  </HARD-GATE>
326
613
 
327
- ### Step 3.1 Design Research (2 agents, parallel, both use Playwright)
614
+ **Mode-specific branch files drive Phase 3 in detail:**
615
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 3 (HIG + App Store + screenlane harvest → iOS Design Board, SwiftUI Preview QA loop).
616
+ - `project_type=web`: follow `protocols/web-phase-branches.md` §Phase 3 — this file contains the NEW structure with steps 3.0-3.7 covering Visual DNA Selection (Brand Guardian as DNA owner at 3.0), Visual Research, Component Library Mapping, UX Architecture, Visual Design Spec, Inclusive Visuals Check, Style Guide Implementation (wrapped in Design Critic metric loop), and A11y Design Review. See `orchestration-proposed-state.md` §11 for the component library strategy.
328
617
 
329
- Follow the Design Protocol (`protocols/design.md`), Step 3.1.
618
+ **Phase 3 write discipline:** Phase 3 is the writer for `docs/plans/visual-design-spec.md` (web) and extends `docs/plans/refs.json` to cover the visual spec anchors once it lands. Phase 3 does NOT write to `architecture.md` or `sprint-tasks.md` — those are Phase 2's.
330
619
 
331
- Call the Agent tool 2 times in one message:
620
+ <HARD-GATE>
621
+ LRR BLOCK backward edge: `LRR BLOCK authoring=Phase 3 → back to Phase 3`. The ⭐⭐ star rule routes BLOCK findings via Aggregator decisions.jsonl `decided_by` lookup; if `decided_by == design-brand-guardian` or any Phase 3 writer, the build re-opens Phase 3 with the finding as input.
622
+ </HARD-GATE>
332
623
 
333
- 1. Description: "Competitive visual audit" Prompt: "Research the top 5-8 competitors/analogues for: [product description]. Use Playwright to screenshot each site (desktop 1920x1080 + mobile 375x812). Screenshot standout components (hero, cards, forms, nav, CTAs). Save to docs/plans/design-references/competitors/. Analyze visual language: colors, typography, spacing, what feels premium vs cheap. Rank by visual quality. DESIGN DOC: [paste]."
624
+ **On re-entry from LRR backward routing:** When Phase 3 is re-opened via the re-entry dispatch template (Step 6.3), the orchestrator passes the re-entry payload (`{blocking_finding, prior_output: "docs/plans/visual-design-spec.md" or "docs/plans/visual-dna.md", decision_row}`) into the specific Phase 3 step named by `decision_row.author`. That step revises the prior output to address `blocking_finding` only DNA lock, component manifest, or visual spec and emits a new decision_row. Unaffected steps are NOT re-run. Mode-specific branch files (`protocols/web-phase-branches.md` / `protocols/ios-phase-branches.md`) define which step owns which `decided_by` value.
334
625
 
335
- 2. Description: "Design inspiration mining" — Prompt: "Search Awwwards.com, Godly.website, SiteInspire for award-winning sites in category: [product category]. Use Playwright to screenshot top 5-8 results + standout components. Save to docs/plans/design-references/inspiration/. Identify visual trends, what separates best-in-class from generic. DESIGN DOC: [paste]."
626
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
336
627
 
337
- After both return, synthesize a **Design Research Brief** to `docs/plans/design-research.md`. Include all screenshot paths.
628
+ ---
338
629
 
339
- ### Step 3.2Design Direction (2 agents, sequential)
630
+ ## Phase 4: Build PARALLEL BATCHES by task dependencies
340
631
 
341
- Follow the Design Protocol (`protocols/design.md`), Step 3.2.
632
+ <HARD-GATE>
633
+ Before starting Phase 4: Phase 2 must be approved, Phase 3 must have produced the design artifact for this mode (`visual-design-spec.md` web / `ios-design-board.md` iOS). You MUST call the Agent tool for EVERY task. No exceptions.
634
+ </HARD-GATE>
342
635
 
343
- 1. Call the Agent tool description: "UX architecture" — Prompt: "Create structural design foundation. INPUTS: frontend architecture section from architecture.md [paste], Design Research Brief [paste], reference screenshot paths [list], user persona [paste]. OUTPUT: information architecture, layout strategy, component hierarchy, responsive approach, interaction patterns. Base decisions on competitive research, not generic patterns."
636
+ **Goal**: Scaffold project + execute sprint tasks in dependency-ordered batches. Independent sibling tasks run in parallel (~30-50% wall-clock saving on typical sprint).
344
637
 
345
- 2. Call the Agent tool — description: "Visual design spec" — Prompt: "Create the Visual Design Spec with AUTONOMOUS decisions — pick the single best direction, do not present options. INPUTS: UX foundation [paste previous output], Design Research Brief [paste], reference screenshot paths [list], user persona [paste]. OUTPUT: color system (with hex, light+dark), typography (Google Fonts, mathematical scale), 8px spacing system, tinted shadow system, border radius, animation/motion, component styles with ALL states. Every choice must cite the research. Apply anti-AI-template rules from the Design Protocol. Save to docs/plans/visual-design-spec.md."
638
+ **Mode-specific branch:**
639
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 4 (entitlements generator + Info.plist hardening, XcodeBuildMCP folder structure, SwiftUI design tokens, Maestro flow stubs).
640
+ - `project_type=web`: follow `protocols/web-phase-branches.md` §Phase 4 (web project scaffolding, CSS design system tokens, Playwright acceptance test stubs).
346
641
 
347
- ### Step 3.3Living Style Guide (1 implementation agent)
642
+ ### Step 4.0Scaffold (old Phase 4 Foundation merged here)
348
643
 
349
- Follow the Design Protocol (`protocols/design.md`), Step 3.3.
644
+ Scaffolding is project skeleton + design system + acceptance test stubs. Three sequential dispatches (full details in the mode-specific branch file):
350
645
 
351
- Call the Agent tool description: "Build living style guide" mode: "bypassPermissions" prompt: "[COMPLEXITY: L] Build a living style guide page (/design-system route or standalone HTML). INPUTS: Visual Design Spec [paste], UX foundation [paste relevant sections], reference screenshots [list paths — these are your quality targets]. Must include rendered, interactive examples of: color swatches, typography scale, spacing scale, buttons (all states), form elements (all states), cards, navigation, feedback components (alerts, toasts, spinners, empty states), modals/overlays, and layout grid examples. Every component interactive (hover, focus, transitions work). Mobile-responsive. This ships with the product. Commit: 'feat: living style guide'."
646
+ **CONTEXT header:** Render `rendered_context_header` for phase 4 per the canonical template (see CONTEXT HEADER HARD-GATE above). Includes `dna` field for web projects. Prepend to every Phase 4 scaffold prompt below; branch files do the same for per-task flow.
352
647
 
353
- ### Step 3.4Visual QA Loop (Playwright + Metric Loop)
648
+ 1. Description: "Project scaffolding" subagent_type: `engineering-rapid-prototyper` mode: "bypassPermissions" — prompt per branch file (web: Next.js/Vite/etc; iOS: Xcode project from bootstrap). Prepend CONTEXT header above. [COMPLEXITY: M]
354
649
 
355
- Run the Metric Loop Protocol (`protocols/metric-loop.md`) using the measurement criteria from the Design Protocol (`protocols/design.md`, Step 3.4).
650
+ 2. Description: "Design system setup" — subagent_type: `engineering-frontend-developer` mode: "bypassPermissions" prompt per branch file. Prepend CONTEXT header above. Implements design tokens from `visual-design-spec.md` or `ios-design-board.md`. The living style guide from Phase 3 is the reference implementation — components must match. [COMPLEXITY: M]
356
651
 
357
- Measurement: Playwright screenshots of the living style guide sections (desktop + mobile). Design critic agent scores 0-100 across 6 dimensions: spacing/alignment, typography hierarchy, color harmony, component polish, responsive quality, originality (anti-AI-template check). Receives screenshots + Visual Design Spec + reference screenshots.
652
+ 3. Description: "Scaffold acceptance tests" INTERNAL inline role-string mode: "bypassPermissions" prompt: "[CONTEXT header above] Scaffold acceptance tests from sprint-tasks.md. Use Page Object Model. Read `docs/plans/sprint-tasks.md`. For every task with a Behavioral Test field, create a Playwright test stub (web) or Maestro flow stub (iOS). Each stub: navigate interact assert. Stubs must FAIL right now (features aren't built yet) — that's correct. Commit: 'test: scaffold acceptance tests from sprint tasks'."
358
653
 
359
- **Target: 80. Max 5 iterations.** On stall: accept if >= 65, log warning below 65.
654
+ **Scaffold verification:** Run the Verify Protocol (INTERNAL inline "Verify scaffolding") — 7 checks sequentially, stop on first FAIL. Do not proceed to Step 4.1 until PASS.
360
655
 
361
- ### Step 3.5Autonomous Quality Gate
656
+ ### Step 4.1+Task execution in dependency-ordered batches
362
657
 
363
- Log to `docs/plans/build-log.md`: final screenshot paths, score history table, design decisions, originality score. No user pause. Proceed to Phase 4.
658
+ Expand TodoWrite with each sprint task.
364
659
 
365
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
660
+ Build a DAG from `sprint-tasks.md` Dependencies fields. Execute in batches: the next batch is the set of all tasks whose dependencies are all complete. Dispatch each batch as parallel Agent tool calls in ONE message.
366
661
 
367
- ---
662
+ **Per-task flow (runs for every task in every batch):**
368
663
 
369
- ## Phase 4: Foundation
664
+ #### Briefing Officer (INTERNAL inline)
370
665
 
371
- <HARD-GATE>
372
- Before starting Phase 4: Phase 2 must be approved AND Phase 3 must have produced `docs/plans/visual-design-spec.md`.
373
- If visual-design-spec.md does not exist, DO NOT PROCEED. Return to Phase 3.
374
- Step 4.2 (Design System) MUST implement from visual-design-spec.md — not generic architecture tokens.
375
- </HARD-GATE>
666
+ Dispatch before every implementer. Assembles a compact <40-line context map that tells the implementer EXACTLY where to look for each kind of context. Refs not pastes.
667
+
668
+ Call the Agent tool — description: "Briefing for [task name]" — INTERNAL inline role-string — prompt: "You are the Briefing Officer. Read `docs/plans/refs.json` and the task row for [task-id] from `docs/plans/sprint-tasks.md`. Build a compact context map (~40 lines max) in this exact shape:
376
669
 
377
- ### Step 4.1 — Scaffolding
670
+ ```
671
+ CONTEXT MAP — [task-id] [task name]
672
+ persona / JTBD → design-doc.md#persona
673
+ product scope → design-doc.md#scope
674
+ visual tokens → visual-design-spec.md#tokens
675
+ component variants → component-manifest.md#[category]
676
+ auth model → architecture.md#auth
677
+ data schema → architecture.md#data-model
678
+ sibling task deps → sprint-tasks.md#[dep-id-1], #[dep-id-2]
679
+ prior decisions → decisions.jsonl rows [row-id-1], [row-id-2]
680
+ quality targets → quality-targets.json (full file)
681
+ ```
378
682
 
379
- Call the Agent tool description: "Project scaffolding" mode: "bypassPermissions" prompt: "[COMPLEXITY: M] Set up the project from this architecture: [paste]. Create directory structure, dependencies, build tooling, linting config, test framework with one passing test, .gitignore, .env.example. Commit: 'feat: initial scaffolding'."
683
+ CLAUDE.md is NOT in the mapit auto-loads into every subagent. Raw Phase 1 research is NOT in the map it is SPENT. The implementer reads refs on-demand using the Read tool; no full pastes."
380
684
 
381
- ### Step 4.2Design System (frontend only)
685
+ The Briefing Officer's output is the handoff payload for the implementer not for the orchestrator to re-paste.
382
686
 
383
- Call the Agent tool description: "Design system setup" — mode: "bypassPermissions" — prompt: "Implement the design system from the Visual Design Spec: [paste from docs/plans/visual-design-spec.md]. Create CSS tokens matching the spec's color system, typography scale, spacing system, shadow/elevation tokens, and base layout components. The living style guide from Phase 3 is the reference implementation — components must match. Commit: 'feat: design system'."
687
+ #### Implementer dispatch (subagent_type by task type)
384
688
 
385
- ### Step 4.2b Acceptance Test Scaffolding
689
+ Dispatch by task type and complexity:
690
+ - UI tasks: `subagent_type: engineering-frontend-developer` (S/M) or `subagent_type: engineering-senior-developer` (L)
691
+ - Backend tasks: `subagent_type: engineering-backend-architect` (L) or `subagent_type: engineering-senior-developer` (M)
692
+ - Hard / complex / cross-cutting tasks: `subagent_type: engineering-senior-developer`
386
693
 
387
- Call the Agent tool — description: "Scaffold acceptance tests" — mode: "bypassPermissions" — prompt: "Read docs/plans/sprint-tasks.md. For every task with a Behavioral Test field, create a Playwright test stub in tests/e2e/acceptance/. Use Page Object Model. Each test should: navigate to the page, perform the interaction, assert the expected outcome. Tests should FAIL right now (features aren't built yet) — that's correct. Also ensure agent-browser is available (run `which agent-browser`). Commit: 'test: scaffold acceptance tests from sprint tasks'."
694
+ Call the Agent tool — description: "[task-id] [task name]" — subagent_type per above — mode: "bypassPermissions" — prompt: "[CONTEXT header above] [COMPLEXITY: S/M/L from sprint-tasks.md]. TASK: [task description + acceptance criteria from sprint-tasks.md]. Sprint context is prepended; focus on this task.
388
695
 
389
- ### Step 4.3 — Metric Loop: Scaffold Health
696
+ ## Prior Learnings
697
+ [paste contents of `docs/plans/.active-learnings.md` if it exists, otherwise omit this section]
390
698
 
391
- Run the Metric Loop Protocol. Define a metric: builds clean, tests pass, lint clean, structure matches architecture. Max 3 iterations.
699
+ ## Deviation Reporting
700
+ If your implementation deviates from the planned architecture, return a `deviation_row` object per the schema in `protocols/decision-log.md`. If no deviation, return `deviation_row: null`. Do NOT write `decisions.jsonl` directly.
392
701
 
393
- ### Step 4.4 Verification Gate
702
+ Implement fully with real code and tests. Commit: 'feat: [task]'. Report what you built, files changed, and test results.
394
703
 
395
- Run the Verification Protocol (`protocols/verify.md`). Critical rules (survive compaction):
396
- - ONE agent runs all 6 checks sequentially: Build Type-Check Lint Test Security Diff Review. Stop on first FAIL.
397
- - Agent auto-detects stack from manifest files (package.json → Node, go.mod → Go, etc.).
398
- - On FAIL: for build/type/lint errors, use the Build-Fix Protocol (`protocols/build-fix.md`) — fixes one error at a time with cascade detection. For test/security/diff failures, spawn a targeted fix agent. Re-verify. Max 3 fix attempts.
399
- - On PASS: log `VERIFY: PASS (6/6)` to `docs/plans/.build-state.md`. Proceed.
704
+ ## On Re-entry (from LRR backward routing)
705
+ **[ORCHESTRATOR: Include the "On Re-entry" section below ONLY when this is a re-entry dispatch from LRR backward routing. For normal Phase 4 execution, OMIT it.]**
400
706
 
401
- Call the Agent tool description: "Verify scaffolding" mode: "bypassPermissions" prompt: "Run the Verification Protocol. Execute all 6 checks sequentially, stop on first failure. Report: VERIFY: PASS or VERIFY: FAIL with details."
707
+ If this dispatch is a re-entry (the orchestrator passes `blocking_finding`, `prior_output`, and `decision_row` in the prompt), DO NOT treat this as a fresh task. Read `prior_output` (the path to your previous task artifact under `.task-outputs/[task-id].json` + changed files) and `decision_row` (the original deviation rationale from decisions.jsonl). Revise ONLY what `blocking_finding` requires — do not redo unaffected code, do not re-run acceptance tests that already passed, do not touch files outside the blast radius of the finding. Return a fresh `deviation_row` in your result payload documenting the revision rationale (author=this task-id, type and summary describing the revision)."
402
708
 
403
- Do not proceed to Phase 5 until verification passes.
709
+ #### Per-task security review (auth/PII tasks only)
404
710
 
405
- Update TodoWrite and state.
711
+ FOR tasks touching auth, PII, secrets, or payment flows — add a per-task security review BEFORE Senior Dev cleanup:
406
712
 
407
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
713
+ Call the Agent tool — description: "Security review for [task-id]" — subagent_type: `security-reviewer` prompt: "[CONTEXT header above] Review changed files from [task-id] for security issues. Scope: auth logic, input validation, secrets handling, dependency hygiene, OWASP Top 10 for web (or iOS Keychain / ATS / data protection for iOS). Return blocking findings only — 80%+ confidence threshold. Files to review: [list from implementer's changeset]."
408
714
 
409
- ---
715
+ #### Senior Dev cleanup (simplifier + refactor-cleaner if TS)
716
+
717
+ Two-pass cleanup. Scope is sacred: ONLY files from the implementation changeset. Zero exceptions.
718
+
719
+ 1. Call the Agent tool — description: "Simplify [task-id]" — subagent_type: `code-simplifier` — mode: "bypassPermissions" — prompt: "[CONTEXT header above] Simplify changed files from [task-id]. Remove dead code, unused imports, redundant abstractions. Do NOT add features. Do NOT change architecture. Do NOT touch files outside the changeset. If simplification breaks acceptance criteria, revert and skip. Files: [list]."
720
+
721
+ 2. If TS/JS task: Call the Agent tool — description: "Refactor [task-id]" — subagent_type: `refactor-cleaner` — mode: "bypassPermissions" — prompt: "[CONTEXT header above] Run knip/depcheck/ts-prune on changed files from [task-id]. Remove orphaned exports, unused deps, dead files. Same scope rules as simplifier — changeset only. Files: [list]."
722
+
723
+ Skip cleanup if trivial (< 20 lines, single file).
724
+
725
+ #### Per-task code review (parallel pair)
726
+
727
+ Call the Agent tool 2 times in one message after Senior Dev cleanup:
728
+
729
+ 1. Description: "Code review for [task-id]" — subagent_type: `code-reviewer` — Prompt: "[CONTEXT header above] Review changed files from [task-id]. Report findings with 80%+ confidence threshold only — skip low-confidence nitpicks. Scope: changeset only. Acceptance criteria: [paste from task]. Files: [list]."
730
+
731
+ 2. Description: "Silent failure hunt for [task-id]" — subagent_type: `silent-failure-hunter` — Prompt: "[CONTEXT header above] Hunt silent failures in changed files from [task-id]. Targets: empty catch blocks, try/catch returning null, swallowed errors, unhandled promise rejections, assertions disabled in production. Files: [list]. Report blocking findings only."
732
+
733
+ #### Metric Loop (generator/critic) — authoritative behavioral check
734
+
735
+ Run the Metric Loop Protocol (callable service) on the task implementation. Define a metric based on the task's acceptance criteria. For UI-facing tasks, include behavioral verification per the mode-specific branch file (web: agent-browser; iOS: SwiftUI Preview captures). Max 5 iterations.
736
+
737
+ The metric loop's final measurement IS the authoritative behavioral verification for this task — no separate smoke-test dispatch. The critic's final score + pass/fail is what downstream steps consume.
738
+
739
+ Generator: same implementer agent re-invoked. Critic: measurement agent dispatched fresh. Never share context.
740
+
741
+ On target met: mark task complete. On stall: accept if score >= 60% of target (autonomous) or present to user (interactive).
742
+
743
+ #### Verify Service (static checks only)
410
744
 
411
- ## Phase 5: BuildMetric-Driven Dev Loops
745
+ Run the Verify Protocol (INTERNAL inline — "Verify scaffolding") after the metric loop exits. Verify now covers STATIC checks only: type-check, lint, build. Behavioral verification has already happened in the metric loop above verify consumes the metric loop's final pass/fail + score from `.build-state.json.metric_loop_scores[]` rather than re-running behavioral checks. If any static check FAILS, dispatch a fix agent with the error, re-verify. Max 3 fix attempts.
746
+
747
+ #### After each task completes
748
+
749
+ Update TodoWrite and `.build-state.json`. Write a compact summary to `docs/plans/.task-outputs/[task-id].json` with {files-changed, tests-passing, verify-status}.
750
+
751
+ **Writes:** source code, `docs/plans/.task-outputs/`. Deviation rows flow through the orchestrator's `scribe_decision` MCP calls below — implementers do NOT touch `decisions.jsonl`.
412
752
 
413
753
  <HARD-GATE>
414
- Before starting: Phase 2 must be approved, Phase 3 must produce docs/plans/visual-design-spec.md, Phase 4 must pass. You MUST call the Agent tool for EVERY task. No exceptions.
754
+ DECISIONS.JSONL ORCHESTRATOR-SCRIBE ONLY via `scribe_decision` MCP. Only the orchestrator may cause appends to `docs/plans/decisions.jsonl`, and it does so exclusively by invoking the `scribe_decision` MCP tool. Any dispatch prompt asking a subagent to write this file is a bug. The orchestrator itself MUST NOT Write or Edit the file directly. Subagents return `deviation_row` objects in their structured result; the orchestrator forwards them through the MCP, which owns ID allocation and atomic append.
415
755
  </HARD-GATE>
416
756
 
417
- Expand TodoWrite with each sprint task.
757
+ #### Orchestrator-scribe dispatch (route deviation rows through `scribe_decision` MCP)
418
758
 
419
- **For EACH task:**
759
+ Runs after every Phase 4 parallel batch returns (and anywhere else a subagent returns a `deviation_row`, including Phase 1 synthesis and Phase 2 architecture synthesis). The scribe MCP is the single writer for `docs/plans/decisions.jsonl`; the orchestrator is the single caller of the MCP.
420
760
 
421
- ### Step 5.1 Implement
761
+ 1. Walk `batch_results`. Collect every non-null `deviation_row` from each subagent return.
762
+ 2. For each row, invoke the `scribe_decision` MCP tool with the row's fields (`phase`, `category`/`type`, `summary`, `decided_by`/`author`, `impact_level`, `rationale`, `related_files`) per the MCP's documented schema. One MCP call per row.
763
+ 3. The MCP allocates the `decision_id` (`D-{N}-<seq>`), stamps `timestamp` (ISO-8601) and `status: "open"`, validates against `decisions.schema.json`, and atomically appends the line. The orchestrator MUST NOT Write or Edit `docs/plans/decisions.jsonl` directly, MUST NOT pre-compute decision IDs, and MUST NOT read or allocate `.build-state.json.decisions_next_id.P{N}` — ID allocation is the MCP's responsibility.
764
+ 4. Regenerate `.build-state.md` after the batch completes so the rendered view reflects the newly appended rows.
422
765
 
423
- Call the Agent tool description: "[task name]" mode: "bypassPermissions" prompt: "TASK: [task description + acceptance criteria]. HANDOFF Architecture section: [paste ONLY the relevant section from architecture.md]. Design section: [paste ONLY the relevant section from the design doc]. Previous task output: [what the last completed task produced, if relevant]. For UI tasks: the living style guide at /design-system shows every component's exact styling and states match it. Implement fully with real code and tests. Commit: 'feat: [task]'. Report what you built, files changed, and test results."
766
+ **On resume:** the scribe MCP reconstructs its ID allocator internally on first invocation by scanning `docs/plans/decisions.jsonl` (for each phase `N`, `max(seq)+1` across rows whose `decision_id` matches `D-{N}-<seq>`). The orchestrator no longer maintains `decisions_next_id` in `.build-state.json`; the field is effectively deprecated under Stage 2 (scribe owns ID allocation end-to-end) and is scheduled for formal removal in Stage 4 schema bump A7 (see Task 4.5.1 in `docs/migration/sdk-hybrid/TASK-BREAKDOWN.md`). TODO(stage-4-A7): drop `decisions_next_id` from the state schema.
424
767
 
425
- Pick the right developer framing: frontend, backend, AI, etc. Set `[COMPLEXITY: S/M/L]` based on the task's Size from sprint-tasks.md.
768
+ <HARD-GATE>
769
+ LRR NEEDS_WORK backward edge: `LRR NEEDS_WORK (code-level) → back to Phase 4 target task`. The Aggregator classifies the finding and routes to the specific task via `related_decision_id` lookup; Phase 4 re-opens that task with the finding as input.
770
+ </HARD-GATE>
426
771
 
427
- ### Step 5.1b Cleanup (De-Sloppify)
772
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
428
773
 
429
- Follow the Cleanup Protocol (`protocols/cleanup.md`). Critical rules (survive compaction):
430
- [COMPLEXITY: S]
431
- - Skip if trivial (< 20 lines, single file).
432
- - Cleanup agent is a SEPARATE agent from the implementer — no cleaning your own mess.
433
- - Scope is sacred: ONLY files from the implementation changeset. Zero exceptions.
434
- - Cleanup fixes: naming, dead code, unused imports, style, DRY. Does NOT: add features, change architecture, touch other files.
435
- - If cleanup breaks acceptance criteria, revert and skip. Never block the metric loop on cleanup failure.
774
+ ---
436
775
 
437
- Call the Agent tool — description: "Cleanup [task name]" mode: "bypassPermissions" with the list of files changed and the task's acceptance criteria.
776
+ ## Phase 5: AuditTEAM of 6 + eval harness + 3 parallel + feedback synth
438
777
 
439
- ### Step 5.2 — Metric Loop: Task Quality
778
+ <HARD-GATE>
779
+ Before starting Phase 5: run the Verify Protocol (7 checks) one more time. All checks must pass before expensive audit agents fire.
780
+ </HARD-GATE>
440
781
 
441
- Run the Metric Loop Protocol on the task implementation. Define a metric based on the task's acceptance criteria. For UI-facing tasks, include behavioral verification: the measurement agent should use agent-browser to verify the feature renders and responds to interaction, not just read the code. Max 5 iterations.
782
+ **Goal**: Surface quality issues before Launch Review. Split from old Phase 6 old 6.1-6.3 (5-agent audit, eval harness, E2E + dogfood + fake-data) live here. Old 6.4-6.5 (Reality Check + LRR) move to Phase 6.
442
783
 
443
- ### Step 5.3 — Loop Exit
784
+ **Mode-specific branch:**
785
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 5 (iOS twin commands: `/buildanything:verify` → `/buildanything:ux-review` → `/buildanything:fix` in sequence; Maestro smoke tests). Skip the web TEAM below and jump to Step 5.4 Feedback Synthesizer with iOS evidence.
786
+ - `project_type=web`: continue below.
444
787
 
445
- On target met: mark task complete in TodoWrite, report "Task X/N: [name] — COMPLETE (score: [final], iterations: [count])".
788
+ ### Step 5.1 TEAM of 6 parallel auditors (ONE message)
446
789
 
447
- On stall or max iterations:
448
- - **Interactive:** present score history + top remaining issue to user.
449
- - **Autonomous:** accept if score >= 60% of target, skip otherwise. Log to `docs/plans/build-log.md`.
790
+ Read the NFRs from `docs/plans/quality-targets.json`. Pass the relevant targets to each audit agent so they have concrete thresholds, not generic checks.
450
791
 
451
- After each task: update TodoWrite and `docs/plans/.build-state.md`.
792
+ **CONTEXT header:** Render `rendered_context_header` for phase 5 per the canonical template (see CONTEXT HEADER HARD-GATE above). Prepend to every Phase 5 prompt below.
452
793
 
453
- ### Step 5.3b Behavioral Smoke Test
794
+ Call the Agent tool 6 times in one message:
454
795
 
455
- Skip if this task has no Behavioral Test criteria (API-only, config, infrastructure tasks).
796
+ 1. Description: "API testing" subagent_type: `testing-api-tester` Prompt: "[CONTEXT header above] Comprehensive API validation: all endpoints, edge cases, error responses, auth flows. NFR targets: Read `docs/plans/quality-targets.json` via your Read tool for performance and reliability thresholds. Report findings with severity counts."
456
797
 
457
- Run the Smoke Test Protocol (`protocols/smoke-test.md`). This uses agent-browser to open the app, execute the task's behavioral acceptance criteria, and verify the feature actually works.
798
+ 2. Description: "Performance audit" subagent_type: `testing-performance-benchmarker` — Prompt: "[CONTEXT header above] Measure response times, identify bottlenecks, flag performance issues. NFR targets: Read `docs/plans/quality-targets.json` via your Read tool for performance thresholds. Bundle size per-Scope budgets apply (Marketing 500KB / Product 300KB / Dashboard 400KB / Internal 200KB gzipped). Report benchmarks AGAINST these targets, not generic metrics."
458
799
 
459
- Evidence saved to `docs/plans/evidence/[task-name]/`: annotated screenshot, snapshot diff, error log, network log, HAR file.
800
+ 3. Description: "A11y audit" — subagent_type: `a11y-architect` — Prompt: "[CONTEXT header above] WCAG 2.2 AA runtime compliance audit on all interfaces. Check screen reader, keyboard nav, contrast, focus order, touch targets (>=44px), reduced-motion variants. Report issues with severity (Critical/Serious/Moderate/Minor)."
460
801
 
461
- On FAIL: spawn fix agent with the evidence. The fix agent receives: what was expected (from acceptance criteria), what actually happened (snapshot diff + errors + screenshot), and the relevant source files. Max 2 fix-and-retest cycles.
802
+ 4. Description: "Security audit" subagent_type: `engineering-security-engineer` Prompt: "[CONTEXT header above] Security review at app level: auth, input validation, data exposure, dependency vulnerabilities. NFR targets: Read `docs/plans/quality-targets.json` via your Read tool for security thresholds. Report findings with severity."
462
803
 
463
- On PASS: proceed to Step 5.4.
804
+ 5. Description: "UX quality audit" — subagent_type: `design-ux-researcher` — Prompt: "[CONTEXT header above] UX quality review of every user-facing page. First, screenshot the living style guide at /design-system (web) as your reference. Then review every product page: loading states (every async action shows a loading indicator), error states (every form and API call shows user-friendly feedback), empty states (lists/tables handle zero items), mobile responsiveness (test at 375px — touch targets >= 44px, no horizontal scroll), form validation (inline feedback, not alert()), transition smoothness, visual consistency vs style guide (buttons, inputs, cards, colors, spacing should match). Report issues with page, severity, and screenshot."
464
805
 
465
- ### Step 5.4 Post-Task Verification
806
+ 6. Description: "Brand Guardian drift check" — subagent_type: `design-brand-guardian` — Prompt: "[CONTEXT header above] You are the Phase 5 drift check. Read docs/plans/visual-dna.md (the DNA card locked at Phase 3.0) + the actually-built pages via Playwright screenshots under docs/plans/evidence/. Score whether Phase 4 implementers stayed true to the DNA or drifted away from it. Specifically check: does the built Character axis match the DNA? Does Density match? Is Material consistent? Is Motion aligned? Report drift count and specific elements. Save findings to docs/plans/evidence/brand-drift.md. Note: this is a drift check only — the Phase 6 LRR Brand Guardian chapter does the verdict. You do NOT issue a pass/fail here, only surface findings."
466
807
 
467
- Run the Verification Protocol (`protocols/verify.md`). If FAIL, fix before starting the next task.
808
+ ### Step 5.2 Sequence: Eval Harness Metric Loop
468
809
 
469
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
810
+ Run the Eval Harness Protocol (`protocols/eval-harness.md`). Define 8-15 concrete, executable eval cases from the audit findings and architecture doc. Run the eval agent. Record baseline pass rate. CRITICAL and HIGH failures feed into the Metric Loop as specific issues to fix.
470
811
 
471
- ---
812
+ Run the Metric Loop Protocol (callable service) on the full codebase using audit findings as initial input. Define a composite metric based on what this project needs. Max 4 iterations. When fixing, dispatch to the RIGHT specialist — security → `security-reviewer`, a11y → `engineering-frontend-developer`, perf → `testing-performance-benchmarker`. Don't send everything to one agent.
472
813
 
473
- ## Phase 6: Harden Metric-Driven Hardening
814
+ Re-run the Eval Harness after the metric loop exits. All CRITICAL eval cases must now pass. If any CRITICAL case still fails, include it as evidence for Phase 6.
474
815
 
475
- ### Step 6.0Pre-Hardening Verification
816
+ ### Step 5.3TEAM of 3 parallel (ONE message)
476
817
 
477
- Run the Verification Protocol (`protocols/verify.md`). All checks must pass before starting expensive audit agents.
818
+ Call the Agent tool 3 times in one message:
478
819
 
479
- ### Step 6.1Initial Audit (5 agents in parallel, ONE message)
820
+ 1. Description: "E2E runner" INTERNAL inline role-string — mode: "bypassPermissions" — Prompt: "Run Playwright E2E test generation, execution, and stability check per `protocols/web-phase-branches.md` Phase 5 E2E steps (generate and run E2E tests for User Journeys, 3 mandatory iterations for flakiness detection). Report results + artifact paths. Records results to `docs/plans/evidence/e2e/iter-3-results.json`."
480
821
 
481
- Read the NFRs from `docs/plans/sprint-tasks.md`. Pass the relevant NFR thresholds to each audit agent so they have concrete targets, not generic checks.
822
+ 2. Description: "Dogfood the app" INTERNAL inline role-string + agent-browser skill — mode: "bypassPermissions" — Prompt: "You are the Dogfood runner. Run the agent-browser dogfood skill against the running app at http://localhost:[port]. Explore every reachable page. Click every button. Fill every form. Check console for errors. Report a structured list of issues with severity ratings, screenshots, repro steps. Write findings to `docs/plans/evidence/dogfood/findings.md`. Do NOT classify or route findings that's the Feedback Synthesizer's job at Step 5.4."
482
823
 
483
- Call the Agent tool 5 times in one message:
824
+ 3. Description: "Fake-data detector" — INTERNAL inline role-string — mode: "bypassPermissions" — Prompt: "Run the Fake Data Detector Protocol (`protocols/fake-data-detector.md`). Static analysis: grep for Math.random() in business data paths, hardcoded API responses, setTimeout faking async, placeholder text. Dynamic analysis: inspect HAR files from `docs/plans/evidence/` for missing real API calls, static responses, absent WebSocket traffic. Write findings to `docs/plans/evidence/fake-data-audit.md` with file:line refs and severity."
484
825
 
485
- 1. Description: "API testing" Prompt: "Comprehensive API validation: all endpoints, edge cases, error responses, auth flows. NFR targets: [paste performance and reliability NFRs]. Report findings with counts."
826
+ ### Step 5.4Feedback Synthesizer
486
827
 
487
- 2. Description: "Performance audit" Prompt: "Measure response times, identify bottlenecks, flag performance issues. NFR targets: [paste performance NFRs — e.g., API < 200ms, page load < 3s]. Report benchmarks AGAINST these targets."
828
+ The Dogfood findings used to dead-end. Now route them to fix loops.
488
829
 
489
- 3. Description: "Accessibility audit"Prompt: "WCAG compliance audit on all interfaces. NFR target: [paste accessibility NFR e.g., WCAG AA]. Check screen reader, keyboard nav, contrast. Report issues with counts."
830
+ Call the Agent tooldescription: "Synthesize dogfood findings" subagent_type: `product-feedback-synthesizer` Prompt: "[CONTEXT header above] Interpret Dogfood output. Input: `docs/plans/evidence/dogfood/findings.md`. For each finding, classify it and assign a target phase for the fix:
831
+ - Code-level bug (broken feature, failing logic, fake data) → `target_phase: 4`, assign to the specific task that owns the affected file
832
+ - Visual/design issue (styling drift, missing state, a11y gap) → `target_phase: 3`, assign to the Phase 3 step that owns the relevant artifact
833
+ - Structural/architecture issue (missing feature, wrong data flow, API mismatch) → `target_phase: 2`, assign to the architecture section
490
834
 
491
- 4. Description: "Security audit" Prompt: "Security review: auth, input validation, data exposure, dependency vulnerabilities. NFR targets: [paste security NFRs]. Report findings with severity."
835
+ Output: `docs/plans/evidence/dogfood/classified-findings.json` with shape `[{finding_id, severity, target_phase, target_task_or_step, description, evidence_ref}, ...]`. This file is read by the Phase 5 fix loop and by the Phase 6 LRR Aggregator for backward routing."
492
836
 
493
- 5. Description: "UX quality audit" — Prompt: "UX quality review of every user-facing page. NFR targets: [paste accessibility NFRs]. First, screenshot the living style guide at /design-system as your reference for how components should look. Then review every product page and check: loading states (every async action must show a loading indicator), error states (every form and API call must show user-friendly error feedback), empty states (every list/table must handle zero items gracefully), mobile responsiveness (test at 375px viewport — touch targets >= 44px, no horizontal scroll, readable text), form validation (inline feedback, not just alert()), transition smoothness (no layout shifts, no janky animations), visual consistency (compare each page's components against the style guide buttons, inputs, cards, colors, spacing should match). Report issues with page, severity, and screenshot."
837
+ **Phase 5 fix loop:** For each CRITICAL/HIGH classified finding, dispatch the appropriate fix agent based on `target_phase`. Max 2 fix cycles.
494
838
 
495
- ### Step 6.1bEval Harness
839
+ **Writes:** `docs/plans/evidence/*.json`, `docs/plans/evidence/fake-data-audit.md`, `docs/plans/evidence/dogfood/classified-findings.json`, `docs/plans/learnings.jsonl` (reality sweep writes PITFALL/PATTERN rows see `protocols/decision-log.md` for the Dissent Log Revisit Pass path).
496
840
 
497
- Run the Eval Harness Protocol (`protocols/eval-harness.md`). Define 8-15 concrete, executable eval cases from the audit findings and architecture doc. For UI flows, eval cases should use agent-browser: "agent-browser open /dashboard -> agent-browser click @submit -> agent-browser wait --text Success -> expect text contains confirmation ID". Run the eval agent. Record baseline pass rate. CRITICAL and HIGH failures feed into the metric loop in Step 6.2 as specific issues to fix.
841
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
498
842
 
499
- ### Step 6.2 — Metric Loop: Hardening Quality
843
+ ---
500
844
 
501
- Run the Metric Loop Protocol on the full codebase using audit findings as initial input. Define a composite metric based on what this project needs. Max 4 iterations.
845
+ ## Phase 6: Launch Readiness Review
502
846
 
503
- When fixing, dispatch to the RIGHT specialist. Security security agent. Accessibility frontend agent. Don't send everything to one agent.
847
+ **Goal**: 5 independent chapter judges + mechanical aggregator with file-completeness checkpoint + author-aware backward routing on BLOCK.
504
848
 
505
- ### Step 6.2bEval Re-run
849
+ Split from old Phase 6. Old 6.4 (Reality Check) and 6.5 (LRR) merged and restructured. Reality Checker keeps its evidence sweep role only the combined verdict authority moved to the LRR Aggregator.
506
850
 
507
- Re-run the Eval Harness after the metric loop exits. All CRITICAL eval cases must now pass. If any CRITICAL case still fails, include it as evidence for the Reality Checker.
851
+ ### Step 6.0 Reality Check (evidence sweep + dissent log revisit pass)
508
852
 
509
- ### Step 6.2c E2E Testing (3 mandatory iterations)
853
+ Reality Checker runs its existing evidence sweep per `commands/build.md` precondition list. Writes the manifest to `docs/plans/evidence/reality-check-manifest.json`. Does NOT issue a combined verdict.
510
854
 
511
855
  <HARD-GATE>
512
- ALL 3 ITERATIONS ARE MANDATORY. Do NOT stop after iteration 1 even if all tests pass. The purpose of 3 runs is to catch flaky tests, timing-dependent failures, and race conditions that only surface on repeated execution. Skip this step ONLY if the project has no user-facing frontend.
856
+ PRECONDITION (orchestrator-side, BEFORE dispatching Reality Checker):
857
+
858
+ REQUIRED EVIDENCE FOR ALL PROJECTS:
859
+ - `docs/plans/.build-state.json` exists, contains current build session id, contains a recent `VERIFY: PASS` line from this session.
860
+
861
+ REQUIRED EVIDENCE FOR `project_type=web`:
862
+ - `docs/plans/evidence/eval-harness/baseline.json` (non-empty)
863
+ - `docs/plans/evidence/eval-harness/final.json` (non-empty)
864
+ - `docs/plans/evidence/e2e/iter-3-results.json` (non-empty)
865
+ - `docs/plans/evidence/dogfood/findings.md` (non-empty)
866
+ - `docs/plans/evidence/dogfood/classified-findings.json` (non-empty)
867
+ - `docs/plans/evidence/fake-data-audit.md` (non-empty)
868
+ - `docs/plans/evidence/manifest.json`
869
+
870
+ REQUIRED EVIDENCE FOR `project_type=ios`:
871
+ - `docs/plans/ios-verify-report.md` (non-empty)
872
+ - `docs/plans/ios-ux-review-report.md` (non-empty)
873
+ - At least one `*.yaml` file in `maestro/`
874
+ - At least one `*.png` screenshot in `docs/plans/evidence/maestro-runs/` from this build session
875
+ - `docs/plans/evidence/manifest.json`
876
+
877
+ If any required file does not exist or is empty, do NOT dispatch Reality Checker. Log "REALITY CHECK BLOCKED" with missing-file list. Interactive: present blocker to user. Autonomous: return to the failing step and re-dispatch once; if still missing, abort.
513
878
  </HARD-GATE>
514
879
 
515
- Generate and execute end-to-end tests using Playwright against the running application. Tests cover the **User Journeys** defined in `docs/plans/sprint-tasks.md` (Step 0 of the Planning Protocol). Each journey = one E2E test file.
880
+ **CONTEXT header:** Render `rendered_context_header` for phase 6 per the canonical template (see CONTEXT HEADER HARD-GATE above). Prepend to every Phase 6 prompt below (Reality Checker + the 5 LRR chapters).
516
881
 
517
- **Iteration 1Generate & Run:**
882
+ Call the Agent tool description: "Evidence sweep" — subagent_type: `testing-reality-checker` — Prompt: "[CONTEXT header above] You are the Reality Checker — evidence-sweep role only. Default verdict: NONE. You receive evidence by FILE PATH only — never by paste. Use Read and Glob tools to verify each file exists, is non-empty, was modified within this build session, contains no placeholder strings ('TODO', 'PLACEHOLDER', 'TBD', 'FIXME', 'XXX').
518
883
 
519
- Call the Agent tool — description: "E2E test generation" mode: "bypassPermissions" — prompt:
884
+ Evidence paths to verify: [orchestrator pastes the precondition list per project_type].
520
885
 
521
- "[COMPLEXITY: L] Generate and run end-to-end Playwright tests for this application.
886
+ For every Behavioral Test field in `docs/plans/sprint-tasks.md`, verify a corresponding evidence file exists in `docs/plans/evidence/[task-slug]/` AND that the test-stub-detector (per `protocols/verify.md` Step 2) does not flag the corresponding test file as a stub.
522
887
 
523
- INPUTS:
524
- - User Journeys from docs/plans/sprint-tasks.md: [paste the User Journeys section — each journey becomes one E2E test]
525
- - Architecture doc (API contracts): [paste relevant sections from docs/plans/architecture.md]
526
- - NFRs from docs/plans/sprint-tasks.md: [paste — use performance thresholds as test assertions]
527
- - Visual Design Spec (component selectors): [paste relevant sections from docs/plans/visual-design-spec.md]
888
+ For every architecture MUST in `docs/plans/architecture.md`, verify the implementation file exists via Glob AND contains the named symbol via Grep.
528
889
 
529
- REQUIREMENTS:
530
- 1. One E2E test per User Journey from sprint-tasks.md (each journey = one test file covering the full flow)
531
- 2. Use Page Object Model patternone page object per major view
532
- 3. Use data-testid selectors (add them to components if missing)
533
- 4. Wait for API responses, NEVER use arbitrary timeouts (no waitForTimeout)
534
- 5. Capture screenshots at critical verification points
535
- 6. Configure multi-browser: Chromium + Firefox + WebKit
536
- 7. Set up playwright.config.ts with: fullyParallel, retries: 0 (we handle retries ourselves), screenshot: 'only-on-failure', video: 'retain-on-failure', trace: 'on-first-retry'
537
- 8. Run all tests. Report: total, passed, failed, with failure details and screenshot paths.
538
- 9. Commit: 'test: e2e test suite for critical user journeys'
890
+ **Dissent Log Revisit Pass:** Read `docs/plans/decisions.jsonl`. For every row where `status == \"open\"` and `revisit_criterion` is non-empty, semantically evaluate the criterion against current evidence. If triggered:
891
+ 1. Emit a structural finding in the manifest: `revisit-criterion-triggered: D-N-M [criterion]`
892
+ 2. Append a PITFALL row to `docs/plans/learnings.jsonl` with `{pattern_type: \"PITFALL\", top_issue: \"[decision] [criterion]\", fix_applied: \"[what build did instead]\", provenance: {decision_id: \"D-N-M\"}}`
893
+ 3. Flag the triggered decision this feeds LRR as a potential cross-chapter concern
539
894
 
540
- Test priority:
541
- - CRITICAL: Auth, core feature happy path, data submission, payment/transaction flows
542
- - HIGH: Search, filtering, navigation, error states
543
- - MEDIUM: Responsive layout, animations, edge cases"
895
+ Write the evidence manifest to `docs/plans/evidence/reality-check-manifest.json` with fields `{file_path, sha256, byte_count, modified_time, verdict_contribution}` per file. Emit any structural findings surfaced during the sweep. DO NOT issue a combined verdict — that authority moved to the LRR Aggregator at Step 6.1 below."
544
896
 
545
- Record results: total tests, pass count, fail count, failure details. Log to `docs/plans/.build-state.md` under `## E2E Testing`:
897
+ ### Step 6.1 LRR: 5 chapter judges in parallel (ONE message)
546
898
 
547
- ```
548
- | Iter | Total | Passed | Failed | Flaky | Top Failure |
549
- |------|-------|--------|--------|-------|-------------|
550
- | 1 | ... | ... | ... | ... | ... |
551
- ```
899
+ Follow the Launch Readiness Review Protocol (`protocols/launch-readiness.md`). The net-5 panel: Eng-Quality (merged Eng+QA with PM chapter folded in), Security, SRE (includes Performance), A11y (NEW SEAT), Brand Guardian (REPLACES old Design mechanical check).
552
900
 
553
- **Iteration 2 Fix & Re-run:**
901
+ Dispatch 5 chapter judges in parallel. Each receives fresh context, its own evidence slice, and the chapter verdict schema from `protocols/launch-readiness.md`.
554
902
 
555
- Call the Agent tool description: "E2E fix iteration 2" — mode: "bypassPermissions" prompt: "[COMPLEXITY: M] Fix E2E test failures from iteration 1: [paste failure details — test names, error messages, screenshot paths]. Diagnose each as real bug, flaky test, or missing selector. Fix accordingly do NOT delete or skip tests. Re-run ALL tests. Commit: 'fix: e2e test failures iteration 2'."
903
+ Call the Agent tool 5 times in ONE message. Note: the Eng-Quality chapter dispatches `code-reviewer` as primary, with a parallel `pr-test-analyzer` sub-dispatch for test-coverage adequacy evidence that feeds into the Eng-Quality verdict file.
556
904
 
557
- Record results in the E2E table. Identify flaky candidates (passed iter 1, failed iter 2 or vice versa).
905
+ 1. Description: "LRR Eng-Quality chapter" — subagent_type: `code-reviewer` — Prompt: "[CONTEXT header above] You are the Eng-Quality chapter of the Launch Readiness Review. Your natural tendency is to be encouraging. Fight it. Default verdict: NEEDS WORK.
558
906
 
559
- **Iteration 3Final Stability Run:**
907
+ Read: `docs/plans/architecture.md`, `docs/plans/design-doc.md` (PRD needed for requirements coverage evaluation), `docs/plans/sprint-tasks.md`, `docs/plans/.task-outputs/`, `protocols/verify.md` check outputs from `.build-state.json`, test results from Phase 4 and 5, eval-harness results from `docs/plans/evidence/eval-harness/`. Also read `docs/plans/decisions.jsonl` for cross-chapter context.
560
908
 
561
- Call the Agent tooldescription: "E2E stability run" mode: "bypassPermissions" prompt: "[COMPLEXITY: M] Final E2E stability run (3 of 3). Previous results Iter 1: [pass/fail counts], Iter 2: [pass/fail counts], Flaky candidates: [list]. Run ALL tests with --repeat-each=3. Quarantine inconsistent tests with test.fixme(). Fix remaining consistent failures. PASS CRITERIA: 95%+ pass rate (quarantined flaky tests excluded but logged). Commit: 'test: e2e stability fixes iteration 3'."
909
+ Requirements coverage is folded into this chapter not a separate dispatch. For EVERY feature listed in the MVP scope of `design-doc.md`, evaluate: (1) does it have a corresponding implemented task in sprint-tasks.md, (2) does it have a passing test or behavioral verification in evidence, (3) is it reachable and functional per the task-outputs. Emit a `requirements_coverage` field in your verdict JSON with shape `[{feature: \"<name>\", status: \"COVERED\" | \"PARTIAL\" | \"MISSING\"}, ...]`. Any MISSING feature is a BLOCK finding. Any PARTIAL feature is a CONCERNS finding at minimum.
562
910
 
563
- Record final results. Include in Reality Checker evidence.
911
+ Before writing the final verdict, spawn a parallel subagent dispatch: description: 'LRR test coverage adequacy' — subagent_type: `pr-test-analyzer` — prompt: 'You are a test-coverage auditor for the Eng-Quality LRR chapter. Read the test files under tests/, task-outputs/, and behavioral-test stub detector output. Evaluate: (1) do declared behavioral tests have non-stub bodies, (2) does coverage match the PR diff scope, (3) are edge cases covered, (4) are any tests flaky markers set. Return a JSON summary with test_coverage_score (0-100), stub_flagged_count, edge_case_gap_count, recommendations[]. Save to docs/plans/evidence/lrr/eng-quality-coverage.json.' Read the resulting eng-quality-coverage.json and fold its findings into your verdict.
564
912
 
565
- ### Step 6.2dAutonomous Dogfooding
913
+ Evaluate code quality + test coverage adequacy + architecture conformance + requirements coverage TOGETHER (single coherent view merged from old Eng + QA chapters). Check: do declared behavioral tests actually exercise the features? Are there stub-flagged tests? Do tests match task acceptance criteria? Does the built code match architecture MUSTs? Are MVP features all COVERED?
566
914
 
567
- Run the agent-browser dogfood skill against the running app. Unlike the per-task smoke tests (which verify specific acceptance criteria), dogfooding is **exploratory** it autonomously navigates every reachable page, clicks buttons, fills forms, checks console errors, and finds issues we didn't think to test.
915
+ Write verdict to `docs/plans/evidence/lrr/eng-quality.json` per `protocols/launch-readiness.md` schema. Fields: `chapter=eng-quality`, `verdict` (PASS|CONCERNS|BLOCK), `override_blocks_launch` (false unless BLOCK), `evidence_files_read` (non-empty, MUST include eng-quality-coverage.json), `findings[]` (each with `severity`, `description`, `evidence_ref`, `related_decision_id` if blocker ties to a decisions.jsonl row), `requirements_coverage[]` (one entry per MVP feature with `{feature, status}`), `follow_up_spawned=false`, `follow_up_findings=null`. Eng-Quality CANNOT spawn follow-ups."
568
916
 
569
- Start the dev server if not running. Then invoke the dogfood skill:
917
+ 2. Description: "LRR Security chapter" — subagent_type: `security-reviewer` — Prompt: "[CONTEXT header above] You are the Security chapter of the LRR. Read: `docs/plans/evidence/fake-data-audit.md`, Phase 5 security audit output (from Step 5.1), eval-harness security cases. Also read `docs/plans/decisions.jsonl` for context.
570
918
 
571
- Call the Agent tool description: "Dogfood the app" — mode: "bypassPermissions" — prompt: "Run the agent-browser dogfood skill against the running app at http://localhost:[port]. Explore every reachable page. Click every button. Fill every form. Check console for errors. Report a structured list of issues with severity ratings (critical/high/medium/low), screenshots, and repro steps. If dogfood skill is not available, use agent-browser manually: snapshot each page, click all interactive elements, check errors and network requests. Also evaluate UX quality: missing loading states, poor error messages, broken mobile layouts (resize to 375px), visual inconsistencies, missing empty states, form validation gaps. Report UX issues separately from functional issues."
919
+ Evaluate auth model, input validation, secrets management, dependency vulnerabilities. Write verdict to `docs/plans/evidence/lrr/security.json` per schema. Fields: `chapter=security`, `verdict`, `override_blocks_launch`, `evidence_files_read` (non-empty), `findings[]` (with `related_decision_id` when applicable), `follow_up_spawned` (boolean), `follow_up_findings` (null or typed object).
572
920
 
573
- **Fix loop:** For each CRITICAL or HIGH issue found:
574
- 1. Classify: is this a code bug (fix in Phase 5 style — spawn implementation fix agent) or a structural problem (needs architecture change — spawn architect agent to propose a fix plan, then implementation agent to execute)?
575
- 2. Spawn the appropriate fix agent with: the issue description, repro steps, screenshot, affected page/component.
576
- 3. After fixes, re-run dogfood on the affected pages only (not the full app). If new CRITICAL/HIGH issues appear, repeat. Max 3 fix cycles.
921
+ Security MAY spawn ONE read-only follow-up investigation, but ONLY if verdict would be BLOCK — NOT on suspicion. This is tightened from current behavior. Follow-up: read-only, Read/Grep/Glob only, max 15 tool calls, self-report tool_calls_used. See `protocols/launch-readiness.md` for follow-up flow."
577
922
 
578
- MEDIUM/LOW issues: log to `docs/plans/build-log.md` for the Reality Checker.
923
+ 3. Description: "LRR SRE chapter" — subagent_type: `engineering-sre` — Prompt: "[CONTEXT header above] You are the SRE chapter of the LRR. Read: performance-audit outputs from Phase 5 (Step 5.1 performance auditor + Step 5.2 eval-harness perf cases), Performance Benchmarker evidence, NFRs from `docs/plans/quality-targets.json` and `docs/plans/sprint-tasks.md`, reliability checks. Also read `docs/plans/decisions.jsonl` for context.
579
924
 
580
- ### Step 6.2e Fake Data Detector
925
+ Evaluate whether the build meets NFR targets (response time, load handling, error rates) and is production-ready under load. Bundle-size budget violations (>25% over Scope budget) auto-block. Write verdict to `docs/plans/evidence/lrr/sre.json` per schema.
581
926
 
582
- Call the Agent tool description: "Fake data audit" — mode: "bypassPermissions" — prompt: "Run the Fake Data Detector Protocol (protocols/fake-data-detector.md). Check for mock/hardcoded data in production paths. Static analysis: grep for Math.random() business data, hardcoded API responses, setTimeout faking async, placeholder text. Dynamic analysis: inspect HAR files from docs/plans/evidence/ for missing real API calls, static responses, absent WebSocket traffic. Report findings with file:line references and severity."
927
+ SRE MAY spawn ONE read-only follow-up investigation, but ONLY if verdict would be BLOCK. Same caps as Security."
583
928
 
584
- **Fix loop:** For each CRITICAL finding:
585
- 1. Spawn a fix agent with: the finding (file:line, what's fake, what it should be), and the relevant source files.
586
- 2. The fix agent replaces fake data with real API calls, real WebSocket connections, real data sources. If real data sources aren't available (missing API keys, no backend), the fix agent must flag this as a blocker — not paper over it with better-looking fake data.
587
- 3. After fixes, re-run the fake data detector (static checks only — fast). Max 2 fix cycles.
929
+ 4. Description: "LRR A11y chapter" — subagent_type: `a11y-architect` — Prompt: "[CONTEXT header above] You are the A11y chapter of the LRR (NEW SEAT in this panel — closes the biggest coverage gap). Read: Phase 5 a11y audit output (from Step 5.1), WCAG 2.2 AA runtime check, per-page accessibility findings, `docs/plans/quality-targets.json` a11y section.
588
930
 
589
- Remaining findings feed into the Reality Checker in Step 6.4.
931
+ Scoring rules:
932
+ - PASS if zero Serious + zero Critical findings
933
+ - CONCERNS if 1-3 Serious + 0 Critical
934
+ - BLOCK if any Critical OR >3 Serious
590
935
 
591
- ### Step 6.4 Reality Check
936
+ Write verdict to `docs/plans/evidence/lrr/a11y.json` per schema. A11y CANNOT spawn follow-ups."
592
937
 
593
- Call the Agent tool description: "Final verdict" prompt: "You are the Reality Checker. Default: NEEDS WORK. The hardening loop reached score [final_score] after [iterations] iterations. Score history: [paste table]. Review all evidence. Eval harness results: [baseline pass rate] [final pass rate]. E2E test results: [paste E2E table — 3 iterations, final pass rate, quarantined count]. Dogfood results: [paste issue count and any CRITICAL/HIGH findings, or 'clean — no issues found']. Fake data audit results: [paste findings or 'clean — no fake data detected']. CRITICAL failures remaining: [list or none]. Verdict: PRODUCTION READY or NEEDS WORK with specifics."
938
+ 5. Description: "LRR Brand Guardian chapter" — subagent_type: `design-brand-guardian` Prompt: "[CONTEXT header above] You are the Brand Guardian chapter of the LRR (REPLACES the old Design mechanical check real taste judgment, not a 15-line mechanical gate). Your natural tendency is to be encouraging. Fight it. Default verdict: NEEDS WORK.
594
939
 
595
- <HARD-GATE>Do NOT self-approve. Reality Checker must give the verdict.</HARD-GATE>
940
+ Read: `docs/plans/visual-design-spec.md`, `docs/plans/visual-dna.md` (the 6-axis DNA card locked at Phase 3.0), `docs/plans/design-references.md`, Playwright screenshots under `docs/plans/evidence/` matching production pages, Phase 3.6 Design Critic final score from `.build-state.json`.
596
941
 
597
- **On PRODUCTION READY:** Log verdict. Proceed to Phase 7.
942
+ Evaluate DRIFT: did the built product stay true to the DNA card locked at Phase 3.0? Score the gap on 6 DNA axes (Scope, Density, Character, Material, Motion, Type) + 5 craft dimensions (whitespace rhythm, visual hierarchy, motion coherence, color harmony, typographic refinement). Cite specific elements ('the hero padding at landing.tsx:42 is 32px but DNA calls for Airy density — should be 48px+') — never vague ('needs polish').
598
943
 
599
- **On NEEDS WORK:** The Reality Checker returns specific issues. These must be fixed — not logged and ignored.
944
+ Write verdict to `docs/plans/evidence/lrr/brand-guardian.json` per schema. Fields per protocol. Brand Guardian CANNOT spawn follow-ups."
600
945
 
601
- 1. Read the Reality Checker's specific findings. Classify each:
602
- - **Code bug** (broken feature, failing test, fake data) → spawn implementation fix agent with the finding + affected files.
603
- - **Structural issue** (missing feature, wrong architecture, data flow problem) → spawn architect agent to produce a fix plan, then implementation agent to execute it. This is a mini Phase 5 loop for the specific issue.
604
- - **Blocker** (missing API key, no backend, needs human action) → log to `docs/plans/build-log.md` and present to user. Cannot be auto-fixed.
605
- 2. After fixes, re-run verification (7 checks) + the specific failing gate (E2E, dogfood, or fake data — whichever surfaced the issue).
606
- 3. Re-run the Reality Checker with updated evidence.
946
+ **Security/SRE BLOCK-only follow-up dispatch — SDK-gated (Stage 5 / task 5.3.1).** The read-only follow-up investigations spawned by the Security and SRE chapters (BLOCK-only trigger per `protocols/launch-readiness.md`) are dispatched via a TS switch: when the SDK flag is active (default), the orchestrator dispatches the follow-up through `claude-agent-sdk` with `maxTurns: 15` — a hard safety rail that prevents runaway remediation loops. When the SDK is disabled (`BUILDANYTHING_SDK=off`), fall back to the standard Agent tool dispatch with the same 15 tool-call cap self-reported via `tool_calls_used` (the markdown-mode cap documented in `protocols/launch-readiness.md`). If a follow-up exceeds 15 turns under SDK mode, the orchestrator flags to the user (interactive) or logs a warning and treats the parent chapter as BLOCK confirmed (autonomous) — do NOT let the subagent churn indefinitely.
607
947
 
608
- <HARD-GATE>
609
- Max 2 NEEDS WORK cycles. If the Reality Checker returns NEEDS WORK a third time:
610
- - **Interactive:** Present all remaining issues to user. Ask for direction.
611
- - **Autonomous:** Log remaining issues to `docs/plans/build-log.md`. Proceed to Phase 7 with a warning in the completion report.
612
- Do not loop forever.
613
- </HARD-GATE>
948
+ ### Step 6.1a — PM coverage fold-in
614
949
 
615
- **Compaction checkpoint.** Update `docs/plans/.build-state.md` per the format above.
950
+ PM coverage is a sub-input of the Eng-Quality chapter — evaluated inline within the Eng-Quality dispatch at Step 6.1 above against `design-doc.md` MVP scope and emitted as a `requirements_coverage[]` field on `eng-quality.json`. The LRR Aggregator runs exactly once. Chapter count stays 5.
616
951
 
617
- ---
952
+ ### Step 6.2 — LRR Aggregator (sequential, after all 5 chapter files exist)
618
953
 
619
- ## Phase 7: Ship
954
+ Call the Agent tool — description: "LRR Aggregator" — INTERNAL inline role-string — Prompt: "You are the LRR Aggregator. You mechanically apply the 6 aggregation rules from `protocols/launch-readiness.md`. You may NOT self-approve — you cite the triggering rule number on every verdict.
955
+
956
+ **STEP 1 — FILE-COMPLETENESS CHECKPOINT:** Before applying any aggregation rule, use Glob to list `docs/plans/evidence/lrr/*.json` and verify ALL 5 expected chapter files exist and parse as valid JSON:
957
+ - `eng-quality.json`
958
+ - `security.json`
959
+ - `sre.json`
960
+ - `a11y.json`
961
+ - `brand-guardian.json`
962
+
963
+ If any are missing or malformed, log 'LRR INCOMPLETE' with the missing file list, write a partial status to `docs/plans/evidence/lrr-incomplete.json`, and STOP — do not emit a combined verdict. This is the file-completeness checkpoint that closes the partial-glob race the current Aggregator is vulnerable to.
964
+
965
+ **STEP 2 — APPLY 6 RULES per `protocols/launch-readiness.md`:**
966
+ 1. ANY `override_blocks_launch: true` → combined_verdict = BLOCKED
967
+ 2. ALL verdicts PASS AND zero follow-ups spawned → combined_verdict = PRODUCTION READY
968
+ 3. ANY verdict BLOCK (with override_blocks_launch: false) → combined_verdict = NEEDS WORK + findings routed to fix loop
969
+ 4. ANY verdict CONCERNS → combined_verdict = NEEDS WORK, concerns logged
970
+ 5. Follow-up spawned AND follow_up.confirmed: true → treat parent chapter verdict as if BLOCK
971
+ 6. Contradictions between chapters on typed fields → combined_verdict = BLOCKED with cross-chapter contradiction finding
972
+
973
+ **STEP 3 — ON BLOCK VERDICT (the ⭐⭐ star rule — backward routing):** For each BLOCK finding in any chapter, read the `related_decision_id` field. Look up that row in `docs/plans/decisions.jsonl`. Find the `decided_by` field (author of the decision — per the `decided_by` free-form role-string convention in `protocols/decision-log.md`. The Aggregator matches on the string value directly. Common values: `architect` (Phase 2 architecture decisions), `design-brand-guardian` (Phase 3 Visual DNA lock), `implementer` (Phase 4 deviation rows), `human` (Gate 1/2 user decisions)). Route BACKWARD to the authoring phase with the finding as input. This replaces the current 'stop and wait' BLOCK behavior with author-aware re-entry.
974
+
975
+ **BLOCK sequentialization (Stage 4 A6 / task 4.4.3).** When multiple chapters return BLOCK in the same LRR round, the aggregator MUST process the BLOCK findings one-at-a-time in chapter declaration order (Eng-Quality → Security → SRE → A11y → Brand Guardian). DO NOT dispatch backward-routing re-entries or Security/SRE follow-up investigations in parallel — sequentialize to preserve deterministic commit ordering, avoid writer-owner lease contention on shared artifacts (`decisions.jsonl`, `lrr-routing.json`), and make the per-target-phase cycle-counter increments monotonic. Parallel BLOCK dispatch is a hard error.
620
976
 
621
- ### Step 7.0 Pre-Ship Verification
977
+ Write routing decisions to `docs/plans/evidence/lrr-routing.json` with shape `[{finding_id, chapter, related_decision_id, authoring_phase, action: \"re-open\"}, ...]`.
622
978
 
623
- Run the Verification Protocol (`protocols/verify.md`). All checks must pass before documenting and shipping. If FAIL persists after 3 fix attempts, return to Phase 6.
979
+ **STEP 4 ON NEEDS_WORK:** Classify findings & route to Phase 4 (code-level single-task fix) or Phase 2 (structural re-architect) or Phase 3 (visual — re-design). Same routing file.
624
980
 
625
- ### Step 7.0b Requirements Coverage Report
981
+ **STEP 5ON READY:** Write `docs/plans/evidence/lrr-aggregate.json` with shape:
626
982
 
627
- Call the Agent tool — description: "Requirements coverage check" — prompt: "Re-read the original Design Document (docs/plans/*.md design doc) and the user journeys + NFRs from docs/plans/sprint-tasks.md. For EVERY feature listed in the MVP scope, verify: (1) it has a corresponding implemented task, (2) it has a passing test or behavioral verification, (3) it is reachable and functional in the running app. Produce a coverage table:
983
+ ```json
984
+ {
985
+ \"combined_verdict\": \"PRODUCTION READY | NEEDS WORK | BLOCKED\",
986
+ \"chapter_verdicts\": {\"eng-quality\": \"PASS|CONCERNS|BLOCK\", \"security\": \"...\", \"sre\": \"...\", \"a11y\": \"...\", \"brand-guardian\": \"...\"},
987
+ \"triggered_rule\": <1-6>,
988
+ \"findings\": [...aggregated from all chapters...],
989
+ \"follow_ups_spawned\": [list of chapters that spawned follow-ups],
990
+ \"backward_routing\": [...from lrr-routing.json if any...],
991
+ \"timestamp\": \"ISO-8601\"
992
+ }
993
+ ```
994
+
995
+ Forward to Phase 7.
996
+
997
+ Cite triggering rule number in output. No verdict is valid without citing the rule."
628
998
 
629
- | MVP Feature | Task | Test | Verified | Status |
630
- |-------------|------|------|----------|--------|
999
+ ### Step 6.3 Verdict resolution
631
1000
 
632
- Mark each as COVERED, PARTIAL (implemented but untested), or MISSING. Any MISSING feature is a blocker — report it immediately."
1001
+ The LRR Aggregator's `combined_verdict` is the authoritative verdict. Resolution rules:
633
1002
 
634
- If any features are MISSING: spawn implementation agents to build them, then re-run verification. This is the final safety net before shipping — it catches requirements that were planned but somehow never built.
1003
+ - **PRODUCTION READY** log aggregate path to `.build-state.json` and `build-log.md`. Proceed to Phase 7.
1004
+ - **NEEDS WORK** → apply backward routing from `lrr-routing.json` per the re-entry template below. Max 2 NEEDS_WORK cycles before presenting to user (interactive) or proceeding with warning (autonomous).
1005
+ - **BLOCKED** → apply backward routing (⭐⭐ star rule) per the re-entry template below. NEVER proceed to Phase 7 with BLOCKED.
1006
+
1007
+ **Re-entry dispatch template (used by backward routing from LRR BLOCK / NEEDS_WORK, and by the Phase 5 → Phase 4 fix loop):**
1008
+
1009
+ ```
1010
+ On re-entry from LRR BLOCK:
1011
+ INPUT passed to the re-opened phase:
1012
+ blocking_finding: {chapter, finding_id, severity, description, related_decision_id, related_files}
1013
+ prior_output: path to the phase's previous artifact
1014
+ decision_row: the row from decisions.jsonl containing original reasoning + authorship
1015
+ TASK for the re-opened phase:
1016
+ Revise prior_output to address blocking_finding. Do NOT redo unaffected work. Emit a new decision_row documenting the revision rationale.
1017
+ ```
635
1018
 
636
- ### Step 7.1 Documentation
1019
+ The orchestrator assembles this payload from `lrr-routing.json` + `decisions.jsonl` + the prior artifact path, then invokes the target phase's "on re-entry" branch (see Phase 2 Step 2.2, Phase 3, and Phase 4 implementer dispatches).
637
1020
 
638
- Call the Agent tool — description: "Documentation" — mode: "bypassPermissions" — prompt: "Write project docs: README with setup/architecture/usage, API docs if applicable, deployment notes. Commit: 'docs: project documentation'."
1021
+ <HARD-GATE>
1022
+ The LRR Aggregator is the ONLY agent that may emit `combined_verdict`. No other agent — not the orchestrator, not Reality Checker, not individual chapters — may self-issue a combined verdict. This is the non-negotiable independence guarantee.
639
1023
 
640
- ### Step 7.2 Metric Loop: Documentation Quality
1024
+ Max 2 NEEDS_WORK cycles. If LRR returns NEEDS_WORK a third time:
1025
+ - Interactive: present all remaining issues. Ask for direction.
1026
+ - Autonomous: log remaining issues. Proceed to Phase 7 with a warning in the Completion Report.
1027
+ Do not loop forever.
1028
+ </HARD-GATE>
641
1029
 
642
- Run the Metric Loop Protocol on documentation. Define a metric based on completeness and whether a new developer could follow the README. Max 3 iterations.
1030
+ **Writes:** `docs/plans/evidence/lrr/*.json`, `docs/plans/evidence/lrr-aggregate.json`, `docs/plans/evidence/lrr-routing.json`.
643
1031
 
644
- ### Step 7.3 Record Learnings
1032
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.
645
1033
 
646
- Append to `docs/plans/learnings.md` (create if it doesn't exist). Review the build and record 3-5 learnings:
1034
+ ---
647
1035
 
648
- - **PATTERN:** [what worked well and should be repeated in future builds]
649
- - **PITFALL:** [what failed, caused waste, or required excessive iterations]
650
- - **HEURISTIC:** [project-specific tuning discovered during this build]
1036
+ ## Phase 7: Ship
651
1037
 
652
- Base learnings on: metric loop stall patterns, build-fix frequency, phases that exceeded expected iterations, agent prompts that needed rework.
1038
+ **Pre-ship Verify gate:** Run the Verify Protocol (INTERNAL inline — "Verify scaffolding") before any Step 7.1 dispatch. All 7 checks (Build → Type-Check Lint Test Security → Diff Review → Artifacts) must pass. If any check FAILS, dispatch a fix agent with the error, re-verify. Max 2 fix attempts. Do not proceed to Step 7.1 until PASS.
653
1039
 
654
- ### Completion Report
1040
+ **Mode-specific branch:**
1041
+ - `project_type=ios`: follow `protocols/ios-phase-branches.md` §Phase 7 — ship pipeline is optional (simulator-only is a valid end-state). If shipping, run asc-* agents + fastlane.
1042
+ - `project_type=web`: follow `protocols/web-phase-branches.md` §Phase 7 (Step 7.1 documentation + deploy notes).
655
1043
 
656
- Create final commit. Present:
1044
+ ### Step 7.1 — Sequence: Documentation → Doc Metric Loop → ASO (iOS) → Deploy → Completion Report
1045
+
1046
+ **CONTEXT header:** Render `rendered_context_header` for phase 7 per the canonical template (see CONTEXT HEADER HARD-GATE above). Prepend to every Phase 7 prompt below.
1047
+
1048
+ 1. Description: "Technical Writer" — subagent_type: `engineering-technical-writer` — mode: "bypassPermissions" — Prompt: "[CONTEXT header above] Write project docs: README with setup/architecture/usage, API docs if applicable, deployment notes. The README is the first thing a new developer reads — optimize for that reader. Commit: 'docs: project documentation'. Deployment target per the PRD (Vercel/Netlify/Railway/Fly.io/etc.) — include the deploy flow specific to that target in the README."
1049
+
1050
+ 2. Documentation Metric Loop: Run the Metric Loop Protocol (callable service) on documentation. Define a metric based on completeness and whether a new developer could follow the README end-to-end. Max 3 iterations.
1051
+
1052
+ 3. Description: "App Store Optimizer" (iOS only, conditional on ship) — subagent_type: `marketing-app-store-optimizer` — Prompt per `protocols/ios-phase-branches.md` §Phase 7 (asc-* flow — app name, subtitle, keywords, description, screenshots, privacy labels). Prepend CONTEXT header above. Skip entirely for web.
1053
+
1054
+ 4. Description: "Deploy" — subagent_type: `engineering-devops-automator` — mode: "bypassPermissions" — Prompt: "[CONTEXT header above] Deploy the app to the target from the PRD (`docs/plans/design-doc.md#tech-stack`). Run pre-deploy checks: build, env vars, secrets. Execute deploy. Verify the deployed URL returns 200 and serves the built app (not the placeholder). Report deploy URL and any smoke-test findings."
1055
+
1056
+ 5. Description: "Completion Report" — INTERNAL inline role-string — Prompt: "[CONTEXT header above] You are the Completion Report writer. Draw verification surface from the LRR Aggregator's structured output (`docs/plans/evidence/lrr-aggregate.json`) and the Reality Checker evidence manifest (`docs/plans/evidence/reality-check-manifest.json`) — NOT from orchestrator summary prose. Present:
657
1057
 
658
1058
  ```
659
1059
  BUILD COMPLETE
660
1060
  Project: [name] | Tasks: [done]/[total] | Tests: [count] passing
661
- Agents used: [list] | Verdict: [Reality Checker result]
1061
+ Agents used: [list distinct subagent_types] | Verdict: [combined_verdict from lrr-aggregate.json]
662
1062
  Metric loops run: [count] | Avg iterations: [N]
663
- Remaining: [any NEEDS WORK items]
1063
+ Remaining: [any NEEDS WORK items from lrr-routing.json]
664
1064
  ```
665
1065
 
666
- Mark all TodoWrite items complete. Update `docs/plans/.build-state.md`: "Phase: 7 COMPLETE."
1066
+ **Verification table (MANDATORY pulled from LRR aggregator output):**
1067
+
1068
+ | Metric | Count | Status |
1069
+ |--------|-------|--------|
1070
+ | Behavioral Tests declared in spec | from sprint-tasks.md | — |
1071
+ | Behavioral Tests with non-stub bodies | from Eng-Quality findings | PASS if equal |
1072
+ | Behavioral evidence files written | count from manifest | — |
1073
+ | Maestro flows present (iOS) | count of maestro/*.yaml | — |
1074
+ | Test-stub detector flagged files | from Eng-Quality findings | PASS if 0 |
1075
+ | Combined verdict | from lrr-aggregate.json | — |
1076
+ | LRR chapter verdicts | list of chapter:verdict pairs | — |
1077
+ | LRR follow-ups spawned | count | — |
1078
+ | LRR triggered rule | rule number 1-6 | — |
1079
+
1080
+ If there's a Verification Gap (declared != passing, or stub-flagged > 0), surface a top-level 'Verification Gap' section BEFORE writing the report to disk. Ask user: 'Write Completion Report with this verification gap surfaced? [YES/NO]'. In autonomous mode: write but flag prominently.
1081
+
1082
+ Create final commit. Mark all TodoWrite items complete. Update `.build-state.json`: 'Phase: 7 COMPLETE'."
1083
+
1084
+ **Writes:** `docs/plans/learnings.jsonl` (late learnings only — doc friction, deploy blockers, late-surfacing gaps). If no late learnings surfaced, skip. Row schema: `{run_id, timestamp, project_type, phase_where_learning_surfaced: \"7.x\", metric, top_issue, fix_applied, score_delta, pattern_type}`.
1085
+
1086
+ **Compaction checkpoint.** Update `.build-state.json` per the format above.