@cubis/foundry 0.3.77 → 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 (206) 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 +787 -25
  6. package/dist/cli/core.js.map +1 -1
  7. package/package.json +4 -3
  8. package/src/cli/build/commands.ts +39 -0
  9. package/src/cli/commands/register.ts +6 -0
  10. package/src/cli/core.ts +960 -28
  11. package/workflows/skills/generated/skill-audit.json +11 -2
  12. package/workflows/skills/generated/skill-catalog.json +38 -4
  13. package/workflows/skills/skills_index.json +34 -0
  14. package/workflows/skills/spec-driven-delivery/SKILL.md +63 -0
  15. package/workflows/workflows/agent-environment-setup/generated/route-manifest.json +117 -4
  16. package/workflows/workflows/agent-environment-setup/manifest.json +21 -0
  17. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/accessibility.toml +10 -5
  18. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/architecture.toml +19 -0
  19. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/backend.toml +10 -5
  20. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/create.toml +10 -5
  21. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/database.toml +10 -5
  22. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/debug.toml +10 -5
  23. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/devops.toml +10 -5
  24. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/implement-track.toml +10 -5
  25. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/migrate.toml +10 -5
  26. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/mobile.toml +10 -5
  27. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/onboard.toml +10 -5
  28. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/orchestrate.toml +10 -5
  29. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/plan.toml +10 -5
  30. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/refactor.toml +10 -5
  31. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/release.toml +10 -5
  32. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/review.toml +10 -5
  33. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/security.toml +10 -5
  34. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/spec.toml +19 -0
  35. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/test.toml +10 -5
  36. package/workflows/workflows/agent-environment-setup/platforms/antigravity/commands/vercel.toml +10 -5
  37. package/workflows/workflows/agent-environment-setup/platforms/antigravity/rules/GEMINI.md +3 -1
  38. package/workflows/workflows/agent-environment-setup/platforms/antigravity/skills/spec-driven-delivery/SKILL.md +65 -0
  39. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/architecture.md +82 -0
  40. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/backend.md +3 -0
  41. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/create.md +4 -1
  42. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/database.md +3 -0
  43. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/implement-track.md +7 -1
  44. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/migrate.md +4 -1
  45. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/mobile.md +3 -0
  46. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/onboard.md +1 -0
  47. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/orchestrate.md +6 -1
  48. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/plan.md +12 -2
  49. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/refactor.md +3 -0
  50. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/release.md +3 -0
  51. package/workflows/workflows/agent-environment-setup/platforms/antigravity/workflows/spec.md +81 -0
  52. package/workflows/workflows/agent-environment-setup/platforms/claude/rules/CLAUDE.md +3 -1
  53. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/skills_index.json +34 -0
  54. package/workflows/workflows/agent-environment-setup/platforms/claude/skills/spec-driven-delivery/SKILL.md +66 -0
  55. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/architecture.md +80 -0
  56. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/backend.md +3 -0
  57. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/create.md +4 -1
  58. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/database.md +3 -0
  59. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/implement-track.md +7 -1
  60. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/migrate.md +4 -1
  61. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/mobile.md +3 -0
  62. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/onboard.md +1 -0
  63. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/orchestrate.md +6 -1
  64. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/plan.md +12 -2
  65. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/refactor.md +3 -0
  66. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/release.md +3 -0
  67. package/workflows/workflows/agent-environment-setup/platforms/claude/workflows/spec.md +79 -0
  68. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/backend-specialist.md +1 -1
  69. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/code-archaeologist.md +1 -1
  70. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/database-architect.md +1 -1
  71. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/debugger.md +1 -1
  72. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/devops-engineer.md +1 -1
  73. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/documentation-writer.md +1 -1
  74. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/frontend-specialist.md +1 -1
  75. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/game-developer.md +1 -1
  76. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/mobile-developer.md +1 -1
  77. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/orchestrator.md +1 -1
  78. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/penetration-tester.md +1 -1
  79. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/performance-optimizer.md +1 -1
  80. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/product-manager.md +1 -1
  81. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/project-planner.md +1 -1
  82. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/qa-automation-engineer.md +1 -1
  83. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/researcher.md +1 -1
  84. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/security-auditor.md +1 -1
  85. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/seo-specialist.md +1 -1
  86. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/sre-engineer.md +1 -1
  87. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/test-engineer.md +1 -1
  88. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/validator.md +1 -1
  89. package/workflows/workflows/agent-environment-setup/platforms/codex/agents/vercel-expert.md +1 -1
  90. package/workflows/workflows/agent-environment-setup/platforms/codex/rules/AGENTS.md +3 -1
  91. package/workflows/workflows/agent-environment-setup/platforms/codex/skills/spec-driven-delivery/SKILL.md +65 -0
  92. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/accessibility.md +1 -1
  93. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/architecture.md +82 -0
  94. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/backend.md +4 -1
  95. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/create.md +5 -2
  96. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/database.md +4 -1
  97. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/debug.md +1 -1
  98. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/devops.md +1 -1
  99. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/implement-track.md +8 -2
  100. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/migrate.md +5 -2
  101. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/mobile.md +4 -1
  102. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/onboard.md +2 -1
  103. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/orchestrate.md +7 -2
  104. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/plan.md +13 -3
  105. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/refactor.md +4 -1
  106. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/release.md +4 -1
  107. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/review.md +1 -1
  108. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/security.md +1 -1
  109. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/spec.md +81 -0
  110. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/test.md +1 -1
  111. package/workflows/workflows/agent-environment-setup/platforms/codex/workflows/vercel.md +1 -1
  112. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-accessibility.prompt.md +9 -4
  113. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-architecture.prompt.md +18 -0
  114. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-backend.prompt.md +9 -4
  115. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-create.prompt.md +9 -4
  116. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-database.prompt.md +9 -4
  117. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-debug.prompt.md +9 -4
  118. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-devops.prompt.md +9 -4
  119. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-implement-track.prompt.md +9 -4
  120. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-migrate.prompt.md +9 -4
  121. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-mobile.prompt.md +9 -4
  122. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-onboard.prompt.md +9 -4
  123. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-orchestrate.prompt.md +9 -4
  124. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-plan.prompt.md +9 -4
  125. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-refactor.prompt.md +9 -4
  126. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-release.prompt.md +9 -4
  127. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-review.prompt.md +9 -4
  128. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-security.prompt.md +9 -4
  129. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-spec.prompt.md +18 -0
  130. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-test.prompt.md +9 -4
  131. package/workflows/workflows/agent-environment-setup/platforms/copilot/prompts/workflow-vercel.prompt.md +9 -4
  132. package/workflows/workflows/agent-environment-setup/platforms/copilot/rules/copilot-instructions.md +3 -1
  133. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/skills_index.json +34 -0
  134. package/workflows/workflows/agent-environment-setup/platforms/copilot/skills/spec-driven-delivery/SKILL.md +70 -0
  135. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/architecture.md +80 -0
  136. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/backend.md +3 -0
  137. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/create.md +4 -1
  138. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/database.md +3 -0
  139. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/implement-track.md +7 -1
  140. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/migrate.md +4 -1
  141. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/mobile.md +3 -0
  142. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/onboard.md +1 -0
  143. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/orchestrate.md +6 -1
  144. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/plan.md +12 -2
  145. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/refactor.md +3 -0
  146. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/release.md +3 -0
  147. package/workflows/workflows/agent-environment-setup/platforms/copilot/workflows/spec.md +79 -0
  148. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/accessibility.toml +10 -5
  149. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/architecture.toml +19 -0
  150. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/backend.toml +10 -5
  151. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/create.toml +10 -5
  152. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/database.toml +10 -5
  153. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/debug.toml +10 -5
  154. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/devops.toml +10 -5
  155. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/implement-track.toml +10 -5
  156. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/migrate.toml +10 -5
  157. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/mobile.toml +10 -5
  158. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/onboard.toml +10 -5
  159. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/orchestrate.toml +10 -5
  160. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/plan.toml +10 -5
  161. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/refactor.toml +10 -5
  162. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/release.toml +10 -5
  163. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/review.toml +10 -5
  164. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/security.toml +10 -5
  165. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/spec.toml +19 -0
  166. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/test.toml +10 -5
  167. package/workflows/workflows/agent-environment-setup/platforms/gemini/commands/vercel.toml +10 -5
  168. package/workflows/workflows/agent-environment-setup/platforms/gemini/rules/GEMINI.md +3 -1
  169. package/workflows/workflows/agent-environment-setup/platforms/gemini/skills/spec-driven-delivery/SKILL.md +65 -0
  170. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/architecture.md +82 -0
  171. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/backend.md +3 -0
  172. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/create.md +4 -1
  173. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/database.md +3 -0
  174. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/implement-track.md +7 -1
  175. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/migrate.md +4 -1
  176. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/mobile.md +3 -0
  177. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/onboard.md +1 -0
  178. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/orchestrate.md +6 -1
  179. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/plan.md +12 -2
  180. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/refactor.md +3 -0
  181. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/release.md +3 -0
  182. package/workflows/workflows/agent-environment-setup/platforms/gemini/workflows/spec.md +81 -0
  183. package/workflows/workflows/agent-environment-setup/shared/agents/backend-specialist.md +5 -5
  184. package/workflows/workflows/agent-environment-setup/shared/agents/database-architect.md +3 -3
  185. package/workflows/workflows/agent-environment-setup/shared/agents/orchestrator.md +8 -8
  186. package/workflows/workflows/agent-environment-setup/shared/agents/penetration-tester.md +3 -3
  187. package/workflows/workflows/agent-environment-setup/shared/agents/product-manager.md +6 -6
  188. package/workflows/workflows/agent-environment-setup/shared/agents/project-planner.md +8 -8
  189. package/workflows/workflows/agent-environment-setup/shared/agents/researcher.md +8 -8
  190. package/workflows/workflows/agent-environment-setup/shared/agents/security-auditor.md +2 -2
  191. package/workflows/workflows/agent-environment-setup/shared/rules/STEERING.md +13 -0
  192. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/codex.md +3 -3
  193. package/workflows/workflows/agent-environment-setup/shared/workflows/architecture.md +80 -0
  194. package/workflows/workflows/agent-environment-setup/shared/workflows/backend.md +8 -5
  195. package/workflows/workflows/agent-environment-setup/shared/workflows/create.md +5 -2
  196. package/workflows/workflows/agent-environment-setup/shared/workflows/database.md +6 -3
  197. package/workflows/workflows/agent-environment-setup/shared/workflows/implement-track.md +12 -6
  198. package/workflows/workflows/agent-environment-setup/shared/workflows/migrate.md +7 -4
  199. package/workflows/workflows/agent-environment-setup/shared/workflows/mobile.md +3 -0
  200. package/workflows/workflows/agent-environment-setup/shared/workflows/onboard.md +6 -5
  201. package/workflows/workflows/agent-environment-setup/shared/workflows/orchestrate.md +10 -5
  202. package/workflows/workflows/agent-environment-setup/shared/workflows/plan.md +17 -7
  203. package/workflows/workflows/agent-environment-setup/shared/workflows/refactor.md +5 -2
  204. package/workflows/workflows/agent-environment-setup/shared/workflows/release.md +3 -0
  205. package/workflows/workflows/agent-environment-setup/shared/workflows/security.md +2 -2
  206. 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",
