@tiangong-lca/foundry 0.1.2
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/LICENSE +21 -0
- package/README.md +532 -0
- package/docs/architecture.md +450 -0
- package/docs/foundry-task-contracts.md +147 -0
- package/docs/import-profiles/bafu/constraints.md +343 -0
- package/docs/import-profiles/bafu/leaf-process-classification-authoring.md +153 -0
- package/docs/import-profiles/bafu/profile.md +183 -0
- package/docs/import-profiles/uslci/constraints.md +29 -0
- package/docs/import-profiles/uslci/profile.md +43 -0
- package/docs/import-profiles/worldsteel/constraints.md +77 -0
- package/docs/import-profiles/worldsteel/import-coverage.md +93 -0
- package/docs/import-profiles/worldsteel/import-plan.md +375 -0
- package/docs/import-profiles/worldsteel/profile.md +78 -0
- package/docs/package-distribution-contract.md +287 -0
- package/docs/public-runtime-contract.md +218 -0
- package/docs/runtime-context-contract.md +138 -0
- package/docs/safety-policy.md +164 -0
- package/docs/task-authorization-contract.md +131 -0
- package/docs/uslci-import-runbook.md +336 -0
- package/docs/workspace-migration-contract.md +127 -0
- package/package-dist/assets/foundry-package-descriptor.json +1661 -0
- package/package-dist/scripts/foundry-facade.d.ts +78 -0
- package/package-dist/scripts/foundry-facade.js +1317 -0
- package/package-dist/scripts/foundry-runtime.d.ts +180 -0
- package/package-dist/scripts/foundry-runtime.js +190 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.d.ts +27 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-attempt-ledger.js +85 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.d.ts +38 -0
- package/package-dist/scripts/lib/batch-orchestration/scope-resume-contract.js +90 -0
- package/package-dist/scripts/lib/bundle-row-types.d.ts +44 -0
- package/package-dist/scripts/lib/bundle-row-types.js +46 -0
- package/package-dist/scripts/lib/bundle-sample-utils.d.ts +183 -0
- package/package-dist/scripts/lib/bundle-sample-utils.js +526 -0
- package/package-dist/scripts/lib/bundle-source-context.d.ts +31 -0
- package/package-dist/scripts/lib/bundle-source-context.js +142 -0
- package/package-dist/scripts/lib/canonical-description.d.ts +12 -0
- package/package-dist/scripts/lib/canonical-description.js +72 -0
- package/package-dist/scripts/lib/canonical-support-rewrites.d.ts +127 -0
- package/package-dist/scripts/lib/canonical-support-rewrites.js +527 -0
- package/package-dist/scripts/lib/decision-owners/classification.d.ts +245 -0
- package/package-dist/scripts/lib/decision-owners/classification.js +754 -0
- package/package-dist/scripts/lib/decision-owners/identity-preflight.d.ts +333 -0
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +1353 -0
- package/package-dist/scripts/lib/decision-owners/identity-task.d.ts +130 -0
- package/package-dist/scripts/lib/decision-owners/identity-task.js +494 -0
- package/package-dist/scripts/lib/decision-owners/identity.d.ts +74 -0
- package/package-dist/scripts/lib/decision-owners/identity.js +443 -0
- package/package-dist/scripts/lib/decision-owners/location.d.ts +239 -0
- package/package-dist/scripts/lib/decision-owners/location.js +704 -0
- package/package-dist/scripts/lib/decision-task-utils.d.ts +484 -0
- package/package-dist/scripts/lib/decision-task-utils.js +735 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +52 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +146 -0
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.d.ts +79 -0
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +515 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +234 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +1720 -0
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.d.ts +140 -0
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +656 -0
- package/package-dist/scripts/lib/foundry-args.d.ts +7 -0
- package/package-dist/scripts/lib/foundry-args.js +38 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.js +55 -0
- package/package-dist/scripts/lib/foundry-authorization-input.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-authorization-input.js +151 -0
- package/package-dist/scripts/lib/foundry-command-metadata.d.ts +32 -0
- package/package-dist/scripts/lib/foundry-command-metadata.js +1012 -0
- package/package-dist/scripts/lib/foundry-command-registry.d.ts +34 -0
- package/package-dist/scripts/lib/foundry-command-registry.js +241 -0
- package/package-dist/scripts/lib/foundry-command-spec.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-command-spec.js +1 -0
- package/package-dist/scripts/lib/foundry-decision-owners.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-decision-owners.js +68 -0
- package/package-dist/scripts/lib/foundry-decision-routing.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-decision-routing.js +38 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +33 -0
- package/package-dist/scripts/lib/foundry-execution-admission.js +225 -0
- package/package-dist/scripts/lib/foundry-execution-attempt.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-execution-attempt.js +33 -0
- package/package-dist/scripts/lib/foundry-execution-context-format.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-execution-context-format.js +83 -0
- package/package-dist/scripts/lib/foundry-facade-store.d.ts +25 -0
- package/package-dist/scripts/lib/foundry-facade-store.js +449 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +203 -0
- package/package-dist/scripts/lib/foundry-identity-owners.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-identity-owners.js +58 -0
- package/package-dist/scripts/lib/foundry-managed-host.d.ts +7 -0
- package/package-dist/scripts/lib/foundry-managed-host.js +173 -0
- package/package-dist/scripts/lib/foundry-migration-adoption-plan.d.ts +39 -0
- package/package-dist/scripts/lib/foundry-migration-adoption-plan.js +467 -0
- package/package-dist/scripts/lib/foundry-migration-adoption.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-migration-adoption.js +187 -0
- package/package-dist/scripts/lib/foundry-migration-authority.d.ts +42 -0
- package/package-dist/scripts/lib/foundry-migration-authority.js +280 -0
- package/package-dist/scripts/lib/foundry-migration-inventory.d.ts +31 -0
- package/package-dist/scripts/lib/foundry-migration-inventory.js +148 -0
- package/package-dist/scripts/lib/foundry-migration-plan.d.ts +48 -0
- package/package-dist/scripts/lib/foundry-migration-plan.js +234 -0
- package/package-dist/scripts/lib/foundry-migration-replay.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-migration-replay.js +134 -0
- package/package-dist/scripts/lib/foundry-migration-stage.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-migration-stage.js +152 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.js +226 -0
- package/package-dist/scripts/lib/foundry-migration-transfer.d.ts +36 -0
- package/package-dist/scripts/lib/foundry-migration-transfer.js +350 -0
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +71 -0
- package/package-dist/scripts/lib/foundry-operation-result.js +264 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +319 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +293 -0
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +189 -0
- package/package-dist/scripts/lib/foundry-owner-trace-acceptance.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-owner-trace-acceptance.js +68 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +56 -0
- package/package-dist/scripts/lib/foundry-package-contract.js +392 -0
- package/package-dist/scripts/lib/foundry-private-path.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-private-path.js +20 -0
- package/package-dist/scripts/lib/foundry-runtime-cache.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-runtime-cache.js +25 -0
- package/package-dist/scripts/lib/foundry-runtime-command-policy.d.ts +20 -0
- package/package-dist/scripts/lib/foundry-runtime-command-policy.js +173 -0
- package/package-dist/scripts/lib/foundry-runtime-context-types.d.ts +59 -0
- package/package-dist/scripts/lib/foundry-runtime-context-types.js +1 -0
- package/package-dist/scripts/lib/foundry-runtime-context.d.ts +27 -0
- package/package-dist/scripts/lib/foundry-runtime-context.js +668 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +9 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +90 -0
- package/package-dist/scripts/lib/foundry-runtime-error.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-runtime-error.js +8 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +127 -0
- package/package-dist/scripts/lib/foundry-runtime-paths.d.ts +16 -0
- package/package-dist/scripts/lib/foundry-runtime-paths.js +159 -0
- package/package-dist/scripts/lib/foundry-runtime-qualification.d.ts +66 -0
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +223 -0
- package/package-dist/scripts/lib/foundry-runtime-selection-record.d.ts +16 -0
- package/package-dist/scripts/lib/foundry-runtime-selection-record.js +32 -0
- package/package-dist/scripts/lib/foundry-runtime-selection.d.ts +14 -0
- package/package-dist/scripts/lib/foundry-runtime-selection.js +123 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +178 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +603 -0
- package/package-dist/scripts/lib/foundry-semantic-input.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +132 -0
- package/package-dist/scripts/lib/foundry-task-authorization.d.ts +68 -0
- package/package-dist/scripts/lib/foundry-task-authorization.js +350 -0
- package/package-dist/scripts/lib/foundry-task-io.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-task-io.js +92 -0
- package/package-dist/scripts/lib/foundry-task-registration.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +384 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +34 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.js +161 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-task-store.js +466 -0
- package/package-dist/scripts/lib/foundry-task-types.d.ts +99 -0
- package/package-dist/scripts/lib/foundry-task-types.js +1 -0
- package/package-dist/scripts/lib/foundry-workflow-approval-continuation.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-approval-continuation.js +136 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +231 -0
- package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +174 -0
- package/package-dist/scripts/lib/foundry-workflow-context.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-workflow-context.js +99 -0
- package/package-dist/scripts/lib/foundry-workflow-decisions.d.ts +18 -0
- package/package-dist/scripts/lib/foundry-workflow-decisions.js +123 -0
- package/package-dist/scripts/lib/foundry-workflow-execution.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-workflow-execution.js +248 -0
- package/package-dist/scripts/lib/foundry-workflow-finalize.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +264 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-apply.d.ts +14 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-apply.js +159 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +153 -0
- package/package-dist/scripts/lib/foundry-workflow-import.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-import.js +70 -0
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-workflow-io.js +77 -0
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.d.ts +41 -0
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +266 -0
- package/package-dist/scripts/lib/foundry-workflow-rows.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-workflow-rows.js +47 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +367 -0
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +37 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +158 -0
- package/package-dist/scripts/lib/full-context-proof.d.ts +51 -0
- package/package-dist/scripts/lib/full-context-proof.js +932 -0
- package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +184 -0
- package/package-dist/scripts/lib/identity-preflight-artifacts.js +573 -0
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +117 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +341 -0
- package/package-dist/scripts/lib/identity-reference-rewrite-utils.d.ts +147 -0
- package/package-dist/scripts/lib/identity-reference-rewrite-utils.js +817 -0
- package/package-dist/scripts/lib/import-curation/authoring-packages.d.ts +28 -0
- package/package-dist/scripts/lib/import-curation/authoring-packages.js +92 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +32 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +203 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +47 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.js +528 -0
- package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.d.ts +24 -0
- package/package-dist/scripts/lib/import-curation/internal/artifact-inputs.js +152 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.d.ts +3 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-patch-workflow.js +3 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/internal/authoring-task-workflow.js +1 -0
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.d.ts +56 -0
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +206 -0
- package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.d.ts +14 -0
- package/package-dist/scripts/lib/import-curation/internal/curation-gate-workflow.js +14 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-payload.d.ts +70 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-payload.js +141 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-types.d.ts +25 -0
- package/package-dist/scripts/lib/import-curation/internal/dataset-types.js +45 -0
- package/package-dist/scripts/lib/import-curation/internal/full-context-proof.d.ts +129 -0
- package/package-dist/scripts/lib/import-curation/internal/full-context-proof.js +552 -0
- package/package-dist/scripts/lib/import-curation/internal/hash-utils.d.ts +2 -0
- package/package-dist/scripts/lib/import-curation/internal/hash-utils.js +10 -0
- package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.d.ts +15 -0
- package/package-dist/scripts/lib/import-curation/internal/mutation-manifest-workflow.js +15 -0
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +31 -0
- package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +467 -0
- package/package-dist/scripts/lib/import-curation/internal/profiles-config.d.ts +47 -0
- package/package-dist/scripts/lib/import-curation/internal/profiles-config.js +88 -0
- package/package-dist/scripts/lib/import-curation/internal/runtime-io.d.ts +23 -0
- package/package-dist/scripts/lib/import-curation/internal/runtime-io.js +132 -0
- package/package-dist/scripts/lib/import-curation/internal/trace-summary.d.ts +53 -0
- package/package-dist/scripts/lib/import-curation/internal/trace-summary.js +114 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.d.ts +141 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +854 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.d.ts +20 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-apply-context.js +46 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.d.ts +110 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-decision-full-context.js +782 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.d.ts +24 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-dry-run-context.js +191 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.d.ts +80 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-evidence-scope.js +359 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.d.ts +146 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-decision-context.js +381 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.d.ts +223 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +1079 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.d.ts +41 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +412 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.d.ts +117 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence-context.js +278 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.d.ts +59 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-patch-evidence.js +593 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.d.ts +58 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +263 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.d.ts +177 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +812 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.d.ts +159 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-row-transform-context.js +466 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.d.ts +152 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +1377 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.d.ts +38 -0
- package/package-dist/scripts/lib/import-curation/internal/workflow-source-reference-context.js +116 -0
- package/package-dist/scripts/lib/import-curation/mutation-manifest.d.ts +51 -0
- package/package-dist/scripts/lib/import-curation/mutation-manifest.js +542 -0
- package/package-dist/scripts/lib/import-curation/patch-collect.d.ts +18 -0
- package/package-dist/scripts/lib/import-curation/patch-collect.js +172 -0
- package/package-dist/scripts/lib/import-curation/profiles.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/profiles.js +1 -0
- package/package-dist/scripts/lib/import-curation/trace-summary.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/trace-summary.js +1 -0
- package/package-dist/scripts/lib/oauth-session-reference.d.ts +1 -0
- package/package-dist/scripts/lib/oauth-session-reference.js +20 -0
- package/package-dist/scripts/lib/post-authoring-finalize-utils.d.ts +95 -0
- package/package-dist/scripts/lib/post-authoring-finalize-utils.js +548 -0
- package/package-dist/scripts/lib/post-write-root-proof.d.ts +44 -0
- package/package-dist/scripts/lib/post-write-root-proof.js +169 -0
- package/package-dist/scripts/lib/reference-description-text.d.ts +2 -0
- package/package-dist/scripts/lib/reference-description-text.js +12 -0
- package/package-dist/scripts/lib/remote-verification-accepted-diff.d.ts +42 -0
- package/package-dist/scripts/lib/remote-verification-accepted-diff.js +424 -0
- package/package-dist/scripts/lib/same-identity-commit-recovery.d.ts +8 -0
- package/package-dist/scripts/lib/same-identity-commit-recovery.js +52 -0
- package/package-dist/scripts/lib/source-semantics.d.ts +255 -0
- package/package-dist/scripts/lib/source-semantics.js +888 -0
- package/package-dist/scripts/lib/stage-contract.d.ts +36 -0
- package/package-dist/scripts/lib/stage-contract.js +25 -0
- package/package-dist/scripts/lib/task-authorization.d.ts +84 -0
- package/package-dist/scripts/lib/task-authorization.js +210 -0
- package/package-dist/scripts/lib/tidas-adapter.d.ts +113 -0
- package/package-dist/scripts/lib/tidas-adapter.js +525 -0
- package/package-dist/scripts/lib/tidas-language-utils.d.ts +8 -0
- package/package-dist/scripts/lib/tidas-language-utils.js +206 -0
- package/package-dist/scripts/lib/tidas-row-utils.d.ts +70 -0
- package/package-dist/scripts/lib/tidas-row-utils.js +225 -0
- package/package-dist/scripts/lib/trace-coverage.d.ts +53 -0
- package/package-dist/scripts/lib/trace-coverage.js +178 -0
- package/package-dist/scripts/package-entry.d.ts +2 -0
- package/package-dist/scripts/package-entry.js +4 -0
- package/package-dist/scripts/public-api.d.ts +80 -0
- package/package-dist/scripts/public-api.js +28 -0
- package/package-dist/scripts/runtime-entry.d.ts +23 -0
- package/package-dist/scripts/runtime-entry.js +424 -0
- package/package.json +93 -0
- package/specs/canonical-support/flow-properties-unit-groups.json +2692 -0
- package/specs/import-profiles.json +118 -0
- package/specs/prewrite-content-policy.json +105 -0
- package/specs/schemas/authorization-derivation.schema.json +34 -0
- package/specs/schemas/execution-context.schema.json +68 -0
- package/specs/schemas/foundry-authorization-input.schema.json +120 -0
- package/specs/schemas/foundry-facade-request-index.schema.json +78 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +122 -0
- package/specs/schemas/foundry-migration-activation.schema.json +213 -0
- package/specs/schemas/foundry-migration-adoption-plan.schema.json +548 -0
- package/specs/schemas/foundry-migration-transfer-receipt.schema.json +93 -0
- package/specs/schemas/foundry-operation-result.schema.json +147 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +134 -0
- package/specs/schemas/foundry-runtime-selection.schema.json +59 -0
- package/specs/schemas/foundry-semantic-input.schema.json +36 -0
- package/specs/schemas/foundry-task-start.schema.json +123 -0
- package/specs/schemas/foundry-workspace-migration-pending.schema.json +17 -0
- package/specs/schemas/foundry-workspace-migration-plan.schema.json +59 -0
- package/specs/schemas/foundry-workspace-migration-transfer-plan.schema.json +357 -0
- package/specs/schemas/foundry-workspace-v2.schema.json +70 -0
- package/specs/schemas/runtime-qualification.schema.json +63 -0
- package/specs/schemas/task-authorization.schema.json +154 -0
- package/specs/schemas/tidas-runtime-expectation.schema.json +54 -0
|
@@ -0,0 +1,1079 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { validateIdentityPreflightEvidence } from "../../identity-preflight-proof.js";
|
|
3
|
+
import { readJsonLinesIfExists, resolveArtifactPath } from "./artifact-inputs.js";
|
|
4
|
+
import { dataSetInformation, datasetRoot, identityFreshnessIdentityKey, } from "./dataset-payload.js";
|
|
5
|
+
import { sha256Json } from "./hash-utils.js";
|
|
6
|
+
import { asText, ensureArray, fileExists, readJson, readJsonIfExists, readText, repoRelativePath, resolveRepoPath, } from "./runtime-io.js";
|
|
7
|
+
import { identityDecisionApplyContextClosesAction, } from "./workflow-identity-decision-context.js";
|
|
8
|
+
import { classCode, classLevel, classText, locationCodeMapForPatch, processCategoryPathForCode, } from "./workflow-patch-evidence.js";
|
|
9
|
+
import { identityPreflightIndexPath } from "./workflow-queue-context.js";
|
|
10
|
+
import { deterministicRowsFileTransformEntries } from "./workflow-row-transform-context.js";
|
|
11
|
+
import { classificationEntriesForPayload, flowTypeForPayload, flowUsesElementaryClassification, jsonPointerToken, nameTextForPayload, } from "./workflow-semantic-actions.js";
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function asRecord(value) {
|
|
16
|
+
return isRecord(value) ? value : {};
|
|
17
|
+
}
|
|
18
|
+
// part-01.mjs
|
|
19
|
+
export function identityPreflightResultFile(repoRoot, indexPath, row) {
|
|
20
|
+
const typedRow = asRecord(row);
|
|
21
|
+
const baseDir = path.dirname(indexPath);
|
|
22
|
+
const explicit = typedRow.expected_report_file ??
|
|
23
|
+
typedRow.identity_decision_file ??
|
|
24
|
+
typedRow.identityDecisionFile ??
|
|
25
|
+
typedRow.report_file ??
|
|
26
|
+
typedRow.reportFile;
|
|
27
|
+
if (explicit)
|
|
28
|
+
return resolveArtifactPath(repoRoot, asText(explicit), baseDir);
|
|
29
|
+
const outputDir = asText(typedRow.output_dir ?? typedRow.outputDir);
|
|
30
|
+
if (!outputDir)
|
|
31
|
+
return null;
|
|
32
|
+
const resolvedOutputDir = path.isAbsolute(outputDir)
|
|
33
|
+
? outputDir
|
|
34
|
+
: path.resolve(baseDir, outputDir);
|
|
35
|
+
const fromIndexBase = path.join(resolvedOutputDir, "outputs", "identity-decision.json");
|
|
36
|
+
if (fileExists(fromIndexBase))
|
|
37
|
+
return fromIndexBase;
|
|
38
|
+
return resolveRepoPath(repoRoot, path.join(outputDir, "outputs", "identity-decision.json"));
|
|
39
|
+
}
|
|
40
|
+
export function readIdentityPreflightIndexRow(repoRoot, indexPath, row) {
|
|
41
|
+
const typedRow = asRecord(row);
|
|
42
|
+
const baseDir = path.dirname(indexPath);
|
|
43
|
+
const datasetType = asText(typedRow.dataset_type ?? typedRow.type);
|
|
44
|
+
const datasetId = asText(typedRow.dataset_id ?? typedRow.entity_id ?? typedRow.id);
|
|
45
|
+
const datasetVersion = asText(typedRow.dataset_version ?? typedRow.version) || "00.00.001";
|
|
46
|
+
if (!datasetType || !datasetId)
|
|
47
|
+
return null;
|
|
48
|
+
const requestPath = resolveArtifactPath(repoRoot, asText(typedRow.request_file), baseDir);
|
|
49
|
+
const request = requestPath ? readJsonIfExists(requestPath) : null;
|
|
50
|
+
const requestText = requestPath && fileExists(requestPath) ? readText(requestPath) : null;
|
|
51
|
+
const resultPath = identityPreflightResultFile(repoRoot, indexPath, row);
|
|
52
|
+
const result = resultPath ? readJsonIfExists(resultPath) : null;
|
|
53
|
+
const resultText = resultPath && fileExists(resultPath) ? readText(resultPath) : null;
|
|
54
|
+
const executionManifestPath = resolveArtifactPath(repoRoot, asText(typedRow.execution_manifest_file ?? typedRow.executionManifestFile), baseDir) ??
|
|
55
|
+
(resultPath
|
|
56
|
+
? path.join(path.dirname(resultPath), "foundry-identity-preflight-execution.json")
|
|
57
|
+
: null);
|
|
58
|
+
const executionManifest = executionManifestPath
|
|
59
|
+
? readJsonIfExists(executionManifestPath)
|
|
60
|
+
: null;
|
|
61
|
+
const targetSha256 = typedRow.target_sha256 ??
|
|
62
|
+
typedRow.targetSha256 ??
|
|
63
|
+
(request ? sha256Json(request.target ?? null) : null);
|
|
64
|
+
const executionEvidence = validateIdentityPreflightEvidence(executionManifest, {
|
|
65
|
+
requestText,
|
|
66
|
+
reportText: resultText,
|
|
67
|
+
datasetType,
|
|
68
|
+
datasetId,
|
|
69
|
+
datasetVersion,
|
|
70
|
+
targetSha256: asText(targetSha256),
|
|
71
|
+
expectedProjectRef: asText(typedRow.expected_project_ref ?? typedRow.expectedProjectRef) || null,
|
|
72
|
+
expectedUserId: asText(typedRow.expected_user_id ?? typedRow.expectedUserId) || null,
|
|
73
|
+
});
|
|
74
|
+
const completedResult = result && executionEvidence.ok ? result : null;
|
|
75
|
+
// Candidate files are convenience exports and are not covered by the bound
|
|
76
|
+
// execution manifest. Downstream semantic evidence comes only from the
|
|
77
|
+
// manifest-bound identity-decision report.
|
|
78
|
+
const rowOutputDir = asText(typedRow.output_dir);
|
|
79
|
+
const resultOutputDir = asText(result?.out_dir);
|
|
80
|
+
const outputDir = rowOutputDir
|
|
81
|
+
? (resolveArtifactPath(repoRoot, rowOutputDir, baseDir) ??
|
|
82
|
+
resolveRepoPath(repoRoot, rowOutputDir))
|
|
83
|
+
: resultOutputDir || null;
|
|
84
|
+
return {
|
|
85
|
+
dataset_type: datasetType,
|
|
86
|
+
dataset_id: datasetId,
|
|
87
|
+
dataset_version: datasetVersion,
|
|
88
|
+
source_file: typedRow.source_file ?? null,
|
|
89
|
+
request_file: requestPath ? repoRelativePath(repoRoot, requestPath) : null,
|
|
90
|
+
output_dir: outputDir ? repoRelativePath(repoRoot, outputDir) : null,
|
|
91
|
+
command: typedRow.command ?? null,
|
|
92
|
+
remote_search: typedRow.remote_search ?? request?.remote_candidate_search ?? null,
|
|
93
|
+
request: request
|
|
94
|
+
? {
|
|
95
|
+
schema_version: request.schema_version ?? null,
|
|
96
|
+
remote_candidate_search: request.remote_candidate_search ?? null,
|
|
97
|
+
target_sha256: targetSha256,
|
|
98
|
+
}
|
|
99
|
+
: typedRow.target_sha256 || typedRow.targetSha256
|
|
100
|
+
? {
|
|
101
|
+
schema_version: null,
|
|
102
|
+
remote_candidate_search: null,
|
|
103
|
+
target_sha256: typedRow.target_sha256 ?? typedRow.targetSha256,
|
|
104
|
+
}
|
|
105
|
+
: null,
|
|
106
|
+
result: completedResult
|
|
107
|
+
? {
|
|
108
|
+
status: completedResult.status ?? null,
|
|
109
|
+
decision: completedResult.decision ?? null,
|
|
110
|
+
confidence: completedResult.confidence ?? null,
|
|
111
|
+
next_action: completedResult.next_action ?? null,
|
|
112
|
+
target: completedResult.target ?? null,
|
|
113
|
+
candidates: ensureArray(completedResult.candidates),
|
|
114
|
+
candidate_sources: completedResult.candidate_sources ?? null,
|
|
115
|
+
findings: completedResult.findings ?? [],
|
|
116
|
+
blockers: completedResult.blockers ?? [],
|
|
117
|
+
files: completedResult.files ?? null,
|
|
118
|
+
}
|
|
119
|
+
: null,
|
|
120
|
+
execution_evidence: {
|
|
121
|
+
status: executionEvidence.ok ? "verified" : "invalid_or_missing",
|
|
122
|
+
code: executionEvidence.code ?? null,
|
|
123
|
+
manifest_file: executionManifestPath && fileExists(executionManifestPath)
|
|
124
|
+
? repoRelativePath(repoRoot, executionManifestPath)
|
|
125
|
+
: null,
|
|
126
|
+
},
|
|
127
|
+
status: completedResult ? "completed" : "pending_execution",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function readIdentityPreflightContext(repoRoot, options, rowsFile) {
|
|
131
|
+
const indexPath = identityPreflightIndexPath(repoRoot, options, rowsFile);
|
|
132
|
+
if (!indexPath)
|
|
133
|
+
return null;
|
|
134
|
+
if (!fileExists(indexPath)) {
|
|
135
|
+
throw new Error(`--identity-preflight-index must point to a readable JSONL file: ${indexPath}`);
|
|
136
|
+
}
|
|
137
|
+
const rows = readJsonLinesIfExists(indexPath)
|
|
138
|
+
.map((row) => readIdentityPreflightIndexRow(repoRoot, indexPath, row))
|
|
139
|
+
.filter((row) => row !== null);
|
|
140
|
+
const rowsByIdentity = new Map();
|
|
141
|
+
for (const row of rows) {
|
|
142
|
+
const key = `${row.dataset_type}:${row.dataset_id}@@${row.dataset_version}`;
|
|
143
|
+
rowsByIdentity.set(key, row);
|
|
144
|
+
if (!rowsByIdentity.has(`${row.dataset_type}:${row.dataset_id}`)) {
|
|
145
|
+
rowsByIdentity.set(`${row.dataset_type}:${row.dataset_id}`, row);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
indexPath,
|
|
150
|
+
rows,
|
|
151
|
+
rowsByIdentity,
|
|
152
|
+
completed: rows.filter((row) => row.status === "completed").length,
|
|
153
|
+
pending: rows.filter((row) => row.status !== "completed").length,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export function identityPreflightRowForIdentity(context, datasetType, identity) {
|
|
157
|
+
if (!context || !identity?.id)
|
|
158
|
+
return null;
|
|
159
|
+
return (context.rowsByIdentity.get(`${datasetType}:${identity.id}@@${identity.version || "00.00.001"}`) ??
|
|
160
|
+
context.rowsByIdentity.get(`${datasetType}:${identity.id}`) ??
|
|
161
|
+
null);
|
|
162
|
+
}
|
|
163
|
+
export function identityPreflightFreshness(row, payload) {
|
|
164
|
+
const request = asRecord(asRecord(row).request);
|
|
165
|
+
const currentPayloadSha256 = payload ? sha256Json(payload) : null;
|
|
166
|
+
const requestTargetSha256 = asText(request.target_sha256) || null;
|
|
167
|
+
return {
|
|
168
|
+
current_payload_sha256: currentPayloadSha256,
|
|
169
|
+
request_target_sha256: requestTargetSha256,
|
|
170
|
+
current_payload_matches_request: Boolean(currentPayloadSha256 && requestTargetSha256 && currentPayloadSha256 === requestTargetSha256),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export function classificationFreshnessAllowance({ repoRoot, freshness, datasetType, identity, classificationDecisionApplyContext, }) {
|
|
174
|
+
if (freshness?.current_payload_matches_request === true ||
|
|
175
|
+
classificationDecisionApplyContext?.status !== "completed") {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const key = identityFreshnessIdentityKey({ datasetType, identity });
|
|
179
|
+
if (!key)
|
|
180
|
+
return null;
|
|
181
|
+
const classificationInputPayloadSha256 = classificationDecisionApplyContext.inputPayloadSha256ByIdentity?.get(key) ?? null;
|
|
182
|
+
const classificationOutputPayloadSha256 = classificationDecisionApplyContext.outputPayloadSha256ByIdentity?.get(key) ?? null;
|
|
183
|
+
const requestMatchesClassificationInput = Boolean(freshness?.request_target_sha256 &&
|
|
184
|
+
classificationInputPayloadSha256 &&
|
|
185
|
+
freshness.request_target_sha256 === classificationInputPayloadSha256);
|
|
186
|
+
const currentMatchesClassificationOutput = Boolean(freshness?.current_payload_sha256 &&
|
|
187
|
+
classificationOutputPayloadSha256 &&
|
|
188
|
+
freshness.current_payload_sha256 === classificationOutputPayloadSha256);
|
|
189
|
+
if (!requestMatchesClassificationInput || !currentMatchesClassificationOutput) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
reason: "classification_decision_apply",
|
|
194
|
+
report: classificationDecisionApplyContext.reportPath
|
|
195
|
+
? repoRelativePath(repoRoot, classificationDecisionApplyContext.reportPath)
|
|
196
|
+
: null,
|
|
197
|
+
input_rows_files: classificationDecisionApplyContext.inputRows.map((file) => repoRelativePath(repoRoot, file)),
|
|
198
|
+
output_rows_files: classificationDecisionApplyContext.outputRows.map((file) => repoRelativePath(repoRoot, file)),
|
|
199
|
+
request_payload_matches_classification_input: requestMatchesClassificationInput,
|
|
200
|
+
current_payload_matches_classification_output: currentMatchesClassificationOutput,
|
|
201
|
+
classification_input_payload_sha256: classificationInputPayloadSha256,
|
|
202
|
+
classification_output_payload_sha256: classificationOutputPayloadSha256,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export function deterministicTransformFreshnessAllowance({ repoRoot, freshness, datasetType, identity, patchApplyContext, classificationDecisionApplyContext, locationDecisionApplyContext, identityDecisionApplyContext, identityReferenceRewriteContext, unresolvedExchangeExternalizationContext, sourceContactRewriteContext, canonicalSupportRewriteContext, cleanupContext, }) {
|
|
206
|
+
if (freshness?.current_payload_matches_request === true ||
|
|
207
|
+
!freshness?.request_target_sha256 ||
|
|
208
|
+
!freshness?.current_payload_sha256) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
const key = identityFreshnessIdentityKey({ datasetType, identity });
|
|
212
|
+
if (!key)
|
|
213
|
+
return null;
|
|
214
|
+
const transforms = deterministicRowsFileTransformEntries({
|
|
215
|
+
patchApplyContext,
|
|
216
|
+
classificationDecisionApplyContext,
|
|
217
|
+
locationDecisionApplyContext,
|
|
218
|
+
identityDecisionApplyContext,
|
|
219
|
+
identityReferenceRewriteContext,
|
|
220
|
+
unresolvedExchangeExternalizationContext,
|
|
221
|
+
sourceContactRewriteContext,
|
|
222
|
+
canonicalSupportRewriteContext,
|
|
223
|
+
cleanupContext,
|
|
224
|
+
});
|
|
225
|
+
const reachable = new Set([freshness.request_target_sha256]);
|
|
226
|
+
const applied = [];
|
|
227
|
+
for (let pass = 0; pass <= transforms.length; pass += 1) {
|
|
228
|
+
let changed = false;
|
|
229
|
+
for (const transform of transforms) {
|
|
230
|
+
const inputPayloadSha256 = transform.inputPayloadSha256ByIdentity?.get(key) ?? null;
|
|
231
|
+
const outputPayloadSha256 = transform.outputPayloadSha256ByIdentity?.get(key) ?? null;
|
|
232
|
+
if (!inputPayloadSha256 || !outputPayloadSha256 || !reachable.has(inputPayloadSha256)) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (!reachable.has(outputPayloadSha256)) {
|
|
236
|
+
reachable.add(outputPayloadSha256);
|
|
237
|
+
applied.push({
|
|
238
|
+
kind: transform.kind,
|
|
239
|
+
input_payload_sha256: inputPayloadSha256,
|
|
240
|
+
output_payload_sha256: outputPayloadSha256,
|
|
241
|
+
input_rows_file: transform.inputRowsFile
|
|
242
|
+
? repoRelativePath(repoRoot, transform.inputRowsFile)
|
|
243
|
+
: null,
|
|
244
|
+
output_rows_file: transform.outputRowsFile
|
|
245
|
+
? repoRelativePath(repoRoot, transform.outputRowsFile)
|
|
246
|
+
: null,
|
|
247
|
+
});
|
|
248
|
+
changed = true;
|
|
249
|
+
}
|
|
250
|
+
if (reachable.has(freshness.current_payload_sha256)) {
|
|
251
|
+
return {
|
|
252
|
+
reason: "deterministic_rows_file_transform_chain",
|
|
253
|
+
request_payload_sha256: freshness.request_target_sha256,
|
|
254
|
+
current_payload_sha256: freshness.current_payload_sha256,
|
|
255
|
+
accepted_payload_sha256: freshness.current_payload_sha256,
|
|
256
|
+
transforms: applied,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (reachable.has(freshness.current_payload_sha256)) {
|
|
261
|
+
return {
|
|
262
|
+
reason: "deterministic_rows_file_transform_chain",
|
|
263
|
+
request_payload_sha256: freshness.request_target_sha256,
|
|
264
|
+
current_payload_sha256: freshness.current_payload_sha256,
|
|
265
|
+
accepted_payload_sha256: freshness.current_payload_sha256,
|
|
266
|
+
transforms: applied,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
if (!changed)
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
export function externalizationFreshnessAllowance({ freshness, datasetType, identity, unresolvedExchangeExternalizationContext, }) {
|
|
275
|
+
if (datasetType !== "process" ||
|
|
276
|
+
freshness?.current_payload_matches_request === true ||
|
|
277
|
+
unresolvedExchangeExternalizationContext?.status !== "completed") {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
const key = identityFreshnessIdentityKey({ datasetType, identity });
|
|
281
|
+
if (!key || !unresolvedExchangeExternalizationContext.affectedKeys.has(key)) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const externalizedPayloadSha256 = unresolvedExchangeExternalizationContext.outputPayloadSha256ByIdentity.get(key) ?? null;
|
|
285
|
+
return {
|
|
286
|
+
reason: "unresolved_exchange_externalization",
|
|
287
|
+
report: unresolvedExchangeExternalizationContext.reportPathRelative,
|
|
288
|
+
input_rows_file: unresolvedExchangeExternalizationContext.inputRowsFileRelative,
|
|
289
|
+
output_rows_file: unresolvedExchangeExternalizationContext.outputRowsFileRelative,
|
|
290
|
+
traces_file: unresolvedExchangeExternalizationContext.tracesFileRelative,
|
|
291
|
+
externalized_exchange_count: unresolvedExchangeExternalizationContext.externalizedExchangeCountByIdentity.get(key) ?? 0,
|
|
292
|
+
current_payload_matches_externalized_output: Boolean(freshness?.current_payload_sha256 &&
|
|
293
|
+
externalizedPayloadSha256 &&
|
|
294
|
+
freshness.current_payload_sha256 === externalizedPayloadSha256),
|
|
295
|
+
externalized_payload_sha256: externalizedPayloadSha256,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export function attachIdentityPreflightFreshness(row, payload, options = {}) {
|
|
299
|
+
if (!row)
|
|
300
|
+
return null;
|
|
301
|
+
const freshness = identityPreflightFreshness(row, payload);
|
|
302
|
+
const deterministicAllowances = [
|
|
303
|
+
classificationFreshnessAllowance({
|
|
304
|
+
repoRoot: options.repoRoot,
|
|
305
|
+
freshness,
|
|
306
|
+
datasetType: options.datasetType,
|
|
307
|
+
identity: options.identity,
|
|
308
|
+
classificationDecisionApplyContext: options.classificationDecisionApplyContext,
|
|
309
|
+
}),
|
|
310
|
+
externalizationFreshnessAllowance({
|
|
311
|
+
freshness,
|
|
312
|
+
datasetType: options.datasetType,
|
|
313
|
+
identity: options.identity,
|
|
314
|
+
unresolvedExchangeExternalizationContext: options.unresolvedExchangeExternalizationContext,
|
|
315
|
+
}),
|
|
316
|
+
deterministicTransformFreshnessAllowance({
|
|
317
|
+
repoRoot: options.repoRoot,
|
|
318
|
+
freshness,
|
|
319
|
+
datasetType: options.datasetType,
|
|
320
|
+
identity: options.identity,
|
|
321
|
+
patchApplyContext: options.patchApplyContext,
|
|
322
|
+
classificationDecisionApplyContext: options.classificationDecisionApplyContext,
|
|
323
|
+
locationDecisionApplyContext: options.locationDecisionApplyContext,
|
|
324
|
+
identityDecisionApplyContext: options.identityDecisionApplyContext,
|
|
325
|
+
identityReferenceRewriteContext: options.identityReferenceRewriteContext,
|
|
326
|
+
unresolvedExchangeExternalizationContext: options.unresolvedExchangeExternalizationContext,
|
|
327
|
+
sourceContactRewriteContext: options.sourceContactRewriteContext,
|
|
328
|
+
canonicalSupportRewriteContext: options.canonicalSupportRewriteContext,
|
|
329
|
+
cleanupContext: options.cleanupContext,
|
|
330
|
+
}),
|
|
331
|
+
].filter(Boolean);
|
|
332
|
+
return {
|
|
333
|
+
...row,
|
|
334
|
+
freshness: {
|
|
335
|
+
...freshness,
|
|
336
|
+
deterministic_transform_allowance: deterministicAllowances[0] ?? null,
|
|
337
|
+
deterministic_transform_allowances: deterministicAllowances,
|
|
338
|
+
current_payload_scope_accepted: Boolean(freshness.current_payload_matches_request || deterministicAllowances.length > 0),
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
export function identityPreflightFreshnessAccepted(freshness) {
|
|
343
|
+
const typedFreshness = asRecord(freshness);
|
|
344
|
+
return Boolean(typedFreshness.current_payload_matches_request === true ||
|
|
345
|
+
typedFreshness.current_payload_scope_accepted === true);
|
|
346
|
+
}
|
|
347
|
+
export function identityPreflightSourceContextRequired({ profile, datasetType, curationQueueContext, context, }) {
|
|
348
|
+
return Boolean(asText(profile?.id).toLowerCase() === "bafu" &&
|
|
349
|
+
["flow", "process"].includes(datasetType) &&
|
|
350
|
+
curationQueueContext?.status === "attached" &&
|
|
351
|
+
ensureArray(context?.rows).some((row) => asText(asRecord(row).source_file)));
|
|
352
|
+
}
|
|
353
|
+
export function identityPreflightHasSourceContext(row) {
|
|
354
|
+
return Boolean(asText(asRecord(row).source_file));
|
|
355
|
+
}
|
|
356
|
+
export function dependencyPayloadForFreshness(dependency) {
|
|
357
|
+
const typedDependency = asRecord(dependency);
|
|
358
|
+
const rows = ensureArray(typedDependency.input_rows ??
|
|
359
|
+
typedDependency.rows ??
|
|
360
|
+
typedDependency.payload_rows ??
|
|
361
|
+
typedDependency.payloadRows).filter(Boolean);
|
|
362
|
+
return rows[0] ?? typedDependency.payload ?? null;
|
|
363
|
+
}
|
|
364
|
+
export function dependencyIdentityPreflightRows(context, curationQueueContext, options = {}) {
|
|
365
|
+
if (!context || !curationQueueContext)
|
|
366
|
+
return [];
|
|
367
|
+
const rows = [];
|
|
368
|
+
const seen = new Set();
|
|
369
|
+
for (const dependency of ensureArray(curationQueueContext.dependency_rows)) {
|
|
370
|
+
const typedDependency = asRecord(dependency);
|
|
371
|
+
const task = asRecord(typedDependency.task);
|
|
372
|
+
const datasetType = asText(task.entity_type);
|
|
373
|
+
const identity = {
|
|
374
|
+
id: asText(task.entity_id),
|
|
375
|
+
version: asText(task.version) || "00.00.001",
|
|
376
|
+
};
|
|
377
|
+
const row = identityPreflightRowForIdentity(context, datasetType, identity);
|
|
378
|
+
if (!row)
|
|
379
|
+
continue;
|
|
380
|
+
const key = `${row.dataset_type}:${row.dataset_id}@@${row.dataset_version}`;
|
|
381
|
+
if (seen.has(key))
|
|
382
|
+
continue;
|
|
383
|
+
seen.add(key);
|
|
384
|
+
rows.push({
|
|
385
|
+
relation: "dependency",
|
|
386
|
+
ref: typedDependency.ref ?? null,
|
|
387
|
+
ref_path: typedDependency.ref_path ?? null,
|
|
388
|
+
identity_preflight: attachIdentityPreflightFreshness(row, dependencyPayloadForFreshness(dependency), {
|
|
389
|
+
datasetType,
|
|
390
|
+
identity,
|
|
391
|
+
repoRoot: options.repoRoot,
|
|
392
|
+
classificationDecisionApplyContext: options.classificationDecisionApplyContext,
|
|
393
|
+
locationDecisionApplyContext: options.locationDecisionApplyContext,
|
|
394
|
+
identityDecisionApplyContext: options.identityDecisionApplyContext,
|
|
395
|
+
identityReferenceRewriteContext: options.identityReferenceRewriteContext,
|
|
396
|
+
unresolvedExchangeExternalizationContext: options.unresolvedExchangeExternalizationContext,
|
|
397
|
+
sourceContactRewriteContext: options.sourceContactRewriteContext,
|
|
398
|
+
canonicalSupportRewriteContext: options.canonicalSupportRewriteContext,
|
|
399
|
+
cleanupContext: options.cleanupContext,
|
|
400
|
+
}),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return rows;
|
|
404
|
+
}
|
|
405
|
+
export function buildIdentityPreflightAuthoringContext({ context, datasetType, identity, curationQueueContext, repoRoot, unresolvedExchangeExternalizationContext, classificationDecisionApplyContext, locationDecisionApplyContext, identityDecisionApplyContext, identityReferenceRewriteContext, sourceContactRewriteContext, canonicalSupportRewriteContext, cleanupContext, }) {
|
|
406
|
+
if (!context)
|
|
407
|
+
return null;
|
|
408
|
+
const current = attachIdentityPreflightFreshness(identityPreflightRowForIdentity(context, datasetType, identity), identity.payload, {
|
|
409
|
+
datasetType,
|
|
410
|
+
identity,
|
|
411
|
+
repoRoot,
|
|
412
|
+
classificationDecisionApplyContext,
|
|
413
|
+
locationDecisionApplyContext,
|
|
414
|
+
identityDecisionApplyContext,
|
|
415
|
+
identityReferenceRewriteContext,
|
|
416
|
+
unresolvedExchangeExternalizationContext,
|
|
417
|
+
sourceContactRewriteContext,
|
|
418
|
+
canonicalSupportRewriteContext,
|
|
419
|
+
cleanupContext,
|
|
420
|
+
});
|
|
421
|
+
const dependencies = dependencyIdentityPreflightRows(context, curationQueueContext, {
|
|
422
|
+
repoRoot,
|
|
423
|
+
classificationDecisionApplyContext,
|
|
424
|
+
locationDecisionApplyContext,
|
|
425
|
+
identityDecisionApplyContext,
|
|
426
|
+
identityReferenceRewriteContext,
|
|
427
|
+
unresolvedExchangeExternalizationContext,
|
|
428
|
+
sourceContactRewriteContext,
|
|
429
|
+
canonicalSupportRewriteContext,
|
|
430
|
+
cleanupContext,
|
|
431
|
+
});
|
|
432
|
+
return {
|
|
433
|
+
index_file: repoRelativePath(repoRoot, context.indexPath),
|
|
434
|
+
status: current?.status === "completed" &&
|
|
435
|
+
dependencies.every((row) => row.identity_preflight?.status === "completed")
|
|
436
|
+
? "completed"
|
|
437
|
+
: "pending_or_partial",
|
|
438
|
+
current,
|
|
439
|
+
dependencies,
|
|
440
|
+
counts: {
|
|
441
|
+
index_rows: context.rows.length,
|
|
442
|
+
completed: context.completed,
|
|
443
|
+
pending: context.pending,
|
|
444
|
+
dependency_rows: dependencies.length,
|
|
445
|
+
},
|
|
446
|
+
policy: "Identity preflight is a read-only database candidate recall and deterministic identity decision artifact. AI may use it as evidence, but database writes still require Foundry finalize and CLI commit handoff gates.",
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
export function identityPreflightGateItems({ required, context, authoringContext, datasetType, identity, curationQueueContext, profile, }) {
|
|
450
|
+
if (!required || !["flow", "process"].includes(datasetType))
|
|
451
|
+
return [];
|
|
452
|
+
const items = [];
|
|
453
|
+
const baseInstruction = "Run dataset-identity-preflight-run for the generated identity-preflight-requests index before AI authoring, then pass the same index to dataset-curation-gate with --identity-preflight-index.";
|
|
454
|
+
if (!context) {
|
|
455
|
+
return [
|
|
456
|
+
{
|
|
457
|
+
source: "identity_preflight",
|
|
458
|
+
code: "identity_preflight_index_required",
|
|
459
|
+
path: null,
|
|
460
|
+
message: "Full-context AI authoring requires read-only database identity-preflight request/result context.",
|
|
461
|
+
action_kind: "identity_preflight_required",
|
|
462
|
+
required_owner: "foundry_identity_preflight_run",
|
|
463
|
+
ai_required: false,
|
|
464
|
+
instruction: baseInstruction,
|
|
465
|
+
},
|
|
466
|
+
];
|
|
467
|
+
}
|
|
468
|
+
const current = authoringContext?.current ?? null;
|
|
469
|
+
const staleInstruction = "Regenerate identity-preflight requests from the exact current rows file, rerun dataset-identity-preflight-run, and pass that same fresh index to the curation gate.";
|
|
470
|
+
const sourceContextInstruction = "Regenerate identity-preflight requests from the exact current rows file with dataset-identity-preflight-requests-build --source-index <original-full-identity-preflight-requests.jsonl>, rerun dataset-identity-preflight-run, merge the refreshed current rows back into the original full index, and pass that merged index to the curation gate.";
|
|
471
|
+
const requiresSourceContext = identityPreflightSourceContextRequired({
|
|
472
|
+
profile,
|
|
473
|
+
datasetType,
|
|
474
|
+
curationQueueContext,
|
|
475
|
+
context,
|
|
476
|
+
});
|
|
477
|
+
if (!current) {
|
|
478
|
+
items.push({
|
|
479
|
+
source: "identity_preflight",
|
|
480
|
+
code: "identity_preflight_current_result_missing",
|
|
481
|
+
path: null,
|
|
482
|
+
message: "No identity-preflight result is attached for the current entity.",
|
|
483
|
+
action_kind: "identity_preflight_required",
|
|
484
|
+
required_owner: "foundry_identity_preflight_run",
|
|
485
|
+
ai_required: false,
|
|
486
|
+
dataset_type: datasetType,
|
|
487
|
+
dataset_id: identity.id,
|
|
488
|
+
dataset_version: identity.version,
|
|
489
|
+
instruction: baseInstruction,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
else if (current.status !== "completed") {
|
|
493
|
+
items.push({
|
|
494
|
+
source: "identity_preflight",
|
|
495
|
+
code: "identity_preflight_current_result_pending",
|
|
496
|
+
path: null,
|
|
497
|
+
message: `Current entity identity-preflight status is ${current.status}.`,
|
|
498
|
+
action_kind: "identity_preflight_required",
|
|
499
|
+
required_owner: "foundry_identity_preflight_run",
|
|
500
|
+
ai_required: false,
|
|
501
|
+
dataset_type: datasetType,
|
|
502
|
+
dataset_id: identity.id,
|
|
503
|
+
dataset_version: identity.version,
|
|
504
|
+
instruction: baseInstruction,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
else if (!identityPreflightFreshnessAccepted(current.freshness)) {
|
|
508
|
+
items.push({
|
|
509
|
+
source: "identity_preflight",
|
|
510
|
+
code: "identity_preflight_current_scope_stale",
|
|
511
|
+
path: null,
|
|
512
|
+
message: "Current entity identity-preflight result was generated from a different target payload than the rows file currently being curated.",
|
|
513
|
+
action_kind: "identity_preflight_required",
|
|
514
|
+
required_owner: "foundry_identity_preflight_run",
|
|
515
|
+
ai_required: false,
|
|
516
|
+
dataset_type: datasetType,
|
|
517
|
+
dataset_id: identity.id,
|
|
518
|
+
dataset_version: identity.version,
|
|
519
|
+
instruction: staleInstruction,
|
|
520
|
+
evidence: current.freshness ?? null,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
else if (requiresSourceContext && !identityPreflightHasSourceContext(current)) {
|
|
524
|
+
items.push({
|
|
525
|
+
source: "identity_preflight",
|
|
526
|
+
code: "identity_preflight_current_source_context_missing",
|
|
527
|
+
path: null,
|
|
528
|
+
message: "Current entity identity-preflight was refreshed without source_file trace context, so hybrid search and AI authoring may lose source-package evidence.",
|
|
529
|
+
action_kind: "identity_preflight_required",
|
|
530
|
+
required_owner: "foundry_identity_preflight_run",
|
|
531
|
+
ai_required: false,
|
|
532
|
+
dataset_type: datasetType,
|
|
533
|
+
dataset_id: identity.id,
|
|
534
|
+
dataset_version: identity.version,
|
|
535
|
+
instruction: sourceContextInstruction,
|
|
536
|
+
evidence: {
|
|
537
|
+
remote_search: current.remote_search ?? null,
|
|
538
|
+
request_file: current.request_file ?? null,
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
if (datasetType === "process" && curationQueueContext?.status === "attached") {
|
|
543
|
+
const dependencyPreflightRows = ensureArray(authoringContext?.dependencies).map((dependency) => dependency?.identity_preflight);
|
|
544
|
+
const dependencyRows = ensureArray(curationQueueContext.dependency_rows);
|
|
545
|
+
for (const dependency of dependencyRows) {
|
|
546
|
+
const typedDependency = asRecord(dependency);
|
|
547
|
+
const task = asRecord(typedDependency.task);
|
|
548
|
+
const dependencyType = asText(task.entity_type);
|
|
549
|
+
if (!["flow", "process"].includes(dependencyType))
|
|
550
|
+
continue;
|
|
551
|
+
const dependencyIdentity = {
|
|
552
|
+
id: asText(task.entity_id),
|
|
553
|
+
version: asText(task.version) || "00.00.001",
|
|
554
|
+
};
|
|
555
|
+
if (!dependencyIdentity.id)
|
|
556
|
+
continue;
|
|
557
|
+
const dependencyPreflight = identityPreflightRowForIdentity(context, dependencyType, dependencyIdentity);
|
|
558
|
+
const dependencyPreflightWithFreshness = dependencyPreflightRows.find((row) => row?.dataset_type === dependencyType &&
|
|
559
|
+
row?.dataset_id === dependencyIdentity.id &&
|
|
560
|
+
row?.dataset_version === dependencyIdentity.version) ?? dependencyPreflight;
|
|
561
|
+
if (!dependencyPreflight) {
|
|
562
|
+
items.push({
|
|
563
|
+
source: "identity_preflight",
|
|
564
|
+
code: "identity_preflight_dependency_result_missing",
|
|
565
|
+
path: typedDependency.ref_path ?? null,
|
|
566
|
+
message: "No identity-preflight result is attached for a referenced dependency entity.",
|
|
567
|
+
action_kind: "identity_preflight_required",
|
|
568
|
+
required_owner: "foundry_identity_preflight_run",
|
|
569
|
+
ai_required: false,
|
|
570
|
+
dependency_type: dependencyType,
|
|
571
|
+
dependency_id: dependencyIdentity.id,
|
|
572
|
+
dependency_version: dependencyIdentity.version,
|
|
573
|
+
instruction: baseInstruction,
|
|
574
|
+
});
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
const evaluatedPreflight = dependencyPreflightWithFreshness ?? dependencyPreflight;
|
|
578
|
+
if (evaluatedPreflight.status !== "completed") {
|
|
579
|
+
items.push({
|
|
580
|
+
source: "identity_preflight",
|
|
581
|
+
code: "identity_preflight_dependency_result_pending",
|
|
582
|
+
path: typedDependency.ref_path ?? null,
|
|
583
|
+
message: `Referenced dependency identity-preflight status is ${evaluatedPreflight.status}.`,
|
|
584
|
+
action_kind: "identity_preflight_required",
|
|
585
|
+
required_owner: "foundry_identity_preflight_run",
|
|
586
|
+
ai_required: false,
|
|
587
|
+
dependency_type: dependencyType,
|
|
588
|
+
dependency_id: dependencyIdentity.id,
|
|
589
|
+
dependency_version: dependencyIdentity.version,
|
|
590
|
+
instruction: baseInstruction,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
else if (evaluatedPreflight.freshness &&
|
|
594
|
+
!identityPreflightFreshnessAccepted(evaluatedPreflight.freshness)) {
|
|
595
|
+
items.push({
|
|
596
|
+
source: "identity_preflight",
|
|
597
|
+
code: "identity_preflight_dependency_scope_stale",
|
|
598
|
+
path: typedDependency.ref_path ?? null,
|
|
599
|
+
message: "Referenced dependency identity-preflight result was generated from a different dependency payload than the current curation queue context.",
|
|
600
|
+
action_kind: "identity_preflight_required",
|
|
601
|
+
required_owner: "foundry_identity_preflight_run",
|
|
602
|
+
ai_required: false,
|
|
603
|
+
dependency_type: dependencyType,
|
|
604
|
+
dependency_id: dependencyIdentity.id,
|
|
605
|
+
dependency_version: dependencyIdentity.version,
|
|
606
|
+
instruction: staleInstruction,
|
|
607
|
+
evidence: evaluatedPreflight.freshness,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
else if (requiresSourceContext && !identityPreflightHasSourceContext(evaluatedPreflight)) {
|
|
611
|
+
items.push({
|
|
612
|
+
source: "identity_preflight",
|
|
613
|
+
code: "identity_preflight_dependency_source_context_missing",
|
|
614
|
+
path: typedDependency.ref_path ?? null,
|
|
615
|
+
message: "Referenced dependency identity-preflight is missing source_file trace context, so hybrid search and AI authoring may lose source-package evidence.",
|
|
616
|
+
action_kind: "identity_preflight_required",
|
|
617
|
+
required_owner: "foundry_identity_preflight_run",
|
|
618
|
+
ai_required: false,
|
|
619
|
+
dependency_type: dependencyType,
|
|
620
|
+
dependency_id: dependencyIdentity.id,
|
|
621
|
+
dependency_version: dependencyIdentity.version,
|
|
622
|
+
instruction: sourceContextInstruction,
|
|
623
|
+
evidence: {
|
|
624
|
+
remote_search: evaluatedPreflight.remote_search ?? null,
|
|
625
|
+
request_file: evaluatedPreflight.request_file ?? null,
|
|
626
|
+
},
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return items;
|
|
632
|
+
}
|
|
633
|
+
export function identityPreflightNeedsAiDecision(row) {
|
|
634
|
+
const result = asRecord(row).result;
|
|
635
|
+
if (!result)
|
|
636
|
+
return false;
|
|
637
|
+
const typedResult = asRecord(result);
|
|
638
|
+
const status = asText(typedResult.status);
|
|
639
|
+
const decision = asText(typedResult.decision);
|
|
640
|
+
return status === "needs_review" || decision === "manual_review";
|
|
641
|
+
}
|
|
642
|
+
export function identityPreflightAiDecisionActionItem({ datasetType, identity, row, relation = "current", path = null, dependencyType = null, dependencyId = null, dependencyVersion = null, }) {
|
|
643
|
+
const typedRow = asRecord(row);
|
|
644
|
+
const result = asRecord(typedRow.result);
|
|
645
|
+
const candidates = ensureArray(result.candidates);
|
|
646
|
+
const resultFlowType = asText(asRecord(asRecord(result.target).fields).type_of_dataset);
|
|
647
|
+
const isElementaryFlow = (dependencyType || datasetType) === "flow" &&
|
|
648
|
+
(flowUsesElementaryClassification(identity.payload) || resultFlowType === "Elementary flow");
|
|
649
|
+
return {
|
|
650
|
+
source: "identity_preflight",
|
|
651
|
+
code: isElementaryFlow
|
|
652
|
+
? "elementary_flow_identity_manual_review"
|
|
653
|
+
: "identity_preflight_manual_review",
|
|
654
|
+
path,
|
|
655
|
+
message: isElementaryFlow
|
|
656
|
+
? "Elementary flow identity-preflight needs AI review. Elementary flows are reference-only and must select an existing TianGong flow before write planning."
|
|
657
|
+
: "Identity-preflight returned manual_review/needs_review and requires AI to decide whether to reuse an existing database row or continue as a new write candidate.",
|
|
658
|
+
action_kind: "identity_decision_authoring",
|
|
659
|
+
required_owner: "foundry_ai_authoring",
|
|
660
|
+
ai_required: true,
|
|
661
|
+
dataset_type: datasetType,
|
|
662
|
+
dataset_id: identity.id,
|
|
663
|
+
dataset_version: identity.version,
|
|
664
|
+
relation,
|
|
665
|
+
dependency_type: dependencyType,
|
|
666
|
+
dependency_id: dependencyId,
|
|
667
|
+
dependency_version: dependencyVersion,
|
|
668
|
+
common_other_deferral_allowed: false,
|
|
669
|
+
evidence: {
|
|
670
|
+
identity_preflight_status: result.status ?? null,
|
|
671
|
+
identity_preflight_decision: result.decision ?? null,
|
|
672
|
+
confidence: result.confidence ?? null,
|
|
673
|
+
next_action: result.next_action ?? null,
|
|
674
|
+
candidate_count: candidates.length,
|
|
675
|
+
remote_search: typedRow.remote_search ?? null,
|
|
676
|
+
target: result.target ?? null,
|
|
677
|
+
top_candidates: candidates.slice(0, 10),
|
|
678
|
+
},
|
|
679
|
+
instruction: isElementaryFlow
|
|
680
|
+
? "Use the full schema/YAML/context package plus flow_hybrid_search candidates to choose the existing TianGong elementary flow reference. Do not create or write a BAFU-owned elementary flow. If no candidate is sufficient, return an unresolved identity blocker with the searched query and candidate evidence."
|
|
681
|
+
: "Use the full schema/YAML/context package plus identity-preflight candidates to decide reuse_existing_reference versus create_new. If reusing, output a structured identity reference rewrite with canonical id/version and evidence. If creating new, include evidence explaining why candidates are not identity-equivalent.",
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
export function identityPreflightAuthoringActionItems({ required, authoringContext, datasetType, identity, identityDecisionApplyContext = null, }) {
|
|
685
|
+
if (!required || !authoringContext)
|
|
686
|
+
return [];
|
|
687
|
+
const items = [];
|
|
688
|
+
const current = authoringContext.current;
|
|
689
|
+
if (identityPreflightNeedsAiDecision(current)) {
|
|
690
|
+
const item = identityPreflightAiDecisionActionItem({
|
|
691
|
+
datasetType,
|
|
692
|
+
identity,
|
|
693
|
+
row: current,
|
|
694
|
+
});
|
|
695
|
+
if (!identityDecisionApplyContextClosesAction({
|
|
696
|
+
context: identityDecisionApplyContext,
|
|
697
|
+
datasetType,
|
|
698
|
+
id: current?.dataset_id ?? identity.id,
|
|
699
|
+
version: current?.dataset_version ?? identity.version,
|
|
700
|
+
code: item.code,
|
|
701
|
+
})) {
|
|
702
|
+
items.push(item);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (datasetType === "process") {
|
|
706
|
+
for (const dependency of ensureArray(authoringContext.dependencies)) {
|
|
707
|
+
const dependencyPreflight = dependency?.identity_preflight;
|
|
708
|
+
if (!identityPreflightNeedsAiDecision(dependencyPreflight))
|
|
709
|
+
continue;
|
|
710
|
+
const item = identityPreflightAiDecisionActionItem({
|
|
711
|
+
datasetType,
|
|
712
|
+
identity,
|
|
713
|
+
row: dependencyPreflight,
|
|
714
|
+
relation: "dependency",
|
|
715
|
+
path: dependency?.ref_path ?? null,
|
|
716
|
+
dependencyType: dependencyPreflight?.dataset_type ?? null,
|
|
717
|
+
dependencyId: dependencyPreflight?.dataset_id ?? null,
|
|
718
|
+
dependencyVersion: dependencyPreflight?.dataset_version ?? null,
|
|
719
|
+
});
|
|
720
|
+
if (!identityDecisionApplyContextClosesAction({
|
|
721
|
+
context: identityDecisionApplyContext,
|
|
722
|
+
datasetType: dependencyPreflight?.dataset_type ?? null,
|
|
723
|
+
id: dependencyPreflight?.dataset_id ?? null,
|
|
724
|
+
version: dependencyPreflight?.dataset_version ?? null,
|
|
725
|
+
code: item.code,
|
|
726
|
+
})) {
|
|
727
|
+
items.push(item);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return items;
|
|
732
|
+
}
|
|
733
|
+
export function comparableText(value) {
|
|
734
|
+
return asText(value).replace(/\s+/gu, " ").trim().toLowerCase();
|
|
735
|
+
}
|
|
736
|
+
export function classificationClassesForPayload(payload, datasetType) {
|
|
737
|
+
const root = datasetRoot(payload, datasetType);
|
|
738
|
+
const info = dataSetInformation(root, datasetType);
|
|
739
|
+
const classification = info?.classificationInformation?.["common:classification"] ?? null;
|
|
740
|
+
const classes = classification?.["common:class"] ?? classification?.["common:category"] ?? null;
|
|
741
|
+
return ensureArray(classes).filter(isRecord);
|
|
742
|
+
}
|
|
743
|
+
export function classificationDisplayForPayload(payload, datasetType) {
|
|
744
|
+
return classificationClassesForPayload(payload, datasetType)
|
|
745
|
+
.map((item) => asText(item?.["#text"] ?? item?.text ?? item?.label))
|
|
746
|
+
.filter(Boolean)
|
|
747
|
+
.join(" > ");
|
|
748
|
+
}
|
|
749
|
+
export function textContent(value) {
|
|
750
|
+
if (Array.isArray(value)) {
|
|
751
|
+
return value.map(textContent).filter(Boolean).join(" ");
|
|
752
|
+
}
|
|
753
|
+
if (value && typeof value === "object") {
|
|
754
|
+
const record = value;
|
|
755
|
+
return asText(record["#text"] ?? record.text ?? record.label ?? record.name);
|
|
756
|
+
}
|
|
757
|
+
return asText(value);
|
|
758
|
+
}
|
|
759
|
+
export function sourcePrewriteIdentityBlockers(payload, datasetType) {
|
|
760
|
+
if (datasetType !== "source")
|
|
761
|
+
return [];
|
|
762
|
+
const root = datasetRoot(payload, "source");
|
|
763
|
+
const info = dataSetInformation(root, "source");
|
|
764
|
+
const shortName = textContent(info?.["common:shortName"] ?? info?.shortName);
|
|
765
|
+
const sourceCitation = textContent(info?.sourceCitation ?? info?.["common:sourceCitation"]);
|
|
766
|
+
const classification = classificationDisplayForPayload(payload, "source");
|
|
767
|
+
const blockers = [];
|
|
768
|
+
if (/^(ILCD format|Not specified|Not declared|Unspecified)$/iu.test(shortName)) {
|
|
769
|
+
blockers.push({
|
|
770
|
+
code: "source_identity_not_true_source",
|
|
771
|
+
stage: "source_semantics",
|
|
772
|
+
message: "Source shortName is a format/compliance/placeholder identity, not a true report, publication, or traceable source record.",
|
|
773
|
+
short_name: shortName,
|
|
774
|
+
source_citation: sourceCitation || null,
|
|
775
|
+
classification: classification || null,
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
if (/^(ILCD format|Not specified|Not declared|Unspecified)$/iu.test(sourceCitation)) {
|
|
779
|
+
blockers.push({
|
|
780
|
+
code: "source_citation_not_true_source",
|
|
781
|
+
stage: "source_semantics",
|
|
782
|
+
message: "Source citation is a format/compliance/placeholder identity, not bibliographic or report evidence.",
|
|
783
|
+
short_name: shortName || null,
|
|
784
|
+
source_citation: sourceCitation,
|
|
785
|
+
classification: classification || null,
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
if (/\b(Data set formats|Compliance systems)\b/iu.test(classification)) {
|
|
789
|
+
blockers.push({
|
|
790
|
+
code: "source_classification_not_true_source",
|
|
791
|
+
stage: "source_semantics",
|
|
792
|
+
message: "Source classification identifies a data format or compliance system. BAFU-owned source rows must be reports, publications, or traceable source records.",
|
|
793
|
+
short_name: shortName || null,
|
|
794
|
+
source_citation: sourceCitation || null,
|
|
795
|
+
classification,
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
return blockers;
|
|
799
|
+
}
|
|
800
|
+
export function flowPrewriteIdentityBlockers(payload, datasetType, allowAccountLocalSupportAndElementary = false) {
|
|
801
|
+
if (datasetType !== "flow")
|
|
802
|
+
return [];
|
|
803
|
+
if (allowAccountLocalSupportAndElementary)
|
|
804
|
+
return [];
|
|
805
|
+
if (!flowUsesElementaryClassification(payload))
|
|
806
|
+
return [];
|
|
807
|
+
const root = datasetRoot(payload, "flow");
|
|
808
|
+
const info = dataSetInformation(root, "flow");
|
|
809
|
+
const name = nameTextForPayload(payload, "flow");
|
|
810
|
+
const classification = classificationEntriesForPayload(payload, "flow")
|
|
811
|
+
.map((entry) => entry.text)
|
|
812
|
+
.filter(Boolean)
|
|
813
|
+
.join(" > ");
|
|
814
|
+
return [
|
|
815
|
+
{
|
|
816
|
+
code: "elementary_flow_write_blocked",
|
|
817
|
+
stage: "flow_identity_reuse_policy",
|
|
818
|
+
message: "Elementary flows are reference-only for Foundry imports. Select an existing TianGong database elementary flow and rewrite references instead of writing a BAFU-owned elementary flow.",
|
|
819
|
+
flow_name: name || null,
|
|
820
|
+
flow_type: flowTypeForPayload(payload) || null,
|
|
821
|
+
flow_uuid: asText(info?.["common:UUID"] ?? info?.UUID) || null,
|
|
822
|
+
classification: classification || null,
|
|
823
|
+
},
|
|
824
|
+
];
|
|
825
|
+
}
|
|
826
|
+
const defaultPrewriteContentPolicyFile = "specs/prewrite-content-policy.json";
|
|
827
|
+
function readPrewriteContentPolicy(repoRoot) {
|
|
828
|
+
const policyPath = resolveRepoPath(repoRoot, defaultPrewriteContentPolicyFile);
|
|
829
|
+
if (!policyPath || !fileExists(policyPath))
|
|
830
|
+
return null;
|
|
831
|
+
return {
|
|
832
|
+
path: policyPath,
|
|
833
|
+
relative_path: repoRelativePath(repoRoot, policyPath),
|
|
834
|
+
value: readJson(policyPath),
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
function isFoundryTracePathSegments(pathSegments) {
|
|
838
|
+
return pathSegments.some((segment) => {
|
|
839
|
+
const text = String(segment).toLowerCase();
|
|
840
|
+
return text === "common:other" || text.startsWith("tiangongfoundry:");
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
function payloadTextLeaves(value, pathSegments = [], leaves = []) {
|
|
844
|
+
if (isFoundryTracePathSegments(pathSegments))
|
|
845
|
+
return leaves;
|
|
846
|
+
if (typeof value === "string") {
|
|
847
|
+
leaves.push({
|
|
848
|
+
path: pathSegments.length > 0 ? `/${pathSegments.map(jsonPointerToken).join("/")}` : "/",
|
|
849
|
+
path_segments: pathSegments,
|
|
850
|
+
text: value,
|
|
851
|
+
});
|
|
852
|
+
return leaves;
|
|
853
|
+
}
|
|
854
|
+
if (Array.isArray(value)) {
|
|
855
|
+
value.forEach((item, index) => payloadTextLeaves(item, [...pathSegments, String(index)], leaves));
|
|
856
|
+
return leaves;
|
|
857
|
+
}
|
|
858
|
+
if (!value || typeof value !== "object")
|
|
859
|
+
return leaves;
|
|
860
|
+
for (const [key, child] of Object.entries(value)) {
|
|
861
|
+
payloadTextLeaves(child, [...pathSegments, key], leaves);
|
|
862
|
+
}
|
|
863
|
+
return leaves;
|
|
864
|
+
}
|
|
865
|
+
function normalizedPathSegments(pathSegments) {
|
|
866
|
+
return pathSegments.map((segment) => String(segment).replace(/^common:/u, ""));
|
|
867
|
+
}
|
|
868
|
+
function pathScopeMatches(pathSegments, pathScope = {}) {
|
|
869
|
+
const typedScope = asRecord(pathScope);
|
|
870
|
+
const raw = pathSegments.map(String);
|
|
871
|
+
const normalized = normalizedPathSegments(pathSegments);
|
|
872
|
+
const contains = ensureArray(typedScope.contains).map(String);
|
|
873
|
+
const excludeContains = ensureArray(typedScope.exclude_contains).map(String);
|
|
874
|
+
const hasSegment = (segment) => raw.includes(segment) || normalized.includes(segment.replace(/^common:/u, ""));
|
|
875
|
+
if (contains.some((segment) => !hasSegment(segment)))
|
|
876
|
+
return false;
|
|
877
|
+
if (excludeContains.some((segment) => hasSegment(segment)))
|
|
878
|
+
return false;
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
function compilePolicyPattern(entry) {
|
|
882
|
+
const typedEntry = asRecord(entry);
|
|
883
|
+
try {
|
|
884
|
+
return new RegExp(asText(typedEntry.pattern), asText(typedEntry.flags) || "u");
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
return null;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
function policyLexiconEntries(policy, rule) {
|
|
891
|
+
const typedRule = asRecord(rule);
|
|
892
|
+
const lexiconName = asText(typedRule.lexicon);
|
|
893
|
+
if (!lexiconName)
|
|
894
|
+
return [];
|
|
895
|
+
return ensureArray(asRecord(policy.lexicons)[lexiconName]);
|
|
896
|
+
}
|
|
897
|
+
export function prewriteContentQualityBlockers({ repoRoot, payload, datasetType, profile = null, }) {
|
|
898
|
+
if (!["flow", "process", "lifecyclemodel"].includes(datasetType))
|
|
899
|
+
return [];
|
|
900
|
+
const policy = readPrewriteContentPolicy(repoRoot);
|
|
901
|
+
if (!policy)
|
|
902
|
+
return [];
|
|
903
|
+
const leaves = payloadTextLeaves(payload);
|
|
904
|
+
const blockers = [];
|
|
905
|
+
for (const rule of ensureArray(policy.value.rules)) {
|
|
906
|
+
const typedRule = asRecord(rule);
|
|
907
|
+
const allowedTypes = ensureArray(typedRule.dataset_types).map(asText);
|
|
908
|
+
if (allowedTypes.length > 0 && !allowedTypes.includes(datasetType))
|
|
909
|
+
continue;
|
|
910
|
+
const entries = policyLexiconEntries(policy.value, rule);
|
|
911
|
+
for (const leaf of leaves) {
|
|
912
|
+
if (!pathScopeMatches(leaf.path_segments, typedRule.path_scope))
|
|
913
|
+
continue;
|
|
914
|
+
for (const entry of entries) {
|
|
915
|
+
const typedEntry = asRecord(entry);
|
|
916
|
+
const pattern = compilePolicyPattern(entry);
|
|
917
|
+
if (!pattern || !pattern.test(leaf.text))
|
|
918
|
+
continue;
|
|
919
|
+
// A source naming convention classifies only its trailing metadata match.
|
|
920
|
+
// Other matches, markers and fields still take the normal blocker path.
|
|
921
|
+
const namingRule = asRecord(asRecord(asRecord(profile).domainRules).process_name_geography_year);
|
|
922
|
+
const geographySuffix = /\b(Global|EU)\s+(?:19|20)\d{2}(?:\s+v\d+)?$/iu.exec(leaf.text);
|
|
923
|
+
if (datasetType === "process" &&
|
|
924
|
+
asRecord(profile).id === "worldsteel" &&
|
|
925
|
+
typedRule.code === "source_locator_in_dataset_name" &&
|
|
926
|
+
typedEntry.id === "latin-author-year" &&
|
|
927
|
+
namingRule.marker === "latin-author-year" &&
|
|
928
|
+
namingRule.field === "baseName" &&
|
|
929
|
+
leaf.path_segments.includes("baseName") &&
|
|
930
|
+
geographySuffix &&
|
|
931
|
+
geographySuffix.index > 0 &&
|
|
932
|
+
ensureArray(namingRule.geographies).some((geo) => asText(geo).toLowerCase() === geographySuffix[1].toLowerCase())) {
|
|
933
|
+
const matches = [
|
|
934
|
+
...leaf.text.matchAll(new RegExp(pattern.source, `${pattern.flags.replace(/g/gu, "")}g`)),
|
|
935
|
+
];
|
|
936
|
+
if (matches.length === 1 && matches[0].index === geographySuffix.index)
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
blockers.push({
|
|
940
|
+
code: asText(typedRule.code) || "prewrite_content_quality_blocked",
|
|
941
|
+
stage: asText(typedRule.stage) || "prewrite_content_quality",
|
|
942
|
+
message: asText(typedRule.message) ||
|
|
943
|
+
"Write payload text violates the configured prewrite content policy.",
|
|
944
|
+
dataset_type: datasetType,
|
|
945
|
+
policy: policy.relative_path,
|
|
946
|
+
rule_id: asText(typedRule.id) || null,
|
|
947
|
+
lexicon: asText(typedRule.lexicon) || null,
|
|
948
|
+
marker_id: asText(typedEntry.id) || null,
|
|
949
|
+
path: leaf.path,
|
|
950
|
+
text: leaf.text,
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return blockers;
|
|
956
|
+
}
|
|
957
|
+
export function prewriteIdentityBlockers(payload, datasetType, repoRoot = null, { allowAccountLocalSupportAndElementary = false, profile = null } = {}) {
|
|
958
|
+
return [
|
|
959
|
+
...sourcePrewriteIdentityBlockers(payload, datasetType),
|
|
960
|
+
...flowPrewriteIdentityBlockers(payload, datasetType, allowAccountLocalSupportAndElementary),
|
|
961
|
+
...prewriteContentQualityBlockers({ repoRoot, payload, datasetType, profile }),
|
|
962
|
+
];
|
|
963
|
+
}
|
|
964
|
+
export function processClassificationClassesAreCanonical(repoRoot, classes) {
|
|
965
|
+
const rawCodes = classes.map(classCode).filter(Boolean);
|
|
966
|
+
const leafCode = rawCodes.at(-1);
|
|
967
|
+
const canonical = processCategoryPathForCode(repoRoot, leafCode);
|
|
968
|
+
if (!leafCode || canonical.length === 0)
|
|
969
|
+
return false;
|
|
970
|
+
const canonicalPrefix = canonical.slice(0, rawCodes.length);
|
|
971
|
+
if (rawCodes.join("/") !== canonicalPrefix.map((entry) => entry.code).join("/")) {
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
return classes.every((item, index) => {
|
|
975
|
+
const expected = canonicalPrefix[index];
|
|
976
|
+
if (!expected)
|
|
977
|
+
return false;
|
|
978
|
+
const level = classLevel(item);
|
|
979
|
+
const text = classText(item);
|
|
980
|
+
return (level === null || level === expected.level) && (!text || text === expected.text);
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
export function classificationQueueRowStillNeedsAuthoring({ repoRoot, datasetType = "process", payload, row, }) {
|
|
984
|
+
const typedRow = asRecord(row);
|
|
985
|
+
const expectedDisplay = comparableText(typedRow.current_classification);
|
|
986
|
+
if (!expectedDisplay)
|
|
987
|
+
return true;
|
|
988
|
+
const currentDisplay = comparableText(classificationDisplayForPayload(payload, datasetType));
|
|
989
|
+
if (!currentDisplay)
|
|
990
|
+
return true;
|
|
991
|
+
if (currentDisplay === expectedDisplay)
|
|
992
|
+
return true;
|
|
993
|
+
if (datasetType === "process" &&
|
|
994
|
+
!processClassificationClassesAreCanonical(repoRoot, classificationClassesForPayload(payload, datasetType))) {
|
|
995
|
+
return true;
|
|
996
|
+
}
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
export function valueAtDotPath(value, dotPath) {
|
|
1000
|
+
const parts = asText(dotPath).split(".").filter(Boolean);
|
|
1001
|
+
let current = value;
|
|
1002
|
+
for (const part of parts) {
|
|
1003
|
+
if (Array.isArray(current)) {
|
|
1004
|
+
const index = Number(part);
|
|
1005
|
+
if (!Number.isInteger(index))
|
|
1006
|
+
return undefined;
|
|
1007
|
+
current = current[index];
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
if (!current || typeof current !== "object")
|
|
1011
|
+
return undefined;
|
|
1012
|
+
current = current[part];
|
|
1013
|
+
}
|
|
1014
|
+
return current;
|
|
1015
|
+
}
|
|
1016
|
+
export function locationQueueRowStillNeedsAuthoring({ repoRoot, payload, row, }) {
|
|
1017
|
+
const typedRow = asRecord(row);
|
|
1018
|
+
const targetPath = asText(typedRow.target_path ?? typedRow.path);
|
|
1019
|
+
if (!targetPath)
|
|
1020
|
+
return true;
|
|
1021
|
+
const currentLocation = asText(valueAtDotPath(payload, targetPath));
|
|
1022
|
+
if (!currentLocation)
|
|
1023
|
+
return true;
|
|
1024
|
+
const queuedLocation = asText(typedRow.current_location ?? typedRow.location);
|
|
1025
|
+
if (!locationCodeMapForPatch(repoRoot).has(currentLocation))
|
|
1026
|
+
return true;
|
|
1027
|
+
if (queuedLocation && currentLocation === queuedLocation)
|
|
1028
|
+
return true;
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
export function classificationQueueActionItem(row) {
|
|
1032
|
+
const typedRow = asRecord(row);
|
|
1033
|
+
const datasetType = asText(typedRow.dataset_type) || "process";
|
|
1034
|
+
const classificationPath = datasetType === "flow"
|
|
1035
|
+
? "flowDataSet.flowInformation.dataSetInformation.classificationInformation.common:classification"
|
|
1036
|
+
: "processDataSet.processInformation.dataSetInformation.classificationInformation.common:classification";
|
|
1037
|
+
return {
|
|
1038
|
+
source: "classification_authoring_queue",
|
|
1039
|
+
code: asText(typedRow.code) || "process_classification_requires_authoring",
|
|
1040
|
+
path: classificationPath,
|
|
1041
|
+
message: asText(typedRow.message) ||
|
|
1042
|
+
"Converted classification requires AI authoring before remote write.",
|
|
1043
|
+
evidence: {
|
|
1044
|
+
current_classification: typedRow.current_classification ?? null,
|
|
1045
|
+
source_classification: typedRow.source_classification ?? null,
|
|
1046
|
+
authoring_context: typedRow.authoring_context ?? null,
|
|
1047
|
+
source_file: typedRow.source_file ?? null,
|
|
1048
|
+
classification_workflow: typedRow.classification_workflow ?? null,
|
|
1049
|
+
},
|
|
1050
|
+
instruction: asText(typedRow.required_resolution) ||
|
|
1051
|
+
"Use the full schema/YAML/context package and TIDAS classification workflow to choose the target classification. Preserve source classification only as provenance.",
|
|
1052
|
+
action_kind: "classification_decision_authoring",
|
|
1053
|
+
required_owner: "foundry_ai_authoring",
|
|
1054
|
+
ai_required: true,
|
|
1055
|
+
common_other_deferral_allowed: false,
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
export function locationQueueActionItem(row) {
|
|
1059
|
+
const typedRow = asRecord(row);
|
|
1060
|
+
return {
|
|
1061
|
+
source: "location_authoring_queue",
|
|
1062
|
+
code: asText(typedRow.code) || "location_code_requires_authoring",
|
|
1063
|
+
path: asText(typedRow.target_path ?? typedRow.path) || null,
|
|
1064
|
+
message: asText(typedRow.message) ||
|
|
1065
|
+
"Location value must be replaced with a valid TIDAS location code before remote write.",
|
|
1066
|
+
evidence: {
|
|
1067
|
+
current_location: typedRow.current_location ?? typedRow.location ?? null,
|
|
1068
|
+
target_path: typedRow.target_path ?? typedRow.path ?? null,
|
|
1069
|
+
location_workflow: typedRow.location_workflow ?? null,
|
|
1070
|
+
source_file: typedRow.source_file ?? null,
|
|
1071
|
+
},
|
|
1072
|
+
instruction: asText(typedRow.required_resolution) ||
|
|
1073
|
+
"Use the full schema/YAML/context package and TIDAS location classification workflow to choose the target location code.",
|
|
1074
|
+
action_kind: "location_decision_authoring",
|
|
1075
|
+
required_owner: "foundry_ai_authoring",
|
|
1076
|
+
ai_required: true,
|
|
1077
|
+
common_other_deferral_allowed: false,
|
|
1078
|
+
};
|
|
1079
|
+
}
|