@tiangong-lca/foundry 0.1.18 → 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/docs/package-distribution-contract.md +5 -5
- package/docs/public-runtime-contract.md +12 -0
- package/docs/runtime-context-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +268 -98
- package/package-dist/scripts/foundry-facade.js +3 -0
- package/package-dist/scripts/foundry-runtime.d.ts +1 -1
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- 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 +9 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -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-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 +24 -2
- 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 +68 -2
- package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
- 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 +2 -2
- package/package-dist/scripts/lib/foundry-package-contract.js +2 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
- 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-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 +19 -1
- 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-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-workflow-assessment.js +67 -29
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
- package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
- package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
- package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
- package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
- 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 +41 -21
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package.json +2 -2
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -15,6 +15,8 @@ import { createFoundryExecutionCapsule } from "./foundry-execution-admission.js"
|
|
|
15
15
|
import { registerWorkflowStageFiles } from "./foundry-workflow-io.js";
|
|
16
16
|
import { createFoundryCommandSpec, createFileArtifactFact } from "./foundry-command-spec.js";
|
|
17
17
|
import { parseFoundryCommandSpec } from "@tiangong-lca/cli/command-spec";
|
|
18
|
+
import { buildEdgeSupportPlan, isFoundryEdgeDraftType } from "./foundry-edge-support-plan.js";
|
|
19
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
18
20
|
import { readNativeDraftHandoff } from "./finalize-owners/native-draft-handoff.js";
|
|
19
21
|
import { foundryRepairSelection, readFoundryRepairPreparation } from "./foundry-workflow-repair.js";
|
|
20
22
|
import { createFoundryRepairHandoffPlan } from "./foundry-repair-handoff.js";
|
|
@@ -293,8 +295,34 @@ export async function recordFoundryWorkflowAuthorization(context, qualified, ide
|
|
|
293
295
|
: {}),
|
|
294
296
|
}));
|
|
295
297
|
handoff = bindHandoffCommands(context, handoff, inputFile);
|
|
298
|
+
const commands = workflowObject(handoff.commands);
|
|
299
|
+
const edgeType = request.datasetType;
|
|
300
|
+
if (commands.commit &&
|
|
301
|
+
qualified.cli.expectation.package_version === "0.4.0" &&
|
|
302
|
+
isFoundryEdgeDraftType(edgeType)) {
|
|
303
|
+
const finalizePath = resolveFoundryOutput(context, path.resolve(context.assetRoot, String(scope.report)));
|
|
304
|
+
const finalized = workflowObject(JSON.parse(readFoundryInput(context, finalizePath).toString("utf8")));
|
|
305
|
+
const verifyPath = resolveFoundryOutput(context, path.resolve(context.assetRoot, String(workflowObject(finalized.files).remote_verify_report)));
|
|
306
|
+
const referenceEvidence = {
|
|
307
|
+
fact: captureFoundryInput(verifyPath),
|
|
308
|
+
report: JSON.parse(readFoundryInput(context, verifyPath).toString("utf8")),
|
|
309
|
+
};
|
|
310
|
+
commands.commit = buildEdgeSupportPlan(edgeType, captureFoundryInput(inputFile), {
|
|
311
|
+
project_ref: context.accountIntent.projectRef,
|
|
312
|
+
user_id: context.accountIntent.userId,
|
|
313
|
+
}, readRows(inputFile, (file) => readFoundryInput(context, file).toString("utf8")), referenceEvidence, undefined, request.executionContract && captureFoundryInput(request.executionContract.path));
|
|
314
|
+
commands.post_write_verify = null;
|
|
315
|
+
handoff.account_write_guard = {
|
|
316
|
+
...workflowObject(handoff.account_write_guard),
|
|
317
|
+
execution_precondition: "Foundry must seal the exact Edge create plan for the verified owner.",
|
|
318
|
+
};
|
|
319
|
+
handoff.policy = {
|
|
320
|
+
...workflowObject(handoff.policy),
|
|
321
|
+
commit_boundary: "The owner submits the sealed Edge create plan and verifies the exact draft and dependencies.",
|
|
322
|
+
};
|
|
323
|
+
}
|
|
296
324
|
fs.writeFileSync(path.join(output, "handoff", "dataset-commit-handoff-plan.json"), JSON.stringify(handoff, null, 2) + "\n");
|
|
297
|
-
const command =
|
|
325
|
+
const command = commands.commit;
|
|
298
326
|
if (command) {
|
|
299
327
|
const requiredActions = authorization.allowed_actions.filter((action) => request.datasetType === "flow"
|
|
300
328
|
? action === "elementary_flow_write" || action === "elementary_flow_create_new"
|
|
@@ -334,6 +362,59 @@ export async function recordFoundryWorkflowAuthorization(context, qualified, ide
|
|
|
334
362
|
contractFile: request.executionContract.path,
|
|
335
363
|
outDir: handoffDir,
|
|
336
364
|
}), inputFile);
|
|
365
|
+
if (qualified.cli.expectation.package_version === "0.4.0") {
|
|
366
|
+
const contract = captureFoundryInput(request.executionContract.path);
|
|
367
|
+
const preparation = captureFoundryInput(request.repairPreparation.path);
|
|
368
|
+
readFoundryInput(context, preparation.path);
|
|
369
|
+
const before = captureFoundryInput(resolveFoundryInputPath(context, foundryRepairSelection(context).before));
|
|
370
|
+
const read = (file) => readFoundryInput(context, file).toString("utf8");
|
|
371
|
+
const preparedEvidence = workflowObject(workflowObject(JSON.parse(read(preparation.path))).evidence);
|
|
372
|
+
const preflight = Array.isArray(preparedEvidence.detail)
|
|
373
|
+
? preparedEvidence.detail
|
|
374
|
+
.map(workflowObject)
|
|
375
|
+
.find((item) => item.role === "edge_preflight")
|
|
376
|
+
: undefined;
|
|
377
|
+
const ruleVerification = workflowObject(workflowObject(preflight?.report ?? {}).rule_verification ?? {});
|
|
378
|
+
const dependencyFact = Array.isArray(preparedEvidence.files)
|
|
379
|
+
? preparedEvidence.files
|
|
380
|
+
.map(workflowObject)
|
|
381
|
+
.find((file) => file.role === "edge-repair:out/references/edge-support-precommit.json")
|
|
382
|
+
: undefined;
|
|
383
|
+
if (typeof dependencyFact?.path !== "string")
|
|
384
|
+
throw new FoundryContextError("repair_edge_scope_changed", "Guarded update requires the exact dependency report registered during preparation.");
|
|
385
|
+
const dependencies = resolveFoundryOutput(context, dependencyFact.path);
|
|
386
|
+
const dependencyFile = captureFoundryInput(dependencies);
|
|
387
|
+
if (dependencyFile.sha256 !== dependencyFact.sha256 ||
|
|
388
|
+
dependencyFile.bytes !== dependencyFact.bytes)
|
|
389
|
+
throw new FoundryContextError("repair_edge_scope_changed", "The registered dependency report changed after preparation.");
|
|
390
|
+
const commands = workflowObject(handoff.commands);
|
|
391
|
+
commands.commit = buildEdgeSupportPlan("process", captureFoundryInput(inputFile), {
|
|
392
|
+
project_ref: context.accountIntent.projectRef,
|
|
393
|
+
user_id: context.accountIntent.userId,
|
|
394
|
+
}, readRows(inputFile, read), {
|
|
395
|
+
fact: dependencyFile,
|
|
396
|
+
report: JSON.parse(read(dependencies)),
|
|
397
|
+
}, {
|
|
398
|
+
binding: {
|
|
399
|
+
before,
|
|
400
|
+
contract,
|
|
401
|
+
preparation,
|
|
402
|
+
rule_verification: ruleVerification,
|
|
403
|
+
},
|
|
404
|
+
rows: readRows(before.path, read),
|
|
405
|
+
});
|
|
406
|
+
commands.post_write_verify = null;
|
|
407
|
+
handoff.account_write_guard = {
|
|
408
|
+
target_user_id: context.accountIntent.userId,
|
|
409
|
+
commit_account_binding: "sealed_guarded_edge_update",
|
|
410
|
+
execution_precondition: "Compare the exact reviewed before document inside the Edge save-draft transaction.",
|
|
411
|
+
};
|
|
412
|
+
handoff.policy = {
|
|
413
|
+
commit_boundary: "The sealed owner attempt sends one guarded update and recovers exclusively through exact readback.",
|
|
414
|
+
post_write_verify_required: true,
|
|
415
|
+
compare_root_payload_required: true,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
337
418
|
fs.writeFileSync(path.join(handoffDir, "dataset-commit-handoff-plan.json"), JSON.stringify(handoff, null, 2) + "\n");
|
|
338
419
|
const command = workflowObject(handoff.commands).commit;
|
|
339
420
|
if (command) {
|
|
@@ -3,13 +3,14 @@ import path from "node:path";
|
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
4
|
import { FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
5
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
6
|
-
import {
|
|
6
|
+
import { withFoundryIsolatedLocalCliEnvironment } from "./foundry-runtime-environment.js";
|
|
7
7
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
8
|
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
9
9
|
import { supportedDatasetTypes } from "./import-curation/internal/dataset-types.js";
|
|
10
10
|
import { bindWorkflowChildExecution, workflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
11
11
|
import { createWorkflowDirectory } from "./foundry-workflow-io.js";
|
|
12
12
|
import { readFoundryTaskRuntimeAdoption } from "./foundry-task-runtime-adoption.js";
|
|
13
|
+
import { createTypedContextCommand, projectTypedContext } from "./foundry-typed-context.js";
|
|
13
14
|
export async function prepareFoundryWorkflowContext(context, qualified, selectedTypes) {
|
|
14
15
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
15
16
|
if (!selectedTypes.length || selectedTypes.some((type) => !supportedDatasetTypes.has(type)))
|
|
@@ -17,12 +18,13 @@ export async function prepareFoundryWorkflowContext(context, qualified, selected
|
|
|
17
18
|
const types = [
|
|
18
19
|
...new Set(selectedTypes.flatMap((type) => type === "support" ? ["contact", "source", "flowproperty", "unitgroup"] : [type])),
|
|
19
20
|
].sort();
|
|
21
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
20
22
|
const adoption = readFoundryTaskRuntimeAdoption(context);
|
|
21
23
|
return runFoundryTaskOperation(context, {
|
|
22
24
|
command: "dataset-context-pack",
|
|
23
25
|
options: {
|
|
24
26
|
types,
|
|
25
|
-
profile: "ai-import",
|
|
27
|
+
profile: typed ? "default" : "ai-import",
|
|
26
28
|
...(adoption ? { runtime_adoption_plan_sha256: adoption.plan_sha256 } : {}),
|
|
27
29
|
},
|
|
28
30
|
}, (operation) => {
|
|
@@ -39,31 +41,37 @@ export async function prepareFoundryWorkflowContext(context, qualified, selected
|
|
|
39
41
|
const temporary = createWorkflowDirectory(context, path.join(context.tempRoot, "context-"));
|
|
40
42
|
try {
|
|
41
43
|
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
42
|
-
const environment = createFoundryIsolatedChildEnvironment({ tempRoot: temporary });
|
|
43
44
|
const reports = [];
|
|
44
45
|
for (const type of types) {
|
|
45
46
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
46
47
|
const destination = path.join(output, type);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
const outputDirectory = path.join(destination, "outputs");
|
|
49
|
+
const reportPath = path.join(outputDirectory, "contract-report.json");
|
|
50
|
+
const resultPath = path.join(outputDirectory, "contract-result.json");
|
|
51
|
+
if (typed)
|
|
52
|
+
fs.mkdirSync(outputDirectory, { recursive: true, mode: 0o700 });
|
|
53
|
+
const argv = typed
|
|
54
|
+
? createTypedContextCommand(type, resultPath)
|
|
55
|
+
: [
|
|
56
|
+
"dataset",
|
|
57
|
+
"context-pack",
|
|
58
|
+
"--type",
|
|
59
|
+
type,
|
|
60
|
+
"--profile",
|
|
61
|
+
"ai-import",
|
|
62
|
+
"--out-dir",
|
|
63
|
+
destination,
|
|
64
|
+
"--json",
|
|
65
|
+
];
|
|
58
66
|
const execution = bindWorkflowChildExecution(context, qualified, cli.binPath, argv);
|
|
59
|
-
const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
67
|
+
const child = withFoundryIsolatedLocalCliEnvironment(temporary, (env) => spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
60
68
|
cwd: context.workspaceRoot,
|
|
61
|
-
env
|
|
69
|
+
env,
|
|
62
70
|
encoding: "utf8",
|
|
63
71
|
shell: false,
|
|
64
72
|
maxBuffer: 8 * 1024 * 1024,
|
|
65
73
|
timeout: 120_000,
|
|
66
|
-
});
|
|
74
|
+
}));
|
|
67
75
|
const kind = child.error
|
|
68
76
|
? "spawn_error"
|
|
69
77
|
: child.signal
|
|
@@ -90,7 +98,40 @@ export async function prepareFoundryWorkflowContext(context, qualified, selected
|
|
|
90
98
|
!("status" in value) ||
|
|
91
99
|
value.status !== "completed")
|
|
92
100
|
throw workflowChildFailure(execution, child, "invalid_report");
|
|
93
|
-
|
|
101
|
+
if (typed) {
|
|
102
|
+
let projected;
|
|
103
|
+
try {
|
|
104
|
+
projected = projectTypedContext(type, resultPath, value, fs.readFileSync(resultPath));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw workflowChildFailure(execution, child, "invalid_report", error);
|
|
108
|
+
}
|
|
109
|
+
const manifestPath = path.join(outputDirectory, "contract-manifest.json");
|
|
110
|
+
const files = {
|
|
111
|
+
manifest: manifestPath,
|
|
112
|
+
result: resultPath,
|
|
113
|
+
report: reportPath,
|
|
114
|
+
};
|
|
115
|
+
for (const { key, name, text } of projected.files) {
|
|
116
|
+
const file = path.join(outputDirectory, name);
|
|
117
|
+
fs.writeFileSync(file, text, { flag: "wx", mode: 0o600 });
|
|
118
|
+
files[key] = file;
|
|
119
|
+
}
|
|
120
|
+
fs.writeFileSync(manifestPath, JSON.stringify(projected.manifest, null, 2), {
|
|
121
|
+
flag: "wx",
|
|
122
|
+
mode: 0o600,
|
|
123
|
+
});
|
|
124
|
+
fs.writeFileSync(reportPath, JSON.stringify({
|
|
125
|
+
schema_version: 1,
|
|
126
|
+
status: "completed",
|
|
127
|
+
type,
|
|
128
|
+
profile: projected.profile,
|
|
129
|
+
source: projected.source,
|
|
130
|
+
manifest: projected.manifest,
|
|
131
|
+
files,
|
|
132
|
+
}), { flag: "wx", mode: 0o600 });
|
|
133
|
+
}
|
|
134
|
+
reports.push({ type, report: reportPath });
|
|
94
135
|
}
|
|
95
136
|
const files = [];
|
|
96
137
|
const register = (directory) => {
|
|
@@ -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
|
}
|
|
@@ -7,6 +7,8 @@ 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
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";
|
|
10
12
|
import { createFoundryFinalizeOwners } from "./foundry-finalize-owners.js";
|
|
11
13
|
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
12
14
|
import { runFoundryTaskOperation, withFoundryTaskMetadata } from "./foundry-task-store.js";
|
|
@@ -139,13 +141,15 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
139
141
|
tidasExecutable,
|
|
140
142
|
receiptFile,
|
|
141
143
|
datasetType: set.type,
|
|
144
|
+
outputRoot: path.join(output, set.type),
|
|
142
145
|
});
|
|
143
146
|
const contract = contracts.get(set.type);
|
|
144
147
|
if (!contract)
|
|
145
148
|
throw new FoundryContextError("workflow_context_required", "Finalization requires the current owner contract pack.");
|
|
146
149
|
const needsIdentity = ["flow", "process"].includes(set.type);
|
|
147
150
|
let identityIndex = state.identity?.value.index;
|
|
148
|
-
|
|
151
|
+
const typed = qualified.cli.expectation.package_version === "0.4.0";
|
|
152
|
+
if (!typed && needsIdentity && typeof identityIndex === "string") {
|
|
149
153
|
const prepared = workflowObject(owners.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
150
154
|
type: set.type,
|
|
151
155
|
rowsFile: set.file,
|
|
@@ -165,7 +169,7 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
165
169
|
throw new FoundryContextError("finalize_identity_inputs_invalid", "Finalization identity index could not preserve dependency evidence.");
|
|
166
170
|
identityIndex = path.resolve(context.assetRoot, mergedFile);
|
|
167
171
|
}
|
|
168
|
-
const
|
|
172
|
+
const finalizeOptions = {
|
|
169
173
|
type: ["unitgroup", "flowproperty"].includes(set.type) ? "support" : set.type,
|
|
170
174
|
rowsFile: set.file,
|
|
171
175
|
...referenceOptions.get(set.type),
|
|
@@ -205,7 +209,27 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
205
209
|
verifyRemote: Boolean(context.accountIntent),
|
|
206
210
|
remoteStateCode: "0",
|
|
207
211
|
remoteRootPolicy: "candidate",
|
|
208
|
-
}
|
|
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);
|
|
209
233
|
const files = workflowObject(result.files);
|
|
210
234
|
sets.push({
|
|
211
235
|
type: set.type,
|