@tiangong-lca/foundry 0.1.9 → 0.1.11

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 (107) hide show
  1. package/README.md +13 -11
  2. package/docs/architecture.md +12 -10
  3. package/docs/foundry-task-contracts.md +16 -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 +11 -9
  11. package/docs/public-runtime-contract.md +31 -9
  12. package/docs/runtime-context-contract.md +7 -5
  13. package/docs/task-authorization-contract.md +5 -3
  14. package/package-dist/assets/foundry-package-descriptor.json +300 -154
  15. package/package-dist/scripts/foundry-facade.d.ts +1 -0
  16. package/package-dist/scripts/foundry-facade.js +233 -28
  17. package/package-dist/scripts/foundry-runtime.d.ts +14 -3
  18. package/package-dist/scripts/foundry-runtime.js +2 -2
  19. package/package-dist/scripts/lib/finalize-owners/commit-handoff.js +3 -3
  20. package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.d.ts → native-draft-closeout.d.ts} +1 -1
  21. package/package-dist/scripts/lib/finalize-owners/{native-insert-closeout.js → native-draft-closeout.js} +10 -6
  22. package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.d.ts → native-draft-handoff.d.ts} +7 -5
  23. package/package-dist/scripts/lib/finalize-owners/{native-insert-handoff.js → native-draft-handoff.js} +30 -11
  24. package/package-dist/scripts/lib/finalize-owners/post-write-closeout.js +2 -2
  25. package/package-dist/scripts/lib/foundry-authorization-input.d.ts +10 -1
  26. package/package-dist/scripts/lib/foundry-authorization-input.js +27 -3
  27. package/package-dist/scripts/lib/foundry-command-metadata.js +25 -2
  28. package/package-dist/scripts/lib/foundry-command-registry.d.ts +4 -4
  29. package/package-dist/scripts/lib/foundry-command-registry.js +3 -0
  30. package/package-dist/scripts/lib/foundry-execution-admission.js +3 -3
  31. package/package-dist/scripts/lib/foundry-facade-store.js +56 -6
  32. package/package-dist/scripts/lib/foundry-interaction-input.d.ts +19 -0
  33. package/package-dist/scripts/lib/foundry-interaction-input.js +327 -0
  34. package/package-dist/scripts/lib/foundry-interaction-projection.d.ts +22 -0
  35. package/package-dist/scripts/lib/foundry-interaction-projection.js +81 -0
  36. package/package-dist/scripts/lib/foundry-interaction-types.d.ts +17 -0
  37. package/package-dist/scripts/lib/foundry-interaction-types.js +4 -0
  38. package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +33 -16
  39. package/package-dist/scripts/lib/foundry-owner-execution-store.js +66 -5
  40. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +3 -0
  41. package/package-dist/scripts/lib/foundry-owner-readback.js +101 -27
  42. package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
  43. package/package-dist/scripts/lib/foundry-package-contract.js +4 -2
  44. package/package-dist/scripts/lib/foundry-repair-execution.d.ts +11 -0
  45. package/package-dist/scripts/lib/foundry-repair-execution.js +70 -0
  46. package/package-dist/scripts/lib/foundry-repair-handoff.d.ts +16 -0
  47. package/package-dist/scripts/lib/foundry-repair-handoff.js +108 -0
  48. package/package-dist/scripts/lib/foundry-repair-preflight.d.ts +96 -0
  49. package/package-dist/scripts/lib/foundry-repair-preflight.js +313 -0
  50. package/package-dist/scripts/lib/foundry-repair-reference-binding.d.ts +26 -0
  51. package/package-dist/scripts/lib/foundry-repair-reference-binding.js +120 -0
  52. package/package-dist/scripts/lib/foundry-repair-reference-proof.d.ts +63 -0
  53. package/package-dist/scripts/lib/foundry-repair-reference-proof.js +329 -0
  54. package/package-dist/scripts/lib/foundry-repair-scope.d.ts +76 -0
  55. package/package-dist/scripts/lib/foundry-repair-scope.js +304 -0
  56. package/package-dist/scripts/lib/foundry-runtime-command-policy.js +1 -0
  57. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  58. package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +3 -0
  59. package/package-dist/scripts/lib/foundry-runtime-utils.js +6 -1
  60. package/package-dist/scripts/lib/foundry-semantic-input.d.ts +2 -0
  61. package/package-dist/scripts/lib/foundry-semantic-input.js +29 -2
  62. package/package-dist/scripts/lib/foundry-semantic-interaction.d.ts +12 -0
  63. package/package-dist/scripts/lib/foundry-semantic-interaction.js +38 -0
  64. package/package-dist/scripts/lib/foundry-successor-predecessor.d.ts +36 -0
  65. package/package-dist/scripts/lib/foundry-successor-predecessor.js +399 -0
  66. package/package-dist/scripts/lib/foundry-task-registration.js +64 -3
  67. package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +14 -0
  68. package/package-dist/scripts/lib/foundry-task-start-spec.js +60 -1
  69. package/package-dist/scripts/lib/foundry-task-store.d.ts +13 -1
  70. package/package-dist/scripts/lib/foundry-task-store.js +23 -12
  71. package/package-dist/scripts/lib/foundry-task-types.d.ts +22 -1
  72. package/package-dist/scripts/lib/foundry-tidas-source.d.ts +15 -0
  73. package/package-dist/scripts/lib/foundry-tidas-source.js +90 -0
  74. package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +7 -1
  75. package/package-dist/scripts/lib/foundry-workflow-assessment.js +127 -6
  76. package/package-dist/scripts/lib/foundry-workflow-authorization.d.ts +2 -1
  77. package/package-dist/scripts/lib/foundry-workflow-authorization.js +194 -26
  78. package/package-dist/scripts/lib/foundry-workflow-context.js +4 -0
  79. package/package-dist/scripts/lib/foundry-workflow-execution.js +6 -1
  80. package/package-dist/scripts/lib/foundry-workflow-finalize.js +7 -4
  81. package/package-dist/scripts/lib/foundry-workflow-interaction.d.ts +4 -0
  82. package/package-dist/scripts/lib/foundry-workflow-interaction.js +63 -0
  83. package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +36 -0
  84. package/package-dist/scripts/lib/foundry-workflow-repair.js +580 -0
  85. package/package-dist/scripts/lib/foundry-workflow-semantic.js +21 -1
  86. package/package-dist/scripts/lib/foundry-workflow-state.d.ts +9 -1
  87. package/package-dist/scripts/lib/foundry-workflow-state.js +239 -39
  88. package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -8
  89. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  90. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.d.ts +13 -2
  91. package/package-dist/scripts/lib/import-curation/internal/prewrite-cleanup.js +100 -29
  92. package/package-dist/scripts/lib/import-curation/internal/workflow-authoring-tasks.js +1 -2
  93. package/package-dist/scripts/lib/import-curation/internal/workflow-patch-collect.js +2 -3
  94. package/package-dist/scripts/lib/import-curation/internal/workflow-queue-context.js +8 -8
  95. package/package-dist/scripts/lib/import-curation/internal/workflow-semantic-actions.js +12 -2
  96. package/package-dist/scripts/public-api.d.ts +2 -0
  97. package/package-dist/scripts/public-api.js +1 -0
  98. package/package-dist/scripts/runtime-entry.js +9 -1
  99. package/package.json +3 -2
  100. package/specs/import-profiles.json +1 -1
  101. package/specs/schemas/foundry-authorization-input.schema.json +45 -2
  102. package/specs/schemas/foundry-interaction-input.schema.json +173 -0
  103. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  104. package/specs/schemas/foundry-package-descriptor.schema.json +3 -2
  105. package/specs/schemas/foundry-semantic-input.schema.json +12 -1
  106. package/specs/schemas/foundry-task-start.schema.json +275 -19
  107. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -4,6 +4,7 @@ import { createFileArtifactFact } from "../foundry-command-spec.js";
