@leitwerk-dev/server 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-WfwKzrVk.d.ts → app-CsuxFZT5.d.ts} +332 -111
- package/dist/app-JM4CBTND.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-LK3RO6C7.js → chunk-FPMDWQF7.js} +3050 -645
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-KIOQNNG6.js → chunk-MBHRCQFE.js} +2781 -1822
- package/dist/chunk-MBHRCQFE.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +14 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- package/dist/db/mapped-llm-run-repo.d.ts +56 -0
- package/dist/db/mapped-llm-run-repo.d.ts.map +1 -0
- package/dist/db/process-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +4 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +7 -1
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- package/dist/db/repo-helpers.d.ts +6 -0
- package/dist/db/repo-helpers.d.ts.map +1 -1
- package/dist/db/repositories.d.ts +16 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +1177 -71
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +1 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts +4 -14
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator-test-harness.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +11 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/mapped-turns.d.ts +45 -0
- package/dist/process-engine/mapped-turns.d.ts.map +1 -0
- package/dist/process-engine/operation.d.ts +1 -1
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts +2 -0
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts.map +1 -1
- package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +10 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +10 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +2 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts +5 -0
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts.map +1 -0
- package/dist/process-engine/writes/writes.d.ts +35 -49
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.d.ts.map +1 -1
- package/dist/process-turn-navigation.d.ts +12 -2
- package/dist/process-turn-navigation.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +15 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.d.ts.map +1 -1
- package/dist/routes/process-diagnostics-assembler.d.ts +3 -1
- package/dist/routes/process-diagnostics-assembler.d.ts.map +1 -1
- package/dist/routes/process-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-primary-path-assembler.d.ts +4 -12
- package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
- package/dist/routes/process-route-helpers.d.ts +15 -41
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +83 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +5 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +3 -0
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +2 -0
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +4 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +2 -2
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/test-helpers/accepted-turn-start.d.ts +18 -4
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/owned-test-deps.d.ts +18 -0
- package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +14 -10
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +117 -5
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +40 -2
- package/src/config/config-types.ts +14 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/db/database.ts +159 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +9 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +53 -13
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +22 -0
- package/src/db/schema.ts +173 -2
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +13 -3
- package/src/db/turn-summary-repo.ts +12 -3
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +4 -149
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +14 -22
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator-test-harness.ts +8 -4
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +98 -0
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +13 -4
- package/src/process-engine/mapped-turns.ts +328 -0
- package/src/process-engine/operation.ts +1 -1
- package/src/process-engine/ops/accept-worker-turn-start.ts +6 -0
- package/src/process-engine/ops/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +10 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +65 -62
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +33 -5
- package/src/process-engine/runner.ts +8 -8
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +15 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -19
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +118 -21
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +20 -2
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +73 -61
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-navigation.ts +86 -8
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +249 -298
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +10 -10
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-diagnostics-assembler.ts +32 -6
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +161 -327
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +736 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +7 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +97 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +3 -0
- package/src/startup-evidence.ts +20 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +29 -18
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +42 -0
- package/src/supervisor/worker-supervisor.ts +5 -0
- package/src/supervisor/worker-turn-ipc-recorder.ts +13 -1
- package/src/test-helpers/accepted-turn-start.ts +51 -27
- package/src/test-helpers/owned-test-deps.ts +45 -0
- package/src/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/testing.ts +4 -1
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -1
- package/dist/app-4QSV4FUQ.js +0 -8
- package/dist/chunk-KIOQNNG6.js.map +0 -1
- package/dist/chunk-LK3RO6C7.js.map +0 -1
- /package/dist/{app-4QSV4FUQ.js.map → app-JM4CBTND.js.map} +0 -0
package/src/db/schema.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wikiTopics } from "@leitwerk-dev/wiki/server";
|
|
2
|
+
|
|
3
|
+
export { wikiPages, wikiRevisions, wikiTopics } from "@leitwerk-dev/wiki/server";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type MappedItem,
|
|
7
|
+
type MappedRunStatus,
|
|
8
|
+
SERIALIZED_SYSTEM_ACTOR,
|
|
9
|
+
} from "@leitwerk-dev/domain";
|
|
10
|
+
import type { SkillRevisionProvenance } from "@leitwerk-dev/protocol";
|
|
2
11
|
import type { SessionTransferPhase } from "@leitwerk-dev/session-transfer";
|
|
3
12
|
import { sql } from "drizzle-orm";
|
|
4
13
|
import {
|
|
@@ -11,6 +20,19 @@ import {
|
|
|
11
20
|
uniqueIndex,
|
|
12
21
|
} from "drizzle-orm/sqlite-core";
|
|
13
22
|
|
|
23
|
+
export const topicPublications = sqliteTable(
|
|
24
|
+
"topic_publications",
|
|
25
|
+
{
|
|
26
|
+
key: text("key").primaryKey(),
|
|
27
|
+
topicId: text("topic_id")
|
|
28
|
+
.notNull()
|
|
29
|
+
.references(() => wikiTopics.id),
|
|
30
|
+
externalId: text("external_id"),
|
|
31
|
+
data: text("data").notNull(),
|
|
32
|
+
},
|
|
33
|
+
(table) => [uniqueIndex("idx_topic_publications_external").on(table.externalId)],
|
|
34
|
+
);
|
|
35
|
+
|
|
14
36
|
export const startupObservations = sqliteTable(
|
|
15
37
|
"startup_observations",
|
|
16
38
|
{
|
|
@@ -23,6 +45,33 @@ export const startupObservations = sqliteTable(
|
|
|
23
45
|
(t) => [uniqueIndex("idx_startup_observations_lease_milestone").on(t.workerLeaseId, t.milestone)],
|
|
24
46
|
);
|
|
25
47
|
|
|
48
|
+
export const inspectionContents = sqliteTable("inspection_contents", {
|
|
49
|
+
digest: text("digest").primaryKey(),
|
|
50
|
+
contentJson: text("content_json").notNull(),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const executionInspections = sqliteTable(
|
|
54
|
+
"execution_inspections",
|
|
55
|
+
{
|
|
56
|
+
sequence: integer("sequence").primaryKey({ autoIncrement: true }),
|
|
57
|
+
id: text("id").notNull(),
|
|
58
|
+
instanceId: text("instance_id")
|
|
59
|
+
.notNull()
|
|
60
|
+
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
61
|
+
turnRecordId: text("turn_record_id")
|
|
62
|
+
.notNull()
|
|
63
|
+
.references(() => turnRecords.id, { onDelete: "cascade" }),
|
|
64
|
+
startRecordId: text("start_record_id").notNull(),
|
|
65
|
+
workerLeaseId: text("worker_lease_id").notNull(),
|
|
66
|
+
capturedAt: text("captured_at").notNull(),
|
|
67
|
+
factJson: text("fact_json").notNull(),
|
|
68
|
+
},
|
|
69
|
+
(t) => [
|
|
70
|
+
uniqueIndex("idx_execution_inspections_id").on(t.id),
|
|
71
|
+
index("idx_execution_inspections_turn").on(t.instanceId, t.turnRecordId),
|
|
72
|
+
],
|
|
73
|
+
);
|
|
74
|
+
|
|
26
75
|
export const processInstances = sqliteTable(
|
|
27
76
|
"process_instances",
|
|
28
77
|
{
|
|
@@ -95,7 +144,8 @@ export const skills = sqliteTable("skills", {
|
|
|
95
144
|
activeRevisionId: text("active_revision_id"),
|
|
96
145
|
createdAt: text("created_at").notNull(),
|
|
97
146
|
updatedAt: text("updated_at").notNull(),
|
|
98
|
-
|
|
147
|
+
ownerExtensionId: text("owner_extension_id"),
|
|
148
|
+
registrationKind: text("registration_kind", { enum: ["configuration", "catalog", "extension"] })
|
|
99
149
|
.notNull()
|
|
100
150
|
.default("configuration"),
|
|
101
151
|
});
|
|
@@ -109,6 +159,7 @@ export const skillRevisions = sqliteTable(
|
|
|
109
159
|
.references(() => skills.id),
|
|
110
160
|
bundleDigest: text("bundle_digest").notNull(),
|
|
111
161
|
bundleBytes: blob("bundle_bytes", { mode: "buffer" }).notNull(),
|
|
162
|
+
provenance: text("provenance_json", { mode: "json" }).$type<SkillRevisionProvenance>(),
|
|
112
163
|
sourceRevision: text("source_revision"),
|
|
113
164
|
importedAt: text("imported_at").notNull(),
|
|
114
165
|
},
|
|
@@ -448,8 +499,12 @@ export const turnRecords = sqliteTable(
|
|
|
448
499
|
endedAt: text("ended_at"),
|
|
449
500
|
modelSelectionKind: text("model_selection_kind"),
|
|
450
501
|
modelSelectionSource: text("model_selection_source"),
|
|
502
|
+
mappedRunId: text("mapped_run_id"),
|
|
503
|
+
mappedItemKey: text("mapped_item_key"),
|
|
504
|
+
mappedItemIndex: integer("mapped_item_index"),
|
|
451
505
|
},
|
|
452
506
|
(t) => [
|
|
507
|
+
index("idx_turn_records_page").on(t.instanceId, t.startedAt, t.id),
|
|
453
508
|
uniqueIndex("uq_turn_records_instance_id").on(t.instanceId, t.id),
|
|
454
509
|
uniqueIndex("uq_turn_records_turn_start_record").on(t.turnStartRecordId),
|
|
455
510
|
index("idx_turn_records_instance").on(t.instanceId),
|
|
@@ -479,6 +534,9 @@ export const turnStartRecords = sqliteTable(
|
|
|
479
534
|
stateJson: text("state_json").notNull(),
|
|
480
535
|
createdAt: text("created_at").notNull(),
|
|
481
536
|
updatedAt: text("updated_at").notNull(),
|
|
537
|
+
mappedRunId: text("mapped_run_id"),
|
|
538
|
+
mappedItemKey: text("mapped_item_key"),
|
|
539
|
+
mappedItemIndex: integer("mapped_item_index"),
|
|
482
540
|
},
|
|
483
541
|
(t) => [
|
|
484
542
|
uniqueIndex("uq_turn_start_records_proposed_turn_record").on(t.proposedTurnRecordId),
|
|
@@ -555,6 +613,7 @@ export const turnAnnotations = sqliteTable(
|
|
|
555
613
|
updatedAt: text("updated_at").notNull(),
|
|
556
614
|
},
|
|
557
615
|
(t) => [
|
|
616
|
+
index("idx_turn_annotations_created").on(t.instanceId, t.createdAt),
|
|
558
617
|
index("idx_turn_annotations_instance").on(t.instanceId),
|
|
559
618
|
index("idx_turn_annotations_type").on(t.annotationType),
|
|
560
619
|
uniqueIndex("uq_turn_annotations_instance_key").on(t.instanceId, t.annotationKey),
|
|
@@ -585,6 +644,8 @@ export const workerLeases = sqliteTable(
|
|
|
585
644
|
readyAt: text("ready_at"),
|
|
586
645
|
},
|
|
587
646
|
(t) => [
|
|
647
|
+
index("idx_worker_leases_exited").on(t.instanceId, t.exitedAt),
|
|
648
|
+
index("idx_worker_leases_started").on(t.instanceId, t.startedAt),
|
|
588
649
|
uniqueIndex("uq_worker_leases_instance_id").on(t.instanceId, t.id),
|
|
589
650
|
index("idx_worker_leases_instance").on(t.instanceId),
|
|
590
651
|
index("idx_worker_leases_turn_start").on(t.turnStartRecordId),
|
|
@@ -794,6 +855,65 @@ export const externalWriteLog = sqliteTable(
|
|
|
794
855
|
],
|
|
795
856
|
);
|
|
796
857
|
|
|
858
|
+
export const mappedLlmRuns = sqliteTable(
|
|
859
|
+
"mapped_llm_runs",
|
|
860
|
+
{
|
|
861
|
+
id: text("id").primaryKey(),
|
|
862
|
+
instanceId: text("instance_id")
|
|
863
|
+
.notNull()
|
|
864
|
+
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
865
|
+
turnId: text("turn_id").notNull(),
|
|
866
|
+
status: text("status").$type<MappedRunStatus>().notNull(),
|
|
867
|
+
itemCount: integer("item_count").notNull(),
|
|
868
|
+
nextIndex: integer("next_index").notNull(),
|
|
869
|
+
createdAt: text("created_at").notNull(),
|
|
870
|
+
updatedAt: text("updated_at").notNull(),
|
|
871
|
+
},
|
|
872
|
+
(t) => [
|
|
873
|
+
index("idx_mapped_llm_runs_instance").on(t.instanceId),
|
|
874
|
+
uniqueIndex("uq_mapped_llm_runs_active_instance")
|
|
875
|
+
.on(t.instanceId)
|
|
876
|
+
.where(sql`${t.status} = 'active'`),
|
|
877
|
+
check("mapped_llm_runs_status", sql`${t.status} in ('active', 'completed', 'aborted')`),
|
|
878
|
+
check(
|
|
879
|
+
"mapped_llm_runs_progress",
|
|
880
|
+
sql`${t.itemCount} >= 0 and ${t.nextIndex} >= 0 and ${t.nextIndex} <= ${t.itemCount}`,
|
|
881
|
+
),
|
|
882
|
+
],
|
|
883
|
+
);
|
|
884
|
+
|
|
885
|
+
export const mappedLlmItems = sqliteTable(
|
|
886
|
+
"mapped_llm_items",
|
|
887
|
+
{
|
|
888
|
+
runId: text("run_id")
|
|
889
|
+
.notNull()
|
|
890
|
+
.references(() => mappedLlmRuns.id, { onDelete: "cascade" }),
|
|
891
|
+
instanceId: text("instance_id")
|
|
892
|
+
.notNull()
|
|
893
|
+
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
894
|
+
itemIndex: integer("item_index").notNull(),
|
|
895
|
+
itemKey: text("item_key").notNull(),
|
|
896
|
+
label: text("label").notNull(),
|
|
897
|
+
itemJson: text("item_json").notNull(),
|
|
898
|
+
status: text("status").$type<MappedItem["status"]>().notNull().default("pending"),
|
|
899
|
+
outcome: text("outcome"),
|
|
900
|
+
resultJson: text("result_json"),
|
|
901
|
+
turnRecordId: text("turn_record_id"),
|
|
902
|
+
completedAt: text("completed_at"),
|
|
903
|
+
},
|
|
904
|
+
(t) => [
|
|
905
|
+
uniqueIndex("uq_mapped_llm_items_run_index").on(t.runId, t.itemIndex),
|
|
906
|
+
uniqueIndex("uq_mapped_llm_items_run_key").on(t.runId, t.itemKey),
|
|
907
|
+
index("idx_mapped_llm_items_instance").on(t.instanceId),
|
|
908
|
+
check("mapped_llm_items_status", sql`${t.status} in ('pending', 'completed')`),
|
|
909
|
+
check("mapped_llm_items_item_json", sql`json_valid(${t.itemJson})`),
|
|
910
|
+
check(
|
|
911
|
+
"mapped_llm_items_result",
|
|
912
|
+
sql`(${t.status} = 'pending' and ${t.resultJson} is null) or (${t.status} = 'completed' and ${t.resultJson} is not null and json_valid(${t.resultJson}))`,
|
|
913
|
+
),
|
|
914
|
+
],
|
|
915
|
+
);
|
|
916
|
+
|
|
797
917
|
/**
|
|
798
918
|
* Composite foreign keys for the cyclic execution graph. Drizzle cannot infer
|
|
799
919
|
* these mutually recursive table types without degrading declarations to any,
|
|
@@ -862,3 +982,54 @@ export const sessionSummaries = sqliteTable("session_summaries", {
|
|
|
862
982
|
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
863
983
|
summaryJson: text("summary_json").notNull(),
|
|
864
984
|
});
|
|
985
|
+
export const settingsSubjects = sqliteTable(
|
|
986
|
+
"settings_subjects",
|
|
987
|
+
{
|
|
988
|
+
id: text("id").primaryKey(),
|
|
989
|
+
scopeType: text("scope_type").notNull(),
|
|
990
|
+
identity: text("identity").notNull(),
|
|
991
|
+
label: text("label").notNull(),
|
|
992
|
+
contextJson: text("context_json").notNull(),
|
|
993
|
+
schemaVersion: integer("schema_version").notNull(),
|
|
994
|
+
revision: integer("revision").notNull(),
|
|
995
|
+
createdAt: text("created_at").notNull(),
|
|
996
|
+
updatedAt: text("updated_at").notNull(),
|
|
997
|
+
actorJson: text("actor_json").notNull(),
|
|
998
|
+
},
|
|
999
|
+
(t) => [uniqueIndex("uq_settings_subject_identity").on(t.scopeType, t.identity)],
|
|
1000
|
+
);
|
|
1001
|
+
|
|
1002
|
+
export const settingsAliases = sqliteTable("settings_aliases", {
|
|
1003
|
+
alias: text("alias").primaryKey(),
|
|
1004
|
+
subjectId: text("subject_id")
|
|
1005
|
+
.notNull()
|
|
1006
|
+
.references(() => settingsSubjects.id),
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
export const settingsSubjectRedirects = sqliteTable("settings_subject_redirects", {
|
|
1010
|
+
subjectId: text("subject_id")
|
|
1011
|
+
.primaryKey()
|
|
1012
|
+
.references(() => settingsSubjects.id),
|
|
1013
|
+
canonicalSubjectId: text("canonical_subject_id")
|
|
1014
|
+
.notNull()
|
|
1015
|
+
.references(() => settingsSubjects.id),
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
export const settingsOverrides = sqliteTable(
|
|
1019
|
+
"settings_overrides",
|
|
1020
|
+
{
|
|
1021
|
+
subjectId: text("subject_id")
|
|
1022
|
+
.notNull()
|
|
1023
|
+
.references(() => settingsSubjects.id),
|
|
1024
|
+
key: text("key").notNull(),
|
|
1025
|
+
valueJson: text("value_json").notNull(),
|
|
1026
|
+
mode: text("mode").notNull(),
|
|
1027
|
+
reset: integer("reset", { mode: "boolean" }).notNull(),
|
|
1028
|
+
schemaVersion: integer("schema_version").notNull(),
|
|
1029
|
+
revision: integer("revision").notNull(),
|
|
1030
|
+
createdAt: text("created_at").notNull(),
|
|
1031
|
+
updatedAt: text("updated_at").notNull(),
|
|
1032
|
+
actorJson: text("actor_json").notNull(),
|
|
1033
|
+
},
|
|
1034
|
+
(t) => [uniqueIndex("uq_settings_override").on(t.subjectId, t.key)],
|
|
1035
|
+
);
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { SettingsOverride, SettingsSubject } from "@leitwerk-dev/domain";
|
|
2
|
+
import { SYSTEM_ACTOR } from "@leitwerk-dev/domain";
|
|
3
|
+
import { and, eq, notInArray } from "drizzle-orm";
|
|
4
|
+
import type { LeitwerkDb } from "./database.js";
|
|
5
|
+
import { generateId, now } from "./repo-helpers.js";
|
|
6
|
+
import * as s from "./schema.js";
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
9
|
+
export type SettingsWrite = Omit<SettingsOverride, "revision" | "createdAt" | "updatedAt"> & {
|
|
10
|
+
/** @internal */
|
|
11
|
+
expectedRevision: number;
|
|
12
|
+
};
|
|
13
|
+
/** @internal */
|
|
14
|
+
type SubjectWrite = Pick<SettingsSubject, "scopeType" | "identity" | "label" | "context"> & {
|
|
15
|
+
/** @internal */
|
|
16
|
+
id?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function subject(row: typeof s.settingsSubjects.$inferSelect): SettingsSubject {
|
|
20
|
+
const { contextJson, actorJson, ...rest } = row;
|
|
21
|
+
return { ...rest, context: JSON.parse(contextJson), actor: JSON.parse(actorJson) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function override(row: typeof s.settingsOverrides.$inferSelect): SettingsOverride {
|
|
25
|
+
const { valueJson, actorJson, mode, ...rest } = row;
|
|
26
|
+
return {
|
|
27
|
+
...rest,
|
|
28
|
+
mode: mode as SettingsOverride["mode"],
|
|
29
|
+
value: JSON.parse(valueJson),
|
|
30
|
+
actor: JSON.parse(actorJson),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function overrideRow({ value, actor, ...rest }: SettingsOverride) {
|
|
35
|
+
return { ...rest, valueJson: JSON.stringify(value), actorJson: JSON.stringify(actor) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
export function createScopedSettingsRepo(db: LeitwerkDb) {
|
|
40
|
+
return {
|
|
41
|
+
/** @internal */
|
|
42
|
+
listSubjects(): SettingsSubject[] {
|
|
43
|
+
return db
|
|
44
|
+
.select()
|
|
45
|
+
.from(s.settingsSubjects)
|
|
46
|
+
.where(
|
|
47
|
+
notInArray(
|
|
48
|
+
s.settingsSubjects.id,
|
|
49
|
+
db
|
|
50
|
+
.select({ id: s.settingsSubjectRedirects.subjectId })
|
|
51
|
+
.from(s.settingsSubjectRedirects),
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
.all()
|
|
55
|
+
.map(subject);
|
|
56
|
+
},
|
|
57
|
+
/** @internal */
|
|
58
|
+
getSubject(id: string): SettingsSubject | null {
|
|
59
|
+
const visited = new Set<string>();
|
|
60
|
+
while (!visited.has(id)) {
|
|
61
|
+
visited.add(id);
|
|
62
|
+
const redirect = db
|
|
63
|
+
.select()
|
|
64
|
+
.from(s.settingsSubjectRedirects)
|
|
65
|
+
.where(eq(s.settingsSubjectRedirects.subjectId, id))
|
|
66
|
+
.get();
|
|
67
|
+
if (!redirect) {
|
|
68
|
+
const row = db
|
|
69
|
+
.select()
|
|
70
|
+
.from(s.settingsSubjects)
|
|
71
|
+
.where(eq(s.settingsSubjects.id, id))
|
|
72
|
+
.get();
|
|
73
|
+
return row ? subject(row) : null;
|
|
74
|
+
}
|
|
75
|
+
id = redirect.canonicalSubjectId;
|
|
76
|
+
}
|
|
77
|
+
throw new Error("Cyclic settings subject redirects");
|
|
78
|
+
},
|
|
79
|
+
/** @internal */
|
|
80
|
+
findIdentity(scopeType: string, identity: string): SettingsSubject | null {
|
|
81
|
+
const row = db
|
|
82
|
+
.select()
|
|
83
|
+
.from(s.settingsSubjects)
|
|
84
|
+
.where(
|
|
85
|
+
and(
|
|
86
|
+
eq(s.settingsSubjects.scopeType, scopeType),
|
|
87
|
+
eq(s.settingsSubjects.identity, identity),
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
.get();
|
|
91
|
+
return row ? this.getSubject(row.id) : null;
|
|
92
|
+
},
|
|
93
|
+
/** @internal */
|
|
94
|
+
findAlias(alias: string): SettingsSubject | null {
|
|
95
|
+
const row = db
|
|
96
|
+
.select()
|
|
97
|
+
.from(s.settingsAliases)
|
|
98
|
+
.where(eq(s.settingsAliases.alias, alias))
|
|
99
|
+
.get();
|
|
100
|
+
return row ? this.getSubject(row.subjectId) : null;
|
|
101
|
+
},
|
|
102
|
+
/** @internal */
|
|
103
|
+
putSubject(input: SubjectWrite): SettingsSubject {
|
|
104
|
+
const ts = now();
|
|
105
|
+
const previous = input.id ? this.getSubject(input.id) : null;
|
|
106
|
+
const values = {
|
|
107
|
+
id: input.id ?? generateId("scope"),
|
|
108
|
+
scopeType: input.scopeType,
|
|
109
|
+
identity: input.identity,
|
|
110
|
+
label: input.label,
|
|
111
|
+
contextJson: JSON.stringify(input.context),
|
|
112
|
+
schemaVersion: 1,
|
|
113
|
+
revision: (previous?.revision ?? 0) + 1,
|
|
114
|
+
createdAt: previous?.createdAt ?? ts,
|
|
115
|
+
updatedAt: ts,
|
|
116
|
+
actorJson: JSON.stringify(SYSTEM_ACTOR),
|
|
117
|
+
};
|
|
118
|
+
db.insert(s.settingsSubjects)
|
|
119
|
+
.values(values)
|
|
120
|
+
.onConflictDoUpdate({ target: s.settingsSubjects.id, set: values })
|
|
121
|
+
.run();
|
|
122
|
+
return subject(values);
|
|
123
|
+
},
|
|
124
|
+
/** @internal */
|
|
125
|
+
putAlias(alias: string, subjectId: string): void {
|
|
126
|
+
db.insert(s.settingsAliases).values({ alias, subjectId }).onConflictDoNothing().run();
|
|
127
|
+
if (this.findAlias(alias)?.id !== subjectId)
|
|
128
|
+
throw new Error(`Repository alias '${alias}' already belongs to another settings subject`);
|
|
129
|
+
},
|
|
130
|
+
/** @internal */
|
|
131
|
+
listOverrides(subjectId?: string): SettingsOverride[] {
|
|
132
|
+
const canonicalId = subjectId ? (this.getSubject(subjectId)?.id ?? subjectId) : undefined;
|
|
133
|
+
return db
|
|
134
|
+
.select()
|
|
135
|
+
.from(s.settingsOverrides)
|
|
136
|
+
.where(
|
|
137
|
+
canonicalId
|
|
138
|
+
? eq(s.settingsOverrides.subjectId, canonicalId)
|
|
139
|
+
: notInArray(
|
|
140
|
+
s.settingsOverrides.subjectId,
|
|
141
|
+
db
|
|
142
|
+
.select({ id: s.settingsSubjectRedirects.subjectId })
|
|
143
|
+
.from(s.settingsSubjectRedirects),
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
.all()
|
|
147
|
+
.map(override);
|
|
148
|
+
},
|
|
149
|
+
/** @internal */
|
|
150
|
+
getOverride(subjectId: string, key: string): SettingsOverride | null {
|
|
151
|
+
subjectId = this.getSubject(subjectId)?.id ?? subjectId;
|
|
152
|
+
const row = db
|
|
153
|
+
.select()
|
|
154
|
+
.from(s.settingsOverrides)
|
|
155
|
+
.where(and(eq(s.settingsOverrides.subjectId, subjectId), eq(s.settingsOverrides.key, key)))
|
|
156
|
+
.get();
|
|
157
|
+
return row ? override(row) : null;
|
|
158
|
+
},
|
|
159
|
+
/** Atomic compare-and-swap, including resets and first writes. @internal */
|
|
160
|
+
write(input: SettingsWrite): SettingsOverride | null {
|
|
161
|
+
const ts = now();
|
|
162
|
+
const { expectedRevision, ...change } = input;
|
|
163
|
+
const values = overrideRow({
|
|
164
|
+
...change,
|
|
165
|
+
subjectId: this.getSubject(input.subjectId)?.id ?? input.subjectId,
|
|
166
|
+
revision: expectedRevision + 1,
|
|
167
|
+
createdAt: ts,
|
|
168
|
+
updatedAt: ts,
|
|
169
|
+
});
|
|
170
|
+
const { createdAt: _createdAt, ...update } = values;
|
|
171
|
+
if (input.expectedRevision > 0) {
|
|
172
|
+
const row = db
|
|
173
|
+
.update(s.settingsOverrides)
|
|
174
|
+
.set(update)
|
|
175
|
+
.where(
|
|
176
|
+
and(
|
|
177
|
+
eq(s.settingsOverrides.subjectId, values.subjectId),
|
|
178
|
+
eq(s.settingsOverrides.key, input.key),
|
|
179
|
+
eq(s.settingsOverrides.revision, input.expectedRevision),
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
.returning()
|
|
183
|
+
.get();
|
|
184
|
+
return row ? override(row) : null;
|
|
185
|
+
}
|
|
186
|
+
const row = db
|
|
187
|
+
.insert(s.settingsOverrides)
|
|
188
|
+
.values(values)
|
|
189
|
+
.onConflictDoNothing()
|
|
190
|
+
.returning()
|
|
191
|
+
.get();
|
|
192
|
+
return row ? override(row) : null;
|
|
193
|
+
},
|
|
194
|
+
/** Call inside a transaction after verifying that active overrides agree. @internal */
|
|
195
|
+
mergeLocatorSubject(sourceId: string, targetId: string): void {
|
|
196
|
+
const source = this.getSubject(sourceId);
|
|
197
|
+
const target = this.getSubject(targetId);
|
|
198
|
+
if (
|
|
199
|
+
!source ||
|
|
200
|
+
!target ||
|
|
201
|
+
source.id === target.id ||
|
|
202
|
+
source.scopeType !== "repository" ||
|
|
203
|
+
target.scopeType !== "repository" ||
|
|
204
|
+
!source.identity.startsWith("locator:")
|
|
205
|
+
)
|
|
206
|
+
throw new Error("Only distinct locator subjects can merge into a repository");
|
|
207
|
+
for (const incoming of this.listOverrides(source.id)) {
|
|
208
|
+
const current = this.getOverride(target.id, incoming.key);
|
|
209
|
+
const retained = current && !current.reset ? current : incoming;
|
|
210
|
+
const values = overrideRow({
|
|
211
|
+
...retained,
|
|
212
|
+
subjectId: target.id,
|
|
213
|
+
revision: Math.max(incoming.revision, current?.revision ?? 0) + 1,
|
|
214
|
+
updatedAt: now(),
|
|
215
|
+
});
|
|
216
|
+
db.insert(s.settingsOverrides)
|
|
217
|
+
.values(values)
|
|
218
|
+
.onConflictDoUpdate({
|
|
219
|
+
target: [s.settingsOverrides.subjectId, s.settingsOverrides.key],
|
|
220
|
+
set: values,
|
|
221
|
+
})
|
|
222
|
+
.run();
|
|
223
|
+
}
|
|
224
|
+
db.update(s.settingsAliases)
|
|
225
|
+
.set({ subjectId: target.id })
|
|
226
|
+
.where(eq(s.settingsAliases.subjectId, source.id))
|
|
227
|
+
.run();
|
|
228
|
+
// Keep original subjects and overrides for historical references and attribution.
|
|
229
|
+
db.insert(s.settingsSubjectRedirects)
|
|
230
|
+
.values({ subjectId: source.id, canonicalSubjectId: target.id })
|
|
231
|
+
.run();
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|