@jamie-tam/forge 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/agents/architect.md +92 -0
  4. package/agents/builder.md +122 -0
  5. package/agents/code-reviewer.md +107 -0
  6. package/agents/concept-designer.md +207 -0
  7. package/agents/craft-reviewer.md +132 -0
  8. package/agents/critic.md +130 -0
  9. package/agents/doc-writer.md +85 -0
  10. package/agents/dreamer.md +129 -0
  11. package/agents/e2e-runner.md +89 -0
  12. package/agents/gotcha-hunter.md +127 -0
  13. package/agents/prototype-builder.md +193 -0
  14. package/agents/prototype-codifier.md +204 -0
  15. package/agents/prototype-reviewer.md +163 -0
  16. package/agents/security-reviewer.md +108 -0
  17. package/agents/spec-reviewer.md +94 -0
  18. package/agents/tracer.md +98 -0
  19. package/agents/wireframer.md +109 -0
  20. package/commands/abort.md +25 -0
  21. package/commands/bugfix.md +151 -0
  22. package/commands/evolve.md +118 -0
  23. package/commands/feature.md +236 -0
  24. package/commands/forge.md +100 -0
  25. package/commands/greenfield.md +185 -0
  26. package/commands/hotfix.md +98 -0
  27. package/commands/refactor.md +147 -0
  28. package/commands/resume.md +25 -0
  29. package/commands/setup.md +201 -0
  30. package/commands/status.md +27 -0
  31. package/commands/task-force.md +110 -0
  32. package/commands/validate.md +12 -0
  33. package/dist/__tests__/active-manifest.test.js +272 -0
  34. package/dist/__tests__/copy.test.js +96 -0
  35. package/dist/__tests__/gate-check.test.js +384 -0
  36. package/dist/__tests__/wiki.test.js +472 -0
  37. package/dist/__tests__/work-manifest.test.js +304 -0
  38. package/dist/active-manifest.js +229 -0
  39. package/dist/cli.js +158 -0
  40. package/dist/copy.js +124 -0
  41. package/dist/gate-check.js +326 -0
  42. package/dist/hooks.js +60 -0
  43. package/dist/init.js +140 -0
  44. package/dist/manifest.js +90 -0
  45. package/dist/merge.js +77 -0
  46. package/dist/paths.js +36 -0
  47. package/dist/uninstall.js +216 -0
  48. package/dist/update.js +158 -0
  49. package/dist/verify-manifest.js +65 -0
  50. package/dist/verify.js +98 -0
  51. package/dist/wiki-ui.js +310 -0
  52. package/dist/wiki.js +364 -0
  53. package/dist/work-manifest.js +798 -0
  54. package/hooks/config/gate-requirements.json +79 -0
  55. package/hooks/hooks.json +143 -0
  56. package/hooks/scripts/analyze-telemetry.sh +114 -0
  57. package/hooks/scripts/gate-enforcer.sh +164 -0
  58. package/hooks/scripts/pre-compact.sh +90 -0
  59. package/hooks/scripts/session-start.sh +81 -0
  60. package/hooks/scripts/telemetry.sh +41 -0
  61. package/hooks/scripts/wiki-lint.sh +87 -0
  62. package/hooks/templates/AGENTS.md.template +48 -0
  63. package/hooks/templates/CLAUDE.md.template +45 -0
  64. package/package.json +55 -0
  65. package/protocols/README.md +40 -0
  66. package/protocols/codex.md +151 -0
  67. package/protocols/graphify.md +156 -0
  68. package/references/common/agent-coordination.md +65 -0
  69. package/references/common/coding-standards.md +54 -0
  70. package/references/common/feature-tracking.md +21 -0
  71. package/references/common/io-protocol.md +36 -0
  72. package/references/common/phases.md +57 -0
  73. package/references/common/quality-gates.md +130 -0
  74. package/references/common/skill-authoring.md +154 -0
  75. package/references/common/skill-compliance.md +30 -0
  76. package/references/python/standards.md +44 -0
  77. package/references/react/standards.md +61 -0
  78. package/references/typescript/standards.md +42 -0
  79. package/rules/common/forge-system.md +59 -0
  80. package/rules/common/git-workflow.md +40 -0
  81. package/rules/common/guardrails.md +37 -0
  82. package/rules/common/quality-gates.md +18 -0
  83. package/rules/common/security.md +50 -0
  84. package/rules/common/skill-selection.md +78 -0
  85. package/rules/common/testing.md +58 -0
  86. package/rules/common/verification.md +39 -0
  87. package/skills/build-pr-workflow/SKILL.md +301 -0
  88. package/skills/build-pr-workflow/references/pr-template.md +62 -0
  89. package/skills/build-pr-workflow/references/subagent-merge.md +47 -0
  90. package/skills/build-pr-workflow/references/worktree-setup.md +125 -0
  91. package/skills/build-prototype/SKILL.md +264 -0
  92. package/skills/build-scaffold/SKILL.md +340 -0
  93. package/skills/build-tdd/SKILL.md +89 -0
  94. package/skills/build-wireframe/SKILL.md +110 -0
  95. package/skills/build-wireframe/assets/baseline-template.html +486 -0
  96. package/skills/build-wireframe/references/demo-walkthroughs.md +170 -0
  97. package/skills/build-wireframe/references/gotchas.md +188 -0
  98. package/skills/build-wireframe/references/legend-lines.md +141 -0
  99. package/skills/concept-slides/SKILL.md +192 -0
  100. package/skills/deliver-db-migration/SKILL.md +466 -0
  101. package/skills/deliver-deploy/SKILL.md +407 -0
  102. package/skills/deliver-onboarding/SKILL.md +198 -0
  103. package/skills/deliver-onboarding/references/document-templates.md +393 -0
  104. package/skills/deliver-onboarding/templates/getting-started.md +122 -0
  105. package/skills/discover-codebase-analysis/SKILL.md +448 -0
  106. package/skills/discover-requirements/SKILL.md +418 -0
  107. package/skills/discover-requirements/templates/prd.md +99 -0
  108. package/skills/discover-requirements/templates/technical-spec.md +123 -0
  109. package/skills/discover-requirements/templates/user-stories.md +76 -0
  110. package/skills/harden/SKILL.md +214 -0
  111. package/skills/iterate-prototype/SKILL.md +241 -0
  112. package/skills/plan-architecture/SKILL.md +457 -0
  113. package/skills/plan-architecture/templates/adr-template.md +52 -0
  114. package/skills/plan-architecture/templates/api-contract.md +99 -0
  115. package/skills/plan-architecture/templates/db-schema.md +81 -0
  116. package/skills/plan-architecture/templates/system-design.md +111 -0
  117. package/skills/plan-brainstorm/SKILL.md +433 -0
  118. package/skills/plan-design-system/SKILL.md +279 -0
  119. package/skills/plan-task-decompose/SKILL.md +454 -0
  120. package/skills/quality-code-review/SKILL.md +286 -0
  121. package/skills/quality-security-audit/SKILL.md +292 -0
  122. package/skills/quality-security-audit/references/audit-report-template.md +89 -0
  123. package/skills/quality-security-audit/references/owasp-checks.md +178 -0
  124. package/skills/quality-test-execution/SKILL.md +435 -0
  125. package/skills/quality-test-plan/SKILL.md +297 -0
  126. package/skills/quality-test-plan/references/test-type-guide.md +263 -0
  127. package/skills/quality-test-plan/templates/e2e-test-plan.md +72 -0
  128. package/skills/quality-test-plan/templates/integration-test-plan.md +74 -0
  129. package/skills/quality-test-plan/templates/load-test-plan.md +111 -0
  130. package/skills/quality-test-plan/templates/smoke-test-plan.md +68 -0
  131. package/skills/quality-test-plan/templates/unit-test-plan.md +56 -0
  132. package/skills/quality-uiux/SKILL.md +481 -0
  133. package/skills/support-debug/SKILL.md +464 -0
  134. package/skills/support-dream/SKILL.md +213 -0
  135. package/skills/support-gotcha/SKILL.md +249 -0
  136. package/skills/support-runtime-reachability/SKILL.md +190 -0
  137. package/skills/support-runtime-reachability/scripts/__fixtures__/case-01-passes-app-use/src/app.ts +7 -0
  138. package/skills/support-runtime-reachability/scripts/__fixtures__/case-01-passes-app-use/src/handlers/cases.ts +7 -0
  139. package/skills/support-runtime-reachability/scripts/__fixtures__/case-02-orphan-no-app-use/src/app.ts +8 -0
  140. package/skills/support-runtime-reachability/scripts/__fixtures__/case-02-orphan-no-app-use/src/handlers/cases.ts +7 -0
  141. package/skills/support-runtime-reachability/scripts/__fixtures__/case-03-orphan-import-only/src/App.tsx +5 -0
  142. package/skills/support-runtime-reachability/scripts/__fixtures__/case-03-orphan-import-only/src/components/RingingBanner.tsx +7 -0
  143. package/skills/support-runtime-reachability/scripts/__fixtures__/case-03-orphan-import-only/src/hooks/useTwilio.ts +6 -0
  144. package/skills/support-runtime-reachability/scripts/__fixtures__/case-04-jsx-component-rendered/src/App.tsx +5 -0
  145. package/skills/support-runtime-reachability/scripts/__fixtures__/case-04-jsx-component-rendered/src/components/MyComp.tsx +3 -0
  146. package/skills/support-runtime-reachability/scripts/__fixtures__/case-05-jsx-component-not-rendered/src/App.tsx +3 -0
  147. package/skills/support-runtime-reachability/scripts/__fixtures__/case-05-jsx-component-not-rendered/src/components/Orphan.tsx +3 -0
  148. package/skills/support-runtime-reachability/scripts/__fixtures__/case-06-class-instantiated/src/lib/Service.ts +6 -0
  149. package/skills/support-runtime-reachability/scripts/__fixtures__/case-06-class-instantiated/src/main.ts +4 -0
  150. package/skills/support-runtime-reachability/scripts/__fixtures__/case-07-class-not-instantiated/src/lib/Lonely.ts +5 -0
  151. package/skills/support-runtime-reachability/scripts/__fixtures__/case-07-class-not-instantiated/src/main.ts +2 -0
  152. package/skills/support-runtime-reachability/scripts/__fixtures__/case-08-default-export-imported-and-called/src/handler.ts +3 -0
  153. package/skills/support-runtime-reachability/scripts/__fixtures__/case-08-default-export-imported-and-called/src/main.ts +3 -0
  154. package/skills/support-runtime-reachability/scripts/__fixtures__/case-09-default-export-orphan/src/handler.ts +3 -0
  155. package/skills/support-runtime-reachability/scripts/__fixtures__/case-09-default-export-orphan/src/main.ts +2 -0
  156. package/skills/support-runtime-reachability/scripts/__fixtures__/case-10-aliased-named-export/src/lib.ts +5 -0
  157. package/skills/support-runtime-reachability/scripts/__fixtures__/case-10-aliased-named-export/src/main.ts +3 -0
  158. package/skills/support-runtime-reachability/scripts/__fixtures__/case-11-re-export-chain/src/lib/index.ts +1 -0
  159. package/skills/support-runtime-reachability/scripts/__fixtures__/case-11-re-export-chain/src/lib/internal.ts +3 -0
  160. package/skills/support-runtime-reachability/scripts/__fixtures__/case-11-re-export-chain/src/main.ts +3 -0
  161. package/skills/support-runtime-reachability/scripts/__fixtures__/case-12-test-only-caller/src/util.test.ts +5 -0
  162. package/skills/support-runtime-reachability/scripts/__fixtures__/case-12-test-only-caller/src/util.ts +3 -0
  163. package/skills/support-runtime-reachability/scripts/__fixtures__/case-13-gated-pending-annotation/src/future.ts +4 -0
  164. package/skills/support-runtime-reachability/scripts/__fixtures__/case-14-untraceable-annotation/src/decorated.ts +4 -0
  165. package/skills/support-runtime-reachability/scripts/__fixtures__/case-15-untraceable-empty/src/lazy.ts +4 -0
  166. package/skills/support-runtime-reachability/scripts/__fixtures__/case-16-python-module/src/lib.py +15 -0
  167. package/skills/support-runtime-reachability/scripts/__fixtures__/case-16-python-module/src/main.py +5 -0
  168. package/skills/support-runtime-reachability/scripts/__fixtures__/case-17-router-use/src/parent.ts +5 -0
  169. package/skills/support-runtime-reachability/scripts/__fixtures__/case-17-router-use/src/routes/cases.ts +5 -0
  170. package/skills/support-runtime-reachability/scripts/__fixtures__/case-18-shadowed-name-fp/src/lib/foo.ts +3 -0
  171. package/skills/support-runtime-reachability/scripts/__fixtures__/case-18-shadowed-name-fp/src/other.ts +8 -0
  172. package/skills/support-runtime-reachability/scripts/__fixtures__/case-19-same-name-different-module/src/handlers/cases.ts +4 -0
  173. package/skills/support-runtime-reachability/scripts/__fixtures__/case-19-same-name-different-module/src/handlers/users.ts +4 -0
  174. package/skills/support-runtime-reachability/scripts/__fixtures__/case-19-same-name-different-module/src/main.ts +5 -0
  175. package/skills/support-runtime-reachability/scripts/__fixtures__/case-20-aliased-import-usage/src/handlers/cases.ts +3 -0
  176. package/skills/support-runtime-reachability/scripts/__fixtures__/case-20-aliased-import-usage/src/main.ts +4 -0
  177. package/skills/support-runtime-reachability/scripts/__fixtures__/case-21-mixed-default-and-named/src/lib.ts +5 -0
  178. package/skills/support-runtime-reachability/scripts/__fixtures__/case-21-mixed-default-and-named/src/main.ts +5 -0
  179. package/skills/support-runtime-reachability/scripts/__fixtures__/case-22-dynamic-import-then-caller/src/lib.ts +3 -0
  180. package/skills/support-runtime-reachability/scripts/__fixtures__/case-22-dynamic-import-then-caller/src/main.ts +8 -0
  181. package/skills/support-runtime-reachability/scripts/__fixtures__/case-23-dynamic-import-with-space/src/lib.ts +3 -0
  182. package/skills/support-runtime-reachability/scripts/__fixtures__/case-23-dynamic-import-with-space/src/main.ts +7 -0
  183. package/skills/support-runtime-reachability/scripts/check.mjs +638 -0
  184. package/skills/support-runtime-reachability/scripts/check.test.mjs +244 -0
  185. package/skills/support-skill-validator/SKILL.md +194 -0
  186. package/skills/support-skill-validator/references/false-positives.md +59 -0
  187. package/skills/support-skill-validator/references/validation-checks.md +280 -0
  188. package/skills/support-system-guide/SKILL.md +311 -0
  189. package/skills/support-task-force/SKILL.md +265 -0
  190. package/skills/support-task-force/references/dispatch-pattern.md +178 -0
  191. package/skills/support-task-force/references/synthesis-template.md +126 -0
  192. package/skills/support-wiki-bootstrap/SKILL.md +37 -0
  193. package/skills/support-wiki-lint/SKILL.md +196 -0
  194. package/skills/support-wiki-lint/scripts/lint.mjs +488 -0
  195. package/skills/support-wiki-lint/scripts/lint.test.mjs +196 -0
  196. package/templates/README.md +23 -0
  197. package/templates/aiwiki/CLAUDE.md.template +78 -0
  198. package/templates/aiwiki/schemas/architecture.md +118 -0
  199. package/templates/aiwiki/schemas/convention.md +112 -0
  200. package/templates/aiwiki/schemas/decision.md +144 -0
  201. package/templates/aiwiki/schemas/gotcha.md +118 -0
  202. package/templates/aiwiki/schemas/oracle.md +105 -0
  203. package/templates/aiwiki/schemas/session.md +125 -0
  204. package/templates/manifests/bugfix.yaml +41 -0
  205. package/templates/manifests/feature.yaml +69 -0
  206. package/templates/manifests/greenfield.yaml +61 -0
  207. package/templates/manifests/hotfix.yaml +45 -0
  208. package/templates/manifests/refactor.yaml +44 -0
  209. package/templates/manifests/v5/SCHEMA.md +327 -0
  210. package/templates/manifests/v5/feature.yaml +77 -0
  211. package/templates/manifests/v6/SCHEMA.md +199 -0
  212. package/templates/wiki-html/dream-detail.html +378 -0
  213. package/templates/wiki-html/dreams-list.html +155 -0
