@tiangong-lca/foundry 0.1.10 → 0.1.11
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 +9 -3
- package/docs/package-distribution-contract.md +6 -4
- package/docs/public-runtime-contract.md +17 -5
- package/docs/runtime-context-contract.md +5 -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 +165 -31
- 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 +127 -6
- 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
|
@@ -16,7 +16,14 @@ function exact(value, keys) {
|
|
|
16
16
|
}
|
|
17
17
|
export function parseFoundrySemanticInput(value) {
|
|
18
18
|
const data = workflowObject(value);
|
|
19
|
-
exact(data, [
|
|
19
|
+
exact(data, [
|
|
20
|
+
"schema",
|
|
21
|
+
"task_id",
|
|
22
|
+
"actor_id",
|
|
23
|
+
"assessment_sha256",
|
|
24
|
+
"submissions",
|
|
25
|
+
...(Object.hasOwn(data, "interaction_sha256") ? ["interaction_sha256"] : []),
|
|
26
|
+
]);
|
|
20
27
|
if (data.schema !== FOUNDRY_SEMANTIC_INPUT_SCHEMA ||
|
|
21
28
|
typeof data.task_id !== "string" ||
|
|
22
29
|
!/^task-[0-9a-f]{64}-r\d{4}$/u.test(data.task_id) ||
|
|
@@ -24,13 +31,21 @@ export function parseFoundrySemanticInput(value) {
|
|
|
24
31
|
!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(data.actor_id) ||
|
|
25
32
|
typeof data.assessment_sha256 !== "string" ||
|
|
26
33
|
!sha.test(data.assessment_sha256) ||
|
|
34
|
+
(Object.hasOwn(data, "interaction_sha256") &&
|
|
35
|
+
(typeof data.interaction_sha256 !== "string" || !sha.test(data.interaction_sha256))) ||
|
|
27
36
|
!Array.isArray(data.submissions) ||
|
|
28
37
|
!data.submissions.length ||
|
|
29
38
|
data.submissions.length > 1000)
|
|
30
39
|
invalid("Semantic input must bind a task, actor, assessment and bounded submission selection.");
|
|
31
40
|
const submissions = data.submissions.map((item) => {
|
|
32
41
|
const part = workflowObject(item);
|
|
33
|
-
exact(part, [
|
|
42
|
+
exact(part, [
|
|
43
|
+
"kind",
|
|
44
|
+
"authoring_task_sha256",
|
|
45
|
+
"file",
|
|
46
|
+
"sha256",
|
|
47
|
+
...(Object.hasOwn(part, "decision_ids") ? ["decision_ids"] : []),
|
|
48
|
+
]);
|
|
34
49
|
if ((part.kind !== "patch" &&
|
|
35
50
|
part.kind !== "classification" &&
|
|
36
51
|
part.kind !== "location" &&
|
|
@@ -44,11 +59,20 @@ export function parseFoundrySemanticInput(value) {
|
|
|
44
59
|
part.file.length > 4096 ||
|
|
45
60
|
/[\0\r\n]/u.test(part.file))
|
|
46
61
|
invalid("A semantic submission reference is invalid.");
|
|
62
|
+
if (Object.hasOwn(part, "decision_ids") &&
|
|
63
|
+
(!Array.isArray(part.decision_ids) ||
|
|
64
|
+
part.decision_ids.length > 100 ||
|
|
65
|
+
part.decision_ids.some((id) => typeof id !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u.test(id)) ||
|
|
66
|
+
new Set(part.decision_ids).size !== part.decision_ids.length))
|
|
67
|
+
invalid("Semantic decision ids must be unique bounded identifiers.");
|
|
47
68
|
return Object.freeze({
|
|
48
69
|
kind: part.kind,
|
|
49
70
|
authoring_task_sha256: part.authoring_task_sha256,
|
|
50
71
|
file: part.file,
|
|
51
72
|
sha256: part.sha256,
|
|
73
|
+
...(Object.hasOwn(part, "decision_ids")
|
|
74
|
+
? { decision_ids: Object.freeze([...part.decision_ids]) }
|
|
75
|
+
: {}),
|
|
52
76
|
});
|
|
53
77
|
});
|
|
54
78
|
if (new Set(submissions.map((part) => part.authoring_task_sha256)).size !== submissions.length)
|
|
@@ -58,6 +82,9 @@ export function parseFoundrySemanticInput(value) {
|
|
|
58
82
|
task_id: data.task_id,
|
|
59
83
|
actor_id: data.actor_id,
|
|
60
84
|
assessment_sha256: data.assessment_sha256,
|
|
85
|
+
...(Object.hasOwn(data, "interaction_sha256")
|
|
86
|
+
? { interaction_sha256: data.interaction_sha256 }
|
|
87
|
+
: {}),
|
|
61
88
|
submissions: Object.freeze(submissions),
|
|
62
89
|
});
|
|
63
90
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FoundrySemanticInput } from "./foundry-semantic-input.ts";
|
|
2
|
+
import type { FoundryInteractionState } from "./foundry-interaction-input.ts";
|
|
3
|
+
export interface SemanticInteractionScope {
|
|
4
|
+
readonly work_item_sha256: string;
|
|
5
|
+
readonly dataset_type: string;
|
|
6
|
+
readonly decision_ids: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/** Bind a semantic proposal to the latest applicable user choices without treating them as data proof. */
|
|
9
|
+
export declare function verifyFoundrySemanticInteraction(input: FoundrySemanticInput, interaction: {
|
|
10
|
+
readonly sha256: string;
|
|
11
|
+
readonly state: FoundryInteractionState;
|
|
12
|
+
} | null, selectedScopes: ReadonlyMap<string, string>): readonly SemanticInteractionScope[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FoundryContextError } from "./foundry-runtime-context.js";
|
|
2
|
+
import { currentFoundryDecisionsForType, currentFoundryQuestions, currentFoundryInvestigations, foundryInteractionScopeApplies, } from "./foundry-interaction-projection.js";
|
|
3
|
+
function fail(message) {
|
|
4
|
+
throw new FoundryContextError("semantic_interaction_invalid", message);
|
|
5
|
+
}
|
|
6
|
+
/** Bind a semantic proposal to the latest applicable user choices without treating them as data proof. */
|
|
7
|
+
export function verifyFoundrySemanticInteraction(input, interaction, selectedScopes) {
|
|
8
|
+
if ((input.interaction_sha256 ?? null) !== (interaction?.sha256 ?? null))
|
|
9
|
+
fail("Semantic input must name the current registered interaction state.");
|
|
10
|
+
const result = [];
|
|
11
|
+
for (const part of input.submissions) {
|
|
12
|
+
const type = selectedScopes.get(part.authoring_task_sha256);
|
|
13
|
+
if (!type)
|
|
14
|
+
fail("Semantic work is not in the current assessed scope.");
|
|
15
|
+
const expected = interaction
|
|
16
|
+
? currentFoundryDecisionsForType(interaction.state, type).map((decision) => String(decision.decision_id))
|
|
17
|
+
: [];
|
|
18
|
+
const actual = part.decision_ids ?? [];
|
|
19
|
+
if (expected.length !== actual.length ||
|
|
20
|
+
expected.some((id) => !actual.includes(id)) ||
|
|
21
|
+
actual.some((id) => !expected.includes(id)))
|
|
22
|
+
fail("Semantic work must name exactly the current applicable user decision ids.");
|
|
23
|
+
if (interaction) {
|
|
24
|
+
const unresolved = [
|
|
25
|
+
...currentFoundryQuestions(interaction.state),
|
|
26
|
+
...currentFoundryInvestigations(interaction.state),
|
|
27
|
+
];
|
|
28
|
+
if (unresolved.some((item) => foundryInteractionScopeApplies(item.dataset_type, type)))
|
|
29
|
+
fail("Resolve or investigate the current decision gap before applying dependent semantic work.");
|
|
30
|
+
}
|
|
31
|
+
result.push(Object.freeze({
|
|
32
|
+
work_item_sha256: part.authoring_task_sha256,
|
|
33
|
+
dataset_type: type,
|
|
34
|
+
decision_ids: Object.freeze([...expected]),
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return Object.freeze(result);
|
|
38
|
+
}
|
|
@@ -18,6 +18,15 @@ interface CleanupPreparation {
|
|
|
18
18
|
readonly source_input: string | null;
|
|
19
19
|
readonly output_directory: string;
|
|
20
20
|
}
|
|
21
|
+
export interface FoundryTaskBrief {
|
|
22
|
+
readonly original_request: string | null;
|
|
23
|
+
readonly goal: string;
|
|
24
|
+
readonly intended_use: string | null;
|
|
25
|
+
readonly scope: string | null;
|
|
26
|
+
readonly deliverables: readonly string[];
|
|
27
|
+
readonly user_constraints: readonly string[];
|
|
28
|
+
readonly ai_assumptions: readonly string[];
|
|
29
|
+
}
|
|
21
30
|
export interface FoundryTaskStartSpec {
|
|
22
31
|
readonly schema: typeof FOUNDRY_TASK_START_SPEC_SCHEMA;
|
|
23
32
|
readonly request_id: string;
|
|
@@ -29,6 +38,8 @@ export interface FoundryTaskStartSpec {
|
|
|
29
38
|
readonly seed: Readonly<SourceSelection> | null;
|
|
30
39
|
readonly account_intent: Readonly<AccountIntentSelection> | null;
|
|
31
40
|
readonly preparation: Readonly<CleanupPreparation> | null;
|
|
41
|
+
/** Omitted for legacy requests, preserving their normalized bytes and fingerprints. */
|
|
42
|
+
readonly brief?: Readonly<FoundryTaskBrief>;
|
|
32
43
|
/** Present only for the existing-owner-draft-repair lane, so v1 fingerprints never change. */
|
|
33
44
|
readonly repair?: Readonly<FoundryRepairSelection>;
|
|
34
45
|
}
|
|
@@ -96,6 +96,40 @@ function preparation(value, sources) {
|
|
|
96
96
|
output_directory: item.output_directory,
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
+
function briefText(value, label, maxLength) {
|
|
100
|
+
if (typeof value !== "string" || !value.trim() || Array.from(value).length > maxLength)
|
|
101
|
+
fail("task_spec_brief_invalid", `${label} must be a bounded nonblank string.`);
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
function nullableBriefText(value, label, maxLength) {
|
|
105
|
+
return value === null ? null : briefText(value, label, maxLength);
|
|
106
|
+
}
|
|
107
|
+
function briefItems(value, label) {
|
|
108
|
+
if (!Array.isArray(value) || value.length > 32)
|
|
109
|
+
fail("task_spec_brief_invalid", `${label} must be a bounded string list.`);
|
|
110
|
+
return Object.freeze(value.map((item) => briefText(item, `${label} item`, 2_048)));
|
|
111
|
+
}
|
|
112
|
+
function taskBrief(value) {
|
|
113
|
+
const item = record(value, "Task brief");
|
|
114
|
+
exact(item, [
|
|
115
|
+
"original_request",
|
|
116
|
+
"goal",
|
|
117
|
+
"intended_use",
|
|
118
|
+
"scope",
|
|
119
|
+
"deliverables",
|
|
120
|
+
"user_constraints",
|
|
121
|
+
"ai_assumptions",
|
|
122
|
+
], "Task brief");
|
|
123
|
+
return Object.freeze({
|
|
124
|
+
original_request: nullableBriefText(item.original_request, "Original request", 16_384),
|
|
125
|
+
goal: briefText(item.goal, "Task goal", 4_096),
|
|
126
|
+
intended_use: nullableBriefText(item.intended_use, "Intended use", 4_096),
|
|
127
|
+
scope: nullableBriefText(item.scope, "Task scope", 4_096),
|
|
128
|
+
deliverables: briefItems(item.deliverables, "Deliverables"),
|
|
129
|
+
user_constraints: briefItems(item.user_constraints, "User constraints"),
|
|
130
|
+
ai_assumptions: briefItems(item.ai_assumptions, "AI assumptions"),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
99
133
|
export function parseFoundryTaskStartSpec(value) {
|
|
100
134
|
const item = record(value, "Task-start spec");
|
|
101
135
|
exact(item, [
|
|
@@ -109,6 +143,7 @@ export function parseFoundryTaskStartSpec(value) {
|
|
|
109
143
|
"seed",
|
|
110
144
|
"account_intent",
|
|
111
145
|
"preparation",
|
|
146
|
+
...(Object.hasOwn(item, "brief") ? ["brief"] : []),
|
|
112
147
|
...(Object.hasOwn(item, "repair") ? ["repair"] : []),
|
|
113
148
|
], "Task-start spec");
|
|
114
149
|
if (item.schema !== FOUNDRY_TASK_START_SPEC_SCHEMA ||
|
|
@@ -167,6 +202,7 @@ export function parseFoundryTaskStartSpec(value) {
|
|
|
167
202
|
seed,
|
|
168
203
|
account_intent: account(item.account_intent),
|
|
169
204
|
preparation: preparation(item.preparation, sources),
|
|
205
|
+
...(Object.hasOwn(item, "brief") ? { brief: taskBrief(item.brief) } : {}),
|
|
170
206
|
...(repair ? { repair } : {}),
|
|
171
207
|
};
|
|
172
208
|
return Object.freeze(spec);
|
|
@@ -23,7 +23,7 @@ export declare function assertFoundryTaskInputLineage(context: FoundryRuntimeCon
|
|
|
23
23
|
}>>;
|
|
24
24
|
/** Short local preparation transaction. Remote mutation/batch execution must not use this replay path. */
|
|
25
25
|
export declare function runFoundryTaskOperation(context: FoundryRuntimeContext, input: {
|
|
26
|
-
command: "dataset-curation-cleanup" | "dataset-tidas-import" | "dataset-context-pack" | "dataset-workflow-rows" | "dataset-workflow-assessment" | "dataset-workflow-identity" | "dataset-workflow-finalize" | "dataset-workflow-authorization" | "dataset-workflow-native-contract" | "dataset-workflow-repair-preflight" | "dataset-workflow-reference-input" | "dataset-workflow-execution-prepare" | "dataset-workflow-execution-result" | "dataset-workflow-execution-consume" | "dataset-workflow-execution-observation" | "dataset-workflow-reference-verify" | "dataset-semantic-apply";
|
|
26
|
+
command: "dataset-curation-cleanup" | "dataset-tidas-import" | "dataset-context-pack" | "dataset-workflow-rows" | "dataset-workflow-assessment" | "dataset-workflow-identity" | "dataset-workflow-finalize" | "dataset-workflow-authorization" | "dataset-workflow-native-contract" | "dataset-workflow-repair-preflight" | "dataset-workflow-reference-input" | "dataset-workflow-execution-prepare" | "dataset-workflow-execution-result" | "dataset-workflow-execution-consume" | "dataset-workflow-execution-observation" | "dataset-workflow-reference-verify" | "dataset-workflow-interaction" | "dataset-semantic-apply";
|
|
27
27
|
options: JsonRecord;
|
|
28
28
|
task?: FoundryTaskOptions;
|
|
29
29
|
validateCurrent?: (index: readonly ArtifactEntry[]) => void;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
2
|
import { type QualifiedFoundryRuntime } from "./foundry-runtime-qualification.ts";
|
|
3
|
-
export
|
|
3
|
+
export interface FoundryAssessmentOptions {
|
|
4
|
+
/** Omit to retain the original all-set operation for direct callers. */
|
|
5
|
+
scopeType?: string;
|
|
6
|
+
previousAssessment?: string;
|
|
7
|
+
interactionSha256?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function assessFoundryWorkflowRows(context: FoundryRuntimeContext, qualified: QualifiedFoundryRuntime, rowsReport: string, contextReports: readonly string[], identityReport?: string, options?: FoundryAssessmentOptions): Promise<import("./foundry-task-types.ts").JsonRecord>;
|
|
@@ -10,22 +10,64 @@ import { runDatasetCurationGate } from "./import-curation/curation-gate.js";
|
|
|
10
10
|
import { runDatasetAuthoringTaskBuild } from "./import-curation/authoring-packages.js";
|
|
11
11
|
import { routeFoundryDecisionAction } from "./foundry-decision-routing.js";
|
|
12
12
|
import { prepareFoundryDecisionWork } from "./foundry-workflow-decisions.js";
|
|
13
|
+
import { currentWorkflowState, workflowAssessmentQueueScopeSha256, } from "./foundry-workflow-state.js";
|
|
14
|
+
import { currentFoundryInteractionState } from "./foundry-interaction-input.js";
|
|
15
|
+
import { applicableFoundryInteractionDigest, applicableFoundryInteractionProjection, } from "./foundry-interaction-projection.js";
|
|
13
16
|
import { createWorkflowStageDirectory, createWorkflowDirectory, registerWorkflowStageFiles, runWorkflowLocalCli, } from "./foundry-workflow-io.js";
|
|
14
17
|
function record(value) {
|
|
15
18
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
19
|
throw new FoundryContextError("workflow_report_invalid", "Stage metadata must be an object.");
|
|
17
20
|
return value;
|
|
18
21
|
}
|
|
19
|
-
export function assessFoundryWorkflowRows(context, qualified, rowsReport, contextReports, identityReport) {
|
|
22
|
+
export function assessFoundryWorkflowRows(context, qualified, rowsReport, contextReports, identityReport, options = {}) {
|
|
20
23
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
21
24
|
resolveFoundryAsset(context, "specs/prewrite-content-policy.json");
|
|
22
25
|
resolveFoundryAsset(context, "specs/import-profiles.json");
|
|
26
|
+
const previous = options.previousAssessment
|
|
27
|
+
? captureFoundryInput(options.previousAssessment)
|
|
28
|
+
: null;
|
|
29
|
+
if (previous)
|
|
30
|
+
readFoundryInput(context, previous.path);
|
|
31
|
+
if (options.previousAssessment && !options.scopeType)
|
|
32
|
+
throw new FoundryContextError("workflow_assessment_invalid", "An assessment predecessor requires a selected row set.");
|
|
33
|
+
let selectedState = null;
|
|
34
|
+
let selectedInteraction = null;
|
|
23
35
|
return runFoundryTaskOperation(context, {
|
|
24
36
|
command: "dataset-workflow-assessment",
|
|
25
37
|
options: {
|
|
26
38
|
rows_report: rowsReport,
|
|
27
39
|
context_reports: contextReports,
|
|
28
40
|
identity_report: identityReport ?? null,
|
|
41
|
+
...(options.scopeType
|
|
42
|
+
? {
|
|
43
|
+
scope_type: options.scopeType,
|
|
44
|
+
previous_assessment_sha256: previous?.sha256 ?? null,
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
...(options.interactionSha256 ? { interaction_sha256: options.interactionSha256 } : {}),
|
|
48
|
+
},
|
|
49
|
+
validateCurrent(index) {
|
|
50
|
+
const state = currentWorkflowState(context, index);
|
|
51
|
+
selectedState = state;
|
|
52
|
+
selectedInteraction = currentFoundryInteractionState(context, index);
|
|
53
|
+
if (state.rows?.file !== rowsReport)
|
|
54
|
+
throw new FoundryContextError("workflow_rows_changed", "Current rows changed before assessment.");
|
|
55
|
+
if ((state.identity?.value.status === "completed" ? state.identity.file : null) !==
|
|
56
|
+
(identityReport ?? null))
|
|
57
|
+
throw new FoundryContextError("workflow_identity_changed", "Current identity evidence changed before assessment.");
|
|
58
|
+
if (state.interactionSha256 !== (options.interactionSha256 ?? null))
|
|
59
|
+
throw new FoundryContextError("workflow_interaction_changed", "Current task decisions changed before assessment.");
|
|
60
|
+
if (!options.scopeType)
|
|
61
|
+
return;
|
|
62
|
+
const current = state.assessment;
|
|
63
|
+
if (current?.file === (previous?.path ?? null) || (!current && !previous))
|
|
64
|
+
return;
|
|
65
|
+
// A concurrent identical operation can have completed before this caller obtains the lock.
|
|
66
|
+
// The receipt path below will replay that exact result, without advancing another scope.
|
|
67
|
+
if (current?.value.previous_assessment === (previous?.path ?? null) &&
|
|
68
|
+
current.value.assessed_type === options.scopeType)
|
|
69
|
+
return;
|
|
70
|
+
throw new FoundryContextError("workflow_assessment_changed", "Assessment progress changed before this row set was checked.");
|
|
29
71
|
},
|
|
30
72
|
}, (operation) => {
|
|
31
73
|
for (const input of context.inputs)
|
|
@@ -42,6 +84,7 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
42
84
|
!Array.isArray(identity.sets)))
|
|
43
85
|
throw new FoundryContextError("workflow_identity_invalid", "Identity preflight must bind these current rows.");
|
|
44
86
|
const contracts = new Map();
|
|
87
|
+
const contractShaByType = new Map();
|
|
45
88
|
const retainedReports = (key) => {
|
|
46
89
|
const value = rows[key] ?? [];
|
|
47
90
|
if (!Array.isArray(value) || value.some((file) => typeof file !== "string"))
|
|
@@ -58,6 +101,7 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
58
101
|
if (value.status !== "completed" || typeof value.type !== "string")
|
|
59
102
|
throw new FoundryContextError("workflow_context_invalid", "A contract pack is incomplete.");
|
|
60
103
|
contracts.set(value.type, record(value.files));
|
|
104
|
+
contractShaByType.set(value.type, captureFoundryInput(file).sha256);
|
|
61
105
|
}
|
|
62
106
|
const output = createWorkflowStageDirectory(context, operation, "assessment");
|
|
63
107
|
fs.mkdirSync(resolveFoundryOutput(context, "tmp"), { recursive: true, mode: 0o700 });
|
|
@@ -70,9 +114,48 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
70
114
|
throw new FoundryContextError("runtime_tidas_unqualified", "Selected native bytes changed.");
|
|
71
115
|
const environment = createFoundryIsolatedChildEnvironment({ tempRoot: temporary });
|
|
72
116
|
const selectedSets = rows.sets.map(record);
|
|
117
|
+
for (const set of selectedSets) {
|
|
118
|
+
if (typeof set.type !== "string" || typeof set.file !== "string")
|
|
119
|
+
throw new FoundryContextError("workflow_rows_invalid", "A row set is invalid.");
|
|
120
|
+
readFoundryInput(context, set.file);
|
|
121
|
+
}
|
|
122
|
+
const previousReport = previous
|
|
123
|
+
? record(JSON.parse(readFoundryInput(context, previous.path).toString("utf8")))
|
|
124
|
+
: null;
|
|
125
|
+
const previousSets = selectedState?.assessment?.value.sets ?? [];
|
|
126
|
+
if (options.scopeType) {
|
|
127
|
+
if ((previousReport &&
|
|
128
|
+
(previousReport.schema !== "tiangong-foundry.assessment-stage.v1" ||
|
|
129
|
+
previousReport.owner_base !== context.assetRoot ||
|
|
130
|
+
!["in_progress", "completed"].includes(String(previousReport.status)))) ||
|
|
131
|
+
(previous && selectedState?.assessment?.file !== previous.path) ||
|
|
132
|
+
(!previous && selectedState?.assessment) ||
|
|
133
|
+
previousSets.length >= selectedSets.length ||
|
|
134
|
+
!selectedState?.assessmentRemainingTypes.includes(options.scopeType))
|
|
135
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Select the next row set against the current registered assessment progress.");
|
|
136
|
+
}
|
|
137
|
+
for (const set of previousSets) {
|
|
138
|
+
for (const key of [
|
|
139
|
+
"rows",
|
|
140
|
+
"schema_report",
|
|
141
|
+
"qa_report",
|
|
142
|
+
"curation_report",
|
|
143
|
+
"authoring_manifest",
|
|
144
|
+
"interaction_context",
|
|
145
|
+
]) {
|
|
146
|
+
const file = set[key];
|
|
147
|
+
if (file !== undefined)
|
|
148
|
+
readFoundryInput(context, String(file));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const queueScopeSha256 = workflowAssessmentQueueScopeSha256(selectedSets.map((set) => ({
|
|
152
|
+
type: String(set.type),
|
|
153
|
+
file: String(set.file),
|
|
154
|
+
count: Number(set.count),
|
|
155
|
+
})));
|
|
73
156
|
const processes = selectedSets.find((set) => set.type === "process");
|
|
74
157
|
let queueDir;
|
|
75
|
-
if (processes) {
|
|
158
|
+
if (processes && (!options.scopeType || ["flow", "process"].includes(options.scopeType))) {
|
|
76
159
|
if (typeof processes.file !== "string")
|
|
77
160
|
throw new FoundryContextError("workflow_rows_invalid", "Process rows are missing.");
|
|
78
161
|
queueDir = path.join(output, "queue");
|
|
@@ -97,8 +180,11 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
97
180
|
}
|
|
98
181
|
runWorkflowLocalCli(context, qualified, temporary, args);
|
|
99
182
|
}
|
|
100
|
-
const assessed =
|
|
101
|
-
|
|
183
|
+
const assessed = previousSets.map(record);
|
|
184
|
+
const toAssess = options.scopeType
|
|
185
|
+
? [selectedSets.find((set) => set.type === options.scopeType)]
|
|
186
|
+
: selectedSets;
|
|
187
|
+
for (const candidate of toAssess) {
|
|
102
188
|
const set = record(candidate);
|
|
103
189
|
if (typeof set.type !== "string" ||
|
|
104
190
|
typeof set.file !== "string" ||
|
|
@@ -195,6 +281,20 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
195
281
|
includeExecutionCommands: false,
|
|
196
282
|
},
|
|
197
283
|
});
|
|
284
|
+
const interactionDigest = applicableFoundryInteractionDigest(selectedInteraction?.state ?? null, set.type);
|
|
285
|
+
const interactionContext = selectedInteraction
|
|
286
|
+
? path.join(output, set.type, "interaction-context.json")
|
|
287
|
+
: null;
|
|
288
|
+
if (interactionContext && selectedInteraction) {
|
|
289
|
+
const projected = applicableFoundryInteractionProjection(selectedInteraction.state, set.type);
|
|
290
|
+
operation.writeJson(interactionContext, {
|
|
291
|
+
schema: projected.schema,
|
|
292
|
+
dataset_type: set.type,
|
|
293
|
+
source_state_sha256: selectedInteraction.entry.sha256,
|
|
294
|
+
decisions: projected.decisions,
|
|
295
|
+
ai_assumptions: projected.ai_assumptions,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
198
298
|
assessed.push({
|
|
199
299
|
type: set.type,
|
|
200
300
|
rows: set.file,
|
|
@@ -207,19 +307,40 @@ export function assessFoundryWorkflowRows(context, qualified, rowsReport, contex
|
|
|
207
307
|
authoring_status: authoring.status,
|
|
208
308
|
authoring_counts: authoring.counts,
|
|
209
309
|
decisions: decisionWork,
|
|
310
|
+
...(options.scopeType || selectedInteraction
|
|
311
|
+
? { context_report_sha256: contractShaByType.get(set.type) }
|
|
312
|
+
: {}),
|
|
313
|
+
...(queueScopeSha256 &&
|
|
314
|
+
["flow", "process"].includes(set.type) &&
|
|
315
|
+
(options.scopeType || selectedInteraction)
|
|
316
|
+
? { queue_scope_sha256: queueScopeSha256 }
|
|
317
|
+
: {}),
|
|
318
|
+
...(interactionDigest ? { interaction_digest: interactionDigest } : {}),
|
|
319
|
+
...(interactionContext ? { interaction_context: interactionContext } : {}),
|
|
210
320
|
});
|
|
211
321
|
}
|
|
322
|
+
const orderedAssessed = selectedSets
|
|
323
|
+
.map((set) => assessed.find((item) => item.type === set.type))
|
|
324
|
+
.filter((set) => Boolean(set));
|
|
212
325
|
for (const input of context.inputs)
|
|
213
326
|
readFoundryInput(context, input.path);
|
|
214
327
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
215
328
|
registerWorkflowStageFiles(context, operation, output);
|
|
216
329
|
const report = {
|
|
217
330
|
schema: "tiangong-foundry.assessment-stage.v1",
|
|
218
|
-
status: "completed",
|
|
331
|
+
status: orderedAssessed.length === selectedSets.length ? "completed" : "in_progress",
|
|
219
332
|
owner_base: context.assetRoot,
|
|
220
333
|
rows_report: rowsReport,
|
|
221
334
|
identity_report: identityReport ?? null,
|
|
222
|
-
sets:
|
|
335
|
+
sets: orderedAssessed,
|
|
336
|
+
...(options.scopeType
|
|
337
|
+
? {
|
|
338
|
+
previous_assessment: previous?.path ?? null,
|
|
339
|
+
previous_assessment_sha256: previous?.sha256 ?? null,
|
|
340
|
+
assessed_type: options.scopeType,
|
|
341
|
+
}
|
|
342
|
+
: {}),
|
|
343
|
+
...(options.interactionSha256 ? { interaction_sha256: options.interactionSha256 } : {}),
|
|
223
344
|
};
|
|
224
345
|
operation.writeJson(path.join(output, "foundry-assessment.json"), report);
|
|
225
346
|
return report;
|
|
@@ -17,7 +17,7 @@ import { createHash } from "node:crypto";
|
|
|
17
17
|
export async function finalizeFoundryWorkflow(context, qualified, entries, authentication = { mode: "oauth" }, approval, executionProgress) {
|
|
18
18
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
19
19
|
const state = currentWorkflowState(context, entries), rows = state.rows;
|
|
20
|
-
if (!rows || !state.assessment)
|
|
20
|
+
if (!rows || !state.assessment || !state.assessmentComplete)
|
|
21
21
|
throw new FoundryContextError("workflow_assessment_required", "Assess the current rows before finalization.");
|
|
22
22
|
const referenceOptions = new Map();
|
|
23
23
|
for (const set of rows.value.sets) {
|
|
@@ -266,10 +266,13 @@ export async function finalizeFoundryWorkflow(context, qualified, entries, authe
|
|
|
266
266
|
: {}),
|
|
267
267
|
},
|
|
268
268
|
validateCurrent(index) {
|
|
269
|
-
|
|
269
|
+
const current = currentWorkflowState(context, index);
|
|
270
|
+
if (current.rows?.entry.sha256 !== rows.entry.sha256)
|
|
270
271
|
throw new FoundryContextError("workflow_rows_changed", "Rows changed during finalization.");
|
|
271
|
-
if (
|
|
272
|
-
state.
|
|
272
|
+
if (!current.assessmentComplete ||
|
|
273
|
+
current.assessment?.entry.sha256 !== state.assessment?.entry.sha256)
|
|
274
|
+
throw new FoundryContextError("workflow_assessment_changed", "Assessment changed during finalization.");
|
|
275
|
+
if (current.referenceInputsSha256 !== state.referenceInputsSha256)
|
|
273
276
|
throw new FoundryContextError("reference_input_changed", "Reference selection changed during finalization.");
|
|
274
277
|
if (authorization &&
|
|
275
278
|
(createHash("sha256")
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FoundryRuntimeContext } from "./foundry-runtime-context.ts";
|
|
2
|
+
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
3
|
+
import { type SelectedFoundryInteractionInput } from "./foundry-interaction-input.ts";
|
|
4
|
+
export declare function recordFoundryInteractionInput(context: FoundryRuntimeContext, entries: readonly ArtifactEntry[], selected: SelectedFoundryInteractionInput, targetEntities: readonly string[]): Promise<Record<string, unknown>>;
|
|
@@ -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;
|