@tiangong-lca/foundry 0.1.10 → 0.1.12
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 +6 -6
- package/docs/architecture.md +6 -6
- package/docs/foundry-task-contracts.md +11 -3
- package/docs/package-distribution-contract.md +6 -4
- package/docs/public-runtime-contract.md +21 -5
- package/docs/runtime-context-contract.md +7 -3
- package/docs/task-authorization-contract.md +5 -3
- package/package-dist/assets/foundry-package-descriptor.json +120 -64
- package/package-dist/scripts/foundry-facade.d.ts +1 -0
- package/package-dist/scripts/foundry-facade.js +261 -36
- package/package-dist/scripts/foundry-runtime.d.ts +2 -1
- package/package-dist/scripts/foundry-runtime.js +2 -2
- package/package-dist/scripts/lib/foundry-interaction-input.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-interaction-input.js +327 -0
- package/package-dist/scripts/lib/foundry-interaction-projection.d.ts +22 -0
- package/package-dist/scripts/lib/foundry-interaction-projection.js +81 -0
- package/package-dist/scripts/lib/foundry-interaction-types.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-interaction-types.js +4 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -2
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +3 -3
- package/package-dist/scripts/lib/foundry-package-contract.js +3 -1
- package/package-dist/scripts/lib/foundry-semantic-input.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +29 -2
- package/package-dist/scripts/lib/foundry-semantic-interaction.d.ts +12 -0
- package/package-dist/scripts/lib/foundry-semantic-interaction.js +38 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-task-start-spec.js +36 -0
- package/package-dist/scripts/lib/foundry-task-store.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +7 -1
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +301 -8
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +7 -4
- package/package-dist/scripts/lib/foundry-workflow-interaction.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-workflow-interaction.js +63 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +21 -1
- package/package-dist/scripts/lib/foundry-workflow-state.d.ts +9 -1
- package/package-dist/scripts/lib/foundry-workflow-state.js +173 -21
- package/package-dist/scripts/public-api.d.ts +2 -0
- package/package-dist/scripts/public-api.js +1 -0
- package/package-dist/scripts/runtime-entry.js +9 -1
- package/package.json +2 -1
- package/specs/schemas/foundry-interaction-input.schema.json +173 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +2 -1
- package/specs/schemas/foundry-semantic-input.schema.json +12 -1
- package/specs/schemas/foundry-task-start.schema.json +75 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { FoundryContextError, readFoundryInput, } from "./foundry-runtime-context.js";
|
|
3
|
+
import { runFoundryTaskOperation } from "./foundry-task-store.js";
|
|
4
|
+
import { advanceFoundryInteractionState, assertSelectedFoundryInteractionInput, currentFoundryInteractionState, FOUNDRY_INTERACTION_COMMAND, FOUNDRY_INTERACTION_REPORT, readSelectedFoundryInteractionBytes, } from "./foundry-interaction-input.js";
|
|
5
|
+
import { readWorkflowArtifact } from "./foundry-workflow-state.js";
|
|
6
|
+
import { createWorkflowStageDirectory } from "./foundry-workflow-io.js";
|
|
7
|
+
const resultName = "interaction-result.json";
|
|
8
|
+
function priorSubmission(context, entries, sha256) {
|
|
9
|
+
for (const entry of [...entries].reverse()) {
|
|
10
|
+
if (entry.command !== FOUNDRY_INTERACTION_COMMAND || path.basename(entry.path) !== resultName)
|
|
11
|
+
continue;
|
|
12
|
+
const report = readWorkflowArtifact(context, entry).value;
|
|
13
|
+
if (report.schema === "tiangong-foundry.interaction-result.v1" &&
|
|
14
|
+
report.descriptor_sha256 === sha256)
|
|
15
|
+
return report;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export async function recordFoundryInteractionInput(context, entries, selected, targetEntities) {
|
|
20
|
+
assertSelectedFoundryInteractionInput(selected);
|
|
21
|
+
const prior = priorSubmission(context, entries, selected.descriptor.sha256);
|
|
22
|
+
if (prior)
|
|
23
|
+
return prior;
|
|
24
|
+
const current = currentFoundryInteractionState(context, entries);
|
|
25
|
+
const currentSha = current?.entry.sha256 ?? null;
|
|
26
|
+
const known = new Set([
|
|
27
|
+
...context.inputs.map((fact) => fact.sha256),
|
|
28
|
+
...entries.map((entry) => entry.sha256),
|
|
29
|
+
]);
|
|
30
|
+
const accepted = advanceFoundryInteractionState(current?.state ?? null, selected.spec, currentSha, known, new Set(targetEntities));
|
|
31
|
+
return runFoundryTaskOperation(context, {
|
|
32
|
+
command: FOUNDRY_INTERACTION_COMMAND,
|
|
33
|
+
options: {
|
|
34
|
+
descriptor: selected.descriptor,
|
|
35
|
+
expected_state_sha256: currentSha,
|
|
36
|
+
},
|
|
37
|
+
validateCurrent(index) {
|
|
38
|
+
if (index.some((entry) => ["dataset-workflow-execution-prepare", "dataset-workflow-execution-consume"].includes(entry.command)))
|
|
39
|
+
throw new FoundryContextError("interaction_after_approval", "Preserve the approved or attempted scope; a changed decision needs a separately reviewed task revision.");
|
|
40
|
+
const present = currentFoundryInteractionState(context, index);
|
|
41
|
+
if ((present?.entry.sha256 ?? null) !== currentSha)
|
|
42
|
+
throw new FoundryContextError("interaction_state_changed", "Interaction state changed before this input acquired the task lock.");
|
|
43
|
+
},
|
|
44
|
+
}, (operation) => {
|
|
45
|
+
assertSelectedFoundryInteractionInput(selected);
|
|
46
|
+
for (const input of context.inputs)
|
|
47
|
+
readFoundryInput(context, input.path);
|
|
48
|
+
const freshBytes = readSelectedFoundryInteractionBytes(selected.descriptor);
|
|
49
|
+
const output = createWorkflowStageDirectory(context, operation, "interaction");
|
|
50
|
+
operation.writeText(path.join(output, "interaction-input.json"), freshBytes);
|
|
51
|
+
operation.writeJson(path.join(output, FOUNDRY_INTERACTION_REPORT), accepted);
|
|
52
|
+
const result = {
|
|
53
|
+
schema: "tiangong-foundry.interaction-result.v1",
|
|
54
|
+
status: "completed",
|
|
55
|
+
task_id: selected.spec.task_id,
|
|
56
|
+
descriptor_sha256: selected.descriptor.sha256,
|
|
57
|
+
previous_state_sha256: currentSha,
|
|
58
|
+
event_count: accepted.events.length,
|
|
59
|
+
};
|
|
60
|
+
operation.writeJson(path.join(output, resultName), result);
|
|
61
|
+
return result;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -10,6 +10,8 @@ import { runDatasetAuthoringPatchCollect } from "./import-curation/patch-collect
|
|
|
10
10
|
import { readJsonOrJsonl, ensureArray, readRows } from "./import-curation/internal/runtime-io.js";
|
|
11
11
|
import { createFoundryDecisionOwners } from "./foundry-decision-owners.js";
|
|
12
12
|
import { applyFoundryIdentityDecisions } from "./foundry-workflow-identity-apply.js";
|
|
13
|
+
import { currentFoundryInteractionState } from "./foundry-interaction-input.js";
|
|
14
|
+
import { verifyFoundrySemanticInteraction } from "./foundry-semantic-interaction.js";
|
|
13
15
|
import { operationFullContextEvidenceBlockers, operationUsedContextKinds, patchPayloadPatchSets, patchSetOperations, taskRequiredContextKinds, } from "./import-curation/internal/workflow-authoring-tasks.js";
|
|
14
16
|
function fail(code, message) {
|
|
15
17
|
throw new FoundryContextError(code, message);
|
|
@@ -33,6 +35,9 @@ function priorApplication(context, entries, submission) {
|
|
|
33
35
|
export async function applyFoundrySemanticInput(context, qualified, entries, submission) {
|
|
34
36
|
assertSelectedSemanticInput(submission);
|
|
35
37
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
38
|
+
const interaction = currentFoundryInteractionState(context, entries);
|
|
39
|
+
if ((submission.spec.interaction_sha256 ?? null) !== (interaction?.entry.sha256 ?? null))
|
|
40
|
+
fail("semantic_interaction_changed", "Submit against the current registered task decisions.");
|
|
36
41
|
const prior = priorApplication(context, entries, submission);
|
|
37
42
|
if (prior)
|
|
38
43
|
return prior;
|
|
@@ -114,17 +119,29 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
114
119
|
fail("task_semantic_owner_conflict", "Submit one decision/patch owner per row set, then reassess before the next owner.");
|
|
115
120
|
rowOwners.add(item.type);
|
|
116
121
|
}
|
|
122
|
+
const selectedScopes = new Map();
|
|
123
|
+
for (const group of work)
|
|
124
|
+
for (const item of group.tasks)
|
|
125
|
+
selectedScopes.set(item.sha, text(group.set.type, "Dataset type"));
|
|
126
|
+
for (const item of decisionWork)
|
|
127
|
+
selectedScopes.set(item.sha, item.type);
|
|
128
|
+
const adoptedDecisions = verifyFoundrySemanticInteraction(submission.spec, interaction ? { sha256: interaction.entry.sha256, state: interaction.state } : null, selectedScopes);
|
|
117
129
|
return runFoundryTaskOperation(context, {
|
|
118
130
|
command: "dataset-semantic-apply",
|
|
119
131
|
options: {
|
|
120
132
|
submission: submission.descriptor,
|
|
121
133
|
files: submission.files,
|
|
122
134
|
assessment: assessment.entry.sha256,
|
|
135
|
+
...(interaction
|
|
136
|
+
? { interaction: interaction.entry.sha256, adopted_decisions: adoptedDecisions }
|
|
137
|
+
: {}),
|
|
123
138
|
},
|
|
124
139
|
validateCurrent(index) {
|
|
125
140
|
const current = currentWorkflowState(context, index);
|
|
126
141
|
if (current.assessment?.entry.sha256 !== assessment.entry.sha256 ||
|
|
127
|
-
current.rows?.entry.sha256 !== rows.entry.sha256
|
|
142
|
+
current.rows?.entry.sha256 !== rows.entry.sha256 ||
|
|
143
|
+
(currentFoundryInteractionState(context, index)?.entry.sha256 ?? null) !==
|
|
144
|
+
(interaction?.entry.sha256 ?? null))
|
|
128
145
|
fail("semantic_assessment_changed", "Assessment advanced before this submission acquired the task lock.");
|
|
129
146
|
},
|
|
130
147
|
}, (operation) => {
|
|
@@ -354,6 +371,9 @@ export async function applyFoundrySemanticInput(context, qualified, entries, sub
|
|
|
354
371
|
submission_sha256: submission.descriptor.sha256,
|
|
355
372
|
assessment_sha256: assessment.entry.sha256,
|
|
356
373
|
work_items: [...used],
|
|
374
|
+
...(interaction
|
|
375
|
+
? { interaction_sha256: interaction.entry.sha256, adopted_decisions: adoptedDecisions }
|
|
376
|
+
: {}),
|
|
357
377
|
results,
|
|
358
378
|
blockers,
|
|
359
379
|
};
|
|
@@ -19,17 +19,25 @@ export interface WorkflowRows {
|
|
|
19
19
|
}
|
|
20
20
|
export interface WorkflowAssessment {
|
|
21
21
|
schema: "tiangong-foundry.assessment-stage.v1";
|
|
22
|
-
status:
|
|
22
|
+
status: "in_progress" | "completed";
|
|
23
23
|
owner_base: string;
|
|
24
24
|
rows_report?: string;
|
|
25
25
|
identity_report?: string | null;
|
|
26
|
+
previous_assessment?: string | null;
|
|
27
|
+
previous_assessment_sha256?: string | null;
|
|
28
|
+
interaction_sha256?: string;
|
|
29
|
+
assessed_type?: string;
|
|
26
30
|
sets: Array<Record<string, unknown>>;
|
|
27
31
|
}
|
|
32
|
+
export declare function workflowAssessmentQueueScopeSha256(sets: readonly WorkflowRowSet[]): string | null;
|
|
28
33
|
export declare function workflowObject(value: unknown): Record<string, unknown>;
|
|
29
34
|
export declare function readWorkflowArtifact(context: FoundryRuntimeContext, entry: ArtifactEntry): WorkflowArtifact<Record<string, unknown>>;
|
|
30
35
|
export declare function currentWorkflowState(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[]): {
|
|
31
36
|
rows: WorkflowArtifact<WorkflowRows> | null;
|
|
32
37
|
assessment: WorkflowArtifact<WorkflowAssessment> | null;
|
|
38
|
+
assessmentComplete: boolean;
|
|
39
|
+
assessmentRemainingTypes: string[];
|
|
40
|
+
interactionSha256: string | null;
|
|
33
41
|
identity: WorkflowArtifact<Record<string, unknown>> | null;
|
|
34
42
|
finalization: WorkflowArtifact<Record<string, unknown>> | null;
|
|
35
43
|
authorization: WorkflowArtifact<Record<string, unknown>> | null;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
4
|
+
import { captureFoundryInput, FoundryContextError, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
5
5
|
import { readTaskBytes } from "./foundry-task-io.js";
|
|
6
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
7
|
+
import { applicableFoundryInteractionDigest } from "./foundry-interaction-projection.js";
|
|
6
8
|
/**
|
|
7
9
|
* The repair producer's registration of the preparation report. These two values are repeated here
|
|
8
10
|
* rather than imported so this projection module stays a graph leaf; the public repair suite fails
|
|
@@ -11,6 +13,28 @@ import { readTaskBytes } from "./foundry-task-io.js";
|
|
|
11
13
|
const FOUNDRY_REPAIR_PREFLIGHT_COMMAND = "dataset-workflow-repair-preflight";
|
|
12
14
|
const FOUNDRY_REPAIR_REPORT_NAME = "foundry-repair-preflight.json";
|
|
13
15
|
const FOUNDRY_REPAIR_PREPARATION_SCHEMA = "tiangong-foundry.repair-preparation.v1";
|
|
16
|
+
const queueTypes = new Set(["process", "flow", "contact", "source", "unitgroup", "flowproperty"]);
|
|
17
|
+
export function workflowAssessmentQueueScopeSha256(sets) {
|
|
18
|
+
if (!sets.some((set) => set.type === "process"))
|
|
19
|
+
return null;
|
|
20
|
+
return sha256Json(sets
|
|
21
|
+
.filter((set) => queueTypes.has(set.type))
|
|
22
|
+
.map((set) => {
|
|
23
|
+
const fact = captureFoundryInput(set.file);
|
|
24
|
+
return { type: set.type, path: set.file, bytes: fact.bytes, sha256: fact.sha256 };
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
function registeredAssessmentFile(context, entries, file) {
|
|
28
|
+
if (typeof file !== "string")
|
|
29
|
+
return false;
|
|
30
|
+
const entry = entries.find((candidate) => resolveFoundryOutput(context, candidate.path) === file);
|
|
31
|
+
if (!entry)
|
|
32
|
+
return false;
|
|
33
|
+
const fact = captureFoundryInput(file);
|
|
34
|
+
if (fact.bytes !== entry.bytes || fact.sha256 !== entry.sha256)
|
|
35
|
+
throw new FoundryContextError("workflow_assessment_changed", "A registered assessment input or report changed.");
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
14
38
|
export function workflowObject(value) {
|
|
15
39
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
40
|
throw new FoundryContextError("workflow_report_invalid", "Workflow metadata must be an object.");
|
|
@@ -85,6 +109,29 @@ export function currentWorkflowState(context, entries) {
|
|
|
85
109
|
}
|
|
86
110
|
}
|
|
87
111
|
}
|
|
112
|
+
const interactionEntry = entries.findLast((entry) => entry.command === "dataset-workflow-interaction" &&
|
|
113
|
+
path.basename(entry.path) === "interaction-state.json");
|
|
114
|
+
const interactionSha256 = interactionEntry?.sha256 ?? null;
|
|
115
|
+
const interactionValue = interactionEntry
|
|
116
|
+
? readWorkflowArtifact(context, interactionEntry).value
|
|
117
|
+
: null;
|
|
118
|
+
if (interactionValue &&
|
|
119
|
+
(interactionValue.schema !== "tiangong-foundry.interaction-state.v1" ||
|
|
120
|
+
interactionValue.task_id !== context.taskId ||
|
|
121
|
+
interactionValue.actor_id !== context.actorId ||
|
|
122
|
+
!Array.isArray(interactionValue.events)))
|
|
123
|
+
throw new FoundryContextError("workflow_interaction_invalid", "Registered task decisions are invalid.");
|
|
124
|
+
const interaction = interactionValue;
|
|
125
|
+
const contextShaByType = new Map();
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
if (entry.command !== "dataset-context-pack" ||
|
|
128
|
+
path.basename(entry.path) !== "contract-report.json")
|
|
129
|
+
continue;
|
|
130
|
+
const report = readWorkflowArtifact(context, entry).value;
|
|
131
|
+
if (report.status === "completed" && typeof report.type === "string")
|
|
132
|
+
contextShaByType.set(report.type, entry.sha256);
|
|
133
|
+
}
|
|
134
|
+
const queueScopeSha256 = rows ? workflowAssessmentQueueScopeSha256(rows.value.sets) : null;
|
|
88
135
|
let assessment = null;
|
|
89
136
|
if (rows) {
|
|
90
137
|
for (const entry of [...entries].reverse()) {
|
|
@@ -93,31 +140,133 @@ export function currentWorkflowState(context, entries) {
|
|
|
93
140
|
continue;
|
|
94
141
|
const found = readWorkflowArtifact(context, entry), value = found.value;
|
|
95
142
|
if (value.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
96
|
-
|
|
143
|
+
value.owner_base !== context.assetRoot ||
|
|
144
|
+
!["in_progress", "completed"].includes(String(value.status)) ||
|
|
97
145
|
!Array.isArray(value.sets))
|
|
98
146
|
throw new FoundryContextError("workflow_assessment_invalid", "Registered assessment metadata is invalid.");
|
|
99
147
|
const sets = value.sets.map(workflowObject);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
const reportRowsEntry = entries.find((candidate) => ["dataset-workflow-rows", "dataset-semantic-apply"].includes(candidate.command) &&
|
|
149
|
+
path.basename(candidate.path) === "foundry-rows.json" &&
|
|
150
|
+
resolveFoundryOutput(context, candidate.path) === value.rows_report);
|
|
151
|
+
const reportRows = reportRowsEntry
|
|
152
|
+
? readWorkflowArtifact(context, reportRowsEntry).value
|
|
153
|
+
: value.rows_report === undefined
|
|
154
|
+
? rows.value
|
|
155
|
+
: null;
|
|
156
|
+
if (!reportRows || !Array.isArray(reportRows.sets))
|
|
157
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment row ancestry is not registered.");
|
|
158
|
+
// An empty reference-only row revision needs its own assessment receipt. There are
|
|
159
|
+
// no per-type set facts to reuse from a predecessor with different rows.
|
|
160
|
+
if (!rows.value.sets.length && value.rows_report !== rows.file)
|
|
161
|
+
continue;
|
|
162
|
+
const originalRows = reportRows.sets.map(workflowObject);
|
|
163
|
+
let lastOriginal = -1;
|
|
164
|
+
for (const set of sets) {
|
|
165
|
+
const next = originalRows.findIndex((row, index) => index > lastOriginal && row.type === set.type && row.file === set.rows);
|
|
166
|
+
if (next < 0)
|
|
167
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment contains an unbound or duplicate row set.");
|
|
168
|
+
lastOriginal = next;
|
|
169
|
+
}
|
|
170
|
+
if ((value.status === "completed") !== (sets.length === originalRows.length))
|
|
171
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment completion must match its registered row-set coverage.");
|
|
172
|
+
if (value.previous_assessment !== undefined) {
|
|
173
|
+
const previousPath = value.previous_assessment;
|
|
174
|
+
const previousSha = value.previous_assessment_sha256;
|
|
175
|
+
const previousEntry = typeof previousPath === "string"
|
|
176
|
+
? entries.find((candidate) => candidate.command === "dataset-workflow-assessment" &&
|
|
177
|
+
candidate.sequence < entry.sequence &&
|
|
178
|
+
resolveFoundryOutput(context, candidate.path) === previousPath &&
|
|
179
|
+
candidate.sha256 === previousSha)
|
|
180
|
+
: undefined;
|
|
181
|
+
if ((previousPath === null && previousSha !== null) ||
|
|
182
|
+
(typeof previousPath === "string" && !previousEntry) ||
|
|
183
|
+
(previousPath !== null && typeof previousPath !== "string") ||
|
|
184
|
+
(previousPath === null && (sets.length !== 1 || value.assessed_type !== sets[0]?.type)))
|
|
185
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment progress has no matching registered predecessor.");
|
|
186
|
+
if (previousEntry) {
|
|
187
|
+
const prior = readWorkflowArtifact(context, previousEntry).value;
|
|
188
|
+
const priorSets = Array.isArray(prior.sets) ? prior.sets.map(workflowObject) : null;
|
|
189
|
+
if (prior.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
190
|
+
!priorSets ||
|
|
191
|
+
typeof value.assessed_type !== "string" ||
|
|
192
|
+
!sets.some((set) => set.type === value.assessed_type) ||
|
|
193
|
+
sets.some((set) => set.type !== value.assessed_type &&
|
|
194
|
+
!priorSets.some((old) => sha256Json(old) === sha256Json(set))))
|
|
195
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Assessment retained a set outside its registered predecessor.");
|
|
196
|
+
}
|
|
118
197
|
}
|
|
198
|
+
else if (value.status === "in_progress") {
|
|
199
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Partial assessment must identify its predecessor boundary.");
|
|
200
|
+
}
|
|
201
|
+
const identityMatches = (value.identity_report ?? null) ===
|
|
202
|
+
(identity?.value.status === "completed" ? identity.file : null);
|
|
203
|
+
const currentSets = identityMatches
|
|
204
|
+
? sets.filter((set) => {
|
|
205
|
+
const row = rows.value.sets.find((candidate) => candidate.type === set.type);
|
|
206
|
+
if (!row || row.file !== set.rows)
|
|
207
|
+
return false;
|
|
208
|
+
if ((set.interaction_digest ?? null) !==
|
|
209
|
+
applicableFoundryInteractionDigest(interaction, row.type))
|
|
210
|
+
return false;
|
|
211
|
+
const expectedContext = contextShaByType.get(row.type);
|
|
212
|
+
if ((set.context_report_sha256 !== undefined &&
|
|
213
|
+
set.context_report_sha256 !== expectedContext) ||
|
|
214
|
+
(set.context_report_sha256 === undefined && value.rows_report !== rows.file))
|
|
215
|
+
return false;
|
|
216
|
+
if (["flow", "process"].includes(row.type)) {
|
|
217
|
+
if ((set.queue_scope_sha256 !== undefined &&
|
|
218
|
+
set.queue_scope_sha256 !== queueScopeSha256) ||
|
|
219
|
+
(set.queue_scope_sha256 === undefined &&
|
|
220
|
+
queueScopeSha256 !== null &&
|
|
221
|
+
value.rows_report !== rows.file))
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const files = [
|
|
225
|
+
set.rows,
|
|
226
|
+
set.schema_report,
|
|
227
|
+
set.qa_report,
|
|
228
|
+
set.curation_report,
|
|
229
|
+
set.authoring_manifest,
|
|
230
|
+
];
|
|
231
|
+
if (set.interaction_context !== undefined)
|
|
232
|
+
files.push(set.interaction_context);
|
|
233
|
+
if (files.some((file) => !registeredAssessmentFile(context, entries, file)))
|
|
234
|
+
throw new FoundryContextError("workflow_assessment_invalid", "A reusable assessment file is not registered.");
|
|
235
|
+
return true;
|
|
236
|
+
})
|
|
237
|
+
: [];
|
|
238
|
+
const covered = new Set(currentSets.map((set) => set.type));
|
|
239
|
+
assessment = {
|
|
240
|
+
...found,
|
|
241
|
+
value: {
|
|
242
|
+
schema: "tiangong-foundry.assessment-stage.v1",
|
|
243
|
+
status: covered.size === rows.value.sets.length ? "completed" : "in_progress",
|
|
244
|
+
owner_base: value.owner_base,
|
|
245
|
+
rows_report: rows.file,
|
|
246
|
+
identity_report: identity?.value.status === "completed" ? identity.file : null,
|
|
247
|
+
...(value.previous_assessment !== undefined
|
|
248
|
+
? {
|
|
249
|
+
previous_assessment: value.previous_assessment,
|
|
250
|
+
previous_assessment_sha256: value.previous_assessment_sha256,
|
|
251
|
+
}
|
|
252
|
+
: {}),
|
|
253
|
+
...(typeof value.interaction_sha256 === "string"
|
|
254
|
+
? { interaction_sha256: value.interaction_sha256 }
|
|
255
|
+
: {}),
|
|
256
|
+
...(typeof value.assessed_type === "string"
|
|
257
|
+
? { assessed_type: value.assessed_type }
|
|
258
|
+
: {}),
|
|
259
|
+
sets: currentSets,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
break;
|
|
119
263
|
}
|
|
120
264
|
}
|
|
265
|
+
const assessmentComplete = assessment?.value.status === "completed";
|
|
266
|
+
const coveredTypes = new Set(assessment?.value.sets.map((set) => set.type) ?? []);
|
|
267
|
+
const assessmentRemainingTypes = rows
|
|
268
|
+
? rows.value.sets.filter((set) => !coveredTypes.has(set.type)).map((set) => set.type)
|
|
269
|
+
: [];
|
|
121
270
|
const referenceInputs = new Map();
|
|
122
271
|
for (const entry of entries) {
|
|
123
272
|
if (entry.command !== "dataset-workflow-reference-input" ||
|
|
@@ -138,7 +287,7 @@ export function currentWorkflowState(context, entries) {
|
|
|
138
287
|
.digest("hex")
|
|
139
288
|
: null;
|
|
140
289
|
let finalization = null;
|
|
141
|
-
if (rows && assessment) {
|
|
290
|
+
if (rows && assessmentComplete && assessment) {
|
|
142
291
|
for (const entry of [...entries].reverse()) {
|
|
143
292
|
if (entry.command !== "dataset-workflow-finalize" ||
|
|
144
293
|
path.basename(entry.path) !== "foundry-finalize.json")
|
|
@@ -225,6 +374,9 @@ export function currentWorkflowState(context, entries) {
|
|
|
225
374
|
return {
|
|
226
375
|
rows,
|
|
227
376
|
assessment,
|
|
377
|
+
assessmentComplete,
|
|
378
|
+
assessmentRemainingTypes,
|
|
379
|
+
interactionSha256,
|
|
228
380
|
identity,
|
|
229
381
|
finalization,
|
|
230
382
|
authorization,
|
|
@@ -11,6 +11,7 @@ export type { FoundryFacadeRuntimeSelection } from "./foundry-facade.ts";
|
|
|
11
11
|
export { FOUNDRY_AUTHORIZATION_INPUT_SCHEMA, type FoundryAuthorizationInput, } from "./lib/foundry-authorization-input.ts";
|
|
12
12
|
export type { FoundryAuthentication, FoundryPublicOAuthConfiguration, } from "./lib/foundry-runtime-identity.ts";
|
|
13
13
|
export { FOUNDRY_SEMANTIC_INPUT_SCHEMA, type FoundrySemanticInput, type SemanticPatchInput, type SemanticDecisionInput, type SemanticSubmission, } from "./lib/foundry-semantic-input.ts";
|
|
14
|
+
export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, type FoundryInteractionInput, type FoundryInteractionState, } from "./lib/foundry-interaction-input.ts";
|
|
14
15
|
export type { FoundryWorkspaceAccess } from "./lib/foundry-runtime-context.ts";
|
|
15
16
|
export { FOUNDRY_RUNTIME_SELECTION_SCHEMA, type FoundryRuntimeSelectionRecord, } from "./lib/foundry-runtime-selection-record.ts";
|
|
16
17
|
export type { FoundryRuntimeManagerOptions } from "./lib/foundry-runtime-selection.ts";
|
|
@@ -62,6 +63,7 @@ export declare function createFoundryFacade(options: FoundryPackageFacadeOptions
|
|
|
62
63
|
taskId: string;
|
|
63
64
|
actorId: string;
|
|
64
65
|
semanticInputFile?: string;
|
|
66
|
+
interactionInputFile?: string;
|
|
65
67
|
authorizationInputFile?: string;
|
|
66
68
|
referenceInputFile?: string;
|
|
67
69
|
}): Promise<import("./lib/foundry-operation-result.ts").FoundryOperationResult>;
|
|
@@ -12,6 +12,7 @@ export function createFoundryWorkspaceAccess(input) {
|
|
|
12
12
|
}
|
|
13
13
|
export { FOUNDRY_AUTHORIZATION_INPUT_SCHEMA, } from "./lib/foundry-authorization-input.js";
|
|
14
14
|
export { FOUNDRY_SEMANTIC_INPUT_SCHEMA, } from "./lib/foundry-semantic-input.js";
|
|
15
|
+
export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, } from "./lib/foundry-interaction-input.js";
|
|
15
16
|
export { FOUNDRY_RUNTIME_SELECTION_SCHEMA, } from "./lib/foundry-runtime-selection-record.js";
|
|
16
17
|
/** Public host factory with package/source identity bound by this module, never caller input. */
|
|
17
18
|
export function createFoundryFacade(options) {
|
|
@@ -119,7 +119,14 @@ async function runPublicCommand(parsed, host) {
|
|
|
119
119
|
: parsed.operation === "task.start"
|
|
120
120
|
? ["spec"]
|
|
121
121
|
: parsed.operation === "task.resume"
|
|
122
|
-
? [
|
|
122
|
+
? [
|
|
123
|
+
"task",
|
|
124
|
+
"actor",
|
|
125
|
+
"semanticInput",
|
|
126
|
+
"authorizationInput",
|
|
127
|
+
"referenceInput",
|
|
128
|
+
"interactionInput",
|
|
129
|
+
]
|
|
123
130
|
: parsed.operation === "task.status"
|
|
124
131
|
? ["task", "actor"]
|
|
125
132
|
: []),
|
|
@@ -298,6 +305,7 @@ async function runPublicCommand(parsed, host) {
|
|
|
298
305
|
taskId,
|
|
299
306
|
actorId,
|
|
300
307
|
semanticInputFile: option(parsed.args.semanticInput, "--semantic-input") ?? undefined,
|
|
308
|
+
interactionInputFile: option(parsed.args.interactionInput, "--interaction-input") ?? undefined,
|
|
301
309
|
referenceInputFile: option(parsed.args.referenceInput, "--reference-input") ?? undefined,
|
|
302
310
|
authorizationInputFile: option(parsed.args.authorizationInput, "--authorization-input") ?? undefined,
|
|
303
311
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiangong-lca/foundry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Control plane for TianGong LCA external dataset import and TIDAS authoring work.",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"specs/schemas/foundry-package-descriptor.schema.json",
|
|
42
42
|
"specs/schemas/foundry-task-start.schema.json",
|
|
43
43
|
"specs/schemas/foundry-semantic-input.schema.json",
|
|
44
|
+
"specs/schemas/foundry-interaction-input.schema.json",
|
|
44
45
|
"specs/schemas/foundry-authorization-input.schema.json",
|
|
45
46
|
"specs/schemas/foundry-reference-input.schema.json",
|
|
46
47
|
"specs/schemas/foundry-workspace-migration-plan.schema.json",
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://tiangong-lca.local/foundry/interaction-input.schema.json",
|
|
4
|
+
"title": "Foundry task interaction input v1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["schema", "task_id", "actor_id", "expected_state_sha256", "events"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"schema": { "const": "tiangong-foundry.interaction-input.v1" },
|
|
10
|
+
"task_id": { "type": "string", "pattern": "^task-[0-9a-f]{64}-r[0-9]{4}$" },
|
|
11
|
+
"actor_id": { "$ref": "#/$defs/id" },
|
|
12
|
+
"expected_state_sha256": {
|
|
13
|
+
"oneOf": [{ "$ref": "#/$defs/sha" }, { "type": "null" }]
|
|
14
|
+
},
|
|
15
|
+
"events": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"minItems": 1,
|
|
18
|
+
"maxItems": 16,
|
|
19
|
+
"items": {
|
|
20
|
+
"oneOf": [
|
|
21
|
+
{ "$ref": "#/$defs/question" },
|
|
22
|
+
{ "$ref": "#/$defs/answer" },
|
|
23
|
+
{ "$ref": "#/$defs/assumption" }
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"$defs": {
|
|
29
|
+
"id": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"minLength": 1,
|
|
32
|
+
"maxLength": 256,
|
|
33
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$"
|
|
34
|
+
},
|
|
35
|
+
"sha": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
|
|
36
|
+
"text": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"minLength": 1,
|
|
39
|
+
"maxLength": 4096,
|
|
40
|
+
"pattern": "^[^\\u0000\\r\\n]+$"
|
|
41
|
+
},
|
|
42
|
+
"shortText": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"minLength": 1,
|
|
45
|
+
"maxLength": 1200,
|
|
46
|
+
"pattern": "^[^\\u0000\\r\\n]+$"
|
|
47
|
+
},
|
|
48
|
+
"scope": {
|
|
49
|
+
"oneOf": [
|
|
50
|
+
{ "type": "null" },
|
|
51
|
+
{
|
|
52
|
+
"enum": [
|
|
53
|
+
"contact",
|
|
54
|
+
"source",
|
|
55
|
+
"support",
|
|
56
|
+
"flow",
|
|
57
|
+
"flowproperty",
|
|
58
|
+
"unitgroup",
|
|
59
|
+
"process",
|
|
60
|
+
"lifecyclemodel"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"evidence": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"maxItems": 16,
|
|
68
|
+
"uniqueItems": true,
|
|
69
|
+
"items": { "$ref": "#/$defs/sha" }
|
|
70
|
+
},
|
|
71
|
+
"question": {
|
|
72
|
+
"type": "object",
|
|
73
|
+
"additionalProperties": false,
|
|
74
|
+
"required": [
|
|
75
|
+
"kind",
|
|
76
|
+
"id",
|
|
77
|
+
"dataset_type",
|
|
78
|
+
"missing",
|
|
79
|
+
"impact",
|
|
80
|
+
"recommendation",
|
|
81
|
+
"ask",
|
|
82
|
+
"choices",
|
|
83
|
+
"evidence_sha256",
|
|
84
|
+
"supersedes"
|
|
85
|
+
],
|
|
86
|
+
"properties": {
|
|
87
|
+
"kind": { "const": "question" },
|
|
88
|
+
"id": { "$ref": "#/$defs/id" },
|
|
89
|
+
"dataset_type": { "$ref": "#/$defs/scope" },
|
|
90
|
+
"missing": { "$ref": "#/$defs/shortText" },
|
|
91
|
+
"impact": { "$ref": "#/$defs/shortText" },
|
|
92
|
+
"recommendation": { "$ref": "#/$defs/shortText" },
|
|
93
|
+
"ask": { "$ref": "#/$defs/shortText" },
|
|
94
|
+
"choices": {
|
|
95
|
+
"type": "array",
|
|
96
|
+
"maxItems": 4,
|
|
97
|
+
"uniqueItems": true,
|
|
98
|
+
"items": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"minLength": 1,
|
|
101
|
+
"maxLength": 240,
|
|
102
|
+
"pattern": "^[^\\u0000\\r\\n]+$"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"evidence_sha256": { "$ref": "#/$defs/evidence" },
|
|
106
|
+
"supersedes": { "oneOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }] }
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"answer": {
|
|
110
|
+
"type": "object",
|
|
111
|
+
"additionalProperties": false,
|
|
112
|
+
"required": [
|
|
113
|
+
"kind",
|
|
114
|
+
"question_id",
|
|
115
|
+
"decision_id",
|
|
116
|
+
"supersedes_decision_id",
|
|
117
|
+
"raw_answer",
|
|
118
|
+
"adopted_decision",
|
|
119
|
+
"disposition",
|
|
120
|
+
"evidence_sha256"
|
|
121
|
+
],
|
|
122
|
+
"properties": {
|
|
123
|
+
"kind": { "const": "answer" },
|
|
124
|
+
"question_id": { "$ref": "#/$defs/id" },
|
|
125
|
+
"decision_id": { "$ref": "#/$defs/id" },
|
|
126
|
+
"supersedes_decision_id": {
|
|
127
|
+
"oneOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }]
|
|
128
|
+
},
|
|
129
|
+
"raw_answer": {
|
|
130
|
+
"type": "string",
|
|
131
|
+
"minLength": 1,
|
|
132
|
+
"maxLength": 16384,
|
|
133
|
+
"pattern": "^[^\\u0000]+$"
|
|
134
|
+
},
|
|
135
|
+
"adopted_decision": { "oneOf": [{ "$ref": "#/$defs/text" }, { "type": "null" }] },
|
|
136
|
+
"disposition": { "enum": ["decided", "investigate"] },
|
|
137
|
+
"evidence_sha256": { "$ref": "#/$defs/evidence" }
|
|
138
|
+
},
|
|
139
|
+
"allOf": [
|
|
140
|
+
{
|
|
141
|
+
"if": {
|
|
142
|
+
"properties": { "disposition": { "const": "investigate" } },
|
|
143
|
+
"required": ["disposition"]
|
|
144
|
+
},
|
|
145
|
+
"then": { "properties": { "adopted_decision": { "type": "null" } } },
|
|
146
|
+
"else": { "properties": { "adopted_decision": { "$ref": "#/$defs/text" } } }
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
"assumption": {
|
|
151
|
+
"type": "object",
|
|
152
|
+
"additionalProperties": false,
|
|
153
|
+
"required": [
|
|
154
|
+
"kind",
|
|
155
|
+
"id",
|
|
156
|
+
"dataset_type",
|
|
157
|
+
"statement",
|
|
158
|
+
"impact",
|
|
159
|
+
"evidence_sha256",
|
|
160
|
+
"supersedes"
|
|
161
|
+
],
|
|
162
|
+
"properties": {
|
|
163
|
+
"kind": { "const": "assumption" },
|
|
164
|
+
"id": { "$ref": "#/$defs/id" },
|
|
165
|
+
"dataset_type": { "$ref": "#/$defs/scope" },
|
|
166
|
+
"statement": { "$ref": "#/$defs/text" },
|
|
167
|
+
"impact": { "$ref": "#/$defs/text" },
|
|
168
|
+
"evidence_sha256": { "$ref": "#/$defs/evidence" },
|
|
169
|
+
"supersedes": { "oneOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }] }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"const": "@tiangong-lca/foundry"
|
|
19
19
|
},
|
|
20
20
|
"version": {
|
|
21
|
-
"const": "0.1.
|
|
21
|
+
"const": "0.1.12"
|
|
22
22
|
},
|
|
23
23
|
"cli_dependency": {
|
|
24
24
|
"type": "object",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"tiangong-foundry.operation-result.v1",
|
|
74
74
|
"tiangong-foundry.task-start.v1",
|
|
75
75
|
"tiangong-foundry.semantic-input.v1",
|
|
76
|
+
"tiangong-foundry.interaction-input.v1",
|
|
76
77
|
"tiangong-foundry.authorization-input.v1",
|
|
77
78
|
"tiangong-foundry.reference-input.v1",
|
|
78
79
|
"tiangong-foundry.facade-request-index.v1",
|