@tiangong-lca/foundry 0.1.18 → 0.1.19

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 (84) hide show
  1. package/docs/package-distribution-contract.md +5 -5
  2. package/docs/public-runtime-contract.md +12 -0
  3. package/docs/runtime-context-contract.md +2 -0
  4. package/package-dist/assets/foundry-package-descriptor.json +268 -98
  5. package/package-dist/scripts/foundry-facade.js +3 -0
  6. package/package-dist/scripts/foundry-runtime.d.ts +1 -1
  7. package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
  8. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
  9. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
  10. package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +9 -0
  11. package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
  12. package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
  13. package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
  14. package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
  15. package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
  16. package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
  17. package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
  18. package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
  19. package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
  20. package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
  21. package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
  22. package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
  23. package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +21 -0
  24. package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
  25. package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
  26. package/package-dist/scripts/lib/foundry-edge-session.js +69 -0
  27. package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
  28. package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
  29. package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
  30. package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
  31. package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
  32. package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
  33. package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
  34. package/package-dist/scripts/lib/foundry-execution-admission.js +24 -2
  35. package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
  36. package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
  37. package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
  38. package/package-dist/scripts/lib/foundry-finalize-owners.js +68 -2
  39. package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
  40. package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
  41. package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
  42. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +20 -0
  43. package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
  44. package/package-dist/scripts/lib/foundry-package-contract.d.ts +2 -2
  45. package/package-dist/scripts/lib/foundry-package-contract.js +2 -2
  46. package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
  47. package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
  48. package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
  49. package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
  50. package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
  51. package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
  52. package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
  53. package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
  54. package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
  55. package/package-dist/scripts/lib/foundry-runtime-identity.js +19 -1
  56. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  57. package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
  58. package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
  59. package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
  60. package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
  61. package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
  62. package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
  63. package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
  64. package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
  65. package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
  66. package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
  67. package/package-dist/scripts/lib/foundry-workflow-assessment.js +67 -29
  68. package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
  69. package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
  70. package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
  71. package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
  72. package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
  73. package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
  74. package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
  75. package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
  76. package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
  77. package/package-dist/scripts/lib/foundry-workflow-semantic.js +41 -21
  78. package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
  79. package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
  80. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  81. package/package.json +2 -2
  82. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  83. package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
  84. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -199,6 +199,9 @@ function failure(operation, taskId, error, identity = null) {
199
199
  "EMFILE",
200
200
  "ENFILE",
201
201
  "EBUSY",
202
+ "BATCH_RUN_LOCK_TIMEOUT",
203
+ "BATCH_RUN_LOCK_IDENTITY_CONFLICT",
204
+ "ERR_SYSTEM_ERROR",
202
205
  "UNKNOWN",
203
206
  "ERR_INVALID_ARG_TYPE",
204
207
  "ERR_INVALID_ARG_VALUE",
@@ -138,7 +138,7 @@ export declare function createFoundryRuntime(context: FoundryRuntimeContext, qua
138
138
  capsule_sha256: string;
139
139
  }>>;
140
140
  rehydrateExecution: (identity: VerifiedFoundryIdentity, options: RehydrateFoundryExecutionAdmissionOptions) => Promise<FoundryExecutionAdmission>;
141
- admitExecution: (identity: VerifiedFoundryIdentity, admission: FoundryExecutionAdmission) => Promise<import("@tiangong-lca/cli/command-spec").FoundryCommandSpec>;
141
+ admitExecution: (identity: VerifiedFoundryIdentity, admission: FoundryExecutionAdmission) => Promise<import("./lib/foundry-edge-support-plan.ts").EdgeSupportPlan | import("@tiangong-lca/cli/command-spec").FoundryCommandSpec>;
142
142
  profiles: () => import("./lib/import-curation/internal/profiles-config.ts").ImportProfilesList;
143
143
  describe: () => {
144
144
  platform: string;
@@ -290,7 +290,9 @@ export function createIdentityPreflightRunCommands({ executionEnvironment = proc
290
290
  maxAgeMs: positiveIntegerOption(options.authReceiptMaxAgeMs, 300_000) ?? 300_000,
291
291
  expectedProjectRef,
292
292
  expectedUserId,
293
- sessionMode: executionEnvironment.TIANGONG_LCA_AUTH_MODE === "access_token" ? "headless" : "oauth",
293
+ sessionMode: ["access-token", "access_token"].includes(executionEnvironment.TIANGONG_LCA_AUTH_MODE ?? "")
294
+ ? "headless"
295
+ : "oauth",
294
296
  });
295
297
  }
296
298
  const logDir = path.join(outDir, "logs");
@@ -3,7 +3,8 @@ type CliResolution = {
3
3
  command: string;
4
4
  args: string[];
5
5
  display: string;
6
- package: JsonRecord | null;
6
+ package: string | JsonRecord | null;
7
+ package_version?: string | null;
7
8
  };
8
9
  export type CliWrapperOptions = Record<string, unknown> & {
9
10
  help?: unknown;
@@ -48,5 +49,75 @@ export type CliWrapperFactoryDependencies = {
48
49
  export declare function createCliWrapperCommands({ executionEnvironment, executionCwd, appendOption, appendRepeatedOptions, repoRoot, resolveTiangongLcaCliCommand, resolveTiangongLcaCliBin, }: CliWrapperFactoryDependencies): {
49
50
  runDatasetCurationQueueBuild: (options: CliWrapperOptions) => JsonRecord;
50
51
  runDatasetPatchApply: (options: CliWrapperOptions) => JsonRecord;
52
+ runDatasetQaStage: (stage: string, argv: string[]) => {
53
+ stage: string;
54
+ exit_code: number;
55
+ report: {
56
+ schema: string;
57
+ status: string;
58
+ rows_file: string;
59
+ validation_input: string;
60
+ validation_operation: string;
61
+ validations: {
62
+ id: string;
63
+ version: string;
64
+ result: string;
65
+ reference_documents: string | null;
66
+ complete_sha256: string;
67
+ }[];
68
+ rows: {
69
+ findings: {
70
+ entity_id: string;
71
+ version: string;
72
+ severity: string;
73
+ code: string;
74
+ path: string;
75
+ message: string;
76
+ }[];
77
+ }[];
78
+ findings: {
79
+ entity_id: string;
80
+ version: string;
81
+ severity: string;
82
+ code: string;
83
+ path: string;
84
+ message: string;
85
+ }[];
86
+ files: {
87
+ report: string;
88
+ };
89
+ } | {
90
+ status: string;
91
+ policy_decision_owner: string;
92
+ qa_mode: string;
93
+ mass_balance: import("../foundry-process-mass-balance.ts").ProcessMassBalance[];
94
+ findings: {
95
+ process_file: string;
96
+ severity: "info" | "warning" | "blocker";
97
+ code: string;
98
+ methodology_rule_id: string | null;
99
+ message: string;
100
+ source: "rule";
101
+ evidence?: {
102
+ [x: string]: unknown;
103
+ };
104
+ }[];
105
+ schema: string;
106
+ rows_file: string;
107
+ reference_evidence: import("../foundry-runtime-context-types.ts").FoundryInputFact[];
108
+ files: {
109
+ report: string;
110
+ };
111
+ };
112
+ report_file: string;
113
+ cli_validation?: {
114
+ report: string;
115
+ exit: number;
116
+ } | undefined;
117
+ status: string;
118
+ command: string;
119
+ args: string[];
120
+ stderr: string;
121
+ } | null;
51
122
  };
52
123
  export {};
@@ -1,8 +1,14 @@
1
1
  import { spawnSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
2
4
  import path from "node:path";
3
5
  import process from "node:process";
6
+ import { buildFoundryCurationQueue } from "../foundry-curation-queue.js";
7
+ import { applyTypedAuthoringPatch } from "../foundry-typed-authoring-patch.js";
8
+ import { runTypedDatasetQa } from "../foundry-typed-flow-qa.js";
9
+ import { createFoundryIsolatedChildEnvironment } from "../foundry-runtime-environment.js";
4
10
  export function createCliWrapperCommands({ executionEnvironment = process.env, executionCwd, appendOption, appendRepeatedOptions, repoRoot, resolveTiangongLcaCliCommand, resolveTiangongLcaCliBin, }) {
5
- function runJsonCli(cliArgs, errorMessage) {
11
+ function runJsonCli(cliArgs, errorMessage, temporary) {
6
12
  const cli = resolveTiangongLcaCliCommand
7
13
  ? resolveTiangongLcaCliCommand()
8
14
  : {
@@ -13,8 +19,10 @@ export function createCliWrapperCommands({ executionEnvironment = process.env, e
13
19
  };
14
20
  const spawnArgs = [...cli.args, ...cliArgs];
15
21
  const result = spawnSync(cli.command, spawnArgs, {
16
- cwd: executionCwd ?? repoRoot,
17
- env: executionEnvironment,
22
+ cwd: temporary ?? executionCwd ?? repoRoot,
23
+ env: temporary
24
+ ? createFoundryIsolatedChildEnvironment({ tempRoot: temporary })
25
+ : executionEnvironment,
18
26
  encoding: "utf8",
19
27
  // Mega-scope stages emit large JSON payloads on stdout; the 1MB spawnSync
20
28
  // default overflows with ENOBUFS. Cap below V8's max string length.
@@ -46,6 +54,57 @@ export function createCliWrapperCommands({ executionEnvironment = process.env, e
46
54
  stderr: result.stderr || "",
47
55
  };
48
56
  }
57
+ const localPath = (name) => path.resolve(executionCwd ?? repoRoot, String(name));
58
+ function writeLocalText(file, value) {
59
+ fs.mkdirSync(path.dirname(file), { recursive: true });
60
+ fs.writeFileSync(file, value, { mode: 0o600 });
61
+ }
62
+ const localStage = (temporary) => ({
63
+ workspace: temporary,
64
+ readInput: fs.readFileSync,
65
+ readRowsFile: (file) => fs.readFileSync(file, "utf8"),
66
+ readResult(file) {
67
+ if (!fs.lstatSync(file).isFile())
68
+ throw new Error("Expected a regular typed CLI result file.");
69
+ return fs.readFileSync(file);
70
+ },
71
+ writeJson: (file, value) => writeLocalText(file, JSON.stringify(value, null, 2) + "\n"),
72
+ run(args) {
73
+ const { exitCode, report } = runJsonCli(args, "Typed CLI stage did not emit JSON.", temporary);
74
+ return { exit: exitCode, report, validate: (check) => check() };
75
+ },
76
+ });
77
+ function runDatasetQaStage(stage, argv) {
78
+ const qaType = argv[0] === "qa" ? argv[1] : null;
79
+ if (qaType !== "flow" && qaType !== "process" && qaType !== "lifecyclemodel")
80
+ return null;
81
+ const cli = resolveTiangongLcaCliCommand?.();
82
+ if (cli?.package_version !== "0.4.0")
83
+ return null;
84
+ const rowsFile = localPath(argv[argv.indexOf("--rows-file") + 1]);
85
+ const directory = localPath(argv[argv.indexOf("--out-dir") + 1]);
86
+ const referenceFiles = argv.flatMap((value, index) => value === "--reference-rows-file" ? [localPath(argv[index + 1])] : []);
87
+ const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "foundry-local-qa-"));
88
+ try {
89
+ const result = runTypedDatasetQa(qaType, rowsFile, directory, { referenceFiles }, localStage(temporary));
90
+ return {
91
+ stage,
92
+ exit_code: result.exit || (qaType !== "process" && result.report.findings.length) ? 2 : 0,
93
+ report: result.report,
94
+ report_file: result.reportFile,
95
+ ...(qaType === "process"
96
+ ? { cli_validation: { report: result.validationReportFile, exit: result.exit } }
97
+ : {}),
98
+ status: result.report.status,
99
+ command: cli.command,
100
+ args: [...cli.args, "dataset", qaType === "lifecyclemodel" ? "model" : qaType, "validate"],
101
+ stderr: "",
102
+ };
103
+ }
104
+ finally {
105
+ fs.rmSync(temporary, { recursive: true, force: true });
106
+ }
107
+ }
49
108
  function runDatasetCurationQueueBuild(options) {
50
109
  if (options.help) {
51
110
  return {
@@ -73,6 +132,33 @@ export function createCliWrapperCommands({ executionEnvironment = process.env, e
73
132
  appendRepeatedOptions(cliArgs, "--exclude-process-id", options.excludeProcessId || options.excludeProcessIds);
74
133
  appendOption(cliArgs, "--process-limit", options.processLimit);
75
134
  appendOption(cliArgs, "--out-dir", outDir);
135
+ const cliVersion = resolveTiangongLcaCliCommand?.().package_version;
136
+ if (cliVersion === "0.4.0") {
137
+ const cwd = executionCwd ?? repoRoot;
138
+ const file = (name) => path.resolve(cwd, name);
139
+ const repeated = (flag) => cliArgs.flatMap((name, index) => (name === flag ? [cliArgs[index + 1]] : []));
140
+ const processLimit = repeated("--process-limit")[0];
141
+ const limit = processLimit === undefined ? undefined : Number.parseInt(processLimit, 10);
142
+ if (limit !== undefined && (!Number.isInteger(limit) || limit < 1))
143
+ throw new Error("--process-limit must be a positive integer.");
144
+ const [processesFile] = repeated("--processes");
145
+ if (!processesFile)
146
+ throw new Error("--processes requires a Process rows file.");
147
+ const [flowsFile] = repeated("--flows");
148
+ const report = buildFoundryCurationQueue({
149
+ processes: file(processesFile),
150
+ flows: flowsFile ? file(flowsFile) : null,
151
+ support: repeated("--support").map(file),
152
+ external: repeated("--external-flow-ref").map(file),
153
+ excludeProcessIds: repeated("--exclude-process-id"),
154
+ processLimit: limit,
155
+ outDir: file(String(outDir)),
156
+ });
157
+ return {
158
+ ...report,
159
+ foundry_wrapper: { exit_code: report.blockers.length ? 1 : 0, owner: "foundry" },
160
+ };
161
+ }
76
162
  const { cliBin, cli, spawnArgs, exitCode, report, stderr } = runJsonCli(cliArgs, "tiangong-lca dataset curation-queue build did not emit JSON.");
77
163
  return {
78
164
  ...report,
@@ -110,6 +196,39 @@ export function createCliWrapperCommands({ executionEnvironment = process.env, e
110
196
  const patch = options.patch || options.patchFile || options.patches || options.suggestions;
111
197
  const outDir = (options.outDir || ".foundry/workspaces/dataset-patch-apply");
112
198
  const out = options.out || options.outFile || path.join(outDir, "patched-rows.jsonl");
199
+ if (resolveTiangongLcaCliCommand?.().package_version === "0.4.0") {
200
+ if (!input || !patch)
201
+ throw new Error("Dataset patch apply requires --input and --patch.");
202
+ const packageDir = options.authoringPackageDir || options.authoringPackagesDir;
203
+ const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "foundry-local-patch-"));
204
+ const io = localStage(temporary);
205
+ try {
206
+ const result = applyTypedAuthoringPatch({
207
+ input: localPath(input),
208
+ patch: localPath(patch),
209
+ output: localPath(out),
210
+ directory: localPath(outDir),
211
+ packageDirectory: packageDir ? localPath(packageDir) : undefined,
212
+ requirePackage: options.requireAuthoringPackage === true ||
213
+ options.requireAuthoringPackage === "true",
214
+ requireClosure: options.requireActionItemClosure === true ||
215
+ options.requireActionItemClosure === "true",
216
+ writeText: writeLocalText,
217
+ writeJson: io.writeJson,
218
+ }, io);
219
+ return {
220
+ ...result.report,
221
+ foundry_wrapper: {
222
+ exit_code: result.exit,
223
+ owner: "tiangong-lca-cli",
224
+ remote_write_mode: "read-only",
225
+ },
226
+ };
227
+ }
228
+ finally {
229
+ fs.rmSync(temporary, { recursive: true, force: true });
230
+ }
231
+ }
113
232
  const cliArgs = ["dataset", "patch", "apply", "--json"];
114
233
  appendOption(cliArgs, "--input", input);
115
234
  appendOption(cliArgs, "--patch", patch);
@@ -142,5 +261,6 @@ export function createCliWrapperCommands({ executionEnvironment = process.env, e
142
261
  return {
143
262
  runDatasetCurationQueueBuild,
144
263
  runDatasetPatchApply,
264
+ runDatasetQaStage,
145
265
  };
146
266
  }
@@ -104,6 +104,10 @@ interface FinalizeStage extends JsonRecord {
104
104
  stderr?: string;
105
105
  report?: FinalizeStage;
106
106
  report_file?: string | null;
107
+ cli_validation?: {
108
+ report: string;
109
+ exit: number;
110
+ };
107
111
  rust_report?: unknown;
108
112
  binary_version?: unknown;
109
113
  counts?: CountMap;
@@ -231,5 +235,10 @@ interface FinalizeDependencies {
231
235
  }
232
236
  export declare function createPostAuthoringFinalizeCommands({ appendOption, applyCanonicalSupportRewrites, applyIdentityReferenceRewrites, asText, profileFor, blockersFromLocationAuditStage, buildLibraryContactPayload, booleanOption, compactStageReport, cloneJson, contactGlobalReference, datasetIdentity, datasetRowsFileStem, ensureArray, externalizeUnresolvedProcessFlowExchanges, fileExists, normalizedList, nowIso, postAuthoringPrewriteGateBlockers, processSourceReferenceRows, profileFullContextRequirement, repoRelativeMaybe, loadCanonicalSupportCache, repoRelativePath, repoRoot, reportFileFromCliStage, readRowsFile, readReferenceBytes, repairTrueSourceClassification, repairTrueSourceDescription, repairTrueSourceIdentity, resolveRepoPath, rewriteCanonicalSourceReferences, rewriteContactReferences, rewriteTrueSourceReferenceDescriptions, runDatasetCommitHandoffPlan, runDatasetCurationCleanup, runDatasetCurationGate, runDatasetMutationManifest, runFinalizeAutoCurationQueue, runFinalizeIdentityPreflightStage, runTidasRowsValidation, runTiangongJsonStage, skippedPrewriteStage, sourceReferenceSemanticBlockers, sourceReferenceRewritesFileForRowsFile, sourceSemanticSummary, unique, writeFinalizeImportLedger, writeJson, writeJsonLines, }: FinalizeDependencies): {
233
237
  runDatasetPostAuthoringFinalize: (options: FinalizeOptions) => FinalizeStage;
238
+ finalizeStages: (options: FinalizeOptions, asynchronousIdentity: boolean) => Generator<{
239
+ rowsFile: string;
240
+ outDir: string;
241
+ options: FinalizeOptions;
242
+ }, FinalizeStage, FinalizeStage>;
234
243
  };
235
244
  export {};
@@ -623,7 +623,7 @@ export function createPostAuthoringFinalizeCommands({ appendOption, applyCanonic
623
623
  output_rows_file: repoRelativePath(outputRowsFile),
624
624
  };
625
625
  }
626
- function runDatasetPostAuthoringFinalize(options) {
626
+ function* finalizeStages(options, asynchronousIdentity) {
627
627
  const finalizeStartedAtUtc = nowIso();
628
628
  const finalizeStartedAtMs = Date.now();
629
629
  const finalizeTimings = [];
@@ -1038,14 +1038,27 @@ export function createPostAuthoringFinalizeCommands({ appendOption, applyCanonic
1038
1038
  if (sourceContactSupportFinalizeRequested) {
1039
1039
  sourceContactSupportFinalize = timeStage("source_contact_support_finalize", finalizeSourceContactSupport);
1040
1040
  }
1041
- const identityPreflightRunStage = timeStage("identity_preflight_run", () => runFinalizeIdentityPreflightStage({
1041
+ const identityRequest = {
1042
1042
  rowsFile: cleanedRowsFile,
1043
1043
  outDir,
1044
- options: {
1045
- ...options,
1046
- type: datasetType,
1047
- },
1048
- }));
1044
+ options: { ...options, type: datasetType },
1045
+ };
1046
+ let identityPreflightRunStage;
1047
+ if (asynchronousIdentity && booleanOption(options.runIdentityPreflight)) {
1048
+ const started_at_utc = nowIso();
1049
+ const startedAt = Date.now();
1050
+ identityPreflightRunStage = yield identityRequest;
1051
+ finalizeTimings.push({
1052
+ stage: "identity_preflight_run",
1053
+ status: stageStatus(identityPreflightRunStage),
1054
+ started_at_utc,
1055
+ finished_at_utc: nowIso(),
1056
+ duration_ms: Date.now() - startedAt,
1057
+ });
1058
+ }
1059
+ else {
1060
+ identityPreflightRunStage = timeStage("identity_preflight_run", () => runFinalizeIdentityPreflightStage(identityRequest));
1061
+ }
1049
1062
  const curationQueueStage = timeStage("curation_queue", () => runFinalizeAutoCurationQueue({
1050
1063
  datasetType,
1051
1064
  rowsFile,
@@ -1151,6 +1164,7 @@ export function createPostAuthoringFinalizeCommands({ appendOption, applyCanonic
1151
1164
  const curationGate = timeStage("post_authoring_curation_gate", () => requiresCurationGate
1152
1165
  ? runDatasetCurationGate({
1153
1166
  repoRoot,
1167
+ cliValidation: qaStage.cli_validation,
1154
1168
  options: {
1155
1169
  ...options,
1156
1170
  type: datasetType,
@@ -1314,6 +1328,15 @@ export function createPostAuthoringFinalizeCommands({ appendOption, applyCanonic
1314
1328
  if (prewriteGateReady) {
1315
1329
  stage.report_file = reportFileFromCliStage(stage, ["files.report"], path.join(remoteOutDir, "outputs", "remote-verification-report.json"));
1316
1330
  remoteVerifyReportFile = stage.report_file;
1331
+ if (stage.report?.schema === "tiangong-foundry.edge-support-precommit.v1" &&
1332
+ stage.status !== "passed_remote_verification") {
1333
+ prewriteGateBlockers.push({
1334
+ code: "edge_precommit_verification_blocked",
1335
+ stage: "remote_verify_precommit",
1336
+ message: "Resolve the exact remote identity and dependency checks before requesting write approval.",
1337
+ report: repoRelativeMaybe(remoteVerifyReportFile),
1338
+ });
1339
+ }
1317
1340
  }
1318
1341
  return stage;
1319
1342
  });
@@ -1756,5 +1779,11 @@ export function createPostAuthoringFinalizeCommands({ appendOption, applyCanonic
1756
1779
  },
1757
1780
  };
1758
1781
  }
1759
- return { runDatasetPostAuthoringFinalize };
1782
+ function runDatasetPostAuthoringFinalize(options) {
1783
+ const result = finalizeStages(options, false).next();
1784
+ if (!result.done)
1785
+ throw new Error("Unexpected asynchronous identity stage.");
1786
+ return result.value;
1787
+ }
1788
+ return { runDatasetPostAuthoringFinalize, finalizeStages };
1760
1789
  }
@@ -45,7 +45,7 @@ export function createFoundryAuthenticationEnvironment(authentication, sessionRe
45
45
  else {
46
46
  if (!authentication.accessToken || !authentication.apiBaseUrl || !authentication.publishableKey)
47
47
  reject("headless_target_required", "Headless mode requires the existing CLI explicit target and process-only actor token.");
48
- environment.TIANGONG_LCA_AUTH_MODE = "access_token";
48
+ environment.TIANGONG_LCA_AUTH_MODE = "access-token";
49
49
  environment.TIANGONG_LCA_ACCESS_TOKEN = authentication.accessToken;
50
50
  environment.TIANGONG_LCA_API_BASE_URL = authentication.apiBaseUrl;
51
51
  environment.TIANGONG_LCA_SUPABASE_PUBLISHABLE_KEY = authentication.publishableKey;
@@ -0,0 +1,73 @@
1
+ type Entity = "support" | "flow" | "process";
2
+ type QueueOptions = {
3
+ processes: string;
4
+ flows?: string | null;
5
+ support?: readonly string[];
6
+ external?: readonly string[];
7
+ excludeProcessIds?: readonly string[];
8
+ processLimit?: number;
9
+ outDir: string;
10
+ readInput?: (file: string) => Buffer;
11
+ };
12
+ export declare function buildFoundryCurationQueue(options: QueueOptions): {
13
+ schema_version: number;
14
+ producer: string;
15
+ generated_at_utc: string;
16
+ status: string;
17
+ out_dir: string;
18
+ inputs: {
19
+ processes: string;
20
+ flows: string | null;
21
+ support: string[];
22
+ external_flow_refs: string[];
23
+ };
24
+ counts: {
25
+ support_rows: number;
26
+ flow_rows: number;
27
+ process_rows: number;
28
+ external_flow_refs: number;
29
+ tasks: number;
30
+ blockers: number;
31
+ };
32
+ hashes: {
33
+ inputs: Record<string, string>;
34
+ task_order: string;
35
+ };
36
+ files: {
37
+ manifest: string;
38
+ tasks: string;
39
+ blockers: string;
40
+ locks: string;
41
+ };
42
+ tasks: {
43
+ schema_version: number;
44
+ entity_type: Entity;
45
+ task_id: string;
46
+ entity_id: string;
47
+ version: string;
48
+ lock_key: string;
49
+ depends_on: string[];
50
+ work_dir: string;
51
+ input_rows_file: string;
52
+ checkpoint_file: string;
53
+ run_plan_file: string;
54
+ closure_file: string;
55
+ }[];
56
+ blockers: {
57
+ schema_version: number;
58
+ code: string;
59
+ severity: string;
60
+ entity_type: string;
61
+ entity_id: string;
62
+ version: string;
63
+ message: string;
64
+ details: {
65
+ missing_flow_refs: {
66
+ id: string;
67
+ version: string | null;
68
+ path: string;
69
+ }[];
70
+ };
71
+ }[];
72
+ };
73
+ export {};