@tiangong-lca/foundry 0.1.16 → 0.1.18
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 +19 -5
- package/docs/foundry-task-contracts.md +27 -3
- package/docs/package-distribution-contract.md +47 -15
- package/docs/public-runtime-contract.md +77 -5
- package/docs/runtime-context-contract.md +21 -5
- package/docs/task-authorization-contract.md +15 -3
- package/docs/workspace-migration-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +351 -137
- package/package-dist/scripts/foundry-facade.d.ts +5 -0
- package/package-dist/scripts/foundry-facade.js +258 -16
- package/package-dist/scripts/foundry-runtime.d.ts +1 -1
- 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 +16 -6
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +2 -1
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +28 -1
- 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-command-metadata.js +6 -1
- 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-execution-admission.js +4 -1
- package/package-dist/scripts/lib/foundry-finalize-owners.js +64 -17
- 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-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 +22 -0
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +213 -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-runtime-identity.js +3 -1
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- 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-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 +149 -18
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +17 -4
- 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 +37 -8
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +37 -0
- 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 +676 -0
- package/package-dist/scripts/lib/foundry-workflow-identity.js +10 -1
- package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-io.js +79 -13
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +27 -13
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-state.js +175 -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 +5 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +73 -1
- 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 +6 -1
- package/package-dist/scripts/lib/import-curation/curation-gate.js +48 -2
- 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/lib/tidas-adapter.js +38 -15
- package/package-dist/scripts/lib/tidas-process-flow-context.d.ts +12 -0
- package/package-dist/scripts/lib/tidas-process-flow-context.js +96 -0
- 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,123 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { captureFoundryInput } from "./foundry-runtime-context.js";
|
|
4
|
+
import { sha256Json as cleanupProofSha256 } from "./import-curation/internal/hash-utils.js";
|
|
5
|
+
import { canonicalPayloadSha256 } from "./post-write-root-proof.js";
|
|
6
|
+
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
7
|
+
import { datasetIdentity, unwrapDatasetPayload, } from "./import-curation/internal/dataset-payload.js";
|
|
8
|
+
function object(value) {
|
|
9
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
10
|
+
}
|
|
11
|
+
function same(a, b) {
|
|
12
|
+
return canonicalPayloadSha256(a) === canonicalPayloadSha256(b);
|
|
13
|
+
}
|
|
14
|
+
/** Verify the existing cleanup producer's explicit validation-context proof. Never transform rows. */
|
|
15
|
+
export function unchangedQualityReviewRows(input) {
|
|
16
|
+
const rows = readRows(input.finalRowsFile);
|
|
17
|
+
if (same(rows, input.originalRows))
|
|
18
|
+
return true;
|
|
19
|
+
if (typeof input.cleanupReport !== "string" ||
|
|
20
|
+
!input.referenceFiles.length ||
|
|
21
|
+
rows.length !== input.originalRows.length)
|
|
22
|
+
return false;
|
|
23
|
+
const reportFile = path.resolve(input.assetRoot, input.cleanupReport);
|
|
24
|
+
if (!fs.realpathSync(reportFile).startsWith(`${fs.realpathSync(input.taskRoot)}${path.sep}`))
|
|
25
|
+
return false;
|
|
26
|
+
const report = object(JSON.parse(fs.readFileSync(reportFile, "utf8")));
|
|
27
|
+
const proof = object(report?.process_validation_references);
|
|
28
|
+
if (report?.command !== "dataset-curation-cleanup" ||
|
|
29
|
+
report.status !== "completed" ||
|
|
30
|
+
report.dataset_type !== "process" ||
|
|
31
|
+
report.remote_write_mode !== "read-only" ||
|
|
32
|
+
typeof report.rows_file !== "string" ||
|
|
33
|
+
typeof report.cleaned_rows_file !== "string" ||
|
|
34
|
+
path.resolve(input.assetRoot, report.cleaned_rows_file) !== input.finalRowsFile ||
|
|
35
|
+
!proof ||
|
|
36
|
+
!Array.isArray(proof.files) ||
|
|
37
|
+
!Array.isArray(proof.rows) ||
|
|
38
|
+
proof.rows.length !== rows.length)
|
|
39
|
+
return false;
|
|
40
|
+
const sourceFile = path.resolve(input.assetRoot, report.rows_file);
|
|
41
|
+
if (!same(readRows(sourceFile), input.originalRows))
|
|
42
|
+
return false;
|
|
43
|
+
if (proof.files.length !== input.referenceFiles.length)
|
|
44
|
+
return false;
|
|
45
|
+
const documents = new Map();
|
|
46
|
+
const documentKey = (value) => {
|
|
47
|
+
const identity = datasetIdentity(value, 0, "flow");
|
|
48
|
+
return JSON.stringify([identity.id, identity.version]);
|
|
49
|
+
};
|
|
50
|
+
for (const [index, original] of input.referenceFiles.entries()) {
|
|
51
|
+
const recorded = object(proof.files[index]);
|
|
52
|
+
if (!recorded ||
|
|
53
|
+
typeof recorded.path !== "string" ||
|
|
54
|
+
recorded.bytes !== original.bytes ||
|
|
55
|
+
recorded.sha256 !== original.sha256 ||
|
|
56
|
+
path.resolve(input.assetRoot, recorded.path) !== original.path)
|
|
57
|
+
return false;
|
|
58
|
+
const observed = captureFoundryInput(original.path);
|
|
59
|
+
if (observed.bytes !== original.bytes || observed.sha256 !== original.sha256)
|
|
60
|
+
return false;
|
|
61
|
+
for (const row of readRows(original.path)) {
|
|
62
|
+
const payload = unwrapDatasetPayload(row, "flow");
|
|
63
|
+
if (object(payload)?.flowDataSet) {
|
|
64
|
+
const key = documentKey(payload), previous = documents.get(key);
|
|
65
|
+
if (previous && !same(previous, payload))
|
|
66
|
+
return false;
|
|
67
|
+
documents.set(key, payload);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return rows.every((row, index) => {
|
|
72
|
+
const before = input.originalRows[index], original = datasetIdentity(before, index, "process"), current = datasetIdentity(row, index, "process");
|
|
73
|
+
if (original.id !== current.id ||
|
|
74
|
+
original.version !== current.version ||
|
|
75
|
+
!same(original.payload, current.payload))
|
|
76
|
+
return false;
|
|
77
|
+
const expectedWrapper = original.payload === before ? { json: original.payload } : { ...object(before) };
|
|
78
|
+
const actualWrapper = { ...object(row) };
|
|
79
|
+
delete expectedWrapper.semantic_context;
|
|
80
|
+
delete actualWrapper.semantic_context;
|
|
81
|
+
if (!same(expectedWrapper, actualWrapper))
|
|
82
|
+
return false;
|
|
83
|
+
const sourceContext = object(object(before)?.semantic_context) ?? {};
|
|
84
|
+
const finalContext = object(object(row)?.semantic_context);
|
|
85
|
+
const flowDocuments = finalContext?.flow_documents;
|
|
86
|
+
if (!finalContext || !Array.isArray(flowDocuments))
|
|
87
|
+
return false;
|
|
88
|
+
const { flow_documents: priorDocuments, ...priorOther } = sourceContext;
|
|
89
|
+
const { flow_documents: _currentDocuments, ...currentOther } = finalContext;
|
|
90
|
+
if (!same(priorOther, currentOther) ||
|
|
91
|
+
(priorDocuments !== undefined && !Array.isArray(priorDocuments)))
|
|
92
|
+
return false;
|
|
93
|
+
const prior = Array.isArray(priorDocuments) ? priorDocuments : [];
|
|
94
|
+
if (flowDocuments.length < prior.length ||
|
|
95
|
+
prior.some((value, i) => !same(value, flowDocuments[i])))
|
|
96
|
+
return false;
|
|
97
|
+
const process = object(object(current.payload)?.processDataSet), exchanges = object(process?.exchanges)?.exchange;
|
|
98
|
+
const refs = (Array.isArray(exchanges) ? exchanges : exchanges ? [exchanges] : []).flatMap((value) => {
|
|
99
|
+
const ref = object(object(value)?.referenceToFlowDataSet);
|
|
100
|
+
return ref ? [JSON.stringify([ref["@refObjectId"], ref["@version"]])] : [];
|
|
101
|
+
});
|
|
102
|
+
const included = new Map();
|
|
103
|
+
for (const document of prior) {
|
|
104
|
+
if (!object(document)?.flowDataSet)
|
|
105
|
+
return false;
|
|
106
|
+
const key = documentKey(document), selected = documents.get(key), earlier = included.get(key);
|
|
107
|
+
if ((selected && !same(selected, document)) || (earlier && !same(earlier, document)))
|
|
108
|
+
return false;
|
|
109
|
+
included.set(key, document);
|
|
110
|
+
}
|
|
111
|
+
const expectedKeys = [...new Set(refs)].filter((key) => documents.has(key) && !included.has(key));
|
|
112
|
+
const added = flowDocuments.slice(prior.length);
|
|
113
|
+
if (added.length !== expectedKeys.length ||
|
|
114
|
+
added.some((document, i) => documentKey(document) !== expectedKeys[i] ||
|
|
115
|
+
!same(document, documents.get(expectedKeys[i]))))
|
|
116
|
+
return false;
|
|
117
|
+
const recorded = object(proof.rows[index]);
|
|
118
|
+
return (recorded?.row_index === index &&
|
|
119
|
+
recorded.input_payload_sha256 === cleanupProofSha256(original.payload) &&
|
|
120
|
+
recorded.output_payload_sha256 === cleanupProofSha256(current.payload) &&
|
|
121
|
+
recorded.flow_documents_sha256 === cleanupProofSha256(flowDocuments));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
+
import { type FoundryQualityReviewInput, type SelectedFoundryQualityReviewInput } from "./foundry-quality-review-input.ts";
|
|
4
|
+
import { currentWorkflowState } from "./foundry-workflow-state.ts";
|
|
5
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
6
|
+
type JsonRecord = Record<string, unknown>;
|
|
7
|
+
/** Read-only scope projection, not a review decision or an approval template with default consent. */
|
|
8
|
+
export declare function foundryQualityReviewScope(context: FoundryRuntimeContext, qualificationSha256: string, entries: readonly ArtifactEntry[], state?: ReturnType<typeof currentWorkflowState>): {
|
|
9
|
+
binding: {
|
|
10
|
+
workspace_id: string;
|
|
11
|
+
task_id: string;
|
|
12
|
+
actor_id: string;
|
|
13
|
+
project_ref: string;
|
|
14
|
+
user_id: string;
|
|
15
|
+
profile_id: string;
|
|
16
|
+
profile_sha256: string;
|
|
17
|
+
input_scope_sha256: string;
|
|
18
|
+
};
|
|
19
|
+
runtime_qualification_sha256: string;
|
|
20
|
+
rows_manifest_sha256: string;
|
|
21
|
+
assessment_sha256: string;
|
|
22
|
+
context_sha256: string;
|
|
23
|
+
reference_inputs_sha256: string | null;
|
|
24
|
+
interaction_context_sha256: string | null;
|
|
25
|
+
qa_report_sha256: string;
|
|
26
|
+
qa_findings_sha256: string;
|
|
27
|
+
expected_previous_sha256: string | null;
|
|
28
|
+
candidates: {
|
|
29
|
+
row_index: number;
|
|
30
|
+
id: string;
|
|
31
|
+
version: string;
|
|
32
|
+
payload_sha256: string;
|
|
33
|
+
code: string;
|
|
34
|
+
finding_sha256: string;
|
|
35
|
+
finding: {
|
|
36
|
+
[x: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
input: FoundryInputFact;
|
|
40
|
+
qa: FoundryInputFact;
|
|
41
|
+
rows_content_sha256: string;
|
|
42
|
+
qa_observation_sha256: string;
|
|
43
|
+
} | null;
|
|
44
|
+
/** Mechanical selection material; an untouched draft is deliberately not an accepted input. */
|
|
45
|
+
export declare function createFoundryQualityReviewTemplate(scope: NonNullable<ReturnType<typeof foundryQualityReviewScope>>): {
|
|
46
|
+
schema: "tiangong-foundry.quality-review-draft.v1";
|
|
47
|
+
binding: {
|
|
48
|
+
workspace_id: string;
|
|
49
|
+
task_id: string;
|
|
50
|
+
actor_id: string;
|
|
51
|
+
project_ref: string;
|
|
52
|
+
user_id: string;
|
|
53
|
+
profile_id: string;
|
|
54
|
+
profile_sha256: string;
|
|
55
|
+
input_scope_sha256: string;
|
|
56
|
+
};
|
|
57
|
+
runtime_qualification_sha256: string;
|
|
58
|
+
rows_manifest_sha256: string;
|
|
59
|
+
assessment_sha256: string;
|
|
60
|
+
context_sha256: string;
|
|
61
|
+
reference_inputs_sha256: string | null;
|
|
62
|
+
interaction_context_sha256: string | null;
|
|
63
|
+
qa_report_sha256: string;
|
|
64
|
+
qa_findings_sha256: string;
|
|
65
|
+
expected_previous_sha256: string | null;
|
|
66
|
+
issued_at_utc: string;
|
|
67
|
+
expires_at_utc: string;
|
|
68
|
+
reviews: {
|
|
69
|
+
row_index: number;
|
|
70
|
+
id: string;
|
|
71
|
+
version: string;
|
|
72
|
+
payload_sha256: string;
|
|
73
|
+
code: string;
|
|
74
|
+
finding_sha256: string;
|
|
75
|
+
disposition: null;
|
|
76
|
+
evidence_ids: string[];
|
|
77
|
+
rationale: string;
|
|
78
|
+
}[];
|
|
79
|
+
evidence: {
|
|
80
|
+
id: string;
|
|
81
|
+
kind: "user-decision" | "source-model";
|
|
82
|
+
file: string;
|
|
83
|
+
}[];
|
|
84
|
+
};
|
|
85
|
+
export declare function recordFoundryQualityReview(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], selected: SelectedFoundryQualityReviewInput): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
86
|
+
export interface FoundryQualityReview {
|
|
87
|
+
readonly receipt_sha256: string;
|
|
88
|
+
readonly expires_at_utc: string;
|
|
89
|
+
readonly spec: FoundryQualityReviewInput;
|
|
90
|
+
readonly rows_content_sha256: string;
|
|
91
|
+
readonly qa_observation_sha256: string;
|
|
92
|
+
readonly qaReferenceRows: readonly string[];
|
|
93
|
+
readonly validate: () => void;
|
|
94
|
+
readonly rowsMatch: (rowsFile: string, cleanupReport?: unknown) => boolean;
|
|
95
|
+
}
|
|
96
|
+
export declare function loadFoundryQualityReview(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[]): FoundryQualityReview | null;
|
|
97
|
+
/** Called by the existing curation owner after fresh QA, including on cleaned final rows. */
|
|
98
|
+
export declare function reviewedFoundryQualityFindings(review: unknown, rowsFile: string, qaReport: JsonRecord, findings: readonly JsonRecord[], cleanupReport?: unknown): {
|
|
99
|
+
row_index: number;
|
|
100
|
+
id: string;
|
|
101
|
+
version: string;
|
|
102
|
+
payload_sha256: string;
|
|
103
|
+
finding_sha256: string;
|
|
104
|
+
code: "process_material_balance_deviation";
|
|
105
|
+
evidence_ids: readonly string[];
|
|
106
|
+
rationale: string;
|
|
107
|
+
finding: JsonRecord;
|
|
108
|
+
receipt_sha256: string;
|
|
109
|
+
}[];
|
|
110
|
+
/** Recheck local review evidence at write admission; this function grants no write capability. */
|
|
111
|
+
export declare function assertFoundryQualityReviewForExecution(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, entries: readonly ArtifactEntry[], finalRowsFile: string): void;
|
|
112
|
+
export {};
|