@tiangong-lca/foundry 0.1.17 → 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 (162) hide show
  1. package/README.md +23 -7
  2. package/docs/architecture.md +15 -3
  3. package/docs/foundry-task-contracts.md +27 -3
  4. package/docs/package-distribution-contract.md +45 -13
  5. package/docs/public-runtime-contract.md +85 -5
  6. package/docs/runtime-context-contract.md +22 -4
  7. package/docs/task-authorization-contract.md +15 -3
  8. package/docs/workspace-migration-contract.md +5 -3
  9. package/package-dist/assets/foundry-package-descriptor.json +541 -177
  10. package/package-dist/scripts/foundry-facade.d.ts +5 -0
  11. package/package-dist/scripts/foundry-facade.js +261 -16
  12. package/package-dist/scripts/foundry-runtime.d.ts +2 -2
  13. package/package-dist/scripts/lib/bundle-sample-utils.d.ts +4 -4
  14. package/package-dist/scripts/lib/bundle-source-context.d.ts +6 -4
  15. package/package-dist/scripts/lib/bundle-source-context.js +10 -8
  16. package/package-dist/scripts/lib/decision-owners/identity-preflight.js +18 -6
  17. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
  18. package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
  19. package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +11 -1
  20. package/package-dist/scripts/lib/finalize-owners/post-authoring.js +65 -9
  21. package/package-dist/scripts/lib/foundry-assessment-producer.d.ts +6 -0
  22. package/package-dist/scripts/lib/foundry-assessment-producer.js +167 -0
  23. package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
  24. package/package-dist/scripts/lib/foundry-command-metadata.js +6 -1
  25. package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
  26. package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
  27. package/package-dist/scripts/lib/foundry-decision-owners.d.ts +1 -1
  28. package/package-dist/scripts/lib/foundry-decision-owners.js +15 -7
  29. package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
  30. package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
  31. package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
  32. package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
  33. package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
  34. package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
  35. package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
  36. package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
  37. package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +21 -0
  38. package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
  39. package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
  40. package/package-dist/scripts/lib/foundry-edge-session.js +69 -0
  41. package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
  42. package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
  43. package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
  44. package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
  45. package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
  46. package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
  47. package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
  48. package/package-dist/scripts/lib/foundry-execution-admission.js +28 -3
  49. package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
  50. package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
  51. package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
  52. package/package-dist/scripts/lib/foundry-finalize-owners.js +126 -13
  53. package/package-dist/scripts/lib/foundry-identity-stage-input.d.ts +24 -0
  54. package/package-dist/scripts/lib/foundry-identity-stage-input.js +122 -0
  55. package/package-dist/scripts/lib/foundry-identity-stage-state.d.ts +17 -0
  56. package/package-dist/scripts/lib/foundry-identity-stage-state.js +48 -0
  57. package/package-dist/scripts/lib/foundry-installed-entry.d.ts +2 -0
  58. package/package-dist/scripts/lib/foundry-installed-entry.js +173 -0
  59. package/package-dist/scripts/lib/foundry-managed-adoption.d.ts +12 -0
  60. package/package-dist/scripts/lib/foundry-managed-adoption.js +108 -0
  61. package/package-dist/scripts/lib/foundry-managed-authentication.d.ts +4 -0
  62. package/package-dist/scripts/lib/foundry-managed-authentication.js +28 -0
  63. package/package-dist/scripts/lib/foundry-managed-host.js +14 -2
  64. package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +2 -0
  65. package/package-dist/scripts/lib/foundry-migration-transfer-io.js +27 -3
  66. package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
  67. package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
  68. package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
  69. package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
  70. package/package-dist/scripts/lib/foundry-owner-readback.d.ts +20 -0
  71. package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
  72. package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
  73. package/package-dist/scripts/lib/foundry-package-contract.js +10 -2
  74. package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +2 -0
  75. package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +96 -3
  76. package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
  77. package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
  78. package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
  79. package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
  80. package/package-dist/scripts/lib/foundry-quality-review-context.d.ts +3 -0
  81. package/package-dist/scripts/lib/foundry-quality-review-context.js +18 -0
  82. package/package-dist/scripts/lib/foundry-quality-review-input.d.ts +48 -0
  83. package/package-dist/scripts/lib/foundry-quality-review-input.js +284 -0
  84. package/package-dist/scripts/lib/foundry-quality-review-lineage.d.ts +13 -0
  85. package/package-dist/scripts/lib/foundry-quality-review-lineage.js +123 -0
  86. package/package-dist/scripts/lib/foundry-quality-review.d.ts +112 -0
  87. package/package-dist/scripts/lib/foundry-quality-review.js +487 -0
  88. package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
  89. package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
  90. package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
  91. package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
  92. package/package-dist/scripts/lib/foundry-runtime-identity.js +22 -2
  93. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  94. package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
  95. package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
  96. package/package-dist/scripts/lib/foundry-task-authorization.d.ts +2 -1
  97. package/package-dist/scripts/lib/foundry-task-authorization.js +32 -11
  98. package/package-dist/scripts/lib/foundry-task-registration.js +4 -5
  99. package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.d.ts +28 -0
  100. package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.js +250 -0
  101. package/package-dist/scripts/lib/foundry-task-runtime-adoption.d.ts +60 -0
  102. package/package-dist/scripts/lib/foundry-task-runtime-adoption.js +549 -0
  103. package/package-dist/scripts/lib/foundry-task-store.d.ts +4 -1
  104. package/package-dist/scripts/lib/foundry-task-store.js +113 -4
  105. package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -1
  106. package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
  107. package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
  108. package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
  109. package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
  110. package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
  111. package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
  112. package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
  113. package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
  114. package/package-dist/scripts/lib/foundry-validation-reference-context.d.ts +8 -0
  115. package/package-dist/scripts/lib/foundry-validation-reference-context.js +115 -0
  116. package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +1 -0
  117. package/package-dist/scripts/lib/foundry-workflow-assessment.js +165 -34
  118. package/package-dist/scripts/lib/foundry-workflow-authorization.js +99 -5
  119. package/package-dist/scripts/lib/foundry-workflow-child-failure.d.ts +44 -0
  120. package/package-dist/scripts/lib/foundry-workflow-child-failure.js +439 -0
  121. package/package-dist/scripts/lib/foundry-workflow-context.js +92 -22
  122. package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
  123. package/package-dist/scripts/lib/foundry-workflow-finalize.js +64 -3
  124. package/package-dist/scripts/lib/foundry-workflow-identity-recovery.d.ts +6 -0
  125. package/package-dist/scripts/lib/foundry-workflow-identity-recovery.js +450 -0
  126. package/package-dist/scripts/lib/foundry-workflow-identity-stage.d.ts +9 -0
  127. package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +717 -0
  128. package/package-dist/scripts/lib/foundry-workflow-identity.js +26 -11
  129. package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
  130. package/package-dist/scripts/lib/foundry-workflow-io.js +102 -16
  131. package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
  132. package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
  133. package/package-dist/scripts/lib/foundry-workflow-semantic.js +65 -31
  134. package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
  135. package/package-dist/scripts/lib/foundry-workflow-state.js +165 -22
  136. package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +4 -7
  137. package/package-dist/scripts/lib/identity-preflight-artifacts.js +18 -5
  138. package/package-dist/scripts/lib/identity-preflight-proof.d.ts +6 -0
  139. package/package-dist/scripts/lib/identity-preflight-proof.js +92 -13
  140. package/package-dist/scripts/lib/identity-preflight-recovery-proof.d.ts +78 -0
  141. package/package-dist/scripts/lib/identity-preflight-recovery-proof.js +415 -0
  142. package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +9 -1
  143. package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -2
  144. package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +1 -0
  145. package/package-dist/scripts/lib/import-curation/curation-gate.js +19 -1
  146. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  147. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +11 -2
  148. package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +4 -1
  149. package/package-dist/scripts/package-entry.js +2 -3
  150. package/package-dist/scripts/public-api.d.ts +5 -0
  151. package/package-dist/scripts/public-api.js +2 -0
  152. package/package-dist/scripts/runtime-entry.d.ts +2 -0
  153. package/package-dist/scripts/runtime-entry.js +42 -15
  154. package/package.json +6 -2
  155. package/specs/schemas/foundry-identity-stage-input.schema.json +47 -0
  156. package/specs/schemas/foundry-managed-adoption.schema.json +40 -0
  157. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  158. package/specs/schemas/foundry-operation-result.schema.json +1 -0
  159. package/specs/schemas/foundry-package-descriptor.schema.json +6 -2
  160. package/specs/schemas/foundry-quality-review-draft.schema.json +271 -0
  161. package/specs/schemas/foundry-quality-review-input.schema.json +271 -0
  162. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -0,0 +1,166 @@
