@tiangong-lca/foundry 0.1.6 → 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.
Files changed (64) hide show
  1. package/README.md +7 -5
  2. package/docs/architecture.md +7 -5
  3. package/docs/foundry-task-contracts.md +4 -4
  4. package/docs/import-profiles/worldsteel/constraints.md +3 -3
  5. package/docs/import-profiles/worldsteel/import-coverage.md +3 -3
  6. package/docs/import-profiles/worldsteel/import-plan.md +1 -1
  7. package/docs/import-profiles/worldsteel/profile.md +3 -3
  8. package/docs/package-distribution-contract.md +11 -7
  9. package/docs/public-runtime-contract.md +23 -7
  10. package/docs/runtime-context-contract.md +11 -5
  11. package/docs/task-authorization-contract.md +8 -4
  12. package/package-dist/assets/foundry-package-descriptor.json +166 -90
  13. package/package-dist/scripts/foundry-facade.d.ts +1 -0
  14. package/package-dist/scripts/foundry-facade.js +35 -4
  15. package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +65 -10
  16. package/package-dist/scripts/lib/finalize-owners/finalize-reference-inputs.d.ts +12 -0
  17. package/package-dist/scripts/lib/finalize-owners/finalize-reference-inputs.js +57 -0
  18. package/package-dist/scripts/lib/finalize-owners/handoff-reference-intent.d.ts +28 -0
  19. package/package-dist/scripts/lib/finalize-owners/handoff-reference-intent.js +115 -0
  20. package/package-dist/scripts/lib/finalize-owners/native-insert-closeout.d.ts +13 -0
  21. package/package-dist/scripts/lib/finalize-owners/native-insert-closeout.js +99 -0
  22. package/package-dist/scripts/lib/finalize-owners/native-insert-handoff.d.ts +47 -0
  23. package/package-dist/scripts/lib/finalize-owners/native-insert-handoff.js +146 -0
  24. package/package-dist/scripts/lib/finalize-owners/post-authoring.js +13 -0
  25. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.d.ts +8 -2
  26. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +48 -2
  27. package/package-dist/scripts/lib/finalize-owners/reference-intent-closeout.d.ts +12 -0
  28. package/package-dist/scripts/lib/finalize-owners/reference-intent-closeout.js +77 -0
  29. package/package-dist/scripts/lib/foundry-authorization-input.d.ts +8 -0
  30. package/package-dist/scripts/lib/foundry-authorization-input.js +68 -1
  31. package/package-dist/scripts/lib/foundry-command-metadata.js +15 -1
  32. package/package-dist/scripts/lib/foundry-execution-admission.js +82 -5
  33. package/package-dist/scripts/lib/foundry-managed-actions.d.ts +4 -0
  34. package/package-dist/scripts/lib/foundry-managed-actions.js +56 -0
  35. package/package-dist/scripts/lib/foundry-managed-host.d.ts +2 -2
  36. package/package-dist/scripts/lib/foundry-managed-host.js +2 -0
  37. package/package-dist/scripts/lib/foundry-owner-execution-store.js +25 -2
  38. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +2 -0
  39. package/package-dist/scripts/lib/foundry-owner-readback.js +65 -14
  40. package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
  41. package/package-dist/scripts/lib/foundry-package-contract.js +4 -2
  42. package/package-dist/scripts/lib/foundry-reference-input.d.ts +28 -0
  43. package/package-dist/scripts/lib/foundry-reference-input.js +235 -0
  44. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  45. package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
  46. package/package-dist/scripts/lib/foundry-task-store.d.ts +1 -1
  47. package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +2 -1
  48. package/package-dist/scripts/lib/foundry-workflow-authorization.js +38 -2
  49. package/package-dist/scripts/lib/foundry-workflow-execution.js +7 -1
  50. package/package-dist/scripts/lib/foundry-workflow-finalize.js +43 -1
  51. package/package-dist/scripts/lib/foundry-workflow-state.d.ts +2 -0
  52. package/package-dist/scripts/lib/foundry-workflow-state.js +31 -2
  53. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  54. package/package-dist/scripts/public-api.d.ts +1 -0
  55. package/package-dist/scripts/runtime-entry.d.ts +5 -1
  56. package/package-dist/scripts/runtime-entry.js +4 -1
  57. package/package.json +3 -2
  58. package/specs/import-profiles.json +1 -1
  59. package/specs/prewrite-content-policy.json +1 -1
  60. package/specs/schemas/foundry-authorization-input.schema.json +38 -1
  61. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  62. package/specs/schemas/foundry-package-descriptor.schema.json +3 -2
  63. package/specs/schemas/foundry-reference-input.schema.json +137 -0
  64. 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
