@libar-dev/architect 1.0.0-pre.3

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 (800) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/LICENSE +25 -0
  3. package/LICENSE-MCP +62 -0
  4. package/README.md +147 -0
  5. package/dist/api/arch-queries.d.ts +95 -0
  6. package/dist/api/arch-queries.d.ts.map +1 -0
  7. package/dist/api/arch-queries.js +310 -0
  8. package/dist/api/arch-queries.js.map +1 -0
  9. package/dist/api/context-assembler.d.ts +124 -0
  10. package/dist/api/context-assembler.d.ts.map +1 -0
  11. package/dist/api/context-assembler.js +472 -0
  12. package/dist/api/context-assembler.js.map +1 -0
  13. package/dist/api/context-formatter.d.ts +26 -0
  14. package/dist/api/context-formatter.d.ts.map +1 -0
  15. package/dist/api/context-formatter.js +183 -0
  16. package/dist/api/context-formatter.js.map +1 -0
  17. package/dist/api/coverage-analyzer.d.ts +38 -0
  18. package/dist/api/coverage-analyzer.d.ts.map +1 -0
  19. package/dist/api/coverage-analyzer.js +117 -0
  20. package/dist/api/coverage-analyzer.js.map +1 -0
  21. package/dist/api/fuzzy-match.d.ts +75 -0
  22. package/dist/api/fuzzy-match.d.ts.map +1 -0
  23. package/dist/api/fuzzy-match.js +150 -0
  24. package/dist/api/fuzzy-match.js.map +1 -0
  25. package/dist/api/handoff-generator.d.ts +45 -0
  26. package/dist/api/handoff-generator.d.ts.map +1 -0
  27. package/dist/api/handoff-generator.js +139 -0
  28. package/dist/api/handoff-generator.js.map +1 -0
  29. package/dist/api/index.d.ts +61 -0
  30. package/dist/api/index.d.ts.map +1 -0
  31. package/dist/api/index.js +54 -0
  32. package/dist/api/index.js.map +1 -0
  33. package/dist/api/pattern-helpers.d.ts +51 -0
  34. package/dist/api/pattern-helpers.d.ts.map +1 -0
  35. package/dist/api/pattern-helpers.js +84 -0
  36. package/dist/api/pattern-helpers.js.map +1 -0
  37. package/dist/api/process-state.d.ts +224 -0
  38. package/dist/api/process-state.d.ts.map +1 -0
  39. package/dist/api/process-state.js +308 -0
  40. package/dist/api/process-state.js.map +1 -0
  41. package/dist/api/rules-query.d.ts +60 -0
  42. package/dist/api/rules-query.d.ts.map +1 -0
  43. package/dist/api/rules-query.js +154 -0
  44. package/dist/api/rules-query.js.map +1 -0
  45. package/dist/api/scope-validator.d.ts +56 -0
  46. package/dist/api/scope-validator.d.ts.map +1 -0
  47. package/dist/api/scope-validator.js +293 -0
  48. package/dist/api/scope-validator.js.map +1 -0
  49. package/dist/api/stub-resolver.d.ts +117 -0
  50. package/dist/api/stub-resolver.d.ts.map +1 -0
  51. package/dist/api/stub-resolver.js +154 -0
  52. package/dist/api/stub-resolver.js.map +1 -0
  53. package/dist/api/summarize.d.ts +75 -0
  54. package/dist/api/summarize.d.ts.map +1 -0
  55. package/dist/api/summarize.js +97 -0
  56. package/dist/api/summarize.js.map +1 -0
  57. package/dist/api/types.d.ts +221 -0
  58. package/dist/api/types.d.ts.map +1 -0
  59. package/dist/api/types.js +57 -0
  60. package/dist/api/types.js.map +1 -0
  61. package/dist/cache/file-cache.d.ts +72 -0
  62. package/dist/cache/file-cache.d.ts.map +1 -0
  63. package/dist/cache/file-cache.js +80 -0
  64. package/dist/cache/file-cache.js.map +1 -0
  65. package/dist/cache/index.d.ts +5 -0
  66. package/dist/cache/index.d.ts.map +1 -0
  67. package/dist/cache/index.js +5 -0
  68. package/dist/cache/index.js.map +1 -0
  69. package/dist/cli/cli-schema.d.ts +83 -0
  70. package/dist/cli/cli-schema.d.ts.map +1 -0
  71. package/dist/cli/cli-schema.js +505 -0
  72. package/dist/cli/cli-schema.js.map +1 -0
  73. package/dist/cli/dataset-cache.d.ts +66 -0
  74. package/dist/cli/dataset-cache.d.ts.map +1 -0
  75. package/dist/cli/dataset-cache.js +179 -0
  76. package/dist/cli/dataset-cache.js.map +1 -0
  77. package/dist/cli/error-handler.d.ts +84 -0
  78. package/dist/cli/error-handler.d.ts.map +1 -0
  79. package/dist/cli/error-handler.js +197 -0
  80. package/dist/cli/error-handler.js.map +1 -0
  81. package/dist/cli/generate-docs.d.ts +30 -0
  82. package/dist/cli/generate-docs.d.ts.map +1 -0
  83. package/dist/cli/generate-docs.js +370 -0
  84. package/dist/cli/generate-docs.js.map +1 -0
  85. package/dist/cli/lint-patterns.d.ts +57 -0
  86. package/dist/cli/lint-patterns.d.ts.map +1 -0
  87. package/dist/cli/lint-patterns.js +257 -0
  88. package/dist/cli/lint-patterns.js.map +1 -0
  89. package/dist/cli/lint-process.d.ts +54 -0
  90. package/dist/cli/lint-process.d.ts.map +1 -0
  91. package/dist/cli/lint-process.js +319 -0
  92. package/dist/cli/lint-process.js.map +1 -0
  93. package/dist/cli/lint-steps.d.ts +32 -0
  94. package/dist/cli/lint-steps.d.ts.map +1 -0
  95. package/dist/cli/lint-steps.js +172 -0
  96. package/dist/cli/lint-steps.js.map +1 -0
  97. package/dist/cli/mcp-server.d.ts +22 -0
  98. package/dist/cli/mcp-server.d.ts.map +1 -0
  99. package/dist/cli/mcp-server.js +57 -0
  100. package/dist/cli/mcp-server.js.map +1 -0
  101. package/dist/cli/output-pipeline.d.ts +130 -0
  102. package/dist/cli/output-pipeline.d.ts.map +1 -0
  103. package/dist/cli/output-pipeline.js +234 -0
  104. package/dist/cli/output-pipeline.js.map +1 -0
  105. package/dist/cli/process-api.d.ts +37 -0
  106. package/dist/cli/process-api.d.ts.map +1 -0
  107. package/dist/cli/process-api.js +1550 -0
  108. package/dist/cli/process-api.js.map +1 -0
  109. package/dist/cli/repl.d.ts +38 -0
  110. package/dist/cli/repl.d.ts.map +1 -0
  111. package/dist/cli/repl.js +239 -0
  112. package/dist/cli/repl.js.map +1 -0
  113. package/dist/cli/validate-patterns.d.ts +115 -0
  114. package/dist/cli/validate-patterns.d.ts.map +1 -0
  115. package/dist/cli/validate-patterns.js +707 -0
  116. package/dist/cli/validate-patterns.js.map +1 -0
  117. package/dist/cli/version.d.ts +35 -0
  118. package/dist/cli/version.d.ts.map +1 -0
  119. package/dist/cli/version.js +64 -0
  120. package/dist/cli/version.js.map +1 -0
  121. package/dist/config/config-loader.d.ts +167 -0
  122. package/dist/config/config-loader.d.ts.map +1 -0
  123. package/dist/config/config-loader.js +294 -0
  124. package/dist/config/config-loader.js.map +1 -0
  125. package/dist/config/defaults.d.ts +92 -0
  126. package/dist/config/defaults.d.ts.map +1 -0
  127. package/dist/config/defaults.js +103 -0
  128. package/dist/config/defaults.js.map +1 -0
  129. package/dist/config/define-config.d.ts +37 -0
  130. package/dist/config/define-config.d.ts.map +1 -0
  131. package/dist/config/define-config.js +38 -0
  132. package/dist/config/define-config.js.map +1 -0
  133. package/dist/config/factory.d.ts +79 -0
  134. package/dist/config/factory.d.ts.map +1 -0
  135. package/dist/config/factory.js +116 -0
  136. package/dist/config/factory.js.map +1 -0
  137. package/dist/config/index.d.ts +45 -0
  138. package/dist/config/index.d.ts.map +1 -0
  139. package/dist/config/index.js +48 -0
  140. package/dist/config/index.js.map +1 -0
  141. package/dist/config/merge-sources.d.ts +47 -0
  142. package/dist/config/merge-sources.d.ts.map +1 -0
  143. package/dist/config/merge-sources.js +61 -0
  144. package/dist/config/merge-sources.js.map +1 -0
  145. package/dist/config/presets.d.ts +115 -0
  146. package/dist/config/presets.d.ts.map +1 -0
  147. package/dist/config/presets.js +119 -0
  148. package/dist/config/presets.js.map +1 -0
  149. package/dist/config/project-config-schema.d.ts +192 -0
  150. package/dist/config/project-config-schema.d.ts.map +1 -0
  151. package/dist/config/project-config-schema.js +231 -0
  152. package/dist/config/project-config-schema.js.map +1 -0
  153. package/dist/config/project-config.d.ts +229 -0
  154. package/dist/config/project-config.d.ts.map +1 -0
  155. package/dist/config/project-config.js +37 -0
  156. package/dist/config/project-config.js.map +1 -0
  157. package/dist/config/regex-builders.d.ts +49 -0
  158. package/dist/config/regex-builders.d.ts.map +1 -0
  159. package/dist/config/regex-builders.js +85 -0
  160. package/dist/config/regex-builders.js.map +1 -0
  161. package/dist/config/resolve-config.d.ts +65 -0
  162. package/dist/config/resolve-config.d.ts.map +1 -0
  163. package/dist/config/resolve-config.js +150 -0
  164. package/dist/config/resolve-config.js.map +1 -0
  165. package/dist/config/types.d.ts +81 -0
  166. package/dist/config/types.d.ts.map +1 -0
  167. package/dist/config/types.js +22 -0
  168. package/dist/config/types.js.map +1 -0
  169. package/dist/config/workflow-loader.d.ts +90 -0
  170. package/dist/config/workflow-loader.d.ts.map +1 -0
  171. package/dist/config/workflow-loader.js +167 -0
  172. package/dist/config/workflow-loader.js.map +1 -0
  173. package/dist/extractor/doc-extractor.d.ts +233 -0
  174. package/dist/extractor/doc-extractor.d.ts.map +1 -0
  175. package/dist/extractor/doc-extractor.js +481 -0
  176. package/dist/extractor/doc-extractor.js.map +1 -0
  177. package/dist/extractor/dual-source-extractor.d.ts +161 -0
  178. package/dist/extractor/dual-source-extractor.d.ts.map +1 -0
  179. package/dist/extractor/dual-source-extractor.js +407 -0
  180. package/dist/extractor/dual-source-extractor.js.map +1 -0
  181. package/dist/extractor/gherkin-extractor.d.ts +170 -0
  182. package/dist/extractor/gherkin-extractor.d.ts.map +1 -0
  183. package/dist/extractor/gherkin-extractor.js +543 -0
  184. package/dist/extractor/gherkin-extractor.js.map +1 -0
  185. package/dist/extractor/index.d.ts +7 -0
  186. package/dist/extractor/index.d.ts.map +1 -0
  187. package/dist/extractor/index.js +11 -0
  188. package/dist/extractor/index.js.map +1 -0
  189. package/dist/extractor/layer-inference.d.ts +66 -0
  190. package/dist/extractor/layer-inference.d.ts.map +1 -0
  191. package/dist/extractor/layer-inference.js +93 -0
  192. package/dist/extractor/layer-inference.js.map +1 -0
  193. package/dist/extractor/shape-extractor.d.ts +79 -0
  194. package/dist/extractor/shape-extractor.d.ts.map +1 -0
  195. package/dist/extractor/shape-extractor.js +966 -0
  196. package/dist/extractor/shape-extractor.js.map +1 -0
  197. package/dist/generators/built-in/cli-recipe-generator.d.ts +30 -0
  198. package/dist/generators/built-in/cli-recipe-generator.d.ts.map +1 -0
  199. package/dist/generators/built-in/cli-recipe-generator.js +155 -0
  200. package/dist/generators/built-in/cli-recipe-generator.js.map +1 -0
  201. package/dist/generators/built-in/codec-generators.d.ts +29 -0
  202. package/dist/generators/built-in/codec-generators.d.ts.map +1 -0
  203. package/dist/generators/built-in/codec-generators.js +195 -0
  204. package/dist/generators/built-in/codec-generators.js.map +1 -0
  205. package/dist/generators/built-in/decision-doc-generator.d.ts +204 -0
  206. package/dist/generators/built-in/decision-doc-generator.d.ts.map +1 -0
  207. package/dist/generators/built-in/decision-doc-generator.js +654 -0
  208. package/dist/generators/built-in/decision-doc-generator.js.map +1 -0
  209. package/dist/generators/built-in/design-review-generator.d.ts +26 -0
  210. package/dist/generators/built-in/design-review-generator.d.ts.map +1 -0
  211. package/dist/generators/built-in/design-review-generator.js +94 -0
  212. package/dist/generators/built-in/design-review-generator.js.map +1 -0
  213. package/dist/generators/built-in/index.d.ts +22 -0
  214. package/dist/generators/built-in/index.d.ts.map +1 -0
  215. package/dist/generators/built-in/index.js +23 -0
  216. package/dist/generators/built-in/index.js.map +1 -0
  217. package/dist/generators/built-in/process-api-reference-generator.d.ts +18 -0
  218. package/dist/generators/built-in/process-api-reference-generator.d.ts.map +1 -0
  219. package/dist/generators/built-in/process-api-reference-generator.js +85 -0
  220. package/dist/generators/built-in/process-api-reference-generator.js.map +1 -0
  221. package/dist/generators/built-in/reference-generators.d.ts +51 -0
  222. package/dist/generators/built-in/reference-generators.d.ts.map +1 -0
  223. package/dist/generators/built-in/reference-generators.js +320 -0
  224. package/dist/generators/built-in/reference-generators.js.map +1 -0
  225. package/dist/generators/codec-based.d.ts +63 -0
  226. package/dist/generators/codec-based.d.ts.map +1 -0
  227. package/dist/generators/codec-based.js +88 -0
  228. package/dist/generators/codec-based.js.map +1 -0
  229. package/dist/generators/content-deduplicator.d.ts +114 -0
  230. package/dist/generators/content-deduplicator.d.ts.map +1 -0
  231. package/dist/generators/content-deduplicator.js +356 -0
  232. package/dist/generators/content-deduplicator.js.map +1 -0
  233. package/dist/generators/index.d.ts +50 -0
  234. package/dist/generators/index.d.ts.map +1 -0
  235. package/dist/generators/index.js +54 -0
  236. package/dist/generators/index.js.map +1 -0
  237. package/dist/generators/orchestrator.d.ts +265 -0
  238. package/dist/generators/orchestrator.d.ts.map +1 -0
  239. package/dist/generators/orchestrator.js +570 -0
  240. package/dist/generators/orchestrator.js.map +1 -0
  241. package/dist/generators/pipeline/build-pipeline.d.ts +131 -0
  242. package/dist/generators/pipeline/build-pipeline.d.ts.map +1 -0
  243. package/dist/generators/pipeline/build-pipeline.js +248 -0
  244. package/dist/generators/pipeline/build-pipeline.js.map +1 -0
  245. package/dist/generators/pipeline/context-inference.d.ts +55 -0
  246. package/dist/generators/pipeline/context-inference.d.ts.map +1 -0
  247. package/dist/generators/pipeline/context-inference.js +76 -0
  248. package/dist/generators/pipeline/context-inference.js.map +1 -0
  249. package/dist/generators/pipeline/index.d.ts +27 -0
  250. package/dist/generators/pipeline/index.d.ts.map +1 -0
  251. package/dist/generators/pipeline/index.js +34 -0
  252. package/dist/generators/pipeline/index.js.map +1 -0
  253. package/dist/generators/pipeline/merge-patterns.d.ts +33 -0
  254. package/dist/generators/pipeline/merge-patterns.d.ts.map +1 -0
  255. package/dist/generators/pipeline/merge-patterns.js +50 -0
  256. package/dist/generators/pipeline/merge-patterns.js.map +1 -0
  257. package/dist/generators/pipeline/relationship-resolver.d.ts +47 -0
  258. package/dist/generators/pipeline/relationship-resolver.d.ts.map +1 -0
  259. package/dist/generators/pipeline/relationship-resolver.js +132 -0
  260. package/dist/generators/pipeline/relationship-resolver.js.map +1 -0
  261. package/dist/generators/pipeline/sequence-utils.d.ts +49 -0
  262. package/dist/generators/pipeline/sequence-utils.d.ts.map +1 -0
  263. package/dist/generators/pipeline/sequence-utils.js +235 -0
  264. package/dist/generators/pipeline/sequence-utils.js.map +1 -0
  265. package/dist/generators/pipeline/transform-dataset.d.ts +82 -0
  266. package/dist/generators/pipeline/transform-dataset.d.ts.map +1 -0
  267. package/dist/generators/pipeline/transform-dataset.js +355 -0
  268. package/dist/generators/pipeline/transform-dataset.js.map +1 -0
  269. package/dist/generators/pipeline/transform-types.d.ts +96 -0
  270. package/dist/generators/pipeline/transform-types.d.ts.map +1 -0
  271. package/dist/generators/pipeline/transform-types.js +18 -0
  272. package/dist/generators/pipeline/transform-types.js.map +1 -0
  273. package/dist/generators/registry.d.ts +64 -0
  274. package/dist/generators/registry.d.ts.map +1 -0
  275. package/dist/generators/registry.js +77 -0
  276. package/dist/generators/registry.js.map +1 -0
  277. package/dist/generators/source-mapper.d.ts +143 -0
  278. package/dist/generators/source-mapper.d.ts.map +1 -0
  279. package/dist/generators/source-mapper.js +602 -0
  280. package/dist/generators/source-mapper.js.map +1 -0
  281. package/dist/generators/source-mapping-validator.d.ts +118 -0
  282. package/dist/generators/source-mapping-validator.d.ts.map +1 -0
  283. package/dist/generators/source-mapping-validator.js +334 -0
  284. package/dist/generators/source-mapping-validator.js.map +1 -0
  285. package/dist/generators/types.d.ts +104 -0
  286. package/dist/generators/types.d.ts.map +1 -0
  287. package/dist/generators/types.js +5 -0
  288. package/dist/generators/types.js.map +1 -0
  289. package/dist/generators/warning-collector.d.ts +144 -0
  290. package/dist/generators/warning-collector.d.ts.map +1 -0
  291. package/dist/generators/warning-collector.js +166 -0
  292. package/dist/generators/warning-collector.js.map +1 -0
  293. package/dist/git/branch-diff.d.ts +44 -0
  294. package/dist/git/branch-diff.d.ts.map +1 -0
  295. package/dist/git/branch-diff.js +57 -0
  296. package/dist/git/branch-diff.js.map +1 -0
  297. package/dist/git/helpers.d.ts +46 -0
  298. package/dist/git/helpers.d.ts.map +1 -0
  299. package/dist/git/helpers.js +67 -0
  300. package/dist/git/helpers.js.map +1 -0
  301. package/dist/git/index.d.ts +18 -0
  302. package/dist/git/index.d.ts.map +1 -0
  303. package/dist/git/index.js +18 -0
  304. package/dist/git/index.js.map +1 -0
  305. package/dist/git/name-status.d.ts +32 -0
  306. package/dist/git/name-status.d.ts.map +1 -0
  307. package/dist/git/name-status.js +66 -0
  308. package/dist/git/name-status.js.map +1 -0
  309. package/dist/index.d.ts +107 -0
  310. package/dist/index.d.ts.map +1 -0
  311. package/dist/index.js +122 -0
  312. package/dist/index.js.map +1 -0
  313. package/dist/lint/engine.d.ts +113 -0
  314. package/dist/lint/engine.d.ts.map +1 -0
  315. package/dist/lint/engine.js +228 -0
  316. package/dist/lint/engine.js.map +1 -0
  317. package/dist/lint/index.d.ts +26 -0
  318. package/dist/lint/index.d.ts.map +1 -0
  319. package/dist/lint/index.js +24 -0
  320. package/dist/lint/index.js.map +1 -0
  321. package/dist/lint/process-guard/decider.d.ts +166 -0
  322. package/dist/lint/process-guard/decider.d.ts.map +1 -0
  323. package/dist/lint/process-guard/decider.js +412 -0
  324. package/dist/lint/process-guard/decider.js.map +1 -0
  325. package/dist/lint/process-guard/derive-state.d.ts +96 -0
  326. package/dist/lint/process-guard/derive-state.d.ts.map +1 -0
  327. package/dist/lint/process-guard/derive-state.js +368 -0
  328. package/dist/lint/process-guard/derive-state.js.map +1 -0
  329. package/dist/lint/process-guard/detect-changes.d.ts +109 -0
  330. package/dist/lint/process-guard/detect-changes.d.ts.map +1 -0
  331. package/dist/lint/process-guard/detect-changes.js +487 -0
  332. package/dist/lint/process-guard/detect-changes.js.map +1 -0
  333. package/dist/lint/process-guard/index.d.ts +35 -0
  334. package/dist/lint/process-guard/index.d.ts.map +1 -0
  335. package/dist/lint/process-guard/index.js +39 -0
  336. package/dist/lint/process-guard/index.js.map +1 -0
  337. package/dist/lint/process-guard/types.d.ts +255 -0
  338. package/dist/lint/process-guard/types.d.ts.map +1 -0
  339. package/dist/lint/process-guard/types.js +31 -0
  340. package/dist/lint/process-guard/types.js.map +1 -0
  341. package/dist/lint/rules.d.ts +147 -0
  342. package/dist/lint/rules.d.ts.map +1 -0
  343. package/dist/lint/rules.js +289 -0
  344. package/dist/lint/rules.js.map +1 -0
  345. package/dist/lint/steps/cross-checks.d.ts +66 -0
  346. package/dist/lint/steps/cross-checks.d.ts.map +1 -0
  347. package/dist/lint/steps/cross-checks.js +290 -0
  348. package/dist/lint/steps/cross-checks.js.map +1 -0
  349. package/dist/lint/steps/feature-checks.d.ts +78 -0
  350. package/dist/lint/steps/feature-checks.d.ts.map +1 -0
  351. package/dist/lint/steps/feature-checks.js +279 -0
  352. package/dist/lint/steps/feature-checks.js.map +1 -0
  353. package/dist/lint/steps/index.d.ts +22 -0
  354. package/dist/lint/steps/index.d.ts.map +1 -0
  355. package/dist/lint/steps/index.js +26 -0
  356. package/dist/lint/steps/index.js.map +1 -0
  357. package/dist/lint/steps/pair-resolver.d.ts +29 -0
  358. package/dist/lint/steps/pair-resolver.d.ts.map +1 -0
  359. package/dist/lint/steps/pair-resolver.js +76 -0
  360. package/dist/lint/steps/pair-resolver.js.map +1 -0
  361. package/dist/lint/steps/runner.d.ts +28 -0
  362. package/dist/lint/steps/runner.d.ts.map +1 -0
  363. package/dist/lint/steps/runner.js +143 -0
  364. package/dist/lint/steps/runner.js.map +1 -0
  365. package/dist/lint/steps/step-checks.d.ts +41 -0
  366. package/dist/lint/steps/step-checks.d.ts.map +1 -0
  367. package/dist/lint/steps/step-checks.js +164 -0
  368. package/dist/lint/steps/step-checks.js.map +1 -0
  369. package/dist/lint/steps/types.d.ts +95 -0
  370. package/dist/lint/steps/types.d.ts.map +1 -0
  371. package/dist/lint/steps/types.js +79 -0
  372. package/dist/lint/steps/types.js.map +1 -0
  373. package/dist/lint/steps/utils.d.ts +22 -0
  374. package/dist/lint/steps/utils.d.ts.map +1 -0
  375. package/dist/lint/steps/utils.js +57 -0
  376. package/dist/lint/steps/utils.js.map +1 -0
  377. package/dist/mcp/file-watcher.d.ts +24 -0
  378. package/dist/mcp/file-watcher.d.ts.map +1 -0
  379. package/dist/mcp/file-watcher.js +75 -0
  380. package/dist/mcp/file-watcher.js.map +1 -0
  381. package/dist/mcp/index.d.ts +19 -0
  382. package/dist/mcp/index.d.ts.map +1 -0
  383. package/dist/mcp/index.js +21 -0
  384. package/dist/mcp/index.js.map +1 -0
  385. package/dist/mcp/pipeline-session.d.ts +33 -0
  386. package/dist/mcp/pipeline-session.d.ts.map +1 -0
  387. package/dist/mcp/pipeline-session.js +149 -0
  388. package/dist/mcp/pipeline-session.js.map +1 -0
  389. package/dist/mcp/server.d.ts +28 -0
  390. package/dist/mcp/server.d.ts.map +1 -0
  391. package/dist/mcp/server.js +197 -0
  392. package/dist/mcp/server.js.map +1 -0
  393. package/dist/mcp/tool-registry.d.ts +4 -0
  394. package/dist/mcp/tool-registry.d.ts.map +1 -0
  395. package/dist/mcp/tool-registry.js +525 -0
  396. package/dist/mcp/tool-registry.js.map +1 -0
  397. package/dist/renderable/codecs/adr.d.ts +4730 -0
  398. package/dist/renderable/codecs/adr.d.ts.map +1 -0
  399. package/dist/renderable/codecs/adr.js +590 -0
  400. package/dist/renderable/codecs/adr.js.map +1 -0
  401. package/dist/renderable/codecs/architecture.d.ts +4760 -0
  402. package/dist/renderable/codecs/architecture.d.ts.map +1 -0
  403. package/dist/renderable/codecs/architecture.js +524 -0
  404. package/dist/renderable/codecs/architecture.js.map +1 -0
  405. package/dist/renderable/codecs/business-rules.d.ts +4777 -0
  406. package/dist/renderable/codecs/business-rules.d.ts.map +1 -0
  407. package/dist/renderable/codecs/business-rules.js +648 -0
  408. package/dist/renderable/codecs/business-rules.js.map +1 -0
  409. package/dist/renderable/codecs/claude-module.d.ts +4710 -0
  410. package/dist/renderable/codecs/claude-module.d.ts.map +1 -0
  411. package/dist/renderable/codecs/claude-module.js +214 -0
  412. package/dist/renderable/codecs/claude-module.js.map +1 -0
  413. package/dist/renderable/codecs/composite.d.ts +84 -0
  414. package/dist/renderable/codecs/composite.d.ts.map +1 -0
  415. package/dist/renderable/codecs/composite.js +124 -0
  416. package/dist/renderable/codecs/composite.js.map +1 -0
  417. package/dist/renderable/codecs/convention-extractor.d.ts +105 -0
  418. package/dist/renderable/codecs/convention-extractor.d.ts.map +1 -0
  419. package/dist/renderable/codecs/convention-extractor.js +353 -0
  420. package/dist/renderable/codecs/convention-extractor.js.map +1 -0
  421. package/dist/renderable/codecs/decision-doc.d.ts +308 -0
  422. package/dist/renderable/codecs/decision-doc.d.ts.map +1 -0
  423. package/dist/renderable/codecs/decision-doc.js +485 -0
  424. package/dist/renderable/codecs/decision-doc.js.map +1 -0
  425. package/dist/renderable/codecs/design-review.d.ts +55 -0
  426. package/dist/renderable/codecs/design-review.d.ts.map +1 -0
  427. package/dist/renderable/codecs/design-review.js +532 -0
  428. package/dist/renderable/codecs/design-review.js.map +1 -0
  429. package/dist/renderable/codecs/diagram-utils.d.ts +62 -0
  430. package/dist/renderable/codecs/diagram-utils.d.ts.map +1 -0
  431. package/dist/renderable/codecs/diagram-utils.js +70 -0
  432. package/dist/renderable/codecs/diagram-utils.js.map +1 -0
  433. package/dist/renderable/codecs/helpers.d.ts +553 -0
  434. package/dist/renderable/codecs/helpers.d.ts.map +1 -0
  435. package/dist/renderable/codecs/helpers.js +913 -0
  436. package/dist/renderable/codecs/helpers.js.map +1 -0
  437. package/dist/renderable/codecs/index-codec.d.ts +4714 -0
  438. package/dist/renderable/codecs/index-codec.d.ts.map +1 -0
  439. package/dist/renderable/codecs/index-codec.js +250 -0
  440. package/dist/renderable/codecs/index-codec.js.map +1 -0
  441. package/dist/renderable/codecs/index.d.ts +46 -0
  442. package/dist/renderable/codecs/index.d.ts.map +1 -0
  443. package/dist/renderable/codecs/index.js +70 -0
  444. package/dist/renderable/codecs/index.js.map +1 -0
  445. package/dist/renderable/codecs/patterns.d.ts +4757 -0
  446. package/dist/renderable/codecs/patterns.d.ts.map +1 -0
  447. package/dist/renderable/codecs/patterns.js +462 -0
  448. package/dist/renderable/codecs/patterns.js.map +1 -0
  449. package/dist/renderable/codecs/planning.d.ts +14055 -0
  450. package/dist/renderable/codecs/planning.d.ts.map +1 -0
  451. package/dist/renderable/codecs/planning.js +449 -0
  452. package/dist/renderable/codecs/planning.js.map +1 -0
  453. package/dist/renderable/codecs/pr-changes.d.ts +4742 -0
  454. package/dist/renderable/codecs/pr-changes.d.ts.map +1 -0
  455. package/dist/renderable/codecs/pr-changes.js +425 -0
  456. package/dist/renderable/codecs/pr-changes.js.map +1 -0
  457. package/dist/renderable/codecs/reference.d.ts +215 -0
  458. package/dist/renderable/codecs/reference.d.ts.map +1 -0
  459. package/dist/renderable/codecs/reference.js +1578 -0
  460. package/dist/renderable/codecs/reference.js.map +1 -0
  461. package/dist/renderable/codecs/reporting.d.ts +14026 -0
  462. package/dist/renderable/codecs/reporting.d.ts.map +1 -0
  463. package/dist/renderable/codecs/reporting.js +365 -0
  464. package/dist/renderable/codecs/reporting.js.map +1 -0
  465. package/dist/renderable/codecs/requirements.d.ts +4743 -0
  466. package/dist/renderable/codecs/requirements.d.ts.map +1 -0
  467. package/dist/renderable/codecs/requirements.js +428 -0
  468. package/dist/renderable/codecs/requirements.js.map +1 -0
  469. package/dist/renderable/codecs/session.d.ts +9410 -0
  470. package/dist/renderable/codecs/session.d.ts.map +1 -0
  471. package/dist/renderable/codecs/session.js +848 -0
  472. package/dist/renderable/codecs/session.js.map +1 -0
  473. package/dist/renderable/codecs/shape-matcher.d.ts +54 -0
  474. package/dist/renderable/codecs/shape-matcher.d.ts.map +1 -0
  475. package/dist/renderable/codecs/shape-matcher.js +106 -0
  476. package/dist/renderable/codecs/shape-matcher.js.map +1 -0
  477. package/dist/renderable/codecs/shared-schema.d.ts +44 -0
  478. package/dist/renderable/codecs/shared-schema.d.ts.map +1 -0
  479. package/dist/renderable/codecs/shared-schema.js +43 -0
  480. package/dist/renderable/codecs/shared-schema.js.map +1 -0
  481. package/dist/renderable/codecs/taxonomy.d.ts +4733 -0
  482. package/dist/renderable/codecs/taxonomy.d.ts.map +1 -0
  483. package/dist/renderable/codecs/taxonomy.js +570 -0
  484. package/dist/renderable/codecs/taxonomy.js.map +1 -0
  485. package/dist/renderable/codecs/timeline.d.ts +14094 -0
  486. package/dist/renderable/codecs/timeline.d.ts.map +1 -0
  487. package/dist/renderable/codecs/timeline.js +906 -0
  488. package/dist/renderable/codecs/timeline.js.map +1 -0
  489. package/dist/renderable/codecs/types/base.d.ts +81 -0
  490. package/dist/renderable/codecs/types/base.d.ts.map +1 -0
  491. package/dist/renderable/codecs/types/base.js +56 -0
  492. package/dist/renderable/codecs/types/base.js.map +1 -0
  493. package/dist/renderable/codecs/types/index.d.ts +5 -0
  494. package/dist/renderable/codecs/types/index.d.ts.map +1 -0
  495. package/dist/renderable/codecs/types/index.js +5 -0
  496. package/dist/renderable/codecs/types/index.js.map +1 -0
  497. package/dist/renderable/codecs/validation-rules.d.ts +4773 -0
  498. package/dist/renderable/codecs/validation-rules.d.ts.map +1 -0
  499. package/dist/renderable/codecs/validation-rules.js +537 -0
  500. package/dist/renderable/codecs/validation-rules.js.map +1 -0
  501. package/dist/renderable/generate.d.ts +338 -0
  502. package/dist/renderable/generate.d.ts.map +1 -0
  503. package/dist/renderable/generate.js +437 -0
  504. package/dist/renderable/generate.js.map +1 -0
  505. package/dist/renderable/index.d.ts +36 -0
  506. package/dist/renderable/index.d.ts.map +1 -0
  507. package/dist/renderable/index.js +58 -0
  508. package/dist/renderable/index.js.map +1 -0
  509. package/dist/renderable/load-preamble.d.ts +56 -0
  510. package/dist/renderable/load-preamble.d.ts.map +1 -0
  511. package/dist/renderable/load-preamble.js +298 -0
  512. package/dist/renderable/load-preamble.js.map +1 -0
  513. package/dist/renderable/render.d.ts +61 -0
  514. package/dist/renderable/render.d.ts.map +1 -0
  515. package/dist/renderable/render.js +346 -0
  516. package/dist/renderable/render.js.map +1 -0
  517. package/dist/renderable/schema.d.ts +194 -0
  518. package/dist/renderable/schema.d.ts.map +1 -0
  519. package/dist/renderable/schema.js +197 -0
  520. package/dist/renderable/schema.js.map +1 -0
  521. package/dist/renderable/utils.d.ts +146 -0
  522. package/dist/renderable/utils.d.ts.map +1 -0
  523. package/dist/renderable/utils.js +362 -0
  524. package/dist/renderable/utils.js.map +1 -0
  525. package/dist/scanner/ast-parser.d.ts +75 -0
  526. package/dist/scanner/ast-parser.d.ts.map +1 -0
  527. package/dist/scanner/ast-parser.js +835 -0
  528. package/dist/scanner/ast-parser.js.map +1 -0
  529. package/dist/scanner/gherkin-ast-parser.d.ts +166 -0
  530. package/dist/scanner/gherkin-ast-parser.d.ts.map +1 -0
  531. package/dist/scanner/gherkin-ast-parser.js +507 -0
  532. package/dist/scanner/gherkin-ast-parser.js.map +1 -0
  533. package/dist/scanner/gherkin-scanner.d.ts +106 -0
  534. package/dist/scanner/gherkin-scanner.d.ts.map +1 -0
  535. package/dist/scanner/gherkin-scanner.js +149 -0
  536. package/dist/scanner/gherkin-scanner.js.map +1 -0
  537. package/dist/scanner/index.d.ts +85 -0
  538. package/dist/scanner/index.d.ts.map +1 -0
  539. package/dist/scanner/index.js +102 -0
  540. package/dist/scanner/index.js.map +1 -0
  541. package/dist/scanner/pattern-scanner.d.ts +83 -0
  542. package/dist/scanner/pattern-scanner.d.ts.map +1 -0
  543. package/dist/scanner/pattern-scanner.js +110 -0
  544. package/dist/scanner/pattern-scanner.js.map +1 -0
  545. package/dist/taxonomy/categories.d.ts +47 -0
  546. package/dist/taxonomy/categories.d.ts.map +1 -0
  547. package/dist/taxonomy/categories.js +175 -0
  548. package/dist/taxonomy/categories.js.map +1 -0
  549. package/dist/taxonomy/claude-section-values.d.ts +12 -0
  550. package/dist/taxonomy/claude-section-values.d.ts.map +1 -0
  551. package/dist/taxonomy/claude-section-values.js +17 -0
  552. package/dist/taxonomy/claude-section-values.js.map +1 -0
  553. package/dist/taxonomy/conventions.d.ts +13 -0
  554. package/dist/taxonomy/conventions.d.ts.map +1 -0
  555. package/dist/taxonomy/conventions.js +27 -0
  556. package/dist/taxonomy/conventions.js.map +1 -0
  557. package/dist/taxonomy/deliverable-status.d.ts +99 -0
  558. package/dist/taxonomy/deliverable-status.d.ts.map +1 -0
  559. package/dist/taxonomy/deliverable-status.js +131 -0
  560. package/dist/taxonomy/deliverable-status.js.map +1 -0
  561. package/dist/taxonomy/format-types.d.ts +17 -0
  562. package/dist/taxonomy/format-types.d.ts.map +1 -0
  563. package/dist/taxonomy/format-types.js +23 -0
  564. package/dist/taxonomy/format-types.js.map +1 -0
  565. package/dist/taxonomy/generator-options.d.ts +67 -0
  566. package/dist/taxonomy/generator-options.d.ts.map +1 -0
  567. package/dist/taxonomy/generator-options.js +75 -0
  568. package/dist/taxonomy/generator-options.js.map +1 -0
  569. package/dist/taxonomy/hierarchy-levels.d.ts +23 -0
  570. package/dist/taxonomy/hierarchy-levels.d.ts.map +1 -0
  571. package/dist/taxonomy/hierarchy-levels.js +22 -0
  572. package/dist/taxonomy/hierarchy-levels.js.map +1 -0
  573. package/dist/taxonomy/index.d.ts +35 -0
  574. package/dist/taxonomy/index.d.ts.map +1 -0
  575. package/dist/taxonomy/index.js +56 -0
  576. package/dist/taxonomy/index.js.map +1 -0
  577. package/dist/taxonomy/layer-types.d.ts +22 -0
  578. package/dist/taxonomy/layer-types.d.ts.map +1 -0
  579. package/dist/taxonomy/layer-types.js +28 -0
  580. package/dist/taxonomy/layer-types.js.map +1 -0
  581. package/dist/taxonomy/normalized-status.d.ts +99 -0
  582. package/dist/taxonomy/normalized-status.d.ts.map +1 -0
  583. package/dist/taxonomy/normalized-status.js +113 -0
  584. package/dist/taxonomy/normalized-status.js.map +1 -0
  585. package/dist/taxonomy/registry-builder.d.ts +104 -0
  586. package/dist/taxonomy/registry-builder.d.ts.map +1 -0
  587. package/dist/taxonomy/registry-builder.js +561 -0
  588. package/dist/taxonomy/registry-builder.js.map +1 -0
  589. package/dist/taxonomy/risk-levels.d.ts +16 -0
  590. package/dist/taxonomy/risk-levels.d.ts.map +1 -0
  591. package/dist/taxonomy/risk-levels.js +15 -0
  592. package/dist/taxonomy/risk-levels.js.map +1 -0
  593. package/dist/taxonomy/severity-types.d.ts +6 -0
  594. package/dist/taxonomy/severity-types.d.ts.map +1 -0
  595. package/dist/taxonomy/severity-types.js +5 -0
  596. package/dist/taxonomy/severity-types.js.map +1 -0
  597. package/dist/taxonomy/status-values.d.ts +39 -0
  598. package/dist/taxonomy/status-values.d.ts.map +1 -0
  599. package/dist/taxonomy/status-values.js +42 -0
  600. package/dist/taxonomy/status-values.js.map +1 -0
  601. package/dist/types/branded.d.ts +89 -0
  602. package/dist/types/branded.d.ts.map +1 -0
  603. package/dist/types/branded.js +57 -0
  604. package/dist/types/branded.js.map +1 -0
  605. package/dist/types/errors.d.ts +342 -0
  606. package/dist/types/errors.d.ts.map +1 -0
  607. package/dist/types/errors.js +251 -0
  608. package/dist/types/errors.js.map +1 -0
  609. package/dist/types/index.d.ts +41 -0
  610. package/dist/types/index.d.ts.map +1 -0
  611. package/dist/types/index.js +5 -0
  612. package/dist/types/index.js.map +1 -0
  613. package/dist/types/result.d.ts +78 -0
  614. package/dist/types/result.d.ts.map +1 -0
  615. package/dist/types/result.js +78 -0
  616. package/dist/types/result.js.map +1 -0
  617. package/dist/utils/collection-utils.d.ts +49 -0
  618. package/dist/utils/collection-utils.d.ts.map +1 -0
  619. package/dist/utils/collection-utils.js +58 -0
  620. package/dist/utils/collection-utils.js.map +1 -0
  621. package/dist/utils/id-utils.d.ts +46 -0
  622. package/dist/utils/id-utils.d.ts.map +1 -0
  623. package/dist/utils/id-utils.js +51 -0
  624. package/dist/utils/id-utils.js.map +1 -0
  625. package/dist/utils/index.d.ts +21 -0
  626. package/dist/utils/index.d.ts.map +1 -0
  627. package/dist/utils/index.js +21 -0
  628. package/dist/utils/index.js.map +1 -0
  629. package/dist/utils/string-utils.d.ts +150 -0
  630. package/dist/utils/string-utils.d.ts.map +1 -0
  631. package/dist/utils/string-utils.js +281 -0
  632. package/dist/utils/string-utils.js.map +1 -0
  633. package/dist/validation/anti-patterns.d.ts +134 -0
  634. package/dist/validation/anti-patterns.d.ts.map +1 -0
  635. package/dist/validation/anti-patterns.js +307 -0
  636. package/dist/validation/anti-patterns.js.map +1 -0
  637. package/dist/validation/dod-validator.d.ts +94 -0
  638. package/dist/validation/dod-validator.d.ts.map +1 -0
  639. package/dist/validation/dod-validator.js +198 -0
  640. package/dist/validation/dod-validator.js.map +1 -0
  641. package/dist/validation/fsm/index.d.ts +59 -0
  642. package/dist/validation/fsm/index.d.ts.map +1 -0
  643. package/dist/validation/fsm/index.js +64 -0
  644. package/dist/validation/fsm/index.js.map +1 -0
  645. package/dist/validation/fsm/states.d.ts +93 -0
  646. package/dist/validation/fsm/states.d.ts.map +1 -0
  647. package/dist/validation/fsm/states.js +98 -0
  648. package/dist/validation/fsm/states.js.map +1 -0
  649. package/dist/validation/fsm/transitions.d.ts +100 -0
  650. package/dist/validation/fsm/transitions.d.ts.map +1 -0
  651. package/dist/validation/fsm/transitions.js +122 -0
  652. package/dist/validation/fsm/transitions.js.map +1 -0
  653. package/dist/validation/fsm/validator.d.ts +163 -0
  654. package/dist/validation/fsm/validator.d.ts.map +1 -0
  655. package/dist/validation/fsm/validator.js +205 -0
  656. package/dist/validation/fsm/validator.js.map +1 -0
  657. package/dist/validation/index.d.ts +23 -0
  658. package/dist/validation/index.d.ts.map +1 -0
  659. package/dist/validation/index.js +25 -0
  660. package/dist/validation/index.js.map +1 -0
  661. package/dist/validation/types.d.ts +136 -0
  662. package/dist/validation/types.d.ts.map +1 -0
  663. package/dist/validation/types.js +56 -0
  664. package/dist/validation/types.js.map +1 -0
  665. package/dist/validation-schemas/codec-utils.d.ts +188 -0
  666. package/dist/validation-schemas/codec-utils.d.ts.map +1 -0
  667. package/dist/validation-schemas/codec-utils.js +258 -0
  668. package/dist/validation-schemas/codec-utils.js.map +1 -0
  669. package/dist/validation-schemas/config.d.ts +99 -0
  670. package/dist/validation-schemas/config.d.ts.map +1 -0
  671. package/dist/validation-schemas/config.js +178 -0
  672. package/dist/validation-schemas/config.js.map +1 -0
  673. package/dist/validation-schemas/doc-directive.d.ts +195 -0
  674. package/dist/validation-schemas/doc-directive.d.ts.map +1 -0
  675. package/dist/validation-schemas/doc-directive.js +239 -0
  676. package/dist/validation-schemas/doc-directive.js.map +1 -0
  677. package/dist/validation-schemas/dual-source.d.ts +167 -0
  678. package/dist/validation-schemas/dual-source.d.ts.map +1 -0
  679. package/dist/validation-schemas/dual-source.js +168 -0
  680. package/dist/validation-schemas/dual-source.js.map +1 -0
  681. package/dist/validation-schemas/export-info.d.ts +53 -0
  682. package/dist/validation-schemas/export-info.d.ts.map +1 -0
  683. package/dist/validation-schemas/export-info.js +101 -0
  684. package/dist/validation-schemas/export-info.js.map +1 -0
  685. package/dist/validation-schemas/extracted-pattern.d.ts +351 -0
  686. package/dist/validation-schemas/extracted-pattern.d.ts.map +1 -0
  687. package/dist/validation-schemas/extracted-pattern.js +459 -0
  688. package/dist/validation-schemas/extracted-pattern.js.map +1 -0
  689. package/dist/validation-schemas/extracted-shape.d.ts +200 -0
  690. package/dist/validation-schemas/extracted-shape.d.ts.map +1 -0
  691. package/dist/validation-schemas/extracted-shape.js +182 -0
  692. package/dist/validation-schemas/extracted-shape.js.map +1 -0
  693. package/dist/validation-schemas/feature.d.ts +554 -0
  694. package/dist/validation-schemas/feature.d.ts.map +1 -0
  695. package/dist/validation-schemas/feature.js +262 -0
  696. package/dist/validation-schemas/feature.js.map +1 -0
  697. package/dist/validation-schemas/index.d.ts +15 -0
  698. package/dist/validation-schemas/index.d.ts.map +1 -0
  699. package/dist/validation-schemas/index.js +32 -0
  700. package/dist/validation-schemas/index.js.map +1 -0
  701. package/dist/validation-schemas/lint.d.ts +46 -0
  702. package/dist/validation-schemas/lint.d.ts.map +1 -0
  703. package/dist/validation-schemas/lint.js +45 -0
  704. package/dist/validation-schemas/lint.js.map +1 -0
  705. package/dist/validation-schemas/master-dataset.d.ts +8299 -0
  706. package/dist/validation-schemas/master-dataset.d.ts.map +1 -0
  707. package/dist/validation-schemas/master-dataset.js +275 -0
  708. package/dist/validation-schemas/master-dataset.js.map +1 -0
  709. package/dist/validation-schemas/output-schemas.d.ts +183 -0
  710. package/dist/validation-schemas/output-schemas.d.ts.map +1 -0
  711. package/dist/validation-schemas/output-schemas.js +149 -0
  712. package/dist/validation-schemas/output-schemas.js.map +1 -0
  713. package/dist/validation-schemas/scenario-ref.d.ts +80 -0
  714. package/dist/validation-schemas/scenario-ref.d.ts.map +1 -0
  715. package/dist/validation-schemas/scenario-ref.js +73 -0
  716. package/dist/validation-schemas/scenario-ref.js.map +1 -0
  717. package/dist/validation-schemas/tag-registry.d.ts +210 -0
  718. package/dist/validation-schemas/tag-registry.d.ts.map +1 -0
  719. package/dist/validation-schemas/tag-registry.js +248 -0
  720. package/dist/validation-schemas/tag-registry.js.map +1 -0
  721. package/dist/validation-schemas/workflow-config.d.ts +125 -0
  722. package/dist/validation-schemas/workflow-config.d.ts.map +1 -0
  723. package/dist/validation-schemas/workflow-config.js +138 -0
  724. package/dist/validation-schemas/workflow-config.js.map +1 -0
  725. package/docs/ANNOTATION-GUIDE.md +271 -0
  726. package/docs/ARCHITECTURE.md +1636 -0
  727. package/docs/CONFIGURATION.md +337 -0
  728. package/docs/DOCS-GAP-ANALYSIS.md +811 -0
  729. package/docs/GHERKIN-PATTERNS.md +366 -0
  730. package/docs/INDEX.md +345 -0
  731. package/docs/MCP-SETUP.md +140 -0
  732. package/docs/METHODOLOGY.md +240 -0
  733. package/docs/PROCESS-API.md +65 -0
  734. package/docs/PROCESS-GUARD.md +341 -0
  735. package/docs/SESSION-GUIDES.md +391 -0
  736. package/docs/TAXONOMY.md +106 -0
  737. package/docs/VALIDATION.md +418 -0
  738. package/docs-live/ARCHITECTURE.md +362 -0
  739. package/docs-live/BUSINESS-RULES.md +24 -0
  740. package/docs-live/CHANGELOG-GENERATED.md +375 -0
  741. package/docs-live/DECISIONS.md +78 -0
  742. package/docs-live/INDEX.md +231 -0
  743. package/docs-live/PRODUCT-AREAS.md +255 -0
  744. package/docs-live/TAXONOMY.md +202 -0
  745. package/docs-live/VALIDATION-RULES.md +119 -0
  746. package/docs-live/_claude-md/annotation/annotation-overview.md +26 -0
  747. package/docs-live/_claude-md/annotation/annotation-reference.md +213 -0
  748. package/docs-live/_claude-md/architecture/architecture-codecs.md +160 -0
  749. package/docs-live/_claude-md/architecture/architecture-types.md +32 -0
  750. package/docs-live/_claude-md/architecture/reference-sample.md +162 -0
  751. package/docs-live/_claude-md/authoring/gherkin-authoring-guide.md +245 -0
  752. package/docs-live/_claude-md/configuration/configuration-guide.md +216 -0
  753. package/docs-live/_claude-md/configuration/configuration-overview.md +37 -0
  754. package/docs-live/_claude-md/core-types/core-types-overview.md +20 -0
  755. package/docs-live/_claude-md/data-api/data-api-overview.md +39 -0
  756. package/docs-live/_claude-md/generation/generation-overview.md +30 -0
  757. package/docs-live/_claude-md/process/process-overview.md +127 -0
  758. package/docs-live/_claude-md/validation/process-guard.md +185 -0
  759. package/docs-live/_claude-md/validation/validation-overview.md +37 -0
  760. package/docs-live/_claude-md/validation/validation-tools-guide.md +242 -0
  761. package/docs-live/_claude-md/workflow/session-workflow-guide.md +141 -0
  762. package/docs-live/business-rules/annotation.md +1462 -0
  763. package/docs-live/business-rules/configuration.md +465 -0
  764. package/docs-live/business-rules/core-types.md +531 -0
  765. package/docs-live/business-rules/data-api.md +1403 -0
  766. package/docs-live/business-rules/generation.md +4726 -0
  767. package/docs-live/business-rules/process.md +122 -0
  768. package/docs-live/business-rules/validation.md +998 -0
  769. package/docs-live/decisions/adr-001-taxonomy-canonical-values.md +197 -0
  770. package/docs-live/decisions/adr-002-gherkin-only-testing.md +57 -0
  771. package/docs-live/decisions/adr-003-source-first-pattern-architecture.md +147 -0
  772. package/docs-live/decisions/adr-004-session-workflow-commands.md +137 -0
  773. package/docs-live/decisions/adr-005-codec-based-markdown-rendering.md +150 -0
  774. package/docs-live/decisions/adr-006-single-read-model-architecture.md +136 -0
  775. package/docs-live/decisions/adr-021-doc-generation-proof-of-concept.md +489 -0
  776. package/docs-live/product-areas/ANNOTATION.md +591 -0
  777. package/docs-live/product-areas/CONFIGURATION.md +1048 -0
  778. package/docs-live/product-areas/CORE-TYPES.md +221 -0
  779. package/docs-live/product-areas/DATA-API.md +850 -0
  780. package/docs-live/product-areas/GENERATION.md +1200 -0
  781. package/docs-live/product-areas/PROCESS.md +351 -0
  782. package/docs-live/product-areas/VALIDATION.md +1135 -0
  783. package/docs-live/reference/ANNOTATION-REFERENCE.md +232 -0
  784. package/docs-live/reference/ARCHITECTURE-CODECS.md +675 -0
  785. package/docs-live/reference/ARCHITECTURE-TYPES.md +436 -0
  786. package/docs-live/reference/CONFIGURATION-GUIDE.md +235 -0
  787. package/docs-live/reference/GHERKIN-AUTHORING-GUIDE.md +270 -0
  788. package/docs-live/reference/PROCESS-API-RECIPES.md +476 -0
  789. package/docs-live/reference/PROCESS-API-REFERENCE.md +63 -0
  790. package/docs-live/reference/PROCESS-GUARD-REFERENCE.md +258 -0
  791. package/docs-live/reference/REFERENCE-SAMPLE.md +1135 -0
  792. package/docs-live/reference/SESSION-WORKFLOW-GUIDE.md +384 -0
  793. package/docs-live/reference/VALIDATION-TOOLS-GUIDE.md +263 -0
  794. package/docs-live/taxonomy/categories.md +33 -0
  795. package/docs-live/taxonomy/format-types.md +67 -0
  796. package/docs-live/taxonomy/metadata-tags.md +693 -0
  797. package/docs-live/validation/error-catalog.md +78 -0
  798. package/docs-live/validation/fsm-transitions.md +50 -0
  799. package/docs-live/validation/protection-levels.md +51 -0
  800. package/package.json +233 -0
