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,150 @@
1
+ import { sourceKey } from "./types.js";
2
+ /**
3
+ * Build BrownfieldContext + BrownfieldDetail from scan results.
4
+ *
5
+ * Pure function: no I/O, no side effects.
6
+ *
7
+ * BrownfieldContext contains Tier 1+2 items (for Build Spec Section 7).
8
+ * BrownfieldDetail contains Tier 3 (full scan results with anchors).
9
+ * detail_anchor links Tier 1+2 items to their Tier 3 detail sections.
10
+ */
11
+ export function buildBrownfield(scopeId, scanResults) {
12
+ const related_files = [];
13
+ const module_dependencies = [];
14
+ const api_contracts = [];
15
+ const db_schemas = [];
16
+ const config_env = [];
17
+ const sections = [];
18
+ for (const result of scanResults) {
19
+ const srcKey = sourceKey(result.source);
20
+ const srcLabel = result.source.description ?? srcKey;
21
+ // ── Files → related_files ──
22
+ for (const file of result.files) {
23
+ if (file.category === "source" || file.category === "config" || file.category === "schema" || file.category === "test") {
24
+ const anchor = makeAnchor(srcKey, file.path);
25
+ related_files.push({
26
+ path: file.path,
27
+ role: file.category === "test"
28
+ ? `test (${srcLabel})`
29
+ : `${file.language ?? file.category} (${srcLabel})`,
30
+ detail_anchor: anchor,
31
+ });
32
+ sections.push({
33
+ anchor,
34
+ source: srcLabel,
35
+ title: file.path,
36
+ content: `- 카테고리: ${file.category}\n- 언어: ${file.language ?? "N/A"}\n- 크기: ${file.size_bytes} bytes`,
37
+ });
38
+ }
39
+ }
40
+ // ── Dependency graph → module_dependencies ──
41
+ const seenDeps = new Set();
42
+ for (const edge of result.dependency_graph) {
43
+ const depKey = `${edge.from}→${edge.to}`;
44
+ if (seenDeps.has(depKey))
45
+ continue;
46
+ seenDeps.add(depKey);
47
+ const anchor = makeAnchor(srcKey, `dep-${edge.from}-${edge.to}`);
48
+ module_dependencies.push({
49
+ module: edge.from,
50
+ depends_on: edge.to,
51
+ detail_anchor: anchor,
52
+ });
53
+ sections.push({
54
+ anchor,
55
+ source: srcLabel,
56
+ title: `${edge.from} → ${edge.to}`,
57
+ content: `- 종류: ${edge.kind}\n- 출처 파일: ${edge.from}`,
58
+ });
59
+ }
60
+ // ── API patterns → api_contracts ──
61
+ for (const api of result.api_patterns) {
62
+ const anchor = makeAnchor(srcKey, `api-${api.method}-${api.path}-${api.file}-L${api.line}`);
63
+ api_contracts.push({
64
+ endpoint: api.path,
65
+ method: api.method,
66
+ description: `${api.file}:${api.line}`,
67
+ detail_anchor: anchor,
68
+ });
69
+ sections.push({
70
+ anchor,
71
+ source: srcLabel,
72
+ title: `${api.method} ${api.path}`,
73
+ content: `- 파일: ${api.file}\n- 라인: ${api.line}`,
74
+ });
75
+ }
76
+ // ── Schema patterns → db_schemas ──
77
+ for (const schema of result.schema_patterns) {
78
+ const anchor = makeAnchor(srcKey, `schema-${schema.table}-${schema.file}-L${schema.line}`);
79
+ db_schemas.push({
80
+ table: schema.table,
81
+ columns: schema.columns,
82
+ detail_anchor: anchor,
83
+ });
84
+ sections.push({
85
+ anchor,
86
+ source: srcLabel,
87
+ title: schema.table,
88
+ content: `- 파일: ${schema.file}\n- 라인: ${schema.line}\n- 컬럼: ${schema.columns}`,
89
+ });
90
+ }
91
+ // ── Config patterns → config_env ──
92
+ for (const cfg of result.config_patterns) {
93
+ const anchor = makeAnchor(srcKey, `config-${cfg.key}-${cfg.file}-L${cfg.line}`);
94
+ config_env.push({
95
+ key: cfg.key,
96
+ description: `${cfg.source_type} (${cfg.file}:${cfg.line})`,
97
+ detail_anchor: anchor,
98
+ });
99
+ sections.push({
100
+ anchor,
101
+ source: srcLabel,
102
+ title: cfg.key,
103
+ content: `- 타입: ${cfg.source_type}\n- 파일: ${cfg.file}\n- 라인: ${cfg.line}`,
104
+ });
105
+ }
106
+ // ── Doc structures → detail sections only (no BrownfieldContext field) ──
107
+ for (const doc of result.doc_structure) {
108
+ const anchor = makeAnchor(srcKey, `doc-${doc.file}`);
109
+ const parts = [`- 형식: ${doc.format}`];
110
+ if (doc.headings)
111
+ parts.push(`- 제목: ${doc.headings.join(", ")}`);
112
+ if (doc.top_level_keys)
113
+ parts.push(`- 키: ${doc.top_level_keys.join(", ")}`);
114
+ if (doc.item_counts) {
115
+ const counts = Object.entries(doc.item_counts).map(([k, v]) => `${k}: ${v}`).join(", ");
116
+ parts.push(`- 항목 수: ${counts}`);
117
+ }
118
+ sections.push({
119
+ anchor,
120
+ source: srcLabel,
121
+ title: doc.file,
122
+ content: parts.join("\n"),
123
+ });
124
+ }
125
+ }
126
+ return {
127
+ context: {
128
+ related_files,
129
+ module_dependencies,
130
+ api_contracts: api_contracts.length > 0 ? api_contracts : undefined,
131
+ db_schemas: db_schemas.length > 0 ? db_schemas : undefined,
132
+ config_env: config_env.length > 0 ? config_env : undefined,
133
+ },
134
+ detail: {
135
+ scope_id: scopeId,
136
+ sections,
137
+ },
138
+ };
139
+ }
140
+ // ─── Anchor generation ───
141
+ function makeAnchor(srcKey, suffix) {
142
+ return sanitizeAnchor(`${srcKey}-${suffix}`);
143
+ }
144
+ function sanitizeAnchor(raw) {
145
+ return raw
146
+ .toLowerCase()
147
+ .replace(/[^a-z0-9가-힣_-]/g, "-")
148
+ .replace(/-+/g, "-")
149
+ .replace(/^-|-$/g, "");
150
+ }
@@ -0,0 +1,136 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { buildBrownfield } from "./brownfield-builder.js";
3
+ function makeScanResult(overrides = {}) {
4
+ return {
5
+ source: { type: "add-dir", path: "/test" },
6
+ scanned_at: "2026-03-09T00:00:00Z",
7
+ files: [],
8
+ content_hashes: {},
9
+ dependency_graph: [],
10
+ api_patterns: [],
11
+ schema_patterns: [],
12
+ config_patterns: [],
13
+ doc_structure: [],
14
+ ...overrides,
15
+ };
16
+ }
17
+ describe("buildBrownfield", () => {
18
+ it("returns empty context and detail for empty scan results", () => {
19
+ const { context, detail } = buildBrownfield("SC-TEST", []);
20
+ expect(context.related_files).toEqual([]);
21
+ expect(context.module_dependencies).toEqual([]);
22
+ expect(detail.sections).toEqual([]);
23
+ expect(detail.scope_id).toBe("SC-TEST");
24
+ });
25
+ it("maps files to related_files with detail_anchor", () => {
26
+ const result = makeScanResult({
27
+ files: [
28
+ { path: "src/app.ts", category: "source", language: "typescript", size_bytes: 100 },
29
+ ],
30
+ });
31
+ const { context, detail } = buildBrownfield("SC-TEST", [result]);
32
+ expect(context.related_files).toHaveLength(1);
33
+ expect(context.related_files[0].path).toBe("src/app.ts");
34
+ expect(context.related_files[0].detail_anchor).toBeTruthy();
35
+ // detail has matching section
36
+ const anchor = context.related_files[0].detail_anchor;
37
+ expect(detail.sections.some(s => s.anchor === anchor)).toBe(true);
38
+ });
39
+ it("maps dependency_graph to module_dependencies", () => {
40
+ const result = makeScanResult({
41
+ dependency_graph: [
42
+ { from: "app.ts", to: "./utils", kind: "import" },
43
+ ],
44
+ });
45
+ const { context } = buildBrownfield("SC-TEST", [result]);
46
+ expect(context.module_dependencies).toHaveLength(1);
47
+ expect(context.module_dependencies[0].module).toBe("app.ts");
48
+ expect(context.module_dependencies[0].depends_on).toBe("./utils");
49
+ });
50
+ it("maps api_patterns to api_contracts", () => {
51
+ const result = makeScanResult({
52
+ api_patterns: [
53
+ { file: "Controller.java", method: "GET", path: "/api/users", line: 10 },
54
+ ],
55
+ });
56
+ const { context } = buildBrownfield("SC-TEST", [result]);
57
+ expect(context.api_contracts).toHaveLength(1);
58
+ expect(context.api_contracts[0].endpoint).toBe("/api/users");
59
+ });
60
+ it("maps schema_patterns to db_schemas", () => {
61
+ const result = makeScanResult({
62
+ schema_patterns: [
63
+ { file: "V1.sql", table: "users", columns: "id, name", line: 1 },
64
+ ],
65
+ });
66
+ const { context } = buildBrownfield("SC-TEST", [result]);
67
+ expect(context.db_schemas).toHaveLength(1);
68
+ expect(context.db_schemas[0].table).toBe("users");
69
+ });
70
+ it("maps config_patterns to config_env", () => {
71
+ const result = makeScanResult({
72
+ config_patterns: [
73
+ { file: ".env", key: "DB_URL", source_type: "dotenv", line: 1 },
74
+ ],
75
+ });
76
+ const { context } = buildBrownfield("SC-TEST", [result]);
77
+ expect(context.config_env).toHaveLength(1);
78
+ expect(context.config_env[0].key).toBe("DB_URL");
79
+ });
80
+ it("deduplicates dependency edges", () => {
81
+ const result = makeScanResult({
82
+ dependency_graph: [
83
+ { from: "a.ts", to: "b", kind: "import" },
84
+ { from: "a.ts", to: "b", kind: "import" },
85
+ ],
86
+ });
87
+ const { context } = buildBrownfield("SC-TEST", [result]);
88
+ expect(context.module_dependencies).toHaveLength(1);
89
+ });
90
+ it("merges multiple scan results", () => {
91
+ const r1 = makeScanResult({
92
+ source: { type: "add-dir", path: "/project1" },
93
+ files: [{ path: "a.ts", category: "source", language: "typescript", size_bytes: 50 }],
94
+ });
95
+ const r2 = makeScanResult({
96
+ source: { type: "add-dir", path: "/project2" },
97
+ files: [{ path: "b.java", category: "source", language: "java", size_bytes: 80 }],
98
+ });
99
+ const { context, detail } = buildBrownfield("SC-TEST", [r1, r2]);
100
+ expect(context.related_files).toHaveLength(2);
101
+ expect(detail.sections.length).toBeGreaterThanOrEqual(2);
102
+ });
103
+ it("generates sanitized anchors", () => {
104
+ const result = makeScanResult({
105
+ files: [{ path: "src/모듈/컴포넌트.tsx", category: "source", language: "typescript", size_bytes: 100 }],
106
+ });
107
+ const { context } = buildBrownfield("SC-TEST", [result]);
108
+ const anchor = context.related_files[0].detail_anchor;
109
+ // anchor should not contain special characters that break markdown links
110
+ expect(anchor).not.toMatch(/[<>[\]{}()|\\^`"']/);
111
+ });
112
+ it("omits optional fields when empty", () => {
113
+ const { context } = buildBrownfield("SC-TEST", [makeScanResult()]);
114
+ expect(context.api_contracts).toBeUndefined();
115
+ expect(context.db_schemas).toBeUndefined();
116
+ expect(context.config_env).toBeUndefined();
117
+ });
118
+ it("includes test category files in related_files with test role", () => {
119
+ const result = makeScanResult({
120
+ files: [
121
+ { path: "src/app.ts", category: "source", language: "typescript", size_bytes: 100 },
122
+ { path: "src/app.test.ts", category: "test", language: "typescript", size_bytes: 80 },
123
+ ],
124
+ });
125
+ const { context, detail } = buildBrownfield("SC-TEST", [result]);
126
+ expect(context.related_files).toHaveLength(2);
127
+ const testFile = context.related_files.find(f => f.path === "src/app.test.ts");
128
+ expect(testFile).toBeDefined();
129
+ expect(testFile.role).toMatch(/^test \(/);
130
+ expect(testFile.detail_anchor).toBeTruthy();
131
+ const sourceFile = context.related_files.find(f => f.path === "src/app.ts");
132
+ expect(sourceFile.role).not.toMatch(/^test \(/);
133
+ // detail section exists for the test file
134
+ expect(detail.sections.some(s => s.anchor === testFile.detail_anchor)).toBe(true);
135
+ });
136
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 6관점 통합 코드 청크 수집 오케스트레이션.
3
+ *
4
+ * viewpoint-collectors.ts의 6개 수집 함수를 호출하고,
5
+ * 결과를 RelevantCodeChunks 구조로 조합한다.
6
+ */
7
+ import { collectSemantics, collectDependency, collectLogic, collectStructure, collectPragmatics, collectEvolution, } from "./viewpoint-collectors.js";
8
+ // ─── Main ───
9
+ export function collectRelevantChunks(resolved, ontologyResult, scanResult, keywords, options) {
10
+ const defaultMax = options?.maxChunksPerViewpoint ?? 10;
11
+ function getMax(vp) {
12
+ const override = options?.viewpointOverrides?.[vp];
13
+ if (override?.enabled === false)
14
+ return 0;
15
+ return override?.maxChunks ?? defaultMax;
16
+ }
17
+ const by_viewpoint = {
18
+ semantics: collectSemantics(resolved, getMax("semantics")),
19
+ dependency: collectDependency(resolved, scanResult.dependency_graph, getMax("dependency")),
20
+ logic: collectLogic(ontologyResult, resolved, getMax("logic")),
21
+ structure: collectStructure(resolved, scanResult.files, scanResult.schema_patterns, scanResult.config_patterns, getMax("structure")),
22
+ pragmatics: collectPragmatics(ontologyResult.matched_entities, scanResult.api_patterns, resolved, getMax("pragmatics")),
23
+ evolution: collectEvolution(resolved, scanResult.files, scanResult.schema_patterns, getMax("evolution")),
24
+ };
25
+ // 중복 파일은 토큰 추정에서 1회만 카운트
26
+ const uniqueFiles = new Set();
27
+ let totalChunks = 0;
28
+ const viewpoint_counts = {};
29
+ for (const [vp, chunks] of Object.entries(by_viewpoint)) {
30
+ viewpoint_counts[vp] = chunks.length;
31
+ totalChunks += chunks.length;
32
+ for (const c of chunks) {
33
+ if (c.file_path)
34
+ uniqueFiles.add(c.file_path);
35
+ }
36
+ }
37
+ const unresolvedCount = resolved.filter((r) => r.resolution_method === "unresolved").length;
38
+ return {
39
+ by_viewpoint,
40
+ coverage_gaps: [], // 에이전트가 채움
41
+ ontology_result: ontologyResult,
42
+ total_chunks: totalChunks,
43
+ total_tokens_estimate: uniqueFiles.size * 500, // 파일당 ~500 토큰 추정
44
+ search_confidence: {
45
+ method: "ontology",
46
+ ontology_match_count: ontologyResult.matched_entities.length,
47
+ unresolved_count: unresolvedCount,
48
+ keywords_used: keywords,
49
+ viewpoint_counts,
50
+ ...(unresolvedCount > 0 ? { warning: `${unresolvedCount}건의 source_code가 파일로 해석되지 않았습니다` } : {}),
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,136 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { collectRelevantChunks } from "./code-chunk-collector.js";
3
+ // ─── Fixtures ───
4
+ const RESOLVED = [
5
+ { reference: "TrialLectureCommandServiceImpl.create()", resolved_files: ["src/TrialLectureCommandServiceImpl.java"], resolution_method: "filename" },
6
+ { reference: "UnknownService.call()", resolved_files: [], resolution_method: "unresolved" },
7
+ ];
8
+ const ONTOLOGY_RESULT = {
9
+ matched_entities: ["TrialLesson", "Ticket"],
10
+ code_locations: [{ reference: "TrialLectureCommandServiceImpl.create()", context: "Action TRIAL-1", entity: "TrialLesson" }],
11
+ db_tables: ["GT_CLASS"],
12
+ related_actions: [{ id: "TRIAL-1", display_name: "체험 수업 생성", source_code: "TrialLectureCommandServiceImpl.create()" }],
13
+ related_transitions: [],
14
+ value_filters: [{ entity: "TrialLesson", column: "CITY", value: "PODO_TRIAL", description: "체험 수업" }],
15
+ total_glossary_count: 2,
16
+ };
17
+ const SCAN_RESULT = {
18
+ source: { type: "add-dir", path: "./src" },
19
+ scanned_at: new Date().toISOString(),
20
+ files: [
21
+ { path: "src/TrialLectureCommandServiceImpl.java", category: "source", language: "java", size_bytes: 2000 },
22
+ { path: "src/LectureController.java", category: "source", language: "java", size_bytes: 1500 },
23
+ { path: "test/TrialLectureTest.java", category: "test", language: "java", size_bytes: 1000 },
24
+ { path: "schema/GT_CLASS.sql", category: "schema", language: "sql", size_bytes: 500 },
25
+ ],
26
+ content_hashes: {},
27
+ dependency_graph: [
28
+ { from: "src/LectureController.java", to: "src/TrialLectureCommandServiceImpl.java", kind: "import" },
29
+ ],
30
+ api_patterns: [
31
+ { file: "src/LectureController.java", method: "GET", path: "/trial/list", line: 30 },
32
+ ],
33
+ schema_patterns: [
34
+ { file: "schema/GT_CLASS.sql", table: "GT_CLASS", columns: "id, city, status", line: 1 },
35
+ ],
36
+ config_patterns: [],
37
+ doc_structure: [],
38
+ };
39
+ // ─── Tests ───
40
+ describe("collectRelevantChunks", () => {
41
+ it("6관점 모두에서 결과를 생성한다", () => {
42
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험", "수업"]);
43
+ expect(result.by_viewpoint.semantics.length).toBeGreaterThan(0);
44
+ expect(result.by_viewpoint.dependency.length).toBeGreaterThan(0);
45
+ expect(result.coverage_gaps).toEqual([]); // 에이전트가 채움
46
+ expect(result.search_confidence.method).toBe("ontology");
47
+ });
48
+ it("total_chunks는 6관점 합계이다", () => {
49
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
50
+ const sum = Object.values(result.by_viewpoint).reduce((acc, chunks) => acc + chunks.length, 0);
51
+ expect(result.total_chunks).toBe(sum);
52
+ });
53
+ it("unresolved_count를 정확히 기록한다", () => {
54
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
55
+ expect(result.search_confidence.unresolved_count).toBe(1); // UnknownService
56
+ });
57
+ it("viewpoint_counts가 관점별 청크 수를 기록한다", () => {
58
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
59
+ for (const [vp, count] of Object.entries(result.search_confidence.viewpoint_counts)) {
60
+ expect(count).toBe(result.by_viewpoint[vp].length);
61
+ }
62
+ });
63
+ it("viewpointOverrides로 특정 관점을 비활성화할 수 있다", () => {
64
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"], {
65
+ viewpointOverrides: { evolution: { enabled: false } },
66
+ });
67
+ expect(result.by_viewpoint.evolution).toEqual([]);
68
+ });
69
+ it("maxChunksPerViewpoint로 관점당 상한을 제어한다", () => {
70
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"], {
71
+ maxChunksPerViewpoint: 1,
72
+ });
73
+ for (const chunks of Object.values(result.by_viewpoint)) {
74
+ expect(chunks.length).toBeLessThanOrEqual(1);
75
+ }
76
+ });
77
+ it("value_filters가 logic 관점에 반영된다", () => {
78
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
79
+ const logicContexts = result.by_viewpoint.logic.map((c) => c.context);
80
+ expect(logicContexts.some((ctx) => ctx.includes("PODO_TRIAL"))).toBe(true);
81
+ });
82
+ it("keywords_used가 기록된다", () => {
83
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험", "수업"]);
84
+ expect(result.search_confidence.keywords_used).toEqual(["체험", "수업"]);
85
+ });
86
+ it("guard_note가 있는 action이 logic 관점에 반영된다", () => {
87
+ const withGuard = {
88
+ ...ONTOLOGY_RESULT,
89
+ related_actions: [{
90
+ id: "TRIAL-1",
91
+ display_name: "체험 수업 생성",
92
+ source_code: "TrialLectureCommandServiceImpl.create()",
93
+ guard_note: "체험 수업은 1회만 가능",
94
+ }],
95
+ };
96
+ const result = collectRelevantChunks(RESOLVED, withGuard, SCAN_RESULT, ["체험"]);
97
+ const logicChunks = result.by_viewpoint.logic;
98
+ expect(logicChunks.some((c) => c.context.includes("체험 수업은 1회만 가능"))).toBe(true);
99
+ // guard_note가 있는 청크는 실제 파일 경로를 가져야 함
100
+ const guardChunk = logicChunks.find((c) => c.context.includes("체험 수업은 1회만 가능"));
101
+ expect(guardChunk?.file_path).toBe("src/TrialLectureCommandServiceImpl.java");
102
+ });
103
+ it("preconditions가 있는 action이 logic 관점에 반영된다", () => {
104
+ const withPreconditions = {
105
+ ...ONTOLOGY_RESULT,
106
+ related_actions: [{
107
+ id: "TRIAL-1",
108
+ display_name: "체험 수업 생성",
109
+ source_code: "TrialLectureCommandServiceImpl.create()",
110
+ preconditions: [{ check: "학생이 체험 수업을 받은 적 없음" }],
111
+ }],
112
+ };
113
+ const result = collectRelevantChunks(RESOLVED, withPreconditions, SCAN_RESULT, ["체험"]);
114
+ const logicChunks = result.by_viewpoint.logic;
115
+ expect(logicChunks.some((c) => c.context.includes("학생이 체험 수업을 받은 적 없음"))).toBe(true);
116
+ });
117
+ it("value_filters의 search_hint가 file_path가 아닌 별도 필드에 저장된다", () => {
118
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
119
+ const vfChunks = result.by_viewpoint.logic.filter((c) => c.search_hint);
120
+ expect(vfChunks.length).toBeGreaterThan(0);
121
+ for (const c of vfChunks) {
122
+ expect(c.file_path).toBeUndefined(); // file_path 없이 search_hint만 사용
123
+ expect(c.search_hint).toMatch(/^grep:/);
124
+ }
125
+ });
126
+ it("search_hint만 있는 청크는 토큰 추정에서 제외된다", () => {
127
+ const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
128
+ // 빈 file_path는 uniqueFiles에 포함되지 않으므로 토큰 추정에 영향 없음
129
+ const allFilePaths = Object.values(result.by_viewpoint)
130
+ .flat()
131
+ .map((c) => c.file_path)
132
+ .filter((fp) => fp !== undefined);
133
+ const uniqueFiles = new Set(allFilePaths);
134
+ expect(result.total_tokens_estimate).toBe(uniqueFiles.size * 500);
135
+ });
136
+ });