@tiangong-lca/foundry 0.1.16 → 0.1.17

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 (27) hide show
  1. package/README.md +5 -5
  2. package/docs/architecture.md +7 -5
  3. package/docs/foundry-task-contracts.md +2 -2
  4. package/docs/package-distribution-contract.md +10 -10
  5. package/docs/public-runtime-contract.md +8 -4
  6. package/docs/runtime-context-contract.md +5 -5
  7. package/docs/task-authorization-contract.md +2 -2
  8. package/package-dist/assets/foundry-package-descriptor.json +57 -37
  9. package/package-dist/scripts/lib/foundry-package-contract.d.ts +2 -2
  10. package/package-dist/scripts/lib/foundry-package-contract.js +2 -2
  11. package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +20 -0
  12. package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +191 -0
  13. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  14. package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
  15. package/package-dist/scripts/lib/foundry-workflow-assessment.js +47 -9
  16. package/package-dist/scripts/lib/foundry-workflow-io.js +3 -2
  17. package/package-dist/scripts/lib/foundry-workflow-state.js +10 -0
  18. package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +5 -1
  19. package/package-dist/scripts/lib/import-curation/curation-gate.js +29 -1
  20. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  21. package/package-dist/scripts/lib/tidas-adapter.js +38 -15
  22. package/package-dist/scripts/lib/tidas-process-flow-context.d.ts +12 -0
  23. package/package-dist/scripts/lib/tidas-process-flow-context.js +96 -0
  24. package/package.json +2 -2
  25. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  26. package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
  27. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -0,0 +1,191 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import { sha256Text } from "./identity-preflight-proof.js";
