@tiangong-lca/foundry 0.1.17 → 0.1.19
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/README.md +23 -7
- package/docs/architecture.md +15 -3
- package/docs/foundry-task-contracts.md +27 -3
- package/docs/package-distribution-contract.md +45 -13
- package/docs/public-runtime-contract.md +85 -5
- package/docs/runtime-context-contract.md +22 -4
- package/docs/task-authorization-contract.md +15 -3
- package/docs/workspace-migration-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +541 -177
- package/package-dist/scripts/foundry-facade.d.ts +5 -0
- package/package-dist/scripts/foundry-facade.js +261 -16
- package/package-dist/scripts/foundry-runtime.d.ts +2 -2
- package/package-dist/scripts/lib/bundle-sample-utils.d.ts +4 -4
- package/package-dist/scripts/lib/bundle-source-context.d.ts +6 -4
- package/package-dist/scripts/lib/bundle-source-context.js +10 -8
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +18 -6
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +11 -1
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +65 -9
- package/package-dist/scripts/lib/foundry-assessment-producer.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-assessment-producer.js +167 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-command-metadata.js +6 -1
- package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
- package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
- package/package-dist/scripts/lib/foundry-decision-owners.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-decision-owners.js +15 -7
- package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
- package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
- package/package-dist/scripts/lib/foundry-execution-admission.js +28 -3
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +126 -13
- package/package-dist/scripts/lib/foundry-identity-stage-input.d.ts +24 -0
- package/package-dist/scripts/lib/foundry-identity-stage-input.js +122 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.js +48 -0
- package/package-dist/scripts/lib/foundry-installed-entry.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-installed-entry.js +173 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.d.ts +12 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.js +108 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.js +28 -0
- package/package-dist/scripts/lib/foundry-managed-host.js +14 -2
- package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.js +27 -3
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +20 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +10 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +96 -3
- package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
- package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
- package/package-dist/scripts/lib/foundry-quality-review-context.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-quality-review-context.js +18 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.d.ts +48 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.js +284 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.js +123 -0
- package/package-dist/scripts/lib/foundry-quality-review.d.ts +112 -0
- package/package-dist/scripts/lib/foundry-quality-review.js +487 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +22 -2
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-task-authorization.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-task-authorization.js +32 -11
- package/package-dist/scripts/lib/foundry-task-registration.js +4 -5
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.d.ts +28 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.js +250 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.d.ts +60 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.js +549 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +4 -1
- package/package-dist/scripts/lib/foundry-task-store.js +113 -4
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
- package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
- package/package-dist/scripts/lib/foundry-validation-reference-context.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-validation-reference-context.js +115 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +165 -34
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +99 -5
- package/package-dist/scripts/lib/foundry-workflow-child-failure.d.ts +44 -0
- package/package-dist/scripts/lib/foundry-workflow-child-failure.js +439 -0
- package/package-dist/scripts/lib/foundry-workflow-context.js +92 -22
- package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +64 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.js +450 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.d.ts +9 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +717 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +26 -11
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-io.js +102 -16
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +65 -31
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +165 -22
- package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +4 -7
- package/package-dist/scripts/lib/identity-preflight-artifacts.js +18 -5
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +6 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +92 -13
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.d.ts +78 -0
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.js +415 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +9 -1
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -2
- package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.js +19 -1
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +11 -2
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +4 -1
- package/package-dist/scripts/package-entry.js +2 -3
- package/package-dist/scripts/public-api.d.ts +5 -0
- package/package-dist/scripts/public-api.js +2 -0
- package/package-dist/scripts/runtime-entry.d.ts +2 -0
- package/package-dist/scripts/runtime-entry.js +42 -15
- package/package.json +6 -2
- package/specs/schemas/foundry-identity-stage-input.schema.json +47 -0
- package/specs/schemas/foundry-managed-adoption.schema.json +40 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-operation-result.schema.json +1 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +6 -2
- package/specs/schemas/foundry-quality-review-draft.schema.json +271 -0
- package/specs/schemas/foundry-quality-review-input.schema.json +271 -0
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -19,8 +19,14 @@ import { workflowObject } from "./foundry-workflow-state.js";
|
|
|
19
19
|
import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
|
|
20
20
|
import { summarizeSameIdentityCommitFailures } from "./same-identity-commit-recovery.js";
|
|
21
21
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
22
|
+
import { verifySelectedEdgeDraftPlan } from "./foundry-edge-draft-admission.js";
|
|
23
|
+
import { isEdgeSupportPlan } from "./foundry-edge-support-plan.js";
|
|
24
|
+
import { createFoundryEdgeActor } from "./foundry-edge-session.js";
|
|
25
|
+
import { dispatchFoundryEdgeSupport, verifyFoundryEdgeSupport } from "./foundry-edge-support.js";
|
|
26
|
+
import { createFoundryTypedModelDraft } from "./foundry-typed-model-write.js";
|
|
22
27
|
export async function executeFoundryOwnerScope(context, qualified, entries, requested, authentication = { mode: "oauth" }) {
|
|
23
28
|
const request = requested.request;
|
|
29
|
+
const edgePlan = isEdgeSupportPlan(request.content.commit) ? request.content.commit : null;
|
|
24
30
|
if (!entries.some((entry) => entry.path === requested.entry.path && entry.sha256 === requested.entry.sha256))
|
|
25
31
|
throw new FoundryContextError("execution_request_unregistered", "Select a registered owner execution request.");
|
|
26
32
|
const lock = resolveFoundryOutput(context, `owner-locks/${context.taskId}-${request.scope_id}.json`, "state");
|
|
@@ -49,6 +55,7 @@ export async function executeFoundryOwnerScope(context, qualified, entries, requ
|
|
|
49
55
|
throw new FoundryContextError("execution_observation_invalid", "Dispatch observation belongs to another request.");
|
|
50
56
|
let identity = null;
|
|
51
57
|
let admission = null;
|
|
58
|
+
let edgeDispatch = null;
|
|
52
59
|
if (!consumed) {
|
|
53
60
|
identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
54
61
|
admission = await rehydrateFoundryExecutionAdmission(context, qualified, identity, {
|
|
@@ -61,10 +68,22 @@ export async function executeFoundryOwnerScope(context, qualified, entries, requ
|
|
|
61
68
|
await assertFoundryExecutionAdmission(context, qualified, identity, admission);
|
|
62
69
|
if (observation)
|
|
63
70
|
throw new FoundryContextError("execution_observation_invalid", "Existing dispatch evidence cannot be treated as unattempted.");
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
if (edgePlan) {
|
|
72
|
+
const rows = verifySelectedEdgeDraftPlan(context, edgePlan, captureFoundryInput(request.content.input.path), request.policy);
|
|
73
|
+
const actor = await createFoundryEdgeActor(context, qualified, authentication);
|
|
74
|
+
const before = await verifyFoundryEdgeSupport(actor, edgePlan, "before");
|
|
75
|
+
if (before.blockers.length)
|
|
76
|
+
throw new FoundryContextError("edge_support_before_conflict", "The Edge draft identity is already in use or a required dependency cannot be verified.");
|
|
77
|
+
identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
78
|
+
await assertFoundryExecutionAdmission(context, qualified, identity, admission);
|
|
79
|
+
edgeDispatch = { actor, rows, before };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const out = commandSpecOptionValue(request.content.commit, "--out-dir");
|
|
83
|
+
resolveFoundryOutput(context, out);
|
|
84
|
+
if (fs.existsSync(out) && fs.readdirSync(out).length)
|
|
85
|
+
throw new FoundryContextError("execution_output_not_empty", "An unattempted command cannot adopt existing output artifacts.");
|
|
86
|
+
}
|
|
68
87
|
}
|
|
69
88
|
const attemptStore = ownerAttemptStore(context, request.scope_id, {
|
|
70
89
|
path: requested.file,
|
|
@@ -107,6 +126,34 @@ export async function executeFoundryOwnerScope(context, qualified, entries, requ
|
|
|
107
126
|
if (!identity || !admission)
|
|
108
127
|
throw new FoundryContextError("execution_admission_required", "Mutation requires fresh process-local admission.");
|
|
109
128
|
const command = request.content.commit;
|
|
129
|
+
if (isEdgeSupportPlan(command)) {
|
|
130
|
+
if (!edgeDispatch)
|
|
131
|
+
throw new FoundryContextError("execution_admission_required", "Edge creation requires fresh verified draft admission.");
|
|
132
|
+
writeFoundryArtifact(context, path.join(observationDir, "edge-before.json"), JSON.stringify(edgeDispatch.before, null, 2) + "\n");
|
|
133
|
+
let acknowledgements = null;
|
|
134
|
+
const { actor, rows } = edgeDispatch;
|
|
135
|
+
try {
|
|
136
|
+
acknowledgements = await dispatchFoundryEdgeSupport(actor, command, rows, (root, content) => createFoundryTypedModelDraft(context, qualified, authentication, actor.receipt, requested.entry.sha256, root, content));
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// The durable owner attempt was consumed before the first request. A lost
|
|
140
|
+
// response can only be settled by independent exact readback.
|
|
141
|
+
}
|
|
142
|
+
observation = {
|
|
143
|
+
schema: "tiangong-foundry.dispatch-observation.v1",
|
|
144
|
+
request_sha256: requested.entry.sha256,
|
|
145
|
+
disposition: acknowledgements ? "confirmed" : "unknown",
|
|
146
|
+
edge_plan_sha256: command.sha256,
|
|
147
|
+
acknowledgements,
|
|
148
|
+
};
|
|
149
|
+
writeFoundryArtifact(context, observationFile, JSON.stringify(observation, null, 2) + "\n");
|
|
150
|
+
if (!acknowledgements)
|
|
151
|
+
throw new Error("Edge dispatch requires exact readback.");
|
|
152
|
+
const verified = await readback();
|
|
153
|
+
if (!verified)
|
|
154
|
+
throw new Error("Edge drafts are not independently verified.");
|
|
155
|
+
return verified.proof;
|
|
156
|
+
}
|
|
110
157
|
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
|
|
111
158
|
environment.FOUNDRY_VERIFIED_PROJECT_REF = request.policy.project_ref;
|
|
112
159
|
environment.FOUNDRY_VERIFIED_USER_ID = request.policy.user_id;
|
|
@@ -224,7 +271,9 @@ export async function executeFoundryOwnerScope(context, qualified, entries, requ
|
|
|
224
271
|
if (!observationRegistered) {
|
|
225
272
|
if (fs.existsSync(observationDir))
|
|
226
273
|
registerWorkflowStageFiles(context, operation, observationDir);
|
|
227
|
-
const commitDir =
|
|
274
|
+
const commitDir = edgePlan
|
|
275
|
+
? null
|
|
276
|
+
: commandSpecOptionValue(request.content.commit, "--out-dir");
|
|
228
277
|
if (commitDir && fs.existsSync(commitDir))
|
|
229
278
|
registerWorkflowStageFiles(context, operation, commitDir);
|
|
230
279
|
}
|
|
@@ -6,6 +6,9 @@ import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.
|
|
|
6
6
|
import { verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
7
7
|
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
8
8
|
import { createFoundryIsolatedChildEnvironment, copyFoundryIsolatedExecutable, } from "./foundry-runtime-environment.js";
|
|
9
|
+
import { WorkflowChildFailure } from "./foundry-workflow-child-failure.js";
|
|
10
|
+
import { createFoundryIdentityOwners } from "./foundry-identity-owners.js";
|
|
11
|
+
import { refreshFoundryFinalizeIdentity } from "./foundry-finalize-edge-identity.js";
|
|
9
12
|
import { createFoundryFinalizeOwners } from "./foundry-finalize-owners.js";
|
|
10
13
|
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
11
14
|
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
@@ -14,12 +17,14 @@ import { readTaskBytes } from "./foundry-task-io.js";
|
|
|
14
17
|
import { loadFoundryTaskAuthorization } from "./foundry-task-authorization.js";
|
|
15
18
|
import { taskAuthorizationMatches } from "./task-authorization.js";
|
|
16
19
|
import { createHash } from "node:crypto";
|
|
20
|
+
import { loadFoundryQualityReview } from "./foundry-quality-review.js";
|
|
17
21
|
export async function finalizeFoundryWorkflow(context, qualified, entries, authentication = { mode: "oauth" }, approval, executionProgress) {
|
|
18
22
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
19
23
|
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
20
24
|
if (!rows || !state.assessment || !state.assessmentComplete)
|
|
21
25
|
throw new FoundryContextError("workflow_assessment_required", "Assess the current rows before finalization.");
|
|
22
26
|
const referenceOptions = new Map();
|
|
27
|
+
const qualityReview = loadFoundryQualityReview(context, qualified, entries);
|
|
23
28
|
for (const set of rows.value.sets) {
|
|
24
29
|
if (executionProgress?.scopes.has(set.type))
|
|
25
30
|
continue;
|
|
@@ -136,13 +141,15 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
136
141
|
tidasExecutable,
|
|
137
142
|
receiptFile,
|
|
138
143
|
datasetType: set.type,
|
|
144
|
+
outputRoot: path.join(output, set.type),
|
|
139
145
|
});
|
|
140
146
|
const contract = contracts.get(set.type);
|
|
141
147
|
if (!contract)
|
|
142
148
|
throw new FoundryContextError("workflow_context_required", "Finalization requires the current owner contract pack.");
|
|
143
149
|
const needsIdentity = ["flow", "process"].includes(set.type);
|
|
144
150
|
let identityIndex = state.identity?.value.index;
|
|
145
|
-
|
|
151
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
152
|
+
if (!typed && needsIdentity && typeof identityIndex === "string") {
|
|
146
153
|
const prepared = workflowObject(owners.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
147
154
|
type: set.type,
|
|
148
155
|
rowsFile: set.file,
|
|
@@ -162,10 +169,13 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
162
169
|
throw new FoundryContextError("finalize_identity_inputs_invalid", "Finalization identity index could not preserve dependency evidence.");
|
|
163
170
|
identityIndex = path.resolve(context.assetRoot, mergedFile);
|
|
164
171
|
}
|
|
165
|
-
const
|
|
172
|
+
const finalizeOptions = {
|
|
166
173
|
type: ["unitgroup", "flowproperty"].includes(set.type) ? "support" : set.type,
|
|
167
174
|
rowsFile: set.file,
|
|
168
175
|
...referenceOptions.get(set.type),
|
|
176
|
+
...(set.type === "process" && qualityReview
|
|
177
|
+
? { qualityReview, qaReferenceRows: [...qualityReview.qaReferenceRows] }
|
|
178
|
+
: {}),
|
|
169
179
|
outDir: path.join(output, set.type),
|
|
170
180
|
profile,
|
|
171
181
|
...(approval?.datasetType === set.type && authorization
|
|
@@ -199,7 +209,27 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
199
209
|
verifyRemote: Boolean(context.accountIntent),
|
|
200
210
|
remoteStateCode: "0",
|
|
201
211
|
remoteRootPolicy: "candidate",
|
|
202
|
-
}
|
|
212
|
+
};
|
|
213
|
+
const stages = owners.finalize.finalizeStages(finalizeOptions, typed);
|
|
214
|
+
let finished = owners.invoke(() => stages.next());
|
|
215
|
+
if (!finished.done) {
|
|
216
|
+
if ((set.type !== "flow" && set.type !== "process") || typeof identityIndex !== "string")
|
|
217
|
+
throw new FoundryContextError("finalize_identity_inputs_invalid", "Finalization requires a selected Flow or Process identity index.");
|
|
218
|
+
const identityOwner = createFoundryIdentityOwners(context, qualified, set.type, {
|
|
219
|
+
environment,
|
|
220
|
+
cwd: temporary,
|
|
221
|
+
});
|
|
222
|
+
const refreshed = await refreshFoundryFinalizeIdentity(context, qualified, authentication, identityOwner, {
|
|
223
|
+
type: set.type,
|
|
224
|
+
rowsFile: finished.value.rowsFile,
|
|
225
|
+
outDir: finished.value.outDir,
|
|
226
|
+
index: identityIndex,
|
|
227
|
+
});
|
|
228
|
+
finished = owners.invoke(() => stages.next(refreshed));
|
|
229
|
+
}
|
|
230
|
+
if (!finished.done)
|
|
231
|
+
throw new FoundryContextError("finalize_identity_inputs_invalid", "Unexpected additional identity stage.");
|
|
232
|
+
const result = workflowObject(finished.value);
|
|
203
233
|
const files = workflowObject(result.files);
|
|
204
234
|
sets.push({
|
|
205
235
|
type: set.type,
|
|
@@ -261,11 +291,17 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
261
291
|
options: {
|
|
262
292
|
nonce,
|
|
263
293
|
rows_report: rows.file,
|
|
294
|
+
...(state.qualityReviewSha256
|
|
295
|
+
? { quality_review_sha256: state.qualityReviewSha256 }
|
|
296
|
+
: {}),
|
|
264
297
|
...(state.referenceInputsSha256
|
|
265
298
|
? { reference_inputs_sha256: state.referenceInputsSha256 }
|
|
266
299
|
: {}),
|
|
267
300
|
},
|
|
268
301
|
validateCurrent(index) {
|
|
302
|
+
if (currentWorkflowState(context, index).qualityReviewSha256 !== state.qualityReviewSha256)
|
|
303
|
+
throw new FoundryContextError("quality_review_changed", "Quality review changed during finalization.");
|
|
304
|
+
qualityReview?.validate();
|
|
269
305
|
const current = currentWorkflowState(context, index);
|
|
270
306
|
if (current.rows?.entry.sha256 !== rows.entry.sha256)
|
|
271
307
|
throw new FoundryContextError("workflow_rows_changed", "Rows changed during finalization.");
|
|
@@ -291,6 +327,9 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
291
327
|
? { reference_inputs_sha256: state.referenceInputsSha256 }
|
|
292
328
|
: {}),
|
|
293
329
|
assessment_report: state.assessment.file,
|
|
330
|
+
...(state.qualityReviewSha256
|
|
331
|
+
? { quality_review_sha256: state.qualityReviewSha256 }
|
|
332
|
+
: {}),
|
|
294
333
|
owner_base: context.assetRoot,
|
|
295
334
|
approval_source_sha256: approval?.sourceSha256 ?? null,
|
|
296
335
|
approval_authorization_sha256: approval?.authorizationSha256 ?? null,
|
|
@@ -302,6 +341,28 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
302
341
|
return result;
|
|
303
342
|
});
|
|
304
343
|
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
if (!(error instanceof WorkflowChildFailure))
|
|
346
|
+
throw error;
|
|
347
|
+
// The read/local call already occurred outside the replayable transaction. Register only
|
|
348
|
+
// its actual captured failure; the callback cannot dispatch or reconstruct an earlier call.
|
|
349
|
+
return await runFoundryTaskOperation(context, {
|
|
350
|
+
command: "dataset-workflow-finalize",
|
|
351
|
+
options: {
|
|
352
|
+
nonce,
|
|
353
|
+
rows_report: rows.file,
|
|
354
|
+
failure_execution_id: error.evidence.execution_id,
|
|
355
|
+
...(state.qualityReviewSha256
|
|
356
|
+
? { quality_review_sha256: state.qualityReviewSha256 }
|
|
357
|
+
: {}),
|
|
358
|
+
...(state.referenceInputsSha256
|
|
359
|
+
? { reference_inputs_sha256: state.referenceInputsSha256 }
|
|
360
|
+
: {}),
|
|
361
|
+
},
|
|
362
|
+
}, () => {
|
|
363
|
+
throw error;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
305
366
|
finally {
|
|
306
367
|
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
307
368
|
fs.rmSync(temporary, { recursive: true, force: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type AuthIdentityReceipt } from "./identity-preflight-proof.ts";
|
|
4
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
5
|
+
/** A new local interpretation, retaining the original failed attempts and their query/auth facts. */
|
|
6
|
+
export declare function recoverFoundryWorkflowIdentity(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], currentAuth: AuthIdentityReceipt): Promise<Record<string, unknown> | null>;
|