@tiangong-lca/foundry 0.1.17 → 0.1.18
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 +73 -5
- package/docs/runtime-context-contract.md +20 -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 +333 -139
- package/package-dist/scripts/foundry-facade.d.ts +5 -0
- package/package-dist/scripts/foundry-facade.js +258 -16
- package/package-dist/scripts/foundry-runtime.d.ts +1 -1
- 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 +16 -6
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +2 -1
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +28 -1
- 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-command-metadata.js +6 -1
- 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-execution-admission.js +4 -1
- package/package-dist/scripts/lib/foundry-finalize-owners.js +64 -17
- 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-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 +25 -3
- 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-runtime-identity.js +3 -1
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- 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-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 +115 -22
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +17 -4
- 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 +37 -8
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +37 -0
- 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 +676 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +10 -1
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-io.js +76 -11
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +27 -13
- 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 +5 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +73 -1
- 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
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { migrationCredentialPath } from "./foundry-private-path.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { assertCliRuntimeMatches } from "@tiangong-lca/cli/runtime";
|
|
5
|
+
import { resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
|
+
import { bytes, digest, exact, fail, facts, object, readTaskBytes } from "./foundry-task-io.js";
|
|
7
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
8
|
+
import { transferRead } from "./foundry-migration-transfer-io.js";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import { transferFileContentFact, transferFileFact, transferPath, } from "./foundry-migration-transfer-io.js";
|
|
11
|
+
const trustedQualifications = new WeakSet();
|
|
12
|
+
/** The independent host supplies the expected digest; task input cannot grant compatibility. */
|
|
13
|
+
export function createFoundryRuntimeAdoptionQualification(input) {
|
|
14
|
+
const data = Buffer.from(input.bytes);
|
|
15
|
+
if (data.length > 8 * 1024 * 1024 ||
|
|
16
|
+
!/^[0-9a-f]{64}$/u.test(input.expectedSha256) ||
|
|
17
|
+
digest(data) !== input.expectedSha256)
|
|
18
|
+
fail("runtime_adoption_qualification_untrusted", "Qualification must match the host's independently reviewed digest.");
|
|
19
|
+
const value = object(JSON.parse(data.toString("utf8")));
|
|
20
|
+
qualificationShape(value);
|
|
21
|
+
const result = Object.freeze({ sha256: sha256Json(value), value: deepFreeze(value) });
|
|
22
|
+
trustedQualifications.add(result);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
function deepFreeze(value) {
|
|
26
|
+
if (value && typeof value === "object") {
|
|
27
|
+
Object.values(value).forEach(deepFreeze);
|
|
28
|
+
Object.freeze(value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export function assertTrustedQualification(selection, trusted) {
|
|
33
|
+
if (!trusted ||
|
|
34
|
+
!trustedQualifications.has(trusted) ||
|
|
35
|
+
sha256Json(object(selection).qualification) !== trusted.sha256)
|
|
36
|
+
fail("runtime_adoption_qualification_untrusted", "Plan/apply require an independently selected host qualification; ordinary input is not authority.");
|
|
37
|
+
}
|
|
38
|
+
export function verifyEvidence(value) {
|
|
39
|
+
const selected = facts(value);
|
|
40
|
+
if (!selected.length || selected.length > 64)
|
|
41
|
+
fail("runtime_adoption_evidence_invalid", "Select bounded nonempty qualification evidence.");
|
|
42
|
+
for (const fact of selected) {
|
|
43
|
+
if (!path.isAbsolute(fact.path) || migrationCredentialPath(fact.path))
|
|
44
|
+
fail("runtime_adoption_evidence_invalid", "Evidence must name absolute regular files.");
|
|
45
|
+
const content = transferRead(fact.path, 512 * 1024 * 1024);
|
|
46
|
+
if (content.length !== fact.bytes || digest(content) !== fact.sha256)
|
|
47
|
+
fail("runtime_adoption_evidence_changed", "Adoption evidence or retained input changed.");
|
|
48
|
+
}
|
|
49
|
+
return selected;
|
|
50
|
+
}
|
|
51
|
+
function qualificationShape(value) {
|
|
52
|
+
exact(value, [
|
|
53
|
+
"schema",
|
|
54
|
+
"original_runtime",
|
|
55
|
+
"successor_runtime",
|
|
56
|
+
"original_manifest_sha256",
|
|
57
|
+
"successor_manifest_sha256",
|
|
58
|
+
"original_cli",
|
|
59
|
+
"successor_cli",
|
|
60
|
+
"tidas",
|
|
61
|
+
"reviewer",
|
|
62
|
+
"evidence",
|
|
63
|
+
"allowed_changes",
|
|
64
|
+
"runtime_manifests",
|
|
65
|
+
"original_descriptor_sha256",
|
|
66
|
+
"successor_descriptor_sha256",
|
|
67
|
+
]);
|
|
68
|
+
if (value.schema !== "tiangong-foundry.runtime-adoption-qualification.v1" ||
|
|
69
|
+
typeof value.reviewer !== "string" ||
|
|
70
|
+
!value.reviewer.trim() ||
|
|
71
|
+
JSON.stringify(value.allowed_changes) !== '["foundry","cli"]' ||
|
|
72
|
+
![value.original_manifest_sha256, value.successor_manifest_sha256].every((item) => typeof item === "string" && /^[0-9a-f]{64}$/u.test(item)))
|
|
73
|
+
fail("runtime_adoption_qualification_invalid", "Require reviewed exact manifests and only the qualified Foundry/CLI change.");
|
|
74
|
+
}
|
|
75
|
+
function validateAdoptionQualification(context, selection, originalEntry, successor, historical = false) {
|
|
76
|
+
const value = object(selection.qualification);
|
|
77
|
+
qualificationShape(value);
|
|
78
|
+
if (sha256Json(value.original_runtime) !== sha256Json(selection.original_runtime) ||
|
|
79
|
+
sha256Json(value.successor_runtime) !== sha256Json(successor.identity) ||
|
|
80
|
+
(!historical && context.workspaceManifestSha256 !== value.successor_manifest_sha256))
|
|
81
|
+
fail("runtime_adoption_qualification_mismatch", "Compatibility must bind the original identity and independently selected executing manifest.");
|
|
82
|
+
const originalDescriptor = facts([selection.original_descriptor])[0];
|
|
83
|
+
if ((!historical &&
|
|
84
|
+
context.runtime.entryRepoRelativePath !== "package-dist/scripts/package-entry.js") ||
|
|
85
|
+
originalDescriptor.sha256 !== value.original_descriptor_sha256 ||
|
|
86
|
+
successor.descriptor.sha256 !== value.successor_descriptor_sha256)
|
|
87
|
+
fail("runtime_adoption_qualification_mismatch", "Adoption requires the independently qualified complete old/new installed package inventories.");
|
|
88
|
+
verifyEvidence(value.evidence);
|
|
89
|
+
const manifests = verifyEvidence(value.runtime_manifests);
|
|
90
|
+
if (manifests.length !== 2 ||
|
|
91
|
+
manifests[0].sha256 !== value.original_manifest_sha256 ||
|
|
92
|
+
manifests[1].sha256 !== value.successor_manifest_sha256)
|
|
93
|
+
fail("runtime_adoption_qualification_mismatch", "Retained product manifests differ from the qualified pair.");
|
|
94
|
+
const oldCli = object(value.original_cli), newCli = object(value.successor_cli);
|
|
95
|
+
exact(oldCli, ["expectation", "files"]);
|
|
96
|
+
exact(newCli, ["expectation", "files"]);
|
|
97
|
+
if (!historical) {
|
|
98
|
+
const current = assertCliRuntimeMatches(newCli.expectation);
|
|
99
|
+
if (sha256Json(current.files) !== sha256Json(newCli.files))
|
|
100
|
+
fail("runtime_adoption_dependency_changed", "Successor CLI inventory differs from the qualified exact combination.");
|
|
101
|
+
}
|
|
102
|
+
const oldExpectation = object(oldCli.expectation), newExpectation = object(newCli.expectation);
|
|
103
|
+
exact(oldExpectation, [
|
|
104
|
+
"schema",
|
|
105
|
+
"package_version",
|
|
106
|
+
"platform",
|
|
107
|
+
"content_sha256",
|
|
108
|
+
"node_version",
|
|
109
|
+
"node_sha256",
|
|
110
|
+
]);
|
|
111
|
+
if (oldExpectation.schema !== "tiangong-lca.cli-runtime-expectation.v1" ||
|
|
112
|
+
oldExpectation.node_version !== newExpectation.node_version ||
|
|
113
|
+
oldExpectation.node_sha256 !== newExpectation.node_sha256 ||
|
|
114
|
+
oldExpectation.platform !== newExpectation.platform)
|
|
115
|
+
fail("runtime_adoption_dependency_changed", "Node and platform must remain unchanged in this compatibility protocol.");
|
|
116
|
+
verifyRetainedCli(originalEntry, oldCli);
|
|
117
|
+
verifyRetainedCli(successor.entry.path, newCli);
|
|
118
|
+
const tidas = verifyEvidence(value.tidas);
|
|
119
|
+
if (tidas.length !== 2 ||
|
|
120
|
+
tidas[0].sha256 !== tidas[1].sha256 ||
|
|
121
|
+
tidas[0].bytes !== tidas[1].bytes)
|
|
122
|
+
fail("runtime_adoption_dependency_changed", "Original and successor Toolkit must retain identical executable bytes.");
|
|
123
|
+
}
|
|
124
|
+
function verifyRetainedCli(entry, claim) {
|
|
125
|
+
const expectation = object(claim.expectation);
|
|
126
|
+
exact(expectation, [
|
|
127
|
+
"schema",
|
|
128
|
+
"package_version",
|
|
129
|
+
"platform",
|
|
130
|
+
"content_sha256",
|
|
131
|
+
"node_version",
|
|
132
|
+
"node_sha256",
|
|
133
|
+
]);
|
|
134
|
+
if (expectation.schema !== "tiangong-lca.cli-runtime-expectation.v1" ||
|
|
135
|
+
typeof expectation.package_version !== "string" ||
|
|
136
|
+
typeof expectation.platform !== "string" ||
|
|
137
|
+
typeof expectation.node_version !== "string" ||
|
|
138
|
+
![expectation.node_sha256, expectation.content_sha256].every((value) => typeof value === "string" && /^[0-9a-f]{64}$/u.test(value)))
|
|
139
|
+
fail("runtime_adoption_dependency_changed", "Retained CLI expectation is invalid.");
|
|
140
|
+
const originalCliRoot = (createRequire(entry).resolve.paths("@tiangong-lca/cli") ?? [])
|
|
141
|
+
.map((directory) => path.join(directory, "@tiangong-lca/cli"))
|
|
142
|
+
.find((directory) => fs.existsSync(path.join(directory, "package.json")));
|
|
143
|
+
if (!originalCliRoot)
|
|
144
|
+
fail("runtime_adoption_dependency_changed", "Original CLI dependency is unavailable.");
|
|
145
|
+
const oldRoot = fs.realpathSync(originalCliRoot);
|
|
146
|
+
const oldFiles = facts(claim.files);
|
|
147
|
+
if (!oldFiles.length ||
|
|
148
|
+
oldFiles.length > 10000 ||
|
|
149
|
+
digest(JSON.stringify(oldFiles)) !== expectation.content_sha256)
|
|
150
|
+
fail("runtime_adoption_dependency_changed", "Original CLI inventory does not match its independent expectation.");
|
|
151
|
+
for (const fact of oldFiles) {
|
|
152
|
+
const previous = transferFileContentFact(transferPath(oldRoot, fact.path));
|
|
153
|
+
if (previous.bytes !== fact.bytes || previous.sha256 !== fact.sha256)
|
|
154
|
+
fail("runtime_adoption_dependency_changed", "Original CLI bytes differ from the qualified combination.");
|
|
155
|
+
}
|
|
156
|
+
const oldPackage = object(JSON.parse(transferRead(path.join(oldRoot, "package.json"), 1024 * 1024).toString("utf8")));
|
|
157
|
+
if (oldPackage.name !== "@tiangong-lca/cli" || oldPackage.version !== expectation.package_version)
|
|
158
|
+
fail("runtime_adoption_dependency_changed", "Original CLI version differs from qualification.");
|
|
159
|
+
}
|
|
160
|
+
function retainedRuntime(entryValue, descriptorValue, expected) {
|
|
161
|
+
const entry = verifyEvidence([entryValue])[0], descriptor = verifyEvidence([descriptorValue])[0];
|
|
162
|
+
const root = path.resolve(entry.path, "../../..");
|
|
163
|
+
if (path.relative(root, entry.path).split(path.sep).join("/") !==
|
|
164
|
+
"package-dist/scripts/package-entry.js" ||
|
|
165
|
+
descriptor.path !== path.join(root, "package-dist/assets/foundry-package-descriptor.json"))
|
|
166
|
+
fail("runtime_adoption_original_invalid", "Retained runtime locators must name one complete installed package.");
|
|
167
|
+
const manifest = transferRead(path.join(root, "package.json"), 1024 * 1024);
|
|
168
|
+
const pkg = object(JSON.parse(manifest.toString("utf8")));
|
|
169
|
+
const identity = {
|
|
170
|
+
package_name: pkg.name,
|
|
171
|
+
package_version: pkg.version,
|
|
172
|
+
manifest_sha256: digest(manifest),
|
|
173
|
+
entry_sha256: entry.sha256,
|
|
174
|
+
};
|
|
175
|
+
if (sha256Json(identity) !== sha256Json(expected))
|
|
176
|
+
fail("runtime_adoption_original_invalid", "Retained package identity differs from its qualified transition.");
|
|
177
|
+
const inventory = object(JSON.parse(transferRead(descriptor.path, 8 * 1024 * 1024).toString("utf8")));
|
|
178
|
+
if (inventory.schema !== "tiangong-foundry.package-descriptor.v1" ||
|
|
179
|
+
!Array.isArray(inventory.files) ||
|
|
180
|
+
inventory.files.length > 5000 ||
|
|
181
|
+
inventory.files_sha256 !== sha256Json(inventory.files))
|
|
182
|
+
fail("runtime_adoption_original_invalid", "Retained package inventory changed.");
|
|
183
|
+
for (const fact of facts(inventory.files)) {
|
|
184
|
+
const current = transferFileContentFact(transferPath(root, fact.path));
|
|
185
|
+
if (current.bytes !== fact.bytes || current.sha256 !== fact.sha256)
|
|
186
|
+
fail("runtime_adoption_original_invalid", "Retained package code or assets changed.");
|
|
187
|
+
}
|
|
188
|
+
return { root, identity: identity, entry, descriptor };
|
|
189
|
+
}
|
|
190
|
+
export function currentAdoptionRuntimeFacts(context) {
|
|
191
|
+
return retainedRuntime(transferFileFact(transferPath(context.runtimeRoot, "package-dist/scripts/package-entry.js")), transferFileFact(transferPath(context.runtimeRoot, "package-dist/assets/foundry-package-descriptor.json")), currentAdoptionRuntime(context));
|
|
192
|
+
}
|
|
193
|
+
/** Bind an adopted task's actual selected Toolkit to the independently reviewed executable. */
|
|
194
|
+
export function assertRuntimeAdoptionToolkit(selected, selection) {
|
|
195
|
+
const tidas = verifyEvidence(object(object(selection).qualification).tidas);
|
|
196
|
+
if (!selected ||
|
|
197
|
+
tidas.length !== 2 ||
|
|
198
|
+
fs.realpathSync(selected.tidas.executable_path) !== fs.realpathSync(tidas[1].path) ||
|
|
199
|
+
selected.tidas.expectation.executable.sha256 !== tidas[1].sha256 ||
|
|
200
|
+
selected.tidas.expectation.executable.bytes !== tidas[1].bytes)
|
|
201
|
+
fail("runtime_adoption_dependency_changed", "Select the exact independently qualified successor Toolkit for this adopted task.");
|
|
202
|
+
}
|
|
203
|
+
export const TASK_RUNTIME_ADOPTION_SCHEMA = "tiangong-foundry.task-runtime-adoption-plan.v2";
|
|
204
|
+
const legacyPlanSchema = "tiangong-foundry.task-runtime-adoption-plan.v1";
|
|
205
|
+
const maxAdoptions = 64;
|
|
206
|
+
export function currentAdoptionRuntime(context) {
|
|
207
|
+
return {
|
|
208
|
+
package_name: context.runtime.packageName,
|
|
209
|
+
package_version: context.runtime.packageVersion,
|
|
210
|
+
manifest_sha256: context.runtime.packageManifestSha256,
|
|
211
|
+
entry_sha256: context.runtime.entrySha256,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function anchorPath(context) {
|
|
215
|
+
return resolveFoundryOutput(context, `task-runtime-adoptions/${context.taskId}.json`, "state");
|
|
216
|
+
}
|
|
217
|
+
export function registration(context) {
|
|
218
|
+
const data = transferRead(resolveFoundryOutput(context, `task-registrations/${context.taskId}.json`, "state"), 24 * 1024 * 1024);
|
|
219
|
+
const value = object(JSON.parse(data.toString("utf8")));
|
|
220
|
+
const { registration_sha256, ...payload } = value;
|
|
221
|
+
const job = object(value.job);
|
|
222
|
+
if (value.schema !== "tiangong-foundry.task-registration.v1" ||
|
|
223
|
+
registration_sha256 !== sha256Json(payload) ||
|
|
224
|
+
job.workspace_id !== context.workspaceId ||
|
|
225
|
+
job.task_id !== context.taskId ||
|
|
226
|
+
job.actor_id !== context.actorId ||
|
|
227
|
+
!bytes(job).equals(readTaskBytes(context, "foundry-job.json")))
|
|
228
|
+
fail("runtime_adoption_registration_invalid", "Original immutable task registration or job changed.");
|
|
229
|
+
return { value, job, sha256: digest(data) };
|
|
230
|
+
}
|
|
231
|
+
/** Explicit operator-selected evidence does not grant business permission. It authorizes only these exact registrations. */
|
|
232
|
+
export function validateSelection(context, selection, options = {}) {
|
|
233
|
+
const value = object(selection);
|
|
234
|
+
const successor = options.successor ?? currentAdoptionRuntimeFacts(context);
|
|
235
|
+
exact(value, [
|
|
236
|
+
"schema",
|
|
237
|
+
"scope",
|
|
238
|
+
"original_entry",
|
|
239
|
+
"original_descriptor",
|
|
240
|
+
"original_runtime",
|
|
241
|
+
"successor_runtime",
|
|
242
|
+
"qualification",
|
|
243
|
+
"writer_handoff",
|
|
244
|
+
"authorization",
|
|
245
|
+
]);
|
|
246
|
+
if (value.schema !== "tiangong-foundry.task-runtime-compatibility-selection.v1" ||
|
|
247
|
+
!Array.isArray(value.scope) ||
|
|
248
|
+
!value.scope.length ||
|
|
249
|
+
value.scope.length > 64 ||
|
|
250
|
+
sha256Json(value.successor_runtime) !== sha256Json(successor.identity))
|
|
251
|
+
fail("runtime_adoption_selection_invalid", "Select a bounded exact task roster and the executing compatible runtime.");
|
|
252
|
+
const scope = value.scope.map((item) => {
|
|
253
|
+
const row = object(item);
|
|
254
|
+
exact(row, ["task_id", "registration_sha256"]);
|
|
255
|
+
if (typeof row.task_id !== "string" ||
|
|
256
|
+
!/^task-[0-9a-f]{64}-r\d{4}$/u.test(row.task_id) ||
|
|
257
|
+
typeof row.registration_sha256 !== "string" ||
|
|
258
|
+
!/^[0-9a-f]{64}$/u.test(row.registration_sha256))
|
|
259
|
+
fail("runtime_adoption_selection_invalid", "Selected registration identities are malformed.");
|
|
260
|
+
return row;
|
|
261
|
+
});
|
|
262
|
+
if (new Set(scope.map((row) => row.task_id)).size !== scope.length)
|
|
263
|
+
fail("runtime_adoption_selection_invalid", "Selected registrations must be unique.");
|
|
264
|
+
const original = facts([value.original_entry])[0], authorization = facts([value.authorization])[0];
|
|
265
|
+
for (const fact of [original, authorization]) {
|
|
266
|
+
if (!path.isAbsolute(fact.path))
|
|
267
|
+
fail("runtime_adoption_selection_invalid", "Select absolute regular evidence files.");
|
|
268
|
+
const content = transferRead(fact.path, 16 * 1024 * 1024);
|
|
269
|
+
if (content.length !== fact.bytes || digest(content) !== fact.sha256)
|
|
270
|
+
fail("runtime_adoption_evidence_changed", "Independent compatibility or authorization evidence changed.");
|
|
271
|
+
}
|
|
272
|
+
const originalRoot = path.resolve(original.path, "../../..");
|
|
273
|
+
if (path.relative(originalRoot, original.path).split(path.sep).join("/") !==
|
|
274
|
+
"package-dist/scripts/package-entry.js")
|
|
275
|
+
fail("runtime_adoption_original_invalid", "Select the retained original emitted package entry.");
|
|
276
|
+
const oldManifest = transferRead(path.join(originalRoot, "package.json"), 1024 * 1024);
|
|
277
|
+
const oldJson = object(JSON.parse(oldManifest.toString("utf8")));
|
|
278
|
+
const oldIdentity = {
|
|
279
|
+
package_name: oldJson.name,
|
|
280
|
+
package_version: oldJson.version,
|
|
281
|
+
manifest_sha256: digest(oldManifest),
|
|
282
|
+
entry_sha256: original.sha256,
|
|
283
|
+
};
|
|
284
|
+
const descriptorFact = facts([value.original_descriptor])[0];
|
|
285
|
+
if (descriptorFact.path !==
|
|
286
|
+
path.join(originalRoot, "package-dist/assets/foundry-package-descriptor.json"))
|
|
287
|
+
fail("runtime_adoption_original_invalid", "Select the original package descriptor alongside its entry.");
|
|
288
|
+
const descriptorBytes = transferRead(descriptorFact.path, 8 * 1024 * 1024);
|
|
289
|
+
const descriptor = object(JSON.parse(descriptorBytes.toString("utf8")));
|
|
290
|
+
if (descriptorBytes.length !== descriptorFact.bytes ||
|
|
291
|
+
digest(descriptorBytes) !== descriptorFact.sha256 ||
|
|
292
|
+
descriptor.schema !== "tiangong-foundry.package-descriptor.v1" ||
|
|
293
|
+
!Array.isArray(descriptor.files) ||
|
|
294
|
+
descriptor.files.length > 5000 ||
|
|
295
|
+
descriptor.files_sha256 !== sha256Json(descriptor.files))
|
|
296
|
+
fail("runtime_adoption_original_invalid", "Retained original package inventory changed.");
|
|
297
|
+
for (const fact of facts(descriptor.files)) {
|
|
298
|
+
const current = transferFileContentFact(transferPath(originalRoot, fact.path));
|
|
299
|
+
if (current.bytes !== fact.bytes || current.sha256 !== fact.sha256)
|
|
300
|
+
fail("runtime_adoption_original_invalid", "Original package code or assets changed.");
|
|
301
|
+
}
|
|
302
|
+
if (sha256Json(oldIdentity) !== sha256Json(value.original_runtime) ||
|
|
303
|
+
(sha256Json(oldIdentity) === sha256Json(successor.identity) &&
|
|
304
|
+
descriptorFact.sha256 === successor.descriptor.sha256 &&
|
|
305
|
+
sha256Json(object(value.qualification).original_cli) ===
|
|
306
|
+
sha256Json(object(value.qualification).successor_cli)))
|
|
307
|
+
fail("runtime_adoption_original_invalid", "The retained original package must match the predecessor and the qualified complete combination must change.");
|
|
308
|
+
validateAdoptionQualification(context, value, original.path, successor, options.historical);
|
|
309
|
+
const handoff = object(value.writer_handoff);
|
|
310
|
+
exact(handoff, [
|
|
311
|
+
"schema",
|
|
312
|
+
"task_id",
|
|
313
|
+
"actor_id",
|
|
314
|
+
"registration_sha256",
|
|
315
|
+
"writer_stopped",
|
|
316
|
+
"evidence",
|
|
317
|
+
...(handoff.schema === "tiangong-foundry.runtime-adoption-handoff.v2"
|
|
318
|
+
? ["predecessor_plan_sha256"]
|
|
319
|
+
: []),
|
|
320
|
+
]);
|
|
321
|
+
if (![
|
|
322
|
+
"tiangong-foundry.runtime-adoption-handoff.v1",
|
|
323
|
+
"tiangong-foundry.runtime-adoption-handoff.v2",
|
|
324
|
+
].includes(String(handoff.schema)) ||
|
|
325
|
+
(handoff.schema === "tiangong-foundry.runtime-adoption-handoff.v2" &&
|
|
326
|
+
(typeof handoff.predecessor_plan_sha256 !== "string" ||
|
|
327
|
+
!/^[0-9a-f]{64}$/u.test(handoff.predecessor_plan_sha256))) ||
|
|
328
|
+
handoff.task_id !== context.taskId ||
|
|
329
|
+
handoff.actor_id !== context.actorId ||
|
|
330
|
+
handoff.writer_stopped !== true ||
|
|
331
|
+
!scope.some((row) => row.task_id === handoff.task_id && row.registration_sha256 === handoff.registration_sha256))
|
|
332
|
+
fail("runtime_adoption_writer_not_stopped", "Require the original writer's exact stopped-task handoff before adoption.");
|
|
333
|
+
verifyEvidence([handoff.evidence]);
|
|
334
|
+
return { value, scope };
|
|
335
|
+
}
|
|
336
|
+
export function parsePlan(value) {
|
|
337
|
+
const plan = object(value);
|
|
338
|
+
exact(plan, [
|
|
339
|
+
"schema",
|
|
340
|
+
"workspace_id",
|
|
341
|
+
"task_id",
|
|
342
|
+
"actor_id",
|
|
343
|
+
"registration_sha256",
|
|
344
|
+
"job_sha256",
|
|
345
|
+
"selection",
|
|
346
|
+
"continuation",
|
|
347
|
+
"prior_context_reports",
|
|
348
|
+
"witness",
|
|
349
|
+
"plan_sha256",
|
|
350
|
+
...(plan.schema === TASK_RUNTIME_ADOPTION_SCHEMA
|
|
351
|
+
? ["predecessor_plan_sha256", "successor_entry", "successor_descriptor"]
|
|
352
|
+
: []),
|
|
353
|
+
]);
|
|
354
|
+
const { plan_sha256, ...payload } = plan;
|
|
355
|
+
if (![TASK_RUNTIME_ADOPTION_SCHEMA, legacyPlanSchema].includes(String(plan.schema)) ||
|
|
356
|
+
(plan.schema === TASK_RUNTIME_ADOPTION_SCHEMA &&
|
|
357
|
+
plan.predecessor_plan_sha256 !== null &&
|
|
358
|
+
(typeof plan.predecessor_plan_sha256 !== "string" ||
|
|
359
|
+
!/^[0-9a-f]{64}$/u.test(plan.predecessor_plan_sha256))) ||
|
|
360
|
+
!["preparation_only", "original_owner_recovery"].includes(String(plan.continuation)) ||
|
|
361
|
+
plan_sha256 !== sha256Json(payload))
|
|
362
|
+
fail("runtime_adoption_plan_invalid", "Select a complete immutable adoption plan.");
|
|
363
|
+
const reports = facts(plan.prior_context_reports);
|
|
364
|
+
if (reports.length > 64 ||
|
|
365
|
+
reports.some((fact) => path.isAbsolute(fact.path) ||
|
|
366
|
+
path.basename(fact.path) !== "contract-report.json" ||
|
|
367
|
+
fact.path.split(/[\\/]/u).includes("..")))
|
|
368
|
+
fail("runtime_adoption_plan_invalid", "Prior context report bindings must be bounded task-local facts.");
|
|
369
|
+
return plan;
|
|
370
|
+
}
|
|
371
|
+
export function adoptionSuccessorPath(context, predecessor) {
|
|
372
|
+
if (!/^[0-9a-f]{64}$/u.test(predecessor))
|
|
373
|
+
fail("runtime_adoption_plan_invalid", "Predecessor digest is invalid.");
|
|
374
|
+
return resolveFoundryOutput(context, `task-runtime-adoptions/${context.taskId}/successors/${predecessor}.json`, "state");
|
|
375
|
+
}
|
|
376
|
+
function readAdoptionPlans(context) {
|
|
377
|
+
if (!context.taskId || !fs.existsSync(anchorPath(context)))
|
|
378
|
+
return null;
|
|
379
|
+
const anchor = object(JSON.parse(transferRead(anchorPath(context), 64 * 1024).toString("utf8")));
|
|
380
|
+
exact(anchor, ["schema", "workspace_id", "task_id", "plan_sha256", "receipt_sha256"]);
|
|
381
|
+
if (anchor.schema !== "tiangong-foundry.task-runtime-adoption-anchor.v1" ||
|
|
382
|
+
anchor.workspace_id !== context.workspaceId ||
|
|
383
|
+
anchor.task_id !== context.taskId ||
|
|
384
|
+
typeof anchor.plan_sha256 !== "string" ||
|
|
385
|
+
!/^[0-9a-f]{64}$/u.test(anchor.plan_sha256))
|
|
386
|
+
fail("runtime_adoption_anchor_invalid", "Runtime adoption anchor does not belong to this task.");
|
|
387
|
+
const plans = [];
|
|
388
|
+
let pointer = anchor;
|
|
389
|
+
let totalBytes = 0;
|
|
390
|
+
for (;;) {
|
|
391
|
+
if (plans.length >= maxAdoptions ||
|
|
392
|
+
plans.some((plan) => plan.plan_sha256 === pointer.plan_sha256))
|
|
393
|
+
fail("runtime_adoption_limit", "Runtime adoption chain exceeds its bound or repeats a receipt.");
|
|
394
|
+
const content = transferRead(resolveFoundryOutput(context, `runtime-adoptions/${pointer.plan_sha256}.json`), 16 * 1024 * 1024);
|
|
395
|
+
totalBytes += content.length;
|
|
396
|
+
if (totalBytes > 64 * 1024 * 1024)
|
|
397
|
+
fail("runtime_adoption_limit", "Runtime adoption receipts exceed 64 MiB.");
|
|
398
|
+
if (digest(content) !== pointer.receipt_sha256)
|
|
399
|
+
fail("runtime_adoption_receipt_changed", "Runtime adoption receipt changed.");
|
|
400
|
+
const plan = parsePlan(JSON.parse(content.toString("utf8")));
|
|
401
|
+
const predecessor = plans.at(-1)?.plan_sha256 ?? null;
|
|
402
|
+
if (plan.plan_sha256 !== pointer.plan_sha256 ||
|
|
403
|
+
(plan.predecessor_plan_sha256 ?? null) !== predecessor)
|
|
404
|
+
fail("runtime_adoption_binding_changed", "Runtime adoption predecessor differs from its immutable link.");
|
|
405
|
+
plans.push(plan);
|
|
406
|
+
const nextPath = adoptionSuccessorPath(context, String(plan.plan_sha256));
|
|
407
|
+
if (!fs.existsSync(nextPath))
|
|
408
|
+
break;
|
|
409
|
+
const nextBytes = transferRead(nextPath, 64 * 1024);
|
|
410
|
+
const next = object(JSON.parse(nextBytes.toString("utf8")));
|
|
411
|
+
exact(next, [
|
|
412
|
+
"schema",
|
|
413
|
+
"workspace_id",
|
|
414
|
+
"task_id",
|
|
415
|
+
"predecessor_plan_sha256",
|
|
416
|
+
"plan_sha256",
|
|
417
|
+
"receipt_sha256",
|
|
418
|
+
]);
|
|
419
|
+
if (next.schema !== "tiangong-foundry.task-runtime-adoption-successor.v1" ||
|
|
420
|
+
next.workspace_id !== context.workspaceId ||
|
|
421
|
+
next.task_id !== context.taskId ||
|
|
422
|
+
next.predecessor_plan_sha256 !== plan.plan_sha256 ||
|
|
423
|
+
typeof next.plan_sha256 !== "string" ||
|
|
424
|
+
!/^[0-9a-f]{64}$/u.test(next.plan_sha256))
|
|
425
|
+
fail("runtime_adoption_anchor_invalid", "Runtime adoption successor link changed.");
|
|
426
|
+
if (!nextBytes.equals(bytes({
|
|
427
|
+
schema: next.schema,
|
|
428
|
+
workspace_id: next.workspace_id,
|
|
429
|
+
task_id: next.task_id,
|
|
430
|
+
plan_sha256: next.plan_sha256,
|
|
431
|
+
receipt_sha256: next.receipt_sha256,
|
|
432
|
+
predecessor_plan_sha256: next.predecessor_plan_sha256,
|
|
433
|
+
})))
|
|
434
|
+
fail("runtime_adoption_anchor_invalid", "Immutable successor link bytes differ from the native writer contract.");
|
|
435
|
+
pointer = next;
|
|
436
|
+
}
|
|
437
|
+
return plans;
|
|
438
|
+
}
|
|
439
|
+
/** Inspect anchored historical proofs; a locator for a legacy tip cannot replace its stored pair claims. */
|
|
440
|
+
export function readFoundryTaskRuntimeAdoptionChain(context, legacyTipSelection) {
|
|
441
|
+
const plans = readAdoptionPlans(context);
|
|
442
|
+
if (!plans)
|
|
443
|
+
return null;
|
|
444
|
+
const registered = registration(context), runtimes = [];
|
|
445
|
+
const reports = new Map();
|
|
446
|
+
let previous;
|
|
447
|
+
for (const [index, plan] of plans.entries()) {
|
|
448
|
+
const value = object(plan.selection);
|
|
449
|
+
const next = plans[index + 1] ? object(plans[index + 1].selection) : null;
|
|
450
|
+
let successor;
|
|
451
|
+
if (plan.schema === TASK_RUNTIME_ADOPTION_SCHEMA)
|
|
452
|
+
successor = retainedRuntime(plan.successor_entry, plan.successor_descriptor, value.successor_runtime);
|
|
453
|
+
else if (next)
|
|
454
|
+
successor = retainedRuntime(next.original_entry, next.original_descriptor, value.successor_runtime);
|
|
455
|
+
else if (legacyTipSelection) {
|
|
456
|
+
const locator = object(legacyTipSelection);
|
|
457
|
+
successor = retainedRuntime(locator.original_entry, locator.original_descriptor, value.successor_runtime);
|
|
458
|
+
}
|
|
459
|
+
else if (sha256Json(value.successor_runtime) === sha256Json(currentAdoptionRuntime(context))) {
|
|
460
|
+
successor = currentAdoptionRuntimeFacts(context);
|
|
461
|
+
}
|
|
462
|
+
else
|
|
463
|
+
fail("runtime_adoption_legacy_locator_required", "Retain an exact installed successor locator for the legacy adoption tip.");
|
|
464
|
+
const selected = validateSelection(context, value, { successor, historical: true });
|
|
465
|
+
const original = retainedRuntime(value.original_entry, value.original_descriptor, value.original_runtime);
|
|
466
|
+
const expectedOriginal = previous
|
|
467
|
+
? object(previous.selection).successor_runtime
|
|
468
|
+
: registered.job.runtime_identity;
|
|
469
|
+
if (!selected.scope.some((row) => row.task_id === context.taskId && row.registration_sha256 === registered.sha256) ||
|
|
470
|
+
sha256Json(value.original_runtime) !== sha256Json(expectedOriginal))
|
|
471
|
+
fail("runtime_adoption_scope_mismatch", "Retained transition differs from its registered predecessor.");
|
|
472
|
+
if (plan.workspace_id !== context.workspaceId ||
|
|
473
|
+
plan.task_id !== context.taskId ||
|
|
474
|
+
plan.actor_id !== context.actorId ||
|
|
475
|
+
plan.registration_sha256 !== registered.sha256 ||
|
|
476
|
+
plan.job_sha256 !== digest(bytes(registered.job)))
|
|
477
|
+
fail("runtime_adoption_binding_changed", "Runtime adoption registration changed.");
|
|
478
|
+
if (previous) {
|
|
479
|
+
const prior = object(object(previous.selection).qualification), current = object(value.qualification);
|
|
480
|
+
const retained = runtimes.at(-1);
|
|
481
|
+
const handoff = object(value.writer_handoff);
|
|
482
|
+
const priorToolkit = facts(prior.tidas)[1], originalToolkit = facts(current.tidas)[0];
|
|
483
|
+
if (sha256Json(original) !== sha256Json(retained) ||
|
|
484
|
+
current.original_manifest_sha256 !== prior.successor_manifest_sha256 ||
|
|
485
|
+
sha256Json(current.original_cli) !== sha256Json(prior.successor_cli) ||
|
|
486
|
+
originalToolkit.sha256 !== priorToolkit.sha256 ||
|
|
487
|
+
originalToolkit.bytes !== priorToolkit.bytes ||
|
|
488
|
+
handoff.predecessor_plan_sha256 !== previous.plan_sha256 ||
|
|
489
|
+
(previous.continuation === "original_owner_recovery" &&
|
|
490
|
+
plan.continuation !== "original_owner_recovery"))
|
|
491
|
+
fail("runtime_adoption_binding_changed", "Successor transition cannot reinterpret or clear its historical predecessor proof.");
|
|
492
|
+
}
|
|
493
|
+
else
|
|
494
|
+
runtimes.push(original);
|
|
495
|
+
for (const fact of facts(plan.prior_context_reports)) {
|
|
496
|
+
const data = readTaskBytes(context, fact.path);
|
|
497
|
+
const existing = reports.get(fact.path);
|
|
498
|
+
if (data.length !== fact.bytes ||
|
|
499
|
+
digest(data) !== fact.sha256 ||
|
|
500
|
+
(existing && sha256Json(existing) !== sha256Json(fact)))
|
|
501
|
+
fail("runtime_adoption_evidence_changed", "Retained context report changed.");
|
|
502
|
+
reports.set(fact.path, fact);
|
|
503
|
+
}
|
|
504
|
+
if (previous &&
|
|
505
|
+
facts(previous.prior_context_reports).some((fact) => !facts(plan.prior_context_reports).some((current) => sha256Json(current) === sha256Json(fact))))
|
|
506
|
+
fail("runtime_adoption_binding_changed", "Successor transition must retain preceding context facts.");
|
|
507
|
+
runtimes.push(successor);
|
|
508
|
+
previous = plan;
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
plans,
|
|
512
|
+
tip: plans.at(-1),
|
|
513
|
+
runtimes,
|
|
514
|
+
retained_runtime_roots: runtimes.map((runtime) => runtime.root),
|
|
515
|
+
prior_context_reports: [...reports.values()],
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export function readFoundryTaskRuntimeAdoption(context) {
|
|
519
|
+
const chain = readFoundryTaskRuntimeAdoptionChain(context);
|
|
520
|
+
if (!chain)
|
|
521
|
+
return null;
|
|
522
|
+
const current = currentAdoptionRuntimeFacts(context);
|
|
523
|
+
if (sha256Json(object(chain.tip.selection).successor_runtime) !== sha256Json(current.identity) ||
|
|
524
|
+
current.descriptor.sha256 !== chain.runtimes.at(-1).descriptor.sha256)
|
|
525
|
+
fail("task_runtime_changed", "Only the current adoption tip may continue this Task.");
|
|
526
|
+
verifyRetainedCli(current.entry.path, object(object(object(chain.tip.selection).qualification).successor_cli));
|
|
527
|
+
return chain.tip;
|
|
528
|
+
}
|
|
529
|
+
export function assertAdoptedRuntimeToolkit(context, selected, allowTransition = false) {
|
|
530
|
+
if (!context.taskId || !fs.existsSync(anchorPath(context)))
|
|
531
|
+
return;
|
|
532
|
+
// Only the explicit plan/apply caller may inspect a future combination; its writer verifies
|
|
533
|
+
// every stored transition and the independently selected complete old/new pair before recording it.
|
|
534
|
+
if (allowTransition)
|
|
535
|
+
return;
|
|
536
|
+
const adopted = readFoundryTaskRuntimeAdoption(context);
|
|
537
|
+
if (adopted)
|
|
538
|
+
assertRuntimeAdoptionToolkit(selected, adopted.selection);
|
|
539
|
+
}
|
|
540
|
+
export function assertTaskRuntimeIdentity(context, original) {
|
|
541
|
+
if (!fs.existsSync(anchorPath(context)) &&
|
|
542
|
+
sha256Json(original) === sha256Json(currentAdoptionRuntime(context)))
|
|
543
|
+
return;
|
|
544
|
+
const adoption = readFoundryTaskRuntimeAdoption(context);
|
|
545
|
+
if (adoption?.continuation === "original_owner_recovery" && context.workspaceAccess === "write")
|
|
546
|
+
fail("runtime_adoption_original_recovery_required", "Retained finalization or attempt history requires the original runtime owner; adoption cannot renew a grant or replay a write.");
|
|
547
|
+
if (!adoption || sha256Json(registration(context).job.runtime_identity) !== sha256Json(original))
|
|
548
|
+
fail("task_runtime_changed", "Task runtime identity changed; use the pinned runtime or explicit same-task adoption.");
|
|
549
|
+
}
|
|
@@ -21,9 +21,12 @@ export declare function assertFoundryTaskInputLineage(context: FoundryRuntimeCon
|
|
|
21
21
|
ancestor: FoundryInputFact;
|
|
22
22
|
derived: FoundryInputFact;
|
|
23
23
|
}>>;
|
|
24
|
+
export declare function readFoundryTaskArtifactIndex(context: FoundryRuntimeContext): ArtifactEntry[];
|
|
25
|
+
/** Reuse the producer/source verifier for every indexed artifact without selecting a new runtime. */
|
|
26
|
+
export declare function verifyFoundryTaskArtifactLineage(context: FoundryRuntimeContext, task: LoadedTask, index: ArtifactEntry[]): void;
|
|
24
27
|
/** Short local preparation transaction. Remote mutation/batch execution must not use this replay path. */
|
|
25
28
|
export declare function runFoundryTaskOperation(context: FoundryRuntimeContext, input: {
|
|
26
|
-
command: "dataset-curation-cleanup" | "dataset-tidas-import" | "dataset-context-pack" | "dataset-workflow-rows" | "dataset-workflow-assessment" | "dataset-workflow-identity" | "dataset-workflow-finalize" | "dataset-workflow-authorization" | "dataset-workflow-native-contract" | "dataset-workflow-repair-preflight" | "dataset-workflow-reference-input" | "dataset-workflow-execution-prepare" | "dataset-workflow-execution-result" | "dataset-workflow-execution-consume" | "dataset-workflow-execution-observation" | "dataset-workflow-reference-verify" | "dataset-workflow-interaction" | "dataset-semantic-apply";
|
|
29
|
+
command: "dataset-curation-cleanup" | "dataset-tidas-import" | "dataset-context-pack" | "dataset-workflow-rows" | "dataset-workflow-assessment" | "dataset-workflow-identity" | "dataset-workflow-identity-stage-prepare" | "dataset-workflow-identity-stage-dispatch" | "dataset-workflow-finalize" | "dataset-workflow-authorization" | "dataset-workflow-native-contract" | "dataset-workflow-repair-preflight" | "dataset-workflow-reference-input" | "dataset-workflow-quality-review" | "dataset-workflow-execution-prepare" | "dataset-workflow-execution-result" | "dataset-workflow-execution-consume" | "dataset-workflow-execution-observation" | "dataset-workflow-reference-verify" | "dataset-workflow-interaction" | "dataset-semantic-apply";
|
|
27
30
|
options: JsonRecord;
|
|
28
31
|
task?: FoundryTaskOptions;
|
|
29
32
|
validateCurrent?: (index: readonly ArtifactEntry[]) => void;
|