onto-mcp 0.3.2 → 0.4.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/processes/reconstruct/actionable-ontology-seed-recomposition-design.md +447 -0
- package/.onto/processes/reconstruct/foundry-style-ontology-seed-contract.md +934 -0
- package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +303 -725
- package/.onto/processes/reconstruct/reconstruct-contract-registry.yaml +1645 -0
- package/.onto/processes/reconstruct/reconstruct-execution-ux-contract.md +26 -22
- package/.onto/processes/reconstruct/source-profile-contract.md +49 -23
- package/.onto/processes/reconstruct/source-profiles/code.md +6 -3
- package/.onto/processes/reconstruct/source-profiles/database.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/document.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +5 -4
- package/.onto/processes/review/review-execution-ux-contract.md +40 -0
- package/.onto/processes/shared/pipeline-execution-ledger-contract.md +26 -10
- package/.onto/processes/shared/target-material-kind-contract.md +29 -16
- package/AGENTS.md +6 -4
- package/README.md +135 -76
- package/dist/cli.js +8 -8
- package/dist/core-api/reconstruct-api.js +117 -31
- package/dist/core-api/review-api.js +47 -0
- package/dist/core-runtime/cli/codex-review-unit-executor.js +39 -2
- package/dist/core-runtime/cli/complete-review-session.js +2 -2
- package/dist/core-runtime/cli/mock-review-unit-executor.js +1 -1
- package/dist/core-runtime/cli/review-invoke.js +9 -9
- package/dist/core-runtime/cli/run-review-prompt-execution.js +39 -5
- package/dist/core-runtime/cli/spawn-watcher.js +266 -47
- package/dist/core-runtime/cli/start-review-session.js +3 -3
- package/dist/core-runtime/llm/llm-caller.js +11 -0
- package/dist/core-runtime/llm/llm-tool-loop.js +2 -0
- package/dist/core-runtime/observability/runtime-stream-observation.js +118 -0
- package/dist/core-runtime/onboard/cli-host.js +149 -0
- package/dist/core-runtime/onboard/host-target.js +22 -0
- package/dist/core-runtime/onboard/json-config-host.js +122 -0
- package/dist/core-runtime/onboard/path-scan.js +26 -0
- package/dist/core-runtime/onboard/prompt.js +51 -0
- package/dist/core-runtime/onboard/register.js +207 -0
- package/dist/core-runtime/onboard/types.js +27 -0
- package/dist/core-runtime/reconstruct/actionable-seed-validation.js +1777 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +10 -4
- package/dist/core-runtime/reconstruct/contract-registry.js +623 -0
- package/dist/core-runtime/reconstruct/domain-id.js +10 -0
- package/dist/core-runtime/reconstruct/governing-snapshot.js +716 -0
- package/dist/core-runtime/reconstruct/material-profile-validation.js +191 -0
- package/dist/core-runtime/reconstruct/materialize-preparation.js +49 -11
- package/dist/core-runtime/reconstruct/pipeline-execution-ledger.js +269 -79
- package/dist/core-runtime/reconstruct/post-seed-validation.js +1194 -51
- package/dist/core-runtime/reconstruct/record.js +104 -20
- package/dist/core-runtime/reconstruct/run.js +2107 -413
- package/dist/core-runtime/reconstruct/seed-claim-projections.js +268 -0
- package/dist/core-runtime/reconstruct/source-profiles.js +93 -4
- package/dist/core-runtime/reconstruct/terminal-validation.js +807 -0
- package/dist/core-runtime/review/review-invocation-runner.js +4 -4
- package/dist/mcp/server.js +110 -38
- package/dist/mcp/tool-schemas.js +20 -6
- package/package.json +8 -17
- package/scripts/onto-review-watch.sh +486 -0
- package/scripts/onto-runtime-watch.sh +122 -0
- package/scripts/postinstall-hint.js +22 -0
- package/.onto/processes/reconstruct/top-level-concept-discovery-contract.md +0 -387
- package/dist/core-runtime/cli/bootstrap-review-binding.js +0 -186
- package/dist/core-runtime/cli/codex-nested-dispatch.test.js +0 -390
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +0 -335
- package/dist/core-runtime/cli/coordinator-helpers.js +0 -583
- package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +0 -167
- package/dist/core-runtime/cli/coordinator-state-machine.js +0 -794
- package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +0 -615
- package/dist/core-runtime/cli/e2e-start-review-session.test.js +0 -312
- package/dist/core-runtime/cli/health.js +0 -44
- package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +0 -567
- package/dist/core-runtime/cli/materialize-review-execution-preparation.js +0 -104
- package/dist/core-runtime/cli/migrate-session-roots.js +0 -118
- package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +0 -106
- package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +0 -268
- package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +0 -136
- package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +0 -201
- package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +0 -192
- package/dist/core-runtime/cli/session-root-guard.js +0 -168
- package/dist/core-runtime/cli/spawn-watcher.test.js +0 -457
- package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +0 -79
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +0 -412
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +0 -351
- package/dist/core-runtime/cli/topology-executor-mapping.js +0 -139
- package/dist/core-runtime/cli/topology-executor-mapping.test.js +0 -173
- package/dist/core-runtime/cli/write-review-interpretation.js +0 -81
- package/dist/core-runtime/config/onto-config-cli.js +0 -278
- package/dist/core-runtime/config/onto-config-key-path.js +0 -288
- package/dist/core-runtime/config/onto-config-key-path.test.js +0 -195
- package/dist/core-runtime/config/onto-config-preview.js +0 -108
- package/dist/core-runtime/config/onto-config-preview.test.js +0 -132
- package/dist/core-runtime/discovery/config-chain.js +0 -118
- package/dist/core-runtime/discovery/config-chain.test.js +0 -103
- package/dist/core-runtime/discovery/config-profile.js +0 -199
- package/dist/core-runtime/discovery/config-profile.test.js +0 -233
- package/dist/core-runtime/discovery/host-detection.test.js +0 -186
- package/dist/core-runtime/discovery/installation-paths.test.js +0 -65
- package/dist/core-runtime/discovery/lens-registry.test.js +0 -81
- package/dist/core-runtime/discovery/path-normalization.test.js +0 -22
- package/dist/core-runtime/discovery/plugin-path.js +0 -72
- package/dist/core-runtime/discovery/plugin-path.test.js +0 -95
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +0 -344
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +0 -915
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +0 -564
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +0 -708
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +0 -165
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +0 -227
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +0 -59
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +0 -205
- package/dist/core-runtime/evolve/adapters/methodology/adapter.js +0 -16
- package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +0 -9
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +0 -298
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +0 -70
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +0 -46
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +0 -73
- package/dist/core-runtime/evolve/adapters/registry.js +0 -47
- package/dist/core-runtime/evolve/adapters/registry.test.js +0 -67
- package/dist/core-runtime/evolve/cli.js +0 -256
- package/dist/core-runtime/evolve/commands/align.js +0 -194
- package/dist/core-runtime/evolve/commands/align.test.js +0 -82
- package/dist/core-runtime/evolve/commands/apply.js +0 -161
- package/dist/core-runtime/evolve/commands/apply.test.js +0 -138
- package/dist/core-runtime/evolve/commands/close.js +0 -39
- package/dist/core-runtime/evolve/commands/close.test.js +0 -99
- package/dist/core-runtime/evolve/commands/defer.js +0 -40
- package/dist/core-runtime/evolve/commands/defer.test.js +0 -134
- package/dist/core-runtime/evolve/commands/draft.js +0 -323
- package/dist/core-runtime/evolve/commands/draft.test.js +0 -178
- package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +0 -208
- package/dist/core-runtime/evolve/commands/error-messages.js +0 -125
- package/dist/core-runtime/evolve/commands/error-messages.test.js +0 -167
- package/dist/core-runtime/evolve/commands/propose-align.js +0 -222
- package/dist/core-runtime/evolve/commands/propose-align.test.js +0 -136
- package/dist/core-runtime/evolve/commands/reconstruct.js +0 -330
- package/dist/core-runtime/evolve/commands/reconstruct.test.js +0 -278
- package/dist/core-runtime/evolve/commands/shared.js +0 -22
- package/dist/core-runtime/evolve/commands/stale-check.js +0 -103
- package/dist/core-runtime/evolve/commands/stale-check.test.js +0 -84
- package/dist/core-runtime/evolve/commands/start.js +0 -887
- package/dist/core-runtime/evolve/commands/start.test.js +0 -396
- package/dist/core-runtime/evolve/config/project-config.js +0 -99
- package/dist/core-runtime/evolve/config/project-config.test.js +0 -170
- package/dist/core-runtime/evolve/renderers/align-packet.js +0 -280
- package/dist/core-runtime/evolve/renderers/align-packet.test.js +0 -332
- package/dist/core-runtime/evolve/renderers/draft-packet.js +0 -303
- package/dist/core-runtime/evolve/renderers/draft-packet.test.js +0 -377
- package/dist/core-runtime/evolve/renderers/format.js +0 -5
- package/dist/core-runtime/evolve/renderers/scope-md.js +0 -237
- package/dist/core-runtime/evolve/renderers/scope-md.test.js +0 -306
- package/dist/core-runtime/govern/cli.js +0 -369
- package/dist/core-runtime/govern/cli.test.js +0 -314
- package/dist/core-runtime/govern/drift-engine.js +0 -103
- package/dist/core-runtime/govern/drift-engine.test.js +0 -319
- package/dist/core-runtime/govern/promote-principle.js +0 -206
- package/dist/core-runtime/govern/promote-principle.test.js +0 -368
- package/dist/core-runtime/govern/queue.js +0 -81
- package/dist/core-runtime/govern/types.js +0 -16
- package/dist/core-runtime/install/cli.js +0 -530
- package/dist/core-runtime/install/detect.js +0 -128
- package/dist/core-runtime/install/detect.test.js +0 -155
- package/dist/core-runtime/install/gitignore-update.js +0 -74
- package/dist/core-runtime/install/gitignore-update.test.js +0 -64
- package/dist/core-runtime/install/install-integration.test.js +0 -373
- package/dist/core-runtime/install/prompts.js +0 -389
- package/dist/core-runtime/install/prompts.test.js +0 -293
- package/dist/core-runtime/install/types.js +0 -26
- package/dist/core-runtime/install/validation.js +0 -295
- package/dist/core-runtime/install/validation.test.js +0 -313
- package/dist/core-runtime/install/writer.js +0 -254
- package/dist/core-runtime/install/writer.test.js +0 -218
- package/dist/core-runtime/learning/extractor.js +0 -461
- package/dist/core-runtime/learning/feedback.js +0 -179
- package/dist/core-runtime/learning/health-report.js +0 -165
- package/dist/core-runtime/learning/health-report.test.js +0 -169
- package/dist/core-runtime/learning/loader.js +0 -388
- package/dist/core-runtime/learning/loader.test.js +0 -102
- package/dist/core-runtime/learning/promote/apply-state.js +0 -240
- package/dist/core-runtime/learning/promote/audit-obligation.js +0 -195
- package/dist/core-runtime/learning/promote/collector.js +0 -432
- package/dist/core-runtime/learning/promote/degraded-state.js +0 -125
- package/dist/core-runtime/learning/promote/domain-doc-proposer.js +0 -166
- package/dist/core-runtime/learning/promote/e2e-promote.test.js +0 -6385
- package/dist/core-runtime/learning/promote/health-snapshot.js +0 -150
- package/dist/core-runtime/learning/promote/insight-reclassifier.js +0 -544
- package/dist/core-runtime/learning/promote/judgment-auditor.js +0 -517
- package/dist/core-runtime/learning/promote/panel-reviewer.js +0 -1158
- package/dist/core-runtime/learning/promote/promote-executor.js +0 -1675
- package/dist/core-runtime/learning/promote/promoter.js +0 -307
- package/dist/core-runtime/learning/promote/retirement.js +0 -122
- package/dist/core-runtime/learning/promote/types.js +0 -23
- package/dist/core-runtime/learning/prompt-sections.js +0 -51
- package/dist/core-runtime/learning/shared/artifact-registry-init.js +0 -45
- package/dist/core-runtime/learning/shared/artifact-registry.js +0 -254
- package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +0 -73
- package/dist/core-runtime/learning/shared/audit-state.js +0 -99
- package/dist/core-runtime/learning/shared/duplicate-check.js +0 -28
- package/dist/core-runtime/learning/shared/llm-caller.js +0 -831
- package/dist/core-runtime/learning/shared/llm-caller.test.js +0 -601
- package/dist/core-runtime/learning/shared/llm-tool-loop.js +0 -393
- package/dist/core-runtime/learning/shared/mode.js +0 -25
- package/dist/core-runtime/learning/shared/paths.js +0 -84
- package/dist/core-runtime/learning/shared/paths.test.js +0 -79
- package/dist/core-runtime/learning/shared/patterns.js +0 -37
- package/dist/core-runtime/learning/shared/recoverability.js +0 -355
- package/dist/core-runtime/learning/shared/recovery-context.js +0 -374
- package/dist/core-runtime/learning/shared/scope.js +0 -1
- package/dist/core-runtime/learning/shared/semantic-classifier.js +0 -94
- package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +0 -42
- package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +0 -37
- package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +0 -39
- package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +0 -41
- package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +0 -38
- package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +0 -113
- package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +0 -36
- package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +0 -48
- package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/spec-helpers.js +0 -64
- package/dist/core-runtime/learning/usage-tracker.js +0 -190
- package/dist/core-runtime/learning/usage-tracker.test.js +0 -176
- package/dist/core-runtime/onboard/detect-review-axes.js +0 -122
- package/dist/core-runtime/onboard/detect-review-axes.test.js +0 -127
- package/dist/core-runtime/onboard/write-review-block.js +0 -188
- package/dist/core-runtime/onboard/write-review-block.test.js +0 -240
- package/dist/core-runtime/readers/brownfield-builder.js +0 -150
- package/dist/core-runtime/readers/brownfield-builder.test.js +0 -136
- package/dist/core-runtime/readers/code-chunk-collector.js +0 -53
- package/dist/core-runtime/readers/code-chunk-collector.test.js +0 -136
- package/dist/core-runtime/readers/file-utils.js +0 -240
- package/dist/core-runtime/readers/file-utils.test.js +0 -146
- package/dist/core-runtime/readers/lexicon-citation-check.js +0 -93
- package/dist/core-runtime/readers/lexicon-citation-check.test.js +0 -77
- package/dist/core-runtime/readers/mcp-figma.js +0 -30
- package/dist/core-runtime/readers/mcp-figma.test.js +0 -82
- package/dist/core-runtime/readers/mcp-generic.js +0 -31
- package/dist/core-runtime/readers/mcp-generic.test.js +0 -76
- package/dist/core-runtime/readers/ontology-index.js +0 -148
- package/dist/core-runtime/readers/ontology-index.test.js +0 -245
- package/dist/core-runtime/readers/ontology-query.js +0 -168
- package/dist/core-runtime/readers/ontology-query.test.js +0 -311
- package/dist/core-runtime/readers/ontology-resolve.js +0 -48
- package/dist/core-runtime/readers/ontology-resolve.test.js +0 -48
- package/dist/core-runtime/readers/patterns/index.js +0 -7
- package/dist/core-runtime/readers/review-log.js +0 -213
- package/dist/core-runtime/readers/review-log.test.js +0 -313
- package/dist/core-runtime/readers/scan-local.js +0 -102
- package/dist/core-runtime/readers/scan-local.test.js +0 -102
- package/dist/core-runtime/readers/scan-tarball.js +0 -121
- package/dist/core-runtime/readers/scan-tarball.test.js +0 -283
- package/dist/core-runtime/readers/scan-vault.js +0 -34
- package/dist/core-runtime/readers/scan-vault.test.js +0 -81
- package/dist/core-runtime/readers/types.js +0 -42
- package/dist/core-runtime/readers/types.test.js +0 -94
- package/dist/core-runtime/readers/viewpoint-collectors.js +0 -229
- package/dist/core-runtime/reconstruct/seed-candidate-validation.js +0 -385
- package/dist/core-runtime/review/citation-audit.test.js +0 -165
- package/dist/core-runtime/review/execution-plan-resolver.js +0 -247
- package/dist/core-runtime/review/execution-plan-resolver.test.js +0 -243
- package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +0 -246
- package/dist/core-runtime/review/execution-topology-resolver.js +0 -401
- package/dist/core-runtime/review/execution-topology-resolver.test.js +0 -315
- package/dist/core-runtime/review/inline-context-embedder.test.js +0 -154
- package/dist/core-runtime/review/legacy-mode-policy.js +0 -88
- package/dist/core-runtime/review/materializers-effort-persist.test.js +0 -79
- package/dist/core-runtime/review/ontology-path-classifier.js +0 -179
- package/dist/core-runtime/review/ontology-path-classifier.test.js +0 -216
- package/dist/core-runtime/review/packet-boundary-policy.test.js +0 -107
- package/dist/core-runtime/review/participating-lens-paths.test.js +0 -73
- package/dist/core-runtime/review/review-config-legacy-translate.js +0 -244
- package/dist/core-runtime/review/review-config-legacy-translate.test.js +0 -161
- package/dist/core-runtime/review/review-config-validator.js +0 -289
- package/dist/core-runtime/review/review-config-validator.test.js +0 -236
- package/dist/core-runtime/review/shape-pipeline-audit.test.js +0 -311
- package/dist/core-runtime/review/shape-to-topology-id.js +0 -117
- package/dist/core-runtime/review/shape-to-topology-id.test.js +0 -132
- package/dist/core-runtime/review/topology-shape-derivation.js +0 -155
- package/dist/core-runtime/review/topology-shape-derivation.test.js +0 -195
- package/dist/core-runtime/scope-runtime/constants.js +0 -12
- package/dist/core-runtime/scope-runtime/constraint-pool.js +0 -166
- package/dist/core-runtime/scope-runtime/constraint-pool.test.js +0 -674
- package/dist/core-runtime/scope-runtime/domain-validation-log.js +0 -135
- package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +0 -156
- package/dist/core-runtime/scope-runtime/eval-persistence.js +0 -65
- package/dist/core-runtime/scope-runtime/eval-persistence.test.js +0 -84
- package/dist/core-runtime/scope-runtime/event-pipeline.js +0 -64
- package/dist/core-runtime/scope-runtime/event-pipeline.test.js +0 -450
- package/dist/core-runtime/scope-runtime/event-store.js +0 -39
- package/dist/core-runtime/scope-runtime/event-store.test.js +0 -95
- package/dist/core-runtime/scope-runtime/gate-guard.js +0 -348
- package/dist/core-runtime/scope-runtime/gate-guard.test.js +0 -1047
- package/dist/core-runtime/scope-runtime/hash.js +0 -4
- package/dist/core-runtime/scope-runtime/hash.test.js +0 -33
- package/dist/core-runtime/scope-runtime/id.js +0 -4
- package/dist/core-runtime/scope-runtime/id.test.js +0 -17
- package/dist/core-runtime/scope-runtime/reducer.js +0 -297
- package/dist/core-runtime/scope-runtime/reducer.test.js +0 -759
- package/dist/core-runtime/scope-runtime/scope-manager.js +0 -161
- package/dist/core-runtime/scope-runtime/state-machine.js +0 -309
- package/dist/core-runtime/scope-runtime/state-machine.test.js +0 -704
- package/dist/core-runtime/scope-runtime/types.js +0 -116
- package/dist/core-runtime/scope-runtime/types.test.js +0 -69
- package/dist/core-runtime/translate/render-for-user.js +0 -169
- package/dist/core-runtime/translate/render-for-user.test.js +0 -122
- package/dist/providers/capability-contract.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const RECONSTRUCT_STAGE_IDS = [
|
|
2
2
|
"invocation_binding",
|
|
3
3
|
"target_material_profile",
|
|
4
|
+
"target_material_profile_validation",
|
|
4
5
|
"source_inventory",
|
|
5
6
|
"initial_source_frontier",
|
|
6
7
|
"source_observation",
|
|
@@ -10,10 +11,11 @@ export const RECONSTRUCT_STAGE_IDS = [
|
|
|
10
11
|
"exploration_synthesis",
|
|
11
12
|
"source_frontier",
|
|
12
13
|
"source_frontier_validation",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"candidate_inventory",
|
|
15
|
+
"candidate_disposition",
|
|
16
|
+
"candidate_disposition_validation",
|
|
17
|
+
"ontology_seed",
|
|
18
|
+
"ontology_seed_validation",
|
|
17
19
|
"claim_realization",
|
|
18
20
|
"claim_realization_validation",
|
|
19
21
|
"seed_confirmation",
|
|
@@ -28,6 +30,10 @@ export const RECONSTRUCT_STAGE_IDS = [
|
|
|
28
30
|
"revision_proposal_validation",
|
|
29
31
|
"metrics",
|
|
30
32
|
"stop_decision",
|
|
33
|
+
"pre_handoff_run_manifest_validation",
|
|
34
|
+
"handoff_decision_validation",
|
|
31
35
|
"final_output",
|
|
36
|
+
"final_output_provenance_validation",
|
|
32
37
|
"record_assembly",
|
|
38
|
+
"post_publication_run_manifest_validation",
|
|
33
39
|
];
|
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parse as parseYaml } from "yaml";
|
|
5
|
+
import { isTargetMaterialKind, } from "../target-material-kind.js";
|
|
6
|
+
const PROFILE_MIGRATION_FIELDS = [
|
|
7
|
+
"supersedes",
|
|
8
|
+
"replaced_by",
|
|
9
|
+
"split_from",
|
|
10
|
+
"split_into",
|
|
11
|
+
"merged_from",
|
|
12
|
+
"merged_into",
|
|
13
|
+
];
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function requiredString(record, key, context) {
|
|
18
|
+
const value = record[key];
|
|
19
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
20
|
+
throw new Error(`${context}.${key} must be a non-empty string`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function optionalString(record, key, context) {
|
|
25
|
+
const value = record[key];
|
|
26
|
+
if (value === null)
|
|
27
|
+
return null;
|
|
28
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
29
|
+
throw new Error(`${context}.${key} must be a non-empty string or null`);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function requiredNumber(record, key, context) {
|
|
34
|
+
const value = record[key];
|
|
35
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
36
|
+
throw new Error(`${context}.${key} must be an integer`);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
function requiredBoolean(record, key, context) {
|
|
41
|
+
const value = record[key];
|
|
42
|
+
if (typeof value !== "boolean") {
|
|
43
|
+
throw new Error(`${context}.${key} must be a boolean`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function optionalNumber(record, key, context) {
|
|
48
|
+
const value = record[key];
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
52
|
+
throw new Error(`${context}.${key} must be an integer when present`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function stringArray(record, key, context) {
|
|
57
|
+
const value = record[key];
|
|
58
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
59
|
+
throw new Error(`${context}.${key} must be a string array`);
|
|
60
|
+
}
|
|
61
|
+
return [...value];
|
|
62
|
+
}
|
|
63
|
+
function optionalStringArray(record, key) {
|
|
64
|
+
const value = record[key];
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
return [];
|
|
67
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
68
|
+
throw new Error(`${key} must be a string array when present`);
|
|
69
|
+
}
|
|
70
|
+
return [...value];
|
|
71
|
+
}
|
|
72
|
+
function optionalPolicyString(record, key, context) {
|
|
73
|
+
const value = record[key];
|
|
74
|
+
if (value === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
77
|
+
throw new Error(`${context}.${key} must be a non-empty string when present`);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function optionalPolicyStringArray(record, key, context) {
|
|
82
|
+
const value = record[key];
|
|
83
|
+
if (value === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
86
|
+
throw new Error(`${context}.${key} must be a string array when present`);
|
|
87
|
+
}
|
|
88
|
+
return [...value];
|
|
89
|
+
}
|
|
90
|
+
function parseSourceProfileRecord(value, index) {
|
|
91
|
+
if (!isRecord(value)) {
|
|
92
|
+
throw new Error(`source_profile_records[${index}] must be an object`);
|
|
93
|
+
}
|
|
94
|
+
const context = `source_profile_records[${index}]`;
|
|
95
|
+
const targetMaterialKind = requiredString(value, "target_material_kind", context);
|
|
96
|
+
if (!isTargetMaterialKind(targetMaterialKind)) {
|
|
97
|
+
throw new Error(`${context}.target_material_kind is not a valid TargetMaterialKind`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
profile_id: requiredString(value, "profile_id", context),
|
|
101
|
+
target_material_kind: targetMaterialKind,
|
|
102
|
+
is_default_for_kind: requiredBoolean(value, "is_default_for_kind", context),
|
|
103
|
+
definition_ref: optionalString(value, "definition_ref", context),
|
|
104
|
+
definition_sha256: requiredString(value, "definition_sha256", context),
|
|
105
|
+
contract_status: requiredString(value, "contract_status", context),
|
|
106
|
+
runtime_implementation_status: requiredString(value, "runtime_implementation_status", context),
|
|
107
|
+
schema_version: requiredNumber(value, "schema_version", context),
|
|
108
|
+
profile_version: requiredNumber(value, "profile_version", context),
|
|
109
|
+
migration_status: requiredString(value, "migration_status", context),
|
|
110
|
+
supersedes: stringArray(value, "supersedes", context),
|
|
111
|
+
replaced_by: stringArray(value, "replaced_by", context),
|
|
112
|
+
split_from: stringArray(value, "split_from", context),
|
|
113
|
+
split_into: stringArray(value, "split_into", context),
|
|
114
|
+
merged_from: stringArray(value, "merged_from", context),
|
|
115
|
+
merged_into: stringArray(value, "merged_into", context),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function parseActiveContractRecord(value, index) {
|
|
119
|
+
if (!isRecord(value)) {
|
|
120
|
+
throw new Error(`active_contract_refs[${index}] must be an object`);
|
|
121
|
+
}
|
|
122
|
+
const context = `active_contract_refs[${index}]`;
|
|
123
|
+
return {
|
|
124
|
+
contract_id: requiredString(value, "contract_id", context),
|
|
125
|
+
ref: requiredString(value, "ref", context),
|
|
126
|
+
role: requiredString(value, "role", context),
|
|
127
|
+
schema_version: requiredNumber(value, "schema_version", context),
|
|
128
|
+
migration_status: requiredString(value, "migration_status", context),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function parseCandidateKindRecord(value, index) {
|
|
132
|
+
if (!isRecord(value)) {
|
|
133
|
+
throw new Error(`candidate_kind_registry[${index}] must be an object`);
|
|
134
|
+
}
|
|
135
|
+
const context = `candidate_kind_registry[${index}]`;
|
|
136
|
+
return {
|
|
137
|
+
candidate_kind_id: requiredString(value, "candidate_kind_id", context),
|
|
138
|
+
canonical_projection_hint: requiredString(value, "canonical_projection_hint", context),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function parseCandidateDispositionRecord(value, index) {
|
|
142
|
+
if (!isRecord(value)) {
|
|
143
|
+
throw new Error(`candidate_disposition_registry[${index}] must be an object`);
|
|
144
|
+
}
|
|
145
|
+
const context = `candidate_disposition_registry[${index}]`;
|
|
146
|
+
return {
|
|
147
|
+
disposition_id: requiredString(value, "disposition_id", context),
|
|
148
|
+
meaning: requiredString(value, "meaning", context),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function parseAxisRecord(value, index, registryName) {
|
|
152
|
+
if (!isRecord(value)) {
|
|
153
|
+
throw new Error(`${registryName}[${index}] must be an object`);
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
axis_id: requiredString(value, "axis_id", `${registryName}[${index}]`),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function parseReferenceStandardRecord(value, index) {
|
|
160
|
+
if (!isRecord(value)) {
|
|
161
|
+
throw new Error(`reference_standard_registry[${index}] must be an object`);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
standard_ref_id: requiredString(value, "standard_ref_id", `reference_standard_registry[${index}]`),
|
|
165
|
+
canonical_uri: requiredString(value, "canonical_uri", `reference_standard_registry[${index}]`),
|
|
166
|
+
version_or_snapshot_id: requiredString(value, "version_or_snapshot_id", `reference_standard_registry[${index}]`),
|
|
167
|
+
migration_status: requiredString(value, "migration_status", `reference_standard_registry[${index}]`),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function parseReferencePatternCatalogRecord(value, index) {
|
|
171
|
+
if (!isRecord(value)) {
|
|
172
|
+
throw new Error(`reference_pattern_catalog_registry[${index}] must be an object`);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
pattern_catalog_ref_id: requiredString(value, "pattern_catalog_ref_id", `reference_pattern_catalog_registry[${index}]`),
|
|
176
|
+
canonical_uri_policy: requiredString(value, "canonical_uri_policy", `reference_pattern_catalog_registry[${index}]`),
|
|
177
|
+
version_or_snapshot_id: requiredString(value, "version_or_snapshot_id", `reference_pattern_catalog_registry[${index}]`),
|
|
178
|
+
migration_status: requiredString(value, "migration_status", `reference_pattern_catalog_registry[${index}]`),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function parseFacetRecord(value, index, registryName) {
|
|
182
|
+
if (!isRecord(value)) {
|
|
183
|
+
throw new Error(`${registryName}[${index}] must be an object`);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
facet_id: requiredString(value, "facet_id", `${registryName}[${index}]`),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function parseModelingConcernRecord(value, index) {
|
|
190
|
+
if (!isRecord(value)) {
|
|
191
|
+
throw new Error(`modeling_concern_applicability_registry[${index}] must be an object`);
|
|
192
|
+
}
|
|
193
|
+
const context = `modeling_concern_applicability_registry[${index}]`;
|
|
194
|
+
const record = {
|
|
195
|
+
concern_id: requiredString(value, "concern_id", context),
|
|
196
|
+
};
|
|
197
|
+
const applicabilityPredicateId = optionalPolicyString(value, "applicability_predicate_id", context);
|
|
198
|
+
if (applicabilityPredicateId !== undefined) {
|
|
199
|
+
record.applicability_predicate_id = applicabilityPredicateId;
|
|
200
|
+
}
|
|
201
|
+
return record;
|
|
202
|
+
}
|
|
203
|
+
function parseProofContractRecord(value, index, registryName) {
|
|
204
|
+
if (!isRecord(value)) {
|
|
205
|
+
throw new Error(`${registryName}[${index}] must be an object`);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
contract_ref_id: requiredString(value, "contract_ref_id", `${registryName}[${index}]`),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function parseArtifactAuthorityRecord(value, key) {
|
|
212
|
+
if (!isRecord(value)) {
|
|
213
|
+
throw new Error(`artifact_authorities.${key} must be an object`);
|
|
214
|
+
}
|
|
215
|
+
const context = `artifact_authorities.${key}`;
|
|
216
|
+
const record = {
|
|
217
|
+
authority_ref: requiredString(value, "authority_ref", context),
|
|
218
|
+
validation_ref: optionalString(value, "validation_ref", context),
|
|
219
|
+
};
|
|
220
|
+
const projectionPolicy = optionalPolicyString(value, "projection_policy", context);
|
|
221
|
+
if (projectionPolicy !== undefined)
|
|
222
|
+
record.projection_policy = projectionPolicy;
|
|
223
|
+
const registryRef = optionalPolicyString(value, "registry_ref", context);
|
|
224
|
+
if (registryRef !== undefined)
|
|
225
|
+
record.registry_ref = registryRef;
|
|
226
|
+
const requiredSnapshotFieldsRef = optionalPolicyString(value, "required_snapshot_fields_ref", context);
|
|
227
|
+
if (requiredSnapshotFieldsRef !== undefined) {
|
|
228
|
+
record.required_snapshot_fields_ref = requiredSnapshotFieldsRef;
|
|
229
|
+
}
|
|
230
|
+
const snapshotMatchRule = optionalPolicyString(value, "snapshot_match_rule", context);
|
|
231
|
+
if (snapshotMatchRule !== undefined)
|
|
232
|
+
record.snapshot_match_rule = snapshotMatchRule;
|
|
233
|
+
return record;
|
|
234
|
+
}
|
|
235
|
+
function parseArtifactAuthorities(value) {
|
|
236
|
+
if (!isRecord(value)) {
|
|
237
|
+
throw new Error("artifact_authorities must be an object");
|
|
238
|
+
}
|
|
239
|
+
return Object.fromEntries(Object.entries(value).map(([key, record]) => [
|
|
240
|
+
key,
|
|
241
|
+
parseArtifactAuthorityRecord(record, key),
|
|
242
|
+
]));
|
|
243
|
+
}
|
|
244
|
+
function parseValidationGateRecord(value, index) {
|
|
245
|
+
if (!isRecord(value)) {
|
|
246
|
+
throw new Error(`validation_gate_catalog[${index}] must be an object`);
|
|
247
|
+
}
|
|
248
|
+
const context = `validation_gate_catalog[${index}]`;
|
|
249
|
+
return {
|
|
250
|
+
gate_id: requiredString(value, "gate_id", context),
|
|
251
|
+
validation_artifact_ref: requiredString(value, "validation_artifact_ref", context),
|
|
252
|
+
required_when: requiredString(value, "required_when", context),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function parsePredicateExecutionContract(value) {
|
|
256
|
+
if (!isRecord(value)) {
|
|
257
|
+
throw new Error("registry.ontology_handoff_facet_contract.predicate_execution_contract must be an object");
|
|
258
|
+
}
|
|
259
|
+
const context = "ontology_handoff_facet_contract.predicate_execution_contract";
|
|
260
|
+
return {
|
|
261
|
+
default_predicate_evaluator_id: requiredString(value, "default_predicate_evaluator_id", context),
|
|
262
|
+
allowed_predicate_evaluator_ids: stringArray(value, "allowed_predicate_evaluator_ids", context),
|
|
263
|
+
predicate_phase_values: stringArray(value, "predicate_phase_values", context),
|
|
264
|
+
default_predicate_phase: requiredString(value, "default_predicate_phase", context),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function parseDomainCompetencyAdmissionPolicy(value) {
|
|
268
|
+
if (!isRecord(value)) {
|
|
269
|
+
throw new Error("ontology_handoff_facet_contract.domain_competency_trace_contract.admitted_domain_competency_disposition_rule must be an object");
|
|
270
|
+
}
|
|
271
|
+
const context = "ontology_handoff_facet_contract.domain_competency_trace_contract.admitted_domain_competency_disposition_rule";
|
|
272
|
+
return {
|
|
273
|
+
admission_policy_id: requiredString(value, "admission_policy_id", context),
|
|
274
|
+
supported_runtime_admission_policy_ids: stringArray(value, "supported_runtime_admission_policy_ids", context),
|
|
275
|
+
required_priority_values: stringArray(value, "required_priority_values", context),
|
|
276
|
+
metadata_priority_values: stringArray(value, "metadata_priority_values", context),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function parseRequiredWhenPredicateRecord(args) {
|
|
280
|
+
if (!isRecord(args.value)) {
|
|
281
|
+
throw new Error(`required_when_predicate_catalog[${args.index}] must be an object`);
|
|
282
|
+
}
|
|
283
|
+
const context = `required_when_predicate_catalog[${args.index}]`;
|
|
284
|
+
const predicatePhase = optionalPolicyString(args.value, "predicate_phase", context) ?? args.predicateExecutionContract.default_predicate_phase;
|
|
285
|
+
const predicateEvaluatorId = optionalPolicyString(args.value, "predicate_evaluator_id", context) ?? args.predicateExecutionContract.default_predicate_evaluator_id;
|
|
286
|
+
const predicateEvaluatorVersion = optionalNumber(args.value, "predicate_evaluator_version", context) ?? 1;
|
|
287
|
+
const record = {
|
|
288
|
+
predicate_id: requiredString(args.value, "predicate_id", context),
|
|
289
|
+
input_authority_refs: stringArray(args.value, "input_authority_refs", context),
|
|
290
|
+
truth_expression: requiredString(args.value, "truth_expression", context),
|
|
291
|
+
unknown_projection: requiredString(args.value, "unknown_projection", context),
|
|
292
|
+
explanation_template: requiredString(args.value, "explanation_template", context),
|
|
293
|
+
predicate_phase: predicatePhase,
|
|
294
|
+
predicate_evaluator_id: predicateEvaluatorId,
|
|
295
|
+
predicate_evaluator_version: predicateEvaluatorVersion,
|
|
296
|
+
};
|
|
297
|
+
const usageStatus = optionalPolicyString(args.value, "usage_status", context);
|
|
298
|
+
if (usageStatus !== undefined)
|
|
299
|
+
record.usage_status = usageStatus;
|
|
300
|
+
const reservedFor = optionalPolicyString(args.value, "reserved_for", context);
|
|
301
|
+
if (reservedFor !== undefined)
|
|
302
|
+
record.reserved_for = reservedFor;
|
|
303
|
+
const gateInstanceScope = optionalPolicyString(args.value, "gate_instance_scope", context);
|
|
304
|
+
if (gateInstanceScope !== undefined) {
|
|
305
|
+
record.gate_instance_scope = gateInstanceScope;
|
|
306
|
+
}
|
|
307
|
+
return record;
|
|
308
|
+
}
|
|
309
|
+
function parseValidatorRecord(value, index) {
|
|
310
|
+
if (!isRecord(value)) {
|
|
311
|
+
throw new Error(`validator_records[${index}] must be an object`);
|
|
312
|
+
}
|
|
313
|
+
const context = `validator_records[${index}]`;
|
|
314
|
+
return {
|
|
315
|
+
validator_id: requiredString(value, "validator_id", context),
|
|
316
|
+
gate_ids: stringArray(value, "gate_ids", context),
|
|
317
|
+
validator_version: requiredNumber(value, "validator_version", context),
|
|
318
|
+
input_authority_refs: optionalStringArray(value, "input_authority_refs"),
|
|
319
|
+
output_ref: requiredString(value, "output_ref", context),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function requiredArray(record, key, context) {
|
|
323
|
+
const value = record[key];
|
|
324
|
+
if (!Array.isArray(value)) {
|
|
325
|
+
throw new Error(`${context}.${key} must be an array`);
|
|
326
|
+
}
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
async function sha256File(filePath) {
|
|
330
|
+
const bytes = await fs.readFile(filePath);
|
|
331
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
332
|
+
}
|
|
333
|
+
export function resolveRegistryRef(args) {
|
|
334
|
+
return path.isAbsolute(args.ref)
|
|
335
|
+
? path.resolve(args.ref)
|
|
336
|
+
: path.resolve(args.projectRoot, args.ref);
|
|
337
|
+
}
|
|
338
|
+
export function projectRootFromProfilesRoot(profilesRoot) {
|
|
339
|
+
return path.resolve(profilesRoot, "../../../..");
|
|
340
|
+
}
|
|
341
|
+
export async function loadReconstructContractRegistry(args) {
|
|
342
|
+
const parsed = parseYaml(await fs.readFile(args.registryPath, "utf8"));
|
|
343
|
+
if (!isRecord(parsed)) {
|
|
344
|
+
throw new Error("reconstruct contract registry must be an object");
|
|
345
|
+
}
|
|
346
|
+
const ontologyHandoffFacetContract = parsed.ontology_handoff_facet_contract;
|
|
347
|
+
if (!isRecord(ontologyHandoffFacetContract)) {
|
|
348
|
+
throw new Error("reconstruct contract registry must include ontology_handoff_facet_contract");
|
|
349
|
+
}
|
|
350
|
+
const reasoningOrFormalismProfileContract = parsed.reasoning_or_formalism_profile_contract;
|
|
351
|
+
if (!isRecord(reasoningOrFormalismProfileContract)) {
|
|
352
|
+
throw new Error("reconstruct contract registry must include reasoning_or_formalism_profile_contract");
|
|
353
|
+
}
|
|
354
|
+
const predicateExecutionContract = parsePredicateExecutionContract(ontologyHandoffFacetContract.predicate_execution_contract);
|
|
355
|
+
const domainCompetencyTraceContract = ontologyHandoffFacetContract.domain_competency_trace_contract;
|
|
356
|
+
if (!isRecord(domainCompetencyTraceContract)) {
|
|
357
|
+
throw new Error("reconstruct contract registry must include ontology_handoff_facet_contract.domain_competency_trace_contract");
|
|
358
|
+
}
|
|
359
|
+
const sourceProfileRecords = parsed.source_profile_records;
|
|
360
|
+
if (!Array.isArray(sourceProfileRecords)) {
|
|
361
|
+
throw new Error("reconstruct contract registry must include source_profile_records");
|
|
362
|
+
}
|
|
363
|
+
const registry = {
|
|
364
|
+
schema_version: requiredNumber(parsed, "schema_version", "registry"),
|
|
365
|
+
registry_id: requiredString(parsed, "registry_id", "registry"),
|
|
366
|
+
status: requiredString(parsed, "status", "registry"),
|
|
367
|
+
active_contract_refs: requiredArray(parsed, "active_contract_refs", "registry")
|
|
368
|
+
.map(parseActiveContractRecord),
|
|
369
|
+
source_profile_records: sourceProfileRecords.map(parseSourceProfileRecord),
|
|
370
|
+
candidate_kind_registry: requiredArray(parsed, "candidate_kind_registry", "registry").map(parseCandidateKindRecord),
|
|
371
|
+
candidate_disposition_registry: requiredArray(parsed, "candidate_disposition_registry", "registry").map(parseCandidateDispositionRecord),
|
|
372
|
+
coverage_axis_registry: requiredArray(parsed, "coverage_axis_registry", "registry").map((value, index) => parseAxisRecord(value, index, "coverage_axis_registry")),
|
|
373
|
+
ontology_handoff_axis_registry: requiredArray(parsed, "ontology_handoff_axis_registry", "registry").map((value, index) => parseAxisRecord(value, index, "ontology_handoff_axis_registry")),
|
|
374
|
+
reference_standard_registry: requiredArray(ontologyHandoffFacetContract, "reference_standard_registry", "ontology_handoff_facet_contract").map(parseReferenceStandardRecord),
|
|
375
|
+
reference_pattern_catalog_registry: requiredArray(ontologyHandoffFacetContract, "reference_pattern_catalog_registry", "ontology_handoff_facet_contract").map(parseReferencePatternCatalogRecord),
|
|
376
|
+
reasoning_or_formalism_profile_values: {
|
|
377
|
+
representation_formalism_values: stringArray(reasoningOrFormalismProfileContract, "representation_formalism_values", "reasoning_or_formalism_profile_contract"),
|
|
378
|
+
vocabulary_system_values: stringArray(reasoningOrFormalismProfileContract, "vocabulary_system_values", "reasoning_or_formalism_profile_contract"),
|
|
379
|
+
validation_formalism_values: stringArray(reasoningOrFormalismProfileContract, "validation_formalism_values", "reasoning_or_formalism_profile_contract"),
|
|
380
|
+
ontology_type_values: stringArray(reasoningOrFormalismProfileContract, "ontology_type_values", "reasoning_or_formalism_profile_contract"),
|
|
381
|
+
alignment_posture_values: stringArray(reasoningOrFormalismProfileContract, "alignment_posture_values", "reasoning_or_formalism_profile_contract"),
|
|
382
|
+
owl_profile_values: stringArray(reasoningOrFormalismProfileContract, "owl_profile_values", "reasoning_or_formalism_profile_contract"),
|
|
383
|
+
},
|
|
384
|
+
reasoning_or_formalism_facet_registry: requiredArray(reasoningOrFormalismProfileContract, "facet_registry", "reasoning_or_formalism_profile_contract").map((value, index) => parseFacetRecord(value, index, "reasoning_or_formalism_profile_contract.facet_registry")),
|
|
385
|
+
entity_identity_facet_registry: requiredArray(ontologyHandoffFacetContract, "entity_identity_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "entity_identity_facet_registry")),
|
|
386
|
+
instance_assertion_facet_registry: requiredArray(ontologyHandoffFacetContract, "instance_assertion_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "instance_assertion_facet_registry")),
|
|
387
|
+
terminology_facet_registry: requiredArray(ontologyHandoffFacetContract, "terminology_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "terminology_facet_registry")),
|
|
388
|
+
relation_type_facet_registry: requiredArray(ontologyHandoffFacetContract, "relation_type_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "relation_type_facet_registry")),
|
|
389
|
+
classification_facet_registry: requiredArray(ontologyHandoffFacetContract, "classification_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "classification_facet_registry")),
|
|
390
|
+
constraint_facet_registry: requiredArray(ontologyHandoffFacetContract, "constraint_facet_registry", "ontology_handoff_facet_contract").map((value, index) => parseFacetRecord(value, index, "constraint_facet_registry")),
|
|
391
|
+
modeling_concern_applicability_registry: requiredArray(ontologyHandoffFacetContract, "modeling_concern_applicability_registry", "ontology_handoff_facet_contract").map(parseModelingConcernRecord),
|
|
392
|
+
query_access_contract_registry: requiredArray(ontologyHandoffFacetContract, "query_access_contract_registry", "ontology_handoff_facet_contract").map((value, index) => parseProofContractRecord(value, index, "query_access_contract_registry")),
|
|
393
|
+
visualization_contract_registry: requiredArray(ontologyHandoffFacetContract, "visualization_contract_registry", "ontology_handoff_facet_contract").map((value, index) => parseProofContractRecord(value, index, "visualization_contract_registry")),
|
|
394
|
+
graph_exploration_contract_registry: requiredArray(ontologyHandoffFacetContract, "graph_exploration_contract_registry", "ontology_handoff_facet_contract").map((value, index) => parseProofContractRecord(value, index, "graph_exploration_contract_registry")),
|
|
395
|
+
artifact_authorities: parseArtifactAuthorities(parsed.artifact_authorities),
|
|
396
|
+
validation_gate_catalog: requiredArray(parsed, "validation_gate_catalog", "registry").map(parseValidationGateRecord),
|
|
397
|
+
predicate_execution_contract: predicateExecutionContract,
|
|
398
|
+
domain_competency_admission_policy: parseDomainCompetencyAdmissionPolicy(domainCompetencyTraceContract.admitted_domain_competency_disposition_rule),
|
|
399
|
+
required_when_predicate_catalog: requiredArray(parsed, "required_when_predicate_catalog", "registry").map((value, index) => parseRequiredWhenPredicateRecord({
|
|
400
|
+
value,
|
|
401
|
+
index,
|
|
402
|
+
predicateExecutionContract,
|
|
403
|
+
})),
|
|
404
|
+
validator_records: requiredArray(parsed, "validator_records", "registry")
|
|
405
|
+
.map(parseValidatorRecord),
|
|
406
|
+
};
|
|
407
|
+
const sourceProfileMigrationPolicy = parsed.source_profile_migration_policy;
|
|
408
|
+
if (isRecord(sourceProfileMigrationPolicy)) {
|
|
409
|
+
const policy = {};
|
|
410
|
+
const values = optionalPolicyStringArray(sourceProfileMigrationPolicy, "migration_status_values", "source_profile_migration_policy");
|
|
411
|
+
if (values !== undefined)
|
|
412
|
+
policy.migration_status_values = values;
|
|
413
|
+
registry.source_profile_migration_policy = policy;
|
|
414
|
+
}
|
|
415
|
+
const versionPolicy = parsed.version_policy;
|
|
416
|
+
if (isRecord(versionPolicy)) {
|
|
417
|
+
const policy = {};
|
|
418
|
+
const requiredFields = optionalPolicyStringArray(versionPolicy, "selected_source_profile_snapshot_required_fields", "version_policy");
|
|
419
|
+
if (requiredFields !== undefined) {
|
|
420
|
+
policy.selected_source_profile_snapshot_required_fields = requiredFields;
|
|
421
|
+
}
|
|
422
|
+
const migrationStatusValuesRef = optionalPolicyString(versionPolicy, "selected_source_profile_migration_status_values_ref", "version_policy");
|
|
423
|
+
if (migrationStatusValuesRef !== undefined) {
|
|
424
|
+
policy.selected_source_profile_migration_status_values_ref =
|
|
425
|
+
migrationStatusValuesRef;
|
|
426
|
+
}
|
|
427
|
+
const contractMigrationStatusValues = optionalPolicyStringArray(versionPolicy, "contract_migration_status_values", "version_policy");
|
|
428
|
+
if (contractMigrationStatusValues !== undefined) {
|
|
429
|
+
policy.contract_migration_status_values = contractMigrationStatusValues;
|
|
430
|
+
}
|
|
431
|
+
registry.version_policy = policy;
|
|
432
|
+
}
|
|
433
|
+
validateReconstructContractRegistry(registry);
|
|
434
|
+
return registry;
|
|
435
|
+
}
|
|
436
|
+
function assertUnique(values, description) {
|
|
437
|
+
const seen = new Set();
|
|
438
|
+
for (const value of values) {
|
|
439
|
+
if (seen.has(value)) {
|
|
440
|
+
throw new Error(`Duplicate ${description}: ${value}`);
|
|
441
|
+
}
|
|
442
|
+
seen.add(value);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
export function validateReconstructContractRegistry(registry) {
|
|
446
|
+
assertUnique(registry.active_contract_refs.map((record) => record.contract_id), "active contract id");
|
|
447
|
+
assertUnique(registry.candidate_kind_registry.map((record) => record.candidate_kind_id), "candidate kind id");
|
|
448
|
+
assertUnique(registry.candidate_disposition_registry.map((record) => record.disposition_id), "candidate disposition id");
|
|
449
|
+
assertUnique(registry.coverage_axis_registry.map((record) => record.axis_id), "coverage axis id");
|
|
450
|
+
assertUnique(registry.ontology_handoff_axis_registry.map((record) => record.axis_id), "ontology handoff axis id");
|
|
451
|
+
assertUnique(registry.reference_standard_registry.map((record) => record.standard_ref_id), "reference standard id");
|
|
452
|
+
assertUnique(registry.reference_pattern_catalog_registry.map((record) => record.pattern_catalog_ref_id), "reference pattern catalog id");
|
|
453
|
+
assertUnique(Object.values(registry.artifact_authorities).map((record) => record.authority_ref), "artifact authority ref");
|
|
454
|
+
assertUnique(registry.validation_gate_catalog.map((record) => record.gate_id), "validation gate id");
|
|
455
|
+
assertUnique(registry.required_when_predicate_catalog.map((record) => record.predicate_id), "required-when predicate id");
|
|
456
|
+
assertUnique(registry.validator_records.map((record) => record.validator_id), "validator id");
|
|
457
|
+
for (const evaluatorId of registry.predicate_execution_contract
|
|
458
|
+
.allowed_predicate_evaluator_ids) {
|
|
459
|
+
if (typeof evaluatorId !== "string" || evaluatorId.trim().length === 0) {
|
|
460
|
+
throw new Error("allowed predicate evaluator ids must be non-empty strings");
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const allowedEvaluatorIds = new Set(registry.predicate_execution_contract.allowed_predicate_evaluator_ids);
|
|
464
|
+
if (!allowedEvaluatorIds.has(registry.predicate_execution_contract.default_predicate_evaluator_id)) {
|
|
465
|
+
throw new Error("default predicate evaluator id must be listed in allowed_predicate_evaluator_ids");
|
|
466
|
+
}
|
|
467
|
+
const allowedPredicatePhases = new Set(registry.predicate_execution_contract.predicate_phase_values);
|
|
468
|
+
if (!allowedPredicatePhases.has(registry.predicate_execution_contract.default_predicate_phase)) {
|
|
469
|
+
throw new Error("default predicate phase must be listed in predicate_phase_values");
|
|
470
|
+
}
|
|
471
|
+
const admissionPolicy = registry.domain_competency_admission_policy;
|
|
472
|
+
const supportedAdmissionPolicyIds = new Set(admissionPolicy.supported_runtime_admission_policy_ids);
|
|
473
|
+
if (!supportedAdmissionPolicyIds.has(admissionPolicy.admission_policy_id)) {
|
|
474
|
+
throw new Error(`Domain competency admission policy ${admissionPolicy.admission_policy_id} must be listed in supported_runtime_admission_policy_ids`);
|
|
475
|
+
}
|
|
476
|
+
const allowedPriorityValues = new Set(["P1", "P2", "P3"]);
|
|
477
|
+
const seenPriorityValues = new Set();
|
|
478
|
+
for (const priority of [
|
|
479
|
+
...admissionPolicy.required_priority_values,
|
|
480
|
+
...admissionPolicy.metadata_priority_values,
|
|
481
|
+
]) {
|
|
482
|
+
if (!allowedPriorityValues.has(priority)) {
|
|
483
|
+
throw new Error(`Domain competency admission policy ${admissionPolicy.admission_policy_id} uses unsupported priority ${priority}`);
|
|
484
|
+
}
|
|
485
|
+
if (seenPriorityValues.has(priority)) {
|
|
486
|
+
throw new Error(`Domain competency admission policy ${admissionPolicy.admission_policy_id} repeats priority ${priority}`);
|
|
487
|
+
}
|
|
488
|
+
seenPriorityValues.add(priority);
|
|
489
|
+
}
|
|
490
|
+
const artifactRefs = new Set(Object.values(registry.artifact_authorities).map((record) => record.authority_ref));
|
|
491
|
+
for (const [artifactId, artifact] of Object.entries(registry.artifact_authorities)) {
|
|
492
|
+
if (artifact.validation_ref !== null && !artifactRefs.has(artifact.validation_ref)) {
|
|
493
|
+
throw new Error(`artifact_authorities.${artifactId}.validation_ref references unknown artifact authority ${artifact.validation_ref}`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const gateIds = new Set(registry.validation_gate_catalog.map((record) => record.gate_id));
|
|
497
|
+
const predicateIds = new Set(registry.required_when_predicate_catalog.map((record) => record.predicate_id));
|
|
498
|
+
const activePredicateIds = new Set(registry.validation_gate_catalog.map((record) => record.required_when));
|
|
499
|
+
for (const predicate of registry.required_when_predicate_catalog) {
|
|
500
|
+
if (predicate.usage_status === "reserved") {
|
|
501
|
+
if (!predicate.reserved_for) {
|
|
502
|
+
throw new Error(`Reserved required-when predicate ${predicate.predicate_id} must declare reserved_for`);
|
|
503
|
+
}
|
|
504
|
+
if (activePredicateIds.has(predicate.predicate_id)) {
|
|
505
|
+
throw new Error(`Reserved required-when predicate ${predicate.predicate_id} must not be used by an active validation gate`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
else if (predicate.reserved_for) {
|
|
509
|
+
throw new Error(`Required-when predicate ${predicate.predicate_id} declares reserved_for without usage_status=reserved`);
|
|
510
|
+
}
|
|
511
|
+
if (!allowedEvaluatorIds.has(predicate.predicate_evaluator_id)) {
|
|
512
|
+
throw new Error(`Required-when predicate ${predicate.predicate_id} uses unknown evaluator ${predicate.predicate_evaluator_id}`);
|
|
513
|
+
}
|
|
514
|
+
if (!allowedPredicatePhases.has(predicate.predicate_phase)) {
|
|
515
|
+
throw new Error(`Required-when predicate ${predicate.predicate_id} uses unknown phase ${predicate.predicate_phase}`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
for (const gate of registry.validation_gate_catalog) {
|
|
519
|
+
if (!artifactRefs.has(gate.validation_artifact_ref)) {
|
|
520
|
+
throw new Error(`Validation gate ${gate.gate_id} references unknown validation artifact ${gate.validation_artifact_ref}`);
|
|
521
|
+
}
|
|
522
|
+
if (!predicateIds.has(gate.required_when)) {
|
|
523
|
+
throw new Error(`Validation gate ${gate.gate_id} references unknown required_when predicate ${gate.required_when}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
for (const validator of registry.validator_records) {
|
|
527
|
+
for (const gateId of validator.gate_ids) {
|
|
528
|
+
if (!gateIds.has(gateId)) {
|
|
529
|
+
throw new Error(`Validator ${validator.validator_id} references unknown gate ${gateId}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (!artifactRefs.has(validator.output_ref)) {
|
|
533
|
+
throw new Error(`Validator ${validator.validator_id} references unknown output artifact ${validator.output_ref}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const profileIds = new Set();
|
|
537
|
+
const defaultProfilesByKind = new Map();
|
|
538
|
+
const allowedSourceProfileMigrationStatuses = new Set(registry.source_profile_migration_policy?.migration_status_values ?? []);
|
|
539
|
+
for (const record of registry.source_profile_records) {
|
|
540
|
+
if (profileIds.has(record.profile_id)) {
|
|
541
|
+
throw new Error(`Duplicate source profile id: ${record.profile_id}`);
|
|
542
|
+
}
|
|
543
|
+
profileIds.add(record.profile_id);
|
|
544
|
+
if (record.is_default_for_kind) {
|
|
545
|
+
const existing = defaultProfilesByKind.get(record.target_material_kind) ?? [];
|
|
546
|
+
existing.push(record.profile_id);
|
|
547
|
+
defaultProfilesByKind.set(record.target_material_kind, existing);
|
|
548
|
+
}
|
|
549
|
+
if (allowedSourceProfileMigrationStatuses.size > 0 &&
|
|
550
|
+
!allowedSourceProfileMigrationStatuses.has(record.migration_status)) {
|
|
551
|
+
throw new Error(`Source profile ${record.profile_id} uses unsupported migration_status ${record.migration_status}`);
|
|
552
|
+
}
|
|
553
|
+
for (const field of PROFILE_MIGRATION_FIELDS) {
|
|
554
|
+
for (const ref of record[field]) {
|
|
555
|
+
if (!profileIds.has(ref)) {
|
|
556
|
+
// Forward references are allowed in YAML order, so final closure is below.
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
for (const [targetMaterialKind, defaultProfileIds] of defaultProfilesByKind) {
|
|
563
|
+
if (defaultProfileIds.length > 1) {
|
|
564
|
+
throw new Error(`Multiple default source profiles for target material kind ${targetMaterialKind}: ${defaultProfileIds.join(", ")}`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
for (const targetMaterialKind of new Set(registry.source_profile_records.map((record) => record.target_material_kind))) {
|
|
568
|
+
if (!defaultProfilesByKind.has(targetMaterialKind)) {
|
|
569
|
+
throw new Error(`No default source profile for target material kind ${targetMaterialKind}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
for (const record of registry.source_profile_records) {
|
|
573
|
+
for (const field of PROFILE_MIGRATION_FIELDS) {
|
|
574
|
+
for (const ref of record[field]) {
|
|
575
|
+
if (!profileIds.has(ref)) {
|
|
576
|
+
throw new Error(`Source profile ${record.profile_id} ${field} references unknown profile ${ref}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const sourceProfileStatusRef = registry.version_policy?.selected_source_profile_migration_status_values_ref;
|
|
582
|
+
if (sourceProfileStatusRef &&
|
|
583
|
+
sourceProfileStatusRef !== "source_profile_migration_policy.migration_status_values") {
|
|
584
|
+
throw new Error("version_policy.selected_source_profile_migration_status_values_ref must point to source_profile_migration_policy.migration_status_values");
|
|
585
|
+
}
|
|
586
|
+
const allowedContractMigrationStatuses = new Set(registry.version_policy?.contract_migration_status_values ?? []);
|
|
587
|
+
for (const record of registry.active_contract_refs) {
|
|
588
|
+
if (allowedContractMigrationStatuses.size > 0 &&
|
|
589
|
+
!allowedContractMigrationStatuses.has(record.migration_status)) {
|
|
590
|
+
throw new Error(`Active contract ${record.contract_id} uses unsupported migration_status ${record.migration_status}`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
for (const record of registry.reference_standard_registry) {
|
|
594
|
+
if (allowedContractMigrationStatuses.size > 0 &&
|
|
595
|
+
!allowedContractMigrationStatuses.has(record.migration_status)) {
|
|
596
|
+
throw new Error(`Reference standard ${record.standard_ref_id} uses unsupported migration_status ${record.migration_status}`);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
for (const record of registry.reference_pattern_catalog_registry) {
|
|
600
|
+
if (allowedContractMigrationStatuses.size > 0 &&
|
|
601
|
+
!allowedContractMigrationStatuses.has(record.migration_status)) {
|
|
602
|
+
throw new Error(`Reference pattern catalog ${record.pattern_catalog_ref_id} uses unsupported migration_status ${record.migration_status}`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
export async function validateSourceProfileDefinitionHashes(args) {
|
|
607
|
+
await Promise.all(args.registry.source_profile_records.map(async (record) => {
|
|
608
|
+
if (record.definition_ref === null) {
|
|
609
|
+
if (record.definition_sha256 !== "not_applicable") {
|
|
610
|
+
throw new Error(`Source profile ${record.profile_id} without definition_ref must use definition_sha256=not_applicable`);
|
|
611
|
+
}
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const resolved = resolveRegistryRef({
|
|
615
|
+
projectRoot: args.projectRoot,
|
|
616
|
+
ref: record.definition_ref,
|
|
617
|
+
});
|
|
618
|
+
const actual = await sha256File(resolved);
|
|
619
|
+
if (actual !== record.definition_sha256) {
|
|
620
|
+
throw new Error(`Source profile ${record.profile_id} hash mismatch: expected ${record.definition_sha256}, got ${actual}`);
|
|
621
|
+
}
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const RECONSTRUCT_DOMAIN_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2
|
+
export const RECONSTRUCT_DOMAIN_ID_GRAMMAR_DESCRIPTION = "lowercase letters or digits separated by single hyphens";
|
|
3
|
+
export function isReconstructDomainId(value) {
|
|
4
|
+
return RECONSTRUCT_DOMAIN_ID_PATTERN.test(value);
|
|
5
|
+
}
|
|
6
|
+
export function assertReconstructDomainId(value, label = "domain") {
|
|
7
|
+
if (isReconstructDomainId(value))
|
|
8
|
+
return;
|
|
9
|
+
throw new Error(`${label} must use ${RECONSTRUCT_DOMAIN_ID_GRAMMAR_DESCRIPTION}: ${value}`);
|
|
10
|
+
}
|