@v11g/agents-rock 1.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 (223) hide show
  1. package/README.md +65 -0
  2. package/bin/agents-rock.mjs +4 -0
  3. package/package.json +13 -0
  4. package/plugins/solution-architect/.claude-plugin/plugin.json +9 -0
  5. package/plugins/solution-architect/skills/analyze-requirements/README.md +75 -0
  6. package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +31 -0
  7. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/OFL.txt +98 -0
  8. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  9. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-mono-latin-600-normal.woff2 +0 -0
  10. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  11. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-500-normal.woff2 +0 -0
  12. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-600-normal.woff2 +0 -0
  13. package/plugins/solution-architect/skills/analyze-requirements/assets/mermaid-theme.json +52 -0
  14. package/plugins/solution-architect/skills/analyze-requirements/assets/section-help.json +101 -0
  15. package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +2389 -0
  16. package/plugins/solution-architect/skills/analyze-requirements/references/interview.md +53 -0
  17. package/plugins/solution-architect/skills/analyze-requirements/references/likec4.md +157 -0
  18. package/plugins/solution-architect/skills/analyze-requirements/references/project-types.md +60 -0
  19. package/plugins/solution-architect/skills/analyze-requirements/references/research.md +78 -0
  20. package/plugins/solution-architect/skills/analyze-requirements/references/viewer.md +772 -0
  21. package/plugins/solution-architect/skills/analyze-requirements/references/writing.md +206 -0
  22. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/cdp.mjs +74 -0
  23. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/chrome.mjs +66 -0
  24. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/companion-links.mjs +20 -0
  25. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-kinds.mjs +37 -0
  26. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-links.mjs +26 -0
  27. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-routes.mjs +27 -0
  28. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-sections.mjs +78 -0
  29. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/embed.mjs +8 -0
  30. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/er-entities.mjs +16 -0
  31. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/fonts.mjs +39 -0
  32. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/frontmatter.mjs +17 -0
  33. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/inputs.mjs +41 -0
  34. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-config.mjs +41 -0
  35. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-extract.mjs +29 -0
  36. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-steps.mjs +22 -0
  37. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-defs.mjs +20 -0
  38. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-flows.mjs +46 -0
  39. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-inline.mjs +31 -0
  40. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-links.mjs +7 -0
  41. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-list.mjs +64 -0
  42. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-render.mjs +127 -0
  43. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-shape.mjs +19 -0
  44. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-tables.mjs +30 -0
  45. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-views.mjs +48 -0
  46. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-wide.mjs +44 -0
  47. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/nav.mjs +72 -0
  48. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/offline.mjs +19 -0
  49. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/port.mjs +13 -0
  50. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/quality-gate.mjs +113 -0
  51. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/section-help.mjs +49 -0
  52. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/slug-registry.mjs +11 -0
  53. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-clusters.mjs +15 -0
  54. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-deployment.mjs +8 -0
  55. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-elections.mjs +20 -0
  56. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-links.mjs +23 -0
  57. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-model-tables.mjs +24 -0
  58. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-palette.mjs +34 -0
  59. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-provenance.mjs +20 -0
  60. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-tree.mjs +16 -0
  61. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-config.mjs +19 -0
  62. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-export.mjs +35 -0
  63. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-gen.mjs +39 -0
  64. package/plugins/solution-architect/skills/analyze-requirements/scripts/render.mjs +130 -0
  65. package/plugins/solution-architect/skills/analyze-requirements/scripts/serve.mjs +71 -0
  66. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/browser.test.mjs +553 -0
  67. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/companion-links.test.mjs +60 -0
  68. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-kinds.test.mjs +41 -0
  69. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-links.test.mjs +104 -0
  70. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-routes.test.mjs +54 -0
  71. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-sections.test.mjs +197 -0
  72. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/embed.test.mjs +28 -0
  73. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/er-entities.test.mjs +14 -0
  74. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/ARCHITECTURE.md +47 -0
  75. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/c4-src/broken/model.c4 +27 -0
  76. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/c4-src/pass/model.c4 +29 -0
  77. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/adr/0001-sample.md +18 -0
  78. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/estimate.html +2 -0
  79. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/estimation.md +8 -0
  80. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/model-broken.json +1 -0
  81. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/model.json +1 -0
  82. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/threat-model.md +8 -0
  83. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/sample-model.json +1 -0
  84. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/sample.c4 +28 -0
  85. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fonts.test.mjs +38 -0
  86. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/frontmatter.test.mjs +27 -0
  87. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/inputs.test.mjs +72 -0
  88. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-config-cli.test.mjs +26 -0
  89. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-config.test.mjs +74 -0
  90. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-export-cli.test.mjs +61 -0
  91. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-extract.test.mjs +37 -0
  92. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-gen-cli.test.mjs +73 -0
  93. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-steps.test.mjs +32 -0
  94. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-flows.test.mjs +82 -0
  95. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-links.test.mjs +16 -0
  96. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-provenance.test.mjs +42 -0
  97. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-render.test.mjs +226 -0
  98. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-tables.test.mjs +30 -0
  99. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-views.test.mjs +76 -0
  100. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-wide.test.mjs +76 -0
  101. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/nav.test.mjs +236 -0
  102. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/offline.test.mjs +37 -0
  103. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gate.test.mjs +86 -0
  104. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gates.test.mjs +20 -0
  105. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/render.test.mjs +171 -0
  106. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/research-workflow.test.mjs +38 -0
  107. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/section-help.test.mjs +101 -0
  108. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/serve.test.mjs +48 -0
  109. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-clusters.test.mjs +46 -0
  110. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-deployment.test.mjs +23 -0
  111. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-elections.test.mjs +30 -0
  112. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-links.test.mjs +38 -0
  113. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-model-tables.test.mjs +51 -0
  114. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-provenance.test.mjs +28 -0
  115. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-tree.test.mjs +43 -0
  116. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/viewer-template.test.mjs +1206 -0
  117. package/plugins/solution-architect/skills/analyze-requirements/scripts/validate.mjs +88 -0
  118. package/plugins/solution-architect/skills/analyze-requirements/workflows/research.js +57 -0
  119. package/plugins/solution-architect/skills/estimate/README.md +67 -0
  120. package/plugins/solution-architect/skills/estimate/SKILL.md +64 -0
  121. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +1128 -0
  122. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +95 -0
  123. package/plugins/solution-architect/skills/estimate/references/interview.md +80 -0
  124. package/plugins/solution-architect/skills/estimate/references/slicing.md +55 -0
  125. package/plugins/solution-architect/skills/estimate/references/techniques.md +111 -0
  126. package/plugins/solution-architect/skills/estimate/references/writing.md +211 -0
  127. package/plugins/solution-architect/skills/estimate/scripts/compute.mjs +23 -0
  128. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +128 -0
  129. package/plugins/solution-architect/skills/estimate/scripts/lib/components.mjs +19 -0
  130. package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +85 -0
  131. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +10 -0
  132. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +30 -0
  133. package/plugins/solution-architect/skills/estimate/scripts/lib/roadmap.mjs +32 -0
  134. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +122 -0
  135. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +128 -0
  136. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +65 -0
  137. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +623 -0
  138. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +88 -0
  139. package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +34 -0
  140. package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +112 -0
  141. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +58 -0
  142. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +30 -0
  143. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +60 -0
  144. package/plugins/solution-architect/skills/estimate/scripts/test/quality-gates.test.mjs +20 -0
  145. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +71 -0
  146. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +121 -0
  147. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +129 -0
  148. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +72 -0
  149. package/plugins/solution-architect/skills/estimate/scripts/validate.mjs +20 -0
  150. package/plugins/solution-architect/skills/new-lead/README.md +48 -0
  151. package/plugins/solution-architect/skills/new-lead/SKILL.md +113 -0
  152. package/plugins/solution-architect/skills/new-lead/assets/dashboard/detail.html +842 -0
  153. package/plugins/solution-architect/skills/new-lead/assets/dashboard/index.html +655 -0
  154. package/plugins/solution-architect/skills/new-lead/assets/dashboard/start.sh +3 -0
  155. package/plugins/solution-architect/skills/new-lead/assets/dashboard/stats.mjs +98 -0
  156. package/plugins/solution-architect/skills/new-lead/assets/dashboard/vendor/reactflow-bundle.js +473 -0
  157. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/entry.jsx +33 -0
  158. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/package-lock.json +1055 -0
  159. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/package.json +19 -0
  160. package/plugins/solution-architect/skills/new-lead/scripts/init-root.mjs +73 -0
  161. package/plugins/solution-architect/skills/new-lead/scripts/lead-upsert.mjs +31 -0
  162. package/plugins/solution-architect/skills/new-lead/scripts/lib/enrich.mjs +20 -0
  163. package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +124 -0
  164. package/plugins/solution-architect/skills/new-lead/scripts/lib/map.mjs +117 -0
  165. package/plugins/solution-architect/skills/new-lead/scripts/lib/port.mjs +15 -0
  166. package/plugins/solution-architect/skills/new-lead/scripts/lib/registry.mjs +116 -0
  167. package/plugins/solution-architect/skills/new-lead/scripts/serve.mjs +163 -0
  168. package/plugins/solution-architect/skills/new-lead/scripts/test/e2e-workspace.test.mjs +59 -0
  169. package/plugins/solution-architect/skills/new-lead/scripts/test/enrich.test.mjs +16 -0
  170. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/ARCHITECTURE.md +16 -0
  171. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/brief.md +4 -0
  172. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/index.html +11 -0
  173. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/proposal-non-tech.html +2 -0
  174. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/threat-model.html +2 -0
  175. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/estimation-inputs.json +6 -0
  176. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/estimation.json +10 -0
  177. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/notes.md +3 -0
  178. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/proposal-non-tech.md +3 -0
  179. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/rfp.md +3 -0
  180. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads.json +25 -0
  181. package/plugins/solution-architect/skills/new-lead/scripts/test/init-root.test.mjs +81 -0
  182. package/plugins/solution-architect/skills/new-lead/scripts/test/lead-upsert.test.mjs +67 -0
  183. package/plugins/solution-architect/skills/new-lead/scripts/test/map.test.mjs +72 -0
  184. package/plugins/solution-architect/skills/new-lead/scripts/test/port.test.mjs +31 -0
  185. package/plugins/solution-architect/skills/new-lead/scripts/test/registry-io.test.mjs +57 -0
  186. package/plugins/solution-architect/skills/new-lead/scripts/test/registry.test.mjs +49 -0
  187. package/plugins/solution-architect/skills/new-lead/scripts/test/serve.test.mjs +205 -0
  188. package/plugins/solution-architect/skills/new-lead/scripts/test/stats.test.mjs +92 -0
  189. package/plugins/solution-architect/skills/new-lead/scripts/test/validate-cli.test.mjs +24 -0
  190. package/plugins/solution-architect/skills/new-lead/scripts/test/vendor-bundle.test.mjs +9 -0
  191. package/plugins/solution-architect/skills/new-lead/scripts/validate.mjs +9 -0
  192. package/plugins/solution-architect/skills/proposal/README.md +36 -0
  193. package/plugins/solution-architect/skills/proposal/SKILL.md +58 -0
  194. package/plugins/solution-architect/skills/proposal/assets/proposal-template.html +82 -0
  195. package/plugins/solution-architect/skills/proposal/references/interview.md +63 -0
  196. package/plugins/solution-architect/skills/proposal/references/review.md +28 -0
  197. package/plugins/solution-architect/skills/proposal/references/writing.md +102 -0
  198. package/plugins/solution-architect/skills/proposal/scripts/derive.mjs +22 -0
  199. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-client.mjs +75 -0
  200. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-doc.mjs +54 -0
  201. package/plugins/solution-architect/skills/proposal/scripts/lib/checks.mjs +17 -0
  202. package/plugins/solution-architect/skills/proposal/scripts/lib/figures.mjs +43 -0
  203. package/plugins/solution-architect/skills/proposal/scripts/lib/jargon.mjs +9 -0
  204. package/plugins/solution-architect/skills/proposal/scripts/lib/sections.mjs +32 -0
  205. package/plugins/solution-architect/skills/proposal/scripts/render.mjs +60 -0
  206. package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +144 -0
  207. package/plugins/solution-architect/skills/proposal/scripts/test/checks-doc.test.mjs +93 -0
  208. package/plugins/solution-architect/skills/proposal/scripts/test/docs.test.mjs +51 -0
  209. package/plugins/solution-architect/skills/proposal/scripts/test/e2e.test.mjs +30 -0
  210. package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +81 -0
  211. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-fail.md +22 -0
  212. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-pass.md +55 -0
  213. package/plugins/solution-architect/skills/proposal/scripts/test/quality-gates.test.mjs +20 -0
  214. package/plugins/solution-architect/skills/proposal/scripts/test/render.test.mjs +70 -0
  215. package/plugins/solution-architect/skills/proposal/scripts/test/validate.test.mjs +40 -0
  216. package/plugins/solution-architect/skills/proposal/scripts/validate.mjs +20 -0
  217. package/src/cli/agents.mjs +12 -0
  218. package/src/cli/args.mjs +46 -0
  219. package/src/cli/install.mjs +68 -0
  220. package/src/cli/main.mjs +124 -0
  221. package/src/cli/picker.mjs +78 -0
  222. package/src/cli/registry.mjs +26 -0
  223. package/src/cli/uninstall.mjs +38 -0
