@cubis/foundry 0.3.76 → 0.3.78

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 (276) hide show
  1. package/dist/cli/build/commands.js +19 -0
  2. package/dist/cli/build/commands.js.map +1 -0
  3. package/dist/cli/commands/register.js +4 -0
  4. package/dist/cli/commands/register.js.map +1 -1
  5. package/dist/cli/core.js +844 -25
  6. package/dist/cli/core.js.map +1 -1
  7. package/mcp/src/tools/skillTools.test.ts +34 -1
  8. package/package.json +4 -3
  9. package/src/cli/build/commands.ts +39 -0
  10. package/src/cli/commands/register.ts +6 -0
  11. package/src/cli/core.ts +1026 -28
  12. package/workflows/skills/_schema/skill-platform-attributes.json +7 -0
  13. package/workflows/skills/deep-research/SKILL.md +81 -0
  14. package/workflows/skills/deep-research/evals/assertions.md +17 -0
  15. package/workflows/skills/deep-research/evals/evals.json +56 -0
  16. package/workflows/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  17. package/workflows/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  18. package/workflows/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  19. package/workflows/skills/deep-research/references/comparison-checklist.md +57 -0
  20. package/workflows/skills/deep-research/references/research-output.md +69 -0
  21. package/workflows/skills/deep-research/references/source-ladder.md +81 -0
  22. package/workflows/skills/generated/skill-audit.json +20 -2
  23. package/workflows/skills/generated/skill-catalog.json +70 -4
  24. package/workflows/skills/skills_index.json +66 -0
  25. package/workflows/skills/spec-driven-delivery/SKILL.md +63 -0
  26. package/workflows/workflows/agent-environment-setup/generated/route-manifest.json +123 -10
  27. package/workflows/workflows/agent-environment-setup/manifest.json +48 -1
  28. package/workflows/workflows/agent-environment-setup/platforms/antigravity/agents/orchestrator.md +6 -5
  29. package/workflows/workflows/agent-environment-setup/platforms/antigravity/agents/project-planner.md +4 -3
  30. package/workflows/workflows/agent-environment-setup/platforms/antigravity/agents/researcher.md +8 -4
  31. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/accessibility.toml +10 -3
  32. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/architecture.toml +19 -0
  33. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/backend.toml +10 -3
  34. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/create.toml +10 -3
  35. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/database.toml +10 -3
  36. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/debug.toml +10 -3
  37. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/devops.toml +10 -3
  38. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/implement-track.toml +10 -3
  39. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/migrate.toml +10 -3
  40. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/mobile.toml +10 -3
  41. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/onboard.toml +10 -3
  42. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/orchestrate.toml +10 -3
  43. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/plan.toml +10 -3
  44. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/refactor.toml +10 -3
  45. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/release.toml +10 -3
  46. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/review.toml +10 -3
  47. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/security.toml +10 -3
  48. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/spec.toml +19 -0
  49. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/test.toml +10 -3
  50. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/vercel.toml +10 -3
  51. package/workflows/workflows/agent-environment-setup/platforms/antigravity/rules/GEMINI.md +15 -8
  52. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/SKILL.md +89 -0
  53. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/evals/assertions.md +17 -0
  54. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/evals/evals.json +56 -0
  55. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  56. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  57. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  58. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/references/comparison-checklist.md +57 -0
  59. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/references/research-output.md +69 -0
  60. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/deep-research/references/source-ladder.md +81 -0
  61. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/spec-driven-delivery/SKILL.md +65 -0
  62. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/architecture.md +82 -0
  63. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/backend.md +3 -0
  64. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/create.md +4 -1
  65. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/database.md +3 -0
  66. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/implement-track.md +7 -1
  67. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/migrate.md +4 -1
  68. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/mobile.md +3 -0
  69. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/onboard.md +4 -3
  70. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/orchestrate.md +8 -3
  71. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/plan.md +16 -6
  72. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/refactor.md +3 -0
  73. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/release.md +3 -0
  74. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/spec.md +81 -0
  75. package/workflows/workflows/agent-environment-setup/platforms/claude/agents/orchestrator.md +6 -5
  76. package/workflows/workflows/agent-environment-setup/platforms/claude/agents/project-planner.md +4 -3
  77. package/workflows/workflows/agent-environment-setup/platforms/claude/agents/researcher.md +8 -4
  78. package/workflows/workflows/agent-environment-setup/platforms/claude/hooks/README.md +15 -0
  79. package/workflows/workflows/agent-environment-setup/platforms/claude/hooks/route-research-guard.mjs +39 -0
  80. package/workflows/workflows/agent-environment-setup/platforms/claude/hooks/settings.snippet.json +15 -0
  81. package/workflows/workflows/agent-environment-setup/platforms/claude/rules/CLAUDE.md +17 -8
  82. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/SKILL.md +95 -0
  83. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/evals/assertions.md +17 -0
  84. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/evals/evals.json +56 -0
  85. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  86. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  87. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  88. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/references/comparison-checklist.md +57 -0
  89. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/references/research-output.md +69 -0
  90. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/deep-research/references/source-ladder.md +81 -0
  91. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/skills_index.json +66 -0
  92. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/spec-driven-delivery/SKILL.md +66 -0
  93. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/architecture.md +80 -0
  94. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/backend.md +3 -0
  95. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/create.md +4 -1
  96. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/database.md +3 -0
  97. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/implement-track.md +7 -1
  98. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/migrate.md +4 -1
  99. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/mobile.md +3 -0
  100. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/onboard.md +4 -3
  101. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/orchestrate.md +8 -3
  102. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/plan.md +16 -6
  103. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/refactor.md +3 -0
  104. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/release.md +3 -0
  105. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/spec.md +79 -0
  106. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/backend-specialist.md +1 -1
  107. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/code-archaeologist.md +1 -1
  108. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/database-architect.md +1 -1
  109. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/debugger.md +1 -1
  110. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/devops-engineer.md +1 -1
  111. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/documentation-writer.md +1 -1
  112. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/frontend-specialist.md +1 -1
  113. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/game-developer.md +1 -1
  114. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/mobile-developer.md +1 -1
  115. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/orchestrator.md +7 -6
  116. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/penetration-tester.md +1 -1
  117. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/performance-optimizer.md +1 -1
  118. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/product-manager.md +1 -1
  119. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/project-planner.md +5 -4
  120. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/qa-automation-engineer.md +1 -1
  121. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/researcher.md +9 -5
  122. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/security-auditor.md +1 -1
  123. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/seo-specialist.md +1 -1
  124. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/sre-engineer.md +1 -1
  125. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/test-engineer.md +1 -1
  126. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/validator.md +1 -1
  127. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/vercel-expert.md +1 -1
  128. package/workflows/workflows/agent-environment-setup/platforms/codex/rules/AGENTS.md +15 -8
  129. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/SKILL.md +89 -0
  130. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/evals/assertions.md +17 -0
  131. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/evals/evals.json +56 -0
  132. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  133. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  134. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  135. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/references/comparison-checklist.md +57 -0
  136. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/references/research-output.md +69 -0
  137. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/deep-research/references/source-ladder.md +81 -0
  138. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/spec-driven-delivery/SKILL.md +65 -0
  139. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/accessibility.md +1 -1
  140. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/architecture.md +82 -0
  141. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/backend.md +4 -1
  142. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/create.md +5 -2
  143. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/database.md +4 -1
  144. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/debug.md +1 -1
  145. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/devops.md +1 -1
  146. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/implement-track.md +8 -2
  147. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/migrate.md +5 -2
  148. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/mobile.md +4 -1
  149. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/onboard.md +5 -4
  150. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/orchestrate.md +9 -4
  151. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/plan.md +17 -7
  152. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/refactor.md +4 -1
  153. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/release.md +4 -1
  154. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/review.md +1 -1
  155. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/security.md +1 -1
  156. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/spec.md +81 -0
  157. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/test.md +1 -1
  158. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/vercel.md +1 -1
  159. package/workflows/workflows/agent-environment-setup/platforms/copilot/agents/orchestrator.md +6 -5
  160. package/workflows/workflows/agent-environment-setup/platforms/copilot/agents/project-planner.md +4 -3
  161. package/workflows/workflows/agent-environment-setup/platforms/copilot/agents/researcher.md +8 -4
  162. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-accessibility.prompt.md +9 -3
  163. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-architecture.prompt.md +18 -0
  164. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-backend.prompt.md +9 -3
  165. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-create.prompt.md +9 -3
  166. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-database.prompt.md +9 -3
  167. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-debug.prompt.md +9 -3
  168. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-devops.prompt.md +9 -3
  169. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-implement-track.prompt.md +9 -3
  170. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-migrate.prompt.md +9 -3
  171. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-mobile.prompt.md +9 -3
  172. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-onboard.prompt.md +9 -3
  173. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-orchestrate.prompt.md +9 -3
  174. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-plan.prompt.md +9 -3
  175. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-refactor.prompt.md +9 -3
  176. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-release.prompt.md +9 -3
  177. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-review.prompt.md +9 -3
  178. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-security.prompt.md +9 -3
  179. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-spec.prompt.md +18 -0
  180. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-test.prompt.md +9 -3
  181. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-vercel.prompt.md +9 -3
  182. package/workflows/workflows/agent-environment-setup/platforms/copilot/rules/copilot-instructions.md +15 -8
  183. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/SKILL.md +94 -0
  184. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/evals/assertions.md +17 -0
  185. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/evals/evals.json +56 -0
  186. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  187. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  188. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  189. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/references/comparison-checklist.md +57 -0
  190. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/references/research-output.md +69 -0
  191. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/deep-research/references/source-ladder.md +81 -0
  192. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/skills_index.json +66 -0
  193. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/spec-driven-delivery/SKILL.md +70 -0
  194. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/architecture.md +80 -0
  195. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/backend.md +3 -0
  196. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/create.md +4 -1
  197. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/database.md +3 -0
  198. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/implement-track.md +7 -1
  199. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/migrate.md +4 -1
  200. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/mobile.md +3 -0
  201. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/onboard.md +4 -3
  202. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/orchestrate.md +8 -3
  203. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/plan.md +16 -6
  204. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/refactor.md +3 -0
  205. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/release.md +3 -0
  206. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/spec.md +79 -0
  207. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/accessibility.toml +10 -3
  208. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/architecture.toml +19 -0
  209. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/backend.toml +10 -3
  210. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/create.toml +10 -3
  211. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/database.toml +10 -3
  212. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/debug.toml +10 -3
  213. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/devops.toml +10 -3
  214. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/implement-track.toml +10 -3
  215. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/migrate.toml +10 -3
  216. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/mobile.toml +10 -3
  217. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/onboard.toml +10 -3
  218. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/orchestrate.toml +10 -3
  219. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/plan.toml +10 -3
  220. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/refactor.toml +10 -3
  221. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/release.toml +10 -3
  222. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/review.toml +10 -3
  223. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/security.toml +10 -3
  224. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/spec.toml +19 -0
  225. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/test.toml +10 -3
  226. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/vercel.toml +10 -3
  227. package/workflows/workflows/agent-environment-setup/platforms/gemini/rules/GEMINI.md +15 -8
  228. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/SKILL.md +89 -0
  229. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/evals/assertions.md +17 -0
  230. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/evals/evals.json +56 -0
  231. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/examples/01-latest-docs-check.md +12 -0
  232. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/examples/02-ecosystem-comparison.md +12 -0
  233. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/examples/03-research-to-implementation-handoff.md +12 -0
  234. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/references/comparison-checklist.md +57 -0
  235. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/references/research-output.md +69 -0
  236. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/deep-research/references/source-ladder.md +81 -0
  237. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/spec-driven-delivery/SKILL.md +65 -0
  238. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/architecture.md +82 -0
  239. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/backend.md +3 -0
  240. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/create.md +4 -1
  241. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/database.md +3 -0
  242. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/implement-track.md +7 -1
  243. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/migrate.md +4 -1
  244. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/mobile.md +3 -0
  245. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/onboard.md +4 -3
  246. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/orchestrate.md +8 -3
  247. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/plan.md +16 -6
  248. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/refactor.md +3 -0
  249. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/release.md +3 -0
  250. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/spec.md +81 -0
  251. package/workflows/workflows/agent-environment-setup/shared/agents/backend-specialist.md +5 -5
  252. package/workflows/workflows/agent-environment-setup/shared/agents/database-architect.md +3 -3
  253. package/workflows/workflows/agent-environment-setup/shared/agents/orchestrator.md +10 -9
  254. package/workflows/workflows/agent-environment-setup/shared/agents/penetration-tester.md +3 -3
  255. package/workflows/workflows/agent-environment-setup/shared/agents/product-manager.md +6 -6
  256. package/workflows/workflows/agent-environment-setup/shared/agents/project-planner.md +10 -9
  257. package/workflows/workflows/agent-environment-setup/shared/agents/researcher.md +13 -9
  258. package/workflows/workflows/agent-environment-setup/shared/agents/security-auditor.md +2 -2
  259. package/workflows/workflows/agent-environment-setup/shared/rules/STEERING.md +57 -13
  260. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/claude.md +2 -0
  261. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/codex.md +3 -3
  262. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/gemini.md +20 -0
  263. package/workflows/workflows/agent-environment-setup/shared/workflows/architecture.md +80 -0
  264. package/workflows/workflows/agent-environment-setup/shared/workflows/backend.md +8 -5
  265. package/workflows/workflows/agent-environment-setup/shared/workflows/create.md +5 -2
  266. package/workflows/workflows/agent-environment-setup/shared/workflows/database.md +6 -3
  267. package/workflows/workflows/agent-environment-setup/shared/workflows/implement-track.md +12 -6
  268. package/workflows/workflows/agent-environment-setup/shared/workflows/migrate.md +7 -4
  269. package/workflows/workflows/agent-environment-setup/shared/workflows/mobile.md +3 -0
  270. package/workflows/workflows/agent-environment-setup/shared/workflows/onboard.md +6 -5
  271. package/workflows/workflows/agent-environment-setup/shared/workflows/orchestrate.md +10 -5
  272. package/workflows/workflows/agent-environment-setup/shared/workflows/plan.md +18 -8
  273. package/workflows/workflows/agent-environment-setup/shared/workflows/refactor.md +5 -2
  274. package/workflows/workflows/agent-environment-setup/shared/workflows/release.md +3 -0
  275. package/workflows/workflows/agent-environment-setup/shared/workflows/security.md +2 -2
  276. package/workflows/workflows/agent-environment-setup/shared/workflows/spec.md +79 -0
