@leitwerk-dev/server 0.2.1 → 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.
Files changed (123) hide show
  1. package/dist/{app-WfwKzrVk.d.ts → app-BuJCdkvy.d.ts} +82 -2
  2. package/dist/app-MSJXFK33.js +8 -0
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/{chunk-ZSKM25SD.js → chunk-HK6BLLHA.js} +1702 -496
  5. package/dist/chunk-HK6BLLHA.js.map +1 -0
  6. package/dist/{chunk-CNITOV76.js → chunk-QCHS3X33.js} +546 -1132
  7. package/dist/chunk-QCHS3X33.js.map +1 -0
  8. package/dist/db/database.d.ts.map +1 -1
  9. package/dist/db/mapped-llm-run-repo.d.ts +56 -0
  10. package/dist/db/mapped-llm-run-repo.d.ts.map +1 -0
  11. package/dist/db/process-turn-record-repo.d.ts +3 -1
  12. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  13. package/dist/db/repo-helpers.d.ts +6 -0
  14. package/dist/db/repo-helpers.d.ts.map +1 -1
  15. package/dist/db/repositories.d.ts +4 -0
  16. package/dist/db/repositories.d.ts.map +1 -1
  17. package/dist/db/schema.d.ts +415 -0
  18. package/dist/db/schema.d.ts.map +1 -1
  19. package/dist/db/turn-start-record-repo.d.ts.map +1 -1
  20. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  21. package/dist/future-execution-presenter.d.ts +4 -14
  22. package/dist/future-execution-presenter.d.ts.map +1 -1
  23. package/dist/index.js +2 -2
  24. package/dist/launch-coordinator-test-harness.d.ts.map +1 -1
  25. package/dist/main.js +3 -3
  26. package/dist/process-action-presenter.d.ts +16 -0
  27. package/dist/process-action-presenter.d.ts.map +1 -0
  28. package/dist/process-engine/mapped-turns.d.ts +45 -0
  29. package/dist/process-engine/mapped-turns.d.ts.map +1 -0
  30. package/dist/process-engine/operation.d.ts +1 -1
  31. package/dist/process-engine/operation.d.ts.map +1 -1
  32. package/dist/process-engine/ops/accept-worker-turn-start.d.ts +2 -0
  33. package/dist/process-engine/ops/accept-worker-turn-start.d.ts.map +1 -1
  34. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  35. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  36. package/dist/process-engine/recorder.d.ts.map +1 -1
  37. package/dist/process-engine/types.d.ts +5 -0
  38. package/dist/process-engine/types.d.ts.map +1 -1
  39. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  40. package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -1
  41. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +8 -1
  42. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  43. package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
  44. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  45. package/dist/process-engine/writes/reserve-selected-turn-start.d.ts +5 -0
  46. package/dist/process-engine/writes/reserve-selected-turn-start.d.ts.map +1 -0
  47. package/dist/process-engine/writes/writes.d.ts +18 -0
  48. package/dist/process-engine/writes/writes.d.ts.map +1 -1
  49. package/dist/process-turn-navigation.d.ts +12 -2
  50. package/dist/process-turn-navigation.d.ts.map +1 -1
  51. package/dist/process-ui-snapshot-presenter.d.ts +2 -1
  52. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  53. package/dist/routes/process-actions.d.ts.map +1 -1
  54. package/dist/routes/process-diagnostics-assembler.d.ts +3 -1
  55. package/dist/routes/process-diagnostics-assembler.d.ts.map +1 -1
  56. package/dist/routes/process-primary-path-assembler.d.ts +4 -12
  57. package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
  58. package/dist/routes/process-route-helpers.d.ts +7 -32
  59. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  60. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  61. package/dist/supervisor/worker-start-payload-builder.d.ts +2 -0
  62. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  63. package/dist/supervisor/worker-supervisor.d.ts +2 -0
  64. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  65. package/dist/supervisor/worker-turn-ipc-recorder.d.ts +2 -2
  66. package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
  67. package/dist/test-helpers/accepted-turn-start.d.ts +23 -4
  68. package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
  69. package/dist/test-helpers/owned-test-deps.d.ts +18 -0
  70. package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
  71. package/dist/test-helpers/prepared-fixture-start.d.ts +14 -0
  72. package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -0
  73. package/dist/testing.d.ts +2 -1
  74. package/dist/testing.d.ts.map +1 -1
  75. package/dist/testing.js +72 -11
  76. package/dist/testing.js.map +1 -1
  77. package/package.json +11 -11
  78. package/src/app.ts +2 -0
  79. package/src/db/database.ts +28 -0
  80. package/src/db/mapped-llm-run-repo.ts +177 -0
  81. package/src/db/process-turn-record-repo.ts +8 -1
  82. package/src/db/repo-helpers.ts +11 -1
  83. package/src/db/repositories.ts +5 -0
  84. package/src/db/schema.ts +70 -1
  85. package/src/db/turn-start-record-repo.ts +5 -1
  86. package/src/domain-logic/outcome-tools.ts +50 -6
  87. package/src/future-execution-presenter.ts +10 -17
  88. package/src/launch-coordinator-test-harness.ts +8 -4
  89. package/src/process-action-presenter.ts +133 -0
  90. package/src/process-engine/engine.ts +2 -2
  91. package/src/process-engine/mapped-turns.ts +330 -0
  92. package/src/process-engine/operation.ts +1 -1
  93. package/src/process-engine/ops/accept-worker-turn-start.ts +6 -0
  94. package/src/process-engine/ops/retry-startup.ts +1 -0
  95. package/src/process-engine/ops/turn-outcome.ts +7 -5
  96. package/src/process-engine/recorder.ts +12 -0
  97. package/src/process-engine/runner.ts +8 -8
  98. package/src/process-engine/types.ts +6 -0
  99. package/src/process-engine/writes/build-process-abort-writes.ts +1 -0
  100. package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
  101. package/src/process-engine/writes/build-turn-outcome-writes.ts +80 -20
  102. package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
  103. package/src/process-engine/writes/commit-writes.ts +5 -0
  104. package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
  105. package/src/process-engine/writes/writes.ts +27 -0
  106. package/src/process-turn-navigation.ts +86 -8
  107. package/src/process-ui-snapshot-presenter.ts +40 -4
  108. package/src/routes/process-actions.ts +1 -1
  109. package/src/routes/process-diagnostics-assembler.ts +32 -6
  110. package/src/routes/process-primary-path-assembler.ts +17 -33
  111. package/src/routes/process-route-helpers.ts +8 -165
  112. package/src/supervisor/ipc-handler.ts +27 -18
  113. package/src/supervisor/worker-start-payload-builder.ts +25 -0
  114. package/src/supervisor/worker-supervisor.ts +2 -0
  115. package/src/supervisor/worker-turn-ipc-recorder.ts +13 -1
  116. package/src/test-helpers/accepted-turn-start.ts +54 -27
  117. package/src/test-helpers/owned-test-deps.ts +45 -0
  118. package/src/test-helpers/prepared-fixture-start.ts +74 -0
  119. package/src/testing.ts +5 -1
  120. package/dist/app-7PKX73TU.js +0 -8
  121. package/dist/chunk-CNITOV76.js.map +0 -1
  122. package/dist/chunk-ZSKM25SD.js.map +0 -1
  123. /package/dist/{app-7PKX73TU.js.map → app-MSJXFK33.js.map} +0 -0
