@tiangong-lca/foundry 0.1.7 → 0.1.8
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 +7 -5
- package/docs/architecture.md +7 -5
- package/docs/foundry-task-contracts.md +4 -4
- package/docs/import-profiles/worldsteel/constraints.md +3 -3
- package/docs/import-profiles/worldsteel/import-coverage.md +3 -3
- package/docs/import-profiles/worldsteel/import-plan.md +1 -1
- package/docs/import-profiles/worldsteel/profile.md +3 -3
- package/docs/package-distribution-contract.md +6 -6
- package/docs/public-runtime-contract.md +22 -6
- package/docs/runtime-context-contract.md +9 -5
- package/docs/task-authorization-contract.md +8 -4
- package/package-dist/assets/foundry-package-descriptor.json +150 -84
- package/package-dist/scripts/foundry-facade.d.ts +1 -0
- package/package-dist/scripts/foundry-facade.js +35 -4
- package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +65 -10
- package/package-dist/scripts/lib/finalize-owners/finalize-reference-inputs.d.ts +12 -0
- package/package-dist/scripts/lib/finalize-owners/finalize-reference-inputs.js +57 -0
- package/package-dist/scripts/lib/finalize-owners/handoff-reference-intent.d.ts +28 -0
- package/package-dist/scripts/lib/finalize-owners/handoff-reference-intent.js +115 -0
- package/package-dist/scripts/lib/finalize-owners/native-insert-closeout.d.ts +13 -0
- package/package-dist/scripts/lib/finalize-owners/native-insert-closeout.js +99 -0
- package/package-dist/scripts/lib/finalize-owners/native-insert-handoff.d.ts +47 -0
- package/package-dist/scripts/lib/finalize-owners/native-insert-handoff.js +146 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +13 -0
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.d.ts +8 -2
- package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +48 -2
- package/package-dist/scripts/lib/finalize-owners/reference-intent-closeout.d.ts +12 -0
- package/package-dist/scripts/lib/finalize-owners/reference-intent-closeout.js +77 -0
- package/package-dist/scripts/lib/foundry-authorization-input.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-authorization-input.js +68 -1
- package/package-dist/scripts/lib/foundry-command-metadata.js +15 -1
- package/package-dist/scripts/lib/foundry-execution-admission.js +82 -5
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +25 -2
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +65 -14
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +4 -2
- package/package-dist/scripts/lib/foundry-reference-input.d.ts +28 -0
- package/package-dist/scripts/lib/foundry-reference-input.js +235 -0
- 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-store.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +38 -2
- package/package-dist/scripts/lib/foundry-workflow-execution.js +7 -1
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +43 -1
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +31 -2
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/public-api.d.ts +1 -0
- package/package-dist/scripts/runtime-entry.js +2 -1
- package/package.json +3 -2
- package/specs/import-profiles.json +1 -1
- package/specs/prewrite-content-policy.json +1 -1
- package/specs/schemas/foundry-authorization-input.schema.json +38 -1
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-package-descriptor.schema.json +3 -2
- package/specs/schemas/foundry-reference-input.schema.json +137 -0
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -2,6 +2,8 @@ import { parseCapsule, FOUNDRY_EXECUTION_CAPSULE_SCHEMA, } from "./foundry-execu
|
|
|
2
2
|
export { FOUNDRY_EXECUTION_CAPSULE_SCHEMA, } from "./foundry-execution-context-format.js";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { readNativeInsertHandoff } from "./finalize-owners/native-insert-handoff.js";
|
|
6
|
+
import { readHandoffReferenceEvidence } from "./finalize-owners/handoff-reference-intent.js";
|
|
5
7
|
import { assertFoundryCommandSpecArtifactsCurrent, commandSpecOptionValue, parseFoundryCommandSpec, } from "@tiangong-lca/cli/command-spec";
|
|
6
8
|
import { assertFoundryRuntimeContext, assertFoundryWorkspaceActive, captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryInputPath, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
7
9
|
import { assertVerifiedFoundryIdentity, } from "./foundry-runtime-identity.js";
|
|
@@ -40,9 +42,15 @@ function resolveSpecArtifact(context, value) {
|
|
|
40
42
|
}
|
|
41
43
|
function commandSpec(context, value, finalRows, actions) {
|
|
42
44
|
const spec = assertFoundryCommandSpecArtifactsCurrent(value, (artifactPath) => resolveSpecArtifact(context, artifactPath));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
45
|
+
const nativeFile = commandSpecOptionValue(spec, "--execution-contract");
|
|
46
|
+
const rowArtifacts = spec.binding.artifacts.filter((item) => item.role === "final_rows");
|
|
47
|
+
const contractArtifacts = spec.binding.artifacts.filter((item) => item.role === "execution_contract");
|
|
48
|
+
const referenceArtifacts = spec.binding.artifacts.filter((item) => ["reference_intent", "reference_precommit", "reference_review"].includes(item.role));
|
|
49
|
+
if (rowArtifacts.length !== 1 ||
|
|
50
|
+
spec.binding.artifacts.length !== (nativeFile ? 2 : 1) + referenceArtifacts.length ||
|
|
51
|
+
contractArtifacts.length !== (nativeFile ? 1 : 0))
|
|
52
|
+
fail("execution_final_rows_unbound", "Restricted execution requires exact final rows and only explicitly selected native contract evidence.");
|
|
53
|
+
const artifact = rowArtifacts[0];
|
|
46
54
|
if (resolveSpecArtifact(context, artifact.path) !== finalRows.path ||
|
|
47
55
|
artifact.bytes !== finalRows.bytes ||
|
|
48
56
|
artifact.sha256 !== finalRows.sha256)
|
|
@@ -69,10 +77,77 @@ function commandSpec(context, value, finalRows, actions) {
|
|
|
69
77
|
fail("execution_command_unadmitted", "Restricted execution requires the owner CLI commit and machine-result flags.");
|
|
70
78
|
const [group, operation] = spec.argv.slice(1, 3);
|
|
71
79
|
const datasetType = commandSpecOptionValue(spec, "--type");
|
|
80
|
+
const nativeSave = Boolean(nativeFile &&
|
|
81
|
+
group === "dataset" &&
|
|
82
|
+
operation === "save-draft" &&
|
|
83
|
+
datasetType &&
|
|
84
|
+
["flow", "process", "source"].includes(datasetType));
|
|
85
|
+
if (nativeFile) {
|
|
86
|
+
if (!nativeSave)
|
|
87
|
+
fail("execution_command_unadmitted", "Native insert contracts require the reviewed dataset save-draft operation.");
|
|
88
|
+
const fact = selected(context, nativeFile);
|
|
89
|
+
const bound = contractArtifacts[0];
|
|
90
|
+
if (resolveSpecArtifact(context, bound.path) !== fact.path ||
|
|
91
|
+
bound.bytes !== fact.bytes ||
|
|
92
|
+
bound.sha256 !== fact.sha256)
|
|
93
|
+
fail("execution_native_contract_unbound", "Native contract must bind the independently selected current bytes.");
|
|
94
|
+
readFoundryInput(context, fact.path, 8 * 1024 * 1024);
|
|
95
|
+
readFoundryInput(context, finalRows.path);
|
|
96
|
+
const native = readNativeInsertHandoff({
|
|
97
|
+
contractFile: fact.path,
|
|
98
|
+
rowsFile: finalRows.path,
|
|
99
|
+
datasetType: datasetType,
|
|
100
|
+
targetUserId: context.accountIntent?.userId ?? "",
|
|
101
|
+
verifiedProjectRef: context.accountIntent?.projectRef ?? "",
|
|
102
|
+
stateCode: "0",
|
|
103
|
+
relativePath: (file) => path.relative(context.workspaceRoot, file),
|
|
104
|
+
});
|
|
105
|
+
if (native.rows_sha256 !== finalRows.sha256 || native.artifact.sha256 !== fact.sha256)
|
|
106
|
+
fail("execution_native_contract_unbound", "Native contract or final rows changed during execution admission.");
|
|
107
|
+
}
|
|
108
|
+
if (referenceArtifacts.length) {
|
|
109
|
+
const intents = referenceArtifacts.filter((item) => item.role === "reference_intent");
|
|
110
|
+
const precommits = referenceArtifacts.filter((item) => item.role === "reference_precommit");
|
|
111
|
+
if (intents.length !== 1 || precommits.length !== 1 || referenceArtifacts.length < 3)
|
|
112
|
+
fail("execution_reference_evidence_unbound", "Execution requires exactly one intent, one precommit and its review evidence.");
|
|
113
|
+
for (const artifact of referenceArtifacts) {
|
|
114
|
+
const fact = selected(context, artifact.path);
|
|
115
|
+
if (fact.bytes !== artifact.bytes || fact.sha256 !== artifact.sha256)
|
|
116
|
+
fail("execution_reference_evidence_unbound", "Reference artifacts differ from the current host selection.");
|
|
117
|
+
readFoundryInput(context, fact.path);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const reference = readHandoffReferenceEvidence({
|
|
121
|
+
finalize: {
|
|
122
|
+
files: { remote_verify_report: resolveSpecArtifact(context, precommits[0].path) },
|
|
123
|
+
reference_intent_file: resolveSpecArtifact(context, intents[0].path),
|
|
124
|
+
},
|
|
125
|
+
options: { referenceIntentFile: resolveSpecArtifact(context, intents[0].path) },
|
|
126
|
+
rowsFile: finalRows.path,
|
|
127
|
+
datasetType: datasetType ?? group,
|
|
128
|
+
targetUserId: context.accountIntent?.userId ?? "",
|
|
129
|
+
projectRef: context.accountIntent?.projectRef ?? "",
|
|
130
|
+
resolveFile: (value) => typeof value === "string" ? resolveSpecArtifact(context, value) : null,
|
|
131
|
+
relativePath: (file) => file,
|
|
132
|
+
});
|
|
133
|
+
if (!reference ||
|
|
134
|
+
reference.rows_sha256 !== finalRows.sha256 ||
|
|
135
|
+
reference.artifacts.length !== referenceArtifacts.length ||
|
|
136
|
+
!reference.artifacts.every((expected) => referenceArtifacts.some((bound) => bound.role === expected.role &&
|
|
137
|
+
resolveSpecArtifact(context, bound.path) === expected.path &&
|
|
138
|
+
bound.sha256 === expected.sha256 &&
|
|
139
|
+
bound.bytes === expected.bytes)))
|
|
140
|
+
throw new Error("Reference binding mismatch");
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
fail("execution_reference_evidence_unbound", "Execution must retain the exact current consumer, intent, precommit and review evidence.");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
72
146
|
const isDatasetSave = group === "dataset" &&
|
|
73
147
|
operation === "save-draft" &&
|
|
74
148
|
datasetType !== null &&
|
|
75
|
-
["auto", "contact", "source", "unitgroup", "flowproperty"].includes(datasetType)
|
|
149
|
+
(["auto", "contact", "source", "unitgroup", "flowproperty"].includes(datasetType) ||
|
|
150
|
+
nativeSave);
|
|
76
151
|
const isProcessSave = group === "process" && operation === "save-draft" && !datasetType;
|
|
77
152
|
const isLifecycleSave = group === "lifecyclemodel" && operation === "save-draft" && !datasetType;
|
|
78
153
|
const isFlowPublish = group === "flow" && operation === "publish-version" && !datasetType;
|
|
@@ -83,7 +158,9 @@ function commandSpec(context, value, finalRows, actions) {
|
|
|
83
158
|
(datasetType === "flowproperty" && !has("flowproperty_write")) ||
|
|
84
159
|
(has("unitgroup_write") && !["unitgroup", "auto"].includes(datasetType ?? "")) ||
|
|
85
160
|
(has("flowproperty_write") && !["flowproperty", "auto"].includes(datasetType ?? "")) ||
|
|
86
|
-
((has("elementary_flow_write") || has("elementary_flow_create_new")) &&
|
|
161
|
+
((has("elementary_flow_write") || has("elementary_flow_create_new")) &&
|
|
162
|
+
!isFlowPublish &&
|
|
163
|
+
!(nativeSave && datasetType === "flow")) ||
|
|
87
164
|
(has("elementary_flow_create_new") && !has("elementary_flow_write")) ||
|
|
88
165
|
(has("canonical_support_local_mint") && !has("unitgroup_write") && !has("flowproperty_write")))
|
|
89
166
|
fail("execution_action_command_mismatch", "Authorized exception actions do not match the selected owner CLI write operation.");
|
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { createBatchContract, createBatchItemContract, parseBatchItemContract, } from "@tiangong-lca/cli/batch";
|
|
5
|
-
import { parseFoundryCommandSpec } from "@tiangong-lca/cli/command-spec";
|
|
5
|
+
import { parseFoundryCommandSpec, commandSpecOptionValue } from "@tiangong-lca/cli/command-spec";
|
|
6
6
|
import { createScopeAttemptLedgerService } from "./batch-orchestration/scope-attempt-ledger.js";
|
|
7
7
|
import { captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
8
8
|
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
@@ -254,7 +254,30 @@ export function inspectOwnerExecutions(context, entries) {
|
|
|
254
254
|
!Array.isArray(proof.blockers) ||
|
|
255
255
|
proof.blockers.length)
|
|
256
256
|
throw new FoundryContextError("execution_result_invalid", "Execution result has no verified readback.");
|
|
257
|
-
|
|
257
|
+
const native = commandSpecOptionValue(item.request.content.commit, "--execution-contract") !== null;
|
|
258
|
+
const referenceSpec = parseFoundryCommandSpec(item.request.content.verify);
|
|
259
|
+
const referenceSelected = commandSpecOptionValue(referenceSpec, "--reference-intent-file") !== null;
|
|
260
|
+
const referenceFacts = referenceSelected ? proof.reference_evidence : [];
|
|
261
|
+
const expectedReferenceFacts = referenceSpec.binding.artifacts.filter((fact) => ["reference_intent", "reference_precommit", "reference_review"].includes(fact.role));
|
|
262
|
+
if (!Array.isArray(referenceFacts) ||
|
|
263
|
+
(referenceSelected &&
|
|
264
|
+
(expectedReferenceFacts.length < 3 ||
|
|
265
|
+
referenceFacts.length !== expectedReferenceFacts.length ||
|
|
266
|
+
!expectedReferenceFacts.every((bound) => referenceFacts.some((raw) => {
|
|
267
|
+
const fact = workflowObject(raw);
|
|
268
|
+
return (typeof fact.path === "string" &&
|
|
269
|
+
path.resolve(context.assetRoot, bound.path) === path.resolve(fact.path) &&
|
|
270
|
+
bound.sha256 === fact.sha256 &&
|
|
271
|
+
bound.bytes === fact.bytes);
|
|
272
|
+
})))))
|
|
273
|
+
throw new FoundryContextError("execution_result_invalid", "Reference-intent completion requires every bound reference evidence fact.");
|
|
274
|
+
for (const raw of [
|
|
275
|
+
...referenceFacts,
|
|
276
|
+
proof.input,
|
|
277
|
+
proof.report,
|
|
278
|
+
proof.checks,
|
|
279
|
+
...(native ? [proof.commit_report] : []),
|
|
280
|
+
]) {
|
|
258
281
|
const fact = workflowObject(raw);
|
|
259
282
|
if (typeof fact.path !== "string")
|
|
260
283
|
throw new FoundryContextError("execution_result_invalid", "Readback content fact is missing.");
|
|
@@ -12,6 +12,8 @@ export declare function readbackFoundryOwner(context: FoundryRuntimeContext, qua
|
|
|
12
12
|
command: import("@tiangong-lca/cli/command-spec").FoundryCommandSpec;
|
|
13
13
|
report: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
|
|
14
14
|
checks: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
|
|
15
|
+
commit_report?: import("./foundry-runtime-context-types.ts").FoundryInputFact | null | undefined;
|
|
16
|
+
reference_evidence?: import("./foundry-runtime-context-types.ts").FoundryInputFact[] | undefined;
|
|
15
17
|
original_verification: {
|
|
16
18
|
report: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
|
|
17
19
|
checks: import("./foundry-runtime-context-types.ts").FoundryInputFact | null;
|
|
@@ -62,6 +62,28 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
62
62
|
fs.writeFileSync(path.join(output, "stdout.json"), result.stdout ?? "");
|
|
63
63
|
fs.writeFileSync(path.join(output, "stderr.log"), result.stderr ?? "");
|
|
64
64
|
const blockers = [];
|
|
65
|
+
const native = commandSpecOptionValue(request.content.commit, "--execution-contract") !== null;
|
|
66
|
+
let commitFact = null;
|
|
67
|
+
if (native) {
|
|
68
|
+
try {
|
|
69
|
+
const commitOutput = commandSpecOptionValue(request.content.commit, "--out-dir");
|
|
70
|
+
if (!commitOutput)
|
|
71
|
+
throw new Error("Native output is missing.");
|
|
72
|
+
const candidate = resolveFoundryOutput(context, commitReport ?? path.join(commitOutput, "outputs", "dataset-save-draft", "summary.json"));
|
|
73
|
+
if (path.relative(commitOutput, candidate).startsWith("..") ||
|
|
74
|
+
!fs.lstatSync(candidate).isFile() ||
|
|
75
|
+
fs.lstatSync(candidate).isSymbolicLink())
|
|
76
|
+
throw new Error("Native receipt must be contained and regular.");
|
|
77
|
+
commitFact = captureFoundryInput(candidate);
|
|
78
|
+
commitReport = candidate;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
blockers.push({
|
|
82
|
+
code: "native_execution_report_required",
|
|
83
|
+
message: "Native insert recovery requires the original matching CLI execution report; root readback alone cannot prove contract consumption.",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
65
87
|
let report = {}, reportFile = null, checksFile = null;
|
|
66
88
|
try {
|
|
67
89
|
report = workflowObject(JSON.parse(result.stdout));
|
|
@@ -93,6 +115,7 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
93
115
|
checks: checksFile ? captureFoundryInput(checksFile) : null,
|
|
94
116
|
};
|
|
95
117
|
let acceptance = null;
|
|
118
|
+
let referenceFacts = [];
|
|
96
119
|
if (!blockers.length &&
|
|
97
120
|
reportFile &&
|
|
98
121
|
!result.error &&
|
|
@@ -133,7 +156,8 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
133
156
|
environment,
|
|
134
157
|
tidasExecutable: qualified.tidas.executable_path,
|
|
135
158
|
});
|
|
136
|
-
owners.closeout.validatePostWriteVerifyForCloseout({
|
|
159
|
+
const rootProof = owners.closeout.validatePostWriteVerifyForCloseout({
|
|
160
|
+
handoffPlan: JSON.parse(readFoundryInput(context, request.handoff_file).toString("utf8")),
|
|
137
161
|
verifyReport: report,
|
|
138
162
|
verifyReportPath: reportFile,
|
|
139
163
|
finalRowsFile: request.content.input.path,
|
|
@@ -144,6 +168,11 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
144
168
|
allowTraceHashOnlyNormalization: request.policy.account_mode !== "production-test",
|
|
145
169
|
blockers,
|
|
146
170
|
});
|
|
171
|
+
referenceFacts = (rootProof.referenceArtifacts ?? []).map(({ path, sha256, bytes }) => ({
|
|
172
|
+
path,
|
|
173
|
+
sha256,
|
|
174
|
+
bytes,
|
|
175
|
+
}));
|
|
147
176
|
blockers.push(...buildReferenceClosureBlockers({
|
|
148
177
|
repoRoot: context.assetRoot,
|
|
149
178
|
rows,
|
|
@@ -152,21 +181,41 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
152
181
|
allowAccountLocalSupportAndElementary: false,
|
|
153
182
|
}));
|
|
154
183
|
if (commitReport) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
184
|
+
try {
|
|
185
|
+
const closed = workflowObject(owners.closeout.runDatasetPostWriteCloseout({
|
|
186
|
+
handoffPlan: request.handoff_file,
|
|
187
|
+
commitReport,
|
|
188
|
+
postWriteVerifyReport: reportFile,
|
|
189
|
+
rowsFile: request.content.input.path,
|
|
190
|
+
finalizeReport: request.finalize_file,
|
|
191
|
+
mutationManifest: request.mutation_file,
|
|
192
|
+
outDir: path.join(output, "closeout"),
|
|
193
|
+
targetUserId: request.policy.user_id,
|
|
194
|
+
stateCode: "0",
|
|
195
|
+
}));
|
|
196
|
+
if (closed.status !== "completed")
|
|
197
|
+
blockers.push({ code: "owner_closeout_blocked", report: closed });
|
|
198
|
+
if (commitFact && captureFoundryInput(commitReport).sha256 !== commitFact.sha256)
|
|
199
|
+
throw new Error("Native receipt changed during verification.");
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (!native)
|
|
203
|
+
throw error;
|
|
204
|
+
blockers.push({
|
|
205
|
+
code: "native_execution_evidence_invalid",
|
|
206
|
+
message: "Native execution receipt could not be verified.",
|
|
207
|
+
});
|
|
208
|
+
}
|
|
168
209
|
}
|
|
169
210
|
}
|
|
211
|
+
for (const fact of referenceFacts) {
|
|
212
|
+
const current = captureFoundryInput(fact.path);
|
|
213
|
+
if (current.sha256 !== fact.sha256 || current.bytes !== fact.bytes)
|
|
214
|
+
blockers.push({
|
|
215
|
+
code: "reference_intent_evidence_invalid",
|
|
216
|
+
message: "Reference evidence changed during owner readback.",
|
|
217
|
+
});
|
|
218
|
+
}
|
|
170
219
|
readFoundryInput(context, request.content.input.path);
|
|
171
220
|
const proof = {
|
|
172
221
|
schema: "tiangong-foundry.owner-readback.v1",
|
|
@@ -176,6 +225,8 @@ export async function readbackFoundryOwner(context, qualified, request, authenti
|
|
|
176
225
|
command: spec,
|
|
177
226
|
report: reportFile ? captureFoundryInput(reportFile) : null,
|
|
178
227
|
checks: checksFile ? captureFoundryInput(checksFile) : null,
|
|
228
|
+
...(native ? { commit_report: commitFact } : {}),
|
|
229
|
+
...(referenceFacts.length ? { reference_evidence: referenceFacts } : {}),
|
|
179
230
|
original_verification: original,
|
|
180
231
|
acceptance,
|
|
181
232
|
blockers,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export declare const FOUNDRY_PACKAGE_DESCRIPTOR_SCHEMA: "tiangong-foundry.package-descriptor.v1";
|
|
2
2
|
export declare const foundryPackageDescriptorPath: "package-dist/assets/foundry-package-descriptor.json";
|
|
3
|
-
export declare const foundryPackageStaticFiles: readonly ["package-dist/", "specs/import-profiles.json", "specs/prewrite-content-policy.json", "specs/canonical-support/flow-properties-unit-groups.json", "specs/schemas/authorization-derivation.schema.json", "specs/schemas/execution-context.schema.json", "specs/schemas/foundry-facade-request-index.schema.json", "specs/schemas/foundry-operation-result.schema.json", "specs/schemas/foundry-package-descriptor.schema.json", "specs/schemas/foundry-task-start.schema.json", "specs/schemas/foundry-semantic-input.schema.json", "specs/schemas/foundry-authorization-input.schema.json", "specs/schemas/foundry-workspace-migration-plan.schema.json", "specs/schemas/foundry-workspace-migration-transfer-plan.schema.json", "specs/schemas/foundry-migration-transfer-receipt.schema.json", "specs/schemas/foundry-workspace-migration-pending.schema.json", "specs/schemas/foundry-migration-adoption-plan.schema.json", "specs/schemas/foundry-migration-activation.schema.json", "specs/schemas/foundry-workspace-v2.schema.json", "specs/schemas/foundry-runtime-selection.schema.json", "specs/schemas/foundry-managed-runtime.schema.json", "specs/schemas/runtime-qualification.schema.json", "specs/schemas/task-authorization.schema.json", "specs/schemas/tidas-runtime-expectation.schema.json", "docs/architecture.md", "docs/package-distribution-contract.md", "docs/foundry-task-contracts.md", "docs/public-runtime-contract.md", "docs/runtime-context-contract.md", "docs/workspace-migration-contract.md", "docs/safety-policy.md", "docs/task-authorization-contract.md", "docs/import-profiles/bafu/constraints.md", "docs/import-profiles/bafu/leaf-process-classification-authoring.md", "docs/import-profiles/bafu/profile.md", "docs/import-profiles/uslci/constraints.md", "docs/import-profiles/uslci/profile.md", "docs/uslci-import-runbook.md", "docs/import-profiles/worldsteel/constraints.md", "docs/import-profiles/worldsteel/import-coverage.md", "docs/import-profiles/worldsteel/import-plan.md", "docs/import-profiles/worldsteel/profile.md", "README.md", "LICENSE"];
|
|
3
|
+
export declare const foundryPackageStaticFiles: readonly ["package-dist/", "specs/import-profiles.json", "specs/prewrite-content-policy.json", "specs/canonical-support/flow-properties-unit-groups.json", "specs/schemas/authorization-derivation.schema.json", "specs/schemas/execution-context.schema.json", "specs/schemas/foundry-facade-request-index.schema.json", "specs/schemas/foundry-operation-result.schema.json", "specs/schemas/foundry-package-descriptor.schema.json", "specs/schemas/foundry-task-start.schema.json", "specs/schemas/foundry-semantic-input.schema.json", "specs/schemas/foundry-authorization-input.schema.json", "specs/schemas/foundry-reference-input.schema.json", "specs/schemas/foundry-workspace-migration-plan.schema.json", "specs/schemas/foundry-workspace-migration-transfer-plan.schema.json", "specs/schemas/foundry-migration-transfer-receipt.schema.json", "specs/schemas/foundry-workspace-migration-pending.schema.json", "specs/schemas/foundry-migration-adoption-plan.schema.json", "specs/schemas/foundry-migration-activation.schema.json", "specs/schemas/foundry-workspace-v2.schema.json", "specs/schemas/foundry-runtime-selection.schema.json", "specs/schemas/foundry-managed-runtime.schema.json", "specs/schemas/runtime-qualification.schema.json", "specs/schemas/task-authorization.schema.json", "specs/schemas/tidas-runtime-expectation.schema.json", "docs/architecture.md", "docs/package-distribution-contract.md", "docs/foundry-task-contracts.md", "docs/public-runtime-contract.md", "docs/runtime-context-contract.md", "docs/workspace-migration-contract.md", "docs/safety-policy.md", "docs/task-authorization-contract.md", "docs/import-profiles/bafu/constraints.md", "docs/import-profiles/bafu/leaf-process-classification-authoring.md", "docs/import-profiles/bafu/profile.md", "docs/import-profiles/uslci/constraints.md", "docs/import-profiles/uslci/profile.md", "docs/uslci-import-runbook.md", "docs/import-profiles/worldsteel/constraints.md", "docs/import-profiles/worldsteel/import-coverage.md", "docs/import-profiles/worldsteel/import-plan.md", "docs/import-profiles/worldsteel/profile.md", "README.md", "LICENSE"];
|
|
4
4
|
declare const packageName = "@tiangong-lca/foundry";
|
|
5
|
-
declare const packageVersion = "0.1.
|
|
5
|
+
declare const packageVersion = "0.1.8";
|
|
6
6
|
declare const cliPackageName = "@tiangong-lca/cli";
|
|
7
|
-
declare const cliPackageVersion = "0.1.
|
|
7
|
+
declare const cliPackageVersion = "0.1.14";
|
|
8
8
|
declare const packageBin = "package-dist/scripts/package-entry.js";
|
|
9
9
|
declare const packageApi = "package-dist/scripts/public-api.js";
|
|
10
10
|
declare const packageTypes = "package-dist/scripts/public-api.d.ts";
|
|
11
11
|
declare const supportedPlatforms: readonly ["linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"];
|
|
12
|
-
declare const protocolSchemas: readonly ["tiangong-foundry.operation-result.v1", "tiangong-foundry.task-start.v1", "tiangong-foundry.semantic-input.v1", "tiangong-foundry.authorization-input.v1", "tiangong-foundry.facade-request-index.v1", "tiangong-foundry.workspace-migration-plan.v1", "tiangong-foundry.workspace-migration-transfer-plan.v2", "tiangong-foundry.migration-transfer-receipt.v1", "tiangong-foundry.workspace-migration-pending.v1", "tiangong-foundry.migration-adoption-plan.v1", "tiangong-foundry.migration-activation.v1", "tiangong-foundry.workspace.v2", "tiangong-foundry.workspace-runtime-selection.v1", "tiangong-foundry.managed-runtime.v1", "tiangong-foundry.runtime-qualification.v1", "tiangong-foundry.tidas-runtime-expectation.v1", "tiangong-foundry.execution-context.v1", "tiangong-foundry.authorization-derivation.v1", "tiangong-foundry.task-authorization.v1"];
|
|
12
|
+
declare const protocolSchemas: readonly ["tiangong-foundry.operation-result.v1", "tiangong-foundry.task-start.v1", "tiangong-foundry.semantic-input.v1", "tiangong-foundry.authorization-input.v1", "tiangong-foundry.reference-input.v1", "tiangong-foundry.facade-request-index.v1", "tiangong-foundry.workspace-migration-plan.v1", "tiangong-foundry.workspace-migration-transfer-plan.v2", "tiangong-foundry.migration-transfer-receipt.v1", "tiangong-foundry.workspace-migration-pending.v1", "tiangong-foundry.migration-adoption-plan.v1", "tiangong-foundry.migration-activation.v1", "tiangong-foundry.workspace.v2", "tiangong-foundry.workspace-runtime-selection.v1", "tiangong-foundry.managed-runtime.v1", "tiangong-foundry.runtime-qualification.v1", "tiangong-foundry.tidas-runtime-expectation.v1", "tiangong-foundry.execution-context.v1", "tiangong-foundry.authorization-derivation.v1", "tiangong-foundry.task-authorization.v1"];
|
|
13
13
|
export interface FoundryPackageFileFact {
|
|
14
14
|
readonly path: string;
|
|
15
15
|
readonly bytes: number;
|
|
@@ -17,6 +17,7 @@ export const foundryPackageStaticFiles = Object.freeze([
|
|
|
17
17
|
"specs/schemas/foundry-task-start.schema.json",
|
|
18
18
|
"specs/schemas/foundry-semantic-input.schema.json",
|
|
19
19
|
"specs/schemas/foundry-authorization-input.schema.json",
|
|
20
|
+
"specs/schemas/foundry-reference-input.schema.json",
|
|
20
21
|
"specs/schemas/foundry-workspace-migration-plan.schema.json",
|
|
21
22
|
"specs/schemas/foundry-workspace-migration-transfer-plan.schema.json",
|
|
22
23
|
"specs/schemas/foundry-migration-transfer-receipt.schema.json",
|
|
@@ -51,10 +52,10 @@ export const foundryPackageStaticFiles = Object.freeze([
|
|
|
51
52
|
"LICENSE",
|
|
52
53
|
]);
|
|
53
54
|
const packageName = "@tiangong-lca/foundry";
|
|
54
|
-
const packageVersion = "0.1.
|
|
55
|
+
const packageVersion = "0.1.8";
|
|
55
56
|
const packageDescription = "Control plane for TianGong LCA external dataset import and TIDAS authoring work.";
|
|
56
57
|
const cliPackageName = "@tiangong-lca/cli";
|
|
57
|
-
const cliPackageVersion = "0.1.
|
|
58
|
+
const cliPackageVersion = "0.1.14";
|
|
58
59
|
const packageBin = "package-dist/scripts/package-entry.js";
|
|
59
60
|
const packageApi = "package-dist/scripts/public-api.js";
|
|
60
61
|
const packageTypes = "package-dist/scripts/public-api.d.ts";
|
|
@@ -69,6 +70,7 @@ const protocolSchemas = Object.freeze([
|
|
|
69
70
|
"tiangong-foundry.task-start.v1",
|
|
70
71
|
"tiangong-foundry.semantic-input.v1",
|
|
71
72
|
"tiangong-foundry.authorization-input.v1",
|
|
73
|
+
"tiangong-foundry.reference-input.v1",
|
|
72
74
|
"tiangong-foundry.facade-request-index.v1",
|
|
73
75
|
"tiangong-foundry.workspace-migration-plan.v1",
|
|
74
76
|
"tiangong-foundry.workspace-migration-transfer-plan.v2",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
3
|
+
export declare const FOUNDRY_REFERENCE_INPUT_SCHEMA: "tiangong-foundry.reference-input.v1";
|
|
4
|
+
type FileSelection = {
|
|
5
|
+
file: string;
|
|
6
|
+
sha256: string;
|
|
7
|
+
};
|
|
8
|
+
export interface FoundryReferenceInput {
|
|
9
|
+
schema: typeof FOUNDRY_REFERENCE_INPUT_SCHEMA;
|
|
10
|
+
task_id: string;
|
|
11
|
+
actor_id: string;
|
|
12
|
+
rows_manifest_sha256: string;
|
|
13
|
+
dataset_type: string;
|
|
14
|
+
qa_reference_rows: readonly FileSelection[];
|
|
15
|
+
intent: FileSelection | null;
|
|
16
|
+
review_files: readonly FileSelection[];
|
|
17
|
+
}
|
|
18
|
+
interface SelectedReferenceInput {
|
|
19
|
+
spec: FoundryReferenceInput;
|
|
20
|
+
descriptor: FoundryInputFact;
|
|
21
|
+
qa: readonly FoundryInputFact[];
|
|
22
|
+
intent: FoundryInputFact | null;
|
|
23
|
+
reviews: readonly FoundryInputFact[];
|
|
24
|
+
}
|
|
25
|
+
export declare function parseFoundryReferenceInput(value: unknown): FoundryReferenceInput;
|
|
26
|
+
export declare function selectFoundryReferenceInput(context: FoundryRuntimeContext, descriptorFile: string): SelectedReferenceInput;
|
|
27
|
+
export declare function recordFoundryReferenceInput(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[], selected: SelectedReferenceInput): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { captureFoundryInput, readFoundryInput, FoundryContextError, } from "./foundry-runtime-context.js";
|
|
5
|
+
import { assertNotFoundrySessionFile, migrationCredentialPath } from "./foundry-private-path.js";
|
|
6
|
+
import { readSelectedSemanticBytes } from "./foundry-semantic-input.js";
|
|
7
|
+
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./foundry-workflow-state.js";
|
|
8
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
9
|
+
export const FOUNDRY_REFERENCE_INPUT_SCHEMA = "tiangong-foundry.reference-input.v1";
|
|
10
|
+
const selections = new WeakSet();
|
|
11
|
+
const sha = /^[a-f0-9]{64}$/u;
|
|
12
|
+
function invalid(message) {
|
|
13
|
+
throw new FoundryContextError("reference_input_invalid", message);
|
|
14
|
+
}
|
|
15
|
+
function exact(value, keys) {
|
|
16
|
+
if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
|
|
17
|
+
invalid("Reference input has missing or unsupported fields.");
|
|
18
|
+
}
|
|
19
|
+
function file(value) {
|
|
20
|
+
const selected = workflowObject(value);
|
|
21
|
+
exact(selected, ["file", "sha256"]);
|
|
22
|
+
if (typeof selected.file !== "string" ||
|
|
23
|
+
!selected.file.trim() ||
|
|
24
|
+
selected.file.length > 4096 ||
|
|
25
|
+
/[\0\r\n]/u.test(selected.file) ||
|
|
26
|
+
typeof selected.sha256 !== "string" ||
|
|
27
|
+
!sha.test(selected.sha256))
|
|
28
|
+
invalid("Reference file selection is invalid.");
|
|
29
|
+
return Object.freeze({ file: selected.file, sha256: selected.sha256 });
|
|
30
|
+
}
|
|
31
|
+
export function parseFoundryReferenceInput(value) {
|
|
32
|
+
const data = workflowObject(value);
|
|
33
|
+
exact(data, [
|
|
34
|
+
"schema",
|
|
35
|
+
"task_id",
|
|
36
|
+
"actor_id",
|
|
37
|
+
"rows_manifest_sha256",
|
|
38
|
+
"dataset_type",
|
|
39
|
+
"qa_reference_rows",
|
|
40
|
+
"intent",
|
|
41
|
+
"review_files",
|
|
42
|
+
]);
|
|
43
|
+
if (data.schema !== FOUNDRY_REFERENCE_INPUT_SCHEMA ||
|
|
44
|
+
typeof data.task_id !== "string" ||
|
|
45
|
+
!/^task-[0-9a-f]{64}-r[0-9]{4}$/u.test(data.task_id) ||
|
|
46
|
+
typeof data.actor_id !== "string" ||
|
|
47
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(data.actor_id) ||
|
|
48
|
+
typeof data.rows_manifest_sha256 !== "string" ||
|
|
49
|
+
!sha.test(data.rows_manifest_sha256) ||
|
|
50
|
+
typeof data.dataset_type !== "string" ||
|
|
51
|
+
![
|
|
52
|
+
"process",
|
|
53
|
+
"flow",
|
|
54
|
+
"source",
|
|
55
|
+
"contact",
|
|
56
|
+
"lifecyclemodel",
|
|
57
|
+
"unitgroup",
|
|
58
|
+
"flowproperty",
|
|
59
|
+
].includes(data.dataset_type) ||
|
|
60
|
+
!Array.isArray(data.qa_reference_rows) ||
|
|
61
|
+
!Array.isArray(data.review_files) ||
|
|
62
|
+
data.qa_reference_rows.length > 128 ||
|
|
63
|
+
data.review_files.length > 128)
|
|
64
|
+
invalid("Reference input scope or file lists are invalid.");
|
|
65
|
+
const qa = data.qa_reference_rows.map(file), reviews = data.review_files.map(file), intent = data.intent === null ? null : file(data.intent);
|
|
66
|
+
if ((!qa.length && !intent) ||
|
|
67
|
+
(qa.length && data.dataset_type !== "process") ||
|
|
68
|
+
Boolean(intent) !== Boolean(reviews.length))
|
|
69
|
+
invalid("Select Process QA references and/or one intent with its explicit reviews.");
|
|
70
|
+
return Object.freeze({
|
|
71
|
+
schema: FOUNDRY_REFERENCE_INPUT_SCHEMA,
|
|
72
|
+
task_id: data.task_id,
|
|
73
|
+
actor_id: data.actor_id,
|
|
74
|
+
rows_manifest_sha256: data.rows_manifest_sha256,
|
|
75
|
+
dataset_type: data.dataset_type,
|
|
76
|
+
qa_reference_rows: Object.freeze(qa),
|
|
77
|
+
intent,
|
|
78
|
+
review_files: Object.freeze(reviews),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function selectFoundryReferenceInput(context, descriptorFile) {
|
|
82
|
+
let total = 0;
|
|
83
|
+
const capture = (name) => {
|
|
84
|
+
if (!name.trim() || name.length > 4096 || /[\0\r\n]/u.test(name))
|
|
85
|
+
invalid("Reference input path is invalid.");
|
|
86
|
+
const target = path.resolve(context.workspaceRoot, name);
|
|
87
|
+
if (migrationCredentialPath(path.relative(context.workspaceRoot, target)))
|
|
88
|
+
invalid("Credential paths cannot be reference inputs.");
|
|
89
|
+
assertNotFoundrySessionFile(target, context.accountIntent?.sessionReference);
|
|
90
|
+
const stat = fs.lstatSync(target);
|
|
91
|
+
if (!stat.isFile() || stat.size > 8 * 1024 * 1024)
|
|
92
|
+
invalid("Reference inputs must be bounded regular files.");
|
|
93
|
+
total += stat.size;
|
|
94
|
+
if (total > 64 * 1024 * 1024)
|
|
95
|
+
invalid("Reference input selection exceeds 64 MiB.");
|
|
96
|
+
return Object.freeze(captureFoundryInput(target));
|
|
97
|
+
};
|
|
98
|
+
const descriptor = capture(descriptorFile);
|
|
99
|
+
let spec;
|
|
100
|
+
try {
|
|
101
|
+
spec = parseFoundryReferenceInput(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(readSelectedSemanticBytes(descriptor))));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
invalid("Select a complete supported reference-input descriptor.");
|
|
105
|
+
}
|
|
106
|
+
if (spec.task_id !== context.taskId || spec.actor_id !== context.actorId)
|
|
107
|
+
invalid("Reference selection belongs to another task or actor.");
|
|
108
|
+
const selected = (entry) => {
|
|
109
|
+
const fact = capture(entry.file);
|
|
110
|
+
if (fact.sha256 !== entry.sha256)
|
|
111
|
+
invalid("Reference input bytes differ from the selected digest.");
|
|
112
|
+
return fact;
|
|
113
|
+
};
|
|
114
|
+
const result = Object.freeze({
|
|
115
|
+
spec,
|
|
116
|
+
descriptor,
|
|
117
|
+
qa: Object.freeze(spec.qa_reference_rows.map(selected)),
|
|
118
|
+
intent: spec.intent ? selected(spec.intent) : null,
|
|
119
|
+
reviews: Object.freeze(spec.review_files.map(selected)),
|
|
120
|
+
});
|
|
121
|
+
if (new Set(result.qa.map((fact) => fact.path)).size !== result.qa.length ||
|
|
122
|
+
new Set(result.reviews.map((fact) => fact.path)).size !== result.reviews.length)
|
|
123
|
+
invalid("Select each reference file only once.");
|
|
124
|
+
selections.add(result);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function assertSelected(selected) {
|
|
128
|
+
if (!selections.has(selected))
|
|
129
|
+
invalid("Reference input must be selected by the current host.");
|
|
130
|
+
for (const fact of [
|
|
131
|
+
selected.descriptor,
|
|
132
|
+
...selected.qa,
|
|
133
|
+
...selected.reviews,
|
|
134
|
+
...(selected.intent ? [selected.intent] : []),
|
|
135
|
+
])
|
|
136
|
+
readSelectedSemanticBytes(fact);
|
|
137
|
+
}
|
|
138
|
+
export async function recordFoundryReferenceInput(context, entries, selected) {
|
|
139
|
+
assertSelected(selected);
|
|
140
|
+
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
141
|
+
if (!rows || rows.entry.sha256 !== selected.spec.rows_manifest_sha256)
|
|
142
|
+
invalid("Reference input requires the current row manifest.");
|
|
143
|
+
const set = rows.value.sets.find((item) => item.type === selected.spec.dataset_type);
|
|
144
|
+
if (!set)
|
|
145
|
+
invalid("Reference selection has no current dataset scope.");
|
|
146
|
+
const assertUnprepared = (index) => {
|
|
147
|
+
if (index.some((entry) => entry.command === "dataset-workflow-execution-prepare" &&
|
|
148
|
+
path.basename(entry.path) === "owner-execution-request.json" &&
|
|
149
|
+
workflowObject(readWorkflowArtifact(context, entry).value.policy).dataset_type ===
|
|
150
|
+
selected.spec.dataset_type))
|
|
151
|
+
invalid("A prepared or consumed owner scope cannot replace reference inputs.");
|
|
152
|
+
};
|
|
153
|
+
assertUnprepared(entries);
|
|
154
|
+
const previous = state.referenceInputs.get(set.type)?.entry.sha256 ?? null;
|
|
155
|
+
readFoundryInput(context, set.file);
|
|
156
|
+
const input = captureFoundryInput(set.file);
|
|
157
|
+
const existing = state.referenceInputs.get(set.type);
|
|
158
|
+
if (existing?.value.source_sha256 === selected.descriptor.sha256)
|
|
159
|
+
return existing.value;
|
|
160
|
+
let intentValue = null;
|
|
161
|
+
const reviewPointers = [];
|
|
162
|
+
if (selected.intent) {
|
|
163
|
+
try {
|
|
164
|
+
intentValue = workflowObject(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(readSelectedSemanticBytes(selected.intent))));
|
|
165
|
+
if (intentValue.schema_version !== "dataset-exact-reference-intent.v1" ||
|
|
166
|
+
!Array.isArray(intentValue.references) ||
|
|
167
|
+
!intentValue.references.length)
|
|
168
|
+
invalid("Reference intent does not expose the supported explicit review locators.");
|
|
169
|
+
for (const value of intentValue.references) {
|
|
170
|
+
const review = workflowObject(workflowObject(value).review);
|
|
171
|
+
if (typeof review.file !== "string")
|
|
172
|
+
invalid("Reference review locator is missing.");
|
|
173
|
+
const canonical = fs.realpathSync(path.resolve(path.dirname(selected.intent.path), review.file));
|
|
174
|
+
const fact = selected.reviews.find((item) => item.path === canonical && item.sha256 === review.sha256);
|
|
175
|
+
if (!fact)
|
|
176
|
+
invalid("Every intent review must match an independently selected file and digest.");
|
|
177
|
+
reviewPointers.push({ value: review, source: fact });
|
|
178
|
+
}
|
|
179
|
+
if (new Set(reviewPointers.map((item) => item.source.path)).size !== selected.reviews.length)
|
|
180
|
+
invalid("Reference selection contains unused review files.");
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
invalid("Reference intent and independently selected reviews do not match.");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const output = path.join(context.taskRoot, "outputs", "reference-input", randomUUID());
|
|
187
|
+
return runFoundryTaskOperation(context, {
|
|
188
|
+
command: "dataset-workflow-reference-input",
|
|
189
|
+
options: { descriptor: selected.descriptor, input, rows_manifest_sha256: rows.entry.sha256 },
|
|
190
|
+
validateCurrent(index) {
|
|
191
|
+
assertSelected(selected);
|
|
192
|
+
assertUnprepared(index);
|
|
193
|
+
if ((currentWorkflowState(context, index).referenceInputs.get(set.type)?.entry.sha256 ??
|
|
194
|
+
null) !== previous)
|
|
195
|
+
invalid("Reference selection changed concurrently.");
|
|
196
|
+
if (currentWorkflowState(context, index).rows?.entry.sha256 !== rows.entry.sha256)
|
|
197
|
+
invalid("Rows changed during reference selection.");
|
|
198
|
+
},
|
|
199
|
+
}, (operation) => {
|
|
200
|
+
const snapshot = (fact, name) => {
|
|
201
|
+
const target = path.join(output, name);
|
|
202
|
+
operation.writeText(target, readSelectedSemanticBytes(fact));
|
|
203
|
+
const captured = captureFoundryInput(target);
|
|
204
|
+
if (captured.sha256 !== fact.sha256 || captured.bytes !== fact.bytes)
|
|
205
|
+
invalid("Reference snapshot differs from selected bytes.");
|
|
206
|
+
return captured;
|
|
207
|
+
};
|
|
208
|
+
const qa = selected.qa.map((fact, index) => snapshot(fact, `qa-${index}${path.extname(fact.path).toLowerCase() === ".jsonl" ? ".jsonl" : ".json"}`));
|
|
209
|
+
const reviews = selected.reviews.map((fact, index) => snapshot(fact, `review-${index}.json`));
|
|
210
|
+
let intent = null;
|
|
211
|
+
if (selected.intent && intentValue) {
|
|
212
|
+
snapshot(selected.intent, "original-intent.json");
|
|
213
|
+
for (const pointer of reviewPointers)
|
|
214
|
+
pointer.value.file = reviews[selected.reviews.indexOf(pointer.source)].path;
|
|
215
|
+
const target = path.join(output, "intent.json");
|
|
216
|
+
operation.writeJson(target, intentValue);
|
|
217
|
+
intent = captureFoundryInput(target);
|
|
218
|
+
}
|
|
219
|
+
snapshot(selected.descriptor, "descriptor.json");
|
|
220
|
+
const result = {
|
|
221
|
+
schema: "tiangong-foundry.reference-selection.v1",
|
|
222
|
+
status: "selected",
|
|
223
|
+
dataset_type: set.type,
|
|
224
|
+
rows_manifest_sha256: rows.entry.sha256,
|
|
225
|
+
source_sha256: selected.descriptor.sha256,
|
|
226
|
+
input,
|
|
227
|
+
qa_files: qa,
|
|
228
|
+
intent,
|
|
229
|
+
review_files: reviews,
|
|
230
|
+
grants_permission: false,
|
|
231
|
+
};
|
|
232
|
+
operation.writeJson(path.join(output, "foundry-reference-input.json"), result);
|
|
233
|
+
return result;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
@@ -157,8 +157,8 @@ export function qualifyFoundryRuntime(context, options) {
|
|
|
157
157
|
catch {
|
|
158
158
|
return fail("runtime_cli_unqualified", "CLI runtime bytes do not match the independently selected C1 expectation.");
|
|
159
159
|
}
|
|
160
|
-
if (cli.package.version !== "0.1.
|
|
161
|
-
fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.
|
|
160
|
+
if (cli.package.version !== "0.1.14" || cli.platform !== context.platform)
|
|
161
|
+
fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.14 C1 runtime on the selected platform.");
|
|
162
162
|
const cliExpectation = Object.freeze({ ...options.cliExpectation });
|
|
163
163
|
if (cliExpectation.schema !== CLI_RUNTIME_EXPECTATION_SCHEMA)
|
|
164
164
|
fail("runtime_cli_unqualified", "CLI runtime expectation is not the supported schema.");
|
|
@@ -8,7 +8,7 @@ import { runtimeEnvFilePolicyDisabled, runtimeEnvFilePolicyKey, } from "./foundr
|
|
|
8
8
|
import { resolveFoundryRuntimePaths } from "./foundry-runtime-paths.js";
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
10
|
const tiangongLcaCliPackageName = "@tiangong-lca/cli";
|
|
11
|
-
const tiangongLcaCliPackageVersion = "0.1.
|
|
11
|
+
const tiangongLcaCliPackageVersion = "0.1.14";
|
|
12
12
|
const tiangongLcaCliBinName = "tiangong-lca";
|
|
13
13
|
const { repoRoot: foundryRepoRoot } = resolveFoundryRuntimePaths(import.meta.url);
|
|
14
14
|
function isRecord(value) {
|