@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,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 {};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { bundleRowTypes } from "./bundle-row-types.js";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
4
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
5
|
+
import { dataSetInformation, datasetRoot, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
6
|
+
import { collectDatasetReferences } from "./import-curation/internal/workflow-reference-closure.js";
|
|
7
|
+
import { edgeReferenceKey, readEdgeReferenceSnapshot, } from "./foundry-edge-reference-intent.js";
|
|
8
|
+
const schema = "tiangong-foundry.edge-support-create.v1";
|
|
9
|
+
const uuid = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/u;
|
|
10
|
+
const versionPattern = /^\d{2}\.\d{2}\.\d{3}$/u;
|
|
11
|
+
const hash = /^[a-f0-9]{64}$/u;
|
|
12
|
+
const referenceTables = [
|
|
13
|
+
"contacts",
|
|
14
|
+
"sources",
|
|
15
|
+
"unitgroups",
|
|
16
|
+
"flowproperties",
|
|
17
|
+
"flows",
|
|
18
|
+
"processes",
|
|
19
|
+
"lifecyclemodels",
|
|
20
|
+
"lciamethods",
|
|
21
|
+
];
|
|
22
|
+
const edgeDraftTypes = [
|
|
23
|
+
"unitgroup",
|
|
24
|
+
"flowproperty",
|
|
25
|
+
"process",
|
|
26
|
+
"contact",
|
|
27
|
+
"source",
|
|
28
|
+
"flow",
|
|
29
|
+
"lifecyclemodel",
|
|
30
|
+
];
|
|
31
|
+
export const isFoundryEdgeDraftType = (value) => edgeDraftTypes.some((type) => type === value);
|
|
32
|
+
function invalid(message) {
|
|
33
|
+
throw new FoundryContextError("edge_support_plan_invalid", message);
|
|
34
|
+
}
|
|
35
|
+
function object(value) {
|
|
36
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
37
|
+
return invalid("Edge draft plan requires structured objects.");
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
function exactKey(table, id, version) {
|
|
41
|
+
if (typeof table !== "string" ||
|
|
42
|
+
!referenceTables.includes(table) ||
|
|
43
|
+
typeof id !== "string" ||
|
|
44
|
+
!uuid.test(id) ||
|
|
45
|
+
typeof version !== "string" ||
|
|
46
|
+
!versionPattern.test(version))
|
|
47
|
+
return invalid("Every draft and dependency must select an exact UUID and version.");
|
|
48
|
+
return { table, id, version };
|
|
49
|
+
}
|
|
50
|
+
function rootsFor(type, rows) {
|
|
51
|
+
if (!rows.length)
|
|
52
|
+
return invalid("Edge draft plan requires at least one approved dataset row.");
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
const table = bundleRowTypes[type].plural;
|
|
55
|
+
return rows.map((row) => {
|
|
56
|
+
const content = object(unwrapDatasetPayload(row, type));
|
|
57
|
+
const root = datasetRoot(content, type);
|
|
58
|
+
const own = object(object(root.administrativeInformation).publicationAndOwnership);
|
|
59
|
+
const key = exactKey(table, dataSetInformation(root, type)["common:UUID"], own["common:dataSetVersion"]);
|
|
60
|
+
const envelope = object(row);
|
|
61
|
+
if ((envelope.id !== undefined && envelope.id !== key.id) ||
|
|
62
|
+
(envelope.version !== undefined && envelope.version !== key.version) ||
|
|
63
|
+
seen.has(key.id))
|
|
64
|
+
return invalid("The approved rows contain an ambiguous identity or multiple versions.");
|
|
65
|
+
seen.add(key.id);
|
|
66
|
+
const refs = collectDatasetReferences(content);
|
|
67
|
+
if (type === "flowproperty") {
|
|
68
|
+
const unitGroup = refs.filter((ref) => ref.path.endsWith("/quantitativeReference/referenceToReferenceUnitGroup"));
|
|
69
|
+
if (unitGroup.length !== 1 || unitGroup[0].table !== "unitgroups")
|
|
70
|
+
return invalid("FlowProperty creation requires one exact reference UnitGroup.");
|
|
71
|
+
}
|
|
72
|
+
const references = new Map();
|
|
73
|
+
for (const ref of refs) {
|
|
74
|
+
const exact = exactKey(ref.table, ref.id, ref.version);
|
|
75
|
+
references.set(`${exact.table}:${exact.id}@${exact.version}`, exact);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
root: { ...key, payload_sha256: sha256Json(content), references: [...references.values()] },
|
|
79
|
+
content,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function buildEdgeSupportPlan(type, input, target, rows, evidence, update, insertContract) {
|
|
84
|
+
if (!isAbsolute(input.path) ||
|
|
85
|
+
!hash.test(input.sha256) ||
|
|
86
|
+
!Number.isSafeInteger(input.bytes) ||
|
|
87
|
+
input.bytes < 1)
|
|
88
|
+
return invalid("The Edge draft plan requires exact approved input bytes.");
|
|
89
|
+
if (!target.project_ref || !uuid.test(target.user_id))
|
|
90
|
+
return invalid("The Edge draft plan requires an exact project and owner.");
|
|
91
|
+
const documents = rootsFor(type, rows);
|
|
92
|
+
const payload = {
|
|
93
|
+
schema,
|
|
94
|
+
dataset_type: type,
|
|
95
|
+
input,
|
|
96
|
+
project_ref: target.project_ref,
|
|
97
|
+
user_id: target.user_id,
|
|
98
|
+
state_code: 0,
|
|
99
|
+
roots: documents.map(({ root }) => root),
|
|
100
|
+
};
|
|
101
|
+
if (evidence) {
|
|
102
|
+
const report = object(evidence.report);
|
|
103
|
+
if (report.schema !== "tiangong-foundry.edge-support-precommit.v1" ||
|
|
104
|
+
report.status !== "passed_remote_verification" ||
|
|
105
|
+
report.input_path !== input.path ||
|
|
106
|
+
report.edge_plan_sha256 !== sha256Json(payload) ||
|
|
107
|
+
!Array.isArray(report.checks))
|
|
108
|
+
return invalid("Reference evidence must verify all dependencies for these final rows.");
|
|
109
|
+
const checks = report.checks.map(object);
|
|
110
|
+
if (type === "flow") {
|
|
111
|
+
const heads = report.flow_heads;
|
|
112
|
+
if (!Array.isArray(heads) || heads.length !== payload.roots.length)
|
|
113
|
+
return invalid("Flow planning requires one observed head for every approved identity.");
|
|
114
|
+
payload.roots.forEach((root, index) => {
|
|
115
|
+
const observed = object(heads[index]);
|
|
116
|
+
if (observed.id !== root.id)
|
|
117
|
+
invalid("The observed Flow head belongs to another identity.");
|
|
118
|
+
root.flow_head =
|
|
119
|
+
observed.head === null ? null : readEdgeReferenceSnapshot(observed.head, target.user_id);
|
|
120
|
+
if (root.flow_head &&
|
|
121
|
+
(root.flow_head.table !== root.table ||
|
|
122
|
+
root.flow_head.id !== root.id ||
|
|
123
|
+
!isNextFlowVersion(root.flow_head.version, root.version)))
|
|
124
|
+
invalid("A new Flow version must immediately follow its verified current head.");
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const reviewed = new Map();
|
|
128
|
+
if (report.reference_intent) {
|
|
129
|
+
const intent = object(report.reference_intent);
|
|
130
|
+
if (!Array.isArray(intent.references) ||
|
|
131
|
+
!intent.references.length ||
|
|
132
|
+
!Array.isArray(intent.review_files) ||
|
|
133
|
+
!intent.review_files.length)
|
|
134
|
+
return invalid("Explicit reference intent requires the selected review artifacts.");
|
|
135
|
+
for (const raw of intent.references) {
|
|
136
|
+
const reference = object(raw);
|
|
137
|
+
const selected = readEdgeReferenceSnapshot(reference.selected, target.user_id);
|
|
138
|
+
const latest = readEdgeReferenceSnapshot(object(reference.review).latest, target.user_id);
|
|
139
|
+
reviewed.set(edgeReferenceKey(selected), { selected, latest });
|
|
140
|
+
}
|
|
141
|
+
payload.reference_intent = [intent.file, ...intent.review_files].map((raw) => {
|
|
142
|
+
const fact = object(raw);
|
|
143
|
+
if (typeof fact.path !== "string" ||
|
|
144
|
+
!isAbsolute(fact.path) ||
|
|
145
|
+
typeof fact.sha256 !== "string" ||
|
|
146
|
+
!hash.test(fact.sha256) ||
|
|
147
|
+
typeof fact.bytes !== "number" ||
|
|
148
|
+
!Number.isSafeInteger(fact.bytes) ||
|
|
149
|
+
fact.bytes < 1)
|
|
150
|
+
return invalid("Explicit reference artifacts require exact file facts.");
|
|
151
|
+
return { path: fact.path, sha256: fact.sha256, bytes: fact.bytes };
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
for (const root of payload.roots) {
|
|
155
|
+
root.references = root.references.map((reference) => {
|
|
156
|
+
const selected = checks.filter((check) => check.table === reference.table &&
|
|
157
|
+
check.id === reference.id &&
|
|
158
|
+
check.version === reference.version);
|
|
159
|
+
const check = selected[0];
|
|
160
|
+
const review = reviewed.get(edgeReferenceKey(reference));
|
|
161
|
+
if (selected.length !== 1 ||
|
|
162
|
+
check.role !== "reference" ||
|
|
163
|
+
check.status !== "ok" ||
|
|
164
|
+
typeof check.remote_payload_sha256 !== "string" ||
|
|
165
|
+
!hash.test(check.remote_payload_sha256) ||
|
|
166
|
+
!([100, 200].includes(Number(check.remote_state_code)) ||
|
|
167
|
+
(check.remote_state_code === 0 && check.remote_user_id === target.user_id)))
|
|
168
|
+
return invalid("A sealed draft dependency lacks exact owner and content evidence.");
|
|
169
|
+
if (review &&
|
|
170
|
+
(sha256Json(check.reviewed_latest) !== sha256Json(review.latest) ||
|
|
171
|
+
check.remote_payload_sha256 !== review.selected.payload_sha256 ||
|
|
172
|
+
check.remote_state_code !== review.selected.state_code ||
|
|
173
|
+
check.remote_user_id !== review.selected.user_id))
|
|
174
|
+
return invalid("Reviewed dependency evidence differs from the selected and latest snapshots.");
|
|
175
|
+
return {
|
|
176
|
+
...reference,
|
|
177
|
+
payload_sha256: check.remote_payload_sha256,
|
|
178
|
+
expected_state_code: Number(check.remote_state_code),
|
|
179
|
+
expected_owner: typeof check.remote_user_id === "string" ? check.remote_user_id : null,
|
|
180
|
+
...(review ? { reviewed_latest: review.latest } : {}),
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
payload.reference_evidence = evidence.fact;
|
|
185
|
+
}
|
|
186
|
+
if (update) {
|
|
187
|
+
if (type !== "process")
|
|
188
|
+
return invalid("Guarded Edge updates require a Process repair scope.");
|
|
189
|
+
const before = beforeFor(documents, update.rows);
|
|
190
|
+
payload.roots.forEach((root, index) => {
|
|
191
|
+
root.before_sha256 = sha256Json(before[index].content);
|
|
192
|
+
if (typeof update.binding.rule_verification[root.payload_sha256] !== "boolean")
|
|
193
|
+
invalid("Every update must preserve its approved validation result.");
|
|
194
|
+
});
|
|
195
|
+
if (payload.roots.every((root) => root.before_sha256 === root.payload_sha256))
|
|
196
|
+
return invalid("An unchanged draft does not require a guarded update.");
|
|
197
|
+
payload.update = update.binding;
|
|
198
|
+
}
|
|
199
|
+
if (insertContract) {
|
|
200
|
+
if (update || !["flow", "process", "source"].includes(type))
|
|
201
|
+
return invalid("An explicit insert contract must select eligible final rows.");
|
|
202
|
+
payload.insert_contract = insertContract;
|
|
203
|
+
}
|
|
204
|
+
return { ...payload, sha256: sha256Json(payload) };
|
|
205
|
+
}
|
|
206
|
+
export function isNextFlowVersion(current, desired) {
|
|
207
|
+
if (!versionPattern.test(current) || !versionPattern.test(desired))
|
|
208
|
+
return false;
|
|
209
|
+
const sequence = (value) => Number(value.replaceAll(".", ""));
|
|
210
|
+
return sequence(desired) === sequence(current) + 1;
|
|
211
|
+
}
|
|
212
|
+
function beforeFor(documents, rows) {
|
|
213
|
+
const previous = rootsFor("process", rows);
|
|
214
|
+
if (previous.length !== documents.length)
|
|
215
|
+
return invalid("Guarded update requires one before document for every exact target.");
|
|
216
|
+
const occurrences = (content) => collectDatasetReferences(content)
|
|
217
|
+
.map(({ table, id, version, path }) => sha256Json({ table, id, version, path }))
|
|
218
|
+
.sort();
|
|
219
|
+
return documents.map(({ root, content }) => {
|
|
220
|
+
const selected = previous.find((item) => item.root.id === root.id && item.root.version === root.version);
|
|
221
|
+
if (!selected || sha256Json(occurrences(selected.content)) !== sha256Json(occurrences(content)))
|
|
222
|
+
return invalid("Before and desired draft references must select the same exact dependencies.");
|
|
223
|
+
return selected;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
export function isEdgeSupportPlan(value) {
|
|
227
|
+
if (!value || typeof value !== "object" || !("schema" in value))
|
|
228
|
+
return false;
|
|
229
|
+
return value.schema === schema;
|
|
230
|
+
}
|
|
231
|
+
export function verifyEdgeSupportPlan(plan, approved, target, rows, evidence, update, insertContract) {
|
|
232
|
+
if (!evidence || !plan.reference_evidence)
|
|
233
|
+
return invalid("Edge draft execution requires sealed exact dependency evidence.");
|
|
234
|
+
if (!isFoundryEdgeDraftType(plan.dataset_type))
|
|
235
|
+
return invalid("Edge creation requires a supported dataset scope.");
|
|
236
|
+
const current = buildEdgeSupportPlan(plan.dataset_type, approved, target, rows, evidence, update, insertContract);
|
|
237
|
+
if (sha256Json(current) !== sha256Json(plan))
|
|
238
|
+
return invalid("The sealed Edge draft plan disagrees with the task approval or final rows.");
|
|
239
|
+
const documents = rootsFor(plan.dataset_type, rows);
|
|
240
|
+
const before = update && beforeFor(documents, update.rows);
|
|
241
|
+
return documents.map((item, index) => ({
|
|
242
|
+
...item,
|
|
243
|
+
...(before ? { beforeContent: before[index].content } : {}),
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type EdgeDraftType } from "./foundry-edge-support-plan.ts";
|
|
2
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
3
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
4
|
+
export declare function planFoundryEdgeSupportStage(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, environment: NodeJS.ProcessEnv, type: EdgeDraftType, stage: string, source: readonly string[], verifyDependencies: boolean, receiptFile: string | undefined, selectedInput?: FoundryInputFact): {
|
|
5
|
+
stage: string;
|
|
6
|
+
status: string;
|
|
7
|
+
report: {
|
|
8
|
+
schema: string;
|
|
9
|
+
status: string;
|
|
10
|
+
mode: string;
|
|
11
|
+
dry_run: boolean;
|
|
12
|
+
commit: boolean;
|
|
13
|
+
input_path: string;
|
|
14
|
+
counts: {
|
|
15
|
+
selected: number;
|
|
16
|
+
executed: number;
|
|
17
|
+
failed: number;
|
|
18
|
+
};
|
|
19
|
+
files: {
|
|
20
|
+
summary_json: string;
|
|
21
|
+
progress_jsonl: string;
|
|
22
|
+
report?: string | undefined;
|
|
23
|
+
success_list?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exit_code: number;
|
|
27
|
+
command: string;
|
|
28
|
+
args: never[];
|
|
29
|
+
stderr: string;
|
|
30
|
+
referenceDocuments?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
stage: string;
|
|
33
|
+
status: string;
|
|
34
|
+
report: {
|
|
35
|
+
schema: string;
|
|
36
|
+
status: string;
|
|
37
|
+
input_path: string;
|
|
38
|
+
edge_plan_sha256: string;
|
|
39
|
+
checks: {
|
|
40
|
+
table: string;
|
|
41
|
+
id: string;
|
|
42
|
+
version: string;
|
|
43
|
+
payload_sha256?: string;
|
|
44
|
+
expected_state_code?: number;
|
|
45
|
+
expected_owner?: string | null;
|
|
46
|
+
reviewed_latest?: import("./foundry-edge-reference-intent.ts").EdgeReferenceSnapshot;
|
|
47
|
+
role: string;
|
|
48
|
+
status: string;
|
|
49
|
+
}[];
|
|
50
|
+
blockers: {
|
|
51
|
+
table: string;
|
|
52
|
+
id: string;
|
|
53
|
+
version: string;
|
|
54
|
+
payload_sha256?: string;
|
|
55
|
+
expected_state_code?: number;
|
|
56
|
+
expected_owner?: string | null;
|
|
57
|
+
reviewed_latest?: import("./foundry-edge-reference-intent.ts").EdgeReferenceSnapshot;
|
|
58
|
+
role: string;
|
|
59
|
+
status: string;
|
|
60
|
+
code: string;
|
|
61
|
+
}[];
|
|
62
|
+
counts: {
|
|
63
|
+
rows: number;
|
|
64
|
+
blockers: number;
|
|
65
|
+
};
|
|
66
|
+
reference_intent?: {
|
|
67
|
+
file: {
|
|
68
|
+
path: string;
|
|
69
|
+
sha256: string;
|
|
70
|
+
bytes: number;
|
|
71
|
+
};
|
|
72
|
+
project_ref: string;
|
|
73
|
+
actor_user_id: string;
|
|
74
|
+
consumers: {
|
|
75
|
+
row_index: number;
|
|
76
|
+
table: string;
|
|
77
|
+
id: string;
|
|
78
|
+
version: string;
|
|
79
|
+
payload_sha256: string;
|
|
80
|
+
}[];
|
|
81
|
+
references: {
|
|
82
|
+
row_index: number;
|
|
83
|
+
path: string;
|
|
84
|
+
selected: import("./foundry-edge-reference-intent.ts").EdgeReferenceSnapshot;
|
|
85
|
+
review: {
|
|
86
|
+
file: FoundryInputFact;
|
|
87
|
+
latest: import("./foundry-edge-reference-intent.ts").EdgeReferenceSnapshot;
|
|
88
|
+
};
|
|
89
|
+
}[];
|
|
90
|
+
review_files: FoundryInputFact[];
|
|
91
|
+
} | undefined;
|
|
92
|
+
flow_heads?: ({
|
|
93
|
+
id: string;
|
|
94
|
+
head: null;
|
|
95
|
+
} | {
|
|
96
|
+
id: string;
|
|
97
|
+
head: {
|
|
98
|
+
table: string;
|
|
99
|
+
id: string;
|
|
100
|
+
version: string;
|
|
101
|
+
user_id: string;
|
|
102
|
+
state_code: number;
|
|
103
|
+
payload_sha256: string;
|
|
104
|
+
};
|
|
105
|
+
})[] | undefined;
|
|
106
|
+
files: {
|
|
107
|
+
report: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
exit_code: number;
|
|
111
|
+
referenceDocuments: unknown[];
|
|
112
|
+
command: string;
|
|
113
|
+
args: never[];
|
|
114
|
+
stderr: string;
|
|
115
|
+
};
|