@jungjaehoon/mama-core 2.4.1 → 4.1.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/README.md +76 -239
- package/db/migrations/030-case-first-memory-substrate.sql +13 -98
- package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
- package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
- package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
- package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
- package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
- package/db/migrations/069-create-registry-nodes.sql +52 -0
- package/db/migrations/070-record-identity.sql +35 -0
- package/db/migrations/071-service-operation-origins.sql +187 -0
- package/db/migrations/072-observation-versions.sql +29 -0
- package/db/migrations/073-registry-corrections.sql +45 -0
- package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
- package/db/migrations/075-agent-judgments.sql +58 -0
- package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
- package/db/migrations/077-legacy-record-kind.sql +6 -0
- package/db/migrations/078-source-ingest-commands.sql +18 -0
- package/db/migrations/079-twin-edge-relations.sql +43 -0
- package/db/migrations/080-restore-duration-days.sql +7 -0
- package/db/migrations/081-mailbox.sql +61 -0
- package/db/migrations/082-commitments-row-id.sql +12 -0
- package/db/migrations/083-observation-is-the-evidence.sql +49 -0
- package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
- package/db/migrations/085-a-migration-has-a-source.sql +37 -0
- package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
- package/db/migrations/087-mailbox-payload.sql +5 -0
- package/db/migrations/088-native-input-journal.sql +14 -0
- package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
- package/db/migrations/090-model-run-native-inputs.sql +29 -0
- package/db/migrations/091-native-turn-results.sql +11 -0
- package/db/migrations/092-restore-decision-fts.sql +34 -0
- package/db/migrations/093-native-turn-primary-kind.sql +14 -0
- package/db/migrations/094-commitment-run-provenance.sql +9 -0
- package/db/migrations/095-model-run-native-input-identity.sql +39 -0
- package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
- package/db/migrations/097-native-input-json-validity.sql +37 -0
- package/db/migrations/098-workflow-memory-kind.sql +105 -0
- package/db/migrations/099-commitment-revision-graph.sql +2 -0
- package/dist/action-contracts.d.ts +212 -0
- package/dist/action-contracts.js +10 -0
- package/dist/api/catalog.d.ts +118 -0
- package/dist/api/catalog.js +1756 -0
- package/dist/api/dispatch.d.ts +76 -0
- package/dist/api/dispatch.js +372 -0
- package/dist/canonicalize.d.ts +2 -2
- package/dist/canonicalize.js +3 -3
- package/dist/client/client.d.ts +33 -0
- package/dist/client/client.js +123 -0
- package/dist/client/ipc.d.ts +81 -0
- package/dist/client/ipc.js +314 -0
- package/dist/db-adapter/base-adapter.d.ts +6 -66
- package/dist/db-adapter/base-adapter.js +6 -6
- package/dist/db-adapter/index.d.ts +5 -5
- package/dist/db-adapter/index.js +2 -5
- package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
- package/dist/db-adapter/node-sqlite-adapter.js +1985 -570
- package/dist/db-manager.d.ts +53 -97
- package/dist/db-manager.js +121 -603
- package/dist/embedding/embedder.d.ts +132 -0
- package/dist/embedding/embedder.js +299 -0
- package/dist/identity/principal-repository.d.ts +2 -2
- package/dist/index.d.ts +43 -58
- package/dist/index.js +97 -145
- package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
- package/dist/knowledge/access.js +663 -0
- package/dist/knowledge/case-errors.d.ts +31 -0
- package/dist/knowledge/case-errors.js +40 -0
- package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
- package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
- package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
- package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
- package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
- package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
- package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
- package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
- package/dist/knowledge/commitment-revision-migration.d.ts +4 -0
- package/dist/knowledge/commitment-revision-migration.js +50 -0
- package/dist/knowledge/commitments.d.ts +192 -0
- package/dist/knowledge/commitments.js +386 -0
- package/dist/knowledge/decision-edges.d.ts +70 -0
- package/dist/knowledge/decision-edges.js +123 -0
- package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
- package/dist/knowledge/graph-query.js +1585 -0
- package/dist/knowledge/identity.d.ts +16 -0
- package/dist/knowledge/identity.js +22 -0
- package/dist/knowledge/index.d.ts +47 -0
- package/dist/knowledge/index.js +90 -0
- package/dist/knowledge/judgment-edge.d.ts +6 -0
- package/dist/knowledge/judgment-edge.js +22 -0
- package/dist/knowledge/judgments.d.ts +118 -0
- package/dist/knowledge/judgments.js +802 -0
- package/dist/knowledge/observations.d.ts +160 -0
- package/dist/knowledge/observations.js +449 -0
- package/dist/knowledge/question-type.d.ts +34 -0
- package/dist/knowledge/question-type.js +70 -0
- package/dist/{search → knowledge}/ranker-features.js +1 -1
- package/dist/{search → knowledge}/search-quality.d.ts +0 -1
- package/dist/knowledge/search.d.ts +38 -0
- package/dist/knowledge/search.js +91 -0
- package/dist/knowledge/source-ingest.d.ts +65 -0
- package/dist/knowledge/source-ingest.js +174 -0
- package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
- package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
- package/dist/knowledge/work-dates.d.ts +49 -0
- package/dist/knowledge/work-dates.js +120 -0
- package/dist/mama-api.d.ts +114 -778
- package/dist/mama-api.js +313 -2461
- package/dist/memory/api.d.ts +264 -24
- package/dist/memory/api.js +1633 -843
- package/dist/memory/bootstrap-builder.d.ts +2 -1
- package/dist/memory/bootstrap-builder.js +5 -5
- package/dist/memory/channel-summary-state-store.d.ts +3 -2
- package/dist/memory/channel-summary-state-store.js +53 -51
- package/dist/memory/channel-summary-store.d.ts +5 -3
- package/dist/memory/channel-summary-store.js +3 -8
- package/dist/memory/dashboard-read.d.ts +46 -0
- package/dist/memory/dashboard-read.js +94 -0
- package/dist/memory/event-store.d.ts +3 -3
- package/dist/memory/event-store.js +3 -10
- package/dist/memory/finding-store.d.ts +3 -2
- package/dist/memory/finding-store.js +2 -7
- package/dist/memory/graph-read.d.ts +52 -0
- package/dist/memory/graph-read.js +130 -0
- package/dist/memory/judgment-types.d.ts +394 -0
- package/dist/memory/judgment-types.js +16 -0
- package/dist/memory/provenance-audit.d.ts +5 -2
- package/dist/memory/provenance-audit.js +8 -14
- package/dist/memory/provenance-live.d.ts +141 -0
- package/dist/memory/provenance-live.js +409 -0
- package/dist/memory/provenance-query.d.ts +5 -4
- package/dist/memory/provenance-query.js +21 -29
- package/dist/memory/provenance-resolver.d.ts +191 -0
- package/dist/memory/provenance-resolver.js +155 -0
- package/dist/memory/provenance.d.ts +1 -11
- package/dist/memory/provenance.js +2 -33
- package/dist/memory/recall-sanitize.d.ts +55 -0
- package/dist/memory/recall-sanitize.js +144 -0
- package/dist/memory/secret-filter.d.ts +32 -0
- package/dist/memory/secret-filter.js +126 -0
- package/dist/memory/truth-store.d.ts +2 -1
- package/dist/memory/truth-store.js +1 -4
- package/dist/memory/types.d.ts +74 -24
- package/dist/memory/types.js +75 -5
- package/dist/memory/write-adapters.d.ts +98 -0
- package/dist/memory/write-adapters.js +242 -0
- package/dist/operations/owner-action-effects.d.ts +53 -0
- package/dist/operations/owner-action-effects.js +96 -0
- package/dist/provenance/source-ref.d.ts +1 -1
- package/dist/provenance/source-ref.js +0 -2
- package/dist/registry/corrections.d.ts +31 -0
- package/dist/registry/corrections.js +332 -0
- package/dist/registry/record-identity.d.ts +49 -0
- package/dist/registry/record-identity.js +133 -0
- package/dist/registry/store.d.ts +101 -0
- package/dist/registry/store.js +395 -0
- package/dist/registry/types.d.ts +28 -0
- package/dist/registry/types.js +5 -0
- package/dist/relevance-scorer.js +2 -2
- package/dist/runtime/agent-event-bus.d.ts +50 -0
- package/dist/runtime/agent-event-bus.js +101 -0
- package/dist/runtime/drivers/claude-cli-wrapper.d.ts +152 -0
- package/dist/runtime/drivers/claude-cli-wrapper.js +375 -0
- package/dist/runtime/drivers/claude-effort.d.ts +4 -0
- package/dist/runtime/drivers/claude-effort.js +16 -0
- package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
- package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
- package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
- package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
- package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
- package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
- package/dist/runtime/drivers/codex-home.d.ts +20 -0
- package/dist/runtime/drivers/codex-home.js +674 -0
- package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
- package/dist/runtime/drivers/codex-thread-registry.js +433 -0
- package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
- package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
- package/dist/runtime/drivers/persistent-cli-process.d.ts +425 -0
- package/dist/runtime/drivers/persistent-cli-process.js +1529 -0
- package/dist/runtime/drivers/types.d.ts +456 -0
- package/dist/runtime/drivers/types.js +110 -0
- package/dist/runtime/mailbox.d.ts +223 -0
- package/dist/runtime/mailbox.js +582 -0
- package/dist/runtime/model-run-store.d.ts +28 -0
- package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
- package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
- package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
- package/dist/runtime/native-effect-observer.d.ts +22 -0
- package/dist/runtime/native-effect-observer.js +103 -0
- package/dist/runtime/native-input-journal.d.ts +46 -0
- package/dist/runtime/native-input-journal.js +308 -0
- package/dist/runtime/native-prompt.d.ts +118 -0
- package/dist/runtime/native-prompt.js +496 -0
- package/dist/runtime/native-session.d.ts +10 -0
- package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
- package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
- package/dist/runtime/native-tool-trace-observer.js +65 -0
- package/dist/runtime/native-turn.d.ts +272 -0
- package/dist/runtime/native-turn.js +1041 -0
- package/dist/runtime/operations.d.ts +236 -0
- package/dist/runtime/operations.js +565 -0
- package/dist/runtime/post-tool-handler.d.ts +74 -0
- package/dist/runtime/post-tool-handler.js +137 -0
- package/dist/runtime/prompt-layers.d.ts +126 -0
- package/dist/runtime/prompt-layers.js +239 -0
- package/dist/runtime/runtime-process.d.ts +102 -0
- package/dist/runtime/runtime-process.js +206 -0
- package/dist/runtime/runtime.d.ts +278 -0
- package/dist/runtime/runtime.js +563 -0
- package/dist/runtime/session-pool.d.ts +176 -0
- package/dist/runtime/session-pool.js +369 -0
- package/dist/runtime/stimulus-payload.d.ts +5 -0
- package/dist/runtime/stimulus-payload.js +50 -0
- package/dist/runtime/subagent-bridge.d.ts +24 -0
- package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
- package/dist/runtime/text-completion.d.ts +22 -0
- package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
- package/dist/runtime/token-estimator.d.ts +25 -0
- package/dist/runtime/token-estimator.js +75 -0
- package/dist/runtime/tool-trace-store.d.ts +22 -0
- package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
- package/dist/runtime/trace-summary.d.ts +5 -0
- package/dist/runtime/trace-summary.js +74 -0
- package/dist/runtime/turn-text.d.ts +23 -0
- package/dist/runtime/turn-text.js +41 -0
- package/dist/storage/database.d.ts +67 -0
- package/dist/storage/database.js +158 -0
- package/package.json +20 -34
- package/dist/agent-graph/alias-write.d.ts +0 -3
- package/dist/agent-graph/alias-write.js +0 -234
- package/dist/agent-graph/entity-resolve.d.ts +0 -3
- package/dist/agent-graph/entity-resolve.js +0 -271
- package/dist/agent-graph/errors.d.ts +0 -4
- package/dist/agent-graph/errors.js +0 -11
- package/dist/agent-graph/graph-query.d.ts +0 -5
- package/dist/agent-graph/graph-query.js +0 -360
- package/dist/agent-graph/index.d.ts +0 -6
- package/dist/agent-situation/builder.d.ts +0 -8
- package/dist/agent-situation/builder.js +0 -239
- package/dist/agent-situation/cache-key.d.ts +0 -4
- package/dist/agent-situation/cache-key.js +0 -64
- package/dist/agent-situation/index.d.ts +0 -7
- package/dist/agent-situation/index.js +0 -28
- package/dist/agent-situation/packet-store.d.ts +0 -27
- package/dist/agent-situation/packet-store.js +0 -228
- package/dist/agent-situation/ranking-policy.d.ts +0 -18
- package/dist/agent-situation/ranking-policy.js +0 -75
- package/dist/agent-situation/source-readers.d.ts +0 -52
- package/dist/agent-situation/source-readers.js +0 -300
- package/dist/agent-situation/types.d.ts +0 -195
- package/dist/cases/wiki-page-index.d.ts +0 -37
- package/dist/cases/wiki-page-index.js +0 -201
- package/dist/config-loader.d.ts +0 -68
- package/dist/config-loader.js +0 -239
- package/dist/connectors/event-index.d.ts +0 -24
- package/dist/connectors/event-index.js +0 -245
- package/dist/connectors/raw-query.d.ts +0 -40
- package/dist/connectors/raw-query.js +0 -412
- package/dist/connectors/types.d.ts +0 -117
- package/dist/connectors/types.js +0 -3
- package/dist/context-compile/boundary-defaults.d.ts +0 -12
- package/dist/context-compile/boundary-defaults.js +0 -105
- package/dist/context-compile/channel-grant.js +0 -66
- package/dist/context-compile/compiler-policy.d.ts +0 -39
- package/dist/context-compile/compiler-policy.js +0 -147
- package/dist/context-compile/compiler.d.ts +0 -18
- package/dist/context-compile/compiler.js +0 -404
- package/dist/context-compile/index.d.ts +0 -10
- package/dist/context-compile/index.js +0 -26
- package/dist/context-compile/packet-store.d.ts +0 -8
- package/dist/context-compile/packet-store.js +0 -239
- package/dist/context-compile/ref.d.ts +0 -7
- package/dist/context-compile/ref.js +0 -102
- package/dist/context-compile/source-readers.d.ts +0 -70
- package/dist/context-compile/source-readers.js +0 -840
- package/dist/context-compile/types.d.ts +0 -155
- package/dist/context-compile/types.js +0 -11
- package/dist/context-compile/visibility.d.ts +0 -21
- package/dist/context-compile/visibility.js +0 -224
- package/dist/decision-tracker.d.ts +0 -206
- package/dist/decision-tracker.js +0 -481
- package/dist/edges/ref-validation.d.ts +0 -7
- package/dist/edges/ref-validation.js +0 -321
- package/dist/edges/store.d.ts +0 -8
- package/dist/edges/store.js +0 -129
- package/dist/embedding-client.d.ts +0 -28
- package/dist/embedding-client.js +0 -53
- package/dist/embedding-server/index.d.ts +0 -67
- package/dist/embedding-server/index.js +0 -405
- package/dist/embedding-server/mobile/auth.d.ts +0 -44
- package/dist/embedding-server/mobile/auth.js +0 -150
- package/dist/embedding-server/mobile/daemon.d.ts +0 -129
- package/dist/embedding-server/mobile/daemon.js +0 -313
- package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
- package/dist/embedding-server/mobile/output-parser.js +0 -241
- package/dist/embedding-server/mobile/session-api.d.ts +0 -57
- package/dist/embedding-server/mobile/session-api.js +0 -261
- package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
- package/dist/embedding-server/mobile/session-manager.js +0 -378
- package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
- package/dist/embedding-server/mobile/websocket-handler.js +0 -486
- package/dist/embeddings.d.ts +0 -68
- package/dist/embeddings.js +0 -244
- package/dist/entities/audit-metrics.d.ts +0 -68
- package/dist/entities/audit-metrics.js +0 -124
- package/dist/entities/candidate-generator.d.ts +0 -8
- package/dist/entities/candidate-generator.js +0 -24
- package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
- package/dist/entities/entity-linked-decision-counts.js +0 -29
- package/dist/entities/entity-list.d.ts +0 -22
- package/dist/entities/entity-list.js +0 -3
- package/dist/entities/entity-orphan-list.d.ts +0 -17
- package/dist/entities/entity-orphan-list.js +0 -3
- package/dist/entities/entity-search.d.ts +0 -20
- package/dist/entities/entity-search.js +0 -3
- package/dist/entities/errors.d.ts +0 -55
- package/dist/entities/errors.js +0 -100
- package/dist/entities/lineage-store.d.ts +0 -28
- package/dist/entities/lineage-store.js +0 -204
- package/dist/entities/normalization.d.ts +0 -14
- package/dist/entities/normalization.js +0 -63
- package/dist/entities/policy-store.d.ts +0 -8
- package/dist/entities/policy-store.js +0 -75
- package/dist/entities/policy-types.d.ts +0 -72
- package/dist/entities/policy-types.js +0 -59
- package/dist/entities/projection.d.ts +0 -8
- package/dist/entities/projection.js +0 -82
- package/dist/entities/provenance-query.d.ts +0 -32
- package/dist/entities/provenance-query.js +0 -3
- package/dist/entities/read-identity.d.ts +0 -31
- package/dist/entities/read-identity.js +0 -264
- package/dist/entities/recall-bridge.d.ts +0 -5
- package/dist/entities/recall-bridge.js +0 -171
- package/dist/entities/resolution-engine.d.ts +0 -8
- package/dist/entities/resolution-engine.js +0 -3
- package/dist/entities/rollback-preview.d.ts +0 -35
- package/dist/entities/rollback-preview.js +0 -3
- package/dist/entities/source-locator.d.ts +0 -3
- package/dist/entities/source-locator.js +0 -32
- package/dist/entities/store.d.ts +0 -69
- package/dist/entities/store.js +0 -544
- package/dist/entities/types.d.ts +0 -166
- package/dist/entities/types.js +0 -30
- package/dist/memory/extraction-prompt.d.ts +0 -4
- package/dist/memory/extraction-prompt.js +0 -89
- package/dist/memory/scope-backfill.d.ts +0 -14
- package/dist/memory/scope-backfill.js +0 -3
- package/dist/memory/scope-store.d.ts +0 -4
- package/dist/memory/scope-store.js +0 -9
- package/dist/memory-store.d.ts +0 -87
- package/dist/memory-store.js +0 -78
- package/dist/model-runs/store.d.ts +0 -13
- package/dist/model-runs/tool-trace-store.d.ts +0 -8
- package/dist/notification-manager.d.ts +0 -7
- package/dist/notification-manager.js +0 -12
- package/dist/outcome-tracker.d.ts +0 -151
- package/dist/outcome-tracker.js +0 -271
- package/dist/query-intent.d.ts +0 -23
- package/dist/query-intent.js +0 -114
- package/dist/runtime/trusted-provenance.d.ts +0 -3
- package/dist/runtime/trusted-provenance.js +0 -6
- package/dist/search/question-type.d.ts +0 -5
- package/dist/search/question-type.js +0 -41
- package/dist/test-utils.d.ts +0 -80
- package/dist/test-utils.js +0 -218
- package/dist/tier-validator.d.ts +0 -43
- package/dist/tier-validator.js +0 -159
- package/dist/time-formatter.d.ts +0 -25
- package/dist/time-formatter.js +0 -93
- /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
- /package/dist/{search → knowledge}/feedback-store.js +0 -0
- /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
- /package/dist/{search → knowledge}/search-quality.js +0 -0
|
@@ -1,114 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
-- Retired: this migration declared the observation sequence on the connector event index.
|
|
2
|
+
--
|
|
3
|
+
-- The index moved to the package that has connectors. Three of the four consumers
|
|
4
|
+
-- of this core have none, and were running these statements against tables they
|
|
5
|
+
-- never write. The schema is declared whole in standalone/db/migrations/001.
|
|
6
|
+
--
|
|
7
|
+
-- The file stays, and the number stays claimed: databases in the field recorded
|
|
8
|
+
-- 62 as applied, and a number that comes back meaning something else is worse
|
|
9
|
+
-- than a number that means nothing.
|
|
5
10
|
|
|
6
|
-
CREATE TABLE IF NOT EXISTS connector_event_index_observation_cursors (
|
|
7
|
-
source_connector TEXT PRIMARY KEY,
|
|
8
|
-
next_seq INTEGER NOT NULL CHECK (next_seq >= 1)
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
WITH ranked AS (
|
|
12
|
-
SELECT event_index_id,
|
|
13
|
-
ROW_NUMBER() OVER (
|
|
14
|
-
PARTITION BY source_connector
|
|
15
|
-
ORDER BY source_timestamp_ms, rowid
|
|
16
|
-
) AS seq
|
|
17
|
-
FROM connector_event_index
|
|
18
|
-
)
|
|
19
|
-
UPDATE connector_event_index
|
|
20
|
-
SET operator_observation_seq = (
|
|
21
|
-
SELECT seq FROM ranked WHERE ranked.event_index_id = connector_event_index.event_index_id
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
INSERT INTO connector_event_index_observation_cursors (source_connector, next_seq)
|
|
25
|
-
SELECT source_connector, MAX(operator_observation_seq) + 1
|
|
26
|
-
FROM connector_event_index
|
|
27
|
-
GROUP BY source_connector
|
|
28
|
-
ON CONFLICT(source_connector) DO UPDATE SET next_seq = CASE
|
|
29
|
-
WHEN connector_event_index_observation_cursors.next_seq < excluded.next_seq
|
|
30
|
-
THEN excluded.next_seq
|
|
31
|
-
ELSE connector_event_index_observation_cursors.next_seq
|
|
32
|
-
END;
|
|
33
|
-
|
|
34
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_connector_event_index_observation_seq
|
|
35
|
-
ON connector_event_index(source_connector, operator_observation_seq)
|
|
36
|
-
WHERE operator_observation_seq IS NOT NULL;
|
|
37
|
-
|
|
38
|
-
CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_operator_ingest_seq_au
|
|
39
|
-
AFTER UPDATE OF operator_ingest_seq ON connector_event_index
|
|
40
|
-
WHEN NEW.operator_ingest_seq IS NULL AND OLD.operator_ingest_seq IS NOT NULL
|
|
41
|
-
BEGIN
|
|
42
|
-
INSERT INTO connector_event_index_operator_seq_cursors
|
|
43
|
-
(source_connector, channel, next_seq)
|
|
44
|
-
VALUES (NEW.source_connector, COALESCE(NEW.channel, ''), 1)
|
|
45
|
-
ON CONFLICT(source_connector, channel) DO NOTHING;
|
|
46
|
-
UPDATE connector_event_index
|
|
47
|
-
SET operator_ingest_seq = (
|
|
48
|
-
SELECT next_seq FROM connector_event_index_operator_seq_cursors
|
|
49
|
-
WHERE source_connector = NEW.source_connector
|
|
50
|
-
AND channel = COALESCE(NEW.channel, '')
|
|
51
|
-
)
|
|
52
|
-
WHERE event_index_id = NEW.event_index_id;
|
|
53
|
-
UPDATE connector_event_index_operator_seq_cursors
|
|
54
|
-
SET next_seq = next_seq + 1
|
|
55
|
-
WHERE source_connector = NEW.source_connector
|
|
56
|
-
AND channel = COALESCE(NEW.channel, '');
|
|
57
|
-
END;
|
|
58
|
-
|
|
59
|
-
CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_ai
|
|
60
|
-
AFTER INSERT ON connector_event_index
|
|
61
|
-
WHEN NEW.operator_observation_seq IS NULL
|
|
62
|
-
BEGIN
|
|
63
|
-
INSERT INTO connector_event_index_observation_cursors
|
|
64
|
-
(source_connector, next_seq)
|
|
65
|
-
VALUES (NEW.source_connector, 1)
|
|
66
|
-
ON CONFLICT(source_connector) DO NOTHING;
|
|
67
|
-
UPDATE connector_event_index
|
|
68
|
-
SET operator_observation_seq = (
|
|
69
|
-
SELECT next_seq FROM connector_event_index_observation_cursors
|
|
70
|
-
WHERE source_connector = NEW.source_connector
|
|
71
|
-
)
|
|
72
|
-
WHERE event_index_id = NEW.event_index_id;
|
|
73
|
-
UPDATE connector_event_index_observation_cursors
|
|
74
|
-
SET next_seq = next_seq + 1
|
|
75
|
-
WHERE source_connector = NEW.source_connector;
|
|
76
|
-
END;
|
|
77
|
-
|
|
78
|
-
CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_au
|
|
79
|
-
AFTER UPDATE OF operator_observation_seq ON connector_event_index
|
|
80
|
-
WHEN NEW.operator_observation_seq IS NULL AND OLD.operator_observation_seq IS NOT NULL
|
|
81
|
-
BEGIN
|
|
82
|
-
INSERT INTO connector_event_index_observation_cursors
|
|
83
|
-
(source_connector, next_seq)
|
|
84
|
-
VALUES (NEW.source_connector, 1)
|
|
85
|
-
ON CONFLICT(source_connector) DO NOTHING;
|
|
86
|
-
UPDATE connector_event_index
|
|
87
|
-
SET operator_observation_seq = (
|
|
88
|
-
SELECT next_seq FROM connector_event_index_observation_cursors
|
|
89
|
-
WHERE source_connector = NEW.source_connector
|
|
90
|
-
)
|
|
91
|
-
WHERE event_index_id = NEW.event_index_id;
|
|
92
|
-
UPDATE connector_event_index_observation_cursors
|
|
93
|
-
SET next_seq = next_seq + 1
|
|
94
|
-
WHERE source_connector = NEW.source_connector;
|
|
95
|
-
END;
|
|
96
|
-
|
|
97
|
-
CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_explicit_ai
|
|
98
|
-
AFTER INSERT ON connector_event_index
|
|
99
|
-
WHEN NEW.operator_observation_seq IS NOT NULL
|
|
100
|
-
BEGIN
|
|
101
|
-
INSERT INTO connector_event_index_observation_cursors
|
|
102
|
-
(source_connector, next_seq)
|
|
103
|
-
VALUES (NEW.source_connector, 1)
|
|
104
|
-
ON CONFLICT(source_connector) DO NOTHING;
|
|
105
|
-
UPDATE connector_event_index_observation_cursors
|
|
106
|
-
SET next_seq = CASE
|
|
107
|
-
WHEN next_seq <= NEW.operator_observation_seq THEN NEW.operator_observation_seq + 1
|
|
108
|
-
ELSE next_seq
|
|
109
|
-
END
|
|
110
|
-
WHERE source_connector = NEW.source_connector;
|
|
111
|
-
END;
|
|
112
|
-
|
|
113
|
-
INSERT INTO schema_version (version, description)
|
|
114
|
-
VALUES (62, 'Refresh connector event delivery and observation sequences');
|
|
@@ -1,33 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
-- Retired: this migration declared the legacy content refresh trigger on the connector event index.
|
|
2
|
+
--
|
|
3
|
+
-- The index moved to the package that has connectors. Three of the four consumers
|
|
4
|
+
-- of this core have none, and were running these statements against tables they
|
|
5
|
+
-- never write. The schema is declared whole in standalone/db/migrations/001.
|
|
6
|
+
--
|
|
7
|
+
-- The file stays, and the number stays claimed: databases in the field recorded
|
|
8
|
+
-- 63 as applied, and a number that comes back meaning something else is worse
|
|
9
|
+
-- than a number that means nothing.
|
|
5
10
|
|
|
6
|
-
CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_legacy_content_refresh_au
|
|
7
|
-
AFTER UPDATE OF content_hash, metadata_json, source_timestamp_ms, source_type, channel
|
|
8
|
-
ON connector_event_index
|
|
9
|
-
WHEN (
|
|
10
|
-
OLD.content_hash IS NOT NEW.content_hash
|
|
11
|
-
OR OLD.metadata_json IS NOT NEW.metadata_json
|
|
12
|
-
OR OLD.source_timestamp_ms IS NOT NEW.source_timestamp_ms
|
|
13
|
-
OR OLD.source_type IS NOT NEW.source_type
|
|
14
|
-
OR OLD.channel IS NOT NEW.channel
|
|
15
|
-
) AND (
|
|
16
|
-
NEW.operator_ingest_seq IS OLD.operator_ingest_seq
|
|
17
|
-
OR NEW.operator_observation_seq IS OLD.operator_observation_seq
|
|
18
|
-
)
|
|
19
|
-
BEGIN
|
|
20
|
-
UPDATE connector_event_index
|
|
21
|
-
SET operator_ingest_seq = CASE
|
|
22
|
-
WHEN NEW.operator_ingest_seq IS OLD.operator_ingest_seq THEN NULL
|
|
23
|
-
ELSE NEW.operator_ingest_seq
|
|
24
|
-
END,
|
|
25
|
-
operator_observation_seq = CASE
|
|
26
|
-
WHEN NEW.operator_observation_seq IS OLD.operator_observation_seq THEN NULL
|
|
27
|
-
ELSE NEW.operator_observation_seq
|
|
28
|
-
END
|
|
29
|
-
WHERE event_index_id = NEW.event_index_id;
|
|
30
|
-
END;
|
|
31
|
-
|
|
32
|
-
INSERT OR IGNORE INTO schema_version (version, description)
|
|
33
|
-
VALUES (63, 'Refresh sequences for legacy connector event updates');
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
--
|
|
2
|
-
--
|
|
3
|
-
--
|
|
4
|
-
--
|
|
5
|
-
|
|
1
|
+
-- Retired: this migration declared the source entity id on the connector event index.
|
|
2
|
+
--
|
|
3
|
+
-- The index moved to the package that has connectors. Three of the four consumers
|
|
4
|
+
-- of this core have none, and were running these statements against tables they
|
|
5
|
+
-- never write. The schema is declared whole in standalone/db/migrations/001.
|
|
6
|
+
--
|
|
7
|
+
-- The file stays, and the number stays claimed: databases in the field recorded
|
|
8
|
+
-- 67 as applied, and a number that comes back meaning something else is worse
|
|
9
|
+
-- than a number that means nothing.
|
|
6
10
|
|
|
7
|
-
UPDATE connector_event_index
|
|
8
|
-
SET source_entity_id = json_extract(metadata_json, '$.sourceEntityId')
|
|
9
|
-
WHERE source_entity_id IS NULL
|
|
10
|
-
AND metadata_json IS NOT NULL
|
|
11
|
-
AND json_extract(metadata_json, '$.sourceEntityId') IS NOT NULL;
|
|
12
|
-
|
|
13
|
-
CREATE INDEX IF NOT EXISTS idx_connector_event_source_entity
|
|
14
|
-
ON connector_event_index(source_connector, source_entity_id);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-- Registry: the one place that says "these names are the same thing".
|
|
2
|
+
--
|
|
3
|
+
-- A work item or a person is a node; every spelling it is known by is an alias row. Records
|
|
4
|
+
-- and tasks point at the node, so a fact filed under one spelling and a task titled with
|
|
5
|
+
-- another still join.
|
|
6
|
+
--
|
|
7
|
+
-- Merging is a decision, never a similarity guess. Alias uniqueness is keyed by kind and
|
|
8
|
+
-- visibility scope, so a contested alias inside one scope is explicit while separate scopes
|
|
9
|
+
-- may use the same spelling independently.
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS registry_nodes (
|
|
12
|
+
id TEXT PRIMARY KEY,
|
|
13
|
+
kind TEXT NOT NULL CHECK (kind IN ('item', 'person', 'client')),
|
|
14
|
+
name TEXT NOT NULL,
|
|
15
|
+
-- Set when an owner correction splits one item into the files it really covers.
|
|
16
|
+
parent_id TEXT REFERENCES registry_nodes(id) ON DELETE SET NULL,
|
|
17
|
+
-- Set when this node was merged away; resolution follows the pointer to the survivor.
|
|
18
|
+
merged_into TEXT REFERENCES registry_nodes(id) ON DELETE SET NULL,
|
|
19
|
+
merge_reason TEXT,
|
|
20
|
+
note TEXT,
|
|
21
|
+
created_at INTEGER NOT NULL,
|
|
22
|
+
updated_at INTEGER NOT NULL
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE INDEX IF NOT EXISTS idx_registry_nodes_kind ON registry_nodes(kind, merged_into);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS idx_registry_nodes_parent ON registry_nodes(parent_id);
|
|
27
|
+
|
|
28
|
+
CREATE TABLE IF NOT EXISTS registry_aliases (
|
|
29
|
+
node_id TEXT NOT NULL REFERENCES registry_nodes(id) ON DELETE CASCADE,
|
|
30
|
+
kind TEXT NOT NULL CHECK (kind IN ('item', 'person', 'client')),
|
|
31
|
+
-- Case- and space-normalised at write time; the display form stays in `alias_display`.
|
|
32
|
+
alias TEXT NOT NULL,
|
|
33
|
+
alias_display TEXT NOT NULL,
|
|
34
|
+
scope_kind TEXT NOT NULL CHECK (scope_kind IN ('global', 'user', 'channel', 'project')),
|
|
35
|
+
scope_id TEXT NOT NULL,
|
|
36
|
+
created_at INTEGER NOT NULL,
|
|
37
|
+
PRIMARY KEY (kind, alias, scope_kind, scope_id)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE INDEX IF NOT EXISTS idx_registry_aliases_node ON registry_aliases(node_id);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_registry_aliases_scope
|
|
42
|
+
ON registry_aliases(kind, alias, scope_kind, scope_id);
|
|
43
|
+
|
|
44
|
+
CREATE TABLE IF NOT EXISTS registry_scope_bindings (
|
|
45
|
+
node_id TEXT NOT NULL REFERENCES registry_nodes(id) ON DELETE CASCADE,
|
|
46
|
+
scope_kind TEXT NOT NULL CHECK (scope_kind IN ('global', 'user', 'channel', 'project')),
|
|
47
|
+
scope_id TEXT NOT NULL,
|
|
48
|
+
PRIMARY KEY (node_id, scope_kind, scope_id)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE INDEX IF NOT EXISTS idx_registry_scope_lookup
|
|
52
|
+
ON registry_scope_bindings(scope_kind, scope_id, node_id);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- What a record is about, and who was involved, as references instead of prose.
|
|
2
|
+
--
|
|
3
|
+
-- The only statement of subject used to be the `topic` text. `item_id` points at a
|
|
4
|
+
-- registry node, so two spellings of one item join.
|
|
5
|
+
--
|
|
6
|
+
-- `record_actors` is a table rather than a column because one record routinely involves
|
|
7
|
+
-- several people in different roles - the person who did the work, the one who relayed it,
|
|
8
|
+
-- the client contact. The single `assignee` slot on a task was losing that distinction, and
|
|
9
|
+
-- putting it back as one column would lose it again. The role is free text: production work
|
|
10
|
+
-- and a booking do not share a role vocabulary, and the registry holds the person while the
|
|
11
|
+
-- role belongs to this record.
|
|
12
|
+
--
|
|
13
|
+
-- No foreign key to registry_nodes: the store validates the node and its kind before
|
|
14
|
+
-- writing, and a merge rewrites nothing (readers canonicalise through merged_into), so a
|
|
15
|
+
-- database-level constraint would only add a failure mode without adding a guarantee.
|
|
16
|
+
|
|
17
|
+
ALTER TABLE decisions ADD COLUMN item_id TEXT;
|
|
18
|
+
|
|
19
|
+
-- Only the item. A composite index over
|
|
20
|
+
-- COALESCE(event_datetime, created_at) was tried first and broke recovery of databases whose
|
|
21
|
+
-- schema_version is newer than their structure - event_datetime arrives in migration 030 and
|
|
22
|
+
-- is not guaranteed to exist when this one runs.
|
|
23
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_item ON decisions(item_id);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE IF NOT EXISTS record_actors (
|
|
26
|
+
record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE CASCADE,
|
|
27
|
+
person_id TEXT NOT NULL,
|
|
28
|
+
role TEXT NOT NULL,
|
|
29
|
+
-- Insertion order, so the actor list reads back the way the agent stated it.
|
|
30
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
31
|
+
created_at INTEGER NOT NULL,
|
|
32
|
+
PRIMARY KEY (record_id, person_id, role)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_record_actors_person ON record_actors(person_id, record_id);
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
-- Migration 071: a truthful service/CLI operation can trace itself.
|
|
2
|
+
--
|
|
3
|
+
-- tool_traces was model-only: model_run_id was NOT NULL with an FK to
|
|
4
|
+
-- model_runs, so a host operation could be recorded only by forging a fake
|
|
5
|
+
-- model run. This migration relaxes that: model_run_id becomes nullable, and
|
|
6
|
+
-- an operation-origin row is anchored instead by a nonempty operation_id and
|
|
7
|
+
-- actor_principal_id. A CHECK forbids a row with neither origin. Legacy rows
|
|
8
|
+
-- keep their model id and semantics; the model_runs FK is preserved.
|
|
9
|
+
--
|
|
10
|
+
-- WHY A TABLE REBUILD: dropping the NOT NULL on model_run_id and adding a CHECK
|
|
11
|
+
-- cannot be done with ALTER; SQLite requires create/copy/drop/rename. This SQL
|
|
12
|
+
-- file rebuilds the canonical (post-068) column set and is what the plain
|
|
13
|
+
-- applyAll test path runs. The migration runner special-cases version 71 with a
|
|
14
|
+
-- dynamic rebuild that additionally preserves any extra runtime columns/indexes/
|
|
15
|
+
-- triggers a live database may carry (see node-sqlite-adapter). Both produce the
|
|
16
|
+
-- same canonical shape. The rebuild copies every existing row and re-creates
|
|
17
|
+
-- every 033/061/068 index; nothing is dropped.
|
|
18
|
+
--
|
|
19
|
+
-- GUARD: this canonical-only direct-SQL path can express ONLY the exact pre-071
|
|
20
|
+
-- canonical tool_traces (the fresh 033/061/068 chain: 17 columns with fixed
|
|
21
|
+
-- types/NOT NULL/DEFAULT/PK, one FK to model_runs, the PK auto-index, and the
|
|
22
|
+
-- four 033/068 named indexes). It copies no origin values and carries no
|
|
23
|
+
-- triggers, embedded constraints, custom/unique indexes or referencing children
|
|
24
|
+
-- across the rebuild. Against anything else it would SILENTLY DROP it (a runtime
|
|
25
|
+
-- column, a changed column constraint/default, an embedded CHECK/UNIQUE, an
|
|
26
|
+
-- extra outgoing FK, a trigger, a custom/unique index, an already-present
|
|
27
|
+
-- operation_id / actor_principal_id value) or CASCADE-delete a referencing child
|
|
28
|
+
-- row on the DROP TABLE. Production extended-schema upgrades must instead go
|
|
29
|
+
-- through the dynamic adapter path, which preserves all of those verbatim. So
|
|
30
|
+
-- this guard fails LOUDLY, before altering any data, on any deviation from the
|
|
31
|
+
-- exact canonical pre-071 shape: the CHECK on _migration071_guard aborts the
|
|
32
|
+
-- whole script if the CASE evaluates to 0.
|
|
33
|
+
--
|
|
34
|
+
-- This is a strict canonical-shape precondition (a fingerprint of the known
|
|
35
|
+
-- fresh pre-071 chain), NOT a general SQL migration engine and NOT a policy on
|
|
36
|
+
-- the production adapter. It enumerates the full canonical column tuples, the
|
|
37
|
+
-- single canonical FK, exactly one auto-index (the PK), and rejects embedded
|
|
38
|
+
-- CHECK text, triggers, extra explicit indexes, and referencing children.
|
|
39
|
+
-- NOTE: the pre-071 canonical shape has NO operation_id/actor_principal_id
|
|
40
|
+
-- columns (071 adds them); their presence means a noncanonical source this path
|
|
41
|
+
-- cannot faithfully carry.
|
|
42
|
+
|
|
43
|
+
CREATE TEMP TABLE _migration071_guard (ok INTEGER NOT NULL CHECK (ok = 1));
|
|
44
|
+
INSERT INTO _migration071_guard (ok)
|
|
45
|
+
SELECT CASE
|
|
46
|
+
-- (1) column count must be exactly the 17 canonical columns (catches an extra
|
|
47
|
+
-- column - including an already-present origin column this path cannot
|
|
48
|
+
-- copy - and a missing column).
|
|
49
|
+
WHEN (SELECT count(*) FROM pragma_table_info('tool_traces')) <> 17 THEN 0
|
|
50
|
+
-- (2) every column must match the canonical (name, type, NOT NULL, DEFAULT, PK)
|
|
51
|
+
-- tuple. Catches a renamed/extra column, a changed column constraint, a
|
|
52
|
+
-- changed default, and an already-present operation_id/actor_principal_id.
|
|
53
|
+
WHEN EXISTS (
|
|
54
|
+
SELECT 1 FROM pragma_table_info('tool_traces') ti
|
|
55
|
+
WHERE NOT EXISTS (
|
|
56
|
+
SELECT 1 FROM (
|
|
57
|
+
SELECT 'trace_id' AS cname, 'TEXT' AS ctype, 0 AS cnn, NULL AS cdflt, 1 AS cpk
|
|
58
|
+
UNION ALL SELECT 'model_run_id', 'TEXT', 1, NULL, 0
|
|
59
|
+
UNION ALL SELECT 'gateway_call_id', 'TEXT', 0, NULL, 0
|
|
60
|
+
UNION ALL SELECT 'tool_name', 'TEXT', 1, NULL, 0
|
|
61
|
+
UNION ALL SELECT 'input_summary', 'TEXT', 0, NULL, 0
|
|
62
|
+
UNION ALL SELECT 'output_summary', 'TEXT', 0, NULL, 0
|
|
63
|
+
UNION ALL SELECT 'execution_status', 'TEXT', 0, NULL, 0
|
|
64
|
+
UNION ALL SELECT 'duration_ms', 'INTEGER', 0, '0', 0
|
|
65
|
+
UNION ALL SELECT 'envelope_hash', 'TEXT', 0, NULL, 0
|
|
66
|
+
UNION ALL SELECT 'created_at', 'INTEGER', 1, NULL, 0
|
|
67
|
+
UNION ALL SELECT 'failure_code', 'TEXT', 0, NULL, 0
|
|
68
|
+
UNION ALL SELECT 'diagnostic_json', 'TEXT', 0, NULL, 0
|
|
69
|
+
UNION ALL SELECT 'evidence_json', 'TEXT', 0, NULL, 0
|
|
70
|
+
UNION ALL SELECT 'catalog_revision', 'TEXT', 0, NULL, 0
|
|
71
|
+
UNION ALL SELECT 'owner_scope', 'TEXT', 0, NULL, 0
|
|
72
|
+
UNION ALL SELECT 'project_id', 'TEXT', 0, NULL, 0
|
|
73
|
+
UNION ALL SELECT 'channel_id', 'TEXT', 0, NULL, 0
|
|
74
|
+
) canon
|
|
75
|
+
WHERE canon.cname = ti.name
|
|
76
|
+
AND canon.ctype = ti.type
|
|
77
|
+
AND canon.cnn = ti."notnull"
|
|
78
|
+
AND canon.cpk = ti.pk
|
|
79
|
+
AND ((canon.cdflt IS NULL AND ti.dflt_value IS NULL) OR canon.cdflt = ti.dflt_value)
|
|
80
|
+
)
|
|
81
|
+
) THEN 0
|
|
82
|
+
-- (3) the outgoing FK set must be exactly the single canonical model_runs FK
|
|
83
|
+
-- (catches an extra or changed outgoing FK).
|
|
84
|
+
WHEN (SELECT count(*) FROM pragma_foreign_key_list('tool_traces')) <> 1 THEN 0
|
|
85
|
+
WHEN NOT EXISTS (
|
|
86
|
+
SELECT 1 FROM pragma_foreign_key_list('tool_traces')
|
|
87
|
+
WHERE "from" = 'model_run_id' AND "table" = 'model_runs' AND "to" = 'model_run_id'
|
|
88
|
+
) THEN 0
|
|
89
|
+
-- (4) no embedded CHECK constraint. pragma does not expose CHECK, so scan the
|
|
90
|
+
-- stored CREATE TABLE text; the canonical shape carries no CHECK keyword.
|
|
91
|
+
WHEN EXISTS (
|
|
92
|
+
SELECT 1 FROM sqlite_master
|
|
93
|
+
WHERE type = 'table' AND name = 'tool_traces' AND instr(upper(sql), 'CHECK') > 0
|
|
94
|
+
) THEN 0
|
|
95
|
+
-- (5) exactly one auto-index (the trace_id PK). An embedded UNIQUE constraint
|
|
96
|
+
-- (table- or column-level) adds a second sql-IS-NULL auto-index; merely
|
|
97
|
+
-- ignoring sql-IS-NULL auto-indexes would silently drop it on rebuild.
|
|
98
|
+
WHEN (
|
|
99
|
+
SELECT count(*) FROM sqlite_master
|
|
100
|
+
WHERE type = 'index' AND tbl_name = 'tool_traces' AND sql IS NULL
|
|
101
|
+
) <> 1 THEN 0
|
|
102
|
+
-- (6) any trigger on tool_traces (DROP/RENAME would not carry it).
|
|
103
|
+
WHEN EXISTS (
|
|
104
|
+
SELECT 1 FROM sqlite_master WHERE type = 'trigger' AND tbl_name = 'tool_traces'
|
|
105
|
+
) THEN 0
|
|
106
|
+
-- (7) any non-canonical explicit index on tool_traces (a user/unique index
|
|
107
|
+
-- with its own CREATE statement this path does not recreate).
|
|
108
|
+
WHEN EXISTS (
|
|
109
|
+
SELECT 1 FROM sqlite_master
|
|
110
|
+
WHERE type = 'index' AND tbl_name = 'tool_traces' AND sql IS NOT NULL
|
|
111
|
+
AND name NOT IN (
|
|
112
|
+
'idx_tool_traces_model_run_id', 'idx_tool_traces_gateway_call_id',
|
|
113
|
+
'idx_tool_traces_scope_recency', 'idx_tool_traces_channel_recency'
|
|
114
|
+
)
|
|
115
|
+
) THEN 0
|
|
116
|
+
-- (8) any table that references tool_traces - the DROP TABLE below would
|
|
117
|
+
-- CASCADE-delete its rows. Detected via the per-table FK list.
|
|
118
|
+
WHEN EXISTS (
|
|
119
|
+
SELECT 1 FROM sqlite_master m
|
|
120
|
+
WHERE m.type = 'table' AND m.name NOT LIKE 'sqlite_%' AND m.name <> 'tool_traces'
|
|
121
|
+
AND EXISTS (
|
|
122
|
+
SELECT 1 FROM pragma_foreign_key_list(m.name) fk WHERE fk."table" = 'tool_traces'
|
|
123
|
+
)
|
|
124
|
+
) THEN 0
|
|
125
|
+
ELSE 1
|
|
126
|
+
END;
|
|
127
|
+
DROP TABLE _migration071_guard;
|
|
128
|
+
|
|
129
|
+
CREATE TABLE tool_traces_071_new (
|
|
130
|
+
trace_id TEXT PRIMARY KEY,
|
|
131
|
+
model_run_id TEXT,
|
|
132
|
+
gateway_call_id TEXT,
|
|
133
|
+
tool_name TEXT NOT NULL,
|
|
134
|
+
input_summary TEXT,
|
|
135
|
+
output_summary TEXT,
|
|
136
|
+
execution_status TEXT,
|
|
137
|
+
duration_ms INTEGER DEFAULT 0,
|
|
138
|
+
envelope_hash TEXT,
|
|
139
|
+
created_at INTEGER NOT NULL,
|
|
140
|
+
failure_code TEXT,
|
|
141
|
+
diagnostic_json TEXT,
|
|
142
|
+
evidence_json TEXT,
|
|
143
|
+
catalog_revision TEXT,
|
|
144
|
+
owner_scope TEXT,
|
|
145
|
+
project_id TEXT,
|
|
146
|
+
channel_id TEXT,
|
|
147
|
+
operation_id TEXT,
|
|
148
|
+
actor_principal_id TEXT,
|
|
149
|
+
CHECK (
|
|
150
|
+
(model_run_id IS NOT NULL AND operation_id IS NULL AND actor_principal_id IS NULL)
|
|
151
|
+
OR (
|
|
152
|
+
operation_id IS NOT NULL AND length(trim(operation_id)) > 0
|
|
153
|
+
AND actor_principal_id IS NOT NULL AND length(trim(actor_principal_id)) > 0
|
|
154
|
+
)
|
|
155
|
+
),
|
|
156
|
+
FOREIGN KEY (model_run_id) REFERENCES model_runs(model_run_id)
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
INSERT INTO tool_traces_071_new (
|
|
160
|
+
trace_id, model_run_id, gateway_call_id, tool_name, input_summary, output_summary,
|
|
161
|
+
execution_status, duration_ms, envelope_hash, created_at, failure_code,
|
|
162
|
+
diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
163
|
+
)
|
|
164
|
+
SELECT
|
|
165
|
+
trace_id, model_run_id, gateway_call_id, tool_name, input_summary, output_summary,
|
|
166
|
+
execution_status, duration_ms, envelope_hash, created_at, failure_code,
|
|
167
|
+
diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
168
|
+
FROM tool_traces;
|
|
169
|
+
|
|
170
|
+
DROP TABLE tool_traces;
|
|
171
|
+
ALTER TABLE tool_traces_071_new RENAME TO tool_traces;
|
|
172
|
+
|
|
173
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_model_run_id
|
|
174
|
+
ON tool_traces(model_run_id, created_at DESC);
|
|
175
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_gateway_call_id
|
|
176
|
+
ON tool_traces(gateway_call_id);
|
|
177
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_scope_recency
|
|
178
|
+
ON tool_traces(owner_scope, project_id, created_at DESC, trace_id DESC);
|
|
179
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_channel_recency
|
|
180
|
+
ON tool_traces(owner_scope, project_id, channel_id, created_at DESC, trace_id DESC);
|
|
181
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_operation_id
|
|
182
|
+
ON tool_traces(operation_id, created_at DESC);
|
|
183
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_actor_principal
|
|
184
|
+
ON tool_traces(actor_principal_id, created_at DESC);
|
|
185
|
+
|
|
186
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
187
|
+
VALUES (71, 'Service operation-origin tool traces');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-- Immutable source observations. The current event index points at the exact captured version;
|
|
2
|
+
-- retention of the mutable index never deletes the historical observation.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS observation_versions (
|
|
4
|
+
observation_id TEXT PRIMARY KEY,
|
|
5
|
+
source TEXT NOT NULL CHECK (length(trim(source)) > 0),
|
|
6
|
+
source_id TEXT NOT NULL CHECK (length(trim(source_id)) > 0),
|
|
7
|
+
producer_version_id TEXT,
|
|
8
|
+
body TEXT,
|
|
9
|
+
body_location_json TEXT,
|
|
10
|
+
author TEXT,
|
|
11
|
+
source_at INTEGER,
|
|
12
|
+
observed_at INTEGER NOT NULL,
|
|
13
|
+
content_hash TEXT NOT NULL CHECK (length(trim(content_hash)) > 0),
|
|
14
|
+
metadata_json TEXT NOT NULL,
|
|
15
|
+
scope_json TEXT NOT NULL,
|
|
16
|
+
CHECK ((body IS NOT NULL AND body_location_json IS NULL)
|
|
17
|
+
OR (body IS NULL AND body_location_json IS NOT NULL))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
CREATE INDEX IF NOT EXISTS observation_source_versions
|
|
21
|
+
ON observation_versions(source, source_id, observed_at, observation_id);
|
|
22
|
+
|
|
23
|
+
-- `connector_event_index.current_observation_id` was added here. The index belongs
|
|
24
|
+
-- to the package that has connectors and declares that column itself; the core no
|
|
25
|
+
-- longer knows the table exists. The direction it records is unchanged, and it was
|
|
26
|
+
-- always the right one: the index points at the observation.
|
|
27
|
+
|
|
28
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
29
|
+
VALUES (72, 'Immutable connector and owner observation versions');
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- Atomic, scoped identity corrections. Migration 069 remains the authority for aliases and
|
|
2
|
+
-- scope bindings; correction history extends that schema without rewriting it.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS registry_identity_state (
|
|
4
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
5
|
+
revision INTEGER NOT NULL CHECK (revision >= 0)
|
|
6
|
+
);
|
|
7
|
+
INSERT OR IGNORE INTO registry_identity_state (singleton, revision) VALUES (1, 0);
|
|
8
|
+
|
|
9
|
+
CREATE TABLE IF NOT EXISTS registry_corrections (
|
|
10
|
+
command_id TEXT PRIMARY KEY,
|
|
11
|
+
operation TEXT NOT NULL CHECK (operation IN ('add_alias', 'merge', 'split', 'assign_refs')),
|
|
12
|
+
expected_revision INTEGER NOT NULL CHECK (expected_revision >= 0),
|
|
13
|
+
committed_revision INTEGER NOT NULL UNIQUE CHECK (committed_revision > expected_revision),
|
|
14
|
+
principal_id TEXT,
|
|
15
|
+
agent_id TEXT,
|
|
16
|
+
origin TEXT NOT NULL CHECK (origin IN ('trusted', 'legacy_unattributed')),
|
|
17
|
+
payload_json TEXT NOT NULL,
|
|
18
|
+
reason TEXT NOT NULL CHECK (length(trim(reason)) > 0),
|
|
19
|
+
evidence_json TEXT NOT NULL,
|
|
20
|
+
scope_json TEXT NOT NULL,
|
|
21
|
+
receipt_json TEXT NOT NULL,
|
|
22
|
+
created_at INTEGER NOT NULL,
|
|
23
|
+
CHECK (
|
|
24
|
+
(origin = 'trusted' AND principal_id IS NOT NULL AND length(trim(principal_id)) > 0
|
|
25
|
+
AND agent_id IS NOT NULL AND length(trim(agent_id)) > 0)
|
|
26
|
+
OR (origin = 'legacy_unattributed' AND principal_id IS NULL AND agent_id IS NULL)
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
CREATE TABLE IF NOT EXISTS registry_ref_assignments (
|
|
31
|
+
command_id TEXT NOT NULL REFERENCES registry_corrections(command_id) ON DELETE CASCADE,
|
|
32
|
+
edge_id TEXT NOT NULL,
|
|
33
|
+
endpoint TEXT NOT NULL CHECK (endpoint IN ('from', 'to')),
|
|
34
|
+
original_kind TEXT NOT NULL,
|
|
35
|
+
original_id TEXT NOT NULL,
|
|
36
|
+
resolved_node_id TEXT REFERENCES registry_nodes(id),
|
|
37
|
+
committed_revision INTEGER NOT NULL,
|
|
38
|
+
created_at INTEGER NOT NULL,
|
|
39
|
+
PRIMARY KEY (command_id, edge_id, endpoint)
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_registry_ref_assignments_current
|
|
42
|
+
ON registry_ref_assignments(edge_id, endpoint, committed_revision DESC);
|
|
43
|
+
|
|
44
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
45
|
+
VALUES (73, 'Atomic scoped registry correction history');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- Extend work-graph reference kinds without rewriting edge identity or provenance.
|
|
2
|
+
ALTER TABLE twin_edges RENAME TO twin_edges_legacy_074;
|
|
3
|
+
CREATE TABLE twin_edges (
|
|
4
|
+
edge_id TEXT PRIMARY KEY,
|
|
5
|
+
edge_type TEXT NOT NULL CHECK (edge_type IN ('supersedes','builds_on','debates','synthesizes','mentions','derived_from','case_member','alias_of','next_action_for','blocks')),
|
|
6
|
+
subject_kind TEXT NOT NULL CHECK (subject_kind IN ('memory','case','entity','report','edge','registry','observation')),
|
|
7
|
+
subject_id TEXT NOT NULL,
|
|
8
|
+
object_kind TEXT NOT NULL CHECK (object_kind IN ('memory','case','entity','report','edge','raw','registry','observation')),
|
|
9
|
+
object_id TEXT NOT NULL,
|
|
10
|
+
relation_attrs_json TEXT,
|
|
11
|
+
confidence REAL NOT NULL DEFAULT 1.0 CHECK (confidence >= 0.0 AND confidence <= 1.0),
|
|
12
|
+
source TEXT NOT NULL CHECK (source IN ('agent','human','code')),
|
|
13
|
+
agent_id TEXT,
|
|
14
|
+
model_run_id TEXT,
|
|
15
|
+
envelope_hash TEXT,
|
|
16
|
+
human_actor_id TEXT,
|
|
17
|
+
human_actor_role TEXT,
|
|
18
|
+
authority_scope_json TEXT,
|
|
19
|
+
reason_classification TEXT,
|
|
20
|
+
reason_text TEXT,
|
|
21
|
+
evidence_refs_json TEXT,
|
|
22
|
+
request_idempotency_key TEXT,
|
|
23
|
+
edge_idempotency_key TEXT,
|
|
24
|
+
content_hash BLOB NOT NULL CHECK(length(content_hash)=32),
|
|
25
|
+
created_at INTEGER NOT NULL
|
|
26
|
+
);
|
|
27
|
+
INSERT INTO twin_edges SELECT * FROM twin_edges_legacy_074;
|
|
28
|
+
DROP TABLE twin_edges_legacy_074;
|
|
29
|
+
CREATE INDEX idx_twin_edges_subject ON twin_edges(subject_kind, subject_id, created_at DESC);
|
|
30
|
+
CREATE INDEX idx_twin_edges_object ON twin_edges(object_kind, object_id, created_at DESC);
|
|
31
|
+
CREATE INDEX idx_twin_edges_model_run_id ON twin_edges(model_run_id, created_at DESC);
|
|
32
|
+
CREATE INDEX idx_twin_edges_request_idempotency
|
|
33
|
+
ON twin_edges(model_run_id, request_idempotency_key, created_at DESC)
|
|
34
|
+
WHERE model_run_id IS NOT NULL AND request_idempotency_key IS NOT NULL;
|
|
35
|
+
CREATE UNIQUE INDEX ux_twin_edges_model_run_edge_idempotency
|
|
36
|
+
ON twin_edges(model_run_id, edge_idempotency_key)
|
|
37
|
+
WHERE model_run_id IS NOT NULL AND edge_idempotency_key IS NOT NULL;
|
|
38
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
39
|
+
VALUES (74, 'Registry and observation work graph references');
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
-- Core-owned judgment and commitment command bindings.
|
|
2
|
+
-- Existing decisions, registry, observations, edges, and effect receipts remain authoritative.
|
|
3
|
+
|
|
4
|
+
ALTER TABLE decisions ADD COLUMN record_kind TEXT NOT NULL DEFAULT 'legacy'
|
|
5
|
+
CHECK (record_kind IN ('legacy', 'judgment', 'commitment'));
|
|
6
|
+
ALTER TABLE decisions ADD COLUMN payload_json TEXT NOT NULL DEFAULT '{}'
|
|
7
|
+
CHECK (json_valid(payload_json));
|
|
8
|
+
ALTER TABLE decisions ADD COLUMN applies_from INTEGER;
|
|
9
|
+
ALTER TABLE decisions ADD COLUMN applies_until INTEGER;
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS command_bindings (
|
|
12
|
+
command_id TEXT PRIMARY KEY,
|
|
13
|
+
principal_id TEXT NOT NULL CHECK (length(trim(principal_id)) > 0),
|
|
14
|
+
action TEXT NOT NULL CHECK (length(trim(action)) > 0),
|
|
15
|
+
payload_hash TEXT NOT NULL CHECK (length(trim(payload_hash)) > 0),
|
|
16
|
+
receipt_kind TEXT NOT NULL CHECK (receipt_kind IN ('judgment', 'observation', 'identity', 'effect')),
|
|
17
|
+
receipt_key TEXT NOT NULL CHECK (length(trim(receipt_key)) > 0),
|
|
18
|
+
created_at INTEGER NOT NULL CHECK (created_at >= 0)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS judgment_commands (
|
|
22
|
+
command_id TEXT PRIMARY KEY REFERENCES command_bindings(command_id) ON DELETE RESTRICT,
|
|
23
|
+
record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
|
|
24
|
+
committed_watermark INTEGER NOT NULL CHECK (committed_watermark >= 0),
|
|
25
|
+
receipt_json TEXT NOT NULL CHECK (json_valid(receipt_json)),
|
|
26
|
+
created_at INTEGER NOT NULL CHECK (created_at >= 0)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE TABLE IF NOT EXISTS commitments (
|
|
30
|
+
task_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
31
|
+
commitment_id TEXT NOT NULL UNIQUE,
|
|
32
|
+
current_revision INTEGER NOT NULL CHECK (current_revision >= 1),
|
|
33
|
+
head_record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
|
|
34
|
+
withdrawn INTEGER NOT NULL DEFAULT 0 CHECK (withdrawn IN (0, 1)),
|
|
35
|
+
created_at INTEGER NOT NULL CHECK (created_at >= 0),
|
|
36
|
+
updated_at INTEGER NOT NULL CHECK (updated_at >= 0)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE TABLE IF NOT EXISTS commitment_assignments (
|
|
40
|
+
commitment_id TEXT NOT NULL REFERENCES commitments(commitment_id) ON DELETE RESTRICT,
|
|
41
|
+
revision INTEGER NOT NULL CHECK (revision >= 1),
|
|
42
|
+
record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
|
|
43
|
+
operation TEXT NOT NULL CHECK (operation IN ('create', 'revise', 'withdraw')),
|
|
44
|
+
set_json TEXT NOT NULL CHECK (json_valid(set_json)),
|
|
45
|
+
clear_json TEXT NOT NULL CHECK (json_valid(clear_json)),
|
|
46
|
+
applies_from INTEGER,
|
|
47
|
+
applies_until INTEGER,
|
|
48
|
+
created_at INTEGER NOT NULL CHECK (created_at >= 0),
|
|
49
|
+
PRIMARY KEY (commitment_id, revision),
|
|
50
|
+
UNIQUE (commitment_id, record_id)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_judgment_commands_record ON judgment_commands(record_id, created_at DESC);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_commitments_head ON commitments(head_record_id);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_commitment_assignments_record ON commitment_assignments(record_id);
|
|
56
|
+
|
|
57
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
58
|
+
VALUES (75, 'Core-owned agent judgment and commitment commands');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Checkpoints are readable only when their explicit scope is bound. Legacy rows remain unscoped.
|
|
2
|
+
|
|
3
|
+
CREATE TABLE IF NOT EXISTS checkpoint_scope_bindings (
|
|
4
|
+
checkpoint_id INTEGER NOT NULL REFERENCES checkpoints(id) ON DELETE CASCADE,
|
|
5
|
+
scope_id TEXT NOT NULL REFERENCES memory_scopes(id) ON DELETE RESTRICT,
|
|
6
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
7
|
+
created_at INTEGER NOT NULL CHECK (created_at >= 0),
|
|
8
|
+
PRIMARY KEY (checkpoint_id, scope_id)
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
CREATE INDEX IF NOT EXISTS idx_checkpoint_scope_bindings_scope
|
|
12
|
+
ON checkpoint_scope_bindings(scope_id, checkpoint_id DESC);
|
|
13
|
+
|
|
14
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
15
|
+
VALUES (76, 'Scoped checkpoint bindings');
|