@leitwerk-dev/server 0.3.0 → 0.3.1
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/dist/{app-WfwKzrVk.d.ts → app-BuJCdkvy.d.ts} +82 -2
- package/dist/app-MSJXFK33.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-KIOQNNG6.js → chunk-HK6BLLHA.js} +738 -506
- package/dist/chunk-HK6BLLHA.js.map +1 -0
- package/dist/{chunk-LK3RO6C7.js → chunk-QCHS3X33.js} +486 -136
- package/dist/chunk-QCHS3X33.js.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/mapped-llm-run-repo.d.ts +56 -0
- package/dist/db/mapped-llm-run-repo.d.ts.map +1 -0
- package/dist/db/process-turn-record-repo.d.ts +3 -1
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/repo-helpers.d.ts +6 -0
- package/dist/db/repo-helpers.d.ts.map +1 -1
- package/dist/db/repositories.d.ts +4 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +415 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts +4 -14
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/launch-coordinator-test-harness.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/process-action-presenter.d.ts +16 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- package/dist/process-engine/mapped-turns.d.ts +45 -0
- package/dist/process-engine/mapped-turns.d.ts.map +1 -0
- package/dist/process-engine/operation.d.ts +1 -1
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts +2 -0
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +5 -0
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +8 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts +5 -0
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts.map +1 -0
- package/dist/process-engine/writes/writes.d.ts +18 -0
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-turn-navigation.d.ts +12 -2
- package/dist/process-turn-navigation.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +2 -1
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-diagnostics-assembler.d.ts +3 -1
- package/dist/routes/process-diagnostics-assembler.d.ts.map +1 -1
- package/dist/routes/process-primary-path-assembler.d.ts +4 -12
- package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
- package/dist/routes/process-route-helpers.d.ts +7 -32
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +2 -0
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +2 -2
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/test-helpers/accepted-turn-start.d.ts +18 -4
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/owned-test-deps.d.ts +18 -0
- package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +13 -10
- package/dist/testing.js.map +1 -1
- package/package.json +11 -11
- package/src/app.ts +2 -0
- package/src/db/database.ts +28 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-turn-record-repo.ts +8 -1
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +5 -0
- package/src/db/schema.ts +70 -1
- package/src/db/turn-start-record-repo.ts +5 -1
- package/src/domain-logic/outcome-tools.ts +50 -6
- package/src/future-execution-presenter.ts +10 -17
- package/src/launch-coordinator-test-harness.ts +8 -4
- package/src/process-action-presenter.ts +133 -0
- package/src/process-engine/engine.ts +2 -2
- package/src/process-engine/mapped-turns.ts +330 -0
- package/src/process-engine/operation.ts +1 -1
- package/src/process-engine/ops/accept-worker-turn-start.ts +6 -0
- package/src/process-engine/ops/retry-startup.ts +1 -0
- package/src/process-engine/ops/turn-outcome.ts +7 -5
- package/src/process-engine/recorder.ts +12 -0
- package/src/process-engine/runner.ts +8 -8
- package/src/process-engine/types.ts +6 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +1 -0
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +80 -20
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +5 -0
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +27 -0
- package/src/process-turn-navigation.ts +86 -8
- package/src/process-ui-snapshot-presenter.ts +40 -4
- package/src/routes/process-actions.ts +1 -1
- package/src/routes/process-diagnostics-assembler.ts +32 -6
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +8 -165
- package/src/supervisor/ipc-handler.ts +27 -18
- package/src/supervisor/worker-start-payload-builder.ts +25 -0
- package/src/supervisor/worker-supervisor.ts +2 -0
- package/src/supervisor/worker-turn-ipc-recorder.ts +13 -1
- package/src/test-helpers/accepted-turn-start.ts +51 -27
- package/src/test-helpers/owned-test-deps.ts +45 -0
- package/src/testing.ts +4 -1
- package/dist/app-4QSV4FUQ.js +0 -8
- package/dist/chunk-KIOQNNG6.js.map +0 -1
- package/dist/chunk-LK3RO6C7.js.map +0 -1
- /package/dist/{app-4QSV4FUQ.js.map → app-MSJXFK33.js.map} +0 -0
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
MappedTurnItemRef,
|
|
3
|
+
ProcessInstance,
|
|
4
|
+
ProcessProject,
|
|
5
|
+
TurnOutcomePayload,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
7
|
+
import { SafeOutcomePlanningError } from "@leitwerk-dev/process-sdk";
|
|
8
|
+
import type { RepositoryBundle } from "../../db/repositories.js";
|
|
2
9
|
import {
|
|
3
10
|
checkTurnOutcomeAvailability,
|
|
4
11
|
validateTurnOutcome,
|
|
@@ -8,6 +15,7 @@ import type { ProcessActionRegistry } from "../../process-action-registry.js";
|
|
|
8
15
|
import type { ProcessGraphRegistry } from "../../process-graph.js";
|
|
9
16
|
import { validateQueuedProcessInput } from "../../process-input-dispatch.js";
|
|
10
17
|
import type { TurnRecordMarkdownLookup } from "../../turn-result-markdown.js";
|
|
18
|
+
import { buildMappedItemOutcomeWrites } from "../mapped-turns.js";
|
|
11
19
|
import { buildServerTransitionWrites } from "./build-server-transition-writes.js";
|
|
12
20
|
import { buildTurnSelectionWrites } from "./build-turn-selection-writes.js";
|
|
13
21
|
import { createDeferredExtensionEvent } from "./deferred-extension-events.js";
|
|
@@ -30,6 +38,21 @@ function hasExplicitTurnSelectionChange(process: ProcessInstance, writes: Writes
|
|
|
30
38
|
);
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
function loadPreparedData(
|
|
42
|
+
process: ProcessInstance,
|
|
43
|
+
payload: TurnOutcomePayload,
|
|
44
|
+
events?: Pick<RepositoryBundle, "events">["events"],
|
|
45
|
+
): unknown {
|
|
46
|
+
const preparationEvent = events
|
|
47
|
+
?.listByInstanceTurnRecordEventTypes(process.id, payload.turnRecordId, ["turn.prepared"])
|
|
48
|
+
.at(-1);
|
|
49
|
+
return preparationEvent?.data &&
|
|
50
|
+
typeof preparationEvent.data === "object" &&
|
|
51
|
+
"data" in preparationEvent.data
|
|
52
|
+
? preparationEvent.data.data
|
|
53
|
+
: undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
33
56
|
async function buildProcessTurnOutcomeEffectWrites(
|
|
34
57
|
processGraphs: ProcessGraphRegistry,
|
|
35
58
|
process: ProcessInstance,
|
|
@@ -37,24 +60,34 @@ async function buildProcessTurnOutcomeEffectWrites(
|
|
|
37
60
|
payload: TurnOutcomePayload,
|
|
38
61
|
processActionRegistry: ProcessActionRegistry,
|
|
39
62
|
turnRecords: TurnRecordMarkdownLookup,
|
|
63
|
+
events?: Pick<RepositoryBundle, "events">["events"],
|
|
40
64
|
): Promise<WriteBuildResult> {
|
|
41
65
|
const serverDef = processActionRegistry.getServerDefinition(process.processId);
|
|
42
66
|
const handlers = serverDef?.turnOutcomeHandlers.get(payload.turnId) ?? [];
|
|
43
67
|
|
|
44
68
|
const { params, state } = processActionRegistry.resolveContextData(process.processId, process);
|
|
45
69
|
const plan = createProcessPlanCollector({ process, projects, params, state, turnRecords });
|
|
70
|
+
const prepared = loadPreparedData(process, payload, events);
|
|
46
71
|
|
|
47
72
|
for (const handler of handlers) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
try {
|
|
74
|
+
await handler(
|
|
75
|
+
{
|
|
76
|
+
turnRecordId: payload.turnRecordId,
|
|
77
|
+
turnId: payload.turnId,
|
|
78
|
+
outcome: payload.outcome,
|
|
79
|
+
params: payload.params ?? {},
|
|
80
|
+
turnResultMarkdown: payload.turnResultMarkdown ?? null,
|
|
81
|
+
...(prepared !== undefined ? { prepared } : {}),
|
|
82
|
+
},
|
|
83
|
+
plan.context,
|
|
84
|
+
);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof SafeOutcomePlanningError) {
|
|
87
|
+
return { ok: false, code: error.code, message: error.message };
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
58
91
|
}
|
|
59
92
|
|
|
60
93
|
for (const queuedInput of plan.queuedInputs) {
|
|
@@ -102,6 +135,12 @@ export interface TurnOutcomePlanningInput {
|
|
|
102
135
|
processGraphs: ProcessGraphRegistry;
|
|
103
136
|
/** @internal */
|
|
104
137
|
processActionRegistry: ProcessActionRegistry;
|
|
138
|
+
/** @internal */
|
|
139
|
+
events?: Pick<RepositoryBundle, "events">["events"];
|
|
140
|
+
/** @internal */
|
|
141
|
+
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
142
|
+
/** Mapped item executed by the accepted start, when any. @internal */
|
|
143
|
+
iteration?: MappedTurnItemRef | null;
|
|
105
144
|
}
|
|
106
145
|
|
|
107
146
|
/** @internal */
|
|
@@ -151,6 +190,34 @@ export async function buildTurnOutcomeWrites(
|
|
|
151
190
|
);
|
|
152
191
|
}
|
|
153
192
|
const processForEffects: ProcessInstance = { ...input.process, ...baseWrites.processPatch };
|
|
193
|
+
const outcomeEvent = createDeferredExtensionEvent(input.process.id, "turn_outcome", {
|
|
194
|
+
turnRecordId: input.payload.turnRecordId,
|
|
195
|
+
turnId: input.payload.turnId,
|
|
196
|
+
outcome: input.payload.outcome,
|
|
197
|
+
params: input.payload.params ?? {},
|
|
198
|
+
turnResultMarkdown: input.payload.turnResultMarkdown ?? null,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const mappedSpec = turnDefinition?.kind === "llm" ? turnDefinition.forEach : undefined;
|
|
202
|
+
if (mappedSpec) {
|
|
203
|
+
const mappedWrites = await buildMappedItemOutcomeWrites({
|
|
204
|
+
processGraphs: input.processGraphs,
|
|
205
|
+
registry: input.processActionRegistry,
|
|
206
|
+
mappedRuns: input.mappedRuns,
|
|
207
|
+
process: processForEffects,
|
|
208
|
+
projects: input.projects,
|
|
209
|
+
payload: input.payload,
|
|
210
|
+
spec: mappedSpec,
|
|
211
|
+
iteration: input.iteration,
|
|
212
|
+
prepared: loadPreparedData(processForEffects, input.payload, input.events),
|
|
213
|
+
});
|
|
214
|
+
if (isWriteBuildFailure(mappedWrites)) {
|
|
215
|
+
return mappedWrites;
|
|
216
|
+
}
|
|
217
|
+
const writes = mergeWrites(baseWrites, mappedWrites);
|
|
218
|
+
writes.extensionEvents.push(outcomeEvent);
|
|
219
|
+
return writes;
|
|
220
|
+
}
|
|
154
221
|
|
|
155
222
|
const effectWrites = await buildProcessTurnOutcomeEffectWrites(
|
|
156
223
|
input.processGraphs,
|
|
@@ -159,6 +226,7 @@ export async function buildTurnOutcomeWrites(
|
|
|
159
226
|
input.payload,
|
|
160
227
|
input.processActionRegistry,
|
|
161
228
|
input.turnRecords,
|
|
229
|
+
input.events,
|
|
162
230
|
);
|
|
163
231
|
if (isWriteBuildFailure(effectWrites)) {
|
|
164
232
|
return effectWrites;
|
|
@@ -195,15 +263,7 @@ export async function buildTurnOutcomeWrites(
|
|
|
195
263
|
}
|
|
196
264
|
}
|
|
197
265
|
|
|
198
|
-
writes.extensionEvents.push(
|
|
199
|
-
createDeferredExtensionEvent(input.process.id, "turn_outcome", {
|
|
200
|
-
turnRecordId: input.payload.turnRecordId,
|
|
201
|
-
turnId: input.payload.turnId,
|
|
202
|
-
outcome: input.payload.outcome,
|
|
203
|
-
params: input.payload.params ?? {},
|
|
204
|
-
turnResultMarkdown: input.payload.turnResultMarkdown ?? null,
|
|
205
|
-
}),
|
|
206
|
-
);
|
|
266
|
+
writes.extensionEvents.push(outcomeEvent);
|
|
207
267
|
|
|
208
268
|
return writes;
|
|
209
269
|
}
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
type TransitionTrigger,
|
|
6
6
|
type TurnId,
|
|
7
7
|
} from "@leitwerk-dev/domain";
|
|
8
|
-
import { generateId } from "../../db/repo-helpers.js";
|
|
9
8
|
import { tryTransition } from "../../domain-logic/process-state-machine.js";
|
|
10
9
|
import { getProcessTurnGraph, type ProcessGraphRegistry } from "../../process-graph.js";
|
|
11
10
|
import { selectedTurnRequiresWorker } from "../turn-worker-requirement.js";
|
|
11
|
+
import { reserveSelectedTurnStart } from "./reserve-selected-turn-start.js";
|
|
12
12
|
import {
|
|
13
13
|
appendProcessEvent,
|
|
14
14
|
applyProcessPatchField,
|
|
@@ -116,36 +116,7 @@ export function buildTurnSelectionWrites(
|
|
|
116
116
|
if (input.toTurnId && targetLifecycleStatus === "active") {
|
|
117
117
|
const target = getProcessTurnGraph(processGraphs, process.processId, input.toTurnId);
|
|
118
118
|
if (target?.turnType === "llm" || target?.turnType === "automatic") {
|
|
119
|
-
|
|
120
|
-
writes.turnStartWrites.push({
|
|
121
|
-
kind: "create",
|
|
122
|
-
input: {
|
|
123
|
-
id: startId,
|
|
124
|
-
instanceId: process.id,
|
|
125
|
-
turnId: input.toTurnId,
|
|
126
|
-
turnType: target.turnType,
|
|
127
|
-
proposedTurnRecordId: generateId("trn"),
|
|
128
|
-
startKind: "selected_turn",
|
|
129
|
-
recoveryTurnRecordId: null,
|
|
130
|
-
continuation: null,
|
|
131
|
-
state:
|
|
132
|
-
target.turnType === "automatic"
|
|
133
|
-
? { kind: "starting", start: { kind: "automatic" } }
|
|
134
|
-
: {
|
|
135
|
-
kind: "preparation_failed",
|
|
136
|
-
requestedModelProfileId: process.selectedTurnModelProfileId ?? null,
|
|
137
|
-
providerOptions: {},
|
|
138
|
-
code: "model_required",
|
|
139
|
-
safeSummary: "LLM start requires model preflight",
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
applyProcessPatchField(writes, process, "currentExecution", {
|
|
144
|
-
kind: "worker_start",
|
|
145
|
-
id: startId,
|
|
146
|
-
});
|
|
147
|
-
if (target.turnType === "llm")
|
|
148
|
-
applyProcessPatchField(writes, process, "lifecycleStatus", "error");
|
|
119
|
+
reserveSelectedTurnStart(writes, process, input.toTurnId, target.turnType);
|
|
149
120
|
}
|
|
150
121
|
} else if (
|
|
151
122
|
input.toTurnId === null ||
|
|
@@ -192,6 +192,11 @@ export function commitWrites(
|
|
|
192
192
|
return deps.transaction((repos) => {
|
|
193
193
|
const processBefore = repos.processes.getById(instanceId);
|
|
194
194
|
const committedTurnRecords: ProcessTurnRecord[] = [];
|
|
195
|
+
for (const write of writes.mappedRunWrites) {
|
|
196
|
+
if (write.kind === "create") repos.mappedRuns.create(write.input);
|
|
197
|
+
else if (write.kind === "complete_item") repos.mappedRuns.completeItem(write.input);
|
|
198
|
+
else repos.mappedRuns.abortActiveByInstance(instanceId);
|
|
199
|
+
}
|
|
195
200
|
for (const write of writes.turnStartWrites) {
|
|
196
201
|
if (write.kind === "create") repos.turnStarts.create(write.input);
|
|
197
202
|
else if (!repos.turnStarts.compareAndSetState(write)) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { MappedTurnItemRef, ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
|
+
import { generateId } from "../../db/repo-helpers.js";
|
|
3
|
+
import { applyProcessPatchField, type Writes } from "./writes.js";
|
|
4
|
+
|
|
5
|
+
/** Reserves a worker start without creating an attempt; acceptance creates the record. @internal */
|
|
6
|
+
export function reserveSelectedTurnStart(
|
|
7
|
+
writes: Writes,
|
|
8
|
+
process: ProcessInstance,
|
|
9
|
+
turnId: string,
|
|
10
|
+
turnType: "llm" | "automatic",
|
|
11
|
+
iteration?: MappedTurnItemRef,
|
|
12
|
+
): void {
|
|
13
|
+
const startId = generateId("tsr");
|
|
14
|
+
writes.turnStartWrites.push({
|
|
15
|
+
kind: "create",
|
|
16
|
+
input: {
|
|
17
|
+
id: startId,
|
|
18
|
+
instanceId: process.id,
|
|
19
|
+
turnId,
|
|
20
|
+
turnType,
|
|
21
|
+
proposedTurnRecordId: generateId("trn"),
|
|
22
|
+
startKind: "selected_turn",
|
|
23
|
+
recoveryTurnRecordId: null,
|
|
24
|
+
continuation: null,
|
|
25
|
+
state:
|
|
26
|
+
turnType === "automatic"
|
|
27
|
+
? { kind: "starting", start: { kind: "automatic" } }
|
|
28
|
+
: {
|
|
29
|
+
kind: "preparation_failed",
|
|
30
|
+
requestedModelProfileId: process.selectedTurnModelProfileId ?? null,
|
|
31
|
+
providerOptions: {},
|
|
32
|
+
code: "model_required",
|
|
33
|
+
safeSummary: "LLM start requires model preflight",
|
|
34
|
+
},
|
|
35
|
+
...(iteration ? { iteration } : {}),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
applyProcessPatchField(writes, process, "currentExecution", {
|
|
39
|
+
kind: "worker_start",
|
|
40
|
+
id: startId,
|
|
41
|
+
});
|
|
42
|
+
// Model preflight activates LLM starts before the worker can accept them.
|
|
43
|
+
if (turnType === "llm") applyProcessPatchField(writes, process, "lifecycleStatus", "error");
|
|
44
|
+
}
|
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
type TurnStartRecord,
|
|
8
8
|
} from "@leitwerk-dev/domain";
|
|
9
9
|
import type { DurableWsFrameInput } from "@leitwerk-dev/protocol";
|
|
10
|
+
import type {
|
|
11
|
+
CompleteMappedItemInput,
|
|
12
|
+
CreateMappedRunInput,
|
|
13
|
+
} from "../../db/mapped-llm-run-repo.js";
|
|
10
14
|
import type {
|
|
11
15
|
CreatePendingExternalSourceFireInput,
|
|
12
16
|
UpdatePendingExternalSourceFireInput,
|
|
@@ -92,6 +96,25 @@ export type TurnAnnotationWrite =
|
|
|
92
96
|
id: string;
|
|
93
97
|
};
|
|
94
98
|
|
|
99
|
+
/** Mapped-run writes, committed in order before turn starts. @internal */
|
|
100
|
+
export type MappedRunWrite =
|
|
101
|
+
| {
|
|
102
|
+
/** @internal */
|
|
103
|
+
kind: "create";
|
|
104
|
+
/** @internal */
|
|
105
|
+
input: CreateMappedRunInput;
|
|
106
|
+
}
|
|
107
|
+
| {
|
|
108
|
+
/** @internal */
|
|
109
|
+
kind: "complete_item";
|
|
110
|
+
/** @internal */
|
|
111
|
+
input: CompleteMappedItemInput;
|
|
112
|
+
}
|
|
113
|
+
| {
|
|
114
|
+
/** @internal */
|
|
115
|
+
kind: "abort_active";
|
|
116
|
+
};
|
|
117
|
+
|
|
95
118
|
/** @internal */
|
|
96
119
|
export type LeafOutcomeSnapshotWrite = {
|
|
97
120
|
/** @internal */
|
|
@@ -187,6 +210,8 @@ export interface Writes {
|
|
|
187
210
|
/** @internal */
|
|
188
211
|
turnStartWrites: TurnStartWrite[];
|
|
189
212
|
/** @internal */
|
|
213
|
+
mappedRunWrites: MappedRunWrite[];
|
|
214
|
+
/** @internal */
|
|
190
215
|
turnAnnotationWrites: TurnAnnotationWrite[];
|
|
191
216
|
/** @internal */
|
|
192
217
|
leafOutcomeSnapshotWrites: LeafOutcomeSnapshotWrite[];
|
|
@@ -226,6 +251,7 @@ export function createWrites(init: Partial<Writes> = {}): Writes {
|
|
|
226
251
|
...(init.projectWrite ? { projectWrite: init.projectWrite } : {}),
|
|
227
252
|
turnRecordWrites: [...(init.turnRecordWrites ?? [])],
|
|
228
253
|
turnStartWrites: [...(init.turnStartWrites ?? [])],
|
|
254
|
+
mappedRunWrites: [...(init.mappedRunWrites ?? [])],
|
|
229
255
|
turnAnnotationWrites: [...(init.turnAnnotationWrites ?? [])],
|
|
230
256
|
leafOutcomeSnapshotWrites: [...(init.leafOutcomeSnapshotWrites ?? [])],
|
|
231
257
|
events: [...(init.events ?? [])],
|
|
@@ -254,6 +280,7 @@ export function mergeWrites(...writesList: Array<Writes | undefined>): Writes {
|
|
|
254
280
|
}
|
|
255
281
|
merged.turnRecordWrites.push(...writes.turnRecordWrites);
|
|
256
282
|
merged.turnStartWrites.push(...writes.turnStartWrites);
|
|
283
|
+
merged.mappedRunWrites.push(...writes.mappedRunWrites);
|
|
257
284
|
merged.turnAnnotationWrites.push(...writes.turnAnnotationWrites);
|
|
258
285
|
merged.leafOutcomeSnapshotWrites.push(...writes.leafOutcomeSnapshotWrites);
|
|
259
286
|
merged.events.push(...writes.events);
|
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
MappedItem,
|
|
3
|
+
MappedRun,
|
|
4
|
+
ProcessLifecycleStatus,
|
|
5
|
+
ProcessTurnRecord,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
2
7
|
import type { ProcessGraphView } from "@leitwerk-dev/process-sdk";
|
|
3
|
-
import type { ProcessTimelineTurnSummary } from "@leitwerk-dev/protocol";
|
|
8
|
+
import type { ProcessTimelineIteration, ProcessTimelineTurnSummary } from "@leitwerk-dev/protocol";
|
|
9
|
+
|
|
10
|
+
/** Mapped runs and items of one process, joined for presentation. @internal */
|
|
11
|
+
export interface MappedRunPresentation {
|
|
12
|
+
/** @internal */
|
|
13
|
+
runs: readonly MappedRun[];
|
|
14
|
+
/** @internal */
|
|
15
|
+
items: readonly MappedItem[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function iterationFor(
|
|
19
|
+
run: MappedRun,
|
|
20
|
+
item: MappedItem | undefined,
|
|
21
|
+
index: number,
|
|
22
|
+
itemKey: string,
|
|
23
|
+
): ProcessTimelineIteration {
|
|
24
|
+
return {
|
|
25
|
+
runId: run.id,
|
|
26
|
+
itemKey,
|
|
27
|
+
index,
|
|
28
|
+
count: run.itemCount,
|
|
29
|
+
label: item?.label ?? itemKey,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function withItemLabel(description: string, iteration: ProcessTimelineIteration): string {
|
|
34
|
+
return `${description}: ${iteration.label}`;
|
|
35
|
+
}
|
|
4
36
|
|
|
5
37
|
/** Navigation retains human decisions omitted by the business-flow diagram. */
|
|
6
38
|
export function presentProcessTurnNavigation(input: {
|
|
@@ -8,20 +40,66 @@ export function presentProcessTurnNavigation(input: {
|
|
|
8
40
|
turns: readonly ProcessTimelineTurnSummary[];
|
|
9
41
|
selectedTurnId: string | null;
|
|
10
42
|
lifecycleStatus: ProcessLifecycleStatus;
|
|
43
|
+
turnRecords?: readonly Pick<ProcessTurnRecord, "id" | "iteration">[];
|
|
44
|
+
mapped?: MappedRunPresentation;
|
|
11
45
|
}): {
|
|
12
46
|
turns: ProcessTimelineTurnSummary[];
|
|
13
|
-
plannedNextTurn: {
|
|
47
|
+
plannedNextTurn: {
|
|
48
|
+
turnId: string;
|
|
49
|
+
description: string;
|
|
50
|
+
iteration?: ProcessTimelineIteration;
|
|
51
|
+
} | null;
|
|
14
52
|
} {
|
|
53
|
+
const runs = new Map(input.mapped?.runs.map((run) => [run.id, run]) ?? []);
|
|
54
|
+
const items = new Map(
|
|
55
|
+
input.mapped?.items.map((item) => [`${item.runId}:${item.itemIndex}`, item]) ?? [],
|
|
56
|
+
);
|
|
57
|
+
const iterationsByRecordId = new Map<string, ProcessTimelineIteration>();
|
|
58
|
+
for (const record of input.turnRecords ?? []) {
|
|
59
|
+
const ref = record.iteration;
|
|
60
|
+
const run = ref ? runs.get(ref.runId) : undefined;
|
|
61
|
+
if (!ref || !run) continue;
|
|
62
|
+
iterationsByRecordId.set(
|
|
63
|
+
record.id,
|
|
64
|
+
iterationFor(run, items.get(`${ref.runId}:${ref.itemIndex}`), ref.itemIndex, ref.itemKey),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const describe = (turnId: string) => input.graph.turns.get(turnId)?.description.trim();
|
|
68
|
+
|
|
69
|
+
const activeRun = input.mapped?.runs.find(
|
|
70
|
+
(run) => run.status === "active" && run.turnId === input.selectedTurnId,
|
|
71
|
+
);
|
|
72
|
+
const nextItem =
|
|
73
|
+
input.lifecycleStatus === "active" && activeRun
|
|
74
|
+
? items.get(`${activeRun.id}:${activeRun.nextIndex + 1}`)
|
|
75
|
+
: undefined;
|
|
15
76
|
const path = input.graph.happyPath ?? [];
|
|
16
77
|
const currentIndex = path.indexOf(input.selectedTurnId ?? "");
|
|
17
78
|
const nextId =
|
|
18
79
|
input.lifecycleStatus === "active" && currentIndex >= 0 ? path[currentIndex + 1] : undefined;
|
|
19
80
|
const next = nextId ? input.graph.turns.get(nextId) : undefined;
|
|
81
|
+
let plannedNextTurn: {
|
|
82
|
+
turnId: string;
|
|
83
|
+
description: string;
|
|
84
|
+
iteration?: ProcessTimelineIteration;
|
|
85
|
+
} | null = next && nextId ? { turnId: nextId, description: next.description } : null;
|
|
86
|
+
if (activeRun && nextItem) {
|
|
87
|
+
const iteration = iterationFor(activeRun, nextItem, nextItem.itemIndex, nextItem.itemKey);
|
|
88
|
+
plannedNextTurn = {
|
|
89
|
+
turnId: activeRun.turnId,
|
|
90
|
+
description: withItemLabel(describe(activeRun.turnId) || activeRun.turnId, iteration),
|
|
91
|
+
iteration,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
20
95
|
return {
|
|
21
|
-
turns: input.turns.map((turn) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
96
|
+
turns: input.turns.map((turn) => {
|
|
97
|
+
const displayTurn = describe(turn.turnId) || turn.displayTurn;
|
|
98
|
+
const iteration = iterationsByRecordId.get(turn.id);
|
|
99
|
+
return iteration
|
|
100
|
+
? { ...turn, displayTurn: withItemLabel(displayTurn, iteration), iteration }
|
|
101
|
+
: { ...turn, displayTurn };
|
|
102
|
+
}),
|
|
103
|
+
plannedNextTurn,
|
|
26
104
|
};
|
|
27
105
|
}
|
|
@@ -55,8 +55,10 @@ import {
|
|
|
55
55
|
} from "@leitwerk-dev/protocol";
|
|
56
56
|
import type { SessionSummary } from "./db/turn-summary-repo.js";
|
|
57
57
|
import { normalizeExternalObservation } from "./external-source-reporting.js";
|
|
58
|
+
import { getScheduledActionDetailForProcess } from "./future-execution-presenter.js";
|
|
58
59
|
import { physicalWorkerStarts } from "./physical-worker-starts.js";
|
|
59
60
|
import type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
|
|
61
|
+
import { listVisibleActionsForProcess } from "./process-action-presenter.js";
|
|
60
62
|
import { resolveCurrentExecutionTurnRecordId } from "./process-execution.js";
|
|
61
63
|
import { buildProcessFlowViewForProcess, getProcessGraph } from "./process-graph.js";
|
|
62
64
|
import { presentProcessInstanceTree } from "./process-instance-tree-presenter.js";
|
|
@@ -70,9 +72,7 @@ import {
|
|
|
70
72
|
import {
|
|
71
73
|
buildProcessLaunchConfigurationView,
|
|
72
74
|
buildProcessRunDetailsView,
|
|
73
|
-
getScheduledActionDetailForProcess,
|
|
74
75
|
getSelectedTurnSummaryForProcess,
|
|
75
|
-
listVisibleActionsForProcess,
|
|
76
76
|
processDefinesLeafOutcome,
|
|
77
77
|
type RouteDeps,
|
|
78
78
|
} from "./routes/process-route-helpers.js";
|
|
@@ -101,7 +101,7 @@ function sortEventsAscending(events: readonly ProcessEvent[]): ProcessEvent[] {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function compactDetailEvents(
|
|
104
|
-
deps: RouteDeps,
|
|
104
|
+
deps: Pick<RouteDeps, "events">,
|
|
105
105
|
instanceId: string,
|
|
106
106
|
turnRecords: readonly ProcessTurnRecord[],
|
|
107
107
|
): ProcessEvent[] {
|
|
@@ -1203,8 +1203,38 @@ export function buildProcessUiSnapshotProjections(input: {
|
|
|
1203
1203
|
};
|
|
1204
1204
|
}
|
|
1205
1205
|
|
|
1206
|
+
type ProcessUiSnapshotDeps = Pick<
|
|
1207
|
+
RouteDeps,
|
|
1208
|
+
| "processes"
|
|
1209
|
+
| "projects"
|
|
1210
|
+
| "inputs"
|
|
1211
|
+
| "events"
|
|
1212
|
+
| "turnRecords"
|
|
1213
|
+
| "mappedRuns"
|
|
1214
|
+
| "turnStarts"
|
|
1215
|
+
| "turnAnnotations"
|
|
1216
|
+
| "turnSummaries"
|
|
1217
|
+
| "leafOutcomeSnapshots"
|
|
1218
|
+
| "questionRequests"
|
|
1219
|
+
| "toolApprovalRequests"
|
|
1220
|
+
| "leases"
|
|
1221
|
+
| "startupObservations"
|
|
1222
|
+
| "futureExecutions"
|
|
1223
|
+
| "processGraphs"
|
|
1224
|
+
| "processActionRegistry"
|
|
1225
|
+
| "processUiRegistry"
|
|
1226
|
+
| "processModelPolicy"
|
|
1227
|
+
| "modelStatusCache"
|
|
1228
|
+
| "launcherService"
|
|
1229
|
+
| "sessionReader"
|
|
1230
|
+
| "sessionTransferService"
|
|
1231
|
+
| "externalSourceService"
|
|
1232
|
+
| "toolRenderers"
|
|
1233
|
+
| "config"
|
|
1234
|
+
>;
|
|
1235
|
+
|
|
1206
1236
|
export class ProcessUiSnapshotAssembler {
|
|
1207
|
-
constructor(private readonly deps:
|
|
1237
|
+
constructor(private readonly deps: ProcessUiSnapshotDeps) {}
|
|
1208
1238
|
|
|
1209
1239
|
async assemble(instanceId: string): Promise<ProcessDetailUiSnapshotResponseBody | null> {
|
|
1210
1240
|
const process = this.deps.processes.getById(instanceId);
|
|
@@ -1215,6 +1245,10 @@ export class ProcessUiSnapshotAssembler {
|
|
|
1215
1245
|
// combine process/turn state from opposite sides of a concurrent mutation.
|
|
1216
1246
|
const projects = this.deps.projects.listByInstance(instanceId);
|
|
1217
1247
|
const turnRecords = this.deps.turnRecords.listByInstance(instanceId);
|
|
1248
|
+
const mapped = {
|
|
1249
|
+
runs: this.deps.mappedRuns?.listByInstance(instanceId) ?? [],
|
|
1250
|
+
items: this.deps.mappedRuns?.listItemsByInstance(instanceId) ?? [],
|
|
1251
|
+
};
|
|
1218
1252
|
const events = compactDetailEvents(this.deps, instanceId, turnRecords);
|
|
1219
1253
|
const turnAnnotations = this.deps.turnAnnotations.listByInstance(instanceId);
|
|
1220
1254
|
const inputs = this.deps.inputs.listByInstance(instanceId);
|
|
@@ -1317,6 +1351,8 @@ export class ProcessUiSnapshotAssembler {
|
|
|
1317
1351
|
turns: projections.timeline.turns,
|
|
1318
1352
|
selectedTurnId: process.selectedTurnId,
|
|
1319
1353
|
lifecycleStatus: process.lifecycleStatus,
|
|
1354
|
+
turnRecords,
|
|
1355
|
+
mapped,
|
|
1320
1356
|
});
|
|
1321
1357
|
|
|
1322
1358
|
return {
|
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
6
6
|
import type { FutureExecutionLifecycle } from "../future-execution/index.js";
|
|
7
7
|
import { loadProviderOptionChoices } from "../model-providers/provider-options.js";
|
|
8
|
+
import { listVisibleActionsForProcess } from "../process-action-presenter.js";
|
|
8
9
|
import { sendEngineFailure } from "./process-engine-http.js";
|
|
9
10
|
import {
|
|
10
11
|
getProcessOrReply,
|
|
11
|
-
listVisibleActionsForProcess,
|
|
12
12
|
normalizeActionRequest,
|
|
13
13
|
normalizeContinueRequest,
|
|
14
14
|
normalizeRecoveryModelRequest,
|
|
@@ -9,22 +9,46 @@ import type {
|
|
|
9
9
|
ProcessDiagnosticsData,
|
|
10
10
|
ProcessRetryConfig,
|
|
11
11
|
} from "@leitwerk-dev/protocol/http-contracts";
|
|
12
|
+
import { getScheduledActionDetailForProcess } from "../future-execution-presenter.js";
|
|
13
|
+
import { listVisibleActionsForProcess } from "../process-action-presenter.js";
|
|
12
14
|
import { buildProcessFlowViewForProcess, serializeProcessGraph } from "../process-graph.js";
|
|
13
15
|
import { presentProcessModelConfiguration } from "../process-model-policy-presenter.js";
|
|
14
16
|
import { getProcessDisplayName } from "../process-operator-attention.js";
|
|
15
17
|
import {
|
|
16
18
|
buildProcessLaunchConfigurationView,
|
|
17
19
|
buildProcessRunDetailsView,
|
|
18
|
-
getScheduledActionDetailForProcess,
|
|
19
20
|
getSelectedTurnSummaryForProcess,
|
|
20
|
-
listVisibleActionsForProcess,
|
|
21
21
|
mergeProcessEventWindowsAscending,
|
|
22
22
|
processDefinesLeafOutcome,
|
|
23
23
|
type RouteDeps,
|
|
24
24
|
} from "./process-route-helpers.js";
|
|
25
25
|
|
|
26
|
+
type ProcessDiagnosticsDeps = Pick<
|
|
27
|
+
RouteDeps,
|
|
28
|
+
| "processes"
|
|
29
|
+
| "projects"
|
|
30
|
+
| "inputs"
|
|
31
|
+
| "events"
|
|
32
|
+
| "leafOutcomeSnapshots"
|
|
33
|
+
| "turnRecords"
|
|
34
|
+
| "turnStarts"
|
|
35
|
+
| "turnAnnotations"
|
|
36
|
+
| "leases"
|
|
37
|
+
| "processSkills"
|
|
38
|
+
| "futureExecutions"
|
|
39
|
+
| "processGraphs"
|
|
40
|
+
| "processActionRegistry"
|
|
41
|
+
| "processUiRegistry"
|
|
42
|
+
| "processModelPolicy"
|
|
43
|
+
| "modelStatusCache"
|
|
44
|
+
| "launcherService"
|
|
45
|
+
| "sessionReader"
|
|
46
|
+
| "toolRenderers"
|
|
47
|
+
| "config"
|
|
48
|
+
>;
|
|
49
|
+
|
|
26
50
|
export class ProcessDiagnosticsAssembler {
|
|
27
|
-
constructor(private readonly deps:
|
|
51
|
+
constructor(private readonly deps: ProcessDiagnosticsDeps) {}
|
|
28
52
|
|
|
29
53
|
async assembleDetail(instanceId: string): Promise<ProcessDiagnosticsData | null> {
|
|
30
54
|
const process = this.deps.processes.getById(instanceId);
|
|
@@ -32,7 +56,6 @@ export class ProcessDiagnosticsAssembler {
|
|
|
32
56
|
return null;
|
|
33
57
|
}
|
|
34
58
|
const projects = this.deps.projects.listByInstance(instanceId);
|
|
35
|
-
const piSessionTree = await this.deps.sessionReader.readPiSessionTree(instanceId);
|
|
36
59
|
const recentEvents = this.deps.events.listByInstance(instanceId, 500);
|
|
37
60
|
const retainedOperationalEvents = this.deps.events.listByInstanceEventTypes(
|
|
38
61
|
instanceId,
|
|
@@ -47,7 +70,9 @@ export class ProcessDiagnosticsAssembler {
|
|
|
47
70
|
availability: this.deps.modelStatusCache.snapshot(),
|
|
48
71
|
}),
|
|
49
72
|
);
|
|
50
|
-
|
|
73
|
+
// Capture durable facts and their derived presentation before session I/O yields
|
|
74
|
+
// to a concurrent process mutation. The session tree is a separate snapshot.
|
|
75
|
+
const detail: Omit<ProcessDiagnosticsData, "piSessionEntries"> = {
|
|
51
76
|
process,
|
|
52
77
|
projects,
|
|
53
78
|
inputs: this.deps.inputs.listByInstance(instanceId),
|
|
@@ -59,7 +84,6 @@ export class ProcessDiagnosticsAssembler {
|
|
|
59
84
|
processDisplayName: getProcessDisplayName(this.deps, process.processId),
|
|
60
85
|
processGraph: serializeProcessGraph(this.deps.processGraphs, process.processId),
|
|
61
86
|
processFlow: buildProcessFlowViewForProcess(this.deps.processGraphs, process.processId),
|
|
62
|
-
piSessionEntries: piSessionTree.entries,
|
|
63
87
|
definesLeafOutcome: processDefinesLeafOutcome(this.deps, process),
|
|
64
88
|
selectedTurn: getSelectedTurnSummaryForProcess(this.deps, process),
|
|
65
89
|
scheduledAction: getScheduledActionDetailForProcess(this.deps, process),
|
|
@@ -69,6 +93,8 @@ export class ProcessDiagnosticsAssembler {
|
|
|
69
93
|
actions: listVisibleActionsForProcess(this.deps, process),
|
|
70
94
|
toolRenderers: [...(this.deps.toolRenderers?.values() ?? [])],
|
|
71
95
|
};
|
|
96
|
+
const piSessionTree = await this.deps.sessionReader.readPiSessionTree(instanceId);
|
|
97
|
+
return { ...detail, piSessionEntries: piSessionTree.entries };
|
|
72
98
|
}
|
|
73
99
|
|
|
74
100
|
async assembleRetryConfig(instanceId: string): Promise<ProcessRetryConfig | null> {
|