signetai 0.221.9 → 0.221.11

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/mcp-stdio.js CHANGED
@@ -25170,6 +25170,12 @@ function up(db) {
25170
25170
  CREATE INDEX IF NOT EXISTS idx_transcript_import_harness ON transcript_import_conversations(agent_id,harness);
25171
25171
  `);
25172
25172
  }
25173
+ function up2(db) {
25174
+ db.exec(`
25175
+ DROP INDEX IF EXISTS idx_memory_artifacts_agent_sha;
25176
+ CREATE INDEX idx_memory_artifacts_agent_sha ON memory_artifacts(agent_id, source_sha256, COALESCE(source_id, ''), COALESCE(is_deleted, 0), captured_at DESC, source_path)
25177
+ `);
25178
+ }
25173
25179
  function normalizeSql(sql) {
25174
25180
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
25175
25181
  }
@@ -25322,7 +25328,7 @@ function memoriesFtsNeedsTokenizerRepair(sql) {
25322
25328
  return true;
25323
25329
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
25324
25330
  }
25325
- function up2(db) {
25331
+ function up3(db) {
25326
25332
  db.exec(`
25327
25333
  CREATE TABLE IF NOT EXISTS schema_migrations (
25328
25334
  version INTEGER PRIMARY KEY,
@@ -25420,7 +25426,7 @@ function addColumnIfMissing(db, table, column, definition) {
25420
25426
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25421
25427
  }
25422
25428
  }
25423
- function up3(db) {
25429
+ function up4(db) {
25424
25430
  addColumnIfMissing(db, "memories", "content_hash", "TEXT");
25425
25431
  addColumnIfMissing(db, "memories", "normalized_content", "TEXT");
25426
25432
  addColumnIfMissing(db, "memories", "is_deleted", "INTEGER DEFAULT 0");
@@ -25538,7 +25544,7 @@ function addColumnIfMissing2(db, table, column, definition) {
25538
25544
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25539
25545
  return true;
25540
25546
  }
25541
- function up4(db) {
25547
+ function up5(db) {
25542
25548
  addColumnIfMissing2(db, "memories", "why", "TEXT");
25543
25549
  addColumnIfMissing2(db, "memories", "project", "TEXT");
25544
25550
  db.exec(`DROP INDEX IF EXISTS idx_memories_content_hash`);
@@ -25575,7 +25581,7 @@ function addColumnIfMissing3(db, table, column, definition) {
25575
25581
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25576
25582
  }
25577
25583
  }
25578
- function up5(db) {
25584
+ function up6(db) {
25579
25585
  addColumnIfMissing3(db, "memory_history", "actor_type", "TEXT");
25580
25586
  addColumnIfMissing3(db, "memory_history", "session_id", "TEXT");
25581
25587
  addColumnIfMissing3(db, "memory_history", "request_id", "TEXT");
@@ -25608,7 +25614,7 @@ function addColumnIfMissing4(db, table, column, definition) {
25608
25614
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25609
25615
  }
25610
25616
  }
25611
- function up6(db) {
25617
+ function up7(db) {
25612
25618
  addColumnIfMissing4(db, "entities", "canonical_name", "TEXT");
25613
25619
  addColumnIfMissing4(db, "entities", "mentions", "INTEGER DEFAULT 0");
25614
25620
  addColumnIfMissing4(db, "entities", "embedding", "BLOB");
@@ -25625,7 +25631,7 @@ function hasColumn4(db, table, column) {
25625
25631
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
25626
25632
  return rows.some((r2) => r2.name === column);
25627
25633
  }
25628
- function up7(db) {
25634
+ function up8(db) {
25629
25635
  if (!hasColumn4(db, "memories", "idempotency_key")) {
25630
25636
  db.exec("ALTER TABLE memories ADD COLUMN idempotency_key TEXT");
25631
25637
  }
@@ -25640,7 +25646,7 @@ function hasColumn5(db, table, column) {
25640
25646
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
25641
25647
  return rows.some((r2) => r2.name === column);
25642
25648
  }
25643
- function up8(db) {
25649
+ function up9(db) {
25644
25650
  db.exec(`
25645
25651
  CREATE TABLE IF NOT EXISTS documents (
25646
25652
  id TEXT PRIMARY KEY,
@@ -25697,7 +25703,7 @@ function up8(db) {
25697
25703
  db.exec("ALTER TABLE memory_jobs ADD COLUMN document_id TEXT");
25698
25704
  }
25699
25705
  }
25700
- function up9(db) {
25706
+ function up10(db) {
25701
25707
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='embeddings'").all();
25702
25708
  if (tables.length === 0)
25703
25709
  return;
@@ -25714,7 +25720,7 @@ function up9(db) {
25714
25720
  ON embeddings(content_hash)
25715
25721
  `);
25716
25722
  }
25717
- function up10(db) {
25723
+ function up11(db) {
25718
25724
  db.exec(`
25719
25725
  CREATE TABLE IF NOT EXISTS summary_jobs (
25720
25726
  id TEXT PRIMARY KEY,
@@ -25734,7 +25740,7 @@ function up10(db) {
25734
25740
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
25735
25741
  ON summary_jobs(status)`);
25736
25742
  }
25737
- function up11(db) {
25743
+ function up12(db) {
25738
25744
  db.exec(`
25739
25745
  CREATE TABLE IF NOT EXISTS umap_cache (
25740
25746
  id INTEGER PRIMARY KEY,
@@ -25745,7 +25751,7 @@ function up11(db) {
25745
25751
  )
25746
25752
  `);
25747
25753
  }
25748
- function up12(db) {
25754
+ function up13(db) {
25749
25755
  db.exec(`
25750
25756
  CREATE TABLE IF NOT EXISTS session_scores (
25751
25757
  id TEXT PRIMARY KEY,
@@ -25765,7 +25771,7 @@ function up12(db) {
25765
25771
  ON session_scores(session_key);
25766
25772
  `);
25767
25773
  }
25768
- function up13(db) {
25774
+ function up14(db) {
25769
25775
  db.exec(`
25770
25776
  CREATE TABLE IF NOT EXISTS scheduled_tasks (
25771
25777
  id TEXT PRIMARY KEY,
@@ -25806,7 +25812,7 @@ function addColumnIfMissing5(db, table, column, definition) {
25806
25812
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25807
25813
  }
25808
25814
  }
25809
- function up14(db) {
25815
+ function up15(db) {
25810
25816
  db.exec(`
25811
25817
  CREATE TABLE IF NOT EXISTS ingestion_jobs (
25812
25818
  id TEXT PRIMARY KEY,
@@ -25832,7 +25838,7 @@ function up14(db) {
25832
25838
  addColumnIfMissing5(db, "memories", "source_path", "TEXT");
25833
25839
  addColumnIfMissing5(db, "memories", "source_section", "TEXT");
25834
25840
  }
25835
- function up15(db) {
25841
+ function up16(db) {
25836
25842
  db.exec(`
25837
25843
  CREATE TABLE IF NOT EXISTS telemetry_events (
25838
25844
  id TEXT PRIMARY KEY,
@@ -25857,7 +25863,7 @@ function addColumnIfMissing6(db, table, column, definition) {
25857
25863
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
25858
25864
  }
25859
25865
  }
25860
- function up16(db) {
25866
+ function up17(db) {
25861
25867
  db.exec(`
25862
25868
  CREATE TABLE IF NOT EXISTS session_memories (
25863
25869
  id TEXT PRIMARY KEY,
@@ -25884,7 +25890,7 @@ function up16(db) {
25884
25890
  addColumnIfMissing6(db, "session_scores", "confidence", "REAL");
25885
25891
  addColumnIfMissing6(db, "session_scores", "continuity_reasoning", "TEXT");
25886
25892
  }
25887
- function up17(db) {
25893
+ function up18(db) {
25888
25894
  db.exec(`
25889
25895
  CREATE TABLE IF NOT EXISTS session_checkpoints (
25890
25896
  id TEXT PRIMARY KEY,
@@ -25906,7 +25912,7 @@ function up17(db) {
25906
25912
  ON session_checkpoints(project_normalized, created_at DESC);
25907
25913
  `);
25908
25914
  }
25909
- function up18(db) {
25915
+ function up19(db) {
25910
25916
  const cols = db.prepare("PRAGMA table_info(scheduled_tasks)").all();
25911
25917
  const colNames = new Set(cols.flatMap((c2) => typeof c2.name === "string" ? [c2.name] : []));
25912
25918
  if (!colNames.has("skill_name")) {
@@ -25917,7 +25923,7 @@ function up18(db) {
25917
25923
  CHECK (skill_mode IN ('inject', 'slash') OR skill_mode IS NULL)`);
25918
25924
  }
25919
25925
  }
25920
- function up19(db) {
25926
+ function up20(db) {
25921
25927
  const existing = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='skill_meta'").get();
25922
25928
  if (existing)
25923
25929
  return;
@@ -25949,7 +25955,7 @@ function up19(db) {
25949
25955
  CREATE INDEX idx_skill_meta_source ON skill_meta(source);
25950
25956
  `);
25951
25957
  }
25952
- function up20(db) {
25958
+ function up21(db) {
25953
25959
  const entityCols = db.prepare("PRAGMA table_info(entities)").all();
25954
25960
  const entityColNames = new Set(entityCols.flatMap((c2) => typeof c2.name === "string" ? [c2.name] : []));
25955
25961
  if (!entityColNames.has("agent_id")) {
@@ -26034,13 +26040,13 @@ function addColumnIfMissing7(db, table, column, definition) {
26034
26040
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26035
26041
  }
26036
26042
  }
26037
- function up21(db) {
26043
+ function up22(db) {
26038
26044
  addColumnIfMissing7(db, "session_memories", "entity_slot", "INTEGER");
26039
26045
  addColumnIfMissing7(db, "session_memories", "aspect_slot", "INTEGER");
26040
26046
  addColumnIfMissing7(db, "session_memories", "is_constraint", "INTEGER NOT NULL DEFAULT 0");
26041
26047
  addColumnIfMissing7(db, "session_memories", "structural_density", "INTEGER");
26042
26048
  }
26043
- function up22(db) {
26049
+ function up23(db) {
26044
26050
  const columns = db.prepare("PRAGMA table_info(session_checkpoints)").all();
26045
26051
  const columnNames = new Set(columns.flatMap((column) => typeof column.name === "string" ? [column.name] : []));
26046
26052
  if (!columnNames.has("focal_entity_ids")) {
@@ -26065,25 +26071,25 @@ function addColumnIfMissing8(db, table, column, definition) {
26065
26071
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26066
26072
  }
26067
26073
  }
26068
- function up23(db) {
26074
+ function up24(db) {
26069
26075
  addColumnIfMissing8(db, "entities", "pinned", "INTEGER NOT NULL DEFAULT 0");
26070
26076
  addColumnIfMissing8(db, "entities", "pinned_at", "TEXT");
26071
26077
  db.exec("CREATE INDEX IF NOT EXISTS idx_entities_pinned ON entities(agent_id, pinned, pinned_at DESC)");
26072
26078
  }
26073
- function up24(_db) {}
26074
26079
  function up25(_db) {}
26080
+ function up26(_db) {}
26075
26081
  function addColumnIfMissing9(db, table, column, definition) {
26076
26082
  const cols = db.prepare(`PRAGMA table_info(${table})`).all();
26077
26083
  if (!cols.some((c2) => c2.name === column)) {
26078
26084
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26079
26085
  }
26080
26086
  }
26081
- function up26(db) {
26087
+ function up27(db) {
26082
26088
  addColumnIfMissing9(db, "session_memories", "agent_relevance_score", "REAL");
26083
26089
  addColumnIfMissing9(db, "session_memories", "agent_feedback_count", "INTEGER DEFAULT 0");
26084
26090
  }
26085
- function up27(_db) {}
26086
- function up28(db) {
26091
+ function up28(_db) {}
26092
+ function up29(db) {
26087
26093
  db.exec(`
26088
26094
  UPDATE entities
26089
26095
  SET canonical_name = REPLACE(REPLACE(REPLACE(
@@ -26092,7 +26098,7 @@ function up28(db) {
26092
26098
  WHERE canonical_name IS NULL
26093
26099
  `);
26094
26100
  }
26095
- function up29(db) {
26101
+ function up30(db) {
26096
26102
  db.exec(`
26097
26103
  CREATE TABLE IF NOT EXISTS memories_cold (
26098
26104
  archive_id TEXT PRIMARY KEY,
@@ -26129,7 +26135,7 @@ function up29(db) {
26129
26135
  CREATE INDEX IF NOT EXISTS idx_cold_source ON memories_cold(cold_source_id);
26130
26136
  `);
26131
26137
  }
26132
- function up30(db) {
26138
+ function up31(db) {
26133
26139
  db.exec(`
26134
26140
  CREATE TABLE IF NOT EXISTS session_summaries (
26135
26141
  id TEXT PRIMARY KEY,
@@ -26174,7 +26180,7 @@ function up30(db) {
26174
26180
  WHERE session_key IS NOT NULL;
26175
26181
  `);
26176
26182
  }
26177
- function up31(db) {
26183
+ function up32(db) {
26178
26184
  db.exec(`
26179
26185
  CREATE TABLE IF NOT EXISTS memory_jobs_new (
26180
26186
  id TEXT PRIMARY KEY,
@@ -26219,7 +26225,7 @@ function up31(db) {
26219
26225
  ON memory_jobs(failed_at);
26220
26226
  `);
26221
26227
  }
26222
- function up32(db) {
26228
+ function up33(db) {
26223
26229
  const depCols = db.prepare("PRAGMA table_info(entity_dependencies)").all();
26224
26230
  if (!depCols.some((c2) => c2.name === "reason")) {
26225
26231
  db.exec("ALTER TABLE entity_dependencies ADD COLUMN reason TEXT");
@@ -26229,7 +26235,7 @@ function up32(db) {
26229
26235
  db.exec("ALTER TABLE entities ADD COLUMN last_synthesized_at TEXT");
26230
26236
  }
26231
26237
  }
26232
- function up33(db) {
26238
+ function up34(db) {
26233
26239
  const cols = db.prepare("PRAGMA table_info(embeddings)").all();
26234
26240
  if (cols.length === 0)
26235
26241
  return;
@@ -26237,14 +26243,14 @@ function up33(db) {
26237
26243
  db.exec("ALTER TABLE embeddings ADD COLUMN vector BLOB");
26238
26244
  }
26239
26245
  }
26240
- function up34(db) {
26246
+ function up35(db) {
26241
26247
  const cols = db.prepare("PRAGMA table_info(memories)").all();
26242
26248
  if (!cols.some((c2) => c2.name === "scope")) {
26243
26249
  db.exec("ALTER TABLE memories ADD COLUMN scope TEXT DEFAULT NULL");
26244
26250
  }
26245
26251
  db.exec("CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope) WHERE scope IS NOT NULL");
26246
26252
  }
26247
- function up35(db) {
26253
+ function up36(db) {
26248
26254
  db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
26249
26255
  db.exec(`
26250
26256
  CREATE UNIQUE INDEX idx_memories_content_hash_unique
@@ -26252,7 +26258,7 @@ function up35(db) {
26252
26258
  WHERE content_hash IS NOT NULL AND is_deleted = 0
26253
26259
  `);
26254
26260
  }
26255
- function up36(db) {
26261
+ function up37(db) {
26256
26262
  db.exec(`
26257
26263
  CREATE VIRTUAL TABLE IF NOT EXISTS entities_fts USING fts5(
26258
26264
  name, canonical_name,
@@ -26284,13 +26290,13 @@ function up36(db) {
26284
26290
  END
26285
26291
  `);
26286
26292
  }
26287
- function up37(db) {
26293
+ function up38(db) {
26288
26294
  const cols = db.prepare("PRAGMA table_info(entity_dependencies)").all();
26289
26295
  if (!cols.some((c2) => c2.name === "confidence")) {
26290
26296
  db.exec("ALTER TABLE entity_dependencies ADD COLUMN confidence REAL DEFAULT 0.7");
26291
26297
  }
26292
26298
  }
26293
- function up38(db) {
26299
+ function up39(db) {
26294
26300
  db.exec(`
26295
26301
  CREATE TABLE IF NOT EXISTS entity_communities (
26296
26302
  id TEXT PRIMARY KEY,
@@ -26308,7 +26314,7 @@ function up38(db) {
26308
26314
  db.exec("ALTER TABLE entities ADD COLUMN community_id TEXT REFERENCES entity_communities(id)");
26309
26315
  }
26310
26316
  }
26311
- function up39(db) {
26317
+ function up40(db) {
26312
26318
  db.exec(`
26313
26319
  CREATE TABLE IF NOT EXISTS memory_hints (
26314
26320
  id TEXT PRIMARY KEY,
@@ -26348,7 +26354,7 @@ function up39(db) {
26348
26354
  END
26349
26355
  `);
26350
26356
  }
26351
- function up40(db) {
26357
+ function up41(db) {
26352
26358
  db.exec(`
26353
26359
  DELETE FROM entity_dependencies
26354
26360
  WHERE id NOT IN (
@@ -26366,7 +26372,7 @@ function up40(db) {
26366
26372
  )
26367
26373
  `);
26368
26374
  }
26369
- function up41(db) {
26375
+ function up42(db) {
26370
26376
  db.exec(`
26371
26377
  CREATE TABLE IF NOT EXISTS session_transcripts (
26372
26378
  session_key TEXT PRIMARY KEY,
@@ -26389,7 +26395,7 @@ function addColumnIfMissing10(db, table, column, definition) {
26389
26395
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26390
26396
  }
26391
26397
  }
26392
- function up42(db) {
26398
+ function up43(db) {
26393
26399
  addColumnIfMissing10(db, "session_memories", "path_json", "TEXT");
26394
26400
  db.exec(`
26395
26401
  CREATE TABLE IF NOT EXISTS path_feedback_events (
@@ -26464,7 +26470,7 @@ function addColumnIfMissing11(db, table, column, definition) {
26464
26470
  return;
26465
26471
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26466
26472
  }
26467
- function up43(db) {
26473
+ function up44(db) {
26468
26474
  addColumnIfMissing11(db, "session_memories", "entity_slot", "INTEGER");
26469
26475
  addColumnIfMissing11(db, "session_memories", "aspect_slot", "INTEGER");
26470
26476
  addColumnIfMissing11(db, "session_memories", "is_constraint", "INTEGER NOT NULL DEFAULT 0");
@@ -26552,7 +26558,7 @@ function addColumnIfMissing12(db, table, column, definition) {
26552
26558
  return;
26553
26559
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26554
26560
  }
26555
- function up44(db) {
26561
+ function up45(db) {
26556
26562
  db.exec(`
26557
26563
  CREATE TABLE IF NOT EXISTS agents (
26558
26564
  id TEXT PRIMARY KEY,
@@ -26581,7 +26587,7 @@ function addColumnIfMissing13(db, table, column, definition) {
26581
26587
  return;
26582
26588
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26583
26589
  }
26584
- function up45(db) {
26590
+ function up46(db) {
26585
26591
  addColumnIfMissing13(db, "session_summaries", "source_type", "TEXT");
26586
26592
  addColumnIfMissing13(db, "session_summaries", "source_ref", "TEXT");
26587
26593
  addColumnIfMissing13(db, "session_summaries", "meta_json", "TEXT");
@@ -26607,7 +26613,7 @@ function addColumnIfMissing14(db, table, column, definition) {
26607
26613
  return;
26608
26614
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
26609
26615
  }
26610
- function up46(db) {
26616
+ function up47(db) {
26611
26617
  addColumnIfMissing14(db, "session_transcripts", "updated_at", "TEXT");
26612
26618
  addColumnIfMissing14(db, "summary_jobs", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
26613
26619
  addColumnIfMissing14(db, "session_scores", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
@@ -26678,7 +26684,7 @@ function up46(db) {
26678
26684
  ON memory_md_heads(lease_expires_at);
26679
26685
  `);
26680
26686
  }
26681
- function up47(db) {
26687
+ function up48(db) {
26682
26688
  db.exec(`
26683
26689
  DROP INDEX IF EXISTS idx_summaries_session_depth;
26684
26690
 
@@ -26739,7 +26745,7 @@ function up47(db) {
26739
26745
  AND COALESCE(source_type, 'summary') = 'summary';
26740
26746
  `);
26741
26747
  }
26742
- function up48(db) {
26748
+ function up49(db) {
26743
26749
  db.exec(`
26744
26750
  DROP TRIGGER IF EXISTS session_transcripts_fts_ai;
26745
26751
  DROP TRIGGER IF EXISTS session_transcripts_fts_ad;
@@ -26837,7 +26843,7 @@ function up48(db) {
26837
26843
  AND COALESCE(source_type, 'summary') = 'summary';
26838
26844
  `);
26839
26845
  }
26840
- function up49(db) {
26846
+ function up50(db) {
26841
26847
  db.exec(`
26842
26848
  CREATE TABLE IF NOT EXISTS memory_thread_heads (
26843
26849
  agent_id TEXT NOT NULL DEFAULT 'default',
@@ -26955,7 +26961,7 @@ function up49(db) {
26955
26961
  WHERE excluded.latest_at >= memory_thread_heads.latest_at;
26956
26962
  `);
26957
26963
  }
26958
- function up50(db) {
26964
+ function up51(db) {
26959
26965
  db.exec(`
26960
26966
  CREATE TABLE IF NOT EXISTS session_extract_cursors (
26961
26967
  session_key TEXT NOT NULL,
@@ -26972,7 +26978,7 @@ function hasTable(db, name) {
26972
26978
  WHERE type = 'table' AND name = ?
26973
26979
  LIMIT 1`).get(name) !== undefined;
26974
26980
  }
26975
- function up51(db) {
26981
+ function up52(db) {
26976
26982
  db.exec(`
26977
26983
  CREATE TABLE IF NOT EXISTS entity_dependency_history (
26978
26984
  id TEXT PRIMARY KEY,
@@ -27142,7 +27148,7 @@ function addColumnIfMissing15(db, table, column, definition) {
27142
27148
  return;
27143
27149
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
27144
27150
  }
27145
- function up52(db) {
27151
+ function up53(db) {
27146
27152
  addColumnIfMissing15(db, "summary_jobs", "session_id", "TEXT");
27147
27153
  addColumnIfMissing15(db, "summary_jobs", "trigger", "TEXT NOT NULL DEFAULT 'session_end'");
27148
27154
  addColumnIfMissing15(db, "summary_jobs", "captured_at", "TEXT");
@@ -27234,7 +27240,7 @@ function up52(db) {
27234
27240
  VALUES ('rebuild');
27235
27241
  `);
27236
27242
  }
27237
- function up53(db) {
27243
+ function up54(db) {
27238
27244
  db.exec(`
27239
27245
  CREATE TABLE IF NOT EXISTS mcp_invocations (
27240
27246
  id TEXT PRIMARY KEY,
@@ -27251,7 +27257,7 @@ function up53(db) {
27251
27257
  CREATE INDEX IF NOT EXISTS idx_mcp_inv_agent ON mcp_invocations(agent_id, created_at);
27252
27258
  `);
27253
27259
  }
27254
- function up54(db) {
27260
+ function up55(db) {
27255
27261
  db.exec(`
27256
27262
  CREATE TABLE IF NOT EXISTS skill_invocations (
27257
27263
  id TEXT PRIMARY KEY,
@@ -27267,7 +27273,7 @@ function up54(db) {
27267
27273
  CREATE INDEX IF NOT EXISTS idx_skill_inv_agent ON skill_invocations(agent_id, created_at);
27268
27274
  `);
27269
27275
  }
27270
- function up55(db) {
27276
+ function up56(db) {
27271
27277
  db.exec(`
27272
27278
  CREATE TABLE IF NOT EXISTS task_scope_hints (
27273
27279
  task_id TEXT PRIMARY KEY REFERENCES scheduled_tasks(id) ON DELETE CASCADE,
@@ -27298,7 +27304,7 @@ function up55(db) {
27298
27304
  ON task_scope_hints(agent_id, updated_at);
27299
27305
  `);
27300
27306
  }
27301
- function up56(db) {
27307
+ function up57(db) {
27302
27308
  db.exec(`
27303
27309
  CREATE TABLE IF NOT EXISTS dreaming_state (
27304
27310
  agent_id TEXT PRIMARY KEY NOT NULL,
@@ -27341,7 +27347,7 @@ function ensureMemoriesScopeColumns(db) {
27341
27347
  if (!names.has("scope"))
27342
27348
  db.exec("ALTER TABLE memories ADD COLUMN scope TEXT");
27343
27349
  }
27344
- function up57(db) {
27350
+ function up58(db) {
27345
27351
  ensureMemoriesScopeColumns(db);
27346
27352
  db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
27347
27353
  db.exec(`
@@ -27354,20 +27360,20 @@ function up57(db) {
27354
27360
  WHERE content_hash IS NOT NULL AND is_deleted = 0
27355
27361
  `);
27356
27362
  }
27357
- function up58(db) {
27363
+ function up59(db) {
27358
27364
  const sql = readMemoriesFtsSql(db);
27359
27365
  if (sql !== null && !memoriesFtsNeedsTokenizerRepair(sql))
27360
27366
  return;
27361
27367
  recreateMemoriesFts(db);
27362
27368
  }
27363
- function up59(db) {
27369
+ function up60(db) {
27364
27370
  db.exec(`CREATE INDEX IF NOT EXISTS idx_entities_order
27365
27371
  ON entities(agent_id, pinned DESC, pinned_at DESC, mentions DESC, updated_at DESC, name)`);
27366
27372
  db.exec(`CREATE INDEX IF NOT EXISTS idx_entities_extracted_mentions
27367
27373
  ON entities(entity_type, mentions)
27368
27374
  WHERE entity_type = 'extracted'`);
27369
27375
  }
27370
- function up60(db) {
27376
+ function up61(db) {
27371
27377
  const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
27372
27378
  if (!cols.some((col) => col.name === "claim_key")) {
27373
27379
  db.exec("ALTER TABLE entity_attributes ADD COLUMN claim_key TEXT");
@@ -27376,7 +27382,7 @@ function up60(db) {
27376
27382
  ON entity_attributes(agent_id, aspect_id, claim_key, status)
27377
27383
  WHERE claim_key IS NOT NULL`);
27378
27384
  }
27379
- function up61(db) {
27385
+ function up62(db) {
27380
27386
  const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
27381
27387
  if (!cols.some((col) => col.name === "group_key")) {
27382
27388
  db.exec("ALTER TABLE entity_attributes ADD COLUMN group_key TEXT");
@@ -27388,13 +27394,13 @@ function up61(db) {
27388
27394
  ON entity_attributes(agent_id, aspect_id, group_key, claim_key, status)
27389
27395
  WHERE claim_key IS NOT NULL`);
27390
27396
  }
27391
- function up62(db) {
27397
+ function up63(db) {
27392
27398
  const cols = db.prepare("PRAGMA table_info(memory_artifacts)").all();
27393
27399
  if (cols.some((col) => col.name === "source_mtime_ms"))
27394
27400
  return;
27395
27401
  db.exec("ALTER TABLE memory_artifacts ADD COLUMN source_mtime_ms REAL");
27396
27402
  }
27397
- function up63(db) {
27403
+ function up64(db) {
27398
27404
  const cols = db.prepare("PRAGMA table_info(memory_artifacts)").all();
27399
27405
  const names = new Set(cols.map((col) => col.name));
27400
27406
  if (!names.has("is_deleted")) {
@@ -27408,7 +27414,7 @@ function up63(db) {
27408
27414
  ON memory_artifacts(agent_id, is_deleted, deleted_at)
27409
27415
  `);
27410
27416
  }
27411
- function up64(db) {
27417
+ function up65(db) {
27412
27418
  db.exec("DROP TRIGGER IF EXISTS memories_au");
27413
27419
  db.exec(`
27414
27420
  CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE OF content ON memories BEGIN
@@ -27426,7 +27432,7 @@ function addColumnIfMissing16(db, table, column, definition) {
27426
27432
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
27427
27433
  }
27428
27434
  }
27429
- function up65(db) {
27435
+ function up66(db) {
27430
27436
  for (const table of ["entities", "entity_communities", "entity_attributes", "entity_dependencies"]) {
27431
27437
  addColumnIfMissing16(db, table, "source_id", "TEXT");
27432
27438
  addColumnIfMissing16(db, table, "source_kind", "TEXT");
@@ -27446,7 +27452,7 @@ function hasColumn7(db, table, column) {
27446
27452
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
27447
27453
  return rows.some((row) => row.name === column);
27448
27454
  }
27449
- function up66(db) {
27455
+ function up67(db) {
27450
27456
  if (!hasTable2(db, "embeddings"))
27451
27457
  return;
27452
27458
  if (!hasColumn7(db, "embeddings", "agent_id")) {
@@ -27454,7 +27460,7 @@ function up66(db) {
27454
27460
  }
27455
27461
  db.exec("CREATE INDEX IF NOT EXISTS idx_embeddings_agent_source ON embeddings(agent_id, source_type, source_id)");
27456
27462
  }
27457
- function up67(db) {
27463
+ function up68(db) {
27458
27464
  db.exec(`
27459
27465
  CREATE TABLE IF NOT EXISTS memory_search_telemetry (
27460
27466
  id TEXT PRIMARY KEY,
@@ -27495,7 +27501,7 @@ function addColumnIfMissing17(db, table, column, definition) {
27495
27501
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
27496
27502
  }
27497
27503
  }
27498
- function up68(db) {
27504
+ function up69(db) {
27499
27505
  db.exec(`
27500
27506
  CREATE TABLE IF NOT EXISTS ontology_proposals (
27501
27507
  id TEXT PRIMARY KEY,
@@ -27538,7 +27544,7 @@ function up68(db) {
27538
27544
  db.exec(`CREATE INDEX IF NOT EXISTS idx_${table}_proposal ON ${table}(agent_id, proposal_id)`);
27539
27545
  }
27540
27546
  }
27541
- function up69(db) {
27547
+ function up70(db) {
27542
27548
  db.exec(`
27543
27549
  CREATE TABLE IF NOT EXISTS daily_reflections (
27544
27550
  id TEXT PRIMARY KEY,
@@ -27565,7 +27571,7 @@ function up69(db) {
27565
27571
  WHERE content_key IS NOT NULL;
27566
27572
  `);
27567
27573
  }
27568
- function up70(db) {
27574
+ function up71(db) {
27569
27575
  const cols = db.prepare("PRAGMA table_info(daily_reflections)").all();
27570
27576
  const colNames = new Set(cols.flatMap((c2) => typeof c2.name === "string" ? [c2.name] : []));
27571
27577
  if (!colNames.has("content_key")) {
@@ -27602,7 +27608,7 @@ function backfillVersionRoots(db) {
27602
27608
  WHERE version_root_id IS NULL
27603
27609
  `);
27604
27610
  }
27605
- function up71(db) {
27611
+ function up72(db) {
27606
27612
  for (const table of ["entities", "entity_aspects", "entity_dependencies"]) {
27607
27613
  addColumnIfMissing18(db, table, "status", "TEXT NOT NULL DEFAULT 'active'");
27608
27614
  addColumnIfMissing18(db, table, "archived_at", "TEXT");
@@ -27637,7 +27643,7 @@ function up71(db) {
27637
27643
  ON entity_aspects(agent_id, proposal_id);
27638
27644
  `);
27639
27645
  }
27640
- function up72(db) {
27646
+ function up73(db) {
27641
27647
  db.exec(`
27642
27648
  CREATE TABLE IF NOT EXISTS epistemic_assertions (
27643
27649
  id TEXT PRIMARY KEY,
@@ -27693,7 +27699,7 @@ function ensureMemoriesScopeColumns2(db) {
27693
27699
  if (!names.has("runtime_path"))
27694
27700
  db.exec("ALTER TABLE memories ADD COLUMN runtime_path TEXT");
27695
27701
  }
27696
- function up73(db) {
27702
+ function up74(db) {
27697
27703
  ensureMemoriesScopeColumns2(db);
27698
27704
  db.exec("DROP INDEX IF EXISTS idx_memories_idempotency_key");
27699
27705
  db.exec(`
@@ -27707,7 +27713,7 @@ function up73(db) {
27707
27713
  WHERE idempotency_key IS NOT NULL AND is_deleted = 0
27708
27714
  `);
27709
27715
  }
27710
- function up74(db) {
27716
+ function up75(db) {
27711
27717
  db.exec(`
27712
27718
  CREATE TABLE IF NOT EXISTS session_context_epochs (
27713
27719
  session_key TEXT NOT NULL,
@@ -27742,7 +27748,7 @@ function up74(db) {
27742
27748
  ON session_recall_events(item_kind, item_id, created_at DESC);
27743
27749
  `);
27744
27750
  }
27745
- function up75(db) {
27751
+ function up76(db) {
27746
27752
  db.exec(`
27747
27753
  CREATE TABLE IF NOT EXISTS aggregate_memory_sources (
27748
27754
  aggregate_memory_id TEXT NOT NULL,
@@ -27761,7 +27767,7 @@ function addColumnIfMissing19(db, table, column, definition) {
27761
27767
  return;
27762
27768
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
27763
27769
  }
27764
- function up76(db) {
27770
+ function up77(db) {
27765
27771
  addColumnIfMissing19(db, "memory_artifacts", "source_id", "TEXT");
27766
27772
  addColumnIfMissing19(db, "memory_artifacts", "source_root", "TEXT");
27767
27773
  addColumnIfMissing19(db, "memory_artifacts", "source_external_id", "TEXT");
@@ -27774,7 +27780,7 @@ function up76(db) {
27774
27780
  ON memory_artifacts(agent_id, source_id, source_root);
27775
27781
  `);
27776
27782
  }
27777
- function up77(db) {
27783
+ function up78(db) {
27778
27784
  db.exec(`
27779
27785
  CREATE TABLE IF NOT EXISTS temporal_edges (
27780
27786
  id TEXT PRIMARY KEY,
@@ -27797,7 +27803,7 @@ function up77(db) {
27797
27803
  ON temporal_edges(agent_id, subject_type, subject_id);
27798
27804
  `);
27799
27805
  }
27800
- function up78(db) {
27806
+ function up79(db) {
27801
27807
  db.exec(`
27802
27808
  CREATE TABLE IF NOT EXISTS entity_aliases (
27803
27809
  id TEXT PRIMARY KEY,
@@ -27821,7 +27827,7 @@ function up78(db) {
27821
27827
  ON entity_aliases(agent_id, canonical_alias, status);
27822
27828
  `);
27823
27829
  }
27824
- function up79(db) {
27830
+ function up80(db) {
27825
27831
  db.exec(`
27826
27832
  CREATE TABLE IF NOT EXISTS api_keys (
27827
27833
  id TEXT PRIMARY KEY,
@@ -27849,7 +27855,7 @@ function up79(db) {
27849
27855
  ON api_keys(connector, harness);
27850
27856
  `);
27851
27857
  }
27852
- function up80(db) {
27858
+ function up81(db) {
27853
27859
  db.exec(`
27854
27860
  CREATE TABLE IF NOT EXISTS transcript_capture_jobs (
27855
27861
  id TEXT PRIMARY KEY,
@@ -27884,7 +27890,7 @@ function hasColumn10(db, table, column) {
27884
27890
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
27885
27891
  return rows.some((row) => row.name === column);
27886
27892
  }
27887
- function up81(db) {
27893
+ function up82(db) {
27888
27894
  if (!hasColumn10(db, "documents", "agent_id")) {
27889
27895
  db.exec("ALTER TABLE documents ADD COLUMN agent_id TEXT NOT NULL DEFAULT 'default'");
27890
27896
  }
@@ -27970,7 +27976,7 @@ function up81(db) {
27970
27976
  db.exec("CREATE INDEX IF NOT EXISTS idx_documents_agent_project ON documents(agent_id, project)");
27971
27977
  db.exec("CREATE INDEX IF NOT EXISTS idx_documents_source_scope ON documents(source_url, agent_id, project)");
27972
27978
  }
27973
- function up82(db) {
27979
+ function up83(db) {
27974
27980
  db.exec(`
27975
27981
  CREATE TABLE IF NOT EXISTS aggregate_evidence_sources (
27976
27982
  aggregate_memory_id TEXT NOT NULL,
@@ -27991,7 +27997,7 @@ function hasColumn11(db, table, column) {
27991
27997
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
27992
27998
  return rows.some((row) => row.name === column);
27993
27999
  }
27994
- function up83(db) {
28000
+ function up84(db) {
27995
28001
  for (const column of COLUMNS) {
27996
28002
  if (!hasColumn11(db, "skill_invocations", column)) {
27997
28003
  db.exec(`ALTER TABLE skill_invocations ADD COLUMN ${column} TEXT`);
@@ -28038,7 +28044,7 @@ function documentScopeColumnsPreservingExisting(db) {
28038
28044
  `);
28039
28045
  }
28040
28046
  try {
28041
- up81(db);
28047
+ up82(db);
28042
28048
  if (preserveAgentId) {
28043
28049
  db.exec(`
28044
28050
  UPDATE documents
@@ -28058,12 +28064,12 @@ function documentScopeColumnsPreservingExisting(db) {
28058
28064
  db.exec("DROP TABLE IF EXISTS temp.__signet_doc_project_guard");
28059
28065
  }
28060
28066
  }
28061
- function up84(db) {
28062
- up80(db);
28067
+ function up85(db) {
28068
+ up81(db);
28063
28069
  if (hasTable3(db, "documents")) {
28064
28070
  documentScopeColumnsPreservingExisting(db);
28065
28071
  }
28066
- up82(db);
28072
+ up83(db);
28067
28073
  addColumnIfMissing20(db, "memories", "superseded_by", "TEXT");
28068
28074
  addColumnIfMissing20(db, "memories", "superseded_at", "TEXT");
28069
28075
  addColumnIfMissing20(db, "memories", "superseded_reason", "TEXT");
@@ -28120,7 +28126,7 @@ function up84(db) {
28120
28126
  AND ${sourceAgentId} = ${targetAgentId}
28121
28127
  `);
28122
28128
  }
28123
- function up85(db) {
28129
+ function up86(db) {
28124
28130
  db.exec(`
28125
28131
  CREATE TABLE IF NOT EXISTS legacy_markdown_imports (
28126
28132
  path TEXT PRIMARY KEY,
@@ -28150,7 +28156,7 @@ function up85(db) {
28150
28156
  ON legacy_markdown_chunks(memory_id);
28151
28157
  `);
28152
28158
  }
28153
- function up86(db) {
28159
+ function up87(db) {
28154
28160
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name IN ('relations', 'entity_dependencies')").all();
28155
28161
  const tableNames = new Set(tables.map((r2) => String(r2.name)));
28156
28162
  if (!tableNames.has("relations") || !tableNames.has("entity_dependencies"))
@@ -28209,7 +28215,7 @@ function addColumnIfMissing21(db, table, column, definition) {
28209
28215
  return;
28210
28216
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
28211
28217
  }
28212
- function up87(db) {
28218
+ function up88(db) {
28213
28219
  addColumnIfMissing21(db, "summary_jobs", "content_hash", "TEXT");
28214
28220
  db.exec(`
28215
28221
  CREATE INDEX IF NOT EXISTS idx_summary_jobs_agent_session_content_hash
@@ -28222,14 +28228,14 @@ function addColumnIfMissing22(db, table, column, definition) {
28222
28228
  return;
28223
28229
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
28224
28230
  }
28225
- function up88(db) {
28231
+ function up89(db) {
28226
28232
  addColumnIfMissing22(db, "summary_jobs", "boundary_reason", "TEXT");
28227
28233
  db.exec(`
28228
28234
  CREATE INDEX IF NOT EXISTS idx_summary_jobs_boundary_reason
28229
28235
  ON summary_jobs(agent_id, session_key, boundary_reason)
28230
28236
  `);
28231
28237
  }
28232
- function up89(db) {
28238
+ function up90(db) {
28233
28239
  db.exec(`
28234
28240
  CREATE TABLE IF NOT EXISTS transcript_recovery_files (
28235
28241
  agent_id TEXT NOT NULL,
@@ -28247,7 +28253,7 @@ function up89(db) {
28247
28253
  ON transcript_capture_jobs(agent_id, session_id, status);
28248
28254
  `);
28249
28255
  }
28250
- function up90(db) {
28256
+ function up91(db) {
28251
28257
  db.exec(`
28252
28258
  CREATE TABLE IF NOT EXISTS job_cancellations (
28253
28259
  id TEXT PRIMARY KEY,
@@ -28275,7 +28281,7 @@ function indexExists(db, table, indexName) {
28275
28281
  const rows = db.prepare(`PRAGMA index_list(${table})`).all();
28276
28282
  return rows.some((row) => row.name === indexName);
28277
28283
  }
28278
- function up91(db) {
28284
+ function up92(db) {
28279
28285
  db.exec(`
28280
28286
  CREATE TABLE IF NOT EXISTS job_archive (
28281
28287
  id TEXT PRIMARY KEY,
@@ -28302,7 +28308,7 @@ function indexExists2(db, table, indexName) {
28302
28308
  const rows = db.prepare(`PRAGMA index_list(${table})`).all();
28303
28309
  return rows.some((row) => row.name === indexName);
28304
28310
  }
28305
- function up92(db) {
28311
+ function up93(db) {
28306
28312
  db.exec(`
28307
28313
  CREATE TABLE IF NOT EXISTS embedding_index_state (
28308
28314
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -28315,7 +28321,7 @@ function up92(db) {
28315
28321
  )
28316
28322
  `);
28317
28323
  }
28318
- function up93(db) {
28324
+ function up94(db) {
28319
28325
  db.exec(`
28320
28326
  CREATE TABLE IF NOT EXISTS embeddings_staging (
28321
28327
  id TEXT PRIMARY KEY,
@@ -28334,7 +28340,7 @@ function up93(db) {
28334
28340
  ON embeddings_staging(agent_id, source_type, source_id);
28335
28341
  `);
28336
28342
  }
28337
- function up94(db) {
28343
+ function up95(db) {
28338
28344
  const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
28339
28345
  if (!columns.some((column) => column.name === "evidence_cursor")) {
28340
28346
  db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
@@ -28344,7 +28350,7 @@ function hasColumn13(db, table, column) {
28344
28350
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
28345
28351
  return rows.some((r2) => r2.name === column);
28346
28352
  }
28347
- function up95(db) {
28353
+ function up96(db) {
28348
28354
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
28349
28355
  if (tables.length === 0)
28350
28356
  return;
@@ -28369,23 +28375,23 @@ function up95(db) {
28369
28375
  function hasColumn14(db, table, column) {
28370
28376
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
28371
28377
  }
28372
- function up96(db) {
28378
+ function up97(db) {
28373
28379
  const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
28374
28380
  if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
28375
28381
  return;
28376
28382
  db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
28377
28383
  }
28378
- function up97(db) {
28384
+ function up98(db) {
28379
28385
  db.exec("DROP TABLE IF EXISTS ingestion_jobs");
28380
28386
  }
28381
- function up98(db) {
28387
+ function up99(db) {
28382
28388
  const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
28383
28389
  if (!columns.some((column) => column.name === "last_failure_at")) {
28384
28390
  db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
28385
28391
  }
28386
28392
  db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
28387
28393
  }
28388
- function up99(db) {
28394
+ function up100(db) {
28389
28395
  db.exec(`
28390
28396
  CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
28391
28397
  agent_id TEXT NOT NULL,
@@ -28402,7 +28408,7 @@ function up99(db) {
28402
28408
  ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
28403
28409
  `);
28404
28410
  }
28405
- function up100(db) {
28411
+ function up101(db) {
28406
28412
  db.exec(`
28407
28413
  CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
28408
28414
  id TEXT PRIMARY KEY,
@@ -28422,7 +28428,7 @@ function up100(db) {
28422
28428
  ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
28423
28429
  `);
28424
28430
  }
28425
- function up101(db) {
28431
+ function up102(db) {
28426
28432
  const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
28427
28433
  if (!columns.some((column) => column.name === "evidence_window_json")) {
28428
28434
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
@@ -28431,7 +28437,7 @@ function up101(db) {
28431
28437
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
28432
28438
  }
28433
28439
  }
28434
- function up102(db) {
28440
+ function up103(db) {
28435
28441
  db.exec(`
28436
28442
  CREATE TABLE IF NOT EXISTS dreaming_attention (
28437
28443
  id TEXT PRIMARY KEY,
@@ -28453,7 +28459,7 @@ function up102(db) {
28453
28459
  function hasColumn15(db, table, column) {
28454
28460
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
28455
28461
  }
28456
- function up103(db) {
28462
+ function up104(db) {
28457
28463
  const requiredMemoryColumns = [
28458
28464
  "content_hash",
28459
28465
  "normalized_content",
@@ -28504,7 +28510,7 @@ function up103(db) {
28504
28510
  WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
28505
28511
  `);
28506
28512
  }
28507
- function up104(db) {
28513
+ function up105(db) {
28508
28514
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
28509
28515
  if (tables.length !== 2)
28510
28516
  return;
@@ -28527,7 +28533,7 @@ function tableExists(db, table) {
28527
28533
  function hasColumn16(db, table, column) {
28528
28534
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
28529
28535
  }
28530
- function up105(db) {
28536
+ function up106(db) {
28531
28537
  db.exec(`
28532
28538
  CREATE TABLE IF NOT EXISTS derived_memory_sources (
28533
28539
  derived_memory_id TEXT NOT NULL,
@@ -28570,7 +28576,7 @@ function up105(db) {
28570
28576
  `);
28571
28577
  }
28572
28578
  }
28573
- function up106(db) {
28579
+ function up107(db) {
28574
28580
  db.exec(`
28575
28581
  DROP TRIGGER IF EXISTS entities_fts_ai;
28576
28582
  DROP TRIGGER IF EXISTS entities_fts_ad;
@@ -28659,7 +28665,7 @@ function up106(db) {
28659
28665
  function hasColumn17(db, table, column) {
28660
28666
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
28661
28667
  }
28662
- function up107(db) {
28668
+ function up108(db) {
28663
28669
  if (!hasColumn17(db, "memories", "review_after")) {
28664
28670
  db.exec("ALTER TABLE memories ADD COLUMN review_after TEXT;");
28665
28671
  }
@@ -28668,14 +28674,14 @@ function up107(db) {
28668
28674
  function hasColumn18(db, table, column) {
28669
28675
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
28670
28676
  }
28671
- function up108(db) {
28677
+ function up109(db) {
28672
28678
  for (const [column, type] of TOKEN_COLUMNS) {
28673
28679
  if (!hasColumn18(db, "dreaming_passes", column)) {
28674
28680
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${column} ${type};`);
28675
28681
  }
28676
28682
  }
28677
28683
  }
28678
- function up109(db) {
28684
+ function up110(db) {
28679
28685
  db.exec(`
28680
28686
  CREATE TABLE IF NOT EXISTS embedding_usage (
28681
28687
  day TEXT NOT NULL,
@@ -28688,7 +28694,7 @@ function up109(db) {
28688
28694
  );
28689
28695
  `);
28690
28696
  }
28691
- function up110(db) {
28697
+ function up111(db) {
28692
28698
  db.exec(`
28693
28699
  CREATE TABLE IF NOT EXISTS telemetry_install (
28694
28700
  id TEXT PRIMARY KEY,
@@ -28696,7 +28702,7 @@ function up110(db) {
28696
28702
  );
28697
28703
  `);
28698
28704
  }
28699
- function up111(db) {
28705
+ function up112(db) {
28700
28706
  db.exec(`
28701
28707
  CREATE INDEX IF NOT EXISTS idx_memory_entity_mentions_entity_memory
28702
28708
  ON memory_entity_mentions(entity_id, memory_id);
@@ -28706,7 +28712,7 @@ function hasColumn19(db, table, column) {
28706
28712
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
28707
28713
  return rows.some((row) => row.name === column);
28708
28714
  }
28709
- function up112(db) {
28715
+ function up113(db) {
28710
28716
  for (const column of COLUMNS2) {
28711
28717
  if (!hasColumn19(db, "telemetry_install", column)) {
28712
28718
  db.exec(`ALTER TABLE telemetry_install ADD COLUMN ${column} TEXT`);
@@ -28722,7 +28728,7 @@ function addColumnIfMissing23(db, column, definition) {
28722
28728
  db.exec(`ALTER TABLE telemetry_events ADD COLUMN ${column} ${definition}`);
28723
28729
  }
28724
28730
  }
28725
- function up113(db) {
28731
+ function up114(db) {
28726
28732
  addColumnIfMissing23(db, "source", "TEXT NOT NULL DEFAULT 'daemon'");
28727
28733
  addColumnIfMissing23(db, "claim_token", "TEXT");
28728
28734
  addColumnIfMissing23(db, "claimed_at", "TEXT");
@@ -28731,7 +28737,7 @@ function up113(db) {
28731
28737
  ON telemetry_events(source, sent_to_posthog, claimed_at, timestamp);
28732
28738
  `);
28733
28739
  }
28734
- function up114(db) {
28740
+ function up115(db) {
28735
28741
  db.exec(`
28736
28742
  CREATE TABLE IF NOT EXISTS session_claims (
28737
28743
  session_key TEXT NOT NULL,
@@ -28752,7 +28758,7 @@ function up114(db) {
28752
28758
  ON session_claims(agent_id, state, expires_at);
28753
28759
  `);
28754
28760
  }
28755
- function up115(db) {
28761
+ function up116(db) {
28756
28762
  const table = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'entity_attributes'").get();
28757
28763
  if (table == null)
28758
28764
  return;
@@ -28761,7 +28767,7 @@ function up115(db) {
28761
28767
  ON entity_attributes(memory_id, agent_id, status, importance);
28762
28768
  `);
28763
28769
  }
28764
- function up116(db) {
28770
+ function up117(db) {
28765
28771
  db.exec(`
28766
28772
  CREATE TABLE IF NOT EXISTS cross_agent_messages (
28767
28773
  id TEXT PRIMARY KEY,
@@ -28818,7 +28824,7 @@ function addColumnIfMissing24(db, column, definition) {
28818
28824
  db.exec(`ALTER TABLE cross_agent_messages ADD COLUMN ${column} ${definition}`);
28819
28825
  }
28820
28826
  }
28821
- function up117(db) {
28827
+ function up118(db) {
28822
28828
  const table = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'cross_agent_messages'").get();
28823
28829
  if (table == null)
28824
28830
  return;
@@ -29018,7 +29024,7 @@ function backfillTranscriptsFromSummaryJobs(db) {
29018
29024
  insert.run(...values);
29019
29025
  }
29020
29026
  }
29021
- function up118(db) {
29027
+ function up119(db) {
29022
29028
  if (!hasTable4(db, "session_transcripts"))
29023
29029
  return;
29024
29030
  addColumnIfMissing25(db, "session_transcripts", "completed_at", "TEXT");
@@ -29071,7 +29077,7 @@ function up118(db) {
29071
29077
  ON session_transcripts(agent_id, content_hash);
29072
29078
  `);
29073
29079
  }
29074
- function up119(db) {
29080
+ function up120(db) {
29075
29081
  db.exec(`
29076
29082
  CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_status
29077
29083
  ON memory_jobs(status)
@@ -29090,12 +29096,12 @@ function up119(db) {
29090
29096
  function hasColumn22(db, table, column) {
29091
29097
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
29092
29098
  }
29093
- function up120(db) {
29099
+ function up121(db) {
29094
29100
  if (!hasColumn22(db, "telemetry_install", "last_seen_version")) {
29095
29101
  db.exec("ALTER TABLE telemetry_install ADD COLUMN last_seen_version TEXT");
29096
29102
  }
29097
29103
  }
29098
- function up121(db) {
29104
+ function up122(db) {
29099
29105
  db.exec(`
29100
29106
  CREATE TABLE IF NOT EXISTS source_lifecycle_state (
29101
29107
  agent_id TEXT NOT NULL,
@@ -29124,7 +29130,7 @@ function addColumnIfMissing26(db, column, definition) {
29124
29130
  db.exec(`ALTER TABLE telemetry_events ADD COLUMN ${column} ${definition}`);
29125
29131
  }
29126
29132
  }
29127
- function up122(db) {
29133
+ function up123(db) {
29128
29134
  addColumnIfMissing26(db, "delivery_attempts", "INTEGER NOT NULL DEFAULT 0");
29129
29135
  addColumnIfMissing26(db, "last_attempt_at", "TEXT");
29130
29136
  addColumnIfMissing26(db, "sent_at", "TEXT");
@@ -29145,7 +29151,7 @@ function up122(db) {
29145
29151
  VALUES (1, CURRENT_TIMESTAMP);
29146
29152
  `);
29147
29153
  }
29148
- function up123(db) {
29154
+ function up124(db) {
29149
29155
  const columns = db.prepare("PRAGMA table_info(dreaming_evidence_exclusions)").all();
29150
29156
  const names = new Set(columns.map((column) => column.name));
29151
29157
  if (!names.has("failure_class")) {
@@ -29162,7 +29168,7 @@ function up123(db) {
29162
29168
  }
29163
29169
  db.exec("CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_retry ON dreaming_evidence_exclusions (resolved_at, requeue_requested_at, failure_class, retry_count, last_requeued_at)");
29164
29170
  }
29165
- function up124(db) {
29171
+ function up125(db) {
29166
29172
  db.exec(`
29167
29173
  CREATE TABLE IF NOT EXISTS embedding_index_failures (
29168
29174
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -29186,7 +29192,7 @@ function up124(db) {
29186
29192
  ON embedding_index_failures(source_type, source_id);
29187
29193
  `);
29188
29194
  }
29189
- function up125(db) {
29195
+ function up126(db) {
29190
29196
  db.exec(`
29191
29197
  CREATE TABLE IF NOT EXISTS imported_source_lifecycle (
29192
29198
  id TEXT PRIMARY KEY,
@@ -29236,7 +29242,7 @@ function backfillTable(db, params) {
29236
29242
  FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
29237
29243
  backfill(db, rows, params.sourceKind, params.scannedAt);
29238
29244
  }
29239
- function up126(db) {
29245
+ function up127(db) {
29240
29246
  db.exec(`
29241
29247
  CREATE TABLE IF NOT EXISTS memory_content_safety (
29242
29248
  agent_id TEXT NOT NULL,
@@ -29293,7 +29299,7 @@ function up126(db) {
29293
29299
  scannedAt
29294
29300
  });
29295
29301
  }
29296
- function up127(db) {
29302
+ function up128(db) {
29297
29303
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
29298
29304
  if (!table)
29299
29305
  return;
@@ -29327,7 +29333,7 @@ function up127(db) {
29327
29333
  ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
29328
29334
  `);
29329
29335
  }
29330
- function up128(db) {
29336
+ function up129(db) {
29331
29337
  db.exec(`
29332
29338
  CREATE TABLE IF NOT EXISTS ontology_contradictions (
29333
29339
  id TEXT PRIMARY KEY,
@@ -29383,7 +29389,7 @@ function up128(db) {
29383
29389
  ON ontology_contradictions(agent_id, left_source_id, right_source_id);
29384
29390
  `);
29385
29391
  }
29386
- function up129(db) {
29392
+ function up130(db) {
29387
29393
  db.exec(`
29388
29394
  CREATE INDEX IF NOT EXISTS idx_memory_jobs_diagnostics_status_created_at
29389
29395
  ON memory_jobs(status, created_at)
@@ -29398,7 +29404,7 @@ function up129(db) {
29398
29404
  function tableExists3(db, table) {
29399
29405
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
29400
29406
  }
29401
- function up130(db) {
29407
+ function up131(db) {
29402
29408
  if (!tableExists3(db, "memory_jobs"))
29403
29409
  return;
29404
29410
  if (!tableExists3(db, "job_cancellations")) {
@@ -29447,7 +29453,7 @@ function up130(db) {
29447
29453
  AND status IN ('pending', 'leased');
29448
29454
  `);
29449
29455
  }
29450
- function up131(db) {
29456
+ function up132(db) {
29451
29457
  db.exec(`
29452
29458
  CREATE TABLE IF NOT EXISTS embedding_repair_budget (
29453
29459
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -29487,7 +29493,7 @@ function up131(db) {
29487
29493
  END;
29488
29494
  `);
29489
29495
  }
29490
- function up132(db) {
29496
+ function up133(db) {
29491
29497
  db.exec(`
29492
29498
  CREATE TABLE IF NOT EXISTS dreaming_evidence_consumption (
29493
29499
  agent_id TEXT NOT NULL,
@@ -29510,13 +29516,13 @@ function up132(db) {
29510
29516
  ON dreaming_evidence_consumption(agent_id, pass_id, delivered_offset, source_length);
29511
29517
  `);
29512
29518
  }
29513
- function up133(db) {
29519
+ function up134(db) {
29514
29520
  db.exec(`
29515
29521
  CREATE INDEX IF NOT EXISTS idx_epistemic_assertions_observer_entity
29516
29522
  ON epistemic_assertions(agent_id, subject_entity_id, status, asserted_at DESC, created_at DESC);
29517
29523
  `);
29518
29524
  }
29519
- function up134(db) {
29525
+ function up135(db) {
29520
29526
  db.exec(`
29521
29527
  CREATE TABLE IF NOT EXISTS memory_head_revisions (
29522
29528
  id TEXT PRIMARY KEY,
@@ -29568,7 +29574,7 @@ function up134(db) {
29568
29574
  if (!names.has("format_version"))
29569
29575
  db.exec("ALTER TABLE memory_md_heads ADD COLUMN format_version INTEGER NOT NULL DEFAULT 1");
29570
29576
  }
29571
- function up135(db) {
29577
+ function up136(db) {
29572
29578
  db.exec(`
29573
29579
  CREATE TABLE memory_head_entries_v134 (
29574
29580
  entry_id TEXT NOT NULL, agent_id TEXT NOT NULL, canonical_text TEXT NOT NULL,
@@ -29586,7 +29592,7 @@ function up135(db) {
29586
29592
  ON memory_head_entries(agent_id, entry_id, last_revision DESC);
29587
29593
  `);
29588
29594
  }
29589
- function up136(db) {
29595
+ function up137(db) {
29590
29596
  db.exec(`
29591
29597
  CREATE TABLE IF NOT EXISTS memory_head_publications (
29592
29598
  agent_id TEXT NOT NULL,
@@ -29602,7 +29608,7 @@ function up136(db) {
29602
29608
  ON memory_head_publications(agent_id, status, revision DESC);
29603
29609
  `);
29604
29610
  }
29605
- function up137(db) {
29611
+ function up138(db) {
29606
29612
  const cols = new Set(db.prepare("PRAGMA table_info(memory_head_revisions)").all().map((r2) => r2.name));
29607
29613
  for (const [name, type] of [
29608
29614
  ["entry_id", "TEXT"],
@@ -29616,7 +29622,7 @@ function up137(db) {
29616
29622
  }
29617
29623
  db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_head_revisions_entry ON memory_head_revisions(agent_id, revision, entry_id)");
29618
29624
  }
29619
- function up138(db) {
29625
+ function up139(db) {
29620
29626
  const cols = new Set(db.prepare("PRAGMA table_info(dreaming_passes)").all().map((r2) => r2.name));
29621
29627
  for (const [name, type] of [
29622
29628
  ["head_revision", "INTEGER"],
@@ -29638,7 +29644,7 @@ function addColumnIfMissing27(db, table, column, definition) {
29638
29644
  if (!hasColumn25(db, table, column))
29639
29645
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
29640
29646
  }
29641
- function up139(db) {
29647
+ function up140(db) {
29642
29648
  addColumnIfMissing27(db, "memories", "manual_override", "INTEGER DEFAULT 0");
29643
29649
  db.exec(`
29644
29650
  CREATE TABLE IF NOT EXISTS transcript_capture_status (
@@ -29943,7 +29949,7 @@ function up139(db) {
29943
29949
  GROUP BY j.agent_id;
29944
29950
  `);
29945
29951
  }
29946
- function up140(db) {
29952
+ function up141(db) {
29947
29953
  db.exec(`
29948
29954
  CREATE TABLE IF NOT EXISTS native_source_sync_state (
29949
29955
  agent_id TEXT NOT NULL,
@@ -29959,7 +29965,7 @@ function up140(db) {
29959
29965
  ON native_source_sync_state(agent_id, status);
29960
29966
  `);
29961
29967
  }
29962
- function up141(db) {
29968
+ function up142(db) {
29963
29969
  db.exec(`
29964
29970
  CREATE TABLE IF NOT EXISTS transcript_recovery_frontiers (
29965
29971
  agent_id TEXT NOT NULL,
@@ -29971,7 +29977,7 @@ function up141(db) {
29971
29977
  );
29972
29978
  `);
29973
29979
  }
29974
- function up142(db) {
29980
+ function up143(db) {
29975
29981
  db.exec(`
29976
29982
  CREATE TABLE IF NOT EXISTS source_sync_checkpoints (
29977
29983
  agent_id TEXT NOT NULL,
@@ -29985,13 +29991,13 @@ function up142(db) {
29985
29991
  );
29986
29992
  `);
29987
29993
  }
29988
- function up143(db) {
29994
+ function up144(db) {
29989
29995
  const columns = db.prepare("PRAGMA table_info(source_sync_checkpoints)").all();
29990
29996
  if (!columns.some((column) => column.name === "frontier")) {
29991
29997
  db.exec("ALTER TABLE source_sync_checkpoints ADD COLUMN frontier TEXT");
29992
29998
  }
29993
29999
  }
29994
- function up144(db) {
30000
+ function up145(db) {
29995
30001
  const columns = new Set(db.prepare("PRAGMA table_info(embedding_index_state)").all().map((row) => row.name).filter((name) => typeof name === "string"));
29996
30002
  const additions = [
29997
30003
  ["migration_phase", "TEXT"],
@@ -30026,13 +30032,13 @@ function up144(db) {
30026
30032
  `);
30027
30033
  }
30028
30034
  }
30029
- function up145(db) {
30035
+ function up146(db) {
30030
30036
  const columns = new Set(db.prepare("PRAGMA table_info(memory_jobs)").all().map((row) => row.name).filter((name) => typeof name === "string"));
30031
30037
  if (!columns.has("lease_token")) {
30032
30038
  db.exec("ALTER TABLE memory_jobs ADD COLUMN lease_token TEXT");
30033
30039
  }
30034
30040
  }
30035
- function up146(db) {
30041
+ function up147(db) {
30036
30042
  db.exec(`
30037
30043
  CREATE TABLE IF NOT EXISTS dreaming_evidence_reviews (
30038
30044
  agent_id TEXT NOT NULL,
@@ -30050,7 +30056,7 @@ function up146(db) {
30050
30056
  ON dreaming_evidence_reviews (agent_id, reviewed_at DESC);
30051
30057
  `);
30052
30058
  }
30053
- function up147(db) {
30059
+ function up148(db) {
30054
30060
  db.exec(`
30055
30061
  CREATE TABLE IF NOT EXISTS source_import_jobs (
30056
30062
  id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind = 'import'), agent_id TEXT NOT NULL,
@@ -30117,16 +30123,16 @@ function up147(db) {
30117
30123
  }
30118
30124
  db.exec("CREATE INDEX IF NOT EXISTS idx_session_transcripts_agent_source ON session_transcripts(agent_id, source_id)");
30119
30125
  }
30120
- function up148(db) {
30126
+ function up149(db) {
30121
30127
  db.exec("CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state)");
30122
30128
  }
30123
- function up149(db) {
30129
+ function up150(db) {
30124
30130
  const columns = db.prepare("PRAGMA table_info(source_import_record_attempts)").all();
30125
30131
  if (!columns.some((column) => column.name === "source_id")) {
30126
30132
  db.exec("ALTER TABLE source_import_record_attempts ADD COLUMN source_id TEXT");
30127
30133
  }
30128
30134
  }
30129
- function up150(db) {
30135
+ function up151(db) {
30130
30136
  const addColumn = (table, column, definition) => {
30131
30137
  const statement = db.prepare("SELECT 1 AS found FROM pragma_table_info(?) WHERE name = ?");
30132
30138
  let exists;
@@ -30147,7 +30153,7 @@ function addColumnIfMissing28(db, table, column, definition) {
30147
30153
  if (!columns.some((row) => row.name === column))
30148
30154
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
30149
30155
  }
30150
- function up151(db) {
30156
+ function up152(db) {
30151
30157
  addColumnIfMissing28(db, "memory_md_heads", "is_current", "INTEGER NOT NULL DEFAULT 0");
30152
30158
  addColumnIfMissing28(db, "dreaming_passes", "head_base_revision", "INTEGER");
30153
30159
  db.exec("CREATE INDEX IF NOT EXISTS idx_memory_head_revisions_content_hash ON memory_head_revisions(content_hash)");
@@ -30350,6 +30356,10 @@ function existingTables(db) {
30350
30356
  const rows = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
30351
30357
  return new Set(rows.filter(hasStringName).map((r2) => r2.name));
30352
30358
  }
30359
+ function existingIndexes(db) {
30360
+ const rows = db.prepare("SELECT name FROM sqlite_master WHERE type='index'").all();
30361
+ return new Set(rows.filter(hasStringName).map((r2) => r2.name));
30362
+ }
30353
30363
  function tableColumns2(db, table, cache) {
30354
30364
  let cols = cache.get(table);
30355
30365
  if (cols)
@@ -30359,45 +30369,38 @@ function tableColumns2(db, table, cache) {
30359
30369
  cache.set(table, cols);
30360
30370
  return cols;
30361
30371
  }
30372
+ function missingArtifact(db, artifacts, tables, indexes, colCache) {
30373
+ for (const table of artifacts.tables ?? []) {
30374
+ if (!tables.has(table))
30375
+ return `table "${table}"`;
30376
+ }
30377
+ for (const column of artifacts.columns ?? []) {
30378
+ if (!tables.has(column.table)) {
30379
+ if (column.optional)
30380
+ continue;
30381
+ return `column "${column.table}.${column.column}" (table missing)`;
30382
+ }
30383
+ if (!tableColumns2(db, column.table, colCache).has(column.column)) {
30384
+ if (column.optional)
30385
+ continue;
30386
+ return `column "${column.table}.${column.column}"`;
30387
+ }
30388
+ }
30389
+ for (const index of artifacts.indexes ?? []) {
30390
+ if (!indexes.has(index))
30391
+ return `index "${index}"`;
30392
+ }
30393
+ return;
30394
+ }
30362
30395
  function findPhantomVersions(db, precomputedApplied) {
30363
30396
  const tables = existingTables(db);
30397
+ const indexes = existingIndexes(db);
30364
30398
  const colCache = new Map;
30365
30399
  const phantoms = new Set;
30366
30400
  const applied = precomputedApplied ?? appliedVersions(db);
30367
30401
  for (const migration of MIGRATIONS) {
30368
- if (!migration.artifacts)
30369
- continue;
30370
- if (migration.version === 1)
30371
- continue;
30372
- if (!applied.has(migration.version))
30373
- continue;
30374
- let missing = false;
30375
- if (migration.artifacts.tables) {
30376
- for (const t2 of migration.artifacts.tables) {
30377
- if (!tables.has(t2)) {
30378
- missing = true;
30379
- break;
30380
- }
30381
- }
30382
- }
30383
- if (!missing && migration.artifacts.columns) {
30384
- for (const col of migration.artifacts.columns) {
30385
- if (!tables.has(col.table)) {
30386
- if (col.optional)
30387
- continue;
30388
- missing = true;
30389
- break;
30390
- }
30391
- const cols = tableColumns2(db, col.table, colCache);
30392
- if (!cols.has(col.column)) {
30393
- if (col.optional)
30394
- continue;
30395
- missing = true;
30396
- break;
30397
- }
30398
- }
30399
- }
30400
- if (missing)
30402
+ const artifacts = migration.artifacts;
30403
+ if (artifacts && migration.version !== 1 && applied.has(migration.version) && missingArtifact(db, artifacts, tables, indexes, colCache))
30401
30404
  phantoms.add(migration.version);
30402
30405
  }
30403
30406
  return phantoms;
@@ -30419,31 +30422,13 @@ function appliedVersions(db) {
30419
30422
  const rows = db.prepare("SELECT version FROM schema_migrations").all();
30420
30423
  return new Set(rows.filter(hasNumericVersion).map((r2) => r2.version));
30421
30424
  }
30422
- function verifyArtifacts(db, migration) {
30423
- if (!migration.artifacts)
30424
- return;
30425
- const tables = existingTables(db);
30426
- if (migration.artifacts.tables) {
30427
- for (const t2 of migration.artifacts.tables) {
30428
- if (!tables.has(t2)) {
30429
- throw new Error(`Post-DDL verification failed: migration ${migration.version} (${migration.name}) ` + `declares table "${t2}" but it was not created`);
30430
- }
30431
- }
30432
- }
30433
- if (migration.artifacts.columns) {
30434
- const colCache = new Map;
30435
- for (const col of migration.artifacts.columns) {
30436
- if (!tables.has(col.table)) {
30437
- if (col.optional)
30438
- continue;
30439
- throw new Error(`Post-DDL verification failed: migration ${migration.version} (${migration.name}) ` + `declares column "${col.table}.${col.column}" but table does not exist`);
30440
- }
30441
- const colNames = tableColumns2(db, col.table, colCache);
30442
- if (!colNames.has(col.column)) {
30443
- throw new Error(`Post-DDL verification failed: migration ${migration.version} (${migration.name}) ` + `declares column "${col.table}.${col.column}" but it was not created`);
30444
- }
30445
- }
30446
- }
30425
+ function verifyArtifacts(db, migration) {
30426
+ const artifacts = migration.artifacts;
30427
+ if (!artifacts)
30428
+ return;
30429
+ const missing = missingArtifact(db, artifacts, existingTables(db), existingIndexes(db), new Map);
30430
+ if (missing)
30431
+ throw new Error(`Post-DDL verification failed: migration ${migration.version} (${migration.name}) declares ${missing} but it was not created`);
30447
30432
  }
30448
30433
  function hasPendingMigrations(db) {
30449
30434
  ensureMetaTables(db);
@@ -39169,13 +39154,13 @@ ${end.comment}` : end.comment;
39169
39154
  {
39170
39155
  version: 1,
39171
39156
  name: "baseline",
39172
- up: up2,
39157
+ up: up3,
39173
39158
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
39174
39159
  },
39175
39160
  {
39176
39161
  version: 2,
39177
39162
  name: "pipeline-v2",
39178
- up: up3,
39163
+ up: up4,
39179
39164
  artifacts: {
39180
39165
  tables: ["memory_history", "memory_jobs", "entities", "relations", "memory_entity_mentions"]
39181
39166
  }
@@ -39183,12 +39168,12 @@ ${end.comment}` : end.comment;
39183
39168
  {
39184
39169
  version: 3,
39185
39170
  name: "unique-content-hash",
39186
- up: up4
39171
+ up: up5
39187
39172
  },
39188
39173
  {
39189
39174
  version: 4,
39190
39175
  name: "history-actor-and-retention",
39191
- up: up5,
39176
+ up: up6,
39192
39177
  artifacts: {
39193
39178
  columns: [{ table: "memory_history", column: "actor_type" }]
39194
39179
  }
@@ -39196,7 +39181,7 @@ ${end.comment}` : end.comment;
39196
39181
  {
39197
39182
  version: 5,
39198
39183
  name: "graph-extended",
39199
- up: up6,
39184
+ up: up7,
39200
39185
  artifacts: {
39201
39186
  columns: [{ table: "entities", column: "canonical_name" }]
39202
39187
  }
@@ -39204,7 +39189,7 @@ ${end.comment}` : end.comment;
39204
39189
  {
39205
39190
  version: 6,
39206
39191
  name: "idempotency-key",
39207
- up: up7,
39192
+ up: up8,
39208
39193
  artifacts: {
39209
39194
  columns: [{ table: "memories", column: "idempotency_key" }]
39210
39195
  }
@@ -39212,42 +39197,42 @@ ${end.comment}` : end.comment;
39212
39197
  {
39213
39198
  version: 7,
39214
39199
  name: "documents-and-connectors",
39215
- up: up8,
39200
+ up: up9,
39216
39201
  artifacts: { tables: ["documents", "document_memories", "connectors"] }
39217
39202
  },
39218
39203
  {
39219
39204
  version: 8,
39220
39205
  name: "embeddings-unique-hash",
39221
- up: up9
39206
+ up: up10
39222
39207
  },
39223
39208
  {
39224
39209
  version: 9,
39225
39210
  name: "summary-jobs",
39226
- up: up10,
39211
+ up: up11,
39227
39212
  artifacts: { tables: ["summary_jobs"] }
39228
39213
  },
39229
39214
  {
39230
39215
  version: 10,
39231
39216
  name: "umap-cache",
39232
- up: up11,
39217
+ up: up12,
39233
39218
  artifacts: { tables: ["umap_cache"] }
39234
39219
  },
39235
39220
  {
39236
39221
  version: 11,
39237
39222
  name: "session-scores",
39238
- up: up12,
39223
+ up: up13,
39239
39224
  artifacts: { tables: ["session_scores"] }
39240
39225
  },
39241
39226
  {
39242
39227
  version: 12,
39243
39228
  name: "scheduled-tasks",
39244
- up: up13,
39229
+ up: up14,
39245
39230
  artifacts: { tables: ["scheduled_tasks", "task_runs"] }
39246
39231
  },
39247
39232
  {
39248
39233
  version: 13,
39249
39234
  name: "ingestion-tracking",
39250
- up: up14,
39235
+ up: up15,
39251
39236
  artifacts: {
39252
39237
  columns: [
39253
39238
  { table: "memories", column: "source_path" },
@@ -39258,13 +39243,13 @@ ${end.comment}` : end.comment;
39258
39243
  {
39259
39244
  version: 14,
39260
39245
  name: "telemetry",
39261
- up: up15,
39246
+ up: up16,
39262
39247
  artifacts: { tables: ["telemetry_events"] }
39263
39248
  },
39264
39249
  {
39265
39250
  version: 15,
39266
39251
  name: "session-memories",
39267
- up: up16,
39252
+ up: up17,
39268
39253
  artifacts: {
39269
39254
  tables: ["session_memories"],
39270
39255
  columns: [
@@ -39276,13 +39261,13 @@ ${end.comment}` : end.comment;
39276
39261
  {
39277
39262
  version: 16,
39278
39263
  name: "session-checkpoints",
39279
- up: up17,
39264
+ up: up18,
39280
39265
  artifacts: { tables: ["session_checkpoints"] }
39281
39266
  },
39282
39267
  {
39283
39268
  version: 17,
39284
39269
  name: "task-skills",
39285
- up: up18,
39270
+ up: up19,
39286
39271
  artifacts: {
39287
39272
  columns: [{ table: "scheduled_tasks", column: "skill_name" }]
39288
39273
  }
@@ -39290,13 +39275,13 @@ ${end.comment}` : end.comment;
39290
39275
  {
39291
39276
  version: 18,
39292
39277
  name: "skill-meta",
39293
- up: up19,
39278
+ up: up20,
39294
39279
  artifacts: { tables: ["skill_meta"] }
39295
39280
  },
39296
39281
  {
39297
39282
  version: 19,
39298
39283
  name: "knowledge-structure",
39299
- up: up20,
39284
+ up: up21,
39300
39285
  artifacts: {
39301
39286
  tables: ["entity_aspects", "entity_attributes", "entity_dependencies", "task_meta"],
39302
39287
  columns: [{ table: "entities", column: "agent_id" }]
@@ -39305,7 +39290,7 @@ ${end.comment}` : end.comment;
39305
39290
  {
39306
39291
  version: 20,
39307
39292
  name: "session-structural-columns",
39308
- up: up21,
39293
+ up: up22,
39309
39294
  artifacts: {
39310
39295
  columns: [
39311
39296
  { table: "session_memories", column: "entity_slot" },
@@ -39318,7 +39303,7 @@ ${end.comment}` : end.comment;
39318
39303
  {
39319
39304
  version: 21,
39320
39305
  name: "checkpoint-structural",
39321
- up: up22,
39306
+ up: up23,
39322
39307
  artifacts: {
39323
39308
  columns: [{ table: "session_checkpoints", column: "focal_entity_ids" }]
39324
39309
  }
@@ -39326,7 +39311,7 @@ ${end.comment}` : end.comment;
39326
39311
  {
39327
39312
  version: 22,
39328
39313
  name: "entity-pinning",
39329
- up: up23,
39314
+ up: up24,
39330
39315
  artifacts: {
39331
39316
  columns: [
39332
39317
  { table: "entities", column: "pinned" },
@@ -39337,17 +39322,17 @@ ${end.comment}` : end.comment;
39337
39322
  {
39338
39323
  version: 23,
39339
39324
  name: "retired-scorer-gap",
39340
- up: up24
39325
+ up: up25
39341
39326
  },
39342
39327
  {
39343
39328
  version: 24,
39344
39329
  name: "retired-scorer-gap",
39345
- up: up25
39330
+ up: up26
39346
39331
  },
39347
39332
  {
39348
39333
  version: 25,
39349
39334
  name: "agent-feedback",
39350
- up: up26,
39335
+ up: up27,
39351
39336
  artifacts: {
39352
39337
  columns: [{ table: "session_memories", column: "agent_relevance_score" }]
39353
39338
  }
@@ -39355,32 +39340,32 @@ ${end.comment}` : end.comment;
39355
39340
  {
39356
39341
  version: 26,
39357
39342
  name: "retired-scorer-gap",
39358
- up: up27
39343
+ up: up28
39359
39344
  },
39360
39345
  {
39361
39346
  version: 27,
39362
39347
  name: "backfill-canonical-names",
39363
- up: up28
39348
+ up: up29
39364
39349
  },
39365
39350
  {
39366
39351
  version: 28,
39367
39352
  name: "lossless-retention",
39368
- up: up29
39353
+ up: up30
39369
39354
  },
39370
39355
  {
39371
39356
  version: 29,
39372
39357
  name: "session-summary-dag",
39373
- up: up30
39358
+ up: up31
39374
39359
  },
39375
39360
  {
39376
39361
  version: 30,
39377
39362
  name: "nullable-memory-job-memory-id",
39378
- up: up31
39363
+ up: up32
39379
39364
  },
39380
39365
  {
39381
39366
  version: 31,
39382
39367
  name: "dependency-reason",
39383
- up: up32,
39368
+ up: up33,
39384
39369
  artifacts: {
39385
39370
  columns: [
39386
39371
  { table: "entity_dependencies", column: "reason" },
@@ -39391,7 +39376,7 @@ ${end.comment}` : end.comment;
39391
39376
  {
39392
39377
  version: 32,
39393
39378
  name: "embeddings-vector-column",
39394
- up: up33,
39379
+ up: up34,
39395
39380
  artifacts: {
39396
39381
  columns: [{ table: "embeddings", column: "vector", optional: true }]
39397
39382
  }
@@ -39399,7 +39384,7 @@ ${end.comment}` : end.comment;
39399
39384
  {
39400
39385
  version: 33,
39401
39386
  name: "scope",
39402
- up: up34,
39387
+ up: up35,
39403
39388
  artifacts: {
39404
39389
  columns: [{ table: "memories", column: "scope" }]
39405
39390
  }
@@ -39407,17 +39392,17 @@ ${end.comment}` : end.comment;
39407
39392
  {
39408
39393
  version: 34,
39409
39394
  name: "scope-aware-dedup",
39410
- up: up35
39395
+ up: up36
39411
39396
  },
39412
39397
  {
39413
39398
  version: 35,
39414
39399
  name: "entity-fts",
39415
- up: up36
39400
+ up: up37
39416
39401
  },
39417
39402
  {
39418
39403
  version: 36,
39419
39404
  name: "dependency-confidence",
39420
- up: up37,
39405
+ up: up38,
39421
39406
  artifacts: {
39422
39407
  columns: [{ table: "entity_dependencies", column: "confidence" }]
39423
39408
  }
@@ -39425,7 +39410,7 @@ ${end.comment}` : end.comment;
39425
39410
  {
39426
39411
  version: 37,
39427
39412
  name: "entity-communities",
39428
- up: up38,
39413
+ up: up39,
39429
39414
  artifacts: {
39430
39415
  tables: ["entity_communities"],
39431
39416
  columns: [{ table: "entities", column: "community_id" }]
@@ -39434,24 +39419,24 @@ ${end.comment}` : end.comment;
39434
39419
  {
39435
39420
  version: 38,
39436
39421
  name: "memory-hints",
39437
- up: up39,
39422
+ up: up40,
39438
39423
  artifacts: { tables: ["memory_hints"] }
39439
39424
  },
39440
39425
  {
39441
39426
  version: 39,
39442
39427
  name: "dedup-entity-dependencies",
39443
- up: up40
39428
+ up: up41
39444
39429
  },
39445
39430
  {
39446
39431
  version: 40,
39447
39432
  name: "session-transcripts",
39448
- up: up41,
39433
+ up: up42,
39449
39434
  artifacts: { tables: ["session_transcripts"] }
39450
39435
  },
39451
39436
  {
39452
39437
  version: 41,
39453
39438
  name: "path-feedback",
39454
- up: up42,
39439
+ up: up43,
39455
39440
  artifacts: {
39456
39441
  tables: [
39457
39442
  "path_feedback_events",
@@ -39466,7 +39451,7 @@ ${end.comment}` : end.comment;
39466
39451
  {
39467
39452
  version: 42,
39468
39453
  name: "session-memories-agent-id",
39469
- up: up43,
39454
+ up: up44,
39470
39455
  artifacts: {
39471
39456
  columns: [{ table: "session_memories", column: "agent_id" }]
39472
39457
  }
@@ -39474,7 +39459,7 @@ ${end.comment}` : end.comment;
39474
39459
  {
39475
39460
  version: 43,
39476
39461
  name: "agents-table",
39477
- up: up44,
39462
+ up: up45,
39478
39463
  artifacts: {
39479
39464
  tables: ["agents"],
39480
39465
  columns: [
@@ -39486,7 +39471,7 @@ ${end.comment}` : end.comment;
39486
39471
  {
39487
39472
  version: 44,
39488
39473
  name: "memory-md-temporal-head",
39489
- up: up45,
39474
+ up: up46,
39490
39475
  artifacts: {
39491
39476
  columns: [
39492
39477
  { table: "session_summaries", column: "source_type" },
@@ -39498,7 +39483,7 @@ ${end.comment}` : end.comment;
39498
39483
  {
39499
39484
  version: 45,
39500
39485
  name: "lossless-working-memory-hardening",
39501
- up: up46,
39486
+ up: up47,
39502
39487
  artifacts: {
39503
39488
  tables: ["session_transcripts_fts", "memory_md_heads"],
39504
39489
  columns: [
@@ -39511,17 +39496,17 @@ ${end.comment}` : end.comment;
39511
39496
  {
39512
39497
  version: 46,
39513
39498
  name: "session-summary-uniqueness",
39514
- up: up47
39499
+ up: up48
39515
39500
  },
39516
39501
  {
39517
39502
  version: 47,
39518
39503
  name: "agent-scoped-temporal-uniqueness",
39519
- up: up48
39504
+ up: up49
39520
39505
  },
39521
39506
  {
39522
39507
  version: 48,
39523
39508
  name: "thread-heads",
39524
- up: up49,
39509
+ up: up50,
39525
39510
  artifacts: {
39526
39511
  tables: ["memory_thread_heads"]
39527
39512
  }
@@ -39529,7 +39514,7 @@ ${end.comment}` : end.comment;
39529
39514
  {
39530
39515
  version: 49,
39531
39516
  name: "session-extract-cursors",
39532
- up: up50,
39517
+ up: up51,
39533
39518
  artifacts: {
39534
39519
  tables: ["session_extract_cursors"]
39535
39520
  }
@@ -39537,7 +39522,7 @@ ${end.comment}` : end.comment;
39537
39522
  {
39538
39523
  version: 50,
39539
39524
  name: "related-to-audit",
39540
- up: up51,
39525
+ up: up52,
39541
39526
  artifacts: {
39542
39527
  tables: ["entity_dependency_history"]
39543
39528
  }
@@ -39545,7 +39530,7 @@ ${end.comment}` : end.comment;
39545
39530
  {
39546
39531
  version: 51,
39547
39532
  name: "memory-md-rolling-window-lineage",
39548
- up: up52,
39533
+ up: up53,
39549
39534
  artifacts: {
39550
39535
  tables: ["memory_artifacts", "memory_artifact_tombstones", "memory_artifacts_fts"],
39551
39536
  columns: [
@@ -39560,7 +39545,7 @@ ${end.comment}` : end.comment;
39560
39545
  {
39561
39546
  version: 52,
39562
39547
  name: "mcp-invocations",
39563
- up: up53,
39548
+ up: up54,
39564
39549
  artifacts: {
39565
39550
  tables: ["mcp_invocations"]
39566
39551
  }
@@ -39568,7 +39553,7 @@ ${end.comment}` : end.comment;
39568
39553
  {
39569
39554
  version: 53,
39570
39555
  name: "skill-invocations",
39571
- up: up54,
39556
+ up: up55,
39572
39557
  artifacts: {
39573
39558
  tables: ["skill_invocations"]
39574
39559
  }
@@ -39576,7 +39561,7 @@ ${end.comment}` : end.comment;
39576
39561
  {
39577
39562
  version: 54,
39578
39563
  name: "task-agent-scope",
39579
- up: up55,
39564
+ up: up56,
39580
39565
  artifacts: {
39581
39566
  tables: ["task_scope_hints"]
39582
39567
  }
@@ -39584,7 +39569,7 @@ ${end.comment}` : end.comment;
39584
39569
  {
39585
39570
  version: 55,
39586
39571
  name: "dreaming-state",
39587
- up: up56,
39572
+ up: up57,
39588
39573
  artifacts: {
39589
39574
  tables: ["dreaming_state", "dreaming_passes"]
39590
39575
  }
@@ -39592,22 +39577,22 @@ ${end.comment}` : end.comment;
39592
39577
  {
39593
39578
  version: 56,
39594
39579
  name: "agent-scoped-content-hash",
39595
- up: up57
39580
+ up: up58
39596
39581
  },
39597
39582
  {
39598
39583
  version: 57,
39599
39584
  name: "memories-fts-tokenizer-repair",
39600
- up: up58
39585
+ up: up59
39601
39586
  },
39602
39587
  {
39603
39588
  version: 58,
39604
39589
  name: "knowledge-graph-indices",
39605
- up: up59
39590
+ up: up60
39606
39591
  },
39607
39592
  {
39608
39593
  version: 59,
39609
39594
  name: "entity-attribute-claim-key",
39610
- up: up60,
39595
+ up: up61,
39611
39596
  artifacts: {
39612
39597
  columns: [{ table: "entity_attributes", column: "claim_key" }]
39613
39598
  }
@@ -39615,7 +39600,7 @@ ${end.comment}` : end.comment;
39615
39600
  {
39616
39601
  version: 60,
39617
39602
  name: "entity-attribute-group-key",
39618
- up: up61,
39603
+ up: up62,
39619
39604
  artifacts: {
39620
39605
  columns: [{ table: "entity_attributes", column: "group_key" }]
39621
39606
  }
@@ -39623,7 +39608,7 @@ ${end.comment}` : end.comment;
39623
39608
  {
39624
39609
  version: 61,
39625
39610
  name: "memory-artifact-source-mtime",
39626
- up: up62,
39611
+ up: up63,
39627
39612
  artifacts: {
39628
39613
  columns: [{ table: "memory_artifacts", column: "source_mtime_ms" }]
39629
39614
  }
@@ -39631,7 +39616,7 @@ ${end.comment}` : end.comment;
39631
39616
  {
39632
39617
  version: 62,
39633
39618
  name: "memory-artifact-soft-delete",
39634
- up: up63,
39619
+ up: up64,
39635
39620
  artifacts: {
39636
39621
  columns: [
39637
39622
  { table: "memory_artifacts", column: "is_deleted" },
@@ -39642,12 +39627,12 @@ ${end.comment}` : end.comment;
39642
39627
  {
39643
39628
  version: 63,
39644
39629
  name: "content-only-memories-fts-update",
39645
- up: up64
39630
+ up: up65
39646
39631
  },
39647
39632
  {
39648
39633
  version: 64,
39649
39634
  name: "source-graph-provenance",
39650
- up: up65,
39635
+ up: up66,
39651
39636
  artifacts: {
39652
39637
  columns: [
39653
39638
  { table: "entities", column: "source_path" },
@@ -39660,7 +39645,7 @@ ${end.comment}` : end.comment;
39660
39645
  {
39661
39646
  version: 65,
39662
39647
  name: "source-embedding-agent-scope",
39663
- up: up66,
39648
+ up: up67,
39664
39649
  artifacts: {
39665
39650
  columns: [{ table: "embeddings", column: "agent_id", optional: true }]
39666
39651
  }
@@ -39668,7 +39653,7 @@ ${end.comment}` : end.comment;
39668
39653
  {
39669
39654
  version: 66,
39670
39655
  name: "memory-search-telemetry",
39671
- up: up67,
39656
+ up: up68,
39672
39657
  artifacts: {
39673
39658
  tables: ["memory_search_telemetry"]
39674
39659
  }
@@ -39676,7 +39661,7 @@ ${end.comment}` : end.comment;
39676
39661
  {
39677
39662
  version: 67,
39678
39663
  name: "ontology-proposals",
39679
- up: up68,
39664
+ up: up69,
39680
39665
  artifacts: {
39681
39666
  tables: ["ontology_proposals"],
39682
39667
  columns: [
@@ -39690,7 +39675,7 @@ ${end.comment}` : end.comment;
39690
39675
  {
39691
39676
  version: 68,
39692
39677
  name: "daily-reflections",
39693
- up: up69,
39678
+ up: up70,
39694
39679
  artifacts: {
39695
39680
  tables: ["daily_reflections"]
39696
39681
  }
@@ -39698,7 +39683,7 @@ ${end.comment}` : end.comment;
39698
39683
  {
39699
39684
  version: 69,
39700
39685
  name: "daily-reflections-multiple-insights",
39701
- up: up70,
39686
+ up: up71,
39702
39687
  artifacts: {
39703
39688
  tables: ["daily_reflections"]
39704
39689
  }
@@ -39706,7 +39691,7 @@ ${end.comment}` : end.comment;
39706
39691
  {
39707
39692
  version: 70,
39708
39693
  name: "ontology-control-plane-state",
39709
- up: up71,
39694
+ up: up72,
39710
39695
  artifacts: {
39711
39696
  columns: [
39712
39697
  { table: "entities", column: "status" },
@@ -39721,7 +39706,7 @@ ${end.comment}` : end.comment;
39721
39706
  {
39722
39707
  version: 71,
39723
39708
  name: "epistemic-assertions",
39724
- up: up72,
39709
+ up: up73,
39725
39710
  artifacts: {
39726
39711
  tables: ["epistemic_assertions"]
39727
39712
  }
@@ -39729,7 +39714,7 @@ ${end.comment}` : end.comment;
39729
39714
  {
39730
39715
  version: 72,
39731
39716
  name: "agent-scoped-idempotency-key",
39732
- up: up73,
39717
+ up: up74,
39733
39718
  artifacts: {
39734
39719
  columns: [
39735
39720
  { table: "memories", column: "idempotency_key" },
@@ -39740,7 +39725,7 @@ ${end.comment}` : end.comment;
39740
39725
  {
39741
39726
  version: 73,
39742
39727
  name: "recall-context-dedupe",
39743
- up: up74,
39728
+ up: up75,
39744
39729
  artifacts: {
39745
39730
  tables: ["session_context_epochs", "session_recall_events"]
39746
39731
  }
@@ -39748,7 +39733,7 @@ ${end.comment}` : end.comment;
39748
39733
  {
39749
39734
  version: 74,
39750
39735
  name: "aggregate-memory-links",
39751
- up: up75,
39736
+ up: up76,
39752
39737
  artifacts: {
39753
39738
  tables: ["aggregate_memory_sources"]
39754
39739
  }
@@ -39756,7 +39741,7 @@ ${end.comment}` : end.comment;
39756
39741
  {
39757
39742
  version: 75,
39758
39743
  name: "memory-artifact-source-provenance",
39759
- up: up76,
39744
+ up: up77,
39760
39745
  artifacts: {
39761
39746
  columns: [
39762
39747
  { table: "memory_artifacts", column: "source_id" },
@@ -39770,7 +39755,7 @@ ${end.comment}` : end.comment;
39770
39755
  {
39771
39756
  version: 76,
39772
39757
  name: "temporal-edges",
39773
- up: up77,
39758
+ up: up78,
39774
39759
  artifacts: {
39775
39760
  tables: ["temporal_edges"]
39776
39761
  }
@@ -39778,7 +39763,7 @@ ${end.comment}` : end.comment;
39778
39763
  {
39779
39764
  version: 77,
39780
39765
  name: "entity-aliases",
39781
- up: up78,
39766
+ up: up79,
39782
39767
  artifacts: {
39783
39768
  tables: ["entity_aliases"]
39784
39769
  }
@@ -39786,7 +39771,7 @@ ${end.comment}` : end.comment;
39786
39771
  {
39787
39772
  version: 78,
39788
39773
  name: "api-keys",
39789
- up: up79,
39774
+ up: up80,
39790
39775
  artifacts: {
39791
39776
  tables: ["api_keys"]
39792
39777
  }
@@ -39794,7 +39779,7 @@ ${end.comment}` : end.comment;
39794
39779
  {
39795
39780
  version: 79,
39796
39781
  name: "transcript-capture-jobs",
39797
- up: up80,
39782
+ up: up81,
39798
39783
  artifacts: {
39799
39784
  tables: ["transcript_capture_jobs"]
39800
39785
  }
@@ -39802,7 +39787,7 @@ ${end.comment}` : end.comment;
39802
39787
  {
39803
39788
  version: 80,
39804
39789
  name: "document-scope-columns",
39805
- up: up81,
39790
+ up: up82,
39806
39791
  artifacts: {
39807
39792
  columns: [
39808
39793
  { table: "documents", column: "agent_id" },
@@ -39813,7 +39798,7 @@ ${end.comment}` : end.comment;
39813
39798
  {
39814
39799
  version: 81,
39815
39800
  name: "aggregate-evidence-sources",
39816
- up: up82,
39801
+ up: up83,
39817
39802
  artifacts: {
39818
39803
  tables: ["aggregate_evidence_sources"]
39819
39804
  }
@@ -39821,7 +39806,7 @@ ${end.comment}` : end.comment;
39821
39806
  {
39822
39807
  version: 82,
39823
39808
  name: "skill-invocations-harness",
39824
- up: up83,
39809
+ up: up84,
39825
39810
  artifacts: {
39826
39811
  columns: [
39827
39812
  { table: "skill_invocations", column: "harness" },
@@ -39832,7 +39817,7 @@ ${end.comment}` : end.comment;
39832
39817
  {
39833
39818
  version: 83,
39834
39819
  name: "memory-lifecycle-repair",
39835
- up: up84,
39820
+ up: up85,
39836
39821
  artifacts: {
39837
39822
  tables: ["transcript_capture_jobs", "aggregate_evidence_sources", "entity_dependencies"],
39838
39823
  columns: [
@@ -39847,7 +39832,7 @@ ${end.comment}` : end.comment;
39847
39832
  {
39848
39833
  version: 84,
39849
39834
  name: "legacy-markdown-import-state",
39850
- up: up85,
39835
+ up: up86,
39851
39836
  artifacts: {
39852
39837
  tables: ["legacy_markdown_imports", "legacy_markdown_chunks"]
39853
39838
  }
@@ -39855,7 +39840,7 @@ ${end.comment}` : end.comment;
39855
39840
  {
39856
39841
  version: 85,
39857
39842
  name: "backfill-relations-to-dependencies",
39858
- up: up86,
39843
+ up: up87,
39859
39844
  artifacts: {
39860
39845
  tables: ["entity_dependencies"]
39861
39846
  }
@@ -39863,7 +39848,7 @@ ${end.comment}` : end.comment;
39863
39848
  {
39864
39849
  version: 86,
39865
39850
  name: "summary-jobs-content-hash",
39866
- up: up87,
39851
+ up: up88,
39867
39852
  artifacts: {
39868
39853
  columns: [{ table: "summary_jobs", column: "content_hash" }]
39869
39854
  }
@@ -39871,7 +39856,7 @@ ${end.comment}` : end.comment;
39871
39856
  {
39872
39857
  version: 87,
39873
39858
  name: "summary-jobs-boundary-reason",
39874
- up: up88,
39859
+ up: up89,
39875
39860
  artifacts: {
39876
39861
  columns: [{ table: "summary_jobs", column: "boundary_reason" }]
39877
39862
  }
@@ -39879,7 +39864,7 @@ ${end.comment}` : end.comment;
39879
39864
  {
39880
39865
  version: 88,
39881
39866
  name: "transcript-recovery-files",
39882
- up: up89,
39867
+ up: up90,
39883
39868
  artifacts: {
39884
39869
  tables: ["transcript_recovery_files"]
39885
39870
  }
@@ -39887,7 +39872,7 @@ ${end.comment}` : end.comment;
39887
39872
  {
39888
39873
  version: 89,
39889
39874
  name: "job-cancellations",
39890
- up: up90,
39875
+ up: up91,
39891
39876
  artifacts: {
39892
39877
  tables: ["job_cancellations"]
39893
39878
  }
@@ -39895,7 +39880,7 @@ ${end.comment}` : end.comment;
39895
39880
  {
39896
39881
  version: 90,
39897
39882
  name: "job-archive",
39898
- up: up91,
39883
+ up: up92,
39899
39884
  artifacts: {
39900
39885
  tables: ["job_archive"]
39901
39886
  }
@@ -39903,25 +39888,25 @@ ${end.comment}` : end.comment;
39903
39888
  {
39904
39889
  version: 91,
39905
39890
  name: "embedding-index-generations",
39906
- up: up92,
39891
+ up: up93,
39907
39892
  artifacts: { tables: ["embedding_index_state"] }
39908
39893
  },
39909
39894
  {
39910
39895
  version: 92,
39911
39896
  name: "embedding-staging-store",
39912
- up: up93,
39897
+ up: up94,
39913
39898
  artifacts: { tables: ["embeddings_staging"] }
39914
39899
  },
39915
39900
  {
39916
39901
  version: 93,
39917
39902
  name: "dreaming-evidence-cursor",
39918
- up: up94,
39903
+ up: up95,
39919
39904
  artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
39920
39905
  },
39921
39906
  {
39922
39907
  version: 94,
39923
39908
  name: "memory-kind",
39924
- up: up95,
39909
+ up: up96,
39925
39910
  artifacts: {
39926
39911
  columns: [
39927
39912
  { table: "memories", column: "memory_kind" },
@@ -39932,35 +39917,35 @@ ${end.comment}` : end.comment;
39932
39917
  {
39933
39918
  version: 95,
39934
39919
  name: "compaction-recall-projections",
39935
- up: up96
39920
+ up: up97
39936
39921
  },
39937
39922
  {
39938
39923
  version: 96,
39939
39924
  name: "retire-legacy-ingestion",
39940
- up: up97
39925
+ up: up98
39941
39926
  },
39942
39927
  {
39943
39928
  version: 97,
39944
39929
  name: "dreaming-failure-backoff",
39945
- up: up98,
39930
+ up: up99,
39946
39931
  artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
39947
39932
  },
39948
39933
  {
39949
39934
  version: 98,
39950
39935
  name: "dreaming-evidence-exclusions",
39951
- up: up99,
39936
+ up: up100,
39952
39937
  artifacts: { tables: ["dreaming_evidence_exclusions"] }
39953
39938
  },
39954
39939
  {
39955
39940
  version: 99,
39956
39941
  name: "dreaming-tool-calls",
39957
- up: up100,
39942
+ up: up101,
39958
39943
  artifacts: { tables: ["dreaming_tool_calls"] }
39959
39944
  },
39960
39945
  {
39961
39946
  version: 100,
39962
39947
  name: "dreaming-runbook",
39963
- up: up101,
39948
+ up: up102,
39964
39949
  artifacts: {
39965
39950
  columns: [
39966
39951
  { table: "dreaming_passes", column: "evidence_window_json" },
@@ -39971,23 +39956,23 @@ ${end.comment}` : end.comment;
39971
39956
  {
39972
39957
  version: 101,
39973
39958
  name: "dreaming-attention",
39974
- up: up102,
39959
+ up: up103,
39975
39960
  artifacts: { tables: ["dreaming_attention"] }
39976
39961
  },
39977
39962
  {
39978
39963
  version: 102,
39979
39964
  name: "attribute-semantic-memories",
39980
- up: up103
39965
+ up: up104
39981
39966
  },
39982
39967
  {
39983
39968
  version: 103,
39984
39969
  name: "semantic-memory-kind",
39985
- up: up104
39970
+ up: up105
39986
39971
  },
39987
39972
  {
39988
39973
  version: 104,
39989
39974
  name: "derived-memory-provenance",
39990
- up: up105,
39975
+ up: up106,
39991
39976
  artifacts: {
39992
39977
  tables: ["derived_memory_sources"],
39993
39978
  columns: [{ table: "memories", column: "stale_at" }]
@@ -39996,12 +39981,12 @@ ${end.comment}` : end.comment;
39996
39981
  {
39997
39982
  version: 105,
39998
39983
  name: "agent-scoped-entity-name",
39999
- up: up106
39984
+ up: up107
40000
39985
  },
40001
39986
  {
40002
39987
  version: 106,
40003
39988
  name: "memory-review-after",
40004
- up: up107,
39989
+ up: up108,
40005
39990
  artifacts: {
40006
39991
  columns: [{ table: "memories", column: "review_after" }]
40007
39992
  }
@@ -40009,7 +39994,7 @@ ${end.comment}` : end.comment;
40009
39994
  {
40010
39995
  version: 107,
40011
39996
  name: "dreaming-pass-usage",
40012
- up: up108,
39997
+ up: up109,
40013
39998
  artifacts: {
40014
39999
  columns: [
40015
40000
  { table: "dreaming_passes", column: "tokens_input" },
@@ -40023,7 +40008,7 @@ ${end.comment}` : end.comment;
40023
40008
  {
40024
40009
  version: 108,
40025
40010
  name: "embedding-usage",
40026
- up: up109,
40011
+ up: up110,
40027
40012
  artifacts: {
40028
40013
  tables: ["embedding_usage"]
40029
40014
  }
@@ -40031,7 +40016,7 @@ ${end.comment}` : end.comment;
40031
40016
  {
40032
40017
  version: 109,
40033
40018
  name: "telemetry-install",
40034
- up: up110,
40019
+ up: up111,
40035
40020
  artifacts: {
40036
40021
  tables: ["telemetry_install"]
40037
40022
  }
@@ -40039,12 +40024,12 @@ ${end.comment}` : end.comment;
40039
40024
  {
40040
40025
  version: 110,
40041
40026
  name: "memory-mention-join-index",
40042
- up: up111
40027
+ up: up112
40043
40028
  },
40044
40029
  {
40045
40030
  version: 111,
40046
40031
  name: "telemetry-first-use",
40047
- up: up112,
40032
+ up: up113,
40048
40033
  artifacts: {
40049
40034
  columns: [
40050
40035
  { table: "telemetry_install", column: "first_remember_at" },
@@ -40055,7 +40040,7 @@ ${end.comment}` : end.comment;
40055
40040
  {
40056
40041
  version: 112,
40057
40042
  name: "telemetry-queue-ownership",
40058
- up: up113,
40043
+ up: up114,
40059
40044
  artifacts: {
40060
40045
  columns: [
40061
40046
  { table: "telemetry_events", column: "source" },
@@ -40067,7 +40052,7 @@ ${end.comment}` : end.comment;
40067
40052
  {
40068
40053
  version: 113,
40069
40054
  name: "session-claims",
40070
- up: up114,
40055
+ up: up115,
40071
40056
  artifacts: {
40072
40057
  tables: ["session_claims"],
40073
40058
  columns: [
@@ -40081,12 +40066,12 @@ ${end.comment}` : end.comment;
40081
40066
  {
40082
40067
  version: 114,
40083
40068
  name: "memory-traversal-hydration-index",
40084
- up: up115
40069
+ up: up116
40085
40070
  },
40086
40071
  {
40087
40072
  version: 115,
40088
40073
  name: "cross-agent-message-notifications",
40089
- up: up116,
40074
+ up: up117,
40090
40075
  artifacts: {
40091
40076
  tables: ["cross_agent_messages", "cross_agent_message_receipts"]
40092
40077
  }
@@ -40094,7 +40079,7 @@ ${end.comment}` : end.comment;
40094
40079
  {
40095
40080
  version: 116,
40096
40081
  name: "acp-delivery-reconciliation",
40097
- up: up117,
40082
+ up: up118,
40098
40083
  artifacts: {
40099
40084
  columns: [
40100
40085
  { table: "cross_agent_messages", column: "delivery_state" },
@@ -40108,7 +40093,7 @@ ${end.comment}` : end.comment;
40108
40093
  {
40109
40094
  version: 117,
40110
40095
  name: "retire-summary-worker",
40111
- up: up118,
40096
+ up: up119,
40112
40097
  artifacts: {
40113
40098
  columns: [
40114
40099
  { table: "session_transcripts", column: "completed_at" },
@@ -40119,24 +40104,24 @@ ${end.comment}` : end.comment;
40119
40104
  {
40120
40105
  version: 118,
40121
40106
  name: "queue-pressure-indices",
40122
- up: up119
40107
+ up: up120
40123
40108
  },
40124
40109
  {
40125
40110
  version: 119,
40126
40111
  name: "telemetry-version-observation",
40127
- up: up120,
40112
+ up: up121,
40128
40113
  artifacts: { columns: [{ table: "telemetry_install", column: "last_seen_version" }] }
40129
40114
  },
40130
40115
  {
40131
40116
  version: 120,
40132
40117
  name: "source-lifecycle-telemetry",
40133
- up: up121,
40118
+ up: up122,
40134
40119
  artifacts: { tables: ["source_lifecycle_state"] }
40135
40120
  },
40136
40121
  {
40137
40122
  version: 121,
40138
40123
  name: "telemetry-delivery-health",
40139
- up: up122,
40124
+ up: up123,
40140
40125
  artifacts: {
40141
40126
  tables: ["telemetry_delivery_state"],
40142
40127
  columns: [
@@ -40150,7 +40135,7 @@ ${end.comment}` : end.comment;
40150
40135
  {
40151
40136
  version: 122,
40152
40137
  name: "dreaming-evidence-retry",
40153
- up: up123,
40138
+ up: up124,
40154
40139
  artifacts: {
40155
40140
  columns: [
40156
40141
  { table: "dreaming_evidence_exclusions", column: "failure_class" },
@@ -40163,13 +40148,13 @@ ${end.comment}` : end.comment;
40163
40148
  {
40164
40149
  version: 123,
40165
40150
  name: "embedding-index-failures",
40166
- up: up124,
40151
+ up: up125,
40167
40152
  artifacts: { tables: ["embedding_index_failures"] }
40168
40153
  },
40169
40154
  {
40170
40155
  version: 124,
40171
40156
  name: "import-derived-lifecycle",
40172
- up: up125,
40157
+ up: up126,
40173
40158
  artifacts: {
40174
40159
  tables: ["imported_source_lifecycle"]
40175
40160
  }
@@ -40177,77 +40162,77 @@ ${end.comment}` : end.comment;
40177
40162
  {
40178
40163
  version: 125,
40179
40164
  name: "memory-content-safety",
40180
- up: up126,
40165
+ up: up127,
40181
40166
  artifacts: { tables: ["memory_content_safety"] }
40182
40167
  },
40183
40168
  {
40184
40169
  version: 126,
40185
40170
  name: "dreaming-surprisal-attention",
40186
- up: up127,
40171
+ up: up128,
40187
40172
  artifacts: { tables: ["dreaming_attention"] }
40188
40173
  },
40189
40174
  {
40190
40175
  version: 127,
40191
40176
  name: "ontology-contradictions",
40192
- up: up128,
40177
+ up: up129,
40193
40178
  artifacts: { tables: ["ontology_contradictions"] }
40194
40179
  },
40195
40180
  {
40196
40181
  version: 128,
40197
40182
  name: "bounded-queue-diagnostics",
40198
- up: up129
40183
+ up: up130
40199
40184
  },
40200
40185
  {
40201
40186
  version: 129,
40202
40187
  name: "retire-structural-jobs",
40203
- up: up130
40188
+ up: up131
40204
40189
  },
40205
40190
  {
40206
40191
  version: 130,
40207
40192
  name: "embedding-repair-state",
40208
- up: up131,
40193
+ up: up132,
40209
40194
  artifacts: { tables: ["embedding_repair_budget", "embedding_repair_backoff"] }
40210
40195
  },
40211
40196
  {
40212
40197
  version: 131,
40213
40198
  name: "dreaming-evidence-consumption",
40214
- up: up132,
40199
+ up: up133,
40215
40200
  artifacts: { tables: ["dreaming_evidence_consumption"] }
40216
40201
  },
40217
40202
  {
40218
40203
  version: 132,
40219
40204
  name: "observer-scoped-epistemic-assertions",
40220
- up: up133,
40205
+ up: up134,
40221
40206
  artifacts: { tables: ["epistemic_assertions"] }
40222
40207
  },
40223
40208
  {
40224
40209
  version: 133,
40225
40210
  name: "dreaming-memory-head",
40226
- up: up134,
40211
+ up: up135,
40227
40212
  artifacts: { tables: ["memory_head_revisions", "memory_head_entries", "memory_head_revision_entries"] }
40228
40213
  },
40229
40214
  {
40230
40215
  version: 134,
40231
40216
  name: "scope-memory-head-entries",
40232
- up: up135,
40217
+ up: up136,
40233
40218
  artifacts: { tables: ["memory_head_entries"] }
40234
40219
  },
40235
40220
  {
40236
40221
  version: 135,
40237
40222
  name: "memory-head-publication",
40238
- up: up136,
40223
+ up: up137,
40239
40224
  artifacts: { tables: ["memory_head_publications"] }
40240
40225
  },
40241
40226
  {
40242
40227
  version: 136,
40243
40228
  name: "memory-head-revisions",
40244
- up: up137,
40229
+ up: up138,
40245
40230
  artifacts: { tables: ["memory_head_revisions"] }
40246
40231
  },
40247
40232
  {
40248
40233
  version: 137,
40249
40234
  name: "dreaming-head-manifest",
40250
- up: up138,
40235
+ up: up139,
40251
40236
  artifacts: {
40252
40237
  columns: [
40253
40238
  { table: "dreaming_passes", column: "head_revision" },
@@ -40258,7 +40243,7 @@ ${end.comment}` : end.comment;
40258
40243
  {
40259
40244
  version: 138,
40260
40245
  name: "bounded-status-projections",
40261
- up: up139,
40246
+ up: up140,
40262
40247
  artifacts: {
40263
40248
  tables: ["transcript_capture_status", "memories_duplicate_hash_counts", "memories_diagnostics_state"]
40264
40249
  }
@@ -40266,31 +40251,31 @@ ${end.comment}` : end.comment;
40266
40251
  {
40267
40252
  version: 139,
40268
40253
  name: "native-source-sync-state",
40269
- up: up140,
40254
+ up: up141,
40270
40255
  artifacts: { tables: ["native_source_sync_state"] }
40271
40256
  },
40272
40257
  {
40273
40258
  version: 140,
40274
40259
  name: "transcript-recovery-frontier",
40275
- up: up141,
40260
+ up: up142,
40276
40261
  artifacts: { tables: ["transcript_recovery_frontiers"] }
40277
40262
  },
40278
40263
  {
40279
40264
  version: 141,
40280
40265
  name: "source-sync-checkpoints",
40281
- up: up142,
40266
+ up: up143,
40282
40267
  artifacts: { tables: ["source_sync_checkpoints"] }
40283
40268
  },
40284
40269
  {
40285
40270
  version: 142,
40286
40271
  name: "source-sync-frontier",
40287
- up: up143,
40272
+ up: up144,
40288
40273
  artifacts: { columns: [{ table: "source_sync_checkpoints", column: "frontier" }] }
40289
40274
  },
40290
40275
  {
40291
40276
  version: 143,
40292
40277
  name: "embedding-index-progress",
40293
- up: up144,
40278
+ up: up145,
40294
40279
  artifacts: {
40295
40280
  columns: [
40296
40281
  { table: "embedding_index_state", column: "migration_phase" },
@@ -40306,19 +40291,19 @@ ${end.comment}` : end.comment;
40306
40291
  {
40307
40292
  version: 144,
40308
40293
  name: "memory-job-lease-token",
40309
- up: up145,
40294
+ up: up146,
40310
40295
  artifacts: { columns: [{ table: "memory_jobs", column: "lease_token" }] }
40311
40296
  },
40312
40297
  {
40313
40298
  version: 145,
40314
40299
  name: "dreaming-evidence-reviews",
40315
- up: up146,
40300
+ up: up147,
40316
40301
  artifacts: { tables: ["dreaming_evidence_reviews"] }
40317
40302
  },
40318
40303
  {
40319
40304
  version: 146,
40320
40305
  name: "source-transcript-import",
40321
- up: up147,
40306
+ up: up148,
40322
40307
  artifacts: {
40323
40308
  tables: [
40324
40309
  "source_import_jobs",
@@ -40337,19 +40322,19 @@ ${end.comment}` : end.comment;
40337
40322
  {
40338
40323
  version: 147,
40339
40324
  name: "source-import-replay-file-slots",
40340
- up: up148,
40325
+ up: up149,
40341
40326
  artifacts: { tables: ["source_import_files"] }
40342
40327
  },
40343
40328
  {
40344
40329
  version: 148,
40345
40330
  name: "source-import-attempt-provenance",
40346
- up: up149,
40331
+ up: up150,
40347
40332
  artifacts: { columns: [{ table: "source_import_record_attempts", column: "source_id" }] }
40348
40333
  },
40349
40334
  {
40350
40335
  version: 149,
40351
40336
  name: "transcript-import-state-machine",
40352
- up: up150,
40337
+ up: up151,
40353
40338
  artifacts: {
40354
40339
  columns: [
40355
40340
  { table: "source_import_jobs", column: "duplicate_mode" },
@@ -40361,7 +40346,7 @@ ${end.comment}` : end.comment;
40361
40346
  {
40362
40347
  version: 150,
40363
40348
  name: "memory-head-freshness",
40364
- up: up151,
40349
+ up: up152,
40365
40350
  artifacts: {
40366
40351
  columns: [
40367
40352
  { table: "memory_md_heads", column: "is_current" },
@@ -40397,6 +40382,12 @@ ${end.comment}` : end.comment;
40397
40382
  }))
40398
40383
  ]
40399
40384
  }
40385
+ },
40386
+ {
40387
+ version: 152,
40388
+ name: "memory-artifact-sha-index",
40389
+ up: up2,
40390
+ artifacts: { indexes: ["idx_memory_artifacts_agent_sha"] }
40400
40391
  }
40401
40392
  ];
40402
40393
  LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -43564,10 +43555,15 @@ function verifyMigrationArtifacts(writeConn, auditHighWaterMark) {
43564
43555
  for (const migration of MIGRATIONS) {
43565
43556
  if (!appliedVersions2.has(migration.version))
43566
43557
  continue;
43567
- for (const table of migration.artifacts?.tables ?? []) {
43568
- const row = writeConn.prepare("SELECT 1 AS present FROM sqlite_schema WHERE name = ? LIMIT 1").get(table);
43569
- if (row === undefined)
43570
- missing.push(`table ${table} (migration ${migration.version})`);
43558
+ for (const [type, names] of [
43559
+ ["table", migration.artifacts?.tables],
43560
+ ["index", migration.artifacts?.indexes]
43561
+ ]) {
43562
+ for (const name of names ?? []) {
43563
+ const row = writeConn.prepare("SELECT 1 AS present FROM sqlite_schema WHERE type = ? AND name = ? LIMIT 1").get(type, name);
43564
+ if (row === undefined)
43565
+ missing.push(`${type} ${name} (migration ${migration.version})`);
43566
+ }
43571
43567
  }
43572
43568
  for (const column of migration.artifacts?.columns ?? []) {
43573
43569
  const rows = writeConn.prepare(`PRAGMA table_info(${JSON.stringify(column.table)})`).all();
@@ -56230,7 +56226,8 @@ function findEpisodicSourceAgentIds(db, from) {
56230
56226
  function searchEpisodicSources(db, params) {
56231
56227
  const query = params.query.trim();
56232
56228
  const limit = params.limit === null ? null : Math.max(1, Math.min(Math.floor(params.limit ?? 20), 51));
56233
- const like = `%${query}%`;
56229
+ const contentPredicate = (column) => `((? = '' AND ${column} IS NOT NULL) OR ${column} LIKE ?)`;
56230
+ const contentArgs = [query, `%${query}%`];
56234
56231
  const sinceArgs = params.since !== undefined ? [params.since, EPISODIC_CAPTURED_AT_FLOOR] : [];
56235
56232
  const beforeArgs = params.before !== undefined ? [params.before] : [];
56236
56233
  const deliveredFilterEnabled = params.excludeDelivered === true && db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_evidence_consumption'").get() != null;
@@ -56254,6 +56251,7 @@ function searchEpisodicSources(db, params) {
56254
56251
  const transcriptHasCompletedAt = tableHasColumn2(db, "session_transcripts", "completed_at");
56255
56252
  const transcriptSearchTime = transcriptHasCompletedAt ? transcriptHasUpdatedAt ? "COALESCE(session_transcripts.completed_at, session_transcripts.updated_at, session_transcripts.created_at)" : "COALESCE(session_transcripts.completed_at, session_transcripts.created_at)" : transcriptHasUpdatedAt ? "COALESCE(session_transcripts.updated_at, session_transcripts.created_at)" : "session_transcripts.created_at";
56256
56253
  const transcriptCompleted = transcriptHasCompletedAt ? "session_transcripts.completed_at IS NOT NULL" : "0";
56254
+ const commonArgs = [params.agentId, ...contentArgs, ...sinceArgs, ...beforeArgs, ...deliveredArgs, ...reviewedArgs];
56257
56255
  const branches = [];
56258
56256
  if (params.kind === undefined || params.kind === "memory") {
56259
56257
  branches.push({
@@ -56261,12 +56259,12 @@ function searchEpisodicSources(db, params) {
56261
56259
  FROM memories
56262
56260
  WHERE agent_id = ? AND memory_kind = 'episodic'
56263
56261
  AND COALESCE(is_deleted, 0) = 0 AND visibility != 'archived' AND scope IS NULL
56264
- AND COALESCE(type, '') != 'session_summary' AND content LIKE ?
56262
+ AND COALESCE(type, '') != 'session_summary' AND ${contentPredicate("content")}
56265
56263
  ${params.since ? "AND (julianday(created_at) >= julianday(?) OR julianday(created_at) < julianday(?))" : ""}
56266
56264
  ${params.before ? "AND julianday(created_at) <= julianday(?)" : ""}
56267
56265
  ${deliveredPredicate("memory", "id", "created_at", "''", "created_at")}
56268
56266
  ${reviewedPredicate("memory", "id", "created_at", "''", "created_at")}`,
56269
- args: [params.agentId, like, ...sinceArgs, ...beforeArgs, ...deliveredArgs, ...reviewedArgs]
56267
+ args: commonArgs
56270
56268
  });
56271
56269
  }
56272
56270
  if (params.kind === undefined || params.kind === "artifact") {
@@ -56274,33 +56272,33 @@ function searchEpisodicSources(db, params) {
56274
56272
  sql: `SELECT 'artifact' AS kind, ma.source_path AS id, ma.captured_at AS captured_at
56275
56273
  FROM memory_artifacts ma
56276
56274
  WHERE ma.agent_id = ? AND COALESCE(ma.is_deleted, 0) = 0
56277
- AND length(ma.content) > 0 AND ma.content LIKE ?
56275
+ AND length(ma.content) > 0 AND ${contentPredicate("ma.content")}
56278
56276
  ${params.since ? "AND (julianday(ma.captured_at) >= julianday(?) OR julianday(ma.captured_at) < julianday(?))" : ""}
56279
56277
  ${params.before ? "AND julianday(ma.captured_at) <= julianday(?)" : ""}
56280
56278
  ${deliveredPredicate("artifact", "ma.source_path", "ma.captured_at", "COALESCE(ma.source_id, '')", "CASE WHEN ma.source_sha256 IS NULL OR ma.source_sha256 = '' THEN ma.captured_at ELSE ma.source_sha256 END")}
56281
56279
  ${reviewedPredicate("artifact", "ma.source_path", "ma.captured_at", "COALESCE(ma.source_id, '')", "CASE WHEN ma.source_sha256 IS NULL OR ma.source_sha256 = '' THEN ma.captured_at ELSE ma.source_sha256 END")}
56282
56280
  AND (ma.source_sha256 IS NULL OR ma.source_sha256 = ''
56283
- OR (ma.agent_id, ma.source_path) = (
56284
- SELECT ma2.agent_id, ma2.source_path FROM memory_artifacts ma2
56281
+ OR ma.source_path = (
56282
+ SELECT ma2.source_path FROM memory_artifacts ma2
56285
56283
  WHERE ma2.agent_id = ma.agent_id AND COALESCE(ma2.is_deleted, 0) = 0
56286
56284
  AND ma2.source_sha256 = ma.source_sha256
56287
56285
  AND COALESCE(ma2.source_id, '') = COALESCE(ma.source_id, '')
56288
56286
  ORDER BY ma2.captured_at DESC, ma2.source_path ASC
56289
56287
  LIMIT 1
56290
56288
  ))`,
56291
- args: [params.agentId, like, ...sinceArgs, ...beforeArgs, ...deliveredArgs, ...reviewedArgs]
56289
+ args: commonArgs
56292
56290
  });
56293
56291
  }
56294
56292
  if (params.kind === undefined || params.kind === "transcript") {
56295
56293
  branches.push({
56296
56294
  sql: `SELECT 'transcript' AS kind, session_key AS id, ${transcriptSearchTime} AS captured_at
56297
56295
  FROM session_transcripts
56298
- WHERE agent_id = ? AND ${transcriptCompleted} AND content LIKE ?
56296
+ WHERE agent_id = ? AND ${transcriptCompleted} AND ${contentPredicate("session_transcripts.content")}
56299
56297
  ${params.since ? `AND (julianday(${transcriptSearchTime}) >= julianday(?) OR julianday(${transcriptSearchTime}) < julianday(?))` : ""}
56300
56298
  ${params.before ? `AND julianday(${transcriptSearchTime}) <= julianday(?)` : ""}
56301
56299
  ${deliveredPredicate("transcript", "session_key", transcriptSearchTime, "''", transcriptSearchTime)}
56302
56300
  ${reviewedPredicate("transcript", "session_key", transcriptSearchTime, "''", transcriptSearchTime)}`,
56303
- args: [params.agentId, like, ...sinceArgs, ...beforeArgs, ...deliveredArgs, ...reviewedArgs]
56301
+ args: commonArgs
56304
56302
  });
56305
56303
  }
56306
56304
  if (params.kind === "summary") {
@@ -56309,12 +56307,12 @@ function searchEpisodicSources(db, params) {
56309
56307
  FROM session_summaries
56310
56308
  WHERE agent_id = ? AND depth = 0
56311
56309
  AND COALESCE(source_type, 'summary') IN ('summary', 'compaction', 'checkpoint')
56312
- AND content LIKE ?
56310
+ AND ${contentPredicate("content")}
56313
56311
  ${params.since ? "AND (julianday(latest_at) >= julianday(?) OR julianday(latest_at) < julianday(?))" : ""}
56314
56312
  ${params.before ? "AND julianday(latest_at) <= julianday(?)" : ""}
56315
56313
  ${deliveredPredicate("summary", "id", "latest_at", "''", "latest_at")}
56316
56314
  ${reviewedPredicate("summary", "id", "latest_at", "''", "latest_at")}`,
56317
- args: [params.agentId, like, ...sinceArgs, ...beforeArgs, ...deliveredArgs, ...reviewedArgs]
56315
+ args: commonArgs
56318
56316
  });
56319
56317
  }
56320
56318
  const union3 = branches.map((branch) => branch.sql).join(`
@@ -56336,8 +56334,7 @@ init_db_accessor();
56336
56334
 
56337
56335
  // ../../platform/daemon/src/pipeline/dreaming-token-cache.ts
56338
56336
  import { existsSync as existsSync12 } from "node:fs";
56339
- import { join as join14 } from "node:path";
56340
- import { dirname as dirname11 } from "node:path";
56337
+ import { dirname as dirname11, join as join14 } from "node:path";
56341
56338
  import { fileURLToPath as fileURLToPath3 } from "node:url";
56342
56339
  import { Worker } from "node:worker_threads";
56343
56340
 
@@ -56387,42 +56384,81 @@ function addTokenCounts(total, count) {
56387
56384
  function requestKey(kind, agentId, entries, stopAt) {
56388
56385
  return JSON.stringify([kind, agentId, entries.map((entry) => [entry.key, entry.revision]), stopAt]);
56389
56386
  }
56387
+ var DREAMING_BACKLOG_CACHE_MAX_AGE_MS = 60000;
56390
56388
 
56391
56389
  class DreamingBacklogTokenCache {
56392
56390
  values = new Map;
56393
56391
  entries = new Map;
56392
+ generations = new Map;
56393
+ lifecycleGeneration = 0;
56394
56394
  exactInflight = new Map;
56395
56395
  batchInflight = new Map;
56396
56396
  tails = new Map;
56397
56397
  workers = new Set;
56398
56398
  async replaceExactSnapshot(agentId, entries) {
56399
56399
  const key = requestKey("exact", agentId, entries);
56400
- return await this.enqueue(agentId, key, this.exactInflight, async () => await this.replaceExactSnapshotNow(agentId, entries));
56400
+ const measurement = this.beginMeasurement(agentId);
56401
+ return await this.enqueue(agentId, key, this.exactInflight, async () => await this.replaceExactSnapshotNow(agentId, entries, measurement));
56401
56402
  }
56402
56403
  async countEntries(agentId, entries, stopAtTokens) {
56403
56404
  const stopAt = stopAtTokens === undefined ? undefined : ensureTokenCount(stopAtTokens, "Dreaming token stop limit");
56404
56405
  const key = requestKey("batch", agentId, entries, stopAt);
56405
- return await this.enqueue(agentId, key, this.batchInflight, async () => await this.countEntriesNow(agentId, entries, stopAt));
56406
+ const lifecycleGeneration = this.lifecycleGeneration;
56407
+ return await this.enqueue(agentId, key, this.batchInflight, async () => await this.countEntriesNow(agentId, entries, stopAt, lifecycleGeneration));
56408
+ }
56409
+ beginMeasurement(agentId) {
56410
+ return {
56411
+ generation: this.generationFor(agentId),
56412
+ lifecycleGeneration: this.lifecycleGeneration
56413
+ };
56414
+ }
56415
+ generationFor(agentId) {
56416
+ return this.generations.get(agentId) ?? 0;
56417
+ }
56418
+ isCurrent(agentId, measurement) {
56419
+ return measurement.lifecycleGeneration === this.lifecycleGeneration && measurement.generation === this.generationFor(agentId);
56406
56420
  }
56407
56421
  get(agentId) {
56408
- return this.values.get(agentId) ?? 0;
56422
+ return this.getFresh(agentId) ?? 0;
56423
+ }
56424
+ getFresh(agentId) {
56425
+ const cached2 = this.values.get(agentId);
56426
+ if (cached2 === undefined)
56427
+ return null;
56428
+ if (Date.now() - cached2.measuredAtMs > DREAMING_BACKLOG_CACHE_MAX_AGE_MS) {
56429
+ this.values.delete(agentId);
56430
+ return null;
56431
+ }
56432
+ return cached2.count;
56409
56433
  }
56410
- recordExactTotal(agentId, count) {
56411
- this.values.set(agentId, ensureTokenCount(count, "Dreaming exact token total"));
56434
+ recordExactTotal(agentId, count, measurement = this.beginMeasurement(agentId)) {
56435
+ if (!this.isCurrent(agentId, measurement))
56436
+ return;
56437
+ this.values.set(agentId, {
56438
+ count: ensureTokenCount(count, "Dreaming exact token total"),
56439
+ measuredAtMs: Date.now()
56440
+ });
56412
56441
  }
56413
- hasValue(agentId) {
56414
- return this.values.has(agentId);
56442
+ invalidate(agentId) {
56443
+ this.values.delete(agentId);
56444
+ this.generations.set(agentId, this.generationFor(agentId) + 1);
56415
56445
  }
56416
56446
  stop() {
56447
+ this.lifecycleGeneration += 1;
56417
56448
  for (const worker of this.workers)
56418
56449
  worker.terminate();
56419
56450
  this.workers.clear();
56420
56451
  this.exactInflight.clear();
56421
56452
  this.batchInflight.clear();
56422
56453
  this.tails.clear();
56423
- }
56424
- async replaceExactSnapshotNow(agentId, entries) {
56425
- const result = await this.countEntriesNow(agentId, entries);
56454
+ this.values.clear();
56455
+ this.entries.clear();
56456
+ this.generations.clear();
56457
+ }
56458
+ async replaceExactSnapshotNow(agentId, entries, measurement) {
56459
+ const result = await this.countEntriesNow(agentId, entries, undefined, measurement.lifecycleGeneration);
56460
+ if (!this.isCurrent(agentId, measurement))
56461
+ return result.tokens;
56426
56462
  const nextKeys = new Set(entries.map((entry) => entry.key));
56427
56463
  const agentEntries = this.entries.get(agentId);
56428
56464
  if (agentEntries === undefined) {
@@ -56432,10 +56468,10 @@ class DreamingBacklogTokenCache {
56432
56468
  if (!nextKeys.has(key))
56433
56469
  agentEntries.delete(key);
56434
56470
  }
56435
- this.values.set(agentId, result.tokens);
56471
+ this.recordExactTotal(agentId, result.tokens, measurement);
56436
56472
  return result.tokens;
56437
56473
  }
56438
- async countEntriesNow(agentId, entries, stopAtTokens) {
56474
+ async countEntriesNow(agentId, entries, stopAtTokens, lifecycleGeneration) {
56439
56475
  const agentEntries = this.entries.get(agentId) ?? new Map;
56440
56476
  this.entries.set(agentId, agentEntries);
56441
56477
  if (entries.length === 0 || stopAtTokens === 0)
@@ -56468,6 +56504,9 @@ class DreamingBacklogTokenCache {
56468
56504
  }
56469
56505
  const segment = entries.slice(index, end);
56470
56506
  const counts = await this.count(segment, stopAtTokens === undefined ? undefined : stopAtTokens - tokens);
56507
+ if (lifecycleGeneration !== this.lifecycleGeneration) {
56508
+ throw new Error("Dreaming token cache stopped during measurement");
56509
+ }
56471
56510
  if (counts.length === 0)
56472
56511
  throw new Error(`Dreaming token worker omitted ${entry.key}`);
56473
56512
  for (let resultIndex = 0;resultIndex < counts.length; resultIndex += 1) {
@@ -56514,7 +56553,14 @@ class DreamingBacklogTokenCache {
56514
56553
  if (active !== undefined)
56515
56554
  return active;
56516
56555
  const prior = this.tails.get(agentId) ?? Promise.resolve();
56517
- const promise3 = prior.then(operation, operation);
56556
+ const lifecycleGeneration = this.lifecycleGeneration;
56557
+ const run = () => {
56558
+ if (lifecycleGeneration !== this.lifecycleGeneration) {
56559
+ return Promise.reject(new Error("Dreaming token cache stopped during operation"));
56560
+ }
56561
+ return operation();
56562
+ };
56563
+ const promise3 = prior.then(run, run);
56518
56564
  inflight.set(key, promise3);
56519
56565
  const tail = promise3.then(() => {
56520
56566
  return;