4
4
  import { sha256Json, sha256Text } from "../identity-preflight-proof.js";
5
5
  import { datasetIdentity } from "../import-curation/internal/dataset-payload.js";
6
6
  import { readRows } from "../import-curation/internal/runtime-io.js";
7
+ const BEFORE_SHA256_PATTERN = /^[0-9a-f]{64}$/u;
7
8
  function fail(message) {
8
9
  throw new Error(`--execution-contract-file: ${message}`);
9
10
  }
@@ -17,6 +18,20 @@ function token(value) {
17
18
  return fail("Contract identity fields must be non-empty strings.");
18
19
  return value.trim();
19
20
  }
21
+ /**
22
+ * One action binds exactly one draft operation: an absent row inserts, an existing owner draft
23
+ * updates in place with its complete before hash. The CLI execution contract applies the same
24
+ * rule, so a contract that contradicts itself never reaches admission.
25
+ */
26
+ function draftOperationBinding(operation, beforeSha256) {
27
+ if (operation === "insert" && beforeSha256 === null)
28
+ return { expected_operation: "insert", before_sha256: null };
29
+ if (operation === "save_draft" &&
30
+ typeof beforeSha256 === "string" &&
31
+ BEFORE_SHA256_PATTERN.test(beforeSha256))
32
+ return { expected_operation: "save_draft", before_sha256: beforeSha256 };
33
+ return null;
34
+ }
20
35
  export function assertExecutionContractSelection(options) {
21
36
  if (Object.keys(options).some((key) => key.startsWith("executionContract") && key !== "executionContractFile") ||
22
37
  (Object.hasOwn(options, "executionContractFile") &&
@@ -25,10 +40,10 @@ export function assertExecutionContractSelection(options) {
25
40
  fail("Use one non-empty string selection; unsupported options or repeated values are invalid.");
26
41
  }
27
42
  /** Consumer admission only; CLI owns parsing at execution, attempts and readback. */
28
- export function readNativeInsertHandoff(input) {
43
+ export function readNativeDraftHandoff(input) {
29
44
  const tables = { flow: "flows", process: "processes", source: "sources" };
30
45
  if (!Object.hasOwn(tables, input.datasetType) || input.stateCode !== "0")
31
- fail("Native insert handoffs support only Flow, Process and Source owner drafts.");
46
+ fail("Native draft handoffs support only Flow, Process and Source owner drafts.");
32
47
  if (!fs.lstatSync(input.contractFile).isFile())
33
48
  fail("Select a regular contract file.");
34
49
  const bytes = fs.readFileSync(input.contractFile, "utf8");
@@ -58,17 +73,17 @@ export function readNativeInsertHandoff(input) {
58
73
  const id = token(info["common:UUID"]);
59
74
  const version = token(publication["common:dataSetVersion"]);
60
75
  const target = JSON.stringify([id, version]);
76
+ const operation = draftOperationBinding(action.expected_operation, action.before_sha256);
61
77
  if (actionIds.has(actionId) ||
62
78
  targets.has(target) ||
63
- action.expected_operation !== "insert" ||
64
- action.before_sha256 !== null ||
79
+ !operation ||
65
80
  action.table !== tables[input.datasetType] ||
66
81
  token(action.id) !== id ||
67
82
  token(action.version) !== version ||
68
83
  identity.id !== id ||
69
84
  identity.version !== version ||
70
85
  action.desired_sha256 !== sha256Json(identity.payload))
71
- fail("Contract insert action does not bind the exact final payload and identity.");
86
+ fail("Contract action does not bind the exact final payload, identity and draft operation.");
72
87
  if (!Array.isArray(action.dependency_action_ids))
73
88
  fail("Action dependencies must be explicit.");
74
89
  const dependencies = action.dependency_action_ids.map(token);
@@ -77,19 +92,23 @@ export function readNativeInsertHandoff(input) {
77
92
  fail("Dependencies must identify unique earlier contract actions.");
78
93
  actionIds.add(actionId);
79
94
  targets.add(target);
95
+ // Project the native owner's normalized wire fields for its report digest. The action keeps
96
+ // the CLI execution contract's exact eight keys so both sides hash the same object shape.
80
97
  return {
81
98
  action_id: actionId,
82
99
  desired_sha256: action.desired_sha256,
83
- expected_operation: "insert",
100
+ expected_operation: operation.expected_operation,
84
101
  table: tables[input.datasetType],
85
102
  id,
86
103
  version,
87
- before_sha256: null,
104
+ before_sha256: operation.before_sha256,
88
105
  dependency_action_ids: dependencies,
89
106
  };
90
107
  });
91
- // Project the native owner's normalized wire fields for its report digest.
92
- // Raw file bytes are bound separately, so ignored metadata cannot drift.
108
+ // Raw file bytes are bound separately, so ignored metadata cannot drift. The operation label is
109
+ // derived from the hashed actions only: one operation keeps its name, both become "mixed".
110
+ const operations = [...new Set(actions.map((action) => action.expected_operation))];
111
+ const operation = operations.length === 1 ? operations[0] : "mixed";
93
112
  const contract = {
94
113
  schema_version: "dataset-save-draft-execution-contract.v1",
95
114
  execution_id: token(raw.execution_id),
@@ -118,7 +137,7 @@ export function readNativeInsertHandoff(input) {
118
137
  canonical_sha256: sha256Json(contract),
119
138
  execution_id: contract.execution_id,
120
139
  project_ref: contract.project_ref,
121
- operation: "insert",
140
+ operation,
122
141
  },
123
142
  rows_sha256: sha256Text(rowsText),
124
143
  };
@@ -127,7 +146,7 @@ export function reserveNativeHandoffDirectory(directory) {
127
146
  fs.mkdirSync(path.dirname(directory), { recursive: true });
128
147
  fs.mkdirSync(directory);
129
148
  }
130
- export function nativeInsertCommitArguments(prefix, datasetType, rowsFile, outDir, contractFile) {
149
+ export function nativeDraftCommitArguments(prefix, datasetType, rowsFile, outDir, contractFile) {
131
150
  return [
132
151
  ...prefix,
133
152
  "dataset",
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
  import { createFileArtifactFact } from "../foundry-command-spec.js";
3
3
  import { normalizeAllowedTraceHashDifference } from "../remote-verification-accepted-diff.js";
4
4
  import { canonicalPayloadSha256, validateUniqueRootReadbacks } from "../post-write-root-proof.js";
5
- import { validateNativeInsertCloseout } from "./native-insert-closeout.js";
5
+ import { validateNativeDraftCloseout } from "./native-draft-closeout.js";
6
6
  import { validateReferenceIntentReadback } from "./reference-intent-closeout.js";
7
7
  function isJsonRecord(value) {
8
8
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -10,7 +10,7 @@ function isJsonRecord(value) {
10
10
  export function createPostWriteCloseoutCommands({ executionEnvironment = process.env, asText, countJsonLinesFile, countRowsFile, datasetIdentity, ensureArray, fileExists, fullContextProofCheck, nowIso, readJsonArtifactOption, readJsonLines, readRowsFile, repoRelativeMaybe, repoRelativePath, reportInputPath, resolveRepoPath, sameResolvedPath, validateTraceQueueCoverageForRows, writeCloseoutImportLedger, writeJson, }) {
11
11
  function validateCommitReportForCloseout({ commitReport, commitReportPath, datasetType, finalRowsFile, expectedRows, blockers, handoffPlan, targetUserId, expectedStateCode, }) {
12
12
  try {
13
- if (validateNativeInsertCloseout({
13
+ if (validateNativeDraftCloseout({
14
14
  handoff: handoffPlan ?? {},
15
15
  report: commitReport,
16
16
  rowsFile: finalRowsFile,
@@ -7,13 +7,21 @@ export interface FoundryAuthorizationInput {
7
7
  actor_id: string;
8
8
  finalization_sha256: string;
9
9
  dataset_type: string;
10
- input_kind: "current_rows" | "final_rows";
10
+ /**
11
+ * `repair_rows` is the existing-owner-draft repair scope: its authority is the registered repair
12
+ * preparation report, never a finalization report, and it always carries the native contract.
13
+ */
14
+ input_kind: "current_rows" | "final_rows" | "repair_rows";
11
15
  input_sha256: string;
12
16
  expected_previous_sha256: string | null;
13
17
  execution_contract?: {
14
18
  file: string;
15
19
  sha256: string;
16
20
  };
21
+ repair_preparation?: {
22
+ file: string;
23
+ sha256: string;
24
+ };
17
25
  grant: {
18
26
  file: string;
19
27
  sha256: string;
@@ -32,6 +40,7 @@ export interface SelectedAuthorizationInput {
32
40
  readonly evidence: readonly FoundryInputFact[];
33
41
  readonly executionContract?: FoundryInputFact;
34
42
  readonly executionContractSource?: FoundryInputFact;
43
+ readonly repairPreparation?: FoundryInputFact;
35
44
  }
36
45
  export declare function parseFoundryAuthorizationInput(value: unknown): FoundryAuthorizationInput;
37
46
  export declare function selectFoundryAuthorizationInput(context: FoundryRuntimeContext, file: string): SelectedAuthorizationInput;
@@ -40,6 +40,7 @@ export function parseFoundryAuthorizationInput(value) {
40
40
  "grant",
41
41
  "evidence",
42
42
  ...(Object.hasOwn(data, "execution_contract") ? ["execution_contract"] : []),
43
+ ...(Object.hasOwn(data, "repair_preparation") ? ["repair_preparation"] : []),
43
44
  ]);
44
45
  if (data.schema !== FOUNDRY_AUTHORIZATION_INPUT_SCHEMA ||
45
46
  typeof data.task_id !== "string" ||
@@ -60,7 +61,9 @@ export function parseFoundryAuthorizationInput(value) {
60
61
  "flowproperty",
61
62
  "lifecyclemodel",
62
63
  ].includes(data.dataset_type) ||
63
- (data.input_kind !== "current_rows" && data.input_kind !== "final_rows") ||
64
+ (data.input_kind !== "current_rows" &&
65
+ data.input_kind !== "final_rows" &&
66
+ data.input_kind !== "repair_rows") ||
64
67
  (data.expected_previous_sha256 !== null &&
65
68
  (typeof data.expected_previous_sha256 !== "string" ||
66
69
  !sha.test(data.expected_previous_sha256))) ||
@@ -72,13 +75,29 @@ export function parseFoundryAuthorizationInput(value) {
72
75
  exact(grant, ["file", "sha256"]);
73
76
  let executionContract;
74
77
  if (Object.hasOwn(data, "execution_contract")) {
75
- if (data.input_kind !== "final_rows" ||
78
+ if (!["final_rows", "repair_rows"].includes(String(data.input_kind)) ||
76
79
  !["flow", "process", "source"].includes(data.dataset_type))
77
- invalid("Native insert contracts require finalized Flow, Process or Source rows.");
80
+ invalid("Native draft contracts require finalized Flow, Process or Source rows.");
78
81
  const selected = workflowObject(data.execution_contract);
79
82
  exact(selected, ["file", "sha256"]);
80
83
  executionContract = Object.freeze(fileReference(selected));
81
84
  }
85
+ let repairPreparation;
86
+ if (Object.hasOwn(data, "repair_preparation")) {
87
+ const selected = workflowObject(data.repair_preparation);
88
+ exact(selected, ["file", "sha256"]);
89
+ repairPreparation = Object.freeze(fileReference(selected));
90
+ }
91
+ if ((data.input_kind === "repair_rows") !== Boolean(repairPreparation))
92
+ invalid("A repair scope is exactly the repair_rows input kind carrying its registered preparation report.");
93
+ if (repairPreparation) {
94
+ if (data.dataset_type !== "process")
95
+ invalid("A repair scope admits only Process owner drafts.");
96
+ if (!executionContract)
97
+ invalid("A repair scope always carries the selected native execution contract.");
98
+ if (data.finalization_sha256 !== repairPreparation.sha256)
99
+ invalid("A repair scope authority is the registered preparation report digest; a finalization digest is not accepted.");
100
+ }
82
101
  const evidence = data.evidence.map((raw) => {
83
102
  const item = workflowObject(raw);
84
103
  exact(item, ["id", "kind", "file", "sha256"]);
@@ -103,6 +122,7 @@ export function parseFoundryAuthorizationInput(value) {
103
122
  grant: Object.freeze(fileReference(grant)),
104
123
  evidence: Object.freeze(evidence),
105
124
  ...(executionContract ? { execution_contract: executionContract } : {}),
125
+ ...(repairPreparation ? { repair_preparation: repairPreparation } : {}),
106
126
  });
107
127
  }
108
128
  export function selectFoundryAuthorizationInput(context, file) {
@@ -149,12 +169,16 @@ export function selectFoundryAuthorizationInput(context, file) {
149
169
  const executionContract = spec.execution_contract ? select(spec.execution_contract.file) : null;
150
170
  if (executionContract && executionContract.sha256 !== spec.execution_contract.sha256)
151
171
  invalid("Native execution contract bytes differ from the selected digest.");
172
+ const repairPreparation = spec.repair_preparation ? select(spec.repair_preparation.file) : null;
173
+ if (repairPreparation && repairPreparation.sha256 !== spec.repair_preparation.sha256)
174
+ invalid("Repair preparation bytes differ from the selected digest.");
152
175
  const result = Object.freeze({
153
176
  spec,
154
177
  descriptor,
155
178
  grant: selected[0],
156
179
  evidence: Object.freeze(selected.slice(1)),
157
180
  ...(executionContract ? { executionContract } : {}),
181
+ ...(repairPreparation ? { repairPreparation } : {}),
158
182
  });
159
183
  selections.add(result);
160
184
  return result;
@@ -238,6 +238,26 @@ export const commandMetadata = {
238
238
  nodeTest("test/unit/execution-capsule-attempt-state.test.mts", "attempt dispositions distinguish unattempted, recovered success, and unknown no-replay states"),
239
239
  ],
240
240
  }),
241
+ "final-delivery-promote": metadata({
242
+ category: "workflow-internal",
243
+ ownerModule: "scripts/commands/final-delivery-promotion.ts",
244
+ ownerExport: "createFinalDeliveryPromotionCommands().runFinalDeliveryPromote",
245
+ inputs: [
246
+ "foundry-final-delivery-manifest.v1",
247
+ "content-bound local delivery artifacts",
248
+ "declarative algebra and workbook policies",
249
+ "independent reviewer reports",
250
+ ],
251
+ outputs: [
252
+ "final-delivery-manifest-snapshot.json",
253
+ "final-delivery-promotion-ledger.jsonl",
254
+ "final-delivery-promotion-report.json",
255
+ "final-delivery-promotion-seal.json when all checks pass",
256
+ ],
257
+ keyTests: [
258
+ nodeTest("test/commands/final-delivery-promotion.test.mts", "final delivery promotion validates exact content, rows, algebra, workbook, redaction, review, and immutable seal behavior"),
259
+ ],
260
+ }),
241
261
  "dataset-incremental-change-set-compose": metadata({
242
262
  category: "workflow-internal",
243
263
  ownerModule: "scripts/commands/incremental-change-set.ts",
@@ -529,7 +549,7 @@ export const commandMetadata = {
529
549
  "blocked_invalid_datetime_metadata: ordered blockers, null cleaned rows, and every pre-existing stale output preserved",
530
550
  ],
531
551
  keyTests: [
532
- nodeTest("test/scenarios/curation-cleanup-quality-gates.test.mts", "curation cleanup fills placeholder annual supply with searchable sentinel"),
552
+ nodeTest("test/scenarios/curation-cleanup-quality-gates.test.mts", "curation cleanup normalizes placeholder annual supply to the supported unknown array"),
533
553
  nodeTest("test/scenarios/curation-cleanup-quality-gates.test.mts", "curation cleanup CLI exits nonzero and emits only blocker evidence for an impossible datetime"),
534
554
  nodeTest("test/unit/curation-cleanup-runner-contract.test.mts", "impossible datetime blocks the whole cleanup before partial transforms or cleaned-row output"),
535
555
  importCurationEntryContract,
@@ -929,7 +949,7 @@ export const commandMetadata = {
929
949
  "finalize report",
930
950
  "location audit evidence",
931
951
  "current task authorization for restricted final rows or QA exceptions",
932
- "optional explicit native insert execution-contract file for Flow, Process or Source",
952
+ "optional explicit native draft execution-contract file (insert or save_draft) for Flow, Process or Source",
933
953
  ],
934
954
  outputs: [
935
955
  "commit handoff plan JSON report",
@@ -941,6 +961,8 @@ export const commandMetadata = {
941
961
  keyTests: [
942
962
  nodeTest("test/scenarios/handoff-reference-intent.test.mts", "handoff automatically retains the passing reference intent and all evidence in both command specs"),
943
963
  nodeTest("test/scenarios/native-insert-closeout.test.mts", "native closeout rejects a completed report from a different contract despite exact root readback"),
964
+ nodeTest("test/unit/handoff-identity-task-command-factories.test.mts", "explicit native draft handoff binds a save_draft update and preserves the exact CLI action projection"),
965
+ nodeTest("test/scenarios/foundry-public-native-draft.test.mts", "public native draft repair accepts a bound save_draft contract without extra dispatch"),
944
966
  nodeTest("test/unit/handoff-identity-task-command-factories.test.mts", "mixed support handoff rechecks exact task actions against actual final rows"),
945
967
  nodeTest("test/unit/foundry-command-spec.test.mts", "CommandSpec blocks artifact byte drift before spawn and never executes display"),
946
968
  nodeTest("test/scenarios/full-context-completion-closeout.test.mts", "commit handoff blocks nonzero location audit blockers"),
@@ -961,6 +983,7 @@ export const commandMetadata = {
961
983
  outputs: ["post-write-closeout-report.json"],
962
984
  keyTests: [
963
985
  nodeTest("test/scenarios/native-insert-closeout.test.mts", "native closeout accepts exact consumed insert/readback evidence and still requires unique roots"),
986
+ nodeTest("test/unit/handoff-identity-task-command-factories.test.mts", "native draft closeout rejects forged, incomplete or wrong-operation recovered rows"),
964
987
  nodeTest("test/scenarios/full-context-completion-closeout.test.mts", "post-write closeout requires common:other trace queues to match final rows"),
965
988
  ],
966
989
  }),
@@ -1,6 +1,6 @@
1
1
  export declare const publicCommands: readonly ["init", "doctor", "env-check", "workflow-check", "storage-check", "surface-audit", "acceptance-check", "workspace-map", "capabilities-list", "profiles-list", "route-task", "tasks-list", "tasks-check", "task-complete", "tidas-handshake"];
2
- export declare const datasetPolicyCommands: readonly ["dataset-tidas-import", "dataset-tidas-validate", "execution-capsule-admit", "dataset-incremental-change-set-compose", "dataset-topology-convergence-compose", "dataset-curation-queue-build", "dataset-curation-gate", "dataset-authoring-plan", "dataset-authoring-task-build", "dataset-authoring-patch-collect", "dataset-identity-decision-task-build", "dataset-classification-decision-task-build", "dataset-library-classification-decisions-project", "dataset-bafu-leaf-classification-tasks-prepare", "dataset-bafu-leaf-classification-category-map-project", "dataset-bafu-identity-decisions-autofill", "dataset-bafu-authoring-patches-autofill", "dataset-classification-decisions-apply", "dataset-location-decision-task-build", "dataset-location-decisions-suggest", "dataset-location-decisions-apply", "dataset-curation-cleanup", "dataset-patch-apply", "dataset-support-cache-refresh", "dataset-canonical-support-mappings-autofill", "dataset-bundle-sample-rows", "dataset-identity-preflight-requests-build", "dataset-identity-preflight-query-audit", "dataset-identity-preflight-run", "dataset-identity-preflight-index-merge", "dataset-library-index-build", "dataset-library-authoring-plan", "dataset-library-identity-decisions-from-preflight", "dataset-library-decisions-apply", "dataset-process-scope-run", "dataset-bafu-process-scope-e2e", "dataset-bafu-batch-import-run", "dataset-uslci-batch-import-run", "dataset-worldsteel-batch-import-run", "dataset-bafu-universe-coverage-report", "dataset-identity-reference-rewrites-apply", "dataset-identity-decisions-apply", "dataset-post-authoring-finalize", "dataset-commit-handoff-plan", "dataset-post-write-closeout", "dataset-import-completion-report", "dataset-import-ledger-report", "dataset-mutation-manifest"];
3
- export declare const knownCommands: ("acceptance-check" | "capabilities-list" | "dataset-authoring-patch-collect" | "dataset-authoring-plan" | "dataset-authoring-task-build" | "dataset-bafu-authoring-patches-autofill" | "dataset-bafu-batch-import-run" | "dataset-bafu-identity-decisions-autofill" | "dataset-bafu-leaf-classification-category-map-project" | "dataset-bafu-leaf-classification-tasks-prepare" | "dataset-bafu-process-scope-e2e" | "dataset-bafu-universe-coverage-report" | "dataset-bundle-sample-rows" | "dataset-canonical-support-mappings-autofill" | "dataset-classification-decision-task-build" | "dataset-classification-decisions-apply" | "dataset-commit-handoff-plan" | "dataset-curation-cleanup" | "dataset-curation-gate" | "dataset-curation-queue-build" | "dataset-identity-decision-task-build" | "dataset-identity-decisions-apply" | "dataset-identity-preflight-index-merge" | "dataset-identity-preflight-query-audit" | "dataset-identity-preflight-requests-build" | "dataset-identity-preflight-run" | "dataset-identity-reference-rewrites-apply" | "dataset-import-completion-report" | "dataset-import-ledger-report" | "dataset-incremental-change-set-compose" | "dataset-library-authoring-plan" | "dataset-library-classification-decisions-project" | "dataset-library-decisions-apply" | "dataset-library-identity-decisions-from-preflight" | "dataset-library-index-build" | "dataset-location-decision-task-build" | "dataset-location-decisions-apply" | "dataset-location-decisions-suggest" | "dataset-mutation-manifest" | "dataset-patch-apply" | "dataset-post-authoring-finalize" | "dataset-post-write-closeout" | "dataset-process-scope-run" | "dataset-support-cache-refresh" | "dataset-tidas-import" | "dataset-tidas-validate" | "dataset-topology-convergence-compose" | "dataset-uslci-batch-import-run" | "dataset-worldsteel-batch-import-run" | "doctor" | "env-check" | "execution-capsule-admit" | "init" | "profiles-list" | "route-task" | "storage-check" | "surface-audit" | "task-complete" | "tasks-check" | "tasks-list" | "tidas-handshake" | "workflow-check" | "workspace-map")[];
2
+ export declare const datasetPolicyCommands: readonly ["dataset-tidas-import", "dataset-tidas-validate", "execution-capsule-admit", "dataset-incremental-change-set-compose", "dataset-topology-convergence-compose", "final-delivery-promote", "dataset-curation-queue-build", "dataset-curation-gate", "dataset-authoring-plan", "dataset-authoring-task-build", "dataset-authoring-patch-collect", "dataset-identity-decision-task-build", "dataset-classification-decision-task-build", "dataset-library-classification-decisions-project", "dataset-bafu-leaf-classification-tasks-prepare", "dataset-bafu-leaf-classification-category-map-project", "dataset-bafu-identity-decisions-autofill", "dataset-bafu-authoring-patches-autofill", "dataset-classification-decisions-apply", "dataset-location-decision-task-build", "dataset-location-decisions-suggest", "dataset-location-decisions-apply", "dataset-curation-cleanup", "dataset-patch-apply", "dataset-support-cache-refresh", "dataset-canonical-support-mappings-autofill", "dataset-bundle-sample-rows", "dataset-identity-preflight-requests-build", "dataset-identity-preflight-query-audit", "dataset-identity-preflight-run", "dataset-identity-preflight-index-merge", "dataset-library-index-build", "dataset-library-authoring-plan", "dataset-library-identity-decisions-from-preflight", "dataset-library-decisions-apply", "dataset-process-scope-run", "dataset-bafu-process-scope-e2e", "dataset-bafu-batch-import-run", "dataset-uslci-batch-import-run", "dataset-worldsteel-batch-import-run", "dataset-bafu-universe-coverage-report", "dataset-identity-reference-rewrites-apply", "dataset-identity-decisions-apply", "dataset-post-authoring-finalize", "dataset-commit-handoff-plan", "dataset-post-write-closeout", "dataset-import-completion-report", "dataset-import-ledger-report", "dataset-mutation-manifest"];
3
+ export declare const knownCommands: ("acceptance-check" | "capabilities-list" | "dataset-authoring-patch-collect" | "dataset-authoring-plan" | "dataset-authoring-task-build" | "dataset-bafu-authoring-patches-autofill" | "dataset-bafu-batch-import-run" | "dataset-bafu-identity-decisions-autofill" | "dataset-bafu-leaf-classification-category-map-project" | "dataset-bafu-leaf-classification-tasks-prepare" | "dataset-bafu-process-scope-e2e" | "dataset-bafu-universe-coverage-report" | "dataset-bundle-sample-rows" | "dataset-canonical-support-mappings-autofill" | "dataset-classification-decision-task-build" | "dataset-classification-decisions-apply" | "dataset-commit-handoff-plan" | "dataset-curation-cleanup" | "dataset-curation-gate" | "dataset-curation-queue-build" | "dataset-identity-decision-task-build" | "dataset-identity-decisions-apply" | "dataset-identity-preflight-index-merge" | "dataset-identity-preflight-query-audit" | "dataset-identity-preflight-requests-build" | "dataset-identity-preflight-run" | "dataset-identity-reference-rewrites-apply" | "dataset-import-completion-report" | "dataset-import-ledger-report" | "dataset-incremental-change-set-compose" | "dataset-library-authoring-plan" | "dataset-library-classification-decisions-project" | "dataset-library-decisions-apply" | "dataset-library-identity-decisions-from-preflight" | "dataset-library-index-build" | "dataset-location-decision-task-build" | "dataset-location-decisions-apply" | "dataset-location-decisions-suggest" | "dataset-mutation-manifest" | "dataset-patch-apply" | "dataset-post-authoring-finalize" | "dataset-post-write-closeout" | "dataset-process-scope-run" | "dataset-support-cache-refresh" | "dataset-tidas-import" | "dataset-tidas-validate" | "dataset-topology-convergence-compose" | "dataset-uslci-batch-import-run" | "dataset-worldsteel-batch-import-run" | "doctor" | "env-check" | "execution-capsule-admit" | "final-delivery-promote" | "init" | "profiles-list" | "route-task" | "storage-check" | "surface-audit" | "task-complete" | "tasks-check" | "tasks-list" | "tidas-handshake" | "workflow-check" | "workspace-map")[];
4
4
  export type FoundryCommand = (typeof knownCommands)[number];
5
5
  type CommandResult = {
6
6
  status?: string;
@@ -26,8 +26,8 @@ type CommandResult = {
26
26
  };
27
27
  export declare function usage(): {
28
28
  public_commands: readonly ["init", "doctor", "env-check", "workflow-check", "storage-check", "surface-audit", "acceptance-check", "workspace-map", "capabilities-list", "profiles-list", "route-task", "tasks-list", "tasks-check", "task-complete", "tidas-handshake"];
29
- dataset_policy_commands: readonly ["dataset-tidas-import", "dataset-tidas-validate", "execution-capsule-admit", "dataset-incremental-change-set-compose", "dataset-topology-convergence-compose", "dataset-curation-queue-build", "dataset-curation-gate", "dataset-authoring-plan", "dataset-authoring-task-build", "dataset-authoring-patch-collect", "dataset-identity-decision-task-build", "dataset-classification-decision-task-build", "dataset-library-classification-decisions-project", "dataset-bafu-leaf-classification-tasks-prepare", "dataset-bafu-leaf-classification-category-map-project", "dataset-bafu-identity-decisions-autofill", "dataset-bafu-authoring-patches-autofill", "dataset-classification-decisions-apply", "dataset-location-decision-task-build", "dataset-location-decisions-suggest", "dataset-location-decisions-apply", "dataset-curation-cleanup", "dataset-patch-apply", "dataset-support-cache-refresh", "dataset-canonical-support-mappings-autofill", "dataset-bundle-sample-rows", "dataset-identity-preflight-requests-build", "dataset-identity-preflight-query-audit", "dataset-identity-preflight-run", "dataset-identity-preflight-index-merge", "dataset-library-index-build", "dataset-library-authoring-plan", "dataset-library-identity-decisions-from-preflight", "dataset-library-decisions-apply", "dataset-process-scope-run", "dataset-bafu-process-scope-e2e", "dataset-bafu-batch-import-run", "dataset-uslci-batch-import-run", "dataset-worldsteel-batch-import-run", "dataset-bafu-universe-coverage-report", "dataset-identity-reference-rewrites-apply", "dataset-identity-decisions-apply", "dataset-post-authoring-finalize", "dataset-commit-handoff-plan", "dataset-post-write-closeout", "dataset-import-completion-report", "dataset-import-ledger-report", "dataset-mutation-manifest"];
30
- commands: ("acceptance-check" | "capabilities-list" | "dataset-authoring-patch-collect" | "dataset-authoring-plan" | "dataset-authoring-task-build" | "dataset-bafu-authoring-patches-autofill" | "dataset-bafu-batch-import-run" | "dataset-bafu-identity-decisions-autofill" | "dataset-bafu-leaf-classification-category-map-project" | "dataset-bafu-leaf-classification-tasks-prepare" | "dataset-bafu-process-scope-e2e" | "dataset-bafu-universe-coverage-report" | "dataset-bundle-sample-rows" | "dataset-canonical-support-mappings-autofill" | "dataset-classification-decision-task-build" | "dataset-classification-decisions-apply" | "dataset-commit-handoff-plan" | "dataset-curation-cleanup" | "dataset-curation-gate" | "dataset-curation-queue-build" | "dataset-identity-decision-task-build" | "dataset-identity-decisions-apply" | "dataset-identity-preflight-index-merge" | "dataset-identity-preflight-query-audit" | "dataset-identity-preflight-requests-build" | "dataset-identity-preflight-run" | "dataset-identity-reference-rewrites-apply" | "dataset-import-completion-report" | "dataset-import-ledger-report" | "dataset-incremental-change-set-compose" | "dataset-library-authoring-plan" | "dataset-library-classification-decisions-project" | "dataset-library-decisions-apply" | "dataset-library-identity-decisions-from-preflight" | "dataset-library-index-build" | "dataset-location-decision-task-build" | "dataset-location-decisions-apply" | "dataset-location-decisions-suggest" | "dataset-mutation-manifest" | "dataset-patch-apply" | "dataset-post-authoring-finalize" | "dataset-post-write-closeout" | "dataset-process-scope-run" | "dataset-support-cache-refresh" | "dataset-tidas-import" | "dataset-tidas-validate" | "dataset-topology-convergence-compose" | "dataset-uslci-batch-import-run" | "dataset-worldsteel-batch-import-run" | "doctor" | "env-check" | "execution-capsule-admit" | "init" | "profiles-list" | "route-task" | "storage-check" | "surface-audit" | "task-complete" | "tasks-check" | "tasks-list" | "tidas-handshake" | "workflow-check" | "workspace-map")[];
29
+ dataset_policy_commands: readonly ["dataset-tidas-import", "dataset-tidas-validate", "execution-capsule-admit", "dataset-incremental-change-set-compose", "dataset-topology-convergence-compose", "final-delivery-promote", "dataset-curation-queue-build", "dataset-curation-gate", "dataset-authoring-plan", "dataset-authoring-task-build", "dataset-authoring-patch-collect", "dataset-identity-decision-task-build", "dataset-classification-decision-task-build", "dataset-library-classification-decisions-project", "dataset-bafu-leaf-classification-tasks-prepare", "dataset-bafu-leaf-classification-category-map-project", "dataset-bafu-identity-decisions-autofill", "dataset-bafu-authoring-patches-autofill", "dataset-classification-decisions-apply", "dataset-location-decision-task-build", "dataset-location-decisions-suggest", "dataset-location-decisions-apply", "dataset-curation-cleanup", "dataset-patch-apply", "dataset-support-cache-refresh", "dataset-canonical-support-mappings-autofill", "dataset-bundle-sample-rows", "dataset-identity-preflight-requests-build", "dataset-identity-preflight-query-audit", "dataset-identity-preflight-run", "dataset-identity-preflight-index-merge", "dataset-library-index-build", "dataset-library-authoring-plan", "dataset-library-identity-decisions-from-preflight", "dataset-library-decisions-apply", "dataset-process-scope-run", "dataset-bafu-process-scope-e2e", "dataset-bafu-batch-import-run", "dataset-uslci-batch-import-run", "dataset-worldsteel-batch-import-run", "dataset-bafu-universe-coverage-report", "dataset-identity-reference-rewrites-apply", "dataset-identity-decisions-apply", "dataset-post-authoring-finalize", "dataset-commit-handoff-plan", "dataset-post-write-closeout", "dataset-import-completion-report", "dataset-import-ledger-report", "dataset-mutation-manifest"];
30
+ commands: ("acceptance-check" | "capabilities-list" | "dataset-authoring-patch-collect" | "dataset-authoring-plan" | "dataset-authoring-task-build" | "dataset-bafu-authoring-patches-autofill" | "dataset-bafu-batch-import-run" | "dataset-bafu-identity-decisions-autofill" | "dataset-bafu-leaf-classification-category-map-project" | "dataset-bafu-leaf-classification-tasks-prepare" | "dataset-bafu-process-scope-e2e" | "dataset-bafu-universe-coverage-report" | "dataset-bundle-sample-rows" | "dataset-canonical-support-mappings-autofill" | "dataset-classification-decision-task-build" | "dataset-classification-decisions-apply" | "dataset-commit-handoff-plan" | "dataset-curation-cleanup" | "dataset-curation-gate" | "dataset-curation-queue-build" | "dataset-identity-decision-task-build" | "dataset-identity-decisions-apply" | "dataset-identity-preflight-index-merge" | "dataset-identity-preflight-query-audit" | "dataset-identity-preflight-requests-build" | "dataset-identity-preflight-run" | "dataset-identity-reference-rewrites-apply" | "dataset-import-completion-report" | "dataset-import-ledger-report" | "dataset-incremental-change-set-compose" | "dataset-library-authoring-plan" | "dataset-library-classification-decisions-project" | "dataset-library-decisions-apply" | "dataset-library-identity-decisions-from-preflight" | "dataset-library-index-build" | "dataset-location-decision-task-build" | "dataset-location-decisions-apply" | "dataset-location-decisions-suggest" | "dataset-mutation-manifest" | "dataset-patch-apply" | "dataset-post-authoring-finalize" | "dataset-post-write-closeout" | "dataset-process-scope-run" | "dataset-support-cache-refresh" | "dataset-tidas-import" | "dataset-tidas-validate" | "dataset-topology-convergence-compose" | "dataset-uslci-batch-import-run" | "dataset-worldsteel-batch-import-run" | "doctor" | "env-check" | "execution-capsule-admit" | "final-delivery-promote" | "init" | "profiles-list" | "route-task" | "storage-check" | "surface-audit" | "task-complete" | "tasks-check" | "tasks-list" | "tidas-handshake" | "workflow-check" | "workspace-map")[];
31
31
  ownership_note: string;
32
32
  };
33
33
  export declare function exitCodeForCommand(command: string, result: CommandResult | null | undefined): number;
@@ -21,6 +21,7 @@ export const datasetPolicyCommands = [
21
21
  "execution-capsule-admit",
22
22
  "dataset-incremental-change-set-compose",
23
23
  "dataset-topology-convergence-compose",
24
+ "final-delivery-promote",
24
25
  "dataset-curation-queue-build",
25
26
  "dataset-curation-gate",
26
27
  "dataset-authoring-plan",
@@ -109,6 +110,8 @@ export function exitCodeForCommand(command, result) {
109
110
  return result?.foundry_wrapper?.exit_code ?? 1;
110
111
  case "execution-capsule-admit":
111
112
  return statusIs(result, ["help", "sealed"]) ? 0 : 1;
113
+ case "final-delivery-promote":
114
+ return statusIs(result, ["help", "promoted"]) ? 0 : 1;
112
115
  case "dataset-incremental-change-set-compose":
113
116
  return statusIs(result, ["help", "completed", "completed_with_holds", "completed_no_actions"])
114
117
  ? 0
@@ -2,7 +2,7 @@ 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";
5
+ import { readNativeDraftHandoff } from "./finalize-owners/native-draft-handoff.js";
6
6
  import { readHandoffReferenceEvidence } from "./finalize-owners/handoff-reference-intent.js";
7
7
  import { assertFoundryCommandSpecArtifactsCurrent, commandSpecOptionValue, parseFoundryCommandSpec, } from "@tiangong-lca/cli/command-spec";
8
8
  import { assertFoundryRuntimeContext, assertFoundryWorkspaceActive, captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoundryInputPath, resolveFoundryOutput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
@@ -84,7 +84,7 @@ function commandSpec(context, value, finalRows, actions) {
84
84
  ["flow", "process", "source"].includes(datasetType));
85
85
  if (nativeFile) {
86
86
  if (!nativeSave)
87
- fail("execution_command_unadmitted", "Native insert contracts require the reviewed dataset save-draft operation.");
87
+ fail("execution_command_unadmitted", "Native draft contracts require the reviewed dataset save-draft operation.");
88
88
  const fact = selected(context, nativeFile);
89
89
  const bound = contractArtifacts[0];
90
90
  if (resolveSpecArtifact(context, bound.path) !== fact.path ||
@@ -93,7 +93,7 @@ function commandSpec(context, value, finalRows, actions) {
93
93
  fail("execution_native_contract_unbound", "Native contract must bind the independently selected current bytes.");
94
94
  readFoundryInput(context, fact.path, 8 * 1024 * 1024);
95
95
  readFoundryInput(context, finalRows.path);
96
- const native = readNativeInsertHandoff({
96
+ const native = readNativeDraftHandoff({
97
97
  contractFile: fact.path,
98
98
  rowsFile: finalRows.path,
99
99
  datasetType: datasetType,
@@ -5,6 +5,20 @@ import { withBatchRunLock } from "@tiangong-lca/cli/batch";
5
5
  import { assertFoundryRuntimeContext, assertFoundryWorkspaceWrite, assertPendingFoundryTaskIntent, FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
6
6
  import { parseFoundryTaskStartSpec, taskStartSpecFingerprint, } from "./foundry-task-start-spec.js";
7
7
  import { sha256Json } from "./identity-preflight-proof.js";
8
+ import { assertFoundryNoDispatchSuccessor } from "./foundry-successor-predecessor.js";
9
+ function successorLinks(chain) {
10
+ return new Map(chain.slice(0, -1).map((link, index) => [link.task_id, chain[index + 1]]));
11
+ }
12
+ /**
13
+ * An explicitly declared predecessor must be a retained revision of this same request. A declaration
14
+ * naming a foreign task grants nothing and is refused, so a cross-request or dangling binding can
15
+ * never be mistaken for a verified successor link.
16
+ */
17
+ function requireDeclaredPredecessor(spec, retained) {
18
+ const declared = spec.repair?.predecessor ?? null;
19
+ if (declared && !retained.some((revision) => revision.task_id === declared.task_id))
20
+ fail("facade_predecessor_readback_required", `Declared predecessor ${declared.task_id} is not a retained revision of this request; use its original owner for status/readback before any revision can continue.`);
21
+ }
8
22
  export const FOUNDRY_FACADE_REQUEST_INDEX_SCHEMA = "tiangong-foundry.facade-request-index.v1";
9
23
  export const FOUNDRY_FACADE_TASK_POINTER_SCHEMA = "tiangong-foundry.facade-task-pointer.v1";
10
24
  const shaPattern = /^[0-9a-f]{64}$/u;
@@ -258,7 +272,14 @@ function pointer(value, context) {
258
272
  fail("facade_task_pointer_invalid", "Facade task pointer is malformed.");
259
273
  return item;
260
274
  }
261
- function requireUnattemptedPredecessors(context, predecessors) {
275
+ /**
276
+ * Every retained predecessor must be unattempted, or carry its own explicitly declared successor
277
+ * whose evidence proves the predecessor's only terminal outcome was a CLI failure that dispatched
278
+ * nothing. The exception is additive: the failure code and message for every other case are
279
+ * unchanged, and it is re-derived from the predecessor's own index on every call, so start, status
280
+ * and resume always agree.
281
+ */
282
+ function requireUnattemptedPredecessors(context, predecessors, successors) {
262
283
  for (const predecessor of predecessors) {
263
284
  const workspaces = path.join(context.controlRoot, "workspaces"), taskRoot = path.join(workspaces, predecessor.task_id), jobFile = path.join(taskRoot, "foundry-job.json");
264
285
  try {
@@ -297,8 +318,21 @@ function requireUnattemptedPredecessors(context, predecessors) {
297
318
  fail("facade_predecessor_history_invalid", "Predecessor attempts must remain a contained directory.");
298
319
  const directory = fs.opendirSync(attempts);
299
320
  try {
300
- if (directory.readSync())
301
- fail("facade_predecessor_readback_required", `Retained predecessor ${predecessor.task_id} has attempt evidence; use its original owner for status/readback before any revision can continue.`);
321
+ if (directory.readSync()) {
322
+ const successor = successors.get(predecessor.task_id);
323
+ if (!successor)
324
+ fail("facade_predecessor_readback_required", `Retained predecessor ${predecessor.task_id} has attempt evidence; use its original owner for status/readback before any revision can continue.`);
325
+ assertFoundryNoDispatchSuccessor({
326
+ context,
327
+ predecessorTaskId: predecessor.task_id,
328
+ predecessorInputs: predecessor.inputs,
329
+ successor: {
330
+ task_id: successor.task_id,
331
+ spec: successor.spec,
332
+ inputs: successor.inputs,
333
+ },
334
+ });
335
+ }
302
336
  }
303
337
  finally {
304
338
  directory.closeSync();
@@ -341,7 +375,18 @@ export async function registerFoundryFacadeTask(context, options) {
341
375
  const taskId = `task-${requestSha256}-r${String(revisionNumber).padStart(4, "0")}`;
342
376
  assertPendingFoundryTaskIntent(context, taskId, spec.request_id, spec.actor_id, fingerprint);
343
377
  const predecessors = stored.index?.revisions.filter((entry) => entry.task_id !== taskId) ?? [];
344
- requireUnattemptedPredecessors(context, predecessors);
378
+ // The incoming revision is the chain's last link: an earlier predecessor's recorded exception
379
+ // is only current while this spec still declares it with the same terminal report digest.
380
+ const successors = successorLinks([
381
+ ...(stored.index?.revisions ?? []).map((entry) => ({
382
+ task_id: entry.task_id,
383
+ spec: entry.spec,
384
+ inputs: entry.inputs,
385
+ })),
386
+ { task_id: taskId, spec, inputs: options.inputs },
387
+ ]);
388
+ requireDeclaredPredecessor(spec, [...predecessors, { task_id: taskId }]);
389
+ requireUnattemptedPredecessors(context, predecessors, successors);
345
390
  let task;
346
391
  try {
347
392
  task = options.createOrLoad(taskId);
@@ -359,7 +404,7 @@ export async function registerFoundryFacadeTask(context, options) {
359
404
  throw error;
360
405
  }
361
406
  let selected = latest;
362
- requireUnattemptedPredecessors(context, predecessors);
407
+ requireUnattemptedPredecessors(context, predecessors, successors);
363
408
  if (!latest || latest.fingerprint_sha256 !== fingerprint) {
364
409
  const unsigned = {
365
410
  revision: revisionNumber,
@@ -434,7 +479,12 @@ export function loadFoundryFacadeTaskRecord(context, taskId, actorId) {
434
479
  fail("facade_task_pointer_invalid", "Facade task pointer has no current request revision.");
435
480
  if (selected.spec.actor_id !== actorId)
436
481
  fail("task_actor_mismatch", "Current actor does not match the registered task intent.");
437
- requireUnattemptedPredecessors(context, request.revisions.slice(0, taskPointer.revision - 1));
482
+ requireDeclaredPredecessor(selected.spec, request.revisions.slice(0, taskPointer.revision - 1));
483
+ requireUnattemptedPredecessors(context, request.revisions.slice(0, taskPointer.revision - 1), successorLinks(request.revisions.map((entry) => ({
484
+ task_id: entry.task_id,
485
+ spec: entry.spec,
486
+ inputs: entry.inputs,
487
+ }))));
438
488
  return Object.freeze({
439
489
  request_sha256: taskPointer.request_sha256,
440
490
  revision: selected.revision,
@@ -0,0 +1,19 @@
1
+ import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ import type { ArtifactEntry } from "./foundry-task-types.ts";
3
+ import { type FoundryInteractionInput, type FoundryInteractionState } from "./foundry-interaction-types.ts";
4
+ export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, FOUNDRY_INTERACTION_COMMAND, FOUNDRY_INTERACTION_REPORT, } from "./foundry-interaction-types.ts";
5
+ export type { FoundryInteractionInput, FoundryInteractionState, } from "./foundry-interaction-types.ts";
6
+ export interface SelectedFoundryInteractionInput {
7
+ readonly spec: FoundryInteractionInput;
8
+ readonly descriptor: FoundryInputFact;
9
+ }
10
+ export declare function parseFoundryInteractionInput(value: unknown): FoundryInteractionInput;
11
+ export declare function advanceFoundryInteractionState(previous: FoundryInteractionState | null, input: FoundryInteractionInput, currentSha256: string | null, availableEvidence: ReadonlySet<string>, allowedTypes: ReadonlySet<string>): FoundryInteractionState;
12
+ export declare function readSelectedFoundryInteractionBytes(fact: FoundryInputFact): Buffer;
13
+ export declare function selectFoundryInteractionInput(context: FoundryRuntimeContext, file: string): SelectedFoundryInteractionInput;
14
+ export declare function assertSelectedFoundryInteractionInput(input: SelectedFoundryInteractionInput): void;
15
+ export declare function currentFoundryInteractionState(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[]): {
16
+ entry: ArtifactEntry;
17
+ state: FoundryInteractionState;
18
+ } | null;
19
+ export { applicableFoundryInteractionDigest, applicableFoundryInteractionProjection, currentFoundryAssumptions, currentFoundryAssumptionsForType, currentFoundryDecisions, currentFoundryDecisionsForType, currentFoundryInvestigations, currentFoundryQuestions, } from "./foundry-interaction-projection.ts";