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.
- package/.onto/authority/core-lens-registry.yaml +134 -0
- package/.onto/authority/core-lexicon.yaml +1562 -0
- package/.onto/authority/diagnostic-codes.yaml +94 -0
- package/.onto/domains/accounting/competency_qs.md +384 -0
- package/.onto/domains/accounting/concepts.md +186 -0
- package/.onto/domains/accounting/conciseness_rules.md +160 -0
- package/.onto/domains/accounting/dependency_rules.md +239 -0
- package/.onto/domains/accounting/domain_scope.md +213 -0
- package/.onto/domains/accounting/extension_cases.md +416 -0
- package/.onto/domains/accounting/logic_rules.md +226 -0
- package/.onto/domains/accounting/structure_spec.md +298 -0
- package/.onto/domains/accounting-kr/competency_qs.md +562 -0
- package/.onto/domains/accounting-kr/concepts.md +187 -0
- package/.onto/domains/accounting-kr/conciseness_rules.md +125 -0
- package/.onto/domains/accounting-kr/dependency_rules.md +93 -0
- package/.onto/domains/accounting-kr/domain_scope.md +140 -0
- package/.onto/domains/accounting-kr/extension_cases.md +343 -0
- package/.onto/domains/accounting-kr/logic_rules.md +160 -0
- package/.onto/domains/accounting-kr/structure_spec.md +85 -0
- package/.onto/domains/business/competency_qs.md +263 -0
- package/.onto/domains/business/concepts.md +200 -0
- package/.onto/domains/business/conciseness_rules.md +135 -0
- package/.onto/domains/business/dependency_rules.md +113 -0
- package/.onto/domains/business/domain_scope.md +240 -0
- package/.onto/domains/business/extension_cases.md +249 -0
- package/.onto/domains/business/logic_rules.md +134 -0
- package/.onto/domains/business/structure_spec.md +114 -0
- package/.onto/domains/finance/competency_qs.md +362 -0
- package/.onto/domains/finance/concepts.md +194 -0
- package/.onto/domains/finance/conciseness_rules.md +155 -0
- package/.onto/domains/finance/dependency_rules.md +171 -0
- package/.onto/domains/finance/domain_scope.md +215 -0
- package/.onto/domains/finance/extension_cases.md +350 -0
- package/.onto/domains/finance/logic_rules.md +191 -0
- package/.onto/domains/finance/structure_spec.md +182 -0
- package/.onto/domains/llm-native-development/competency_qs.md +430 -0
- package/.onto/domains/llm-native-development/concepts.md +242 -0
- package/.onto/domains/llm-native-development/conciseness_rules.md +163 -0
- package/.onto/domains/llm-native-development/dependency_rules.md +216 -0
- package/.onto/domains/llm-native-development/domain_scope.md +197 -0
- package/.onto/domains/llm-native-development/extension_cases.md +474 -0
- package/.onto/domains/llm-native-development/logic_rules.md +123 -0
- package/.onto/domains/llm-native-development/prompt_interface.md +49 -0
- package/.onto/domains/llm-native-development/structure_spec.md +245 -0
- package/.onto/domains/market-intelligence/competency_qs.md +274 -0
- package/.onto/domains/market-intelligence/concepts.md +233 -0
- package/.onto/domains/market-intelligence/conciseness_rules.md +165 -0
- package/.onto/domains/market-intelligence/dependency_rules.md +197 -0
- package/.onto/domains/market-intelligence/domain_scope.md +231 -0
- package/.onto/domains/market-intelligence/extension_cases.md +425 -0
- package/.onto/domains/market-intelligence/logic_rules.md +247 -0
- package/.onto/domains/market-intelligence/structure_spec.md +209 -0
- package/.onto/domains/ontology/competency_qs.md +394 -0
- package/.onto/domains/ontology/concepts.md +172 -0
- package/.onto/domains/ontology/conciseness_rules.md +134 -0
- package/.onto/domains/ontology/dependency_rules.md +125 -0
- package/.onto/domains/ontology/domain_scope.md +114 -0
- package/.onto/domains/ontology/extension_cases.md +501 -0
- package/.onto/domains/ontology/logic_rules.md +114 -0
- package/.onto/domains/ontology/problem_framing_profile.md +67 -0
- package/.onto/domains/ontology/structure_spec.md +115 -0
- package/.onto/domains/palantir-foundry/RESEARCH_NOTES.md +911 -0
- package/.onto/domains/palantir-foundry/competency_qs.md +191 -0
- package/.onto/domains/palantir-foundry/competitive_comparison.md +329 -0
- package/.onto/domains/palantir-foundry/concepts.md +197 -0
- package/.onto/domains/palantir-foundry/conciseness_rules.md +245 -0
- package/.onto/domains/palantir-foundry/dependency_rules.md +135 -0
- package/.onto/domains/palantir-foundry/domain_scope.md +395 -0
- package/.onto/domains/palantir-foundry/extension_cases.md +210 -0
- package/.onto/domains/palantir-foundry/logic_rules.md +172 -0
- package/.onto/domains/palantir-foundry/structure_spec.md +291 -0
- package/.onto/domains/software-engineering/competency_qs.md +538 -0
- package/.onto/domains/software-engineering/concepts.md +238 -0
- package/.onto/domains/software-engineering/conciseness_rules.md +167 -0
- package/.onto/domains/software-engineering/dependency_rules.md +216 -0
- package/.onto/domains/software-engineering/domain_scope.md +183 -0
- package/.onto/domains/software-engineering/extension_cases.md +551 -0
- package/.onto/domains/software-engineering/logic_rules.md +240 -0
- package/.onto/domains/software-engineering/problem_framing_profile.md +68 -0
- package/.onto/domains/software-engineering/structure_spec.md +185 -0
- package/.onto/domains/ui-design/competency_qs.md +567 -0
- package/.onto/domains/ui-design/concepts.md +194 -0
- package/.onto/domains/ui-design/conciseness_rules.md +190 -0
- package/.onto/domains/ui-design/dependency_rules.md +323 -0
- package/.onto/domains/ui-design/domain_scope.md +340 -0
- package/.onto/domains/ui-design/extension_cases.md +563 -0
- package/.onto/domains/ui-design/logic_rules.md +349 -0
- package/.onto/domains/ui-design/structure_spec.md +252 -0
- package/.onto/domains/visual-design/competency_qs.md +472 -0
- package/.onto/domains/visual-design/concepts.md +147 -0
- package/.onto/domains/visual-design/conciseness_rules.md +186 -0
- package/.onto/domains/visual-design/dependency_rules.md +282 -0
- package/.onto/domains/visual-design/domain_scope.md +290 -0
- package/.onto/domains/visual-design/extension_cases.md +480 -0
- package/.onto/domains/visual-design/logic_rules.md +232 -0
- package/.onto/domains/visual-design/structure_spec.md +213 -0
- package/.onto/principles/llm-native-development-guideline.md +401 -0
- package/.onto/principles/llm-runtime-interface-principles.md +665 -0
- package/.onto/principles/non-specialist-communication-guideline.md +74 -0
- package/.onto/principles/ontology-as-code-guideline.md +243 -0
- package/.onto/principles/ontology-as-code-naming-charter.md +130 -0
- package/.onto/principles/product-locality-principle.md +129 -0
- package/.onto/principles/productization-charter.md +569 -0
- package/.onto/processes/evolve/material-kind-adapter-contract.md +113 -0
- package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +366 -0
- package/.onto/processes/reconstruct/source-profile-contract.md +107 -0
- package/.onto/processes/reconstruct/source-profiles/code.md +72 -0
- package/.onto/processes/reconstruct/source-profiles/database.md +74 -0
- package/.onto/processes/reconstruct/source-profiles/document.md +71 -0
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +79 -0
- package/.onto/processes/review/binding-contract.md +270 -0
- package/.onto/processes/review/execution-preparation-artifacts.md +281 -0
- package/.onto/processes/review/interpretation-contract.md +245 -0
- package/.onto/processes/review/issue-stance-deliberation-contract.md +761 -0
- package/.onto/processes/review/lens-prompt-contract.md +402 -0
- package/.onto/processes/review/lens-registry.md +127 -0
- package/.onto/processes/review/pre-dispatch-contracts.md +428 -0
- package/.onto/processes/review/productized-live-path.md +398 -0
- package/.onto/processes/review/prompt-execution-runner-contract.md +187 -0
- package/.onto/processes/review/record-contract.md +427 -0
- package/.onto/processes/review/record-field-mapping.md +337 -0
- package/.onto/processes/review/review-context-manifest-contract.md +356 -0
- package/.onto/processes/review/review-execution-ux-contract.md +809 -0
- package/.onto/processes/review/review-target-profile-contract.md +259 -0
- package/.onto/processes/review/shared-phenomenon-contract.md +129 -0
- package/.onto/processes/review/synthesize-prompt-contract.md +343 -0
- package/.onto/processes/shared/target-material-kind-contract.md +198 -0
- package/.onto/roles/axiology.md +81 -0
- package/.onto/roles/conciseness.md +36 -0
- package/.onto/roles/coverage.md +34 -0
- package/.onto/roles/dependency.md +37 -0
- package/.onto/roles/evolution.md +35 -0
- package/.onto/roles/logic.md +104 -0
- package/.onto/roles/pragmatics.md +32 -0
- package/.onto/roles/semantics.md +36 -0
- package/.onto/roles/structure.md +33 -0
- package/.onto/roles/synthesize.md +92 -0
- package/AGENTS.md +240 -0
- package/CLAUDE.md +39 -0
- package/README.md +287 -0
- package/bin/onto +92 -0
- package/dist/cli.js +101 -0
- package/dist/core-api/reconstruct-api.js +222 -0
- package/dist/core-api/review-api.js +1271 -0
- package/dist/core-runtime/cli/assemble-review-record.js +431 -0
- package/dist/core-runtime/cli/bootstrap-review-binding.js +186 -0
- package/dist/core-runtime/cli/codex-nested-dispatch.js +226 -0
- package/dist/core-runtime/cli/codex-nested-dispatch.test.js +390 -0
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.js +464 -0
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +335 -0
- package/dist/core-runtime/cli/codex-review-unit-executor.js +228 -0
- package/dist/core-runtime/cli/complete-review-session.js +64 -0
- package/dist/core-runtime/cli/complexity-assessment.js +153 -0
- package/dist/core-runtime/cli/coordinator-helpers.js +583 -0
- package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +167 -0
- package/dist/core-runtime/cli/coordinator-state-machine.js +794 -0
- package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +615 -0
- package/dist/core-runtime/cli/e2e-start-review-session.test.js +312 -0
- package/dist/core-runtime/cli/health.js +44 -0
- package/dist/core-runtime/cli/inline-http-review-unit-executor.js +656 -0
- package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +567 -0
- package/dist/core-runtime/cli/materialize-review-execution-preparation.js +104 -0
- package/dist/core-runtime/cli/materialize-review-prompt-packets.js +952 -0
- package/dist/core-runtime/cli/migrate-session-roots.js +118 -0
- package/dist/core-runtime/cli/mock-review-unit-executor.js +285 -0
- package/dist/core-runtime/cli/onto-tools.js +369 -0
- package/dist/core-runtime/cli/prepare-review-session.js +272 -0
- package/dist/core-runtime/cli/render-review-final-output.js +350 -0
- package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +106 -0
- package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +268 -0
- package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +136 -0
- package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +201 -0
- package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +192 -0
- package/dist/core-runtime/cli/review-invoke.js +2030 -0
- package/dist/core-runtime/cli/run-review-prompt-execution.js +2152 -0
- package/dist/core-runtime/cli/session-root-guard.js +168 -0
- package/dist/core-runtime/cli/spawn-watcher.js +173 -0
- package/dist/core-runtime/cli/spawn-watcher.test.js +457 -0
- package/dist/core-runtime/cli/start-review-session.js +68 -0
- package/dist/core-runtime/cli/strip-wrapping-code-fence.js +56 -0
- package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +79 -0
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +412 -0
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +351 -0
- package/dist/core-runtime/cli/topology-executor-mapping.js +139 -0
- package/dist/core-runtime/cli/topology-executor-mapping.test.js +173 -0
- package/dist/core-runtime/cli/write-review-interpretation.js +81 -0
- package/dist/core-runtime/config/onto-config-cli.js +278 -0
- package/dist/core-runtime/config/onto-config-key-path.js +288 -0
- package/dist/core-runtime/config/onto-config-key-path.test.js +195 -0
- package/dist/core-runtime/config/onto-config-preview.js +108 -0
- package/dist/core-runtime/config/onto-config-preview.test.js +132 -0
- package/dist/core-runtime/discovery/config-chain.js +118 -0
- package/dist/core-runtime/discovery/config-chain.test.js +103 -0
- package/dist/core-runtime/discovery/config-profile.js +199 -0
- package/dist/core-runtime/discovery/config-profile.test.js +233 -0
- package/dist/core-runtime/discovery/host-detection.js +33 -0
- package/dist/core-runtime/discovery/host-detection.test.js +186 -0
- package/dist/core-runtime/discovery/installation-paths.js +21 -0
- package/dist/core-runtime/discovery/installation-paths.test.js +65 -0
- package/dist/core-runtime/discovery/lens-registry.js +60 -0
- package/dist/core-runtime/discovery/lens-registry.test.js +81 -0
- package/dist/core-runtime/discovery/onto-home.js +71 -0
- package/dist/core-runtime/discovery/path-normalization.js +28 -0
- package/dist/core-runtime/discovery/path-normalization.test.js +22 -0
- package/dist/core-runtime/discovery/plugin-path.js +72 -0
- package/dist/core-runtime/discovery/plugin-path.test.js +95 -0
- package/dist/core-runtime/discovery/project-root.js +47 -0
- package/dist/core-runtime/discovery/settings-chain.js +353 -0
- package/dist/core-runtime/discovery/walk-up.js +17 -0
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +344 -0
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +915 -0
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +564 -0
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +708 -0
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +165 -0
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +227 -0
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +59 -0
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +205 -0
- package/dist/core-runtime/evolve/adapters/methodology/adapter.js +16 -0
- package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +9 -0
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +298 -0
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +70 -0
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +46 -0
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +73 -0
- package/dist/core-runtime/evolve/adapters/registry.js +47 -0
- package/dist/core-runtime/evolve/adapters/registry.test.js +67 -0
- package/dist/core-runtime/evolve/cli.js +256 -0
- package/dist/core-runtime/evolve/commands/align.js +194 -0
- package/dist/core-runtime/evolve/commands/align.test.js +82 -0
- package/dist/core-runtime/evolve/commands/apply.js +161 -0
- package/dist/core-runtime/evolve/commands/apply.test.js +138 -0
- package/dist/core-runtime/evolve/commands/close.js +39 -0
- package/dist/core-runtime/evolve/commands/close.test.js +99 -0
- package/dist/core-runtime/evolve/commands/defer.js +40 -0
- package/dist/core-runtime/evolve/commands/defer.test.js +134 -0
- package/dist/core-runtime/evolve/commands/draft.js +323 -0
- package/dist/core-runtime/evolve/commands/draft.test.js +178 -0
- package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +208 -0
- package/dist/core-runtime/evolve/commands/error-messages.js +125 -0
- package/dist/core-runtime/evolve/commands/error-messages.test.js +167 -0
- package/dist/core-runtime/evolve/commands/propose-align.js +222 -0
- package/dist/core-runtime/evolve/commands/propose-align.test.js +136 -0
- package/dist/core-runtime/evolve/commands/reconstruct.js +330 -0
- package/dist/core-runtime/evolve/commands/reconstruct.test.js +278 -0
- package/dist/core-runtime/evolve/commands/shared.js +22 -0
- package/dist/core-runtime/evolve/commands/stale-check.js +103 -0
- package/dist/core-runtime/evolve/commands/stale-check.test.js +84 -0
- package/dist/core-runtime/evolve/commands/start.js +887 -0
- package/dist/core-runtime/evolve/commands/start.test.js +396 -0
- package/dist/core-runtime/evolve/config/project-config.js +99 -0
- package/dist/core-runtime/evolve/config/project-config.test.js +170 -0
- package/dist/core-runtime/evolve/renderers/align-packet.js +280 -0
- package/dist/core-runtime/evolve/renderers/align-packet.test.js +332 -0
- package/dist/core-runtime/evolve/renderers/draft-packet.js +303 -0
- package/dist/core-runtime/evolve/renderers/draft-packet.test.js +377 -0
- package/dist/core-runtime/evolve/renderers/format.js +5 -0
- package/dist/core-runtime/evolve/renderers/scope-md.js +237 -0
- package/dist/core-runtime/evolve/renderers/scope-md.test.js +306 -0
- package/dist/core-runtime/govern/cli.js +369 -0
- package/dist/core-runtime/govern/cli.test.js +314 -0
- package/dist/core-runtime/govern/drift-engine.js +103 -0
- package/dist/core-runtime/govern/drift-engine.test.js +319 -0
- package/dist/core-runtime/govern/promote-principle.js +206 -0
- package/dist/core-runtime/govern/promote-principle.test.js +368 -0
- package/dist/core-runtime/govern/queue.js +81 -0
- package/dist/core-runtime/govern/types.js +16 -0
- package/dist/core-runtime/install/cli.js +530 -0
- package/dist/core-runtime/install/detect.js +128 -0
- package/dist/core-runtime/install/detect.test.js +155 -0
- package/dist/core-runtime/install/gitignore-update.js +74 -0
- package/dist/core-runtime/install/gitignore-update.test.js +64 -0
- package/dist/core-runtime/install/install-integration.test.js +373 -0
- package/dist/core-runtime/install/prompts.js +389 -0
- package/dist/core-runtime/install/prompts.test.js +293 -0
- package/dist/core-runtime/install/types.js +26 -0
- package/dist/core-runtime/install/validation.js +295 -0
- package/dist/core-runtime/install/validation.test.js +313 -0
- package/dist/core-runtime/install/writer.js +254 -0
- package/dist/core-runtime/install/writer.test.js +218 -0
- package/dist/core-runtime/learning/extractor.js +461 -0
- package/dist/core-runtime/learning/feedback.js +179 -0
- package/dist/core-runtime/learning/health-report.js +165 -0
- package/dist/core-runtime/learning/health-report.test.js +169 -0
- package/dist/core-runtime/learning/loader.js +388 -0
- package/dist/core-runtime/learning/loader.test.js +102 -0
- package/dist/core-runtime/learning/promote/apply-state.js +240 -0
- package/dist/core-runtime/learning/promote/audit-obligation.js +195 -0
- package/dist/core-runtime/learning/promote/collector.js +432 -0
- package/dist/core-runtime/learning/promote/degraded-state.js +125 -0
- package/dist/core-runtime/learning/promote/domain-doc-proposer.js +166 -0
- package/dist/core-runtime/learning/promote/e2e-promote.test.js +6385 -0
- package/dist/core-runtime/learning/promote/health-snapshot.js +150 -0
- package/dist/core-runtime/learning/promote/insight-reclassifier.js +544 -0
- package/dist/core-runtime/learning/promote/judgment-auditor.js +517 -0
- package/dist/core-runtime/learning/promote/panel-reviewer.js +1158 -0
- package/dist/core-runtime/learning/promote/promote-executor.js +1675 -0
- package/dist/core-runtime/learning/promote/promoter.js +307 -0
- package/dist/core-runtime/learning/promote/retirement.js +122 -0
- package/dist/core-runtime/learning/promote/types.js +23 -0
- package/dist/core-runtime/learning/prompt-sections.js +51 -0
- package/dist/core-runtime/learning/shared/artifact-registry-init.js +45 -0
- package/dist/core-runtime/learning/shared/artifact-registry.js +254 -0
- package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +73 -0
- package/dist/core-runtime/learning/shared/audit-state.js +99 -0
- package/dist/core-runtime/learning/shared/duplicate-check.js +28 -0
- package/dist/core-runtime/learning/shared/llm-caller.js +831 -0
- package/dist/core-runtime/learning/shared/llm-caller.test.js +601 -0
- package/dist/core-runtime/learning/shared/llm-tool-loop.js +393 -0
- package/dist/core-runtime/learning/shared/mode.js +25 -0
- package/dist/core-runtime/learning/shared/paths.js +84 -0
- package/dist/core-runtime/learning/shared/paths.test.js +79 -0
- package/dist/core-runtime/learning/shared/patterns.js +37 -0
- package/dist/core-runtime/learning/shared/recoverability.js +355 -0
- package/dist/core-runtime/learning/shared/recovery-context.js +374 -0
- package/dist/core-runtime/learning/shared/scope.js +1 -0
- package/dist/core-runtime/learning/shared/semantic-classifier.js +94 -0
- package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +42 -0
- package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +37 -0
- package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +39 -0
- package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +41 -0
- package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +38 -0
- package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +43 -0
- package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +113 -0
- package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +36 -0
- package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +48 -0
- package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +43 -0
- package/dist/core-runtime/learning/shared/specs/spec-helpers.js +64 -0
- package/dist/core-runtime/learning/usage-tracker.js +190 -0
- package/dist/core-runtime/learning/usage-tracker.test.js +176 -0
- package/dist/core-runtime/llm/llm-caller.js +649 -0
- package/dist/core-runtime/llm/llm-tool-loop.js +401 -0
- package/dist/core-runtime/llm/model-switcher.js +62 -0
- package/dist/core-runtime/logger.js +22 -0
- package/dist/core-runtime/onboard/detect-review-axes.js +122 -0
- package/dist/core-runtime/onboard/detect-review-axes.test.js +127 -0
- package/dist/core-runtime/onboard/write-review-block.js +188 -0
- package/dist/core-runtime/onboard/write-review-block.test.js +240 -0
- package/dist/core-runtime/readers/brownfield-builder.js +150 -0
- package/dist/core-runtime/readers/brownfield-builder.test.js +136 -0
- package/dist/core-runtime/readers/code-chunk-collector.js +53 -0
- package/dist/core-runtime/readers/code-chunk-collector.test.js +136 -0
- package/dist/core-runtime/readers/file-utils.js +240 -0
- package/dist/core-runtime/readers/file-utils.test.js +146 -0
- package/dist/core-runtime/readers/lexicon-citation-check.js +93 -0
- package/dist/core-runtime/readers/lexicon-citation-check.test.js +77 -0
- package/dist/core-runtime/readers/mcp-figma.js +30 -0
- package/dist/core-runtime/readers/mcp-figma.test.js +82 -0
- package/dist/core-runtime/readers/mcp-generic.js +31 -0
- package/dist/core-runtime/readers/mcp-generic.test.js +76 -0
- package/dist/core-runtime/readers/ontology-index.js +148 -0
- package/dist/core-runtime/readers/ontology-index.test.js +245 -0
- package/dist/core-runtime/readers/ontology-query.js +168 -0
- package/dist/core-runtime/readers/ontology-query.test.js +311 -0
- package/dist/core-runtime/readers/ontology-resolve.js +48 -0
- package/dist/core-runtime/readers/ontology-resolve.test.js +48 -0
- package/dist/core-runtime/readers/patterns/index.js +7 -0
- package/dist/core-runtime/readers/review-log.js +213 -0
- package/dist/core-runtime/readers/review-log.test.js +313 -0
- package/dist/core-runtime/readers/scan-local.js +102 -0
- package/dist/core-runtime/readers/scan-local.test.js +102 -0
- package/dist/core-runtime/readers/scan-tarball.js +121 -0
- package/dist/core-runtime/readers/scan-tarball.test.js +283 -0
- package/dist/core-runtime/readers/scan-vault.js +34 -0
- package/dist/core-runtime/readers/scan-vault.test.js +81 -0
- package/dist/core-runtime/readers/types.js +42 -0
- package/dist/core-runtime/readers/types.test.js +94 -0
- package/dist/core-runtime/readers/viewpoint-collectors.js +229 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +1 -0
- package/dist/core-runtime/reconstruct/directive-validation.js +123 -0
- package/dist/core-runtime/reconstruct/materialize-preparation.js +251 -0
- package/dist/core-runtime/reconstruct/record.js +198 -0
- package/dist/core-runtime/reconstruct/run.js +578 -0
- package/dist/core-runtime/reconstruct/seed-candidate-validation.js +356 -0
- package/dist/core-runtime/reconstruct/source-observations.js +62 -0
- package/dist/core-runtime/reconstruct/source-profiles.js +73 -0
- package/dist/core-runtime/release-channel/release-channel.js +90 -0
- package/dist/core-runtime/review/artifact-types.js +13 -0
- package/dist/core-runtime/review/citation-audit.js +204 -0
- package/dist/core-runtime/review/citation-audit.test.js +165 -0
- package/dist/core-runtime/review/controlled-lens-deliberation.js +125 -0
- package/dist/core-runtime/review/execution-plan-resolver.js +247 -0
- package/dist/core-runtime/review/execution-plan-resolver.test.js +243 -0
- package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +246 -0
- package/dist/core-runtime/review/execution-topology-resolver.js +401 -0
- package/dist/core-runtime/review/execution-topology-resolver.test.js +315 -0
- package/dist/core-runtime/review/failure-records.js +57 -0
- package/dist/core-runtime/review/inline-context-embedder.js +141 -0
- package/dist/core-runtime/review/inline-context-embedder.test.js +154 -0
- package/dist/core-runtime/review/issue-artifact-runtime.js +859 -0
- package/dist/core-runtime/review/legacy-mode-policy.js +88 -0
- package/dist/core-runtime/review/lens-completion-policy.js +17 -0
- package/dist/core-runtime/review/materializers-effort-persist.test.js +79 -0
- package/dist/core-runtime/review/materializers.js +963 -0
- package/dist/core-runtime/review/ontology-path-classifier.js +179 -0
- package/dist/core-runtime/review/ontology-path-classifier.test.js +216 -0
- package/dist/core-runtime/review/packet-boundary-policy.js +215 -0
- package/dist/core-runtime/review/packet-boundary-policy.test.js +107 -0
- package/dist/core-runtime/review/participating-lens-paths.js +61 -0
- package/dist/core-runtime/review/participating-lens-paths.test.js +73 -0
- package/dist/core-runtime/review/review-artifact-utils.js +287 -0
- package/dist/core-runtime/review/review-config-legacy-translate.js +244 -0
- package/dist/core-runtime/review/review-config-legacy-translate.test.js +161 -0
- package/dist/core-runtime/review/review-config-validator.js +289 -0
- package/dist/core-runtime/review/review-config-validator.test.js +236 -0
- package/dist/core-runtime/review/review-execution-profile.js +193 -0
- package/dist/core-runtime/review/review-execution-route.js +52 -0
- package/dist/core-runtime/review/review-progress-contract.js +123 -0
- package/dist/core-runtime/review/review-record-validation.js +251 -0
- package/dist/core-runtime/review/review-result-classification.js +379 -0
- package/dist/core-runtime/review/review-state-machine.js +39 -0
- package/dist/core-runtime/review/route-visibility.js +125 -0
- package/dist/core-runtime/review/shape-pipeline-audit.test.js +311 -0
- package/dist/core-runtime/review/shape-to-topology-id.js +117 -0
- package/dist/core-runtime/review/shape-to-topology-id.test.js +132 -0
- package/dist/core-runtime/review/topology-shape-derivation.js +155 -0
- package/dist/core-runtime/review/topology-shape-derivation.test.js +195 -0
- package/dist/core-runtime/scope-runtime/constants.js +12 -0
- package/dist/core-runtime/scope-runtime/constraint-pool.js +166 -0
- package/dist/core-runtime/scope-runtime/constraint-pool.test.js +674 -0
- package/dist/core-runtime/scope-runtime/domain-validation-log.js +135 -0
- package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +156 -0
- package/dist/core-runtime/scope-runtime/eval-persistence.js +65 -0
- package/dist/core-runtime/scope-runtime/eval-persistence.test.js +84 -0
- package/dist/core-runtime/scope-runtime/event-pipeline.js +64 -0
- package/dist/core-runtime/scope-runtime/event-pipeline.test.js +450 -0
- package/dist/core-runtime/scope-runtime/event-store.js +39 -0
- package/dist/core-runtime/scope-runtime/event-store.test.js +95 -0
- package/dist/core-runtime/scope-runtime/gate-guard.js +348 -0
- package/dist/core-runtime/scope-runtime/gate-guard.test.js +1047 -0
- package/dist/core-runtime/scope-runtime/hash.js +4 -0
- package/dist/core-runtime/scope-runtime/hash.test.js +33 -0
- package/dist/core-runtime/scope-runtime/id.js +4 -0
- package/dist/core-runtime/scope-runtime/id.test.js +17 -0
- package/dist/core-runtime/scope-runtime/reducer.js +297 -0
- package/dist/core-runtime/scope-runtime/reducer.test.js +759 -0
- package/dist/core-runtime/scope-runtime/scope-manager.js +161 -0
- package/dist/core-runtime/scope-runtime/state-machine.js +309 -0
- package/dist/core-runtime/scope-runtime/state-machine.test.js +704 -0
- package/dist/core-runtime/scope-runtime/types.js +116 -0
- package/dist/core-runtime/scope-runtime/types.test.js +69 -0
- package/dist/core-runtime/target-material-kind.js +256 -0
- package/dist/core-runtime/translate/render-for-user.js +169 -0
- package/dist/core-runtime/translate/render-for-user.test.js +122 -0
- package/dist/mcp/server.js +1011 -0
- package/dist/mcp/tool-schemas.js +93 -0
- package/dist/providers/capability-contract.js +1 -0
- package/package.json +68 -0
- package/settings.example.json +33 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { buildConstraintPool, isConstraintsResolved, findConstraint, } from "./constraint-pool.js";
|
|
5
|
+
// ─── Helpers ───
|
|
6
|
+
const GOLDEN_EVENTS_PATH = resolve(import.meta.dirname, "__fixtures__/example-tutor-block/events.ndjson");
|
|
7
|
+
const GOLDEN_POOL_PATH = resolve(import.meta.dirname, "__fixtures__/example-tutor-block/state/constraint-pool.json");
|
|
8
|
+
function readGoldenEvents() {
|
|
9
|
+
return readFileSync(GOLDEN_EVENTS_PATH, "utf-8")
|
|
10
|
+
.trimEnd()
|
|
11
|
+
.split("\n")
|
|
12
|
+
.map((line) => JSON.parse(line));
|
|
13
|
+
}
|
|
14
|
+
function readGoldenPool() {
|
|
15
|
+
return JSON.parse(readFileSync(GOLDEN_POOL_PATH, "utf-8"));
|
|
16
|
+
}
|
|
17
|
+
/** Create a minimal constraint.discovered event. */
|
|
18
|
+
function discovered(id, revision, overrides = {}) {
|
|
19
|
+
return {
|
|
20
|
+
event_id: `evt_${revision}`,
|
|
21
|
+
scope_id: "SC-TEST",
|
|
22
|
+
type: "constraint.discovered",
|
|
23
|
+
ts: `2026-01-01T00:00:${String(revision).padStart(2, "0")}Z`,
|
|
24
|
+
revision,
|
|
25
|
+
actor: "system",
|
|
26
|
+
state_before: "surface_confirmed",
|
|
27
|
+
state_after: "surface_confirmed",
|
|
28
|
+
payload: {
|
|
29
|
+
constraint_id: id,
|
|
30
|
+
perspective: overrides.perspective ?? "code",
|
|
31
|
+
summary: `test constraint ${id}`,
|
|
32
|
+
severity: overrides.severity ?? "recommended",
|
|
33
|
+
discovery_stage: overrides.discovery_stage ?? "draft_phase2",
|
|
34
|
+
decision_owner: overrides.decision_owner ?? "product_owner",
|
|
35
|
+
impact_if_ignored: "test impact",
|
|
36
|
+
source_refs: [{ source: "test.ts", detail: "test detail" }],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Create a constraint.decision_recorded event. */
|
|
41
|
+
function decisionRecorded(id, revision, overrides = {}) {
|
|
42
|
+
return {
|
|
43
|
+
event_id: `evt_${revision}`,
|
|
44
|
+
scope_id: "SC-TEST",
|
|
45
|
+
type: "constraint.decision_recorded",
|
|
46
|
+
ts: `2026-01-01T00:00:${String(revision).padStart(2, "0")}Z`,
|
|
47
|
+
revision,
|
|
48
|
+
actor: "user",
|
|
49
|
+
state_before: "surface_confirmed",
|
|
50
|
+
state_after: "surface_confirmed",
|
|
51
|
+
payload: {
|
|
52
|
+
constraint_id: id,
|
|
53
|
+
decision: overrides.decision ?? "inject",
|
|
54
|
+
selected_option: overrides.selected_option ?? "option A",
|
|
55
|
+
decision_owner: overrides.decision_owner ?? "product_owner",
|
|
56
|
+
rationale: overrides.rationale ?? "test rationale",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Create a constraint.clarify_requested event. */
|
|
61
|
+
function clarifyRequested(id, revision) {
|
|
62
|
+
return {
|
|
63
|
+
event_id: `evt_${revision}`,
|
|
64
|
+
scope_id: "SC-TEST",
|
|
65
|
+
type: "constraint.clarify_requested",
|
|
66
|
+
ts: `2026-01-01T00:00:${String(revision).padStart(2, "0")}Z`,
|
|
67
|
+
revision,
|
|
68
|
+
actor: "user",
|
|
69
|
+
state_before: "surface_confirmed",
|
|
70
|
+
state_after: "surface_confirmed",
|
|
71
|
+
payload: {
|
|
72
|
+
constraint_id: id,
|
|
73
|
+
question: "test question",
|
|
74
|
+
asked_to: "test team",
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Create a constraint.clarify_resolved event. */
|
|
79
|
+
function clarifyResolved(id, revision, overrides = {}) {
|
|
80
|
+
return {
|
|
81
|
+
event_id: `evt_${revision}`,
|
|
82
|
+
scope_id: "SC-TEST",
|
|
83
|
+
type: "constraint.clarify_resolved",
|
|
84
|
+
ts: `2026-01-01T00:00:${String(revision).padStart(2, "0")}Z`,
|
|
85
|
+
revision,
|
|
86
|
+
actor: "user",
|
|
87
|
+
state_before: "surface_confirmed",
|
|
88
|
+
state_after: "surface_confirmed",
|
|
89
|
+
payload: {
|
|
90
|
+
constraint_id: id,
|
|
91
|
+
resolution: "resolved",
|
|
92
|
+
decision: overrides.decision ?? "inject",
|
|
93
|
+
selected_option: "resolved option",
|
|
94
|
+
decision_owner: overrides.decision_owner ?? "product_owner",
|
|
95
|
+
rationale: "resolved rationale",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Create a constraint.invalidated event. */
|
|
100
|
+
function invalidated(id, revision) {
|
|
101
|
+
return {
|
|
102
|
+
event_id: `evt_${revision}`,
|
|
103
|
+
scope_id: "SC-TEST",
|
|
104
|
+
type: "constraint.invalidated",
|
|
105
|
+
ts: `2026-01-01T00:00:${String(revision).padStart(2, "0")}Z`,
|
|
106
|
+
revision,
|
|
107
|
+
actor: "system",
|
|
108
|
+
state_before: "surface_confirmed",
|
|
109
|
+
state_after: "surface_confirmed",
|
|
110
|
+
payload: {
|
|
111
|
+
constraint_id: id,
|
|
112
|
+
reason: "no longer relevant",
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Assert summary invariants hold for any pool. */
|
|
117
|
+
function assertSummaryInvariants(pool) {
|
|
118
|
+
const { summary, constraints } = pool;
|
|
119
|
+
expect(summary.total).toBe(constraints.length);
|
|
120
|
+
expect(summary.required + summary.recommended).toBe(summary.total);
|
|
121
|
+
expect(summary.decided +
|
|
122
|
+
summary.clarify_pending +
|
|
123
|
+
summary.invalidated +
|
|
124
|
+
summary.undecided).toBe(summary.total);
|
|
125
|
+
}
|
|
126
|
+
// ─── Tests ───
|
|
127
|
+
describe("constraint-pool — golden data", () => {
|
|
128
|
+
const events = readGoldenEvents();
|
|
129
|
+
const expectedPool = readGoldenPool();
|
|
130
|
+
it("buildConstraintPool matches golden constraint-pool.json", () => {
|
|
131
|
+
const pool = buildConstraintPool(events);
|
|
132
|
+
expect(pool.constraints).toHaveLength(expectedPool.constraints.length);
|
|
133
|
+
expect(pool.summary).toEqual(expectedPool.summary);
|
|
134
|
+
for (const expected of expectedPool.constraints) {
|
|
135
|
+
const actual = findConstraint(pool, expected.constraint_id);
|
|
136
|
+
expect(actual).toBeDefined();
|
|
137
|
+
expect(actual).toEqual(expected);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
it("summary invariants hold for golden data", () => {
|
|
141
|
+
const pool = buildConstraintPool(events);
|
|
142
|
+
assertSummaryInvariants(pool);
|
|
143
|
+
});
|
|
144
|
+
it("isConstraintsResolved is true for golden data (all decided)", () => {
|
|
145
|
+
const pool = buildConstraintPool(events);
|
|
146
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe("constraint-pool — status transitions", () => {
|
|
150
|
+
it("discovered → decided", () => {
|
|
151
|
+
const events = [
|
|
152
|
+
discovered("CST-001", 1),
|
|
153
|
+
decisionRecorded("CST-001", 2),
|
|
154
|
+
];
|
|
155
|
+
const pool = buildConstraintPool(events);
|
|
156
|
+
const entry = findConstraint(pool, "CST-001");
|
|
157
|
+
expect(entry.status).toBe("decided");
|
|
158
|
+
expect(entry.decision).toBe("inject");
|
|
159
|
+
expect(entry.discovered_at).toBe(1);
|
|
160
|
+
expect(entry.decided_at).toBe(2);
|
|
161
|
+
});
|
|
162
|
+
it("discovered → clarify_pending → clarify_resolved (decided)", () => {
|
|
163
|
+
const events = [
|
|
164
|
+
discovered("CST-001", 1),
|
|
165
|
+
clarifyRequested("CST-001", 2),
|
|
166
|
+
clarifyResolved("CST-001", 3),
|
|
167
|
+
];
|
|
168
|
+
const pool = buildConstraintPool(events);
|
|
169
|
+
const entry = findConstraint(pool, "CST-001");
|
|
170
|
+
expect(entry.status).toBe("decided");
|
|
171
|
+
expect(entry.decided_at).toBe(3);
|
|
172
|
+
});
|
|
173
|
+
it("discovered → invalidated", () => {
|
|
174
|
+
const events = [discovered("CST-001", 1), invalidated("CST-001", 2)];
|
|
175
|
+
const pool = buildConstraintPool(events);
|
|
176
|
+
const entry = findConstraint(pool, "CST-001");
|
|
177
|
+
expect(entry.status).toBe("invalidated");
|
|
178
|
+
});
|
|
179
|
+
it("undecided → invalidated direct path", () => {
|
|
180
|
+
const events = [
|
|
181
|
+
discovered("CST-001", 1, { severity: "recommended" }),
|
|
182
|
+
invalidated("CST-001", 2),
|
|
183
|
+
];
|
|
184
|
+
const pool = buildConstraintPool(events);
|
|
185
|
+
const entry = findConstraint(pool, "CST-001");
|
|
186
|
+
expect(entry.status).toBe("invalidated");
|
|
187
|
+
expect(entry.severity).toBe("recommended");
|
|
188
|
+
assertSummaryInvariants(pool);
|
|
189
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
190
|
+
expect(pool.summary.undecided).toBe(0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe("constraint-pool — decision_owner update", () => {
|
|
194
|
+
it("discovered(builder) → decision_recorded(builder): same owner preserved", () => {
|
|
195
|
+
const events = [
|
|
196
|
+
discovered("CST-001", 1, { decision_owner: "builder" }),
|
|
197
|
+
decisionRecorded("CST-001", 2, { decision_owner: "builder" }),
|
|
198
|
+
];
|
|
199
|
+
const pool = buildConstraintPool(events);
|
|
200
|
+
expect(findConstraint(pool, "CST-001").decision_owner).toBe("builder");
|
|
201
|
+
});
|
|
202
|
+
it("discovered(builder) → decision_recorded(product_owner): owner changed", () => {
|
|
203
|
+
const events = [
|
|
204
|
+
discovered("CST-001", 1, { decision_owner: "builder" }),
|
|
205
|
+
decisionRecorded("CST-001", 2, { decision_owner: "product_owner" }),
|
|
206
|
+
];
|
|
207
|
+
const pool = buildConstraintPool(events);
|
|
208
|
+
expect(findConstraint(pool, "CST-001").decision_owner).toBe("product_owner");
|
|
209
|
+
});
|
|
210
|
+
it("discovered(PO) → clarify → clarify_resolved(builder): owner changed via clarify", () => {
|
|
211
|
+
const events = [
|
|
212
|
+
discovered("CST-001", 1, { decision_owner: "product_owner" }),
|
|
213
|
+
clarifyRequested("CST-001", 2),
|
|
214
|
+
clarifyResolved("CST-001", 3, { decision_owner: "builder" }),
|
|
215
|
+
];
|
|
216
|
+
const pool = buildConstraintPool(events);
|
|
217
|
+
expect(findConstraint(pool, "CST-001").decision_owner).toBe("builder");
|
|
218
|
+
});
|
|
219
|
+
it("two decision_recorded with different owners → last revision wins", () => {
|
|
220
|
+
const events = [
|
|
221
|
+
discovered("CST-001", 1, { decision_owner: "builder" }),
|
|
222
|
+
decisionRecorded("CST-001", 2, { decision_owner: "builder" }),
|
|
223
|
+
decisionRecorded("CST-001", 3, { decision_owner: "product_owner" }),
|
|
224
|
+
];
|
|
225
|
+
const pool = buildConstraintPool(events);
|
|
226
|
+
const entry = findConstraint(pool, "CST-001");
|
|
227
|
+
expect(entry.decision_owner).toBe("product_owner");
|
|
228
|
+
expect(entry.decided_at).toBe(3);
|
|
229
|
+
});
|
|
230
|
+
it("decision_recorded(builder) → invalidated: preserves last decided owner", () => {
|
|
231
|
+
const events = [
|
|
232
|
+
discovered("CST-001", 1, { decision_owner: "product_owner" }),
|
|
233
|
+
decisionRecorded("CST-001", 2, { decision_owner: "builder" }),
|
|
234
|
+
invalidated("CST-001", 3),
|
|
235
|
+
];
|
|
236
|
+
const pool = buildConstraintPool(events);
|
|
237
|
+
const entry = findConstraint(pool, "CST-001");
|
|
238
|
+
expect(entry.status).toBe("invalidated");
|
|
239
|
+
expect(entry.decision_owner).toBe("builder");
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
describe("constraint-pool — conflict resolution", () => {
|
|
243
|
+
it("same constraint_id with decision_recorded twice → last revision wins", () => {
|
|
244
|
+
const events = [
|
|
245
|
+
discovered("CST-001", 1),
|
|
246
|
+
decisionRecorded("CST-001", 2, {
|
|
247
|
+
decision: "defer",
|
|
248
|
+
selected_option: "option A",
|
|
249
|
+
}),
|
|
250
|
+
decisionRecorded("CST-001", 3, {
|
|
251
|
+
decision: "inject",
|
|
252
|
+
selected_option: "option B",
|
|
253
|
+
}),
|
|
254
|
+
];
|
|
255
|
+
const pool = buildConstraintPool(events);
|
|
256
|
+
const entry = findConstraint(pool, "CST-001");
|
|
257
|
+
expect(entry.decision).toBe("inject");
|
|
258
|
+
expect(entry.selected_option).toBe("option B");
|
|
259
|
+
expect(entry.decided_at).toBe(3);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
describe("constraint-pool — empty pool", () => {
|
|
263
|
+
it("no events → empty pool", () => {
|
|
264
|
+
const pool = buildConstraintPool([]);
|
|
265
|
+
expect(pool.constraints).toHaveLength(0);
|
|
266
|
+
expect(pool.summary.total).toBe(0);
|
|
267
|
+
assertSummaryInvariants(pool);
|
|
268
|
+
});
|
|
269
|
+
it("no constraint events → empty pool", () => {
|
|
270
|
+
const nonConstraintEvent = {
|
|
271
|
+
event_id: "evt_1",
|
|
272
|
+
scope_id: "SC-TEST",
|
|
273
|
+
type: "align.locked",
|
|
274
|
+
ts: "2026-01-01T00:00:01Z",
|
|
275
|
+
revision: 1,
|
|
276
|
+
actor: "user",
|
|
277
|
+
state_before: "align_proposed",
|
|
278
|
+
state_after: "align_locked",
|
|
279
|
+
payload: {
|
|
280
|
+
locked_direction: "test",
|
|
281
|
+
locked_scope_boundaries: { in: [], out: [] },
|
|
282
|
+
locked_in_out: true,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
const pool = buildConstraintPool([nonConstraintEvent]);
|
|
286
|
+
expect(pool.constraints).toHaveLength(0);
|
|
287
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
288
|
+
});
|
|
289
|
+
it("isConstraintsResolved is true for empty pool", () => {
|
|
290
|
+
const pool = buildConstraintPool([]);
|
|
291
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
describe("constraint-pool — isConstraintsResolved", () => {
|
|
295
|
+
it("undecided > 0 → false", () => {
|
|
296
|
+
const events = [discovered("CST-001", 1), discovered("CST-002", 2)];
|
|
297
|
+
const pool = buildConstraintPool(events);
|
|
298
|
+
expect(pool.summary.undecided).toBe(2);
|
|
299
|
+
expect(isConstraintsResolved(pool)).toBe(false);
|
|
300
|
+
});
|
|
301
|
+
it("clarify_pending > 0 → false", () => {
|
|
302
|
+
const events = [
|
|
303
|
+
discovered("CST-001", 1),
|
|
304
|
+
clarifyRequested("CST-001", 2),
|
|
305
|
+
];
|
|
306
|
+
const pool = buildConstraintPool(events);
|
|
307
|
+
expect(pool.summary.clarify_pending).toBe(1);
|
|
308
|
+
expect(isConstraintsResolved(pool)).toBe(false);
|
|
309
|
+
});
|
|
310
|
+
it("all decided → true", () => {
|
|
311
|
+
const events = [
|
|
312
|
+
discovered("CST-001", 1),
|
|
313
|
+
discovered("CST-002", 2),
|
|
314
|
+
decisionRecorded("CST-001", 3),
|
|
315
|
+
decisionRecorded("CST-002", 4),
|
|
316
|
+
];
|
|
317
|
+
const pool = buildConstraintPool(events);
|
|
318
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
it("all invalidated → true", () => {
|
|
321
|
+
const events = [
|
|
322
|
+
discovered("CST-001", 1),
|
|
323
|
+
discovered("CST-002", 2),
|
|
324
|
+
invalidated("CST-001", 3),
|
|
325
|
+
invalidated("CST-002", 4),
|
|
326
|
+
];
|
|
327
|
+
const pool = buildConstraintPool(events);
|
|
328
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
329
|
+
});
|
|
330
|
+
it("decided + invalidated mix, no undecided/clarify → true", () => {
|
|
331
|
+
const events = [
|
|
332
|
+
discovered("CST-001", 1),
|
|
333
|
+
discovered("CST-002", 2),
|
|
334
|
+
discovered("CST-003", 3),
|
|
335
|
+
decisionRecorded("CST-001", 4),
|
|
336
|
+
decisionRecorded("CST-002", 5),
|
|
337
|
+
invalidated("CST-003", 6),
|
|
338
|
+
];
|
|
339
|
+
const pool = buildConstraintPool(events);
|
|
340
|
+
expect(pool.summary.decided).toBe(2);
|
|
341
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
342
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
343
|
+
});
|
|
344
|
+
it("decided 5 + undecided 1 + clarify_pending 1 → false", () => {
|
|
345
|
+
const events = [
|
|
346
|
+
discovered("CST-001", 1),
|
|
347
|
+
discovered("CST-002", 2),
|
|
348
|
+
discovered("CST-003", 3),
|
|
349
|
+
discovered("CST-004", 4),
|
|
350
|
+
discovered("CST-005", 5),
|
|
351
|
+
discovered("CST-006", 6),
|
|
352
|
+
discovered("CST-007", 7),
|
|
353
|
+
decisionRecorded("CST-001", 8),
|
|
354
|
+
decisionRecorded("CST-002", 9),
|
|
355
|
+
decisionRecorded("CST-003", 10),
|
|
356
|
+
decisionRecorded("CST-004", 11),
|
|
357
|
+
decisionRecorded("CST-005", 12),
|
|
358
|
+
clarifyRequested("CST-006", 13),
|
|
359
|
+
// CST-007 remains undecided
|
|
360
|
+
];
|
|
361
|
+
const pool = buildConstraintPool(events);
|
|
362
|
+
expect(pool.summary.decided).toBe(5);
|
|
363
|
+
expect(pool.summary.clarify_pending).toBe(1);
|
|
364
|
+
expect(pool.summary.undecided).toBe(1);
|
|
365
|
+
expect(isConstraintsResolved(pool)).toBe(false);
|
|
366
|
+
assertSummaryInvariants(pool);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
describe("constraint-pool — findConstraint", () => {
|
|
370
|
+
it("existing id → entry", () => {
|
|
371
|
+
const events = [discovered("CST-001", 1)];
|
|
372
|
+
const pool = buildConstraintPool(events);
|
|
373
|
+
expect(findConstraint(pool, "CST-001")).toBeDefined();
|
|
374
|
+
expect(findConstraint(pool, "CST-001").constraint_id).toBe("CST-001");
|
|
375
|
+
});
|
|
376
|
+
it("non-existing id → undefined", () => {
|
|
377
|
+
const events = [discovered("CST-001", 1)];
|
|
378
|
+
const pool = buildConstraintPool(events);
|
|
379
|
+
expect(findConstraint(pool, "CST-999")).toBeUndefined();
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
describe("constraint-pool — defense (skip invalid input)", () => {
|
|
383
|
+
it("decision_recorded for unknown constraint_id → skipped", () => {
|
|
384
|
+
const events = [decisionRecorded("CST-UNKNOWN", 1)];
|
|
385
|
+
const pool = buildConstraintPool(events);
|
|
386
|
+
expect(pool.constraints).toHaveLength(0);
|
|
387
|
+
});
|
|
388
|
+
it("clarify_requested for unknown constraint_id → skipped", () => {
|
|
389
|
+
const events = [clarifyRequested("CST-UNKNOWN", 1)];
|
|
390
|
+
const pool = buildConstraintPool(events);
|
|
391
|
+
expect(pool.constraints).toHaveLength(0);
|
|
392
|
+
});
|
|
393
|
+
it("duplicate constraint.discovered for same id → first one kept", () => {
|
|
394
|
+
const events = [
|
|
395
|
+
discovered("CST-001", 1, { severity: "required" }),
|
|
396
|
+
discovered("CST-001", 2, { severity: "recommended" }),
|
|
397
|
+
];
|
|
398
|
+
const pool = buildConstraintPool(events);
|
|
399
|
+
expect(pool.constraints).toHaveLength(1);
|
|
400
|
+
expect(findConstraint(pool, "CST-001").severity).toBe("required");
|
|
401
|
+
expect(findConstraint(pool, "CST-001").discovered_at).toBe(1);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
describe("constraint-pool — edge cases", () => {
|
|
405
|
+
it("clarify → resolved → clarify again (re-clarify cycle)", () => {
|
|
406
|
+
const events = [
|
|
407
|
+
discovered("CST-001", 1),
|
|
408
|
+
clarifyRequested("CST-001", 2),
|
|
409
|
+
clarifyResolved("CST-001", 3, { decision: "inject" }),
|
|
410
|
+
clarifyRequested("CST-001", 4),
|
|
411
|
+
];
|
|
412
|
+
const pool = buildConstraintPool(events);
|
|
413
|
+
const entry = findConstraint(pool, "CST-001");
|
|
414
|
+
expect(entry.status).toBe("clarify_pending");
|
|
415
|
+
expect(isConstraintsResolved(pool)).toBe(false);
|
|
416
|
+
});
|
|
417
|
+
it("invalidated → decision_recorded: decision overwrites (last-write-wins)", () => {
|
|
418
|
+
const events = [
|
|
419
|
+
discovered("CST-001", 1),
|
|
420
|
+
invalidated("CST-001", 2),
|
|
421
|
+
decisionRecorded("CST-001", 3, { decision: "defer" }),
|
|
422
|
+
];
|
|
423
|
+
const pool = buildConstraintPool(events);
|
|
424
|
+
const entry = findConstraint(pool, "CST-001");
|
|
425
|
+
expect(entry.status).toBe("decided");
|
|
426
|
+
expect(entry.decision).toBe("defer");
|
|
427
|
+
});
|
|
428
|
+
it("discovered with empty source_refs", () => {
|
|
429
|
+
const emptyRefsEvent = {
|
|
430
|
+
event_id: "evt_1",
|
|
431
|
+
scope_id: "SC-TEST",
|
|
432
|
+
type: "constraint.discovered",
|
|
433
|
+
ts: "2026-01-01T00:00:01Z",
|
|
434
|
+
revision: 1,
|
|
435
|
+
actor: "system",
|
|
436
|
+
state_before: "surface_confirmed",
|
|
437
|
+
state_after: "surface_confirmed",
|
|
438
|
+
payload: {
|
|
439
|
+
constraint_id: "CST-001",
|
|
440
|
+
perspective: "code",
|
|
441
|
+
summary: "test constraint",
|
|
442
|
+
severity: "recommended",
|
|
443
|
+
discovery_stage: "draft_phase2",
|
|
444
|
+
decision_owner: "product_owner",
|
|
445
|
+
impact_if_ignored: "test impact",
|
|
446
|
+
source_refs: [],
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
const pool = buildConstraintPool([emptyRefsEvent]);
|
|
450
|
+
const entry = findConstraint(pool, "CST-001");
|
|
451
|
+
expect(entry).toBeDefined();
|
|
452
|
+
expect(entry.source_refs).toEqual([]);
|
|
453
|
+
});
|
|
454
|
+
it("clarify_resolved for unknown constraint_id skipped", () => {
|
|
455
|
+
const events = [clarifyResolved("CST-UNKNOWN", 1)];
|
|
456
|
+
const pool = buildConstraintPool(events);
|
|
457
|
+
expect(pool.constraints).toHaveLength(0);
|
|
458
|
+
});
|
|
459
|
+
it("many constraints (10) summary invariants", () => {
|
|
460
|
+
const severities = [
|
|
461
|
+
"required", "recommended", "required", "recommended", "required",
|
|
462
|
+
"recommended", "required", "recommended", "required", "recommended",
|
|
463
|
+
];
|
|
464
|
+
const events = severities.map((sev, i) => discovered(`CST-${String(i + 1).padStart(3, "0")}`, i + 1, { severity: sev }));
|
|
465
|
+
// Decide some, clarify some, invalidate some
|
|
466
|
+
events.push(decisionRecorded("CST-001", 11));
|
|
467
|
+
events.push(decisionRecorded("CST-002", 12));
|
|
468
|
+
events.push(decisionRecorded("CST-003", 13));
|
|
469
|
+
events.push(clarifyRequested("CST-004", 14));
|
|
470
|
+
events.push(clarifyRequested("CST-005", 15));
|
|
471
|
+
events.push(invalidated("CST-006", 16));
|
|
472
|
+
events.push(invalidated("CST-007", 17));
|
|
473
|
+
// CST-008, CST-009, CST-010 remain undecided
|
|
474
|
+
const pool = buildConstraintPool(events);
|
|
475
|
+
assertSummaryInvariants(pool);
|
|
476
|
+
expect(pool.summary.total).toBe(10);
|
|
477
|
+
expect(pool.summary.decided).toBe(3);
|
|
478
|
+
expect(pool.summary.clarify_pending).toBe(2);
|
|
479
|
+
expect(pool.summary.invalidated).toBe(2);
|
|
480
|
+
expect(pool.summary.undecided).toBe(3);
|
|
481
|
+
expect(pool.summary.decided +
|
|
482
|
+
pool.summary.clarify_pending +
|
|
483
|
+
pool.summary.invalidated +
|
|
484
|
+
pool.summary.undecided).toBe(pool.summary.total);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
describe("constraint-pool — decision change (re-decision)", () => {
|
|
488
|
+
it("decision_recorded twice changes decision value", () => {
|
|
489
|
+
const events = [
|
|
490
|
+
discovered("CST-001", 1),
|
|
491
|
+
decisionRecorded("CST-001", 2, { decision: "inject", selected_option: "option A", rationale: "first reason" }),
|
|
492
|
+
decisionRecorded("CST-001", 3, { decision: "defer", selected_option: "option B", rationale: "changed mind" }),
|
|
493
|
+
];
|
|
494
|
+
const pool = buildConstraintPool(events);
|
|
495
|
+
const entry = findConstraint(pool, "CST-001");
|
|
496
|
+
expect(entry.status).toBe("decided");
|
|
497
|
+
expect(entry.decision).toBe("defer");
|
|
498
|
+
expect(entry.selected_option).toBe("option B");
|
|
499
|
+
expect(entry.rationale).toBe("changed mind");
|
|
500
|
+
expect(entry.decided_at).toBe(3);
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
describe("constraint-pool — invalidation persistence", () => {
|
|
504
|
+
it("invalidated → decided → invalidated: invalidation_reason from latest invalidation", () => {
|
|
505
|
+
const events = [
|
|
506
|
+
discovered("CST-001", 1),
|
|
507
|
+
invalidated("CST-001", 2), // first invalidation (reason: "no longer relevant")
|
|
508
|
+
decisionRecorded("CST-001", 3, { decision: "inject" }), // reactivated
|
|
509
|
+
invalidated("CST-001", 4), // second invalidation (reason: "no longer relevant")
|
|
510
|
+
];
|
|
511
|
+
const pool = buildConstraintPool(events);
|
|
512
|
+
const entry = findConstraint(pool, "CST-001");
|
|
513
|
+
expect(entry.status).toBe("invalidated");
|
|
514
|
+
expect(entry.invalidation_reason).toBe("no longer relevant");
|
|
515
|
+
// The decision fields from step 3 should still be present (not cleared by invalidation)
|
|
516
|
+
expect(entry.decision).toBe("inject");
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
describe("constraint-pool — complex scenario summary accuracy", () => {
|
|
520
|
+
it("complex mixed scenario: 3 required + 4 recommended, various statuses", () => {
|
|
521
|
+
const events = [
|
|
522
|
+
// 3 required
|
|
523
|
+
discovered("CST-R1", 1, { severity: "required", decision_owner: "product_owner" }),
|
|
524
|
+
discovered("CST-R2", 2, { severity: "required", decision_owner: "product_owner" }),
|
|
525
|
+
discovered("CST-R3", 3, { severity: "required", decision_owner: "builder" }),
|
|
526
|
+
// 4 recommended
|
|
527
|
+
discovered("CST-C1", 4, { severity: "recommended", decision_owner: "product_owner" }),
|
|
528
|
+
discovered("CST-C2", 5, { severity: "recommended", decision_owner: "builder" }),
|
|
529
|
+
discovered("CST-C3", 6, { severity: "recommended", decision_owner: "product_owner" }),
|
|
530
|
+
discovered("CST-C4", 7, { severity: "recommended", decision_owner: "builder" }),
|
|
531
|
+
// Decide some
|
|
532
|
+
decisionRecorded("CST-R1", 8, { decision: "inject" }),
|
|
533
|
+
decisionRecorded("CST-C1", 9, { decision: "defer" }),
|
|
534
|
+
// Clarify one
|
|
535
|
+
clarifyRequested("CST-R2", 10),
|
|
536
|
+
// Invalidate one
|
|
537
|
+
invalidated("CST-C2", 11),
|
|
538
|
+
// CST-R3, CST-C3, CST-C4 remain undecided
|
|
539
|
+
];
|
|
540
|
+
const pool = buildConstraintPool(events);
|
|
541
|
+
assertSummaryInvariants(pool);
|
|
542
|
+
expect(pool.summary.total).toBe(7);
|
|
543
|
+
expect(pool.summary.required).toBe(3);
|
|
544
|
+
expect(pool.summary.recommended).toBe(4);
|
|
545
|
+
expect(pool.summary.decided).toBe(2);
|
|
546
|
+
expect(pool.summary.clarify_pending).toBe(1);
|
|
547
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
548
|
+
expect(pool.summary.undecided).toBe(3);
|
|
549
|
+
expect(isConstraintsResolved(pool)).toBe(false);
|
|
550
|
+
});
|
|
551
|
+
it("all constraints resolved through mix of decided + invalidated", () => {
|
|
552
|
+
const events = [
|
|
553
|
+
discovered("CST-001", 1, { severity: "required" }),
|
|
554
|
+
discovered("CST-002", 2, { severity: "recommended" }),
|
|
555
|
+
discovered("CST-003", 3, { severity: "required" }),
|
|
556
|
+
decisionRecorded("CST-001", 4),
|
|
557
|
+
invalidated("CST-002", 5),
|
|
558
|
+
clarifyRequested("CST-003", 6),
|
|
559
|
+
clarifyResolved("CST-003", 7),
|
|
560
|
+
];
|
|
561
|
+
const pool = buildConstraintPool(events);
|
|
562
|
+
assertSummaryInvariants(pool);
|
|
563
|
+
expect(pool.summary.decided).toBe(2);
|
|
564
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
565
|
+
expect(pool.summary.undecided).toBe(0);
|
|
566
|
+
expect(pool.summary.clarify_pending).toBe(0);
|
|
567
|
+
expect(isConstraintsResolved(pool)).toBe(true);
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
describe("constraint-pool — requires_policy_change propagation", () => {
|
|
571
|
+
it("discovered with requires_policy_change=true propagates to entry", () => {
|
|
572
|
+
const evt = {
|
|
573
|
+
event_id: "evt_1", scope_id: "SC-TEST", type: "constraint.discovered",
|
|
574
|
+
ts: "2026-01-01T00:00:01Z", revision: 1, actor: "system",
|
|
575
|
+
state_before: "surface_confirmed", state_after: "surface_confirmed",
|
|
576
|
+
payload: {
|
|
577
|
+
constraint_id: "CST-001", perspective: "policy", summary: "test",
|
|
578
|
+
severity: "required", discovery_stage: "draft_phase2",
|
|
579
|
+
decision_owner: "product_owner", impact_if_ignored: "test",
|
|
580
|
+
source_refs: [{ source: "test.ts", detail: "d" }],
|
|
581
|
+
requires_policy_change: true,
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
const pool = buildConstraintPool([evt]);
|
|
585
|
+
expect(findConstraint(pool, "CST-001").requires_policy_change).toBe(true);
|
|
586
|
+
});
|
|
587
|
+
it("discovered without requires_policy_change defaults to false", () => {
|
|
588
|
+
const events = [discovered("CST-001", 1)];
|
|
589
|
+
const pool = buildConstraintPool(events);
|
|
590
|
+
expect(findConstraint(pool, "CST-001").requires_policy_change).toBe(false);
|
|
591
|
+
});
|
|
592
|
+
it("evidence_updated with requires_policy_change updates the entry", () => {
|
|
593
|
+
const events = [
|
|
594
|
+
discovered("CST-001", 1),
|
|
595
|
+
{
|
|
596
|
+
event_id: "evt_2", scope_id: "SC-TEST", type: "constraint.evidence_updated",
|
|
597
|
+
ts: "2026-01-01T00:00:02Z", revision: 2, actor: "system",
|
|
598
|
+
state_before: "surface_confirmed", state_after: "surface_confirmed",
|
|
599
|
+
payload: {
|
|
600
|
+
constraint_id: "CST-001",
|
|
601
|
+
evidence_status: "verified",
|
|
602
|
+
requires_policy_change: true,
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
];
|
|
606
|
+
const pool = buildConstraintPool(events);
|
|
607
|
+
const entry = findConstraint(pool, "CST-001");
|
|
608
|
+
expect(entry.requires_policy_change).toBe(true);
|
|
609
|
+
expect(entry.evidence_status).toBe("verified");
|
|
610
|
+
});
|
|
611
|
+
it("evidence_updated without requires_policy_change does not change the field", () => {
|
|
612
|
+
const discoverEvt = {
|
|
613
|
+
event_id: "evt_1", scope_id: "SC-TEST", type: "constraint.discovered",
|
|
614
|
+
ts: "2026-01-01T00:00:01Z", revision: 1, actor: "system",
|
|
615
|
+
state_before: "surface_confirmed", state_after: "surface_confirmed",
|
|
616
|
+
payload: {
|
|
617
|
+
constraint_id: "CST-001", perspective: "policy", summary: "test",
|
|
618
|
+
severity: "required", discovery_stage: "draft_phase2",
|
|
619
|
+
decision_owner: "product_owner", impact_if_ignored: "test",
|
|
620
|
+
source_refs: [{ source: "test.ts", detail: "d" }],
|
|
621
|
+
requires_policy_change: true,
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
const events = [
|
|
625
|
+
discoverEvt,
|
|
626
|
+
{
|
|
627
|
+
event_id: "evt_2", scope_id: "SC-TEST", type: "constraint.evidence_updated",
|
|
628
|
+
ts: "2026-01-01T00:00:02Z", revision: 2, actor: "system",
|
|
629
|
+
state_before: "surface_confirmed", state_after: "surface_confirmed",
|
|
630
|
+
payload: {
|
|
631
|
+
constraint_id: "CST-001",
|
|
632
|
+
evidence_status: "verified",
|
|
633
|
+
// requires_policy_change not specified
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
];
|
|
637
|
+
const pool = buildConstraintPool(events);
|
|
638
|
+
expect(findConstraint(pool, "CST-001").requires_policy_change).toBe(true);
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
describe("constraint-pool — summary invariants", () => {
|
|
642
|
+
it("invariants hold for mixed status pool", () => {
|
|
643
|
+
const events = [
|
|
644
|
+
discovered("CST-001", 1, { severity: "required" }),
|
|
645
|
+
discovered("CST-002", 2, { severity: "recommended" }),
|
|
646
|
+
discovered("CST-003", 3, { severity: "required" }),
|
|
647
|
+
discovered("CST-004", 4, { severity: "recommended" }),
|
|
648
|
+
decisionRecorded("CST-001", 5),
|
|
649
|
+
clarifyRequested("CST-002", 6),
|
|
650
|
+
invalidated("CST-003", 7),
|
|
651
|
+
// CST-004 remains undecided
|
|
652
|
+
];
|
|
653
|
+
const pool = buildConstraintPool(events);
|
|
654
|
+
assertSummaryInvariants(pool);
|
|
655
|
+
expect(pool.summary.total).toBe(4);
|
|
656
|
+
expect(pool.summary.required).toBe(2);
|
|
657
|
+
expect(pool.summary.recommended).toBe(2);
|
|
658
|
+
expect(pool.summary.decided).toBe(1);
|
|
659
|
+
expect(pool.summary.clarify_pending).toBe(1);
|
|
660
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
661
|
+
expect(pool.summary.undecided).toBe(1);
|
|
662
|
+
});
|
|
663
|
+
it("severity counts include invalidated constraints", () => {
|
|
664
|
+
const events = [
|
|
665
|
+
discovered("CST-001", 1, { severity: "required" }),
|
|
666
|
+
invalidated("CST-001", 2),
|
|
667
|
+
];
|
|
668
|
+
const pool = buildConstraintPool(events);
|
|
669
|
+
expect(pool.summary.required).toBe(1);
|
|
670
|
+
expect(pool.summary.invalidated).toBe(1);
|
|
671
|
+
expect(pool.summary.total).toBe(1);
|
|
672
|
+
assertSummaryInvariants(pool);
|
|
673
|
+
});
|
|
674
|
+
});
|