4
+ import { FoundryContextError } from "./foundry-runtime-context.js";
5
+ import { sha256Json } from "./identity-preflight-proof.js";
6
+ import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
7
+ function record(value) {
8
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
9
+ }
10
+ function token(...values) {
11
+ for (const value of values)
12
+ if (typeof value === "string" && value.trim())
13
+ return value.trim();
14
+ return null;
15
+ }
16
+ const layerNames = ["schema", "authoring_evidence", "content", "multilingual"];
17
+ const profile = "tidas.process-allocation-reference.v1";
18
+ const tolerance = 0.0010000001;
19
+ function fail() {
20
+ throw new FoundryContextError("workflow_validation_invalid", "Owner CLI validation must bind the exact current Process rows, layers and Flow evidence.");
21
+ }
22
+ function object(value) {
23
+ if (!value || typeof value !== "object" || Array.isArray(value))
24
+ return fail();
25
+ return value;
26
+ }
27
+ function findings(value, statuses) {
28
+ if (!statuses.includes(String(value.status)) || !Array.isArray(value.issues))
29
+ fail();
30
+ if (value.issue_count !== value.issues.length)
31
+ fail();
32
+ if ((value.status === "passed") !== (value.issues.length === 0))
33
+ fail();
34
+ return value.issues.map((issue) => {
35
+ const item = object(issue);
36
+ if (typeof item.code !== "string" ||
37
+ !item.code ||
38
+ typeof item.path !== "string" ||
39
+ typeof item.message !== "string")
40
+ fail();
41
+ return item;
42
+ });
43
+ }
44
+ /** Verify transport and content bindings; the CLI retains every scientific validation decision. */
45
+ export function parseFoundryPreparationCliReport(options) {
46
+ const report = object(options.report);
47
+ if (report.input_path !== options.input ||
48
+ report.requested_type !== "process" ||
49
+ object(report.files).report !==
50
+ path.join(options.outDir, "outputs", "validation-report.json") ||
51
+ !Array.isArray(report.rows) ||
52
+ report.rows.length !== options.rows.length)
53
+ fail();
54
+ const rows = report.rows.map((raw, index) => {
55
+ const row = object(raw);
56
+ const identity = datasetIdentity(options.rows[index], index, "process");
57
+ const candidateHash = sha256Json(identity.payload);
58
+ const wrapper = record(options.rows[index]);
59
+ const process = record(record(identity.payload).processDataSet);
60
+ const id = token(wrapper.id, record(record(process.processInformation).dataSetInformation)["common:UUID"]);
61
+ const version = token(wrapper.version, record(record(process.administrativeInformation).publicationAndOwnership)["common:dataSetVersion"]);
62
+ if (row.index !== index ||
63
+ row.id !== id ||
64
+ row.version !== version ||
65
+ row.type !== "process" ||
66
+ row.payload_sha256 !== candidateHash ||
67
+ !["valid", "invalid"].includes(String(row.status)))
68
+ fail();
69
+ const layers = object(row.validation_layers);
70
+ const layerIssues = layerNames.flatMap((name) => findings(object(layers[name]), ["passed", "failed"]));
71
+ const semantics = object(row.allocation_semantics);
72
+ if (semantics.profile !== profile ||
73
+ semantics.tolerance !== tolerance ||
74
+ semantics.candidate_sha256 !== candidateHash ||
75
+ semantics.options_sha256 !== sha256Json({ profile, tolerance }) ||
76
+ !Array.isArray(semantics.dependencies) ||
77
+ !Array.isArray(semantics.coverage))
78
+ fail();
79
+ const semanticIssues = findings(semantics, ["passed", "failed", "unresolved"]);
80
+ if (semantics.status === "passed") {
81
+ const coverage = semantics.coverage;
82
+ // SDK 0.5.1 emits applicable checks; undeclared/legacy modes omit target/fraction checks.
83
+ const required = ["allocation-target-type", "quantitative-reference"];
84
+ if (coverage.some((entry) => ["invalid", "unresolved"].includes(String(entry.status))) ||
85
+ required.some((check) => !coverage.some((entry) => entry.check === check)))
86
+ fail();
87
+ }
88
+ const supplied = object(options.rows[index]);
89
+ // Published dataset validate reads semantic_context from the original row only.
90
+ const suppliedContexts = [supplied];
91
+ const flowHashes = new Set();
92
+ for (const holder of suppliedContexts) {
93
+ const context = holder.semantic_context;
94
+ if (!context || typeof context !== "object" || Array.isArray(context))
95
+ continue;
96
+ const documents = context.flow_documents;
97
+ if (!Array.isArray(documents))
98
+ continue;
99
+ for (const document of documents) {
100
+ if (!document || typeof document !== "object" || Array.isArray(document))
101
+ continue;
102
+ const flow = document.flowDataSet;
103
+ if (!flow)
104
+ continue;
105
+ const information = flow.flowInformation;
106
+ const administration = flow.administrativeInformation;
107
+ const id = information?.dataSetInformation?.["common:UUID"];
108
+ const version = administration?.publicationAndOwnership?.["common:dataSetVersion"];
109
+ flowHashes.add(JSON.stringify([id, version, sha256Json(document)]));
110
+ }
111
+ }
112
+ for (const rawDependency of semantics.dependencies) {
113
+ const dependency = object(rawDependency);
114
+ if (!flowHashes.has(JSON.stringify([dependency.uuid, dependency.version, dependency.content_sha256])))
115
+ fail();
116
+ }
117
+ for (const rawCoverage of semantics.coverage) {
118
+ const coverage = object(rawCoverage);
119
+ if (typeof coverage.check !== "string" ||
120
+ !Array.isArray(coverage.path) ||
121
+ !["passed", "invalid", "unresolved", "not-applicable"].includes(String(coverage.status)))
122
+ fail();
123
+ }
124
+ const knownIssues = new Set([...layerIssues, ...semanticIssues].map(sha256Json));
125
+ if (!Array.isArray(row.issues) ||
126
+ row.issue_count !== row.issues.length ||
127
+ row.issues.some((issue) => !knownIssues.has(sha256Json(issue))) ||
128
+ (row.status === "valid") !== (row.issues.length === 0) ||
129
+ (row.status === "valid") !== (layerIssues.length + semanticIssues.length === 0))
130
+ fail();
131
+ return row;
132
+ });
133
+ const invalid = rows.filter((row) => row.status === "invalid").length;
134
+ const counts = object(report.counts);
135
+ if (counts.total !== rows.length ||
136
+ counts.invalid !== invalid ||
137
+ counts.valid !== rows.length - invalid ||
138
+ object(counts.by_type).process !== rows.length ||
139
+ options.exit !== (invalid ? 1 : 0) ||
140
+ report.status !== (invalid ? "completed_with_failures" : "completed"))
141
+ fail();
142
+ return rows;
143
+ }
144
+ /** Project owner findings into the existing evidence-backed field patch workflow, without repairs. */
145
+ export function preparationValidationActions(row, receipt) {
146
+ const layers = object(row.validation_layers);
147
+ const semantics = object(row.allocation_semantics);
148
+ const groups = [
149
+ ...layerNames.map((name) => ({ name, value: object(layers[name]) })),
150
+ { name: "allocation_semantics", value: semantics },
151
+ ];
152
+ return groups.flatMap(({ name, value }) => value.issues.map((issue) => ({
153
+ source: "cli_validation",
154
+ validation_layer: name,
155
+ code: issue.code,
156
+ path: issue.path,
157
+ message: issue.message,
158
+ action_kind: "ai_authoring",
159
+ required_owner: "foundry_ai_authoring",
160
+ ai_required: true,
161
+ instruction: "Review the source evidence and current owner finding in full task context. Use the existing bounded authoring patch workflow only for source-backed corrections, then rerun preparation on the exact changed candidate. Unknown scientific evidence remains blocked; do not invent quantities, annual periods, references or allocation fractions.",
162
+ evidence: {
163
+ ...receipt,
164
+ candidate_sha256: row.payload_sha256,
165
+ validation_layer: name,
166
+ validation_layers: layers,
167
+ allocation_semantics: semantics,
168
+ },
169
+ })));
170
+ }
171
+ export function preparationValidationEvidence(row, report, hash) {
172
+ return {
173
+ report_file: report,
174
+ report_sha256: hash,
175
+ row,
176
+ policy: "Owning CLI local save-equivalent evidence; native schema and final remote eligibility remain separate.",
177
+ };
178
+ }
179
+ export function readPreparationCliEvidence(receipt, rows, input) {
180
+ const bytes = fs.readFileSync(receipt.report, "utf8");
181
+ return {
182
+ rows: parseFoundryPreparationCliReport({
183
+ report: JSON.parse(bytes),
184
+ rows,
185
+ input,
186
+ outDir: path.dirname(path.dirname(receipt.report)),
187
+ exit: receipt.exit,
188
+ }),
189
+ sha256: sha256Text(bytes),
190
+ };
191
+ }
@@ -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.26" || cli.platform !== context.platform)
161
- fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.26 C1 runtime on the selected platform.");
160
+ if (cli.package.version !== "0.1.27" || cli.platform !== context.platform)
161
+ fail("runtime_cli_unqualified", "Foundry requires the exact CLI 0.1.27 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.");
@@ -9,7 +9,7 @@ import { resolveFoundryRuntimePaths } from "./foundry-runtime-paths.js";
9
9
  import { resolveTiangongLcaCliTidasSource, } from "./foundry-tidas-source.js";
