@tiangong-lca/foundry 0.1.9 → 0.1.10

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 (83) hide show
  1. package/README.md +10 -8
  2. package/docs/architecture.md +9 -7
  3. package/docs/foundry-task-contracts.md +10 -4
  4. package/docs/import-profiles/bafu/constraints.md +1 -1
  5. package/docs/import-profiles/bafu/profile.md +1 -1
  6. package/docs/import-profiles/worldsteel/constraints.md +3 -3
  7. package/docs/import-profiles/worldsteel/import-coverage.md +3 -3
  8. package/docs/import-profiles/worldsteel/import-plan.md +4 -4
  9. package/docs/import-profiles/worldsteel/profile.md +3 -3
  10. package/docs/package-distribution-contract.md +9 -9
  11. package/docs/public-runtime-contract.md +17 -7
  12. package/docs/runtime-context-contract.md +5 -5
  13. package/docs/task-authorization-contract.md +3 -3
  14. package/package-dist/assets/foundry-package-descriptor.json +218 -128
  15. package/package-dist/scripts/foundry-facade.js +71 -0
  16. package/package-dist/scripts/foundry-runtime.d.ts +12 -2
  17. package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +3 -3
  18. package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.d.ts → native-draft-closeout.d.ts} +1 -1
  19. package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.js → native-draft-closeout.js} +10 -6
  20. package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.d.ts → native-draft-handoff.d.ts} +7 -5
  21. package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.js → native-draft-handoff.js} +30 -11
  22. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +2 -2
  23. package/package-dist/scripts/lib/foundry-authorization-input.d.ts +10 -1
  24. package/package-dist/scripts/lib/foundry-authorization-input.js +27 -3
  25. package/package-dist/scripts/lib/foundry-command-metadata.js +25 -2
  26. package/package-dist/scripts/lib/foundry-command-registry.d.ts +4 -4
  27. package/package-dist/scripts/lib/foundry-command-registry.js +3 -0
  28. package/package-dist/scripts/lib/foundry-execution-admission.js +3 -3
  29. package/package-dist/scripts/lib/foundry-facade-store.js +56 -6
  30. package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +33 -16
  31. package/package-dist/scripts/lib/foundry-owner-execution-store.js +32 -3
  32. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +3 -0
  33. package/package-dist/scripts/lib/foundry-owner-readback.js +101 -27
  34. package/package-dist/scripts/lib/foundry-package-contract.d.ts +2 -2
  35. package/package-dist/scripts/lib/foundry-package-contract.js +2 -2
  36. package/package-dist/scripts/lib/foundry-repair-execution.d.ts +11 -0
  37. package/package-dist/scripts/lib/foundry-repair-execution.js +70 -0
  38. package/package-dist/scripts/lib/foundry-repair-handoff.d.ts +16 -0
  39. package/package-dist/scripts/lib/foundry-repair-handoff.js +108 -0
  40. package/package-dist/scripts/lib/foundry-repair-preflight.d.ts +96 -0
  41. package/package-dist/scripts/lib/foundry-repair-preflight.js +313 -0
  42. package/package-dist/scripts/lib/foundry-repair-reference-binding.d.ts +26 -0
  43. package/package-dist/scripts/lib/foundry-repair-reference-binding.js +120 -0
  44. package/package-dist/scripts/lib/foundry-repair-reference-proof.d.ts +63 -0
  45. package/package-dist/scripts/lib/foundry-repair-reference-proof.js +329 -0
  46. package/package-dist/scripts/lib/foundry-repair-scope.d.ts +76 -0
  47. package/package-dist/scripts/lib/foundry-repair-scope.js +304 -0
  48. package/package-dist/scripts/lib/foundry-runtime-command-policy.js +1 -0
  49. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  50. package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +3 -0
  51. package/package-dist/scripts/lib/foundry-runtime-utils.js +6 -1
  52. package/package-dist/scripts/lib/foundry-successor-predecessor.d.ts +36 -0
  53. package/package-dist/scripts/lib/foundry-successor-predecessor.js +399 -0
  54. package/package-dist/scripts/lib/foundry-task-registration.js +64 -3
  55. package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +3 -0
  56. package/package-dist/scripts/lib/foundry-task-start-spec.js +24 -1
  57. package/package-dist/scripts/lib/foundry-task-store.d.ts +13 -1
  58. package/package-dist/scripts/lib/foundry-task-store.js +23 -12
  59. package/package-dist/scripts/lib/foundry-task-types.d.ts +22 -1
  60. package/package-dist/scripts/lib/foundry-tidas-source.d.ts +15 -0
  61. package/package-dist/scripts/lib/foundry-tidas-source.js +90 -0
  62. package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +2 -1
  63. package/package-dist/scripts/lib/foundry-workflow-authorization.js +194 -26
  64. package/package-dist/scripts/lib/foundry-workflow-context.js +4 -0
  65. package/package-dist/scripts/lib/foundry-workflow-execution.js +6 -1
  66. package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +36 -0
  67. package/package-dist/scripts/lib/foundry-workflow-repair.js +580 -0
  68. package/package-dist/scripts/lib/foundry-workflow-state.js +66 -18
  69. package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -8
  70. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  71. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +13 -2
  72. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +100 -29
  73. package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +1 -2
  74. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +2 -3
  75. package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +8 -8
  76. package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +12 -2
  77. package/package.json +2 -2
  78. package/specs/import-profiles.json +1 -1
  79. package/specs/schemas/foundry-authorization-input.schema.json +45 -2
  80. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  81. package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
  82. package/specs/schemas/foundry-task-start.schema.json +200 -19
  83. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -0,0 +1,304 @@