package/dist/cli/core.js CHANGED
@@ -3,6 +3,7 @@ import { confirm, input, select } from "@inquirer/prompts";
3
3
  import { parse as parseJsonc } from "jsonc-parser";
4
4
  import { existsSync } from "node:fs";
5
5
  import { chmod, cp, mkdir, readdir, readFile, rm, stat, symlink, writeFile, } from "node:fs/promises";
6
+ import { createHash } from "node:crypto";
6
7
  import { createRequire } from "node:module";
7
8
  import { spawn, execFile as execFileCallback } from "node:child_process";
8
9
  import os from "node:os";
@@ -24,6 +25,10 @@ const ENGINEERING_RULES_BLOCK_START_RE = /<!--\s*cbx:engineering:auto:start[^>]*
24
25
  const ENGINEERING_RULES_BLOCK_END_RE = /<!--\s*cbx:engineering:auto:end\s*-->/g;
25
26
  const ENGINEERING_RULES_FILE_BLOCK_START_RE = /<!--\s*cbx:engineering:rules:start[^>]*-->/g;
26
27
  const ENGINEERING_RULES_FILE_BLOCK_END_RE = /<!--\s*cbx:engineering:rules:end\s*-->/g;
28
+ const ENGINEERING_ARCHITECTURE_BLOCK_START_RE = /<!--\s*cbx:architecture:rules:start[^>]*-->/g;
29
+ const ENGINEERING_ARCHITECTURE_BLOCK_END_RE = /<!--\s*cbx:architecture:rules:end\s*-->/g;
30
+ const TECH_ARCHITECTURE_BLOCK_START_RE = /<!--\s*cbx:architecture:tech:start[^>]*-->/g;
31
+ const TECH_ARCHITECTURE_BLOCK_END_RE = /<!--\s*cbx:architecture:tech:end\s*-->/g;
27
32
  const COPILOT_ALLOWED_SKILL_FRONTMATTER_KEYS = new Set([
28
33
  "compatibility",
29
34
  "description",
@@ -137,17 +142,20 @@ const WORKFLOW_PROFILES = {
137
142
  workflowDirs: [".claude/workflows"],
138
143
  agentDirs: [".claude/agents"],
139
144
  skillDirs: [".claude/skills"],
145
+ hookDirs: [".claude/hooks"],
140
146
  ruleFilesByPriority: ["CLAUDE.md"],
141
147
  },
142
148
  global: {
143
149
  workflowDirs: ["~/.claude/workflows"],
144
150
  agentDirs: ["~/.claude/agents"],
145
151
  skillDirs: ["~/.claude/skills"],
152
+ hookDirs: ["~/.claude/hooks"],
146
153
  ruleFilesByPriority: ["~/.claude/CLAUDE.md"],
147
154
  },
148
155
  detectorPaths: [
149
156
  "CLAUDE.md",
150
157
  ".claude",
158
+ ".claude/hooks",
151
159
  ".claude/rules",
152
160
  ".claude/settings.json",
153
161
  ],
@@ -212,11 +220,18 @@ const PLAYWRIGHT_MCP_URL = `http://localhost:${PLAYWRIGHT_DEFAULT_PORT}/mcp`;
212
220
  const POSTMAN_WORKSPACE_MANUAL_CHOICE = "__postman_workspace_manual__";
213
221
  const CBX_CONFIG_FILENAME = "cbx_config.json";
214
222
  const CBX_CREDENTIALS_ENV_FILENAME = "credentials.env";
223
+ const ARCHITECTURE_BUILD_METADATA_FILENAME = "architecture-build.json";
215
224
  const LEGACY_POSTMAN_CONFIG_FILENAME = ["postman", "setting.json"].join("_");
216
225
  const DEFAULT_CREDENTIAL_PROFILE_NAME = "default";
217
226
  const RESERVED_CREDENTIAL_PROFILE_NAMES = new Set(["all"]);
218
227
  const CREDENTIAL_SERVICES = new Set(["postman", "stitch"]);
219
228
  const MCP_RUNTIMES = new Set(["docker", "local"]);
229
+ const ARCHITECTURE_BUILD_PLATFORMS = new Set([
230
+ "codex",
231
+ "claude",
232
+ "gemini",
233
+ "copilot",
234
+ ]);
220
235
  const MCP_FALLBACKS = new Set(["local", "fail", "skip"]);
221
236
  const MCP_UPDATE_POLICIES = new Set(["pinned", "latest"]);
222
237
  const DEFAULT_MCP_RUNTIME = "docker";
@@ -835,6 +850,186 @@ function buildAntigravityTerminalVerificationBlock({ provider, powerShellScriptP
835
850
  "<!-- cbx:terminal:verification:end -->",
836
851
  ].join("\n");
837
852
  }
853
+ function hashStableObject(value) {
854
+ return createHash("sha256")
855
+ .update(JSON.stringify(value))
856
+ .digest("hex")
857
+ .slice(0, 12);
858
+ }
859
+ function firstNonEmpty(values) {
860
+ for (const value of values || []) {
861
+ if (value)
862
+ return value;
863
+ }
864
+ return null;
865
+ }
866
+ function inferArchitectureContractProfile(snapshot) {
867
+ const allSignals = [];
868
+ for (const app of snapshot.architectureByApp || []) {
869
+ for (const signal of app.architectureSignals || []) {
870
+ if (!allSignals.includes(signal))
871
+ allSignals.push(signal);
872
+ }
873
+ }
874
+ const style = firstNonEmpty([
875
+ allSignals.find((signal) => /clean architecture/i.test(signal)),
876
+ allSignals.find((signal) => /hexagonal/i.test(signal)),
877
+ allSignals.find((signal) => /feature-first/i.test(signal)),
878
+ allSignals.find((signal) => /mvvm/i.test(signal)),
879
+ allSignals.find((signal) => /mvc/i.test(signal)),
880
+ ]) || "Undeclared — align to current repository conventions";
881
+ const moduleBoundaries = snapshot.annotatedDirs
882
+ .slice(0, 8)
883
+ .map(({ name, purpose }) => purpose ? `${name}/ (${purpose})` : `${name}/`);
884
+ const dependencyRules = [];
885
+ if (/clean architecture/i.test(style)) {
886
+ dependencyRules.push("Domain code must not depend on infrastructure, framework, or presentation layers.");
887
+ dependencyRules.push("Adapters may depend inward on domain contracts, never the reverse.");
888
+ }
889
+ else if (/hexagonal/i.test(style)) {
890
+ dependencyRules.push("Ports stay stable at the boundary; adapters implement them without leaking infrastructure concerns inward.");
891
+ }
892
+ else {
893
+ dependencyRules.push("Respect existing feature and package boundaries; avoid hidden cross-module imports.");
894
+ }
895
+ dependencyRules.push("Shared UI, data, and platform conventions belong in the declared common layer, not duplicated per feature.");
896
+ const designSystemSource = firstNonEmpty([
897
+ snapshot.topDirs.includes("components")
898
+ ? "components/ is the primary shared UI surface."
899
+ : null,
900
+ snapshot.topDirs.includes("design-system")
901
+ ? "design-system/ is the primary shared UI surface."
902
+ : null,
903
+ snapshot.topDirs.includes("app")
904
+ ? "App-level UI patterns should be centralized and reused across screens."
905
+ : null,
906
+ ]) || "No dedicated design-system directory detected; infer shared UI rules from current components and screens.";
907
+ const testingStrategy = [];
908
+ if (snapshot.keyScripts.some((script) => script.name === "lint")) {
909
+ testingStrategy.push("Linting is part of the baseline quality gate.");
910
+ }
911
+ if (snapshot.keyScripts.some((script) => script.name.includes("type"))) {
912
+ testingStrategy.push("Static typing or analysis should pass before merge when the stack supports it.");
913
+ }
914
+ if (snapshot.keyScripts.some((script) => script.name.startsWith("test"))) {
915
+ testingStrategy.push("Focused automated tests should cover the changed behavior before merge.");
916
+ }
917
+ if (testingStrategy.length === 0) {
918
+ testingStrategy.push("Add focused validation evidence for non-trivial changes even when no standard test command is detected.");
919
+ }
920
+ const scalingConstraints = inferTechnicalConstraints(snapshot, {
921
+ suggestedProfile: inferContextBudget(snapshot).suggestedProfile,
922
+ });
923
+ const docUpdateTriggers = [
924
+ "feature additions that change module boundaries or shared UI rules",
925
+ "migrations, scale changes, or deployment-shape changes",
926
+ "refactors that establish new conventions future work should follow",
927
+ ];
928
+ return {
929
+ style,
930
+ moduleBoundaries,
931
+ dependencyRules,
932
+ designSystemSource,
933
+ testingStrategy,
934
+ scalingConstraints,
935
+ docUpdateTriggers,
936
+ };
937
+ }
938
+ function buildArchitectureMermaid(snapshot) {
939
+ const topDirs = snapshot.topDirs.slice(0, 4);
940
+ const flowNodes = topDirs.length > 0 ? topDirs : ["src", "docs"];
941
+ const lines = [
942
+ "flowchart TD",
943
+ ' user["User / Entry Point"] --> app["Application Surface"]',
944
+ ];
945
+ for (let index = 0; index < flowNodes.length; index += 1) {
946
+ const nodeName = flowNodes[index].replace(/[^A-Za-z0-9]/g, "") || `N${index}`;
947
+ lines.push(` app --> ${nodeName}["${flowNodes[index]}/"]`);
948
+ }
949
+ if (snapshot.isMcpServer || snapshot.mcpSignals.length > 0) {
950
+ lines.push(' app --> mcp["MCP / Tooling Surface"]');
951
+ }
952
+ if (snapshot.cicdSignals.length > 0) {
953
+ lines.push(' app --> deploy["Delivery / Runtime"]');
954
+ }
955
+ return lines.join("\n");
956
+ }
957
+ function buildEngineeringArchitectureSection(snapshot) {
958
+ const profile = inferArchitectureContractProfile(snapshot);
959
+ const hash = hashStableObject(profile);
960
+ return [
961
+ `<!-- cbx:architecture:rules:start version=1 profile=${hash} -->`,
962
+ "## 10) Architecture Contract (auto-managed)",
963
+ "",
964
+ `- Declared style: ${profile.style}.`,
965
+ `- Design-system source of truth: ${profile.designSystemSource}`,
966
+ "- Dependency direction rules:",
967
+ ...profile.dependencyRules.map((rule) => ` - ${rule}`),
968
+ "- Module and package boundaries to preserve:",
969
+ ...(profile.moduleBoundaries.length > 0
970
+ ? profile.moduleBoundaries.map((rule) => ` - ${rule}`)
971
+ : [" - No strong module boundary was detected automatically; keep new boundaries explicit in specs and ADRs."]),
972
+ "- Testability expectations:",
973
+ ...profile.testingStrategy.map((rule) => ` - ${rule}`),
974
+ "- Doc refresh policy:",
975
+ " - Update these managed sections when architecture, scale, boundaries, design-system rules, or testing strategy changes.",
976
+ " - For non-trivial work, read this file before planning and read TECH.md next.",
977
+ "<!-- cbx:architecture:rules:end -->",
978
+ "",
979
+ ].join("\n");
980
+ }
981
+ function buildTechArchitectureSection(snapshot) {
982
+ const profile = inferArchitectureContractProfile(snapshot);
983
+ const payload = {
984
+ style: profile.style,
985
+ topDirs: snapshot.topDirs,
986
+ frameworks: snapshot.frameworks,
987
+ architectureByApp: snapshot.architectureByApp,
988
+ };
989
+ const hash = hashStableObject(payload);
990
+ const architectureSignals = profile.style
991
+ ? [`- Primary inferred style: ${profile.style}.`]
992
+ : [];
993
+ return [
994
+ `<!-- cbx:architecture:tech:start version=1 snapshot=${hash} -->`,
995
+ "## Architecture Snapshot (auto-managed)",
996
+ ...(architectureSignals.length > 0 ? ["", ...architectureSignals] : []),
997
+ ...(snapshot.architectureByApp.length > 0
998
+ ? [
999
+ "- App-level structure signals:",
1000
+ ...snapshot.architectureByApp.slice(0, 6).map((item) => {
1001
+ const label = item.rootPath === "." ? "repo root" : item.rootPath;
1002
+ const signals = item.architectureSignals.length > 0
1003
+ ? item.architectureSignals.join(", ")
1004
+ : "not enough signals to classify";
1005
+ return ` - ${label}: ${signals}`;
1006
+ }),
1007
+ ]
1008
+ : ["- No app-level architecture signals detected automatically."]),
1009
+ "",
1010
+ "### Module / App Topology",
1011
+ ...(profile.moduleBoundaries.length > 0
1012
+ ? profile.moduleBoundaries.map((item) => `- ${item}`)
1013
+ : ["- No significant top-level module boundaries detected automatically."]),
1014
+ "",
1015
+ "### Flow Narratives",
1016
+ "- Describe the primary request, data, and background-job flows here when architecture generation runs.",
1017
+ "- Keep this section current when scale changes or new integration boundaries are introduced.",
1018
+ "",
1019
+ "### Mermaid Diagram",
1020
+ "```mermaid",
1021
+ buildArchitectureMermaid(snapshot),
1022
+ "```",
1023
+ "",
1024
+ "### Scaling / Deployment / Testing Snapshot",
1025
+ ...profile.scalingConstraints.map((item) => `- ${item}`),
1026
+ "",
1027
+ "### External Research Evidence",
1028
+ "- Reserved for `cbx build architecture --research auto|always` when outside evidence informs the architecture notes.",
1029
+ "<!-- cbx:architecture:tech:end -->",
1030
+ "",
1031
+ ].join("\n");
1032
+ }
838
1033
  function buildEngineeringRulesTemplate() {
839
1034
  return [
840
1035
  "# Engineering Rules",
@@ -917,6 +1112,21 @@ function buildEngineeringRulesTemplate() {
917
1112
  "",
918
1113
  "- `TECH.md` is generated from current codebase reality.",
919
1114
  "- Re-run `cbx rules tech-md --overwrite` after major stack or architecture changes.",
1115
+ "",
1116
+ "<!-- cbx:architecture:rules:start version=1 profile=bootstrap -->",
1117
+ "## 10) Architecture Contract (auto-managed)",
1118
+ "",
1119
+ "- Declared style: bootstrap placeholder. Re-run `cbx build architecture --platform <codex|claude|gemini|copilot>` to refresh this contract from the repo.",
1120
+ "- Design-system source of truth: bootstrap placeholder.",
1121
+ "- Dependency direction rules:",
1122
+ " - Replace this placeholder with the managed architecture block when architecture generation runs.",
1123
+ "- Module and package boundaries to preserve:",
1124
+ " - Replace this placeholder with the managed architecture block when architecture generation runs.",
1125
+ "- Testability expectations:",
1126
+ " - Replace this placeholder with the managed architecture block when architecture generation runs.",
1127
+ "- Doc refresh policy:",
1128
+ " - Update this section when architecture, scale, boundaries, design-system rules, or testing strategy changes.",
1129
+ "<!-- cbx:architecture:rules:end -->",
920
1130
  "<!-- cbx:engineering:rules:end -->",
921
1131
  "",
922
1132
  ].join("\n");
@@ -939,10 +1149,11 @@ function buildEngineeringRulesManagedBlock({ platform, engineeringRulesFilePath,
939
1149
  "2. Keep architecture simple (KISS) and avoid speculative work (YAGNI).",
940
1150
  "3. Apply SOLID pragmatically to reduce change risk, not add ceremony.",
941
1151
  "4. Use clear naming with focused responsibilities and explicit boundaries.",
942
- "5. Require validation evidence (lint/types/tests) before merge.",
943
- "6. Use Decision Log response style.",
944
- "7. Every Decision Log must include a `Skills Used` section listing skill, workflow, or agent names.",
945
- "8. If no skill loaded, `Skills Used: none` is mandatory.",
1152
+ "5. For non-trivial work, read ENGINEERING_RULES.md first and TECH.md next before planning or implementation.",
1153
+ "6. Require validation evidence (lint/types/tests) before merge.",
1154
+ "7. Use Decision Log response style.",
1155
+ "8. Every Decision Log must include a `Skills Used` section listing skill, workflow, or agent names.",
1156
+ "9. If no skill loaded, `Skills Used: none` is mandatory.",
946
1157
  "",
947
1158
  "<!-- cbx:engineering:auto:end -->",
948
1159
  ].join("\n");
@@ -1077,6 +1288,105 @@ async function upsertEngineeringRulesBlock({ ruleFilePath, platform, engineering
1077
1288
  warnings,
1078
1289
  };
1079
1290
  }
1291
+ function extractTaggedMarkerAttribute(content, startPattern, key) {
1292
+ const match = String(content || "").match(startPattern);
1293
+ if (!match || !match[0])
1294
+ return null;
1295
+ const attributeMatch = match[0].match(new RegExp(`${key}=([^\\s>]+)`));
1296
+ return attributeMatch?.[1] || null;
1297
+ }
1298
+ async function upsertTaggedSectionInFile({ targetPath, initialContent, block, startPattern, endPattern, dryRun = false, }) {
1299
+ const exists = await pathExists(targetPath);
1300
+ const original = exists ? await readFile(targetPath, "utf8") : initialContent;
1301
+ const analysis = analyzeTaggedBlock(original, startPattern, endPattern);
1302
+ let nextContent = original;
1303
+ if (!exists || analysis.status === "absent") {
1304
+ const trimmed = String(original || "").trimEnd();
1305
+ nextContent =
1306
+ trimmed.length > 0 ? `${trimmed}\n\n${block}\n` : `${block}\n`;
1307
+ }
1308
+ else if (analysis.range) {
1309
+ nextContent = `${original.slice(0, analysis.range.start)}${block}${original.slice(analysis.range.end)}`;
1310
+ }
1311
+ else {
1312
+ const trimmed = String(original || "").trimEnd();
1313
+ nextContent =
1314
+ trimmed.length > 0 ? `${trimmed}\n\n${block}\n` : `${block}\n`;
1315
+ }
1316
+ if (nextContent === original) {
1317
+ return {
1318
+ action: "unchanged",
1319
+ filePath: targetPath,
1320
+ };
1321
+ }
1322
+ if (!dryRun) {
1323
+ await mkdir(path.dirname(targetPath), { recursive: true });
1324
+ await writeFile(targetPath, nextContent, "utf8");
1325
+ }
1326
+ return {
1327
+ action: exists
1328
+ ? dryRun
1329
+ ? "would-patch"
1330
+ : "patched"
1331
+ : dryRun
1332
+ ? "would-create"
1333
+ : "created",
1334
+ filePath: targetPath,
1335
+ };
1336
+ }
1337
+ function buildArchitectureBuildMetadata({ platform, researchMode, rulesProfileHash, techSnapshotHash, }) {
1338
+ return {
1339
+ schemaVersion: 1,
1340
+ generatedBy: "cbx build architecture",
1341
+ generatedAt: new Date().toISOString(),
1342
+ platform,
1343
+ researchMode,
1344
+ rulesProfileHash,
1345
+ techSnapshotHash,
1346
+ };
1347
+ }
1348
+ async function ensureArchitectureDocScaffold({ workspaceRoot, snapshot, overwrite = false, dryRun = false, }) {
1349
+ const engineeringRulesPath = path.join(workspaceRoot, "ENGINEERING_RULES.md");
1350
+ const techMdPath = path.join(workspaceRoot, "TECH.md");
1351
+ const rulesTemplate = buildEngineeringRulesTemplate();
1352
+ const rulesFileResult = await upsertEngineeringRulesFile({
1353
+ targetPath: engineeringRulesPath,
1354
+ template: rulesTemplate,
1355
+ overwrite,
1356
+ dryRun,
1357
+ });
1358
+ const rulesArchitectureResult = await upsertTaggedSectionInFile({
1359
+ targetPath: engineeringRulesPath,
1360
+ initialContent: `${rulesTemplate}\n`,
1361
+ block: buildEngineeringArchitectureSection(snapshot),
1362
+ startPattern: ENGINEERING_ARCHITECTURE_BLOCK_START_RE,
1363
+ endPattern: ENGINEERING_ARCHITECTURE_BLOCK_END_RE,
1364
+ dryRun,
1365
+ });
1366
+ const techContent = `${buildTechMd(snapshot)}\n`;
1367
+ const techResult = await writeTextFile({
1368
+ targetPath: techMdPath,
1369
+ content: techContent,
1370
+ overwrite,
1371
+ dryRun,
1372
+ });
1373
+ const techArchitectureResult = await upsertTaggedSectionInFile({
1374
+ targetPath: techMdPath,
1375
+ initialContent: techContent,
1376
+ block: buildTechArchitectureSection(snapshot),
1377
+ startPattern: TECH_ARCHITECTURE_BLOCK_START_RE,
1378
+ endPattern: TECH_ARCHITECTURE_BLOCK_END_RE,
1379
+ dryRun,
1380
+ });
1381
+ return {
1382
+ engineeringRulesPath,
1383
+ techMdPath,
1384
+ rulesFileResult,
1385
+ rulesArchitectureResult,
1386
+ techResult,
1387
+ techArchitectureResult,
1388
+ };
1389
+ }
1080
1390
  function normalizeTechPackageName(value) {
1081
1391
  if (value === undefined || value === null)
1082
1392
  return null;
@@ -1960,7 +2270,7 @@ function inferRecommendedSkills(snapshot) {
1960
2270
  hasFramework("TypeORM") ||
1961
2271
  hasFramework("Mongoose") ||
1962
2272
  hasFramework("SQLAlchemy")) {
1963
- recommended.add("database-skills");
2273
+ recommended.add("database-design");
1964
2274
  }
1965
2275
  if (recommended.size === 0) {
1966
2276
  recommended.add("clean-code");
@@ -2214,6 +2524,8 @@ function buildTechMd(snapshot, { compact = false } = {}) {
2214
2524
  lines.push(`- Suggested install profile: \`${contextBudget.suggestedProfile}\``);
2215
2525
  lines.push("- Use `--all-skills` only when task scope clearly requires full catalog breadth.");
2216
2526
  lines.push("");
2527
+ lines.push(buildTechArchitectureSection(snapshot).trimEnd());
2528
+ lines.push("");
2217
2529
  if (!compact) {
2218
2530
  lines.push("## Package Signals");
2219
2531
  appendTechPackageSection(lines, "JavaScript / TypeScript (package.json)", snapshot.packageSignals.javascript);
@@ -2379,6 +2691,7 @@ async function recordBundleInstallState({ scope, platform, bundleId, artifacts,
2379
2691
  skills: artifacts.skills.map(toPosixPath),
2380
2692
  commands: (artifacts.commands || []).map(toPosixPath),
2381
2693
  prompts: (artifacts.prompts || []).map(toPosixPath),
2694
+ hooks: (artifacts.hooks || []).map(toPosixPath),
2382
2695
  };
2383
2696
  await writeState(scope, state, cwd);
2384
2697
  }
@@ -2404,6 +2717,7 @@ async function resolveProfilePaths(profileId, scope, cwd = process.cwd()) {
2404
2717
  const skillDirs = Array.isArray(cfg.skillDirs) ? cfg.skillDirs : [];
2405
2718
  const commandDirs = Array.isArray(cfg.commandDirs) ? cfg.commandDirs : [];
2406
2719
  const promptDirs = Array.isArray(cfg.promptDirs) ? cfg.promptDirs : [];
2720
+ const hookDirs = Array.isArray(cfg.hookDirs) ? cfg.hookDirs : [];
2407
2721
  const resolvePreferredDir = async (dirs) => {
2408
2722
  if (dirs.length === 0)
2409
2723
  return null;
@@ -2420,6 +2734,7 @@ async function resolveProfilePaths(profileId, scope, cwd = process.cwd()) {
2420
2734
  skillsDir: await resolvePreferredDir(skillDirs),
2421
2735
  commandsDir: commandDirs[0] ? expandPath(commandDirs[0], cwd) : null,
2422
2736
  promptsDir: promptDirs[0] ? expandPath(promptDirs[0], cwd) : null,
2737
+ hooksDir: hookDirs[0] ? expandPath(hookDirs[0], cwd) : null,
2423
2738
  ruleFilesByPriority: cfg.ruleFilesByPriority.map((filePath) => expandPath(filePath, cwd)),
2424
2739
  };
2425
2740
  }
@@ -2450,6 +2765,7 @@ function resolveProfilePathCandidates(profileId, scope, cwd = process.cwd()) {
2450
2765
  skillsDirs: expandUniquePaths(cfg.skillDirs, cwd),
2451
2766
  commandsDirs: expandUniquePaths(cfg.commandDirs, cwd),
2452
2767
  promptsDirs: expandUniquePaths(cfg.promptDirs, cwd),
2768
+ hooksDirs: expandUniquePaths(cfg.hookDirs, cwd),
2453
2769
  ruleFilesByPriority: expandUniquePaths(cfg.ruleFilesByPriority, cwd),
2454
2770
  };
2455
2771
  }
@@ -2474,6 +2790,7 @@ async function resolveArtifactProfilePaths(profileId, scope, cwd = process.cwd()
2474
2790
  agentsDir: workspacePaths.agentsDir,
2475
2791
  commandsDir: workspacePaths.commandsDir ?? scopedPaths.commandsDir,
2476
2792
  promptsDir: workspacePaths.promptsDir ?? scopedPaths.promptsDir,
2793
+ hooksDir: scopedPaths.hooksDir,
2477
2794
  };
2478
2795
  }
2479
2796
  async function listBundleIds() {
@@ -5490,6 +5807,11 @@ async function installBundleArtifacts({ bundleId, manifest, platform, scope, ove
5490
5807
  platformSpec.prompts.length > 0) {
5491
5808
  await mkdir(profilePaths.promptsDir, { recursive: true });
5492
5809
  }
5810
+ if (profilePaths.hooksDir &&
5811
+ Array.isArray(platformSpec.hooks) &&
5812
+ platformSpec.hooks.some((entry) => typeof entry?.file === "string")) {
5813
+ await mkdir(profilePaths.hooksDir, { recursive: true });
5814
+ }
5493
5815
  }
5494
5816
  const bundleRoot = path.join(agentAssetsRoot(), "workflows", bundleId);
5495
5817
  const platformRoot = path.join(bundleRoot, "platforms", platform);
@@ -5501,6 +5823,7 @@ async function installBundleArtifacts({ bundleId, manifest, platform, scope, ove
5501
5823
  skills: [],
5502
5824
  commands: [],
5503
5825
  prompts: [],
5826
+ hooks: [],
5504
5827
  };
5505
5828
  // Bind useSymlinks into copyArtifact so every call site inherits it
5506
5829
  const copyArt = (args) => copyArtifact({ ...args, useSymlinks });
@@ -5594,6 +5917,35 @@ async function installBundleArtifacts({ bundleId, manifest, platform, scope, ove
5594
5917
  else
5595
5918
  installed.push(destination);
5596
5919
  }
5920
+ const hookFiles = Array.isArray(platformSpec.hooks)
5921
+ ? platformSpec.hooks
5922
+ .map((entry) => typeof entry === "string"
5923
+ ? entry
5924
+ : typeof entry?.file === "string"
5925
+ ? entry.file
5926
+ : null)
5927
+ .filter(Boolean)
5928
+ : [];
5929
+ for (const hookFile of hookFiles) {
5930
+ if (!profilePaths.hooksDir)
5931
+ continue;
5932
+ const source = path.join(platformRoot, "hooks", hookFile);
5933
+ const destination = path.join(profilePaths.hooksDir, path.basename(hookFile));
5934
+ if (!(await pathExists(source))) {
5935
+ throw new Error(`Missing hook source file: ${source}`);
5936
+ }
5937
+ const result = await copyArt({
5938
+ source,
5939
+ destination,
5940
+ overwrite,
5941
+ dryRun,
5942
+ });
5943
+ artifacts.hooks.push(destination);
5944
+ if (result.action === "skipped" || result.action === "would-skip")
5945
+ skipped.push(destination);
5946
+ else
5947
+ installed.push(destination);
5948
+ }
5597
5949
  if (shouldInstallPlatformSkills) {
5598
5950
  const agentSkillDependencies = await resolvePlatformAgentSkillDependencies({
5599
5951
  platformRoot,
@@ -5818,6 +6170,20 @@ async function removeBundleArtifacts({ bundleId, manifest, platform, scope, prof
5818
6170
  if (await safeRemove(destination, dryRun))
5819
6171
  removed.push(destination);
5820
6172
  }
6173
+ for (const hookEntry of platformSpec.hooks || []) {
6174
+ if (!profilePaths.hooksDir)
6175
+ continue;
6176
+ const hookFile = typeof hookEntry === "string"
6177
+ ? hookEntry
6178
+ : typeof hookEntry?.file === "string"
6179
+ ? hookEntry.file
6180
+ : null;
6181
+ if (!hookFile)
6182
+ continue;
6183
+ const destination = path.join(profilePaths.hooksDir, path.basename(hookFile));
6184
+ if (await safeRemove(destination, dryRun))
6185
+ removed.push(destination);
6186
+ }
5821
6187
  const skillIds = await resolveInstallSkillIds({
5822
6188
  platformSpec,
5823
6189
  extraSkillIds: [],
@@ -9536,6 +9902,13 @@ async function upsertEngineeringArtifacts({ platform, scope, overwrite = false,
9536
9902
  if (!ruleFilePath)
9537
9903
  throw new Error(`No rule file configured for platform '${platform}'.`);
9538
9904
  const workspaceRoot = findWorkspaceRoot(cwd);
9905
+ const snapshot = await collectTechSnapshot(workspaceRoot);
9906
+ const scaffold = await ensureArchitectureDocScaffold({
9907
+ workspaceRoot,
9908
+ snapshot,
9909
+ overwrite,
9910
+ dryRun,
9911
+ });
9539
9912
  const techMdPath = path.join(workspaceRoot, "TECH.md");
9540
9913
  const targets = [{ ruleFilePath }];
9541
9914
  if (scope === "global") {
@@ -9546,42 +9919,28 @@ async function upsertEngineeringArtifacts({ platform, scope, overwrite = false,
9546
9919
  targets.push({ ruleFilePath: workspaceRuleFile });
9547
9920
  }
9548
9921
  }
9549
- const template = buildEngineeringRulesTemplate();
9550
9922
  const engineeringResults = [];
9551
9923
  for (const target of targets) {
9552
- const rulesFilePath = path.join(path.dirname(target.ruleFilePath), "ENGINEERING_RULES.md");
9553
- const rulesFileResult = await upsertEngineeringRulesFile({
9554
- targetPath: rulesFilePath,
9555
- template,
9556
- overwrite,
9557
- dryRun,
9558
- });
9559
9924
  const blockResult = await upsertEngineeringRulesBlock({
9560
9925
  ruleFilePath: target.ruleFilePath,
9561
9926
  platform,
9562
- engineeringRulesFilePath: rulesFilePath,
9927
+ engineeringRulesFilePath: scaffold.engineeringRulesPath,
9563
9928
  techMdFilePath: techMdPath,
9564
9929
  dryRun,
9565
9930
  });
9566
9931
  engineeringResults.push({
9567
9932
  ruleFilePath: target.ruleFilePath,
9568
- rulesFilePath,
9569
- rulesFileResult,
9933
+ rulesFilePath: scaffold.engineeringRulesPath,
9934
+ rulesFileResult: scaffold.rulesArchitectureResult.action === "unchanged"
9935
+ ? scaffold.rulesFileResult
9936
+ : scaffold.rulesArchitectureResult,
9570
9937
  blockResult,
9571
9938
  });
9572
9939
  }
9573
9940
  let techResult = null;
9574
9941
  if (!skipTech) {
9575
- const snapshot = await collectTechSnapshot(workspaceRoot);
9576
- const content = buildTechMd(snapshot);
9577
- const fileResult = await writeTextFile({
9578
- targetPath: techMdPath,
9579
- content: `${content}\n`,
9580
- overwrite,
9581
- dryRun,
9582
- });
9583
9942
  techResult = {
9584
- ...fileResult,
9943
+ ...scaffold.techArchitectureResult,
9585
9944
  snapshot,
9586
9945
  };
9587
9946
  }
@@ -9657,6 +10016,465 @@ async function runRulesTechMd(options) {
9657
10016
  process.exit(1);
9658
10017
  }
9659
10018
  }
10019
+ function normalizeArchitectureBuildPlatform(value) {
10020
+ const normalized = normalizePlatform(value);
10021
+ if (!normalized || !ARCHITECTURE_BUILD_PLATFORMS.has(normalized)) {
10022
+ throw new Error("Architecture build platform must be one of: codex, claude, gemini, copilot.");
10023
+ }
10024
+ return normalized;
10025
+ }
10026
+ function normalizeArchitectureResearchMode(value) {
10027
+ const normalized = String(value || "auto")
10028
+ .trim()
10029
+ .toLowerCase();
10030
+ if (!["auto", "always", "never"].includes(normalized)) {
10031
+ throw new Error("Research mode must be one of: auto, always, never.");
10032
+ }
10033
+ return normalized;
10034
+ }
10035
+ async function listSpecPackRoots(workspaceRoot) {
10036
+ const specsRoot = path.join(workspaceRoot, "docs", "specs");
10037
+ if (!(await pathExists(specsRoot)))
10038
+ return [];
10039
+ const entries = await readdir(specsRoot, { withFileTypes: true });
10040
+ return entries
10041
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
10042
+ .map((entry) => `docs/specs/${entry.name}`)
10043
+ .sort((a, b) => a.localeCompare(b))
10044
+ .slice(0, 8);
10045
+ }
10046
+ function resolveArchitectureConditionalSkills(snapshot, specRoots, researchMode) {
10047
+ const conditional = [];
10048
+ const frameworks = new Set(snapshot.frameworks || []);
10049
+ const topDirs = new Set(snapshot.topDirs || []);
10050
+ const jsPackages = new Set(snapshot.packageSignals?.javascript || []);
10051
+ if (snapshot.isMcpServer ||
10052
+ frameworks.has("Next.js") ||
10053
+ frameworks.has("NestJS") ||
10054
+ frameworks.has("FastAPI") ||
10055
+ topDirs.has("api") ||
10056
+ topDirs.has("routes") ||
10057
+ topDirs.has("controllers")) {
10058
+ conditional.push("api-design");
10059
+ }
10060
+ if (topDirs.has("db") ||
10061
+ topDirs.has("database") ||
10062
+ topDirs.has("migrations") ||
10063
+ jsPackages.has("prisma") ||
10064
+ jsPackages.has("drizzle-orm") ||
10065
+ frameworks.has("SQLAlchemy")) {
10066
+ conditional.push("database-design");
10067
+ }
10068
+ if (specRoots.length > 0) {
10069
+ conditional.push("sadd");
10070
+ }
10071
+ if (researchMode === "always") {
10072
+ conditional.push("deep-research");
10073
+ }
10074
+ else if (researchMode === "auto" &&
10075
+ !snapshot.readmeExcerpt &&
10076
+ snapshot.architectureByApp.every((item) => (item.architectureSignals || []).length === 0)) {
10077
+ conditional.push("deep-research");
10078
+ }
10079
+ return [...new Set(conditional)];
10080
+ }
10081
+ async function resolveArchitectureSkillPathHints(platform, cwd, skillIds) {
10082
+ const profilePaths = await resolveProfilePaths(platform, "project", cwd);
10083
+ const skillsDir = profilePaths.skillsDir;
10084
+ if (!skillsDir)
10085
+ return [];
10086
+ return skillIds
10087
+ .map((skillId) => path.join(skillsDir, skillId, "SKILL.md"))
10088
+ .map((filePath) => toPosixPath(path.relative(findWorkspaceRoot(cwd), filePath)));
10089
+ }
10090
+ function buildArchitecturePrompt({ platform, workspaceRoot, snapshot, specRoots, researchMode, coreSkills, conditionalSkills, skillPathHints, }) {
10091
+ const rulesPath = "ENGINEERING_RULES.md";
10092
+ const techPath = "TECH.md";
10093
+ const architectureSignals = snapshot.architectureByApp
10094
+ .filter((item) => (item.architectureSignals || []).length > 0)
10095
+ .map((item) => {
10096
+ const label = item.rootPath === "." ? "repo root" : item.rootPath;
10097
+ return `${label}: ${item.architectureSignals.join(", ")}`;
10098
+ });
10099
+ return [
10100
+ `You are running inside ${platform}.`,
10101
+ "",
10102
+ "Objective:",
10103
+ `- Inspect the repository at ${toPosixPath(workspaceRoot)} and refresh the managed architecture sections in ${rulesPath} and ${techPath}.`,
10104
+ "- Keep ENGINEERING_RULES.md normative and TECH.md descriptive.",
10105
+ "- Preserve manual content outside the managed `cbx:architecture:*` markers.",
10106
+ "",
10107
+ "Required skill bundle:",
10108
+ `- Load these exact skill IDs first: ${coreSkills.map((skillId) => `\`${skillId}\``).join(", ")}`,
10109
+ conditionalSkills.length > 0
10110
+ ? `- Additional skills to load now: ${conditionalSkills.map((skillId) => `\`${skillId}\``).join(", ")}`
10111
+ : "- Conditional skills to load now: none",
10112
+ skillPathHints.length > 0
10113
+ ? `- Local skill file hints if installed: ${skillPathHints.map((hint) => `\`${hint}\``).join(", ")}`
10114
+ : "- Local skill file hints if installed: none detected",
10115
+ "- Treat the route and skill bundle as already resolved. Do not begin with route discovery.",
10116
+ "",
10117
+ "Repository context:",
10118
+ `- Frameworks: ${snapshot.frameworks.length > 0 ? snapshot.frameworks.join(", ") : "none detected"}`,
10119
+ `- Top directories: ${snapshot.topDirs.length > 0 ? snapshot.topDirs.join(", ") : "none detected"}`,
10120
+ `- Existing spec packs: ${specRoots.length > 0 ? specRoots.join(", ") : "none detected"}`,
10121
+ architectureSignals.length > 0
10122
+ ? `- Architecture signals: ${architectureSignals.join(" | ")}`
10123
+ : "- Architecture signals: none confidently inferred from the repo scan",
10124
+ "",
10125
+ "Execution contract:",
10126
+ "1. Read ENGINEERING_RULES.md first if present, then read TECH.md.",
10127
+ "2. Inspect the repo before making architecture claims.",
10128
+ "3. Update only the content between the existing `cbx:architecture:rules` and `cbx:architecture:tech` markers.",
10129
+ "4. Keep the marker lines themselves intact, including their hash metadata.",
10130
+ "5. In ENGINEERING_RULES.md, state architecture style, dependency rules, feature or module structure rules, design-system source of truth, testability expectations, and doc refresh policy.",
10131
+ "6. In TECH.md, update architecture snapshot, module or app topology, flow narratives, Mermaid diagrams, and scaling or deployment notes.",
10132
+ researchMode === "never"
10133
+ ? "7. Stay repo-only. Do not use outside research."
10134
+ : "7. Use repo evidence first. Use official docs when needed. Treat Reddit or community sources only as labeled secondary evidence.",
10135
+ researchMode === "always"
10136
+ ? "8. Include an external research evidence subsection in TECH.md with clearly labeled primary and secondary evidence."
10137
+ : "8. Include external research notes only if they materially informed the architecture update.",
10138
+ "9. If the project clearly follows Clean Architecture, feature-first modules, or another stable structure, make that explicit so future implementation stays consistent.",
10139
+ "",
10140
+ "Return one JSON object on the last line with this shape:",
10141
+ '{"files_written":["ENGINEERING_RULES.md","TECH.md"],"research_used":false,"gaps":[],"next_actions":[]}',
10142
+ "",
10143
+ "Do not emit placeholder TODOs in the managed sections.",
10144
+ ].join("\n");
10145
+ }
10146
+ async function execFileCapture(command, args, options = {}) {
10147
+ try {
10148
+ const result = await execFile(command, args, {
10149
+ ...options,
10150
+ maxBuffer: 8 * 1024 * 1024,
10151
+ });
10152
+ return {
10153
+ ok: true,
10154
+ stdout: result.stdout || "",
10155
+ stderr: result.stderr || "",
10156
+ };
10157
+ }
10158
+ catch (error) {
10159
+ if (error?.code === "ENOENT") {
10160
+ throw new Error(`Required CLI '${command}' is not installed or not on PATH.`);
10161
+ }
10162
+ return {
10163
+ ok: false,
10164
+ stdout: error?.stdout || "",
10165
+ stderr: error?.stderr || "",
10166
+ code: error?.code || 1,
10167
+ };
10168
+ }
10169
+ }
10170
+ async function probeArchitectureAdapter(platform, cwd) {
10171
+ if (platform === "codex") {
10172
+ const help = await execFileCapture("codex", ["exec", "--help"], { cwd });
10173
+ return {
10174
+ platform,
10175
+ binary: "codex",
10176
+ helpText: `${help.stdout}\n${help.stderr}`.trim(),
10177
+ buildInvocation(prompt) {
10178
+ const args = ["exec"];
10179
+ if (this.helpText.includes("--skip-git-repo-check")) {
10180
+ args.push("--skip-git-repo-check");
10181
+ }
10182
+ args.push(prompt);
10183
+ return args;
10184
+ },
10185
+ };
10186
+ }
10187
+ if (platform === "claude") {
10188
+ const help = await execFileCapture("claude", ["--help"], { cwd });
10189
+ const helpText = `${help.stdout}\n${help.stderr}`.trim();
10190
+ const printFlag = helpText.includes("--print")
10191
+ ? "--print"
10192
+ : helpText.includes(" -p") || helpText.includes("\n-p")
10193
+ ? "-p"
10194
+ : null;
10195
+ if (!printFlag) {
10196
+ throw new Error("Claude CLI was found, but no headless print mode was detected. Install a Claude Code build that supports --print or -p.");
10197
+ }
10198
+ return {
10199
+ platform,
10200
+ binary: "claude",
10201
+ helpText,
10202
+ buildInvocation(prompt) {
10203
+ return [printFlag, prompt];
10204
+ },
10205
+ };
10206
+ }
10207
+ if (platform === "gemini") {
10208
+ const help = await execFileCapture("gemini", ["--help"], { cwd });
10209
+ const helpText = `${help.stdout}\n${help.stderr}`.trim();
10210
+ const promptFlag = helpText.includes("--prompt")
10211
+ ? "--prompt"
10212
+ : helpText.includes(" -p") || helpText.includes("\n-p")
10213
+ ? "-p"
10214
+ : null;
10215
+ if (!promptFlag) {
10216
+ throw new Error("Gemini CLI was found, but no prompt flag was detected. Install a Gemini CLI build with --prompt or -p support.");
10217
+ }
10218
+ return {
10219
+ platform,
10220
+ binary: "gemini",
10221
+ helpText,
10222
+ buildInvocation(prompt) {
10223
+ return [promptFlag, prompt];
10224
+ },
10225
+ };
10226
+ }
10227
+ const help = await execFileCapture("copilot", ["--help"], { cwd });
10228
+ const helpText = `${help.stdout}\n${help.stderr}`.trim();
10229
+ const supportsPrompt = helpText.includes("--prompt");
10230
+ const supportsChatPrompt = helpText.includes("chat") && helpText.includes("--prompt");
10231
+ if (!supportsPrompt && !supportsChatPrompt) {
10232
+ throw new Error("Copilot CLI was found, but no headless prompt mode was detected. This command requires a native Copilot CLI surface with --prompt support.");
10233
+ }
10234
+ return {
10235
+ platform,
10236
+ binary: "copilot",
10237
+ helpText,
10238
+ buildInvocation(prompt) {
10239
+ if (supportsPrompt)
10240
+ return ["--prompt", prompt];
10241
+ return ["chat", "--prompt", prompt];
10242
+ },
10243
+ };
10244
+ }
10245
+ function normalizeArchitectureResult({ stdout, workspaceRoot, rulesPath, techPath, researchMode, }) {
10246
+ const trimmed = String(stdout || "").trim();
10247
+ if (trimmed) {
10248
+ const lastLine = trimmed.split(/\r?\n/).pop();
10249
+ if (lastLine && lastLine.startsWith("{") && lastLine.endsWith("}")) {
10250
+ try {
10251
+ const parsed = JSON.parse(lastLine);
10252
+ return {
10253
+ outputRoot: workspaceRoot,
10254
+ filesWritten: Array.isArray(parsed.files_written)
10255
+ ? parsed.files_written
10256
+ : [rulesPath, techPath],
10257
+ researchUsed: typeof parsed.research_used === "boolean"
10258
+ ? parsed.research_used
10259
+ : researchMode === "always",
10260
+ gaps: Array.isArray(parsed.gaps) ? parsed.gaps : [],
10261
+ nextActions: Array.isArray(parsed.next_actions)
10262
+ ? parsed.next_actions
10263
+ : [],
10264
+ rawOutput: trimmed,
10265
+ };
10266
+ }
10267
+ catch {
10268
+ // fall through to default normalization
10269
+ }
10270
+ }
10271
+ }
10272
+ return {
10273
+ outputRoot: workspaceRoot,
10274
+ filesWritten: [rulesPath, techPath],
10275
+ researchUsed: researchMode === "always",
10276
+ gaps: [],
10277
+ nextActions: [],
10278
+ rawOutput: trimmed,
10279
+ };
10280
+ }
10281
+ async function readArchitectureDriftStatus(workspaceRoot, snapshot) {
10282
+ const rulesPath = path.join(workspaceRoot, "ENGINEERING_RULES.md");
10283
+ const techPath = path.join(workspaceRoot, "TECH.md");
10284
+ const metadataPath = path.join(workspaceRoot, ".cbx", ARCHITECTURE_BUILD_METADATA_FILENAME);
10285
+ const rulesExists = await pathExists(rulesPath);
10286
+ const techExists = await pathExists(techPath);
10287
+ const expectedRulesHash = hashStableObject(inferArchitectureContractProfile(snapshot));
10288
+ const expectedTechHash = hashStableObject({
10289
+ style: inferArchitectureContractProfile(snapshot).style,
10290
+ topDirs: snapshot.topDirs,
10291
+ frameworks: snapshot.frameworks,
10292
+ architectureByApp: snapshot.architectureByApp,
10293
+ });
10294
+ const findings = [];
10295
+ let actualRulesHash = null;
10296
+ let actualTechHash = null;
10297
+ if (!rulesExists) {
10298
+ findings.push("ENGINEERING_RULES.md is missing.");
10299
+ }
10300
+ else {
10301
+ const content = await readFile(rulesPath, "utf8");
10302
+ actualRulesHash = extractTaggedMarkerAttribute(content, ENGINEERING_ARCHITECTURE_BLOCK_START_RE, "profile");
10303
+ if (!actualRulesHash) {
10304
+ findings.push("ENGINEERING_RULES.md is missing the managed architecture contract block.");
10305
+ }
10306
+ else if (actualRulesHash !== expectedRulesHash) {
10307
+ findings.push(`ENGINEERING_RULES.md architecture profile is stale (expected ${expectedRulesHash}, found ${actualRulesHash}).`);
10308
+ }
10309
+ }
10310
+ if (!techExists) {
10311
+ findings.push("TECH.md is missing.");
10312
+ }
10313
+ else {
10314
+ const content = await readFile(techPath, "utf8");
10315
+ actualTechHash = extractTaggedMarkerAttribute(content, TECH_ARCHITECTURE_BLOCK_START_RE, "snapshot");
10316
+ if (!actualTechHash) {
10317
+ findings.push("TECH.md is missing the managed architecture snapshot block.");
10318
+ }
10319
+ else if (actualTechHash !== expectedTechHash) {
10320
+ findings.push(`TECH.md architecture snapshot is stale (expected ${expectedTechHash}, found ${actualTechHash}).`);
10321
+ }
10322
+ }
10323
+ const metadata = await readJsonFileIfExists(metadataPath);
10324
+ if (!metadata.exists) {
10325
+ findings.push("Architecture build metadata is missing.");
10326
+ }
10327
+ return {
10328
+ stale: findings.length > 0,
10329
+ findings,
10330
+ rulesPath,
10331
+ techPath,
10332
+ metadataPath,
10333
+ expectedRulesHash,
10334
+ expectedTechHash,
10335
+ actualRulesHash,
10336
+ actualTechHash,
10337
+ };
10338
+ }
10339
+ async function runBuildArchitecture(options) {
10340
+ try {
10341
+ const platform = normalizeArchitectureBuildPlatform(options.platform);
10342
+ const researchMode = normalizeArchitectureResearchMode(options.research);
10343
+ const overwrite = Boolean(options.overwrite);
10344
+ const dryRun = Boolean(options.dryRun);
10345
+ const emitJson = Boolean(options.json);
10346
+ const checkOnly = Boolean(options.check);
10347
+ const cwd = process.cwd();
10348
+ const workspaceRoot = findWorkspaceRoot(cwd);
10349
+ const snapshot = await collectTechSnapshot(workspaceRoot);
10350
+ if (checkOnly) {
10351
+ const drift = await readArchitectureDriftStatus(workspaceRoot, snapshot);
10352
+ if (emitJson) {
10353
+ console.log(JSON.stringify(drift, null, 2));
10354
+ }
10355
+ else {
10356
+ console.log(`Platform: ${platform}`);
10357
+ console.log(`Workspace: ${toPosixPath(workspaceRoot)}`);
10358
+ console.log(`Status: ${drift.stale ? "stale" : "fresh"}`);
10359
+ if (drift.findings.length > 0) {
10360
+ console.log("Findings:");
10361
+ for (const finding of drift.findings) {
10362
+ console.log(`- ${finding}`);
10363
+ }
10364
+ }
10365
+ }
10366
+ if (drift.stale)
10367
+ process.exit(1);
10368
+ return;
10369
+ }
10370
+ const scaffold = await ensureArchitectureDocScaffold({
10371
+ workspaceRoot,
10372
+ snapshot,
10373
+ overwrite,
10374
+ dryRun,
10375
+ });
10376
+ const specRoots = await listSpecPackRoots(workspaceRoot);
10377
+ const coreSkills = [
10378
+ "architecture-doc",
10379
+ "system-design",
10380
+ "tech-doc",
10381
+ "frontend-design",
10382
+ ];
10383
+ const conditionalSkills = resolveArchitectureConditionalSkills(snapshot, specRoots, researchMode);
10384
+ const skillBundle = [...coreSkills, ...conditionalSkills];
10385
+ const skillPathHints = await resolveArchitectureSkillPathHints(platform, cwd, skillBundle);
10386
+ const prompt = buildArchitecturePrompt({
10387
+ platform,
10388
+ workspaceRoot,
10389
+ snapshot,
10390
+ specRoots,
10391
+ researchMode,
10392
+ coreSkills,
10393
+ conditionalSkills,
10394
+ skillPathHints,
10395
+ });
10396
+ const adapter = await probeArchitectureAdapter(platform, workspaceRoot);
10397
+ const args = adapter.buildInvocation(prompt);
10398
+ if (dryRun) {
10399
+ const summary = {
10400
+ platform,
10401
+ workspaceRoot: toPosixPath(workspaceRoot),
10402
+ adapter: adapter.binary,
10403
+ invocation: [adapter.binary, ...args],
10404
+ researchMode,
10405
+ managedTargets: [
10406
+ toPosixPath(scaffold.engineeringRulesPath),
10407
+ toPosixPath(scaffold.techMdPath),
10408
+ ],
10409
+ skillBundle,
10410
+ };
10411
+ if (emitJson) {
10412
+ console.log(JSON.stringify(summary, null, 2));
10413
+ }
10414
+ else {
10415
+ console.log(`Platform: ${platform}`);
10416
+ console.log(`Workspace: ${toPosixPath(workspaceRoot)}`);
10417
+ console.log(`Adapter: ${adapter.binary}`);
10418
+ console.log(`Research mode: ${researchMode}`);
10419
+ console.log(`Managed targets: ${toPosixPath(scaffold.engineeringRulesPath)}, ${toPosixPath(scaffold.techMdPath)}`);
10420
+ console.log(`Skill bundle: ${skillBundle.join(", ")}`);
10421
+ console.log(`Invocation: ${[adapter.binary, ...args].join(" ")}`);
10422
+ }
10423
+ return;
10424
+ }
10425
+ const execution = await execFileCapture(adapter.binary, args, {
10426
+ cwd: workspaceRoot,
10427
+ env: process.env,
10428
+ });
10429
+ if (!execution.ok) {
10430
+ throw new Error(`Architecture build failed via ${adapter.binary}. ${String(execution.stderr || execution.stdout || "").trim()}`);
10431
+ }
10432
+ const rulesContent = await readFile(scaffold.engineeringRulesPath, "utf8");
10433
+ const techContent = await readFile(scaffold.techMdPath, "utf8");
10434
+ const metadataPath = path.join(workspaceRoot, ".cbx", ARCHITECTURE_BUILD_METADATA_FILENAME);
10435
+ const metadata = buildArchitectureBuildMetadata({
10436
+ platform,
10437
+ researchMode,
10438
+ rulesProfileHash: extractTaggedMarkerAttribute(rulesContent, ENGINEERING_ARCHITECTURE_BLOCK_START_RE, "profile") || "unknown",
10439
+ techSnapshotHash: extractTaggedMarkerAttribute(techContent, TECH_ARCHITECTURE_BLOCK_START_RE, "snapshot") || "unknown",
10440
+ });
10441
+ await mkdir(path.dirname(metadataPath), { recursive: true });
10442
+ await writeFile(metadataPath, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
10443
+ const result = normalizeArchitectureResult({
10444
+ stdout: execution.stdout,
10445
+ workspaceRoot: toPosixPath(workspaceRoot),
10446
+ rulesPath: "ENGINEERING_RULES.md",
10447
+ techPath: "TECH.md",
10448
+ researchMode,
10449
+ });
10450
+ if (emitJson) {
10451
+ console.log(JSON.stringify({
10452
+ platform,
10453
+ adapter: adapter.binary,
10454
+ skillBundle,
10455
+ result,
10456
+ }, null, 2));
10457
+ return;
10458
+ }
10459
+ console.log(`Platform: ${platform}`);
10460
+ console.log(`Adapter: ${adapter.binary}`);
10461
+ console.log(`Workspace: ${toPosixPath(workspaceRoot)}`);
10462
+ console.log(`Managed docs: ENGINEERING_RULES.md, TECH.md`);
10463
+ console.log(`Skill bundle: ${skillBundle.join(", ")}`);
10464
+ console.log(`Files written: ${(result.filesWritten || []).join(", ") || "(none reported)"}`);
10465
+ console.log(`Research used: ${result.researchUsed ? "yes" : "no"}`);
10466
+ if (result.gaps.length > 0) {
10467
+ console.log(`Gaps: ${result.gaps.join("; ")}`);
10468
+ }
10469
+ if (result.nextActions.length > 0) {
10470
+ console.log(`Next actions: ${result.nextActions.join("; ")}`);
10471
+ }
10472
+ }
10473
+ catch (error) {
10474
+ console.error(`\nError: ${error.message}`);
10475
+ process.exit(1);
10476
+ }
10477
+ }
9660
10478
  function parseCsvOption(value) {
9661
10479
  return String(value || "")
9662
10480
  .split(",")
@@ -9968,6 +10786,7 @@ export function buildCliProgram() {
9968
10786
  defaultMcpDockerContainerName: DEFAULT_MCP_DOCKER_CONTAINER_NAME,
9969
10787
  runRulesInit,
9970
10788
  runRulesTechMd,
10789
+ runBuildArchitecture,
9971
10790
  });
9972
10791
  }
9973
10792
  export async function runCli(argv = process.argv) {