- if (spec.binding.artifacts.length !== 1 || spec.binding.artifacts[0]?.role !== "final_rows")
44
- fail("execution_final_rows_unbound", "Restricted execution requires one exact final_rows artifact binding.");
45
- const artifact = spec.binding.artifacts[0];
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")) && !isFlowPublish) ||
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.");
@@ -0,0 +1,4 @@
1
+ import { type CliRuntimeDescriptor, type RuntimeHostContext } from "@tiangong-lca/cli/runtime";
2
+ import { type FoundryOperationResult } from "./foundry-operation-result.ts";
3
+ /** Retain the verified host's launch policy when a caller executes a returned action. */
4
+ export declare function createManagedFoundryActionProjector(context: RuntimeHostContext, cli: CliRuntimeDescriptor, packageEntry: string): (result: FoundryOperationResult) => FoundryOperationResult;
@@ -0,0 +1,56 @@
1
+ import fs from "node:fs";
2
+ import { copyTrustedRuntimeManifestBytes, } from "@tiangong-lca/cli/runtime";
3
+ import { assertFoundryOperationResult, commandNextActionBindingSha256, } from "./foundry-operation-result.js";
4
+ import { FoundryContextError } from "./foundry-runtime-error.js";
5
+ import { transferPath, transferWriteOnce } from "./foundry-migration-transfer-io.js";
6
+ /** Retain the verified host's launch policy when a caller executes a returned action. */
7
+ export function createManagedFoundryActionProjector(context, cli, packageEntry) {
8
+ return (result) => {
9
+ assertFoundryOperationResult(result);
10
+ if (!result.next_actions.some((action) => action.kind === "command"))
11
+ return result;
12
+ for (const action of result.next_actions) {
13
+ if (action.kind !== "command")
14
+ continue;
15
+ if (action.executable !== process.execPath ||
16
+ !action.argv[0] ||
17
+ fs.realpathSync(action.argv[0]) !== packageEntry)
18
+ throw new FoundryContextError("managed_action_invalid", "A managed action must continue through the verified Foundry package entry.");
19
+ }
20
+ const bytes = Buffer.from(copyTrustedRuntimeManifestBytes(context.manifest));
21
+ const relative = `foundry-manifests/${context.manifest.sha256}.json`;
22
+ // A content-bound cache copy carries bytes, never authority from workspace state.
23
+ transferWriteOnce(context.cacheDir, relative, bytes);
24
+ const manifestFile = transferPath(context.cacheDir, relative);
25
+ const nextActions = result.next_actions.map((action) => {
26
+ if (action.kind !== "command")
27
+ return action;
28
+ const projected = {
29
+ kind: action.kind,
30
+ code: action.code,
31
+ cwd: action.cwd,
32
+ purpose: action.purpose,
33
+ executable: cli.command.executable,
34
+ argv: [
35
+ ...cli.command.argv,
36
+ "runtime",
37
+ "exec",
38
+ "--manifest",
39
+ manifestFile,
40
+ "--manifest-sha256",
41
+ context.manifest.sha256,
42
+ "--cache-dir",
43
+ context.cacheDir,
44
+ "--entry",
45
+ context.entry,
46
+ "--cwd",
47
+ action.cwd,
48
+ "--",
49
+ ...action.argv.slice(1),
50
+ ],
51
+ };
52
+ return { ...projected, binding_sha256: commandNextActionBindingSha256(projected) };
53
+ });
54
+ return assertFoundryOperationResult({ ...result, next_actions: nextActions });
55
+ };
56
+ }
@@ -1,7 +1,7 @@
1
- import type { FoundryRuntimeCommandHost } from "../runtime-entry.ts";
1
+ import type { PreparedFoundryRuntimeHost } from "../runtime-entry.ts";
2
2
  export declare const FOUNDRY_MANAGED_RUNTIME_SCHEMA: "tiangong-foundry.managed-runtime.v1";
3
3
  export declare const FOUNDRY_MANAGED_RUNTIME_PATH: "metadata/foundry-runtime.json";
4
- type PreparedHost = Omit<FoundryRuntimeCommandHost, "signal" | "writeStdout" | "setExitCode">;
4
+ type PreparedHost = PreparedFoundryRuntimeHost;
5
5
  /** Package-owned initializer; it accepts no task, environment or argv trust anchors. */
6
6
  export declare function receiveFoundryManagedHost(signal: AbortSignal): Promise<PreparedHost>;
7
7
  export {};
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { RUNTIME_HOST_CONTEXT_PROTOCOL, assertCliRuntimeMatches, inspectRuntimeComponents, receiveRuntimeHostContext, trustRuntimeManifest, } from "@tiangong-lca/cli/runtime";
4
+ import { createManagedFoundryActionProjector } from "./foundry-managed-actions.js";
4
5
  import { FoundryContextError } from "./foundry-runtime-error.js";
5
6
  import { describeFoundryRuntime } from "./foundry-runtime-paths.js";
6
7
  import { assertFoundryPackage } from "./foundry-package-contract.js";
@@ -134,6 +135,7 @@ function prepare(context) {
134
135
  if (target.manifest.product.id !== "tiangong-foundry")
135
136
  fail("Runtime selection targets must be Foundry manifests.");
136
137
  return Object.freeze({
138
+ projectNextActions: createManagedFoundryActionProjector(context, observedCli, runtime.entryPath),
137
139
  workspaceAccess: Object.freeze({ manifest: context.manifest, access: policy.access }),
138
140
  runtimeSelection: Object.freeze({
139
141
  cliExpectation: Object.freeze(cli),
@@ -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
- for (const raw of [proof.input, proof.report, proof.checks]) {
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
- const closed = workflowObject(owners.closeout.runDatasetPostWriteCloseout({
156
- handoffPlan: request.handoff_file,
157
- commitReport,
158
- postWriteVerifyReport: reportFile,
159
- rowsFile: request.content.input.path,
160
- finalizeReport: request.finalize_file,
161
- mutationManifest: request.mutation_file,
162
- outDir: path.join(output, "closeout"),
163
- targetUserId: request.policy.user_id,
164
- stateCode: "0",
165
- }));
166
- if (closed.status !== "completed")
167
- blockers.push({ code: "owner_closeout_blocked", report: closed });
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.6";
5
+ declare const packageVersion = "0.1.8";
6
6
  declare const cliPackageName = "@tiangong-lca/cli";
7
- declare const cliPackageVersion = "0.1.13";
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.6";
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.13";
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 {};