@leitwerk-dev/server 0.3.1 → 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-BuJCdkvy.d.ts → app-CsuxFZT5.d.ts} +262 -121
- 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-QCHS3X33.js → chunk-FPMDWQF7.js} +2617 -562
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-MBHRCQFE.js} +2303 -1576
- 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/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 +4 -0
- 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/repositories.d.ts +12 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +693 -2
- 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.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.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 +1 -6
- package/dist/process-action-presenter.d.ts.map +1 -1
- 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.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 +5 -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-turn-outcome-writes.d.ts +2 -0
- package/dist/process-engine/writes/build-turn-outcome-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/writes.d.ts +28 -60
- 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-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +14 -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-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-route-helpers.d.ts +8 -9
- 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.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- 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.js +2 -1
- 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 +115 -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 +131 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -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 +45 -12
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repositories.ts +17 -0
- package/src/db/schema.ts +103 -1
- 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 +8 -2
- 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 -193
- 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 +7 -8
- package/src/integration-tool-registry.ts +59 -26
- 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 +22 -57
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +11 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- 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 +9 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +61 -60
- 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 +21 -5
- 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 +9 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
- package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
- package/src/process-engine/writes/commit-writes.ts +15 -2
- package/src/process-engine/writes/writes.ts +59 -74
- 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-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +210 -295
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +9 -9
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-route-helpers.ts +153 -162
- 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 +2 -0
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +17 -0
- package/src/supervisor/worker-supervisor.ts +3 -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/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-MSJXFK33.js +0 -8
- package/dist/chunk-HK6BLLHA.js.map +0 -1
- package/dist/chunk-QCHS3X33.js.map +0 -1
- /package/dist/{app-MSJXFK33.js.map → app-JM4CBTND.js.map} +0 -0
|
@@ -17,6 +17,7 @@ import { resolveDockerRegistryCredentials } from "../docker-registry-credentials
|
|
|
17
17
|
import { isValidStorageSize } from "../process-storage-size.js";
|
|
18
18
|
import { SAFE_SKILL_ID_PATTERN } from "../skills/skill-id.js";
|
|
19
19
|
import type { LeitwerkConfig } from "./config-types.js";
|
|
20
|
+
import { resolveKubernetesDockerIsolation } from "./kubernetes-docker-isolation.js";
|
|
20
21
|
import { isHttpsOrLoopbackHttpUrl, isValidHttpUrl, parseHttpUrl } from "./url-policy.js";
|
|
21
22
|
|
|
22
23
|
const DEFAULT_SEARCH_PATHS = ["./leitwerk.yaml", "~/.leitwerk/leitwerk.yaml"];
|
|
@@ -135,12 +136,19 @@ export function loadConfigFromFile(filePath: string): ConfigLoadResult | ConfigL
|
|
|
135
136
|
export function loadConfig(explicitPath?: string): ConfigLoadResult | ConfigLoadError {
|
|
136
137
|
const filePath = resolveConfigPath(explicitPath);
|
|
137
138
|
if (!filePath) {
|
|
138
|
-
return {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
error:
|
|
142
|
+
"Configuration file required: configure pi.default_model_profile and pi.model_profiles",
|
|
143
|
+
};
|
|
139
144
|
}
|
|
140
145
|
return loadConfigFromFile(filePath);
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
const stringArraySchema = v.array(v.string());
|
|
149
|
+
const skillIdsSchema = v.array(
|
|
150
|
+
v.pipe(v.string(), v.regex(SAFE_SKILL_ID_PATTERN, "Invalid skill ID")),
|
|
151
|
+
);
|
|
144
152
|
const modelTurnConfigSchema = v.looseObject({
|
|
145
153
|
model_profile: v.optional(v.string()),
|
|
146
154
|
});
|
|
@@ -287,6 +295,10 @@ const configSchema = v.looseObject({
|
|
|
287
295
|
),
|
|
288
296
|
pi: v.looseObject({
|
|
289
297
|
agent_dir: v.string(),
|
|
298
|
+
default_model_profile: v.pipe(
|
|
299
|
+
v.string(),
|
|
300
|
+
v.check((value) => value.trim() !== "", "Must be a non-empty model profile ID"),
|
|
301
|
+
),
|
|
290
302
|
model_profiles: v.array(
|
|
291
303
|
v.looseObject({
|
|
292
304
|
id: v.string(),
|
|
@@ -320,6 +332,7 @@ const configSchema = v.looseObject({
|
|
|
320
332
|
v.record(
|
|
321
333
|
v.string(),
|
|
322
334
|
v.looseObject({
|
|
335
|
+
default_skills: v.optional(skillIdsSchema),
|
|
323
336
|
default_model_profile: v.optional(v.string()),
|
|
324
337
|
allowed_model_profiles: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
|
|
325
338
|
worker_runtime_profile: v.optional(v.string()),
|
|
@@ -350,6 +363,7 @@ const configSchema = v.looseObject({
|
|
|
350
363
|
sources: stringArraySchema,
|
|
351
364
|
}),
|
|
352
365
|
auth: v.optional(authConfigSchema),
|
|
366
|
+
default_skills: v.optional(skillIdsSchema),
|
|
353
367
|
docker_registries: v.optional(
|
|
354
368
|
v.strictObject({
|
|
355
369
|
profiles: v.record(v.string(), v.strictObject(dockerRegistryCredentialSchema.entries)),
|
|
@@ -381,6 +395,7 @@ const configSchema = v.looseObject({
|
|
|
381
395
|
api_server_url: v.optional(v.string()),
|
|
382
396
|
default_worker_runtime_profile: v.optional(v.string()),
|
|
383
397
|
worker_service_account: v.optional(v.string()),
|
|
398
|
+
image_preload: v.optional(v.strictObject({ enabled: v.boolean() })),
|
|
384
399
|
process_volume: v.looseObject({
|
|
385
400
|
storage_class_name: v.optional(v.string()),
|
|
386
401
|
pre_provision: v.optional(
|
|
@@ -392,8 +407,11 @@ const configSchema = v.looseObject({
|
|
|
392
407
|
}),
|
|
393
408
|
docker: v.optional(
|
|
394
409
|
v.strictObject({
|
|
410
|
+
worker_runtime_profile: v.optional(v.pipe(v.string(), v.trim(), v.nonEmpty())),
|
|
411
|
+
node_selector: v.optional(v.record(v.string(), v.string())),
|
|
395
412
|
runtime_class_name: v.optional(v.string()),
|
|
396
413
|
host_users: v.optional(v.boolean()),
|
|
414
|
+
isolation: v.optional(v.picklist(["gvisor", "virtual-machine"])),
|
|
397
415
|
gvisor: v.optional(v.boolean()),
|
|
398
416
|
process_storage_class_name: v.optional(v.string()),
|
|
399
417
|
network: v.optional(dockerNetworkSchema),
|
|
@@ -495,6 +513,11 @@ function collectModelProfileReferenceErrors(config: LeitwerkConfig): string[] {
|
|
|
495
513
|
.filter((profileId) => typeof profileId === "string" && profileId.trim() !== ""),
|
|
496
514
|
);
|
|
497
515
|
const titleModelProfile = config.pi.process_title_generation.model_profile;
|
|
516
|
+
if (!configuredModelProfileIds.has(config.pi.default_model_profile)) {
|
|
517
|
+
errors.push(
|
|
518
|
+
`Unknown model profile '${config.pi.default_model_profile}' at pi.default_model_profile`,
|
|
519
|
+
);
|
|
520
|
+
}
|
|
498
521
|
if (typeof titleModelProfile === "string") {
|
|
499
522
|
if (titleModelProfile.trim() === "") {
|
|
500
523
|
errors.push(
|
|
@@ -560,6 +583,10 @@ function collectWorkerRuntimeProfileErrors(config: LeitwerkConfig): string[] {
|
|
|
560
583
|
config.kubernetes?.default_worker_runtime_profile,
|
|
561
584
|
"kubernetes.default_worker_runtime_profile",
|
|
562
585
|
);
|
|
586
|
+
checkReference(
|
|
587
|
+
config.kubernetes?.docker?.worker_runtime_profile,
|
|
588
|
+
"kubernetes.docker.worker_runtime_profile",
|
|
589
|
+
);
|
|
563
590
|
}
|
|
564
591
|
for (const [key, component] of Object.entries(config.components)) {
|
|
565
592
|
checkReference(component.worker_runtime_profile, `components.${key}.worker_runtime_profile`);
|
|
@@ -737,6 +764,14 @@ function collectKubernetesRunnerConfigErrors(config: LeitwerkConfig): string[] {
|
|
|
737
764
|
errors.push(
|
|
738
765
|
"worker_runtime_profiles must include at least one profile when workers.runner is 'kubernetes'",
|
|
739
766
|
);
|
|
767
|
+
if (k.image_preload?.enabled) {
|
|
768
|
+
for (const [id, profile] of Object.entries(config.worker_runtime_profiles ?? {})) {
|
|
769
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*@sha256:[0-9a-f]{64}$/.test(profile.image))
|
|
770
|
+
errors.push(
|
|
771
|
+
`worker_runtime_profiles.${id}.image must be digest-qualified when kubernetes.image_preload.enabled is true`,
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
740
775
|
const defaultProfile = k.default_worker_runtime_profile ?? config.workers.default_runtime_profile;
|
|
741
776
|
if (!defaultProfile?.trim())
|
|
742
777
|
errors.push(
|
|
@@ -935,6 +970,7 @@ function validateResolvedConfig(config: Record<string, unknown>): string[] {
|
|
|
935
970
|
...collectLocalRunnerConfigErrors(resolvedConfig),
|
|
936
971
|
...collectDockerRunnerConfigErrors(resolvedConfig),
|
|
937
972
|
...collectKubernetesRunnerConfigErrors(resolvedConfig),
|
|
973
|
+
...resolveKubernetesDockerIsolation(resolvedConfig.kubernetes?.docker).errors,
|
|
938
974
|
...collectInternalTlsConfigErrors(resolvedConfig),
|
|
939
975
|
...collectAuthConfigErrors(resolvedConfig),
|
|
940
976
|
];
|
|
@@ -974,7 +1010,7 @@ export function sanitizeConfigForLogging(value: unknown, path: readonly string[]
|
|
|
974
1010
|
return sanitized;
|
|
975
1011
|
}
|
|
976
1012
|
|
|
977
|
-
/** @public */
|
|
1013
|
+
/** Configuration template; set model_profiles and default_model_profile before startup. @public */
|
|
978
1014
|
export function getDefaultConfig(): LeitwerkConfig {
|
|
979
1015
|
return {
|
|
980
1016
|
skill_repositories: [],
|
|
@@ -1028,6 +1064,7 @@ export function getDefaultConfig(): LeitwerkConfig {
|
|
|
1028
1064
|
pi: {
|
|
1029
1065
|
agent_dir: "~/.pi/leitwerk",
|
|
1030
1066
|
model_profiles: [],
|
|
1067
|
+
default_model_profile: "",
|
|
1031
1068
|
process_title_generation: {
|
|
1032
1069
|
model_profile: null,
|
|
1033
1070
|
retry: {
|
|
@@ -1048,6 +1085,7 @@ export function getDefaultConfig(): LeitwerkConfig {
|
|
|
1048
1085
|
},
|
|
1049
1086
|
},
|
|
1050
1087
|
process_configs: {},
|
|
1088
|
+
default_skills: [],
|
|
1051
1089
|
notifications: {
|
|
1052
1090
|
all: { enabled: false, type: "teams_webhook", url: "" },
|
|
1053
1091
|
debug: { enabled: false, type: "teams_webhook", url: "" },
|
|
@@ -165,11 +165,17 @@ export interface KubernetesProcessVolumeConfig {
|
|
|
165
165
|
|
|
166
166
|
/** @internal */
|
|
167
167
|
export interface KubernetesDockerConfig {
|
|
168
|
+
/** Default profile for Docker processes without an explicit process/component profile. @internal */
|
|
169
|
+
worker_runtime_profile?: string;
|
|
170
|
+
/** Docker-only selector keys override matching global Pod selector keys. @internal */
|
|
171
|
+
node_selector?: Record<string, string>;
|
|
168
172
|
/** Pod RuntimeClass selected for every Docker-requiring process. @internal */
|
|
169
173
|
runtime_class_name?: string;
|
|
170
174
|
/** Pod user-namespace policy passed directly to spec.hostUsers. @internal */
|
|
171
175
|
host_users?: boolean;
|
|
172
|
-
/**
|
|
176
|
+
/** Trusted sandbox policy for a separately qualified cluster runtime. @internal */
|
|
177
|
+
isolation?: "gvisor" | "virtual-machine";
|
|
178
|
+
/** Legacy alias for isolation: gvisor when isolation is omitted. @internal */
|
|
173
179
|
gvisor?: boolean;
|
|
174
180
|
/** StorageClass selected for the process's single retained PVC. @internal */
|
|
175
181
|
process_storage_class_name?: string;
|
|
@@ -217,6 +223,11 @@ export interface LocalWorkerRunnerConfig {
|
|
|
217
223
|
|
|
218
224
|
/** @internal */
|
|
219
225
|
export interface KubernetesRunnerConfig {
|
|
226
|
+
/** Optional worker image preparation on eligible nodes; disabled by default. @internal */
|
|
227
|
+
image_preload?: {
|
|
228
|
+
/** @internal */
|
|
229
|
+
enabled: boolean;
|
|
230
|
+
};
|
|
220
231
|
/** Dedicated namespace where the singleton server runs. @internal */
|
|
221
232
|
server_namespace: string;
|
|
222
233
|
/** Safe DNS prefix used to derive one namespace per process instance. @internal */
|
|
@@ -394,6 +405,8 @@ export interface LeitwerkConfig extends ConfigSnapshot {
|
|
|
394
405
|
internal_tls?: InternalTlsConfig;
|
|
395
406
|
/** Git repositories scanned for operator-managed skills. @internal */
|
|
396
407
|
skill_repositories?: SkillRepositoryConfig[];
|
|
408
|
+
/** Installed skill IDs included in new launches unless replaced by process defaults. @public */
|
|
409
|
+
default_skills?: string[];
|
|
397
410
|
/** Server-owned repository-aware commit-message generation rules. @internal */
|
|
398
411
|
commit_messages?: CommitMessageConfig;
|
|
399
412
|
/** Bounded archive and extraction ceilings for local session transfer. @internal */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { KubernetesDockerConfig } from "./config-types.js";
|
|
2
|
+
|
|
3
|
+
/** Normalize trusted sandbox selection before passing it to a worker runner. @internal */
|
|
4
|
+
export function resolveKubernetesDockerIsolation(docker: KubernetesDockerConfig | undefined): {
|
|
5
|
+
isolation: KubernetesDockerConfig["isolation"];
|
|
6
|
+
errors: string[];
|
|
7
|
+
} {
|
|
8
|
+
const isolation = docker?.isolation ?? (docker?.gvisor ? "gvisor" : undefined);
|
|
9
|
+
const errors: string[] = [];
|
|
10
|
+
if (
|
|
11
|
+
docker?.isolation !== undefined &&
|
|
12
|
+
docker.gvisor !== undefined &&
|
|
13
|
+
docker.gvisor !== (docker.isolation === "gvisor")
|
|
14
|
+
) {
|
|
15
|
+
errors.push("kubernetes.docker.gvisor conflicts with kubernetes.docker.isolation");
|
|
16
|
+
}
|
|
17
|
+
if (isolation !== undefined && docker?.host_users !== undefined) {
|
|
18
|
+
errors.push("kubernetes.docker.host_users must be omitted for sandbox isolation");
|
|
19
|
+
}
|
|
20
|
+
return { isolation, errors };
|
|
21
|
+
}
|
package/src/db/database.ts
CHANGED
|
@@ -44,6 +44,17 @@ export class DatabaseSchemaMismatchError extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const ALL_TABLES = [
|
|
47
|
+
schema.wikiTopics,
|
|
48
|
+
schema.wikiPages,
|
|
49
|
+
schema.wikiRevisions,
|
|
50
|
+
schema.topicPublications,
|
|
51
|
+
schema.inspectionContents,
|
|
52
|
+
schema.executionInspections,
|
|
53
|
+
|
|
54
|
+
schema.settingsSubjects,
|
|
55
|
+
schema.settingsAliases,
|
|
56
|
+
schema.settingsOverrides,
|
|
57
|
+
schema.settingsSubjectRedirects,
|
|
47
58
|
schema.startupObservations,
|
|
48
59
|
schema.processInstances,
|
|
49
60
|
schema.launchRuns,
|
|
@@ -338,25 +349,82 @@ interface KnownMigration {
|
|
|
338
349
|
apply(sqlite: DatabaseSync): void;
|
|
339
350
|
}
|
|
340
351
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
352
|
+
function addTablesMigration(
|
|
353
|
+
id: string,
|
|
354
|
+
tables: readonly SQLiteTable[],
|
|
355
|
+
matches: KnownMigration["matches"],
|
|
356
|
+
): KnownMigration {
|
|
357
|
+
return {
|
|
358
|
+
id,
|
|
359
|
+
tableNames: tables.map(getTableName),
|
|
360
|
+
matches,
|
|
347
361
|
apply(sqlite) {
|
|
348
|
-
createTableWithIndexes(sqlite,
|
|
362
|
+
for (const table of tables) createTableWithIndexes(sqlite, table);
|
|
349
363
|
},
|
|
350
|
-
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const HISTORY_INDEXES = [
|
|
367
|
+
"idx_turn_records_page",
|
|
368
|
+
"idx_turn_annotations_created",
|
|
369
|
+
"idx_worker_leases_started",
|
|
370
|
+
"idx_worker_leases_exited",
|
|
371
|
+
] as const;
|
|
372
|
+
|
|
373
|
+
const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
351
374
|
{
|
|
352
|
-
id: "
|
|
353
|
-
tableNames: [
|
|
375
|
+
id: "20261008_remove_repository_instruction_overrides",
|
|
376
|
+
tableNames: [],
|
|
354
377
|
matches: (sqlite) =>
|
|
355
|
-
|
|
378
|
+
existingTableSql(sqlite, "settings_overrides") !== null &&
|
|
379
|
+
Boolean(
|
|
380
|
+
sqlite
|
|
381
|
+
.prepare("SELECT 1 FROM settings_overrides WHERE key = ? LIMIT 1")
|
|
382
|
+
.get("coding.repository_instructions"),
|
|
383
|
+
),
|
|
356
384
|
apply(sqlite) {
|
|
357
|
-
|
|
385
|
+
sqlite
|
|
386
|
+
.prepare("DELETE FROM settings_overrides WHERE key = ?")
|
|
387
|
+
.run("coding.repository_instructions");
|
|
358
388
|
},
|
|
359
389
|
},
|
|
390
|
+
addTablesMigration(
|
|
391
|
+
"20260930_add_topic_wiki",
|
|
392
|
+
[schema.wikiTopics, schema.wikiPages, schema.wikiRevisions, schema.topicPublications],
|
|
393
|
+
(sqlite) => hasExistingSchema(sqlite) && existingTableSql(sqlite, "wiki_topics") === null,
|
|
394
|
+
),
|
|
395
|
+
addTablesMigration(
|
|
396
|
+
"20260925_add_execution_inspections",
|
|
397
|
+
[schema.inspectionContents, schema.executionInspections],
|
|
398
|
+
(sqlite) =>
|
|
399
|
+
hasExistingSchema(sqlite) && existingTableSql(sqlite, "execution_inspections") === null,
|
|
400
|
+
),
|
|
401
|
+
addTablesMigration(
|
|
402
|
+
"20260926_add_scoped_settings",
|
|
403
|
+
[schema.settingsSubjects, schema.settingsAliases, schema.settingsOverrides],
|
|
404
|
+
(sqlite) =>
|
|
405
|
+
existingTableSql(sqlite, "process_instances") !== null &&
|
|
406
|
+
existingTableSql(sqlite, "settings_subjects") === null &&
|
|
407
|
+
existingTableSql(sqlite, "settings_aliases") === null &&
|
|
408
|
+
existingTableSql(sqlite, "settings_overrides") === null,
|
|
409
|
+
),
|
|
410
|
+
addTablesMigration(
|
|
411
|
+
"20260926_add_settings_subject_redirects",
|
|
412
|
+
[schema.settingsSubjectRedirects],
|
|
413
|
+
(sqlite) =>
|
|
414
|
+
hasExistingSchema(sqlite) && existingTableSql(sqlite, "settings_subject_redirects") === null,
|
|
415
|
+
),
|
|
416
|
+
addTablesMigration(
|
|
417
|
+
"20260911_add_startup_observations",
|
|
418
|
+
[schema.startupObservations],
|
|
419
|
+
(sqlite) =>
|
|
420
|
+
hasExistingSchema(sqlite) && existingTableSql(sqlite, "startup_observations") === null,
|
|
421
|
+
),
|
|
422
|
+
addTablesMigration(
|
|
423
|
+
"20260823_add_ticket_destination_recents",
|
|
424
|
+
[schema.ticketDestinationRecents],
|
|
425
|
+
(sqlite) =>
|
|
426
|
+
hasExistingSchema(sqlite) && existingTableSql(sqlite, "ticket_destination_recents") === null,
|
|
427
|
+
),
|
|
360
428
|
{
|
|
361
429
|
id: "20260909_add_reasoning_summaries",
|
|
362
430
|
tableNames: ["process_events", "turn_summaries", "session_summaries"],
|
|
@@ -391,14 +459,13 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
|
391
459
|
createTableWithIndexes(sqlite, schema.sessionSummaries);
|
|
392
460
|
},
|
|
393
461
|
},
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
462
|
+
addTablesMigration(
|
|
463
|
+
"20260908_add_api_tokens",
|
|
464
|
+
[schema.apiTokens],
|
|
465
|
+
(sqlite) =>
|
|
398
466
|
existingTableSql(sqlite, "auth_sessions") !== null &&
|
|
399
467
|
existingTableSql(sqlite, "api_tokens") === null,
|
|
400
|
-
|
|
401
|
-
},
|
|
468
|
+
),
|
|
402
469
|
{
|
|
403
470
|
id: "20260901_add_session_transfers",
|
|
404
471
|
tableNames: ["session_transfer_grants", "session_transfer_attempts"],
|
|
@@ -553,18 +620,13 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
|
553
620
|
}
|
|
554
621
|
},
|
|
555
622
|
},
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
623
|
+
addTablesMigration(
|
|
624
|
+
"20260726_add_sql_backed_skills",
|
|
625
|
+
[schema.skills, schema.skillRevisions, schema.processSkills],
|
|
626
|
+
(sqlite) =>
|
|
560
627
|
existingTableSql(sqlite, "process_instances") !== null &&
|
|
561
628
|
existingTableSql(sqlite, "skills") === null,
|
|
562
|
-
|
|
563
|
-
for (const table of [schema.skills, schema.skillRevisions, schema.processSkills]) {
|
|
564
|
-
createTableWithIndexes(sqlite, table);
|
|
565
|
-
}
|
|
566
|
-
},
|
|
567
|
-
},
|
|
629
|
+
),
|
|
568
630
|
{
|
|
569
631
|
id: "20260728_add_skill_catalog_and_invocations",
|
|
570
632
|
tableNames: ["skills", "skill_catalog_entries", "skill_invocations"],
|
|
@@ -599,21 +661,30 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
|
599
661
|
},
|
|
600
662
|
},
|
|
601
663
|
{
|
|
602
|
-
id: "
|
|
603
|
-
tableNames: ["
|
|
604
|
-
matches: (sqlite) =>
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
},
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
id: "20260726_add_process_question_requests",
|
|
611
|
-
tableNames: ["process_question_requests"],
|
|
612
|
-
matches: (sqlite) => existingTableSql(sqlite, "process_question_requests") === null,
|
|
664
|
+
id: "20261006_add_extension_skill_provenance",
|
|
665
|
+
tableNames: ["skills", "skill_revisions"],
|
|
666
|
+
matches: (sqlite) =>
|
|
667
|
+
!tableHasColumn(sqlite, "skills", "owner_extension_id") ||
|
|
668
|
+
!tableHasColumn(sqlite, "skill_revisions", "provenance_json"),
|
|
613
669
|
apply(sqlite) {
|
|
614
|
-
|
|
670
|
+
if (!tableHasColumn(sqlite, "skills", "owner_extension_id")) {
|
|
671
|
+
sqlite.exec("ALTER TABLE skills ADD COLUMN owner_extension_id text");
|
|
672
|
+
}
|
|
673
|
+
if (!tableHasColumn(sqlite, "skill_revisions", "provenance_json")) {
|
|
674
|
+
sqlite.exec("ALTER TABLE skill_revisions ADD COLUMN provenance_json text");
|
|
675
|
+
}
|
|
615
676
|
},
|
|
616
677
|
},
|
|
678
|
+
addTablesMigration(
|
|
679
|
+
"20260729_add_skill_revision_dependencies",
|
|
680
|
+
[schema.skillRevisionDependencies],
|
|
681
|
+
(sqlite) => existingTableSql(sqlite, "skill_revision_dependencies") === null,
|
|
682
|
+
),
|
|
683
|
+
addTablesMigration(
|
|
684
|
+
"20260726_add_process_question_requests",
|
|
685
|
+
[schema.processQuestionRequests],
|
|
686
|
+
(sqlite) => existingTableSql(sqlite, "process_question_requests") === null,
|
|
687
|
+
),
|
|
617
688
|
{
|
|
618
689
|
id: "20260725_add_model_policy_provenance_and_future_blocks",
|
|
619
690
|
tableNames: ["process_instances", "future_executions", "turn_records"],
|
|
@@ -864,6 +935,26 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
|
864
935
|
}
|
|
865
936
|
},
|
|
866
937
|
},
|
|
938
|
+
{
|
|
939
|
+
id: "20261005_add_process_history_indexes",
|
|
940
|
+
tableNames: [],
|
|
941
|
+
legacyIndexNames: [...HISTORY_INDEXES, "idx_leaf_outcomes_anchored"],
|
|
942
|
+
matches(sqlite) {
|
|
943
|
+
const indexes = existingSchemaObjects(sqlite, "index");
|
|
944
|
+
return (
|
|
945
|
+
hasExistingSchema(sqlite) &&
|
|
946
|
+
(indexes.has("idx_leaf_outcomes_anchored") ||
|
|
947
|
+
HISTORY_INDEXES.some((name) => !indexes.has(name)))
|
|
948
|
+
);
|
|
949
|
+
},
|
|
950
|
+
apply(sqlite) {
|
|
951
|
+
sqlite.exec(`CREATE INDEX IF NOT EXISTS idx_turn_records_page ON turn_records(instance_id, started_at, id);
|
|
952
|
+
CREATE INDEX IF NOT EXISTS idx_turn_annotations_created ON turn_annotations(instance_id, created_at);
|
|
953
|
+
CREATE INDEX IF NOT EXISTS idx_worker_leases_started ON worker_leases(instance_id, started_at);
|
|
954
|
+
CREATE INDEX IF NOT EXISTS idx_worker_leases_exited ON worker_leases(instance_id, exited_at);
|
|
955
|
+
DROP INDEX IF EXISTS idx_leaf_outcomes_anchored;`);
|
|
956
|
+
},
|
|
957
|
+
},
|
|
867
958
|
];
|
|
868
959
|
|
|
869
960
|
function backupSqliteFiles(sqlite: DatabaseSync, sqlitePath: string): string {
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
ExecutionInspectionCapture,
|
|
4
|
+
ExecutionInspectionRecord,
|
|
5
|
+
InspectionContextObservation,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
7
|
+
import type { InspectionConfigurationRevision } from "@leitwerk-dev/protocol";
|
|
8
|
+
import { and, asc, eq, inArray, sql } from "drizzle-orm";
|
|
9
|
+
import type { LeitwerkDb } from "./database.js";
|
|
10
|
+
import { executionInspections, inspectionContents } from "./schema.js";
|
|
11
|
+
|
|
12
|
+
/** Immutable content and incremental observation references. No session ancestry is copied. @internal */
|
|
13
|
+
export function createExecutionInspectionRepo(db: LeitwerkDb) {
|
|
14
|
+
function pack(value: unknown): unknown {
|
|
15
|
+
if (Array.isArray(value)) return value.map(pack);
|
|
16
|
+
if (!value || typeof value !== "object") return value;
|
|
17
|
+
const record = value as Record<string, unknown>;
|
|
18
|
+
if ((record.state === "recorded" || record.state === "redacted") && "value" in record) {
|
|
19
|
+
const contentJson = JSON.stringify(record.value);
|
|
20
|
+
const digest = createHash("sha256").update(contentJson).digest("hex");
|
|
21
|
+
db.insert(inspectionContents).values({ digest, contentJson }).onConflictDoNothing().run();
|
|
22
|
+
return { state: record.state, contentDigest: digest };
|
|
23
|
+
}
|
|
24
|
+
return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, pack(item)]));
|
|
25
|
+
}
|
|
26
|
+
function unpack(value: unknown): unknown {
|
|
27
|
+
if (Array.isArray(value)) return value.map(unpack);
|
|
28
|
+
if (!value || typeof value !== "object") return value;
|
|
29
|
+
const record = value as Record<string, unknown>;
|
|
30
|
+
if (typeof record.contentDigest === "string") {
|
|
31
|
+
const row = db
|
|
32
|
+
.select()
|
|
33
|
+
.from(inspectionContents)
|
|
34
|
+
.where(eq(inspectionContents.digest, record.contentDigest))
|
|
35
|
+
.get();
|
|
36
|
+
return row
|
|
37
|
+
? { state: record.state, value: JSON.parse(row.contentJson) }
|
|
38
|
+
: { state: "unavailable", reason: "Recorded content is unavailable" };
|
|
39
|
+
}
|
|
40
|
+
return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, unpack(item)]));
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
/** Model identities without loading retained prompts or message contents. @internal */
|
|
44
|
+
modelInputs(
|
|
45
|
+
instanceId: string,
|
|
46
|
+
turnRecordId: string,
|
|
47
|
+
): Pick<InspectionConfigurationRevision, "id" | "timestamp" | "boundaryEntryId" | "model">[] {
|
|
48
|
+
return db
|
|
49
|
+
.select({
|
|
50
|
+
id: executionInspections.id,
|
|
51
|
+
timestamp: executionInspections.capturedAt,
|
|
52
|
+
boundaryEntryId: sql<
|
|
53
|
+
string | null
|
|
54
|
+
>`json_extract(${executionInspections.factJson}, '$.boundaryEntryId')`,
|
|
55
|
+
model: sql<string>`json_extract(${executionInspections.factJson}, '$.model')`,
|
|
56
|
+
})
|
|
57
|
+
.from(executionInspections)
|
|
58
|
+
.where(
|
|
59
|
+
and(
|
|
60
|
+
eq(executionInspections.instanceId, instanceId),
|
|
61
|
+
eq(executionInspections.turnRecordId, turnRecordId),
|
|
62
|
+
sql`json_extract(${executionInspections.factJson}, '$.kind') = 'model_input'`,
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
.orderBy(asc(executionInspections.sequence))
|
|
66
|
+
.all()
|
|
67
|
+
.map((row) => ({
|
|
68
|
+
...row,
|
|
69
|
+
model: JSON.parse(row.model) as InspectionConfigurationRevision["model"],
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
/** @internal */
|
|
73
|
+
append(input: Omit<ExecutionInspectionRecord, "sequence">): "stored" | "replay" {
|
|
74
|
+
return db.transaction(() => {
|
|
75
|
+
const factJson = JSON.stringify(pack(input.fact));
|
|
76
|
+
const existing = db
|
|
77
|
+
.select()
|
|
78
|
+
.from(executionInspections)
|
|
79
|
+
.where(eq(executionInspections.id, input.id))
|
|
80
|
+
.get();
|
|
81
|
+
if (existing) {
|
|
82
|
+
if (
|
|
83
|
+
existing.instanceId !== input.instanceId ||
|
|
84
|
+
existing.turnRecordId !== input.turnRecordId ||
|
|
85
|
+
existing.factJson !== factJson
|
|
86
|
+
)
|
|
87
|
+
throw new Error("Inspection observation identity was reused with different evidence");
|
|
88
|
+
return "replay";
|
|
89
|
+
}
|
|
90
|
+
db.insert(executionInspections)
|
|
91
|
+
.values({
|
|
92
|
+
id: input.id,
|
|
93
|
+
instanceId: input.instanceId,
|
|
94
|
+
turnRecordId: input.turnRecordId,
|
|
95
|
+
startRecordId: input.startRecordId,
|
|
96
|
+
workerLeaseId: input.workerLeaseId,
|
|
97
|
+
capturedAt: input.timestamp,
|
|
98
|
+
factJson,
|
|
99
|
+
})
|
|
100
|
+
.run();
|
|
101
|
+
return "stored";
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
/** Expanded evidence is read only on demand. @internal */
|
|
105
|
+
list(instanceId: string, turnRecordId: string): ExecutionInspectionRecord[] {
|
|
106
|
+
return db
|
|
107
|
+
.select()
|
|
108
|
+
.from(executionInspections)
|
|
109
|
+
.where(
|
|
110
|
+
and(
|
|
111
|
+
eq(executionInspections.instanceId, instanceId),
|
|
112
|
+
eq(executionInspections.turnRecordId, turnRecordId),
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
.orderBy(asc(executionInspections.sequence))
|
|
116
|
+
.all()
|
|
117
|
+
.map((row) => ({
|
|
118
|
+
version: 1,
|
|
119
|
+
id: row.id,
|
|
120
|
+
sequence: row.sequence,
|
|
121
|
+
instanceId: row.instanceId,
|
|
122
|
+
turnRecordId: row.turnRecordId,
|
|
123
|
+
startRecordId: row.startRecordId,
|
|
124
|
+
workerLeaseId: row.workerLeaseId,
|
|
125
|
+
timestamp: row.capturedAt,
|
|
126
|
+
fact: unpack(JSON.parse(row.factJson)) as ExecutionInspectionCapture["fact"],
|
|
127
|
+
}));
|
|
128
|
+
},
|
|
129
|
+
/** Small origin/product references for compact lineage without loading prompts. @internal */
|
|
130
|
+
listContextFacts(instanceId: string, turnRecordIds?: string[]): InspectionContextObservation[] {
|
|
131
|
+
if (turnRecordIds?.length === 0) return [];
|
|
132
|
+
return db
|
|
133
|
+
.select()
|
|
134
|
+
.from(executionInspections)
|
|
135
|
+
.where(
|
|
136
|
+
and(
|
|
137
|
+
eq(executionInspections.instanceId, instanceId),
|
|
138
|
+
turnRecordIds ? inArray(executionInspections.turnRecordId, turnRecordIds) : undefined,
|
|
139
|
+
sql`json_extract(${executionInspections.factJson}, '$.kind') IN ('supplied_context', 'product_consumed', 'entry_link')`,
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
.orderBy(asc(executionInspections.sequence))
|
|
143
|
+
.all()
|
|
144
|
+
.map((row) => {
|
|
145
|
+
const fact = JSON.parse(row.factJson) as Extract<
|
|
146
|
+
ExecutionInspectionCapture["fact"],
|
|
147
|
+
{ kind: "supplied_context" | "product_consumed" | "entry_link" }
|
|
148
|
+
>;
|
|
149
|
+
return {
|
|
150
|
+
id: row.id,
|
|
151
|
+
turnRecordId: row.turnRecordId,
|
|
152
|
+
fact:
|
|
153
|
+
fact.kind === "supplied_context"
|
|
154
|
+
? {
|
|
155
|
+
...fact,
|
|
156
|
+
products: fact.products.map(({ content: _content, ...source }) => source),
|
|
157
|
+
}
|
|
158
|
+
: fact,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { and, gte, lte } from "drizzle-orm";
|
|
2
|
+
import type { SQLiteColumn } from "drizzle-orm/sqlite-core";
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export interface HistoryWindow {
|
|
6
|
+
/** @internal */
|
|
7
|
+
since?: string;
|
|
8
|
+
/** @internal */
|
|
9
|
+
until?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export function historyWindow(column: SQLiteColumn, window?: HistoryWindow) {
|
|
14
|
+
return and(
|
|
15
|
+
window?.since ? gte(column, window.since) : undefined,
|
|
16
|
+
window?.until ? lte(column, window.until) : undefined,
|
|
17
|
+
);
|
|
18
|
+
}
|