@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
|
@@ -35,6 +35,7 @@ export interface FoundryTaskJob {
|
|
|
35
35
|
contract: string;
|
|
36
36
|
before: string;
|
|
37
37
|
candidate: string;
|
|
38
|
+
scientific?: string;
|
|
38
39
|
predecessor: Readonly<{
|
|
39
40
|
task_id: string;
|
|
40
41
|
receipt_sha256: string;
|
|
@@ -59,6 +60,7 @@ export interface FoundryTaskOptions {
|
|
|
59
60
|
contract: string;
|
|
60
61
|
before: string;
|
|
61
62
|
candidate: string;
|
|
63
|
+
scientific?: string;
|
|
62
64
|
predecessor: Readonly<{
|
|
63
65
|
task_id: string;
|
|
64
66
|
receipt_sha256: string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
type RecordValue = Record<string, unknown>;
|
|
4
|
+
type PatchDestinations = {
|
|
5
|
+
input: string;
|
|
6
|
+
patch: string;
|
|
7
|
+
output: string;
|
|
8
|
+
directory: string;
|
|
9
|
+
writeJson: (file: string, value: unknown) => void;
|
|
10
|
+
writeText: (file: string, value: string) => void;
|
|
11
|
+
};
|
|
12
|
+
type PatchExecution = {
|
|
13
|
+
readInput: (file: string) => Buffer;
|
|
14
|
+
readResult: (file: string) => Buffer;
|
|
15
|
+
workspace: string;
|
|
16
|
+
run: (argv: string[]) => {
|
|
17
|
+
exit: number;
|
|
18
|
+
report: RecordValue;
|
|
19
|
+
validate: <T>(check: () => T) => T;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function applyFoundryTypedAuthoringPatch(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, options: PatchDestinations & {
|
|
23
|
+
type: string;
|
|
24
|
+
packageDirectory: string;
|
|
25
|
+
}): {
|
|
26
|
+
report: {
|
|
27
|
+
schema_version: number;
|
|
28
|
+
generated_at_utc: string;
|
|
29
|
+
status: string;
|
|
30
|
+
input_path: string;
|
|
31
|
+
patch_path: string;
|
|
32
|
+
out_path: string;
|
|
33
|
+
row_count: number;
|
|
34
|
+
patch_count: number;
|
|
35
|
+
operation_count: number;
|
|
36
|
+
applied_operation_count: number;
|
|
37
|
+
evidence_count: number;
|
|
38
|
+
closed_action_item_count: number;
|
|
39
|
+
blockers: RecordValue[];
|
|
40
|
+
files: {
|
|
41
|
+
report: string;
|
|
42
|
+
patched_rows: string;
|
|
43
|
+
patch_evidence: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exit: number;
|
|
47
|
+
};
|
|
48
|
+
export declare function applyTypedAuthoringPatch(options: PatchDestinations & {
|
|
49
|
+
type?: string;
|
|
50
|
+
packageDirectory?: string;
|
|
51
|
+
requirePackage: boolean;
|
|
52
|
+
requireClosure: boolean;
|
|
53
|
+
}, execution: PatchExecution): {
|
|
54
|
+
report: {
|
|
55
|
+
schema_version: number;
|
|
56
|
+
generated_at_utc: string;
|
|
57
|
+
status: string;
|
|
58
|
+
input_path: string;
|
|
59
|
+
patch_path: string;
|
|
60
|
+
out_path: string;
|
|
61
|
+
row_count: number;
|
|
62
|
+
patch_count: number;
|
|
63
|
+
operation_count: number;
|
|
64
|
+
applied_operation_count: number;
|
|
65
|
+
evidence_count: number;
|
|
66
|
+
closed_action_item_count: number;
|
|
67
|
+
blockers: RecordValue[];
|
|
68
|
+
files: {
|
|
69
|
+
report: string;
|
|
70
|
+
patched_rows: string;
|
|
71
|
+
patch_evidence: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exit: number;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readFoundryInput } from "./foundry-runtime-context.js";
|
|
4
|
+
import { datasetIdentity, detectDatasetType } from "./import-curation/internal/dataset-payload.js";
|
|
5
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
6
|
+
import { operationHasEvidence, patchPayloadPatchSets, patchSetAuthoringPackage, patchSetDatasetId, patchSetOperations, } from "./import-curation/internal/workflow-authoring-tasks.js";
|
|
7
|
+
import { operationClosureKeys, taskActionItemKeys, } from "./import-curation/internal/workflow-patch-evidence.js";
|
|
8
|
+
import { assertWorkflowReportArtifact, runWorkflowLocalCliResult } from "./foundry-workflow-io.js";
|
|
9
|
+
import { workflowObject } from "./foundry-workflow-state.js";
|
|
10
|
+
import { sha256Text } from "./identity-preflight-proof.js";
|
|
11
|
+
export function applyFoundryTypedAuthoringPatch(context, qualified, temporary, options) {
|
|
12
|
+
return applyTypedAuthoringPatch({ ...options, requirePackage: true, requireClosure: true }, {
|
|
13
|
+
readInput: (file) => readFoundryInput(context, file),
|
|
14
|
+
readResult: (file) => fs.readFileSync(assertWorkflowReportArtifact(context, file, options.directory)),
|
|
15
|
+
workspace: options.directory,
|
|
16
|
+
run: (argv) => runWorkflowLocalCliResult(context, qualified, temporary, argv),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function applyTypedAuthoringPatch(options, execution) {
|
|
20
|
+
const rows = readRows(options.input, (file) => execution.readInput(file).toString("utf8"));
|
|
21
|
+
const patches = patchPayloadPatchSets(JSON.parse(fs.readFileSync(options.patch, "utf8")));
|
|
22
|
+
const candidates = [...rows];
|
|
23
|
+
const blockers = [];
|
|
24
|
+
const evidence = [];
|
|
25
|
+
let operationCount = 0;
|
|
26
|
+
if (!patches.length)
|
|
27
|
+
blockers.push({
|
|
28
|
+
code: "patch_payload_invalid",
|
|
29
|
+
message: "At least one dataset patch set is required.",
|
|
30
|
+
});
|
|
31
|
+
for (const [patchIndex, raw] of patches.entries()) {
|
|
32
|
+
const patch = workflowObject(raw);
|
|
33
|
+
const packageName = patchSetAuthoringPackage(patch);
|
|
34
|
+
const declaredId = patchSetDatasetId(patch);
|
|
35
|
+
const declaredVersion = patch.dataset_version ?? patch.version;
|
|
36
|
+
const declaredIndex = patch.row_index ?? patch.rowIndex;
|
|
37
|
+
if ((!packageName || !options.packageDirectory) &&
|
|
38
|
+
(options.requirePackage || options.requireClosure)) {
|
|
39
|
+
blockers.push({ code: "authoring_package_required", patch_index: patchIndex });
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const packageBytes = packageName && options.packageDirectory
|
|
43
|
+
? execution.readInput(path.join(options.packageDirectory, path.basename(packageName)))
|
|
44
|
+
: null;
|
|
45
|
+
const authoring = packageBytes
|
|
46
|
+
? workflowObject(JSON.parse(packageBytes.toString("utf8")))
|
|
47
|
+
: null;
|
|
48
|
+
const packageId = authoring?.entity_id ?? authoring?.process_id;
|
|
49
|
+
const packageVersion = authoring?.version;
|
|
50
|
+
const matches = rows.flatMap((row, index) => {
|
|
51
|
+
const type = options.type ?? detectDatasetType(row);
|
|
52
|
+
if (!type)
|
|
53
|
+
return [];
|
|
54
|
+
const identity = datasetIdentity(row, index, type);
|
|
55
|
+
const expectedIndex = authoring ||
|
|
56
|
+
declaredIndex === undefined ||
|
|
57
|
+
(/^\d+$/u.test(String(declaredIndex)) && Number(declaredIndex) === index);
|
|
58
|
+
const expectedId = !declaredId || identity.id === declaredId;
|
|
59
|
+
const expectedVersion = declaredVersion === undefined || identity.version === declaredVersion;
|
|
60
|
+
const expectedPackage = !authoring || (identity.id === packageId && identity.version === packageVersion);
|
|
61
|
+
return expectedIndex && expectedId && expectedVersion && expectedPackage
|
|
62
|
+
? [{ index, identity, type }]
|
|
63
|
+
: [];
|
|
64
|
+
});
|
|
65
|
+
const selected = matches[0];
|
|
66
|
+
const reject = (code, message) => blockers.push({
|
|
67
|
+
code,
|
|
68
|
+
message,
|
|
69
|
+
patch_index: patchIndex,
|
|
70
|
+
row_index: selected?.index,
|
|
71
|
+
dataset_id: selected?.identity.id ?? declaredId,
|
|
72
|
+
dataset_version: selected?.identity.version ?? declaredVersion,
|
|
73
|
+
});
|
|
74
|
+
const contradictoryIndex = authoring &&
|
|
75
|
+
declaredIndex !== undefined &&
|
|
76
|
+
(!/^\d+$/u.test(String(declaredIndex)) || Number(declaredIndex) !== selected?.index);
|
|
77
|
+
if (matches.length !== 1 ||
|
|
78
|
+
contradictoryIndex ||
|
|
79
|
+
(!authoring && !declaredId && declaredIndex === undefined)) {
|
|
80
|
+
reject("authoring_patch_scope_mismatch", "Select one exact dataset row and its required authoring package.");
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const { index: rowIndex, identity: { id, version }, type, } = selected;
|
|
84
|
+
const operationName = `dataset ${type === "lifecyclemodel" ? "model" : type} patch`;
|
|
85
|
+
const rawOperations = patchSetOperations(patch);
|
|
86
|
+
if (!rawOperations?.length) {
|
|
87
|
+
reject("patch_operations_missing", "Authoring patch must contain an operation.");
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
operationCount += rawOperations.length;
|
|
91
|
+
const required = taskActionItemKeys({
|
|
92
|
+
...authoring,
|
|
93
|
+
action_items: Array.isArray(authoring?.action_items)
|
|
94
|
+
? authoring.action_items.filter((value) => {
|
|
95
|
+
const item = workflowObject(value);
|
|
96
|
+
return (item.ai_required !== false &&
|
|
97
|
+
![
|
|
98
|
+
"identity_decision_authoring",
|
|
99
|
+
"classification_decision_authoring",
|
|
100
|
+
"location_decision_authoring",
|
|
101
|
+
].includes(String(item.action_kind ?? item.actionKind)));
|
|
102
|
+
})
|
|
103
|
+
: [],
|
|
104
|
+
});
|
|
105
|
+
const closed = rawOperations.flatMap((item) => item.op === "test" ? [] : operationClosureKeys(item));
|
|
106
|
+
const matchesClosure = (left, right) => {
|
|
107
|
+
const [leftCode, leftPath] = left.split("\u0000");
|
|
108
|
+
const [rightCode, rightPath] = right.split("\u0000");
|
|
109
|
+
return leftCode === rightCode && (!leftPath || !rightPath || leftPath === rightPath);
|
|
110
|
+
};
|
|
111
|
+
if (options.requireClosure &&
|
|
112
|
+
(closed.some((closure) => !required.some((item) => matchesClosure(closure, item))) ||
|
|
113
|
+
required.some((item) => !closed.some((closure) => matchesClosure(closure, item))))) {
|
|
114
|
+
reject("authoring_action_item_closure_invalid", "Patch closure must match the selected authoring package.");
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (rawOperations.some((item) => item.op !== "test" && !operationHasEvidence(item))) {
|
|
118
|
+
reject("patch_evidence_required", "Each mutation needs its source evidence or basis.");
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const row = workflowObject(candidates[rowIndex]);
|
|
122
|
+
const original = datasetIdentity(row, rowIndex, type);
|
|
123
|
+
const wrapper = original.payload === row
|
|
124
|
+
? null
|
|
125
|
+
: Object.keys(row).find((name) => row[name] === original.payload);
|
|
126
|
+
const prefix = wrapper ? `/${wrapper}` : "";
|
|
127
|
+
const operations = rawOperations.map((item) => {
|
|
128
|
+
const operation = workflowObject(item);
|
|
129
|
+
const location = typeof operation.path === "string" ? operation.path : "";
|
|
130
|
+
return {
|
|
131
|
+
op: operation.op,
|
|
132
|
+
path: location.startsWith(prefix + "/") ? location.slice(prefix.length) : null,
|
|
133
|
+
...(Object.hasOwn(operation, "value") ? { value: operation.value } : {}),
|
|
134
|
+
...(operation.op === "test"
|
|
135
|
+
? {}
|
|
136
|
+
: {
|
|
137
|
+
basis: typeof operation.basis === "string" && operation.basis.trim()
|
|
138
|
+
? operation.basis
|
|
139
|
+
: "Source evidence retained in the selected Foundry authoring patch.",
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
if (operations.some((operation) => operation.path === null)) {
|
|
144
|
+
reject("patch_path_invalid", "Authoring patch pointer must select a field inside the dataset payload.");
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const input = path.join(execution.workspace, `request-${patchIndex + 1}.json`);
|
|
148
|
+
const output = path.join(execution.workspace, `result-${patchIndex + 1}.json`);
|
|
149
|
+
options.writeJson(input, {
|
|
150
|
+
content: original.payload,
|
|
151
|
+
expectedDigest: sha256Text(JSON.stringify(original.payload)),
|
|
152
|
+
operations,
|
|
153
|
+
});
|
|
154
|
+
const result = execution.run([
|
|
155
|
+
...operationName.split(" "),
|
|
156
|
+
"--input",
|
|
157
|
+
input,
|
|
158
|
+
"--output",
|
|
159
|
+
output,
|
|
160
|
+
"--json",
|
|
161
|
+
]);
|
|
162
|
+
if (result.exit !== 0) {
|
|
163
|
+
const error = workflowObject(result.report.error);
|
|
164
|
+
reject(String(error.code), String(error.message));
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const content = result.validate(() => {
|
|
168
|
+
const bytes = execution.readResult(output);
|
|
169
|
+
const payload = workflowObject(JSON.parse(bytes.toString("utf8")));
|
|
170
|
+
const identity = datasetIdentity(payload, rowIndex, type);
|
|
171
|
+
const artifact = Array.isArray(result.report.artifacts)
|
|
172
|
+
? workflowObject(result.report.artifacts[0])
|
|
173
|
+
: {};
|
|
174
|
+
if (result.report.schemaVersion !== 1 ||
|
|
175
|
+
result.report.operation !== operationName ||
|
|
176
|
+
result.report.status !== "completed" ||
|
|
177
|
+
result.report.outcome !== "content_processed" ||
|
|
178
|
+
result.report.error !== null ||
|
|
179
|
+
artifact.path !== output ||
|
|
180
|
+
artifact.purpose !== "complete_result" ||
|
|
181
|
+
artifact.bytes !== bytes.length ||
|
|
182
|
+
workflowObject(result.report.data).contentDigest !== sha256Text(JSON.stringify(payload)) ||
|
|
183
|
+
identity.id !== id ||
|
|
184
|
+
identity.version !== version)
|
|
185
|
+
throw new Error("Typed patch receipt does not bind the exact output and selected row.");
|
|
186
|
+
return payload;
|
|
187
|
+
});
|
|
188
|
+
candidates[rowIndex] = wrapper ? { ...row, [wrapper]: content } : content;
|
|
189
|
+
rawOperations.forEach((item, operationIndex) => {
|
|
190
|
+
if (item.op === "test")
|
|
191
|
+
return;
|
|
192
|
+
evidence.push({
|
|
193
|
+
row_index: rowIndex,
|
|
194
|
+
dataset_id: id,
|
|
195
|
+
dataset_version: version,
|
|
196
|
+
patch_index: patchIndex,
|
|
197
|
+
operation_index: operationIndex,
|
|
198
|
+
op: item.op,
|
|
199
|
+
path: item.path,
|
|
200
|
+
basis: item.basis ?? null,
|
|
201
|
+
evidence: item.evidence ?? null,
|
|
202
|
+
resolution: item.resolution ?? null,
|
|
203
|
+
authoring_package: packageName || null,
|
|
204
|
+
authoring_package_sha256: packageBytes ? sha256Text(packageBytes.toString("utf8")) : null,
|
|
205
|
+
closes_action_items: operationClosureKeys(item).map((key) => {
|
|
206
|
+
const [code, itemPath] = key.split("\u0000");
|
|
207
|
+
return { code, path: itemPath || null };
|
|
208
|
+
}),
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const accepted = !blockers.length;
|
|
213
|
+
const reportFile = path.join(options.directory, "outputs", "dataset-patch-apply-report.json");
|
|
214
|
+
const evidenceFile = path.join(options.directory, "outputs", "patch-evidence.jsonl");
|
|
215
|
+
options.writeText(options.output, (accepted ? candidates : rows).map((row) => JSON.stringify(row) + "\n").join(""));
|
|
216
|
+
options.writeText(evidenceFile, accepted ? evidence.map((row) => JSON.stringify(row) + "\n").join("") : "");
|
|
217
|
+
const report = {
|
|
218
|
+
schema_version: 1,
|
|
219
|
+
generated_at_utc: new Date().toISOString(),
|
|
220
|
+
status: accepted ? "completed" : "blocked",
|
|
221
|
+
input_path: options.input,
|
|
222
|
+
patch_path: options.patch,
|
|
223
|
+
out_path: options.output,
|
|
224
|
+
row_count: rows.length,
|
|
225
|
+
patch_count: patches.length,
|
|
226
|
+
operation_count: operationCount,
|
|
227
|
+
applied_operation_count: accepted ? evidence.length : 0,
|
|
228
|
+
evidence_count: accepted ? evidence.length : 0,
|
|
229
|
+
closed_action_item_count: accepted
|
|
230
|
+
? evidence.reduce((sum, row) => sum + row.closes_action_items.length, 0)
|
|
231
|
+
: 0,
|
|
232
|
+
blockers,
|
|
233
|
+
files: { report: reportFile, patched_rows: options.output, patch_evidence: evidenceFile },
|
|
234
|
+
};
|
|
235
|
+
options.writeJson(reportFile, report);
|
|
236
|
+
return { report, exit: accepted ? 0 : 1 };
|
|
237
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function createTypedContextCommand(type: string, output: string): string[];
|
|
2
|
+
export declare function projectTypedContext(type: string, output: string, receipt: unknown, bytes: Buffer): {
|
|
3
|
+
source: unknown;
|
|
4
|
+
manifest: Record<string, unknown>;
|
|
5
|
+
profile: string;
|
|
6
|
+
files: {
|
|
7
|
+
key: "methodology" | "ruleset" | "schema";
|
|
8
|
+
name: "methodology.yaml" | "runtime-ruleset.json" | "schema.json";
|
|
9
|
+
text: string;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
3
|
+
const components = [
|
|
4
|
+
{ key: "schema", name: "schema.json" },
|
|
5
|
+
{ key: "methodology", name: "methodology.yaml" },
|
|
6
|
+
{ key: "ruleset", name: "runtime-ruleset.json" },
|
|
7
|
+
];
|
|
8
|
+
function cliType(type) {
|
|
9
|
+
return type === "lifecyclemodel" ? "model" : type;
|
|
10
|
+
}
|
|
11
|
+
export function createTypedContextCommand(type, output) {
|
|
12
|
+
return [
|
|
13
|
+
"dataset",
|
|
14
|
+
cliType(type),
|
|
15
|
+
"contract",
|
|
16
|
+
"--include",
|
|
17
|
+
components.map(({ key }) => key).join(","),
|
|
18
|
+
"--output",
|
|
19
|
+
output,
|
|
20
|
+
"--json",
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
function record(value) {
|
|
24
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
25
|
+
? value
|
|
26
|
+
: {};
|
|
27
|
+
}
|
|
28
|
+
function reject(message) {
|
|
29
|
+
throw new FoundryContextError("workflow_context_invalid", message);
|
|
30
|
+
}
|
|
31
|
+
export function projectTypedContext(type, output, receipt, bytes) {
|
|
32
|
+
const result = record(receipt);
|
|
33
|
+
const artifact = Array.isArray(result.artifacts) ? record(result.artifacts[0]) : {};
|
|
34
|
+
if (result.schemaVersion !== 1 ||
|
|
35
|
+
result.operation !== `dataset ${cliType(type)} contract` ||
|
|
36
|
+
result.status !== "completed" ||
|
|
37
|
+
result.outcome !== "contract_read" ||
|
|
38
|
+
artifact.path !== output ||
|
|
39
|
+
artifact.purpose !== "complete_result" ||
|
|
40
|
+
artifact.bytes !== bytes.length)
|
|
41
|
+
return reject("Invalid typed CLI contract receipt for the current task scope.");
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(bytes.toString("utf8"));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return reject("Typed CLI contract output must be valid JSON.");
|
|
48
|
+
}
|
|
49
|
+
const contract = record(parsed);
|
|
50
|
+
const manifest = record(contract.manifest);
|
|
51
|
+
if (!["sdk-contract-api", "sdk-runtime-assets"].includes(String(contract.source)) ||
|
|
52
|
+
manifest.kind !== type ||
|
|
53
|
+
typeof manifest.profile !== "string" ||
|
|
54
|
+
!Array.isArray(contract.unavailable))
|
|
55
|
+
return reject("Typed CLI contract manifest does not match the task dataset type.");
|
|
56
|
+
const payload = record(contract.components);
|
|
57
|
+
const files = [];
|
|
58
|
+
for (const { key, name } of components) {
|
|
59
|
+
const value = payload[key];
|
|
60
|
+
const fact = record(manifest[key]);
|
|
61
|
+
if (value === null &&
|
|
62
|
+
manifest[key] === null &&
|
|
63
|
+
contract.unavailable.includes(key) &&
|
|
64
|
+
key !== "schema" &&
|
|
65
|
+
type !== "flow" &&
|
|
66
|
+
type !== "process")
|
|
67
|
+
continue;
|
|
68
|
+
const text = key === "ruleset" && value && typeof value === "object" && !Array.isArray(value)
|
|
69
|
+
? JSON.stringify(value, null, 2)
|
|
70
|
+
: value;
|
|
71
|
+
if (typeof text !== "string" || !text.length || contract.unavailable.includes(key))
|
|
72
|
+
return reject(`Typed CLI contract is missing ${key} for ${type}.`);
|
|
73
|
+
if (Buffer.byteLength(text) !== fact.bytes ||
|
|
74
|
+
createHash("sha256").update(text).digest("hex") !== fact.sha256)
|
|
75
|
+
return reject(`Typed CLI contract ${key} digest does not match its manifest.`);
|
|
76
|
+
files.push({ key, name, text });
|
|
77
|
+
}
|
|
78
|
+
return { source: contract.source, manifest, profile: manifest.profile, files };
|
|
79
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
type RowIdentity = {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
payload: unknown;
|
|
7
|
+
};
|
|
8
|
+
type ValidationType = "flow" | "process" | "lifecyclemodel";
|
|
9
|
+
export declare function projectFlowValidation(row: RowIdentity, output: string, exit: number, receipt: unknown, bytes: Buffer): {
|
|
10
|
+
entity_id: string;
|
|
11
|
+
version: string;
|
|
12
|
+
severity: string;
|
|
13
|
+
code: string;
|
|
14
|
+
path: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}[];
|
|
17
|
+
type ValidationOptions = {
|
|
18
|
+
referenceFiles?: readonly string[];
|
|
19
|
+
validationInput?: string;
|
|
20
|
+
readRowsFile?: (file: string) => string;
|
|
21
|
+
};
|
|
22
|
+
type ValidationIo = {
|
|
23
|
+
writeJson: (file: string, value: unknown) => void;
|
|
24
|
+
readRowsFile: (file: string) => string;
|
|
25
|
+
readResult: (file: string) => Buffer;
|
|
26
|
+
run: (argv: string[]) => {
|
|
27
|
+
exit: number;
|
|
28
|
+
report: Record<string, unknown>;
|
|
29
|
+
validate: <T>(check: () => T) => T;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function runFoundryTypedDatasetQa(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, temporary: string, writeJson: ValidationIo["writeJson"], type: ValidationType, rowsFile: string, output: string, options?: ValidationOptions): {
|
|
33
|
+
reportFile: string;
|
|
34
|
+
report: {
|
|
35
|
+
schema: string;
|
|
36
|
+
status: string;
|
|
37
|
+
rows_file: string;
|
|
38
|
+
validation_input: string;
|
|
39
|
+
validation_operation: string;
|
|
40
|
+
validations: {
|
|
41
|
+
id: string;
|
|
42
|
+
version: string;
|
|
43
|
+
result: string;
|
|
44
|
+
reference_documents: string | null;
|
|
45
|
+
complete_sha256: string;
|
|
46
|
+
}[];
|
|
47
|
+
rows: {
|
|
48
|
+
findings: {
|
|
49
|
+
entity_id: string;
|
|
50
|
+
version: string;
|
|
51
|
+
severity: string;
|
|
52
|
+
code: string;
|
|
53
|
+
path: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}[];
|
|
56
|
+
}[];
|
|
57
|
+
findings: {
|
|
58
|
+
entity_id: string;
|
|
59
|
+
version: string;
|
|
60
|
+
severity: string;
|
|
61
|
+
code: string;
|
|
62
|
+
path: string;
|
|
63
|
+
message: string;
|
|
64
|
+
}[];
|
|
65
|
+
files: {
|
|
66
|
+
report: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exit: number;
|
|
70
|
+
validationReportFile: string;
|
|
71
|
+
} | {
|
|
72
|
+
reportFile: string;
|
|
73
|
+
report: {
|
|
74
|
+
status: string;
|
|
75
|
+
policy_decision_owner: string;
|
|
76
|
+
qa_mode: string;
|
|
77
|
+
mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
|
|
78
|
+
findings: {
|
|
79
|
+
process_file: string;
|
|
80
|
+
severity: "info" | "warning" | "blocker";
|
|
81
|
+
code: string;
|
|
82
|
+
methodology_rule_id: string | null;
|
|
83
|
+
message: string;
|
|
84
|
+
source: "rule";
|
|
85
|
+
evidence?: {
|
|
86
|
+
[x: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
}[];
|
|
89
|
+
schema: string;
|
|
90
|
+
rows_file: string;
|
|
91
|
+
reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
92
|
+
files: {
|
|
93
|
+
report: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
exit: number;
|
|
97
|
+
validationReportFile: string;
|
|
98
|
+
};
|
|
99
|
+
export declare function runTypedDatasetQa(type: ValidationType, rowsFile: string, directory: string, options: ValidationOptions, { writeJson, readRowsFile, readResult, run }: ValidationIo): {
|
|
100
|
+
reportFile: string;
|
|
101
|
+
report: {
|
|
102
|
+
schema: string;
|
|
103
|
+
status: string;
|
|
104
|
+
rows_file: string;
|
|
105
|
+
validation_input: string;
|
|
106
|
+
validation_operation: string;
|
|
107
|
+
validations: {
|
|
108
|
+
id: string;
|
|
109
|
+
version: string;
|
|
110
|
+
result: string;
|
|
111
|
+
reference_documents: string | null;
|
|
112
|
+
complete_sha256: string;
|
|
113
|
+
}[];
|
|
114
|
+
rows: {
|
|
115
|
+
findings: {
|
|
116
|
+
entity_id: string;
|
|
117
|
+
version: string;
|
|
118
|
+
severity: string;
|
|
119
|
+
code: string;
|
|
120
|
+
path: string;
|
|
121
|
+
message: string;
|
|
122
|
+
}[];
|
|
123
|
+
}[];
|
|
124
|
+
findings: {
|
|
125
|
+
entity_id: string;
|
|
126
|
+
version: string;
|
|
127
|
+
severity: string;
|
|
128
|
+
code: string;
|
|
129
|
+
path: string;
|
|
130
|
+
message: string;
|
|
131
|
+
}[];
|
|
132
|
+
files: {
|
|
133
|
+
report: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
exit: number;
|
|
137
|
+
validationReportFile: string;
|
|
138
|
+
} | {
|
|
139
|
+
reportFile: string;
|
|
140
|
+
report: {
|
|
141
|
+
status: string;
|
|
142
|
+
policy_decision_owner: string;
|
|
143
|
+
qa_mode: string;
|
|
144
|
+
mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
|
|
145
|
+
findings: {
|
|
146
|
+
process_file: string;
|
|
147
|
+
severity: "info" | "warning" | "blocker";
|
|
148
|
+
code: string;
|
|
149
|
+
methodology_rule_id: string | null;
|
|
150
|
+
message: string;
|
|
151
|
+
source: "rule";
|
|
152
|
+
evidence?: {
|
|
153
|
+
[x: string]: unknown;
|
|
154
|
+
};
|
|
155
|
+
}[];
|
|
156
|
+
schema: string;
|
|
157
|
+
rows_file: string;
|
|
158
|
+
reference_evidence: import("./foundry-runtime-context-types.ts").FoundryInputFact[];
|
|
159
|
+
files: {
|
|
160
|
+
report: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
exit: number;
|
|
164
|
+
validationReportFile: string;
|
|
165
|
+
};
|
|
166
|
+
export {};
|