@@ -0,0 +1,206 @@
1
+ # Writing — spine contract, one-home-per-fact, src-column rules
2
+
3
+ Read during the writing phase (SKILL.md step 5), after research completes.
4
+ This file is the writer's single source for ARCHITECTURE.md's structure and
5
+ for the conventions every companion and mattpocock-convention file follows.
6
+
7
+ ## 1. The 16-heading spine
8
+
9
+ Copied verbatim from spec §3.1 — this is the fixed structure. Headings never
10
+ change; a non-applicable section renders `Not applicable — <reason>`
11
+ (`project-types.md` owns per-type table-column variants and elections):
12
+
13
+ **How to write these as markdown.** The table below separates the number from the
14
+ title for readability; the heading itself carries both, as `## 1 Goals and Scope`.
15
+ Real sets also spell out "and" where this table prints "&". Both spellings are
16
+ accepted — the viewer's section explainers normalise the heading before looking up
17
+ their text (`scripts/lib/section-help.mjs`, `normTitle`), dropping the leading
18
+ number and folding `&` to `and`, so numbering that shifts when a section is
19
+ omitted cannot misalign them. The number is presentation, never a key.
20
+
21
+ ```
22
+ frontmatter: name · repo · team · updated · mode · projectType · docVersion · electedDocs
23
+
24
+ 1 Goals & Scope
25
+ 2 Constraints
26
+ 3 Project Structure brownfield only: fs-generated tree depth ≤2 + boundary map
27
+ 4 Solution Strategy ≤5 bullets, each links an ADR, never restates rationale
28
+ 5 Architecture Model LikeC4 C1/C2/C3 views, no prose
29
+ 6 Core Components table: responsibility, tech, deploy unit, key paths, context, invariants
30
+ 7 Runtime Behaviour 2–4 LikeC4 dynamic views, named flows only
31
+ 8 Data Stores mermaid ER + table: type, purpose, retention, PII, migration tool
32
+ 9 External Integrations table: method, auth + credential home, failure mode, rate limit/cost,
33
+ data leaving boundary, lock-in
34
+ 10 Deployment & Infrastructure LikeC4 deployment view + per-env table + CI/CD stage table
35
+ 11 Crosscutting Concepts observability, error handling, validation, config/secrets,
36
+ auth mechanics, testing strategy
37
+ 12 Security mermaid DFD + trust boundaries, authz model, link to threat model
38
+ 13 Quality Requirements & SLOs
39
+ 14 Decisions generated index of docs/adr/ (root + per-context)
40
+ 15 Risks & Technical Debt
41
+ 16 Glossary generated from all CONTEXT.md files; omitted if <5 terms, and says so
42
+ ```
43
+
44
+ ### 1a. Why "arc42 + 2", not more
45
+
46
+ arc42 has 12 chapters. Only one of them draws a seam that matches ours: Context
47
+ and Scope (Ch3) has two named subsections in arc42 itself, 3.1 Business context
48
+ and 3.2 Technical context, and we give each its own heading (§1, §9) — that
49
+ split is arc42's, not ours. Building Block View (Ch5) and Crosscutting Concepts
50
+ (Ch8) are different: arc42 subsections Ch5 by decomposition level (5.1/5.2/5.3),
51
+ each level mixing diagram and blackbox description together, not by a
52
+ diagram-vs-table seam; and Ch8 mentions security only in one inline example
53
+ sentence next to a topic diagram, never as a named subsection. Pulling
54
+ Architecture Model apart from Core Components, and Security out of Crosscutting
55
+ Concepts, are choices *we* made, not seams arc42 drew. They're still splits and
56
+ not new content — both halves of each still trace back to the same arc42
57
+ chapter — so neither counts toward the "+2": both splits are ours, not arc42's.
58
+ Only two of our sixteen have no arc42 chapter behind them at all — those two
59
+ are what `README.md`'s "arc42 + 2 additions" means.
60
+
61
+ | # | our heading | arc42 chapter | relationship |
62
+ |---|---|---|---|
63
+ | 1 | Goals & Scope | Ch1 Introduction and Goals + Ch3 Context and Scope (3.1 Business context) | merge |
64
+ | 2 | Constraints | Ch2 Constraints | direct |
65
+ | 3 | Project Structure | none | **addition** — no arc42 chapter documents repo/filesystem layout |
66
+ | 4 | Solution Strategy | Ch4 Solution Strategy | direct |
67
+ | 5 | Architecture Model | Ch5 Building Block View | split (ours); Ch5's own subsections are its decomposition levels (5.1/5.2/5.3); shares Ch5 with §6 |
68
+ | 6 | Core Components | Ch5 Building Block View | split (ours), shares Ch5 with §5 |
69
+ | 7 | Runtime Behaviour | Ch6 Runtime View | direct |
70
+ | 8 | Data Stores | none | **addition** — no arc42 chapter addresses data stores or ER models at all |
71
+ | 9 | External Integrations | Ch3 Context and Scope (3.2 Technical context) | split (arc42's own seam), shares Ch3 with §1 |
72
+ | 10 | Deployment & Infrastructure | Ch7 Deployment View | direct |
73
+ | 11 | Crosscutting Concepts | Ch8 Crosscutting Concepts | split (ours — security is one inline example here, not a subsection), shares Ch8 with §12 |
74
+ | 12 | Security | Ch8 Crosscutting Concepts | split (ours), shares Ch8 with §11 |
75
+ | 13 | Quality Requirements & SLOs | Ch10 Quality Requirements | direct |
76
+ | 14 | Decisions | Ch9 Architecture Decisions | direct |
77
+ | 15 | Risks & Technical Debt | Ch11 Risks and Technical Debt | direct |
78
+ | 16 | Glossary | Ch12 Glossary | direct |
79
+
80
+ Count: 16 headings, 3 splits (Ch3, Ch5, Ch8 each backing two), 2 with no
81
+ counterpart (Project Structure, Data Stores) → arc42's 12 + 2 additions.
82
+
83
+ Contract notes, verbatim:
84
+
85
+ - The ER diagram is not the domain model. ER = persistence shape; domain =
86
+ concepts and invariants. They legitimately differ (event sourcing, CQRS).
87
+ Two diagrams, two homes.
88
+ - Contested facts have one home: observability → §11 · auth mechanics → §11,
89
+ auth model → §12 · threat list → threat-model doc · decision rationale →
90
+ ADR files · debt → §15.
91
+ - Every table row carries a `src` column: `observed` / `stated` /
92
+ `researched [link]` / `proposed`. Prose facts carry an inline tag.
93
+ Diagrams carry a view-level provenance note.
94
+
95
+ ## 2. One home per fact
96
+
97
+ Diagrams own topology, tables own properties, prose owns neither. Before
98
+ writing a fact anywhere, check the router below — writing the same fact in
99
+ two homes is a defect, not redundancy:
100
+
101
+ | contested fact | home |
102
+ |---|---|
103
+ | Observability | §11 Crosscutting Concepts |
104
+ | Auth mechanics (how auth works) | §11 Crosscutting Concepts |
105
+ | Auth model (who is allowed to do what) | §12 Security |
106
+ | Threat list | threat-model.md |
107
+ | Decision rationale | ADR files (§4 bullets link, never restate) |
108
+ | Technical debt | §15 Risks & Technical Debt |
109
+
110
+ ## 3. Table format rules
111
+
112
+ - Leading **and** trailing pipes on every row: `| cell | cell |`, never a
113
+ bare `cell | cell`.
114
+ - `src` is the last column, header spelled exactly `src` (the provenance
115
+ validator looks up that literal header name).
116
+ - Values are one of the four provenance words: `observed` · `stated` ·
117
+ `researched` · `proposed`. `researched` is always followed by a bracketed
118
+ source: `researched [source]`.
119
+ - Generated-index tables are exempt: `Decisions` (§14) and `Glossary` (§16)
120
+ carry no `src` column — they're derived from `docs/adr/` and `CONTEXT.md`
121
+ files, not asserted facts.
122
+
123
+ ## 3b. Diagram embed convention
124
+
125
+ - **LikeC4 views**: a marker on its own line, `<!-- likec4:view <view-id> -->`.
126
+ The renderer swaps it for the interactive `<c4-view>` webcomponent. Used in
127
+ §5 (C1/C2/C3), §7 (runtime dynamic views), §10 (deployment view).
128
+ - **Mermaid**: stays in fenced ` ```mermaid ` blocks, rendered as static
129
+ diagrams per `viewer.md`'s mermaid rules. Used in §8 (ER) and §12 (security
130
+ DFD) — the only two sections that use mermaid instead of LikeC4.
131
+
132
+ Never mix the two for the same view: a LikeC4-modeled view always uses the
133
+ marker, never a hand-drawn mermaid equivalent.
134
+
135
+ ## 3c. Key paths ↔ clusters (brownfield)
136
+
137
+ The §6 "key paths" column holds **file paths** (comma-separated), never symbol
138
+ names. The brownfield validator matches each path against the `packages` of
139
+ the `get_architecture` clusters — a row matches a cluster when one of its key
140
+ paths equals a cluster package or sits under it (`backend/src` matches package
141
+ `backend`). Every high-cohesion cluster needs a matching row, and every §6 row
142
+ needs a matching cluster — except rows that name a §8 data store (MongoDB has
143
+ no functions, so it can never match a cluster and is exempt).
144
+
145
+ ## 4. Frontmatter contract
146
+
147
+ Fields: `name · repo · team · updated · mode · projectType · docVersion ·
148
+ electedDocs`. `electedDocs` is a **one-line JSON array**, one entry per
149
+ companion doc, each `{ name, elected, reason? }`. Exact convention (from
150
+ Task 7's fixture, `scripts/test/fixtures/docs-pass/ARCHITECTURE.md`):
151
+
152
+ ```yaml
153
+ ---
154
+ electedDocs: [{"name":"threat-model","elected":false,"reason":"CLI-only fixture, no external attack surface"},{"name":"interface-contract","elected":false,"reason":"no public API exposed by this fixture"},{"name":"estimation","elected":false,"reason":"user declined effort estimates"},{"name":"domain-overview","elected":false,"reason":"thin domain: fixture repo"}]
155
+ ---
156
+ ```
157
+
158
+ All four companions (`threat-model`, `interface-contract`, `estimation`,
159
+ `domain-overview`) always get an entry, elected or not — an un-elected
160
+ companion with no `reason` fails validation. Never drop an entry to avoid
161
+ writing a reason.
162
+
163
+ ## 5. Companion contracts
164
+
165
+ - **DOMAIN-OVERVIEW.md** has exactly three parts, each cross-linked, plus
166
+ nothing else:
167
+ - **Actors** — same persona names as the C1 context view; threat model
168
+ reuses them.
169
+ - **Processes** — actor-level steps naming CONTEXT-MAP contexts; each
170
+ links its §7 flow.
171
+ - **Rules** — business statements, each linking the §6 component that
172
+ enforces it and the ADR it came from.
173
+ - Excluded, home elsewhere: terms → `CONTEXT.md` · domain events →
174
+ CONTEXT-MAP relationships / AsyncAPI contract · context relationships →
175
+ `CONTEXT-MAP.md`.
176
+ - **threat-model.md** deliverable: a DFD, trust boundaries, a threat list,
177
+ and mitigations per threat — never just the diagram or just the list.
178
+ - **estimation.md** is not written here: when elected, the `estimate` skill
179
+ produces it (computed, validated — see `project-types.md`). Its honesty
180
+ rule still binds whoever renders it: every row carries confidence +
181
+ assumptions; a row nobody estimated renders `not estimated` — **never
182
+ `0`**, which would misread as "estimated at zero effort."
183
+
184
+ ## 6. mattpocock integration
185
+
186
+ `CONTEXT.md` and `CONTEXT-MAP.md` are mattpocock's formats — write into them
187
+ using their existing structure, never restructure or replace them. Rules:
188
+
189
+ - Multi-context repos keep mattpocock's layout: `src/<context>/CONTEXT.md`
190
+ per context, and a per-context `docs/adr/` alongside it. Root `docs/adr/`
191
+ holds system-wide decisions only.
192
+ - §14 (Decisions) and §16 (Glossary) generators scan **all** `docs/adr/` and
193
+ `CONTEXT.md` files — root and every context — never just the root.
194
+ - ADRs always include **Considered Options**, even though mattpocock's own
195
+ format lists it as optional. The rest of mattpocock's three-part gate
196
+ (offer an ADR only when a decision is hard to reverse, surprising without
197
+ context, and the result of a real trade-off) still governs whether an ADR
198
+ gets written at all — this project only strengthens what's inside it.
199
+
200
+ ## 7. ER ≠ domain model
201
+
202
+ Verbatim, spec §3.1 contract notes: the ER diagram is not the domain model.
203
+ ER = persistence shape; domain = concepts and invariants. They legitimately
204
+ differ (event sourcing, CQRS). Two diagrams, two homes — §8 owns the ER,
205
+ `CONTEXT.md`/DOMAIN-OVERVIEW.md own the domain model. Never let one section
206
+ substitute for the other because they look similar.
@@ -0,0 +1,74 @@
1
+ // A browser, with no dependency added to reach one.
2
+ //
3
+ // Everything about the viewer had been verified by reading the template as text.
4
+ // That catches a missing rule; it cannot catch a rule that is present and loses,
5
+ // a script that throws on boot, or a font that is embedded and never applied —
6
+ // and those are the failures a single-file offline viewer actually has.
7
+ //
8
+ // Node 22+ ships a global WebSocket and fetch, and Chrome speaks DevTools over
9
+ // both, so the whole driver is this file plus chrome.mjs. `npm ls` still reports
10
+ // zero dependencies, which is the property that made shipping the viewer as one
11
+ // file worth doing in the first place.
12
+ import { launch, waitFor } from './chrome.mjs';
13
+
14
+ function connect(url) {
15
+ return new Promise((ok, no) => {
16
+ const ws = new WebSocket(url);
17
+ ws.addEventListener('open', () => ok(ws), { once: true });
18
+ ws.addEventListener('error', () => no(new Error('devtools socket refused')), { once: true });
19
+ });
20
+ }
21
+
22
+ // One socket carries every command and every event, correlated by id. A message
23
+ // with no id is an event, which the console collector below subscribes to.
24
+ function sender(ws, onEvent) {
25
+ let id = 0;
26
+ const waiting = new Map();
27
+ ws.addEventListener('message', (ev) => {
28
+ const msg = JSON.parse(ev.data);
29
+ if (msg.id === undefined) return onEvent(msg);
30
+ const slot = waiting.get(msg.id);
31
+ waiting.delete(msg.id);
32
+ return slot && (msg.error ? slot.no(new Error(msg.error.message)) : slot.ok(msg.result));
33
+ });
34
+ return (method, params) => new Promise((ok, no) => {
35
+ id += 1;
36
+ waiting.set(id, { ok, no });
37
+ ws.send(JSON.stringify({ id, method, params }));
38
+ });
39
+ }
40
+
41
+ function evaluator(send) {
42
+ return async (expression) => {
43
+ const r = await send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
44
+ if (r.exceptionDetails) {
45
+ throw new Error(r.exceptionDetails.exception?.description ?? 'page threw');
46
+ }
47
+ return r.result.value;
48
+ };
49
+ }
50
+
51
+ // Errors are collected from the moment Runtime is enabled, so a throw during boot
52
+ // is caught rather than missed by a check that runs once the page has settled.
53
+ function collector() {
54
+ const errors = [];
55
+ const onEvent = (msg) => {
56
+ if (msg.method === 'Runtime.exceptionThrown') {
57
+ errors.push(msg.params.exceptionDetails.exception?.description ?? 'uncaught');
58
+ } else if (msg.method === 'Runtime.consoleAPICalled' && msg.params.type === 'error') {
59
+ errors.push(msg.params.args.map((a) => a.value ?? a.description).join(' '));
60
+ }
61
+ };
62
+ return { errors, onEvent };
63
+ }
64
+
65
+ export async function openPage(fileUrl) {
66
+ const chrome = await launch(fileUrl);
67
+ const ws = await connect(chrome.wsUrl);
68
+ const { errors, onEvent } = collector();
69
+ const send = sender(ws, onEvent);
70
+ await send('Runtime.enable');
71
+ const evaluate = evaluator(send);
72
+ await waitFor(() => evaluate('document.readyState === "complete"'), 'a loaded document');
73
+ return { eval: evaluate, errors, send, close() { ws.close(); chrome.kill(); } };
74
+ }
@@ -0,0 +1,66 @@
1
+ // Finding, starting and addressing a headless Chrome. The DevTools protocol
2
+ // itself is cdp.mjs' business; this file only gets a socket URL to hand it.
3
+ import { spawn, execFileSync } from 'node:child_process';
4
+ import { existsSync, readFileSync, mkdtempSync, rmSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+ import { setTimeout as sleep } from 'node:timers/promises';
8
+
9
+ const CANDIDATES = ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser'];
10
+
11
+ // Returns null rather than throwing: a machine without Chrome should skip the
12
+ // browser checks, not fail a suite that has nothing to do with it.
13
+ export function findChrome() {
14
+ for (const bin of CANDIDATES) {
15
+ try {
16
+ return execFileSync('which', [bin], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
17
+ } catch { /* try the next name */ }
18
+ }
19
+ return null;
20
+ }
21
+
22
+ // --remote-debugging-port=0 lets the OS choose and Chrome writes the chosen port
23
+ // into the profile directory. A hard-coded port makes two runs on one machine
24
+ // collide, which in a test suite reads as a flake rather than as a conflict.
25
+ const FLAGS = [
26
+ '--headless=new', '--remote-debugging-port=0', '--no-first-run',
27
+ '--no-default-browser-check', '--disable-gpu', '--disable-dev-shm-usage',
28
+ '--hide-scrollbars', '--window-size=1440,900',
29
+ ];
30
+
31
+ export async function waitFor(read, what) {
32
+ for (let i = 0; i < 150; i += 1) {
33
+ const got = await read();
34
+ if (got) return got;
35
+ await sleep(100);
36
+ }
37
+ throw new Error(`chrome never produced ${what}`);
38
+ }
39
+
40
+ function portFile(dir) {
41
+ const file = join(dir, 'DevToolsActivePort');
42
+ if (!existsSync(file)) return null;
43
+ return Number(readFileSync(file, 'utf8').split('\n')[0]) || null;
44
+ }
45
+
46
+ async function pageSocket(port) {
47
+ const res = await fetch(`http://127.0.0.1:${port}/json/list`).catch(() => null);
48
+ if (!res?.ok) return null;
49
+ return (await res.json()).find((t) => t.type === 'page')?.webSocketDebuggerUrl ?? null;
50
+ }
51
+
52
+ export async function launch(fileUrl) {
53
+ const chrome = findChrome();
54
+ if (!chrome) throw new Error('no chrome on PATH');
55
+ const dir = mkdtempSync(join(tmpdir(), 'analyze-requirements-chrome-'));
56
+ const proc = spawn(chrome, [...FLAGS, `--user-data-dir=${dir}`, fileUrl], { stdio: 'ignore' });
57
+ const port = await waitFor(() => portFile(dir), 'a devtools port');
58
+ const wsUrl = await waitFor(() => pageSocket(port), 'a page target');
59
+ return {
60
+ wsUrl,
61
+ kill() {
62
+ proc.kill('SIGKILL');
63
+ rmSync(dir, { recursive: true, force: true });
64
+ },
65
+ };
66
+ }
@@ -0,0 +1,20 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, relative } from 'node:path';
3
+ import { escapeHtml } from './md-inline.mjs';
4
+
5
+ // estimation.md carries the argument; estimate.html is the same numbers made
6
+ // interactive (sortable breakdown, what-if scenarios). Preferred home is the
7
+ // shared dist/ output folder — index.html and estimate.html then ship as one
8
+ // self-contained directory — with the older beside-estimation.md spot kept as
9
+ // a fallback. The link is injected at render time, and only when the file is
10
+ // actually there: an md-only run must produce exactly the viewer it produces
11
+ // today, never a dead link.
12
+ export function estimateLink(page, outDir) {
13
+ if (page.kind !== 'estimation') return '';
14
+ const target = [join(outDir, 'estimate.html'), join(dirname(page.path), 'estimate.html')]
15
+ .find((p) => existsSync(p));
16
+ if (!target) return '';
17
+ const href = escapeHtml(relative(outDir, target));
18
+ return `<p class="estimate-link"><a href="${href}">`
19
+ + 'Interactive estimate — sortable breakdown and what-if scenarios</a></p>\n';
20
+ }
@@ -0,0 +1,37 @@
1
+ import { basename } from 'node:path';
2
+
3
+ // The three companions with fixed basenames. interface-contract is absent on
4
+ // purpose: its filename is stack-dependent (OpenAPI, tool schemas, data
5
+ // contracts, a wire protocol), and if it ships as raw .yaml or .proto it never
6
+ // reaches renderMarkdown at all. Excluded rather than guessed at.
7
+ const COMPANIONS = new Map([
8
+ ['threat-model.md', 'threat-model'],
9
+ ['estimation.md', 'estimation'],
10
+ ['domain-overview.md', 'domain-overview'],
11
+ ]);
12
+
13
+ // The rail row is ~190px wide and companion H1s arrive carrying the project name
14
+ // ("# <Project> — Estimation" is the estimate skill's mandated heading), so the
15
+ // clip lands on the one word that tells the rows apart and every companion reads
16
+ // as a second copy of the spine's row. Labelled by kind instead — the full H1
17
+ // stays on the row's hover title, and the document body is untouched.
18
+ const LABELS = new Map([
19
+ ['threat-model', 'Threat Model'],
20
+ ['estimation', 'Estimation'],
21
+ ['domain-overview', 'Domain Overview'],
22
+ ]);
23
+
24
+ // Undefined for the spine and for anything unclassified: those titles are the
25
+ // author's own and short enough to rail as written.
26
+ export function labelOf(kind) {
27
+ return LABELS.get(kind);
28
+ }
29
+
30
+ // Position, not filename, identifies the spine: render.mjs passes ARCHITECTURE.md
31
+ // as docs[0] and a target repo may call it anything. Everything unmatched returns
32
+ // undefined and renders exactly as it does today — ADRs, CONTEXT.md,
33
+ // CONTEXT-MAP.md and the interface contract are all excluded by the spec.
34
+ export function kindOf(path, index) {
35
+ if (index === 0) return 'spine';
36
+ return COMPANIONS.get(basename(path).toLowerCase());
37
+ }
@@ -0,0 +1,26 @@
1
+ import { dirname, resolve } from 'node:path';
2
+
3
+ // The viewer is one HTML file, so a link to a sibling .md has nothing to open —
4
+ // every such href in a real set is dead on arrival. Each document is already in
5
+ // the DOM under its own id, so an in-set target becomes an in-page anchor. A
6
+ // target the viewer does not contain is unwrapped instead: left as a link it
7
+ // still looks clickable, which reads worse than plain text.
8
+ // The test is "is this a relative path", not "does it end in .md". A .c4 model,
9
+ // a directory, a source module — none of them can be a document in the set, so
10
+ // all of them are equally dead and all of them read better as text.
11
+ const HREF = /<a href="([^"#]*)(#[^"]*)?">([\s\S]*?)<\/a>/g;
12
+ const ABSOLUTE = /^([a-z][a-z0-9+.-]*:|\/\/)/i;
13
+
14
+ export function rewriteDocLinks(html, fromPath, idByPath) {
15
+ const dir = dirname(fromPath);
16
+ return html.replace(HREF, (whole, path, fragment, label) => {
17
+ // No path means an in-page anchor; a scheme or // means it leaves the page.
18
+ if (!path || ABSOLUTE.test(path)) return whole;
19
+ // The fragment is dropped rather than resolved: heading slugs are deduped
20
+ // across the whole set, so #context inside one ADR may have been minted as
21
+ // context-7. The document anchor is the target we can honestly name.
22
+ const id = idByPath.get(resolve(dir, path));
23
+ if (id) return `<a href="#${id}">${label}</a>`;
24
+ return `<span class="ext-ref" title="${path}${fragment ?? ''}">${label}</span>`;
25
+ });
26
+ }
@@ -0,0 +1,27 @@
1
+ import { basename, extname } from 'node:path';
2
+ import { bucketPages, landingOf, slugOf } from './doc-sections.mjs';
3
+ import { nextSlug } from './slug-registry.mjs';
4
+
5
+ // A document is what a reader opens, so a document is what gets a route. The
6
+ // slug comes from the source filename rather than the H1: a title gets
7
+ // reworded, a filename is the thing every other document already links to.
8
+ // A section's index page takes the section slug instead, so #/decision-records
9
+ // lands on the list rather than on a file called index.
10
+ function fileSlug(path) {
11
+ return slugOf(basename(path ?? '', extname(path ?? '')));
12
+ }
13
+
14
+ // Keyed by document id, and built once by the caller, so the nav and the body
15
+ // cannot disagree about which slug opens which page.
16
+ export function routeMap(pages) {
17
+ const routes = new Map();
18
+ const seen = new Map();
19
+ for (const bucket of bucketPages(pages)) {
20
+ const landing = landingOf(bucket);
21
+ for (const page of bucket.pages) {
22
+ const base = page === landing ? slugOf(bucket.label) : fileSlug(page.path);
23
+ routes.set(page.docId, nextSlug(base, seen));
24
+ }
25
+ }
26
+ return routes;
27
+ }
@@ -0,0 +1,78 @@
1
+ import { basename } from 'node:path';
2
+ import { escapeHtml } from './md-inline.mjs';
3
+
4
+ const LANDING = ['index.md', 'readme.md'];
5
+
6
+ // Buckets are consecutive runs, not a group-by: the caller's document order is
7
+ // the reading order, and reordering to match a sort would break it.
8
+ export function bucketPages(pages) {
9
+ const out = [];
10
+ for (const page of pages) {
11
+ const label = page.section || 'Documents';
12
+ const last = out[out.length - 1];
13
+ if (last && last.label === label) last.pages.push(page);
14
+ else out.push({ label, pages: [page] });
15
+ }
16
+ return out;
17
+ }
18
+
19
+ // A section routes only if its author shipped an index page — that is the
20
+ // opt-in, and it needs no document-count threshold. Fifteen records behind an
21
+ // index is a set you browse; fifteen records with no index is a run of
22
+ // documents you read straight through, and hiding them would only lose you the
23
+ // scroll.
24
+ export function landingOf(bucket) {
25
+ // The section holding the root architecture document is the spine of the set:
26
+ // read, not browsed. Ungated, a 226-byte docs/architecture/README.md would win
27
+ // the landing slot and hide ARCHITECTURE.md itself behind a stub.
28
+ if (bucket.pages.some((p) => p.spine)) return undefined;
29
+ const rank = (page) => LANDING.indexOf(basename(page.path ?? '').toLowerCase());
30
+ return bucket.pages.filter((p) => rank(p) >= 0).sort((a, b) => rank(a) - rank(b))[0];
31
+ }
32
+
33
+ function pageEl(page, route) {
34
+ const title = escapeHtml(stripTitle(page.title));
35
+ const at = route ? ` data-route="${route}"` : '';
36
+ // Omitted rather than emptied when there is no kind: data-kind="" still
37
+ // matches a [data-kind] selector, so an unclassified document would look
38
+ // classified to the injection loop.
39
+ const kind = page.kind ? ` data-kind="${escapeHtml(page.kind)}"` : '';
40
+ return `<section class="page" id="page-${page.docId}"${at}${kind} data-title="${title}">`
41
+ + `\n${page.html}\n</section>`;
42
+ }
43
+
44
+ function stripTitle(title) {
45
+ return (title ?? '').replace(/`([^`]+)`/g, '$1').replace(/\*\*([^*]+)\*\*/g, '$1');
46
+ }
47
+
48
+ // Each section is its own page, so it needs an address. Derived from the label
49
+ // rather than a counter: #/decision-records reads as a place and survives a
50
+ // reordered --docs list, #/section-2 does neither.
51
+ export function slugOf(label) {
52
+ return label.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
53
+ }
54
+
55
+ // §14 Decisions already tables every ADR, so a Decision Records rail section is
56
+ // the same set a second time — and the copy the reader did not ask for, since they
57
+ // were looking at §14 when they clicked. The records stay in the document, because
58
+ // a drawer needs something to show, but the section is marked so the router opens
59
+ // them over the page instead of replacing it.
60
+ export function isDrawerBucket(bucket) {
61
+ return bucket.pages.every((p) => p.drawer);
62
+ }
63
+
64
+ function sectionEl(bucket, routes) {
65
+ const landing = landingOf(bucket);
66
+ const routed = landing ? ` data-routed data-landing="page-${landing.docId}"` : '';
67
+ const slug = slugOf(bucket.label);
68
+ const drawer = isDrawerBucket(bucket) ? ' data-drawer' : '';
69
+ const inner = bucket.pages.map((p) => pageEl(p, routes.get(p.docId))).join('\n');
70
+ return `<div class="doc-section" id="sec-${slug}" data-slug="${slug}"`
71
+ + ` data-section="${escapeHtml(bucket.label)}"${routed}${drawer}>${inner}</div>`;
72
+ }
73
+
74
+ // routes default to empty so a caller that has not built them still renders a
75
+ // readable document — it just has no addresses.
76
+ export function buildDoc(pages, routes = new Map()) {
77
+ return bucketPages(pages).map((b) => sectionEl(b, routes)).join('\n');
78
+ }
@@ -0,0 +1,8 @@
1
+ export function embed({ template, slots }) {
2
+ const markers = [...template.matchAll(/<!-- slot:(\w+) -->/g)].map((m) => m[1]);
3
+ const missing = markers.filter((m) => !(m in slots));
4
+ if (missing.length) throw new Error(`no slot content for marker(s): ${missing.join(', ')}`);
5
+ const unused = Object.keys(slots).filter((s) => !markers.includes(s));
6
+ if (unused.length) throw new Error(`slot(s) without marker: ${unused.join(', ')}`);
7
+ return template.replace(/<!-- slot:(\w+) -->/g, (_, name) => slots[name]);
8
+ }
@@ -0,0 +1,16 @@
1
+ export function erEntities(md) {
2
+ const names = new Set();
3
+ const fences = md.match(/```mermaid\n[\s\S]*?```/g) ?? [];
4
+ for (const fence of fences) {
5
+ if (!/^\s*erDiagram/m.test(fence)) continue;
6
+ for (const line of fence.split('\n')) collect(line, names);
7
+ }
8
+ return [...names];
9
+ }
10
+
11
+ function collect(line, names) {
12
+ const rel = line.match(/^\s*(\w+)\s+[|}o][|o.-]+[|{o]\s+(\w+)\s*:/);
13
+ if (rel) { names.add(rel[1]); names.add(rel[2]); return; }
14
+ const block = line.match(/^\s*(\w+)\s*\{\s*$/);
15
+ if (block) names.add(block[1]);
16
+ }
@@ -0,0 +1,39 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ // The viewer named IBM Plex Sans and IBM Plex Mono in its stacks and got them on
5
+ // almost no machine: neither ships with macOS, Windows or a stock Linux desktop,
6
+ // so the body text fell through to system-ui and the code to whatever the
7
+ // platform calls monospace. Both are genre changes, not near-misses — and
8
+ // mermaid-theme.json names the same two faces, so the diagrams missed them too.
9
+ // The serif stack is left alone: Iowan → Charter → Georgia stays a book serif
10
+ // the whole way down, which is a fallback rather than a substitution.
11
+ //
12
+ // Embedded at render time rather than committed into the template, for the same
13
+ // reason the mermaid and LikeC4 bundles are: ~135KB of base64 turns a readable
14
+ // design document into a blob with a stylesheet around it, and every later diff
15
+ // of that file would carry it.
16
+ const FACE = /^(ibm-plex-(?:sans|mono))-latin-(\d{3})-normal\.woff2$/;
17
+
18
+ const FAMILY = { 'ibm-plex-sans': 'IBM Plex Sans', 'ibm-plex-mono': 'IBM Plex Mono' };
19
+
20
+ // No newlines and no spaces around the colons: this lands inside the viewer's own
21
+ // stylesheet, where every other rule is hand-written and readable, and five
22
+ // base64 blobs pretending to be formatted CSS would bury it.
23
+ function faceRule(dir, file) {
24
+ const [, family, weight] = file.match(FACE);
25
+ const b64 = readFileSync(join(dir, file)).toString('base64');
26
+ return `@font-face{font-family:'${FAMILY[family]}';font-style:normal;`
27
+ + `font-weight:${weight};font-display:swap;`
28
+ + `src:url(data:font/woff2;base64,${b64}) format('woff2')}`;
29
+ }
30
+
31
+ // Throws rather than returning '' when there is nothing to embed. An empty
32
+ // string here ships a viewer whose CSS still names the faces, which is the exact
33
+ // silent-fallback failure this function exists to end — and a missing directory
34
+ // means a broken install, not a viewer without fonts.
35
+ export function buildFontFaces(dir) {
36
+ const files = readdirSync(dir).filter((f) => FACE.test(f)).sort();
37
+ if (!files.length) throw new Error(`no woff2 faces in ${dir}`);
38
+ return files.map((f) => faceRule(dir, f)).join('\n');
39
+ }
@@ -0,0 +1,17 @@
1
+ export function parseFrontmatter(md) {
2
+ const m = md.match(/^---\n([\s\S]*?)\n---/);
3
+ if (!m) return { data: null, error: 'no frontmatter block' };
4
+ const data = {};
5
+ for (const line of m[1].split('\n')) {
6
+ if (!line.trim()) continue;
7
+ const i = line.indexOf(':');
8
+ if (i === -1) return { data: null, error: `bad line: ${line}` };
9
+ data[line.slice(0, i).trim()] = parseValue(line.slice(i + 1).trim());
10
+ }
11
+ return { data };
12
+ }
13
+
14
+ function parseValue(raw) {
15
+ if (!raw.startsWith('[') && !raw.startsWith('{')) return raw;
16
+ try { return JSON.parse(raw); } catch { return raw; }
17
+ }