1
+ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
2
+ import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
3
+ type RowIdentity = {
4
+ id: string;
5
+ version: string;
6
+ payload: unknown;
7
+ };
8
+ type ValidationType = "flow" | "process" | "lifecyclemodel";
9
+ export declare function projectFlowValidation(row: RowIdentity, output: string, exit: number, receipt: unknown, bytes: Buffer): {
10
+ entity_id: string;
11
+ version: string;
12
+ severity: string;
13
+ code: string;
14
+ path: string;
15
+ message: string;
16
+ }[];
17
+ type ValidationOptions = {
18
+ referenceFiles?: readonly string[];
19
+ validationInput?: string;
20
+ readRowsFile?: (file: string) => string;
21
+ };
22
+ type ValidationIo = {
23
+ writeJson: (file: string, value: unknown) => void;
24
+ readRowsFile: (file: string) => string;
25
+ readResult: (file: string) => Buffer;
26
+ run: (argv: string[]) => {
27
+ exit: number;
28
+ report: Record<string, unknown>;
29
+ validate: <T>(check: () => T) => T;
30
+ };
31
+ };
32
+ export declare function runFoundryTypedDatasetQa(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, writeJson: ValidationIo["writeJson"], type: ValidationType, rowsFile: string, output: string, options?: ValidationOptions): {
33
+ reportFile: string;
34
+ report: {
35
+ schema: string;
36
+ status: string;
37
+ rows_file: string;
38
+ validation_input: string;
39
+ validation_operation: string;
40
+ validations: {
41
+ id: string;
42
+ version: string;
43
+ result: string;
44
+ reference_documents: string | null;
45
+ complete_sha256: string;
46
+ }[];
47
+ rows: {
48
+ findings: {
49
+ entity_id: string;
50
+ version: string;
51
+ severity: string;
52
+ code: string;
53
+ path: string;
54
+ message: string;
55
+ }[];
56
+ }[];
57
+ findings: {
58
+ entity_id: string;
59
+ version: string;
60
+ severity: string;
61
+ code: string;
62
+ path: string;
63
+ message: string;
64
+ }[];
65
+ files: {
66
+ report: string;
67
+ };
68
+ };
69
+ exit: number;
70
+ validationReportFile: string;
71
+ } | {
72
+ reportFile: string;
73
+ report: {
74
+ status: string;
75
+ policy_decision_owner: string;
76
+ qa_mode: string;
77
+ mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
78
+ findings: {
79
+ process_file: string;
80
+ severity: "info" | "warning" | "blocker";
81
+ code: string;
82
+ methodology_rule_id: string | null;
83
+ message: string;
84
+ source: "rule";
85
+ evidence?: {
86
+ [x: string]: unknown;
87
+ };
88
+ }[];
89
+ schema: string;
90
+ rows_file: string;
91
+ reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
92
+ files: {
93
+ report: string;
94
+ };
95
+ };
96
+ exit: number;
97
+ validationReportFile: string;
98
+ };
99
+ export declare function runTypedDatasetQa(type: ValidationType, rowsFile: string, directory: string, options: ValidationOptions, { writeJson, readRowsFile, readResult, run }: ValidationIo): {
100
+ reportFile: string;
101
+ report: {
102
+ schema: string;
103
+ status: string;
104
+ rows_file: string;
105
+ validation_input: string;
106
+ validation_operation: string;
107
+ validations: {
108
+ id: string;
109
+ version: string;
110
+ result: string;
111
+ reference_documents: string | null;
112
+ complete_sha256: string;
113
+ }[];
114
+ rows: {
115
+ findings: {
116
+ entity_id: string;
117
+ version: string;
118
+ severity: string;
119
+ code: string;
120
+ path: string;
121
+ message: string;
122
+ }[];
123
+ }[];
124
+ findings: {
125
+ entity_id: string;
126
+ version: string;
127
+ severity: string;
128
+ code: string;
129
+ path: string;
130
+ message: string;
131
+ }[];
132
+ files: {
133
+ report: string;
134
+ };
135
+ };
136
+ exit: number;
137
+ validationReportFile: string;
138
+ } | {
139
+ reportFile: string;
140
+ report: {
141
+ status: string;
142
+ policy_decision_owner: string;
143
+ qa_mode: string;
144
+ mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
145
+ findings: {
146
+ process_file: string;
147
+ severity: "info" | "warning" | "blocker";
148
+ code: string;
149
+ methodology_rule_id: string | null;
150
+ message: string;
151
+ source: "rule";
152
+ evidence?: {
153
+ [x: string]: unknown;
154
+ };
155
+ }[];
156
+ schema: string;
157
+ rows_file: string;
158
+ reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
159
+ files: {
160
+ report: string;
161
+ };
162
+ };
163
+ exit: number;
164
+ validationReportFile: string;
165
+ };
166
+ export {};
@@ -0,0 +1,226 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { FoundryContextError, captureFoundryInput, readFoundryInput, resolveFoundryOutput, } from "./foundry-runtime-context.js";
4
+ import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
5
+ import { datasetIdentity, detectDatasetType } from "./import-curation/internal/dataset-payload.js";
6
+ import { foundryProcessQa } from "./foundry-process-qa.js";
7
+ import { sha256Text } from "./identity-preflight-proof.js";
8
+ import { projectFoundryValidationReferences } from "./foundry-validation-reference-context.js";
9
+ import { readRows } from "./import-curation/internal/runtime-io.js";
10
+ import { assertWorkflowReportArtifact, runWorkflowLocalCliResult } from "./foundry-workflow-io.js";
11
+ function invalid() {
12
+ throw new FoundryContextError("workflow_qa_failed", "The complete typed dataset validation does not match the selected row and receipt.");
13
+ }
14
+ function object(value) {
15
+ if (!value || typeof value !== "object" || Array.isArray(value))
16
+ return invalid();
17
+ return value;
18
+ }
19
+ const operationFor = (type) => `dataset ${type === "lifecyclemodel" ? "model" : type} validate`;
20
+ function projectValidation(type, row, output, exit, receipt, bytes) {
21
+ const report = object(receipt);
22
+ const artifact = Array.isArray(report.artifacts) ? object(report.artifacts[0]) : invalid();
23
+ if (report.schemaVersion !== 1 ||
24
+ report.operation !== operationFor(type) ||
25
+ report.status !== "completed" ||
26
+ report.error !== null ||
27
+ artifact.path !== output ||
28
+ artifact.purpose !== "complete_result" ||
29
+ artifact.bytes !== bytes.length)
30
+ return invalid();
31
+ const complete = object(JSON.parse(bytes.toString("utf8")));
32
+ const preview = object(object(report.data).validation);
33
+ const issues = complete.issues;
34
+ const previewIssues = preview.issues;
35
+ const receiptKeys = [
36
+ "id",
37
+ "type",
38
+ "version",
39
+ "status",
40
+ "validator",
41
+ "issue_count",
42
+ "payload_sha256",
43
+ ];
44
+ const status = complete.status;
45
+ const admittedStatuses = type === "process" ? ["passed", "failed", "incomplete"] : ["passed", "failed"];
46
+ if (!admittedStatuses.includes(String(status)) ||
47
+ exit !== (status === "passed" ? 0 : 1) ||
48
+ report.outcome !== `validation_${status}` ||
49
+ complete.type !== type ||
50
+ complete.index !== 0 ||
51
+ complete.id !== row.id ||
52
+ complete.version !== row.version ||
53
+ complete.payload_sha256 !== canonicalPayloadSha256(row.payload) ||
54
+ JSON.stringify(complete.checks) !== '["schema","business"]' ||
55
+ !Array.isArray(issues) ||
56
+ !Array.isArray(previewIssues) ||
57
+ complete.issue_count !== issues.length ||
58
+ (status === "passed" && issues.length !== 0) ||
59
+ (status === "failed" && issues.length === 0) ||
60
+ receiptKeys.some((key) => complete[key] !== preview[key]) ||
61
+ canonicalPayloadSha256(previewIssues) !==
62
+ canonicalPayloadSha256(issues.slice(0, previewIssues.length)))
63
+ return invalid();
64
+ const ownerIssues = [...issues];
65
+ if (type === "process" && status === "incomplete") {
66
+ const names = object(complete.flow_reference_names);
67
+ if (names.status === "unresolved" && Array.isArray(names.issues))
68
+ ownerIssues.push(...names.issues);
69
+ }
70
+ const findings = ownerIssues.map((raw) => {
71
+ const { code, path: issuePath, message } = object(raw);
72
+ if (typeof code !== "string" ||
73
+ !code ||
74
+ typeof issuePath !== "string" ||
75
+ typeof message !== "string" ||
76
+ !message)
77
+ return invalid();
78
+ return {
79
+ entity_id: row.id,
80
+ version: row.version,
81
+ severity: "error",
82
+ code,
83
+ path: issuePath,
84
+ message,
85
+ };
86
+ });
87
+ if (status === "incomplete" && findings.length === 0)
88
+ findings.push({
89
+ entity_id: row.id,
90
+ version: row.version,
91
+ severity: "error",
92
+ code: "process_business_validation_incomplete",
93
+ path: "$",
94
+ message: "Resolve exact Process reference evidence and repeat CLI business validation.",
95
+ });
96
+ return { complete, findings };
97
+ }
98
+ export function projectFlowValidation(row, output, exit, receipt, bytes) {
99
+ return projectValidation("flow", row, output, exit, receipt, bytes).findings;
100
+ }
101
+ export function runFoundryTypedDatasetQa(context, qualified, temporary, writeJson, type, rowsFile, output, options = {}) {
102
+ const directory = resolveFoundryOutput(context, output);
103
+ return runTypedDatasetQa(type, rowsFile, directory, options, {
104
+ writeJson,
105
+ readRowsFile: options.readRowsFile ?? ((file) => readFoundryInput(context, file).toString("utf8")),
106
+ readResult: (file) => fs.readFileSync(assertWorkflowReportArtifact(context, file, directory)),
107
+ run: (argv) => runWorkflowLocalCliResult(context, qualified, temporary, argv),
108
+ });
109
+ }
110
+ export function runTypedDatasetQa(type, rowsFile, directory, options, { writeJson, readRowsFile, readResult, run }) {
111
+ const rows = readRows(rowsFile, readRowsFile);
112
+ fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
113
+ const referenceEvidence = [...new Set(options.referenceFiles ?? [])].map((file) => {
114
+ const fact = captureFoundryInput(file);
115
+ const contents = readRowsFile(file);
116
+ if (sha256Text(contents) !== fact.sha256)
117
+ return invalid();
118
+ return { fact, rows: readRows(file, () => contents) };
119
+ });
120
+ const references = referenceEvidence.flatMap(({ rows }) => rows);
121
+ const projected = type === "process" ? projectFoundryValidationReferences(rows, references) : rows;
122
+ const massReferences = { rows: new Map() };
123
+ const support = [];
124
+ for (const source of references) {
125
+ const kind = detectDatasetType(source);
126
+ if (kind !== "flow" && kind !== "unitgroup" && kind !== "flowproperty")
127
+ return invalid();
128
+ const supplied = datasetIdentity(source, 0, kind);
129
+ const { id, version, payload } = datasetIdentity(supplied.payload, 0, kind);
130
+ const key = `${kind}/${id}/${version}`;
131
+ if (!id || !version || id === "row-1" || id !== supplied.id || version !== supplied.version)
132
+ return invalid();
133
+ const sha256 = canonicalPayloadSha256(payload);
134
+ const prior = massReferences.rows.get(key);
135
+ if (prior && prior.sha256 !== sha256)
136
+ return invalid();
137
+ if (!prior) {
138
+ massReferences.rows.set(key, { payload: object(payload), sha256 });
139
+ if (kind !== "flow")
140
+ support.push(payload);
141
+ }
142
+ }
143
+ const operation = operationFor(type);
144
+ const validations = rows.map((source, index) => {
145
+ const row = datasetIdentity(source, index, type);
146
+ const input = path.join(directory, `${type}-${index + 1}.json`);
147
+ const resultFile = path.join(directory, `validation-${index + 1}.json`);
148
+ // 0.4 checks the typed root before its validation reader unwraps json and reads
149
+ // semantic_context. The complete result must still hash to the original payload.
150
+ const processInput = type === "process" ? object(projected[index]) : null;
151
+ writeJson(input, processInput
152
+ ? {
153
+ ...object(row.payload),
154
+ json: row.payload,
155
+ semantic_context: processInput.semantic_context,
156
+ ...(processInput.allocation_transformation === undefined
157
+ ? {}
158
+ : { allocation_transformation: processInput.allocation_transformation }),
159
+ }
160
+ : row.payload);
161
+ const argv = [
162
+ ...operation.split(" "),
163
+ "--input",
164
+ input,
165
+ "--checks",
166
+ "schema,business",
167
+ "--output",
168
+ resultFile,
169
+ "--json",
170
+ ];
171
+ let referenceDocuments;
172
+ if (type === "process") {
173
+ const flowDocs = object(processInput?.semantic_context).flow_documents;
174
+ if (!Array.isArray(flowDocs))
175
+ return invalid();
176
+ const documents = [
177
+ ...new Map([...flowDocs, ...support].map((document) => [canonicalPayloadSha256(document), document])).values(),
178
+ ];
179
+ if (documents.length) {
180
+ referenceDocuments = path.join(directory, `references-${index + 1}.json`);
181
+ writeJson(referenceDocuments, { documents });
182
+ argv.push("--reference-documents", referenceDocuments);
183
+ }
184
+ }
185
+ const validation = run(argv);
186
+ const result = validation.validate(() => projectValidation(type, row, resultFile, validation.exit, validation.report, readResult(resultFile)));
187
+ return {
188
+ id: row.id,
189
+ version: row.version,
190
+ result: resultFile,
191
+ reference_documents: referenceDocuments ?? null,
192
+ ...result,
193
+ };
194
+ });
195
+ const reportFile = type === "process"
196
+ ? path.join(directory, "outputs", "validation-report.json")
197
+ : path.join(directory, `${type}-qa-report.json`);
198
+ const report = {
199
+ schema: `tiangong-foundry.typed-${type}-qa.v1`,
200
+ status: `completed_typed_${type}_validation`,
201
+ rows_file: rowsFile,
202
+ validation_input: options.validationInput ?? rowsFile,
203
+ validation_operation: operation,
204
+ validations: validations.map(({ complete, findings: _findings, ...validation }) => ({
205
+ ...validation,
206
+ complete_sha256: canonicalPayloadSha256(complete),
207
+ })),
208
+ rows: validations.map(({ complete, findings }) => ({ ...complete, findings })),
209
+ findings: validations.flatMap(({ findings }) => findings),
210
+ files: { report: reportFile },
211
+ };
212
+ writeJson(reportFile, report);
213
+ const exit = validations.some(({ complete }) => complete.status !== "passed") ? 1 : 0;
214
+ if (type !== "process")
215
+ return { reportFile, report, exit, validationReportFile: reportFile };
216
+ const qaFile = path.join(directory, "process-qa-report.json");
217
+ const qa = {
218
+ ...foundryProcessQa(rows, massReferences),
219
+ schema: "tiangong-foundry.process-qa.v1",
220
+ rows_file: rowsFile,
221
+ reference_evidence: referenceEvidence.map(({ fact }) => fact),
222
+ files: { report: qaFile },
223
+ };
224
+ writeJson(qaFile, qa);
225
+ return { reportFile: qaFile, report: qa, exit, validationReportFile: reportFile };
226
+ }
@@ -0,0 +1,6 @@
1
+ import { type FoundryAuthentication } from "./foundry-authentication-environment.ts";
2
+ import type { createFoundryEdgeActor } from "./foundry-edge-session.ts";
3
+ import type { EdgeSupportRoot } from "./foundry-edge-support-plan.ts";
4
+ import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
5
+ import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
6
+ export declare function createFoundryTypedModelDraft(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, receipt: Awaited<ReturnType<typeof createFoundryEdgeActor>>["receipt"], originalRequest: string, root: EdgeSupportRoot, content: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,59 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { createFoundryAuthenticationEnvironment, } from "./foundry-authentication-environment.js";
3
+ import { FoundryContextError } from "./foundry-runtime-context.js";
4
+ import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
5
+ import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
6
+ import { workflowObject } from "./foundry-workflow-state.js";
7
+ import { sha256Json, sha256Text } from "./identity-preflight-proof.js";
8
+ export function createFoundryTypedModelDraft(context, qualified, authentication, receipt, originalRequest, root, content) {
9
+ assertQualifiedFoundryRuntime(context, qualified);
10
+ const cli = resolveInstalledTiangongLcaCliPackage();
11
+ const expectedActor = receipt.identity.user_id;
12
+ const expectedEnvironment = new URL(receipt.project.project_base_url).origin;
13
+ const request = {
14
+ id: root.id,
15
+ version: root.version,
16
+ content,
17
+ requestId: sha256Json({ originalRequest, id: root.id, version: root.version }),
18
+ expectedActor,
19
+ expectedEnvironment,
20
+ };
21
+ const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
22
+ let child;
23
+ try {
24
+ child = spawnSync(process.execPath, [cli.binPath, "dataset", "model", "create", "--input", "-", "--json"], {
25
+ cwd: context.workspaceRoot,
26
+ env: environment,
27
+ input: JSON.stringify(request),
28
+ encoding: "utf8",
29
+ shell: false,
30
+ timeout: 60_000,
31
+ maxBuffer: 8 * 1024 * 1024,
32
+ });
33
+ }
34
+ finally {
35
+ delete environment.TIANGONG_LCA_ACCESS_TOKEN;
36
+ }
37
+ const unproven = () => new FoundryContextError("model_draft_result_unproven", "The original Model write requires independent exact readback.");
38
+ if (child.status !== 0 || child.signal || child.error || child.stderr)
39
+ throw unproven();
40
+ const envelope = workflowObject(JSON.parse(child.stdout));
41
+ const data = workflowObject(envelope.data);
42
+ const subject = workflowObject(data.subject);
43
+ const provenance = workflowObject(envelope.context);
44
+ if (envelope.schemaVersion !== 1 ||
45
+ envelope.operation !== "dataset model create" ||
46
+ envelope.status !== "completed" ||
47
+ envelope.outcome !== "dataset_written" ||
48
+ envelope.error !== null ||
49
+ subject.type !== "model" ||
50
+ subject.id !== root.id ||
51
+ subject.version !== root.version ||
52
+ data.contentDigest !== sha256Text(JSON.stringify(content)) ||
53
+ provenance.environment !== expectedEnvironment ||
54
+ workflowObject(provenance.actor).id !== expectedActor ||
55
+ provenance.requestId !== request.requestId ||
56
+ workflowObject(data.readback).contentMatchesIntent !== true)
57
+ throw unproven();
58
+ return envelope;
59
+ }
@@ -0,0 +1,8 @@
1
+ /** Queue interfaces from selected complete bodies; metadata is not exact-version evidence. */
2
+ export declare function selectedFoundryExternalFlowReferences(processRows: readonly unknown[], referenceRows: readonly unknown[]): Array<{
3
+ id: string;
4
+ version: string;
5
+ source: "selected_read_only_qa_reference";
6
+ }>;
7
+ /** Pure exact-version projection for CLI validation only; no scientific payload or write row changes. */
8
+ export declare function projectFoundryValidationReferences(processRows: readonly unknown[], referenceRows: readonly unknown[]): unknown[];
@@ -0,0 +1,115 @@
1
+ import { FoundryContextError } from "./foundry-runtime-error.js";
2
+ import { sha256Json } from "./identity-preflight-proof.js";
3
+ import { datasetRoot, unwrapDatasetPayload } from "./import-curation/internal/dataset-payload.js";
4
+ function object(value) {
5
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
6
+ }
7
+ function invalid(message) {
8
+ throw new FoundryContextError("workflow_validation_reference_invalid", message);
9
+ }
10
+ function flowKey(document) {
11
+ const flow = object(object(document)?.flowDataSet);
12
+ const information = object(object(flow?.flowInformation)?.dataSetInformation);
13
+ const publication = object(object(flow?.administrativeInformation)?.publicationAndOwnership);
14
+ const id = information?.["common:UUID"], version = publication?.["common:dataSetVersion"];
15
+ return typeof id === "string" && id && typeof version === "string" && version
16
+ ? JSON.stringify([id, version])
17
+ : null;
18
+ }
19
+ /** Queue interfaces from selected complete bodies; metadata is not exact-version evidence. */
20
+ export function selectedFoundryExternalFlowReferences(processRows, referenceRows) {
21
+ const available = new Set();
22
+ for (const row of referenceRows) {
23
+ const key = flowKey(unwrapDatasetPayload(row, "flow"));
24
+ if (key)
25
+ available.add(key);
26
+ }
27
+ const byId = new Map();
28
+ for (const row of processRows) {
29
+ const raw = datasetRoot(unwrapDatasetPayload(row, "process"), "process").exchanges?.exchange;
30
+ for (const exchange of raw ? (Array.isArray(raw) ? raw : [raw]) : []) {
31
+ const ref = object(object(exchange)?.referenceToFlowDataSet);
32
+ const id = ref?.["@refObjectId"];
33
+ if (typeof id !== "string" || !id)
34
+ continue;
35
+ const versions = byId.get(id) ?? new Set();
36
+ versions.add(typeof ref?.["@version"] === "string" ? ref["@version"] : "");
37
+ byId.set(id, versions);
38
+ }
39
+ }
40
+ return [...byId].flatMap(([id, versions]) => [...versions].every((version) => version && available.has(JSON.stringify([id, version])))
41
+ ? [...versions].map((version) => ({
42
+ id,
43
+ version,
44
+ source: "selected_read_only_qa_reference",
45
+ }))
46
+ : []);
47
+ }
48
+ /** Pure exact-version projection for CLI validation only; no scientific payload or write row changes. */
49
+ export function projectFoundryValidationReferences(processRows, referenceRows) {
50
+ const flows = new Map();
51
+ const remember = (document) => {
52
+ const key = flowKey(document);
53
+ if (!key)
54
+ return;
55
+ const hash = sha256Json(document), prior = flows.get(key);
56
+ if (prior && prior.hash !== hash)
57
+ invalid("Exact Flow evidence has conflicting complete bodies.");
58
+ if (!prior)
59
+ flows.set(key, { document, hash });
60
+ };
61
+ for (const row of referenceRows) {
62
+ const document = object(unwrapDatasetPayload(row, "flow"));
63
+ if (document?.flowDataSet)
64
+ remember(document);
65
+ }
66
+ return processRows.map((original) => {
67
+ const source = object(original);
68
+ if (!source)
69
+ invalid("Process validation row must be an object.");
70
+ const payload = unwrapDatasetPayload(original, "process");
71
+ const root = datasetRoot(payload, "process");
72
+ const rawContext = source.semantic_context;
73
+ const context = rawContext === undefined ? {} : object(rawContext);
74
+ if (!context)
75
+ invalid("Existing Process semantic context must be an object.");
76
+ const supplied = context.flow_documents;
77
+ if (supplied !== undefined && !Array.isArray(supplied))
78
+ invalid("Existing Process Flow documents must be an array.");
79
+ const documents = [];
80
+ const included = new Map();
81
+ for (const raw of supplied ?? []) {
82
+ const document = object(raw);
83
+ if (!document?.flowDataSet)
84
+ invalid("Existing Process context must contain complete Flow documents.");
85
+ const key = flowKey(document);
86
+ if (key) {
87
+ const prior = flows.get(key);
88
+ if (prior && prior.hash !== sha256Json(document))
89
+ invalid("Selected Flow evidence conflicts with original Process context.");
90
+ const priorHash = included.get(key);
91
+ if (priorHash && priorHash !== sha256Json(document))
92
+ invalid("Original Process context has conflicting exact Flow bodies.");
93
+ included.set(key, sha256Json(document));
94
+ }
95
+ documents.push(document);
96
+ }
97
+ const raw = root.exchanges?.exchange;
98
+ for (const exchange of raw ? (Array.isArray(raw) ? raw : [raw]) : []) {
99
+ const ref = object(object(exchange)?.referenceToFlowDataSet);
100
+ const id = ref?.["@refObjectId"], version = ref?.["@version"];
101
+ if (typeof id !== "string" || !id || typeof version !== "string" || !version)
102
+ continue;
103
+ const key = JSON.stringify([id, version]), selected = flows.get(key);
104
+ if (selected && !included.has(key)) {
105
+ documents.push(selected.document);
106
+ included.set(key, selected.hash);
107
+ }
108
+ }
109
+ const wrapper = payload === original ? { json: payload } : { ...source };
110
+ const projected = { ...wrapper, semantic_context: { ...context, flow_documents: documents } };
111
+ if (sha256Json(unwrapDatasetPayload(projected, "process")) !== sha256Json(payload))
112
+ invalid("Validation projection changed the Process scientific payload.");
113
+ return projected;
114
+ });
115
+ }
@@ -5,5 +5,6 @@ export interface FoundryAssessmentOptions {
5
5
  scopeType?: string;
6
6
  previousAssessment?: string;
7
7
  interactionSha256?: string | null;
8
+ qualityReviewSha256?: string | null;
8
9
  }
9
10
  export declare function assessFoundryWorkflowRows(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, rowsReport: string, contextReports: readonly string[], identityReport?: string, options?: FoundryAssessmentOptions): Promise<import("./foundry-task-types.ts").JsonRecord>;