10
10
  const require = createRequire(import.meta.url);
11
11
  const tiangongLcaCliPackageName = "@tiangong-lca/cli";
12
- const tiangongLcaCliPackageVersion = "0.1.26";
12
+ const tiangongLcaCliPackageVersion = "0.1.27";
13
13
  const tiangongLcaCliBinName = "tiangong-lca";
14
14
  const { repoRoot: foundryRepoRoot } = resolveFoundryRuntimePaths(import.meta.url);
15
15
  function isRecord(value) {
@@ -10,6 +10,8 @@ import { runTidasRowsValidation } from "./tidas-adapter.js";
10
10
  import { nativeFailureFileName, nativeFailureResultName, nativeValidationFailureEvidence, } from "./foundry-native-validation-failure.js";
11
11
  import { runDatasetCurationGate } from "./import-curation/curation-gate.js";
12
12
  import { runDatasetAuthoringTaskBuild } from "./import-curation/authoring-packages.js";
13
+ import { readRows } from "./import-curation/internal/runtime-io.js";
14
+ import { parseFoundryPreparationCliReport } from "./foundry-preparation-cli-validation.js";
13
15
  import { routeFoundryDecisionAction } from "./foundry-decision-routing.js";
14
16
  import { prepareFoundryDecisionWork } from "./foundry-workflow-decisions.js";
15
17
  import { currentWorkflowState, workflowAssessmentQueueScopeSha256, } from "./foundry-workflow-state.js";
@@ -413,15 +415,16 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
413
415
  const qaDir = path.join(output, set.type, "qa");
414
416
  let qaReport;
415
417
  if (["flow", "process", "lifecyclemodel"].includes(set.type)) {
416
- const qa = runWorkflowLocalCli(context, qualified, temporary, [
417
- "qa",
418
- set.type,
419
- "--rows-file",
420
- set.file,
421
- "--out-dir",
422
- qaDir,
423
- "--json",
424
- ]);
418
+ const qaArgv = ["qa", set.type, "--rows-file", set.file, "--out-dir", qaDir, "--json"];
419
+ if (set.type === "process") {
420
+ for (const referenceSet of selectedSets) {
421
+ if (["flow", "flowproperty", "unitgroup"].includes(String(referenceSet.type))) {
422
+ readFoundryInput(context, String(referenceSet.file));
423
+ qaArgv.push("--reference-rows-file", String(referenceSet.file));
424
+ }
425
+ }
426
+ }
427
+ const qa = runWorkflowLocalCli(context, qualified, temporary, qaArgv);
425
428
  const file = record(qa.files).report;
426
429
  if (typeof file !== "string")
427
430
  throw new FoundryContextError("workflow_qa_failed", "QA returned no report file.");
@@ -435,11 +438,39 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
435
438
  });
