@leitwerk-dev/worker 0.1.8 → 0.2.0
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/automatic-turn-executor.d.ts +1 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -1
- package/dist/{chunk-ZTJ7UAOC.js → chunk-Y7S2MZD3.js} +1423 -917
- package/dist/chunk-Y7S2MZD3.js.map +1 -0
- package/dist/connection-diagnostics.d.ts +5 -0
- package/dist/connection-diagnostics.d.ts.map +1 -0
- package/dist/container-entry-main.d.ts +2 -0
- package/dist/container-entry-main.d.ts.map +1 -0
- package/dist/container-entry-main.js +232 -0
- package/dist/container-entry-main.js.map +1 -0
- package/dist/container-entry.d.ts +14 -0
- package/dist/container-entry.d.ts.map +1 -0
- package/dist/development-tool-environment.d.ts +48 -0
- package/dist/development-tool-environment.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +9 -1
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/docker-registry-credentials.d.ts +8 -0
- package/dist/docker-registry-credentials.d.ts.map +1 -0
- package/dist/entry-runtime.d.ts +1 -0
- package/dist/entry-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/dist/input-consumer.d.ts +6 -11
- package/dist/input-consumer.d.ts.map +1 -1
- package/dist/ipc.d.ts +1 -0
- package/dist/ipc.d.ts.map +1 -1
- package/dist/logical-prompt-runner.d.ts.map +1 -1
- package/dist/managed-pi-bootstrap.d.ts.map +1 -1
- package/dist/missing-tool-recovery-runner.d.ts +4 -3
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -1
- package/dist/pi-adapter.d.ts +1 -0
- package/dist/pi-adapter.d.ts.map +1 -1
- package/dist/pi-event-reporter.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +11 -0
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/pre-turn-targeted-inputs.d.ts +8 -7
- package/dist/pre-turn-targeted-inputs.d.ts.map +1 -1
- package/dist/prompt-guards.d.ts.map +1 -1
- package/dist/repository-bash-tool.d.ts +4 -0
- package/dist/repository-bash-tool.d.ts.map +1 -0
- package/dist/resource-loader-factory.d.ts +1 -2
- package/dist/resource-loader-factory.d.ts.map +1 -1
- package/dist/result-image-upload.d.ts.map +1 -1
- package/dist/runtime/adapters.d.ts +2 -0
- package/dist/runtime/adapters.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +8 -5
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts +14 -18
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/failure-policy.d.ts +1 -0
- package/dist/runtime/failure-policy.d.ts.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reducer.d.ts +4 -1
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -1
- package/dist/runtime/llm-turn-execution.d.ts +3 -8
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -1
- package/dist/runtime/turn-execution.d.ts +2 -9
- package/dist/runtime/turn-execution.d.ts.map +1 -1
- package/dist/session-snapshot-exchange.d.ts +0 -4
- package/dist/session-snapshot-exchange.d.ts.map +1 -1
- package/dist/turn-continuation.d.ts.map +1 -1
- package/dist/turn-execution-error.d.ts +1 -1
- package/dist/turn-execution-error.d.ts.map +1 -1
- package/dist/turn-execution-result.d.ts +1 -0
- package/dist/turn-execution-result.d.ts.map +1 -1
- package/dist/turn-outcome-tool-session.d.ts +0 -2
- package/dist/turn-outcome-tool-session.d.ts.map +1 -1
- package/dist/turn-result-markdown.d.ts +2 -1
- package/dist/turn-result-markdown.d.ts.map +1 -1
- package/dist/turn-tree-strategy.d.ts +0 -1
- package/dist/turn-tree-strategy.d.ts.map +1 -1
- package/dist/worker-entry.js +16 -4
- package/dist/worker-entry.js.map +1 -1
- package/dist/worker-ipc-reporter.d.ts.map +1 -1
- package/dist/workspace/manifest.d.ts +4 -7
- package/dist/workspace/manifest.d.ts.map +1 -1
- package/dist/workspace/node-run-root-git-ops.d.ts +2 -2
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -1
- package/dist/workspace/resource-aggregator.d.ts.map +1 -1
- package/dist/workspace/run-root.d.ts +9 -20
- package/dist/workspace/run-root.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/automatic-turn-executor.ts +2 -0
- package/src/connection-diagnostics.ts +27 -0
- package/src/container-entry-main.ts +24 -0
- package/src/container-entry.ts +246 -0
- package/src/development-tool-environment.ts +452 -0
- package/src/diagnostics.ts +3 -1
- package/src/docker-registry-credentials.ts +65 -0
- package/src/entry-runtime.ts +5 -4
- package/src/index.ts +11 -0
- package/src/input-consumer.ts +7 -29
- package/src/ipc.ts +37 -2
- package/src/logical-prompt-runner.ts +23 -29
- package/src/managed-pi-bootstrap.ts +3 -3
- package/src/missing-tool-recovery-runner.ts +4 -18
- package/src/pi-adapter.ts +19 -50
- package/src/pi-event-reporter.ts +16 -38
- package/src/pi-resource-bundle.ts +67 -1
- package/src/pre-turn-targeted-inputs.ts +9 -11
- package/src/prompt-guards.ts +44 -75
- package/src/repository-bash-tool.ts +15 -0
- package/src/resource-loader-factory.ts +1 -18
- package/src/result-image-upload.ts +16 -27
- package/src/runtime/adapters.ts +2 -0
- package/src/runtime/bootstrap-session.ts +69 -39
- package/src/runtime/bootstrap.ts +160 -103
- package/src/runtime/failure-policy.ts +36 -42
- package/src/runtime/index.ts +49 -14
- package/src/runtime/lifecycle-reducer.ts +140 -173
- package/src/runtime/llm-turn-execution.ts +13 -30
- package/src/runtime/turn-execution.ts +91 -9
- package/src/session-snapshot-exchange.ts +23 -64
- package/src/turn-continuation.ts +9 -17
- package/src/turn-execution-error.ts +3 -11
- package/src/turn-execution-result.ts +1 -0
- package/src/turn-outcome-tool-session.ts +25 -21
- package/src/turn-result-markdown.ts +31 -34
- package/src/turn-tree-strategy.ts +6 -19
- package/src/worker-entry.ts +8 -0
- package/src/worker-ipc-reporter.ts +8 -16
- package/src/workspace/manifest.ts +5 -7
- package/src/workspace/node-run-root-git-ops.ts +65 -25
- package/src/workspace/resource-aggregator.ts +5 -16
- package/src/workspace/run-root.ts +38 -89
- package/dist/automatic-turn-executor.js +0 -58
- package/dist/automatic-turn-executor.js.map +0 -1
- package/dist/chunk-ZTJ7UAOC.js.map +0 -1
- package/dist/diagnostics.js +0 -51
- package/dist/diagnostics.js.map +0 -1
- package/dist/entry-runtime.js +0 -160
- package/dist/entry-runtime.js.map +0 -1
- package/dist/event-translator.js +0 -12
- package/dist/event-translator.js.map +0 -1
- package/dist/extension-entry-roots.js +0 -41
- package/dist/extension-entry-roots.js.map +0 -1
- package/dist/identified-pi-entry.js +0 -125
- package/dist/identified-pi-entry.js.map +0 -1
- package/dist/input-consumer.js +0 -34
- package/dist/input-consumer.js.map +0 -1
- package/dist/integration-tool-bridge.js +0 -53
- package/dist/integration-tool-bridge.js.map +0 -1
- package/dist/ipc.js +0 -192
- package/dist/ipc.js.map +0 -1
- package/dist/logical-prompt-runner.js +0 -225
- package/dist/logical-prompt-runner.js.map +0 -1
- package/dist/managed-pi-agent-dir.js +0 -66
- package/dist/managed-pi-agent-dir.js.map +0 -1
- package/dist/managed-pi-bootstrap.js +0 -135
- package/dist/managed-pi-bootstrap.js.map +0 -1
- package/dist/missing-tool-recovery-runner.js +0 -73
- package/dist/missing-tool-recovery-runner.js.map +0 -1
- package/dist/pi-adapter.js +0 -1648
- package/dist/pi-adapter.js.map +0 -1
- package/dist/pi-branch-guard.js +0 -75
- package/dist/pi-branch-guard.js.map +0 -1
- package/dist/pi-event-reporter.js +0 -136
- package/dist/pi-event-reporter.js.map +0 -1
- package/dist/pi-resource-bundle.js +0 -58
- package/dist/pi-resource-bundle.js.map +0 -1
- package/dist/pre-turn-targeted-inputs.js +0 -101
- package/dist/pre-turn-targeted-inputs.js.map +0 -1
- package/dist/prompt-guards.js +0 -318
- package/dist/prompt-guards.js.map +0 -1
- package/dist/question-bridge.js +0 -24
- package/dist/question-bridge.js.map +0 -1
- package/dist/question-tool.js +0 -54
- package/dist/question-tool.js.map +0 -1
- package/dist/replaying-request-bridge.js +0 -71
- package/dist/replaying-request-bridge.js.map +0 -1
- package/dist/resource-loader-factory.js +0 -87
- package/dist/resource-loader-factory.js.map +0 -1
- package/dist/result-image-upload.js +0 -183
- package/dist/result-image-upload.js.map +0 -1
- package/dist/runtime/adapters.js +0 -15
- package/dist/runtime/adapters.js.map +0 -1
- package/dist/runtime/bootstrap-session.js +0 -199
- package/dist/runtime/bootstrap-session.js.map +0 -1
- package/dist/runtime/bootstrap.js +0 -440
- package/dist/runtime/bootstrap.js.map +0 -1
- package/dist/runtime/failure-policy.js +0 -182
- package/dist/runtime/failure-policy.js.map +0 -1
- package/dist/runtime/index.js +0 -336
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/lifecycle-reducer.js +0 -1100
- package/dist/runtime/lifecycle-reducer.js.map +0 -1
- package/dist/runtime/llm-turn-execution.js +0 -494
- package/dist/runtime/llm-turn-execution.js.map +0 -1
- package/dist/runtime/settings.js +0 -24
- package/dist/runtime/settings.js.map +0 -1
- package/dist/runtime/snapshot-policy.js +0 -16
- package/dist/runtime/snapshot-policy.js.map +0 -1
- package/dist/runtime/turn-execution.js +0 -121
- package/dist/runtime/turn-execution.js.map +0 -1
- package/dist/session-snapshot-exchange.js +0 -102
- package/dist/session-snapshot-exchange.js.map +0 -1
- package/dist/test-helpers/fake-websocket.js +0 -40
- package/dist/test-helpers/fake-websocket.js.map +0 -1
- package/dist/test-helpers/ipc-harness.d.ts +0 -11
- package/dist/test-helpers/ipc-harness.d.ts.map +0 -1
- package/dist/test-helpers/ipc-harness.js +0 -17
- package/dist/test-helpers/ipc-harness.js.map +0 -1
- package/dist/turn-continuation.js +0 -80
- package/dist/turn-continuation.js.map +0 -1
- package/dist/turn-execution-error.js +0 -64
- package/dist/turn-execution-error.js.map +0 -1
- package/dist/turn-execution-result.js +0 -21
- package/dist/turn-execution-result.js.map +0 -1
- package/dist/turn-outcome-tool-session.js +0 -210
- package/dist/turn-outcome-tool-session.js.map +0 -1
- package/dist/turn-record-id.js +0 -10
- package/dist/turn-record-id.js.map +0 -1
- package/dist/turn-result-markdown.js +0 -263
- package/dist/turn-result-markdown.js.map +0 -1
- package/dist/turn-tree-strategy.js +0 -80
- package/dist/turn-tree-strategy.js.map +0 -1
- package/dist/worker-http.js +0 -9
- package/dist/worker-http.js.map +0 -1
- package/dist/worker-ipc-reporter.js +0 -58
- package/dist/worker-ipc-reporter.js.map +0 -1
- package/dist/worker-payloads.js +0 -66
- package/dist/worker-payloads.js.map +0 -1
- package/dist/worker-start-payload.js +0 -5
- package/dist/worker-start-payload.js.map +0 -1
- package/dist/workspace/manifest.js +0 -79
- package/dist/workspace/manifest.js.map +0 -1
- package/dist/workspace/node-run-root-git-ops.js +0 -96
- package/dist/workspace/node-run-root-git-ops.js.map +0 -1
- package/dist/workspace/resource-aggregator.js +0 -39
- package/dist/workspace/resource-aggregator.js.map +0 -1
- package/dist/workspace/run-root.js +0 -209
- package/dist/workspace/run-root.js.map +0 -1
- package/src/test-helpers/ipc-harness.ts +0 -19
|
@@ -33,7 +33,7 @@ export type WorkerRuntimeStateName =
|
|
|
33
33
|
/** Compatibility type used by pure failure normalization. */
|
|
34
34
|
export type WorkerRuntimeState = WorkerRuntimeStateName;
|
|
35
35
|
export type ReportedWorkerState = "idle" | "busy" | "draining";
|
|
36
|
-
export type WorkerTimerName = "heartbeat" | "acceptance_retry" | "credential_poll";
|
|
36
|
+
export type WorkerTimerName = "heartbeat" | "acceptance_retry" | "credential_poll" | "terminal_ack";
|
|
37
37
|
|
|
38
38
|
type ActiveTurnStatus = "pending" | "executing" | "completed";
|
|
39
39
|
type DrainingOperation =
|
|
@@ -108,6 +108,10 @@ type PublicationState =
|
|
|
108
108
|
};
|
|
109
109
|
terminal: PendingTerminal;
|
|
110
110
|
}
|
|
111
|
+
| {
|
|
112
|
+
kind: "terminal_pending_ack";
|
|
113
|
+
terminal: PendingTerminal;
|
|
114
|
+
}
|
|
111
115
|
| {
|
|
112
116
|
kind: "cleanup_snapshot";
|
|
113
117
|
snapshot: {
|
|
@@ -282,7 +286,12 @@ export function createInitialWorkerRuntimeState(): WorkerRuntimeStateMachine {
|
|
|
282
286
|
publication: { kind: "none" },
|
|
283
287
|
},
|
|
284
288
|
credential: null,
|
|
285
|
-
timers: {
|
|
289
|
+
timers: {
|
|
290
|
+
heartbeat: null,
|
|
291
|
+
acceptance_retry: null,
|
|
292
|
+
credential_poll: null,
|
|
293
|
+
terminal_ack: null,
|
|
294
|
+
},
|
|
286
295
|
};
|
|
287
296
|
}
|
|
288
297
|
|
|
@@ -291,7 +300,8 @@ export function deriveReportedWorkerState(state: WorkerRuntimeStateMachine): Rep
|
|
|
291
300
|
if (
|
|
292
301
|
(state.phase.kind === "active" &&
|
|
293
302
|
(state.phase.turnStatus === "executing" ||
|
|
294
|
-
state.work.publication.kind === "terminal_snapshot"
|
|
303
|
+
state.work.publication.kind === "terminal_snapshot" ||
|
|
304
|
+
state.work.publication.kind === "terminal_pending_ack")) ||
|
|
295
305
|
state.work.deliveryHeadSequence !== null
|
|
296
306
|
)
|
|
297
307
|
return "busy";
|
|
@@ -405,87 +415,39 @@ function hasActivePublication(state: WorkerRuntimeStateMachine): boolean {
|
|
|
405
415
|
return state.work.publication.kind !== "none";
|
|
406
416
|
}
|
|
407
417
|
|
|
408
|
-
function
|
|
409
|
-
if (hasActivePublication(state)) throw new Error("Snapshot publication is already active");
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function beginReadySnapshot(
|
|
413
|
-
state: WorkerRuntimeStateMachine,
|
|
414
|
-
source: WorkerSnapshotSource,
|
|
415
|
-
outputs: WorkerRuntimeOutput[],
|
|
416
|
-
): WorkerRuntimeStateMachine {
|
|
417
|
-
requireNoPublication(state);
|
|
418
|
-
const snapshot = {
|
|
419
|
-
point: "after_worker_ready" as const,
|
|
420
|
-
turnRecordId: null,
|
|
421
|
-
required: false as const,
|
|
422
|
-
};
|
|
423
|
-
outputs.push({ kind: "upload_snapshot", ...snapshot, source });
|
|
424
|
-
return {
|
|
425
|
-
...state,
|
|
426
|
-
work: { ...state.work, publication: { kind: "ready_snapshot", snapshot } },
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function beginTerminalSnapshot(
|
|
418
|
+
function beginSnapshot(
|
|
431
419
|
state: WorkerRuntimeStateMachine,
|
|
432
|
-
|
|
433
|
-
turnRecordId: string,
|
|
434
|
-
terminal: PendingTerminal,
|
|
420
|
+
publication: Extract<PublicationState, { snapshot: SnapshotCompletionEvent }>,
|
|
435
421
|
source: WorkerSnapshotSource,
|
|
436
422
|
outputs: WorkerRuntimeOutput[],
|
|
437
423
|
): WorkerRuntimeStateMachine {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return {
|
|
442
|
-
...state,
|
|
443
|
-
work: {
|
|
444
|
-
...state.work,
|
|
445
|
-
publication: { kind: "terminal_snapshot", snapshot, terminal },
|
|
446
|
-
},
|
|
447
|
-
};
|
|
424
|
+
if (hasActivePublication(state)) throw new Error("Snapshot publication is already active");
|
|
425
|
+
outputs.push({ kind: "upload_snapshot", ...publication.snapshot, source });
|
|
426
|
+
return { ...state, work: { ...state.work, publication } };
|
|
448
427
|
}
|
|
449
428
|
|
|
450
|
-
|
|
451
|
-
state: WorkerRuntimeStateMachine,
|
|
452
|
-
source: WorkerSnapshotSource,
|
|
453
|
-
outputs: WorkerRuntimeOutput[],
|
|
454
|
-
): WorkerRuntimeStateMachine {
|
|
455
|
-
requireNoPublication(state);
|
|
456
|
-
const snapshot = {
|
|
457
|
-
point: "before_cleanup_completed" as const,
|
|
458
|
-
turnRecordId: null,
|
|
459
|
-
required: true as const,
|
|
460
|
-
};
|
|
461
|
-
outputs.push({ kind: "upload_snapshot", ...snapshot, source });
|
|
462
|
-
return {
|
|
463
|
-
...state,
|
|
464
|
-
work: { ...state.work, publication: { kind: "cleanup_snapshot", snapshot } },
|
|
465
|
-
};
|
|
466
|
-
}
|
|
429
|
+
const TERMINAL_ACK_RETRY_MS = 5_000;
|
|
467
430
|
|
|
468
|
-
function
|
|
431
|
+
function publishTerminalAndAwaitAcknowledgement(
|
|
469
432
|
state: WorkerRuntimeStateMachine,
|
|
470
|
-
|
|
471
|
-
source: WorkerSnapshotSource,
|
|
472
|
-
afterSnapshot: "exit" | "cleanup",
|
|
433
|
+
terminal: PendingTerminal,
|
|
473
434
|
outputs: WorkerRuntimeOutput[],
|
|
474
435
|
): WorkerRuntimeStateMachine {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
work: {
|
|
485
|
-
...state.work,
|
|
486
|
-
publication: { kind: "fatal_snapshot", snapshot, fatal, afterSnapshot },
|
|
436
|
+
outputs.push(terminal.fact);
|
|
437
|
+
if (terminal.park) outputs.push(protocol("worker.lifecycle_parked", terminal.park));
|
|
438
|
+
return armTimer(
|
|
439
|
+
{
|
|
440
|
+
...state,
|
|
441
|
+
work: {
|
|
442
|
+
...state.work,
|
|
443
|
+
publication: { kind: "terminal_pending_ack", terminal },
|
|
444
|
+
},
|
|
487
445
|
},
|
|
488
|
-
|
|
446
|
+
outputs,
|
|
447
|
+
"terminal_ack",
|
|
448
|
+
TERMINAL_ACK_RETRY_MS,
|
|
449
|
+
terminal.correlation.turnRecordId,
|
|
450
|
+
);
|
|
489
451
|
}
|
|
490
452
|
|
|
491
453
|
function finishFatal(
|
|
@@ -539,7 +501,17 @@ function failureOutputs(
|
|
|
539
501
|
state.phase.kind === "cleaning" && state.phase.stage === "publication"
|
|
540
502
|
? "cleanup"
|
|
541
503
|
: "exit";
|
|
542
|
-
next =
|
|
504
|
+
next = beginSnapshot(
|
|
505
|
+
next,
|
|
506
|
+
{
|
|
507
|
+
kind: "fatal_snapshot",
|
|
508
|
+
snapshot: { point: "before_worker_failed", turnRecordId: null, required: false },
|
|
509
|
+
fatal,
|
|
510
|
+
afterSnapshot,
|
|
511
|
+
},
|
|
512
|
+
disposition.snapshot.source,
|
|
513
|
+
outputs,
|
|
514
|
+
);
|
|
543
515
|
break;
|
|
544
516
|
}
|
|
545
517
|
const finished = finishFatal(next, fatal);
|
|
@@ -704,11 +676,15 @@ function advance(
|
|
|
704
676
|
)
|
|
705
677
|
: { upload: false as const };
|
|
706
678
|
if (cleanupSnapshot.upload && next.session) {
|
|
707
|
-
next =
|
|
679
|
+
next = beginSnapshot(
|
|
708
680
|
{
|
|
709
681
|
...next,
|
|
710
682
|
phase: { kind: "cleaning", reason, exitAfterCleanup, stage: "publication" },
|
|
711
683
|
},
|
|
684
|
+
{
|
|
685
|
+
kind: "cleanup_snapshot",
|
|
686
|
+
snapshot: { point: "before_cleanup_completed", turnRecordId: null, required: true },
|
|
687
|
+
},
|
|
712
688
|
sessionSnapshotSource(next.session),
|
|
713
689
|
outputs,
|
|
714
690
|
);
|
|
@@ -814,9 +790,11 @@ export function reduceWorkerRuntime(
|
|
|
814
790
|
if (state.phase.kind !== "init") break;
|
|
815
791
|
next = { ...state, phase: { kind: "waiting_for_start" } };
|
|
816
792
|
outputs.push(HELLO);
|
|
793
|
+
outputs.push(protocol("worker.bootstrap_progress", { phase: "worker_connected" }));
|
|
817
794
|
break;
|
|
818
795
|
case "transport_connected":
|
|
819
796
|
outputs.push(HELLO);
|
|
797
|
+
outputs.push(protocol("worker.bootstrap_progress", { phase: "worker_connected" }));
|
|
820
798
|
if (state.session) {
|
|
821
799
|
outputs.push(
|
|
822
800
|
protocol("worker.heartbeat", {
|
|
@@ -826,6 +804,13 @@ export function reduceWorkerRuntime(
|
|
|
826
804
|
}),
|
|
827
805
|
);
|
|
828
806
|
}
|
|
807
|
+
if (state.work.publication.kind === "terminal_pending_ack") {
|
|
808
|
+
next = publishTerminalAndAwaitAcknowledgement(
|
|
809
|
+
state,
|
|
810
|
+
state.work.publication.terminal,
|
|
811
|
+
outputs,
|
|
812
|
+
);
|
|
813
|
+
}
|
|
829
814
|
break;
|
|
830
815
|
case "transport_failed": {
|
|
831
816
|
const failed = failureOutputs(state, { kind: "transport", error: event.error });
|
|
@@ -866,7 +851,12 @@ export function reduceWorkerRuntime(
|
|
|
866
851
|
outputs.push({ kind: "cancel_timer", name });
|
|
867
852
|
next = {
|
|
868
853
|
...next,
|
|
869
|
-
timers: {
|
|
854
|
+
timers: {
|
|
855
|
+
heartbeat: null,
|
|
856
|
+
acceptance_retry: null,
|
|
857
|
+
credential_poll: null,
|
|
858
|
+
terminal_ack: null,
|
|
859
|
+
},
|
|
870
860
|
credential: null,
|
|
871
861
|
};
|
|
872
862
|
break;
|
|
@@ -910,6 +900,7 @@ export function reduceWorkerRuntime(
|
|
|
910
900
|
},
|
|
911
901
|
sessionTainted: false,
|
|
912
902
|
};
|
|
903
|
+
outputs.push(protocol("worker.bootstrap_progress", { phase: "preparing_workspace" }));
|
|
913
904
|
outputs.push({ kind: "bootstrap", startRecordId, payload: message.payload });
|
|
914
905
|
break;
|
|
915
906
|
}
|
|
@@ -942,6 +933,21 @@ export function reduceWorkerRuntime(
|
|
|
942
933
|
);
|
|
943
934
|
break;
|
|
944
935
|
}
|
|
936
|
+
if (message.type === "worker.turn_terminal_recorded") {
|
|
937
|
+
const publication = state.work.publication;
|
|
938
|
+
if (
|
|
939
|
+
publication.kind !== "terminal_pending_ack" ||
|
|
940
|
+
publication.terminal.correlation.turnRecordId !== message.payload.turnRecordId
|
|
941
|
+
)
|
|
942
|
+
break;
|
|
943
|
+
outputs.push({ kind: "cancel_timer", name: "terminal_ack" });
|
|
944
|
+
next = {
|
|
945
|
+
...state,
|
|
946
|
+
work: { ...state.work, publication: { kind: "none" } },
|
|
947
|
+
timers: { ...state.timers, terminal_ack: null },
|
|
948
|
+
};
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
945
951
|
if (message.type === "worker.credential_update_accepted") {
|
|
946
952
|
const credential = state.credential;
|
|
947
953
|
if (
|
|
@@ -1029,6 +1035,8 @@ export function reduceWorkerRuntime(
|
|
|
1029
1035
|
kind: "diagnostic",
|
|
1030
1036
|
payload: { level: "warn", code: "bootstrap.diagnostic", message },
|
|
1031
1037
|
});
|
|
1038
|
+
outputs.push(protocol("worker.bootstrap_progress", { phase: "loading_resources" }));
|
|
1039
|
+
outputs.push(protocol("worker.bootstrap_progress", { phase: "preparing_turn" }));
|
|
1032
1040
|
outputs.push(protocol("worker.ready", completion.readyPayload));
|
|
1033
1041
|
if (wasDraining) break;
|
|
1034
1042
|
const readySnapshot = resolveWorkerSnapshotPolicy(
|
|
@@ -1037,7 +1045,15 @@ export function reduceWorkerRuntime(
|
|
|
1037
1045
|
completion.session.piAvailable,
|
|
1038
1046
|
);
|
|
1039
1047
|
if (readySnapshot.upload)
|
|
1040
|
-
next =
|
|
1048
|
+
next = beginSnapshot(
|
|
1049
|
+
next,
|
|
1050
|
+
{
|
|
1051
|
+
kind: "ready_snapshot",
|
|
1052
|
+
snapshot: { point: "after_worker_ready", turnRecordId: null, required: false },
|
|
1053
|
+
},
|
|
1054
|
+
sessionSnapshotSource(completion.session),
|
|
1055
|
+
outputs,
|
|
1056
|
+
);
|
|
1041
1057
|
next = armTimer(
|
|
1042
1058
|
next,
|
|
1043
1059
|
outputs,
|
|
@@ -1108,7 +1124,13 @@ export function reduceWorkerRuntime(
|
|
|
1108
1124
|
});
|
|
1109
1125
|
break;
|
|
1110
1126
|
case "activation_failed":
|
|
1111
|
-
|
|
1127
|
+
case "turn_defect":
|
|
1128
|
+
if (
|
|
1129
|
+
event.kind === "activation_failed"
|
|
1130
|
+
? !matchesActivation(state, event.startRecordId, event.turnRecordId)
|
|
1131
|
+
: !matchesTurn(state, event.turnRecordId)
|
|
1132
|
+
)
|
|
1133
|
+
break;
|
|
1112
1134
|
if (state.phase.kind === "draining") {
|
|
1113
1135
|
next = finishDrainingOperation(state);
|
|
1114
1136
|
} else {
|
|
@@ -1192,6 +1214,7 @@ export function reduceWorkerRuntime(
|
|
|
1192
1214
|
forkPiEntryId: event.result.meta.forkPiEntryId ?? null,
|
|
1193
1215
|
resultPiEntryId: event.result.meta.resultPiEntryId ?? null,
|
|
1194
1216
|
turnResultMarkdown: event.result.meta.turnResultMarkdown ?? null,
|
|
1217
|
+
resultSummary: event.result.meta.resultSummary,
|
|
1195
1218
|
rootEntryId: event.result.meta.rootEntryId ?? null,
|
|
1196
1219
|
} as never),
|
|
1197
1220
|
park: null,
|
|
@@ -1225,8 +1248,7 @@ export function reduceWorkerRuntime(
|
|
|
1225
1248
|
state.phase.kind === "active" ? { ...state.phase, turnStatus: "completed" } : next.phase,
|
|
1226
1249
|
};
|
|
1227
1250
|
if (state.session?.kind === "automatic") {
|
|
1228
|
-
|
|
1229
|
-
if (pending.park) outputs.push(protocol("worker.lifecycle_parked", pending.park));
|
|
1251
|
+
next = publishTerminalAndAwaitAcknowledgement(next, pending, outputs);
|
|
1230
1252
|
} else if (state.session) {
|
|
1231
1253
|
const point =
|
|
1232
1254
|
event.result.kind === "outcome" ? "before_turn_outcome" : "before_turn_failed";
|
|
@@ -1237,98 +1259,33 @@ export function reduceWorkerRuntime(
|
|
|
1237
1259
|
);
|
|
1238
1260
|
if (!snapshotPolicy.upload)
|
|
1239
1261
|
throw new Error("LLM terminal snapshot policy unexpectedly skipped upload");
|
|
1240
|
-
next =
|
|
1262
|
+
next = beginSnapshot(
|
|
1241
1263
|
next,
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1264
|
+
{
|
|
1265
|
+
kind: "terminal_snapshot",
|
|
1266
|
+
snapshot: { point, turnRecordId: event.turnRecordId, required: true },
|
|
1267
|
+
terminal: pending,
|
|
1268
|
+
},
|
|
1245
1269
|
sessionSnapshotSource(state.session),
|
|
1246
1270
|
outputs,
|
|
1247
1271
|
);
|
|
1248
1272
|
}
|
|
1249
1273
|
break;
|
|
1250
1274
|
}
|
|
1251
|
-
case "
|
|
1252
|
-
if (!matchesTurn(state, event.turnRecordId)) break;
|
|
1253
|
-
if (state.phase.kind === "draining") {
|
|
1254
|
-
next = finishDrainingOperation(state);
|
|
1255
|
-
} else {
|
|
1256
|
-
const failed = failureOutputs(next, {
|
|
1257
|
-
kind: "dispatch",
|
|
1258
|
-
error: event.error,
|
|
1259
|
-
state: "busy",
|
|
1260
|
-
session: failureContext(state),
|
|
1261
|
-
});
|
|
1262
|
-
next = failed.state;
|
|
1263
|
-
outputs.push(...failed.outputs);
|
|
1264
|
-
}
|
|
1265
|
-
break;
|
|
1266
|
-
case "snapshot_succeeded": {
|
|
1267
|
-
const publication = state.work.publication;
|
|
1268
|
-
switch (publication.kind) {
|
|
1269
|
-
case "none":
|
|
1270
|
-
case "fatal_pending_cleanup":
|
|
1271
|
-
break;
|
|
1272
|
-
case "ready_snapshot":
|
|
1273
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1274
|
-
next = { ...state, work: { ...state.work, publication: { kind: "none" } } };
|
|
1275
|
-
break;
|
|
1276
|
-
case "terminal_snapshot":
|
|
1277
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1278
|
-
outputs.push(publication.terminal.fact);
|
|
1279
|
-
if (publication.terminal.park)
|
|
1280
|
-
outputs.push(protocol("worker.lifecycle_parked", publication.terminal.park));
|
|
1281
|
-
next = { ...state, work: { ...state.work, publication: { kind: "none" } } };
|
|
1282
|
-
break;
|
|
1283
|
-
case "cleanup_snapshot":
|
|
1284
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1285
|
-
if (state.phase.kind !== "cleaning" || state.phase.stage !== "publication")
|
|
1286
|
-
throw new Error("Cleanup snapshot completed outside cleanup publication");
|
|
1287
|
-
outputs.push({ kind: "cleanup" });
|
|
1288
|
-
next = {
|
|
1289
|
-
...state,
|
|
1290
|
-
phase: { ...state.phase, stage: "resources" },
|
|
1291
|
-
work: { ...state.work, publication: { kind: "none" } },
|
|
1292
|
-
};
|
|
1293
|
-
break;
|
|
1294
|
-
case "fatal_snapshot":
|
|
1295
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1296
|
-
if (publication.afterSnapshot === "exit") {
|
|
1297
|
-
const finished = finishFatal(state, publication.fatal);
|
|
1298
|
-
next = finished.state;
|
|
1299
|
-
outputs.push(...finished.outputs);
|
|
1300
|
-
} else {
|
|
1301
|
-
if (state.phase.kind !== "cleaning" || state.phase.stage !== "publication")
|
|
1302
|
-
throw new Error("Fatal snapshot completed outside cleanup publication");
|
|
1303
|
-
outputs.push({ kind: "cleanup" });
|
|
1304
|
-
next = {
|
|
1305
|
-
...state,
|
|
1306
|
-
phase: { ...state.phase, stage: "resources" },
|
|
1307
|
-
work: {
|
|
1308
|
-
...state.work,
|
|
1309
|
-
publication: {
|
|
1310
|
-
kind: "fatal_pending_cleanup",
|
|
1311
|
-
fatal: publication.fatal,
|
|
1312
|
-
},
|
|
1313
|
-
},
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1275
|
+
case "snapshot_succeeded":
|
|
1320
1276
|
case "snapshot_failed": {
|
|
1321
1277
|
const publication = state.work.publication;
|
|
1278
|
+
if (!("snapshot" in publication) || !snapshotMatches(publication.snapshot, event)) break;
|
|
1279
|
+
const completion = event.kind === "snapshot_succeeded" ? "completed" : "failed";
|
|
1322
1280
|
switch (publication.kind) {
|
|
1323
|
-
case "none":
|
|
1324
|
-
case "fatal_pending_cleanup":
|
|
1325
|
-
break;
|
|
1326
1281
|
case "ready_snapshot":
|
|
1327
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1328
1282
|
next = { ...state, work: { ...state.work, publication: { kind: "none" } } };
|
|
1329
1283
|
break;
|
|
1330
1284
|
case "terminal_snapshot": {
|
|
1331
|
-
if (
|
|
1285
|
+
if (event.kind === "snapshot_succeeded") {
|
|
1286
|
+
next = publishTerminalAndAwaitAcknowledgement(state, publication.terminal, outputs);
|
|
1287
|
+
break;
|
|
1288
|
+
}
|
|
1332
1289
|
const cleared = {
|
|
1333
1290
|
...state,
|
|
1334
1291
|
work: { ...state.work, publication: { kind: "none" } as const },
|
|
@@ -1345,41 +1302,41 @@ export function reduceWorkerRuntime(
|
|
|
1345
1302
|
break;
|
|
1346
1303
|
}
|
|
1347
1304
|
case "cleanup_snapshot": {
|
|
1348
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1349
1305
|
if (state.phase.kind !== "cleaning" || state.phase.stage !== "publication")
|
|
1350
|
-
throw new Error(
|
|
1306
|
+
throw new Error(`Cleanup snapshot ${completion} outside cleanup publication`);
|
|
1351
1307
|
const cleared = {
|
|
1352
1308
|
...state,
|
|
1353
1309
|
work: { ...state.work, publication: { kind: "none" } as const },
|
|
1354
1310
|
};
|
|
1355
|
-
|
|
1356
|
-
kind: "cleanup"
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1311
|
+
if (event.kind === "snapshot_succeeded") {
|
|
1312
|
+
outputs.push({ kind: "cleanup" });
|
|
1313
|
+
next = { ...cleared, phase: { ...state.phase, stage: "resources" } };
|
|
1314
|
+
} else {
|
|
1315
|
+
const failed = failureOutputs(cleared, {
|
|
1316
|
+
kind: "cleanup",
|
|
1317
|
+
error: event.error,
|
|
1318
|
+
session: failureContext(state),
|
|
1319
|
+
});
|
|
1320
|
+
next = failed.state;
|
|
1321
|
+
outputs.push(...failed.outputs);
|
|
1322
|
+
}
|
|
1362
1323
|
break;
|
|
1363
1324
|
}
|
|
1364
1325
|
case "fatal_snapshot":
|
|
1365
|
-
if (!snapshotMatches(publication.snapshot, event)) break;
|
|
1366
1326
|
if (publication.afterSnapshot === "exit") {
|
|
1367
1327
|
const finished = finishFatal(state, publication.fatal);
|
|
1368
1328
|
next = finished.state;
|
|
1369
1329
|
outputs.push(...finished.outputs);
|
|
1370
1330
|
} else {
|
|
1371
1331
|
if (state.phase.kind !== "cleaning" || state.phase.stage !== "publication")
|
|
1372
|
-
throw new Error(
|
|
1332
|
+
throw new Error(`Fatal snapshot ${completion} outside cleanup publication`);
|
|
1373
1333
|
outputs.push({ kind: "cleanup" });
|
|
1374
1334
|
next = {
|
|
1375
1335
|
...state,
|
|
1376
1336
|
phase: { ...state.phase, stage: "resources" },
|
|
1377
1337
|
work: {
|
|
1378
1338
|
...state.work,
|
|
1379
|
-
publication: {
|
|
1380
|
-
kind: "fatal_pending_cleanup",
|
|
1381
|
-
fatal: publication.fatal,
|
|
1382
|
-
},
|
|
1339
|
+
publication: { kind: "fatal_pending_cleanup", fatal: publication.fatal },
|
|
1383
1340
|
},
|
|
1384
1341
|
};
|
|
1385
1342
|
}
|
|
@@ -1416,6 +1373,16 @@ export function reduceWorkerRuntime(
|
|
|
1416
1373
|
}),
|
|
1417
1374
|
);
|
|
1418
1375
|
next = armTimer(next, outputs, "acceptance_retry", 1_000, event.correlation);
|
|
1376
|
+
} else if (
|
|
1377
|
+
event.name === "terminal_ack" &&
|
|
1378
|
+
state.work.publication.kind === "terminal_pending_ack" &&
|
|
1379
|
+
state.work.publication.terminal.correlation.turnRecordId === event.correlation
|
|
1380
|
+
) {
|
|
1381
|
+
next = publishTerminalAndAwaitAcknowledgement(
|
|
1382
|
+
next,
|
|
1383
|
+
state.work.publication.terminal,
|
|
1384
|
+
outputs,
|
|
1385
|
+
);
|
|
1419
1386
|
} else if (
|
|
1420
1387
|
event.name === "credential_poll" &&
|
|
1421
1388
|
state.credential?.enabled &&
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
} from "../missing-tool-recovery-runner.js";
|
|
31
31
|
import type { PiTreeHandle } from "../pi-adapter.js";
|
|
32
32
|
import {
|
|
33
|
+
type AppliedTargetedInputMetadata,
|
|
33
34
|
applyPreTurnTargetedInputs,
|
|
34
35
|
type PreTurnTargetedInput,
|
|
35
36
|
resolvePreTurnTargetStartSelection,
|
|
@@ -108,13 +109,7 @@ export interface LlmTurnExecutorCallbacks {
|
|
|
108
109
|
onPreTurnTargetedInputApplied?(
|
|
109
110
|
inputId: string,
|
|
110
111
|
sequence: number,
|
|
111
|
-
meta?:
|
|
112
|
-
currentPrimaryPathLeafId?: string | null;
|
|
113
|
-
rootEntryId?: string | null;
|
|
114
|
-
targetSemanticRef?: import("@leitwerk-dev/domain").ProcessSemanticEntryRefKey | null;
|
|
115
|
-
targetProductName?: string | null;
|
|
116
|
-
targetEntryId?: string | null;
|
|
117
|
-
},
|
|
112
|
+
meta?: AppliedTargetedInputMetadata,
|
|
118
113
|
): void;
|
|
119
114
|
emit?: WorkerOperationEmitter;
|
|
120
115
|
integrationTools?: readonly import("@leitwerk-dev/process-sdk").PiCustomTool[];
|
|
@@ -123,16 +118,6 @@ export interface LlmTurnExecutorCallbacks {
|
|
|
123
118
|
/** Pi writes these on new sessions before any conversational content exists. */
|
|
124
119
|
const PI_SESSION_BOOTSTRAP_ENTRY_TYPES = new Set(["model_change", "thinking_level_change"]);
|
|
125
120
|
|
|
126
|
-
function visitPiTreeEntries(
|
|
127
|
-
nodes: readonly PiTreeNode[],
|
|
128
|
-
visit: (entryType: string) => void,
|
|
129
|
-
): void {
|
|
130
|
-
for (const node of nodes) {
|
|
131
|
-
visit(node.entry.type);
|
|
132
|
-
visitPiTreeEntries(node.children, visit);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
121
|
/**
|
|
137
122
|
* Empty-tree prepared starts mean "no conversational fork yet". Pi still appends
|
|
138
123
|
* model/thinking bootstrap entries when activating a new session, so those alone
|
|
@@ -141,13 +126,9 @@ function visitPiTreeEntries(
|
|
|
141
126
|
export function isPiTreeEmptyForPreparedEmptyPlan(
|
|
142
127
|
piHandle: Pick<PiTreeHandle, "getTree">,
|
|
143
128
|
): boolean {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
hasNonBootstrap = true;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return !hasNonBootstrap;
|
|
129
|
+
const isBootstrapOnly = (node: PiTreeNode): boolean =>
|
|
130
|
+
PI_SESSION_BOOTSTRAP_ENTRY_TYPES.has(node.entry.type) && node.children.every(isBootstrapOnly);
|
|
131
|
+
return piHandle.getTree().every(isBootstrapOnly);
|
|
151
132
|
}
|
|
152
133
|
|
|
153
134
|
/**
|
|
@@ -210,6 +191,7 @@ function treePlanFromPreparedStart(input: {
|
|
|
210
191
|
export async function executeLlmTurn<TOutcome extends string>(input: {
|
|
211
192
|
resolvedWorkerProcess: ResolvedWorkerProcess;
|
|
212
193
|
ctx: WorkerProcessContext;
|
|
194
|
+
prepared?: unknown;
|
|
213
195
|
piHandle: PiTreeHandle;
|
|
214
196
|
turnDef: LlmTurnDefinition<TOutcome, unknown, unknown>;
|
|
215
197
|
turnId: string;
|
|
@@ -467,7 +449,7 @@ export async function executeLlmTurn<TOutcome extends string>(input: {
|
|
|
467
449
|
initialPromptlessTurnResumeReason === "active_turn_resume"
|
|
468
450
|
) {
|
|
469
451
|
try {
|
|
470
|
-
promptText = await input.turnDef.prompt(input.ctx);
|
|
452
|
+
promptText = await input.turnDef.prompt({ ...input.ctx, prepared: input.prepared });
|
|
471
453
|
} catch (error: unknown) {
|
|
472
454
|
return failWithWorkerError(
|
|
473
455
|
"turn.prompt_preparation_failed",
|
|
@@ -665,15 +647,15 @@ export async function executeLlmTurn<TOutcome extends string>(input: {
|
|
|
665
647
|
const finalCompletionState = recoveryResult.finalAttempt.completionState;
|
|
666
648
|
const finalPromptResult = recoveryResult.finalAttempt.promptResult;
|
|
667
649
|
const finalResolvedOutcome = recoveryResult.finalAttempt.resolvedOutcome;
|
|
668
|
-
if (
|
|
650
|
+
if (recoveryResult.failure) {
|
|
651
|
+
const { recoveryContext, description } = recoveryResult.failure;
|
|
669
652
|
return reportFailedTurn(
|
|
670
653
|
"protocol_error",
|
|
671
|
-
`Turn '${turnId}' completed without the required tool calls after ${MAX_MISSING_TOOL_CALL_RECOVERY_ATTEMPTS} automatic recovery attempts: ${
|
|
654
|
+
`Turn '${turnId}' completed without the required tool calls after ${MAX_MISSING_TOOL_CALL_RECOVERY_ATTEMPTS} automatic recovery attempts: ${description}`,
|
|
672
655
|
finalPromptResult.resultEntryId,
|
|
673
656
|
{
|
|
674
|
-
recoveryContext
|
|
675
|
-
restorePrimaryLeaf:
|
|
676
|
-
recoveryResult.recoveryContext?.failureCode !== "missing_markdown_result",
|
|
657
|
+
recoveryContext,
|
|
658
|
+
restorePrimaryLeaf: recoveryContext.failureCode !== "missing_markdown_result",
|
|
677
659
|
},
|
|
678
660
|
);
|
|
679
661
|
}
|
|
@@ -723,6 +705,7 @@ export async function executeLlmTurn<TOutcome extends string>(input: {
|
|
|
723
705
|
forkPiEntryId: treePlan.forkPiEntryId,
|
|
724
706
|
resultPiEntryId: finalPromptResult.resultEntryId,
|
|
725
707
|
turnResultMarkdown: finalizedTurnResultMarkdown.markdown,
|
|
708
|
+
resultSummary: finalCompletionState.markdownState.resultSummary,
|
|
726
709
|
rootEntryId: rootEntryIdAfterTurn,
|
|
727
710
|
},
|
|
728
711
|
};
|