@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.
- package/README.md +23 -7
- package/docs/architecture.md +15 -3
- package/docs/foundry-task-contracts.md +27 -3
- package/docs/package-distribution-contract.md +45 -13
- package/docs/public-runtime-contract.md +85 -5
- package/docs/runtime-context-contract.md +22 -4
- package/docs/task-authorization-contract.md +15 -3
- package/docs/workspace-migration-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +541 -177
- package/package-dist/scripts/foundry-facade.d.ts +5 -0
- package/package-dist/scripts/foundry-facade.js +261 -16
- package/package-dist/scripts/foundry-runtime.d.ts +2 -2
- package/package-dist/scripts/lib/bundle-sample-utils.d.ts +4 -4
- package/package-dist/scripts/lib/bundle-source-context.d.ts +6 -4
- package/package-dist/scripts/lib/bundle-source-context.js +10 -8
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +18 -6
- 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/post-authoring.d.ts +11 -1
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +65 -9
- package/package-dist/scripts/lib/foundry-assessment-producer.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-assessment-producer.js +167 -0
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-command-metadata.js +6 -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-decision-owners.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-decision-owners.js +15 -7
- 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 +21 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +69 -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 +28 -3
- 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 +126 -13
- package/package-dist/scripts/lib/foundry-identity-stage-input.d.ts +24 -0
- package/package-dist/scripts/lib/foundry-identity-stage-input.js +122 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-identity-stage-state.js +48 -0
- package/package-dist/scripts/lib/foundry-installed-entry.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-installed-entry.js +173 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.d.ts +12 -0
- package/package-dist/scripts/lib/foundry-managed-adoption.js +108 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-managed-authentication.js +28 -0
- package/package-dist/scripts/lib/foundry-managed-host.js +14 -2
- package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-migration-transfer-io.js +27 -3
- 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 +20 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +10 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +96 -3
- 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-quality-review-context.d.ts +3 -0
- package/package-dist/scripts/lib/foundry-quality-review-context.js +18 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.d.ts +48 -0
- package/package-dist/scripts/lib/foundry-quality-review-input.js +284 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.d.ts +13 -0
- package/package-dist/scripts/lib/foundry-quality-review-lineage.js +123 -0
- package/package-dist/scripts/lib/foundry-quality-review.d.ts +112 -0
- package/package-dist/scripts/lib/foundry-quality-review.js +487 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- 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 +22 -2
- 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-task-authorization.d.ts +2 -1
- package/package-dist/scripts/lib/foundry-task-authorization.js +32 -11
- package/package-dist/scripts/lib/foundry-task-registration.js +4 -5
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.d.ts +28 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.js +250 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.d.ts +60 -0
- package/package-dist/scripts/lib/foundry-task-runtime-adoption.js +549 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +4 -1
- package/package-dist/scripts/lib/foundry-task-store.js +113 -4
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -1
- 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-validation-reference-context.d.ts +8 -0
- package/package-dist/scripts/lib/foundry-validation-reference-context.js +115 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +165 -34
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +99 -5
- package/package-dist/scripts/lib/foundry-workflow-child-failure.d.ts +44 -0
- package/package-dist/scripts/lib/foundry-workflow-child-failure.js +439 -0
- package/package-dist/scripts/lib/foundry-workflow-context.js +92 -22
- package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +64 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-recovery.js +450 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.d.ts +9 -0
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +717 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +26 -11
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-io.js +102 -16
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +65 -31
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +165 -22
- package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +4 -7
- package/package-dist/scripts/lib/identity-preflight-artifacts.js +18 -5
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +6 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +92 -13
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.d.ts +78 -0
- package/package-dist/scripts/lib/identity-preflight-recovery-proof.js +415 -0
- package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +9 -1
- package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -2
- package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +1 -0
- package/package-dist/scripts/lib/import-curation/curation-gate.js +19 -1
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +11 -2
- package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +4 -1
- package/package-dist/scripts/package-entry.js +2 -3
- package/package-dist/scripts/public-api.d.ts +5 -0
- package/package-dist/scripts/public-api.js +2 -0
- package/package-dist/scripts/runtime-entry.d.ts +2 -0
- package/package-dist/scripts/runtime-entry.js +42 -15
- package/package.json +6 -2
- package/specs/schemas/foundry-identity-stage-input.schema.json +47 -0
- package/specs/schemas/foundry-managed-adoption.schema.json +40 -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 +6 -2
- package/specs/schemas/foundry-quality-review-draft.schema.json +271 -0
- package/specs/schemas/foundry-quality-review-input.schema.json +271 -0
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { FoundryContextError, readFoundryInput, resolveFoundryInputPath, } from "./foundry-runtime-context.js";
|
|
3
|
+
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
4
|
+
import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
5
|
+
import { collectDatasetReferences } from "./import-curation/internal/workflow-reference-closure.js";
|
|
6
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
7
|
+
const uuid = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/iu;
|
|
8
|
+
const version = /^\d{2}\.\d{2}\.\d{3}$/u;
|
|
9
|
+
const digest = /^[0-9a-f]{64}$/u;
|
|
10
|
+
const maximumFileBytes = 8 * 1024 * 1024;
|
|
11
|
+
export function edgeReferenceKey(reference) {
|
|
12
|
+
return `${reference.table}:${reference.id}@${reference.version}`;
|
|
13
|
+
}
|
|
14
|
+
function requireIntent(value, message) {
|
|
15
|
+
if (!value)
|
|
16
|
+
throw new FoundryContextError("edge_reference_intent_invalid", message);
|
|
17
|
+
}
|
|
18
|
+
function record(value, keys) {
|
|
19
|
+
requireIntent(value &&
|
|
20
|
+
typeof value === "object" &&
|
|
21
|
+
!Array.isArray(value) &&
|
|
22
|
+
Object.keys(value).length === keys.length &&
|
|
23
|
+
keys.every((key) => Object.hasOwn(value, key)), "Reference intent or review contains missing or unsupported fields.");
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
export function readEdgeReferenceSnapshot(value, actor) {
|
|
27
|
+
const snapshot = record(value, [
|
|
28
|
+
"table",
|
|
29
|
+
"id",
|
|
30
|
+
"version",
|
|
31
|
+
"payload_sha256",
|
|
32
|
+
"user_id",
|
|
33
|
+
"state_code",
|
|
34
|
+
]);
|
|
35
|
+
requireIntent(typeof snapshot.table === "string" &&
|
|
36
|
+
typeof snapshot.id === "string" &&
|
|
37
|
+
uuid.test(snapshot.id) &&
|
|
38
|
+
typeof snapshot.version === "string" &&
|
|
39
|
+
version.test(snapshot.version) &&
|
|
40
|
+
typeof snapshot.payload_sha256 === "string" &&
|
|
41
|
+
digest.test(snapshot.payload_sha256) &&
|
|
42
|
+
typeof snapshot.user_id === "string" &&
|
|
43
|
+
uuid.test(snapshot.user_id) &&
|
|
44
|
+
(snapshot.state_code === 100 ||
|
|
45
|
+
(snapshot.state_code === 0 && snapshot.user_id.toLowerCase() === actor)), "A reviewed reference must select exact content of a public version or own draft.");
|
|
46
|
+
return {
|
|
47
|
+
table: snapshot.table,
|
|
48
|
+
id: snapshot.id.toLowerCase(),
|
|
49
|
+
version: snapshot.version,
|
|
50
|
+
payload_sha256: snapshot.payload_sha256,
|
|
51
|
+
user_id: snapshot.user_id.toLowerCase(),
|
|
52
|
+
state_code: snapshot.state_code,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function readEdgeReferenceIntent(context, input, type, target, rows) {
|
|
56
|
+
const read = (inputPath) => {
|
|
57
|
+
const selected = resolveFoundryInputPath(context, inputPath);
|
|
58
|
+
const bytes = readFoundryInput(context, selected, maximumFileBytes);
|
|
59
|
+
const fact = context.inputs.find((item) => item.path === selected);
|
|
60
|
+
const file = { path: fact.path, sha256: fact.sha256, bytes: fact.bytes };
|
|
61
|
+
try {
|
|
62
|
+
const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
63
|
+
return { file, value };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
throw new FoundryContextError("edge_reference_intent_invalid", "Reference evidence must be UTF-8 JSON.");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const { file, value } = read(input);
|
|
70
|
+
const intent = record(value, [
|
|
71
|
+
"schema_version",
|
|
72
|
+
"project_ref",
|
|
73
|
+
"actor_user_id",
|
|
74
|
+
"consumers",
|
|
75
|
+
"references",
|
|
76
|
+
]);
|
|
77
|
+
const identities = rows.map((row, index) => datasetIdentity(row, index, type));
|
|
78
|
+
const consumers = identities.map(({ id, version, payload }, row_index) => ({
|
|
79
|
+
row_index,
|
|
80
|
+
table: bundleRowTypes[type].plural,
|
|
81
|
+
id,
|
|
82
|
+
version,
|
|
83
|
+
payload_sha256: sha256Json(payload),
|
|
84
|
+
}));
|
|
85
|
+
requireIntent(intent.schema_version === "dataset-exact-reference-intent.v1" &&
|
|
86
|
+
/^[a-z0-9]{20}$/u.test(target.project_ref) &&
|
|
87
|
+
intent.project_ref === target.project_ref &&
|
|
88
|
+
typeof intent.actor_user_id === "string" &&
|
|
89
|
+
intent.actor_user_id.toLowerCase() === target.user_id &&
|
|
90
|
+
consumers.length > 0 &&
|
|
91
|
+
Array.isArray(intent.consumers) &&
|
|
92
|
+
sha256Json(intent.consumers.map((raw) => {
|
|
93
|
+
const row = record(raw, ["row_index", "table", "id", "version", "payload_sha256"]);
|
|
94
|
+
requireIntent(typeof row.id === "string" && uuid.test(row.id), "Reference consumer UUID is invalid.");
|
|
95
|
+
return { ...row, id: row.id.toLowerCase() };
|
|
96
|
+
})) === sha256Json(consumers) &&
|
|
97
|
+
Array.isArray(intent.references) &&
|
|
98
|
+
intent.references.length > 0 &&
|
|
99
|
+
intent.references.length <= 10000, "Reference intent must bind the verified actor and every exact final consumer in order.");
|
|
100
|
+
const occurrences = identities.map(({ payload }) => collectDatasetReferences(payload));
|
|
101
|
+
const selectedOccurrences = new Set();
|
|
102
|
+
const reviewFiles = new Map();
|
|
103
|
+
const reviewed = new Map();
|
|
104
|
+
let bytes = file.bytes;
|
|
105
|
+
const references = intent.references.map((raw) => {
|
|
106
|
+
const entry = record(raw, ["row_index", "path", "selected", "review"]);
|
|
107
|
+
const selected = readEdgeReferenceSnapshot(entry.selected, target.user_id);
|
|
108
|
+
const row_index = Number(entry.row_index);
|
|
109
|
+
const pointer = entry.path;
|
|
110
|
+
const occurrence = `${row_index}:${String(pointer)}`;
|
|
111
|
+
requireIntent(typeof entry.row_index === "number" &&
|
|
112
|
+
Number.isInteger(row_index) &&
|
|
113
|
+
typeof pointer === "string" &&
|
|
114
|
+
pointer.startsWith("/") &&
|
|
115
|
+
pointer.trim() === pointer &&
|
|
116
|
+
!selectedOccurrences.has(occurrence) &&
|
|
117
|
+
occurrences[row_index]?.filter((ref) => ref.path === pointer &&
|
|
118
|
+
ref.table === selected.table &&
|
|
119
|
+
ref.id === selected.id &&
|
|
120
|
+
ref.version === selected.version).length === 1, "Review must identify one unchanged exact occurrence in the selected consumer.");
|
|
121
|
+
selectedOccurrences.add(occurrence);
|
|
122
|
+
const locator = record(entry.review, ["file", "sha256"]);
|
|
123
|
+
requireIntent(typeof locator.file === "string" &&
|
|
124
|
+
locator.file.length > 0 &&
|
|
125
|
+
locator.file.trim() === locator.file &&
|
|
126
|
+
!/[\0\r\n]/u.test(locator.file), "Review locator must preserve its exact file spelling.");
|
|
127
|
+
const reviewPath = resolveFoundryInputPath(context, path.resolve(path.dirname(file.path), locator.file));
|
|
128
|
+
let review = reviewFiles.get(reviewPath);
|
|
129
|
+
if (!review) {
|
|
130
|
+
review = read(reviewPath);
|
|
131
|
+
bytes += review.file.bytes;
|
|
132
|
+
requireIntent(bytes <= 64 * 1024 * 1024, "Reference evidence exceeds its content budget.");
|
|
133
|
+
reviewFiles.set(reviewPath, review);
|
|
134
|
+
}
|
|
135
|
+
const declared = record(review.value, [
|
|
136
|
+
"schema_version",
|
|
137
|
+
"decision",
|
|
138
|
+
"reason",
|
|
139
|
+
"selected",
|
|
140
|
+
"latest",
|
|
141
|
+
]);
|
|
142
|
+
const latest = readEdgeReferenceSnapshot(declared.latest, target.user_id);
|
|
143
|
+
const key = edgeReferenceKey(selected);
|
|
144
|
+
const snapshots = { selected, latest };
|
|
145
|
+
requireIntent(locator.sha256 === review.file.sha256 &&
|
|
146
|
+
declared.schema_version === "dataset-exact-reference-review.v1" &&
|
|
147
|
+
declared.decision === "use_selected_exact" &&
|
|
148
|
+
typeof declared.reason === "string" &&
|
|
149
|
+
declared.reason.trim() &&
|
|
150
|
+
declared.reason.length <= 8192 &&
|
|
151
|
+
sha256Json(readEdgeReferenceSnapshot(declared.selected, target.user_id)) ===
|
|
152
|
+
sha256Json(selected) &&
|
|
153
|
+
latest.table === selected.table &&
|
|
154
|
+
latest.id === selected.id &&
|
|
155
|
+
latest.version >= selected.version &&
|
|
156
|
+
(latest.version !== selected.version || sha256Json(latest) === sha256Json(selected)) &&
|
|
157
|
+
(!reviewed.has(key) || sha256Json(reviewed.get(key)) === sha256Json(snapshots)), "Review must bind unchanged selected bytes and a consistent reviewed latest version.");
|
|
158
|
+
reviewed.set(key, snapshots);
|
|
159
|
+
return { row_index, path: pointer, selected, review: { file: review.file, latest } };
|
|
160
|
+
});
|
|
161
|
+
// One remote observation covers identical exact dependencies. Every outdated occurrence still
|
|
162
|
+
// requires its own explicit review before that observation can authorize the older version.
|
|
163
|
+
occurrences.forEach((list, index) => {
|
|
164
|
+
for (const ref of list) {
|
|
165
|
+
if (!ref.table)
|
|
166
|
+
continue;
|
|
167
|
+
const review = reviewed.get(edgeReferenceKey({ ...ref, table: ref.table }));
|
|
168
|
+
requireIntent(!review ||
|
|
169
|
+
review.selected.version === review.latest.version ||
|
|
170
|
+
selectedOccurrences.has(`${index}:${ref.path}`), "Every occurrence of an outdated exact dependency requires its own explicit review.");
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
binding: {
|
|
175
|
+
file,
|
|
176
|
+
project_ref: target.project_ref,
|
|
177
|
+
actor_user_id: target.user_id,
|
|
178
|
+
consumers,
|
|
179
|
+
references,
|
|
180
|
+
review_files: [...reviewFiles.values()].map((item) => item.file),
|
|
181
|
+
},
|
|
182
|
+
reviewed,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryAuthentication } from "./foundry-authentication-environment.ts";
|
|
4
|
+
import { type FoundryRepairExpectation } from "./foundry-repair-preflight.ts";
|
|
5
|
+
export declare function readEdgeRepairValidation(report: Record<string, unknown>, expectation: FoundryRepairExpectation): Record<string, boolean>;
|
|
6
|
+
export declare function prepareEdgeProcessRepair(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, expectation: FoundryRepairExpectation, files: {
|
|
7
|
+
before: string;
|
|
8
|
+
candidate: string;
|
|
9
|
+
temporary: string;
|
|
10
|
+
directory: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
schema: string;
|
|
13
|
+
input_path: string;
|
|
14
|
+
before: FoundryInputFact;
|
|
15
|
+
contract_sha256: string;
|
|
16
|
+
validation_sha256: string;
|
|
17
|
+
before_validation_sha256: string | null;
|
|
18
|
+
rule_verification: Record<string, boolean>;
|
|
19
|
+
reference_evidence: FoundryInputFact;
|
|
20
|
+
remote_before_sha256: string;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { captureFoundryInput, FoundryContextError, readFoundryInput, writeFoundryArtifact, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { createFoundryEdgeActor } from "./foundry-edge-session.js";
|
|
5
|
+
import { buildEdgeSupportPlan } from "./foundry-edge-support-plan.js";
|
|
6
|
+
import { planFoundryEdgeSupportStage } from "./foundry-edge-support-planning.js";
|
|
7
|
+
import { verifyFoundryEdgeSupport } from "./foundry-edge-support.js";
|
|
8
|
+
import { createFoundryAuthenticationEnvironment, } from "./foundry-authentication-environment.js";
|
|
9
|
+
import { runFoundryTypedDatasetQa } from "./foundry-typed-flow-qa.js";
|
|
10
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
11
|
+
import { parseFoundryRepairValidateReport, } from "./foundry-repair-preflight.js";
|
|
12
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
13
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
14
|
+
const invalid = (message) => new FoundryContextError("repair_edge_preflight_invalid", message);
|
|
15
|
+
export function readEdgeRepairValidation(report, expectation) {
|
|
16
|
+
if (report.schema !== "tiangong-foundry.typed-process-qa.v1" || !Array.isArray(report.rows))
|
|
17
|
+
throw invalid("Expected the full typed Process validation evidence.");
|
|
18
|
+
parseFoundryRepairValidateReport(report, expectation);
|
|
19
|
+
const verification = {};
|
|
20
|
+
for (const raw of report.rows) {
|
|
21
|
+
const row = workflowObject(raw);
|
|
22
|
+
if (workflowObject(row.allocation_semantics).status !== "passed" ||
|
|
23
|
+
workflowObject(row.flow_reference_names).status !== "passed" ||
|
|
24
|
+
!Array.isArray(row.issues) ||
|
|
25
|
+
row.issues.some((issue) => workflowObject(issue).code !== "annual_supply_or_production_volume_missing"))
|
|
26
|
+
throw invalid("Repair must preserve qualified allocation, exact Flow names and all validation checks except the bounded unknown annual-volume gap.");
|
|
27
|
+
verification[String(row.payload_sha256)] = row.status === "passed";
|
|
28
|
+
}
|
|
29
|
+
return verification;
|
|
30
|
+
}
|
|
31
|
+
export async function prepareEdgeProcessRepair(context, qualified, authentication, expectation, files) {
|
|
32
|
+
const { before, candidate, temporary, directory } = files;
|
|
33
|
+
const actor = await createFoundryEdgeActor(context, qualified, authentication);
|
|
34
|
+
const receiptFile = path.join(directory, "identity-receipt.json");
|
|
35
|
+
const save = (file, value) => writeFoundryArtifact(context, file, JSON.stringify(value, null, 2) + "\n");
|
|
36
|
+
save(receiptFile, actor.receipt);
|
|
37
|
+
const candidateFact = captureFoundryInput(candidate);
|
|
38
|
+
const referenceDir = path.join(directory, "references");
|
|
39
|
+
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent?.sessionReference, process.env);
|
|
40
|
+
const references = (() => {
|
|
41
|
+
try {
|
|
42
|
+
return planFoundryEdgeSupportStage(context, qualified, environment, "process", "repair_preflight", ["--input", candidate, "--out-dir", referenceDir], true, receiptFile, candidateFact);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
delete environment.TIANGONG_LCA_ACCESS_TOKEN;
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
if (references.exit_code !== 0 || !references.referenceDocuments)
|
|
49
|
+
throw invalid("Every exact repair dependency must be independently readable.");
|
|
50
|
+
const referenceReport = references.report.files.report;
|
|
51
|
+
if (typeof referenceReport !== "string")
|
|
52
|
+
throw invalid("Repair dependency evidence is missing.");
|
|
53
|
+
const documents = path.join(directory, "validation-references.json");
|
|
54
|
+
save(documents, references.referenceDocuments);
|
|
55
|
+
const validate = (file, directory) => {
|
|
56
|
+
const validation = runFoundryTypedDatasetQa(context, qualified, temporary, save, "process", file, directory, {
|
|
57
|
+
referenceFiles: [documents],
|
|
58
|
+
readRowsFile: (file) => file === documents
|
|
59
|
+
? fs.readFileSync(documents, "utf8")
|
|
60
|
+
: readFoundryInput(context, file).toString("utf8"),
|
|
61
|
+
});
|
|
62
|
+
return JSON.parse(fs.readFileSync(validation.validationReportFile, "utf8"));
|
|
63
|
+
};
|
|
64
|
+
const complete = validate(candidate, path.join(directory, "validation"));
|
|
65
|
+
const ruleVerification = readEdgeRepairValidation(complete, expectation);
|
|
66
|
+
const requiresBeforeValidation = Object.values(ruleVerification).includes(false);
|
|
67
|
+
const beforeEvidence = requiresBeforeValidation
|
|
68
|
+
? validate(before, path.join(directory, "before-validation"))
|
|
69
|
+
: null;
|
|
70
|
+
if (beforeEvidence) {
|
|
71
|
+
const beforeRules = readEdgeRepairValidation(beforeEvidence, {
|
|
72
|
+
...expectation,
|
|
73
|
+
actions: expectation.actions.map((action) => ({
|
|
74
|
+
...action,
|
|
75
|
+
desired_sha256: action.before_sha256,
|
|
76
|
+
})),
|
|
77
|
+
});
|
|
78
|
+
if (expectation.actions.some((action) => !ruleVerification[action.desired_sha256] && beforeRules[action.before_sha256]))
|
|
79
|
+
throw invalid("The unknown annual-volume gap must already exist in the selected before draft.");
|
|
80
|
+
}
|
|
81
|
+
const read = (fact) => readRows(fact.path, (file) => readFoundryInput(context, file).toString("utf8"));
|
|
82
|
+
const candidateRows = read(candidateFact);
|
|
83
|
+
const beforeFact = captureFoundryInput(before);
|
|
84
|
+
const target = { project_ref: expectation.project_ref, user_id: expectation.owner_user_id };
|
|
85
|
+
const plan = buildEdgeSupportPlan("process", candidateFact, target, candidateRows, {
|
|
86
|
+
fact: captureFoundryInput(referenceReport),
|
|
87
|
+
report: references.report,
|
|
88
|
+
});
|
|
89
|
+
const beforePlan = buildEdgeSupportPlan("process", beforeFact, target, read(beforeFact));
|
|
90
|
+
const expected = new Map(expectation.actions.map((item) => [`${item.id}@${item.version}`, item]));
|
|
91
|
+
const roots = plan.roots.map((root) => {
|
|
92
|
+
const prior = beforePlan.roots.find((item) => item.id === root.id && item.version === root.version);
|
|
93
|
+
const action = expected.get(`${root.id}@${root.version}`);
|
|
94
|
+
if (!prior ||
|
|
95
|
+
!action ||
|
|
96
|
+
prior.payload_sha256 !== action.before_sha256 ||
|
|
97
|
+
root.payload_sha256 !== action.desired_sha256)
|
|
98
|
+
throw invalid("Guarded update roots must match the exact reviewed contract.");
|
|
99
|
+
return { ...root, payload_sha256: prior.payload_sha256 };
|
|
100
|
+
});
|
|
101
|
+
// The repair scope has already bound every exact reference occurrence in both documents.
|
|
102
|
+
// An older visible dependency can be retained with the same content, owner and state.
|
|
103
|
+
const checked = await verifyFoundryEdgeSupport(actor, { ...plan, roots }, "after", true);
|
|
104
|
+
save(path.join(directory, "edge-before.json"), checked.responses);
|
|
105
|
+
if (checked.blockers.length)
|
|
106
|
+
throw invalid("Current draft or a dependency differs from the exact before snapshot.");
|
|
107
|
+
const report = {
|
|
108
|
+
schema: "tiangong-foundry.edge-repair-preflight.v1",
|
|
109
|
+
input_path: candidate,
|
|
110
|
+
before: beforeFact,
|
|
111
|
+
contract_sha256: expectation.contract_sha256,
|
|
112
|
+
validation_sha256: sha256Json(complete),
|
|
113
|
+
before_validation_sha256: beforeEvidence ? sha256Json(beforeEvidence) : null,
|
|
114
|
+
rule_verification: ruleVerification,
|
|
115
|
+
reference_evidence: captureFoundryInput(referenceReport),
|
|
116
|
+
remote_before_sha256: sha256Json(checked.responses),
|
|
117
|
+
};
|
|
118
|
+
save(path.join(directory, "owner-report.json"), report);
|
|
119
|
+
return report;
|
|
120
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryAuthentication } from "./foundry-runtime-identity.ts";
|
|
4
|
+
type IdentityEndpoint = "flow_hybrid_search" | "process_hybrid_search";
|
|
5
|
+
type EdgeEndpoint = IdentityEndpoint | "app_dataset_create" | "app_dataset_save_draft" | "app_dataset_verify_remote";
|
|
6
|
+
export declare function foundryEdgeProjectOrigin(value: string): string;
|
|
7
|
+
export declare function createFoundryEdgeActor(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication): Promise<{
|
|
8
|
+
receipt: import("@tiangong-lca/cli/auth-identity-receipt").AuthIdentityReceipt;
|
|
9
|
+
post(endpoint: EdgeEndpoint, body: Record<string, unknown>): Promise<unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function queryFoundryEdgeIdentity(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, authentication: FoundryAuthentication, endpoint: IdentityEndpoint, body: Record<string, unknown>): Promise<{
|
|
12
|
+
receipt: import("@tiangong-lca/cli/auth-identity-receipt").AuthIdentityReceipt;
|
|
13
|
+
result: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
2
|
+
import { assertVerifiedFoundryIdentity, verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
3
|
+
import { resolveFoundryEdgeOAuth } from "./foundry-edge-oauth.js";
|
|
4
|
+
export function foundryEdgeProjectOrigin(value) {
|
|
5
|
+
const url = new URL(value);
|
|
6
|
+
if (!["https:", "http:"].includes(url.protocol) ||
|
|
7
|
+
url.username ||
|
|
8
|
+
url.password ||
|
|
9
|
+
url.search ||
|
|
10
|
+
url.hash ||
|
|
11
|
+
!["", "/functions/v1", "/rest/v1"].includes(url.pathname.replace(/\/+$/u, "")))
|
|
12
|
+
throw new FoundryContextError("edge_project_invalid", "Expected an explicit project base URL.");
|
|
13
|
+
return url.origin;
|
|
14
|
+
}
|
|
15
|
+
export async function createFoundryEdgeActor(context, qualified, authentication) {
|
|
16
|
+
const credentials = authentication.mode === "headless"
|
|
17
|
+
? { ...authentication }
|
|
18
|
+
: {
|
|
19
|
+
...authentication,
|
|
20
|
+
configuration: { ...authentication.configuration },
|
|
21
|
+
};
|
|
22
|
+
const identity = verifyFoundryRuntimeIdentity(context, credentials, process.env, qualified);
|
|
23
|
+
const verifiedOrigin = foundryEdgeProjectOrigin(identity.receipt.project.project_base_url);
|
|
24
|
+
const configured = credentials.mode === "headless" ? credentials.apiBaseUrl : credentials.configuration.apiBaseUrl;
|
|
25
|
+
const origin = configured ? foundryEdgeProjectOrigin(configured) : verifiedOrigin;
|
|
26
|
+
if (origin !== verifiedOrigin)
|
|
27
|
+
throw new FoundryContextError("edge_project_mismatch", "Edge target must match the verified operator project.");
|
|
28
|
+
const token = credentials.mode === "headless"
|
|
29
|
+
? credentials.accessToken
|
|
30
|
+
: await resolveFoundryEdgeOAuth(origin, identity.receipt.identity.user_id, credentials.configuration);
|
|
31
|
+
const publishableKey = credentials.mode === "headless"
|
|
32
|
+
? credentials.publishableKey
|
|
33
|
+
: credentials.configuration.publishableKey;
|
|
34
|
+
// Browser authorization can take longer than the CLI receipt window.
|
|
35
|
+
const current = credentials.mode === "headless"
|
|
36
|
+
? identity
|
|
37
|
+
: verifyFoundryRuntimeIdentity(context, credentials, process.env, qualified);
|
|
38
|
+
if (foundryEdgeProjectOrigin(current.receipt.project.project_base_url) !== origin)
|
|
39
|
+
throw new FoundryContextError("edge_project_mismatch", "The OAuth project changed during authentication.");
|
|
40
|
+
return {
|
|
41
|
+
receipt: current.receipt,
|
|
42
|
+
async post(endpoint, body) {
|
|
43
|
+
assertVerifiedFoundryIdentity(context, current, qualified);
|
|
44
|
+
const url = new URL(`/functions/v1/${endpoint}`, origin);
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${token}`,
|
|
49
|
+
...(publishableKey ? { apikey: publishableKey } : {}),
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
Accept: "application/json",
|
|
52
|
+
},
|
|
53
|
+
redirect: "error",
|
|
54
|
+
signal: AbortSignal.timeout(30_000),
|
|
55
|
+
body: JSON.stringify(body),
|
|
56
|
+
});
|
|
57
|
+
if (!response.ok && !(endpoint === "app_dataset_verify_remote" && response.status === 409))
|
|
58
|
+
throw new FoundryContextError("edge_request_failed", "The selected Edge request was rejected.");
|
|
59
|
+
const text = await response.text();
|
|
60
|
+
if (Buffer.byteLength(text) > 8 * 1024 * 1024)
|
|
61
|
+
throw new FoundryContextError("edge_response_invalid", "The Edge response exceeds the evidence limit.");
|
|
62
|
+
return JSON.parse(text);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export async function queryFoundryEdgeIdentity(context, qualified, authentication, endpoint, body) {
|
|
67
|
+
const actor = await createFoundryEdgeActor(context, qualified, authentication);
|
|
68
|
+
return { receipt: actor.receipt, result: await actor.post(endpoint, body) };
|
|
69
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type FoundryInputFact } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type EdgeReferenceSnapshot } from "./foundry-edge-reference-intent.ts";
|
|
3
|
+
declare const schema = "tiangong-foundry.edge-support-create.v1";
|
|
4
|
+
declare const edgeDraftTypes: readonly ["unitgroup", "flowproperty", "process", "contact", "source", "flow", "lifecyclemodel"];
|
|
5
|
+
export type EdgeDraftType = (typeof edgeDraftTypes)[number];
|
|
6
|
+
export declare const isFoundryEdgeDraftType: (value: unknown) => value is EdgeDraftType;
|
|
7
|
+
export type EdgeSupportTarget = {
|
|
8
|
+
project_ref: string;
|
|
9
|
+
user_id: string;
|
|
10
|
+
};
|
|
11
|
+
type ExactKey = {
|
|
12
|
+
table: string;
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
};
|
|
16
|
+
export type EdgeSupportRoot = ExactKey & {
|
|
17
|
+
payload_sha256: string;
|
|
18
|
+
before_sha256?: string;
|
|
19
|
+
flow_head?: EdgeReferenceSnapshot | null;
|
|
20
|
+
references: Array<ExactKey & {
|
|
21
|
+
payload_sha256?: string;
|
|
22
|
+
expected_state_code?: number;
|
|
23
|
+
expected_owner?: string | null;
|
|
24
|
+
reviewed_latest?: EdgeReferenceSnapshot;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type EdgeUpdateBinding = {
|
|
28
|
+
before: FoundryInputFact;
|
|
29
|
+
contract: FoundryInputFact;
|
|
30
|
+
preparation: FoundryInputFact;
|
|
31
|
+
rule_verification: Record<string, boolean>;
|
|
32
|
+
};
|
|
33
|
+
type EdgeUpdateInput = {
|
|
34
|
+
binding: EdgeUpdateBinding;
|
|
35
|
+
rows: unknown[];
|
|
36
|
+
};
|
|
37
|
+
export type EdgeSupportPlan = {
|
|
38
|
+
schema: typeof schema;
|
|
39
|
+
dataset_type: EdgeDraftType;
|
|
40
|
+
input: FoundryInputFact;
|
|
41
|
+
project_ref: string;
|
|
42
|
+
user_id: string;
|
|
43
|
+
state_code: 0;
|
|
44
|
+
roots: EdgeSupportRoot[];
|
|
45
|
+
reference_evidence?: FoundryInputFact;
|
|
46
|
+
reference_intent?: FoundryInputFact[];
|
|
47
|
+
insert_contract?: FoundryInputFact;
|
|
48
|
+
update?: EdgeUpdateBinding;
|
|
49
|
+
sha256: string;
|
|
50
|
+
};
|
|
51
|
+
type ReferenceEvidence = {
|
|
52
|
+
fact: FoundryInputFact;
|
|
53
|
+
report: unknown;
|
|
54
|
+
};
|
|
55
|
+
export declare function buildEdgeSupportPlan(type: EdgeDraftType, input: FoundryInputFact, target: EdgeSupportTarget, rows: unknown[], evidence?: ReferenceEvidence, update?: EdgeUpdateInput, insertContract?: FoundryInputFact): EdgeSupportPlan;
|
|
56
|
+
export declare function isNextFlowVersion(current: string, desired: string): boolean;
|
|
57
|
+
export declare function isEdgeSupportPlan(value: unknown): value is EdgeSupportPlan;
|
|
58
|
+
export declare function verifyEdgeSupportPlan(plan: EdgeSupportPlan, approved: FoundryInputFact, target: EdgeSupportTarget, rows: unknown[], evidence?: ReferenceEvidence, update?: EdgeUpdateInput, insertContract?: FoundryInputFact): {
|
|
59
|
+
root: {
|
|
60
|
+
table: string;
|
|
61
|
+
id: string;
|
|
62
|
+
version: string;
|
|
63
|
+
payload_sha256: string;
|
|
64
|
+
references: ExactKey[];
|
|
65
|
+
};
|
|
66
|
+
content: Record<string, unknown>;
|
|
67
|
+
beforeContent?: Record<string, unknown> | undefined;
|
|
68
|
+
}[];
|
|
69
|
+
export {};
|