436
439
  }
437
440
  const gateDir = path.join(output, set.type, "curation");
441
+ let cliValidation;
442
+ if (set.type === "process") {
443
+ const validationDir = path.join(output, set.type, "cli-validation");
444
+ const validation = runWorkflowLocalCliResult(context, qualified, temporary, [
445
+ "dataset",
446
+ "validate",
447
+ "--input",
448
+ set.file,
449
+ "--type",
450
+ "process",
451
+ "--out-dir",
452
+ validationDir,
453
+ "--json",
454
+ ]);
455
+ parseFoundryPreparationCliReport({
456
+ report: validation.report,
457
+ input: set.file,
458
+ outDir: validationDir,
459
+ rows: readRows(set.file),
460
+ exit: validation.exit,
461
+ });
462
+ const reportFile = path.join(validationDir, "outputs", "validation-report.json");
463
+ if (JSON.stringify(JSON.parse(fs.readFileSync(reportFile, "utf8"))) !==
464
+ JSON.stringify(validation.report))
465
+ throw new FoundryContextError("workflow_validation_invalid", "CLI validation file differs from its returned report.");
466
+ cliValidation = { report: reportFile, exit: validation.exit };
467
+ }
438
468
  const rewrite = identityRewriteReports.findLast((report) => report.dataset_type === set.type);