@@ -215,11 +220,18 @@ const PLAYWRIGHT_MCP_URL = `http://localhost:${PLAYWRIGHT_DEFAULT_PORT}/mcp`;
215
220
  const POSTMAN_WORKSPACE_MANUAL_CHOICE = "__postman_workspace_manual__";
216
221
  const CBX_CONFIG_FILENAME = "cbx_config.json";
217
222
  const CBX_CREDENTIALS_ENV_FILENAME = "credentials.env";
223
+ const ARCHITECTURE_BUILD_METADATA_FILENAME = "architecture-build.json";
218
224
  const LEGACY_POSTMAN_CONFIG_FILENAME = ["postman", "setting.json"].join("_");
219
225
  const DEFAULT_CREDENTIAL_PROFILE_NAME = "default";
220
226
  const RESERVED_CREDENTIAL_PROFILE_NAMES = new Set(["all"]);
221
227
  const CREDENTIAL_SERVICES = new Set(["postman", "stitch"]);
222
228
  const MCP_RUNTIMES = new Set(["docker", "local"]);
229
+ const ARCHITECTURE_BUILD_PLATFORMS = new Set([
230
+ "codex",
231
+ "claude",
232
+ "gemini",
233
+ "copilot",
234
+ ]);
223
235
  const MCP_FALLBACKS = new Set(["local", "fail", "skip"]);
