onto-mcp 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (447) hide show
  1. package/.onto/authority/core-lens-registry.yaml +134 -0
  2. package/.onto/authority/core-lexicon.yaml +1562 -0
  3. package/.onto/authority/diagnostic-codes.yaml +94 -0
  4. package/.onto/domains/accounting/competency_qs.md +384 -0
  5. package/.onto/domains/accounting/concepts.md +186 -0
  6. package/.onto/domains/accounting/conciseness_rules.md +160 -0
  7. package/.onto/domains/accounting/dependency_rules.md +239 -0
  8. package/.onto/domains/accounting/domain_scope.md +213 -0
  9. package/.onto/domains/accounting/extension_cases.md +416 -0
  10. package/.onto/domains/accounting/logic_rules.md +226 -0
  11. package/.onto/domains/accounting/structure_spec.md +298 -0
  12. package/.onto/domains/accounting-kr/competency_qs.md +562 -0
  13. package/.onto/domains/accounting-kr/concepts.md +187 -0
  14. package/.onto/domains/accounting-kr/conciseness_rules.md +125 -0
  15. package/.onto/domains/accounting-kr/dependency_rules.md +93 -0
  16. package/.onto/domains/accounting-kr/domain_scope.md +140 -0
  17. package/.onto/domains/accounting-kr/extension_cases.md +343 -0
  18. package/.onto/domains/accounting-kr/logic_rules.md +160 -0
  19. package/.onto/domains/accounting-kr/structure_spec.md +85 -0
  20. package/.onto/domains/business/competency_qs.md +263 -0
  21. package/.onto/domains/business/concepts.md +200 -0
  22. package/.onto/domains/business/conciseness_rules.md +135 -0
  23. package/.onto/domains/business/dependency_rules.md +113 -0
  24. package/.onto/domains/business/domain_scope.md +240 -0
  25. package/.onto/domains/business/extension_cases.md +249 -0
  26. package/.onto/domains/business/logic_rules.md +134 -0
  27. package/.onto/domains/business/structure_spec.md +114 -0
  28. package/.onto/domains/finance/competency_qs.md +362 -0
  29. package/.onto/domains/finance/concepts.md +194 -0
  30. package/.onto/domains/finance/conciseness_rules.md +155 -0
  31. package/.onto/domains/finance/dependency_rules.md +171 -0
  32. package/.onto/domains/finance/domain_scope.md +215 -0
  33. package/.onto/domains/finance/extension_cases.md +350 -0
  34. package/.onto/domains/finance/logic_rules.md +191 -0
  35. package/.onto/domains/finance/structure_spec.md +182 -0
  36. package/.onto/domains/llm-native-development/competency_qs.md +430 -0
  37. package/.onto/domains/llm-native-development/concepts.md +242 -0
  38. package/.onto/domains/llm-native-development/conciseness_rules.md +163 -0
  39. package/.onto/domains/llm-native-development/dependency_rules.md +216 -0
  40. package/.onto/domains/llm-native-development/domain_scope.md +197 -0
  41. package/.onto/domains/llm-native-development/extension_cases.md +474 -0
  42. package/.onto/domains/llm-native-development/logic_rules.md +123 -0
  43. package/.onto/domains/llm-native-development/prompt_interface.md +49 -0
  44. package/.onto/domains/llm-native-development/structure_spec.md +245 -0
  45. package/.onto/domains/market-intelligence/competency_qs.md +274 -0
  46. package/.onto/domains/market-intelligence/concepts.md +233 -0
  47. package/.onto/domains/market-intelligence/conciseness_rules.md +165 -0
  48. package/.onto/domains/market-intelligence/dependency_rules.md +197 -0
  49. package/.onto/domains/market-intelligence/domain_scope.md +231 -0
  50. package/.onto/domains/market-intelligence/extension_cases.md +425 -0
  51. package/.onto/domains/market-intelligence/logic_rules.md +247 -0
  52. package/.onto/domains/market-intelligence/structure_spec.md +209 -0
  53. package/.onto/domains/ontology/competency_qs.md +394 -0
  54. package/.onto/domains/ontology/concepts.md +172 -0
  55. package/.onto/domains/ontology/conciseness_rules.md +134 -0
  56. package/.onto/domains/ontology/dependency_rules.md +125 -0
  57. package/.onto/domains/ontology/domain_scope.md +114 -0
  58. package/.onto/domains/ontology/extension_cases.md +501 -0
  59. package/.onto/domains/ontology/logic_rules.md +114 -0
  60. package/.onto/domains/ontology/problem_framing_profile.md +67 -0
  61. package/.onto/domains/ontology/structure_spec.md +115 -0
  62. package/.onto/domains/palantir-foundry/RESEARCH_NOTES.md +911 -0
  63. package/.onto/domains/palantir-foundry/competency_qs.md +191 -0
  64. package/.onto/domains/palantir-foundry/competitive_comparison.md +329 -0
  65. package/.onto/domains/palantir-foundry/concepts.md +197 -0
  66. package/.onto/domains/palantir-foundry/conciseness_rules.md +245 -0
  67. package/.onto/domains/palantir-foundry/dependency_rules.md +135 -0
  68. package/.onto/domains/palantir-foundry/domain_scope.md +395 -0
  69. package/.onto/domains/palantir-foundry/extension_cases.md +210 -0
  70. package/.onto/domains/palantir-foundry/logic_rules.md +172 -0
  71. package/.onto/domains/palantir-foundry/structure_spec.md +291 -0
  72. package/.onto/domains/software-engineering/competency_qs.md +538 -0
  73. package/.onto/domains/software-engineering/concepts.md +238 -0
  74. package/.onto/domains/software-engineering/conciseness_rules.md +167 -0
  75. package/.onto/domains/software-engineering/dependency_rules.md +216 -0
  76. package/.onto/domains/software-engineering/domain_scope.md +183 -0
  77. package/.onto/domains/software-engineering/extension_cases.md +551 -0
  78. package/.onto/domains/software-engineering/logic_rules.md +240 -0
  79. package/.onto/domains/software-engineering/problem_framing_profile.md +68 -0
  80. package/.onto/domains/software-engineering/structure_spec.md +185 -0
  81. package/.onto/domains/ui-design/competency_qs.md +567 -0
  82. package/.onto/domains/ui-design/concepts.md +194 -0
  83. package/.onto/domains/ui-design/conciseness_rules.md +190 -0
  84. package/.onto/domains/ui-design/dependency_rules.md +323 -0
  85. package/.onto/domains/ui-design/domain_scope.md +340 -0
  86. package/.onto/domains/ui-design/extension_cases.md +563 -0
  87. package/.onto/domains/ui-design/logic_rules.md +349 -0
  88. package/.onto/domains/ui-design/structure_spec.md +252 -0
  89. package/.onto/domains/visual-design/competency_qs.md +472 -0
  90. package/.onto/domains/visual-design/concepts.md +147 -0
  91. package/.onto/domains/visual-design/conciseness_rules.md +186 -0
  92. package/.onto/domains/visual-design/dependency_rules.md +282 -0
  93. package/.onto/domains/visual-design/domain_scope.md +290 -0
  94. package/.onto/domains/visual-design/extension_cases.md +480 -0
  95. package/.onto/domains/visual-design/logic_rules.md +232 -0
  96. package/.onto/domains/visual-design/structure_spec.md +213 -0
  97. package/.onto/principles/llm-native-development-guideline.md +401 -0
  98. package/.onto/principles/llm-runtime-interface-principles.md +665 -0
  99. package/.onto/principles/non-specialist-communication-guideline.md +74 -0
  100. package/.onto/principles/ontology-as-code-guideline.md +243 -0
  101. package/.onto/principles/ontology-as-code-naming-charter.md +130 -0
  102. package/.onto/principles/product-locality-principle.md +129 -0
  103. package/.onto/principles/productization-charter.md +569 -0
  104. package/.onto/processes/evolve/material-kind-adapter-contract.md +113 -0
  105. package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +366 -0
  106. package/.onto/processes/reconstruct/source-profile-contract.md +107 -0
  107. package/.onto/processes/reconstruct/source-profiles/code.md +72 -0
  108. package/.onto/processes/reconstruct/source-profiles/database.md +74 -0
  109. package/.onto/processes/reconstruct/source-profiles/document.md +71 -0
  110. package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +79 -0
  111. package/.onto/processes/review/binding-contract.md +270 -0
  112. package/.onto/processes/review/execution-preparation-artifacts.md +281 -0
  113. package/.onto/processes/review/interpretation-contract.md +245 -0
  114. package/.onto/processes/review/issue-stance-deliberation-contract.md +761 -0
  115. package/.onto/processes/review/lens-prompt-contract.md +402 -0
  116. package/.onto/processes/review/lens-registry.md +127 -0
  117. package/.onto/processes/review/pre-dispatch-contracts.md +428 -0
  118. package/.onto/processes/review/productized-live-path.md +398 -0
  119. package/.onto/processes/review/prompt-execution-runner-contract.md +187 -0
  120. package/.onto/processes/review/record-contract.md +427 -0
  121. package/.onto/processes/review/record-field-mapping.md +337 -0
  122. package/.onto/processes/review/review-context-manifest-contract.md +356 -0
  123. package/.onto/processes/review/review-execution-ux-contract.md +809 -0
  124. package/.onto/processes/review/review-target-profile-contract.md +259 -0
  125. package/.onto/processes/review/shared-phenomenon-contract.md +129 -0
  126. package/.onto/processes/review/synthesize-prompt-contract.md +343 -0
  127. package/.onto/processes/shared/target-material-kind-contract.md +198 -0
  128. package/.onto/roles/axiology.md +81 -0
  129. package/.onto/roles/conciseness.md +36 -0
  130. package/.onto/roles/coverage.md +34 -0
  131. package/.onto/roles/dependency.md +37 -0
  132. package/.onto/roles/evolution.md +35 -0
  133. package/.onto/roles/logic.md +104 -0
  134. package/.onto/roles/pragmatics.md +32 -0
  135. package/.onto/roles/semantics.md +36 -0
  136. package/.onto/roles/structure.md +33 -0
  137. package/.onto/roles/synthesize.md +92 -0
  138. package/AGENTS.md +240 -0
  139. package/CLAUDE.md +39 -0
  140. package/README.md +287 -0
  141. package/bin/onto +92 -0
  142. package/dist/cli.js +101 -0
  143. package/dist/core-api/reconstruct-api.js +222 -0
  144. package/dist/core-api/review-api.js +1271 -0
  145. package/dist/core-runtime/cli/assemble-review-record.js +431 -0
  146. package/dist/core-runtime/cli/bootstrap-review-binding.js +186 -0
  147. package/dist/core-runtime/cli/codex-nested-dispatch.js +226 -0
  148. package/dist/core-runtime/cli/codex-nested-dispatch.test.js +390 -0
  149. package/dist/core-runtime/cli/codex-nested-teamlead-executor.js +464 -0
  150. package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +335 -0
  151. package/dist/core-runtime/cli/codex-review-unit-executor.js +228 -0
  152. package/dist/core-runtime/cli/complete-review-session.js +64 -0
  153. package/dist/core-runtime/cli/complexity-assessment.js +153 -0
  154. package/dist/core-runtime/cli/coordinator-helpers.js +583 -0
  155. package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +167 -0
  156. package/dist/core-runtime/cli/coordinator-state-machine.js +794 -0
  157. package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +615 -0
  158. package/dist/core-runtime/cli/e2e-start-review-session.test.js +312 -0
  159. package/dist/core-runtime/cli/health.js +44 -0
  160. package/dist/core-runtime/cli/inline-http-review-unit-executor.js +656 -0
  161. package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +567 -0
  162. package/dist/core-runtime/cli/materialize-review-execution-preparation.js +104 -0
  163. package/dist/core-runtime/cli/materialize-review-prompt-packets.js +952 -0
  164. package/dist/core-runtime/cli/migrate-session-roots.js +118 -0
  165. package/dist/core-runtime/cli/mock-review-unit-executor.js +285 -0
  166. package/dist/core-runtime/cli/onto-tools.js +369 -0
  167. package/dist/core-runtime/cli/prepare-review-session.js +272 -0
  168. package/dist/core-runtime/cli/render-review-final-output.js +350 -0
  169. package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +106 -0
  170. package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +268 -0
  171. package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +136 -0
  172. package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +201 -0
  173. package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +192 -0
  174. package/dist/core-runtime/cli/review-invoke.js +2030 -0
  175. package/dist/core-runtime/cli/run-review-prompt-execution.js +2152 -0
  176. package/dist/core-runtime/cli/session-root-guard.js +168 -0
  177. package/dist/core-runtime/cli/spawn-watcher.js +173 -0
  178. package/dist/core-runtime/cli/spawn-watcher.test.js +457 -0
  179. package/dist/core-runtime/cli/start-review-session.js +68 -0
  180. package/dist/core-runtime/cli/strip-wrapping-code-fence.js +56 -0
  181. package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +79 -0
  182. package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +412 -0
  183. package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +351 -0
  184. package/dist/core-runtime/cli/topology-executor-mapping.js +139 -0
  185. package/dist/core-runtime/cli/topology-executor-mapping.test.js +173 -0
  186. package/dist/core-runtime/cli/write-review-interpretation.js +81 -0
  187. package/dist/core-runtime/config/onto-config-cli.js +278 -0
  188. package/dist/core-runtime/config/onto-config-key-path.js +288 -0
  189. package/dist/core-runtime/config/onto-config-key-path.test.js +195 -0
  190. package/dist/core-runtime/config/onto-config-preview.js +108 -0
  191. package/dist/core-runtime/config/onto-config-preview.test.js +132 -0
  192. package/dist/core-runtime/discovery/config-chain.js +118 -0
  193. package/dist/core-runtime/discovery/config-chain.test.js +103 -0
  194. package/dist/core-runtime/discovery/config-profile.js +199 -0
  195. package/dist/core-runtime/discovery/config-profile.test.js +233 -0
  196. package/dist/core-runtime/discovery/host-detection.js +33 -0
  197. package/dist/core-runtime/discovery/host-detection.test.js +186 -0
  198. package/dist/core-runtime/discovery/installation-paths.js +21 -0
  199. package/dist/core-runtime/discovery/installation-paths.test.js +65 -0
  200. package/dist/core-runtime/discovery/lens-registry.js +60 -0
  201. package/dist/core-runtime/discovery/lens-registry.test.js +81 -0
  202. package/dist/core-runtime/discovery/onto-home.js +71 -0
  203. package/dist/core-runtime/discovery/path-normalization.js +28 -0
  204. package/dist/core-runtime/discovery/path-normalization.test.js +22 -0
  205. package/dist/core-runtime/discovery/plugin-path.js +72 -0
  206. package/dist/core-runtime/discovery/plugin-path.test.js +95 -0
  207. package/dist/core-runtime/discovery/project-root.js +47 -0
  208. package/dist/core-runtime/discovery/settings-chain.js +353 -0
  209. package/dist/core-runtime/discovery/walk-up.js +17 -0
  210. package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +344 -0
  211. package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +915 -0
  212. package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +564 -0
  213. package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +708 -0
  214. package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +165 -0
  215. package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +227 -0
  216. package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +59 -0
  217. package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +205 -0
  218. package/dist/core-runtime/evolve/adapters/methodology/adapter.js +16 -0
  219. package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +9 -0
  220. package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +298 -0
  221. package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +70 -0
  222. package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +46 -0
  223. package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +73 -0
  224. package/dist/core-runtime/evolve/adapters/registry.js +47 -0
  225. package/dist/core-runtime/evolve/adapters/registry.test.js +67 -0
  226. package/dist/core-runtime/evolve/cli.js +256 -0
  227. package/dist/core-runtime/evolve/commands/align.js +194 -0
  228. package/dist/core-runtime/evolve/commands/align.test.js +82 -0
  229. package/dist/core-runtime/evolve/commands/apply.js +161 -0
  230. package/dist/core-runtime/evolve/commands/apply.test.js +138 -0
  231. package/dist/core-runtime/evolve/commands/close.js +39 -0
  232. package/dist/core-runtime/evolve/commands/close.test.js +99 -0
  233. package/dist/core-runtime/evolve/commands/defer.js +40 -0
  234. package/dist/core-runtime/evolve/commands/defer.test.js +134 -0
  235. package/dist/core-runtime/evolve/commands/draft.js +323 -0
  236. package/dist/core-runtime/evolve/commands/draft.test.js +178 -0
  237. package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +208 -0
  238. package/dist/core-runtime/evolve/commands/error-messages.js +125 -0
  239. package/dist/core-runtime/evolve/commands/error-messages.test.js +167 -0
  240. package/dist/core-runtime/evolve/commands/propose-align.js +222 -0
  241. package/dist/core-runtime/evolve/commands/propose-align.test.js +136 -0
  242. package/dist/core-runtime/evolve/commands/reconstruct.js +330 -0
  243. package/dist/core-runtime/evolve/commands/reconstruct.test.js +278 -0
  244. package/dist/core-runtime/evolve/commands/shared.js +22 -0
  245. package/dist/core-runtime/evolve/commands/stale-check.js +103 -0
  246. package/dist/core-runtime/evolve/commands/stale-check.test.js +84 -0
  247. package/dist/core-runtime/evolve/commands/start.js +887 -0
  248. package/dist/core-runtime/evolve/commands/start.test.js +396 -0
  249. package/dist/core-runtime/evolve/config/project-config.js +99 -0
  250. package/dist/core-runtime/evolve/config/project-config.test.js +170 -0
  251. package/dist/core-runtime/evolve/renderers/align-packet.js +280 -0
  252. package/dist/core-runtime/evolve/renderers/align-packet.test.js +332 -0
  253. package/dist/core-runtime/evolve/renderers/draft-packet.js +303 -0
  254. package/dist/core-runtime/evolve/renderers/draft-packet.test.js +377 -0
  255. package/dist/core-runtime/evolve/renderers/format.js +5 -0
  256. package/dist/core-runtime/evolve/renderers/scope-md.js +237 -0
  257. package/dist/core-runtime/evolve/renderers/scope-md.test.js +306 -0
  258. package/dist/core-runtime/govern/cli.js +369 -0
  259. package/dist/core-runtime/govern/cli.test.js +314 -0
  260. package/dist/core-runtime/govern/drift-engine.js +103 -0
  261. package/dist/core-runtime/govern/drift-engine.test.js +319 -0
  262. package/dist/core-runtime/govern/promote-principle.js +206 -0
  263. package/dist/core-runtime/govern/promote-principle.test.js +368 -0
  264. package/dist/core-runtime/govern/queue.js +81 -0
  265. package/dist/core-runtime/govern/types.js +16 -0
  266. package/dist/core-runtime/install/cli.js +530 -0
  267. package/dist/core-runtime/install/detect.js +128 -0
  268. package/dist/core-runtime/install/detect.test.js +155 -0
  269. package/dist/core-runtime/install/gitignore-update.js +74 -0
  270. package/dist/core-runtime/install/gitignore-update.test.js +64 -0
  271. package/dist/core-runtime/install/install-integration.test.js +373 -0
  272. package/dist/core-runtime/install/prompts.js +389 -0
  273. package/dist/core-runtime/install/prompts.test.js +293 -0
  274. package/dist/core-runtime/install/types.js +26 -0
  275. package/dist/core-runtime/install/validation.js +295 -0
  276. package/dist/core-runtime/install/validation.test.js +313 -0
  277. package/dist/core-runtime/install/writer.js +254 -0
  278. package/dist/core-runtime/install/writer.test.js +218 -0
  279. package/dist/core-runtime/learning/extractor.js +461 -0
  280. package/dist/core-runtime/learning/feedback.js +179 -0
  281. package/dist/core-runtime/learning/health-report.js +165 -0
  282. package/dist/core-runtime/learning/health-report.test.js +169 -0
  283. package/dist/core-runtime/learning/loader.js +388 -0
  284. package/dist/core-runtime/learning/loader.test.js +102 -0
  285. package/dist/core-runtime/learning/promote/apply-state.js +240 -0
  286. package/dist/core-runtime/learning/promote/audit-obligation.js +195 -0
  287. package/dist/core-runtime/learning/promote/collector.js +432 -0
  288. package/dist/core-runtime/learning/promote/degraded-state.js +125 -0
  289. package/dist/core-runtime/learning/promote/domain-doc-proposer.js +166 -0
  290. package/dist/core-runtime/learning/promote/e2e-promote.test.js +6385 -0
  291. package/dist/core-runtime/learning/promote/health-snapshot.js +150 -0
  292. package/dist/core-runtime/learning/promote/insight-reclassifier.js +544 -0
  293. package/dist/core-runtime/learning/promote/judgment-auditor.js +517 -0
  294. package/dist/core-runtime/learning/promote/panel-reviewer.js +1158 -0
  295. package/dist/core-runtime/learning/promote/promote-executor.js +1675 -0
  296. package/dist/core-runtime/learning/promote/promoter.js +307 -0
  297. package/dist/core-runtime/learning/promote/retirement.js +122 -0
  298. package/dist/core-runtime/learning/promote/types.js +23 -0
  299. package/dist/core-runtime/learning/prompt-sections.js +51 -0
  300. package/dist/core-runtime/learning/shared/artifact-registry-init.js +45 -0
  301. package/dist/core-runtime/learning/shared/artifact-registry.js +254 -0
  302. package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +73 -0
  303. package/dist/core-runtime/learning/shared/audit-state.js +99 -0
  304. package/dist/core-runtime/learning/shared/duplicate-check.js +28 -0
  305. package/dist/core-runtime/learning/shared/llm-caller.js +831 -0
  306. package/dist/core-runtime/learning/shared/llm-caller.test.js +601 -0
  307. package/dist/core-runtime/learning/shared/llm-tool-loop.js +393 -0
  308. package/dist/core-runtime/learning/shared/mode.js +25 -0
  309. package/dist/core-runtime/learning/shared/paths.js +84 -0
  310. package/dist/core-runtime/learning/shared/paths.test.js +79 -0
  311. package/dist/core-runtime/learning/shared/patterns.js +37 -0
  312. package/dist/core-runtime/learning/shared/recoverability.js +355 -0
  313. package/dist/core-runtime/learning/shared/recovery-context.js +374 -0
  314. package/dist/core-runtime/learning/shared/scope.js +1 -0
  315. package/dist/core-runtime/learning/shared/semantic-classifier.js +94 -0
  316. package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +42 -0
  317. package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +37 -0
  318. package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +39 -0
  319. package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +41 -0
  320. package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +38 -0
  321. package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +43 -0
  322. package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +113 -0
  323. package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +36 -0
  324. package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +48 -0
  325. package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +43 -0
  326. package/dist/core-runtime/learning/shared/specs/spec-helpers.js +64 -0
  327. package/dist/core-runtime/learning/usage-tracker.js +190 -0
  328. package/dist/core-runtime/learning/usage-tracker.test.js +176 -0
  329. package/dist/core-runtime/llm/llm-caller.js +649 -0
  330. package/dist/core-runtime/llm/llm-tool-loop.js +401 -0
  331. package/dist/core-runtime/llm/model-switcher.js +62 -0
  332. package/dist/core-runtime/logger.js +22 -0
  333. package/dist/core-runtime/onboard/detect-review-axes.js +122 -0
  334. package/dist/core-runtime/onboard/detect-review-axes.test.js +127 -0
  335. package/dist/core-runtime/onboard/write-review-block.js +188 -0
  336. package/dist/core-runtime/onboard/write-review-block.test.js +240 -0
  337. package/dist/core-runtime/readers/brownfield-builder.js +150 -0
  338. package/dist/core-runtime/readers/brownfield-builder.test.js +136 -0
  339. package/dist/core-runtime/readers/code-chunk-collector.js +53 -0
  340. package/dist/core-runtime/readers/code-chunk-collector.test.js +136 -0
  341. package/dist/core-runtime/readers/file-utils.js +240 -0
  342. package/dist/core-runtime/readers/file-utils.test.js +146 -0
  343. package/dist/core-runtime/readers/lexicon-citation-check.js +93 -0
  344. package/dist/core-runtime/readers/lexicon-citation-check.test.js +77 -0
  345. package/dist/core-runtime/readers/mcp-figma.js +30 -0
  346. package/dist/core-runtime/readers/mcp-figma.test.js +82 -0
  347. package/dist/core-runtime/readers/mcp-generic.js +31 -0
  348. package/dist/core-runtime/readers/mcp-generic.test.js +76 -0
  349. package/dist/core-runtime/readers/ontology-index.js +148 -0
  350. package/dist/core-runtime/readers/ontology-index.test.js +245 -0
  351. package/dist/core-runtime/readers/ontology-query.js +168 -0
  352. package/dist/core-runtime/readers/ontology-query.test.js +311 -0
  353. package/dist/core-runtime/readers/ontology-resolve.js +48 -0
  354. package/dist/core-runtime/readers/ontology-resolve.test.js +48 -0
  355. package/dist/core-runtime/readers/patterns/index.js +7 -0
  356. package/dist/core-runtime/readers/review-log.js +213 -0
  357. package/dist/core-runtime/readers/review-log.test.js +313 -0
  358. package/dist/core-runtime/readers/scan-local.js +102 -0
  359. package/dist/core-runtime/readers/scan-local.test.js +102 -0
  360. package/dist/core-runtime/readers/scan-tarball.js +121 -0
  361. package/dist/core-runtime/readers/scan-tarball.test.js +283 -0
  362. package/dist/core-runtime/readers/scan-vault.js +34 -0
  363. package/dist/core-runtime/readers/scan-vault.test.js +81 -0
  364. package/dist/core-runtime/readers/types.js +42 -0
  365. package/dist/core-runtime/readers/types.test.js +94 -0
  366. package/dist/core-runtime/readers/viewpoint-collectors.js +229 -0
  367. package/dist/core-runtime/reconstruct/artifact-types.js +1 -0
  368. package/dist/core-runtime/reconstruct/directive-validation.js +123 -0
  369. package/dist/core-runtime/reconstruct/materialize-preparation.js +251 -0
  370. package/dist/core-runtime/reconstruct/record.js +198 -0
  371. package/dist/core-runtime/reconstruct/run.js +578 -0
  372. package/dist/core-runtime/reconstruct/seed-candidate-validation.js +356 -0
  373. package/dist/core-runtime/reconstruct/source-observations.js +62 -0
  374. package/dist/core-runtime/reconstruct/source-profiles.js +73 -0
  375. package/dist/core-runtime/release-channel/release-channel.js +90 -0
  376. package/dist/core-runtime/review/artifact-types.js +13 -0
  377. package/dist/core-runtime/review/citation-audit.js +204 -0
  378. package/dist/core-runtime/review/citation-audit.test.js +165 -0
  379. package/dist/core-runtime/review/controlled-lens-deliberation.js +125 -0
  380. package/dist/core-runtime/review/execution-plan-resolver.js +247 -0
  381. package/dist/core-runtime/review/execution-plan-resolver.test.js +243 -0
  382. package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +246 -0
  383. package/dist/core-runtime/review/execution-topology-resolver.js +401 -0
  384. package/dist/core-runtime/review/execution-topology-resolver.test.js +315 -0
  385. package/dist/core-runtime/review/failure-records.js +57 -0
  386. package/dist/core-runtime/review/inline-context-embedder.js +141 -0
  387. package/dist/core-runtime/review/inline-context-embedder.test.js +154 -0
  388. package/dist/core-runtime/review/issue-artifact-runtime.js +859 -0
  389. package/dist/core-runtime/review/legacy-mode-policy.js +88 -0
  390. package/dist/core-runtime/review/lens-completion-policy.js +17 -0
  391. package/dist/core-runtime/review/materializers-effort-persist.test.js +79 -0
  392. package/dist/core-runtime/review/materializers.js +963 -0
  393. package/dist/core-runtime/review/ontology-path-classifier.js +179 -0
  394. package/dist/core-runtime/review/ontology-path-classifier.test.js +216 -0
  395. package/dist/core-runtime/review/packet-boundary-policy.js +215 -0
  396. package/dist/core-runtime/review/packet-boundary-policy.test.js +107 -0
  397. package/dist/core-runtime/review/participating-lens-paths.js +61 -0
  398. package/dist/core-runtime/review/participating-lens-paths.test.js +73 -0
  399. package/dist/core-runtime/review/review-artifact-utils.js +287 -0
  400. package/dist/core-runtime/review/review-config-legacy-translate.js +244 -0
  401. package/dist/core-runtime/review/review-config-legacy-translate.test.js +161 -0
  402. package/dist/core-runtime/review/review-config-validator.js +289 -0
  403. package/dist/core-runtime/review/review-config-validator.test.js +236 -0
  404. package/dist/core-runtime/review/review-execution-profile.js +193 -0
  405. package/dist/core-runtime/review/review-execution-route.js +52 -0
  406. package/dist/core-runtime/review/review-progress-contract.js +123 -0
  407. package/dist/core-runtime/review/review-record-validation.js +251 -0
  408. package/dist/core-runtime/review/review-result-classification.js +379 -0
  409. package/dist/core-runtime/review/review-state-machine.js +39 -0
  410. package/dist/core-runtime/review/route-visibility.js +125 -0
  411. package/dist/core-runtime/review/shape-pipeline-audit.test.js +311 -0
  412. package/dist/core-runtime/review/shape-to-topology-id.js +117 -0
  413. package/dist/core-runtime/review/shape-to-topology-id.test.js +132 -0
  414. package/dist/core-runtime/review/topology-shape-derivation.js +155 -0
  415. package/dist/core-runtime/review/topology-shape-derivation.test.js +195 -0
  416. package/dist/core-runtime/scope-runtime/constants.js +12 -0
  417. package/dist/core-runtime/scope-runtime/constraint-pool.js +166 -0
  418. package/dist/core-runtime/scope-runtime/constraint-pool.test.js +674 -0
  419. package/dist/core-runtime/scope-runtime/domain-validation-log.js +135 -0
  420. package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +156 -0
  421. package/dist/core-runtime/scope-runtime/eval-persistence.js +65 -0
  422. package/dist/core-runtime/scope-runtime/eval-persistence.test.js +84 -0
  423. package/dist/core-runtime/scope-runtime/event-pipeline.js +64 -0
  424. package/dist/core-runtime/scope-runtime/event-pipeline.test.js +450 -0
  425. package/dist/core-runtime/scope-runtime/event-store.js +39 -0
  426. package/dist/core-runtime/scope-runtime/event-store.test.js +95 -0
  427. package/dist/core-runtime/scope-runtime/gate-guard.js +348 -0
  428. package/dist/core-runtime/scope-runtime/gate-guard.test.js +1047 -0
  429. package/dist/core-runtime/scope-runtime/hash.js +4 -0
  430. package/dist/core-runtime/scope-runtime/hash.test.js +33 -0
  431. package/dist/core-runtime/scope-runtime/id.js +4 -0
  432. package/dist/core-runtime/scope-runtime/id.test.js +17 -0
  433. package/dist/core-runtime/scope-runtime/reducer.js +297 -0
  434. package/dist/core-runtime/scope-runtime/reducer.test.js +759 -0
  435. package/dist/core-runtime/scope-runtime/scope-manager.js +161 -0
  436. package/dist/core-runtime/scope-runtime/state-machine.js +309 -0
  437. package/dist/core-runtime/scope-runtime/state-machine.test.js +704 -0
  438. package/dist/core-runtime/scope-runtime/types.js +116 -0
  439. package/dist/core-runtime/scope-runtime/types.test.js +69 -0
  440. package/dist/core-runtime/target-material-kind.js +256 -0
  441. package/dist/core-runtime/translate/render-for-user.js +169 -0
  442. package/dist/core-runtime/translate/render-for-user.test.js +122 -0
  443. package/dist/mcp/server.js +1011 -0
  444. package/dist/mcp/tool-schemas.js +93 -0
  445. package/dist/providers/capability-contract.js +1 -0
  446. package/package.json +68 -0
  447. package/settings.example.json +33 -0