439
469
  const gate = runDatasetCurationGate({
440
470
  repoRoot: context.assetRoot,
441
471
  routeAction: routeFoundryDecisionAction,
442
472
  requireIdentityPreflight: Boolean(identity),
473
+ cliValidation,
443
474
  options: {
444
475
  type: set.type,
445
476
  rowsFile: set.file,
@@ -496,6 +527,13 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
496
527
  type: set.type,
497
528
  rows: set.file,
498
529
  schema_report: schema.report_file,
530
+ ...(cliValidation
531
+ ? {
532
+ cli_validation_report: cliValidation.report,
533
+ cli_validation_report_sha256: captureFoundryInput(cliValidation.report).sha256,
534
+ cli_validation_exit: cliValidation.exit,
535
+ }
536
+ : {}),
499
537
  qa_report: qaReport,
500
538
  curation_report: gateReport,
501
539
  curation_status: gate.status,
@@ -46,14 +46,15 @@ export function runWorkflowLocalCli(context, qualified, temporary, argv) {
46
46
  return result.report;
47
47
  }
48
48
  export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
49
- const local = (argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
49
+ const local = (argv[0] === "dataset" && argv[1] === "validate") ||
50
+ (argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
50
51
  (argv[0] === "dataset" && argv[1] === "curation-queue" && argv[2] === "build") ||
51
52
  (argv[0] === "dataset" &&
52
53
  argv[1] === "classification" &&
53
54
  ["apply", "audit"].includes(argv[2])) ||
54
55
  (argv[0] === "dataset" && argv[1] === "patch" && argv[2] === "apply");
55
56
  if (!local)
56
- throw new FoundryContextError("workflow_command_invalid", "This stage admits local QA, queue preparation and patch application only.");
57
+ throw new FoundryContextError("workflow_command_invalid", "This stage admits local validation, QA, queue preparation and patch application only.");
57
58
  assertQualifiedFoundryRuntime(context, qualified);
58
59
  const cli = resolveInstalledTiangongLcaCliPackage();
59
60
  const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
@@ -228,6 +228,16 @@ export function currentWorkflowState(context, entries) {
228
228
  set.curation_report,
229
229
  set.authoring_manifest,
230
230
  ];
231
+ if (row.type === "process") {
232
+ if (typeof set.cli_validation_report !== "string" ||
233
+ typeof set.cli_validation_exit !== "number" ||
234
+ ![0, 1].includes(set.cli_validation_exit))
235
+ return false;
236
+ const validationFile = resolveFoundryOutput(context, set.cli_validation_report);
237
+ if (captureFoundryInput(validationFile).sha256 !== set.cli_validation_report_sha256)
238
+ throw new FoundryContextError("workflow_assessment_invalid", "CLI validation evidence has changed.");
239
+ files.push(set.cli_validation_report);
240
+ }
231
241
  if (set.interaction_context !== undefined)
232
242
  files.push(set.interaction_context);
233
243
  if (files.some((file) => !registeredAssessmentFile(context, entries, file)))
@@ -42,6 +42,10 @@ interface CurationGateArgs {
42
42
  options?: CurationGateOptions;
43
43
  routeAction?: (action: JsonRecord, datasetType: string, payload: unknown) => JsonRecord;
44
44
  requireIdentityPreflight?: boolean;
45
+ cliValidation?: {
46
+ report: string;
47
+ exit: number;
48
+ };
45
49
  }
46
- export declare function runDatasetCurationGate({ repoRoot, options, routeAction, requireIdentityPreflight, }?: CurationGateArgs): JsonRecord;
50
+ export declare function runDatasetCurationGate({ repoRoot, options, routeAction, requireIdentityPreflight, cliValidation, }?: CurationGateArgs): JsonRecord;
47
51
  export {};
@@ -1,11 +1,12 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { readPreparationCliEvidence, preparationValidationActions, preparationValidationEvidence, } from "../foundry-preparation-cli-validation.js";
3
4
  import * as curationGateWorkflow from "./internal/curation-gate-workflow.js";
4
5
  const { authoringQueueRowsForIdentity, buildIdentityPreflightAuthoringContext, buildQueueAuthoringContext, classificationQueueActionItem, classificationQueueRowStillNeedsAuthoring, collectBundledSchemaContextFiles, collectContextDirFiles, collectExplicitContextFiles, collectProfileSemanticActionItems, contextFileDetails, datasetIdentity, datasetTypeFromOptions, datasetTypePlural, ensureArray, entityIdFromFinding, fileExists, fullContextAiCompletionRequirement, fullContextGateItems, identityDecisionApplyContextDecisionsForIdentity, identityDecisionApplyReportOptionValues, identityKey, identityPreflightAuthoringActionItems, identityPreflightGateItems, jsonLines, locationQueueActionItem, locationQueueRowStillNeedsAuthoring, mapRowsByIdentity, nowIso, profileFor, qaFindingCode, qaFindingCurationAction, readAuthoringQueueContext, readCanonicalSupportRewriteContext, readClassificationDecisionApplyContext, readCleanupTransformContext, readContextFiles, readCurationQueueContext, readIdentityDecisionApplyContexts, readIdentityPreflightContext, readIdentityReferenceRewriteContext, readJson, readJsonArtifactsIfOption, readJsonIfOption, readQaFindings, readRows, readSourceContactRewriteContext, readText, readUnresolvedExchangeExternalizationContext, repoRelativePath, resolveRepoPath, sanitizeFileName, schemaIssueCurationAction, sha256Text, unresolvedExchangeExternalizationRowsForIdentity, writeJson, writeText, } = curationGateWorkflow;
5
6
  function asJsonRecord(value) {
6
7
  return value;
7
8
  }
8
- export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, requireIdentityPreflight = false, } = {}) {
9
+ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, requireIdentityPreflight = false, cliValidation, } = {}) {
9
10
  const datasetType = datasetTypeFromOptions(options);
10
11
  if (options.help) {
11
12
  return {
@@ -46,6 +47,11 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
46
47
  throw new Error("--qa-report is required and must point to a QA report JSON.");
47
48
  }
48
49
  const rows = readRows(rowsFile);
50
+ const cliEvidence = cliValidation
51
+ ? readPreparationCliEvidence(cliValidation, rows, rowsFile)
52
+ : null;
53
+ const cliValidationRows = cliEvidence?.rows;
54
+ const cliValidationReportSha256 = cliEvidence?.sha256;
49
55
  const schemaReport = readJson(schemaReportPath);
50
56
  const qaReport = readJson(qaReportPath);
51
57
  const qaFindings = readQaFindings(root, qaReport, qaReportPath, datasetType);
@@ -181,6 +187,12 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
181
187
  const locationQueueActionItems = unresolvedLocationAuthoringRows.map(locationQueueActionItem);
182
188
  const actionItems = [
183
189
  ...schemaActionItems.filter((item) => item.ai_required),
190
+ ...(cliValidationRows
191
+ ? preparationValidationActions(cliValidationRows[index], {
192
+ report_file: cliValidation.report,
193
+ report_sha256: cliValidationReportSha256,
194
+ })
195
+ : []),
184
196
  ...qaActionItems,
185
197
  ...identityPreflightActionItems,
186
198
  ...classificationQueueActionItems,
@@ -288,6 +300,11 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
288
300
  },
289
301
  missing_context_files: [...profileContext.missing, ...contractContext.missing],
290
302
  schema_issues: schemaIssues,
303
+ ...(cliValidationRows
304
+ ? {
305
+ cli_validation: preparationValidationEvidence(cliValidationRows[index], cliValidation.report, cliValidationReportSha256),
306
+ }
307
+ : {}),
291
308
  qa_findings: entityQaFindings,
292
309
  waived_findings: waivedFindings.map((finding) => ({
293
310
  ...finding,
@@ -408,9 +425,20 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
408
425
  dataset_type: datasetType,
409
426
  rows_file: repoRelativePath(root, rowsFile),
410
427
  schema_report: repoRelativePath(root, schemaReportPath),
428
+ ...(cliValidation
429
+ ? {
430
+ cli_validation_report: repoRelativePath(root, cliValidation.report),
431
+ cli_validation_report_sha256: cliValidationReportSha256,
432
+ }
433
+ : {}),
411
434
  qa_report: repoRelativePath(root, qaReportPath),
412
435
  policy: {
413
436
  cli_qa_role: "deterministic_qa_report_only",
437
+ ...(cliValidation
438
+ ? {
439
+ cli_validation_role: "Current local save-equivalent schema, authoring, content, multilingual and allocation/reference profile evidence; final authenticated reference eligibility remains separate.",
440
+ }
441
+ : {}),
414
442
  foundry_role: "profile policy, AI authoring package, deterministic cleanup, waiver, final prewrite decision",
415
443
  waived_qa_codes: [...waivedQaCodes],
416
444
  required_multilang_english_before_write: true,
@@ -6,7 +6,7 @@ import { asText, directoryExists, ensureArray, fileExists, readJson, readText, r
6
6
  function asJsonRecord(value) {
7
7
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8
8
  }
9
- export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.26/assets/tidas-schemas"];
9
+ export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.27/assets/tidas-schemas"];
10
10
  export function tidasSchemaPath(repoRoot, schemaFile) {
11
11
  void repoRoot;
12
12
  const candidate = path.join(resolveInstalledTiangongLcaCliPackage().schemaDir, schemaFile);
@@ -3,6 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
6
+ import { assertTidasProcessCoverage, augmentTidasProcessFlowContext, } from "./tidas-process-flow-context.js";
6
7
  export const TIDAS_OPERATION_REPORT_SCHEMA = "tidas.operation-report.v1";
7
8
  export const TIDAS_IMPORT_REPORT_SCHEMA = "tidas.import-execution-report.v1";
8
9
  export const TIDAS_VALIDATION_SUMMARY_SCHEMA = "tidas.validation-summary.v1";
@@ -361,6 +362,7 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
361
362
  if (!options.outDir)
362
363
  throw new Error("--out-dir is required.");
363
364
  const rows = readRows(rowsFile);
365
+ const { documents, supplementalOwners } = augmentTidasProcessFlowContext(rows, payloadForRow, identityForPayload);
364
366
  fs.mkdirSync(path.dirname(outDir), { recursive: true });
365
367
  const staging = path.join(path.dirname(outDir), `.tidas-validate-stage-${randomUUID()}`);
366
368
  // Keep staging beside the output for atomic rename; Windows mkdtemp rejects deep prefixes.
@@ -368,7 +370,7 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
368
370
  try {
369
371
  const inputRoot = path.join(staging, "input");
370
372
  const manifest = [];
371
- for (const [ordinal, row] of rows.entries()) {
373
+ for (const [ordinal, row] of documents.entries()) {
372
374
  const payload = payloadForRow(row);
373
375
  const { rootKey, category, informationKey } = documentCategory(payload);
374
376
  const identity = identityForPayload(payload, rootKey, informationKey);
@@ -416,6 +418,8 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
416
418
  finalEvent.completed !== true) {
417
419
  throw new Error("tidas_validation_batch_final_invalid");
418
420
  }
421
+ if (record(finalEvent.summary)?.document_count !== documents.length)
422
+ throw new Error("tidas_validation_document_count_invalid");
419
423
  const finalFingerprints = record(finalEvent.fingerprints);
420
424
  if (finalFingerprints?.asset_fingerprint !== operation.validation_describe.asset_fingerprint) {
421
425
  throw new Error("tidas_validation_asset_fingerprint_mismatch");
@@ -430,33 +434,48 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
430
434
  if (event.type !== "issue")
431
435
  continue;
432
436
  const ordinal = Number(event.document_ordinal);
433
- if (!Number.isSafeInteger(ordinal) || ordinal < 0 || ordinal >= rows.length)
437
+ if (!Number.isSafeInteger(ordinal) || ordinal < 0 || ordinal >= documents.length)
434
438
  throw new Error("tidas_validation_issue_ordinal_invalid");
435
- if (!issuesByOrdinal.has(ordinal))
436
- issuesByOrdinal.set(ordinal, []);
439
+ const owners = supplementalOwners.get(ordinal) ?? new Map([[ordinal, ""]]);
437
440
  const nativeIssue = record(event.issue);
438
441
  if (!nativeIssue)
439
442
  throw new Error("tidas_validation_issue_invalid");
440
443
  const location = typeof nativeIssue.location === "string" ? nativeIssue.location : null;
441
- const payload = payloadForRow(rows[ordinal]);
442
- const wrapper = payload === rows[ordinal]
444
+ const payload = payloadForRow(documents[ordinal]);
445
+ const wrapper = payload === documents[ordinal]
443
446
  ? null
444
- : Object.entries(rows[ordinal]).find(([, value]) => value === payload)?.[0];
447
+ : Object.entries(documents[ordinal]).find(([, value]) => value === payload)?.[0];
445
448
  const pointer = location === null
446
449
  ? null
447
450
  : location === "" || location.startsWith("/")
448
451
  ? location
449
452
  : `/${location}`;
450
- issuesByOrdinal.get(ordinal).push({
451
- ...nativeIssue,
452
- code: nativeIssue.code ?? nativeIssue.issue_code,
453
- path: nativeIssue.path ??
454
- (pointer === null ? null : `${wrapper ? `/${wrapper}` : ""}${pointer}`),
455
- });
453
+ for (const [owner, contextPointer] of owners) {
454
+ if (!issuesByOrdinal.has(owner))
455
+ issuesByOrdinal.set(owner, []);
456
+ issuesByOrdinal.get(owner).push({
457
+ ...nativeIssue,
458
+ code: nativeIssue.code ?? nativeIssue.issue_code,
459
+ path: nativeIssue.path ??
460
+ (pointer === null
461
+ ? null
462
+ : `${contextPointer}${wrapper ? `/${wrapper}` : ""}${pointer}`),
463
+ ...(supplementalOwners.has(ordinal)
464
+ ? { supplemental_document_key: event.document_key, supplemental_context: true }
465
+ : {}),
466
+ });
467
+ }
456
468
  }
457
469
  const invalidOrdinals = new Set(events
458
470
  .filter((event) => event.type === "issue" && record(event.issue)?.severity === "error")
459
- .map((event) => Number(event.document_ordinal)));
471
+ .flatMap((event) => [
472
+ ...(supplementalOwners.get(Number(event.document_ordinal))?.keys() ?? [
473
+ Number(event.document_ordinal),
474
+ ]),
475
+ ]));
476
+ const processCount = rows.filter((row) => record(payloadForRow(row).processDataSet)).length;
477
+ const coverage = record(record(finalEvent.summary)?.semantic_coverage);
478
+ assertTidasProcessCoverage(coverage, operation.binary_version, processCount, rows.filter((row, index) => record(payloadForRow(row).processDataSet) && invalidOrdinals.has(index)).length);
460
479
  const validRows = rows.filter((_, ordinal) => !invalidOrdinals.has(ordinal));
461
480
  const invalidRows = rows.filter((_, ordinal) => invalidOrdinals.has(ordinal));
462
481
  const reportPath = path.join(staging, "outputs", "validation-report.json");
@@ -471,7 +490,7 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
471
490
  dataset_type: String(options.type ?? options.datasetType ?? "auto"),
472
491
  engine: "tidas",
473
492
  binary_version: operation.binary_version,
474
- rows: manifest.map((entry, ordinal) => ({
493
+ rows: manifest.slice(0, rows.length).map((entry, ordinal) => ({
475
494
  index: ordinal,
476
495
  id: entry.identity.dataset_id,
477
496
  version: entry.identity.dataset_version,
@@ -493,6 +512,10 @@ export function runTidasRowsValidation({ repoRoot, options = {}, environment = p
493
512
  profile: finalEvent.profile,
494
513
  logical_issue_stream_sha256: finalEvent.logical_issue_stream_sha256,
495
514
  asset_fingerprint: finalFingerprints?.asset_fingerprint ?? null,
515
+ augmented_document_count: documents.length,
516
+ supplemental_document_count: documents.length - rows.length,
517
+ augmented_manifest_sha256: sha256(fs.readFileSync(manifestPath)),
518
+ semantic_coverage: record(finalEvent.summary)?.semantic_coverage ?? null,
496
519
  validation_describe_schema: TIDAS_VALIDATION_DESCRIBE_SCHEMA,
497
520
  },
498
521
  files: {
@@ -0,0 +1,12 @@
1
+ type Json = Record<string, unknown>;
2
+ /** Preserve explicit owner-row Flow evidence in one native manifest, rejecting exact identity conflicts. */
3
+ export declare function augmentTidasProcessFlowContext(rows: Json[], payloadForRow: (row: Json) => Json, identityForPayload: (payload: Json, root: string, information: string) => {
4
+ id: string | null;
5
+ version: string | null;
6
+ }): {
7
+ documents: Json[];
8
+ supplementalOwners: Map<number, Map<number, string>>;
9
+ };
10
+ /** Admit the native profile's transport coverage without deciding scientific validity. */
11
+ export declare function assertTidasProcessCoverage(coverage: Json | null, binaryVersion: string, processCount: number, invalidProcessCount: number): void;
12
+ export {};