224
236
  const MCP_UPDATE_POLICIES = new Set(["pinned", "latest"]);
225
237
  const DEFAULT_MCP_RUNTIME = "docker";
@@ -838,6 +850,186 @@ function buildAntigravityTerminalVerificationBlock({ provider, powerShellScriptP
838
850
  "<!-- cbx:terminal:verification:end -->",
839
851
  ].join("\n");
840
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
+ }
841
1033
  function buildEngineeringRulesTemplate() {
842
1034
  return [
843
1035
  "# Engineering Rules",
@@ -920,6 +1112,21 @@ function buildEngineeringRulesTemplate() {
920
1112
  "",
921
1113
  "- `TECH.md` is generated from current codebase reality.",
922
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 -->",
923
1130
  "<!-- cbx:engineering:rules:end -->",
924
1131
  "",
925
1132
  ].join("\n");
@@ -942,10 +1149,11 @@ function buildEngineeringRulesManagedBlock({ platform, engineeringRulesFilePath,
942
1149
  "2. Keep architecture simple (KISS) and avoid speculative work (YAGNI).",
943
1150
  "3. Apply SOLID pragmatically to reduce change risk, not add ceremony.",
944
1151
  "4. Use clear naming with focused responsibilities and explicit boundaries.",
945
- "5. Require validation evidence (lint/types/tests) before merge.",
946
- "6. Use Decision Log response style.",
947
- "7. Every Decision Log must include a `Skills Used` section listing skill, workflow, or agent names.",
948
- "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.",
949
1157
  "",
950
1158
  "<!-- cbx:engineering:auto:end -->",
951
1159
  ].join("\n");
@@ -1080,6 +1288,105 @@ async function upsertEngineeringRulesBlock({ ruleFilePath, platform, engineering
1080
1288
  warnings,
1081
1289
  };
1082
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
+ }
1083
1390
  function normalizeTechPackageName(value) {
1084
1391
  if (value === undefined || value === null)
1085
1392
  return null;
@@ -1963,7 +2270,7 @@ function inferRecommendedSkills(snapshot) {
1963
2270
  hasFramework("TypeORM") ||
1964
2271
  hasFramework("Mongoose") ||
1965
2272
  hasFramework("SQLAlchemy")) {
1966
- recommended.add("database-skills");
2273
+ recommended.add("database-design");
1967
2274
  }
1968
2275
  if (recommended.size === 0) {
1969
2276
  recommended.add("clean-code");
@@ -2217,6 +2524,8 @@ function buildTechMd(snapshot, { compact = false } = {}) {
2217
2524
  lines.push(`- Suggested install profile: \`${contextBudget.suggestedProfile}\``);
2218
2525
  lines.push("- Use `--all-skills` only when task scope clearly requires full catalog breadth.");
2219
2526
  lines.push("");
2527
+ lines.push(buildTechArchitectureSection(snapshot).trimEnd());
2528
+ lines.push("");
2220
2529
  if (!compact) {
2221
2530
  lines.push("## Package Signals");
2222
2531
  appendTechPackageSection(lines, "JavaScript / TypeScript (package.json)", snapshot.packageSignals.javascript);
@@ -9593,6 +9902,13 @@ async function upsertEngineeringArtifacts({ platform, scope, overwrite = false,
9593
9902
  if (!ruleFilePath)
9594
9903
  throw new Error(`No rule file configured for platform '${platform}'.`);
9595
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
+ });
9596
9912
  const techMdPath = path.join(workspaceRoot, "TECH.md");
9597
9913
  const targets = [{ ruleFilePath }];
9598
9914
  if (scope === "global") {
@@ -9603,42 +9919,28 @@ async function upsertEngineeringArtifacts({ platform, scope, overwrite = false,
9603
9919
  targets.push({ ruleFilePath: workspaceRuleFile });
9604
9920
  }
9605
9921
  }
9606
- const template = buildEngineeringRulesTemplate();
9607
9922
  const engineeringResults = [];
9608
9923
  for (const target of targets) {
9609
- const rulesFilePath = path.join(path.dirname(target.ruleFilePath), "ENGINEERING_RULES.md");
9610
- const rulesFileResult = await upsertEngineeringRulesFile({
9611
- targetPath: rulesFilePath,
9612
- template,
9613
- overwrite,
9614
- dryRun,
9615
- });
9616
9924
  const blockResult = await upsertEngineeringRulesBlock({
9617
9925
  ruleFilePath: target.ruleFilePath,
9618
9926
  platform,
9619
- engineeringRulesFilePath: rulesFilePath,
9927
+ engineeringRulesFilePath: scaffold.engineeringRulesPath,
9620
9928
  techMdFilePath: techMdPath,
9621
9929
  dryRun,
9622
9930
  });
9623
9931
  engineeringResults.push({
9624
9932
  ruleFilePath: target.ruleFilePath,
9625
- rulesFilePath,
9626
- rulesFileResult,
9933
+ rulesFilePath: scaffold.engineeringRulesPath,
9934
+ rulesFileResult: scaffold.rulesArchitectureResult.action === "unchanged"
9935
+ ? scaffold.rulesFileResult
9936
+ : scaffold.rulesArchitectureResult,
9627
9937
  blockResult,
9628
9938
  });
9629
9939
  }
9630
9940
  let techResult = null;
9631
9941
  if (!skipTech) {
9632
- const snapshot = await collectTechSnapshot(workspaceRoot);
9633
- const content = buildTechMd(snapshot);
9634
- const fileResult = await writeTextFile({
9635
- targetPath: techMdPath,
9636
- content: `${content}\n`,
9637
- overwrite,
9638
- dryRun,
9639
- });
9640
9942
  techResult = {
9641
- ...fileResult,
9943
+ ...scaffold.techArchitectureResult,
9642
9944
  snapshot,
9643
9945
  };
9644
9946
  }
@@ -9714,6 +10016,465 @@ async function runRulesTechMd(options) {
9714
10016
  process.exit(1);
9715
10017
  }
9716
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
+ }
9717
10478
  function parseCsvOption(value) {
9718
10479
  return String(value || "")
9719
10480
  .split(",")
@@ -10025,6 +10786,7 @@ export function buildCliProgram() {
10025
10786
  defaultMcpDockerContainerName: DEFAULT_MCP_DOCKER_CONTAINER_NAME,
10026
10787
  runRulesInit,
10027
10788
  runRulesTechMd,
10789
+ runBuildArchitecture,
10028
10790
  });
10029
10791
  }
10030
10792
  export async function runCli(argv = process.argv) {