@@ -0,0 +1,1578 @@
1
+ /**
2
+ * @architect
3
+ * @architect-pattern ReferenceDocumentCodec
4
+ * @architect-status active
5
+ * @architect-implements CodecDrivenReferenceGeneration
6
+ * @architect-convention codec-registry
7
+ * @architect-product-area:Generation
8
+ *
9
+ * ## ReferenceDocumentCodec
10
+ *
11
+ * A single codec factory that creates reference document codecs from
12
+ * configuration objects. Convention content is sourced from
13
+ * decision records tagged with @architect-convention.
14
+ *
15
+ * **Purpose:** Scoped reference documentation assembling four content layers (conventions, diagrams, shapes, behaviors) into a single document.
16
+ *
17
+ * **Output Files:** Configured per-instance (e.g., `docs/REFERENCE-SAMPLE.md`, `_claude-md/architecture/reference-sample.md`)
18
+ *
19
+ * ### 4-Layer Composition (in order)
20
+ *
21
+ * 1. **Convention content** -- Extracted from `@architect-convention`-tagged patterns (rules, invariants, tables)
22
+ * 2. **Scoped diagrams** -- Mermaid diagrams filtered by `archContext`, `archLayer`, `patterns`, or `include` tags
23
+ * 3. **TypeScript shapes** -- API surfaces from `shapeSelectors` (declaration-level filtering)
24
+ * 4. **Behavior content** -- Gherkin-sourced patterns from `behaviorCategories`
25
+ *
26
+ * ### Key Options (ReferenceDocConfig)
27
+ *
28
+ * | Option | Type | Description |
29
+ * | --- | --- | --- |
30
+ * | conventionTags | string[] | Convention tag values to extract from decision records |
31
+ * | diagramScopes | DiagramScope[] | Multiple diagrams |
32
+ * | shapeSelectors | ShapeSelector[] | Fine-grained declaration-level shape filtering |
33
+ * | behaviorCategories | string[] | Category tags for behavior pattern content |
34
+ * | includeTags | string[] | Cross-cutting content routing via include tags |
35
+ * | preamble | SectionBlock[] | Static editorial sections prepended before generated content |
36
+ * | productArea | string | Pre-filter all content sources to matching product area |
37
+ * | excludeSourcePaths | string[] | Exclude patterns by source path prefix |
38
+ *
39
+ * ### DiagramScope.diagramType Values
40
+ *
41
+ * | Type | Description |
42
+ * | --- | --- |
43
+ * | graph (default) | Flowchart with subgraphs by archContext, custom node shapes |
44
+ * | sequenceDiagram | Sequence diagram with typed messages between participants |
45
+ * | stateDiagram-v2 | State diagram with transitions from dependsOn relationships |
46
+ * | C4Context | C4 context diagram with boundaries, systems, and relationships |
47
+ * | classDiagram | Class diagram with archRole stereotypes and typed arrows |
48
+ *
49
+ * ### ShapeSelector Variants
50
+ *
51
+ * | Variant | Example | Behavior |
52
+ * | --- | --- | --- |
53
+ * | group only | `{ group: "api-types" }` | Match shapes by group tag |
54
+ * | source + names | `{ source: "src/types.ts", names: ["Config"] }` | Named shapes from file |
55
+ * | source only | `{ source: "src/path/*.ts" }` | All tagged shapes from glob |
56
+ *
57
+ * ### When to Use
58
+ *
59
+ * - When generating reference documentation from convention-tagged decisions
60
+ * - When creating scoped product area documents with live diagrams
61
+ * - When creating both detailed (docs/) and summary (_claude-md/) outputs
62
+ * - When assembling multi-layer documents that combine conventions, diagrams, shapes, and behaviors
63
+ *
64
+ * ### Factory Pattern
65
+ *
66
+ * ```typescript
67
+ * const codec = createReferenceCodec(config, { detailLevel: 'detailed' });
68
+ * const doc = codec.decode(dataset);
69
+ * ```
70
+ */
71
+ import { z } from 'zod';
72
+ import { MasterDatasetSchema, } from '../../validation-schemas/master-dataset.js';
73
+ import { heading, paragraph, separator, table, code, list, mermaid, collapsible, linkOut, document, } from '../schema.js';
74
+ import { DEFAULT_BASE_OPTIONS, mergeOptions, } from './types/base.js';
75
+ import { RenderableDocumentOutputSchema } from './shared-schema.js';
76
+ import { extractConventions, extractConventionsFromPatterns, } from './convention-extractor.js';
77
+ import { parseBusinessRuleAnnotations, truncateText } from './helpers.js';
78
+ import { filterShapesBySelectors } from './shape-matcher.js';
79
+ import { sanitizeNodeId, EDGE_STYLES, EDGE_LABELS, SEQUENCE_ARROWS, formatNodeDeclaration, } from './diagram-utils.js';
80
+ import { getPatternName } from '../../api/pattern-helpers.js';
81
+ import { VALID_TRANSITIONS } from '../../validation/fsm/transitions.js';
82
+ import { PROTECTION_LEVELS } from '../../validation/fsm/states.js';
83
+ import { camelCaseToTitleCase, slugify } from '../../utils/string-utils.js';
84
+ // ============================================================================
85
+ // Shared Constants
86
+ // ============================================================================
87
+ /** Content source identifiers for hardcoded domain diagrams */
88
+ export const DIAGRAM_SOURCE_VALUES = [
89
+ 'fsm-lifecycle',
90
+ 'generation-pipeline',
91
+ 'master-dataset-views',
92
+ ];
93
+ // ============================================================================
94
+ // Product Area → archContext Mapping (ADR-001)
95
+ // ============================================================================
96
+ /**
97
+ * Maps canonical product area values to their associated archContext values.
98
+ * Product areas are Gherkin-side tags; archContexts are TypeScript-side tags.
99
+ * This mapping bridges the two tagging domains for diagram scoping.
100
+ */
101
+ export const PRODUCT_AREA_ARCH_CONTEXT_MAP = {
102
+ Annotation: ['scanner', 'extractor', 'taxonomy'],
103
+ Configuration: ['config'],
104
+ Generation: ['generator', 'renderer'],
105
+ Validation: ['validation', 'lint'],
106
+ DataAPI: ['api', 'cli'],
107
+ CoreTypes: [],
108
+ Process: [],
109
+ };
110
+ /**
111
+ * ADR-001 canonical product area metadata for intro sections.
112
+ */
113
+ export const PRODUCT_AREA_META = {
114
+ Annotation: {
115
+ question: 'How do I annotate code?',
116
+ covers: 'Scanning, extraction, tag parsing, dual-source',
117
+ intro: 'The annotation system is the ingestion boundary — it transforms annotated TypeScript ' +
118
+ 'and Gherkin files into `ExtractedPattern[]` objects that feed the entire downstream ' +
119
+ 'pipeline. Two parallel scanning paths (TypeScript AST + Gherkin parser) converge ' +
120
+ 'through dual-source merging. The system is fully data-driven: the `TagRegistry` ' +
121
+ 'defines all tags, formats, and categories — adding a new annotation requires only ' +
122
+ 'a registry entry, zero parser changes.',
123
+ diagramScopes: [
124
+ {
125
+ archContext: ['scanner', 'extractor'],
126
+ diagramType: 'C4Context',
127
+ title: 'Scanning & Extraction Boundary',
128
+ },
129
+ {
130
+ archContext: ['scanner', 'extractor'],
131
+ direction: 'LR',
132
+ title: 'Annotation Pipeline',
133
+ },
134
+ ],
135
+ keyInvariants: [
136
+ 'Source ownership enforced: `uses`/`used-by`/`category` belong in TypeScript only; `depends-on`/`quarter`/`team`/`phase` belong in Gherkin only. Anti-pattern detector validates at lint time',
137
+ 'Data-driven tag dispatch: Both AST parser and Gherkin parser use `TagRegistry.metadataTags` to determine extraction. 6 format types (`value`/`enum`/`csv`/`number`/`flag`/`quoted-value`) cover all tag shapes — zero parser changes for new tags',
138
+ 'Pipeline data preservation: Gherkin `Rule:` blocks, deliverables, scenarios, and all metadata flow through scanner → extractor → `ExtractedPattern` → generators without data loss',
139
+ 'Dual-source merge with conflict detection: Same pattern name in both TypeScript and Gherkin produces a merge conflict error. Phase mismatches between sources produce validation errors',
140
+ ],
141
+ keyPatterns: [
142
+ 'PatternRelationshipModel',
143
+ 'ShapeExtraction',
144
+ 'DualSourceExtraction',
145
+ 'GherkinRulesSupport',
146
+ 'DeclarationLevelShapeTagging',
147
+ 'CrossSourceValidation',
148
+ 'ExtractionPipelineEnhancementsTesting',
149
+ ],
150
+ },
151
+ Configuration: {
152
+ question: 'How do I configure the tool?',
153
+ covers: 'Config loading, presets, resolution, source merging, schema validation',
154
+ intro: 'Configuration is the entry boundary — it transforms a user-authored ' +
155
+ '`architect.config.ts` file into a fully resolved `ArchitectInstance` ' +
156
+ 'that powers the entire pipeline. The flow is: `defineConfig()` provides type-safe ' +
157
+ 'authoring (Vite convention, zero validation), `ConfigLoader` discovers and loads ' +
158
+ 'the file, `ProjectConfigSchema` validates via Zod, `ConfigResolver` applies defaults ' +
159
+ 'and merges stubs into sources, and `ArchitectFactory` builds the final instance ' +
160
+ 'with `TagRegistry` and `RegexBuilders`. Two presets define escalating taxonomy ' +
161
+ 'complexity — from 3 categories (`libar-generic`) to 21 (`ddd-es-cqrs`). ' +
162
+ '`SourceMerger` computes per-generator source overrides, enabling generators like ' +
163
+ 'changelog to pull from different feature sets than the base config.',
164
+ diagramScopes: [
165
+ {
166
+ archContext: ['config'],
167
+ diagramType: 'C4Context',
168
+ title: 'Configuration Loading Boundary',
169
+ },
170
+ {
171
+ archContext: ['config'],
172
+ direction: 'LR',
173
+ title: 'Configuration Resolution Pipeline',
174
+ },
175
+ ],
176
+ keyInvariants: [
177
+ 'Preset-based taxonomy: `libar-generic` (3 categories, `@architect-`) and `ddd-es-cqrs` (21 categories, full DDD). Presets replace base categories entirely — they define prefix, categories, and metadata tags as a unit',
178
+ 'Resolution pipeline: defineConfig() → ConfigLoader → ProjectConfigSchema (Zod) → ConfigResolver → ArchitectFactory → ArchitectInstance. Each stage has a single responsibility',
179
+ 'Stubs merged at resolution time: Stub directory globs are appended to typescript sources, making stubs transparent to the downstream pipeline',
180
+ 'Source override composition: SourceMerger applies per-generator overrides (`replaceFeatures`, `additionalFeatures`, `additionalInput`) to base sources. Exclude is always inherited from base',
181
+ ],
182
+ keyPatterns: [
183
+ 'ArchitectFactory',
184
+ 'ConfigLoader',
185
+ 'ConfigResolver',
186
+ 'DefineConfig',
187
+ 'ConfigurationPresets',
188
+ 'SourceMerger',
189
+ ],
190
+ },
191
+ Generation: {
192
+ question: 'How does code become docs?',
193
+ covers: 'Codecs, generators, orchestrator, rendering, diagrams, progressive disclosure, product areas, RenderableDocument IR',
194
+ intro: 'The generation pipeline transforms annotated source code into markdown documents through a ' +
195
+ 'four-stage architecture: Scanner discovers files, Extractor produces `ExtractedPattern` objects, ' +
196
+ 'Transformer builds MasterDataset with pre-computed views, and Codecs render to markdown via ' +
197
+ 'RenderableDocument IR. Nine specialized codecs handle reference docs, planning, session, reporting, ' +
198
+ 'timeline, ADRs, business rules, taxonomy, and composite output — each supporting three detail levels ' +
199
+ '(detailed, standard, summary). The Orchestrator runs generators in registration order, producing both ' +
200
+ 'detailed `docs-live/` references and compact `_claude-md/` summaries.',
201
+ introSections: [
202
+ heading(3, 'Pipeline Stages'),
203
+ table(['Stage', 'Module', 'Responsibility'], [
204
+ ['Scanner', '`src/scanner/`', 'File discovery, AST parsing, opt-in via `@architect`'],
205
+ [
206
+ 'Extractor',
207
+ '`src/extractor/`',
208
+ 'Pattern extraction from TypeScript JSDoc and Gherkin tags',
209
+ ],
210
+ [
211
+ 'Transformer',
212
+ '`src/generators/pipeline/`',
213
+ 'MasterDataset with pre-computed views for O(1) access (ADR-006)',
214
+ ],
215
+ [
216
+ 'Codec',
217
+ '`src/renderable/`',
218
+ 'Pure functions: MasterDataset → RenderableDocument → Markdown',
219
+ ],
220
+ ]),
221
+ heading(3, 'Codec Inventory'),
222
+ table(['Codec', 'Purpose'], [
223
+ [
224
+ 'ReferenceDocumentCodec',
225
+ 'Conventions, diagrams, shapes, behaviors (4-layer composition)',
226
+ ],
227
+ ['PlanningCodec', 'Roadmap and remaining work'],
228
+ ['SessionCodec', 'Current work and session findings'],
229
+ ['ReportingCodec', 'Changelog'],
230
+ ['TimelineCodec', 'Timeline and traceability'],
231
+ ['RequirementsAdrCodec', 'ADR generation'],
232
+ ['BusinessRulesCodec', 'Gherkin rule extraction'],
233
+ ['TaxonomyCodec', 'Tag registry docs'],
234
+ ['CompositeCodec', 'Composes multiple codecs into a single document'],
235
+ ]),
236
+ ],
237
+ keyInvariants: [
238
+ 'Codec purity: Every codec is a pure function (dataset in, document out). No side effects, no filesystem access. Same input always produces same output',
239
+ 'Single read model (ADR-006): All codecs consume MasterDataset. No codec reads raw scanner/extractor output. Anti-patterns: Parallel Pipeline, Lossy Local Type, Re-derived Relationship',
240
+ 'Progressive disclosure: Every document renders at three detail levels (detailed, standard, summary) from the same codec. Summary feeds `_claude-md/` modules; detailed feeds `docs-live/reference/`',
241
+ 'Config-driven generation: A single `ReferenceDocConfig` produces a complete document. Content sources compose in fixed order: conventions, diagrams, shapes, behaviors',
242
+ 'RenderableDocument IR: Codecs express intent ("this is a table"), the renderer handles syntax ("pipe-delimited markdown"). Switching output format requires only a new renderer',
243
+ 'Composition order: Reference docs compose four content layers in fixed order. Product area docs compose five layers: intro, conventions, diagrams, shapes, business rules',
244
+ 'Shape extraction: TypeScript shapes (`interface`, `type`, `enum`, `function`, `const`) are extracted by declaration-level `@architect-shape` tags. Shapes include source text, JSDoc, type parameters, and property documentation',
245
+ 'Generator registration: Generators self-register via `registerGenerator()`. The orchestrator runs them in registration order. Each generator owns its output files and codec configuration',
246
+ ],
247
+ keyPatterns: [
248
+ 'ADR005CodecBasedMarkdownRendering',
249
+ 'CodecDrivenReferenceGeneration',
250
+ 'CrossCuttingDocumentInclusion',
251
+ 'ArchitectureDiagramGeneration',
252
+ 'ScopedArchitecturalView',
253
+ 'CompositeCodec',
254
+ 'RenderableDocument',
255
+ 'ProductAreaOverview',
256
+ ],
257
+ },
258
+ Validation: {
259
+ question: 'How is the workflow enforced?',
260
+ covers: 'FSM, DoD, anti-patterns, process guard, lint',
261
+ intro: 'Validation is the enforcement boundary — it ensures that every change to annotated source files ' +
262
+ 'respects the delivery lifecycle rules defined by the FSM, protection levels, and scope constraints. ' +
263
+ 'The system operates in three layers: the FSM validator checks status transitions against a 4-state ' +
264
+ 'directed graph, the Process Guard orchestrates commit-time validation using a Decider pattern ' +
265
+ '(state derived from annotations, not stored separately), and the lint engine provides pluggable ' +
266
+ 'rule execution with pretty and JSON output. Anti-pattern detection enforces dual-source ownership ' +
267
+ 'boundaries — `@architect-uses` belongs on TypeScript, `@architect-depends-on` belongs on Gherkin — ' +
268
+ 'preventing cross-domain tag confusion that causes documentation drift. Definition of Done validation ' +
269
+ 'ensures completed patterns have all deliverables marked done and at least one acceptance-criteria scenario.',
270
+ diagramScopes: [
271
+ {
272
+ archContext: ['validation', 'lint'],
273
+ diagramType: 'C4Context',
274
+ title: 'Validation & Lint Boundary',
275
+ },
276
+ {
277
+ archContext: ['validation', 'lint'],
278
+ direction: 'LR',
279
+ title: 'Enforcement Pipeline',
280
+ },
281
+ ],
282
+ keyInvariants: [
283
+ 'Protection levels: `roadmap`/`deferred` = none (fully editable), `active` = scope-locked (no new deliverables), `completed` = hard-locked (requires `@architect-unlock-reason`)',
284
+ 'Valid FSM transitions: Only roadmap→active, roadmap→deferred, active→completed, active→roadmap, deferred→roadmap. Completed is terminal',
285
+ 'Decider pattern: All validation is (state, changes, options) → result. State is derived from annotations, not maintained separately',
286
+ 'Dual-source ownership: Anti-pattern detection enforces tag boundaries — `uses` on TypeScript (runtime deps), `depends-on`/`quarter`/`team` on Gherkin (planning metadata). Violations are flagged before they cause documentation drift',
287
+ ],
288
+ keyPatterns: [
289
+ 'ProcessGuardLinter',
290
+ 'PhaseStateMachineValidation',
291
+ 'DoDValidation',
292
+ 'StepLintVitestCucumber',
293
+ 'ProgressiveGovernance',
294
+ ],
295
+ },
296
+ DataAPI: {
297
+ question: 'How do I query process state?',
298
+ covers: 'Process state API, stubs, context assembly, CLI',
299
+ intro: 'The Data API provides direct terminal access to project state. ' +
300
+ 'It replaces reading generated markdown or launching explore agents — targeted queries ' +
301
+ 'use 5-10x less context. The `context` command assembles curated bundles tailored to ' +
302
+ 'session type (planning, design, implement).',
303
+ keyInvariants: [
304
+ 'One-command context assembly: `context <pattern> --session <type>` returns metadata + file paths + dependency status + architecture position in ~1.5KB',
305
+ 'Session type tailoring: `planning` (~500B, brief + deps), `design` (~1.5KB, spec + stubs + deps), `implement` (deliverables + FSM + tests)',
306
+ 'Direct API queries replace doc reading: JSON output is 5-10x smaller than generated docs',
307
+ ],
308
+ keyPatterns: [
309
+ 'DataAPIContextAssembly',
310
+ 'ProcessStateAPICLI',
311
+ 'DataAPIDesignSessionSupport',
312
+ 'DataAPIRelationshipGraph',
313
+ 'DataAPIOutputShaping',
314
+ ],
315
+ },
316
+ CoreTypes: {
317
+ question: 'What foundational types exist?',
318
+ covers: 'Result monad, error factories, branded types, string utils',
319
+ intro: 'CoreTypes provides the foundational type system used across all other areas. Three pillars ' +
320
+ 'enforce discipline at compile time: the Result monad replaces try/catch with explicit ' +
321
+ 'error handling — functions return `Result.ok(value)` or `Result.err(error)` instead of ' +
322
+ 'throwing. The DocError discriminated union provides structured error context with type, ' +
323
+ 'file, line, and reason fields, enabling exhaustive pattern matching in error handlers. ' +
324
+ 'Branded types create nominal typing from structural TypeScript — `PatternId`, ' +
325
+ '`CategoryName`, and `SourceFilePath` are compile-time distinct despite all being strings. ' +
326
+ 'String utilities handle slugification and case conversion with acronym-aware title casing.',
327
+ diagramScopes: [
328
+ {
329
+ include: ['core-types'],
330
+ diagramType: 'C4Context',
331
+ title: 'Core Type System',
332
+ },
333
+ {
334
+ include: ['core-types'],
335
+ direction: 'LR',
336
+ title: 'Error Handling Flow',
337
+ },
338
+ ],
339
+ keyInvariants: [
340
+ 'Result over try/catch: All functions return `Result<T, E>` instead of throwing. Compile-time verification that errors are handled. `isOk`/`isErr` type guards enable safe narrowing',
341
+ 'DocError discriminated union: 12 structured error types with `type` discriminator field. `isDocError` type guard for safe classification. Specialized union aliases (`ScanError`, `ExtractionError`) scope error handling per operation',
342
+ 'Branded nominal types: `Branded<T, Brand>` creates compile-time distinct types from structural TypeScript. Prevents mixing `PatternId` with `CategoryName` even though both are `string` at runtime',
343
+ 'String transformation consistency: `slugify` produces URL-safe identifiers, `camelCaseToTitleCase` preserves acronyms (e.g., "APIEndpoint" becomes "API Endpoint"), `toKebabCase` handles consecutive uppercase correctly',
344
+ ],
345
+ keyPatterns: [
346
+ 'ResultMonad',
347
+ 'ErrorHandlingUnification',
348
+ 'ErrorFactories',
349
+ 'StringUtils',
350
+ 'KebabCaseSlugs',
351
+ ],
352
+ },
353
+ Process: {
354
+ question: 'How does the session workflow work?',
355
+ covers: 'Session lifecycle, handoffs, FSM alignment, governance decisions, conventions',
356
+ intro: 'Process defines the USDP-inspired session workflow that governs how work moves through ' +
357
+ 'the delivery lifecycle. Three session types (planning, design, implementation) have fixed ' +
358
+ 'input/output contracts: planning creates roadmap specs from pattern briefs, design produces ' +
359
+ 'code stubs and decision records, and implementation writes code against scope-locked specs. ' +
360
+ 'Git is the event store — documentation artifacts are projections of annotated source code, ' +
361
+ 'not hand-maintained files. The FSM enforces state transitions (roadmap → active → completed) ' +
362
+ 'with escalating protection levels, while handoff templates preserve context across LLM session ' +
363
+ 'boundaries. ADR-003 established that TypeScript source owns pattern identity; tier 1 specs ' +
364
+ 'are ephemeral planning documents that lose value after completion.',
365
+ diagramScopes: [
366
+ {
367
+ source: 'fsm-lifecycle',
368
+ title: 'Delivery Lifecycle FSM',
369
+ },
370
+ {
371
+ include: ['process-workflow'],
372
+ direction: 'LR',
373
+ title: 'Process Pattern Relationships',
374
+ },
375
+ ],
376
+ keyInvariants: [
377
+ 'TypeScript source owns pattern identity: `@architect-pattern` in TypeScript defines the pattern. Tier 1 specs are ephemeral working documents',
378
+ '7 canonical product-area values: Annotation, Configuration, Generation, Validation, DataAPI, CoreTypes, Process — reader-facing sections, not source modules',
379
+ 'Two distinct status domains: Pattern FSM status (4 values) vs. deliverable status (6 values). Never cross domains',
380
+ 'Session types define capabilities: planning creates specs, design creates stubs, implementation writes code. Each session type has a fixed input/output contract enforced by convention',
381
+ ],
382
+ keyPatterns: [
383
+ 'ADR001TaxonomyCanonicalValues',
384
+ 'ADR003SourceFirstPatternArchitecture',
385
+ 'MvpWorkflowImplementation',
386
+ 'SessionHandoffs',
387
+ ],
388
+ },
389
+ };
390
+ const DEFAULT_REFERENCE_OPTIONS = {
391
+ ...DEFAULT_BASE_OPTIONS,
392
+ detailLevel: 'standard',
393
+ };
394
+ // ============================================================================
395
+ // Codec Factory
396
+ // ============================================================================
397
+ /**
398
+ * Creates a reference document codec from configuration.
399
+ *
400
+ * The codec composes a RenderableDocument from up to four sources:
401
+ * 1. Convention content from convention-tagged decision records
402
+ * 2. Scoped relationship diagram (if diagramScopes configured)
403
+ * 3. TypeScript shapes from selector-matched patterns
404
+ * 4. Behavior content from category-tagged patterns
405
+ *
406
+ * @param config - Reference document configuration
407
+ * @param options - Codec options including DetailLevel
408
+ */
409
+ export function createReferenceCodec(config, options) {
410
+ const opts = mergeOptions(DEFAULT_REFERENCE_OPTIONS, options);
411
+ return z.codec(MasterDatasetSchema, RenderableDocumentOutputSchema, {
412
+ decode: (dataset) => {
413
+ const sections = [];
414
+ // Product area filtering: when set, pre-filter and auto-derive content sources
415
+ // Preamble is applied inside decodeProductArea() — not here, to avoid dead code
416
+ if (config.productArea !== undefined) {
417
+ return decodeProductArea(dataset, config, opts);
418
+ }
419
+ // DD-1 (CrossCuttingDocumentInclusion): Pre-compute include set for additive merging
420
+ const includeSet = config.includeTags !== undefined && config.includeTags.length > 0
421
+ ? new Set(config.includeTags)
422
+ : undefined;
423
+ // 1. Convention content from tagged decision records
424
+ const conventions = extractConventions(dataset, config.conventionTags);
425
+ // DD-1: Merge include-tagged convention patterns (additive)
426
+ if (includeSet !== undefined) {
427
+ const existingNames = new Set(conventions.flatMap((b) => b.sourceDecisions));
428
+ const includedConventionPatterns = dataset.patterns.filter((p) => !existingNames.has(p.name) &&
429
+ p.include?.some((v) => includeSet.has(v)) === true &&
430
+ p.convention !== undefined &&
431
+ p.convention.length > 0);
432
+ if (includedConventionPatterns.length > 0) {
433
+ // Build bundles from included convention patterns
434
+ const includedConventions = extractConventionsFromPatterns(includedConventionPatterns);
435
+ conventions.push(...includedConventions);
436
+ }
437
+ }
438
+ const conventionBlocks = conventions.length > 0 ? buildConventionSections(conventions, opts.detailLevel) : [];
439
+ // 2. Scoped relationship diagrams
440
+ const diagramBlocks = [];
441
+ if (opts.detailLevel !== 'summary') {
442
+ const scopes = config.diagramScopes ?? [];
443
+ for (const scope of scopes) {
444
+ const diagramSections = buildScopedDiagram(dataset, scope);
445
+ if (diagramSections.length > 0) {
446
+ diagramBlocks.push(...diagramSections);
447
+ }
448
+ }
449
+ }
450
+ // 3. Shape extraction: selector-based filtering only
451
+ const shapeBlocks = [];
452
+ {
453
+ const allShapes = config.shapeSelectors !== undefined && config.shapeSelectors.length > 0
454
+ ? [...filterShapesBySelectors(dataset, config.shapeSelectors)]
455
+ : [];
456
+ const seenNames = new Set(allShapes.map((s) => s.name));
457
+ // DD-1: Merge include-tagged shapes (additive)
458
+ if (includeSet !== undefined) {
459
+ for (const pattern of dataset.patterns) {
460
+ if (pattern.extractedShapes === undefined || pattern.extractedShapes.length === 0)
461
+ continue;
462
+ for (const shape of pattern.extractedShapes) {
463
+ if (!seenNames.has(shape.name) &&
464
+ shape.includes?.some((v) => includeSet.has(v)) === true) {
465
+ seenNames.add(shape.name);
466
+ allShapes.push(shape);
467
+ }
468
+ }
469
+ }
470
+ }
471
+ if (allShapes.length > 0) {
472
+ shapeBlocks.push(...buildShapeSections(allShapes, opts.detailLevel));
473
+ }
474
+ }
475
+ // 4. Behavior content from tagged patterns
476
+ const behaviorPatterns = config.behaviorCategories.length > 0
477
+ ? dataset.patterns.filter((p) => config.behaviorCategories.includes(p.category))
478
+ : [];
479
+ // DD-1: Merge include-tagged behavior patterns (additive)
480
+ if (includeSet !== undefined) {
481
+ const existingNames = new Set(behaviorPatterns.map((p) => p.name));
482
+ const includedBehaviors = dataset.patterns.filter((p) => !existingNames.has(p.name) &&
483
+ p.include?.some((v) => includeSet.has(v)) === true &&
484
+ (p.directive.description.length > 0 || (p.rules !== undefined && p.rules.length > 0)));
485
+ behaviorPatterns.push(...includedBehaviors);
486
+ }
487
+ const behaviorBlocks = behaviorPatterns.length > 0
488
+ ? buildBehaviorSectionsFromPatterns(behaviorPatterns, opts.detailLevel)
489
+ : [];
490
+ // Static preamble: editorial sections before generated content
491
+ if (config.preamble !== undefined && config.preamble.length > 0) {
492
+ sections.push(...config.preamble);
493
+ sections.push(separator());
494
+ }
495
+ // DD-4 (GeneratedDocQuality): Assemble in configured order
496
+ if (config.shapesFirst === true) {
497
+ sections.push(...shapeBlocks, ...conventionBlocks, ...diagramBlocks, ...behaviorBlocks);
498
+ }
499
+ else {
500
+ sections.push(...conventionBlocks, ...diagramBlocks, ...shapeBlocks, ...behaviorBlocks);
501
+ }
502
+ if (sections.length === 0) {
503
+ const diagnostics = [];
504
+ if (config.conventionTags.length > 0) {
505
+ diagnostics.push(`conventions [${config.conventionTags.join(', ')}]`);
506
+ }
507
+ if (config.shapeSelectors !== undefined && config.shapeSelectors.length > 0) {
508
+ diagnostics.push(`selectors [${config.shapeSelectors.length} selectors]`);
509
+ }
510
+ if (config.behaviorCategories.length > 0) {
511
+ diagnostics.push(`behaviors [${config.behaviorCategories.join(', ')}]`);
512
+ }
513
+ if (includeSet !== undefined) {
514
+ diagnostics.push(`includeTags [${[...includeSet].join(', ')}]`);
515
+ }
516
+ sections.push(paragraph(`No content found. Sources checked: ${diagnostics.join('; ')}.`));
517
+ }
518
+ return document(config.title, sections, {
519
+ purpose: `Reference document: ${config.title}`,
520
+ detailLevel: opts.detailLevel === 'summary' ? 'Compact summary' : 'Full reference',
521
+ });
522
+ },
523
+ encode: () => {
524
+ throw new Error('ReferenceDocumentCodec is decode-only');
525
+ },
526
+ });
527
+ }
528
+ // ============================================================================
529
+ // Product Area Decode Path
530
+ // ============================================================================
531
+ /**
532
+ * Decode a product-area-scoped reference document.
533
+ *
534
+ * When `config.productArea` is set, this function replaces the standard decode
535
+ * path. It pre-filters all patterns by product area and auto-derives content
536
+ * sources from the filtered set rather than relying on explicit config arrays.
537
+ *
538
+ * Document structure:
539
+ * 1. Intro (reader question + coverage from ADR-001 metadata)
540
+ * 2. Invariant rules from executable specs (conventions + behavior rules)
541
+ * 3. Architecture diagrams (auto-scoped via productArea→archContext mapping)
542
+ * 4. Key API types (shapes from TypeScript patterns in this area)
543
+ * 5. Behavior specifications (all patterns with rules/descriptions)
544
+ */
545
+ function decodeProductArea(dataset, config, opts) {
546
+ const area = config.productArea;
547
+ if (area === undefined) {
548
+ return document('Error', [paragraph('No product area specified.')], {});
549
+ }
550
+ const sections = [];
551
+ // Static preamble: editorial sections before generated content
552
+ if (config.preamble !== undefined && config.preamble.length > 0) {
553
+ sections.push(...config.preamble);
554
+ sections.push(separator());
555
+ }
556
+ // Pre-computed view: O(1) lookup instead of linear filter
557
+ const areaPatterns = dataset.byProductArea[area] ?? [];
558
+ // Collect TypeScript patterns by explicit archContext tag (for shapes + diagrams)
559
+ // Note: archIndex.byContext includes inferred contexts — use explicit filter to match only tagged patterns
560
+ const archContexts = PRODUCT_AREA_ARCH_CONTEXT_MAP[area] ?? [];
561
+ const contextSet = new Set(archContexts);
562
+ const tsPatterns = contextSet.size > 0
563
+ ? dataset.patterns.filter((p) => p.archContext !== undefined && contextSet.has(p.archContext))
564
+ : [];
565
+ // 1. Intro section from ADR-001 metadata with key invariants
566
+ const meta = PRODUCT_AREA_META[area];
567
+ if (meta !== undefined) {
568
+ sections.push(paragraph(`**${meta.question}** ${meta.intro}`));
569
+ if (meta.introSections !== undefined && opts.detailLevel === 'detailed') {
570
+ sections.push(...meta.introSections);
571
+ }
572
+ if (meta.keyInvariants.length > 0) {
573
+ sections.push(heading(2, 'Key Invariants'));
574
+ sections.push(list([...meta.keyInvariants]));
575
+ }
576
+ sections.push(separator());
577
+ }
578
+ // 2. Convention/invariant content from area patterns with convention tags
579
+ const conventionPatterns = areaPatterns.filter((p) => p.convention !== undefined && p.convention.length > 0);
580
+ if (conventionPatterns.length > 0) {
581
+ const conventions = extractConventionsFromPatterns(conventionPatterns);
582
+ if (conventions.length > 0) {
583
+ sections.push(...buildConventionSections(conventions, opts.detailLevel));
584
+ }
585
+ }
586
+ // 3. Architecture diagrams — priority: config > meta > auto-generate
587
+ if (opts.detailLevel !== 'summary') {
588
+ const scopes = config.diagramScopes ?? meta?.diagramScopes ?? [];
589
+ if (scopes.length > 0) {
590
+ // Explicit scopes from config or meta — always render
591
+ for (const scope of scopes) {
592
+ const diagramSections = buildScopedDiagram(dataset, scope);
593
+ if (diagramSections.length > 0) {
594
+ sections.push(...diagramSections);
595
+ }
596
+ }
597
+ }
598
+ else if (archContexts.length > 0) {
599
+ // Auto-generate fallback — only when archContext mappings exist
600
+ const autoScope = {
601
+ archContext: archContexts,
602
+ direction: 'TB',
603
+ title: `${area} Components`,
604
+ };
605
+ const diagramSections = buildScopedDiagram(dataset, autoScope);
606
+ if (diagramSections.length > 0) {
607
+ sections.push(...diagramSections);
608
+ }
609
+ }
610
+ }
611
+ else {
612
+ // Compact boundary summary for summary-level documents (replaces diagrams)
613
+ const scopes = config.diagramScopes ?? meta?.diagramScopes ?? [];
614
+ const summary = buildBoundarySummary(dataset, scopes);
615
+ if (summary !== undefined) {
616
+ sections.push(summary);
617
+ }
618
+ }
619
+ // 4. Shapes from TypeScript patterns in this product area
620
+ {
621
+ const allShapes = [];
622
+ const seenNames = new Set();
623
+ const seenPatternNames = new Set();
624
+ // Collect shapes from all patterns associated with this area
625
+ for (const pattern of [...areaPatterns, ...tsPatterns]) {
626
+ if (seenPatternNames.has(pattern.name))
627
+ continue;
628
+ seenPatternNames.add(pattern.name);
629
+ if (pattern.extractedShapes === undefined || pattern.extractedShapes.length === 0)
630
+ continue;
631
+ for (const shape of pattern.extractedShapes) {
632
+ if (!seenNames.has(shape.name)) {
633
+ seenNames.add(shape.name);
634
+ allShapes.push(shape);
635
+ }
636
+ }
637
+ }
638
+ if (config.shapeSelectors !== undefined && config.shapeSelectors.length > 0) {
639
+ for (const shape of filterShapesBySelectors(dataset, config.shapeSelectors)) {
640
+ if (!seenNames.has(shape.name)) {
641
+ seenNames.add(shape.name);
642
+ allShapes.push(shape);
643
+ }
644
+ }
645
+ }
646
+ if (allShapes.length > 0) {
647
+ // Prioritize interfaces and types over functions/variables to keep
648
+ // product area docs focused on key API types, not implementation details.
649
+ const kindOrder = {
650
+ interface: 0,
651
+ type: 1,
652
+ enum: 2,
653
+ function: 3,
654
+ const: 4,
655
+ };
656
+ const sorted = [...allShapes].sort((a, b) => (kindOrder[a.kind] ?? 5) - (kindOrder[b.kind] ?? 5));
657
+ const maxShapes = opts.detailLevel === 'detailed' ? 30 : 20;
658
+ const limited = sorted.slice(0, maxShapes);
659
+ sections.push(...buildShapeSections(limited, opts.detailLevel));
660
+ }
661
+ }
662
+ // 5. Compact business rules index (replaces verbose Behavior Specifications)
663
+ // Shows only rule name, invariant, and rationale per rule in tables
664
+ const rulesPatterns = areaPatterns.filter((p) => (config.excludeSourcePaths === undefined ||
665
+ config.excludeSourcePaths.length === 0 ||
666
+ !config.excludeSourcePaths.some((prefix) => p.source.file.startsWith(prefix))) &&
667
+ p.rules !== undefined &&
668
+ p.rules.length > 0);
669
+ if (rulesPatterns.length > 0) {
670
+ sections.push(...buildBusinessRulesCompactSection(rulesPatterns, opts.detailLevel));
671
+ }
672
+ // DD-4 (GeneratedDocQuality): Insert TOC after intro for large product area docs
673
+ const tocBlocks = buildTableOfContents(sections);
674
+ if (tocBlocks.length > 0) {
675
+ const firstSepIdx = sections.findIndex((s) => s.type === 'separator');
676
+ if (firstSepIdx >= 0) {
677
+ sections.splice(firstSepIdx + 1, 0, ...tocBlocks);
678
+ }
679
+ }
680
+ if (sections.length === 0) {
681
+ sections.push(paragraph(`No content found for product area "${area}". ` +
682
+ `Checked ${areaPatterns.length} patterns by productArea tag, ` +
683
+ `${tsPatterns.length} patterns by archContext [${archContexts.join(', ')}].`));
684
+ }
685
+ return document(config.title, sections, {
686
+ purpose: `${area} product area overview`,
687
+ detailLevel: opts.detailLevel === 'summary' ? 'Compact summary' : 'Full reference',
688
+ });
689
+ }
690
+ // ============================================================================
691
+ // Section Builders
692
+ // ============================================================================
693
+ /**
694
+ * Build sections from convention bundles.
695
+ */
696
+ function buildConventionSections(conventions, detailLevel) {
697
+ const sections = [];
698
+ for (const bundle of conventions) {
699
+ if (bundle.rules.length === 0)
700
+ continue;
701
+ for (const rule of bundle.rules) {
702
+ sections.push(heading(2, rule.ruleName));
703
+ if (rule.invariant) {
704
+ sections.push(paragraph(`**Invariant:** ${rule.invariant}`));
705
+ }
706
+ if (rule.narrative && detailLevel !== 'summary') {
707
+ sections.push(paragraph(rule.narrative));
708
+ }
709
+ if (rule.rationale && detailLevel === 'detailed') {
710
+ sections.push(paragraph(`**Rationale:** ${rule.rationale}`));
711
+ }
712
+ for (const tbl of rule.tables) {
713
+ const rows = tbl.rows.map((row) => tbl.headers.map((h) => row[h] ?? ''));
714
+ sections.push(table([...tbl.headers], rows));
715
+ }
716
+ if (rule.codeExamples !== undefined && detailLevel !== 'summary') {
717
+ for (const example of rule.codeExamples) {
718
+ if (example.type === 'code' && example.language === 'mermaid') {
719
+ sections.push(mermaid(example.content));
720
+ }
721
+ else {
722
+ sections.push(example);
723
+ }
724
+ }
725
+ }
726
+ if (rule.verifiedBy && rule.verifiedBy.length > 0 && detailLevel === 'detailed') {
727
+ sections.push(paragraph(`**Verified by:** ${rule.verifiedBy.join(', ')}`));
728
+ }
729
+ sections.push(separator());
730
+ }
731
+ }
732
+ return sections;
733
+ }
734
+ /**
735
+ * Build sections from a pre-filtered list of behavior patterns.
736
+ *
737
+ * DD-1 (CrossCuttingDocumentInclusion): Extracted from buildBehaviorSections to
738
+ * accept pre-merged patterns (category-selected + include-tagged).
739
+ */
740
+ function buildBehaviorSectionsFromPatterns(patterns, detailLevel) {
741
+ const sections = [];
742
+ if (patterns.length === 0)
743
+ return sections;
744
+ sections.push(heading(2, 'Behavior Specifications'));
745
+ for (const pattern of patterns) {
746
+ sections.push(heading(3, pattern.name));
747
+ // Cross-reference link to source file (omitted at summary level)
748
+ if (detailLevel !== 'summary') {
749
+ sections.push(linkOut(`View ${pattern.name} source`, pattern.source.file));
750
+ }
751
+ if (pattern.directive.description && detailLevel !== 'summary') {
752
+ sections.push(paragraph(pattern.directive.description));
753
+ }
754
+ if (pattern.rules && pattern.rules.length > 0) {
755
+ if (detailLevel === 'summary') {
756
+ // Compact table with word-boundary-aware truncation
757
+ const ruleRows = pattern.rules.map((r) => [
758
+ r.name,
759
+ r.description ? truncateText(r.description, 120) : '',
760
+ ]);
761
+ sections.push(table(['Rule', 'Description'], ruleRows));
762
+ }
763
+ else {
764
+ // Structured per-rule rendering with parsed annotations
765
+ // Wrap in collapsible blocks when 3+ rules for progressive disclosure
766
+ const wrapInCollapsible = pattern.rules.length >= 3;
767
+ for (const rule of pattern.rules) {
768
+ const ruleBlocks = [];
769
+ ruleBlocks.push(heading(4, rule.name));
770
+ const annotations = parseBusinessRuleAnnotations(rule.description);
771
+ if (annotations.invariant) {
772
+ ruleBlocks.push(paragraph(`**Invariant:** ${annotations.invariant}`));
773
+ }
774
+ if (annotations.rationale && detailLevel === 'detailed') {
775
+ ruleBlocks.push(paragraph(`**Rationale:** ${annotations.rationale}`));
776
+ }
777
+ if (annotations.remainingContent) {
778
+ ruleBlocks.push(paragraph(annotations.remainingContent));
779
+ }
780
+ if (annotations.codeExamples && detailLevel === 'detailed') {
781
+ for (const example of annotations.codeExamples) {
782
+ ruleBlocks.push(example);
783
+ }
784
+ }
785
+ // Merged scenario names + verifiedBy as deduplicated list
786
+ const names = new Set(rule.scenarioNames);
787
+ if (annotations.verifiedBy) {
788
+ for (const v of annotations.verifiedBy) {
789
+ names.add(v);
790
+ }
791
+ }
792
+ if (names.size > 0) {
793
+ ruleBlocks.push(paragraph('**Verified by:**'));
794
+ ruleBlocks.push(list([...names]));
795
+ }
796
+ if (wrapInCollapsible) {
797
+ const scenarioCount = rule.scenarioNames.length;
798
+ const summary = scenarioCount > 0 ? `${rule.name} (${scenarioCount} scenarios)` : rule.name;
799
+ sections.push(collapsible(summary, ruleBlocks));
800
+ }
801
+ else {
802
+ sections.push(...ruleBlocks);
803
+ }
804
+ }
805
+ }
806
+ }
807
+ }
808
+ sections.push(separator());
809
+ return sections;
810
+ }
811
+ /**
812
+ * Build a compact business rules index section.
813
+ *
814
+ * Replaces the verbose Behavior Specifications in product area docs.
815
+ * Groups rules by pattern, showing only rule name, invariant, and rationale.
816
+ * Always renders open H3 headings with tables for immediate scannability.
817
+ *
818
+ * Detail level controls:
819
+ * - summary: Section omitted entirely
820
+ * - standard: Rules with invariants only; truncated to 150/120 chars
821
+ * - detailed: All rules; full text, no truncation
822
+ */
823
+ function buildBusinessRulesCompactSection(patterns, detailLevel) {
824
+ if (detailLevel === 'summary')
825
+ return [];
826
+ const sections = [];
827
+ // Count totals for header (lightweight pass — no annotation parsing)
828
+ let totalRules = 0;
829
+ let totalInvariants = 0;
830
+ for (const p of patterns) {
831
+ if (p.rules === undefined)
832
+ continue;
833
+ for (const r of p.rules) {
834
+ totalRules++;
835
+ if (r.description.includes('**Invariant:**'))
836
+ totalInvariants++;
837
+ }
838
+ }
839
+ if (totalRules === 0)
840
+ return sections;
841
+ sections.push(heading(2, 'Business Rules'));
842
+ sections.push(paragraph(`${String(patterns.length)} patterns, ` +
843
+ `${String(totalInvariants)} rules with invariants ` +
844
+ `(${String(totalRules)} total)`));
845
+ const isDetailed = detailLevel === 'detailed';
846
+ const maxInvariant = isDetailed ? 0 : 150;
847
+ const maxRationale = isDetailed ? 0 : 120;
848
+ const sorted = [...patterns].sort((a, b) => a.name.localeCompare(b.name));
849
+ for (const pattern of sorted) {
850
+ if (pattern.rules === undefined)
851
+ continue;
852
+ const rows = [];
853
+ for (const rule of pattern.rules) {
854
+ const ann = parseBusinessRuleAnnotations(rule.description);
855
+ // At standard level, skip rules without invariant
856
+ if (!isDetailed && ann.invariant === undefined)
857
+ continue;
858
+ const invariantText = ann.invariant ?? '';
859
+ const rationaleText = ann.rationale ?? '';
860
+ rows.push([
861
+ rule.name,
862
+ maxInvariant > 0 ? truncateText(invariantText, maxInvariant) : invariantText,
863
+ maxRationale > 0 ? truncateText(rationaleText, maxRationale) : rationaleText,
864
+ ]);
865
+ }
866
+ if (rows.length === 0)
867
+ continue;
868
+ sections.push(heading(3, camelCaseToTitleCase(pattern.name)));
869
+ sections.push(table(['Rule', 'Invariant', 'Rationale'], rows));
870
+ }
871
+ sections.push(separator());
872
+ return sections;
873
+ }
874
+ /**
875
+ * Build a table of contents from H2 headings in a sections array.
876
+ *
877
+ * DD-4 (GeneratedDocQuality): Product area docs can be 100+ KB with many
878
+ * sections. A TOC at the top makes browser navigation practical. Only
879
+ * generated when there are 3 or more H2 headings (below that, a TOC adds
880
+ * noise without navigation value).
881
+ */
882
+ function buildTableOfContents(allSections) {
883
+ const h2Headings = allSections.filter((s) => s.type === 'heading' && s.level === 2);
884
+ if (h2Headings.length < 3)
885
+ return [];
886
+ const tocItems = h2Headings.map((h) => {
887
+ const anchor = slugify(h.text);
888
+ return `[${h.text}](#${anchor})`;
889
+ });
890
+ return [heading(2, 'Contents'), list(tocItems), separator()];
891
+ }
892
+ /**
893
+ * Build sections from extracted TypeScript shapes.
894
+ *
895
+ * Composition order follows AD-5: conventions → shapes → behaviors.
896
+ *
897
+ * Detail level controls:
898
+ * - summary: type name + kind table only (compact)
899
+ * - standard: names + source text code blocks
900
+ * - detailed: full source with JSDoc and property doc tables
901
+ */
902
+ function buildShapeSections(shapes, detailLevel) {
903
+ const sections = [];
904
+ sections.push(heading(2, 'API Types'));
905
+ if (detailLevel === 'summary') {
906
+ // Summary: just a table of type names and kinds
907
+ const rows = shapes.map((s) => [s.name, s.kind]);
908
+ sections.push(table(['Type', 'Kind'], rows));
909
+ }
910
+ else {
911
+ // Standard/Detailed: code blocks for each shape
912
+ for (const shape of shapes) {
913
+ sections.push(heading(3, `${shape.name} (${shape.kind})`));
914
+ if (shape.jsDoc) {
915
+ sections.push(code(shape.jsDoc, 'typescript'));
916
+ }
917
+ sections.push(code(shape.sourceText, 'typescript'));
918
+ // Property docs table for interfaces at detailed level
919
+ if (detailLevel === 'detailed' && shape.propertyDocs && shape.propertyDocs.length > 0) {
920
+ const propRows = shape.propertyDocs.map((p) => [p.name, p.jsDoc]);
921
+ sections.push(table(['Property', 'Description'], propRows));
922
+ }
923
+ // Param docs table for functions at standard and detailed levels
924
+ if (shape.params && shape.params.length > 0) {
925
+ const paramRows = shape.params.map((p) => [p.name, p.type ?? '', p.description]);
926
+ sections.push(table(['Parameter', 'Type', 'Description'], paramRows));
927
+ }
928
+ // Returns and throws docs at detailed level only
929
+ if (detailLevel === 'detailed') {
930
+ if (shape.returns) {
931
+ const returnText = shape.returns.type
932
+ ? `**Returns** (\`${shape.returns.type}\`): ${shape.returns.description}`
933
+ : `**Returns:** ${shape.returns.description}`;
934
+ sections.push(paragraph(returnText));
935
+ }
936
+ if (shape.throws && shape.throws.length > 0) {
937
+ const throwsRows = shape.throws.map((t) => [t.type ?? '', t.description]);
938
+ sections.push(table(['Exception', 'Description'], throwsRows));
939
+ }
940
+ }
941
+ }
942
+ }
943
+ sections.push(separator());
944
+ return sections;
945
+ }
946
+ // ============================================================================
947
+ // Boundary Summary Builder
948
+ // ============================================================================
949
+ /**
950
+ * Build a compact boundary summary paragraph from diagram scope data.
951
+ *
952
+ * Groups scope patterns by archContext and produces a text like:
953
+ * **Components:** Scanner (PatternA, PatternB), Extractor (PatternC)
954
+ *
955
+ * Skips scopes with `source` override (hardcoded diagrams like fsm-lifecycle).
956
+ * Returns undefined if no patterns found.
957
+ */
958
+ function buildBoundarySummary(dataset, scopes) {
959
+ const allPatterns = [];
960
+ const seenNames = new Set();
961
+ for (const scope of scopes) {
962
+ // Skip hardcoded source diagrams — they don't represent pattern boundaries
963
+ if (scope.source !== undefined)
964
+ continue;
965
+ for (const pattern of collectScopePatterns(dataset, scope)) {
966
+ const name = getPatternName(pattern);
967
+ if (!seenNames.has(name)) {
968
+ seenNames.add(name);
969
+ allPatterns.push(pattern);
970
+ }
971
+ }
972
+ }
973
+ if (allPatterns.length === 0)
974
+ return undefined;
975
+ // Group by archContext
976
+ const byContext = new Map();
977
+ for (const pattern of allPatterns) {
978
+ const ctx = pattern.archContext ?? 'Other';
979
+ const group = byContext.get(ctx) ?? [];
980
+ group.push(getPatternName(pattern));
981
+ byContext.set(ctx, group);
982
+ }
983
+ // Build compact text: "Context (A, B), Context (C)"
984
+ const parts = [];
985
+ for (const [context, names] of [...byContext.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
986
+ const label = context.charAt(0).toUpperCase() + context.slice(1);
987
+ parts.push(`${label} (${names.join(', ')})`);
988
+ }
989
+ return paragraph(`**Components:** ${parts.join(', ')}`);
990
+ }
991
+ // ============================================================================
992
+ // Scoped Diagram Builder
993
+ // ============================================================================
994
+ /**
995
+ * Collect patterns matching a DiagramScope filter.
996
+ */
997
+ function collectScopePatterns(dataset, scope) {
998
+ const nameSet = new Set(scope.patterns ?? []);
999
+ const contextSet = new Set(scope.archContext ?? []);
1000
+ const viewSet = new Set(scope.include ?? []);
1001
+ const layerSet = new Set(scope.archLayer ?? []);
1002
+ return dataset.patterns.filter((p) => {
1003
+ const name = getPatternName(p);
1004
+ if (nameSet.has(name))
1005
+ return true;
1006
+ if (p.archContext !== undefined && contextSet.has(p.archContext))
1007
+ return true;
1008
+ if (p.include?.some((v) => viewSet.has(v)) === true)
1009
+ return true;
1010
+ if (p.archLayer !== undefined && layerSet.has(p.archLayer))
1011
+ return true;
1012
+ return false;
1013
+ });
1014
+ }
1015
+ /**
1016
+ * Collect neighbor patterns — targets of relationship edges from scope patterns
1017
+ * that are not themselves in scope. Only outgoing edges (uses, dependsOn,
1018
+ * implementsPatterns, extendsPattern) are traversed; incoming edges (usedBy,
1019
+ * enables) are intentionally excluded to keep scoped diagrams focused on what
1020
+ * the scope depends on, not what depends on it.
1021
+ */
1022
+ function collectNeighborPatterns(dataset, scopeNames) {
1023
+ const neighborNames = new Set();
1024
+ const relationships = dataset.relationshipIndex ?? {};
1025
+ for (const name of scopeNames) {
1026
+ const rel = relationships[name];
1027
+ if (!rel)
1028
+ continue;
1029
+ for (const target of rel.uses) {
1030
+ if (!scopeNames.has(target))
1031
+ neighborNames.add(target);
1032
+ }
1033
+ for (const target of rel.dependsOn) {
1034
+ if (!scopeNames.has(target))
1035
+ neighborNames.add(target);
1036
+ }
1037
+ for (const target of rel.implementsPatterns) {
1038
+ if (!scopeNames.has(target))
1039
+ neighborNames.add(target);
1040
+ }
1041
+ if (rel.extendsPattern !== undefined && !scopeNames.has(rel.extendsPattern)) {
1042
+ neighborNames.add(rel.extendsPattern);
1043
+ }
1044
+ }
1045
+ if (neighborNames.size === 0)
1046
+ return [];
1047
+ return dataset.patterns.filter((p) => neighborNames.has(getPatternName(p)));
1048
+ }
1049
+ /** Extract shared setup from scope + dataset into a reusable context */
1050
+ function prepareDiagramContext(dataset, scope) {
1051
+ const scopePatterns = collectScopePatterns(dataset, scope);
1052
+ if (scopePatterns.length === 0)
1053
+ return undefined;
1054
+ const nodeIds = new Map();
1055
+ const scopeNames = new Set();
1056
+ for (const pattern of scopePatterns) {
1057
+ const name = getPatternName(pattern);
1058
+ scopeNames.add(name);
1059
+ nodeIds.set(name, sanitizeNodeId(name));
1060
+ }
1061
+ const neighborPatterns = collectNeighborPatterns(dataset, scopeNames);
1062
+ const neighborNames = new Set();
1063
+ for (const pattern of neighborPatterns) {
1064
+ const name = getPatternName(pattern);
1065
+ neighborNames.add(name);
1066
+ nodeIds.set(name, sanitizeNodeId(name));
1067
+ }
1068
+ const relationships = dataset.relationshipIndex ?? {};
1069
+ const allNames = new Set([...scopeNames, ...neighborNames]);
1070
+ // Prune orphan scope patterns — nodes with zero edges in the diagram context.
1071
+ // A pattern participates if it is the source or target of any edge within allNames.
1072
+ const connected = new Set();
1073
+ for (const name of allNames) {
1074
+ const rel = relationships[name];
1075
+ if (!rel)
1076
+ continue;
1077
+ const edgeArrays = [rel.uses, rel.dependsOn, rel.implementsPatterns];
1078
+ for (const targets of edgeArrays) {
1079
+ for (const target of targets) {
1080
+ if (allNames.has(target)) {
1081
+ connected.add(name);
1082
+ connected.add(target);
1083
+ }
1084
+ }
1085
+ }
1086
+ if (rel.extendsPattern !== undefined && allNames.has(rel.extendsPattern)) {
1087
+ connected.add(name);
1088
+ connected.add(rel.extendsPattern);
1089
+ }
1090
+ }
1091
+ // Only prune orphan scope patterns when the diagram has SOME connected
1092
+ // patterns. If no edges exist at all, the diagram is a component listing
1093
+ // and all scope patterns should be preserved.
1094
+ if (connected.size > 0) {
1095
+ const prunedScopePatterns = scopePatterns.filter((p) => connected.has(getPatternName(p)));
1096
+ if (prunedScopePatterns.length === 0) {
1097
+ return undefined;
1098
+ }
1099
+ const prunedScopeNames = new Set();
1100
+ for (const p of prunedScopePatterns) {
1101
+ prunedScopeNames.add(getPatternName(p));
1102
+ }
1103
+ // Rebuild nodeIds — remove pruned entries
1104
+ const prunedNodeIds = new Map();
1105
+ for (const name of [...prunedScopeNames, ...neighborNames]) {
1106
+ const id = nodeIds.get(name);
1107
+ if (id !== undefined)
1108
+ prunedNodeIds.set(name, id);
1109
+ }
1110
+ const prunedAllNames = new Set([...prunedScopeNames, ...neighborNames]);
1111
+ return {
1112
+ scopePatterns: prunedScopePatterns,
1113
+ neighborPatterns,
1114
+ scopeNames: prunedScopeNames,
1115
+ neighborNames,
1116
+ nodeIds: prunedNodeIds,
1117
+ relationships,
1118
+ allNames: prunedAllNames,
1119
+ };
1120
+ }
1121
+ return {
1122
+ scopePatterns,
1123
+ neighborPatterns,
1124
+ scopeNames,
1125
+ neighborNames,
1126
+ nodeIds,
1127
+ relationships,
1128
+ allNames,
1129
+ };
1130
+ }
1131
+ /** Emit relationship edges for flowchart diagrams (DD-4, DD-7) */
1132
+ function emitFlowchartEdges(ctx, showLabels) {
1133
+ const lines = [];
1134
+ const edgeTypes = ['uses', 'dependsOn', 'implementsPatterns'];
1135
+ for (const sourceName of ctx.allNames) {
1136
+ const sourceId = ctx.nodeIds.get(sourceName);
1137
+ if (sourceId === undefined)
1138
+ continue;
1139
+ const rel = ctx.relationships[sourceName];
1140
+ if (!rel)
1141
+ continue;
1142
+ for (const type of edgeTypes) {
1143
+ for (const target of rel[type]) {
1144
+ const targetId = ctx.nodeIds.get(target);
1145
+ if (targetId !== undefined) {
1146
+ const arrow = EDGE_STYLES[type];
1147
+ const label = showLabels ? `|${EDGE_LABELS[type]}|` : '';
1148
+ lines.push(` ${sourceId} ${arrow}${label} ${targetId}`);
1149
+ }
1150
+ }
1151
+ }
1152
+ if (rel.extendsPattern !== undefined) {
1153
+ const targetId = ctx.nodeIds.get(rel.extendsPattern);
1154
+ if (targetId !== undefined) {
1155
+ const arrow = EDGE_STYLES.extendsPattern;
1156
+ const label = showLabels ? `|${EDGE_LABELS.extendsPattern}|` : '';
1157
+ lines.push(` ${sourceId} ${arrow}${label} ${targetId}`);
1158
+ }
1159
+ }
1160
+ }
1161
+ return lines;
1162
+ }
1163
+ /** Build a Mermaid flowchart diagram with custom shapes and edge labels (DD-1, DD-4) */
1164
+ function buildFlowchartDiagram(ctx, scope) {
1165
+ const direction = scope.direction ?? 'TB';
1166
+ const showLabels = scope.showEdgeLabels !== false;
1167
+ const lines = [`graph ${direction}`];
1168
+ // Group scope patterns by archContext for subgraphs
1169
+ const byContext = new Map();
1170
+ const noContext = [];
1171
+ for (const pattern of ctx.scopePatterns) {
1172
+ if (pattern.archContext !== undefined) {
1173
+ const group = byContext.get(pattern.archContext) ?? [];
1174
+ group.push(pattern);
1175
+ byContext.set(pattern.archContext, group);
1176
+ }
1177
+ else {
1178
+ noContext.push(pattern);
1179
+ }
1180
+ }
1181
+ // Emit context subgraphs
1182
+ for (const [context, patterns] of [...byContext.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
1183
+ const contextLabel = context.charAt(0).toUpperCase() + context.slice(1);
1184
+ lines.push(` subgraph ${sanitizeNodeId(context)}["${contextLabel}"]`);
1185
+ for (const pattern of patterns) {
1186
+ const name = getPatternName(pattern);
1187
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1188
+ lines.push(` ${formatNodeDeclaration(nodeId, name, pattern.archRole)}`);
1189
+ }
1190
+ lines.push(' end');
1191
+ }
1192
+ // Emit scope patterns without context
1193
+ for (const pattern of noContext) {
1194
+ const name = getPatternName(pattern);
1195
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1196
+ lines.push(` ${formatNodeDeclaration(nodeId, name, pattern.archRole)}`);
1197
+ }
1198
+ // Emit neighbor subgraph
1199
+ if (ctx.neighborPatterns.length > 0) {
1200
+ lines.push(' subgraph related["Related"]');
1201
+ for (const pattern of ctx.neighborPatterns) {
1202
+ const name = getPatternName(pattern);
1203
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1204
+ lines.push(` ${nodeId}["${name}"]:::neighbor`);
1205
+ }
1206
+ lines.push(' end');
1207
+ }
1208
+ // Emit edges
1209
+ lines.push(...emitFlowchartEdges(ctx, showLabels));
1210
+ // Add neighbor class definition
1211
+ if (ctx.neighborPatterns.length > 0) {
1212
+ lines.push(' classDef neighbor stroke-dasharray: 5 5');
1213
+ }
1214
+ return lines;
1215
+ }
1216
+ /** Build a Mermaid sequence diagram with participants and messages (DD-2) */
1217
+ function buildSequenceDiagram(ctx) {
1218
+ const lines = ['sequenceDiagram'];
1219
+ const edgeTypes = ['uses', 'dependsOn', 'implementsPatterns'];
1220
+ // Emit participant declarations for scope patterns (sanitized for Mermaid syntax)
1221
+ for (const name of ctx.scopeNames) {
1222
+ lines.push(` participant ${sanitizeNodeId(name)} as ${name}`);
1223
+ }
1224
+ // Emit participant declarations for neighbor patterns
1225
+ for (const name of ctx.neighborNames) {
1226
+ lines.push(` participant ${sanitizeNodeId(name)} as ${name}`);
1227
+ }
1228
+ // Emit messages from relationships
1229
+ for (const sourceName of ctx.allNames) {
1230
+ const rel = ctx.relationships[sourceName];
1231
+ if (!rel)
1232
+ continue;
1233
+ for (const type of edgeTypes) {
1234
+ for (const target of rel[type]) {
1235
+ if (ctx.allNames.has(target)) {
1236
+ const arrow = SEQUENCE_ARROWS[type];
1237
+ lines.push(` ${sanitizeNodeId(sourceName)} ${arrow} ${sanitizeNodeId(target)}: ${EDGE_LABELS[type]}`);
1238
+ }
1239
+ }
1240
+ }
1241
+ if (rel.extendsPattern !== undefined && ctx.allNames.has(rel.extendsPattern)) {
1242
+ const arrow = SEQUENCE_ARROWS.extendsPattern;
1243
+ lines.push(` ${sanitizeNodeId(sourceName)} ${arrow} ${sanitizeNodeId(rel.extendsPattern)}: ${EDGE_LABELS.extendsPattern}`);
1244
+ }
1245
+ }
1246
+ return lines;
1247
+ }
1248
+ /** Build a Mermaid state diagram with transitions and pseudo-states (DD-3) */
1249
+ function buildStateDiagram(ctx, scope) {
1250
+ const showLabels = scope.showEdgeLabels !== false;
1251
+ const lines = ['stateDiagram-v2'];
1252
+ // Track incoming/outgoing dependsOn edges for pseudo-states
1253
+ const hasIncoming = new Set();
1254
+ const hasOutgoing = new Set();
1255
+ // Emit state declarations for scope patterns
1256
+ for (const name of ctx.scopeNames) {
1257
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1258
+ lines.push(` state "${name}" as ${nodeId}`);
1259
+ }
1260
+ // Emit state declarations for neighbor patterns
1261
+ for (const name of ctx.neighborNames) {
1262
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1263
+ lines.push(` state "${name}" as ${nodeId}`);
1264
+ }
1265
+ // Emit transitions from dependsOn relationships
1266
+ for (const sourceName of ctx.allNames) {
1267
+ const rel = ctx.relationships[sourceName];
1268
+ if (!rel)
1269
+ continue;
1270
+ for (const target of rel.dependsOn) {
1271
+ if (!ctx.allNames.has(target))
1272
+ continue;
1273
+ const sourceId = ctx.nodeIds.get(sourceName) ?? sanitizeNodeId(sourceName);
1274
+ const targetId = ctx.nodeIds.get(target) ?? sanitizeNodeId(target);
1275
+ const label = showLabels ? ` : ${EDGE_LABELS.dependsOn}` : '';
1276
+ lines.push(` ${targetId} --> ${sourceId}${label}`);
1277
+ hasIncoming.add(sourceName);
1278
+ hasOutgoing.add(target);
1279
+ }
1280
+ }
1281
+ // Add start pseudo-states for patterns with no incoming edges
1282
+ for (const name of ctx.scopeNames) {
1283
+ if (!hasIncoming.has(name)) {
1284
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1285
+ lines.push(` [*] --> ${nodeId}`);
1286
+ }
1287
+ }
1288
+ // Add end pseudo-states for patterns with no outgoing edges
1289
+ for (const name of ctx.scopeNames) {
1290
+ if (!hasOutgoing.has(name)) {
1291
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1292
+ lines.push(` ${nodeId} --> [*]`);
1293
+ }
1294
+ }
1295
+ return lines;
1296
+ }
1297
+ /** Presentation labels for FSM transitions (codec concern, not FSM domain) */
1298
+ const FSM_TRANSITION_LABELS = {
1299
+ roadmap: { active: 'Start work', deferred: 'Postpone', roadmap: 'Stay in planning' },
1300
+ active: { completed: 'All deliverables done', roadmap: 'Blocked / regressed' },
1301
+ deferred: { roadmap: 'Resume planning' },
1302
+ };
1303
+ /** Display names for protection levels in diagram notes */
1304
+ const PROTECTION_DISPLAY = {
1305
+ none: 'none',
1306
+ scope: 'scope-locked',
1307
+ hard: 'hard-locked',
1308
+ };
1309
+ /** Build FSM lifecycle state diagram from VALID_TRANSITIONS and PROTECTION_LEVELS */
1310
+ function buildFsmLifecycleStateDiagram() {
1311
+ const lines = ['stateDiagram-v2'];
1312
+ const states = Object.keys(VALID_TRANSITIONS);
1313
+ // Entry point: first state is initial
1314
+ const initialState = states[0];
1315
+ if (initialState !== undefined) {
1316
+ lines.push(` [*] --> ${initialState}`);
1317
+ }
1318
+ // Transitions derived from the FSM transition matrix
1319
+ for (const [from, targets] of Object.entries(VALID_TRANSITIONS)) {
1320
+ if (targets.length === 0) {
1321
+ // Terminal state
1322
+ lines.push(` ${from} --> [*]`);
1323
+ }
1324
+ else {
1325
+ for (const to of targets) {
1326
+ const label = FSM_TRANSITION_LABELS[from]?.[to];
1327
+ const suffix = label !== undefined ? ` : ${label}` : '';
1328
+ lines.push(` ${from} --> ${to}${suffix}`);
1329
+ }
1330
+ }
1331
+ }
1332
+ // Protection level notes derived from PROTECTION_LEVELS
1333
+ for (const [state, level] of Object.entries(PROTECTION_LEVELS)) {
1334
+ const display = PROTECTION_DISPLAY[level];
1335
+ lines.push(` note right of ${state}`);
1336
+ lines.push(` Protection: ${display}`);
1337
+ lines.push(' end note');
1338
+ }
1339
+ return lines;
1340
+ }
1341
+ /** Build generation pipeline sequence diagram from hardcoded domain knowledge */
1342
+ function buildGenerationPipelineSequenceDiagram() {
1343
+ return [
1344
+ 'sequenceDiagram',
1345
+ ' participant CLI',
1346
+ ' participant Orchestrator',
1347
+ ' participant Scanner',
1348
+ ' participant Extractor',
1349
+ ' participant Transformer',
1350
+ ' participant Codec',
1351
+ ' participant Renderer',
1352
+ ' CLI ->> Orchestrator: generate(config)',
1353
+ ' Orchestrator ->> Scanner: scanPatterns(globs)',
1354
+ ' Scanner -->> Orchestrator: TypeScript ASTs',
1355
+ ' Orchestrator ->> Scanner: scanGherkinFiles(globs)',
1356
+ ' Scanner -->> Orchestrator: Gherkin documents',
1357
+ ' Orchestrator ->> Extractor: extractPatterns(files)',
1358
+ ' Extractor -->> Orchestrator: ExtractedPattern[]',
1359
+ ' Orchestrator ->> Extractor: extractFromGherkin(docs)',
1360
+ ' Extractor -->> Orchestrator: ExtractedPattern[]',
1361
+ ' Orchestrator ->> Orchestrator: mergePatterns(ts, gherkin)',
1362
+ ' Orchestrator ->> Transformer: transformToMasterDataset(patterns)',
1363
+ ' Transformer -->> Orchestrator: MasterDataset',
1364
+ ' Orchestrator ->> Codec: codec.decode(dataset)',
1365
+ ' Codec -->> Orchestrator: RenderableDocument',
1366
+ ' Orchestrator ->> Renderer: render(document)',
1367
+ ' Renderer -->> Orchestrator: markdown string',
1368
+ ];
1369
+ }
1370
+ /** Build MasterDataset fan-out diagram from hardcoded domain knowledge */
1371
+ function buildMasterDatasetViewsDiagram() {
1372
+ return [
1373
+ 'graph TB',
1374
+ ' MD[MasterDataset]',
1375
+ ' MD --> byStatus["byStatus<br/>(completed / active / planned)"]',
1376
+ ' MD --> byPhase["byPhase<br/>(sorted, with counts)"]',
1377
+ ' MD --> byQuarter["byQuarter<br/>(keyed by Q-YYYY)"]',
1378
+ ' MD --> byCategory["byCategory<br/>(keyed by category name)"]',
1379
+ ' MD --> bySource["bySource<br/>(typescript / gherkin / roadmap / prd)"]',
1380
+ ' MD --> counts["counts<br/>(aggregate statistics)"]',
1381
+ ' MD --> RI["relationshipIndex?<br/>(forward + reverse lookups)"]',
1382
+ ' MD --> AI["archIndex?<br/>(role / context / layer / view)"]',
1383
+ ];
1384
+ }
1385
+ /** Build a Mermaid C4 context diagram with system boundaries */
1386
+ function buildC4Diagram(ctx, scope) {
1387
+ const showLabels = scope.showEdgeLabels !== false;
1388
+ const lines = ['C4Context'];
1389
+ if (scope.title !== undefined) {
1390
+ lines.push(` title ${scope.title}`);
1391
+ }
1392
+ // Group scope patterns by archContext for system boundaries
1393
+ const byContext = new Map();
1394
+ const noContext = [];
1395
+ for (const pattern of ctx.scopePatterns) {
1396
+ if (pattern.archContext !== undefined) {
1397
+ const group = byContext.get(pattern.archContext) ?? [];
1398
+ group.push(pattern);
1399
+ byContext.set(pattern.archContext, group);
1400
+ }
1401
+ else {
1402
+ noContext.push(pattern);
1403
+ }
1404
+ }
1405
+ // Emit system boundaries
1406
+ for (const [context, patterns] of [...byContext.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
1407
+ const contextLabel = context.charAt(0).toUpperCase() + context.slice(1);
1408
+ const contextId = sanitizeNodeId(context);
1409
+ lines.push(` Boundary(${contextId}, "${contextLabel}") {`);
1410
+ for (const pattern of patterns) {
1411
+ const name = getPatternName(pattern);
1412
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1413
+ lines.push(` System(${nodeId}, "${name}")`);
1414
+ }
1415
+ lines.push(' }');
1416
+ }
1417
+ // Emit standalone systems (no context)
1418
+ for (const pattern of noContext) {
1419
+ const name = getPatternName(pattern);
1420
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1421
+ lines.push(` System(${nodeId}, "${name}")`);
1422
+ }
1423
+ // Emit external systems for neighbor patterns
1424
+ for (const pattern of ctx.neighborPatterns) {
1425
+ const name = getPatternName(pattern);
1426
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1427
+ lines.push(` System_Ext(${nodeId}, "${name}")`);
1428
+ }
1429
+ // Emit relationships
1430
+ const edgeTypes = ['uses', 'dependsOn', 'implementsPatterns'];
1431
+ for (const sourceName of ctx.allNames) {
1432
+ const sourceId = ctx.nodeIds.get(sourceName);
1433
+ if (sourceId === undefined)
1434
+ continue;
1435
+ const rel = ctx.relationships[sourceName];
1436
+ if (!rel)
1437
+ continue;
1438
+ for (const type of edgeTypes) {
1439
+ for (const target of rel[type]) {
1440
+ const targetId = ctx.nodeIds.get(target);
1441
+ if (targetId !== undefined) {
1442
+ const label = showLabels ? EDGE_LABELS[type] : '';
1443
+ lines.push(` Rel(${sourceId}, ${targetId}, "${label}")`);
1444
+ }
1445
+ }
1446
+ }
1447
+ if (rel.extendsPattern !== undefined) {
1448
+ const targetId = ctx.nodeIds.get(rel.extendsPattern);
1449
+ if (targetId !== undefined) {
1450
+ const label = showLabels ? EDGE_LABELS.extendsPattern : '';
1451
+ lines.push(` Rel(${sourceId}, ${targetId}, "${label}")`);
1452
+ }
1453
+ }
1454
+ }
1455
+ return lines;
1456
+ }
1457
+ /** Build a Mermaid class diagram with pattern exports and relationships */
1458
+ function buildClassDiagram(ctx) {
1459
+ const lines = ['classDiagram'];
1460
+ const edgeTypes = ['uses', 'dependsOn', 'implementsPatterns'];
1461
+ // Class arrow styles per relationship type
1462
+ const classArrows = {
1463
+ uses: '..>',
1464
+ dependsOn: '..>',
1465
+ implementsPatterns: '..|>',
1466
+ extendsPattern: '--|>',
1467
+ };
1468
+ // Emit class declarations for scope patterns (with members)
1469
+ for (const pattern of ctx.scopePatterns) {
1470
+ const name = getPatternName(pattern);
1471
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1472
+ lines.push(` class ${nodeId} {`);
1473
+ if (pattern.archRole !== undefined) {
1474
+ lines.push(` <<${pattern.archRole}>>`);
1475
+ }
1476
+ if (pattern.exports.length > 0) {
1477
+ for (const exp of pattern.exports) {
1478
+ lines.push(` +${exp.name} ${exp.type}`);
1479
+ }
1480
+ }
1481
+ lines.push(' }');
1482
+ }
1483
+ // Emit class declarations for neighbor patterns (no members)
1484
+ for (const pattern of ctx.neighborPatterns) {
1485
+ const name = getPatternName(pattern);
1486
+ const nodeId = ctx.nodeIds.get(name) ?? sanitizeNodeId(name);
1487
+ lines.push(` class ${nodeId}`);
1488
+ }
1489
+ // Emit relationship edges
1490
+ for (const sourceName of ctx.allNames) {
1491
+ const sourceId = ctx.nodeIds.get(sourceName);
1492
+ if (sourceId === undefined)
1493
+ continue;
1494
+ const rel = ctx.relationships[sourceName];
1495
+ if (!rel)
1496
+ continue;
1497
+ for (const type of edgeTypes) {
1498
+ for (const target of rel[type]) {
1499
+ const targetId = ctx.nodeIds.get(target);
1500
+ if (targetId !== undefined) {
1501
+ const arrow = classArrows[type] ?? '..>';
1502
+ lines.push(` ${sourceId} ${arrow} ${targetId} : ${EDGE_LABELS[type]}`);
1503
+ }
1504
+ }
1505
+ }
1506
+ if (rel.extendsPattern !== undefined) {
1507
+ const targetId = ctx.nodeIds.get(rel.extendsPattern);
1508
+ if (targetId !== undefined) {
1509
+ lines.push(` ${sourceId} --|> ${targetId} : ${EDGE_LABELS.extendsPattern}`);
1510
+ }
1511
+ }
1512
+ }
1513
+ return lines;
1514
+ }
1515
+ /**
1516
+ * Build a scoped relationship diagram from DiagramScope config.
1517
+ *
1518
+ * Dispatches to type-specific builders based on scope.diagramType (DD-6).
1519
+ * Scope patterns are grouped by archContext in subgraphs (flowchart) or
1520
+ * rendered as participants/states (sequence/state diagrams).
1521
+ */
1522
+ export function buildScopedDiagram(dataset, scope) {
1523
+ const title = scope.title ?? 'Component Overview';
1524
+ // Content source override: render hardcoded domain diagrams
1525
+ if (scope.source === 'fsm-lifecycle') {
1526
+ return [
1527
+ heading(2, title),
1528
+ paragraph('FSM lifecycle showing valid state transitions and protection levels:'),
1529
+ mermaid(buildFsmLifecycleStateDiagram().join('\n')),
1530
+ separator(),
1531
+ ];
1532
+ }
1533
+ if (scope.source === 'generation-pipeline') {
1534
+ return [
1535
+ heading(2, title),
1536
+ paragraph('Temporal flow of the documentation generation pipeline:'),
1537
+ mermaid(buildGenerationPipelineSequenceDiagram().join('\n')),
1538
+ separator(),
1539
+ ];
1540
+ }
1541
+ if (scope.source === 'master-dataset-views') {
1542
+ return [
1543
+ heading(2, title),
1544
+ paragraph('Pre-computed view fan-out from MasterDataset (single-pass transform):'),
1545
+ mermaid(buildMasterDatasetViewsDiagram().join('\n')),
1546
+ separator(),
1547
+ ];
1548
+ }
1549
+ const ctx = prepareDiagramContext(dataset, scope);
1550
+ if (ctx === undefined)
1551
+ return [];
1552
+ let diagramLines;
1553
+ switch (scope.diagramType ?? 'graph') {
1554
+ case 'sequenceDiagram':
1555
+ diagramLines = buildSequenceDiagram(ctx);
1556
+ break;
1557
+ case 'stateDiagram-v2':
1558
+ diagramLines = buildStateDiagram(ctx, scope);
1559
+ break;
1560
+ case 'C4Context':
1561
+ diagramLines = buildC4Diagram(ctx, scope);
1562
+ break;
1563
+ case 'classDiagram':
1564
+ diagramLines = buildClassDiagram(ctx);
1565
+ break;
1566
+ case 'graph':
1567
+ default:
1568
+ diagramLines = buildFlowchartDiagram(ctx, scope);
1569
+ break;
1570
+ }
1571
+ return [
1572
+ heading(2, title),
1573
+ paragraph('Scoped architecture diagram showing component relationships:'),
1574
+ mermaid(diagramLines.join('\n')),
1575
+ separator(),
1576
+ ];
1577
+ }
1578
+ //# sourceMappingURL=reference.js.map