@@ -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
+ }
@@ -0,0 +1,74 @@
1
+ import type { ProcessInstance, ResolvedTurnStart } from "@leitwerk-dev/domain";
2
+ import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
3
+ import type { PiResourceBundle } from "@leitwerk-dev/worker-protocol";
4
+ import type { AppContext } from "../app.js";
5
+ import { createPiResourceBundleCache } from "../pi-resources/index.js";
6
+ import { prepareCreatedTurnStarts } from "../process-engine/turn-start-preflight.js";
7
+ import { createWrites, type TurnStartWrite } from "../process-engine/writes/writes.js";
8
+
9
+ /** Prepare fixture resources through the same provider preflight as admitted work. @internal */
10
+ export async function prepareAcceptedFixtureStart(
11
+ ctx: AppContext,
12
+ process: ProcessInstance,
13
+ turnId: string,
14
+ contributions: ExtensionCatalog["piContributions"],
15
+ ): Promise<{
16
+ /** @internal */
17
+ start: Extract<ResolvedTurnStart, { kind: "llm" }>;
18
+ /** @internal */
19
+ bundle: PiResourceBundle;
20
+ }> {
21
+ const profileId =
22
+ process.selectedTurnModelProfileId ??
23
+ process.defaultModelProfileId ??
24
+ ctx.config.process_configs?.[process.processId]?.default_model_profile;
25
+ const write: Extract<TurnStartWrite, { kind: "create" }> = {
26
+ kind: "create",
27
+ input: {
28
+ instanceId: process.id,
29
+ turnId,
30
+ turnType: "llm",
31
+ proposedTurnRecordId: "fixture-preflight",
32
+ startKind: "selected_turn",
33
+ recoveryTurnRecordId: null,
34
+ continuation: null,
35
+ state: {
36
+ kind: "preparation_failed",
37
+ requestedModelProfileId: profileId ?? null,
38
+ providerOptions: {},
39
+ code: "model_required",
40
+ safeSummary: "Fixture preparation",
41
+ },
42
+ },
43
+ };
44
+ const writes = createWrites({ turnStartWrites: [write] });
45
+ const bundleCache = createPiResourceBundleCache();
46
+ const result = await prepareCreatedTurnStarts(
47
+ {
48
+ config: ctx.config,
49
+ registry: ctx.modelProviderRegistry,
50
+ modelStatusCache: ctx.modelStatusCache,
51
+ piContributions: contributions,
52
+ bundleCache,
53
+ projects: ctx.deps.projects,
54
+ processSkills: ctx.deps.processSkills,
55
+ },
56
+ { ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },
57
+ writes,
58
+ );
59
+ if (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);
60
+ const state = write.input.state;
61
+ if (state.kind !== "starting" || state.start.kind !== "llm") {
62
+ throw new Error(
63
+ `Cannot prepare accepted fixture: ${state.kind === "preparation_failed" ? state.safeSummary : state.kind}`,
64
+ );
65
+ }
66
+ const bundle = bundleCache.get(state.start.piResourceSnapshotDigest);
67
+ if (!bundle) throw new Error("Prepared fixture resource bundle is missing");
68
+ return {
69
+ /** @internal */
70
+ start: state.start,
71
+ /** @internal */
72
+ bundle,
73
+ };
74
+ }
package/src/testing.ts CHANGED
@@ -1,6 +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 { createAcceptedLlmTurn } from "./test-helpers/accepted-turn-start.js";
4
+ export {
5
+ createAcceptedLlmTurn,
6
+ createAcceptedWorkerTurn,
7
+ } from "./test-helpers/accepted-turn-start.js";
8
+ export { prepareAcceptedFixtureStart } from "./test-helpers/prepared-fixture-start.js";
5
9
  export { writeProcessSessionSnapshot } from "./test-helpers/session-snapshot-fixtures.js";
6
10
  export { createTestDeps } from "./test-helpers/unit-deps.js";
@@ -1,8 +0,0 @@
1
- import {
2
- createAppContext
3
- } from "./chunk-CNITOV76.js";
4
- import "./chunk-ZSKM25SD.js";
5
- export {
6
- createAppContext
7
- };
8
- //# sourceMappingURL=app-7PKX73TU.js.map