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
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
4
|
+
import { RECONSTRUCT_STAGE_IDS } from "./artifact-types.js";
|
|
5
|
+
import { loadReconstructContractRegistry, } from "./contract-registry.js";
|
|
6
|
+
import { validateReconstructRunGoverningSnapshot } from "./governing-snapshot.js";
|
|
7
|
+
function isoNow() {
|
|
8
|
+
return new Date().toISOString();
|
|
9
|
+
}
|
|
10
|
+
function violation(args) {
|
|
11
|
+
return {
|
|
12
|
+
code: args.code,
|
|
13
|
+
message: args.message,
|
|
14
|
+
subject_id: args.subjectId ?? null,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async function exists(ref) {
|
|
18
|
+
try {
|
|
19
|
+
await fs.access(ref);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function writeYamlDocument(filePath, value) {
|
|
27
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
28
|
+
await fs.writeFile(filePath, stringifyYaml(value), "utf8");
|
|
29
|
+
}
|
|
30
|
+
async function readYamlDocument(filePath) {
|
|
31
|
+
return parseYaml(await fs.readFile(filePath, "utf8"));
|
|
32
|
+
}
|
|
33
|
+
async function readYamlDocumentIfPresent(filePath) {
|
|
34
|
+
if (!filePath)
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
return parseYaml(await fs.readFile(filePath, "utf8"));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code === "ENOENT") {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const SELF_VALIDATION_OUTPUT_REFS = new Set([
|
|
47
|
+
"pre_handoff_run_manifest_validation",
|
|
48
|
+
"post_publication_run_manifest_validation",
|
|
49
|
+
]);
|
|
50
|
+
export async function validateReconstructRunManifest(args) {
|
|
51
|
+
const violations = [];
|
|
52
|
+
const stepById = new Map(args.manifest.steps.map((step) => [step.step_id, step]));
|
|
53
|
+
for (const stageId of RECONSTRUCT_STAGE_IDS) {
|
|
54
|
+
if (!stepById.has(stageId)) {
|
|
55
|
+
violations.push(violation({
|
|
56
|
+
code: "manifest_step_missing",
|
|
57
|
+
message: `manifest is missing stage ${stageId}`,
|
|
58
|
+
subjectId: stageId,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const step of args.manifest.steps) {
|
|
63
|
+
if (step.status !== "completed")
|
|
64
|
+
continue;
|
|
65
|
+
if (step.step_id === "invocation_binding")
|
|
66
|
+
continue;
|
|
67
|
+
if (step.artifact_refs.length === 0) {
|
|
68
|
+
violations.push(violation({
|
|
69
|
+
code: "manifest_artifact_ref_missing",
|
|
70
|
+
message: `completed manifest step has no artifact refs: ${step.step_id}`,
|
|
71
|
+
subjectId: step.step_id,
|
|
72
|
+
}));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (SELF_VALIDATION_OUTPUT_REFS.has(step.step_id))
|
|
76
|
+
continue;
|
|
77
|
+
for (const ref of step.artifact_refs) {
|
|
78
|
+
if (!(await exists(ref))) {
|
|
79
|
+
violations.push(violation({
|
|
80
|
+
code: "manifest_artifact_missing",
|
|
81
|
+
message: `manifest step ${step.step_id} references a missing artifact: ${ref}`,
|
|
82
|
+
subjectId: step.step_id,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (args.projectRoot &&
|
|
88
|
+
args.registryPath &&
|
|
89
|
+
args.contractRegistry &&
|
|
90
|
+
args.selectedSourceProfiles &&
|
|
91
|
+
args.lensIds) {
|
|
92
|
+
violations.push(...await validateReconstructRunGoverningSnapshot({
|
|
93
|
+
projectRoot: args.projectRoot,
|
|
94
|
+
registryPath: args.registryPath,
|
|
95
|
+
contractRegistry: args.contractRegistry,
|
|
96
|
+
selectedSourceProfiles: args.selectedSourceProfiles,
|
|
97
|
+
lensIds: args.lensIds,
|
|
98
|
+
admittedDomainIds: args.admittedDomainIds ?? [],
|
|
99
|
+
snapshot: args.manifest.governing_snapshot,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
else if (!args.manifest.governing_snapshot) {
|
|
103
|
+
violations.push(violation({
|
|
104
|
+
code: "manifest_snapshot_missing",
|
|
105
|
+
message: "manifest validation requires governing_snapshot when registry validation inputs are unavailable",
|
|
106
|
+
subjectId: "governing_snapshot",
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
const completedStepCount = args.manifest.steps.filter((step) => step.status === "completed").length;
|
|
110
|
+
const skippedStepCount = args.manifest.steps.filter((step) => step.status === "skipped").length;
|
|
111
|
+
return {
|
|
112
|
+
schema_version: "1",
|
|
113
|
+
session_id: args.manifest.session_id,
|
|
114
|
+
created_at: isoNow(),
|
|
115
|
+
reconstruct_run_manifest_ref: args.manifestRef ?? null,
|
|
116
|
+
validation_status: violations.length === 0 ? "valid" : "invalid",
|
|
117
|
+
completed_step_count: completedStepCount,
|
|
118
|
+
skipped_step_count: skippedStepCount,
|
|
119
|
+
validation_results: violations.length === 0
|
|
120
|
+
? ["reconstruct_run_manifest_valid"]
|
|
121
|
+
: ["reconstruct_run_manifest_invalid"],
|
|
122
|
+
violations,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function statusOf(artifact) {
|
|
126
|
+
return artifact?.validation_status ?? "not_available";
|
|
127
|
+
}
|
|
128
|
+
function readinessProjection(args) {
|
|
129
|
+
const requiredStatuses = Object.values(args.statuses)
|
|
130
|
+
.filter((status) => status !== "not_applicable");
|
|
131
|
+
const readinessSignals = [];
|
|
132
|
+
if (requiredStatuses.some((status) => status === "not_available")) {
|
|
133
|
+
readinessSignals.push("blocked");
|
|
134
|
+
}
|
|
135
|
+
if (requiredStatuses.some((status) => status === "invalid")) {
|
|
136
|
+
readinessSignals.push("not_ready");
|
|
137
|
+
}
|
|
138
|
+
if (!args.seedConfirmationValidation) {
|
|
139
|
+
readinessSignals.push("blocked");
|
|
140
|
+
}
|
|
141
|
+
else if (args.seedConfirmationValidation.rejected_claim_ids.length > 0 ||
|
|
142
|
+
args.seedConfirmationValidation.partial_claim_ids.length > 0 ||
|
|
143
|
+
args.seedConfirmationValidation.deferred_claim_ids.length > 0) {
|
|
144
|
+
readinessSignals.push("limited");
|
|
145
|
+
}
|
|
146
|
+
if (args.materialFailureCount > 0 || args.metrics.unresolved_question_count > 0) {
|
|
147
|
+
readinessSignals.push("not_ready");
|
|
148
|
+
}
|
|
149
|
+
const ontologyHandoff = args.ontologySeed?.ontology_handoff;
|
|
150
|
+
const handoffReadinessClaim = ontologyHandoff !== null &&
|
|
151
|
+
typeof ontologyHandoff === "object" &&
|
|
152
|
+
!Array.isArray(ontologyHandoff)
|
|
153
|
+
? ontologyHandoff.readiness_claim
|
|
154
|
+
: null;
|
|
155
|
+
if (handoffReadinessClaim === "ready" ||
|
|
156
|
+
handoffReadinessClaim === "limited" ||
|
|
157
|
+
handoffReadinessClaim === "not_ready" ||
|
|
158
|
+
handoffReadinessClaim === "blocked") {
|
|
159
|
+
readinessSignals.push(handoffReadinessClaim);
|
|
160
|
+
}
|
|
161
|
+
for (const assessment of args.competencyQuestionAssessment?.assessments ?? []) {
|
|
162
|
+
switch (assessment.downstream_effect) {
|
|
163
|
+
case "blocked_by_missing_source_or_confirmation":
|
|
164
|
+
readinessSignals.push("blocked");
|
|
165
|
+
break;
|
|
166
|
+
case "blocks_handoff":
|
|
167
|
+
readinessSignals.push("not_ready");
|
|
168
|
+
break;
|
|
169
|
+
case "limited":
|
|
170
|
+
readinessSignals.push("limited");
|
|
171
|
+
break;
|
|
172
|
+
case "ready":
|
|
173
|
+
readinessSignals.push("ready");
|
|
174
|
+
break;
|
|
175
|
+
case "not_applicable":
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (readinessSignals.some((signal) => signal === "blocked")) {
|
|
180
|
+
return "blocked";
|
|
181
|
+
}
|
|
182
|
+
if (readinessSignals.some((signal) => signal === "not_ready")) {
|
|
183
|
+
return "not_ready";
|
|
184
|
+
}
|
|
185
|
+
if (readinessSignals.some((signal) => signal === "limited")) {
|
|
186
|
+
return "limited";
|
|
187
|
+
}
|
|
188
|
+
return "ready";
|
|
189
|
+
}
|
|
190
|
+
function validationArtifactStatuses(args) {
|
|
191
|
+
return new Map([
|
|
192
|
+
["target-material-profile-validation.yaml", statusOf(args.targetMaterialProfileValidation)],
|
|
193
|
+
[
|
|
194
|
+
"source-observation-directive-validation.yaml",
|
|
195
|
+
statusOf(args.sourceObservationDirectiveValidation),
|
|
196
|
+
],
|
|
197
|
+
["source-frontier-validation.yaml", statusOf(args.sourceFrontierValidation)],
|
|
198
|
+
[
|
|
199
|
+
"candidate-disposition-validation.yaml",
|
|
200
|
+
statusOf(args.candidateDispositionValidation),
|
|
201
|
+
],
|
|
202
|
+
["ontology-seed-validation.yaml", statusOf(args.ontologySeedValidation)],
|
|
203
|
+
[
|
|
204
|
+
"claim-realization-map-validation.yaml",
|
|
205
|
+
statusOf(args.claimRealizationMapValidation),
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
"competency-questions-validation.yaml",
|
|
209
|
+
statusOf(args.competencyQuestionsValidation),
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
"competency-question-assessment-validation.yaml",
|
|
213
|
+
statusOf(args.competencyQuestionAssessmentValidation),
|
|
214
|
+
],
|
|
215
|
+
["seed-confirmation-validation.yaml", statusOf(args.seedConfirmationValidation)],
|
|
216
|
+
[
|
|
217
|
+
"failure-classification-validation.yaml",
|
|
218
|
+
statusOf(args.failureClassificationValidation),
|
|
219
|
+
],
|
|
220
|
+
["revision-proposal-validation.yaml", statusOf(args.revisionProposalValidation)],
|
|
221
|
+
[
|
|
222
|
+
"reconstruct-run-manifest.pre-handoff-validation.yaml",
|
|
223
|
+
statusOf(args.manifestValidation),
|
|
224
|
+
],
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
function addValidationStatusByRef(args) {
|
|
228
|
+
if (!args.ref)
|
|
229
|
+
return;
|
|
230
|
+
args.statusesByRef.set(args.ref, args.status);
|
|
231
|
+
args.statusesByRef.set(path.resolve(args.ref), args.status);
|
|
232
|
+
}
|
|
233
|
+
function validationArtifactStatusesByRef(args) {
|
|
234
|
+
const statusesByRef = new Map();
|
|
235
|
+
const refByArtifact = args.refs ?? {};
|
|
236
|
+
for (const [artifactName, ref] of Object.entries(refByArtifact)) {
|
|
237
|
+
const status = args.artifactStatuses.get(artifactName);
|
|
238
|
+
if (status) {
|
|
239
|
+
addValidationStatusByRef({ statusesByRef, ref, status });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const [ref, status] of Object.entries(args.extraStatusesByRef ?? {})) {
|
|
243
|
+
addValidationStatusByRef({ statusesByRef, ref, status });
|
|
244
|
+
}
|
|
245
|
+
return statusesByRef;
|
|
246
|
+
}
|
|
247
|
+
function gateArtifactKey(validationArtifactRef) {
|
|
248
|
+
return path.basename(validationArtifactRef.replace("<round-id>/", ""));
|
|
249
|
+
}
|
|
250
|
+
function addRefToIndex(index, ref) {
|
|
251
|
+
if (!ref)
|
|
252
|
+
return;
|
|
253
|
+
index.allRefs.push(ref);
|
|
254
|
+
const basename = path.basename(ref);
|
|
255
|
+
const refs = index.refsByBasename.get(basename) ?? [];
|
|
256
|
+
refs.push(ref);
|
|
257
|
+
index.refsByBasename.set(basename, refs);
|
|
258
|
+
}
|
|
259
|
+
function buildPredicateInputIndex(args) {
|
|
260
|
+
const index = { refsByBasename: new Map(), allRefs: [] };
|
|
261
|
+
for (const ref of Object.values(args.manifest?.artifact_refs ?? {})) {
|
|
262
|
+
addRefToIndex(index, ref);
|
|
263
|
+
}
|
|
264
|
+
for (const step of args.manifest?.steps ?? []) {
|
|
265
|
+
for (const ref of step.artifact_refs) {
|
|
266
|
+
addRefToIndex(index, ref);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const ref of args.extraRefs ?? []) {
|
|
270
|
+
addRefToIndex(index, ref);
|
|
271
|
+
}
|
|
272
|
+
return index;
|
|
273
|
+
}
|
|
274
|
+
function manifestRefsByBasename(manifest, basename) {
|
|
275
|
+
const refs = [
|
|
276
|
+
...Object.values(manifest?.artifact_refs ?? {}),
|
|
277
|
+
...(manifest?.steps ?? []).flatMap((step) => step.artifact_refs),
|
|
278
|
+
].filter((ref) => typeof ref === "string" && ref.length > 0);
|
|
279
|
+
return [...new Set(refs.filter((ref) => path.basename(ref) === basename))];
|
|
280
|
+
}
|
|
281
|
+
async function readValidationStatusMapFromRefs(refs) {
|
|
282
|
+
const statuses = {};
|
|
283
|
+
await Promise.all(refs.map(async (ref) => {
|
|
284
|
+
const artifact = await readYamlDocumentIfPresent(ref);
|
|
285
|
+
if (artifact?.validation_status) {
|
|
286
|
+
statuses[ref] = artifact.validation_status;
|
|
287
|
+
}
|
|
288
|
+
}));
|
|
289
|
+
return statuses;
|
|
290
|
+
}
|
|
291
|
+
function authorityRefBasename(authorityRef) {
|
|
292
|
+
return path.basename(authorityRef
|
|
293
|
+
.replaceAll("<round-id>/", "")
|
|
294
|
+
.replaceAll("rounds/*/", "")
|
|
295
|
+
.replaceAll("*", ""));
|
|
296
|
+
}
|
|
297
|
+
function concreteInputRefs(inputIndex, authorityRef, roundId) {
|
|
298
|
+
const basename = authorityRefBasename(authorityRef);
|
|
299
|
+
if (basename.length === 0)
|
|
300
|
+
return [];
|
|
301
|
+
const refs = inputIndex.refsByBasename.get(basename) ?? [];
|
|
302
|
+
return roundId ? refs.filter((ref) => roundIdFromRef(ref) === roundId) : refs;
|
|
303
|
+
}
|
|
304
|
+
function artifactExists(inputIndex, authorityRef, roundId) {
|
|
305
|
+
return concreteInputRefs(inputIndex, authorityRef, roundId).length > 0;
|
|
306
|
+
}
|
|
307
|
+
function roundIdFromRef(ref) {
|
|
308
|
+
return ref.match(/(?:^|[/\\])rounds[/\\]([^/\\]+)(?:[/\\]|$)/)?.[1] ?? null;
|
|
309
|
+
}
|
|
310
|
+
function gateIsRoundScoped(args) {
|
|
311
|
+
return args.validationArtifactRef.includes("<round-id>") ||
|
|
312
|
+
args.predicate.gate_instance_scope === "per_round";
|
|
313
|
+
}
|
|
314
|
+
function concreteValidationRefsForGate(inputIndex, validationArtifactRef, roundId) {
|
|
315
|
+
return concreteInputRefs(inputIndex, validationArtifactRef, roundId);
|
|
316
|
+
}
|
|
317
|
+
function predicateExplanation(args) {
|
|
318
|
+
const result = args.result === null ? "unknown" : String(args.result);
|
|
319
|
+
const refs = args.concreteInputRefs.length === 0
|
|
320
|
+
? "no concrete input refs"
|
|
321
|
+
: args.concreteInputRefs.join(", ");
|
|
322
|
+
return `${args.predicate.explanation_template} Result=${result}; inputs=${refs}.`;
|
|
323
|
+
}
|
|
324
|
+
function validationIsValid(artifactStatuses, validationRef) {
|
|
325
|
+
const status = artifactStatuses.get(validationRef) ?? "not_available";
|
|
326
|
+
if (status === "valid")
|
|
327
|
+
return true;
|
|
328
|
+
if (status === "invalid")
|
|
329
|
+
return false;
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function isSupportedPredicateEvaluator(predicate) {
|
|
333
|
+
return predicate.predicate_evaluator_id === "reconstruct_registry_predicate_v1" &&
|
|
334
|
+
predicate.predicate_evaluator_version === 1;
|
|
335
|
+
}
|
|
336
|
+
function isSupportedPredicateTruthExpression(predicate) {
|
|
337
|
+
const expression = predicate.truth_expression;
|
|
338
|
+
return isSupportedPredicateEvaluator(predicate) && (expression === "true" ||
|
|
339
|
+
/^artifact_exists\([^)]+\)$/.test(expression) ||
|
|
340
|
+
expression ===
|
|
341
|
+
"artifact_exists(source-observations.yaml) and source_observations.records_count > 0" ||
|
|
342
|
+
expression === "competency_questions_validation.validation_status == valid" ||
|
|
343
|
+
expression ===
|
|
344
|
+
"seed_validity_projection_requested or handoff_readiness_projection_requested" ||
|
|
345
|
+
expression === "any_required_applicable_validation_artifact_missing_or_failed" ||
|
|
346
|
+
expression ===
|
|
347
|
+
"failure_classification_validation.validation_status == valid and (failure_classification_validation.material_failure_count > 0 or reconstruct_metrics.unresolved_question_count > 0)" ||
|
|
348
|
+
expression ===
|
|
349
|
+
"any_required_applicable_validation_artifact_missing_or_failed or runtime_halted == true" ||
|
|
350
|
+
expression ===
|
|
351
|
+
"any_required_applicable_validation_artifact_missing_or_failed or runtime_halted == true or reconstruct_metrics.unresolved_question_count > 0");
|
|
352
|
+
}
|
|
353
|
+
function evaluatePredicateTruthExpression(args) {
|
|
354
|
+
const expression = args.predicate.truth_expression;
|
|
355
|
+
const artifactExistsMatch = expression.match(/^artifact_exists\(([^)]+)\)$/);
|
|
356
|
+
if (expression === "true")
|
|
357
|
+
return true;
|
|
358
|
+
if (artifactExistsMatch) {
|
|
359
|
+
return artifactExists(args.inputIndex, artifactExistsMatch[1] ?? "", args.roundId);
|
|
360
|
+
}
|
|
361
|
+
if (expression ===
|
|
362
|
+
"artifact_exists(source-observations.yaml) and source_observations.records_count > 0") {
|
|
363
|
+
if (!artifactExists(args.inputIndex, "source-observations.yaml", args.roundId)) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
const count = args.facts.sourceObservationCount ?? args.metrics.source_observation_count;
|
|
367
|
+
return count > 0;
|
|
368
|
+
}
|
|
369
|
+
if (expression === "competency_questions_validation.validation_status == valid") {
|
|
370
|
+
return validationIsValid(args.artifactStatuses, "competency-questions-validation.yaml");
|
|
371
|
+
}
|
|
372
|
+
if (expression ===
|
|
373
|
+
"seed_validity_projection_requested or handoff_readiness_projection_requested") {
|
|
374
|
+
return artifactExists(args.inputIndex, "ontology-seed-validation.yaml", args.roundId) ||
|
|
375
|
+
artifactExists(args.inputIndex, "stop-decision.yaml", args.roundId);
|
|
376
|
+
}
|
|
377
|
+
if (expression ===
|
|
378
|
+
"any_required_applicable_validation_artifact_missing_or_failed") {
|
|
379
|
+
return args.priorGateProjections.some((gate) => gate.applicability === "applicable" &&
|
|
380
|
+
gate.validation_status !== "valid");
|
|
381
|
+
}
|
|
382
|
+
if (expression ===
|
|
383
|
+
"any_required_applicable_validation_artifact_missing_or_failed or runtime_halted == true") {
|
|
384
|
+
return args.facts.runManifestHalted === true ||
|
|
385
|
+
args.priorGateProjections.some((gate) => gate.applicability === "applicable" &&
|
|
386
|
+
gate.validation_status !== "valid");
|
|
387
|
+
}
|
|
388
|
+
if (expression ===
|
|
389
|
+
"any_required_applicable_validation_artifact_missing_or_failed or runtime_halted == true or reconstruct_metrics.unresolved_question_count > 0") {
|
|
390
|
+
return args.facts.runManifestHalted === true ||
|
|
391
|
+
args.metrics.unresolved_question_count > 0 ||
|
|
392
|
+
args.priorGateProjections.some((gate) => gate.applicability === "applicable" &&
|
|
393
|
+
gate.validation_status !== "valid");
|
|
394
|
+
}
|
|
395
|
+
if (expression ===
|
|
396
|
+
"failure_classification_validation.validation_status == valid and (failure_classification_validation.material_failure_count > 0 or reconstruct_metrics.unresolved_question_count > 0)") {
|
|
397
|
+
const status = validationIsValid(args.artifactStatuses, "failure-classification-validation.yaml");
|
|
398
|
+
if (status !== true)
|
|
399
|
+
return status;
|
|
400
|
+
return (args.failureClassificationValidation?.material_failure_count ?? 0) > 0 ||
|
|
401
|
+
args.metrics.unresolved_question_count > 0;
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
function evaluateRequiredWhenPredicate(args) {
|
|
406
|
+
const concreteRefs = args.predicate.input_authority_refs.flatMap((ref) => concreteInputRefs(args.inputIndex, ref, args.roundId));
|
|
407
|
+
const supported = isSupportedPredicateTruthExpression(args.predicate);
|
|
408
|
+
const result = supported ? evaluatePredicateTruthExpression(args) : null;
|
|
409
|
+
const applicability = !supported
|
|
410
|
+
? "unknown"
|
|
411
|
+
: result === true
|
|
412
|
+
? "applicable"
|
|
413
|
+
: result === false || args.predicate.unknown_projection === "not_applicable"
|
|
414
|
+
? "not_applicable"
|
|
415
|
+
: "unknown";
|
|
416
|
+
return {
|
|
417
|
+
result,
|
|
418
|
+
applicability,
|
|
419
|
+
concreteInputRefs: concreteRefs,
|
|
420
|
+
explanation: supported
|
|
421
|
+
? predicateExplanation({
|
|
422
|
+
predicate: args.predicate,
|
|
423
|
+
result,
|
|
424
|
+
concreteInputRefs: concreteRefs,
|
|
425
|
+
})
|
|
426
|
+
: [
|
|
427
|
+
`Unsupported required_when truth expression: ${args.predicate.truth_expression}.`,
|
|
428
|
+
"Runtime fails this gate closed until an evaluator supports the expression.",
|
|
429
|
+
predicateExplanation({
|
|
430
|
+
predicate: args.predicate,
|
|
431
|
+
result,
|
|
432
|
+
concreteInputRefs: concreteRefs,
|
|
433
|
+
}),
|
|
434
|
+
].join(" "),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function roundIdsForGate(args) {
|
|
438
|
+
if (!gateIsRoundScoped({
|
|
439
|
+
validationArtifactRef: args.validationArtifactRef,
|
|
440
|
+
predicate: args.predicate,
|
|
441
|
+
})) {
|
|
442
|
+
return [null];
|
|
443
|
+
}
|
|
444
|
+
const refs = [
|
|
445
|
+
...args.predicate.input_authority_refs.flatMap((ref) => concreteInputRefs(args.inputIndex, ref)),
|
|
446
|
+
...concreteValidationRefsForGate(args.inputIndex, args.validationArtifactRef),
|
|
447
|
+
];
|
|
448
|
+
const roundIds = [...new Set(refs.map(roundIdFromRef).filter((id) => id !== null))].sort();
|
|
449
|
+
return roundIds.length === 0 ? [null] : roundIds;
|
|
450
|
+
}
|
|
451
|
+
function gateInstanceId(gateId, roundId) {
|
|
452
|
+
return roundId ? `${gateId}:${roundId}` : gateId;
|
|
453
|
+
}
|
|
454
|
+
function validationStatusForGate(args) {
|
|
455
|
+
if (args.roundId &&
|
|
456
|
+
args.validationArtifactRef.includes("<round-id>") &&
|
|
457
|
+
args.concreteValidationRefs.length === 0) {
|
|
458
|
+
return "not_available";
|
|
459
|
+
}
|
|
460
|
+
for (const ref of args.concreteValidationRefs) {
|
|
461
|
+
const status = args.artifactStatusesByRef.get(ref) ??
|
|
462
|
+
args.artifactStatusesByRef.get(path.resolve(ref));
|
|
463
|
+
if (status)
|
|
464
|
+
return status;
|
|
465
|
+
}
|
|
466
|
+
return args.artifactStatuses.get(gateArtifactKey(args.validationArtifactRef)) ??
|
|
467
|
+
"not_available";
|
|
468
|
+
}
|
|
469
|
+
function projectGateStatusesOnce(args) {
|
|
470
|
+
const predicatesById = new Map(args.contractRegistry.required_when_predicate_catalog.map((predicate) => [
|
|
471
|
+
predicate.predicate_id,
|
|
472
|
+
predicate,
|
|
473
|
+
]));
|
|
474
|
+
const projected = [];
|
|
475
|
+
for (const gate of args.contractRegistry.validation_gate_catalog) {
|
|
476
|
+
const predicate = predicatesById.get(gate.required_when);
|
|
477
|
+
for (const roundId of predicate
|
|
478
|
+
? roundIdsForGate({
|
|
479
|
+
predicate,
|
|
480
|
+
validationArtifactRef: gate.validation_artifact_ref,
|
|
481
|
+
inputIndex: args.inputIndex,
|
|
482
|
+
})
|
|
483
|
+
: [null]) {
|
|
484
|
+
const evaluated = predicate
|
|
485
|
+
? evaluateRequiredWhenPredicate({
|
|
486
|
+
predicate,
|
|
487
|
+
inputIndex: args.inputIndex,
|
|
488
|
+
artifactStatuses: args.artifactStatuses,
|
|
489
|
+
facts: args.facts,
|
|
490
|
+
metrics: args.metrics,
|
|
491
|
+
failureClassificationValidation: args.failureClassificationValidation,
|
|
492
|
+
priorGateProjections: args.aggregateProjectionBasis ?? projected,
|
|
493
|
+
roundId,
|
|
494
|
+
})
|
|
495
|
+
: null;
|
|
496
|
+
const instanceId = gateInstanceId(gate.gate_id, roundId);
|
|
497
|
+
const concreteValidationRefs = concreteValidationRefsForGate(args.inputIndex, gate.validation_artifact_ref, roundId);
|
|
498
|
+
const predicateProjection = predicate && evaluated
|
|
499
|
+
? {
|
|
500
|
+
gate_instance_id: instanceId,
|
|
501
|
+
round_id: roundId,
|
|
502
|
+
concrete_validation_artifact_ref: concreteValidationRefs[0] ?? null,
|
|
503
|
+
predicate_instance_id: `${instanceId}:${predicate.predicate_id}`,
|
|
504
|
+
predicate_phase: predicate.predicate_phase,
|
|
505
|
+
predicate_evaluator_id: predicate.predicate_evaluator_id,
|
|
506
|
+
predicate_evaluator_version: predicate.predicate_evaluator_version,
|
|
507
|
+
predicate_input_authority_refs: predicate.input_authority_refs,
|
|
508
|
+
predicate_concrete_input_refs: evaluated.concreteInputRefs,
|
|
509
|
+
predicate_truth_expression: predicate.truth_expression,
|
|
510
|
+
predicate_result: evaluated.result,
|
|
511
|
+
unknown_projection: predicate.unknown_projection,
|
|
512
|
+
explanation: evaluated.explanation,
|
|
513
|
+
}
|
|
514
|
+
: {
|
|
515
|
+
gate_instance_id: instanceId,
|
|
516
|
+
round_id: roundId,
|
|
517
|
+
concrete_validation_artifact_ref: concreteValidationRefs[0] ?? null,
|
|
518
|
+
predicate_instance_id: `${instanceId}:${gate.required_when}`,
|
|
519
|
+
predicate_phase: "gate_applicability",
|
|
520
|
+
predicate_evaluator_id: "unknown",
|
|
521
|
+
predicate_evaluator_version: 0,
|
|
522
|
+
predicate_input_authority_refs: [],
|
|
523
|
+
predicate_concrete_input_refs: [],
|
|
524
|
+
predicate_truth_expression: "unknown_predicate",
|
|
525
|
+
predicate_result: null,
|
|
526
|
+
unknown_projection: "blocked",
|
|
527
|
+
explanation: `No required_when_predicate_catalog row exists for ${gate.required_when}.`,
|
|
528
|
+
};
|
|
529
|
+
if (gate.validation_artifact_ref === "handoff-decision-validation.yaml") {
|
|
530
|
+
projected.push({
|
|
531
|
+
gate_id: gate.gate_id,
|
|
532
|
+
validation_artifact_ref: gate.validation_artifact_ref,
|
|
533
|
+
required_when: gate.required_when,
|
|
534
|
+
...predicateProjection,
|
|
535
|
+
applicability: "self_validation_output",
|
|
536
|
+
validation_status: "not_applicable",
|
|
537
|
+
});
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const applicability = evaluated?.applicability ?? "unknown";
|
|
541
|
+
if (applicability === "not_applicable") {
|
|
542
|
+
projected.push({
|
|
543
|
+
gate_id: gate.gate_id,
|
|
544
|
+
validation_artifact_ref: gate.validation_artifact_ref,
|
|
545
|
+
required_when: gate.required_when,
|
|
546
|
+
...predicateProjection,
|
|
547
|
+
applicability: "not_applicable",
|
|
548
|
+
validation_status: "not_applicable",
|
|
549
|
+
});
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
const status = validationStatusForGate({
|
|
553
|
+
artifactStatuses: args.artifactStatuses,
|
|
554
|
+
artifactStatusesByRef: args.artifactStatusesByRef,
|
|
555
|
+
validationArtifactRef: gate.validation_artifact_ref,
|
|
556
|
+
concreteValidationRefs,
|
|
557
|
+
roundId,
|
|
558
|
+
});
|
|
559
|
+
projected.push({
|
|
560
|
+
gate_id: gate.gate_id,
|
|
561
|
+
validation_artifact_ref: gate.validation_artifact_ref,
|
|
562
|
+
required_when: gate.required_when,
|
|
563
|
+
...predicateProjection,
|
|
564
|
+
applicability,
|
|
565
|
+
validation_status: applicability === "unknown" ? "not_available" : status,
|
|
566
|
+
});
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return projected;
|
|
571
|
+
}
|
|
572
|
+
function projectGateStatuses(args) {
|
|
573
|
+
const firstPass = projectGateStatusesOnce(args);
|
|
574
|
+
return projectGateStatusesOnce({
|
|
575
|
+
...args,
|
|
576
|
+
aggregateProjectionBasis: firstPass,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
export function validateHandoffDecision(args) {
|
|
580
|
+
const artifactStatuses = validationArtifactStatuses(args);
|
|
581
|
+
const artifactStatusesByRef = validationArtifactStatusesByRef({
|
|
582
|
+
refs: args.validationArtifactRefs,
|
|
583
|
+
extraStatusesByRef: args.extraValidationArtifactStatusesByRef,
|
|
584
|
+
artifactStatuses,
|
|
585
|
+
});
|
|
586
|
+
const inputIndex = buildPredicateInputIndex({
|
|
587
|
+
manifest: args.manifest,
|
|
588
|
+
extraRefs: [
|
|
589
|
+
args.stopDecisionRef,
|
|
590
|
+
args.manifestValidationRef,
|
|
591
|
+
...(args.predicateInputRefs ?? []),
|
|
592
|
+
],
|
|
593
|
+
});
|
|
594
|
+
const gateProjection = projectGateStatuses({
|
|
595
|
+
contractRegistry: args.contractRegistry,
|
|
596
|
+
artifactStatuses,
|
|
597
|
+
artifactStatusesByRef,
|
|
598
|
+
inputIndex,
|
|
599
|
+
facts: args.predicateFacts ?? {},
|
|
600
|
+
metrics: args.metrics,
|
|
601
|
+
failureClassificationValidation: args.failureClassificationValidation,
|
|
602
|
+
});
|
|
603
|
+
const statuses = Object.fromEntries(gateProjection.map((gate) => [
|
|
604
|
+
gate.gate_instance_id ?? gate.gate_id,
|
|
605
|
+
gate.validation_status,
|
|
606
|
+
]));
|
|
607
|
+
const violations = [];
|
|
608
|
+
for (const gate of gateProjection) {
|
|
609
|
+
if (gate.applicability === "not_applicable" || gate.applicability === "self_validation_output") {
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (gate.applicability === "unknown") {
|
|
613
|
+
violations.push(violation({
|
|
614
|
+
code: "handoff_required_validation_missing",
|
|
615
|
+
message: `handoff validation cannot determine required gate applicability for ${gate.gate_id} (${gate.validation_artifact_ref})`,
|
|
616
|
+
subjectId: gate.gate_instance_id ?? gate.gate_id,
|
|
617
|
+
}));
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
const status = gate.validation_status;
|
|
621
|
+
if (status === "not_available") {
|
|
622
|
+
violations.push(violation({
|
|
623
|
+
code: "handoff_required_validation_missing",
|
|
624
|
+
message: `handoff validation requires ${gate.gate_id} (${gate.validation_artifact_ref}) validation`,
|
|
625
|
+
subjectId: gate.gate_instance_id ?? gate.gate_id,
|
|
626
|
+
}));
|
|
627
|
+
}
|
|
628
|
+
else if (status === "invalid") {
|
|
629
|
+
violations.push(violation({
|
|
630
|
+
code: "handoff_required_validation_invalid",
|
|
631
|
+
message: `handoff validation requires ${gate.gate_id} (${gate.validation_artifact_ref}) validation to be valid`,
|
|
632
|
+
subjectId: gate.gate_instance_id ?? gate.gate_id,
|
|
633
|
+
}));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const projection = readinessProjection({
|
|
637
|
+
statuses,
|
|
638
|
+
metrics: args.metrics,
|
|
639
|
+
ontologySeed: args.ontologySeed,
|
|
640
|
+
competencyQuestionAssessment: args.competencyQuestionAssessment,
|
|
641
|
+
seedConfirmationValidation: args.seedConfirmationValidation,
|
|
642
|
+
materialFailureCount: args.failureClassificationValidation?.material_failure_count ?? 0,
|
|
643
|
+
});
|
|
644
|
+
if (args.stopDecision.decision === "stop" &&
|
|
645
|
+
projection !== "ready" &&
|
|
646
|
+
projection !== "limited") {
|
|
647
|
+
violations.push(violation({
|
|
648
|
+
code: "handoff_decision_inconsistent",
|
|
649
|
+
message: `stop decision cannot be stop when readiness projection is ${projection}`,
|
|
650
|
+
subjectId: args.stopDecision.decision,
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
if (args.stopDecision.decision !== "stop") {
|
|
654
|
+
violations.push(violation({
|
|
655
|
+
code: "handoff_decision_inconsistent",
|
|
656
|
+
message: `terminal handoff requires stop decision; received ${args.stopDecision.decision}`,
|
|
657
|
+
subjectId: args.stopDecision.decision,
|
|
658
|
+
}));
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
schema_version: "1",
|
|
662
|
+
session_id: args.stopDecision.session_id,
|
|
663
|
+
created_at: isoNow(),
|
|
664
|
+
stop_decision_ref: args.stopDecisionRef ?? null,
|
|
665
|
+
pre_handoff_run_manifest_validation_ref: args.manifestValidationRef ?? null,
|
|
666
|
+
validation_status: violations.length === 0 ? "valid" : "invalid",
|
|
667
|
+
readiness_projection_source: "runtime_gate_projection",
|
|
668
|
+
readiness_projection: projection,
|
|
669
|
+
required_validation_statuses: statuses,
|
|
670
|
+
gate_projection: gateProjection,
|
|
671
|
+
material_failure_count: args.failureClassificationValidation?.material_failure_count ?? 0,
|
|
672
|
+
unresolved_count: args.metrics.unresolved_question_count,
|
|
673
|
+
validation_results: violations.length === 0
|
|
674
|
+
? ["handoff_decision_valid"]
|
|
675
|
+
: ["handoff_decision_invalid"],
|
|
676
|
+
violations,
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
export async function writeReconstructRunManifestValidationArtifact(args) {
|
|
680
|
+
const manifest = await readYamlDocument(args.manifestPath);
|
|
681
|
+
const [contractRegistry, targetMaterialProfile] = await Promise.all([
|
|
682
|
+
loadReconstructContractRegistry({ registryPath: args.registryPath }),
|
|
683
|
+
readYamlDocument(args.targetMaterialProfilePath),
|
|
684
|
+
]);
|
|
685
|
+
const validation = await validateReconstructRunManifest({
|
|
686
|
+
manifest,
|
|
687
|
+
manifestRef: path.resolve(args.manifestPath),
|
|
688
|
+
projectRoot: args.projectRoot,
|
|
689
|
+
registryPath: path.resolve(args.registryPath),
|
|
690
|
+
contractRegistry,
|
|
691
|
+
selectedSourceProfiles: targetMaterialProfile.selected_source_profiles,
|
|
692
|
+
lensIds: args.lensIds,
|
|
693
|
+
admittedDomainIds: args.admittedDomainIds ?? [],
|
|
694
|
+
});
|
|
695
|
+
await writeYamlDocument(args.outputPath, validation);
|
|
696
|
+
return validation;
|
|
697
|
+
}
|
|
698
|
+
export async function writeHandoffDecisionValidationArtifact(args) {
|
|
699
|
+
const [stopDecision, manifestValidation, metrics, contractRegistry,] = await Promise.all([
|
|
700
|
+
readYamlDocument(args.stopDecisionPath),
|
|
701
|
+
readYamlDocument(args.manifestValidationPath),
|
|
702
|
+
readYamlDocument(args.metricsPath),
|
|
703
|
+
loadReconstructContractRegistry({ registryPath: args.registryPath }),
|
|
704
|
+
]);
|
|
705
|
+
const manifest = await readYamlDocumentIfPresent(manifestValidation.reconstruct_run_manifest_ref);
|
|
706
|
+
const [targetMaterialProfileValidation, sourceObservationDirectiveValidation, sourceFrontierValidation, candidateDispositionValidation, ontologySeed, ontologySeedValidation, claimRealizationMapValidation, competencyQuestionsValidation, competencyQuestionAssessment, competencyQuestionAssessmentValidation, seedConfirmationValidation, failureClassificationValidation, revisionProposalValidation,] = await Promise.all([
|
|
707
|
+
readYamlDocumentIfPresent(args.targetMaterialProfileValidationPath),
|
|
708
|
+
readYamlDocumentIfPresent(args.sourceObservationDirectiveValidationPath),
|
|
709
|
+
readYamlDocumentIfPresent(args.sourceFrontierValidationPath),
|
|
710
|
+
readYamlDocumentIfPresent(args.candidateDispositionValidationPath),
|
|
711
|
+
readYamlDocumentIfPresent(manifest?.artifact_refs.ontology_seed),
|
|
712
|
+
readYamlDocumentIfPresent(args.ontologySeedValidationPath),
|
|
713
|
+
readYamlDocumentIfPresent(args.claimRealizationMapValidationPath),
|
|
714
|
+
readYamlDocumentIfPresent(args.competencyQuestionsValidationPath),
|
|
715
|
+
readYamlDocumentIfPresent(manifest?.artifact_refs.competency_question_assessment),
|
|
716
|
+
readYamlDocumentIfPresent(args.competencyQuestionAssessmentValidationPath),
|
|
717
|
+
readYamlDocumentIfPresent(args.seedConfirmationValidationPath),
|
|
718
|
+
readYamlDocumentIfPresent(args.failureClassificationValidationPath),
|
|
719
|
+
readYamlDocumentIfPresent(args.revisionProposalValidationPath),
|
|
720
|
+
]);
|
|
721
|
+
const sourceObservations = await readYamlDocumentIfPresent(manifest?.artifact_refs.source_observations);
|
|
722
|
+
const extraValidationArtifactStatusesByRef = await readValidationStatusMapFromRefs([
|
|
723
|
+
...manifestRefsByBasename(manifest, "source-frontier-validation.yaml"),
|
|
724
|
+
]);
|
|
725
|
+
const validation = validateHandoffDecision({
|
|
726
|
+
stopDecision,
|
|
727
|
+
stopDecisionRef: path.resolve(args.stopDecisionPath),
|
|
728
|
+
manifestValidation,
|
|
729
|
+
manifestValidationRef: path.resolve(args.manifestValidationPath),
|
|
730
|
+
manifest,
|
|
731
|
+
ontologySeed,
|
|
732
|
+
competencyQuestionAssessment,
|
|
733
|
+
predicateInputRefs: [
|
|
734
|
+
targetMaterialProfileValidation ? args.targetMaterialProfileValidationPath : null,
|
|
735
|
+
sourceObservationDirectiveValidation
|
|
736
|
+
? args.sourceObservationDirectiveValidationPath
|
|
737
|
+
: null,
|
|
738
|
+
sourceFrontierValidation ? args.sourceFrontierValidationPath : null,
|
|
739
|
+
candidateDispositionValidation ? args.candidateDispositionValidationPath : null,
|
|
740
|
+
ontologySeedValidation ? args.ontologySeedValidationPath : null,
|
|
741
|
+
claimRealizationMapValidation ? args.claimRealizationMapValidationPath : null,
|
|
742
|
+
competencyQuestionsValidation ? args.competencyQuestionsValidationPath : null,
|
|
743
|
+
competencyQuestionAssessmentValidation
|
|
744
|
+
? args.competencyQuestionAssessmentValidationPath
|
|
745
|
+
: null,
|
|
746
|
+
seedConfirmationValidation ? args.seedConfirmationValidationPath : null,
|
|
747
|
+
failureClassificationValidation ? args.failureClassificationValidationPath : null,
|
|
748
|
+
revisionProposalValidation ? args.revisionProposalValidationPath : null,
|
|
749
|
+
],
|
|
750
|
+
predicateFacts: {
|
|
751
|
+
sourceObservationCount: sourceObservations?.observations.length ?? null,
|
|
752
|
+
runManifestHalted: manifest?.steps?.some((step) => step.status === "failed") ?? null,
|
|
753
|
+
},
|
|
754
|
+
validationArtifactRefs: {
|
|
755
|
+
"target-material-profile-validation.yaml": targetMaterialProfileValidation
|
|
756
|
+
? args.targetMaterialProfileValidationPath
|
|
757
|
+
: null,
|
|
758
|
+
"source-observation-directive-validation.yaml": sourceObservationDirectiveValidation
|
|
759
|
+
? args.sourceObservationDirectiveValidationPath
|
|
760
|
+
: null,
|
|
761
|
+
"source-frontier-validation.yaml": sourceFrontierValidation
|
|
762
|
+
? args.sourceFrontierValidationPath
|
|
763
|
+
: null,
|
|
764
|
+
"candidate-disposition-validation.yaml": candidateDispositionValidation
|
|
765
|
+
? args.candidateDispositionValidationPath
|
|
766
|
+
: null,
|
|
767
|
+
"ontology-seed-validation.yaml": ontologySeedValidation
|
|
768
|
+
? args.ontologySeedValidationPath
|
|
769
|
+
: null,
|
|
770
|
+
"claim-realization-map-validation.yaml": claimRealizationMapValidation
|
|
771
|
+
? args.claimRealizationMapValidationPath
|
|
772
|
+
: null,
|
|
773
|
+
"competency-questions-validation.yaml": competencyQuestionsValidation
|
|
774
|
+
? args.competencyQuestionsValidationPath
|
|
775
|
+
: null,
|
|
776
|
+
"competency-question-assessment-validation.yaml": competencyQuestionAssessmentValidation
|
|
777
|
+
? args.competencyQuestionAssessmentValidationPath
|
|
778
|
+
: null,
|
|
779
|
+
"seed-confirmation-validation.yaml": seedConfirmationValidation
|
|
780
|
+
? args.seedConfirmationValidationPath
|
|
781
|
+
: null,
|
|
782
|
+
"failure-classification-validation.yaml": failureClassificationValidation
|
|
783
|
+
? args.failureClassificationValidationPath
|
|
784
|
+
: null,
|
|
785
|
+
"revision-proposal-validation.yaml": revisionProposalValidation
|
|
786
|
+
? args.revisionProposalValidationPath
|
|
787
|
+
: null,
|
|
788
|
+
"reconstruct-run-manifest.pre-handoff-validation.yaml": args.manifestValidationPath,
|
|
789
|
+
},
|
|
790
|
+
extraValidationArtifactStatusesByRef,
|
|
791
|
+
metrics,
|
|
792
|
+
targetMaterialProfileValidation,
|
|
793
|
+
sourceObservationDirectiveValidation,
|
|
794
|
+
sourceFrontierValidation,
|
|
795
|
+
candidateDispositionValidation,
|
|
796
|
+
ontologySeedValidation,
|
|
797
|
+
claimRealizationMapValidation,
|
|
798
|
+
competencyQuestionsValidation,
|
|
799
|
+
competencyQuestionAssessmentValidation,
|
|
800
|
+
seedConfirmationValidation,
|
|
801
|
+
failureClassificationValidation,
|
|
802
|
+
revisionProposalValidation,
|
|
803
|
+
contractRegistry,
|
|
804
|
+
});
|
|
805
|
+
await writeYamlDocument(args.outputPath, validation);
|
|
806
|
+
return validation;
|
|
807
|
+
}
|