@@ -0,0 +1,457 @@
1
+ ---
2
+ name: plan-architecture
3
+ description: "Use when the user has an approved approach and asks for technical artifacts: API contracts, DB schemas, system diagrams, sequence diagrams, component layout. Triggers on 'design the API', 'sketch the architecture', 'data model', 'schema for', 'how should the components fit'. For prototype-driven work, harden produces architecture from the prototype — use this skill only for library/internal-tool/refactor work where prototype/wireframe phases were skipped."
4
+ ---
5
+
6
+ # Plan Architecture
7
+
8
+ **When this skill is the wrong fit:** v6 prototype-driven flow uses the `harden` skill at Phase 5 (codify) to extract architecture from a locked prototype — citation-bound, not invented. The architecture files land in `aiwiki/architecture/` and ADRs in `aiwiki/decisions/`. This skill is the non-prototype fallback that invents architecture upfront from an approved brainstorm; use it only when prototype/wireframe phases don't apply.
9
+
10
+ **Boundary with plan-brainstorm:** Brainstorming produces a high-level design with no code. This skill translates that design into precise technical artifacts. Code examples in architecture artifacts (JSON schemas, SQL DDL, ASCII diagrams, type definitions) are specification artifacts, not implementation code. They define contracts that implementation must follow.
11
+
12
+ **Announce at start:** "I'm using the plan-architecture skill to generate technical artifacts from the approved design."
13
+
14
+ When this skill is invoked: do NOT proceed to task decomposition or implementation until all architecture artifacts are complete and have ZERO TBDs. Every endpoint, every schema column, every error code must be defined. Ambiguity here becomes bugs later. (The gate applies to this skill's flow; prototype-driven flow handles architecture differently via `harden`.)
15
+
16
+ ---
17
+
18
+ ## I/O Contract
19
+
20
+ | Field | Value |
21
+ |---|---|
22
+ | **Requires** | `brainstorm-approved.md` (approved design — produced by `plan-brainstorm` in the non-prototype fallback flow). `codebase-analysis.md` (if existing project). `DESIGN.md` at project root (if frontend — from `plan-design-system`). |
23
+ | **Produces** | `.forge/work/{type}/{name}/architecture/api-contract.md`, `.forge/work/{type}/{name}/architecture/db-schema.md`, `.forge/work/{type}/{name}/architecture/system-diagram.md`, `.forge/work/{type}/{name}/architecture/frontend-architecture.md` (if frontend) |
24
+ | **Feeds into** | `plan-task-decompose`, `build-tdd`, `quality-test-plan` |
25
+ | **Updates manifest** | `artifacts.api-contract`, `artifacts.db-schema`, `artifacts.system-diagram`, `artifacts.frontend-architecture` (if frontend) |
26
+
27
+ ---
28
+
29
+ ## Checklist
30
+
31
+ Complete these steps in order:
32
+
33
+ 1. **Review approved design** -- read brainstorm-approved.md, codebase analysis, and DESIGN.md at project root (if frontend)
34
+ 2. **Generate API contracts** -- endpoints, methods, types, errors, auth
35
+ 3. **Generate DB schema** -- tables, columns, constraints, indexes, relationships
36
+ 4. **Generate system diagrams** -- ASCII format component and sequence diagrams
37
+ 5. **Generate frontend architecture** -- (if frontend) page shells, component boundaries, token implementation
38
+ 6. **Record architectural decisions** -- ADRs for every new pattern choice
39
+ 7. **Resolve all TBDs** -- no ambiguity allowed
40
+ 8. **User review** -- present artifacts for approval
41
+ 9. **Update feature manifest** -- record artifact paths and approval
42
+ 10. **Transition to task decomposition** -- invoke plan-task-decompose
43
+
44
+ ---
45
+
46
+ ## Agent Dispatch
47
+
48
+ Dispatch the **architect** subagent (Opus) to generate the technical artifacts. The architect agent specializes in system design decisions, tradeoff analysis, and produces higher-quality architecture. The architect determines the appropriate depth of analysis based on the complexity of the design.
49
+
50
+ ---
51
+
52
+ ## Process
53
+
54
+ ### Step 1: Review Approved Design
55
+
56
+ Read the inputs thoroughly before generating any artifacts:
57
+
58
+ **From brainstorm-approved.md:**
59
+ - Architecture overview -- what components exist, how they communicate
60
+ - Data model -- entities, relationships, storage decisions
61
+ - API design -- endpoints, interfaces, auth approach
62
+ - Error handling strategy -- how errors propagate
63
+ - Testing strategy -- what test types are needed
64
+
65
+ **From codebase-analysis.md (if existing project):**
66
+ - Existing API patterns -- follow them unless the design explicitly deviates
67
+ - Existing database patterns -- ORM style, naming conventions, migration approach
68
+ - Existing conventions -- naming, types, error handling patterns
69
+ - Flagged risks -- address them in the architecture
70
+
71
+ **From DESIGN.md at project root (if frontend feature):**
72
+ - Design tokens (colors, typography, spacing) -- inform component contracts
73
+ - Layout structure -- page shells, sidebar widths, breakpoints
74
+ - Component conventions -- button sizes, input heights, card patterns
75
+
76
+ **From decision log (aiwiki/decisions/):**
77
+ - Prior architectural decisions that apply to this feature
78
+ - Patterns already established that should be followed
79
+
80
+ ### Step 1.5: Codex Mode Check
81
+
82
+ Now that the approved design and context are reviewed, run the Codex consent flow from `protocols/codex.md`. The selected mode applies for the rest of this skill's invocation.
83
+
84
+ - **Takeover:** Dispatch Codex with the design, codebase analysis, and decision log to generate API contracts, DB schema, and system diagrams. Claude reviews and writes ADRs.
85
+ - **Verify** or **Skip / Codex unavailable:** Proceed with the steps below. Step 6.5 will dispatch Codex to verify Claude's architecture artifacts (Verify only).
86
+
87
+ ### Step 2: Generate API Contracts
88
+
89
+ Write comprehensive API contracts to `.forge/work/{type}/{name}/architecture/api-contract.md`.
90
+
91
+ Use `templates/api-contract.md` as the format. For each endpoint, the contract MUST define: purpose, auth, rate limiting, full request schema (with per-field type + constraints), success response shape, and all applicable error codes with response schema.
92
+
93
+ Rules for API contracts:
94
+
95
+ - **No vague types.** Never use "object", "any", "mixed", or "data". Every field has a specific type.
96
+ - **Every endpoint has error responses.** At minimum: 400, 401, 404, 500. Add 403, 409, 422 where applicable.
97
+ - **Every field has constraints.** String length limits, numeric ranges, enum values, format patterns.
98
+ - **Pagination defined.** If an endpoint returns lists, define the pagination contract (cursor vs offset, page size limits, response envelope).
99
+ - **Versioning noted.** If the project uses API versioning, specify the version.
100
+ - **Follow existing patterns.** If the codebase analysis found a specific API style, match it exactly.
101
+
102
+ ### Step 2b: Verify External Service Contracts
103
+
104
+ For every external service the system integrates with (STT, LLM, payment APIs, third-party SDKs, etc.):
105
+
106
+ 1. **Identify** all external services from the brainstorm-approved design
107
+ 2. **Attempt automated connectivity** — hit a read-only or idempotent endpoint (health check, GET, list) with a 5-second timeout. Never call endpoints that create resources, trigger payments, or have side effects.
108
+ 3. **If reachable** — compare the actual response structure (field names, types, nesting) against what you are writing in the contract. **If there is a mismatch, update the contract to match reality — not the other way around.**
109
+ 4. **If not reachable** — verify the API contract via official documentation (context7 MCP or web search). Document the source of truth.
110
+ 5. **Record in the contract** which endpoints were verified by real call vs documentation only:
111
+
112
+ ```markdown
113
+ ## External Service Verification
114
+
115
+ | Service | Endpoint | Verified By | Response Shape Confirmed |
116
+ |---|---|---|---|
117
+ | Payment API | POST /v1/charges | Real call ✓ | response shape confirmed |
118
+ | Email Service | POST /v3/mail/send | Documentation only | sendgrid.com/docs |
119
+ ```
120
+
121
+ **Why:** Wrong contracts produce wrong mocks, which produce passing tests against a broken integration. A single real call here catches mismatches before any implementation code is written.
122
+
123
+ ### Step 3: Generate DB Schema
124
+
125
+ Write database schema changes to `.forge/work/{type}/{name}/architecture/db-schema.md`.
126
+
127
+ Use `templates/db-schema.md` as the format. Every table needs: columns (type, nullability, default), indexes, foreign keys (with ON DELETE/UPDATE), and constraints.
128
+
129
+ Rules for DB schema:
130
+
131
+ - **Every column has a type, nullability, and default.** No ambiguity.
132
+ - **Every foreign key has ON DELETE and ON UPDATE behavior.** CASCADE, RESTRICT, SET NULL -- choose explicitly.
133
+ - **Indexes for every foreign key.** And for columns used in WHERE, ORDER BY, or JOIN clauses.
134
+ - **Unique constraints documented.** What combinations must be unique?
135
+ - **Migration direction.** Note whether this is a new table, adding columns, or modifying existing columns.
136
+ - **Data migration notes.** If existing data needs transformation, document the strategy.
137
+ - **Follow existing conventions.** If the codebase uses snake_case table names, follow suit. If it uses a specific ORM, match its conventions.
138
+
139
+ ### Step 4: Generate System Diagrams
140
+
141
+ Write ASCII diagrams to `.forge/work/{type}/{name}/architecture/system-diagram.md`.
142
+
143
+ Use `templates/system-design.md` for complex multi-service architectures. Use ASCII box-and-arrow diagrams:
144
+
145
+ ```
146
+ ┌────────┐ ┌─────┐ ┌─────────┐ ┌────────────┐
147
+ │ Client │────>│ API │────>│ Service │────>│ Database │
148
+ └────────┘ └─────┘ └────┬────┘ └────────────┘
149
+
150
+ v
151
+ ┌──────────────┐
152
+ │ External API │
153
+ └──────────────┘
154
+ ```
155
+
156
+ At minimum: component diagram for structure, sequence diagram for flows touching 3+ components, ER diagram if DB changes exist.
157
+
158
+ Rules for diagrams:
159
+
160
+ - **At least one component diagram.** Shows how the new feature fits in the system.
161
+ - **Sequence diagrams for complex flows.** If an operation touches 3+ components, diagram it.
162
+ - **ER diagram if DB changes exist.** Shows relationships between tables.
163
+ - **Label all connections.** Arrows without labels are meaningless.
164
+ - **Keep it readable.** Maximum ~15 nodes per diagram. Split into multiple diagrams if needed.
165
+ - **ASCII only.** Diagrams must be readable in any context — terminal, editor, agent prompt, GitHub.
166
+
167
+ ### Step 4.5: Generate Frontend Architecture (Frontend Features Only)
168
+
169
+ If `DESIGN.md` exists at the project root, write frontend architecture to `.forge/work/{type}/{name}/architecture/frontend-architecture.md`. This captures the technical consequences of the visual direction — how the design tokens are realized structurally in code.
170
+
171
+ **Contents:**
172
+
173
+ - **Page and layout shell structure** — which components own the page-level layout (header, sidebar, main content area), how they compose, responsive behavior at each breakpoint from DESIGN.md
174
+ - **Component boundaries and shared primitives** — which components are shared (Button, Card, Input), which are page-specific, component hierarchy
175
+ - **Token implementation strategy** — how design tokens from DESIGN.md become code: CSS custom properties, Tailwind config values, theme provider, or styled-components theme object
176
+ - **CSS framework integration** — how the chosen framework (from DESIGN.md) integrates with the component tree: utility classes, CSS modules scope, styled-components ThemeProvider
177
+ - **State ownership for UI concerns** — which components own theme state, sidebar collapse, responsive breakpoint detection, modal stacking
178
+ - **Accessibility constraints** — ARIA landmark structure, focus management strategy, keyboard navigation flow across page shells
179
+
180
+ If no `DESIGN.md` exists (backend-only feature), skip this step.
181
+
182
+ ### Step 5: Record Architectural Decisions
183
+
184
+ For every new pattern choice, technology selection, or significant design decision, create an Architecture Decision Record (ADR) in `aiwiki/decisions/`.
185
+
186
+ Use the template from `templates/adr-template.md` if available. ADR format:
187
+
188
+ ```markdown
189
+ # ADR-{number}: {Title}
190
+
191
+ **Date:** YYYY-MM-DD
192
+ **Status:** Accepted
193
+ **Feature:** {feature name}
194
+
195
+ ## Context
196
+ {What is the issue that we're seeing that is motivating this decision?}
197
+
198
+ ## Decision
199
+ {What is the change that we're proposing and/or doing?}
200
+
201
+ ## Consequences
202
+
203
+ ### Positive
204
+ - {Benefit 1}
205
+ - {Benefit 2}
206
+
207
+ ### Negative
208
+ - {Tradeoff 1}
209
+ - {Tradeoff 2}
210
+
211
+ ### Neutral
212
+ - {Side effect that is neither positive nor negative}
213
+
214
+ ## Alternatives Considered
215
+ {Brief summary of alternatives and why they were rejected}
216
+ ```
217
+
218
+ Rules for ADRs:
219
+
220
+ - **One ADR per decision.** Do not bundle unrelated decisions.
221
+ - **Number sequentially.** Check existing ADRs and increment.
222
+ - **Reference from architecture docs.** API contracts and schemas should link to relevant ADRs.
223
+ - **Decisions are immutable.** If a decision is reversed, create a new ADR that supersedes the old one. Never edit a past ADR.
224
+ - **Every new pattern choice gets an ADR.** Choosing a validation library, selecting a caching strategy, picking a pagination approach -- these all merit ADRs.
225
+
226
+ ### Step 6: Resolve All TBDs
227
+
228
+ Before presenting artifacts to the user, scan every document for:
229
+
230
+ - "TBD", "TODO", "TBC", "to be determined", "to be decided"
231
+ - Placeholder values ("xxx", "???", "FIXME")
232
+ - Vague language ("some kind of", "probably", "might need")
233
+
234
+ **Every instance must be resolved.** If you cannot resolve it from the approved design, ask the user:
235
+
236
+ > "I found an unresolved decision in the architecture: {description}. Before I can finalize, I need to know: {specific question with options}."
237
+
238
+ Do not proceed to user review with any TBDs remaining.
239
+
240
+ ### Step 6.5: Critic Review of Architecture
241
+
242
+ Before presenting architecture artifacts to the user, dispatch the **critic** subagent (Opus) to review all artifacts for completeness, feasibility, and gaps. Provide the critic with the brainstorm-approved design, the generated API contracts, DB schema, system diagrams, and decision records.
243
+
244
+ If the critic identifies gaps or TBDs, resolve them before proceeding to user review.
245
+
246
+ **Codex Verify:** Check the mode recorded at Step 1.5. If **Verify** was selected, dispatch Codex alongside the critic to review artifacts for internal consistency, feasibility gaps, missing error cases, and scalability concerns. If **Takeover** was selected, skip this step (Codex already generated the artifacts). If **Skip**, do nothing. Do NOT re-run the consent flow.
247
+
248
+ #### Graphify Context (Optional)
249
+
250
+ **Protocol:** `protocols/graphify.md` | **Guard:** Run the status check from the protocol before Step 1.
251
+
252
+ Graph communities map directly to bounded contexts, and god nodes identify components needing explicit interface contracts.
253
+
254
+ **How graph data maps to this skill:**
255
+ - **Communities** → candidate bounded contexts when defining component boundaries
256
+ - **God nodes** → components that need explicit interface contracts
257
+ - **Community boundaries** → proposed component boundaries should align with graph communities
258
+
259
+ **CLI queries** (if graph exists and CLI available):
260
+ - `graphify query "how does [subsystem A] connect to [subsystem B]" --budget 1500 --graph graphify-out/graph.json` — verify proposed component boundaries match actual dependencies
261
+
262
+ **Codex bridge:** Pass community-informed architecture context to the Codex verify step below.
263
+
264
+ #### Codex Integration
265
+
266
+ **Modes:** Verify or Takeover | **Protocol:** `protocols/codex.md`
267
+
268
+ - **Verify:** Claude generates architecture artifacts, Codex reviews for gaps.
269
+ - **Takeover:** Codex generates API contracts and DB schema, Claude reviews and generates diagrams/ADRs.
270
+
271
+ **When:** Step 6.5 — after architecture artifacts are generated, alongside the critic review (sequential, not parallel).
272
+
273
+ **Context to pass:**
274
+ - Path to `brainstorm-approved.md`
275
+ - Path to `architecture/api-contract.md`
276
+ - Path to `architecture/db-schema.md`
277
+ - Path to `architecture/system-diagram.md`
278
+ - Path to `architecture/frontend-architecture.md` (if present)
279
+
280
+ **What Codex reviews:**
281
+ - Internal consistency (API shapes match DB columns, diagrams match contracts)
282
+ - Feasibility gaps (hand-waving over hard problems)
283
+ - Missing error cases or edge conditions
284
+ - Scalability concerns not addressed
285
+
286
+ **Prompt focus:** "Review these architecture artifacts against the approved design. Check internal consistency, missing error cases, and feasibility gaps. Report specific inconsistencies with file paths and line references."
287
+
288
+ **Presentation:** Present alongside Claude critic findings. Highlight any disagreements between critics.
289
+
290
+ ### Step 7: User Review
291
+
292
+ Present all artifacts to the user for review:
293
+
294
+ > "Architecture artifacts generated:
295
+ >
296
+ > 1. **API Contract** -- `.forge/work/{type}/{name}/architecture/api-contract.md`
297
+ > - {N} endpoints defined
298
+ > - All error responses specified
299
+ >
300
+ > 2. **DB Schema** -- `.forge/work/{type}/{name}/architecture/db-schema.md`
301
+ > - {N} tables ({new/modified})
302
+ > - {N} indexes, {N} foreign keys
303
+ >
304
+ > 3. **System Diagrams** -- `.forge/work/{type}/{name}/architecture/system-diagram.md`
305
+ > - Component diagram showing {scope}
306
+ > - Sequence diagrams for {key flows}
307
+ >
308
+ > 4. **Frontend Architecture** (if frontend) -- `.forge/work/{type}/{name}/architecture/frontend-architecture.md`
309
+ > - Page shells, component boundaries, token implementation strategy
310
+ >
311
+ > 5. **Decisions** -- {N} ADRs recorded in `aiwiki/decisions/`
312
+ >
313
+ > Please review these artifacts. API contracts in particular will become the binding specification for implementation -- any issues should be caught now."
314
+
315
+ Wait for user approval. If changes are requested, make them and re-present.
316
+
317
+ ### Step 8: Update Feature Manifest
318
+
319
+ After approval, update `.forge/work/{type}/{name}/manifest.yaml`:
320
+
321
+ ```yaml
322
+ artifacts:
323
+ api-contract:
324
+ path: architecture/api-contract.md
325
+ status: approved
326
+ approved_at: YYYY-MM-DD
327
+ endpoint_count: N
328
+ db-schema:
329
+ path: architecture/db-schema.md
330
+ status: approved
331
+ approved_at: YYYY-MM-DD
332
+ table_count: N
333
+ new_tables: N
334
+ modified_tables: N
335
+ system-diagram:
336
+ path: architecture/system-diagram.md
337
+ status: approved
338
+ approved_at: YYYY-MM-DD
339
+ diagram_count: N
340
+ decisions:
341
+ - ADR-{N}: {title}
342
+ ```
343
+
344
+ ### Step 9: Transition
345
+
346
+ After the user approves all artifacts, architecture is complete. The calling command determines the next step.
347
+
348
+ ---
349
+
350
+ ## Key Rules
351
+
352
+ 1. **API contracts are BINDING.** Once approved, they are the source of truth for implementation. Subagents implement exactly what the contract specifies. Changes require re-approval.
353
+ 2. **NO TBDs allowed.** Every field, every type, every error code must be defined before proceeding. Ambiguity in architecture becomes bugs in implementation.
354
+ 3. **Every new pattern goes in the decision log.** Choosing a library, defining an error format, selecting a pagination approach -- all merit an ADR.
355
+ 4. **Reference existing conventions.** If codebase-analysis found specific patterns (naming, types, error handling), the architecture MUST follow them unless the approved design explicitly deviates.
356
+ 5. **Diagrams use ASCII.** Renders in GitHub, VS Code, and documentation tools without additional tooling.
357
+ 6. **Error responses are mandatory.** Every endpoint must define its error responses. "Happy path only" contracts are incomplete.
358
+ 7. **Constraints on every field.** String length, numeric range, enum values, format patterns. No unbounded types.
359
+ 8. **Follow existing DB conventions.** If the project uses an ORM, match its naming and type conventions.
360
+
361
+ ---
362
+
363
+ ## Anti-Patterns
364
+
365
+ | Anti-Pattern | Why It Is Wrong | What To Do Instead |
366
+ |---|---|---|
367
+ | **Leaving endpoints undefined** | Implementors will guess, and guess differently | Define every endpoint completely |
368
+ | **Using vague types** | "object" and "any" are not types | Specify exact shape with field types |
369
+ | **Skipping error responses** | Errors are the majority of real-world API traffic | Define every error: status, code, message, when |
370
+ | **No constraints on fields** | "string" allows empty strings, SQL injection, 10MB payloads | Add length limits, format patterns, allowed values |
371
+ | **TBDs in delivered artifacts** | "We'll figure it out during implementation" means rework | Resolve everything before handoff |
372
+ | **Ignoring existing patterns** | New API style in an old codebase creates maintenance debt | Match existing patterns from codebase analysis |
373
+ | **Monolithic diagrams** | 50-node diagram is unreadable | Split into focused diagrams, max ~15 nodes each |
374
+ | **Decisions without ADRs** | Future developers won't know why choices were made | Record every significant decision |
375
+
376
+ ---
377
+
378
+ ## Artifact Dependencies
379
+
380
+ ```
381
+ brainstorm-approved.md ─────────────────────────────────────┐
382
+ | |
383
+ +── api-contract.md (endpoints, types, errors) |
384
+ | |
385
+ +── db-schema.md (tables, columns, indexes) |
386
+ | |
387
+ +── system-diagram.md (component, sequence, ER) |
388
+ | |
389
+ +── aiwiki/decisions/ADR-*.md (one per decision) |
390
+ | |
391
+ DESIGN.md at project root (if frontend) ────────────────────┤
392
+ | |
393
+ +── frontend-architecture.md (page shells, |
394
+ component boundaries, token implementation) |
395
+ | |
396
+ v v
397
+ plan-task-decompose (consumes all of the above)
398
+ ```
399
+
400
+ All architecture artifacts must be internally consistent:
401
+
402
+ - API response shapes must match DB schema columns
403
+ - Sequence diagrams must match API contract endpoints
404
+ - ER diagrams must match DB schema tables and relationships
405
+ - ADRs must align with choices made in contracts and schemas
406
+
407
+ ---
408
+
409
+ ## Handling Special Cases
410
+
411
+ ### No Database Changes
412
+
413
+ If the feature does not require DB changes, skip the db-schema.md artifact and note in the manifest:
414
+
415
+ ```yaml
416
+ artifacts:
417
+ db-schema:
418
+ status: not-applicable
419
+ reason: "Feature does not require database changes"
420
+ ```
421
+
422
+ ### No API Changes
423
+
424
+ If the feature is purely internal (background job, refactoring, etc.), skip the api-contract.md and note in the manifest:
425
+
426
+ ```yaml
427
+ artifacts:
428
+ api-contract:
429
+ status: not-applicable
430
+ reason: "Feature does not expose new API endpoints"
431
+ ```
432
+
433
+ ### Existing API Modifications
434
+
435
+ If modifying existing endpoints, document both the current and new state:
436
+
437
+ ```markdown
438
+ ### PUT /api/users/{id} (MODIFIED)
439
+
440
+ **Change:** Adding `role` field to request and response
441
+
442
+ **Current request body:**
443
+ {existing shape}
444
+
445
+ **New request body:**
446
+ {new shape with additions highlighted}
447
+
448
+ **Migration:** Backward compatible -- `role` is optional with default 'member'
449
+ ```
450
+
451
+ ### Complex Multi-Service Architecture
452
+
453
+ If the feature spans multiple services:
454
+ 1. Create separate API contract sections per service
455
+ 2. Document inter-service communication (sync vs async, protocol, error handling)
456
+ 3. Sequence diagrams for cross-service flows
457
+ 4. Note deployment order dependencies
@@ -0,0 +1,52 @@
1
+ # ADR-{number}: {Title}
2
+
3
+ ## Status
4
+
5
+ {Proposed / Accepted / Deprecated / Superseded}
6
+
7
+ {If superseded: Superseded by [ADR-{number}](./ADR-{number}.md)}
8
+
9
+ ## Date
10
+
11
+ {YYYY-MM-DD}
12
+
13
+ ## Context
14
+
15
+ {What is the issue that we are seeing that is motivating this decision or change? What is the technical, business, or project context? What constraints exist?}
16
+
17
+ ## Decision
18
+
19
+ {What is the change that we are proposing and/or doing? State the decision clearly and concisely.}
20
+
21
+ ## Consequences
22
+
23
+ ### Positive
24
+ - {Benefit 1}
25
+ - {Benefit 2}
26
+ - {Benefit 3}
27
+
28
+ ### Negative
29
+ - {Cost or downside 1}
30
+ - {Cost or downside 2}
31
+
32
+ ### Neutral
33
+ - {Side effect or observation that is neither good nor bad}
34
+
35
+ ## Alternatives Considered
36
+
37
+ ### Alternative 1: {name}
38
+ - **Description**: {what this alternative would look like}
39
+ - **Pros**: {advantages}
40
+ - **Cons**: {disadvantages}
41
+ - **Why rejected**: {specific reason this was not chosen}
42
+
43
+ ### Alternative 2: {name}
44
+ - **Description**: {what this alternative would look like}
45
+ - **Pros**: {advantages}
46
+ - **Cons**: {disadvantages}
47
+ - **Why rejected**: {specific reason this was not chosen}
48
+
49
+ ## References
50
+
51
+ - {Link to relevant documentation, discussion, or research}
52
+ - {Link to prototype or proof of concept if applicable}
@@ -0,0 +1,99 @@
1
+ # API Contract
2
+
3
+ ## Endpoint: {METHOD} {/path}
4
+
5
+ ### Description
6
+ {What this endpoint does in one sentence.}
7
+
8
+ ### Authentication
9
+ - **Required**: Yes / No
10
+ - **Method**: Bearer token / API key / Session cookie / None
11
+ - **Permissions**: {required roles or scopes}
12
+
13
+ ### Request
14
+
15
+ #### Headers
16
+ | Header | Required | Description |
17
+ |--------|----------|-------------|
18
+ | Authorization | Yes | Bearer {token} |
19
+ | Content-Type | Yes | application/json |
20
+ | X-Request-ID | No | Client-generated request ID for tracing |
21
+
22
+ #### Path Parameters
23
+ | Parameter | Type | Description |
24
+ |-----------|------|-------------|
25
+ | {param} | {type} | {description} |
26
+
27
+ #### Query Parameters
28
+ | Parameter | Type | Required | Default | Description |
29
+ |-----------|------|----------|---------|-------------|
30
+ | {param} | {type} | {Yes/No} | {default} | {description} |
31
+
32
+ #### Request Body
33
+ ```json
34
+ {
35
+ "field_name": "string — Description of this field",
36
+ "nested_object": {
37
+ "inner_field": "number — Description of this field"
38
+ },
39
+ "optional_field?": "string — This field is optional"
40
+ }
41
+ ```
42
+
43
+ **Validation Rules**:
44
+ - `field_name`: {min/max length, format, allowed values}
45
+ - `nested_object.inner_field`: {range, constraints}
46
+
47
+ ### Response
48
+
49
+ #### Success Response (200 / 201)
50
+ ```json
51
+ {
52
+ "data": {
53
+ "id": "uuid — Unique identifier",
54
+ "field_name": "string — Description",
55
+ "created_at": "ISO 8601 timestamp"
56
+ }
57
+ }
58
+ ```
59
+
60
+ #### Error Responses
61
+
62
+ | Status | Error Code | Description | Response Body |
63
+ |--------|-----------|-------------|---------------|
64
+ | 400 | VALIDATION_ERROR | Invalid request body | `{"error": {"code": "VALIDATION_ERROR", "message": "...", "details": [{"field": "...", "issue": "..."}]}}` |
65
+ | 401 | UNAUTHORIZED | Missing or invalid auth token | `{"error": {"code": "UNAUTHORIZED", "message": "..."}}` |
66
+ | 403 | FORBIDDEN | Insufficient permissions | `{"error": {"code": "FORBIDDEN", "message": "..."}}` |
67
+ | 404 | NOT_FOUND | Resource does not exist | `{"error": {"code": "NOT_FOUND", "message": "..."}}` |
68
+ | 409 | CONFLICT | Resource already exists | `{"error": {"code": "CONFLICT", "message": "..."}}` |
69
+ | 429 | RATE_LIMITED | Too many requests | `{"error": {"code": "RATE_LIMITED", "message": "...", "retry_after": 60}}` |
70
+ | 500 | INTERNAL_ERROR | Server error | `{"error": {"code": "INTERNAL_ERROR", "message": "..."}}` |
71
+
72
+ ### Example
73
+
74
+ #### Request
75
+ ```bash
76
+ curl -X {METHOD} {base_url}{/path} \
77
+ -H "Authorization: Bearer {token}" \
78
+ -H "Content-Type: application/json" \
79
+ -d '{
80
+ "field_name": "example value"
81
+ }'
82
+ ```
83
+
84
+ #### Response
85
+ ```json
86
+ {
87
+ "data": {
88
+ "id": "550e8400-e29b-41d4-a716-446655440000",
89
+ "field_name": "example value",
90
+ "created_at": "2025-01-15T10:30:00Z"
91
+ }
92
+ }
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Endpoint: {METHOD} {/next-path}
98
+
99
+ {Repeat the same structure for each endpoint.}