@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,704 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
function recordArray(value) {
|
|
5
|
+
return Array.isArray(value)
|
|
6
|
+
? value.filter((item) => Boolean(item) && typeof item === "object" && !Array.isArray(item))
|
|
7
|
+
: [];
|
|
8
|
+
}
|
|
9
|
+
export function createLocationDecisionCommands({ includeExecutionCommands = true, asText, buildClassificationDecisionTaskContextFiles, buildClassificationTaskProvenanceContext, buildDecisionTaskContextBundle, classificationDecisionCode, classificationDecisionSchemaType, classificationDecisionUsedContextKinds, compactStageReport, datasetIdentity, decisionAuthoringContext, decisionCompletionStatus, decisionContextBundleSha256, decisionTaskBuildStatus, decisionTaskChunkLabel, decisionTaskContextBlockers, decisionTaskContextBundleHashes, decisionTaskContextFileSummary, decisionTaskInputRowsOverride, decisionTaskProofList, decisionTaskReportPayload, ensureArray, fileExists, hasQueueSelectionOptions, hasUnresolvedAiPlaceholder, nowIso, readDecisionTaskProofs, readJsonOrJsonLines, repoRelativeMaybe, repoRelativePath, repoRoot, resolveRepoPath, rewriteDecisionTaskQueueRowsForChunk, runTiangongJsonStage, selectDecisionTaskQueueRows, shellQuote, unique, writeJson, writeJsonLines, }) {
|
|
10
|
+
function locationQueueInputRows(row) {
|
|
11
|
+
return asText(row?.location_workflow?.commands?.input_rows);
|
|
12
|
+
}
|
|
13
|
+
function locationQueueOutputRows(row) {
|
|
14
|
+
return asText(row?.location_workflow?.commands?.output_rows);
|
|
15
|
+
}
|
|
16
|
+
function locationQueueTargetKey(row) {
|
|
17
|
+
return `location::${asText(row?.dataset_id)}::${asText(row?.dataset_version)}::${asText(row?.path)}`;
|
|
18
|
+
}
|
|
19
|
+
function locationDecisionTargetPath(decision) {
|
|
20
|
+
return asText(decision?.target_path ??
|
|
21
|
+
decision?.targetPath ??
|
|
22
|
+
decision?.location_path ??
|
|
23
|
+
decision?.locationPath ??
|
|
24
|
+
decision?.path);
|
|
25
|
+
}
|
|
26
|
+
function locationDecisionTargetKey(decision) {
|
|
27
|
+
return `location::${asText(decision?.dataset_id ?? decision?.datasetId ?? decision?.id)}::${asText(decision?.dataset_version ?? decision?.datasetVersion ?? decision?.version)}::${locationDecisionTargetPath(decision)}`;
|
|
28
|
+
}
|
|
29
|
+
function buildLocationTaskInputRowLookup(queueRows) {
|
|
30
|
+
const byInput = new Map();
|
|
31
|
+
for (const queueRow of queueRows) {
|
|
32
|
+
const inputRows = locationQueueInputRows(queueRow);
|
|
33
|
+
if (!inputRows)
|
|
34
|
+
continue;
|
|
35
|
+
const resolved = resolveRepoPath(inputRows);
|
|
36
|
+
if (!resolved || !fileExists(resolved))
|
|
37
|
+
continue;
|
|
38
|
+
if (!byInput.has(resolved)) {
|
|
39
|
+
byInput.set(resolved, readJsonOrJsonLines(resolved));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const lookup = new Map();
|
|
43
|
+
for (const [inputFile, rows] of byInput.entries()) {
|
|
44
|
+
for (const queueRow of queueRows) {
|
|
45
|
+
if (resolveRepoPath(locationQueueInputRows(queueRow)) !== inputFile) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const rowType = asText(queueRow.dataset_type);
|
|
49
|
+
for (const [index, row] of rows.entries()) {
|
|
50
|
+
const identity = datasetIdentity(row, rowType);
|
|
51
|
+
if (identity.id === asText(queueRow.dataset_id) &&
|
|
52
|
+
identity.version === asText(queueRow.dataset_version)) {
|
|
53
|
+
lookup.set(locationQueueTargetKey(queueRow), {
|
|
54
|
+
index,
|
|
55
|
+
row_type: rowType,
|
|
56
|
+
dataset_id: identity.id,
|
|
57
|
+
dataset_version: identity.version,
|
|
58
|
+
input_rows: repoRelativePath(inputFile),
|
|
59
|
+
payload: row,
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return lookup;
|
|
67
|
+
}
|
|
68
|
+
function locationTaskEvidenceForQueueRow(row, index, rowLookup) {
|
|
69
|
+
const inputRow = rowLookup.get(locationQueueTargetKey(row)) ?? null;
|
|
70
|
+
return {
|
|
71
|
+
source: "location-authoring-queue",
|
|
72
|
+
queue_row_index: index,
|
|
73
|
+
current_location: row.current_location ?? null,
|
|
74
|
+
target_path: row.path ?? null,
|
|
75
|
+
source_file: row.source_file ?? null,
|
|
76
|
+
input_rows: locationQueueInputRows(row) || null,
|
|
77
|
+
output_rows: locationQueueOutputRows(row) || null,
|
|
78
|
+
input_row_index: inputRow?.index ?? null,
|
|
79
|
+
input_row_identity: inputRow
|
|
80
|
+
? {
|
|
81
|
+
dataset_id: inputRow.dataset_id,
|
|
82
|
+
dataset_version: inputRow.dataset_version,
|
|
83
|
+
row_type: inputRow.row_type,
|
|
84
|
+
}
|
|
85
|
+
: null,
|
|
86
|
+
input_row_payload: inputRow?.payload ?? null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function buildLocationDecisionTemplateRows(queueRows, rowLookup = new Map(), contextBundle = null) {
|
|
90
|
+
const authoringContext = contextBundle ? decisionAuthoringContext(contextBundle) : null;
|
|
91
|
+
return queueRows.map((row, index) => ({
|
|
92
|
+
dataset_id: row.dataset_id,
|
|
93
|
+
dataset_version: row.dataset_version,
|
|
94
|
+
category_type: "location",
|
|
95
|
+
decision_status: "completed",
|
|
96
|
+
code: "__AI_SELECT_TIDAS_LOCATION_CODE__",
|
|
97
|
+
target_path: row.path,
|
|
98
|
+
basis: "__AI_FILL_LOCATION_DECISION_BASIS__",
|
|
99
|
+
used_context_kinds: ["__AI_FILL_USED_CONTEXT_KINDS__"],
|
|
100
|
+
...(authoringContext ? { authoring_context: authoringContext } : {}),
|
|
101
|
+
evidence: locationTaskEvidenceForQueueRow(row, index, rowLookup),
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
function runDatasetLocationDecisionTaskBuild(options) {
|
|
105
|
+
if (options.help) {
|
|
106
|
+
return {
|
|
107
|
+
schema_version: 1,
|
|
108
|
+
status: "help",
|
|
109
|
+
command: "dataset-location-decision-task-build",
|
|
110
|
+
usage: [
|
|
111
|
+
"node scripts/foundry.ts dataset-location-decision-task-build --location-queue <location-authoring-queue.jsonl> --rows-file <current-rows.jsonl> --schema-file <schema.json> --yaml-file <methodology.yaml> --ruleset-file <runtime-ruleset.json> --classification-schema <tidas_*_category.json> --location-schema <tidas_locations_category.json> --out-dir <task-dir> [--shared-context-cache-dir <cache-dir>]",
|
|
112
|
+
],
|
|
113
|
+
purpose: "Build an AI-facing location coding task from Foundry location queue rows. AI fills TIDAS location codes; deterministic apply is handled by dataset-location-decisions-apply.",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const queuePath = resolveRepoPath(options.locationQueue || options.queue || options.input);
|
|
117
|
+
if (!queuePath || !fileExists(queuePath)) {
|
|
118
|
+
throw new Error("--location-queue is required and must point to location-authoring-queue.jsonl.");
|
|
119
|
+
}
|
|
120
|
+
const outDir = resolveRepoPath(options.outDir || ".foundry/workspaces/location-decision-task");
|
|
121
|
+
const sharedContextCacheDir = resolveRepoPath(options.sharedContextCacheDir || options.contextCacheDir);
|
|
122
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
123
|
+
const sourceQueueRows = readJsonOrJsonLines(queuePath);
|
|
124
|
+
const useSelection = hasQueueSelectionOptions(options);
|
|
125
|
+
const inputRowsOverride = decisionTaskInputRowsOverride(options);
|
|
126
|
+
const shouldDeriveQueue = useSelection || Boolean(inputRowsOverride);
|
|
127
|
+
let queueRows = sourceQueueRows;
|
|
128
|
+
let taskQueuePath = queuePath;
|
|
129
|
+
let selection = {
|
|
130
|
+
source_queue_rows: sourceQueueRows.length,
|
|
131
|
+
matched_queue_rows: sourceQueueRows.length,
|
|
132
|
+
selected_queue_rows: sourceQueueRows.length,
|
|
133
|
+
source_queue_row_indices: sourceQueueRows.map((_, index) => index),
|
|
134
|
+
};
|
|
135
|
+
if (shouldDeriveQueue) {
|
|
136
|
+
const selected = useSelection
|
|
137
|
+
? selectDecisionTaskQueueRows(sourceQueueRows, options, () => "location")
|
|
138
|
+
: {
|
|
139
|
+
selection,
|
|
140
|
+
selected: sourceQueueRows.map((row, sourceIndex) => ({
|
|
141
|
+
row,
|
|
142
|
+
sourceIndex,
|
|
143
|
+
})),
|
|
144
|
+
};
|
|
145
|
+
selection = {
|
|
146
|
+
...selected.selection,
|
|
147
|
+
input_rows_override: inputRowsOverride ? repoRelativePath(inputRowsOverride) : null,
|
|
148
|
+
};
|
|
149
|
+
const chunkLabel = decisionTaskChunkLabel(options, selection, inputRowsOverride ? "location-current-rows" : "location-chunk");
|
|
150
|
+
queueRows = rewriteDecisionTaskQueueRowsForChunk({
|
|
151
|
+
selected: selected.selected,
|
|
152
|
+
sourceQueuePath: queuePath,
|
|
153
|
+
outDir,
|
|
154
|
+
chunkLabel,
|
|
155
|
+
workflowKey: "location_workflow",
|
|
156
|
+
outputSuffix: "located",
|
|
157
|
+
inputRowsForRow: locationQueueInputRows,
|
|
158
|
+
inputRowsOverride,
|
|
159
|
+
});
|
|
160
|
+
selection.chunk_label = chunkLabel;
|
|
161
|
+
taskQueuePath = path.join(outDir, `location-authoring-queue.${chunkLabel}.jsonl`);
|
|
162
|
+
writeJsonLines(taskQueuePath, queueRows);
|
|
163
|
+
}
|
|
164
|
+
const rowLookup = buildLocationTaskInputRowLookup(queueRows);
|
|
165
|
+
const templatePath = path.join(outDir, "location-decisions.template.jsonl");
|
|
166
|
+
const taskPath = path.join(outDir, "location-decision-task.json");
|
|
167
|
+
const reportPath = path.join(outDir, "location-decision-task-report.json");
|
|
168
|
+
const decisionFile = path.join(outDir, "location-decisions.jsonl");
|
|
169
|
+
const contractContext = buildClassificationDecisionTaskContextFiles(options);
|
|
170
|
+
const provenanceContext = buildClassificationTaskProvenanceContext(queuePath);
|
|
171
|
+
const attachedInputRows = [...rowLookup.values()];
|
|
172
|
+
const contextBundle = buildDecisionTaskContextBundle({
|
|
173
|
+
taskKind: "location_decision_authoring",
|
|
174
|
+
taskPath,
|
|
175
|
+
outDir,
|
|
176
|
+
sharedContextCacheDir,
|
|
177
|
+
queuePath: taskQueuePath,
|
|
178
|
+
queueRows,
|
|
179
|
+
contractContext,
|
|
180
|
+
provenanceContext,
|
|
181
|
+
attachedInputRows,
|
|
182
|
+
});
|
|
183
|
+
const templateRows = buildLocationDecisionTemplateRows(queueRows, rowLookup, contextBundle);
|
|
184
|
+
const queueRowsWithAttachedInput = templateRows.filter((row) => row.evidence?.input_row_payload).length;
|
|
185
|
+
const blockers = decisionTaskContextBlockers({
|
|
186
|
+
kind: "location",
|
|
187
|
+
queueRows,
|
|
188
|
+
contractContext,
|
|
189
|
+
requiredContextKinds: [
|
|
190
|
+
"schema",
|
|
191
|
+
"methodology_yaml",
|
|
192
|
+
"ruleset",
|
|
193
|
+
"classification_schema",
|
|
194
|
+
"location_schema",
|
|
195
|
+
],
|
|
196
|
+
attachedInputRowCount: queueRowsWithAttachedInput,
|
|
197
|
+
});
|
|
198
|
+
const datasetTypes = unique(queueRows.map((row) => asText(row.dataset_type)));
|
|
199
|
+
const task = {
|
|
200
|
+
schema_version: 1,
|
|
201
|
+
generated_at_utc: nowIso(),
|
|
202
|
+
status: decisionTaskBuildStatus({
|
|
203
|
+
queueRows,
|
|
204
|
+
blockers,
|
|
205
|
+
readyStatus: "ready_for_ai_location_decisions",
|
|
206
|
+
emptyStatus: "ready_no_location_actions",
|
|
207
|
+
}),
|
|
208
|
+
task_kind: "location_decision_authoring",
|
|
209
|
+
location_queue: repoRelativePath(taskQueuePath),
|
|
210
|
+
counts: {
|
|
211
|
+
queue_rows: queueRows.length,
|
|
212
|
+
template_decisions: templateRows.length,
|
|
213
|
+
dataset_types: datasetTypes.length,
|
|
214
|
+
contract_context_files: contractContext.files.length,
|
|
215
|
+
missing_context_files: contractContext.missing.length,
|
|
216
|
+
attached_input_rows: queueRowsWithAttachedInput,
|
|
217
|
+
unique_attached_input_rows: attachedInputRows.length,
|
|
218
|
+
missing_input_row_payloads: queueRows.length - queueRowsWithAttachedInput,
|
|
219
|
+
provenance_context_files: [
|
|
220
|
+
provenanceContext.source_semantics.file,
|
|
221
|
+
provenanceContext.process_source_references.file,
|
|
222
|
+
provenanceContext.source_reference_rewrites.file,
|
|
223
|
+
].filter(Boolean).length,
|
|
224
|
+
blockers: blockers.length,
|
|
225
|
+
},
|
|
226
|
+
blockers,
|
|
227
|
+
dataset_types: datasetTypes,
|
|
228
|
+
selection,
|
|
229
|
+
source_location_queue: shouldDeriveQueue ? repoRelativePath(queuePath) : null,
|
|
230
|
+
location_queue_rows: queueRows,
|
|
231
|
+
attached_input_rows: attachedInputRows,
|
|
232
|
+
provenance_context: provenanceContext,
|
|
233
|
+
context_bundle: contextBundle,
|
|
234
|
+
shared_context_bundle: contextBundle.shared_context_bundle,
|
|
235
|
+
context_files: contractContext.files.map((file) => file.path),
|
|
236
|
+
contract_context_files: contractContext.files.map(decisionTaskContextFileSummary),
|
|
237
|
+
missing_context_files: contractContext.missing,
|
|
238
|
+
instructions: [
|
|
239
|
+
"Read shared_context_bundle once for full Foundry/SDK schema, methodology YAML, runtime ruleset, tidas_locations_category.json text, then use this task's queue rows, attached payloads, provenance, and source trace before choosing location codes.",
|
|
240
|
+
"Replace each template code with a valid TIDAS location code; keep source location text as evidence, not target code.",
|
|
241
|
+
"Every decision must include dataset_id, dataset_version, category_type=location, code, target_path, basis, used_context_kinds, and structured evidence.",
|
|
242
|
+
"Do not write row JSON directly; run dataset-location-decisions-apply after decisions are complete.",
|
|
243
|
+
],
|
|
244
|
+
files: {
|
|
245
|
+
task: repoRelativePath(taskPath),
|
|
246
|
+
template: repoRelativePath(templatePath),
|
|
247
|
+
expected_decisions: repoRelativePath(decisionFile),
|
|
248
|
+
report: repoRelativePath(reportPath),
|
|
249
|
+
shared_context_bundle: contextBundle.shared_context_bundle.path,
|
|
250
|
+
},
|
|
251
|
+
commands: {
|
|
252
|
+
apply_decisions: includeExecutionCommands
|
|
253
|
+
? [
|
|
254
|
+
process.execPath,
|
|
255
|
+
path.join(repoRoot, "scripts", "foundry.ts"),
|
|
256
|
+
"dataset-location-decisions-apply",
|
|
257
|
+
"--location-queue",
|
|
258
|
+
taskQueuePath,
|
|
259
|
+
"--decisions",
|
|
260
|
+
decisionFile,
|
|
261
|
+
"--decision-task",
|
|
262
|
+
taskPath,
|
|
263
|
+
"--out-dir",
|
|
264
|
+
path.join(outDir, "apply"),
|
|
265
|
+
]
|
|
266
|
+
.map(shellQuote)
|
|
267
|
+
.join(" ")
|
|
268
|
+
: null,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
writeJsonLines(templatePath, templateRows);
|
|
272
|
+
writeJson(taskPath, task);
|
|
273
|
+
writeJson(reportPath, task);
|
|
274
|
+
return task;
|
|
275
|
+
}
|
|
276
|
+
function validateLocationDecisionsForQueue(queueRows, decisions, { decisionTaskProof = null } = {}) {
|
|
277
|
+
const blockers = [];
|
|
278
|
+
const decisionTaskProofs = decisionTaskProofList(decisionTaskProof);
|
|
279
|
+
for (const proof of decisionTaskProofs) {
|
|
280
|
+
blockers.push(...proof.blockers);
|
|
281
|
+
}
|
|
282
|
+
const contextBundleHashes = decisionTaskContextBundleHashes(decisionTaskProofs);
|
|
283
|
+
const queueByKey = new Map(queueRows.map((row) => [locationQueueTargetKey(row), row]));
|
|
284
|
+
const decisionsByKey = new Map();
|
|
285
|
+
for (const [index, decision] of decisions.entries()) {
|
|
286
|
+
const key = locationDecisionTargetKey(decision);
|
|
287
|
+
if (hasUnresolvedAiPlaceholder(decision)) {
|
|
288
|
+
blockers.push({
|
|
289
|
+
code: "location_decision_template_incomplete",
|
|
290
|
+
message: "Location decision still contains an AI placeholder.",
|
|
291
|
+
decision_index: index,
|
|
292
|
+
});
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (decisionCompletionStatus(decision) !== "completed") {
|
|
296
|
+
blockers.push({
|
|
297
|
+
code: "location_decision_status_not_completed",
|
|
298
|
+
message: "Location decision must declare decision_status=completed before deterministic apply.",
|
|
299
|
+
decision_index: index,
|
|
300
|
+
decision_status: decisionCompletionStatus(decision) || null,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (classificationDecisionSchemaType(decision) !== "location") {
|
|
304
|
+
blockers.push({
|
|
305
|
+
code: "location_decision_schema_type_invalid",
|
|
306
|
+
message: "Location decision must include category_type=location.",
|
|
307
|
+
decision_index: index,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (!classificationDecisionCode(decision)) {
|
|
311
|
+
blockers.push({
|
|
312
|
+
code: "location_decision_code_missing",
|
|
313
|
+
message: "Location decision must include a TIDAS location code.",
|
|
314
|
+
decision_index: index,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (!locationDecisionTargetPath(decision)) {
|
|
318
|
+
blockers.push({
|
|
319
|
+
code: "location_decision_target_path_missing",
|
|
320
|
+
message: "Location decision must include target_path.",
|
|
321
|
+
decision_index: index,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
if (!asText(decision.basis)) {
|
|
325
|
+
blockers.push({
|
|
326
|
+
code: "location_decision_basis_missing",
|
|
327
|
+
message: "Location decision must include basis.",
|
|
328
|
+
decision_index: index,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (!decision.evidence || typeof decision.evidence !== "object") {
|
|
332
|
+
blockers.push({
|
|
333
|
+
code: "location_decision_evidence_missing",
|
|
334
|
+
message: "Location decision must include structured evidence.",
|
|
335
|
+
decision_index: index,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (classificationDecisionUsedContextKinds(decision).length === 0) {
|
|
339
|
+
blockers.push({
|
|
340
|
+
code: "location_decision_used_context_missing",
|
|
341
|
+
message: "Location decision must include used_context_kinds so full-context AI evidence is auditable.",
|
|
342
|
+
decision_index: index,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (contextBundleHashes.length > 0) {
|
|
346
|
+
const decisionBundleHash = decisionContextBundleSha256(decision);
|
|
347
|
+
if (!decisionBundleHash) {
|
|
348
|
+
blockers.push({
|
|
349
|
+
code: "location_decision_context_bundle_missing",
|
|
350
|
+
message: "Location decision must include authoring_context.context_bundle_sha256 from the AI decision task template.",
|
|
351
|
+
decision_index: index,
|
|
352
|
+
decision_tasks: decisionTaskProofs.map((proof) => proof.path),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
else if (!contextBundleHashes.includes(decisionBundleHash)) {
|
|
356
|
+
blockers.push({
|
|
357
|
+
code: "location_decision_context_bundle_mismatch",
|
|
358
|
+
message: "Location decision authoring context hash does not match the AI decision task context bundle.",
|
|
359
|
+
decision_index: index,
|
|
360
|
+
expected_context_bundle_sha256: contextBundleHashes.length === 1 ? contextBundleHashes[0] : null,
|
|
361
|
+
expected_context_bundle_sha256_any_of: contextBundleHashes,
|
|
362
|
+
actual_context_bundle_sha256: decisionBundleHash,
|
|
363
|
+
decision_tasks: decisionTaskProofs.map((proof) => proof.path),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (!queueByKey.has(key)) {
|
|
368
|
+
blockers.push({
|
|
369
|
+
code: "location_decision_not_in_queue",
|
|
370
|
+
message: "Location decision does not match a queued dataset_id/version/target_path.",
|
|
371
|
+
decision_index: index,
|
|
372
|
+
decision_key: key,
|
|
373
|
+
});
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (decisionsByKey.has(key)) {
|
|
377
|
+
blockers.push({
|
|
378
|
+
code: "location_decision_duplicate",
|
|
379
|
+
message: "More than one location decision targets the same queue row.",
|
|
380
|
+
decision_index: index,
|
|
381
|
+
decision_key: key,
|
|
382
|
+
});
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
decisionsByKey.set(key, { ...decision, category_type: "location" });
|
|
386
|
+
}
|
|
387
|
+
for (const row of queueRows) {
|
|
388
|
+
const key = locationQueueTargetKey(row);
|
|
389
|
+
if (!decisionsByKey.has(key)) {
|
|
390
|
+
blockers.push({
|
|
391
|
+
code: "location_queue_item_unclosed",
|
|
392
|
+
message: "Every location queue row must be closed by one decision.",
|
|
393
|
+
dataset_type: row.dataset_type,
|
|
394
|
+
dataset_id: row.dataset_id,
|
|
395
|
+
dataset_version: row.dataset_version,
|
|
396
|
+
path: row.path,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { blockers, decisionsByKey };
|
|
401
|
+
}
|
|
402
|
+
function locationDecisionTaskAuthoringContext(task, taskPath) {
|
|
403
|
+
const contextBundle = task?.context_bundle ?? task?.contextBundle;
|
|
404
|
+
const contractFiles = recordArray(contextBundle?.contract_context_files);
|
|
405
|
+
return {
|
|
406
|
+
task: contextBundle?.task ?? repoRelativePath(taskPath),
|
|
407
|
+
context_bundle_sha256: asText(contextBundle?.sha256),
|
|
408
|
+
required_context_kinds: unique(contractFiles.map((file) => asText(file?.kind)).filter(Boolean)),
|
|
409
|
+
context_files: contractFiles.map((file) => ({
|
|
410
|
+
kind: asText(file?.kind) || "context",
|
|
411
|
+
path: asText(file?.path) || null,
|
|
412
|
+
sha256: asText(file?.sha256) || null,
|
|
413
|
+
})),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function locationSchemaCodeSet(options) {
|
|
417
|
+
const schemaPath = resolveRepoPath(options.locationSchema || options.locationCategorySchema);
|
|
418
|
+
if (!schemaPath || !fileExists(schemaPath))
|
|
419
|
+
return null;
|
|
420
|
+
const schemaRows = readJsonOrJsonLines(schemaPath);
|
|
421
|
+
const schema = Array.isArray(schemaRows) && schemaRows.length === 1 ? schemaRows[0] : {};
|
|
422
|
+
const oneOf = recordArray(schema?.oneOf);
|
|
423
|
+
return new Set(oneOf.map((entry) => asText(entry?.const)).filter(Boolean));
|
|
424
|
+
}
|
|
425
|
+
function collectSuggestedLocationCodes(queueRow) {
|
|
426
|
+
const values = [
|
|
427
|
+
queueRow?.suggested_location_code,
|
|
428
|
+
queueRow?.suggestedLocationCode,
|
|
429
|
+
queueRow?.suggested_code,
|
|
430
|
+
queueRow?.suggestedCode,
|
|
431
|
+
queueRow?.evidence?.suggested_value,
|
|
432
|
+
queueRow?.evidence?.suggestedValue,
|
|
433
|
+
];
|
|
434
|
+
for (const candidate of ensureArray(queueRow?.evidence?.candidates)) {
|
|
435
|
+
values.push(candidate?.code);
|
|
436
|
+
values.push(candidate?.suggested_value);
|
|
437
|
+
}
|
|
438
|
+
return unique(values.map(asText).filter(Boolean));
|
|
439
|
+
}
|
|
440
|
+
function runDatasetLocationDecisionsSuggest(options) {
|
|
441
|
+
if (options.help) {
|
|
442
|
+
return {
|
|
443
|
+
schema_version: 1,
|
|
444
|
+
status: "help",
|
|
445
|
+
command: "dataset-location-decisions-suggest",
|
|
446
|
+
usage: [
|
|
447
|
+
"node scripts/foundry.ts dataset-location-decisions-suggest --location-queue <location-authoring-queue.jsonl> --decision-task <location-decision-task.json> --location-schema <tidas_locations_category.json> --out-dir <decisions-dir>",
|
|
448
|
+
],
|
|
449
|
+
purpose: "Generate completed location decisions only for queue rows that already contain one provable TIDAS location code candidate, binding each decision to the exact location decision task context bundle.",
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
const queuePath = resolveRepoPath(options.locationQueue || options.queue);
|
|
453
|
+
const decisionTaskPath = resolveRepoPath(options.decisionTask || options.locationDecisionTask || options.task);
|
|
454
|
+
if (!queuePath || !fileExists(queuePath)) {
|
|
455
|
+
throw new Error("--location-queue is required and must point to location-authoring-queue.jsonl.");
|
|
456
|
+
}
|
|
457
|
+
if (!decisionTaskPath || !fileExists(decisionTaskPath)) {
|
|
458
|
+
throw new Error("--decision-task is required so suggested decisions can bind to the exact full-context task bundle.");
|
|
459
|
+
}
|
|
460
|
+
const outDir = resolveRepoPath(options.outDir || ".foundry/workspaces/location-decisions");
|
|
461
|
+
const queueRows = readJsonOrJsonLines(queuePath);
|
|
462
|
+
const decisionTask = readJsonOrJsonLines(decisionTaskPath);
|
|
463
|
+
const taskPayload = Array.isArray(decisionTask) ? decisionTask[0] : decisionTask;
|
|
464
|
+
const authoringContext = locationDecisionTaskAuthoringContext(taskPayload, decisionTaskPath);
|
|
465
|
+
const requiredContextKinds = unique([
|
|
466
|
+
...authoringContext.required_context_kinds,
|
|
467
|
+
"schema",
|
|
468
|
+
"methodology_yaml",
|
|
469
|
+
"ruleset",
|
|
470
|
+
"classification_schema",
|
|
471
|
+
"location_schema",
|
|
472
|
+
"location_authoring_queue",
|
|
473
|
+
]);
|
|
474
|
+
const validCodes = locationSchemaCodeSet(options);
|
|
475
|
+
const decisions = [];
|
|
476
|
+
const manualReview = [];
|
|
477
|
+
for (const [index, queueRow] of queueRows.entries()) {
|
|
478
|
+
const candidates = collectSuggestedLocationCodes(queueRow);
|
|
479
|
+
const validCandidates = validCodes
|
|
480
|
+
? candidates.filter((code) => validCodes.has(code))
|
|
481
|
+
: candidates;
|
|
482
|
+
if (validCandidates.length !== 1) {
|
|
483
|
+
manualReview.push({
|
|
484
|
+
schema_version: 1,
|
|
485
|
+
status: "manual_review",
|
|
486
|
+
reason: validCandidates.length === 0
|
|
487
|
+
? "location_suggestion_missing_or_invalid"
|
|
488
|
+
: "location_suggestion_conflict",
|
|
489
|
+
queue_row_index: index,
|
|
490
|
+
dataset_type: queueRow.dataset_type ?? null,
|
|
491
|
+
dataset_id: queueRow.dataset_id ?? null,
|
|
492
|
+
dataset_version: queueRow.dataset_version ?? null,
|
|
493
|
+
target_path: queueRow.path ?? null,
|
|
494
|
+
candidate_codes: candidates,
|
|
495
|
+
valid_candidate_codes: validCandidates,
|
|
496
|
+
required_human_action: "Provide one evidence-backed TIDAS location code decision for this queue row, then rerun deterministic location apply.",
|
|
497
|
+
});
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
const code = validCandidates[0];
|
|
501
|
+
const usedContextKinds = requiredContextKinds;
|
|
502
|
+
decisions.push({
|
|
503
|
+
schema_version: 1,
|
|
504
|
+
dataset_id: queueRow.dataset_id,
|
|
505
|
+
dataset_version: queueRow.dataset_version,
|
|
506
|
+
category_type: "location",
|
|
507
|
+
decision_status: "completed",
|
|
508
|
+
code,
|
|
509
|
+
target_path: queueRow.path,
|
|
510
|
+
basis: `The location queue contains one valid source-backed TIDAS location code candidate (${code}) for this target path.`,
|
|
511
|
+
authoring_context: authoringContext,
|
|
512
|
+
used_context_kinds: usedContextKinds,
|
|
513
|
+
evidence: {
|
|
514
|
+
source: "dataset-location-decisions-suggest",
|
|
515
|
+
projection: "queue_suggested_location_code_to_decision",
|
|
516
|
+
used_context_kinds: usedContextKinds,
|
|
517
|
+
queue: {
|
|
518
|
+
row_index: index,
|
|
519
|
+
dataset_type: queueRow.dataset_type ?? null,
|
|
520
|
+
dataset_id: queueRow.dataset_id ?? null,
|
|
521
|
+
dataset_version: queueRow.dataset_version ?? null,
|
|
522
|
+
target_path: queueRow.path ?? null,
|
|
523
|
+
current_location: queueRow.current_location ?? null,
|
|
524
|
+
source_file: queueRow.source_file ?? null,
|
|
525
|
+
suggested_location_code: queueRow.suggested_location_code ?? null,
|
|
526
|
+
evidence: queueRow.evidence ?? null,
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
const decisionsPath = path.join(outDir, "location-decisions.jsonl");
|
|
532
|
+
const manualReviewPath = path.join(outDir, "location-decisions.manual-review.jsonl");
|
|
533
|
+
const reportPath = path.join(outDir, "dataset-location-decisions-suggest-report.json");
|
|
534
|
+
writeJsonLines(decisionsPath, decisions);
|
|
535
|
+
writeJsonLines(manualReviewPath, manualReview);
|
|
536
|
+
const report = {
|
|
537
|
+
schema_version: 1,
|
|
538
|
+
generated_at_utc: nowIso(),
|
|
539
|
+
status: manualReview.length > 0 ? "blocked" : "completed",
|
|
540
|
+
command: "dataset-location-decisions-suggest",
|
|
541
|
+
location_queue: repoRelativePath(queuePath),
|
|
542
|
+
decision_task: repoRelativePath(decisionTaskPath),
|
|
543
|
+
counts: {
|
|
544
|
+
queue_rows: queueRows.length,
|
|
545
|
+
suggested_decisions: decisions.length,
|
|
546
|
+
manual_review: manualReview.length,
|
|
547
|
+
blockers: manualReview.length,
|
|
548
|
+
},
|
|
549
|
+
policy: {
|
|
550
|
+
automatic_scope: "Only queue rows with exactly one valid TIDAS location code candidate are converted to decisions. Conflicts or missing candidates remain blocked for human/AI review.",
|
|
551
|
+
apply_boundary: "This command creates decision artifacts only; dataset-location-decisions-apply must perform the deterministic row update.",
|
|
552
|
+
},
|
|
553
|
+
blockers: manualReview.map((row) => ({
|
|
554
|
+
code: row.reason,
|
|
555
|
+
message: row.required_human_action,
|
|
556
|
+
dataset_type: row.dataset_type,
|
|
557
|
+
dataset_id: row.dataset_id,
|
|
558
|
+
dataset_version: row.dataset_version,
|
|
559
|
+
target_path: row.target_path,
|
|
560
|
+
candidate_codes: row.candidate_codes,
|
|
561
|
+
valid_candidate_codes: row.valid_candidate_codes,
|
|
562
|
+
})),
|
|
563
|
+
files: {
|
|
564
|
+
report: repoRelativePath(reportPath),
|
|
565
|
+
decisions: repoRelativePath(decisionsPath),
|
|
566
|
+
manual_review: repoRelativePath(manualReviewPath),
|
|
567
|
+
},
|
|
568
|
+
};
|
|
569
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
570
|
+
writeJson(reportPath, report);
|
|
571
|
+
return report;
|
|
572
|
+
}
|
|
573
|
+
function outputRowsForLocationGroup(rows, outDir, inputRows, options) {
|
|
574
|
+
if (options.out && rows.length > 0)
|
|
575
|
+
return resolveRepoPath(options.out);
|
|
576
|
+
const outputRows = unique(rows.map(locationQueueOutputRows)).filter(Boolean);
|
|
577
|
+
if (outputRows.length === 1)
|
|
578
|
+
return resolveRepoPath(outputRows[0]);
|
|
579
|
+
const inputBase = path.basename(inputRows).replace(/\.(jsonl|json)$/iu, "");
|
|
580
|
+
return path.join(outDir, "rows", `${inputBase}.located.jsonl`);
|
|
581
|
+
}
|
|
582
|
+
function runDatasetLocationDecisionsApply(options) {
|
|
583
|
+
if (options.help) {
|
|
584
|
+
return {
|
|
585
|
+
schema_version: 1,
|
|
586
|
+
status: "help",
|
|
587
|
+
command: "dataset-location-decisions-apply",
|
|
588
|
+
wraps: "tiangong-lca dataset classification apply --type location",
|
|
589
|
+
usage: [
|
|
590
|
+
"node scripts/foundry.ts dataset-location-decisions-apply --location-queue <location-authoring-queue.jsonl> --decisions <location-decisions.jsonl> --decision-task <location-decision-task.json> --out-dir <apply-dir>",
|
|
591
|
+
],
|
|
592
|
+
purpose: "Validate AI-authored location decisions against the Foundry queue and AI context task, then call the CLI location classification apply command for each required row file.",
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
const queuePath = resolveRepoPath(options.locationQueue || options.queue);
|
|
596
|
+
const decisionsPath = resolveRepoPath(options.decisions || options.decisionFile || options.input);
|
|
597
|
+
if (!queuePath || !fileExists(queuePath)) {
|
|
598
|
+
throw new Error("--location-queue is required and must point to location-authoring-queue.jsonl.");
|
|
599
|
+
}
|
|
600
|
+
if (!decisionsPath || !fileExists(decisionsPath)) {
|
|
601
|
+
throw new Error("--decisions is required and must point to JSON/JSONL location decisions.");
|
|
602
|
+
}
|
|
603
|
+
const outDir = resolveRepoPath(options.outDir || ".foundry/workspaces/location-decisions-apply");
|
|
604
|
+
const reportPath = path.join(outDir, "location-decisions-apply-report.json");
|
|
605
|
+
const queueRows = readJsonOrJsonLines(queuePath);
|
|
606
|
+
const decisions = readJsonOrJsonLines(decisionsPath);
|
|
607
|
+
const decisionTaskProofs = readDecisionTaskProofs(options, "location", queuePath);
|
|
608
|
+
const decisionTaskProof = decisionTaskProofs.length === 1 ? decisionTaskProofs[0] : null;
|
|
609
|
+
const { blockers, decisionsByKey } = validateLocationDecisionsForQueue(queueRows, decisions, {
|
|
610
|
+
decisionTaskProof: decisionTaskProofs,
|
|
611
|
+
});
|
|
612
|
+
const stages = [];
|
|
613
|
+
const inputRows = [];
|
|
614
|
+
const outputRows = [];
|
|
615
|
+
if (blockers.length === 0 && queueRows.length > 0) {
|
|
616
|
+
const queueRowsByInput = new Map();
|
|
617
|
+
for (const row of queueRows) {
|
|
618
|
+
const inputRows = resolveRepoPath(options.rowsFile || options.inputRows || locationQueueInputRows(row));
|
|
619
|
+
if (!inputRows || !fileExists(inputRows)) {
|
|
620
|
+
blockers.push({
|
|
621
|
+
code: "location_input_rows_missing",
|
|
622
|
+
message: "Queued location workflow input rows file is missing.",
|
|
623
|
+
dataset_id: row.dataset_id,
|
|
624
|
+
input_rows: locationQueueInputRows(row),
|
|
625
|
+
});
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
const key = repoRelativePath(inputRows);
|
|
629
|
+
const group = queueRowsByInput.get(key) ?? { inputRows, rows: [] };
|
|
630
|
+
group.rows.push(row);
|
|
631
|
+
queueRowsByInput.set(key, group);
|
|
632
|
+
}
|
|
633
|
+
for (const group of queueRowsByInput.values()) {
|
|
634
|
+
inputRows.push(repoRelativePath(group.inputRows));
|
|
635
|
+
const finalOutputRows = outputRowsForLocationGroup(group.rows, outDir, group.inputRows, options);
|
|
636
|
+
const groupDecisions = group.rows.map((row) => decisionsByKey.get(locationQueueTargetKey(row)));
|
|
637
|
+
const decisionFile = path.join(outDir, "decisions", "location-decisions.jsonl");
|
|
638
|
+
fs.mkdirSync(path.dirname(decisionFile), { recursive: true });
|
|
639
|
+
fs.mkdirSync(path.dirname(finalOutputRows), { recursive: true });
|
|
640
|
+
writeJsonLines(decisionFile, groupDecisions);
|
|
641
|
+
const stage = runTiangongJsonStage("location_apply", [
|
|
642
|
+
"dataset",
|
|
643
|
+
"classification",
|
|
644
|
+
"apply",
|
|
645
|
+
"--input",
|
|
646
|
+
group.inputRows,
|
|
647
|
+
"--decisions",
|
|
648
|
+
decisionFile,
|
|
649
|
+
"--out",
|
|
650
|
+
finalOutputRows,
|
|
651
|
+
"--type",
|
|
652
|
+
"location",
|
|
653
|
+
"--out-dir",
|
|
654
|
+
path.join(outDir, "classification", "location"),
|
|
655
|
+
"--json",
|
|
656
|
+
]);
|
|
657
|
+
stage.report_file = resolveRepoPath(stage.report?.files?.report);
|
|
658
|
+
stages.push(stage);
|
|
659
|
+
if (stage.exit_code !== 0) {
|
|
660
|
+
blockers.push({
|
|
661
|
+
code: "location_apply_stage_failed",
|
|
662
|
+
message: "CLI location apply failed.",
|
|
663
|
+
exit_code: stage.exit_code,
|
|
664
|
+
report_file: repoRelativeMaybe(stage.report_file),
|
|
665
|
+
});
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
outputRows.push(repoRelativePath(finalOutputRows));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const report = {
|
|
672
|
+
schema_version: 1,
|
|
673
|
+
generated_at_utc: nowIso(),
|
|
674
|
+
status: blockers.length > 0 ? "blocked" : "completed",
|
|
675
|
+
command: "dataset-location-decisions-apply",
|
|
676
|
+
location_queue: repoRelativePath(queuePath),
|
|
677
|
+
decisions_file: repoRelativePath(decisionsPath),
|
|
678
|
+
decision_task: decisionTaskReportPayload(decisionTaskProof),
|
|
679
|
+
decision_tasks: decisionTaskProofs.map(decisionTaskReportPayload),
|
|
680
|
+
counts: {
|
|
681
|
+
queue_rows: queueRows.length,
|
|
682
|
+
decisions: decisions.length,
|
|
683
|
+
stages: stages.length,
|
|
684
|
+
applied: stages.reduce((total, stage) => total + Number(stage.report?.counts?.applied ?? 0), 0),
|
|
685
|
+
blockers: blockers.length,
|
|
686
|
+
},
|
|
687
|
+
blockers,
|
|
688
|
+
stages: stages.map(compactStageReport),
|
|
689
|
+
files: {
|
|
690
|
+
report: repoRelativePath(reportPath),
|
|
691
|
+
input_rows: inputRows,
|
|
692
|
+
output_rows: outputRows,
|
|
693
|
+
},
|
|
694
|
+
};
|
|
695
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
696
|
+
writeJson(reportPath, report);
|
|
697
|
+
return report;
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
runDatasetLocationDecisionTaskBuild,
|
|
701
|
+
runDatasetLocationDecisionsSuggest,
|
|
702
|
+
runDatasetLocationDecisionsApply,
|
|
703
|
+
};
|
|
704
|
+
}
|