@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,467 @@
|
|
|
1
|
+
import { datasetIdentity, datasetRoot, unwrapDatasetPayload } from "./dataset-payload.js";
|
|
2
|
+
import { sha256Json, sha256Text } from "./hash-utils.js";
|
|
3
|
+
import { asText, ensureArray } from "./runtime-io.js";
|
|
4
|
+
export const annualSupplyMissingDataSentinelText = "9999 missing-data-sentinel/year";
|
|
5
|
+
export const foundryTraceNamespace = "https://tiangong-lca.dev/foundry/import-curation/1";
|
|
6
|
+
const datetimeFieldsToNormalize = new Set(["common:timeStamp", "common:dateOfLastRevision"]);
|
|
7
|
+
const foundryTraceKeys = [
|
|
8
|
+
"tiangongfoundry:unresolvedTrace",
|
|
9
|
+
"tiangongfoundry:sourceExchangeCompleteness",
|
|
10
|
+
];
|
|
11
|
+
const localSourceLocatorKeys = new Set([
|
|
12
|
+
"source_path",
|
|
13
|
+
"sourcePath",
|
|
14
|
+
"local_source_path",
|
|
15
|
+
"localSourcePath",
|
|
16
|
+
"package_path",
|
|
17
|
+
"packagePath",
|
|
18
|
+
"source_object",
|
|
19
|
+
"sourceObject",
|
|
20
|
+
]);
|
|
21
|
+
class InvalidDateTimeMetadataError extends Error {
|
|
22
|
+
blockers;
|
|
23
|
+
constructor(blockers) {
|
|
24
|
+
super("TIDAS/ILCD datetime metadata contains invalid values.");
|
|
25
|
+
this.name = "InvalidDateTimeMetadataError";
|
|
26
|
+
this.blockers = blockers;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function inspectUtcDateTimeString(value) {
|
|
33
|
+
if (typeof value !== "string") {
|
|
34
|
+
return { normalized: null, reason: "invalid_datetime_value_type" };
|
|
35
|
+
}
|
|
36
|
+
const trimmed = value.trim();
|
|
37
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(Z|([+-])(\d{2}):(\d{2}))$/u.exec(trimmed);
|
|
38
|
+
if (!match) {
|
|
39
|
+
return { normalized: null, reason: "invalid_datetime_syntax" };
|
|
40
|
+
}
|
|
41
|
+
const year = Number(match[1]);
|
|
42
|
+
const month = Number(match[2]);
|
|
43
|
+
const day = Number(match[3]);
|
|
44
|
+
const hour = Number(match[4]);
|
|
45
|
+
const minute = Number(match[5]);
|
|
46
|
+
const second = Number(match[6]);
|
|
47
|
+
const zone = match[7];
|
|
48
|
+
const offsetHour = Number(match[9] ?? 0);
|
|
49
|
+
const offsetMinute = Number(match[10] ?? 0);
|
|
50
|
+
const calendarProbe = new Date(0);
|
|
51
|
+
calendarProbe.setUTCHours(0, 0, 0, 0);
|
|
52
|
+
calendarProbe.setUTCFullYear(year, month - 1, day);
|
|
53
|
+
if (calendarProbe.getUTCFullYear() !== year ||
|
|
54
|
+
calendarProbe.getUTCMonth() !== month - 1 ||
|
|
55
|
+
calendarProbe.getUTCDate() !== day) {
|
|
56
|
+
return { normalized: null, reason: "invalid_calendar_date" };
|
|
57
|
+
}
|
|
58
|
+
if (hour > 23 || minute > 59 || second > 59) {
|
|
59
|
+
return { normalized: null, reason: "invalid_time" };
|
|
60
|
+
}
|
|
61
|
+
if (zone !== "Z" && (offsetHour > 23 || offsetMinute > 59)) {
|
|
62
|
+
return { normalized: null, reason: "invalid_timezone_offset" };
|
|
63
|
+
}
|
|
64
|
+
const time = Date.parse(trimmed);
|
|
65
|
+
if (Number.isNaN(time)) {
|
|
66
|
+
return { normalized: null, reason: "invalid_datetime_syntax" };
|
|
67
|
+
}
|
|
68
|
+
const normalized = new Date(time).toISOString();
|
|
69
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u.test(normalized)) {
|
|
70
|
+
return { normalized: null, reason: null };
|
|
71
|
+
}
|
|
72
|
+
return { normalized: normalized === value ? null : normalized, reason: null };
|
|
73
|
+
}
|
|
74
|
+
export function normalizeUtcDateTimeString(value) {
|
|
75
|
+
const inspection = inspectUtcDateTimeString(value);
|
|
76
|
+
return inspection.reason ? null : inspection.normalized;
|
|
77
|
+
}
|
|
78
|
+
function dateTimeMetadataPlan(value) {
|
|
79
|
+
const updates = [];
|
|
80
|
+
const blockers = [];
|
|
81
|
+
const visit = (node, currentPath) => {
|
|
82
|
+
if (!node || typeof node !== "object")
|
|
83
|
+
return;
|
|
84
|
+
if (Array.isArray(node)) {
|
|
85
|
+
node.forEach((item, index) => visit(item, `${currentPath}[${index}]`));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!isRecord(node))
|
|
89
|
+
return;
|
|
90
|
+
for (const [key, child] of Object.entries(node)) {
|
|
91
|
+
const childPath = `${currentPath}.${key}`;
|
|
92
|
+
if (datetimeFieldsToNormalize.has(key)) {
|
|
93
|
+
const inspection = inspectUtcDateTimeString(child);
|
|
94
|
+
if (inspection.reason) {
|
|
95
|
+
blockers.push({
|
|
96
|
+
code: "invalid_datetime_metadata",
|
|
97
|
+
path: childPath,
|
|
98
|
+
value: child,
|
|
99
|
+
reason: inspection.reason,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else if (inspection.normalized) {
|
|
103
|
+
updates.push({ parent: node, key, normalized: inspection.normalized });
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
visit(child, childPath);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
visit(value, "$");
|
|
111
|
+
return { updates, blockers };
|
|
112
|
+
}
|
|
113
|
+
export function normalizeDateTimeMetadata(value) {
|
|
114
|
+
const { updates, blockers } = dateTimeMetadataPlan(value);
|
|
115
|
+
if (blockers.length > 0)
|
|
116
|
+
throw new InvalidDateTimeMetadataError(blockers);
|
|
117
|
+
for (const update of updates)
|
|
118
|
+
update.parent[update.key] = update.normalized;
|
|
119
|
+
return updates.length;
|
|
120
|
+
}
|
|
121
|
+
function annualSupplyTextValue(value) {
|
|
122
|
+
if (typeof value === "string")
|
|
123
|
+
return value.trim();
|
|
124
|
+
if (isRecord(value)) {
|
|
125
|
+
return asText(value["#text"] ?? value.value);
|
|
126
|
+
}
|
|
127
|
+
return "";
|
|
128
|
+
}
|
|
129
|
+
function isPlaceholderAnnualSupplyValue(value) {
|
|
130
|
+
const text = annualSupplyTextValue(value);
|
|
131
|
+
const normalized = text.toLowerCase();
|
|
132
|
+
return (!text ||
|
|
133
|
+
/^9999$/u.test(text) ||
|
|
134
|
+
/^not\s+specified\.?$/iu.test(text) ||
|
|
135
|
+
/^not\s+declared\s+in\s+source\s+package\.?$/iu.test(text) ||
|
|
136
|
+
normalized.includes("source production volume unavailable") ||
|
|
137
|
+
normalized.includes("production volume unavailable") ||
|
|
138
|
+
normalized.includes("source evidence unavailable"));
|
|
139
|
+
}
|
|
140
|
+
function annualSupplySentinelValue() {
|
|
141
|
+
return {
|
|
142
|
+
"@xml:lang": "en",
|
|
143
|
+
"#text": annualSupplyMissingDataSentinelText,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export function applyAnnualSupplyMissingDataSentinel(row, datasetType) {
|
|
147
|
+
if (datasetType !== "process")
|
|
148
|
+
return false;
|
|
149
|
+
const payload = unwrapDatasetPayload(row, datasetType);
|
|
150
|
+
const root = datasetRoot(payload, datasetType);
|
|
151
|
+
const modelling = isRecord(root.modellingAndValidation) ? root.modellingAndValidation : {};
|
|
152
|
+
const dataSources = modelling.dataSourcesTreatmentAndRepresentativeness;
|
|
153
|
+
if (!isRecord(dataSources))
|
|
154
|
+
return false;
|
|
155
|
+
const current = dataSources.annualSupplyOrProductionVolume;
|
|
156
|
+
if (current !== undefined && !isPlaceholderAnnualSupplyValue(current)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
dataSources.annualSupplyOrProductionVolume = annualSupplySentinelValue();
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
function processDataSetInformation(row) {
|
|
163
|
+
const payload = unwrapDatasetPayload(row, "process");
|
|
164
|
+
const root = datasetRoot(payload, "process");
|
|
165
|
+
const processInformation = isRecord(root.processInformation) ? root.processInformation : {};
|
|
166
|
+
return isRecord(processInformation.dataSetInformation)
|
|
167
|
+
? processInformation.dataSetInformation
|
|
168
|
+
: null;
|
|
169
|
+
}
|
|
170
|
+
function processExchanges(row) {
|
|
171
|
+
const payload = unwrapDatasetPayload(row, "process");
|
|
172
|
+
const root = datasetRoot(payload, "process");
|
|
173
|
+
const exchanges = isRecord(root.exchanges) ? root.exchanges : {};
|
|
174
|
+
return ensureArray(exchanges.exchange);
|
|
175
|
+
}
|
|
176
|
+
function exchangeDirection(exchange) {
|
|
177
|
+
return asText(isRecord(exchange) ? exchange.exchangeDirection : undefined).toLowerCase();
|
|
178
|
+
}
|
|
179
|
+
function stripFlowReferenceFromExchange(value) {
|
|
180
|
+
if (!value || typeof value !== "object")
|
|
181
|
+
return value;
|
|
182
|
+
if (Array.isArray(value)) {
|
|
183
|
+
return value.map((item) => stripFlowReferenceFromExchange(item));
|
|
184
|
+
}
|
|
185
|
+
if (!isRecord(value))
|
|
186
|
+
return value;
|
|
187
|
+
const next = {};
|
|
188
|
+
for (const [key, child] of Object.entries(value)) {
|
|
189
|
+
if (key === "referenceToFlowDataSet")
|
|
190
|
+
continue;
|
|
191
|
+
next[key] = stripFlowReferenceFromExchange(child);
|
|
192
|
+
}
|
|
193
|
+
return next;
|
|
194
|
+
}
|
|
195
|
+
function outputOnlyExchangeProofCandidate({ row, sourceRow, }) {
|
|
196
|
+
const finalExchanges = processExchanges(row);
|
|
197
|
+
const sourceExchanges = processExchanges(sourceRow);
|
|
198
|
+
if (finalExchanges.length === 0 || sourceExchanges.length === 0)
|
|
199
|
+
return null;
|
|
200
|
+
const finalDirections = finalExchanges.map(exchangeDirection);
|
|
201
|
+
const sourceDirections = sourceExchanges.map(exchangeDirection);
|
|
202
|
+
const finalOutputOnly = finalDirections.every((item) => item === "output");
|
|
203
|
+
const sourceOutputOnly = sourceDirections.every((item) => item === "output");
|
|
204
|
+
if (!finalOutputOnly || !sourceOutputOnly)
|
|
205
|
+
return null;
|
|
206
|
+
if (finalExchanges.length !== sourceExchanges.length)
|
|
207
|
+
return null;
|
|
208
|
+
const sourceExchangeSignature = sourceExchanges.map((exchange) => stripFlowReferenceFromExchange(exchange));
|
|
209
|
+
const finalExchangeSignature = finalExchanges.map((exchange) => stripFlowReferenceFromExchange(exchange));
|
|
210
|
+
const sourceExchangeSignatureHash = sha256Json(sourceExchangeSignature);
|
|
211
|
+
const finalExchangeSignatureHash = sha256Json(finalExchangeSignature);
|
|
212
|
+
if (sourceExchangeSignatureHash !== finalExchangeSignatureHash)
|
|
213
|
+
return null;
|
|
214
|
+
return {
|
|
215
|
+
exchange_count: finalExchanges.length,
|
|
216
|
+
directions: finalDirections.map((item) => item || null),
|
|
217
|
+
source_exchange_signature_hash: sourceExchangeSignatureHash,
|
|
218
|
+
final_exchange_signature_hash: finalExchangeSignatureHash,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function acceptedSourceExchangeTraceExists(row) {
|
|
222
|
+
const info = processDataSetInformation(row);
|
|
223
|
+
const traces = ensureArray(isRecord(info?.["common:other"])
|
|
224
|
+
? info["common:other"]["tiangongfoundry:sourceExchangeCompleteness"]
|
|
225
|
+
: undefined);
|
|
226
|
+
return traces.some((trace) => {
|
|
227
|
+
const record = isRecord(trace) ? trace : {};
|
|
228
|
+
return [
|
|
229
|
+
"source_only_output_exchange_verified",
|
|
230
|
+
"accepted_source_only_output",
|
|
231
|
+
"verified",
|
|
232
|
+
].includes(asText(record.status ?? record.decision_status ?? record.decisionStatus));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function sourceRowsByIdentity(sourceRows) {
|
|
236
|
+
const byIdentity = new Map();
|
|
237
|
+
sourceRows.forEach((row, index) => {
|
|
238
|
+
const identity = datasetIdentity(row, index, "process");
|
|
239
|
+
byIdentity.set(`${identity.id}@@${identity.version}`, {
|
|
240
|
+
row,
|
|
241
|
+
index,
|
|
242
|
+
identity,
|
|
243
|
+
});
|
|
244
|
+
if (!byIdentity.has(identity.id)) {
|
|
245
|
+
byIdentity.set(identity.id, { row, index, identity });
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return byIdentity;
|
|
249
|
+
}
|
|
250
|
+
export function applyDeterministicSourceExchangeCompletenessProofs(row, datasetType, { rowIndex, sourceRowsByKey, sourceRowsFile, rowsFile, proofRows, } = {}) {
|
|
251
|
+
if (datasetType !== "process" || !sourceRowsByKey)
|
|
252
|
+
return false;
|
|
253
|
+
if (acceptedSourceExchangeTraceExists(row))
|
|
254
|
+
return false;
|
|
255
|
+
const identity = datasetIdentity(row, rowIndex ?? 0, "process");
|
|
256
|
+
const sourceEntry = sourceRowsByKey.get(`${identity.id}@@${identity.version}`) ?? sourceRowsByKey.get(identity.id);
|
|
257
|
+
if (!sourceEntry)
|
|
258
|
+
return false;
|
|
259
|
+
const proof = outputOnlyExchangeProofCandidate({
|
|
260
|
+
row,
|
|
261
|
+
sourceRow: sourceEntry.row,
|
|
262
|
+
});
|
|
263
|
+
if (!proof)
|
|
264
|
+
return false;
|
|
265
|
+
const info = processDataSetInformation(row);
|
|
266
|
+
if (!info)
|
|
267
|
+
return false;
|
|
268
|
+
const commonOther = isRecord(info["common:other"]) ? info["common:other"] : {};
|
|
269
|
+
commonOther["@xmlns:tiangongfoundry"] =
|
|
270
|
+
commonOther["@xmlns:tiangongfoundry"] ?? foundryTraceNamespace;
|
|
271
|
+
const trace = {
|
|
272
|
+
status: "source_only_output_exchange_verified",
|
|
273
|
+
action_item_code: "semantic_process_only_output_exchange_requires_review",
|
|
274
|
+
source: "foundry_deterministic_cleanup",
|
|
275
|
+
summary: "Foundry verified that the source process row itself contains only Output exchanges and that the final row preserves the non-flow-reference exchange signature.",
|
|
276
|
+
evidence: {
|
|
277
|
+
source: "foundry_deterministic_cleanup",
|
|
278
|
+
source_rows_file: sourceRowsFile || null,
|
|
279
|
+
rows_file: rowsFile || null,
|
|
280
|
+
source_row_index: sourceEntry.index,
|
|
281
|
+
final_row_index: rowIndex ?? null,
|
|
282
|
+
field_path: "processDataSet.exchanges.exchange",
|
|
283
|
+
quote_or_trace: "Source and final exchange lists are Output-only, have the same length, and have matching exchange signatures after excluding allowed referenceToFlowDataSet rewrites.",
|
|
284
|
+
exchange_count: proof.exchange_count,
|
|
285
|
+
directions: proof.directions,
|
|
286
|
+
source_exchange_signature_hash: proof.source_exchange_signature_hash,
|
|
287
|
+
final_exchange_signature_hash: proof.final_exchange_signature_hash,
|
|
288
|
+
proof_kind: "source_output_only_non_flow_reference_exchange_signature_match",
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
const traceHash = sha256Text(JSON.stringify(trace));
|
|
292
|
+
const existing = commonOther["tiangongfoundry:sourceExchangeCompleteness"];
|
|
293
|
+
if (existing === undefined) {
|
|
294
|
+
commonOther["tiangongfoundry:sourceExchangeCompleteness"] = [trace];
|
|
295
|
+
}
|
|
296
|
+
else if (Array.isArray(existing)) {
|
|
297
|
+
existing.push(trace);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
commonOther["tiangongfoundry:sourceExchangeCompleteness"] = [existing, trace];
|
|
301
|
+
}
|
|
302
|
+
info["common:other"] = commonOther;
|
|
303
|
+
proofRows?.push({
|
|
304
|
+
dataset_type: "process",
|
|
305
|
+
dataset_id: identity.id,
|
|
306
|
+
version: identity.version,
|
|
307
|
+
row_index: rowIndex ?? null,
|
|
308
|
+
source_row_index: sourceEntry.index,
|
|
309
|
+
status: trace.status,
|
|
310
|
+
trace_hash: traceHash,
|
|
311
|
+
source_rows_file: sourceRowsFile || null,
|
|
312
|
+
rows_file: rowsFile || null,
|
|
313
|
+
source_exchange_signature_hash: proof.source_exchange_signature_hash,
|
|
314
|
+
final_exchange_signature_hash: proof.final_exchange_signature_hash,
|
|
315
|
+
exchange_count: proof.exchange_count,
|
|
316
|
+
directions: proof.directions,
|
|
317
|
+
});
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
export function buildSourceRowsByIdentity(sourceRows) {
|
|
321
|
+
return sourceRowsByIdentity(sourceRows);
|
|
322
|
+
}
|
|
323
|
+
function appendImportTraceSummary(commonOther, sourceTrace) {
|
|
324
|
+
commonOther["@xmlns:tiangongfoundry"] =
|
|
325
|
+
commonOther["@xmlns:tiangongfoundry"] ?? foundryTraceNamespace;
|
|
326
|
+
const summary = {
|
|
327
|
+
"@sourceExtension": "tidasimport:sourceTrace",
|
|
328
|
+
"@status": "externalized_before_remote_write",
|
|
329
|
+
traceHash: sha256Json(sourceTrace),
|
|
330
|
+
note: "Original import trace was captured in the Foundry AI authoring package and removed from the write payload.",
|
|
331
|
+
};
|
|
332
|
+
const existing = commonOther["tiangongfoundry:importTraceSummary"];
|
|
333
|
+
if (existing === undefined) {
|
|
334
|
+
commonOther["tiangongfoundry:importTraceSummary"] = summary;
|
|
335
|
+
}
|
|
336
|
+
else if (Array.isArray(existing)) {
|
|
337
|
+
existing.push(summary);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
commonOther["tiangongfoundry:importTraceSummary"] = [existing, summary];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export function externalizeImportTraceMetadata(value) {
|
|
344
|
+
let removed = 0;
|
|
345
|
+
let summaries = 0;
|
|
346
|
+
const visit = (node) => {
|
|
347
|
+
if (!node || typeof node !== "object")
|
|
348
|
+
return;
|
|
349
|
+
if (Array.isArray(node)) {
|
|
350
|
+
for (const item of node)
|
|
351
|
+
visit(item);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (!isRecord(node))
|
|
355
|
+
return;
|
|
356
|
+
const commonOther = node["common:other"];
|
|
357
|
+
if (isRecord(commonOther)) {
|
|
358
|
+
if (Object.hasOwn(commonOther, "tidasimport:sourceTrace")) {
|
|
359
|
+
appendImportTraceSummary(commonOther, commonOther["tidasimport:sourceTrace"]);
|
|
360
|
+
delete commonOther["tidasimport:sourceTrace"];
|
|
361
|
+
removed += 1;
|
|
362
|
+
summaries += 1;
|
|
363
|
+
}
|
|
364
|
+
if (Object.hasOwn(commonOther, "@xmlns:tidasimport")) {
|
|
365
|
+
delete commonOther["@xmlns:tidasimport"];
|
|
366
|
+
}
|
|
367
|
+
if (Object.keys(commonOther).length === 0) {
|
|
368
|
+
delete node["common:other"];
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
for (const child of Object.values(node))
|
|
372
|
+
visit(child);
|
|
373
|
+
};
|
|
374
|
+
visit(value);
|
|
375
|
+
return { removed, summaries };
|
|
376
|
+
}
|
|
377
|
+
export function ensureFoundryTraceNamespaces(value) {
|
|
378
|
+
let added = 0;
|
|
379
|
+
const visit = (node) => {
|
|
380
|
+
if (!node || typeof node !== "object")
|
|
381
|
+
return;
|
|
382
|
+
if (Array.isArray(node)) {
|
|
383
|
+
for (const item of node)
|
|
384
|
+
visit(item);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (!isRecord(node))
|
|
388
|
+
return;
|
|
389
|
+
const commonOther = node["common:other"];
|
|
390
|
+
if (isRecord(commonOther)) {
|
|
391
|
+
const hasFoundryExtension = Object.keys(commonOther).some((key) => key.startsWith("tiangongfoundry:"));
|
|
392
|
+
if (hasFoundryExtension && !Object.hasOwn(commonOther, "@xmlns:tiangongfoundry")) {
|
|
393
|
+
commonOther["@xmlns:tiangongfoundry"] = foundryTraceNamespace;
|
|
394
|
+
added += 1;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
for (const child of Object.values(node))
|
|
398
|
+
visit(child);
|
|
399
|
+
};
|
|
400
|
+
visit(value);
|
|
401
|
+
return added;
|
|
402
|
+
}
|
|
403
|
+
function containsLocalSourceLocator(value) {
|
|
404
|
+
const text = asText(value);
|
|
405
|
+
return Boolean(text &&
|
|
406
|
+
/(?:^|["'\s])(?:\/Users\/|\/Volumes\/|\/private\/|\/tmp\/|file:\/\/|[A-Za-z]:\\)|\.zip:|LCI ecoSpold version2 Files/iu.test(text));
|
|
407
|
+
}
|
|
408
|
+
function sanitizeTraceEvidenceValue(value, stats) {
|
|
409
|
+
if (!value || typeof value !== "object")
|
|
410
|
+
return;
|
|
411
|
+
if (Array.isArray(value)) {
|
|
412
|
+
for (const item of value)
|
|
413
|
+
sanitizeTraceEvidenceValue(item, stats);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (!isRecord(value))
|
|
417
|
+
return;
|
|
418
|
+
for (const [key, child] of Object.entries(value)) {
|
|
419
|
+
if (child && typeof child === "object") {
|
|
420
|
+
sanitizeTraceEvidenceValue(child, stats);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (!containsLocalSourceLocator(child))
|
|
424
|
+
continue;
|
|
425
|
+
const hash = sha256Text(String(child));
|
|
426
|
+
if (localSourceLocatorKeys.has(key)) {
|
|
427
|
+
delete value[key];
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
value[key] = `redacted local source locator sha256:${hash}`;
|
|
431
|
+
}
|
|
432
|
+
value.source_locator_sha256 = value.source_locator_sha256 ?? hash;
|
|
433
|
+
value.source_locator_status = value.source_locator_status ?? "redacted_before_remote_write";
|
|
434
|
+
stats.redacted += 1;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
export function sanitizeFoundryTraceEvidenceLocators(value) {
|
|
438
|
+
const stats = { redacted: 0 };
|
|
439
|
+
const visit = (node) => {
|
|
440
|
+
if (!node || typeof node !== "object")
|
|
441
|
+
return;
|
|
442
|
+
if (Array.isArray(node)) {
|
|
443
|
+
for (const item of node)
|
|
444
|
+
visit(item);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (!isRecord(node))
|
|
448
|
+
return;
|
|
449
|
+
const commonOther = node["common:other"];
|
|
450
|
+
if (isRecord(commonOther)) {
|
|
451
|
+
for (const traceKey of foundryTraceKeys) {
|
|
452
|
+
for (const traceEntry of ensureArray(commonOther[traceKey])) {
|
|
453
|
+
if (!traceEntry || typeof traceEntry !== "object" || Array.isArray(traceEntry)) {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const record = traceEntry;
|
|
457
|
+
const evidence = record.evidence ?? record.source_evidence ?? record.sourceEvidence;
|
|
458
|
+
sanitizeTraceEvidenceValue(evidence, stats);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
for (const child of Object.values(node))
|
|
463
|
+
visit(child);
|
|
464
|
+
};
|
|
465
|
+
visit(value);
|
|
466
|
+
return stats.redacted;
|
|
467
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type FullContextAiCompletion } from "./context-inputs.ts";
|
|
2
|
+
import { type DatasetTypeOptions } from "./dataset-types.ts";
|
|
3
|
+
import { type ValidatedTaskAuthorization } from "../../task-authorization.ts";
|
|
4
|
+
interface JsonRecord {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface ProfilesConfig extends JsonRecord {
|
|
8
|
+
schema_version?: unknown;
|
|
9
|
+
default_profile?: unknown;
|
|
10
|
+
profiles?: unknown;
|
|
11
|
+
}
|
|
12
|
+
interface ProfileOptions extends DatasetTypeOptions, JsonRecord {
|
|
13
|
+
profilesFile?: unknown;
|
|
14
|
+
profileDoc?: unknown;
|
|
15
|
+
profileDocs?: unknown;
|
|
16
|
+
waiveQa?: unknown;
|
|
17
|
+
waiveQaCode?: unknown;
|
|
18
|
+
waivedQaCode?: unknown;
|
|
19
|
+
taskAuthorization?: unknown;
|
|
20
|
+
taskAuthorizationBinding?: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface ListProfilesInput {
|
|
23
|
+
repoRoot?: string;
|
|
24
|
+
options?: ProfileOptions;
|
|
25
|
+
}
|
|
26
|
+
export interface NormalizedProfile {
|
|
27
|
+
id: string;
|
|
28
|
+
description: unknown;
|
|
29
|
+
docs: unknown[];
|
|
30
|
+
waivedQaCodesByType: JsonRecord;
|
|
31
|
+
waiverReasons: JsonRecord;
|
|
32
|
+
fullContextAiCompletion: FullContextAiCompletion;
|
|
33
|
+
domainRules: JsonRecord;
|
|
34
|
+
authorization: ValidatedTaskAuthorization | null;
|
|
35
|
+
rulesSha256: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ImportProfilesList {
|
|
38
|
+
schema_version: unknown;
|
|
39
|
+
profiles_file: unknown;
|
|
40
|
+
default_profile: unknown;
|
|
41
|
+
profiles: Record<string, JsonRecord>;
|
|
42
|
+
}
|
|
43
|
+
export declare function normalizeProfile(rawProfile: unknown, profileId: unknown): NormalizedProfile;
|
|
44
|
+
export declare function readProfilesConfig(repoRoot: string, profilesFile?: unknown): ProfilesConfig;
|
|
45
|
+
export declare function profileFor(repoRoot: string, profileId: unknown, options?: ProfileOptions): NormalizedProfile;
|
|
46
|
+
export declare function listImportProfiles({ repoRoot, options, }?: ListProfilesInput): ImportProfilesList;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { normalizeFullContextAiCompletion, } from "./context-inputs.js";
|
|
4
|
+
import { datasetTypeFromOptions, defaultProfilesFile, fallbackProfiles, } from "./dataset-types.js";
|
|
5
|
+
import { ensureArray, optionList, readJsonIfExists, resolveRepoPath } from "./runtime-io.js";
|
|
6
|
+
import { sha256Json } from "../../identity-preflight-proof.js";
|
|
7
|
+
import { taskAuthorizationMatches, } from "../../task-authorization.js";
|
|
8
|
+
export function normalizeProfile(rawProfile, profileId) {
|
|
9
|
+
const profile = (rawProfile && typeof rawProfile === "object" ? rawProfile : {});
|
|
10
|
+
const fullContext = profile.fullContextAiCompletion ?? profile.full_context_ai_completion;
|
|
11
|
+
const scopedRelaxation = fullContext && typeof fullContext === "object" && "scoped_relaxation" in fullContext;
|
|
12
|
+
return {
|
|
13
|
+
id: String(profile.id ?? profileId ?? "generic"),
|
|
14
|
+
description: profile.description ?? "",
|
|
15
|
+
docs: ensureArray(profile.docs),
|
|
16
|
+
// Legacy profile files are readable rule inputs, never executable approval.
|
|
17
|
+
waivedQaCodesByType: {},
|
|
18
|
+
waiverReasons: (profile.waiverReasons ?? profile.waiver_reasons ?? {}),
|
|
19
|
+
fullContextAiCompletion: normalizeFullContextAiCompletion(scopedRelaxation ? { ...fullContext, required: true } : fullContext),
|
|
20
|
+
domainRules: (profile.domain_rules ?? {}),
|
|
21
|
+
authorization: null,
|
|
22
|
+
rulesSha256: sha256Json(rawProfile ?? {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function readProfilesConfig(repoRoot, profilesFile = defaultProfilesFile) {
|
|
26
|
+
const resolved = resolveRepoPath(repoRoot, profilesFile);
|
|
27
|
+
return readJsonIfExists(resolved) ?? fallbackProfiles;
|
|
28
|
+
}
|
|
29
|
+
// part-06.mjs
|
|
30
|
+
export function profileFor(repoRoot, profileId, options = {}) {
|
|
31
|
+
const config = readProfilesConfig(repoRoot, options.profilesFile);
|
|
32
|
+
const requestedId = String(profileId || config.default_profile || "generic")
|
|
33
|
+
.trim()
|
|
34
|
+
.toLowerCase();
|
|
35
|
+
const profiles = (config.profiles ?? {});
|
|
36
|
+
const selected = profiles[requestedId] ?? profiles.generic ?? fallbackProfiles.profiles.generic;
|
|
37
|
+
const profile = normalizeProfile(selected, requestedId);
|
|
38
|
+
const extraDocs = optionList(options.profileDoc ?? options.profileDocs);
|
|
39
|
+
const extraWaivers = optionList(options.waiveQa ?? options.waiveQaCode ?? options.waivedQaCode);
|
|
40
|
+
if (extraWaivers.length > 0)
|
|
41
|
+
datasetTypeFromOptions(options);
|
|
42
|
+
const approval = options.taskAuthorization;
|
|
43
|
+
let authorization = taskAuthorizationMatches(approval, options.taskAuthorizationBinding) &&
|
|
44
|
+
approval.binding.profile_id === profile.id &&
|
|
45
|
+
approval.binding.profile_sha256 === sha256Json(selected)
|
|
46
|
+
? approval
|
|
47
|
+
: null;
|
|
48
|
+
const inputPath = authorization
|
|
49
|
+
? resolveRepoPath(repoRoot, (options.rowsFile || options.input || options.rows))
|
|
50
|
+
: null;
|
|
51
|
+
if (authorization && inputPath) {
|
|
52
|
+
const currentInputSha256 = fs.existsSync(inputPath)
|
|
53
|
+
? createHash("sha256").update(fs.readFileSync(inputPath)).digest("hex")
|
|
54
|
+
: null;
|
|
55
|
+
if (authorization.binding.input_scope_sha256 !== currentInputSha256)
|
|
56
|
+
authorization = null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...profile,
|
|
60
|
+
docs: [...profile.docs, ...extraDocs],
|
|
61
|
+
authorization,
|
|
62
|
+
waivedQaCodesByType: authorization?.qa_waivers.length
|
|
63
|
+
? { process: authorization.qa_waivers.map((waiver) => waiver.code) }
|
|
64
|
+
: {},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function listImportProfiles({ repoRoot, options = {}, } = {}) {
|
|
68
|
+
const config = readProfilesConfig(repoRoot, options.profilesFile);
|
|
69
|
+
const profiles = Object.fromEntries(Object.entries((config.profiles ?? {})).map(([id, profile]) => {
|
|
70
|
+
const normalized = normalizeProfile(profile, id);
|
|
71
|
+
return [
|
|
72
|
+
id,
|
|
73
|
+
{
|
|
74
|
+
id: normalized.id,
|
|
75
|
+
description: normalized.description,
|
|
76
|
+
docs: normalized.docs,
|
|
77
|
+
waived_qa_codes_by_type: normalized.waivedQaCodesByType,
|
|
78
|
+
full_context_ai_completion: normalized.fullContextAiCompletion,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}));
|
|
82
|
+
return {
|
|
83
|
+
schema_version: config.schema_version ?? 1,
|
|
84
|
+
profiles_file: options.profilesFile ?? defaultProfilesFile,
|
|
85
|
+
default_profile: config.default_profile ?? "generic",
|
|
86
|
+
profiles,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
export declare function nowIso(): string;
|
|
3
|
+
export declare function ensureArray<T>(value: T | T[] | null | undefined): T[];
|
|
4
|
+
export declare function readText(filePath: string): string;
|
|
5
|
+
export declare function writeText(filePath: string, text: string | NodeJS.ArrayBufferView): void;
|
|
6
|
+
export declare function writeJsonLines(filePath: string, rows: unknown): void;
|
|
7
|
+
export declare function readJson<T = unknown>(filePath: string): T;
|
|
8
|
+
export declare function readJsonIfExists<T = unknown>(filePath: string): T | null;
|
|
9
|
+
export declare function writeJson(filePath: string, data: unknown): void;
|
|
10
|
+
export declare function fileExists(filePath: fs.PathLike | null | undefined): boolean;
|
|
11
|
+
export declare function directoryExists(filePath: fs.PathLike | null | undefined): boolean;
|
|
12
|
+
export declare function resolveRepoPath(repoRoot: string, filePath: string | null | undefined): string | null;
|
|
13
|
+
export declare function repoRelativePath(repoRoot: string, filePath: string): string;
|
|
14
|
+
export declare function normalizedArtifactPath(repoRoot: string, value: unknown): string | null;
|
|
15
|
+
export declare function sameArtifactPath(repoRoot: string, left: unknown, right: unknown): boolean;
|
|
16
|
+
export declare function repoRelativeArtifactPath(repoRoot: string, value: unknown): string | null;
|
|
17
|
+
export declare function readJsonOrJsonl(filePath: string, reader?: (filePath: string) => string): unknown;
|
|
18
|
+
export declare function readRows(filePath: string, reader?: (filePath: string) => string): unknown[];
|
|
19
|
+
export declare function optionList(value: unknown): string[];
|
|
20
|
+
export declare function jsonLines(rows: unknown[]): string;
|
|
21
|
+
export declare function unique<T>(values: T | T[] | null | undefined): T[];
|
|
22
|
+
export declare function sanitizeFileName(value: unknown): string;
|
|
23
|
+
export declare function asText(value: unknown): string;
|