@leitwerk-dev/server 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
- package/dist/app-KR3N2JAE.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-OUA5EZS2.js} +3127 -689
- package/dist/chunk-OUA5EZS2.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
- package/dist/chunk-YLWY4UTT.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 +16 -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/dashboard-model-issues.d.ts +10 -0
- package/dist/dashboard-model-issues.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 +21 -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 +10 -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/domain-logic/worker-lease-lifecycle.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/automatic-retry-startup.d.ts +8 -0
- package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
- 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 +2 -0
- 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 +13 -2
- 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-availability-recovery.d.ts +1 -1
- package/dist/process-model-availability-recovery.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/dashboard.d.ts +17 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- 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 +98 -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 +7 -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 +4 -3
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/startup-retry-policy.d.ts +8 -0
- package/dist/startup-retry-policy.d.ts.map +1 -0
- 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 +177 -25
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +42 -2
- package/src/config/config-types.ts +16 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/dashboard-model-issues.ts +199 -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 +33 -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 +13 -3
- package/src/db/turn-summary-repo.ts +36 -4
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +18 -216
- package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
- 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 +25 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- package/src/process-engine/ops/automatic-retry-startup.ts +93 -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 +20 -16
- 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 +34 -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 +21 -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 +16 -4
- 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-availability-recovery.ts +6 -4
- 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/dashboard.ts +106 -0
- 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-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 +797 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +12 -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 +94 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +19 -6
- package/src/skills/source-importer.ts +7 -13
- package/src/startup-evidence.ts +29 -8
- package/src/startup-retry-policy.ts +106 -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 +26 -1
- 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-KR3N2JAE.js.map} +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { parseStrictInstanceTurnConfigsJson, trimToNull } from "@leitwerk-dev/domain";
|
|
2
|
+
import { parseFutureActionPayloadJson, parseFutureLaunchPayloadJson } from "@leitwerk-dev/protocol";
|
|
3
|
+
import type { DashboardConfigurationIssue } from "@leitwerk-dev/protocol/http-contracts";
|
|
4
|
+
import { presentProcessModelPolicyFailure } from "./process-model-policy-presenter.js";
|
|
5
|
+
import type { ProcessWatcherServiceLike } from "./process-watcher-registry.js";
|
|
6
|
+
import type { RouteDeps } from "./routes/process-route-helpers.js";
|
|
7
|
+
|
|
8
|
+
type IssueSource = DashboardConfigurationIssue["sources"][number];
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export type DashboardModelIssueDeps = Pick<
|
|
12
|
+
RouteDeps,
|
|
13
|
+
| "config"
|
|
14
|
+
| "processModelPolicy"
|
|
15
|
+
| "modelStatusCache"
|
|
16
|
+
| "processes"
|
|
17
|
+
| "futureExecutions"
|
|
18
|
+
| "scopedSettingsService"
|
|
19
|
+
| "processGraphs"
|
|
20
|
+
> & { /** @internal */ processWatchers?: ProcessWatcherServiceLike };
|
|
21
|
+
|
|
22
|
+
/** Reads cached availability and model references; never resolves launches or process contexts. @internal */
|
|
23
|
+
export function buildDashboardModelIssues(
|
|
24
|
+
deps: DashboardModelIssueDeps,
|
|
25
|
+
): DashboardConfigurationIssue[] {
|
|
26
|
+
const issues = new Map<string, DashboardConfigurationIssue>();
|
|
27
|
+
const availability = deps.modelStatusCache.snapshot();
|
|
28
|
+
function add(code: string, key: string, message: string, source: IssueSource) {
|
|
29
|
+
const id = JSON.stringify([code, key]);
|
|
30
|
+
const issue = issues.get(id) ?? {
|
|
31
|
+
id,
|
|
32
|
+
code,
|
|
33
|
+
severity: code === "model_stale" ? ("warning" as const) : ("error" as const),
|
|
34
|
+
message,
|
|
35
|
+
sources: [],
|
|
36
|
+
};
|
|
37
|
+
if (!issue.sources.some((item) => item.label === source.label && item.href === source.href))
|
|
38
|
+
issue.sources.push(source);
|
|
39
|
+
issues.set(id, issue);
|
|
40
|
+
}
|
|
41
|
+
function check(profileId: string | null | undefined, source: IssueSource, processId = "") {
|
|
42
|
+
const id = trimToNull(profileId);
|
|
43
|
+
if (!id) return;
|
|
44
|
+
const result = deps.processModelPolicy.evaluate({
|
|
45
|
+
kind: "runtime_selection",
|
|
46
|
+
processId,
|
|
47
|
+
selection: {
|
|
48
|
+
modelProfileId: id,
|
|
49
|
+
provenance: { kind: "explicit", source: "instance_default" },
|
|
50
|
+
},
|
|
51
|
+
availability,
|
|
52
|
+
});
|
|
53
|
+
if (result.ok) return;
|
|
54
|
+
const key = result.code === "model_profile_not_allowed" ? JSON.stringify([id, processId]) : id;
|
|
55
|
+
const message = presentProcessModelPolicyFailure(result);
|
|
56
|
+
add(
|
|
57
|
+
result.code,
|
|
58
|
+
key,
|
|
59
|
+
result.code === "model_stale" || result.code === "model_unavailable"
|
|
60
|
+
? `${id}: ${message}`
|
|
61
|
+
: message,
|
|
62
|
+
source,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function checkPersisted(
|
|
66
|
+
input: {
|
|
67
|
+
processId: string;
|
|
68
|
+
defaultModelProfileId?: string | null;
|
|
69
|
+
turnConfigsJson?: string | null;
|
|
70
|
+
selectedTurnModelProfileId?: string | null;
|
|
71
|
+
},
|
|
72
|
+
source: IssueSource,
|
|
73
|
+
) {
|
|
74
|
+
check(
|
|
75
|
+
input.defaultModelProfileId,
|
|
76
|
+
{ ...source, label: `${source.label}: default model` },
|
|
77
|
+
input.processId,
|
|
78
|
+
);
|
|
79
|
+
check(
|
|
80
|
+
input.selectedTurnModelProfileId,
|
|
81
|
+
{ ...source, label: `${source.label}: selected step` },
|
|
82
|
+
input.processId,
|
|
83
|
+
);
|
|
84
|
+
const parsed = parseStrictInstanceTurnConfigsJson(
|
|
85
|
+
input.processId,
|
|
86
|
+
input.turnConfigsJson ?? null,
|
|
87
|
+
);
|
|
88
|
+
if (!parsed.ok) {
|
|
89
|
+
add(
|
|
90
|
+
"invalid_model_configuration",
|
|
91
|
+
source.href ?? source.label,
|
|
92
|
+
"Saved step model configuration is invalid.",
|
|
93
|
+
source,
|
|
94
|
+
);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const [turnId, config] of Object.entries(parsed.value))
|
|
98
|
+
check(
|
|
99
|
+
config.modelProfileId,
|
|
100
|
+
{ ...source, label: `${source.label}: ${turnId}` },
|
|
101
|
+
input.processId,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const config = deps.config;
|
|
105
|
+
if (config) {
|
|
106
|
+
for (const profile of config.pi.model_profiles)
|
|
107
|
+
check(profile.id, { label: `pi.model_profiles (${profile.id})`, href: null });
|
|
108
|
+
check(config.pi.default_model_profile, { label: "pi.default_model_profile", href: null });
|
|
109
|
+
check(config.pi.process_title_generation.model_profile, {
|
|
110
|
+
label: "pi.process_title_generation.model_profile",
|
|
111
|
+
href: null,
|
|
112
|
+
});
|
|
113
|
+
for (const [processId, processConfig] of Object.entries(config.process_configs ?? {})) {
|
|
114
|
+
const prefix = `process_configs.${processId}`;
|
|
115
|
+
check(
|
|
116
|
+
processConfig.default_model_profile,
|
|
117
|
+
{ label: `${prefix}.default_model_profile`, href: null },
|
|
118
|
+
processId,
|
|
119
|
+
);
|
|
120
|
+
for (const [turnId, turnConfig] of Object.entries(processConfig.turn_configs ?? {}))
|
|
121
|
+
check(
|
|
122
|
+
turnConfig.model_profile,
|
|
123
|
+
{ label: `${prefix}.turn_configs.${turnId}.model_profile`, href: null },
|
|
124
|
+
processId,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const reference of deps.scopedSettingsService?.modelReferences() ?? []) {
|
|
129
|
+
const source = {
|
|
130
|
+
label: `${reference.label} (${reference.key})`,
|
|
131
|
+
href: reference.subjectId
|
|
132
|
+
? `/settings?scope=${encodeURIComponent(reference.subjectId)}`
|
|
133
|
+
: null,
|
|
134
|
+
};
|
|
135
|
+
if (reference.invalid)
|
|
136
|
+
add(
|
|
137
|
+
"invalid_model_configuration",
|
|
138
|
+
`${reference.subjectId}:${reference.key}`,
|
|
139
|
+
"Saved model setting is invalid. Correct it in Settings.",
|
|
140
|
+
source,
|
|
141
|
+
);
|
|
142
|
+
else check(reference.modelProfileId, source);
|
|
143
|
+
}
|
|
144
|
+
for (const watcher of deps.processWatchers?.listAll() ?? []) {
|
|
145
|
+
const source = { label: watcher.configPath, href: "/watchers" };
|
|
146
|
+
check(watcher.launchModelConfig.defaultModelProfileId, source, watcher.processId);
|
|
147
|
+
for (const [turnId, turnConfig] of Object.entries(watcher.launchModelConfig.turnConfigs ?? {}))
|
|
148
|
+
check(
|
|
149
|
+
turnConfig.modelProfileId,
|
|
150
|
+
{ ...source, label: `${source.label}: ${turnId}` },
|
|
151
|
+
watcher.processId,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
for (const process of deps.processes.listModelConfigurations()) {
|
|
155
|
+
checkPersisted(
|
|
156
|
+
{
|
|
157
|
+
...process,
|
|
158
|
+
selectedTurnModelProfileId: process.selectedTurnId
|
|
159
|
+
? process.selectedTurnModelProfileId
|
|
160
|
+
: null,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
label: process.title ?? process.id,
|
|
164
|
+
href: `/processes/${encodeURIComponent(process.id)}?inspect=process§ion=inputs`,
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
for (const execution of deps.futureExecutions.listAll()) {
|
|
169
|
+
const source = {
|
|
170
|
+
label: `Scheduled ${execution.kind}: ${execution.id}`,
|
|
171
|
+
href:
|
|
172
|
+
execution.kind === "launch"
|
|
173
|
+
? `/future-launches/${encodeURIComponent(execution.id)}`
|
|
174
|
+
: `/processes/${encodeURIComponent(execution.instanceId ?? "")}`,
|
|
175
|
+
};
|
|
176
|
+
check(execution.modelSelection?.modelProfileId, source, execution.processId);
|
|
177
|
+
const parsed =
|
|
178
|
+
execution.kind === "launch"
|
|
179
|
+
? parseFutureLaunchPayloadJson(execution.payloadJson)
|
|
180
|
+
: parseFutureActionPayloadJson(execution.payloadJson);
|
|
181
|
+
if (!parsed.ok)
|
|
182
|
+
add(
|
|
183
|
+
"invalid_model_configuration",
|
|
184
|
+
execution.id,
|
|
185
|
+
`Scheduled ${execution.kind} configuration is invalid.`,
|
|
186
|
+
source,
|
|
187
|
+
);
|
|
188
|
+
else if ("launchPlan" in parsed.value)
|
|
189
|
+
checkPersisted(parsed.value.launchPlan.processInput, source);
|
|
190
|
+
else check(parsed.value.nextTurnModelProfileId, source, execution.processId);
|
|
191
|
+
}
|
|
192
|
+
for (const issue of issues.values()) issue.sources.sort((a, b) => a.label.localeCompare(b.label));
|
|
193
|
+
return [...issues.values()].sort(
|
|
194
|
+
(a, b) =>
|
|
195
|
+
(a.severity === b.severity ? 0 : a.severity === "error" ? -1 : 1) ||
|
|
196
|
+
a.message.localeCompare(b.message) ||
|
|
197
|
+
a.id.localeCompare(b.id),
|
|
198
|
+
);
|
|
199
|
+
}
|
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
|
+
}
|