1
+ import fs from "node:fs";
2
+ import { FoundryContextError } from "./foundry-runtime-context.js";
3
+ import { sha256Json, sha256Text } from "./identity-preflight-proof.js";
4
+ import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
5
+ import { readRows } from "./import-curation/internal/runtime-io.js";
6
+ import { readNativeDraftHandoff } from "./finalize-owners/native-draft-handoff.js";
7
+ /** Phase 1 admits only Process, and only the two reviewed administrative display-text regions. */
8
+ export const FOUNDRY_REPAIR_SELECTION_KIND = "existing-owner-draft-metadata";
9
+ export const FOUNDRY_REPAIR_ALLOWED_DATASET_TYPE = "process";
10
+ export const FOUNDRY_REPAIR_EDIT_PATHS = Object.freeze([
11
+ "processDataSet.modellingAndValidation.dataSourcesTreatmentAndRepresentativeness" +
12
+ ".referenceToDataSource.*.common:shortDescription.*.#text",
13
+ "processDataSet.administrativeInformation.publicationAndOwnership" +
14
+ ".common:referenceToOwnershipOfDataSet.*.common:shortDescription.*.#text",
15
+ ]);
16
+ /**
17
+ * A repair touching any of these surfaces can change provider selection or scientific content, so it
18
+ * requires a content-bound provider-impact diagnostic that this repository does not produce yet.
19
+ */
20
+ export const FOUNDRY_REPAIR_SHARED_SCIENCE_PREFIXES = Object.freeze([
21
+ "processDataSet.exchanges",
22
+ "processDataSet.quantitativeReference",
23
+ "processDataSet.modellingAndValidation.dataSourcesTreatmentAndRepresentativeness.annualSupplyOrProductionVolume",
24
+ "processDataSet.modellingAndValidation.LCIMethod",
25
+ "processDataSet.processInformation.dataSetInformation.name",
26
+ "processDataSet.processInformation.dataSetInformation.classificationInformation",
27
+ "processDataSet.processInformation.dataSetInformation.common:other",
28
+ "processDataSet.processInformation.geography",
29
+ "processDataSet.administrativeInformation.publicationAndOwnership.common:dataSetVersion",
30
+ "flowDataSet",
31
+ "flowPropertyDataSet",
32
+ "unitGroupDataSet",
33
+ ]);
34
+ const idPattern = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u;
35
+ const shaPattern = /^[0-9a-f]{64}$/u;
36
+ const blankTextSentinel = "FoundryRepairBlankLanguageText";
37
+ const dataSourcePath = [
38
+ "processDataSet",
39
+ "modellingAndValidation",
40
+ "dataSourcesTreatmentAndRepresentativeness",
41
+ ];
42
+ const ownershipPath = [
43
+ "processDataSet",
44
+ "administrativeInformation",
45
+ "publicationAndOwnership",
46
+ ];
47
+ function fail(code, message) {
48
+ throw new FoundryContextError(code, message);
49
+ }
50
+ function isRecord(value) {
51
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
52
+ }
53
+ function record(value, code, label) {
54
+ if (!isRecord(value))
55
+ fail(code, `${label} must be an object.`);
56
+ return value;
57
+ }
58
+ function exact(value, keys, code, label) {
59
+ if (Object.keys(value).length !== keys.length || keys.some((key) => !Object.hasOwn(value, key)))
60
+ fail(code, `${label} has missing or unsupported fields.`);
61
+ }
62
+ function nonEmptyText(value, code, label) {
63
+ if (typeof value !== "string" || !value.trim())
64
+ fail(code, `${label} must be a non-empty string.`);
65
+ return value.trim();
66
+ }
67
+ function selectionPath(value, code, label) {
68
+ if (typeof value !== "string" ||
69
+ !value ||
70
+ value.length > 4_096 ||
71
+ /[\0\r\n]/u.test(value) ||
72
+ /^\.env(?:\.|$)/iu.test(value.split(/[\\/]/u).pop() ?? ""))
73
+ fail(code, `${label} must be a bounded non-credential file path.`);
74
+ return value;
75
+ }
76
+ /** Parse the optional repair selection of a task-start spec against the independently selected sources. */
77
+ export function parseFoundryRepairSelection(value, sources, resolveSelection = (file) => file) {
78
+ const item = record(value, "task_spec_repair_invalid", "Repair selection");
79
+ exact(item, ["kind", "contract", "before", "candidate", "predecessor"], "task_spec_repair_invalid", "Repair selection");
80
+ if (item.kind !== FOUNDRY_REPAIR_SELECTION_KIND)
81
+ fail("task_spec_repair_invalid", "Repair selection kind is unsupported.");
82
+ const contract = resolveSelection(selectionPath(item.contract, "task_spec_repair_invalid", "Repair contract"));
83
+ const before = resolveSelection(selectionPath(item.before, "task_spec_repair_invalid", "Repair before rows"));
84
+ const candidate = resolveSelection(selectionPath(item.candidate, "task_spec_repair_invalid", "Repair candidate rows"));
85
+ if (new Set([contract, before, candidate]).size !== 3)
86
+ fail("task_spec_repair_invalid", "Repair selections must name three distinct files.");
87
+ for (const selected of [contract, before, candidate])
88
+ if (!sources.some((source) => source.path === selected))
89
+ fail("task_spec_repair_invalid", "Repair contract, before rows and candidate rows must each be independently selected sources.");
90
+ let predecessor = null;
91
+ if (item.predecessor !== null) {
92
+ const bound = record(item.predecessor, "task_spec_repair_invalid", "Repair predecessor");
93
+ exact(bound, ["task_id", "receipt_sha256"], "task_spec_repair_invalid", "Repair predecessor");
94
+ const taskId = nonEmptyText(bound.task_id, "task_spec_repair_invalid", "Predecessor task id");
95
+ const receipt = nonEmptyText(bound.receipt_sha256, "task_spec_repair_invalid", "Predecessor receipt hash");
96
+ if (!idPattern.test(taskId) || !shaPattern.test(receipt))
97
+ fail("task_spec_repair_invalid", "Repair predecessor binding is malformed.");
98
+ predecessor = Object.freeze({ task_id: taskId, receipt_sha256: receipt });
99
+ }
100
+ return Object.freeze({
101
+ kind: FOUNDRY_REPAIR_SELECTION_KIND,
102
+ contract,
103
+ before,
104
+ candidate,
105
+ predecessor,
106
+ });
107
+ }
108
+ function navigate(value, path) {
109
+ let current = value;
110
+ for (const segment of path) {
111
+ if (!isRecord(current) || !Object.hasOwn(current, segment))
112
+ return null;
113
+ current = current[segment];
114
+ }
115
+ return current ?? null;
116
+ }
117
+ /**
118
+ * Replace every allowlisted language-node `#text` with one sentinel in a clone of the payload, so that
119
+ * a structure-preserving text-only edit of those nodes disappears while every other difference -
120
+ * values, structure, node count and order, language tags, ids and URIs - survives the canonical hash.
121
+ */
122
+ export function blankRepairEditableText(payload) {
123
+ const copy = structuredClone(payload);
124
+ const description = (value) => {
125
+ if (Array.isArray(value))
126
+ return value.map(description);
127
+ return isRecord(value) && typeof value["#text"] === "string"
128
+ ? { ...value, "#text": blankTextSentinel }
129
+ : value;
130
+ };
131
+ const reference = (value) => {
132
+ if (Array.isArray(value))
133
+ return value.map(reference);
134
+ return isRecord(value) && Object.hasOwn(value, "common:shortDescription")
135
+ ? { ...value, "common:shortDescription": description(value["common:shortDescription"]) }
136
+ : value;
137
+ };
138
+ for (const [regionPath, key] of [
139
+ [dataSourcePath, "referenceToDataSource"],
140
+ [ownershipPath, "common:referenceToOwnershipOfDataSet"],
141
+ ]) {
142
+ const holder = navigate(copy, regionPath);
143
+ if (!isRecord(holder))
144
+ continue;
145
+ if (Object.hasOwn(holder, key))
146
+ holder[key] = reference(holder[key]);
147
+ }
148
+ return copy;
149
+ }
150
+ /** Collect every leaf path where two payloads differ. Values are never included. */
151
+ export function collectRepairChangedPaths(before, after) {
152
+ const changed = [];
153
+ const walk = (left, right, path) => {
154
+ if (changed.length > 2_000)
155
+ return;
156
+ if (Array.isArray(left) || Array.isArray(right)) {
157
+ if (!Array.isArray(left) || !Array.isArray(right)) {
158
+ changed.push(path.join("."));
159
+ return;
160
+ }
161
+ const leftItems = Array.isArray(left) ? left : [];
162
+ const rightItems = Array.isArray(right) ? right : [];
163
+ if (leftItems.length !== rightItems.length) {
164
+ changed.push([...path, "<length>"].join("."));
165
+ return;
166
+ }
167
+ leftItems.forEach((item, index) => walk(item, rightItems[index], [...path, String(index)]));
168
+ return;
169
+ }
170
+ if (isRecord(left) || isRecord(right)) {
171
+ if (!isRecord(left) || !isRecord(right)) {
172
+ changed.push(path.join("."));
173
+ return;
174
+ }
175
+ const leftRecord = isRecord(left) ? left : {};
176
+ const rightRecord = isRecord(right) ? right : {};
177
+ const keys = [...new Set([...Object.keys(leftRecord), ...Object.keys(rightRecord)])].sort();
178
+ for (const key of keys)
179
+ if (!Object.hasOwn(leftRecord, key) || !Object.hasOwn(rightRecord, key))
180
+ changed.push([...path, key].join("."));
181
+ else
182
+ walk(leftRecord[key], rightRecord[key], [...path, key]);
183
+ return;
184
+ }
185
+ if (sha256Json(left ?? null) !== sha256Json(right ?? null))
186
+ changed.push(path.join("."));
187
+ };
188
+ walk(before, after, []);
189
+ return changed;
190
+ }
191
+ function isSharedSciencePath(path) {
192
+ return FOUNDRY_REPAIR_SHARED_SCIENCE_PREFIXES.some((prefix) => path.startsWith(prefix));
193
+ }
194
+ /**
195
+ * Decide whether a before/candidate payload pair stays inside the phase-1 metadata allowlist: only the
196
+ * existing language nodes' `#text` inside the two reviewed regions may change. Everything else blocks,
197
+ * and a shared-science change reports the missing provider-impact diagnostic instead.
198
+ */
199
+ export function classifyRepairMetadataDiff(before, after) {
200
+ const changedPaths = collectRepairChangedPaths(before, after);
201
+ if (!changedPaths.length)
202
+ return { allowed: true, blockers: [] };
203
+ const structurePreserved = sha256Json(blankRepairEditableText(before)) === sha256Json(blankRepairEditableText(after));
204
+ if (structurePreserved)
205
+ return { allowed: true, blockers: [] };
206
+ const blockers = changedPaths.map((path) => ({
207
+ path,
208
+ reason: (isSharedSciencePath(path)
209
+ ? "provider_impact_diagnostics_missing"
210
+ : "unsupported_path"),
211
+ }));
212
+ return blockers.length
213
+ ? { allowed: false, blockers }
214
+ : { allowed: false, blockers: [{ path: "<unclassified>", reason: "structure_change" }] };
215
+ }
216
+ /**
217
+ * Validate one repair task: the CLI execution contract, the CLI-fresh before rows and the candidate rows
218
+ * must agree on the exact same Process identities, every action must be a save_draft against an existing
219
+ * row, and the whole diff must stay inside the metadata allowlist. Nothing is dispatched here.
220
+ */
221
+ export function readFoundryRepairScope(input) {
222
+ if (input.datasetType !== FOUNDRY_REPAIR_ALLOWED_DATASET_TYPE)
223
+ fail("repair_scope_unsupported", "Phase 1 admits only Process owner-draft metadata repair; other dataset types stay blocked.");
224
+ if (input.stateCode !== "0")
225
+ fail("repair_scope_unsupported", "Repair admits only state_code=0 owner drafts.");
226
+ const native = readNativeDraftHandoff({
227
+ contractFile: input.contractFile,
228
+ rowsFile: input.candidateFile,
229
+ datasetType: input.datasetType,
230
+ targetUserId: input.targetUserId,
231
+ verifiedProjectRef: input.verifiedProjectRef,
232
+ stateCode: input.stateCode,
233
+ relativePath: input.relativePath,
234
+ });
235
+ for (const action of native.contract.actions)
236
+ if (action.expected_operation !== "save_draft" || !action.before_sha256)
237
+ fail("repair_insert_not_allowed", "Repair actions must be save_draft against an existing owner draft; insert is never allowed.");
238
+ const payloadsOf = (file, expectedBytesSha256) => {
239
+ const text = fs.readFileSync(file, "utf8");
240
+ if (expectedBytesSha256 && sha256Text(text) !== expectedBytesSha256)
241
+ fail("repair_candidate_changed", "Candidate bytes changed between contract admission and metadata comparison.");
242
+ const rows = readRows(file, () => text);
243
+ const byIdentity = new Map();
244
+ rows.forEach((row, index) => {
245
+ const identity = datasetIdentity(row, index, input.datasetType);
246
+ const key = JSON.stringify([identity.id, identity.version]);
247
+ if (byIdentity.has(key))
248
+ fail("repair_scope_identity_mismatch", "Repair rows contain duplicate dataset identities.");
249
+ byIdentity.set(key, identity.payload);
250
+ });
251
+ return byIdentity;
252
+ };
253
+ const beforeByIdentity = payloadsOf(input.beforeFile);
254
+ const candidateByIdentity = payloadsOf(input.candidateFile, native.rows_sha256);
255
+ if (beforeByIdentity.size !== candidateByIdentity.size ||
256
+ [...beforeByIdentity.keys()].some((key) => !candidateByIdentity.has(key)))
257
+ fail("repair_scope_identity_mismatch", "Repair candidate rows must cover exactly the selected before identities; versions are never minted.");
258
+ const changedPaths = [];
259
+ const actions = native.contract.actions.map((action) => {
260
+ const key = JSON.stringify([action.id, action.version]);
261
+ const beforePayload = beforeByIdentity.get(key);
262
+ if (!beforePayload)
263
+ fail("repair_scope_identity_mismatch", "Every repair action must name an existing draft present in the selected before rows.");
264
+ if (sha256Json(beforePayload) !== action.before_sha256)
265
+ fail("repair_before_content_mismatch", "The contract before hash must equal the canonical hash of the selected before payload.");
266
+ const candidatePayload = candidateByIdentity.get(key);
267
+ if (sha256Json(candidatePayload) === sha256Json(beforePayload))
268
+ return {
269
+ action_id: action.action_id,
270
+ table: action.table,
271
+ id: action.id,
272
+ version: action.version,
273
+ before_sha256: action.before_sha256,
274
+ desired_sha256: action.desired_sha256,
275
+ };
276
+ const changed = collectRepairChangedPaths(beforePayload, candidatePayload);
277
+ const verdict = classifyRepairMetadataDiff(beforePayload, candidatePayload);
278
+ if (!verdict.allowed) {
279
+ fail(verdict.blockers.some((blocker) => blocker.reason === "provider_impact_diagnostics_missing")
280
+ ? "repair_provider_impact_diagnostics_missing"
281
+ : "repair_metadata_scope_blocked", `Repair diff is outside the phase-1 metadata allowlist: ${verdict.blockers
282
+ .slice(0, 8)
283
+ .map((item) => item.path)
284
+ .join(", ")}`);
285
+ }
286
+ changedPaths.push(...changed);
287
+ return {
288
+ action_id: action.action_id,
289
+ table: action.table,
290
+ id: action.id,
291
+ version: action.version,
292
+ before_sha256: action.before_sha256,
293
+ desired_sha256: action.desired_sha256,
294
+ };
295
+ });
296
+ return Object.freeze({
297
+ kind: FOUNDRY_REPAIR_SELECTION_KIND,
298
+ status: changedPaths.length ? "dispatchable" : "satisfied",
299
+ contract_sha256: native.canonical_sha256,
300
+ rows_sha256: native.rows_sha256,
301
+ changed_paths: Object.freeze(changedPaths),
302
+ actions: Object.freeze(actions),
303
+ });
304
+ }
@@ -27,6 +27,7 @@ const taskStages = new Set([
27
27
  "execution-capsule-admit",
28
28
  "dataset-incremental-change-set-compose",
29
29
  "dataset-topology-convergence-compose",
30
+ "final-delivery-promote",
30
31
  "dataset-curation-queue-build",
31
32
  "dataset-curation-gate",
32
33
  "dataset-authoring-plan",
@@ -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.14" || cli.platform !== context.platform)
161
- fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.14 C1 runtime on the selected platform.");
160
+ if (cli.package.version !== "0.1.19" || cli.platform !== context.platform)
161
+ fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.19 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.");
@@ -1,3 +1,4 @@
1
+ import { type TiangongLcaCliTidasSchemaSource } from "./foundry-tidas-source.ts";
1
2
  export interface InstalledTiangongLcaCliPackage {
2
3
  packageName: string;
3
4
  packageVersion: string;
@@ -7,6 +8,8 @@ export interface InstalledTiangongLcaCliPackage {
7
8
  binName: string;
8
9
  binPath: string;
9
10
  schemaDir: string;
11
+ sourceManifestPath: string;
12
+ tidasSpecSource: TiangongLcaCliTidasSchemaSource;
10
13
  }
11
14
  export interface TiangongLcaCliRuntimeCommand {
12
15
  command: string;
@@ -6,9 +6,10 @@ import path from "node:path";
6
6
  import process from "node:process";
7
7
  import { runtimeEnvFilePolicyDisabled, runtimeEnvFilePolicyKey, } from "./foundry-runtime-environment.js";
8
8
  import { resolveFoundryRuntimePaths } from "./foundry-runtime-paths.js";
9
+ import { resolveTiangongLcaCliTidasSource, } from "./foundry-tidas-source.js";
9
10
  const require = createRequire(import.meta.url);
10
11
  const tiangongLcaCliPackageName = "@tiangong-lca/cli";
11
- const tiangongLcaCliPackageVersion = "0.1.14";
12
+ const tiangongLcaCliPackageVersion = "0.1.19";
12
13
  const tiangongLcaCliBinName = "tiangong-lca";
13
14
  const { repoRoot: foundryRepoRoot } = resolveFoundryRuntimePaths(import.meta.url);
14
15
  function isRecord(value) {
@@ -42,12 +43,14 @@ export function resolveInstalledTiangongLcaCliPackage() {
42
43
  const packageRoot = path.dirname(packageJsonPath);
43
44
  const binPath = path.resolve(packageRoot, binEntry);
44
45
  const schemaDir = path.join(packageRoot, "assets", "tidas-schemas");
46
+ const sourceManifestPath = path.join(packageRoot, "assets", "tidas-spec-source.json");
45
47
  if (!fs.existsSync(binPath) || !fs.statSync(binPath).isFile()) {
46
48
  throw new Error(`Installed ${tiangongLcaCliPackageName} bin is missing at ${binPath}.`);
47
49
  }
48
50
  if (!fs.existsSync(schemaDir) || !fs.statSync(schemaDir).isDirectory()) {
49
51
  throw new Error(`Installed ${tiangongLcaCliPackageName} schema assets are missing at ${schemaDir}.`);
50
52
  }
53
+ const tidasSpecSource = resolveTiangongLcaCliTidasSource(sourceManifestPath, schemaDir);
51
54
  return {
52
55
  packageName: packageJson.name,
53
56
  packageVersion: packageJson.version,
@@ -57,6 +60,8 @@ export function resolveInstalledTiangongLcaCliPackage() {
57
60
  binName: tiangongLcaCliBinName,
58
61
  binPath,
59
62
  schemaDir,
63
+ sourceManifestPath,
64
+ tidasSpecSource,
60
65
  };
61
66
  }
62
67
  function shellQuoteCommandToken(value) {
@@ -0,0 +1,36 @@
1
+ import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ import type { FoundryTaskStartSpec } from "./foundry-task-start-spec.ts";
3
+ export interface FoundrySuccessorLink {
4
+ readonly task_id: string;
5
+ readonly spec: FoundryTaskStartSpec;
6
+ readonly inputs: readonly FoundryInputFact[];
7
+ }
8
+ /**
9
+ * The strict reader of one failed native commit report. It never trusts Foundry's own counters: the
10
+ * CLI's machine report must prove that nothing was executed and no CLI attempt was consumed, that
11
+ * every row is a definite failure, and that input, contract and every action are bound to the exact
12
+ * admitted scope. Returns the refusal reason, or null when the report qualifies.
13
+ */
14
+ export declare function noDispatchCommitReportProblem(value: unknown, expected: {
15
+ readonly candidate_path: string;
16
+ readonly contract_sha256: string;
17
+ readonly execution_id: string;
18
+ readonly actions: readonly {
19
+ readonly action_id: string;
20
+ readonly table: string;
21
+ readonly id: string;
22
+ readonly version: string;
23
+ readonly desired_sha256: string;
24
+ }[];
25
+ }): string | null;
26
+ /**
27
+ * Admit one successor revision over a predecessor whose only terminal evidence is a CLI failure that
28
+ * provably dispatched nothing. Every fact is re-derived from the predecessor's own hash-chained index
29
+ * on every call; nothing is cached, and the successor may never name one of the predecessor's files.
30
+ */
31
+ export declare function assertFoundryNoDispatchSuccessor(input: {
32
+ context: FoundryRuntimeContext;
33
+ predecessorTaskId: string;
34
+ predecessorInputs: readonly FoundryInputFact[];
35
+ successor: FoundrySuccessorLink;
36
+ }): void;