@leitwerk-dev/server 0.3.0 → 0.4.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/{app-WfwKzrVk.d.ts → app-CsuxFZT5.d.ts} +332 -111
- package/dist/app-JM4CBTND.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-LK3RO6C7.js → chunk-FPMDWQF7.js} +3050 -645
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-KIOQNNG6.js → chunk-MBHRCQFE.js} +2781 -1822
- package/dist/chunk-MBHRCQFE.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +14 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- 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-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +4 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +7 -1
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- 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 +16 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +1177 -71
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +1 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.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/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator-test-harness.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +11 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- 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/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +10 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -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 +10 -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 +2 -0
- 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 +35 -49
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.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-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +15 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.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-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- 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 +15 -41
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +83 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +5 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +3 -0
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.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 +4 -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/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +14 -10
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +117 -5
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +40 -2
- package/src/config/config-types.ts +14 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/db/database.ts +159 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +9 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +53 -13
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +22 -0
- package/src/db/schema.ts +173 -2
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +13 -3
- package/src/db/turn-summary-repo.ts +12 -3
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +4 -149
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +14 -22
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator-test-harness.ts +8 -4
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +98 -0
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +13 -4
- package/src/process-engine/mapped-turns.ts +328 -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/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +10 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +65 -62
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +33 -5
- package/src/process-engine/runner.ts +8 -8
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +15 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -19
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +118 -21
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +20 -2
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +73 -61
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-navigation.ts +86 -8
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +249 -298
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +10 -10
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-diagnostics-assembler.ts +32 -6
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +161 -327
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +736 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +7 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +97 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +3 -0
- package/src/startup-evidence.ts +20 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +29 -18
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +42 -0
- package/src/supervisor/worker-supervisor.ts +5 -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/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/testing.ts +4 -1
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -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-JM4CBTND.js.map} +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
applyPiEventToLiveTurnProjection,
|
|
3
2
|
asWsEventPayloadRecord,
|
|
4
|
-
buildLiveTurnProjectionFromEvents,
|
|
5
3
|
createDurableWsFrame,
|
|
6
4
|
createEphemeralWsFrame,
|
|
7
|
-
|
|
5
|
+
createLiveTurnProjection,
|
|
8
6
|
isStreamableEvent,
|
|
9
|
-
type
|
|
7
|
+
type LiveTurnProjection,
|
|
10
8
|
mapWorkerEventToWsType,
|
|
11
9
|
readWsEventNonEmptyString,
|
|
12
10
|
readWsEventPiTurnId,
|
|
@@ -21,6 +19,7 @@ import type { RepositoryBundle } from "../db/repositories.js";
|
|
|
21
19
|
import { recordTurnPreparation } from "../turn-preparation.js";
|
|
22
20
|
import { recordTurnProgress } from "../turn-progress.js";
|
|
23
21
|
import type { Broadcaster } from "../ws/broadcast.js";
|
|
22
|
+
import { ingestExecutionInspection } from "./execution-inspection-ingestor.js";
|
|
24
23
|
import { recordInitialTurnObservation } from "./startup-observer.js";
|
|
25
24
|
|
|
26
25
|
/** @internal */
|
|
@@ -48,6 +47,7 @@ export interface WorkerEventLogEntry {
|
|
|
48
47
|
export interface WorkerEventIngestorDeps
|
|
49
48
|
extends Pick<RepositoryBundle, "processes" | "events" | "turnRecords"> {
|
|
50
49
|
leases?: RepositoryBundle["leases"];
|
|
50
|
+
executionInspections?: RepositoryBundle["executionInspections"];
|
|
51
51
|
startupObservations?: RepositoryBundle["startupObservations"];
|
|
52
52
|
broadcaster: Broadcaster;
|
|
53
53
|
workerEventLogger?: (entry: WorkerEventLogEntry) => void;
|
|
@@ -70,28 +70,28 @@ function hydrateLiveTurnProjection(
|
|
|
70
70
|
deps: Pick<WorkerEventIngestorDeps, "events" | "turnRecords">,
|
|
71
71
|
instanceId: string,
|
|
72
72
|
turnRecordId: string | null,
|
|
73
|
-
):
|
|
73
|
+
): LiveTurnProjection {
|
|
74
74
|
if (!turnRecordId) {
|
|
75
|
-
return
|
|
75
|
+
return createLiveTurnProjection();
|
|
76
76
|
}
|
|
77
77
|
const turnRecord = deps.turnRecords.getById(turnRecordId);
|
|
78
78
|
if (!turnRecord) {
|
|
79
|
-
return
|
|
79
|
+
return createLiveTurnProjection();
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return createLiveTurnProjection(deps.events.listByTurnRecord(instanceId, turnRecordId));
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
85
85
|
const liveTurnRecordIds = new Map<string, string>();
|
|
86
86
|
const liveTurnProjections = new Map<
|
|
87
87
|
string,
|
|
88
|
-
{ turnRecordId: string | null; projection:
|
|
88
|
+
{ turnRecordId: string | null; projection: LiveTurnProjection }
|
|
89
89
|
>();
|
|
90
90
|
|
|
91
91
|
function getLiveTurnProjection(
|
|
92
92
|
instanceId: string,
|
|
93
93
|
turnRecordId: string | null,
|
|
94
|
-
):
|
|
94
|
+
): LiveTurnProjection {
|
|
95
95
|
const existing = liveTurnProjections.get(instanceId);
|
|
96
96
|
if (existing && existing.turnRecordId === turnRecordId) {
|
|
97
97
|
return existing.projection;
|
|
@@ -104,7 +104,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
|
104
104
|
function setLiveTurnProjection(instanceId: string, turnRecordId: string | null) {
|
|
105
105
|
liveTurnProjections.set(instanceId, {
|
|
106
106
|
turnRecordId,
|
|
107
|
-
projection:
|
|
107
|
+
projection: createLiveTurnProjection(),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -171,6 +171,18 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
if (suppliedTurnRecordId && suppliedTurnRecordId !== currentTurnRecordId) return;
|
|
174
|
+
if (payload.eventType === "execution.inspection") {
|
|
175
|
+
if (suppliedTurnRecordId && deps.executionInspections && deps.leases)
|
|
176
|
+
ingestExecutionInspection(
|
|
177
|
+
{
|
|
178
|
+
executionInspections: deps.executionInspections,
|
|
179
|
+
turnRecords: deps.turnRecords,
|
|
180
|
+
leases: deps.leases,
|
|
181
|
+
},
|
|
182
|
+
{ instanceId, workerId, turnRecordId: suppliedTurnRecordId, capture: data.capture },
|
|
183
|
+
);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
174
186
|
if (payload.eventType === "turn.progress") {
|
|
175
187
|
const reportedTurnRecordId = readWsEventNonEmptyString(data.turnRecordId);
|
|
176
188
|
if (!reportedTurnRecordId || reportedTurnRecordId !== currentTurnRecordId) return;
|
|
@@ -192,7 +204,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
|
192
204
|
return;
|
|
193
205
|
}
|
|
194
206
|
const projection = getLiveTurnProjection(instanceId, currentTurnRecordId);
|
|
195
|
-
const appliedProjectionEvent =
|
|
207
|
+
const appliedProjectionEvent = projection.apply({
|
|
196
208
|
eventType: payload.eventType,
|
|
197
209
|
data,
|
|
198
210
|
fallbackTimestamp: new Date().toISOString(),
|
|
@@ -200,7 +212,11 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
|
200
212
|
const projectionData = appliedProjectionEvent.canonicalData;
|
|
201
213
|
const enrichedData: Record<string, unknown> =
|
|
202
214
|
currentTurnRecordId && !readWsEventNonEmptyString(projectionData.turnRecordId)
|
|
203
|
-
? {
|
|
215
|
+
? {
|
|
216
|
+
...projectionData,
|
|
217
|
+
turnRecordId: currentTurnRecordId,
|
|
218
|
+
workerLeaseId: deps.leases?.getByInstance(instanceId)?.id ?? null,
|
|
219
|
+
}
|
|
204
220
|
: projectionData;
|
|
205
221
|
const currentSelectedTurnId = payload.selectedTurnId ?? process.selectedTurnId ?? null;
|
|
206
222
|
const normalizedTimestamp = eventTimestamp(enrichedData);
|
|
@@ -263,7 +279,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
|
|
|
263
279
|
);
|
|
264
280
|
}
|
|
265
281
|
} else if (payload.eventType === "pi.usage") {
|
|
266
|
-
const usage =
|
|
282
|
+
const usage = appliedProjectionEvent.usage;
|
|
267
283
|
if (usage) {
|
|
268
284
|
deps.broadcaster.broadcast(
|
|
269
285
|
createEphemeralWsFrame({
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type PiResourceBundle,
|
|
15
15
|
type ServerToWorkerMessage,
|
|
16
16
|
verifyCanonicalPiResourceBundle,
|
|
17
|
+
type WorkerMappedItem,
|
|
17
18
|
type WorkerRuntimeSettingsSnapshot,
|
|
18
19
|
type WorkerStartPayload,
|
|
19
20
|
} from "@leitwerk-dev/worker-protocol";
|
|
@@ -39,6 +40,8 @@ export interface WorkerStartPayloadBuilderDeps
|
|
|
39
40
|
RepositoryBundle,
|
|
40
41
|
"processes" | "projects" | "inputs" | "turnRecords" | "turnStarts" | "leases" | "events"
|
|
41
42
|
> {
|
|
43
|
+
/** Required for processes that declare mapped LLM turns. @internal */
|
|
44
|
+
mappedRuns?: Pick<RepositoryBundle["mappedRuns"], "getById" | "getItem">;
|
|
42
45
|
/** @internal */
|
|
43
46
|
config: LeitwerkConfig;
|
|
44
47
|
/** @internal */
|
|
@@ -219,6 +222,26 @@ function buildTurnResultMarkdownByProduct(
|
|
|
219
222
|
return Object.keys(byProduct).length > 0 ? byProduct : undefined;
|
|
220
223
|
}
|
|
221
224
|
|
|
225
|
+
function resolveMappedItem(
|
|
226
|
+
start: TurnStartRecord,
|
|
227
|
+
deps: Pick<WorkerStartPayloadBuilderDeps, "mappedRuns">,
|
|
228
|
+
): WorkerMappedItem | undefined {
|
|
229
|
+
if (!start.iteration) return undefined;
|
|
230
|
+
const run = deps.mappedRuns?.getById(start.iteration.runId);
|
|
231
|
+
const item = deps.mappedRuns?.getItem(start.iteration.runId, start.iteration.itemIndex);
|
|
232
|
+
if (!run || !item || item.itemKey !== start.iteration.itemKey) {
|
|
233
|
+
throw new Error(`Mapped item for worker start '${start.id}' is unavailable`);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
runId: run.id,
|
|
237
|
+
itemKey: item.itemKey,
|
|
238
|
+
itemLabel: item.label,
|
|
239
|
+
itemIndex: item.itemIndex,
|
|
240
|
+
itemCount: run.itemCount,
|
|
241
|
+
item: JSON.parse(item.itemJson) as unknown,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
222
245
|
function resolveLlmPreparation(
|
|
223
246
|
start: TurnStartRecord,
|
|
224
247
|
deps: Pick<WorkerStartPayloadBuilderDeps, "events">,
|
|
@@ -262,6 +285,22 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
262
285
|
function buildWorkerRuntimeContextSnapshot(process: ProcessInstance, start: TurnStartRecord) {
|
|
263
286
|
const turnResultMarkdownBySemanticRef = buildTurnResultMarkdownBySemanticRef(process, deps);
|
|
264
287
|
const turnResultMarkdownByProduct = buildTurnResultMarkdownByProduct(process, deps);
|
|
288
|
+
const productRefs = parseProductRefsFromStateJsonLenient(process.stateJson);
|
|
289
|
+
const inspectionProducts = Object.entries(turnResultMarkdownByProduct ?? {}).flatMap(
|
|
290
|
+
([name, content]) => {
|
|
291
|
+
const ref = productRefs[name];
|
|
292
|
+
return ref?.turnRecordId
|
|
293
|
+
? [
|
|
294
|
+
{
|
|
295
|
+
name,
|
|
296
|
+
producerTurnRecordId: ref.turnRecordId,
|
|
297
|
+
entryId: ref.entryId,
|
|
298
|
+
content: { state: "recorded" as const, value: content },
|
|
299
|
+
},
|
|
300
|
+
]
|
|
301
|
+
: [];
|
|
302
|
+
},
|
|
303
|
+
);
|
|
265
304
|
const prepared =
|
|
266
305
|
start.state.kind === "starting" ||
|
|
267
306
|
start.state.kind === "accepted" ||
|
|
@@ -279,6 +318,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
279
318
|
projectSnapshots: buildProjectSnapshots(process.id),
|
|
280
319
|
...(turnResultMarkdownBySemanticRef ? { turnResultMarkdownBySemanticRef } : {}),
|
|
281
320
|
...(turnResultMarkdownByProduct ? { turnResultMarkdownByProduct } : {}),
|
|
321
|
+
inspectionProducts,
|
|
282
322
|
};
|
|
283
323
|
}
|
|
284
324
|
|
|
@@ -320,6 +360,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
320
360
|
null)
|
|
321
361
|
: null;
|
|
322
362
|
const contextSnapshot = buildWorkerRuntimeContextSnapshot(process, start);
|
|
363
|
+
const iteration = resolveMappedItem(start, deps);
|
|
323
364
|
const repositoryCredentials =
|
|
324
365
|
deps.resolveRepositoryCredentials?.({
|
|
325
366
|
process,
|
|
@@ -380,6 +421,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
380
421
|
...(repositoryCredentials.length > 0 ? { repositoryCredentials } : {}),
|
|
381
422
|
...(dockerRegistryCredentials.length > 0 ? { dockerRegistryCredentials } : {}),
|
|
382
423
|
...(integrationTools && integrationTools.length > 0 ? { integrationTools } : {}),
|
|
424
|
+
...(iteration ? { iteration } : {}),
|
|
383
425
|
};
|
|
384
426
|
const payload: WorkerStartPayload =
|
|
385
427
|
bootstrap.kind === "llm"
|
|
@@ -82,6 +82,10 @@ export interface SupervisorDeps
|
|
|
82
82
|
/** @internal */
|
|
83
83
|
startupObservations?: RepositoryBundle["startupObservations"];
|
|
84
84
|
/** @internal */
|
|
85
|
+
executionInspections?: RepositoryBundle["executionInspections"];
|
|
86
|
+
/** @internal */
|
|
87
|
+
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
88
|
+
/** @internal */
|
|
85
89
|
config: LeitwerkConfig;
|
|
86
90
|
/** @internal */
|
|
87
91
|
getLaunchCoordinator?: () => LaunchCoordinator | undefined;
|
|
@@ -715,6 +719,7 @@ export function createWorkerSupervisor(deps: SupervisorDeps): WorkerSupervisor {
|
|
|
715
719
|
config: deps.config,
|
|
716
720
|
processId: process.processId,
|
|
717
721
|
componentKeys: deps.projects.listByInstance(process.id).map((project) => project.key),
|
|
722
|
+
docker: deps.processGraphs.get(process.processId)?.runtime?.docker === true,
|
|
718
723
|
}),
|
|
719
724
|
);
|
|
720
725
|
if (!selection.ok) {
|
|
@@ -127,6 +127,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
127
127
|
const recoverRecordingFailure = async (input: {
|
|
128
128
|
instanceId: string;
|
|
129
129
|
workerId: string;
|
|
130
|
+
workerLeaseId: string;
|
|
130
131
|
turnRecordId: string;
|
|
131
132
|
terminalType: TerminalType;
|
|
132
133
|
failure: unknown;
|
|
@@ -147,6 +148,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
150
|
const fallback = await deps.commands.recordWorkerFailure(input.instanceId, {
|
|
151
|
+
workerLeaseId: input.workerLeaseId,
|
|
150
152
|
errorCode: details.code,
|
|
151
153
|
message: `Server could not durably record worker turn ${input.terminalType}: ${details.message}`,
|
|
152
154
|
errorClass: "infrastructure",
|
|
@@ -180,6 +182,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
180
182
|
const recordTerminal = async <T>(input: {
|
|
181
183
|
instanceId: string;
|
|
182
184
|
workerId: string;
|
|
185
|
+
workerLeaseId: string;
|
|
183
186
|
turnRecordId: string;
|
|
184
187
|
terminalType: TerminalType;
|
|
185
188
|
record: () => Promise<T>;
|
|
@@ -204,6 +207,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
204
207
|
recordTurnOutcome(
|
|
205
208
|
instanceId: string,
|
|
206
209
|
workerId: string,
|
|
210
|
+
workerLeaseId: string,
|
|
207
211
|
payload: WorkerTurnOutcomePayload,
|
|
208
212
|
): void {
|
|
209
213
|
const { turnId, ...rest } = payload;
|
|
@@ -217,6 +221,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
217
221
|
void recordTerminal({
|
|
218
222
|
instanceId,
|
|
219
223
|
workerId,
|
|
224
|
+
workerLeaseId,
|
|
220
225
|
turnRecordId: rest.turnRecordId,
|
|
221
226
|
terminalType: "outcome",
|
|
222
227
|
record: () =>
|
|
@@ -236,12 +241,18 @@ export function createWorkerTurnIpcRecorder(
|
|
|
236
241
|
recoveryContext: createGenericFailedTurnRecoveryContext(),
|
|
237
242
|
});
|
|
238
243
|
},
|
|
239
|
-
recordTurnFailed(
|
|
244
|
+
recordTurnFailed(
|
|
245
|
+
instanceId: string,
|
|
246
|
+
workerId: string,
|
|
247
|
+
workerLeaseId: string,
|
|
248
|
+
payload: WorkerTurnFailedPayload,
|
|
249
|
+
): void {
|
|
240
250
|
const { errorClass, failureCode, failureDetails: details, ...rest } = payload;
|
|
241
251
|
if (errorClass !== undefined && !isWorkerErrorClass(errorClass)) {
|
|
242
252
|
void recoverRecordingFailure({
|
|
243
253
|
instanceId,
|
|
244
254
|
workerId,
|
|
255
|
+
workerLeaseId,
|
|
245
256
|
turnRecordId: rest.turnRecordId,
|
|
246
257
|
terminalType: "failure",
|
|
247
258
|
failure: new Error(`Invalid worker error class '${errorClass}'`),
|
|
@@ -260,6 +271,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
260
271
|
void recordTerminal({
|
|
261
272
|
instanceId,
|
|
262
273
|
workerId,
|
|
274
|
+
workerLeaseId,
|
|
263
275
|
turnRecordId: rest.turnRecordId,
|
|
264
276
|
terminalType: "failure",
|
|
265
277
|
record: () =>
|
|
@@ -2,15 +2,32 @@ import type { ResolvedTurnStart } from "@leitwerk-dev/domain";
|
|
|
2
2
|
import type { AppContext } from "../app.js";
|
|
3
3
|
|
|
4
4
|
/** @internal */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type AcceptedTurnRepos = Pick<
|
|
6
|
+
AppContext["deps"],
|
|
7
|
+
"processes" | "turnRecords" | "turnStarts" | "leases"
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
type AcceptedTurnContext = {
|
|
12
|
+
/** @internal */
|
|
13
|
+
deps: AcceptedTurnRepos;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Compatibility name for existing LLM fixtures. @internal */
|
|
17
|
+
export const createAcceptedLlmTurn = createAcceptedWorkerTurn;
|
|
18
|
+
/** Compatibility name for existing LLM starts. @internal */
|
|
19
|
+
export const createAcceptedLlmTurnStart = createAcceptedWorkerTurnStart;
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export function createAcceptedWorkerTurn(
|
|
23
|
+
ctx: AcceptedTurnContext | null,
|
|
24
|
+
input: Parameters<AcceptedTurnRepos["turnRecords"]["create"]>[0] & {
|
|
8
25
|
/** @internal */
|
|
9
26
|
id: string;
|
|
10
27
|
/** @internal */
|
|
11
|
-
turnType: "llm";
|
|
28
|
+
turnType: "llm" | "automatic";
|
|
12
29
|
},
|
|
13
|
-
options: Parameters<typeof
|
|
30
|
+
options: Parameters<typeof createAcceptedWorkerTurnStart>[3] & {
|
|
14
31
|
/** @internal */
|
|
15
32
|
current?: boolean;
|
|
16
33
|
/** @internal */
|
|
@@ -18,24 +35,25 @@ export function createAcceptedLlmTurn(
|
|
|
18
35
|
} = {},
|
|
19
36
|
) {
|
|
20
37
|
if (!ctx) throw new Error("Server context not initialized");
|
|
38
|
+
const { deps: repos } = ctx;
|
|
21
39
|
const current = options.current ?? input.status === "running";
|
|
22
|
-
const lease =
|
|
40
|
+
const lease = repos.leases.create({
|
|
23
41
|
instanceId: input.instanceId,
|
|
24
42
|
workerId: options.workerId ?? `wkr_${input.id}`,
|
|
25
43
|
state: current ? (input.status === "failed" ? "failed" : "busy") : "exited",
|
|
26
44
|
});
|
|
27
|
-
const start =
|
|
28
|
-
const record =
|
|
45
|
+
const start = createAcceptedWorkerTurnStart(ctx, input, lease.id, options);
|
|
46
|
+
const record = repos.turnRecords.create({
|
|
29
47
|
...input,
|
|
30
48
|
turnStartRecordId: start.id,
|
|
31
49
|
acceptedWorkerLeaseId: lease.id,
|
|
32
50
|
});
|
|
33
51
|
if (current) {
|
|
34
|
-
|
|
52
|
+
repos.processes.update(input.instanceId, {
|
|
35
53
|
currentExecution: { kind: "worker_start", id: start.id },
|
|
36
54
|
});
|
|
37
55
|
} else {
|
|
38
|
-
|
|
56
|
+
repos.leases.update(lease.id, {
|
|
39
57
|
exitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),
|
|
40
58
|
});
|
|
41
59
|
}
|
|
@@ -43,9 +61,11 @@ export function createAcceptedLlmTurn(
|
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
/** @internal */
|
|
46
|
-
|
|
47
|
-
ctx:
|
|
64
|
+
function createAcceptedWorkerTurnStart(
|
|
65
|
+
ctx: AcceptedTurnContext,
|
|
48
66
|
input: {
|
|
67
|
+
/** @internal */
|
|
68
|
+
turnType?: "llm" | "automatic";
|
|
49
69
|
/** @internal */
|
|
50
70
|
id: string;
|
|
51
71
|
/** @internal */
|
|
@@ -80,27 +100,31 @@ export function createAcceptedLlmTurnStart(
|
|
|
80
100
|
id: options.id ?? `tsr_${input.id}`,
|
|
81
101
|
instanceId: input.instanceId,
|
|
82
102
|
turnId: input.turnId,
|
|
83
|
-
turnType: "llm",
|
|
103
|
+
turnType: input.turnType ?? "llm",
|
|
84
104
|
proposedTurnRecordId: input.id,
|
|
85
105
|
startKind: "selected_turn",
|
|
86
106
|
recoveryTurnRecordId: null,
|
|
87
107
|
continuation: null,
|
|
88
108
|
state: {
|
|
89
109
|
kind: "accepted",
|
|
90
|
-
start:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
start:
|
|
111
|
+
input.turnType === "automatic"
|
|
112
|
+
? { kind: "automatic" }
|
|
113
|
+
: (options.preparedStart ?? {
|
|
114
|
+
kind: "llm",
|
|
115
|
+
model: options.model ?? {
|
|
116
|
+
profileId: "fixture-profile",
|
|
117
|
+
providerId: "fixture-provider",
|
|
118
|
+
modelId: "fixture-model",
|
|
119
|
+
thinkingLevel: "off",
|
|
120
|
+
},
|
|
121
|
+
providerOptions: {},
|
|
122
|
+
providerWorkerConfig: null,
|
|
123
|
+
piResourceSnapshotDigest:
|
|
124
|
+
options.piResourceSnapshotDigest ?? "fixture-resource-digest",
|
|
125
|
+
workerRuntimeProfileId: options.workerRuntimeProfileId ?? "local",
|
|
126
|
+
piSettings: {},
|
|
127
|
+
}),
|
|
104
128
|
turnRecordId: input.id,
|
|
105
129
|
acceptedWorkerLeaseId,
|
|
106
130
|
},
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import { onTestFinished } from "vitest";
|
|
3
|
+
import { closeDatabase, createDatabase, createInMemoryDatabase } from "../db/database.js";
|
|
4
|
+
import { createTestDeps } from "./unit-deps.js";
|
|
5
|
+
|
|
6
|
+
/** Creates repositories whose database is owned by the current test. @internal */
|
|
7
|
+
export function createOwnedTestDeps(...args: Parameters<typeof createTestDeps>) {
|
|
8
|
+
const deps = createTestDeps(...args);
|
|
9
|
+
onTestFinished(() => closeDatabase(deps.db));
|
|
10
|
+
return deps;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Creates an in-memory database owned by the current test. @internal */
|
|
14
|
+
export function createOwnedInMemoryDatabase(...args: Parameters<typeof createInMemoryDatabase>) {
|
|
15
|
+
const db = createInMemoryDatabase(...args);
|
|
16
|
+
onTestFinished(() => {
|
|
17
|
+
if (db.$client.isOpen) db.$client.close();
|
|
18
|
+
});
|
|
19
|
+
return db;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Tracks file handles so tests can close them before removing storage. @internal */
|
|
23
|
+
export function createOwnedDatabaseScope() {
|
|
24
|
+
const handles = new Set<DatabaseSync>();
|
|
25
|
+
function closeOwnedSqlite() {
|
|
26
|
+
for (const db of handles) if (db.isOpen) db.close();
|
|
27
|
+
handles.clear();
|
|
28
|
+
}
|
|
29
|
+
function own(sqlite: DatabaseSync) {
|
|
30
|
+
handles.add(sqlite);
|
|
31
|
+
onTestFinished(closeOwnedSqlite);
|
|
32
|
+
return sqlite;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
closeOwnedSqlite,
|
|
36
|
+
createDatabase(...args: Parameters<typeof createDatabase>) {
|
|
37
|
+
const db = createDatabase(...args);
|
|
38
|
+
own(db.$client);
|
|
39
|
+
return db;
|
|
40
|
+
},
|
|
41
|
+
openOwnedSqlite(...args: ConstructorParameters<typeof DatabaseSync>) {
|
|
42
|
+
return own(new DatabaseSync(...args));
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -46,6 +46,7 @@ export async function prepareAcceptedFixtureStart(
|
|
|
46
46
|
const result = await prepareCreatedTurnStarts(
|
|
47
47
|
{
|
|
48
48
|
config: ctx.config,
|
|
49
|
+
processModelPolicy: ctx.deps.processModelPolicy,
|
|
49
50
|
registry: ctx.modelProviderRegistry,
|
|
50
51
|
modelStatusCache: ctx.modelStatusCache,
|
|
51
52
|
piContributions: contributions,
|
|
@@ -114,6 +114,7 @@ export function createModelAvailabilitySnapshot(
|
|
|
114
114
|
|
|
115
115
|
export function createTestModelPolicy(
|
|
116
116
|
input: {
|
|
117
|
+
defaultProfileId?: string;
|
|
117
118
|
profiles?: readonly {
|
|
118
119
|
id: string;
|
|
119
120
|
model_id?: string;
|
|
@@ -132,6 +133,7 @@ export function createTestModelPolicy(
|
|
|
132
133
|
processActionRegistry: { getTurnDefinition: () => ReturnType<typeof createTestLlmTurn> };
|
|
133
134
|
} {
|
|
134
135
|
const config = getDefaultConfig();
|
|
136
|
+
config.pi.default_model_profile = input.defaultProfileId ?? "first";
|
|
135
137
|
config.pi.model_profiles = (
|
|
136
138
|
input.profiles ?? [
|
|
137
139
|
{ id: "first", model_id: "one" },
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
|
|
2
|
+
import { buildExtensionCatalogFromModules } from "@leitwerk-dev/extension-runtime/testing";
|
|
3
|
+
import type { LeitwerkExtensionModule, SettingDefinition } from "@leitwerk-dev/process-sdk";
|
|
4
|
+
import { getDefaultConfig } from "../config/config-loader.js";
|
|
5
|
+
import { createAllRepos } from "../db/repositories.js";
|
|
6
|
+
import { buildProcessActionRegistry } from "../process-action-registry.js";
|
|
7
|
+
import { createServerProcessModelPolicy } from "../process-model-policy/index.js";
|
|
8
|
+
import { createScopedSettingsService } from "../scoped-settings-service.js";
|
|
9
|
+
import { createOwnedInMemoryDatabase } from "./owned-test-deps.js";
|
|
10
|
+
import {
|
|
11
|
+
createFixtureHumanTurn,
|
|
12
|
+
createFixtureLlmTurn,
|
|
13
|
+
createFixtureProcess,
|
|
14
|
+
} from "./process-fixtures.js";
|
|
15
|
+
|
|
16
|
+
export const reportLabel: SettingDefinition<string> = {
|
|
17
|
+
key: "settings-test.report_label",
|
|
18
|
+
schemaVersion: 1,
|
|
19
|
+
defaultValue: "Default report",
|
|
20
|
+
scopes: [
|
|
21
|
+
"instance",
|
|
22
|
+
"settings-test.issue-type",
|
|
23
|
+
"settings-test.project",
|
|
24
|
+
"settings-test.project-issue-type",
|
|
25
|
+
],
|
|
26
|
+
merge: "replace",
|
|
27
|
+
schema: {
|
|
28
|
+
parse(value) {
|
|
29
|
+
if (typeof value !== "string") throw new Error("Expected text");
|
|
30
|
+
return value;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
form: { label: "Report label", control: "textarea", group: "Planning" },
|
|
34
|
+
};
|
|
35
|
+
export const repositoryLabel: SettingDefinition<string> = {
|
|
36
|
+
...reportLabel,
|
|
37
|
+
key: "settings-test.repository_label",
|
|
38
|
+
scopes: ["instance", "repository"],
|
|
39
|
+
};
|
|
40
|
+
export const model: SettingDefinition<string | null> = {
|
|
41
|
+
key: "settings-test.model",
|
|
42
|
+
schemaVersion: 1,
|
|
43
|
+
defaultValue: null,
|
|
44
|
+
scopes: ["instance", "repository"],
|
|
45
|
+
merge: "replace",
|
|
46
|
+
schema: {
|
|
47
|
+
parse(value) {
|
|
48
|
+
if (value === null || typeof value === "string") return value;
|
|
49
|
+
throw new Error("Expected a model profile");
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
form: { label: "Planning model", control: "model", group: "Planning" },
|
|
53
|
+
};
|
|
54
|
+
const process = createFixtureProcess({
|
|
55
|
+
id: "settings_process",
|
|
56
|
+
entry: "run",
|
|
57
|
+
turns: {
|
|
58
|
+
run: createFixtureLlmTurn("Plan", { executionPurpose: "settings-test.planning" }),
|
|
59
|
+
review: createFixtureHumanTurn({
|
|
60
|
+
actions: { proceed: { label: "Proceed", acceptanceState: "accepted", to: "run" } },
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
export const settingsExtension: LeitwerkExtensionModule = {
|
|
65
|
+
manifest: { id: "settings-test", version: "1" },
|
|
66
|
+
scopedSettings: {
|
|
67
|
+
scopes: [
|
|
68
|
+
{ id: "settings-test.issue-type", label: "Issue type" },
|
|
69
|
+
{ id: "settings-test.project", label: "Project" },
|
|
70
|
+
{ id: "settings-test.project-issue-type", label: "Project + issue type" },
|
|
71
|
+
],
|
|
72
|
+
settings: [reportLabel, repositoryLabel, model],
|
|
73
|
+
purposes: [
|
|
74
|
+
{
|
|
75
|
+
id: "settings-test.planning",
|
|
76
|
+
label: "Planning",
|
|
77
|
+
modelSettingKey: model.key,
|
|
78
|
+
settingKeys: [reportLabel.key, repositoryLabel.key],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
setupCatalog(api) {
|
|
83
|
+
api.registerProcess(process);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function createSettingsProcess(repos: ReturnType<typeof createAllRepos>, keys: string[]) {
|
|
88
|
+
const process = repos.processes.create({ processId: "settings_process", selectedTurnId: "run" });
|
|
89
|
+
for (const key of keys)
|
|
90
|
+
repos.projects.create({
|
|
91
|
+
instanceId: process.id,
|
|
92
|
+
key,
|
|
93
|
+
repoLocator: `/workspace/${key}`,
|
|
94
|
+
baseBranch: "main",
|
|
95
|
+
});
|
|
96
|
+
return process;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function createSettingsFixture(
|
|
100
|
+
repos = createAllRepos(createOwnedInMemoryDatabase()),
|
|
101
|
+
modules = [settingsExtension],
|
|
102
|
+
) {
|
|
103
|
+
const catalog: ExtensionCatalog = await buildExtensionCatalogFromModules(modules);
|
|
104
|
+
const config = getDefaultConfig();
|
|
105
|
+
config.pi.default_model_profile = "first";
|
|
106
|
+
config.pi.model_profiles = [
|
|
107
|
+
{ id: "first", provider: "test", model_id: "one" },
|
|
108
|
+
{ id: "second", provider: "test", model_id: "two" },
|
|
109
|
+
];
|
|
110
|
+
config.process_configs = modules.length
|
|
111
|
+
? {
|
|
112
|
+
settings_process: {
|
|
113
|
+
default_model_profile: "first",
|
|
114
|
+
turn_configs: { run: { model_profile: "first" } },
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
: {};
|
|
118
|
+
const settings = createScopedSettingsService({ repos, catalog, config });
|
|
119
|
+
const policy = createServerProcessModelPolicy({
|
|
120
|
+
config,
|
|
121
|
+
processGraphs: catalog.processes,
|
|
122
|
+
processActionRegistry: buildProcessActionRegistry(catalog),
|
|
123
|
+
scopedSettings: settings,
|
|
124
|
+
});
|
|
125
|
+
return { repos, catalog, config, settings, policy };
|
|
126
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createCanonicalPiResourceBundle } from "@leitwerk-dev/worker-protocol";
|
|
2
|
+
import type { RepositoryBundle } from "../db/repositories.js";
|
|
3
|
+
|
|
4
|
+
/** Installs a synthetic catalog skill using the operator registration path. @internal */
|
|
5
|
+
export function installTestSkill(
|
|
6
|
+
repos: Pick<RepositoryBundle, "skills">,
|
|
7
|
+
id: string,
|
|
8
|
+
content = "Synthetic skill instructions.",
|
|
9
|
+
) {
|
|
10
|
+
const repositoryId = `test-${id}`;
|
|
11
|
+
repos.skills.mergeCatalog(repositoryId, [
|
|
12
|
+
{
|
|
13
|
+
skillId: id,
|
|
14
|
+
label: id,
|
|
15
|
+
description: "Synthetic skill",
|
|
16
|
+
sourcePath: `skills/${id}`,
|
|
17
|
+
sourceRevision: null,
|
|
18
|
+
bundle: createCanonicalPiResourceBundle([
|
|
19
|
+
{
|
|
20
|
+
path: `skills/${id}/SKILL.md`,
|
|
21
|
+
content: Buffer.from(`---\nname: ${id}\ndescription: Synthetic skill\n---\n${content}\n`),
|
|
22
|
+
},
|
|
23
|
+
]),
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
repos.skills.registerCatalogEntry(repositoryId, id);
|
|
27
|
+
return repos.skills.resolveActive([id]);
|
|
28
|
+
}
|
package/src/testing.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
|
|
2
2
|
export { buildTurnTraceIndexFromSession } from "./process-turn-trace.js";
|
|
3
3
|
export { buildProcessUiSnapshotProjections } from "./process-ui-snapshot-presenter.js";
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
createAcceptedLlmTurn,
|
|
6
|
+
createAcceptedWorkerTurn,
|
|
7
|
+
} from "./test-helpers/accepted-turn-start.js";
|
|
5
8
|
export { prepareAcceptedFixtureStart } from "./test-helpers/prepared-fixture-start.js";
|
|
6
9
|
export { writeProcessSessionSnapshot } from "./test-helpers/session-snapshot-fixtures.js";
|
|
7
10
|
export { createTestDeps } from "./test-helpers/unit-deps.js";
|