@tiangong-lca/foundry 0.1.18 → 0.1.20
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.
- package/README.md +5 -3
- package/docs/architecture.md +5 -3
- package/docs/foundry-task-contracts.md +2 -0
- package/docs/package-distribution-contract.md +10 -8
- package/docs/public-runtime-contract.md +53 -3
- package/docs/runtime-context-contract.md +7 -3
- package/docs/task-authorization-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +374 -136
- package/package-dist/scripts/foundry-facade.d.ts +6 -0
- package/package-dist/scripts/foundry-facade.js +38 -0
- package/package-dist/scripts/foundry-runtime.d.ts +3 -2
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- package/package-dist/scripts/lib/final-delivery-manifest.d.ts +40 -0
- package/package-dist/scripts/lib/final-delivery-manifest.js +145 -0
- package/package-dist/scripts/lib/final-delivery-review.d.ts +37 -0
- package/package-dist/scripts/lib/final-delivery-review.js +108 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
- package/package-dist/scripts/lib/finalize-owners/native-draft-handoff.js +4 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +9 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
- package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +24 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +209 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +32 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +203 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
- package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
- package/package-dist/scripts/lib/foundry-execution-admission.js +24 -2
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +68 -2
- package/package-dist/scripts/lib/foundry-interaction-input.js +2 -2
- package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +61 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +8 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
- package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
- package/package-dist/scripts/lib/foundry-repair-census.d.ts +82 -0
- package/package-dist/scripts/lib/foundry-repair-census.js +574 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-repair-scope.d.ts +15 -2
- package/package-dist/scripts/lib/foundry-repair-scope.js +62 -10
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +19 -1
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-scientific-repair.d.ts +38 -0
- package/package-dist/scripts/lib/foundry-scientific-repair.js +438 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +1 -1
- package/package-dist/scripts/lib/foundry-task-input-preparation.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-task-input-preparation.js +160 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +19 -1
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
- package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +67 -29
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
- package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
- package/package-dist/scripts/lib/foundry-workflow-execution.js +57 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
- package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
- package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-repair.js +204 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +41 -21
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/public-api.d.ts +6 -0
- package/package-dist/scripts/runtime-entry.js +15 -6
- package/package.json +5 -2
- package/specs/schemas/foundry-interaction-draft.schema.json +323 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-operation-result.schema.json +1 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +5 -2
- package/specs/schemas/foundry-scientific-repair.schema.json +66 -0
- package/specs/schemas/foundry-semantic-draft.schema.json +50 -0
- package/specs/schemas/foundry-task-start.schema.json +10 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
// Deterministic Process QA retained from TianGong LCA CLI 0.1.28 (MIT).
|
|
2
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
3
|
+
import { FoundryContextError } from "./foundry-runtime-error.js";
|
|
4
|
+
import { assessProcessMassBalance, } from "./foundry-process-mass-balance.js";
|
|
5
|
+
const methodologyRules = {
|
|
6
|
+
process_missing_source_base_name: "tidas.process.name.base-name.align-reference-flow",
|
|
7
|
+
process_missing_functional_unit: "tidas.process.quantitative-reference.required",
|
|
8
|
+
process_missing_quantitative_reference: "tidas.process.quantitative-reference.required",
|
|
9
|
+
process_missing_exchange_amount: "tidas.process.exchange.amount.required",
|
|
10
|
+
process_material_balance_deviation: "tidas.process.exchange.amount.required",
|
|
11
|
+
process_missing_system_boundary: "tidas.process.evidence.field-bindings.required",
|
|
12
|
+
process_missing_time: "tidas.process.evidence.field-bindings.required",
|
|
13
|
+
process_missing_geography: "tidas.process.evidence.field-bindings.required",
|
|
14
|
+
process_missing_technology: "tidas.process.evidence.field-bindings.required",
|
|
15
|
+
process_missing_admin_metadata: "tidas.process.evidence.field-bindings.required",
|
|
16
|
+
process_exchange_unit_semantic_mismatch: "tidas.process.exchange.amount.required",
|
|
17
|
+
};
|
|
18
|
+
const KIND_RE = /\[tg_io_kind_tag=([^\]]+)\]/gu;
|
|
19
|
+
const UOM_RE = /\[tg_io_uom_tag=([^\]]+)\]/giu;
|
|
20
|
+
const ENERGY_WORDS = [
|
|
21
|
+
"electric",
|
|
22
|
+
"electricity",
|
|
23
|
+
"kwh",
|
|
24
|
+
"mj",
|
|
25
|
+
"heat",
|
|
26
|
+
"steam",
|
|
27
|
+
"fuel",
|
|
28
|
+
"diesel",
|
|
29
|
+
"gas",
|
|
30
|
+
"power",
|
|
31
|
+
"电",
|
|
32
|
+
"能",
|
|
33
|
+
];
|
|
34
|
+
const RAW_WORDS = [
|
|
35
|
+
"raw material",
|
|
36
|
+
"feedstock",
|
|
37
|
+
"fertilizer",
|
|
38
|
+
"water",
|
|
39
|
+
"seed",
|
|
40
|
+
"pesticide",
|
|
41
|
+
"原材料",
|
|
42
|
+
"投入",
|
|
43
|
+
"肥料",
|
|
44
|
+
"种子",
|
|
45
|
+
"农药",
|
|
46
|
+
"用水",
|
|
47
|
+
];
|
|
48
|
+
const BYP_WORDS = ["by-product", "co-product", "副产品", "联产"];
|
|
49
|
+
const WASTE_WORDS = ["waste", "废", "residue", "sludge"];
|
|
50
|
+
function isRecord(value) {
|
|
51
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
52
|
+
}
|
|
53
|
+
function textFromValue(value) {
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
return value
|
|
56
|
+
.filter(isRecord)
|
|
57
|
+
.map((item) => String(item["#text"] ?? ""))
|
|
58
|
+
.join(" ");
|
|
59
|
+
}
|
|
60
|
+
if (isRecord(value)) {
|
|
61
|
+
return String(value["#text"] ?? "");
|
|
62
|
+
}
|
|
63
|
+
return String(value ?? "");
|
|
64
|
+
}
|
|
65
|
+
function deepGet(value, pathParts) {
|
|
66
|
+
let current = value;
|
|
67
|
+
for (const key of pathParts) {
|
|
68
|
+
if (!isRecord(current)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
current = current[key];
|
|
72
|
+
if (current === undefined || current === null) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return current;
|
|
77
|
+
}
|
|
78
|
+
function hasNonEmpty(value) {
|
|
79
|
+
if (value === null || value === undefined) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
return value.trim().length > 0;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return value.some((item) => hasNonEmpty(item));
|
|
87
|
+
}
|
|
88
|
+
if (isRecord(value)) {
|
|
89
|
+
if ("#text" in value) {
|
|
90
|
+
return hasNonEmpty(value["#text"]);
|
|
91
|
+
}
|
|
92
|
+
return Object.values(value).some((item) => hasNonEmpty(item));
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
function extractBaseNames(processPayload) {
|
|
97
|
+
const base = deepGet(processPayload, [
|
|
98
|
+
"processDataSet",
|
|
99
|
+
"processInformation",
|
|
100
|
+
"dataSetInformation",
|
|
101
|
+
"name",
|
|
102
|
+
"baseName",
|
|
103
|
+
]);
|
|
104
|
+
const items = Array.isArray(base) ? base : base ? [base] : [];
|
|
105
|
+
const values = [];
|
|
106
|
+
items.forEach((item) => {
|
|
107
|
+
if (!isRecord(item)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const text = String(item["#text"] ?? "").trim();
|
|
111
|
+
if (!text) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
values.push(text);
|
|
115
|
+
});
|
|
116
|
+
return [values.length > 0, values];
|
|
117
|
+
}
|
|
118
|
+
function sourceTracePayload(exchange) {
|
|
119
|
+
const payload = deepGet(exchange, ["common:other", "tidasimport:sourceTrace", "payload"]);
|
|
120
|
+
if (!isRecord(payload)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return isRecord(payload.sourceTrace) ? payload.sourceTrace : payload;
|
|
124
|
+
}
|
|
125
|
+
function sourceClassification(exchange) {
|
|
126
|
+
const payload = sourceTracePayload(exchange);
|
|
127
|
+
return payload && isRecord(payload.sourceClassification) ? payload.sourceClassification : {};
|
|
128
|
+
}
|
|
129
|
+
function sourceGroup(exchange, groupName) {
|
|
130
|
+
const value = sourceClassification(exchange)[groupName];
|
|
131
|
+
const text = String(value ?? "").trim();
|
|
132
|
+
return text || null;
|
|
133
|
+
}
|
|
134
|
+
function classifyExchange(exchange, referenceFlowId = null) {
|
|
135
|
+
const comments = `${textFromValue(exchange.commonComment)} ${textFromValue(exchange.generalComment)}`;
|
|
136
|
+
const flowDescription = textFromValue(isRecord(exchange.referenceToFlowDataSet)
|
|
137
|
+
? exchange.referenceToFlowDataSet["common:shortDescription"]
|
|
138
|
+
: undefined);
|
|
139
|
+
const rawBlob = `${comments} ${flowDescription}`.trim();
|
|
140
|
+
const blob = rawBlob.toLowerCase();
|
|
141
|
+
const kinds = Array.from(blob.matchAll(KIND_RE), (match) => match[1].toLowerCase());
|
|
142
|
+
const kindSet = new Set(kinds);
|
|
143
|
+
const uoms = Array.from(rawBlob.matchAll(UOM_RE), (match) => match[1]);
|
|
144
|
+
const direction = String(exchange.exchangeDirection ?? "").toLowerCase();
|
|
145
|
+
const inputGroup = sourceGroup(exchange, "inputGroup");
|
|
146
|
+
const outputGroup = sourceGroup(exchange, "outputGroup");
|
|
147
|
+
const internalId = String(exchange["@dataSetInternalID"] ?? "").trim();
|
|
148
|
+
const isReferenceFlow = Boolean(referenceFlowId && internalId === referenceFlowId);
|
|
149
|
+
const meta = {
|
|
150
|
+
kinds,
|
|
151
|
+
uoms,
|
|
152
|
+
blob,
|
|
153
|
+
source_input_group: inputGroup,
|
|
154
|
+
source_output_group: outputGroup,
|
|
155
|
+
reference_flow: isReferenceFlow,
|
|
156
|
+
};
|
|
157
|
+
const isEnergy = ENERGY_WORDS.some((word) => blob.includes(word)) ||
|
|
158
|
+
uoms.some((uom) => uom === "kwh" || uom === "mj" || uom === "gj");
|
|
159
|
+
if (direction === "input") {
|
|
160
|
+
if (kindSet.has("energy") || isEnergy) {
|
|
161
|
+
return { classification: "energy_input", ...meta };
|
|
162
|
+
}
|
|
163
|
+
if (kindSet.has("waste")) {
|
|
164
|
+
return { classification: "other_input", ...meta };
|
|
165
|
+
}
|
|
166
|
+
if (inputGroup === "4" || kindSet.has("raw_material") || kindSet.has("resource")) {
|
|
167
|
+
return { classification: "raw_material_input", ...meta };
|
|
168
|
+
}
|
|
169
|
+
if (kindSet.has("product") || RAW_WORDS.some((word) => blob.includes(word))) {
|
|
170
|
+
return { classification: "raw_material_input", ...meta };
|
|
171
|
+
}
|
|
172
|
+
return { classification: "other_input", ...meta };
|
|
173
|
+
}
|
|
174
|
+
if (direction === "output") {
|
|
175
|
+
if (isReferenceFlow || outputGroup === "0") {
|
|
176
|
+
return { classification: "product_output", ...meta };
|
|
177
|
+
}
|
|
178
|
+
if (kindSet.has("waste") ||
|
|
179
|
+
outputGroup === "4" ||
|
|
180
|
+
outputGroup === "5" ||
|
|
181
|
+
WASTE_WORDS.some((word) => blob.includes(word))) {
|
|
182
|
+
return { classification: "waste_output", ...meta };
|
|
183
|
+
}
|
|
184
|
+
if (BYP_WORDS.some((word) => blob.includes(word))) {
|
|
185
|
+
return { classification: "byproduct_output", ...meta };
|
|
186
|
+
}
|
|
187
|
+
if (kindSet.has("product")) {
|
|
188
|
+
return { classification: "product_output", ...meta };
|
|
189
|
+
}
|
|
190
|
+
return { classification: "other_output", ...meta };
|
|
191
|
+
}
|
|
192
|
+
return { classification: "other", ...meta };
|
|
193
|
+
}
|
|
194
|
+
function unitIssueCheck(exchange, uoms, blob) {
|
|
195
|
+
const flowUuid = isRecord(exchange.referenceToFlowDataSet)
|
|
196
|
+
? String(exchange.referenceToFlowDataSet["@refObjectId"] ?? "")
|
|
197
|
+
: "";
|
|
198
|
+
if (!flowUuid) {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
const currentUnit = (uoms[0] ?? "").toLowerCase();
|
|
202
|
+
if (["electric", "electricity", "交流电", "电力"].some((word) => blob.includes(word)) &&
|
|
203
|
+
currentUnit &&
|
|
204
|
+
!["kwh", "mj", "gj"].includes(currentUnit)) {
|
|
205
|
+
return [
|
|
206
|
+
{
|
|
207
|
+
flow_uuid: flowUuid,
|
|
208
|
+
current_unit: currentUnit,
|
|
209
|
+
suggested_unit: "kWh",
|
|
210
|
+
basis: "flow 描述为电力/电能,但 uom 标签非能量单位",
|
|
211
|
+
confidence: "高",
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
if (["water", "用水", "工艺用水"].some((word) => blob.includes(word)) &&
|
|
216
|
+
currentUnit &&
|
|
217
|
+
["kwh", "mj", "gj"].includes(currentUnit)) {
|
|
218
|
+
return [
|
|
219
|
+
{
|
|
220
|
+
flow_uuid: flowUuid,
|
|
221
|
+
current_unit: currentUnit,
|
|
222
|
+
suggested_unit: "m3 或 kg",
|
|
223
|
+
basis: "flow 描述为水,但 uom 标签为能量单位",
|
|
224
|
+
confidence: "高",
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
if (["co2", "carbon dioxide", "二氧化碳"].some((word) => blob.includes(word)) &&
|
|
229
|
+
currentUnit &&
|
|
230
|
+
["kwh", "mj", "gj"].includes(currentUnit)) {
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
flow_uuid: flowUuid,
|
|
234
|
+
current_unit: currentUnit,
|
|
235
|
+
suggested_unit: "kg",
|
|
236
|
+
basis: "排放流通常质量单位计,当前为能量单位",
|
|
237
|
+
confidence: "中",
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
function hasNumericAmount(exchange) {
|
|
244
|
+
for (const key of ["meanAmount", "resultingAmount"]) {
|
|
245
|
+
const value = exchange[key];
|
|
246
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if (typeof value === "string" && value.trim() && Number.isFinite(Number(value))) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
function createProcessQaFinding(options) {
|
|
256
|
+
const methodologyRuleId = methodologyRules[options.code] ?? null;
|
|
257
|
+
return {
|
|
258
|
+
process_file: options.processFile,
|
|
259
|
+
severity: options.severity,
|
|
260
|
+
code: options.code,
|
|
261
|
+
methodology_rule_id: methodologyRuleId,
|
|
262
|
+
message: options.message,
|
|
263
|
+
source: "rule",
|
|
264
|
+
...(options.evidence ? { evidence: options.evidence } : {}),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function reviewFindingsForBase(processFile, base) {
|
|
268
|
+
const findings = [];
|
|
269
|
+
if (!base.source_name_ok) {
|
|
270
|
+
findings.push(createProcessQaFinding({
|
|
271
|
+
processFile,
|
|
272
|
+
severity: "warning",
|
|
273
|
+
code: "process_missing_source_base_name",
|
|
274
|
+
message: "Process baseName should include a usable source-language entry before Foundry authoring is complete.",
|
|
275
|
+
evidence: { base_names: base.base_names },
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
if (!base.functional_unit_ok) {
|
|
279
|
+
findings.push(createProcessQaFinding({
|
|
280
|
+
processFile,
|
|
281
|
+
severity: "warning",
|
|
282
|
+
code: "process_missing_functional_unit",
|
|
283
|
+
message: "Process quantitative reference functionalUnitOrOther is missing and should be curated by Foundry.",
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
for (const [ok, code, message] of [
|
|
287
|
+
[
|
|
288
|
+
base.system_boundary_ok,
|
|
289
|
+
"process_missing_system_boundary",
|
|
290
|
+
"Process system boundary or typeOfDataSet context is missing.",
|
|
291
|
+
],
|
|
292
|
+
[base.time_ok, "process_missing_time", "Process time coverage is missing."],
|
|
293
|
+
[base.geo_ok, "process_missing_geography", "Process geography is missing."],
|
|
294
|
+
[base.tech_ok, "process_missing_technology", "Process technology description is missing."],
|
|
295
|
+
[
|
|
296
|
+
base.admin_ok,
|
|
297
|
+
"process_missing_admin_metadata",
|
|
298
|
+
"Process administrative metadata is missing.",
|
|
299
|
+
],
|
|
300
|
+
]) {
|
|
301
|
+
if (!ok) {
|
|
302
|
+
findings.push(createProcessQaFinding({
|
|
303
|
+
processFile,
|
|
304
|
+
severity: "warning",
|
|
305
|
+
code,
|
|
306
|
+
message,
|
|
307
|
+
}));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return findings;
|
|
311
|
+
}
|
|
312
|
+
function baseInfoCheck(processPayload) {
|
|
313
|
+
const [sourceNameOk, values] = extractBaseNames(processPayload);
|
|
314
|
+
const functionalUnit = deepGet(processPayload, [
|
|
315
|
+
"processDataSet",
|
|
316
|
+
"processInformation",
|
|
317
|
+
"quantitativeReference",
|
|
318
|
+
"functionalUnitOrOther",
|
|
319
|
+
]);
|
|
320
|
+
const mixAndLocation = deepGet(processPayload, [
|
|
321
|
+
"processDataSet",
|
|
322
|
+
"processInformation",
|
|
323
|
+
"geography",
|
|
324
|
+
"mixAndLocationTypes",
|
|
325
|
+
]);
|
|
326
|
+
const route = deepGet(processPayload, [
|
|
327
|
+
"processDataSet",
|
|
328
|
+
"modellingAndValidation",
|
|
329
|
+
"LCIMethodAndAllocation",
|
|
330
|
+
"typeOfDataSet",
|
|
331
|
+
]);
|
|
332
|
+
const time = deepGet(processPayload, ["processDataSet", "processInformation", "time"]);
|
|
333
|
+
const geography = deepGet(processPayload, ["processDataSet", "processInformation", "geography"]);
|
|
334
|
+
const technology = deepGet(processPayload, ["processDataSet", "modellingAndValidation"]);
|
|
335
|
+
const administrativeInformation = deepGet(processPayload, [
|
|
336
|
+
"processDataSet",
|
|
337
|
+
"administrativeInformation",
|
|
338
|
+
]);
|
|
339
|
+
const functionalUnitOk = hasNonEmpty(functionalUnit);
|
|
340
|
+
const systemBoundaryOk = hasNonEmpty(mixAndLocation) || hasNonEmpty(route);
|
|
341
|
+
const timeOk = hasNonEmpty(time);
|
|
342
|
+
const geographyOk = hasNonEmpty(geography);
|
|
343
|
+
const technologyOk = hasNonEmpty(technology);
|
|
344
|
+
const administrativeOk = hasNonEmpty(administrativeInformation);
|
|
345
|
+
const completenessScore = [
|
|
346
|
+
sourceNameOk,
|
|
347
|
+
functionalUnitOk,
|
|
348
|
+
systemBoundaryOk,
|
|
349
|
+
timeOk,
|
|
350
|
+
geographyOk,
|
|
351
|
+
technologyOk,
|
|
352
|
+
administrativeOk,
|
|
353
|
+
].filter(Boolean).length;
|
|
354
|
+
return {
|
|
355
|
+
source_name_ok: sourceNameOk,
|
|
356
|
+
functional_unit_ok: functionalUnitOk,
|
|
357
|
+
system_boundary_ok: systemBoundaryOk,
|
|
358
|
+
time_ok: timeOk,
|
|
359
|
+
geo_ok: geographyOk,
|
|
360
|
+
tech_ok: technologyOk,
|
|
361
|
+
admin_ok: administrativeOk,
|
|
362
|
+
completeness_score: completenessScore,
|
|
363
|
+
base_names: values,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
export function foundryProcessQa(rows, references) {
|
|
367
|
+
const findings = [];
|
|
368
|
+
const massBalance = rows.map((row, index) => {
|
|
369
|
+
const { id, version, payload } = datasetIdentity(row, index, "process");
|
|
370
|
+
if (!isRecord(payload))
|
|
371
|
+
throw new FoundryContextError("workflow_qa_failed", "Process QA requires a complete dataset.");
|
|
372
|
+
const rawExchanges = deepGet(payload, ["processDataSet", "exchanges", "exchange"]);
|
|
373
|
+
const exchanges = (Array.isArray(rawExchanges) ? rawExchanges : [rawExchanges]).filter(isRecord);
|
|
374
|
+
const referenceFlowId = String(deepGet(payload, [
|
|
375
|
+
"processDataSet",
|
|
376
|
+
"processInformation",
|
|
377
|
+
"quantitativeReference",
|
|
378
|
+
"referenceToReferenceFlow",
|
|
379
|
+
]) ?? "").trim() || null;
|
|
380
|
+
const processFile = `${id}__${version}.json`;
|
|
381
|
+
const base = baseInfoCheck(payload);
|
|
382
|
+
findings.push(...reviewFindingsForBase(processFile, base));
|
|
383
|
+
const addFinding = (code, message, evidence) => findings.push(createProcessQaFinding({ processFile, severity: "warning", code, message, evidence }));
|
|
384
|
+
for (const exchange of exchanges) {
|
|
385
|
+
const classified = classifyExchange(exchange, referenceFlowId);
|
|
386
|
+
if (!hasNumericAmount(exchange))
|
|
387
|
+
addFinding("process_missing_exchange_amount", "Process exchange is missing both numeric meanAmount and resultingAmount and should be curated by Foundry.", {
|
|
388
|
+
exchange_internal_id: String(exchange["@dataSetInternalID"] ?? ""),
|
|
389
|
+
direction: String(exchange.exchangeDirection ?? ""),
|
|
390
|
+
});
|
|
391
|
+
for (const issue of unitIssueCheck(exchange, classified.uoms, classified.blob))
|
|
392
|
+
addFinding("process_exchange_unit_semantic_mismatch", "Exchange unit tag conflicts with flow description semantics.", issue);
|
|
393
|
+
}
|
|
394
|
+
const mass = assessProcessMassBalance({
|
|
395
|
+
processFile,
|
|
396
|
+
processPayload: payload,
|
|
397
|
+
exchanges,
|
|
398
|
+
referenceFlowId,
|
|
399
|
+
references,
|
|
400
|
+
classify: (exchange) => classifyExchange(exchange, referenceFlowId),
|
|
401
|
+
});
|
|
402
|
+
for (const finding of mass.findings)
|
|
403
|
+
addFinding(finding.code, finding.message, { ...finding, unit: "kg" });
|
|
404
|
+
if ((mass.relative_deviation !== null && mass.relative_deviation > 0.05) ||
|
|
405
|
+
(mass.input_mass_kg === 0 && (mass.output_mass_kg ?? 0) > 0))
|
|
406
|
+
addFinding("process_material_balance_deviation", "Comparable mass inputs and outputs require review: positive output has zero input, or the relative kg deviation exceeds the QA threshold.", {
|
|
407
|
+
raw_input: mass.raw_input,
|
|
408
|
+
product: mass.product,
|
|
409
|
+
byproduct: mass.byproduct,
|
|
410
|
+
waste: mass.waste,
|
|
411
|
+
relative_deviation: mass.relative_deviation,
|
|
412
|
+
policy_decision_owner: "foundry",
|
|
413
|
+
});
|
|
414
|
+
return mass;
|
|
415
|
+
});
|
|
416
|
+
return {
|
|
417
|
+
status: "completed_local_process_qa",
|
|
418
|
+
policy_decision_owner: "foundry",
|
|
419
|
+
qa_mode: "deterministic_qa_report",
|
|
420
|
+
mass_balance: massBalance,
|
|
421
|
+
findings,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { FoundryAuthentication } from "./foundry-runtime-identity.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
4
|
+
declare const tables: {
|
|
5
|
+
readonly process: "processes";
|
|
6
|
+
readonly flow: "flows";
|
|
7
|
+
readonly flowproperty: "flowproperties";
|
|
8
|
+
readonly unitgroup: "unitgroups";
|
|
9
|
+
readonly source: "sources";
|
|
10
|
+
readonly contact: "contacts";
|
|
11
|
+
readonly lciamethod: "lciamethods";
|
|
12
|
+
readonly model: "lifecyclemodels";
|
|
13
|
+
};
|
|
14
|
+
type DatasetType = keyof typeof tables;
|
|
15
|
+
export interface FoundryRepairCensusQuery {
|
|
16
|
+
table: (typeof tables)[DatasetType];
|
|
17
|
+
state?: 0 | 100;
|
|
18
|
+
owner?: string;
|
|
19
|
+
id?: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
ids?: readonly string[];
|
|
22
|
+
projection?: "dependencies";
|
|
23
|
+
offset: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
}
|
|
26
|
+
export interface FoundryRepairCensusPage {
|
|
27
|
+
raw: string;
|
|
28
|
+
contentRange: string | null;
|
|
29
|
+
status: number;
|
|
30
|
+
identityReceipt?: unknown;
|
|
31
|
+
requestedAtUtc?: string;
|
|
32
|
+
}
|
|
33
|
+
type Reader = (query: FoundryRepairCensusQuery) => Promise<FoundryRepairCensusPage>;
|
|
34
|
+
type Row = Record<string, unknown>;
|
|
35
|
+
interface CensusObservation {
|
|
36
|
+
query: FoundryRepairCensusQuery;
|
|
37
|
+
page: FoundryRepairCensusPage;
|
|
38
|
+
response_sha256: string;
|
|
39
|
+
}
|
|
40
|
+
/** Two complete compact directory scans prove a bounded family's separation from all visible peers. */
|
|
41
|
+
export declare function readFoundryRepairCensus(workerInput: Row, actor: string, read: Reader, phase?: "before" | "after", observe?: (observation: CensusObservation) => void): Promise<{
|
|
42
|
+
proof: {
|
|
43
|
+
schema: string;
|
|
44
|
+
status: string;
|
|
45
|
+
observation_phase: "after" | "before";
|
|
46
|
+
input_object_sha256: string;
|
|
47
|
+
scope: string;
|
|
48
|
+
actor_user_id: string;
|
|
49
|
+
transaction_snapshot: boolean;
|
|
50
|
+
double_scan: boolean;
|
|
51
|
+
body_scope: string;
|
|
52
|
+
directory_complete: boolean;
|
|
53
|
+
directory_body_content_observed: boolean;
|
|
54
|
+
directory_projection_version: string;
|
|
55
|
+
excluded_process_rows: number;
|
|
56
|
+
excluded_model_rows: number;
|
|
57
|
+
family_separation: string;
|
|
58
|
+
directory_process_rows: number;
|
|
59
|
+
directory_model_rows: number;
|
|
60
|
+
directory_flow_rows: number;
|
|
61
|
+
directory_sha256: string;
|
|
62
|
+
family_nodes: number;
|
|
63
|
+
process_rows: number;
|
|
64
|
+
model_rows: number;
|
|
65
|
+
exact_support_rows: number;
|
|
66
|
+
process_census_sha256: string;
|
|
67
|
+
model_census_sha256: string;
|
|
68
|
+
support_census_sha256: string;
|
|
69
|
+
baseline_sha256: string;
|
|
70
|
+
read_pages: number;
|
|
71
|
+
transferred_bytes: number;
|
|
72
|
+
retained_projection_bytes: number;
|
|
73
|
+
exact_family_bytes: number;
|
|
74
|
+
completed_at_utc: string;
|
|
75
|
+
};
|
|
76
|
+
observations: CensusObservation[];
|
|
77
|
+
}>;
|
|
78
|
+
export declare function verifyFoundryRepairCensus(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, workerInput: Record<string, unknown>, directory: string, phase?: "before" | "after"): Promise<{
|
|
79
|
+
proof: Record<string, unknown>;
|
|
80
|
+
files: string[];
|
|
81
|
+
}>;
|
|
82
|
+
export {};
|