@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,19 @@
1
+ const REMOTE_ASSET = /url\(\s*['"]?https?:\/\/[^)]*\)(\s*format\([^)]*\))?/g;
2
+ const SCRIPT_CLOSE_TAG = /<\/script/i;
3
+
4
+ // Third-party bundles we inline (LikeC4 ships @font-face rules pointing at a CDN)
5
+ // must not fetch anything: the viewer is offline-only. Rewrite every absolute-URL
6
+ // CSS asset to a local() source; url(#fragment) and data: URIs are left untouched.
7
+ // The replacement carries no quote characters: the CSS it lands in is itself inside
8
+ // a JS string literal, and a quote of the wrong style would break the bundle open.
9
+ //
10
+ // render.mjs splices this bundle straight into a <script> element's text content.
11
+ // A literal "</script>" anywhere in it (e.g. inside a string or comment) would
12
+ // close that element early and truncate the page, so refuse loudly instead of
13
+ // shipping a silently broken viewer.
14
+ export function stripRemoteAssets(js) {
15
+ if (SCRIPT_CLOSE_TAG.test(js)) {
16
+ throw new Error('bundle contains a literal </script> that would truncate the inlined <script> tag');
17
+ }
18
+ return js.replace(REMOTE_ASSET, 'local(system-ui)');
19
+ }
@@ -0,0 +1,13 @@
1
+ import net from 'node:net';
2
+
3
+ export async function findFreePort(start = 4173) {
4
+ return (await isFree(start)) ? start : findFreePort(start + 1);
5
+ }
6
+
7
+ function isFree(port) {
8
+ return new Promise((resolve) => {
9
+ const srv = net.createServer();
10
+ srv.once('error', () => resolve(false));
11
+ srv.listen(port, '127.0.0.1', () => srv.close(() => resolve(true)));
12
+ });
13
+ }
@@ -0,0 +1,113 @@
1
+ // Structural limits every skill's scripts must hold. Shared by the three
2
+ // skills' quality-gates tests so the thresholds live in one place.
3
+ //
4
+ // A limit set with a key omitted skips that check — template JavaScript gets
5
+ // the per-function limits only, because a self-contained page is one file by
6
+ // design and can never meet a per-file line or function count.
7
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
8
+ import { join } from 'node:path';
9
+
10
+ export const LIMITS = { fileLines: 200, functions: 10, functionLines: 22, params: 3 };
11
+
12
+ // A rendered page is one self-contained file by design — it inlines its fonts and
13
+ // carries no external URL — so a per-file line or function count can never be met
14
+ // and would say nothing if it were. The per-function limits still apply.
15
+ export const TEMPLATE_LIMITS = { functionLines: 22, params: 3 };
16
+
17
+ // Braces inside a regex, string or comment are not structure. Counting them
18
+ // makes a short function measure long, and the overshoot runs on into whatever
19
+ // follows. Blank the literal out but keep its newlines, so spans stay accurate.
20
+ const blank = (m) => m.replace(/[^\n]/g, ' ');
21
+
22
+ // Order is load-bearing. Escape pairs go first, so an escaped slash or quote can
23
+ // never terminate the literal that contains it. Regex literals go before strings,
24
+ // because a character class may hold a quote or a backtick — md-inline.mjs:9 is a
25
+ // regex holding three backticks, and reading those as a template literal blanks
26
+ // twenty lines of real structure.
27
+ function stripLiterals(src) {
28
+ return src
29
+ .replace(/\\./g, '__')
30
+ .replace(/\/\*[\s\S]*?\*\//g, blank)
31
+ .replace(/\/\/[^\n]*/g, blank)
32
+ .replace(/([=(,:[!&|?;]\s*)(\/(?:\[[^\]\n]*\]|[^/\n])+\/[gimsuy]*)/g, (_, pre, re) => pre + blank(re))
33
+ .replace(/'[^'\n]*'/g, blank)
34
+ .replace(/"[^"\n]*"/g, blank)
35
+ .replace(/`[^`]*`/g, blank);
36
+ }
37
+
38
+ // Measured in lines of code, not lines of text. The limit caps how much logic a
39
+ // reader holds at once, and a static HTML string or a comment block is neither —
40
+ // they arrive here already blanked, so a blank line is a line that carried none.
41
+ function functionSpans(code) {
42
+ const spans = [];
43
+ const starts = [...code.matchAll(/(?:^|\n)\s*(?:export\s+)?(?:async\s+)?function\s+\w+|=>\s*\{/g)];
44
+ for (const m of starts) {
45
+ const open = code.indexOf('{', m.index);
46
+ let depth = 0; let end = code.length - 1;
47
+ for (let i = open; i < code.length; i += 1) {
48
+ if (code[i] === '{') depth += 1;
49
+ if (code[i] === '}') { depth -= 1; if (depth === 0) { end = i; break; } }
50
+ }
51
+ spans.push(code.slice(open, end + 1).split('\n').filter((l) => l.trim() !== '').length);
52
+ }
53
+ return spans;
54
+ }
55
+
56
+ function countParams(sig) {
57
+ let depth = 0; let n = sig.trim() ? 1 : 0;
58
+ for (const ch of sig) {
59
+ if ('([{'.includes(ch)) depth += 1;
60
+ if (')]}'.includes(ch)) depth -= 1;
61
+ if (ch === ',' && depth === 0) n += 1;
62
+ }
63
+ return n;
64
+ }
65
+
66
+ function paramCounts(src) {
67
+ return [
68
+ ...src.matchAll(/function\s+\w+\s*\(([^)]*)\)/g),
69
+ ...src.matchAll(/\(([^)]*)\)\s*=>/g),
70
+ ].map((m) => countParams(m[1]));
71
+ }
72
+
73
+ export function violations(src, limits = LIMITS) {
74
+ const out = [];
75
+ const code = stripLiterals(src);
76
+ const lines = src.split('\n').length;
77
+ if (limits.fileLines && lines > limits.fileLines) out.push(`${lines} lines (max ${limits.fileLines})`);
78
+ const spans = functionSpans(code);
79
+ if (limits.functions && spans.length > limits.functions) out.push(`${spans.length} functions (max ${limits.functions})`);
80
+ for (const n of spans) {
81
+ if (limits.functionLines && n > limits.functionLines) out.push(`function of ${n} lines (max ${limits.functionLines})`);
82
+ }
83
+ for (const n of paramCounts(code)) {
84
+ if (limits.params && n > limits.params) out.push(`function with ${n} params (max ${limits.params})`);
85
+ }
86
+ return out;
87
+ }
88
+
89
+ export function moduleFiles(base, dirs) {
90
+ return dirs.flatMap((d) => readdirSync(join(base, d), { withFileTypes: true })
91
+ .filter((e) => e.isFile() && /\.(mjs|js)$/.test(e.name))
92
+ .map((e) => join(base, d, e.name)));
93
+ }
94
+
95
+ // Keep every byte at its original offset — blank the markup, restore the script
96
+ // bodies in place — so a reported span still counts lines of the real file. The
97
+ // JSON data island is data, not code.
98
+ function scriptText(html) {
99
+ let out = blank(html);
100
+ for (const m of html.matchAll(/<script(?![^>]*application\/json)[^>]*>([\s\S]*?)<\/script>/g)) {
101
+ const at = m.index + m[0].indexOf(m[1]);
102
+ out = out.slice(0, at) + m[1] + out.slice(at + m[1].length);
103
+ }
104
+ return out;
105
+ }
106
+
107
+ export function templateScripts(base) {
108
+ const dir = join(base, 'assets');
109
+ if (!existsSync(dir)) return [];
110
+ return readdirSync(dir, { withFileTypes: true })
111
+ .filter((e) => e.isFile() && e.name.endsWith('.html'))
112
+ .map((e) => ({ file: join(dir, e.name), js: scriptText(readFileSync(join(dir, e.name), 'utf8')) }));
113
+ }
@@ -0,0 +1,49 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ // The lookup keys on heading text rather than on a slug for two reasons: slugify
4
+ // keeps both spaces around a stripped "&", so "Goals & Scope" becomes
5
+ // goals--scope; and h2/h3 ids share one dedupe registry, so an h3 named Security
6
+ // under Crosscutting Concepts would take `security` and demote §12's h2 to
7
+ // security-2.
8
+ //
9
+ // It matches on a normalised form because the markdown is the source of truth and
10
+ // the markdown varies. A real set writes "## 1 Goals and Scope" — number folded
11
+ // into the heading, "and" spelled out — while this list and the fixture write
12
+ // "Goals & Scope". Keyed on the raw string, all 16 lookups missed and the viewer
13
+ // drew nothing, with every test still green because the fixture shared the
14
+ // mistake.
15
+ //
16
+ // The leading number is dropped rather than matched on: §3 Project Structure is
17
+ // brownfield-only, so a greenfield set renumbers every section after it, and a
18
+ // number-keyed lookup would then hand §13's explainer to §12.
19
+ export function normTitle(title) {
20
+ return String(title)
21
+ .replace(/^\s*\d+[.)]?\s+/, '')
22
+ .replace(/&/g, 'and')
23
+ .replace(/\s+/g, ' ')
24
+ .trim()
25
+ .toLowerCase();
26
+ }
27
+
28
+ // The 16 spine headings, title only — see references/writing.md §1.
29
+ export const SPINE_TITLES = Object.freeze([
30
+ 'Goals & Scope', 'Constraints', 'Project Structure', 'Solution Strategy',
31
+ 'Architecture Model', 'Core Components', 'Runtime Behaviour', 'Data Stores',
32
+ 'External Integrations', 'Deployment & Infrastructure', 'Crosscutting Concepts',
33
+ 'Security', 'Quality Requirements & SLOs', 'Decisions',
34
+ 'Risks & Technical Debt', 'Glossary',
35
+ ]);
36
+
37
+ export function sectionHelp() {
38
+ const url = new URL('../../assets/section-help.json', import.meta.url);
39
+ return JSON.parse(readFileSync(url, 'utf8'));
40
+ }
41
+
42
+ // The result is spliced into an inline <script>, so a "</script" sequence
43
+ // anywhere in the prose would close the element early and inject the remainder
44
+ // as markup. Escaping "<" is enough to make that impossible and still parses as
45
+ // JSON. THEME gets away with a raw splice because a palette file is hex and
46
+ // keys; this is author-written sentences.
47
+ export function serialiseHelp(help) {
48
+ return JSON.stringify(help).replace(/</g, '\\u003c');
49
+ }
@@ -0,0 +1,11 @@
1
+ import { slugify } from './validate-links.mjs';
2
+
3
+ // Single source of truth for the -N dedupe rule so the renderer (which assigns
4
+ // heading ids) and the link validator (which must know which ids exist) never
5
+ // drift apart. Callers control dedupe scope by which registry Map they pass in.
6
+ export function nextSlug(text, registry) {
7
+ const base = slugify(text);
8
+ const nth = (registry.get(base) ?? 0) + 1;
9
+ registry.set(base, nth);
10
+ return nth === 1 ? base : `${base}-${nth}`;
11
+ }
@@ -0,0 +1,15 @@
1
+ // Key paths are file paths; clusters carry packages (top-level folders), never
2
+ // file paths — top_nodes are bare symbol names, useless as path prefixes. So
3
+ // the match runs each key path against the cluster's packages. Rows that name
4
+ // a data store (§8) have no code cluster to match and are exempt.
5
+ export function validateClusters({ clusters, componentRows, storeNames = [], minCohesion = 0.5 }) {
6
+ const stores = new Set(storeNames.map((s) => s.toLowerCase()));
7
+ const codeRows = componentRows.filter((r) => !stores.has(r.name.toLowerCase()));
8
+ const matches = (c, row) => row.keyPaths.some((p) => (c.packages ?? []).some((k) => p === k || p.startsWith(k + '/')));
9
+ return [
10
+ ...clusters.filter((c) => c.cohesion >= minCohesion && !codeRows.some((r) => matches(c, r)))
11
+ .map((c) => ({ check: 'clusters', message: `cluster "${c.label}" (cohesion ${c.cohesion}) has no component row` })),
12
+ ...codeRows.filter((r) => !clusters.some((c) => matches(c, r)))
13
+ .map((r) => ({ check: 'clusters', message: `component "${r.name}" matches no detected code cluster` })),
14
+ ];
15
+ }
@@ -0,0 +1,8 @@
1
+ export function validateDeployment({ model }) {
2
+ return model.elements
3
+ .filter((e) => e.kind === 'container' && !model.deployed.includes(e.id))
4
+ .map((e) => ({
5
+ check: 'deployment',
6
+ message: `container "${e.title}" (${e.id}) has no instanceOf in any deployment node`,
7
+ }));
8
+ }
@@ -0,0 +1,20 @@
1
+ const COMPANIONS = ['threat-model', 'interface-contract', 'estimation', 'domain-overview'];
2
+
3
+ export function validateElections({ frontmatter }) {
4
+ const docs = frontmatter.electedDocs;
5
+ if (!Array.isArray(docs)) {
6
+ return [{ check: 'elections', message: 'frontmatter electedDocs missing or not a list' }];
7
+ }
8
+ return COMPANIONS.flatMap((name) => checkOne(name, docs.find((d) => d.name === name)));
9
+ }
10
+
11
+ function checkOne(name, entry) {
12
+ if (!entry) return [{ check: 'elections', message: `no election record for ${name}` }];
13
+ if (typeof entry.elected !== 'boolean') {
14
+ return [{ check: 'elections', message: `${name}: elected must be true or false` }];
15
+ }
16
+ if (!entry.elected && !entry.reason) {
17
+ return [{ check: 'elections', message: `${name}: not elected but no reason recorded` }];
18
+ }
19
+ return [];
20
+ }
@@ -0,0 +1,23 @@
1
+ import { dirname, join, normalize } from 'node:path';
2
+
3
+ export function slugify(heading) {
4
+ return heading.toLowerCase().replace(/[^a-z0-9 -]/g, '').replace(/ /g, '-');
5
+ }
6
+
7
+ export function validateLinks({ links, files, anchors }) {
8
+ return links.flatMap((l) => checkLink(l, files, anchors));
9
+ }
10
+
11
+ function resolveHref(fromDoc, path) {
12
+ return path ? normalize(join(dirname(fromDoc), path)) : '';
13
+ }
14
+
15
+ function checkLink(link, files, anchors) {
16
+ if (/^https?:/.test(link.href)) return [];
17
+ const [path, frag] = link.href.split('#');
18
+ const target = resolveHref(link.fromDoc, path);
19
+ const bad = (why) => [{ check: 'links', message: `${link.fromDoc}: "${link.href}" ${why}` }];
20
+ if (target && !files.includes(target)) return bad('target file missing');
21
+ if (frag && !(anchors[target || link.fromDoc] ?? []).includes(frag)) return bad('anchor missing');
22
+ return [];
23
+ }
@@ -0,0 +1,24 @@
1
+ export function validateModelTables({ model, tables, erNames }) {
2
+ const els = (kinds) => model.elements.filter((e) => kinds.includes(e.kind)).map((e) => e.title);
3
+ return [
4
+ ...diff(els(['container', 'component']), names(tables, 'Core Components'), { sourceName: 'model', label: 'component' }),
5
+ ...diff(els(['external']), names(tables, 'External Integrations'), { sourceName: 'model', label: 'external' }),
6
+ ...diff(erNames, names(tables, 'Data Stores'), { sourceName: 'ER diagram', label: 'store' }),
7
+ ];
8
+ }
9
+
10
+ function names(tables, section) {
11
+ const t = tables.find((x) => x.section.includes(section));
12
+ return (t?.rows ?? []).map((r) => r[0].replace(/\[([^\]]*)\]\([^)]*\)/, '$1'));
13
+ }
14
+
15
+ function diff(modelSide, tableSide, ctx) {
16
+ const low = (xs) => xs.map((x) => x.toLowerCase());
17
+ const [m, t] = [low(modelSide), low(tableSide)];
18
+ return [
19
+ ...modelSide.filter((x) => !t.includes(x.toLowerCase()))
20
+ .map((x) => ({ check: 'model-tables', message: `${ctx.label} "${x}" in ${ctx.sourceName} but no table row` })),
21
+ ...tableSide.filter((x) => !m.includes(x.toLowerCase()))
22
+ .map((x) => ({ check: 'model-tables', message: `${ctx.label} "${x}" in table but not in ${ctx.sourceName}` })),
23
+ ];
24
+ }
@@ -0,0 +1,34 @@
1
+ // The gate that the obvious check fails to be.
2
+ //
3
+ // Grepping the bundle for the brand hex passes on an all-blue bundle: a model
4
+ // declaring its own colour leaves the brand hex sitting in the colour registry,
5
+ // defined and never painted. Both hexes are present and the diagrams are blue.
6
+ // The resolved node colour is the only thing that says what is drawn, so that is
7
+ // what this reads — together with the theme block, whose mere absence means the
8
+ // bundle was generated without the plugin's config at all.
9
+ const THEME_FILL = /primary:\{elements:\{fill:`(#[0-9a-fA-F]{3,8})`/;
10
+ const NODE_COLOR = /shape:`[a-z]+`,color:`([a-z0-9]+)`/g;
11
+
12
+ // The names buildLikec4Config overrides. Anything else reaching a node means the
13
+ // model painted it from outside the palette.
14
+ const IN_PALETTE = new Set(['primary', 'secondary', 'muted', 'gray']);
15
+
16
+ function themeFinding(bundle, brand) {
17
+ const fill = bundle.match(THEME_FILL);
18
+ if (!fill) {
19
+ return 'likec4 bundle carries no theme palette — generated without likec4.config.json';
20
+ }
21
+ return fill[1].toLowerCase() === brand.toLowerCase()
22
+ ? null
23
+ : `likec4 theme fill ${fill[1]} does not match the shared brand ${brand}`;
24
+ }
25
+
26
+ function nodeFinding(bundle) {
27
+ const used = new Set([...bundle.matchAll(NODE_COLOR)].map((m) => m[1]));
28
+ const off = [...used].filter((name) => !IN_PALETTE.has(name));
29
+ return off.length ? `likec4 nodes painted off-palette: ${off.sort().join(', ')}` : null;
30
+ }
31
+
32
+ export function validatePalette({ bundle, theme }) {
33
+ return [themeFinding(bundle, theme.likec4.brand), nodeFinding(bundle)].filter(Boolean);
34
+ }
@@ -0,0 +1,20 @@
1
+ const ALLOWED = ['observed', 'stated', 'researched', 'proposed'];
2
+ const EXEMPT = ['Decisions', 'Glossary'];
3
+
4
+ export function validateProvenance({ tables }) {
5
+ const findings = [];
6
+ for (const t of tables) {
7
+ if (EXEMPT.some((e) => t.section.includes(e))) continue;
8
+ findings.push(...checkTable(t));
9
+ }
10
+ return findings;
11
+ }
12
+
13
+ function checkTable(t) {
14
+ const col = t.headers.indexOf('src');
15
+ if (col === -1) {
16
+ return [{ check: 'provenance', message: `table in "${t.section}" has no src column` }];
17
+ }
18
+ return t.rows.filter((r) => !ALLOWED.some((a) => (r[col] ?? '').startsWith(a)))
19
+ .map((r) => ({ check: 'provenance', message: `"${t.section}" row "${r[0]}": bad src "${r[col]}"` }));
20
+ }
@@ -0,0 +1,16 @@
1
+ export function validateTree({ boundaryRows, fsDirs, allDirs = fsDirs }) {
2
+ const documented = boundaryRows.map(norm);
3
+ const actual = fsDirs.map(norm);
4
+ const onDisk = allDirs.map(norm);
5
+ const covered = (a) => documented.some((d) => a === d || a.startsWith(`${d}/`));
6
+ return [
7
+ ...documented.filter((d) => !onDisk.includes(d))
8
+ .map((d) => ({ check: 'tree', message: `documented dir "${d}" not found on filesystem` })),
9
+ ...actual.filter((a) => !covered(a))
10
+ .map((a) => ({ check: 'tree', message: `dir "${a}" exists but is not documented in the boundary map` })),
11
+ ];
12
+ }
13
+
14
+ function norm(p) {
15
+ return p.replace(/\/+$/, '');
16
+ }
@@ -0,0 +1,19 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { buildLikec4Config } from './lib/likec4-config.mjs';
4
+
5
+ // Written into the folder holding the .c4 sources, which is where LikeC4 looks
6
+ // for a project config — and which the skill generates, so the target repo keeps
7
+ // only markdown. Run before `likec4 gen webcomponent`; render.mjs refuses a
8
+ // bundle generated without it.
9
+ const argv = process.argv.slice(2);
10
+ const out = argv[argv.indexOf('--out') + 1];
11
+ if (!argv.includes('--out') || !out) {
12
+ throw new Error('usage: likec4-config.mjs --out <dir containing the .c4 sources>');
13
+ }
14
+
15
+ const themeUrl = new URL('../assets/mermaid-theme.json', import.meta.url);
16
+ const config = buildLikec4Config(JSON.parse(readFileSync(themeUrl, 'utf8')));
17
+ const path = join(out, 'likec4.config.json');
18
+ writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`);
19
+ console.log(path);
@@ -0,0 +1,35 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { PROJECT_NAME } from './lib/likec4-config.mjs';
4
+
5
+ // likec4.config.json names the project, so the workspace holds two projects
6
+ // (arch-docs + default) and a bare `export json` emits an **array** of project
7
+ // objects — a shape likec4-extract.mjs cannot read. --project pins the export
8
+ // to the single object the validator expects; this wrapper exists so the flag
9
+ // cannot be forgotten.
10
+ function parseArgs(argv) {
11
+ const args = {};
12
+ for (let i = 0; i < argv.length; i += 1) {
13
+ if (argv[i].startsWith('--')) args[argv[i].slice(2)] = argv[i + 1];
14
+ }
15
+ if (!args.dir || !args.out) {
16
+ throw new Error('usage: likec4-export.mjs --dir <dir containing the .c4 sources> --out <model.json>');
17
+ }
18
+ return args;
19
+ }
20
+
21
+ function requireModelObject(path) {
22
+ const raw = JSON.parse(readFileSync(path, 'utf8'));
23
+ if (Array.isArray(raw) || !raw?.elements) {
24
+ throw new Error(`${path} is not a single-project model carrying .elements — was --project ${PROJECT_NAME} dropped?`);
25
+ }
26
+ }
27
+
28
+ const args = parseArgs(process.argv.slice(2));
29
+ try {
30
+ execFileSync('npx', ['likec4', 'export', 'json', '--project', PROJECT_NAME, '--outfile', args.out, args.dir], { stdio: 'inherit' });
31
+ } catch {
32
+ throw new Error('likec4 export failed — the model JSON was not written');
33
+ }
34
+ requireModelObject(args.out);
35
+ console.log(args.out);
@@ -0,0 +1,39 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { likec4Steps } from './lib/likec4-steps.mjs';
5
+
6
+ // Validate, then generate — one command, because two commands is how the
7
+ // validate step got skipped. See lib/likec4-steps.mjs for why gen alone is not
8
+ // a gate.
9
+ function parseArgs(argv) {
10
+ const args = {};
11
+ for (let i = 0; i < argv.length; i += 1) {
12
+ if (argv[i].startsWith('--')) args[argv[i].slice(2)] = argv[i + 1];
13
+ }
14
+ if (!args.dir || !args.out) {
15
+ throw new Error('usage: likec4-gen.mjs --dir <dir containing the .c4 sources> --out <bundle>');
16
+ }
17
+ return args;
18
+ }
19
+
20
+ // Checked here rather than left to render.mjs, which finds it only after the
21
+ // bundle has been built: without the config LikeC4 paints its default blue, and
22
+ // that model still validates and still generates clean.
23
+ function requireConfig(dir) {
24
+ if (existsSync(join(dir, 'likec4.config.json'))) return;
25
+ throw new Error(`${dir} has no likec4.config.json — run scripts/likec4-config.mjs --out ${dir}`);
26
+ }
27
+
28
+ function run([bin, argv]) {
29
+ try {
30
+ execFileSync('npx', [bin, ...argv], { stdio: 'inherit' });
31
+ } catch {
32
+ throw new Error(`likec4 ${argv[0]} failed — the bundle was not written`);
33
+ }
34
+ }
35
+
36
+ const args = parseArgs(process.argv.slice(2));
37
+ requireConfig(args.dir);
38
+ for (const step of likec4Steps(args)) run(step);
39
+ console.log(args.out);
@@ -0,0 +1,130 @@
1
+ import { readFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
+ import { renderMarkdown } from './lib/md-render.mjs';
4
+ import { buildNav } from './lib/nav.mjs';
5
+ import { rewriteDocLinks } from './lib/doc-links.mjs';
6
+ import { buildDoc } from './lib/doc-sections.mjs';
7
+ import { routeMap } from './lib/doc-routes.mjs';
8
+ import { parseFrontmatter } from './lib/frontmatter.mjs';
9
+ import { embed } from './lib/embed.mjs';
10
+ import { kindOf } from './lib/doc-kinds.mjs';
11
+ import { estimateLink } from './lib/companion-links.mjs';
12
+ import { sectionHelp, serialiseHelp } from './lib/section-help.mjs';
13
+ import { stripRemoteAssets } from './lib/offline.mjs';
14
+ import { buildFontFaces } from './lib/fonts.mjs';
15
+ import { validatePalette } from './lib/validate-palette.mjs';
16
+
17
+ function consumeDocs(argv, i, docs) {
18
+ while (argv[i + 1] && !argv[i + 1].startsWith('--')) docs.push(argv[++i]);
19
+ return i;
20
+ }
21
+
22
+ function parseArgs(argv) {
23
+ const args = { root: process.cwd(), docs: [] };
24
+ for (let i = 0; i < argv.length; i += 1) {
25
+ const flag = argv[i];
26
+ if (flag === '--docs') {
27
+ i = consumeDocs(argv, i, args.docs);
28
+ } else if (flag.startsWith('--')) {
29
+ args[flag.slice(2)] = argv[++i];
30
+ }
31
+ }
32
+ return args;
33
+ }
34
+
35
+ function docTitle(archMd) {
36
+ const { data } = parseFrontmatter(archMd);
37
+ if (data?.name) return data.name;
38
+ const h1 = archMd.match(/^#\s+(.+)$/m);
39
+ return h1 ? h1[1].trim() : 'Architecture';
40
+ }
41
+
42
+ // The rail buckets documents by the directory they came from, so a docs/adr run
43
+ // collapses to one row instead of 17. Anything sitting at the set root has no
44
+ // directory name worth showing — threat-model.md and the interface contract live
45
+ // beside ARCHITECTURE.md — so the whole root heads one Architecture section.
46
+ //
47
+ // Compare resolved directories, never the path's spelling. `basename(dirname())`
48
+ // reads the *argument*: the same set rendered from inside its own directory gave
49
+ // a rail section titled "." while an absolute --docs gave one named after the set
50
+ // folder. Index 0 was special-cased out of it, so every other root-level
51
+ // companion fell through.
52
+ const DECISIONS = /^(adrs?|decisions?|rfcs?)$/;
53
+
54
+ function sectionOf(path, index, root) {
55
+ if (index === 0) return 'Architecture';
56
+ const dir = dirname(resolve(path));
57
+ if (dir === resolve(root)) return 'Architecture';
58
+ const name = basename(dir).toLowerCase();
59
+ if (DECISIONS.test(name)) return 'Decision Records';
60
+ return name.replace(/[-_]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
61
+ }
62
+
63
+ // A record is read *because* of the row that referenced it, so it opens over that
64
+ // row rather than replacing the page — §14 already tables every ADR, and a rail
65
+ // section for them is that table a second time.
66
+ function drawerOf(path, index) {
67
+ return index > 0 && DECISIONS.test(basename(dirname(path)).toLowerCase());
68
+ }
69
+
70
+ const args = parseArgs(process.argv.slice(2));
71
+ const archMd = readFileSync(args.arch, 'utf8');
72
+ const docPaths = [args.arch, ...args.docs];
73
+ const slugs = new Map();
74
+ const docSlugs = new Map();
75
+ const pages = docPaths.map((p, i) => ({
76
+ ...renderMarkdown(readFileSync(p, 'utf8'), slugs, docSlugs),
77
+ section: sectionOf(p, i, args.root),
78
+ path: resolve(p),
79
+ spine: i === 0,
80
+ drawer: drawerOf(p, i),
81
+ kind: kindOf(p, i),
82
+ }));
83
+
84
+ // Second pass, because a link's target id is only known once every document has
85
+ // been rendered: the id comes from the target's H1, not from its filename.
86
+ const idByPath = new Map(pages.map((p) => [p.path, p.docId]));
87
+ const linked = pages.map((p) => ({
88
+ ...p,
89
+ html: estimateLink(p, args.out) + rewriteDocLinks(p.html, p.path, idByPath),
90
+ }));
91
+ const routes = routeMap(linked);
92
+
93
+ // The last point at which an off-palette bundle can still be stopped. A model
94
+ // that declares no colours is valid, generates clean and exits 0, so nothing
95
+ // upstream reports anything — the diagrams simply arrive in LikeC4's default
96
+ // blue beside teal mermaid ones. Checked here because this is where the bundle
97
+ // is read, and refused rather than warned about: a viewer is worth building only
98
+ // if its two diagram renderers agree.
99
+ const likec4Bundle = readFileSync(args['likec4-bundle'], 'utf8');
100
+ const themeJson = readFileSync(args.theme, 'utf8');
101
+ const paletteFindings = validatePalette({ bundle: likec4Bundle, theme: JSON.parse(themeJson) });
102
+ if (paletteFindings.length) {
103
+ throw new Error(`${paletteFindings.join('\n')}\n`
104
+ + 'Write the config with scripts/likec4-config.mjs, then re-run likec4 gen webcomponent.');
105
+ }
106
+
107
+ const templateUrl = new URL('../assets/viewer-template.html', import.meta.url);
108
+ const template = readFileSync(templateUrl, 'utf8');
109
+ // Shipped with the skill rather than passed in: unlike the two bundles these are
110
+ // fixed bytes that never need regenerating, so there is nothing for a caller to
111
+ // choose and no build step to get wrong.
112
+ const fontsDir = new URL('../assets/fonts/', import.meta.url).pathname;
113
+ const html = embed({
114
+ template,
115
+ slots: {
116
+ TITLE: docTitle(archMd),
117
+ FONTS: buildFontFaces(fontsDir),
118
+ NAV: buildNav(linked, routes),
119
+ DOC: buildDoc(linked, routes),
120
+ LIKEC4_BUNDLE: stripRemoteAssets(likec4Bundle),
121
+ MERMAID_BUNDLE: stripRemoteAssets(readFileSync(args['mermaid-bundle'], 'utf8')),
122
+ THEME: themeJson,
123
+ SECTION_HELP: serialiseHelp(sectionHelp()),
124
+ },
125
+ });
126
+
127
+ mkdirSync(args.out, { recursive: true });
128
+ const outPath = join(args.out, 'index.html');
129
+ writeFileSync(outPath, html);
130
+ console.log(outPath);