@@ -0,0 +1,251 @@
1
+ import { readYamlDocument, } from "./review-artifact-utils.js";
2
+ import { REVIEW_SEVERITY_ORDER, isReviewFindingSeverity, isMaterialSeverity, } from "./review-result-classification.js";
3
+ const REVIEW_RECORD_STATUS_VALUES = new Set([
4
+ "completed",
5
+ "completed_with_degradation",
6
+ "halted_partial",
7
+ ]);
8
+ const SHARED_PHENOMENON_RELATION_VALUES = new Set([
9
+ "corroboration",
10
+ "disagreement",
11
+ "partial overlap",
12
+ "dedup",
13
+ ]);
14
+ const ACTION_CANDIDATE_VALUES = new Set([
15
+ "fix_now",
16
+ "fix_before_release",
17
+ "accept_risk",
18
+ "follow_up",
19
+ "out_of_scope",
20
+ "needs_evidence",
21
+ "continue_review",
22
+ "retry_execution",
23
+ ]);
24
+ function requireRecord(value, label) {
25
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
26
+ throw new Error(`${label} must be a YAML mapping.`);
27
+ }
28
+ return value;
29
+ }
30
+ function requireString(value, label) {
31
+ if (typeof value !== "string" || value.trim().length === 0) {
32
+ throw new Error(`${label} must be a non-empty string.`);
33
+ }
34
+ return value;
35
+ }
36
+ function requireNullableString(value, label) {
37
+ if (value === null)
38
+ return null;
39
+ return requireString(value, label);
40
+ }
41
+ function requireNumber(value, label) {
42
+ if (typeof value !== "number" || !Number.isFinite(value)) {
43
+ throw new Error(`${label} must be a finite number.`);
44
+ }
45
+ return value;
46
+ }
47
+ function requireInteger(value, label) {
48
+ const number = requireNumber(value, label);
49
+ if (!Number.isInteger(number)) {
50
+ throw new Error(`${label} must be an integer.`);
51
+ }
52
+ return number;
53
+ }
54
+ function requireArray(value, label) {
55
+ if (!Array.isArray(value)) {
56
+ throw new Error(`${label} must be a YAML list.`);
57
+ }
58
+ return value;
59
+ }
60
+ function requireStringArray(value, label) {
61
+ return requireArray(value, label).map((item, index) => requireString(item, `${label}[${index}]`));
62
+ }
63
+ function requireAllowed(value, allowed, label) {
64
+ const text = requireString(value, label);
65
+ if (!allowed.has(text)) {
66
+ throw new Error(`${label} has unsupported value: ${text}. Allowed values: ${[
67
+ ...allowed,
68
+ ].join(", ")}`);
69
+ }
70
+ return text;
71
+ }
72
+ function requireStringMap(value, label) {
73
+ const record = requireRecord(value, label);
74
+ const result = {};
75
+ for (const [key, item] of Object.entries(record)) {
76
+ result[key] = requireString(item, `${label}.${key}`);
77
+ }
78
+ return result;
79
+ }
80
+ function ensureUnique(values, label) {
81
+ const seen = new Set();
82
+ for (const value of values) {
83
+ if (seen.has(value)) {
84
+ throw new Error(`${label} contains duplicate value: ${value}`);
85
+ }
86
+ seen.add(value);
87
+ }
88
+ }
89
+ function validateProvenance(value, participatingLensIds) {
90
+ const provenance = requireRecord(value, "ReviewRecord.per_lens_provenance");
91
+ for (const lensId of participatingLensIds) {
92
+ const lensProvenance = requireRecord(provenance[lensId], `ReviewRecord.per_lens_provenance.${lensId}`);
93
+ if (lensProvenance.domain_constraints_used !== null) {
94
+ for (const [index, item] of requireArray(lensProvenance.domain_constraints_used, `ReviewRecord.per_lens_provenance.${lensId}.domain_constraints_used`).entries()) {
95
+ const constraint = requireRecord(item, `ReviewRecord.per_lens_provenance.${lensId}.domain_constraints_used[${index}]`);
96
+ requireString(constraint.source_doc, `ReviewRecord.per_lens_provenance.${lensId}.domain_constraints_used[${index}].source_doc`);
97
+ requireString(constraint.source_version_or_snapshot_id, `ReviewRecord.per_lens_provenance.${lensId}.domain_constraints_used[${index}].source_version_or_snapshot_id`);
98
+ requireString(constraint.anchor, `ReviewRecord.per_lens_provenance.${lensId}.domain_constraints_used[${index}].anchor`);
99
+ }
100
+ }
101
+ if (lensProvenance.domain_context_assumptions !== null) {
102
+ requireStringArray(lensProvenance.domain_context_assumptions, `ReviewRecord.per_lens_provenance.${lensId}.domain_context_assumptions`);
103
+ }
104
+ }
105
+ }
106
+ function validateIssueProjection(value, label) {
107
+ const projection = requireRecord(value, label);
108
+ requireString(projection.issue_id, `${label}.issue_id`);
109
+ const severity = requireAllowed(projection.severity, new Set(REVIEW_SEVERITY_ORDER), `${label}.severity`);
110
+ if (projection.material !== isMaterialSeverity(severity)) {
111
+ throw new Error(`${label}.material must match severity-derived materiality.`);
112
+ }
113
+ requireString(projection.affected_purpose, `${label}.affected_purpose`);
114
+ requireString(projection.failure_condition, `${label}.failure_condition`);
115
+ requireString(projection.impact, `${label}.impact`);
116
+ requireStringArray(projection.evidence_refs, `${label}.evidence_refs`);
117
+ requireStringArray(projection.source_lens_ids, `${label}.source_lens_ids`);
118
+ for (const [index, candidate] of requireStringArray(projection.action_candidates, `${label}.action_candidates`).entries()) {
119
+ requireAllowed(candidate, ACTION_CANDIDATE_VALUES, `${label}.action_candidates[${index}]`);
120
+ }
121
+ requireString(projection.rationale, `${label}.rationale`);
122
+ }
123
+ function validateClassificationSummary(value) {
124
+ if (value === null || value === undefined)
125
+ return;
126
+ const summary = requireRecord(value, "ReviewRecord.result_classification_summary");
127
+ if (summary.highest_severity !== null &&
128
+ !isReviewFindingSeverity(summary.highest_severity)) {
129
+ throw new Error("ReviewRecord.result_classification_summary.highest_severity must be a known severity or null.");
130
+ }
131
+ requireInteger(summary.finding_count, "ReviewRecord.result_classification_summary.finding_count");
132
+ requireInteger(summary.issue_count, "ReviewRecord.result_classification_summary.issue_count");
133
+ for (const countField of [
134
+ "finding_severity_counts",
135
+ "issue_severity_counts",
136
+ "severity_counts",
137
+ ]) {
138
+ const counts = requireRecord(summary[countField], `ReviewRecord.result_classification_summary.${countField}`);
139
+ for (const severity of REVIEW_SEVERITY_ORDER) {
140
+ requireInteger(counts[severity], `ReviewRecord.result_classification_summary.${countField}.${severity}`);
141
+ }
142
+ }
143
+ requireInteger(summary.material_issue_count, "ReviewRecord.result_classification_summary.material_issue_count");
144
+ requireInteger(summary.non_material_finding_count, "ReviewRecord.result_classification_summary.non_material_finding_count");
145
+ for (const [index, item] of requireArray(summary.material_issues, "ReviewRecord.result_classification_summary.material_issues").entries()) {
146
+ validateIssueProjection(item, `ReviewRecord.result_classification_summary.material_issues[${index}]`);
147
+ }
148
+ for (const [index, item] of requireArray(summary.non_material_findings, "ReviewRecord.result_classification_summary.non_material_findings").entries()) {
149
+ validateIssueProjection(item, `ReviewRecord.result_classification_summary.non_material_findings[${index}]`);
150
+ }
151
+ for (const [index, item] of requireArray(summary.action_candidates, "ReviewRecord.result_classification_summary.action_candidates").entries()) {
152
+ const action = requireRecord(item, `ReviewRecord.result_classification_summary.action_candidates[${index}]`);
153
+ requireString(action.issue_id, `ReviewRecord.result_classification_summary.action_candidates[${index}].issue_id`);
154
+ for (const [candidateIndex, candidate] of requireStringArray(action.candidates, `ReviewRecord.result_classification_summary.action_candidates[${index}].candidates`).entries()) {
155
+ requireAllowed(candidate, ACTION_CANDIDATE_VALUES, `ReviewRecord.result_classification_summary.action_candidates[${index}].candidates[${candidateIndex}]`);
156
+ }
157
+ requireStringArray(action.derivation_refs, `ReviewRecord.result_classification_summary.action_candidates[${index}].derivation_refs`);
158
+ requireString(action.rationale, `ReviewRecord.result_classification_summary.action_candidates[${index}].rationale`);
159
+ }
160
+ }
161
+ function validateSharedPhenomenonSummary(value) {
162
+ for (const [index, item] of requireArray(value, "ReviewRecord.shared_phenomenon_summary").entries()) {
163
+ const entry = requireRecord(item, `ReviewRecord.shared_phenomenon_summary[${index}]`);
164
+ requireString(entry.target, `ReviewRecord.shared_phenomenon_summary[${index}].target`);
165
+ requireString(entry.evidence_anchor, `ReviewRecord.shared_phenomenon_summary[${index}].evidence_anchor`);
166
+ requireStringArray(entry.participating_lens_ids, `ReviewRecord.shared_phenomenon_summary[${index}].participating_lens_ids`);
167
+ requireAllowed(entry.claim_relation, SHARED_PHENOMENON_RELATION_VALUES, `ReviewRecord.shared_phenomenon_summary[${index}].claim_relation`);
168
+ }
169
+ }
170
+ export function validateReviewRecordObject(value) {
171
+ const record = requireRecord(value, "ReviewRecord");
172
+ requireString(record.review_record_id, "ReviewRecord.review_record_id");
173
+ requireString(record.session_id, "ReviewRecord.session_id");
174
+ if (record.entrypoint !== "review") {
175
+ throw new Error("ReviewRecord.entrypoint must be review.");
176
+ }
177
+ const recordStatus = requireAllowed(record.record_status, REVIEW_RECORD_STATUS_VALUES, "ReviewRecord.record_status");
178
+ requireString(record.created_at, "ReviewRecord.created_at");
179
+ requireString(record.updated_at, "ReviewRecord.updated_at");
180
+ requireString(record.request_text, "ReviewRecord.request_text");
181
+ requireString(record.review_target_scope_ref, "ReviewRecord.review_target_scope_ref");
182
+ requireString(record.interpretation_ref, "ReviewRecord.interpretation_ref");
183
+ requireString(record.binding_ref, "ReviewRecord.binding_ref");
184
+ requireString(record.domain_final_selection_ref, "ReviewRecord.domain_final_selection_ref");
185
+ const resolvedLensIds = requireStringArray(record.resolved_lens_ids, "ReviewRecord.resolved_lens_ids");
186
+ ensureUnique(resolvedLensIds, "ReviewRecord.resolved_lens_ids");
187
+ requireString(record.execution_result_ref, "ReviewRecord.execution_result_ref");
188
+ requireString(record.session_metadata_ref, "ReviewRecord.session_metadata_ref");
189
+ requireString(record.target_snapshot_ref, "ReviewRecord.target_snapshot_ref");
190
+ requireString(record.materialized_input_ref, "ReviewRecord.materialized_input_ref");
191
+ requireString(record.review_target_profile_ref, "ReviewRecord.review_target_profile_ref");
192
+ requireString(record.context_candidate_assembly_ref, "ReviewRecord.context_candidate_assembly_ref");
193
+ const lensResultRefs = requireStringMap(record.lens_result_refs, "ReviewRecord.lens_result_refs");
194
+ const lensOutputSchemaVersion = requireInteger(record.lens_output_schema_version, "ReviewRecord.lens_output_schema_version");
195
+ if (lensOutputSchemaVersion < 1) {
196
+ throw new Error("ReviewRecord.lens_output_schema_version must be >= 1.");
197
+ }
198
+ const participatingLensIds = requireStringArray(record.participating_lens_ids, "ReviewRecord.participating_lens_ids");
199
+ ensureUnique(participatingLensIds, "ReviewRecord.participating_lens_ids");
200
+ requireStringArray(record.excluded_lens_ids, "ReviewRecord.excluded_lens_ids");
201
+ requireStringArray(record.degraded_lens_ids, "ReviewRecord.degraded_lens_ids");
202
+ for (const lensId of participatingLensIds) {
203
+ if (!lensResultRefs[lensId]) {
204
+ throw new Error(`ReviewRecord.lens_result_refs missing participating lens: ${lensId}`);
205
+ }
206
+ }
207
+ validateProvenance(record.per_lens_provenance, participatingLensIds);
208
+ if (record.degradation_notes_ref !== undefined) {
209
+ requireNullableString(record.degradation_notes_ref, "ReviewRecord.degradation_notes_ref");
210
+ }
211
+ for (const fieldName of [
212
+ "finding_ledger_ref",
213
+ "finding_relation_graph_ref",
214
+ "issue_ledger_ref",
215
+ "issue_stance_matrix_ref",
216
+ "deliberation_plan_ref",
217
+ "problem_framing_ref",
218
+ ]) {
219
+ if (record[fieldName] !== undefined) {
220
+ requireNullableString(record[fieldName], `ReviewRecord.${fieldName}`);
221
+ }
222
+ }
223
+ if (record.issue_resolution_summary !== undefined) {
224
+ requireArray(record.issue_resolution_summary, "ReviewRecord.issue_resolution_summary");
225
+ }
226
+ validateClassificationSummary(record.result_classification_summary);
227
+ requireNullableString(record.synthesis_result_ref, "ReviewRecord.synthesis_result_ref");
228
+ requireAllowed(record.deliberation_status, new Set(["performed", "not_performed"]), "ReviewRecord.deliberation_status");
229
+ requireNullableString(record.deliberation_result_ref, "ReviewRecord.deliberation_result_ref");
230
+ requireString(record.final_output_ref, "ReviewRecord.final_output_ref");
231
+ validateSharedPhenomenonSummary(record.shared_phenomenon_summary);
232
+ if (recordStatus === "completed") {
233
+ requireString(record.synthesis_result_ref, "ReviewRecord.synthesis_result_ref for completed records");
234
+ requireString(record.deliberation_result_ref, "ReviewRecord.deliberation_result_ref for completed records");
235
+ if (record.deliberation_status !== "performed") {
236
+ throw new Error("Completed ReviewRecord must declare deliberation_status=performed.");
237
+ }
238
+ }
239
+ if (record.deliberation_status === "not_performed") {
240
+ if (record.deliberation_result_ref !== null) {
241
+ throw new Error("ReviewRecord.deliberation_result_ref must be null when deliberation_status=not_performed.");
242
+ }
243
+ if (record.synthesis_result_ref !== null) {
244
+ throw new Error("ReviewRecord.synthesis_result_ref must be null when deliberation_status=not_performed.");
245
+ }
246
+ }
247
+ return record;
248
+ }
249
+ export async function readValidatedReviewRecord(filePath) {
250
+ return validateReviewRecordObject(await readYamlDocument(filePath));
251
+ }
@@ -0,0 +1,379 @@
1
+ import path from "node:path";
2
+ import { fileExists, readYamlDocument, } from "./review-artifact-utils.js";
3
+ export const REVIEW_SEVERITY_ORDER = [
4
+ "blocker",
5
+ "high",
6
+ "medium",
7
+ "low",
8
+ "info",
9
+ ];
10
+ const REVIEW_SEVERITY_VALUES = new Set(REVIEW_SEVERITY_ORDER);
11
+ const MATERIAL_SEVERITIES = new Set([
12
+ "blocker",
13
+ "high",
14
+ "medium",
15
+ ]);
16
+ export function isReviewFindingSeverity(value) {
17
+ return typeof value === "string" && REVIEW_SEVERITY_VALUES.has(value);
18
+ }
19
+ export function normalizeReviewFindingSeverity(value) {
20
+ if (isReviewFindingSeverity(value))
21
+ return value;
22
+ if (value === "critical")
23
+ return "blocker";
24
+ return "info";
25
+ }
26
+ export function isMaterialSeverity(severity) {
27
+ return MATERIAL_SEVERITIES.has(severity);
28
+ }
29
+ export function emptyReviewSeverityCounts() {
30
+ return {
31
+ blocker: 0,
32
+ high: 0,
33
+ medium: 0,
34
+ low: 0,
35
+ info: 0,
36
+ };
37
+ }
38
+ function incrementSeverityCount(counts, severity) {
39
+ counts[severity] += 1;
40
+ }
41
+ function records(value) {
42
+ if (!Array.isArray(value))
43
+ return [];
44
+ return value.filter((item) => item !== null && typeof item === "object" && !Array.isArray(item));
45
+ }
46
+ function stringValue(value, fallback = "") {
47
+ return typeof value === "string" && value.trim().length > 0
48
+ ? value.trim()
49
+ : fallback;
50
+ }
51
+ function nullableStringValue(value) {
52
+ return typeof value === "string" && value.trim().length > 0
53
+ ? value.trim()
54
+ : null;
55
+ }
56
+ function stringArray(value) {
57
+ if (!Array.isArray(value))
58
+ return [];
59
+ return value
60
+ .filter((item) => typeof item === "string")
61
+ .map((item) => item.trim())
62
+ .filter((item) => item.length > 0);
63
+ }
64
+ function unique(values) {
65
+ return [...new Set(values)];
66
+ }
67
+ async function readOptionalYaml(filePath) {
68
+ if (!(await fileExists(filePath)))
69
+ return null;
70
+ return readYamlDocument(filePath);
71
+ }
72
+ function buildFindingEvidenceRefs(finding) {
73
+ const directRefs = stringArray(finding.evidence_refs);
74
+ if (directRefs.length > 0)
75
+ return unique(directRefs);
76
+ const refs = [
77
+ stringValue(finding.source_ref),
78
+ stringValue(finding.evidence_anchor),
79
+ ].filter((ref) => ref.length > 0);
80
+ return unique(refs);
81
+ }
82
+ function candidateFallbackForSeverity(severity) {
83
+ switch (severity) {
84
+ case "blocker":
85
+ return ["fix_now"];
86
+ case "high":
87
+ return ["fix_before_release"];
88
+ case "medium":
89
+ return ["accept_risk", "follow_up"];
90
+ case "low":
91
+ return ["follow_up"];
92
+ case "info":
93
+ return ["needs_evidence"];
94
+ }
95
+ }
96
+ function pushCandidate(candidates, candidate) {
97
+ if (!candidates.includes(candidate))
98
+ candidates.push(candidate);
99
+ }
100
+ function deriveActionCandidates(args) {
101
+ const candidates = [];
102
+ const classification = args.classification;
103
+ switch (classification?.timing_class) {
104
+ case "current_blocker":
105
+ pushCandidate(candidates, "fix_now");
106
+ break;
107
+ case "next_step_blocker":
108
+ pushCandidate(candidates, "fix_before_release");
109
+ break;
110
+ case "planned_follow_up":
111
+ case "defer_watch":
112
+ pushCandidate(candidates, "follow_up");
113
+ break;
114
+ }
115
+ switch (classification?.closure_class) {
116
+ case "fix_now":
117
+ pushCandidate(candidates, "fix_now");
118
+ break;
119
+ case "needs_decision":
120
+ pushCandidate(candidates, "accept_risk");
121
+ break;
122
+ case "needs_evidence":
123
+ pushCandidate(candidates, "needs_evidence");
124
+ break;
125
+ case "carry_forward":
126
+ case "document_only":
127
+ case "watch":
128
+ pushCandidate(candidates, "follow_up");
129
+ break;
130
+ }
131
+ switch (classification?.closure_obligation) {
132
+ case "must_close_in_target":
133
+ pushCandidate(candidates, "fix_now");
134
+ break;
135
+ case "must_close_before_next_stage":
136
+ pushCandidate(candidates, "fix_before_release");
137
+ break;
138
+ case "may_close_during_next_stage":
139
+ case "planned_later":
140
+ pushCandidate(candidates, "follow_up");
141
+ break;
142
+ case "out_of_scope":
143
+ pushCandidate(candidates, "out_of_scope");
144
+ break;
145
+ }
146
+ switch (classification?.judgment_state) {
147
+ case "insufficient_evidence":
148
+ pushCandidate(candidates, "needs_evidence");
149
+ break;
150
+ case "outside_boundary":
151
+ pushCandidate(candidates, "out_of_scope");
152
+ break;
153
+ }
154
+ if (candidates.length > 0)
155
+ return candidates;
156
+ if (args.hasProblemFraming)
157
+ return ["follow_up"];
158
+ return candidateFallbackForSeverity(args.severity);
159
+ }
160
+ function actionRationale(args) {
161
+ const classificationRationale = stringValue(args.classification?.rationale);
162
+ if (classificationRationale.length > 0)
163
+ return classificationRationale;
164
+ if (args.hasProblemFraming) {
165
+ return "Problem framing is present but does not provide a more specific action rationale.";
166
+ }
167
+ if (args.issueStatement.length > 0)
168
+ return args.issueStatement;
169
+ return `Action candidates are derived from severity=${args.severity} because problem framing is unavailable.`;
170
+ }
171
+ function classificationMap(problemFraming) {
172
+ const map = new Map();
173
+ for (const classification of records(problemFraming?.classifications)) {
174
+ const issueId = stringValue(classification.issue_id);
175
+ if (issueId.length > 0)
176
+ map.set(issueId, classification);
177
+ }
178
+ return map;
179
+ }
180
+ function findingMap(findings) {
181
+ const map = new Map();
182
+ for (const finding of findings) {
183
+ const findingId = stringValue(finding.finding_id);
184
+ if (findingId.length > 0)
185
+ map.set(findingId, finding);
186
+ }
187
+ return map;
188
+ }
189
+ function evidenceRefsForIssue(issue, findingsById) {
190
+ const directRefs = stringArray(issue.evidence_refs);
191
+ if (directRefs.length > 0)
192
+ return unique(directRefs);
193
+ const refs = [];
194
+ for (const findingId of stringArray(issue.surface_finding_ids)) {
195
+ const finding = findingsById.get(findingId);
196
+ if (!finding)
197
+ continue;
198
+ refs.push(...buildFindingEvidenceRefs(finding));
199
+ }
200
+ return unique(refs);
201
+ }
202
+ function sourceLensIdsForIssue(issue, findingsById) {
203
+ const direct = stringArray(issue.raised_by_lens_ids);
204
+ if (direct.length > 0)
205
+ return unique(direct);
206
+ const lensIds = [];
207
+ for (const findingId of stringArray(issue.surface_finding_ids)) {
208
+ const lensId = stringValue(findingsById.get(findingId)?.lens_id);
209
+ if (lensId.length > 0)
210
+ lensIds.push(lensId);
211
+ }
212
+ return unique(lensIds);
213
+ }
214
+ function severityCountsFor(recordsToCount) {
215
+ const counts = emptyReviewSeverityCounts();
216
+ for (const record of recordsToCount) {
217
+ incrementSeverityCount(counts, normalizeReviewFindingSeverity(record.severity));
218
+ }
219
+ return counts;
220
+ }
221
+ function highestSeverity(counts) {
222
+ return REVIEW_SEVERITY_ORDER.find((severity) => counts[severity] > 0) ?? null;
223
+ }
224
+ function sortBySeverityAndId(projections) {
225
+ return [...projections].sort((left, right) => {
226
+ const severityDelta = REVIEW_SEVERITY_ORDER.indexOf(left.severity) -
227
+ REVIEW_SEVERITY_ORDER.indexOf(right.severity);
228
+ if (severityDelta !== 0)
229
+ return severityDelta;
230
+ return left.issue_id.localeCompare(right.issue_id);
231
+ });
232
+ }
233
+ function projectionFromIssue(args) {
234
+ const severity = normalizeReviewFindingSeverity(args.issue.severity);
235
+ const issueId = stringValue(args.issue.issue_id, "issue-unknown");
236
+ const issueStatement = stringValue(args.issue.issue_statement);
237
+ const affectedPurpose = stringValue(args.issue.affected_purpose, stringValue(args.classification?.problem_definition, "declared review purpose"));
238
+ const failureCondition = stringValue(args.issue.failure_condition, stringValue(args.issue.root_cause_hypothesis, issueStatement));
239
+ const impact = stringValue(args.issue.impact, stringValue(args.classification?.impact_kind, issueStatement));
240
+ const actionCandidates = deriveActionCandidates({
241
+ severity,
242
+ classification: args.classification,
243
+ hasProblemFraming: args.hasProblemFraming,
244
+ });
245
+ const projection = {
246
+ issue_id: issueId,
247
+ severity,
248
+ material: isMaterialSeverity(severity),
249
+ affected_purpose: affectedPurpose,
250
+ failure_condition: failureCondition,
251
+ impact,
252
+ evidence_refs: evidenceRefsForIssue(args.issue, args.findingsById),
253
+ source_lens_ids: sourceLensIdsForIssue(args.issue, args.findingsById),
254
+ action_candidates: actionCandidates,
255
+ rationale: actionRationale({
256
+ classification: args.classification,
257
+ hasProblemFraming: args.hasProblemFraming,
258
+ severity,
259
+ issueStatement,
260
+ }),
261
+ };
262
+ const domainThresholdUsed = nullableStringValue(args.issue.domain_threshold_used);
263
+ if (domainThresholdUsed !== null)
264
+ projection.domain_threshold_used = domainThresholdUsed;
265
+ const problemDefinition = stringValue(args.classification?.problem_definition);
266
+ if (problemDefinition.length > 0)
267
+ projection.problem_definition = problemDefinition;
268
+ if (issueStatement.length > 0)
269
+ projection.issue_statement = issueStatement;
270
+ const timingClass = stringValue(args.classification?.timing_class);
271
+ if (timingClass.length > 0)
272
+ projection.timing_class = timingClass;
273
+ const closureClass = stringValue(args.classification?.closure_class);
274
+ if (closureClass.length > 0)
275
+ projection.closure_class = closureClass;
276
+ const closureObligation = stringValue(args.classification?.closure_obligation);
277
+ if (closureObligation.length > 0)
278
+ projection.closure_obligation = closureObligation;
279
+ const judgmentState = stringValue(args.classification?.judgment_state);
280
+ if (judgmentState.length > 0)
281
+ projection.judgment_state = judgmentState;
282
+ return projection;
283
+ }
284
+ function projectionFromFinding(finding) {
285
+ const severity = normalizeReviewFindingSeverity(finding.severity);
286
+ const findingId = stringValue(finding.finding_id, "finding-unknown");
287
+ const claim = stringValue(finding.claim);
288
+ const projection = {
289
+ issue_id: `finding:${findingId}`,
290
+ severity,
291
+ material: isMaterialSeverity(severity),
292
+ affected_purpose: stringValue(finding.affected_purpose, "declared review purpose"),
293
+ failure_condition: stringValue(finding.failure_condition, claim),
294
+ impact: stringValue(finding.impact, claim.length > 0
295
+ ? claim
296
+ : "Finding has not yet been clustered into a root-cause issue."),
297
+ evidence_refs: buildFindingEvidenceRefs(finding),
298
+ source_lens_ids: stringValue(finding.lens_id).length > 0
299
+ ? [stringValue(finding.lens_id)]
300
+ : [],
301
+ action_candidates: ["continue_review"],
302
+ rationale: "Finding-level projection is available before root-cause issue classification.",
303
+ };
304
+ const domainThresholdUsed = nullableStringValue(finding.domain_threshold_used);
305
+ if (domainThresholdUsed !== null)
306
+ projection.domain_threshold_used = domainThresholdUsed;
307
+ if (claim.length > 0)
308
+ projection.issue_statement = claim;
309
+ return projection;
310
+ }
311
+ function buildActionCandidateProjection(projection, hasProblemFraming) {
312
+ const refs = projection.issue_id.startsWith("finding:")
313
+ ? ["finding-ledger.yaml"]
314
+ : [
315
+ "issue-ledger.yaml",
316
+ ...(hasProblemFraming ? ["problem-framing.yaml"] : []),
317
+ ];
318
+ return {
319
+ issue_id: projection.issue_id,
320
+ candidates: projection.action_candidates,
321
+ derivation_refs: refs,
322
+ rationale: projection.rationale,
323
+ };
324
+ }
325
+ function runtimeHaltActionCandidate(executionResult) {
326
+ if (executionResult?.execution_status !== "halted_partial")
327
+ return null;
328
+ return {
329
+ issue_id: "runtime-halt",
330
+ candidates: ["retry_execution", "continue_review"],
331
+ derivation_refs: ["execution-result.yaml"],
332
+ rationale: executionResult.halt_reason ?? "Review execution halted before completion.",
333
+ };
334
+ }
335
+ export async function readReviewResultClassification(sessionRoot) {
336
+ const findingLedger = await readOptionalYaml(path.join(sessionRoot, "finding-ledger.yaml"));
337
+ const issueLedger = await readOptionalYaml(path.join(sessionRoot, "issue-ledger.yaml"));
338
+ const problemFraming = await readOptionalYaml(path.join(sessionRoot, "problem-framing.yaml"));
339
+ const executionResult = await readOptionalYaml(path.join(sessionRoot, "execution-result.yaml"));
340
+ const findings = records(findingLedger?.findings);
341
+ const issues = records(issueLedger?.issues);
342
+ const findingsById = findingMap(findings);
343
+ const classificationsByIssueId = classificationMap(problemFraming);
344
+ const hasProblemFraming = problemFraming !== null;
345
+ const findingSeverityCounts = severityCountsFor(findings);
346
+ const issueSeverityCounts = severityCountsFor(issues);
347
+ const projectionSourceIsIssueLedger = issues.length > 0;
348
+ const severityCounts = projectionSourceIsIssueLedger
349
+ ? issueSeverityCounts
350
+ : findingSeverityCounts;
351
+ const projections = projectionSourceIsIssueLedger
352
+ ? issues.map((issue) => projectionFromIssue({
353
+ issue,
354
+ findingsById,
355
+ classification: classificationsByIssueId.get(stringValue(issue.issue_id)) ?? null,
356
+ hasProblemFraming,
357
+ }))
358
+ : findings.map(projectionFromFinding);
359
+ const sortedProjections = sortBySeverityAndId(projections);
360
+ const materialIssues = sortedProjections.filter((projection) => projection.material);
361
+ const nonMaterialFindings = sortedProjections.filter((projection) => !projection.material);
362
+ const actionCandidates = sortedProjections.map((projection) => buildActionCandidateProjection(projection, hasProblemFraming));
363
+ const haltActionCandidate = runtimeHaltActionCandidate(executionResult);
364
+ if (haltActionCandidate)
365
+ actionCandidates.push(haltActionCandidate);
366
+ return {
367
+ highest_severity: highestSeverity(severityCounts),
368
+ finding_count: findings.length,
369
+ issue_count: issues.length,
370
+ finding_severity_counts: findingSeverityCounts,
371
+ issue_severity_counts: issueSeverityCounts,
372
+ severity_counts: severityCounts,
373
+ material_issue_count: materialIssues.length,
374
+ non_material_finding_count: nonMaterialFindings.length,
375
+ material_issues: materialIssues,
376
+ non_material_findings: nonMaterialFindings,
377
+ action_candidates: actionCandidates,
378
+ };
379
+ }
@@ -0,0 +1,39 @@
1
+ export const REVIEW_STATES = [
2
+ "preparing",
3
+ "awaiting_lens_dispatch",
4
+ "validating_lenses",
5
+ "awaiting_adjudication",
6
+ "awaiting_synthesize_dispatch",
7
+ "awaiting_deliberation",
8
+ "completing",
9
+ "completed",
10
+ "halted_partial",
11
+ "failed",
12
+ ];
13
+ export const REVIEW_TERMINAL_STATES = new Set([
14
+ "completed",
15
+ "halted_partial",
16
+ "failed",
17
+ ]);
18
+ export const REVIEW_TRANSITIONS = {
19
+ "(init)": ["preparing"],
20
+ preparing: ["awaiting_lens_dispatch", "failed"],
21
+ awaiting_lens_dispatch: ["validating_lenses"],
22
+ validating_lenses: [
23
+ "awaiting_adjudication",
24
+ "awaiting_deliberation",
25
+ "halted_partial",
26
+ "failed",
27
+ ],
28
+ awaiting_adjudication: ["awaiting_deliberation", "failed"],
29
+ awaiting_deliberation: ["awaiting_synthesize_dispatch", "failed"],
30
+ awaiting_synthesize_dispatch: ["completing"],
31
+ completing: ["completed", "failed"],
32
+ completed: [],
33
+ halted_partial: [],
34
+ failed: [],
35
+ };
36
+ export function canReviewTransition(from, to) {
37
+ const allowed = REVIEW_TRANSITIONS[from];
38
+ return allowed != null && allowed.includes(to);
39
+ }