@signetai/connector-base 1.0.1 → 1.0.2-next.2664

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/index.js CHANGED
@@ -1,10 +1,33 @@
1
1
  // src/index.ts
2
2
  import { randomBytes } from "node:crypto";
3
+
4
+ // src/config.ts
5
+ import { statSync } from "node:fs";
6
+ function isJsonObject(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ function readTrimmedEnv(name) {
10
+ const value = process.env[name];
11
+ if (typeof value !== "string")
12
+ return;
13
+ const trimmed = value.trim().replace(/[\r\n]+/g, "");
14
+ return trimmed.length > 0 ? trimmed : undefined;
15
+ }
16
+ function readManagedTrimmedEnv(name) {
17
+ return readTrimmedEnv(name);
18
+ }
19
+ function isExistingFile(path) {
20
+ if (!path)
21
+ return false;
22
+ return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
23
+ }
24
+
25
+ // src/index.ts
3
26
  import {
4
27
  chmodSync,
5
28
  closeSync,
6
29
  constants,
7
- existsSync,
30
+ existsSync as existsSync2,
8
31
  fchmodSync,
9
32
  fstatSync,
10
33
  ftruncateSync,
@@ -12,13 +35,13 @@ import {
12
35
  readFileSync,
13
36
  realpathSync,
14
37
  renameSync,
15
- statSync,
38
+ statSync as statSync3,
16
39
  unlinkSync,
17
40
  writeFileSync,
18
41
  writeSync
19
42
  } from "node:fs";
20
43
  import { homedir } from "node:os";
21
- import { basename as basename2, dirname as dirname2, isAbsolute, join as join3, relative, sep } from "node:path";
44
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join4, relative, sep } from "node:path";
22
45
 
23
46
  // ../../platform/core/dist/index.js
24
47
  import { createRequire } from "node:module";
@@ -10419,6 +10442,79 @@ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = [
10419
10442
  "dreaming"
10420
10443
  ];
10421
10444
  function up(db) {
10445
+ if (!db.prepare("PRAGMA table_info(source_import_records)").all().some((row) => row.name === "redacted_bytes"))
10446
+ db.exec("ALTER TABLE source_import_records ADD COLUMN redacted_bytes INTEGER NOT NULL DEFAULT 0");
10447
+ db.exec(`
10448
+ CREATE TABLE IF NOT EXISTS session_transcript_deletions (
10449
+ agent_id TEXT NOT NULL,
10450
+ session_key TEXT NOT NULL,
10451
+ generation INTEGER NOT NULL DEFAULT 1,
10452
+ watermark TEXT NOT NULL,
10453
+ opened_at TEXT,
10454
+ blocked INTEGER NOT NULL DEFAULT 1,
10455
+ ended INTEGER NOT NULL DEFAULT 0,
10456
+ pending_start INTEGER NOT NULL DEFAULT 0,
10457
+ lifecycle_intent_seq INTEGER NOT NULL DEFAULT 0,
10458
+ receipt_generation INTEGER NOT NULL DEFAULT 1,
10459
+ harness TEXT,
10460
+ project TEXT,
10461
+ hard INTEGER NOT NULL DEFAULT 0,
10462
+ phase TEXT NOT NULL DEFAULT 'evidence',
10463
+ counts TEXT NOT NULL DEFAULT '{}',
10464
+ PRIMARY KEY (agent_id, session_key)
10465
+ );
10466
+ CREATE TABLE IF NOT EXISTS session_transcript_deleted_prefixes (
10467
+ agent_id TEXT NOT NULL,
10468
+ session_key TEXT NOT NULL,
10469
+ generation INTEGER NOT NULL,
10470
+ origin TEXT NOT NULL,
10471
+ record_count INTEGER NOT NULL,
10472
+ record_hash TEXT NOT NULL,
10473
+ PRIMARY KEY (agent_id, session_key, generation, origin)
10474
+ );
10475
+ CREATE TABLE IF NOT EXISTS session_transcript_deleted_positions (
10476
+ agent_id TEXT NOT NULL,
10477
+ session_key TEXT NOT NULL,
10478
+ generation INTEGER NOT NULL,
10479
+ origin TEXT NOT NULL,
10480
+ position INTEGER NOT NULL,
10481
+ record_hash TEXT NOT NULL,
10482
+ PRIMARY KEY (agent_id, session_key, generation, origin, position),
10483
+ FOREIGN KEY (agent_id, session_key, generation, origin)
10484
+ REFERENCES session_transcript_deleted_prefixes(agent_id, session_key, generation, origin) ON DELETE CASCADE
10485
+ );
10486
+ CREATE TABLE IF NOT EXISTS session_transcript_deleted_sources (
10487
+ agent_id TEXT NOT NULL,
10488
+ session_key TEXT NOT NULL,
10489
+ generation INTEGER NOT NULL,
10490
+ kind TEXT NOT NULL,
10491
+ id TEXT NOT NULL,
10492
+ outcome TEXT NOT NULL DEFAULT 'deleted',
10493
+ PRIMARY KEY (agent_id, session_key, generation, kind, id)
10494
+ );
10495
+ CREATE TABLE IF NOT EXISTS session_transcript_delete_files (
10496
+ agent_id TEXT NOT NULL,
10497
+ session_key TEXT NOT NULL,
10498
+ generation INTEGER NOT NULL,
10499
+ path TEXT NOT NULL,
10500
+ checkpoint TEXT,
10501
+ done INTEGER NOT NULL DEFAULT 0,
10502
+ PRIMARY KEY (agent_id, session_key, generation, path)
10503
+ );
10504
+ CREATE INDEX IF NOT EXISTS idx_session_delete_files_pending ON session_transcript_delete_files(path) WHERE done = 0 AND checkpoint IS NOT NULL;
10505
+ CREATE INDEX IF NOT EXISTS idx_import_records_session_delete ON source_import_records(agent_id,canonical_key,redacted_bytes);
10506
+ CREATE INDEX IF NOT EXISTS idx_memories_session_delete_source ON memories(agent_id,source_id);
10507
+ CREATE INDEX IF NOT EXISTS idx_capture_jobs_session_delete ON transcript_capture_jobs(agent_id,session_key);
10508
+ CREATE INDEX IF NOT EXISTS idx_session_delete_source_lookup
10509
+ ON session_transcript_deleted_sources(agent_id, kind, id, outcome);
10510
+ `);
10511
+ const columns = db.prepare("PRAGMA table_info(session_transcript_deletions)").all();
10512
+ for (const column of ["pending_start", "lifecycle_intent_seq"]) {
10513
+ if (!columns.some((row) => row.name === column))
10514
+ db.exec(`ALTER TABLE session_transcript_deletions ADD COLUMN ${column} INTEGER NOT NULL DEFAULT 0`);
10515
+ }
10516
+ }
10517
+ function up2(db) {
10422
10518
  const hasColumn = (table, column) => {
10423
10519
  const statement = db.prepare(`SELECT 1 FROM pragma_table_info('${table}') WHERE name = ?`);
10424
10520
  try {
@@ -10478,7 +10574,7 @@ function up(db) {
10478
10574
  CREATE INDEX IF NOT EXISTS idx_transcript_import_harness ON transcript_import_conversations(agent_id,harness);
10479
10575
  `);
10480
10576
  }
10481
- function up2(db) {
10577
+ function up3(db) {
10482
10578
  db.exec(`
10483
10579
  DROP INDEX IF EXISTS idx_memory_artifacts_agent_sha;
10484
10580
  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)
@@ -10490,7 +10586,7 @@ function addColumnIfMissing(db, column, definition) {
10490
10586
  return;
10491
10587
  db.exec(`ALTER TABLE transcript_capture_jobs ADD COLUMN ${column} ${definition}`);
10492
10588
  }
10493
- function up3(db) {
10589
+ function up4(db) {
10494
10590
  const table = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'transcript_capture_jobs'").get();
10495
10591
  if (!table?.present)
10496
10592
  return;
@@ -10507,7 +10603,7 @@ function up3(db) {
10507
10603
  ON transcript_capture_jobs(agent_id, source_sha256);
10508
10604
  `);
10509
10605
  }
10510
- function up4(db) {
10606
+ function up5(db) {
10511
10607
  db.exec(`
10512
10608
  CREATE TABLE IF NOT EXISTS source_sync_failures (
10513
10609
  agent_id TEXT NOT NULL,
@@ -10530,7 +10626,7 @@ function up4(db) {
10530
10626
  WHERE resolved_at IS NULL;
10531
10627
  `);
10532
10628
  }
10533
- function up5(db) {
10629
+ function up6(db) {
10534
10630
  db.exec("DROP TABLE IF EXISTS mcp_invocations");
10535
10631
  }
10536
10632
  var MEMORIES_FTS_TOKENIZER = "porter unicode61";
@@ -10645,7 +10741,7 @@ function memoriesFtsNeedsTokenizerRepair(sql) {
10645
10741
  return false;
10646
10742
  return !normalizeSql(sql).includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
10647
10743
  }
10648
- function up6(db) {
10744
+ function up7(db) {
10649
10745
  db.exec(`
10650
10746
  CREATE TABLE IF NOT EXISTS schema_migrations (
10651
10747
  version INTEGER PRIMARY KEY,
@@ -10743,7 +10839,7 @@ function addColumnIfMissing2(db, table, column, definition) {
10743
10839
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10744
10840
  }
10745
10841
  }
10746
- function up7(db) {
10842
+ function up8(db) {
10747
10843
  addColumnIfMissing2(db, "memories", "content_hash", "TEXT");
10748
10844
  addColumnIfMissing2(db, "memories", "normalized_content", "TEXT");
10749
10845
  addColumnIfMissing2(db, "memories", "is_deleted", "INTEGER DEFAULT 0");
@@ -10861,7 +10957,7 @@ function addColumnIfMissing3(db, table, column, definition) {
10861
10957
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10862
10958
  return true;
10863
10959
  }
10864
- function up8(db) {
10960
+ function up9(db) {
10865
10961
  addColumnIfMissing3(db, "memories", "why", "TEXT");
10866
10962
  addColumnIfMissing3(db, "memories", "project", "TEXT");
10867
10963
  db.exec(`DROP INDEX IF EXISTS idx_memories_content_hash`);
@@ -10898,7 +10994,7 @@ function addColumnIfMissing4(db, table, column, definition) {
10898
10994
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10899
10995
  }
10900
10996
  }
10901
- function up9(db) {
10997
+ function up10(db) {
10902
10998
  addColumnIfMissing4(db, "memory_history", "actor_type", "TEXT");
10903
10999
  addColumnIfMissing4(db, "memory_history", "session_id", "TEXT");
10904
11000
  addColumnIfMissing4(db, "memory_history", "request_id", "TEXT");
@@ -10931,7 +11027,7 @@ function addColumnIfMissing5(db, table, column, definition) {
10931
11027
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10932
11028
  }
10933
11029
  }
10934
- function up10(db) {
11030
+ function up11(db) {
10935
11031
  addColumnIfMissing5(db, "entities", "canonical_name", "TEXT");
10936
11032
  addColumnIfMissing5(db, "entities", "mentions", "INTEGER DEFAULT 0");
10937
11033
  addColumnIfMissing5(db, "entities", "embedding", "BLOB");
@@ -10948,7 +11044,7 @@ function hasColumn4(db, table, column) {
10948
11044
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10949
11045
  return rows.some((r) => r.name === column);
10950
11046
  }
10951
- function up11(db) {
11047
+ function up12(db) {
10952
11048
  if (!hasColumn4(db, "memories", "idempotency_key")) {
10953
11049
  db.exec("ALTER TABLE memories ADD COLUMN idempotency_key TEXT");
10954
11050
  }
@@ -10963,7 +11059,7 @@ function hasColumn5(db, table, column) {
10963
11059
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10964
11060
  return rows.some((r) => r.name === column);
10965
11061
  }
10966
- function up12(db) {
11062
+ function up13(db) {
10967
11063
  db.exec(`
10968
11064
  CREATE TABLE IF NOT EXISTS documents (
10969
11065
  id TEXT PRIMARY KEY,
@@ -11020,7 +11116,7 @@ function up12(db) {
11020
11116
  db.exec("ALTER TABLE memory_jobs ADD COLUMN document_id TEXT");
11021
11117
  }
11022
11118
  }
11023
- function up13(db) {
11119
+ function up14(db) {
11024
11120
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='embeddings'").all();
11025
11121
  if (tables.length === 0)
11026
11122
  return;
@@ -11037,7 +11133,7 @@ function up13(db) {
11037
11133
  ON embeddings(content_hash)
11038
11134
  `);
11039
11135
  }
11040
- function up14(db) {
11136
+ function up15(db) {
11041
11137
  db.exec(`
11042
11138
  CREATE TABLE IF NOT EXISTS summary_jobs (
11043
11139
  id TEXT PRIMARY KEY,
@@ -11057,7 +11153,7 @@ function up14(db) {
11057
11153
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
11058
11154
  ON summary_jobs(status)`);
11059
11155
  }
11060
- function up15(db) {
11156
+ function up16(db) {
11061
11157
  db.exec(`
11062
11158
  CREATE TABLE IF NOT EXISTS umap_cache (
11063
11159
  id INTEGER PRIMARY KEY,
@@ -11068,7 +11164,7 @@ function up15(db) {
11068
11164
  )
11069
11165
  `);
11070
11166
  }
11071
- function up16(db) {
11167
+ function up17(db) {
11072
11168
  db.exec(`
11073
11169
  CREATE TABLE IF NOT EXISTS session_scores (
11074
11170
  id TEXT PRIMARY KEY,
@@ -11088,7 +11184,7 @@ function up16(db) {
11088
11184
  ON session_scores(session_key);
11089
11185
  `);
11090
11186
  }
11091
- function up17(db) {
11187
+ function up18(db) {
11092
11188
  db.exec(`
11093
11189
  CREATE TABLE IF NOT EXISTS scheduled_tasks (
11094
11190
  id TEXT PRIMARY KEY,
@@ -11129,7 +11225,7 @@ function addColumnIfMissing6(db, table, column, definition) {
11129
11225
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11130
11226
  }
11131
11227
  }
11132
- function up18(db) {
11228
+ function up19(db) {
11133
11229
  db.exec(`
11134
11230
  CREATE TABLE IF NOT EXISTS ingestion_jobs (
11135
11231
  id TEXT PRIMARY KEY,
@@ -11155,7 +11251,7 @@ function up18(db) {
11155
11251
  addColumnIfMissing6(db, "memories", "source_path", "TEXT");
11156
11252
  addColumnIfMissing6(db, "memories", "source_section", "TEXT");
11157
11253
  }
11158
- function up19(db) {
11254
+ function up20(db) {
11159
11255
  db.exec(`
11160
11256
  CREATE TABLE IF NOT EXISTS telemetry_events (
11161
11257
  id TEXT PRIMARY KEY,
@@ -11180,7 +11276,7 @@ function addColumnIfMissing7(db, table, column, definition) {
11180
11276
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11181
11277
  }
11182
11278
  }
11183
- function up20(db) {
11279
+ function up21(db) {
11184
11280
  db.exec(`
11185
11281
  CREATE TABLE IF NOT EXISTS session_memories (
11186
11282
  id TEXT PRIMARY KEY,
@@ -11207,7 +11303,7 @@ function up20(db) {
11207
11303
  addColumnIfMissing7(db, "session_scores", "confidence", "REAL");
11208
11304
  addColumnIfMissing7(db, "session_scores", "continuity_reasoning", "TEXT");
11209
11305
  }
11210
- function up21(db) {
11306
+ function up22(db) {
11211
11307
  db.exec(`
11212
11308
  CREATE TABLE IF NOT EXISTS session_checkpoints (
11213
11309
  id TEXT PRIMARY KEY,
@@ -11229,7 +11325,7 @@ function up21(db) {
11229
11325
  ON session_checkpoints(project_normalized, created_at DESC);
11230
11326
  `);
11231
11327
  }
11232
- function up22(db) {
11328
+ function up23(db) {
11233
11329
  const cols = db.prepare("PRAGMA table_info(scheduled_tasks)").all();
11234
11330
  const colNames = new Set(cols.flatMap((c) => typeof c.name === "string" ? [c.name] : []));
11235
11331
  if (!colNames.has("skill_name")) {
@@ -11240,7 +11336,7 @@ function up22(db) {
11240
11336
  CHECK (skill_mode IN ('inject', 'slash') OR skill_mode IS NULL)`);
11241
11337
  }
11242
11338
  }
11243
- function up23(db) {
11339
+ function up24(db) {
11244
11340
  const existing = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='skill_meta'").get();
11245
11341
  if (existing)
11246
11342
  return;
@@ -11272,7 +11368,7 @@ function up23(db) {
11272
11368
  CREATE INDEX idx_skill_meta_source ON skill_meta(source);
11273
11369
  `);
11274
11370
  }
11275
- function up24(db) {
11371
+ function up25(db) {
11276
11372
  const entityCols = db.prepare("PRAGMA table_info(entities)").all();
11277
11373
  const entityColNames = new Set(entityCols.flatMap((c) => typeof c.name === "string" ? [c.name] : []));
11278
11374
  if (!entityColNames.has("agent_id")) {
@@ -11357,13 +11453,13 @@ function addColumnIfMissing8(db, table, column, definition) {
11357
11453
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11358
11454
  }
11359
11455
  }
11360
- function up25(db) {
11456
+ function up26(db) {
11361
11457
  addColumnIfMissing8(db, "session_memories", "entity_slot", "INTEGER");
11362
11458
  addColumnIfMissing8(db, "session_memories", "aspect_slot", "INTEGER");
11363
11459
  addColumnIfMissing8(db, "session_memories", "is_constraint", "INTEGER NOT NULL DEFAULT 0");
11364
11460
  addColumnIfMissing8(db, "session_memories", "structural_density", "INTEGER");
11365
11461
  }
11366
- function up26(db) {
11462
+ function up27(db) {
11367
11463
  const columns = db.prepare("PRAGMA table_info(session_checkpoints)").all();
11368
11464
  const columnNames = new Set(columns.flatMap((column) => typeof column.name === "string" ? [column.name] : []));
11369
11465
  if (!columnNames.has("focal_entity_ids")) {
@@ -11388,25 +11484,25 @@ function addColumnIfMissing9(db, table, column, definition) {
11388
11484
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11389
11485
  }
11390
11486
  }
11391
- function up27(db) {
11487
+ function up28(db) {
11392
11488
  addColumnIfMissing9(db, "entities", "pinned", "INTEGER NOT NULL DEFAULT 0");
11393
11489
  addColumnIfMissing9(db, "entities", "pinned_at", "TEXT");
11394
11490
  db.exec("CREATE INDEX IF NOT EXISTS idx_entities_pinned ON entities(agent_id, pinned, pinned_at DESC)");
11395
11491
  }
11396
- function up28(_db) {}
11397
11492
  function up29(_db) {}
11493
+ function up30(_db) {}
11398
11494
  function addColumnIfMissing10(db, table, column, definition) {
11399
11495
  const cols = db.prepare(`PRAGMA table_info(${table})`).all();
11400
11496
  if (!cols.some((c) => c.name === column)) {
11401
11497
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11402
11498
  }
11403
11499
  }
11404
- function up30(db) {
11500
+ function up31(db) {
11405
11501
  addColumnIfMissing10(db, "session_memories", "agent_relevance_score", "REAL");
11406
11502
  addColumnIfMissing10(db, "session_memories", "agent_feedback_count", "INTEGER DEFAULT 0");
11407
11503
  }
11408
- function up31(_db) {}
11409
- function up32(db) {
11504
+ function up32(_db) {}
11505
+ function up33(db) {
11410
11506
  db.exec(`
11411
11507
  UPDATE entities
11412
11508
  SET canonical_name = REPLACE(REPLACE(REPLACE(
@@ -11415,7 +11511,7 @@ function up32(db) {
11415
11511
  WHERE canonical_name IS NULL
11416
11512
  `);
11417
11513
  }
11418
- function up33(db) {
11514
+ function up34(db) {
11419
11515
  db.exec(`
11420
11516
  CREATE TABLE IF NOT EXISTS memories_cold (
11421
11517
  archive_id TEXT PRIMARY KEY,
@@ -11452,7 +11548,7 @@ function up33(db) {
11452
11548
  CREATE INDEX IF NOT EXISTS idx_cold_source ON memories_cold(cold_source_id);
11453
11549
  `);
11454
11550
  }
11455
- function up34(db) {
11551
+ function up35(db) {
11456
11552
  db.exec(`
11457
11553
  CREATE TABLE IF NOT EXISTS session_summaries (
11458
11554
  id TEXT PRIMARY KEY,
@@ -11497,7 +11593,7 @@ function up34(db) {
11497
11593
  WHERE session_key IS NOT NULL;
11498
11594
  `);
11499
11595
  }
11500
- function up35(db) {
11596
+ function up36(db) {
11501
11597
  db.exec(`
11502
11598
  CREATE TABLE IF NOT EXISTS memory_jobs_new (
11503
11599
  id TEXT PRIMARY KEY,
@@ -11542,7 +11638,7 @@ function up35(db) {
11542
11638
  ON memory_jobs(failed_at);
11543
11639
  `);
11544
11640
  }
11545
- function up36(db) {
11641
+ function up37(db) {
11546
11642
  const depCols = db.prepare("PRAGMA table_info(entity_dependencies)").all();
11547
11643
  if (!depCols.some((c) => c.name === "reason")) {
11548
11644
  db.exec("ALTER TABLE entity_dependencies ADD COLUMN reason TEXT");
@@ -11552,7 +11648,7 @@ function up36(db) {
11552
11648
  db.exec("ALTER TABLE entities ADD COLUMN last_synthesized_at TEXT");
11553
11649
  }
11554
11650
  }
11555
- function up37(db) {
11651
+ function up38(db) {
11556
11652
  const cols = db.prepare("PRAGMA table_info(embeddings)").all();
11557
11653
  if (cols.length === 0)
11558
11654
  return;
@@ -11560,14 +11656,14 @@ function up37(db) {
11560
11656
  db.exec("ALTER TABLE embeddings ADD COLUMN vector BLOB");
11561
11657
  }
11562
11658
  }
11563
- function up38(db) {
11659
+ function up39(db) {
11564
11660
  const cols = db.prepare("PRAGMA table_info(memories)").all();
11565
11661
  if (!cols.some((c) => c.name === "scope")) {
11566
11662
  db.exec("ALTER TABLE memories ADD COLUMN scope TEXT DEFAULT NULL");
11567
11663
  }
11568
11664
  db.exec("CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope) WHERE scope IS NOT NULL");
11569
11665
  }
11570
- function up39(db) {
11666
+ function up40(db) {
11571
11667
  db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
11572
11668
  db.exec(`
11573
11669
  CREATE UNIQUE INDEX idx_memories_content_hash_unique
@@ -11575,7 +11671,7 @@ function up39(db) {
11575
11671
  WHERE content_hash IS NOT NULL AND is_deleted = 0
11576
11672
  `);
11577
11673
  }
11578
- function up40(db) {
11674
+ function up41(db) {
11579
11675
  db.exec(`
11580
11676
  CREATE VIRTUAL TABLE IF NOT EXISTS entities_fts USING fts5(
11581
11677
  name, canonical_name,
@@ -11607,13 +11703,13 @@ function up40(db) {
11607
11703
  END
11608
11704
  `);
11609
11705
  }
11610
- function up41(db) {
11706
+ function up42(db) {
11611
11707
  const cols = db.prepare("PRAGMA table_info(entity_dependencies)").all();
11612
11708
  if (!cols.some((c) => c.name === "confidence")) {
11613
11709
  db.exec("ALTER TABLE entity_dependencies ADD COLUMN confidence REAL DEFAULT 0.7");
11614
11710
  }
11615
11711
  }
11616
- function up42(db) {
11712
+ function up43(db) {
11617
11713
  db.exec(`
11618
11714
  CREATE TABLE IF NOT EXISTS entity_communities (
11619
11715
  id TEXT PRIMARY KEY,
@@ -11631,7 +11727,7 @@ function up42(db) {
11631
11727
  db.exec("ALTER TABLE entities ADD COLUMN community_id TEXT REFERENCES entity_communities(id)");
11632
11728
  }
11633
11729
  }
11634
- function up43(db) {
11730
+ function up44(db) {
11635
11731
  db.exec(`
11636
11732
  CREATE TABLE IF NOT EXISTS memory_hints (
11637
11733
  id TEXT PRIMARY KEY,
@@ -11671,7 +11767,7 @@ function up43(db) {
11671
11767
  END
11672
11768
  `);
11673
11769
  }
11674
- function up44(db) {
11770
+ function up45(db) {
11675
11771
  db.exec(`
11676
11772
  DELETE FROM entity_dependencies
11677
11773
  WHERE id NOT IN (
@@ -11689,7 +11785,7 @@ function up44(db) {
11689
11785
  )
11690
11786
  `);
11691
11787
  }
11692
- function up45(db) {
11788
+ function up46(db) {
11693
11789
  db.exec(`
11694
11790
  CREATE TABLE IF NOT EXISTS session_transcripts (
11695
11791
  session_key TEXT PRIMARY KEY,
@@ -11712,7 +11808,7 @@ function addColumnIfMissing11(db, table, column, definition) {
11712
11808
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11713
11809
  }
11714
11810
  }
11715
- function up46(db) {
11811
+ function up47(db) {
11716
11812
  addColumnIfMissing11(db, "session_memories", "path_json", "TEXT");
11717
11813
  db.exec(`
11718
11814
  CREATE TABLE IF NOT EXISTS path_feedback_events (
@@ -11787,7 +11883,7 @@ function addColumnIfMissing12(db, table, column, definition) {
11787
11883
  return;
11788
11884
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11789
11885
  }
11790
- function up47(db) {
11886
+ function up48(db) {
11791
11887
  addColumnIfMissing12(db, "session_memories", "entity_slot", "INTEGER");
11792
11888
  addColumnIfMissing12(db, "session_memories", "aspect_slot", "INTEGER");
11793
11889
  addColumnIfMissing12(db, "session_memories", "is_constraint", "INTEGER NOT NULL DEFAULT 0");
@@ -11875,7 +11971,7 @@ function addColumnIfMissing13(db, table, column, definition) {
11875
11971
  return;
11876
11972
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11877
11973
  }
11878
- function up48(db) {
11974
+ function up49(db) {
11879
11975
  db.exec(`
11880
11976
  CREATE TABLE IF NOT EXISTS agents (
11881
11977
  id TEXT PRIMARY KEY,
@@ -11904,7 +12000,7 @@ function addColumnIfMissing14(db, table, column, definition) {
11904
12000
  return;
11905
12001
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11906
12002
  }
11907
- function up49(db) {
12003
+ function up50(db) {
11908
12004
  addColumnIfMissing14(db, "session_summaries", "source_type", "TEXT");
11909
12005
  addColumnIfMissing14(db, "session_summaries", "source_ref", "TEXT");
11910
12006
  addColumnIfMissing14(db, "session_summaries", "meta_json", "TEXT");
@@ -11930,7 +12026,7 @@ function addColumnIfMissing15(db, table, column, definition) {
11930
12026
  return;
11931
12027
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
11932
12028
  }
11933
- function up50(db) {
12029
+ function up51(db) {
11934
12030
  addColumnIfMissing15(db, "session_transcripts", "updated_at", "TEXT");
11935
12031
  addColumnIfMissing15(db, "summary_jobs", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
11936
12032
  addColumnIfMissing15(db, "session_scores", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
@@ -12001,7 +12097,7 @@ function up50(db) {
12001
12097
  ON memory_md_heads(lease_expires_at);
12002
12098
  `);
12003
12099
  }
12004
- function up51(db) {
12100
+ function up52(db) {
12005
12101
  db.exec(`
12006
12102
  DROP INDEX IF EXISTS idx_summaries_session_depth;
12007
12103
 
@@ -12062,7 +12158,7 @@ function up51(db) {
12062
12158
  AND COALESCE(source_type, 'summary') = 'summary';
12063
12159
  `);
12064
12160
  }
12065
- function up52(db) {
12161
+ function up53(db) {
12066
12162
  db.exec(`
12067
12163
  DROP TRIGGER IF EXISTS session_transcripts_fts_ai;
12068
12164
  DROP TRIGGER IF EXISTS session_transcripts_fts_ad;
@@ -12160,7 +12256,7 @@ function up52(db) {
12160
12256
  AND COALESCE(source_type, 'summary') = 'summary';
12161
12257
  `);
12162
12258
  }
12163
- function up53(db) {
12259
+ function up54(db) {
12164
12260
  db.exec(`
12165
12261
  CREATE TABLE IF NOT EXISTS memory_thread_heads (
12166
12262
  agent_id TEXT NOT NULL DEFAULT 'default',
@@ -12278,7 +12374,7 @@ function up53(db) {
12278
12374
  WHERE excluded.latest_at >= memory_thread_heads.latest_at;
12279
12375
  `);
12280
12376
  }
12281
- function up54(db) {
12377
+ function up55(db) {
12282
12378
  db.exec(`
12283
12379
  CREATE TABLE IF NOT EXISTS session_extract_cursors (
12284
12380
  session_key TEXT NOT NULL,
@@ -12295,7 +12391,7 @@ function hasTable(db, name) {
12295
12391
  WHERE type = 'table' AND name = ?
12296
12392
  LIMIT 1`).get(name) !== undefined;
12297
12393
  }
12298
- function up55(db) {
12394
+ function up56(db) {
12299
12395
  db.exec(`
12300
12396
  CREATE TABLE IF NOT EXISTS entity_dependency_history (
12301
12397
  id TEXT PRIMARY KEY,
@@ -12465,7 +12561,7 @@ function addColumnIfMissing16(db, table, column, definition) {
12465
12561
  return;
12466
12562
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
12467
12563
  }
12468
- function up56(db) {
12564
+ function up57(db) {
12469
12565
  addColumnIfMissing16(db, "summary_jobs", "session_id", "TEXT");
12470
12566
  addColumnIfMissing16(db, "summary_jobs", "trigger", "TEXT NOT NULL DEFAULT 'session_end'");
12471
12567
  addColumnIfMissing16(db, "summary_jobs", "captured_at", "TEXT");
@@ -12557,8 +12653,8 @@ function up56(db) {
12557
12653
  VALUES ('rebuild');
12558
12654
  `);
12559
12655
  }
12560
- function up57(_db) {}
12561
- function up58(db) {
12656
+ function up58(_db) {}
12657
+ function up59(db) {
12562
12658
  db.exec(`
12563
12659
  CREATE TABLE IF NOT EXISTS skill_invocations (
12564
12660
  id TEXT PRIMARY KEY,
@@ -12574,7 +12670,7 @@ function up58(db) {
12574
12670
  CREATE INDEX IF NOT EXISTS idx_skill_inv_agent ON skill_invocations(agent_id, created_at);
12575
12671
  `);
12576
12672
  }
12577
- function up59(db) {
12673
+ function up60(db) {
12578
12674
  db.exec(`
12579
12675
  CREATE TABLE IF NOT EXISTS task_scope_hints (
12580
12676
  task_id TEXT PRIMARY KEY REFERENCES scheduled_tasks(id) ON DELETE CASCADE,
@@ -12605,7 +12701,7 @@ function up59(db) {
12605
12701
  ON task_scope_hints(agent_id, updated_at);
12606
12702
  `);
12607
12703
  }
12608
- function up60(db) {
12704
+ function up61(db) {
12609
12705
  db.exec(`
12610
12706
  CREATE TABLE IF NOT EXISTS dreaming_state (
12611
12707
  agent_id TEXT PRIMARY KEY NOT NULL,
@@ -12648,7 +12744,7 @@ function ensureMemoriesScopeColumns(db) {
12648
12744
  if (!names.has("scope"))
12649
12745
  db.exec("ALTER TABLE memories ADD COLUMN scope TEXT");
12650
12746
  }
12651
- function up61(db) {
12747
+ function up62(db) {
12652
12748
  ensureMemoriesScopeColumns(db);
12653
12749
  db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
12654
12750
  db.exec(`
@@ -12661,20 +12757,20 @@ function up61(db) {
12661
12757
  WHERE content_hash IS NOT NULL AND is_deleted = 0
12662
12758
  `);
12663
12759
  }
12664
- function up62(db) {
12760
+ function up63(db) {
12665
12761
  const sql = readMemoriesFtsSql(db);
12666
12762
  if (sql !== null && !memoriesFtsNeedsTokenizerRepair(sql))
12667
12763
  return;
12668
12764
  recreateMemoriesFts(db);
12669
12765
  }
12670
- function up63(db) {
12766
+ function up64(db) {
12671
12767
  db.exec(`CREATE INDEX IF NOT EXISTS idx_entities_order
12672
12768
  ON entities(agent_id, pinned DESC, pinned_at DESC, mentions DESC, updated_at DESC, name)`);
12673
12769
  db.exec(`CREATE INDEX IF NOT EXISTS idx_entities_extracted_mentions
12674
12770
  ON entities(entity_type, mentions)
12675
12771
  WHERE entity_type = 'extracted'`);
12676
12772
  }
12677
- function up64(db) {
12773
+ function up65(db) {
12678
12774
  const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
12679
12775
  if (!cols.some((col) => col.name === "claim_key")) {
12680
12776
  db.exec("ALTER TABLE entity_attributes ADD COLUMN claim_key TEXT");
@@ -12683,7 +12779,7 @@ function up64(db) {
12683
12779
  ON entity_attributes(agent_id, aspect_id, claim_key, status)
12684
12780
  WHERE claim_key IS NOT NULL`);
12685
12781
  }
12686
- function up65(db) {
12782
+ function up66(db) {
12687
12783
  const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
12688
12784
  if (!cols.some((col) => col.name === "group_key")) {
12689
12785
  db.exec("ALTER TABLE entity_attributes ADD COLUMN group_key TEXT");
@@ -12695,13 +12791,13 @@ function up65(db) {
12695
12791
  ON entity_attributes(agent_id, aspect_id, group_key, claim_key, status)
12696
12792
  WHERE claim_key IS NOT NULL`);
12697
12793
  }
12698
- function up66(db) {
12794
+ function up67(db) {
12699
12795
  const cols = db.prepare("PRAGMA table_info(memory_artifacts)").all();
12700
12796
  if (cols.some((col) => col.name === "source_mtime_ms"))
12701
12797
  return;
12702
12798
  db.exec("ALTER TABLE memory_artifacts ADD COLUMN source_mtime_ms REAL");
12703
12799
  }
12704
- function up67(db) {
12800
+ function up68(db) {
12705
12801
  const cols = db.prepare("PRAGMA table_info(memory_artifacts)").all();
12706
12802
  const names = new Set(cols.map((col) => col.name));
12707
12803
  if (!names.has("is_deleted")) {
@@ -12715,7 +12811,7 @@ function up67(db) {
12715
12811
  ON memory_artifacts(agent_id, is_deleted, deleted_at)
12716
12812
  `);
12717
12813
  }
12718
- function up68(db) {
12814
+ function up69(db) {
12719
12815
  db.exec("DROP TRIGGER IF EXISTS memories_au");
12720
12816
  db.exec(`
12721
12817
  CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE OF content ON memories BEGIN
@@ -12733,7 +12829,7 @@ function addColumnIfMissing17(db, table, column, definition) {
12733
12829
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
12734
12830
  }
12735
12831
  }
12736
- function up69(db) {
12832
+ function up70(db) {
12737
12833
  for (const table of ["entities", "entity_communities", "entity_attributes", "entity_dependencies"]) {
12738
12834
  addColumnIfMissing17(db, table, "source_id", "TEXT");
12739
12835
  addColumnIfMissing17(db, table, "source_kind", "TEXT");
@@ -12753,7 +12849,7 @@ function hasColumn7(db, table, column) {
12753
12849
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
12754
12850
  return rows.some((row) => row.name === column);
12755
12851
  }
12756
- function up70(db) {
12852
+ function up71(db) {
12757
12853
  if (!hasTable2(db, "embeddings"))
12758
12854
  return;
12759
12855
  if (!hasColumn7(db, "embeddings", "agent_id")) {
@@ -12761,7 +12857,7 @@ function up70(db) {
12761
12857
  }
12762
12858
  db.exec("CREATE INDEX IF NOT EXISTS idx_embeddings_agent_source ON embeddings(agent_id, source_type, source_id)");
12763
12859
  }
12764
- function up71(db) {
12860
+ function up72(db) {
12765
12861
  db.exec(`
12766
12862
  CREATE TABLE IF NOT EXISTS memory_search_telemetry (
12767
12863
  id TEXT PRIMARY KEY,
@@ -12802,7 +12898,7 @@ function addColumnIfMissing18(db, table, column, definition) {
12802
12898
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
12803
12899
  }
12804
12900
  }
12805
- function up72(db) {
12901
+ function up73(db) {
12806
12902
  db.exec(`
12807
12903
  CREATE TABLE IF NOT EXISTS ontology_proposals (
12808
12904
  id TEXT PRIMARY KEY,
@@ -12845,7 +12941,7 @@ function up72(db) {
12845
12941
  db.exec(`CREATE INDEX IF NOT EXISTS idx_${table}_proposal ON ${table}(agent_id, proposal_id)`);
12846
12942
  }
12847
12943
  }
12848
- function up73(db) {
12944
+ function up74(db) {
12849
12945
  db.exec(`
12850
12946
  CREATE TABLE IF NOT EXISTS daily_reflections (
12851
12947
  id TEXT PRIMARY KEY,
@@ -12872,7 +12968,7 @@ function up73(db) {
12872
12968
  WHERE content_key IS NOT NULL;
12873
12969
  `);
12874
12970
  }
12875
- function up74(db) {
12971
+ function up75(db) {
12876
12972
  const cols = db.prepare("PRAGMA table_info(daily_reflections)").all();
12877
12973
  const colNames = new Set(cols.flatMap((c) => typeof c.name === "string" ? [c.name] : []));
12878
12974
  if (!colNames.has("content_key")) {
@@ -12909,7 +13005,7 @@ function backfillVersionRoots(db) {
12909
13005
  WHERE version_root_id IS NULL
12910
13006
  `);
12911
13007
  }
12912
- function up75(db) {
13008
+ function up76(db) {
12913
13009
  for (const table of ["entities", "entity_aspects", "entity_dependencies"]) {
12914
13010
  addColumnIfMissing19(db, table, "status", "TEXT NOT NULL DEFAULT 'active'");
12915
13011
  addColumnIfMissing19(db, table, "archived_at", "TEXT");
@@ -12944,7 +13040,7 @@ function up75(db) {
12944
13040
  ON entity_aspects(agent_id, proposal_id);
12945
13041
  `);
12946
13042
  }
12947
- function up76(db) {
13043
+ function up77(db) {
12948
13044
  db.exec(`
12949
13045
  CREATE TABLE IF NOT EXISTS epistemic_assertions (
12950
13046
  id TEXT PRIMARY KEY,
@@ -13000,7 +13096,7 @@ function ensureMemoriesScopeColumns2(db) {
13000
13096
  if (!names.has("runtime_path"))
13001
13097
  db.exec("ALTER TABLE memories ADD COLUMN runtime_path TEXT");
13002
13098
  }
13003
- function up77(db) {
13099
+ function up78(db) {
13004
13100
  ensureMemoriesScopeColumns2(db);
13005
13101
  db.exec("DROP INDEX IF EXISTS idx_memories_idempotency_key");
13006
13102
  db.exec(`
@@ -13014,7 +13110,7 @@ function up77(db) {
13014
13110
  WHERE idempotency_key IS NOT NULL AND is_deleted = 0
13015
13111
  `);
13016
13112
  }
13017
- function up78(db) {
13113
+ function up79(db) {
13018
13114
  db.exec(`
13019
13115
  CREATE TABLE IF NOT EXISTS session_context_epochs (
13020
13116
  session_key TEXT NOT NULL,
@@ -13049,7 +13145,7 @@ function up78(db) {
13049
13145
  ON session_recall_events(item_kind, item_id, created_at DESC);
13050
13146
  `);
13051
13147
  }
13052
- function up79(db) {
13148
+ function up80(db) {
13053
13149
  db.exec(`
13054
13150
  CREATE TABLE IF NOT EXISTS aggregate_memory_sources (
13055
13151
  aggregate_memory_id TEXT NOT NULL,
@@ -13068,7 +13164,7 @@ function addColumnIfMissing20(db, table, column, definition) {
13068
13164
  return;
13069
13165
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
13070
13166
  }
13071
- function up80(db) {
13167
+ function up81(db) {
13072
13168
  addColumnIfMissing20(db, "memory_artifacts", "source_id", "TEXT");
13073
13169
  addColumnIfMissing20(db, "memory_artifacts", "source_root", "TEXT");
13074
13170
  addColumnIfMissing20(db, "memory_artifacts", "source_external_id", "TEXT");
@@ -13081,7 +13177,7 @@ function up80(db) {
13081
13177
  ON memory_artifacts(agent_id, source_id, source_root);
13082
13178
  `);
13083
13179
  }
13084
- function up81(db) {
13180
+ function up82(db) {
13085
13181
  db.exec(`
13086
13182
  CREATE TABLE IF NOT EXISTS temporal_edges (
13087
13183
  id TEXT PRIMARY KEY,
@@ -13104,7 +13200,7 @@ function up81(db) {
13104
13200
  ON temporal_edges(agent_id, subject_type, subject_id);
13105
13201
  `);
13106
13202
  }
13107
- function up82(db) {
13203
+ function up83(db) {
13108
13204
  db.exec(`
13109
13205
  CREATE TABLE IF NOT EXISTS entity_aliases (
13110
13206
  id TEXT PRIMARY KEY,
@@ -13128,7 +13224,7 @@ function up82(db) {
13128
13224
  ON entity_aliases(agent_id, canonical_alias, status);
13129
13225
  `);
13130
13226
  }
13131
- function up83(db) {
13227
+ function up84(db) {
13132
13228
  db.exec(`
13133
13229
  CREATE TABLE IF NOT EXISTS api_keys (
13134
13230
  id TEXT PRIMARY KEY,
@@ -13156,7 +13252,7 @@ function up83(db) {
13156
13252
  ON api_keys(connector, harness);
13157
13253
  `);
13158
13254
  }
13159
- function up84(db) {
13255
+ function up85(db) {
13160
13256
  db.exec(`
13161
13257
  CREATE TABLE IF NOT EXISTS transcript_capture_jobs (
13162
13258
  id TEXT PRIMARY KEY,
@@ -13191,7 +13287,7 @@ function hasColumn10(db, table, column) {
13191
13287
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
13192
13288
  return rows.some((row) => row.name === column);
13193
13289
  }
13194
- function up85(db) {
13290
+ function up86(db) {
13195
13291
  if (!hasColumn10(db, "documents", "agent_id")) {
13196
13292
  db.exec("ALTER TABLE documents ADD COLUMN agent_id TEXT NOT NULL DEFAULT 'default'");
13197
13293
  }
@@ -13277,7 +13373,7 @@ function up85(db) {
13277
13373
  db.exec("CREATE INDEX IF NOT EXISTS idx_documents_agent_project ON documents(agent_id, project)");
13278
13374
  db.exec("CREATE INDEX IF NOT EXISTS idx_documents_source_scope ON documents(source_url, agent_id, project)");
13279
13375
  }
13280
- function up86(db) {
13376
+ function up87(db) {
13281
13377
  db.exec(`
13282
13378
  CREATE TABLE IF NOT EXISTS aggregate_evidence_sources (
13283
13379
  aggregate_memory_id TEXT NOT NULL,
@@ -13299,7 +13395,7 @@ function hasColumn11(db, table, column) {
13299
13395
  return rows.some((row) => row.name === column);
13300
13396
  }
13301
13397
  var COLUMNS = ["harness", "session_id", "tool_use_id", "cwd", "origin", "args"];
13302
- function up87(db) {
13398
+ function up88(db) {
13303
13399
  for (const column of COLUMNS) {
13304
13400
  if (!hasColumn11(db, "skill_invocations", column)) {
13305
13401
  db.exec(`ALTER TABLE skill_invocations ADD COLUMN ${column} TEXT`);
@@ -13380,7 +13476,7 @@ function documentScopeColumnsPreservingExisting(db) {
13380
13476
  `);
13381
13477
  }
13382
13478
  try {
13383
- up85(db);
13479
+ up86(db);
13384
13480
  if (preserveAgentId) {
13385
13481
  db.exec(`
13386
13482
  UPDATE documents
@@ -13400,12 +13496,12 @@ function documentScopeColumnsPreservingExisting(db) {
13400
13496
  db.exec("DROP TABLE IF EXISTS temp.__signet_doc_project_guard");
13401
13497
  }
13402
13498
  }
13403
- function up88(db) {
13404
- up84(db);
13499
+ function up89(db) {
13500
+ up85(db);
13405
13501
  if (hasTable3(db, "documents")) {
13406
13502
  documentScopeColumnsPreservingExisting(db);
13407
13503
  }
13408
- up86(db);
13504
+ up87(db);
13409
13505
  addColumnIfMissing21(db, "memories", "superseded_by", "TEXT");
13410
13506
  addColumnIfMissing21(db, "memories", "superseded_at", "TEXT");
13411
13507
  addColumnIfMissing21(db, "memories", "superseded_reason", "TEXT");
@@ -13462,7 +13558,7 @@ function up88(db) {
13462
13558
  AND ${sourceAgentId} = ${targetAgentId}
13463
13559
  `);
13464
13560
  }
13465
- function up89(db) {
13561
+ function up90(db) {
13466
13562
  db.exec(`
13467
13563
  CREATE TABLE IF NOT EXISTS legacy_markdown_imports (
13468
13564
  path TEXT PRIMARY KEY,
@@ -13492,7 +13588,7 @@ function up89(db) {
13492
13588
  ON legacy_markdown_chunks(memory_id);
13493
13589
  `);
13494
13590
  }
13495
- function up90(db) {
13591
+ function up91(db) {
13496
13592
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name IN ('relations', 'entity_dependencies')").all();
13497
13593
  const tableNames = new Set(tables.map((r) => String(r.name)));
13498
13594
  if (!tableNames.has("relations") || !tableNames.has("entity_dependencies"))
@@ -13551,7 +13647,7 @@ function addColumnIfMissing22(db, table, column, definition) {
13551
13647
  return;
13552
13648
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
13553
13649
  }
13554
- function up91(db) {
13650
+ function up92(db) {
13555
13651
  addColumnIfMissing22(db, "summary_jobs", "content_hash", "TEXT");
13556
13652
  db.exec(`
13557
13653
  CREATE INDEX IF NOT EXISTS idx_summary_jobs_agent_session_content_hash
@@ -13564,14 +13660,14 @@ function addColumnIfMissing23(db, table, column, definition) {
13564
13660
  return;
13565
13661
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
13566
13662
  }
13567
- function up92(db) {
13663
+ function up93(db) {
13568
13664
  addColumnIfMissing23(db, "summary_jobs", "boundary_reason", "TEXT");
13569
13665
  db.exec(`
13570
13666
  CREATE INDEX IF NOT EXISTS idx_summary_jobs_boundary_reason
13571
13667
  ON summary_jobs(agent_id, session_key, boundary_reason)
13572
13668
  `);
13573
13669
  }
13574
- function up93(db) {
13670
+ function up94(db) {
13575
13671
  db.exec(`
13576
13672
  CREATE TABLE IF NOT EXISTS transcript_recovery_files (
13577
13673
  agent_id TEXT NOT NULL,
@@ -13589,7 +13685,7 @@ function up93(db) {
13589
13685
  ON transcript_capture_jobs(agent_id, session_id, status);
13590
13686
  `);
13591
13687
  }
13592
- function up94(db) {
13688
+ function up95(db) {
13593
13689
  db.exec(`
13594
13690
  CREATE TABLE IF NOT EXISTS job_cancellations (
13595
13691
  id TEXT PRIMARY KEY,
@@ -13617,7 +13713,7 @@ function indexExists(db, table, indexName) {
13617
13713
  const rows = db.prepare(`PRAGMA index_list(${table})`).all();
13618
13714
  return rows.some((row) => row.name === indexName);
13619
13715
  }
13620
- function up95(db) {
13716
+ function up96(db) {
13621
13717
  db.exec(`
13622
13718
  CREATE TABLE IF NOT EXISTS job_archive (
13623
13719
  id TEXT PRIMARY KEY,
@@ -13644,7 +13740,7 @@ function indexExists2(db, table, indexName) {
13644
13740
  const rows = db.prepare(`PRAGMA index_list(${table})`).all();
13645
13741
  return rows.some((row) => row.name === indexName);
13646
13742
  }
13647
- function up96(db) {
13743
+ function up97(db) {
13648
13744
  db.exec(`
13649
13745
  CREATE TABLE IF NOT EXISTS embedding_index_state (
13650
13746
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -13657,7 +13753,7 @@ function up96(db) {
13657
13753
  )
13658
13754
  `);
13659
13755
  }
13660
- function up97(db) {
13756
+ function up98(db) {
13661
13757
  db.exec(`
13662
13758
  CREATE TABLE IF NOT EXISTS embeddings_staging (
13663
13759
  id TEXT PRIMARY KEY,
@@ -13676,7 +13772,7 @@ function up97(db) {
13676
13772
  ON embeddings_staging(agent_id, source_type, source_id);
13677
13773
  `);
13678
13774
  }
13679
- function up98(db) {
13775
+ function up99(db) {
13680
13776
  const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
13681
13777
  if (!columns.some((column) => column.name === "evidence_cursor")) {
13682
13778
  db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
@@ -13687,7 +13783,7 @@ function hasColumn13(db, table, column) {
13687
13783
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
13688
13784
  return rows.some((r) => r.name === column);
13689
13785
  }
13690
- function up99(db) {
13786
+ function up100(db) {
13691
13787
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
13692
13788
  if (tables.length === 0)
13693
13789
  return;
@@ -13712,23 +13808,23 @@ function up99(db) {
13712
13808
  function hasColumn14(db, table, column) {
13713
13809
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
13714
13810
  }
13715
- function up100(db) {
13811
+ function up101(db) {
13716
13812
  const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
13717
13813
  if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
13718
13814
  return;
13719
13815
  db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
13720
13816
  }
13721
- function up101(db) {
13817
+ function up102(db) {
13722
13818
  db.exec("DROP TABLE IF EXISTS ingestion_jobs");
13723
13819
  }
13724
- function up102(db) {
13820
+ function up103(db) {
13725
13821
  const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
13726
13822
  if (!columns.some((column) => column.name === "last_failure_at")) {
13727
13823
  db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
13728
13824
  }
13729
13825
  db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
13730
13826
  }
13731
- function up103(db) {
13827
+ function up104(db) {
13732
13828
  db.exec(`
13733
13829
  CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
13734
13830
  agent_id TEXT NOT NULL,
@@ -13745,7 +13841,7 @@ function up103(db) {
13745
13841
  ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
13746
13842
  `);
13747
13843
  }
13748
- function up104(db) {
13844
+ function up105(db) {
13749
13845
  db.exec(`
13750
13846
  CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
13751
13847
  id TEXT PRIMARY KEY,
@@ -13765,7 +13861,7 @@ function up104(db) {
13765
13861
  ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
13766
13862
  `);
13767
13863
  }
13768
- function up105(db) {
13864
+ function up106(db) {
13769
13865
  const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
13770
13866
  if (!columns.some((column) => column.name === "evidence_window_json")) {
13771
13867
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
@@ -13774,7 +13870,7 @@ function up105(db) {
13774
13870
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
13775
13871
  }
13776
13872
  }
13777
- function up106(db) {
13873
+ function up107(db) {
13778
13874
  db.exec(`
13779
13875
  CREATE TABLE IF NOT EXISTS dreaming_attention (
13780
13876
  id TEXT PRIMARY KEY,
@@ -13796,7 +13892,7 @@ function up106(db) {
13796
13892
  function hasColumn15(db, table, column) {
13797
13893
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
13798
13894
  }
13799
- function up107(db) {
13895
+ function up108(db) {
13800
13896
  const requiredMemoryColumns = [
13801
13897
  "content_hash",
13802
13898
  "normalized_content",
@@ -13847,7 +13943,7 @@ function up107(db) {
13847
13943
  WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
13848
13944
  `);
13849
13945
  }
13850
- function up108(db) {
13946
+ function up109(db) {
13851
13947
  const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
13852
13948
  if (tables.length !== 2)
13853
13949
  return;
@@ -13870,7 +13966,7 @@ function tableExists(db, table) {
13870
13966
  function hasColumn16(db, table, column) {
13871
13967
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
13872
13968
  }
13873
- function up109(db) {
13969
+ function up110(db) {
13874
13970
  db.exec(`
13875
13971
  CREATE TABLE IF NOT EXISTS derived_memory_sources (
13876
13972
  derived_memory_id TEXT NOT NULL,
@@ -13913,7 +14009,7 @@ function up109(db) {
13913
14009
  `);
13914
14010
  }
13915
14011
  }
13916
- function up110(db) {
14012
+ function up111(db) {
13917
14013
  db.exec(`
13918
14014
  DROP TRIGGER IF EXISTS entities_fts_ai;
13919
14015
  DROP TRIGGER IF EXISTS entities_fts_ad;
@@ -14002,7 +14098,7 @@ function up110(db) {
14002
14098
  function hasColumn17(db, table, column) {
14003
14099
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
14004
14100
  }
14005
- function up111(db) {
14101
+ function up112(db) {
14006
14102
  if (!hasColumn17(db, "memories", "review_after")) {
14007
14103
  db.exec("ALTER TABLE memories ADD COLUMN review_after TEXT;");
14008
14104
  }
@@ -14018,14 +14114,14 @@ var TOKEN_COLUMNS = [
14018
14114
  ["tokens_cache_write", "INTEGER"],
14019
14115
  ["tokens_cost", "REAL"]
14020
14116
  ];
14021
- function up112(db) {
14117
+ function up113(db) {
14022
14118
  for (const [column, type] of TOKEN_COLUMNS) {
14023
14119
  if (!hasColumn18(db, "dreaming_passes", column)) {
14024
14120
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${column} ${type};`);
14025
14121
  }
14026
14122
  }
14027
14123
  }
14028
- function up113(db) {
14124
+ function up114(db) {
14029
14125
  db.exec(`
14030
14126
  CREATE TABLE IF NOT EXISTS embedding_usage (
14031
14127
  day TEXT NOT NULL,
@@ -14038,7 +14134,7 @@ function up113(db) {
14038
14134
  );
14039
14135
  `);
14040
14136
  }
14041
- function up114(db) {
14137
+ function up115(db) {
14042
14138
  db.exec(`
14043
14139
  CREATE TABLE IF NOT EXISTS telemetry_install (
14044
14140
  id TEXT PRIMARY KEY,
@@ -14046,7 +14142,7 @@ function up114(db) {
14046
14142
  );
14047
14143
  `);
14048
14144
  }
14049
- function up115(db) {
14145
+ function up116(db) {
14050
14146
  db.exec(`
14051
14147
  CREATE INDEX IF NOT EXISTS idx_memory_entity_mentions_entity_memory
14052
14148
  ON memory_entity_mentions(entity_id, memory_id);
@@ -14057,7 +14153,7 @@ function hasColumn19(db, table, column) {
14057
14153
  return rows.some((row) => row.name === column);
14058
14154
  }
14059
14155
  var COLUMNS2 = ["first_remember_at", "first_recall_at"];
14060
- function up116(db) {
14156
+ function up117(db) {
14061
14157
  for (const column of COLUMNS2) {
14062
14158
  if (!hasColumn19(db, "telemetry_install", column)) {
14063
14159
  db.exec(`ALTER TABLE telemetry_install ADD COLUMN ${column} TEXT`);
@@ -14073,7 +14169,7 @@ function addColumnIfMissing24(db, column, definition) {
14073
14169
  db.exec(`ALTER TABLE telemetry_events ADD COLUMN ${column} ${definition}`);
14074
14170
  }
14075
14171
  }
14076
- function up117(db) {
14172
+ function up118(db) {
14077
14173
  addColumnIfMissing24(db, "source", "TEXT NOT NULL DEFAULT 'daemon'");
14078
14174
  addColumnIfMissing24(db, "claim_token", "TEXT");
14079
14175
  addColumnIfMissing24(db, "claimed_at", "TEXT");
@@ -14082,7 +14178,7 @@ function up117(db) {
14082
14178
  ON telemetry_events(source, sent_to_posthog, claimed_at, timestamp);
14083
14179
  `);
14084
14180
  }
14085
- function up118(db) {
14181
+ function up119(db) {
14086
14182
  db.exec(`
14087
14183
  CREATE TABLE IF NOT EXISTS session_claims (
14088
14184
  session_key TEXT NOT NULL,
@@ -14103,7 +14199,7 @@ function up118(db) {
14103
14199
  ON session_claims(agent_id, state, expires_at);
14104
14200
  `);
14105
14201
  }
14106
- function up119(db) {
14202
+ function up120(db) {
14107
14203
  const table = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'entity_attributes'").get();
14108
14204
  if (table == null)
14109
14205
  return;
@@ -14112,7 +14208,7 @@ function up119(db) {
14112
14208
  ON entity_attributes(memory_id, agent_id, status, importance);
14113
14209
  `);
14114
14210
  }
14115
- function up120(db) {
14211
+ function up121(db) {
14116
14212
  db.exec(`
14117
14213
  CREATE TABLE IF NOT EXISTS cross_agent_messages (
14118
14214
  id TEXT PRIMARY KEY,
@@ -14169,7 +14265,7 @@ function addColumnIfMissing25(db, column, definition) {
14169
14265
  db.exec(`ALTER TABLE cross_agent_messages ADD COLUMN ${column} ${definition}`);
14170
14266
  }
14171
14267
  }
14172
- function up121(db) {
14268
+ function up122(db) {
14173
14269
  const table = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'cross_agent_messages'").get();
14174
14270
  if (table == null)
14175
14271
  return;
@@ -14370,7 +14466,7 @@ function backfillTranscriptsFromSummaryJobs(db) {
14370
14466
  insert.run(...values);
14371
14467
  }
14372
14468
  }
14373
- function up122(db) {
14469
+ function up123(db) {
14374
14470
  if (!hasTable4(db, "session_transcripts"))
14375
14471
  return;
14376
14472
  addColumnIfMissing26(db, "session_transcripts", "completed_at", "TEXT");
@@ -14423,7 +14519,7 @@ function up122(db) {
14423
14519
  ON session_transcripts(agent_id, content_hash);
14424
14520
  `);
14425
14521
  }
14426
- function up123(db) {
14522
+ function up124(db) {
14427
14523
  db.exec(`
14428
14524
  CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_status
14429
14525
  ON memory_jobs(status)
@@ -14442,12 +14538,12 @@ function up123(db) {
14442
14538
  function hasColumn22(db, table, column) {
14443
14539
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
14444
14540
  }
14445
- function up124(db) {
14541
+ function up125(db) {
14446
14542
  if (!hasColumn22(db, "telemetry_install", "last_seen_version")) {
14447
14543
  db.exec("ALTER TABLE telemetry_install ADD COLUMN last_seen_version TEXT");
14448
14544
  }
14449
14545
  }
14450
- function up125(db) {
14546
+ function up126(db) {
14451
14547
  db.exec(`
14452
14548
  CREATE TABLE IF NOT EXISTS source_lifecycle_state (
14453
14549
  agent_id TEXT NOT NULL,
@@ -14476,7 +14572,7 @@ function addColumnIfMissing27(db, column, definition) {
14476
14572
  db.exec(`ALTER TABLE telemetry_events ADD COLUMN ${column} ${definition}`);
14477
14573
  }
14478
14574
  }
14479
- function up126(db) {
14575
+ function up127(db) {
14480
14576
  addColumnIfMissing27(db, "delivery_attempts", "INTEGER NOT NULL DEFAULT 0");
14481
14577
  addColumnIfMissing27(db, "last_attempt_at", "TEXT");
14482
14578
  addColumnIfMissing27(db, "sent_at", "TEXT");
@@ -14497,7 +14593,7 @@ function up126(db) {
14497
14593
  VALUES (1, CURRENT_TIMESTAMP);
14498
14594
  `);
14499
14595
  }
14500
- function up127(db) {
14596
+ function up128(db) {
14501
14597
  const columns = db.prepare("PRAGMA table_info(dreaming_evidence_exclusions)").all();
14502
14598
  const names = new Set(columns.map((column) => column.name));
14503
14599
  if (!names.has("failure_class")) {
@@ -14514,7 +14610,7 @@ function up127(db) {
14514
14610
  }
14515
14611
  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)");
14516
14612
  }
14517
- function up128(db) {
14613
+ function up129(db) {
14518
14614
  db.exec(`
14519
14615
  CREATE TABLE IF NOT EXISTS embedding_index_failures (
14520
14616
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -14538,7 +14634,7 @@ function up128(db) {
14538
14634
  ON embedding_index_failures(source_type, source_id);
14539
14635
  `);
14540
14636
  }
14541
- function up129(db) {
14637
+ function up130(db) {
14542
14638
  db.exec(`
14543
14639
  CREATE TABLE IF NOT EXISTS imported_source_lifecycle (
14544
14640
  id TEXT PRIMARY KEY,
@@ -14556,7 +14652,7 @@ function up129(db) {
14556
14652
  ON imported_source_lifecycle(agent_id, status, updated_at DESC);
14557
14653
  `);
14558
14654
  }
14559
- function up130(db) {
14655
+ function up131(db) {
14560
14656
  db.exec(`
14561
14657
  CREATE TABLE IF NOT EXISTS memory_content_safety (
14562
14658
  agent_id TEXT NOT NULL,
@@ -14576,7 +14672,7 @@ function up130(db) {
14576
14672
  ON memory_content_safety(agent_id, source_kind, context_eligible);
14577
14673
  `);
14578
14674
  }
14579
- function up131(db) {
14675
+ function up132(db) {
14580
14676
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
14581
14677
  if (!table)
14582
14678
  return;
@@ -14610,7 +14706,7 @@ function up131(db) {
14610
14706
  ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
14611
14707
  `);
14612
14708
  }
14613
- function up132(db) {
14709
+ function up133(db) {
14614
14710
  db.exec(`
14615
14711
  CREATE TABLE IF NOT EXISTS ontology_contradictions (
14616
14712
  id TEXT PRIMARY KEY,
@@ -14666,7 +14762,7 @@ function up132(db) {
14666
14762
  ON ontology_contradictions(agent_id, left_source_id, right_source_id);
14667
14763
  `);
14668
14764
  }
14669
- function up133(db) {
14765
+ function up134(db) {
14670
14766
  db.exec(`
14671
14767
  CREATE INDEX IF NOT EXISTS idx_memory_jobs_diagnostics_status_created_at
14672
14768
  ON memory_jobs(status, created_at)
@@ -14681,7 +14777,7 @@ function up133(db) {
14681
14777
  function tableExists2(db, table) {
14682
14778
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
14683
14779
  }
14684
- function up134(db) {
14780
+ function up135(db) {
14685
14781
  if (!tableExists2(db, "memory_jobs"))
14686
14782
  return;
14687
14783
  if (!tableExists2(db, "job_cancellations")) {
@@ -14730,7 +14826,7 @@ function up134(db) {
14730
14826
  AND status IN ('pending', 'leased');
14731
14827
  `);
14732
14828
  }
14733
- function up135(db) {
14829
+ function up136(db) {
14734
14830
  db.exec(`
14735
14831
  CREATE TABLE IF NOT EXISTS embedding_repair_budget (
14736
14832
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -14770,7 +14866,7 @@ function up135(db) {
14770
14866
  END;
14771
14867
  `);
14772
14868
  }
14773
- function up136(db) {
14869
+ function up137(db) {
14774
14870
  db.exec(`
14775
14871
  CREATE TABLE IF NOT EXISTS dreaming_evidence_consumption (
14776
14872
  agent_id TEXT NOT NULL,
@@ -14793,13 +14889,13 @@ function up136(db) {
14793
14889
  ON dreaming_evidence_consumption(agent_id, pass_id, delivered_offset, source_length);
14794
14890
  `);
14795
14891
  }
14796
- function up137(db) {
14892
+ function up138(db) {
14797
14893
  db.exec(`
14798
14894
  CREATE INDEX IF NOT EXISTS idx_epistemic_assertions_observer_entity
14799
14895
  ON epistemic_assertions(agent_id, subject_entity_id, status, asserted_at DESC, created_at DESC);
14800
14896
  `);
14801
14897
  }
14802
- function up138(db) {
14898
+ function up139(db) {
14803
14899
  db.exec(`
14804
14900
  CREATE TABLE IF NOT EXISTS memory_head_revisions (
14805
14901
  id TEXT PRIMARY KEY,
@@ -14851,7 +14947,7 @@ function up138(db) {
14851
14947
  if (!names.has("format_version"))
14852
14948
  db.exec("ALTER TABLE memory_md_heads ADD COLUMN format_version INTEGER NOT NULL DEFAULT 1");
14853
14949
  }
14854
- function up139(db) {
14950
+ function up140(db) {
14855
14951
  db.exec(`
14856
14952
  CREATE TABLE memory_head_entries_v134 (
14857
14953
  entry_id TEXT NOT NULL, agent_id TEXT NOT NULL, canonical_text TEXT NOT NULL,
@@ -14869,7 +14965,7 @@ function up139(db) {
14869
14965
  ON memory_head_entries(agent_id, entry_id, last_revision DESC);
14870
14966
  `);
14871
14967
  }
14872
- function up140(db) {
14968
+ function up141(db) {
14873
14969
  db.exec(`
14874
14970
  CREATE TABLE IF NOT EXISTS memory_head_publications (
14875
14971
  agent_id TEXT NOT NULL,
@@ -14885,7 +14981,7 @@ function up140(db) {
14885
14981
  ON memory_head_publications(agent_id, status, revision DESC);
14886
14982
  `);
14887
14983
  }
14888
- function up141(db) {
14984
+ function up142(db) {
14889
14985
  const cols = new Set(db.prepare("PRAGMA table_info(memory_head_revisions)").all().map((r) => r.name));
14890
14986
  for (const [name, type] of [
14891
14987
  ["entry_id", "TEXT"],
@@ -14899,7 +14995,7 @@ function up141(db) {
14899
14995
  }
14900
14996
  db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_head_revisions_entry ON memory_head_revisions(agent_id, revision, entry_id)");
14901
14997
  }
14902
- function up142(db) {
14998
+ function up143(db) {
14903
14999
  const cols = new Set(db.prepare("PRAGMA table_info(dreaming_passes)").all().map((r) => r.name));
14904
15000
  for (const [name, type] of [
14905
15001
  ["head_revision", "INTEGER"],
@@ -14921,7 +15017,7 @@ function addColumnIfMissing28(db, table, column, definition) {
14921
15017
  if (!hasColumn24(db, table, column))
14922
15018
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
14923
15019
  }
14924
- function up143(db) {
15020
+ function up144(db) {
14925
15021
  addColumnIfMissing28(db, "memories", "manual_override", "INTEGER DEFAULT 0");
14926
15022
  db.exec(`
14927
15023
  CREATE TABLE IF NOT EXISTS transcript_capture_status (
@@ -15226,7 +15322,7 @@ function up143(db) {
15226
15322
  GROUP BY j.agent_id;
15227
15323
  `);
15228
15324
  }
15229
- function up144(db) {
15325
+ function up145(db) {
15230
15326
  db.exec(`
15231
15327
  CREATE TABLE IF NOT EXISTS native_source_sync_state (
15232
15328
  agent_id TEXT NOT NULL,
@@ -15242,7 +15338,7 @@ function up144(db) {
15242
15338
  ON native_source_sync_state(agent_id, status);
15243
15339
  `);
15244
15340
  }
15245
- function up145(db) {
15341
+ function up146(db) {
15246
15342
  db.exec(`
15247
15343
  CREATE TABLE IF NOT EXISTS transcript_recovery_frontiers (
15248
15344
  agent_id TEXT NOT NULL,
@@ -15254,7 +15350,7 @@ function up145(db) {
15254
15350
  );
15255
15351
  `);
15256
15352
  }
15257
- function up146(db) {
15353
+ function up147(db) {
15258
15354
  db.exec(`
15259
15355
  CREATE TABLE IF NOT EXISTS source_sync_checkpoints (
15260
15356
  agent_id TEXT NOT NULL,
@@ -15268,13 +15364,13 @@ function up146(db) {
15268
15364
  );
15269
15365
  `);
15270
15366
  }
15271
- function up147(db) {
15367
+ function up148(db) {
15272
15368
  const columns = db.prepare("PRAGMA table_info(source_sync_checkpoints)").all();
15273
15369
  if (!columns.some((column) => column.name === "frontier")) {
15274
15370
  db.exec("ALTER TABLE source_sync_checkpoints ADD COLUMN frontier TEXT");
15275
15371
  }
15276
15372
  }
15277
- function up148(db) {
15373
+ function up149(db) {
15278
15374
  const columns = new Set(db.prepare("PRAGMA table_info(embedding_index_state)").all().map((row) => row.name).filter((name) => typeof name === "string"));
15279
15375
  const additions = [
15280
15376
  ["migration_phase", "TEXT"],
@@ -15309,13 +15405,13 @@ function up148(db) {
15309
15405
  `);
15310
15406
  }
15311
15407
  }
15312
- function up149(db) {
15408
+ function up150(db) {
15313
15409
  const columns = new Set(db.prepare("PRAGMA table_info(memory_jobs)").all().map((row) => row.name).filter((name) => typeof name === "string"));
15314
15410
  if (!columns.has("lease_token")) {
15315
15411
  db.exec("ALTER TABLE memory_jobs ADD COLUMN lease_token TEXT");
15316
15412
  }
15317
15413
  }
15318
- function up150(db) {
15414
+ function up151(db) {
15319
15415
  db.exec(`
15320
15416
  CREATE TABLE IF NOT EXISTS dreaming_evidence_reviews (
15321
15417
  agent_id TEXT NOT NULL,
@@ -15333,7 +15429,7 @@ function up150(db) {
15333
15429
  ON dreaming_evidence_reviews (agent_id, reviewed_at DESC);
15334
15430
  `);
15335
15431
  }
15336
- function up151(db) {
15432
+ function up152(db) {
15337
15433
  db.exec(`
15338
15434
  CREATE TABLE IF NOT EXISTS source_import_jobs (
15339
15435
  id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind = 'import'), agent_id TEXT NOT NULL,
@@ -15400,16 +15496,16 @@ function up151(db) {
15400
15496
  }
15401
15497
  db.exec("CREATE INDEX IF NOT EXISTS idx_session_transcripts_agent_source ON session_transcripts(agent_id, source_id)");
15402
15498
  }
15403
- function up152(db) {
15499
+ function up153(db) {
15404
15500
  db.exec("CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state)");
15405
15501
  }
15406
- function up153(db) {
15502
+ function up154(db) {
15407
15503
  const columns = db.prepare("PRAGMA table_info(source_import_record_attempts)").all();
15408
15504
  if (!columns.some((column) => column.name === "source_id")) {
15409
15505
  db.exec("ALTER TABLE source_import_record_attempts ADD COLUMN source_id TEXT");
15410
15506
  }
15411
15507
  }
15412
- function up154(db) {
15508
+ function up155(db) {
15413
15509
  const addColumn = (table, column, definition) => {
15414
15510
  const statement = db.prepare("SELECT 1 AS found FROM pragma_table_info(?) WHERE name = ?");
15415
15511
  let exists;
@@ -15430,7 +15526,7 @@ function addColumnIfMissing29(db, table, column, definition) {
15430
15526
  if (!columns.some((row) => row.name === column))
15431
15527
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
15432
15528
  }
15433
- function up155(db) {
15529
+ function up156(db) {
15434
15530
  addColumnIfMissing29(db, "memory_md_heads", "is_current", "INTEGER NOT NULL DEFAULT 0");
15435
15531
  addColumnIfMissing29(db, "dreaming_passes", "head_base_revision", "INTEGER");
15436
15532
  db.exec("CREATE INDEX IF NOT EXISTS idx_memory_head_revisions_content_hash ON memory_head_revisions(content_hash)");
@@ -15580,7 +15676,7 @@ function up155(db) {
15580
15676
  `);
15581
15677
  }
15582
15678
  }
15583
- function up156(db) {
15679
+ function up157(db) {
15584
15680
  db.exec(`
15585
15681
  CREATE TABLE IF NOT EXISTS vector_repair_checkpoints (
15586
15682
  operation TEXT NOT NULL CHECK (operation IN ('resync', 'clean-orphans')),
@@ -15605,7 +15701,7 @@ function up156(db) {
15605
15701
  ON vector_repair_checkpoints(status, updated_at);
15606
15702
  `);
15607
15703
  }
15608
- function up157(db) {
15704
+ function up158(db) {
15609
15705
  db.exec(`
15610
15706
  CREATE TABLE IF NOT EXISTS embedding_repair_checkpoints (
15611
15707
  checkpoint_id TEXT PRIMARY KEY,
@@ -15626,7 +15722,7 @@ function up157(db) {
15626
15722
  ON embedding_repair_checkpoints(status, updated_at);
15627
15723
  `);
15628
15724
  }
15629
- function up158(db) {
15725
+ function up159(db) {
15630
15726
  const columns = new Set(db.prepare("PRAGMA table_info(embedding_repair_checkpoints)").all().map((row) => row.name));
15631
15727
  if (!columns.has("profile_fingerprint")) {
15632
15728
  db.exec("ALTER TABLE embedding_repair_checkpoints ADD COLUMN profile_fingerprint TEXT");
@@ -15641,7 +15737,7 @@ function up158(db) {
15641
15737
  );
15642
15738
  `);
15643
15739
  }
15644
- function up159(db) {
15740
+ function up160(db) {
15645
15741
  db.exec(`
15646
15742
  CREATE INDEX IF NOT EXISTS idx_memories_agent_kind
15647
15743
  ON memories(agent_id, memory_kind);
@@ -15708,7 +15804,7 @@ function rebuildLedgerWithoutGlobalKeyPrimaryKey(db) {
15708
15804
  throw error;
15709
15805
  }
15710
15806
  }
15711
- function up160(db) {
15807
+ function up161(db) {
15712
15808
  db.exec(`
15713
15809
  CREATE TABLE IF NOT EXISTS import_admission_ledger (
15714
15810
  key TEXT NOT NULL, agent_id TEXT NOT NULL, workspace_id TEXT NOT NULL DEFAULT '', file_name TEXT NOT NULL,
@@ -15743,13 +15839,13 @@ function up160(db) {
15743
15839
  CREATE INDEX IF NOT EXISTS idx_import_admission_events_key ON import_admission_events(admission_key, agent_id, workspace_id, id);
15744
15840
  `);
15745
15841
  }
15746
- function up161(db) {
15842
+ function up162(db) {
15747
15843
  db.exec(`
15748
15844
  CREATE INDEX IF NOT EXISTS idx_entities_agent_updated_id
15749
15845
  ON entities(agent_id, updated_at DESC, id DESC);
15750
15846
  `);
15751
15847
  }
15752
- function up162(db) {
15848
+ function up163(db) {
15753
15849
  db.exec(`
15754
15850
  CREATE TABLE IF NOT EXISTS generic_entity_prune_scan_state (
15755
15851
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -15790,7 +15886,7 @@ function up162(db) {
15790
15886
  END;
15791
15887
  `);
15792
15888
  }
15793
- function up163(db) {
15889
+ function up164(db) {
15794
15890
  db.exec(`
15795
15891
  DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_ai;
15796
15892
  DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_au;
@@ -15800,7 +15896,7 @@ function up163(db) {
15800
15896
  `);
15801
15897
  }
15802
15898
  var COLUMNS3 = ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"];
15803
- function up164(db) {
15899
+ function up165(db) {
15804
15900
  const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
15805
15901
  for (const column of COLUMNS3) {
15806
15902
  if (!cols.some((col) => col.name === column)) {
@@ -15808,7 +15904,7 @@ function up164(db) {
15808
15904
  }
15809
15905
  }
15810
15906
  }
15811
- function up165(db) {
15907
+ function up166(db) {
15812
15908
  const passColumns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15813
15909
  if (!passColumns.some((column) => column.name === "scope_key")) {
15814
15910
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN scope_key TEXT");
@@ -15831,13 +15927,13 @@ function up165(db) {
15831
15927
  ON dreaming_history_nodes(pass_id) WHERE pass_id IS NOT NULL;
15832
15928
  `);
15833
15929
  }
15834
- function up166(db) {
15930
+ function up167(db) {
15835
15931
  const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15836
15932
  if (!columns.some((column) => column.name === "tokens_peak_context")) {
15837
15933
  db.exec("ALTER TABLE dreaming_passes ADD COLUMN tokens_peak_context INTEGER");
15838
15934
  }
15839
15935
  }
15840
- function up167(db) {
15936
+ function up168(db) {
15841
15937
  const sql = readMemoriesFtsSql(db);
15842
15938
  if (sql !== null && !memoriesFtsNeedsTokenizerRepair(sql))
15843
15939
  return;
@@ -15849,7 +15945,7 @@ function hasTable5(db, table) {
15849
15945
  function hasColumn25(db, table, column) {
15850
15946
  return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
15851
15947
  }
15852
- function up168(db) {
15948
+ function up169(db) {
15853
15949
  if (!hasTable5(db, "entity_attributes") || !hasTable5(db, "entity_aspects") || !hasTable5(db, "entities") || !hasColumn25(db, "entity_attributes", "source_root") || !hasColumn25(db, "entities", "source_root")) {
15854
15950
  return;
15855
15951
  }
@@ -15922,7 +16018,7 @@ function up168(db) {
15922
16018
  DROP TABLE retired_source_paragraphs;
15923
16019
  `);
15924
16020
  }
15925
- function up169(db) {
16021
+ function up170(db) {
15926
16022
  if (db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_evidence_consumption'").get() == null)
15927
16023
  return;
15928
16024
  const columns = db.prepare("PRAGMA table_info(dreaming_evidence_consumption)").all();
@@ -15933,7 +16029,7 @@ function up169(db) {
15933
16029
  db.exec("ALTER TABLE dreaming_evidence_consumption ADD COLUMN stalled_passes INTEGER NOT NULL DEFAULT 0 CHECK (stalled_passes >= 0)");
15934
16030
  }
15935
16031
  }
15936
- function up170(db) {
16032
+ function up171(db) {
15937
16033
  db.exec(`
15938
16034
  CREATE TABLE IF NOT EXISTS dependency_history_compaction_state (
15939
16035
  id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -15944,7 +16040,7 @@ function up170(db) {
15944
16040
  INSERT OR IGNORE INTO dependency_history_compaction_state (id) VALUES (1);
15945
16041
  `);
15946
16042
  }
15947
- function up171(db) {
16043
+ function up172(db) {
15948
16044
  db.exec(`
15949
16045
  CREATE TABLE IF NOT EXISTS cross_agent_message_wakes (
15950
16046
  message_id TEXT PRIMARY KEY,
@@ -16123,17 +16219,38 @@ function repairBoardNotices(db) {
16123
16219
  throw error;
16124
16220
  }
16125
16221
  }
16222
+ function up173(db) {
16223
+ db.exec(`
16224
+ CREATE TABLE IF NOT EXISTS dreaming_policies (
16225
+ hash TEXT PRIMARY KEY,
16226
+ text TEXT NOT NULL,
16227
+ created_at TEXT NOT NULL
16228
+ );
16229
+ `);
16230
+ const columns = new Set(db.prepare("PRAGMA table_info(dreaming_passes)").all().map((column) => column.name));
16231
+ if (!columns.has("policy_hash"))
16232
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN policy_hash TEXT");
16233
+ if (!columns.has("policy_source"))
16234
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN policy_source TEXT CHECK (policy_source IN ('default', 'custom'))");
16235
+ }
16236
+ function up174(db) {
16237
+ db.exec(`
16238
+ CREATE INDEX IF NOT EXISTS idx_memory_artifacts_native_paths
16239
+ ON memory_artifacts(agent_id, harness, source_kind, source_id, source_path, is_deleted)
16240
+ WHERE is_deleted = 0 AND harness IS NOT NULL
16241
+ `);
16242
+ }
16126
16243
  var MIGRATIONS = [
16127
16244
  {
16128
16245
  version: 1,
16129
16246
  name: "baseline",
16130
- up: up6,
16247
+ up: up7,
16131
16248
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
16132
16249
  },
16133
16250
  {
16134
16251
  version: 2,
16135
16252
  name: "pipeline-v2",
16136
- up: up7,
16253
+ up: up8,
16137
16254
  artifacts: {
16138
16255
  tables: ["memory_history", "memory_jobs", "entities", "relations", "memory_entity_mentions"]
16139
16256
  }
@@ -16141,12 +16258,12 @@ var MIGRATIONS = [
16141
16258
  {
16142
16259
  version: 3,
16143
16260
  name: "unique-content-hash",
16144
- up: up8
16261
+ up: up9
16145
16262
  },
16146
16263
  {
16147
16264
  version: 4,
16148
16265
  name: "history-actor-and-retention",
16149
- up: up9,
16266
+ up: up10,
16150
16267
  artifacts: {
16151
16268
  columns: [{ table: "memory_history", column: "actor_type" }]
16152
16269
  }
@@ -16154,7 +16271,7 @@ var MIGRATIONS = [
16154
16271
  {
16155
16272
  version: 5,
16156
16273
  name: "graph-extended",
16157
- up: up10,
16274
+ up: up11,
16158
16275
  artifacts: {
16159
16276
  columns: [{ table: "entities", column: "canonical_name" }]
16160
16277
  }
@@ -16162,7 +16279,7 @@ var MIGRATIONS = [
16162
16279
  {
16163
16280
  version: 6,
16164
16281
  name: "idempotency-key",
16165
- up: up11,
16282
+ up: up12,
16166
16283
  artifacts: {
16167
16284
  columns: [{ table: "memories", column: "idempotency_key" }]
16168
16285
  }
@@ -16170,42 +16287,42 @@ var MIGRATIONS = [
16170
16287
  {
16171
16288
  version: 7,
16172
16289
  name: "documents-and-connectors",
16173
- up: up12,
16290
+ up: up13,
16174
16291
  artifacts: { tables: ["documents", "document_memories", "connectors"] }
16175
16292
  },
16176
16293
  {
16177
16294
  version: 8,
16178
16295
  name: "embeddings-unique-hash",
16179
- up: up13
16296
+ up: up14
16180
16297
  },
16181
16298
  {
16182
16299
  version: 9,
16183
16300
  name: "summary-jobs",
16184
- up: up14,
16301
+ up: up15,
16185
16302
  artifacts: { tables: ["summary_jobs"] }
16186
16303
  },
16187
16304
  {
16188
16305
  version: 10,
16189
16306
  name: "umap-cache",
16190
- up: up15,
16307
+ up: up16,
16191
16308
  artifacts: { tables: ["umap_cache"] }
16192
16309
  },
16193
16310
  {
16194
16311
  version: 11,
16195
16312
  name: "session-scores",
16196
- up: up16,
16313
+ up: up17,
16197
16314
  artifacts: { tables: ["session_scores"] }
16198
16315
  },
16199
16316
  {
16200
16317
  version: 12,
16201
16318
  name: "scheduled-tasks",
16202
- up: up17,
16319
+ up: up18,
16203
16320
  artifacts: { tables: ["scheduled_tasks", "task_runs"] }
16204
16321
  },
16205
16322
  {
16206
16323
  version: 13,
16207
16324
  name: "ingestion-tracking",
16208
- up: up18,
16325
+ up: up19,
16209
16326
  artifacts: {
16210
16327
  columns: [
16211
16328
  { table: "memories", column: "source_path" },
@@ -16216,13 +16333,13 @@ var MIGRATIONS = [
16216
16333
  {
16217
16334
  version: 14,
16218
16335
  name: "telemetry",
16219
- up: up19,
16336
+ up: up20,
16220
16337
  artifacts: { tables: ["telemetry_events"] }
16221
16338
  },
16222
16339
  {
16223
16340
  version: 15,
16224
16341
  name: "session-memories",
16225
- up: up20,
16342
+ up: up21,
16226
16343
  artifacts: {
16227
16344
  tables: ["session_memories"],
16228
16345
  columns: [
@@ -16234,13 +16351,13 @@ var MIGRATIONS = [
16234
16351
  {
16235
16352
  version: 16,
16236
16353
  name: "session-checkpoints",
16237
- up: up21,
16354
+ up: up22,
16238
16355
  artifacts: { tables: ["session_checkpoints"] }
16239
16356
  },
16240
16357
  {
16241
16358
  version: 17,
16242
16359
  name: "task-skills",
16243
- up: up22,
16360
+ up: up23,
16244
16361
  artifacts: {
16245
16362
  columns: [{ table: "scheduled_tasks", column: "skill_name" }]
16246
16363
  }
@@ -16248,13 +16365,13 @@ var MIGRATIONS = [
16248
16365
  {
16249
16366
  version: 18,
16250
16367
  name: "skill-meta",
16251
- up: up23,
16368
+ up: up24,
16252
16369
  artifacts: { tables: ["skill_meta"] }
16253
16370
  },
16254
16371
  {
16255
16372
  version: 19,
16256
16373
  name: "knowledge-structure",
16257
- up: up24,
16374
+ up: up25,
16258
16375
  artifacts: {
16259
16376
  tables: ["entity_aspects", "entity_attributes", "entity_dependencies", "task_meta"],
16260
16377
  columns: [{ table: "entities", column: "agent_id" }]
@@ -16263,7 +16380,7 @@ var MIGRATIONS = [
16263
16380
  {
16264
16381
  version: 20,
16265
16382
  name: "session-structural-columns",
16266
- up: up25,
16383
+ up: up26,
16267
16384
  artifacts: {
16268
16385
  columns: [
16269
16386
  { table: "session_memories", column: "entity_slot" },
@@ -16276,7 +16393,7 @@ var MIGRATIONS = [
16276
16393
  {
16277
16394
  version: 21,
16278
16395
  name: "checkpoint-structural",
16279
- up: up26,
16396
+ up: up27,
16280
16397
  artifacts: {
16281
16398
  columns: [{ table: "session_checkpoints", column: "focal_entity_ids" }]
16282
16399
  }
@@ -16284,7 +16401,7 @@ var MIGRATIONS = [
16284
16401
  {
16285
16402
  version: 22,
16286
16403
  name: "entity-pinning",
16287
- up: up27,
16404
+ up: up28,
16288
16405
  artifacts: {
16289
16406
  columns: [
16290
16407
  { table: "entities", column: "pinned" },
@@ -16295,17 +16412,17 @@ var MIGRATIONS = [
16295
16412
  {
16296
16413
  version: 23,
16297
16414
  name: "retired-scorer-gap",
16298
- up: up28
16415
+ up: up29
16299
16416
  },
16300
16417
  {
16301
16418
  version: 24,
16302
16419
  name: "retired-scorer-gap",
16303
- up: up29
16420
+ up: up30
16304
16421
  },
16305
16422
  {
16306
16423
  version: 25,
16307
16424
  name: "agent-feedback",
16308
- up: up30,
16425
+ up: up31,
16309
16426
  artifacts: {
16310
16427
  columns: [{ table: "session_memories", column: "agent_relevance_score" }]
16311
16428
  }
@@ -16313,32 +16430,32 @@ var MIGRATIONS = [
16313
16430
  {
16314
16431
  version: 26,
16315
16432
  name: "retired-scorer-gap",
16316
- up: up31
16433
+ up: up32
16317
16434
  },
16318
16435
  {
16319
16436
  version: 27,
16320
16437
  name: "backfill-canonical-names",
16321
- up: up32
16438
+ up: up33
16322
16439
  },
16323
16440
  {
16324
16441
  version: 28,
16325
16442
  name: "lossless-retention",
16326
- up: up33
16443
+ up: up34
16327
16444
  },
16328
16445
  {
16329
16446
  version: 29,
16330
16447
  name: "session-summary-dag",
16331
- up: up34
16448
+ up: up35
16332
16449
  },
16333
16450
  {
16334
16451
  version: 30,
16335
16452
  name: "nullable-memory-job-memory-id",
16336
- up: up35
16453
+ up: up36
16337
16454
  },
16338
16455
  {
16339
16456
  version: 31,
16340
16457
  name: "dependency-reason",
16341
- up: up36,
16458
+ up: up37,
16342
16459
  artifacts: {
16343
16460
  columns: [
16344
16461
  { table: "entity_dependencies", column: "reason" },
@@ -16349,7 +16466,7 @@ var MIGRATIONS = [
16349
16466
  {
16350
16467
  version: 32,
16351
16468
  name: "embeddings-vector-column",
16352
- up: up37,
16469
+ up: up38,
16353
16470
  artifacts: {
16354
16471
  columns: [{ table: "embeddings", column: "vector", optional: true }]
16355
16472
  }
@@ -16357,7 +16474,7 @@ var MIGRATIONS = [
16357
16474
  {
16358
16475
  version: 33,
16359
16476
  name: "scope",
16360
- up: up38,
16477
+ up: up39,
16361
16478
  artifacts: {
16362
16479
  columns: [{ table: "memories", column: "scope" }]
16363
16480
  }
@@ -16365,17 +16482,17 @@ var MIGRATIONS = [
16365
16482
  {
16366
16483
  version: 34,
16367
16484
  name: "scope-aware-dedup",
16368
- up: up39
16485
+ up: up40
16369
16486
  },
16370
16487
  {
16371
16488
  version: 35,
16372
16489
  name: "entity-fts",
16373
- up: up40
16490
+ up: up41
16374
16491
  },
16375
16492
  {
16376
16493
  version: 36,
16377
16494
  name: "dependency-confidence",
16378
- up: up41,
16495
+ up: up42,
16379
16496
  artifacts: {
16380
16497
  columns: [{ table: "entity_dependencies", column: "confidence" }]
16381
16498
  }
@@ -16383,7 +16500,7 @@ var MIGRATIONS = [
16383
16500
  {
16384
16501
  version: 37,
16385
16502
  name: "entity-communities",
16386
- up: up42,
16503
+ up: up43,
16387
16504
  artifacts: {
16388
16505
  tables: ["entity_communities"],
16389
16506
  columns: [{ table: "entities", column: "community_id" }]
@@ -16392,24 +16509,24 @@ var MIGRATIONS = [
16392
16509
  {
16393
16510
  version: 38,
16394
16511
  name: "memory-hints",
16395
- up: up43,
16512
+ up: up44,
16396
16513
  artifacts: { tables: ["memory_hints"] }
16397
16514
  },
16398
16515
  {
16399
16516
  version: 39,
16400
16517
  name: "dedup-entity-dependencies",
16401
- up: up44
16518
+ up: up45
16402
16519
  },
16403
16520
  {
16404
16521
  version: 40,
16405
16522
  name: "session-transcripts",
16406
- up: up45,
16523
+ up: up46,
16407
16524
  artifacts: { tables: ["session_transcripts"] }
16408
16525
  },
16409
16526
  {
16410
16527
  version: 41,
16411
16528
  name: "path-feedback",
16412
- up: up46,
16529
+ up: up47,
16413
16530
  artifacts: {
16414
16531
  tables: [
16415
16532
  "path_feedback_events",
@@ -16424,7 +16541,7 @@ var MIGRATIONS = [
16424
16541
  {
16425
16542
  version: 42,
16426
16543
  name: "session-memories-agent-id",
16427
- up: up47,
16544
+ up: up48,
16428
16545
  artifacts: {
16429
16546
  columns: [{ table: "session_memories", column: "agent_id" }]
16430
16547
  }
@@ -16432,7 +16549,7 @@ var MIGRATIONS = [
16432
16549
  {
16433
16550
  version: 43,
16434
16551
  name: "agents-table",
16435
- up: up48,
16552
+ up: up49,
16436
16553
  artifacts: {
16437
16554
  tables: ["agents"],
16438
16555
  columns: [
@@ -16444,7 +16561,7 @@ var MIGRATIONS = [
16444
16561
  {
16445
16562
  version: 44,
16446
16563
  name: "memory-md-temporal-head",
16447
- up: up49,
16564
+ up: up50,
16448
16565
  artifacts: {
16449
16566
  columns: [
16450
16567
  { table: "session_summaries", column: "source_type" },
@@ -16456,7 +16573,7 @@ var MIGRATIONS = [
16456
16573
  {
16457
16574
  version: 45,
16458
16575
  name: "lossless-working-memory-hardening",
16459
- up: up50,
16576
+ up: up51,
16460
16577
  artifacts: {
16461
16578
  tables: ["session_transcripts_fts", "memory_md_heads"],
16462
16579
  columns: [
@@ -16469,17 +16586,17 @@ var MIGRATIONS = [
16469
16586
  {
16470
16587
  version: 46,
16471
16588
  name: "session-summary-uniqueness",
16472
- up: up51
16589
+ up: up52
16473
16590
  },
16474
16591
  {
16475
16592
  version: 47,
16476
16593
  name: "agent-scoped-temporal-uniqueness",
16477
- up: up52
16594
+ up: up53
16478
16595
  },
16479
16596
  {
16480
16597
  version: 48,
16481
16598
  name: "thread-heads",
16482
- up: up53,
16599
+ up: up54,
16483
16600
  artifacts: {
16484
16601
  tables: ["memory_thread_heads"]
16485
16602
  }
@@ -16487,7 +16604,7 @@ var MIGRATIONS = [
16487
16604
  {
16488
16605
  version: 49,
16489
16606
  name: "session-extract-cursors",
16490
- up: up54,
16607
+ up: up55,
16491
16608
  artifacts: {
16492
16609
  tables: ["session_extract_cursors"]
16493
16610
  }
@@ -16495,7 +16612,7 @@ var MIGRATIONS = [
16495
16612
  {
16496
16613
  version: 50,
16497
16614
  name: "related-to-audit",
16498
- up: up55,
16615
+ up: up56,
16499
16616
  artifacts: {
16500
16617
  tables: ["entity_dependency_history"]
16501
16618
  }
@@ -16503,7 +16620,7 @@ var MIGRATIONS = [
16503
16620
  {
16504
16621
  version: 51,
16505
16622
  name: "memory-md-rolling-window-lineage",
16506
- up: up56,
16623
+ up: up57,
16507
16624
  artifacts: {
16508
16625
  tables: ["memory_artifacts", "memory_artifact_tombstones", "memory_artifacts_fts"],
16509
16626
  columns: [
@@ -16518,12 +16635,12 @@ var MIGRATIONS = [
16518
16635
  {
16519
16636
  version: 52,
16520
16637
  name: "mcp-invocations",
16521
- up: up57
16638
+ up: up58
16522
16639
  },
16523
16640
  {
16524
16641
  version: 53,
16525
16642
  name: "skill-invocations",
16526
- up: up58,
16643
+ up: up59,
16527
16644
  artifacts: {
16528
16645
  tables: ["skill_invocations"]
16529
16646
  }
@@ -16531,7 +16648,7 @@ var MIGRATIONS = [
16531
16648
  {
16532
16649
  version: 54,
16533
16650
  name: "task-agent-scope",
16534
- up: up59,
16651
+ up: up60,
16535
16652
  artifacts: {
16536
16653
  tables: ["task_scope_hints"]
16537
16654
  }
@@ -16539,7 +16656,7 @@ var MIGRATIONS = [
16539
16656
  {
16540
16657
  version: 55,
16541
16658
  name: "dreaming-state",
16542
- up: up60,
16659
+ up: up61,
16543
16660
  artifacts: {
16544
16661
  tables: ["dreaming_state", "dreaming_passes"]
16545
16662
  }
@@ -16547,22 +16664,22 @@ var MIGRATIONS = [
16547
16664
  {
16548
16665
  version: 56,
16549
16666
  name: "agent-scoped-content-hash",
16550
- up: up61
16667
+ up: up62
16551
16668
  },
16552
16669
  {
16553
16670
  version: 57,
16554
16671
  name: "memories-fts-tokenizer-repair",
16555
- up: up62
16672
+ up: up63
16556
16673
  },
16557
16674
  {
16558
16675
  version: 58,
16559
16676
  name: "knowledge-graph-indices",
16560
- up: up63
16677
+ up: up64
16561
16678
  },
16562
16679
  {
16563
16680
  version: 59,
16564
16681
  name: "entity-attribute-claim-key",
16565
- up: up64,
16682
+ up: up65,
16566
16683
  artifacts: {
16567
16684
  columns: [{ table: "entity_attributes", column: "claim_key" }]
16568
16685
  }
@@ -16570,7 +16687,7 @@ var MIGRATIONS = [
16570
16687
  {
16571
16688
  version: 60,
16572
16689
  name: "entity-attribute-group-key",
16573
- up: up65,
16690
+ up: up66,
16574
16691
  artifacts: {
16575
16692
  columns: [{ table: "entity_attributes", column: "group_key" }]
16576
16693
  }
@@ -16578,7 +16695,7 @@ var MIGRATIONS = [
16578
16695
  {
16579
16696
  version: 61,
16580
16697
  name: "memory-artifact-source-mtime",
16581
- up: up66,
16698
+ up: up67,
16582
16699
  artifacts: {
16583
16700
  columns: [{ table: "memory_artifacts", column: "source_mtime_ms" }]
16584
16701
  }
@@ -16586,7 +16703,7 @@ var MIGRATIONS = [
16586
16703
  {
16587
16704
  version: 62,
16588
16705
  name: "memory-artifact-soft-delete",
16589
- up: up67,
16706
+ up: up68,
16590
16707
  artifacts: {
16591
16708
  columns: [
16592
16709
  { table: "memory_artifacts", column: "is_deleted" },
@@ -16597,12 +16714,12 @@ var MIGRATIONS = [
16597
16714
  {
16598
16715
  version: 63,
16599
16716
  name: "content-only-memories-fts-update",
16600
- up: up68
16717
+ up: up69
16601
16718
  },
16602
16719
  {
16603
16720
  version: 64,
16604
16721
  name: "source-graph-provenance",
16605
- up: up69,
16722
+ up: up70,
16606
16723
  artifacts: {
16607
16724
  columns: [
16608
16725
  { table: "entities", column: "source_path" },
@@ -16615,7 +16732,7 @@ var MIGRATIONS = [
16615
16732
  {
16616
16733
  version: 65,
16617
16734
  name: "source-embedding-agent-scope",
16618
- up: up70,
16735
+ up: up71,
16619
16736
  artifacts: {
16620
16737
  columns: [{ table: "embeddings", column: "agent_id", optional: true }]
16621
16738
  }
@@ -16623,7 +16740,7 @@ var MIGRATIONS = [
16623
16740
  {
16624
16741
  version: 66,
16625
16742
  name: "memory-search-telemetry",
16626
- up: up71,
16743
+ up: up72,
16627
16744
  artifacts: {
16628
16745
  tables: ["memory_search_telemetry"]
16629
16746
  }
@@ -16631,7 +16748,7 @@ var MIGRATIONS = [
16631
16748
  {
16632
16749
  version: 67,
16633
16750
  name: "ontology-proposals",
16634
- up: up72,
16751
+ up: up73,
16635
16752
  artifacts: {
16636
16753
  tables: ["ontology_proposals"],
16637
16754
  columns: [
@@ -16645,7 +16762,7 @@ var MIGRATIONS = [
16645
16762
  {
16646
16763
  version: 68,
16647
16764
  name: "daily-reflections",
16648
- up: up73,
16765
+ up: up74,
16649
16766
  artifacts: {
16650
16767
  tables: ["daily_reflections"]
16651
16768
  }
@@ -16653,7 +16770,7 @@ var MIGRATIONS = [
16653
16770
  {
16654
16771
  version: 69,
16655
16772
  name: "daily-reflections-multiple-insights",
16656
- up: up74,
16773
+ up: up75,
16657
16774
  artifacts: {
16658
16775
  tables: ["daily_reflections"]
16659
16776
  }
@@ -16661,7 +16778,7 @@ var MIGRATIONS = [
16661
16778
  {
16662
16779
  version: 70,
16663
16780
  name: "ontology-control-plane-state",
16664
- up: up75,
16781
+ up: up76,
16665
16782
  artifacts: {
16666
16783
  columns: [
16667
16784
  { table: "entities", column: "status" },
@@ -16676,7 +16793,7 @@ var MIGRATIONS = [
16676
16793
  {
16677
16794
  version: 71,
16678
16795
  name: "epistemic-assertions",
16679
- up: up76,
16796
+ up: up77,
16680
16797
  artifacts: {
16681
16798
  tables: ["epistemic_assertions"]
16682
16799
  }
@@ -16684,7 +16801,7 @@ var MIGRATIONS = [
16684
16801
  {
16685
16802
  version: 72,
16686
16803
  name: "agent-scoped-idempotency-key",
16687
- up: up77,
16804
+ up: up78,
16688
16805
  artifacts: {
16689
16806
  columns: [
16690
16807
  { table: "memories", column: "idempotency_key" },
@@ -16695,7 +16812,7 @@ var MIGRATIONS = [
16695
16812
  {
16696
16813
  version: 73,
16697
16814
  name: "recall-context-dedupe",
16698
- up: up78,
16815
+ up: up79,
16699
16816
  artifacts: {
16700
16817
  tables: ["session_context_epochs", "session_recall_events"]
16701
16818
  }
@@ -16703,7 +16820,7 @@ var MIGRATIONS = [
16703
16820
  {
16704
16821
  version: 74,
16705
16822
  name: "aggregate-memory-links",
16706
- up: up79,
16823
+ up: up80,
16707
16824
  artifacts: {
16708
16825
  tables: ["aggregate_memory_sources"]
16709
16826
  }
@@ -16711,7 +16828,7 @@ var MIGRATIONS = [
16711
16828
  {
16712
16829
  version: 75,
16713
16830
  name: "memory-artifact-source-provenance",
16714
- up: up80,
16831
+ up: up81,
16715
16832
  artifacts: {
16716
16833
  columns: [
16717
16834
  { table: "memory_artifacts", column: "source_id" },
@@ -16725,7 +16842,7 @@ var MIGRATIONS = [
16725
16842
  {
16726
16843
  version: 76,
16727
16844
  name: "temporal-edges",
16728
- up: up81,
16845
+ up: up82,
16729
16846
  artifacts: {
16730
16847
  tables: ["temporal_edges"]
16731
16848
  }
@@ -16733,7 +16850,7 @@ var MIGRATIONS = [
16733
16850
  {
16734
16851
  version: 77,
16735
16852
  name: "entity-aliases",
16736
- up: up82,
16853
+ up: up83,
16737
16854
  artifacts: {
16738
16855
  tables: ["entity_aliases"]
16739
16856
  }
@@ -16741,7 +16858,7 @@ var MIGRATIONS = [
16741
16858
  {
16742
16859
  version: 78,
16743
16860
  name: "api-keys",
16744
- up: up83,
16861
+ up: up84,
16745
16862
  artifacts: {
16746
16863
  tables: ["api_keys"]
16747
16864
  }
@@ -16749,7 +16866,7 @@ var MIGRATIONS = [
16749
16866
  {
16750
16867
  version: 79,
16751
16868
  name: "transcript-capture-jobs",
16752
- up: up84,
16869
+ up: up85,
16753
16870
  artifacts: {
16754
16871
  tables: ["transcript_capture_jobs"]
16755
16872
  }
@@ -16757,7 +16874,7 @@ var MIGRATIONS = [
16757
16874
  {
16758
16875
  version: 80,
16759
16876
  name: "document-scope-columns",
16760
- up: up85,
16877
+ up: up86,
16761
16878
  artifacts: {
16762
16879
  columns: [
16763
16880
  { table: "documents", column: "agent_id" },
@@ -16768,7 +16885,7 @@ var MIGRATIONS = [
16768
16885
  {
16769
16886
  version: 81,
16770
16887
  name: "aggregate-evidence-sources",
16771
- up: up86,
16888
+ up: up87,
16772
16889
  artifacts: {
16773
16890
  tables: ["aggregate_evidence_sources"]
16774
16891
  }
@@ -16776,7 +16893,7 @@ var MIGRATIONS = [
16776
16893
  {
16777
16894
  version: 82,
16778
16895
  name: "skill-invocations-harness",
16779
- up: up87,
16896
+ up: up88,
16780
16897
  artifacts: {
16781
16898
  columns: [
16782
16899
  { table: "skill_invocations", column: "harness" },
@@ -16787,7 +16904,7 @@ var MIGRATIONS = [
16787
16904
  {
16788
16905
  version: 83,
16789
16906
  name: "memory-lifecycle-repair",
16790
- up: up88,
16907
+ up: up89,
16791
16908
  artifacts: {
16792
16909
  tables: ["transcript_capture_jobs", "aggregate_evidence_sources", "entity_dependencies"],
16793
16910
  columns: [
@@ -16802,7 +16919,7 @@ var MIGRATIONS = [
16802
16919
  {
16803
16920
  version: 84,
16804
16921
  name: "legacy-markdown-import-state",
16805
- up: up89,
16922
+ up: up90,
16806
16923
  artifacts: {
16807
16924
  tables: ["legacy_markdown_imports", "legacy_markdown_chunks"]
16808
16925
  }
@@ -16810,7 +16927,7 @@ var MIGRATIONS = [
16810
16927
  {
16811
16928
  version: 85,
16812
16929
  name: "backfill-relations-to-dependencies",
16813
- up: up90,
16930
+ up: up91,
16814
16931
  artifacts: {
16815
16932
  tables: ["entity_dependencies"]
16816
16933
  }
@@ -16818,7 +16935,7 @@ var MIGRATIONS = [
16818
16935
  {
16819
16936
  version: 86,
16820
16937
  name: "summary-jobs-content-hash",
16821
- up: up91,
16938
+ up: up92,
16822
16939
  artifacts: {
16823
16940
  columns: [{ table: "summary_jobs", column: "content_hash" }]
16824
16941
  }
@@ -16826,7 +16943,7 @@ var MIGRATIONS = [
16826
16943
  {
16827
16944
  version: 87,
16828
16945
  name: "summary-jobs-boundary-reason",
16829
- up: up92,
16946
+ up: up93,
16830
16947
  artifacts: {
16831
16948
  columns: [{ table: "summary_jobs", column: "boundary_reason" }]
16832
16949
  }
@@ -16834,7 +16951,7 @@ var MIGRATIONS = [
16834
16951
  {
16835
16952
  version: 88,
16836
16953
  name: "transcript-recovery-files",
16837
- up: up93,
16954
+ up: up94,
16838
16955
  artifacts: {
16839
16956
  tables: ["transcript_recovery_files"]
16840
16957
  }
@@ -16842,7 +16959,7 @@ var MIGRATIONS = [
16842
16959
  {
16843
16960
  version: 89,
16844
16961
  name: "job-cancellations",
16845
- up: up94,
16962
+ up: up95,
16846
16963
  artifacts: {
16847
16964
  tables: ["job_cancellations"]
16848
16965
  }
@@ -16850,7 +16967,7 @@ var MIGRATIONS = [
16850
16967
  {
16851
16968
  version: 90,
16852
16969
  name: "job-archive",
16853
- up: up95,
16970
+ up: up96,
16854
16971
  artifacts: {
16855
16972
  tables: ["job_archive"]
16856
16973
  }
@@ -16858,25 +16975,25 @@ var MIGRATIONS = [
16858
16975
  {
16859
16976
  version: 91,
16860
16977
  name: "embedding-index-generations",
16861
- up: up96,
16978
+ up: up97,
16862
16979
  artifacts: { tables: ["embedding_index_state"] }
16863
16980
  },
16864
16981
  {
16865
16982
  version: 92,
16866
16983
  name: "embedding-staging-store",
16867
- up: up97,
16984
+ up: up98,
16868
16985
  artifacts: { tables: ["embeddings_staging"] }
16869
16986
  },
16870
16987
  {
16871
16988
  version: 93,
16872
16989
  name: "dreaming-evidence-cursor",
16873
- up: up98,
16990
+ up: up99,
16874
16991
  artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
16875
16992
  },
16876
16993
  {
16877
16994
  version: 94,
16878
16995
  name: "memory-kind",
16879
- up: up99,
16996
+ up: up100,
16880
16997
  artifacts: {
16881
16998
  columns: [
16882
16999
  { table: "memories", column: "memory_kind" },
@@ -16887,35 +17004,35 @@ var MIGRATIONS = [
16887
17004
  {
16888
17005
  version: 95,
16889
17006
  name: "compaction-recall-projections",
16890
- up: up100
17007
+ up: up101
16891
17008
  },
16892
17009
  {
16893
17010
  version: 96,
16894
17011
  name: "retire-legacy-ingestion",
16895
- up: up101
17012
+ up: up102
16896
17013
  },
16897
17014
  {
16898
17015
  version: 97,
16899
17016
  name: "dreaming-failure-backoff",
16900
- up: up102,
17017
+ up: up103,
16901
17018
  artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
16902
17019
  },
16903
17020
  {
16904
17021
  version: 98,
16905
17022
  name: "dreaming-evidence-exclusions",
16906
- up: up103,
17023
+ up: up104,
16907
17024
  artifacts: { tables: ["dreaming_evidence_exclusions"] }
16908
17025
  },
16909
17026
  {
16910
17027
  version: 99,
16911
17028
  name: "dreaming-tool-calls",
16912
- up: up104,
17029
+ up: up105,
16913
17030
  artifacts: { tables: ["dreaming_tool_calls"] }
16914
17031
  },
16915
17032
  {
16916
17033
  version: 100,
16917
17034
  name: "dreaming-runbook",
16918
- up: up105,
17035
+ up: up106,
16919
17036
  artifacts: {
16920
17037
  columns: [
16921
17038
  { table: "dreaming_passes", column: "evidence_window_json" },
@@ -16926,23 +17043,23 @@ var MIGRATIONS = [
16926
17043
  {
16927
17044
  version: 101,
16928
17045
  name: "dreaming-attention",
16929
- up: up106,
17046
+ up: up107,
16930
17047
  artifacts: { tables: ["dreaming_attention"] }
16931
17048
  },
16932
17049
  {
16933
17050
  version: 102,
16934
17051
  name: "attribute-semantic-memories",
16935
- up: up107
17052
+ up: up108
16936
17053
  },
16937
17054
  {
16938
17055
  version: 103,
16939
17056
  name: "semantic-memory-kind",
16940
- up: up108
17057
+ up: up109
16941
17058
  },
16942
17059
  {
16943
17060
  version: 104,
16944
17061
  name: "derived-memory-provenance",
16945
- up: up109,
17062
+ up: up110,
16946
17063
  artifacts: {
16947
17064
  tables: ["derived_memory_sources"],
16948
17065
  columns: [{ table: "memories", column: "stale_at" }]
@@ -16951,12 +17068,12 @@ var MIGRATIONS = [
16951
17068
  {
16952
17069
  version: 105,
16953
17070
  name: "agent-scoped-entity-name",
16954
- up: up110
17071
+ up: up111
16955
17072
  },
16956
17073
  {
16957
17074
  version: 106,
16958
17075
  name: "memory-review-after",
16959
- up: up111,
17076
+ up: up112,
16960
17077
  artifacts: {
16961
17078
  columns: [{ table: "memories", column: "review_after" }]
16962
17079
  }
@@ -16964,7 +17081,7 @@ var MIGRATIONS = [
16964
17081
  {
16965
17082
  version: 107,
16966
17083
  name: "dreaming-pass-usage",
16967
- up: up112,
17084
+ up: up113,
16968
17085
  artifacts: {
16969
17086
  columns: [
16970
17087
  { table: "dreaming_passes", column: "tokens_input" },
@@ -16978,7 +17095,7 @@ var MIGRATIONS = [
16978
17095
  {
16979
17096
  version: 108,
16980
17097
  name: "embedding-usage",
16981
- up: up113,
17098
+ up: up114,
16982
17099
  artifacts: {
16983
17100
  tables: ["embedding_usage"]
16984
17101
  }
@@ -16986,7 +17103,7 @@ var MIGRATIONS = [
16986
17103
  {
16987
17104
  version: 109,
16988
17105
  name: "telemetry-install",
16989
- up: up114,
17106
+ up: up115,
16990
17107
  artifacts: {
16991
17108
  tables: ["telemetry_install"]
16992
17109
  }
@@ -16994,12 +17111,12 @@ var MIGRATIONS = [
16994
17111
  {
16995
17112
  version: 110,
16996
17113
  name: "memory-mention-join-index",
16997
- up: up115
17114
+ up: up116
16998
17115
  },
16999
17116
  {
17000
17117
  version: 111,
17001
17118
  name: "telemetry-first-use",
17002
- up: up116,
17119
+ up: up117,
17003
17120
  artifacts: {
17004
17121
  columns: [
17005
17122
  { table: "telemetry_install", column: "first_remember_at" },
@@ -17010,7 +17127,7 @@ var MIGRATIONS = [
17010
17127
  {
17011
17128
  version: 112,
17012
17129
  name: "telemetry-queue-ownership",
17013
- up: up117,
17130
+ up: up118,
17014
17131
  artifacts: {
17015
17132
  columns: [
17016
17133
  { table: "telemetry_events", column: "source" },
@@ -17022,7 +17139,7 @@ var MIGRATIONS = [
17022
17139
  {
17023
17140
  version: 113,
17024
17141
  name: "session-claims",
17025
- up: up118,
17142
+ up: up119,
17026
17143
  artifacts: {
17027
17144
  tables: ["session_claims"],
17028
17145
  columns: [
@@ -17036,12 +17153,12 @@ var MIGRATIONS = [
17036
17153
  {
17037
17154
  version: 114,
17038
17155
  name: "memory-traversal-hydration-index",
17039
- up: up119
17156
+ up: up120
17040
17157
  },
17041
17158
  {
17042
17159
  version: 115,
17043
17160
  name: "cross-agent-message-notifications",
17044
- up: up120,
17161
+ up: up121,
17045
17162
  artifacts: {
17046
17163
  tables: ["cross_agent_messages", "cross_agent_message_receipts"]
17047
17164
  }
@@ -17049,7 +17166,7 @@ var MIGRATIONS = [
17049
17166
  {
17050
17167
  version: 116,
17051
17168
  name: "acp-delivery-reconciliation",
17052
- up: up121,
17169
+ up: up122,
17053
17170
  artifacts: {
17054
17171
  columns: [
17055
17172
  { table: "cross_agent_messages", column: "delivery_state" },
@@ -17063,7 +17180,7 @@ var MIGRATIONS = [
17063
17180
  {
17064
17181
  version: 117,
17065
17182
  name: "retire-summary-worker",
17066
- up: up122,
17183
+ up: up123,
17067
17184
  artifacts: {
17068
17185
  columns: [
17069
17186
  { table: "session_transcripts", column: "completed_at" },
@@ -17074,24 +17191,24 @@ var MIGRATIONS = [
17074
17191
  {
17075
17192
  version: 118,
17076
17193
  name: "queue-pressure-indices",
17077
- up: up123
17194
+ up: up124
17078
17195
  },
17079
17196
  {
17080
17197
  version: 119,
17081
17198
  name: "telemetry-version-observation",
17082
- up: up124,
17199
+ up: up125,
17083
17200
  artifacts: { columns: [{ table: "telemetry_install", column: "last_seen_version" }] }
17084
17201
  },
17085
17202
  {
17086
17203
  version: 120,
17087
17204
  name: "source-lifecycle-telemetry",
17088
- up: up125,
17205
+ up: up126,
17089
17206
  artifacts: { tables: ["source_lifecycle_state"] }
17090
17207
  },
17091
17208
  {
17092
17209
  version: 121,
17093
17210
  name: "telemetry-delivery-health",
17094
- up: up126,
17211
+ up: up127,
17095
17212
  artifacts: {
17096
17213
  tables: ["telemetry_delivery_state"],
17097
17214
  columns: [
@@ -17105,7 +17222,7 @@ var MIGRATIONS = [
17105
17222
  {
17106
17223
  version: 122,
17107
17224
  name: "dreaming-evidence-retry",
17108
- up: up127,
17225
+ up: up128,
17109
17226
  artifacts: {
17110
17227
  columns: [
17111
17228
  { table: "dreaming_evidence_exclusions", column: "failure_class" },
@@ -17118,13 +17235,13 @@ var MIGRATIONS = [
17118
17235
  {
17119
17236
  version: 123,
17120
17237
  name: "embedding-index-failures",
17121
- up: up128,
17238
+ up: up129,
17122
17239
  artifacts: { tables: ["embedding_index_failures"] }
17123
17240
  },
17124
17241
  {
17125
17242
  version: 124,
17126
17243
  name: "import-derived-lifecycle",
17127
- up: up129,
17244
+ up: up130,
17128
17245
  artifacts: {
17129
17246
  tables: ["imported_source_lifecycle"]
17130
17247
  }
@@ -17132,76 +17249,76 @@ var MIGRATIONS = [
17132
17249
  {
17133
17250
  version: 125,
17134
17251
  name: "memory-content-safety",
17135
- up: up130
17252
+ up: up131
17136
17253
  },
17137
17254
  {
17138
17255
  version: 126,
17139
17256
  name: "dreaming-surprisal-attention",
17140
- up: up131,
17257
+ up: up132,
17141
17258
  artifacts: { tables: ["dreaming_attention"] }
17142
17259
  },
17143
17260
  {
17144
17261
  version: 127,
17145
17262
  name: "ontology-contradictions",
17146
- up: up132,
17263
+ up: up133,
17147
17264
  artifacts: { tables: ["ontology_contradictions"] }
17148
17265
  },
17149
17266
  {
17150
17267
  version: 128,
17151
17268
  name: "bounded-queue-diagnostics",
17152
- up: up133
17269
+ up: up134
17153
17270
  },
17154
17271
  {
17155
17272
  version: 129,
17156
17273
  name: "retire-structural-jobs",
17157
- up: up134
17274
+ up: up135
17158
17275
  },
17159
17276
  {
17160
17277
  version: 130,
17161
17278
  name: "embedding-repair-state",
17162
- up: up135,
17279
+ up: up136,
17163
17280
  artifacts: { tables: ["embedding_repair_budget", "embedding_repair_backoff"] }
17164
17281
  },
17165
17282
  {
17166
17283
  version: 131,
17167
17284
  name: "dreaming-evidence-consumption",
17168
- up: up136,
17285
+ up: up137,
17169
17286
  artifacts: { tables: ["dreaming_evidence_consumption"] }
17170
17287
  },
17171
17288
  {
17172
17289
  version: 132,
17173
17290
  name: "observer-scoped-epistemic-assertions",
17174
- up: up137,
17291
+ up: up138,
17175
17292
  artifacts: { tables: ["epistemic_assertions"] }
17176
17293
  },
17177
17294
  {
17178
17295
  version: 133,
17179
17296
  name: "dreaming-memory-head",
17180
- up: up138,
17297
+ up: up139,
17181
17298
  artifacts: { tables: ["memory_head_revisions", "memory_head_entries", "memory_head_revision_entries"] }
17182
17299
  },
17183
17300
  {
17184
17301
  version: 134,
17185
17302
  name: "scope-memory-head-entries",
17186
- up: up139,
17303
+ up: up140,
17187
17304
  artifacts: { tables: ["memory_head_entries"] }
17188
17305
  },
17189
17306
  {
17190
17307
  version: 135,
17191
17308
  name: "memory-head-publication",
17192
- up: up140,
17309
+ up: up141,
17193
17310
  artifacts: { tables: ["memory_head_publications"] }
17194
17311
  },
17195
17312
  {
17196
17313
  version: 136,
17197
17314
  name: "memory-head-revisions",
17198
- up: up141,
17315
+ up: up142,
17199
17316
  artifacts: { tables: ["memory_head_revisions"] }
17200
17317
  },
17201
17318
  {
17202
17319
  version: 137,
17203
17320
  name: "dreaming-head-manifest",
17204
- up: up142,
17321
+ up: up143,
17205
17322
  artifacts: {
17206
17323
  columns: [
17207
17324
  { table: "dreaming_passes", column: "head_revision" },
@@ -17212,7 +17329,7 @@ var MIGRATIONS = [
17212
17329
  {
17213
17330
  version: 138,
17214
17331
  name: "bounded-status-projections",
17215
- up: up143,
17332
+ up: up144,
17216
17333
  artifacts: {
17217
17334
  tables: ["transcript_capture_status", "memories_duplicate_hash_counts", "memories_diagnostics_state"]
17218
17335
  }
@@ -17220,31 +17337,31 @@ var MIGRATIONS = [
17220
17337
  {
17221
17338
  version: 139,
17222
17339
  name: "native-source-sync-state",
17223
- up: up144,
17340
+ up: up145,
17224
17341
  artifacts: { tables: ["native_source_sync_state"] }
17225
17342
  },
17226
17343
  {
17227
17344
  version: 140,
17228
17345
  name: "transcript-recovery-frontier",
17229
- up: up145,
17346
+ up: up146,
17230
17347
  artifacts: { tables: ["transcript_recovery_frontiers"] }
17231
17348
  },
17232
17349
  {
17233
17350
  version: 141,
17234
17351
  name: "source-sync-checkpoints",
17235
- up: up146,
17352
+ up: up147,
17236
17353
  artifacts: { tables: ["source_sync_checkpoints"] }
17237
17354
  },
17238
17355
  {
17239
17356
  version: 142,
17240
17357
  name: "source-sync-frontier",
17241
- up: up147,
17358
+ up: up148,
17242
17359
  artifacts: { columns: [{ table: "source_sync_checkpoints", column: "frontier" }] }
17243
17360
  },
17244
17361
  {
17245
17362
  version: 143,
17246
17363
  name: "embedding-index-progress",
17247
- up: up148,
17364
+ up: up149,
17248
17365
  artifacts: {
17249
17366
  columns: [
17250
17367
  { table: "embedding_index_state", column: "migration_phase" },
@@ -17260,19 +17377,19 @@ var MIGRATIONS = [
17260
17377
  {
17261
17378
  version: 144,
17262
17379
  name: "memory-job-lease-token",
17263
- up: up149,
17380
+ up: up150,
17264
17381
  artifacts: { columns: [{ table: "memory_jobs", column: "lease_token" }] }
17265
17382
  },
17266
17383
  {
17267
17384
  version: 145,
17268
17385
  name: "dreaming-evidence-reviews",
17269
- up: up150,
17386
+ up: up151,
17270
17387
  artifacts: { tables: ["dreaming_evidence_reviews"] }
17271
17388
  },
17272
17389
  {
17273
17390
  version: 146,
17274
17391
  name: "source-transcript-import",
17275
- up: up151,
17392
+ up: up152,
17276
17393
  artifacts: {
17277
17394
  tables: [
17278
17395
  "source_import_jobs",
@@ -17291,19 +17408,19 @@ var MIGRATIONS = [
17291
17408
  {
17292
17409
  version: 147,
17293
17410
  name: "source-import-replay-file-slots",
17294
- up: up152,
17411
+ up: up153,
17295
17412
  artifacts: { tables: ["source_import_files"] }
17296
17413
  },
17297
17414
  {
17298
17415
  version: 148,
17299
17416
  name: "source-import-attempt-provenance",
17300
- up: up153,
17417
+ up: up154,
17301
17418
  artifacts: { columns: [{ table: "source_import_record_attempts", column: "source_id" }] }
17302
17419
  },
17303
17420
  {
17304
17421
  version: 149,
17305
17422
  name: "transcript-import-state-machine",
17306
- up: up154,
17423
+ up: up155,
17307
17424
  artifacts: {
17308
17425
  columns: [
17309
17426
  { table: "source_import_jobs", column: "duplicate_mode" },
@@ -17315,7 +17432,7 @@ var MIGRATIONS = [
17315
17432
  {
17316
17433
  version: 150,
17317
17434
  name: "memory-head-freshness",
17318
- up: up155,
17435
+ up: up156,
17319
17436
  artifacts: {
17320
17437
  columns: [
17321
17438
  { table: "memory_md_heads", column: "is_current" },
@@ -17326,7 +17443,7 @@ var MIGRATIONS = [
17326
17443
  {
17327
17444
  version: 151,
17328
17445
  name: "transcript-import-bytes",
17329
- up,
17446
+ up: up2,
17330
17447
  artifacts: {
17331
17448
  tables: [
17332
17449
  "source_import_chunks",
@@ -17355,19 +17472,19 @@ var MIGRATIONS = [
17355
17472
  {
17356
17473
  version: 152,
17357
17474
  name: "memory-artifact-sha-index",
17358
- up: up2,
17475
+ up: up3,
17359
17476
  artifacts: { indexes: ["idx_memory_artifacts_agent_sha"] }
17360
17477
  },
17361
17478
  {
17362
17479
  version: 153,
17363
17480
  name: "vector-repair-checkpoints",
17364
- up: up156,
17481
+ up: up157,
17365
17482
  artifacts: { tables: ["vector_repair_checkpoints"] }
17366
17483
  },
17367
17484
  {
17368
17485
  version: 154,
17369
17486
  name: "transcript-capture-source-identity",
17370
- up: up3,
17487
+ up: up4,
17371
17488
  artifacts: {
17372
17489
  columns: [
17373
17490
  { table: "transcript_capture_jobs", column: "source_identity" },
@@ -17382,19 +17499,19 @@ var MIGRATIONS = [
17382
17499
  {
17383
17500
  version: 155,
17384
17501
  name: "source-sync-failures",
17385
- up: up4,
17502
+ up: up5,
17386
17503
  artifacts: { tables: ["source_sync_failures"], indexes: ["idx_source_sync_failures_active"] }
17387
17504
  },
17388
17505
  {
17389
17506
  version: 156,
17390
17507
  name: "embedding-repair-checkpoints",
17391
- up: up157,
17508
+ up: up158,
17392
17509
  artifacts: { tables: ["embedding_repair_checkpoints"] }
17393
17510
  },
17394
17511
  {
17395
17512
  version: 157,
17396
17513
  name: "embedding-repair-progress",
17397
- up: up158,
17514
+ up: up159,
17398
17515
  artifacts: {
17399
17516
  tables: ["embedding_repair_progress"],
17400
17517
  columns: [{ table: "embedding_repair_checkpoints", column: "profile_fingerprint" }]
@@ -17403,18 +17520,18 @@ var MIGRATIONS = [
17403
17520
  {
17404
17521
  version: 158,
17405
17522
  name: "dreaming-candidate-scan-index",
17406
- up: up159,
17523
+ up: up160,
17407
17524
  artifacts: { indexes: ["idx_memories_agent_kind"] }
17408
17525
  },
17409
17526
  {
17410
17527
  version: 159,
17411
17528
  name: "retire-obsolete-invocation-ledger",
17412
- up: up5
17529
+ up: up6
17413
17530
  },
17414
17531
  {
17415
17532
  version: 160,
17416
17533
  name: "import-admission-ledger",
17417
- up: up160,
17534
+ up: up161,
17418
17535
  artifacts: {
17419
17536
  tables: ["import_admission_ledger", "import_admission_events"],
17420
17537
  indexes: ["idx_import_admission_status", "idx_import_admission_events_key"],
@@ -17426,24 +17543,24 @@ var MIGRATIONS = [
17426
17543
  {
17427
17544
  version: 161,
17428
17545
  name: "entity-prune-keyset-index",
17429
- up: up161,
17546
+ up: up162,
17430
17547
  artifacts: { indexes: ["idx_entities_agent_updated_id"] }
17431
17548
  },
17432
17549
  {
17433
17550
  version: 162,
17434
17551
  name: "generic-entity-prune-scan-generation",
17435
- up: up162,
17552
+ up: up163,
17436
17553
  artifacts: { tables: ["generic_entity_prune_scan_state"] }
17437
17554
  },
17438
17555
  {
17439
17556
  version: 163,
17440
17557
  name: "retire-memory-content-safety",
17441
- up: up163
17558
+ up: up164
17442
17559
  },
17443
17560
  {
17444
17561
  version: 164,
17445
17562
  name: "claim-event-time",
17446
- up: up164,
17563
+ up: up165,
17447
17564
  artifacts: {
17448
17565
  columns: ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"].map((column) => ({
17449
17566
  table: "entity_attributes",
@@ -17454,7 +17571,7 @@ var MIGRATIONS = [
17454
17571
  {
17455
17572
  version: 165,
17456
17573
  name: "dreaming-history",
17457
- up: up165,
17574
+ up: up166,
17458
17575
  artifacts: {
17459
17576
  tables: ["dreaming_history_nodes"],
17460
17577
  indexes: ["idx_dreaming_history_nodes_pass"],
@@ -17464,23 +17581,23 @@ var MIGRATIONS = [
17464
17581
  {
17465
17582
  version: 166,
17466
17583
  name: "dreaming-pass-peak-context",
17467
- up: up166,
17584
+ up: up167,
17468
17585
  artifacts: { columns: [{ table: "dreaming_passes", column: "tokens_peak_context" }] }
17469
17586
  },
17470
17587
  {
17471
17588
  version: 167,
17472
17589
  name: "memories-fts-porter",
17473
- up: up167
17590
+ up: up168
17474
17591
  },
17475
17592
  {
17476
17593
  version: 168,
17477
17594
  name: "retire-source-paragraph-claims",
17478
- up: up168
17595
+ up: up169
17479
17596
  },
17480
17597
  {
17481
17598
  version: 169,
17482
17599
  name: "dreaming-evidence-review-cursor",
17483
- up: up169,
17600
+ up: up170,
17484
17601
  artifacts: {
17485
17602
  columns: [
17486
17603
  { table: "dreaming_evidence_consumption", column: "cursor_basis" },
@@ -17491,7 +17608,7 @@ var MIGRATIONS = [
17491
17608
  {
17492
17609
  version: 170,
17493
17610
  name: "dependency-history-compaction-state",
17494
- up: up170,
17611
+ up: up171,
17495
17612
  artifacts: {
17496
17613
  tables: ["dependency_history_compaction_state"]
17497
17614
  }
@@ -17499,7 +17616,7 @@ var MIGRATIONS = [
17499
17616
  {
17500
17617
  version: 171,
17501
17618
  name: "agent-wake-and-message-board",
17502
- up: up171,
17619
+ up: up172,
17503
17620
  artifacts: {
17504
17621
  columns: [
17505
17622
  { table: "cross_agent_message_wakes", column: "session_key" },
@@ -17519,6 +17636,51 @@ var MIGRATIONS = [
17519
17636
  "board_notices"
17520
17637
  ]
17521
17638
  }
17639
+ },
17640
+ {
17641
+ version: 172,
17642
+ name: "dreaming-pass-policy",
17643
+ up: up173,
17644
+ artifacts: {
17645
+ tables: ["dreaming_policies"],
17646
+ columns: [
17647
+ { table: "dreaming_passes", column: "policy_hash" },
17648
+ { table: "dreaming_passes", column: "policy_source" }
17649
+ ]
17650
+ }
17651
+ },
17652
+ {
17653
+ version: 173,
17654
+ name: "memory-artifact-native-path-index",
17655
+ up: up174,
17656
+ artifacts: { indexes: ["idx_memory_artifacts_native_paths"] }
17657
+ },
17658
+ {
17659
+ version: 174,
17660
+ name: "session-transcript-deletions",
17661
+ up,
17662
+ artifacts: {
17663
+ tables: [
17664
+ "session_transcript_deletions",
17665
+ "session_transcript_deleted_prefixes",
17666
+ "session_transcript_deleted_positions",
17667
+ "session_transcript_deleted_sources",
17668
+ "session_transcript_delete_files"
17669
+ ],
17670
+ indexes: [
17671
+ "idx_session_delete_files_pending",
17672
+ "idx_session_delete_source_lookup",
17673
+ "idx_memories_session_delete_source",
17674
+ "idx_capture_jobs_session_delete",
17675
+ "idx_import_records_session_delete"
17676
+ ],
17677
+ columns: [
17678
+ { table: "source_import_records", column: "redacted_bytes" },
17679
+ { table: "session_transcript_deletions", column: "pending_start" },
17680
+ { table: "session_transcript_deletions", column: "lifecycle_intent_seq" },
17681
+ { table: "session_transcript_deleted_prefixes", column: "origin" }
17682
+ ]
17683
+ }
17522
17684
  }
17523
17685
  ];
17524
17686
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -17878,7 +18040,7 @@ var DEFAULT_AGENTS_DIRNAME = ".agents";
17878
18040
  function normalizeWorkspacePath(pathValue, home = homedir4()) {
17879
18041
  return resolve6(expandHome(pathValue.trim(), home));
17880
18042
  }
17881
- function readTrimmedEnv(env, name) {
18043
+ function readTrimmedEnv2(env, name) {
17882
18044
  const value = env[name];
17883
18045
  if (typeof value !== "string")
17884
18046
  return;
@@ -17965,7 +18127,7 @@ function resolveWorkspacePath(options = {}) {
17965
18127
  }
17966
18128
  function resolveEnvWorkspace(env, home, requireExisting) {
17967
18129
  for (const key of WORKSPACE_ENV_KEYS) {
17968
- const raw = readTrimmedEnv(env, key);
18130
+ const raw = readTrimmedEnv2(env, key);
17969
18131
  if (!raw)
17970
18132
  continue;
17971
18133
  const normalized = normalizeWorkspacePath(raw, home);
@@ -18039,13 +18201,6 @@ var IDENTITY_FILES = {
18039
18201
  optional: true,
18040
18202
  context: "session",
18041
18203
  session: "bootstrap"
18042
- },
18043
- dreaming: {
18044
- path: "DREAMING.md",
18045
- description: "Dreaming/reflection prompt used only for dreaming sessions",
18046
- optional: true,
18047
- context: "session",
18048
- session: "dreaming"
18049
18204
  }
18050
18205
  };
18051
18206
  var REQUIRED_IDENTITY_KEYS = Object.entries(IDENTITY_FILES).filter(([, spec]) => !spec.optional).map(([key]) => key);
@@ -18135,6 +18290,210 @@ function escapeRegex(str) {
18135
18290
  }
18136
18291
  var LOCAL_THINKING_EXECUTORS = new Set(["openai-compatible", "llama-cpp", "ollama"]);
18137
18292
 
18293
+ // src/launcher.ts
18294
+ import { existsSync, statSync as statSync2 } from "node:fs";
18295
+ import { dirname as dirname2, isAbsolute, join as join3, parse, win32 } from "node:path";
18296
+ var SIGNET_MCP_STDIO_WORKER_ENV = "SIGNET_MCP_STDIO_WORKER";
18297
+ function quoteCommandArg(value, platform = process.platform) {
18298
+ if (/^[A-Za-z0-9_./\\:@+=,-]+$/.test(value))
18299
+ return value;
18300
+ if (platform === "win32") {
18301
+ return `"${value.replace(/[%^&|<>!"]/g, (char) => char === "%" ? "%%" : `^${char}`)}"`;
18302
+ }
18303
+ return `'${value.replace(/'/g, "'\\''")}'`;
18304
+ }
18305
+ function renderCommand(launcher) {
18306
+ return [launcher.command, ...launcher.args].map((arg) => quoteCommandArg(arg)).join(" ");
18307
+ }
18308
+ function parseHookLauncher(command) {
18309
+ const clean = command.trim().replace(/^(?:(?:SIGNET_DAEMON_URL|SIGNET_API_KEY|SIGNET_PATH|SIGNET_FETCH_TIMEOUT|SIGNET_SESSION_START_TIMEOUT|SIGNET_PROMPT_SUBMIT_TIMEOUT)=(?:'(?:[^']|'\\'')*'|"[^"]*"|\S+)\s+|set "(?:SIGNET_DAEMON_URL|SIGNET_API_KEY|SIGNET_PATH|SIGNET_FETCH_TIMEOUT|SIGNET_SESSION_START_TIMEOUT|SIGNET_PROMPT_SUBMIT_TIMEOUT)=[^"]*" && )+/i, "");
18310
+ const args = [];
18311
+ let value = "";
18312
+ let quote = "";
18313
+ let started = false;
18314
+ for (let i = 0;i < clean.length; i++) {
18315
+ const char = clean.charAt(i);
18316
+ if (!quote && /[$`;&|<>()]/.test(char))
18317
+ return;
18318
+ if (char === "\\" && !quote && clean.charAt(i + 1) === "'") {
18319
+ value += "'";
18320
+ i++;
18321
+ started = true;
18322
+ continue;
18323
+ }
18324
+ if (char === quote) {
18325
+ quote = "";
18326
+ continue;
18327
+ }
18328
+ if (!quote && (char === "'" || char === '"')) {
18329
+ quote = char;
18330
+ started = true;
18331
+ continue;
18332
+ }
18333
+ if (!quote && /\s/.test(char)) {
18334
+ if (started && value === "hook") {
18335
+ const executable = args.shift();
18336
+ const launcher = executable ? { command: executable, args } : undefined;
18337
+ return isSignetCliLauncher(launcher) ? launcher : undefined;
18338
+ }
18339
+ if (started)
18340
+ args.push(value);
18341
+ value = "";
18342
+ started = false;
18343
+ continue;
18344
+ }
18345
+ value += char;
18346
+ started = true;
18347
+ }
18348
+ return;
18349
+ }
18350
+ function isSignetCliLauncher(launcher) {
18351
+ if (!launcher)
18352
+ return false;
18353
+ if (/^signet(?:\.(?:exe|cmd|bat|ps1))?$/i.test(win32.basename(launcher.command)))
18354
+ return launcher.args.length === 0;
18355
+ return /^(?:node|bun)(?:\.exe)?$/i.test(win32.basename(launcher.command)) && launcher.args.length === 1 && /(?:^|[\\/])signet\.js$/.test(launcher.args[0] ?? "");
18356
+ }
18357
+ function readMcpLauncher(value) {
18358
+ if (!isJsonObject(value) || typeof value.command !== "string" || !value.command)
18359
+ return;
18360
+ const args = value.args ?? [];
18361
+ if (!Array.isArray(args) || !args.every((arg) => typeof arg === "string"))
18362
+ return;
18363
+ const env = {};
18364
+ if (isJsonObject(value.env)) {
18365
+ for (const [key, val] of Object.entries(value.env)) {
18366
+ if (typeof val === "string" && key !== "SIGNET_API_KEY" && key !== "SIGNET_TOKEN")
18367
+ env[key] = val;
18368
+ }
18369
+ }
18370
+ const launcher = { command: value.command, args, ...Object.keys(env).length ? { env } : {} };
18371
+ const name = win32.basename(launcher.command);
18372
+ if (/^signet-mcp(?:\.exe)?$/i.test(name))
18373
+ return launcher;
18374
+ if (/^signet(?:\.(?:exe|cmd|bat|ps1))?$/i.test(name) && env.SIGNET_MCP_STDIO_WORKER === "1")
18375
+ return launcher;
18376
+ if (/^(?:node|bun)(?:\.exe)?$/i.test(name) && args.length === 1 && /(?:^|[\\/])(?:dist[\\/]mcp-stdio|signet)\.js$/.test(args[0] ?? ""))
18377
+ return launcher;
18378
+ return;
18379
+ }
18380
+ function override() {
18381
+ const value = process.env.SIGNET_HOOK_COMMAND?.trim();
18382
+ if (!value) {
18383
+ const command = readManagedTrimmedEnv("SIGNET_CLI_PATH");
18384
+ return command ? { command, args: [] } : undefined;
18385
+ }
18386
+ const message = "SIGNET_HOOK_COMMAND must be an executable path without whitespace or a nonempty JSON argv array of command and arguments";
18387
+ if (!value.startsWith("[")) {
18388
+ if (/\s/.test(value))
18389
+ throw new Error(message);
18390
+ return { command: value, args: [] };
18391
+ }
18392
+ let parsed;
18393
+ try {
18394
+ parsed = JSON.parse(value);
18395
+ } catch {
18396
+ throw new Error(message);
18397
+ }
18398
+ if (!Array.isArray(parsed) || !parsed.every((arg) => typeof arg === "string") || !parsed[0]?.trim()) {
18399
+ throw new Error(message);
18400
+ }
18401
+ return { command: parsed[0], args: parsed.slice(1) };
18402
+ }
18403
+ function cliFromMcp(launcher) {
18404
+ if (!launcher)
18405
+ return;
18406
+ if (isSignetCliLauncher(launcher) && (launcher.env?.SIGNET_MCP_STDIO_WORKER === "1" || /^(?:node|bun)(?:\.exe)?$/i.test(win32.basename(launcher.command)))) {
18407
+ return { command: launcher.command, args: launcher.args };
18408
+ }
18409
+ if (/^signet-mcp(?:\.exe)?$/i.test(win32.basename(launcher.command))) {
18410
+ const cli = { command: launcher.command.replace(/signet-mcp(\.exe)?$/i, "signet$1"), args: launcher.args };
18411
+ return isSignetCliLauncher(cli) ? cli : undefined;
18412
+ }
18413
+ if (launcher.args.length !== 1 || !/(?:^|[\\/])dist[\\/]mcp-stdio\.js$/.test(launcher.args[0] ?? ""))
18414
+ return;
18415
+ const cli = {
18416
+ command: launcher.command,
18417
+ args: launcher.args.map((arg) => arg.replace(/dist[\\/]mcp-stdio\.js$/, "bin/signet.js"))
18418
+ };
18419
+ return isSignetCliLauncher(cli) ? cli : undefined;
18420
+ }
18421
+ function mcpFromCli(launcher) {
18422
+ if (!launcher)
18423
+ return;
18424
+ const script = launcher.args.findIndex((arg) => /(?:^|[\\/])signet\.js$/.test(arg));
18425
+ if (script >= 0 && /(?:^|[\\/])bin[\\/]signet\.js$/.test(launcher.args[script] ?? ""))
18426
+ return {
18427
+ command: launcher.command,
18428
+ args: launcher.args.map((arg, i) => i === script ? arg.replace(/bin[\\/]signet\.js$/, "dist/mcp-stdio.js") : arg)
18429
+ };
18430
+ return { ...launcher, env: { ...launcher.env, SIGNET_MCP_STDIO_WORKER: "1" } };
18431
+ }
18432
+ function discover(mcp, runtime) {
18433
+ const roots = [readManagedTrimmedEnv("SIGNET_WRAPPER_DIR"), readManagedTrimmedEnv("SIGNET_DIR")].filter((root) => Boolean(root));
18434
+ const entries = [
18435
+ ...roots.map((root) => join3(root, "bin", "signet.js")),
18436
+ process.argv[1],
18437
+ join3(dirname2(process.execPath), "..", "bin", "signet.js")
18438
+ ];
18439
+ const entry = entries.find((path) => path && win32.basename(path) === "signet.js" && isExistingFile(path));
18440
+ const script = entry ? mcp ? join3(dirname2(entry), "..", "dist", "mcp-stdio.js") : entry : undefined;
18441
+ const host = runtime ?? (/^(?:node|bun)(?:\.exe)?$/i.test(win32.basename(process.execPath)) ? process.execPath : undefined);
18442
+ if (host && script && isExistingFile(script))
18443
+ return { command: host, args: [script] };
18444
+ const name = process.platform === "win32" ? "signet.exe" : "signet";
18445
+ const candidates = [
18446
+ ...roots.flatMap((root) => [join3(root, "native", name), join3(root, "bin", name)]),
18447
+ process.execPath
18448
+ ];
18449
+ const native = candidates.find((path) => /^signet(?:\.exe)?$/i.test(win32.basename(path)) && isExistingFile(path));
18450
+ if (native)
18451
+ return { command: native, args: [], ...mcp ? { env: { SIGNET_MCP_STDIO_WORKER: "1" } } : {} };
18452
+ if (mcp && process.platform === "win32")
18453
+ console.warn(`[signet] Warning: could not resolve mcp-stdio.js from argv[1]="${process.argv[1] ?? ""}". MCP server config will use "signet-mcp" which may fail on Windows without shell:true.`);
18454
+ return { command: mcp ? "signet-mcp" : "signet", args: [] };
18455
+ }
18456
+ function launcherPathStatus(path) {
18457
+ try {
18458
+ if (statSync2(path, { throwIfNoEntry: false }))
18459
+ return "present";
18460
+ } catch (error) {
18461
+ const code = error instanceof Error && "code" in error ? error.code : undefined;
18462
+ if (code !== "ENOTDIR" && code !== "ELOOP")
18463
+ return "unverified";
18464
+ }
18465
+ const root = parse(path).root;
18466
+ const segments = path.slice(root.length).split(/[\\/]/).filter(Boolean);
18467
+ return isAbsolute(path) && segments.length >= 2 && existsSync(join3(root, ...segments.slice(0, 2))) ? "missing" : "unverified";
18468
+ }
18469
+ function reuseLauncher(existing, mcp, runtime) {
18470
+ if (!existing)
18471
+ return discover(mcp, runtime);
18472
+ const paths = [
18473
+ existing.command,
18474
+ .../^(?:node|bun)(?:\.exe)?$/i.test(win32.basename(existing.command)) ? existing.args : []
18475
+ ];
18476
+ const statuses = paths.map((path, index) => index === 0 && !/[\\/]/.test(path) ? "present" : launcherPathStatus(path));
18477
+ if (statuses.includes("missing")) {
18478
+ const replacement = discover(mcp, runtime);
18479
+ console.warn(`[signet] Warning: stale launcher ${renderCommand(existing)} was replaced with ${renderCommand(replacement)}.`);
18480
+ return replacement;
18481
+ }
18482
+ if (statuses.includes("unverified")) {
18483
+ console.warn(`[signet] Warning: launcher ${renderCommand(existing)} could not be verified from this environment; keeping it. Set SIGNET_HOOK_COMMAND to override it.`);
18484
+ }
18485
+ return existing;
18486
+ }
18487
+ function resolveSignetCliCommand(existing, runtime) {
18488
+ return override() ?? reuseLauncher(isSignetCliLauncher(existing) ? existing : undefined, false, runtime);
18489
+ }
18490
+ function resolveSignetMcpCommand(existing, runtime) {
18491
+ const configured = override();
18492
+ if (configured)
18493
+ return mcpFromCli(configured) ?? configured;
18494
+ return reuseLauncher(readMcpLauncher(existing), true, runtime);
18495
+ }
18496
+
18138
18497
  // src/index.ts
18139
18498
  class BaseConnector {
18140
18499
  getIconAsset() {
@@ -18144,20 +18503,20 @@ class BaseConnector {
18144
18503
  return stripSignetBlock(content);
18145
18504
  }
18146
18505
  stripLegacySignetBlock(basePath) {
18147
- const agentsPath = join3(basePath, "AGENTS.md");
18148
- if (!existsSync(agentsPath))
18506
+ const agentsPath = join4(basePath, "AGENTS.md");
18507
+ if (!existsSync2(agentsPath))
18149
18508
  return null;
18150
18509
  const raw = readFileSync(agentsPath, "utf-8");
18151
18510
  const cleaned = stripSignetBlock(raw);
18152
18511
  if (cleaned === raw)
18153
18512
  return null;
18154
18513
  const root = realpathSync(basePath);
18155
- const parent = realpathSync(dirname2(agentsPath));
18156
- const rel = relative(root, join3(parent, "AGENTS.md"));
18157
- if (rel.startsWith("..") || isAbsolute(rel)) {
18514
+ const parent = realpathSync(dirname3(agentsPath));
18515
+ const rel = relative(root, join4(parent, "AGENTS.md"));
18516
+ if (rel.startsWith("..") || isAbsolute2(rel)) {
18158
18517
  throw new Error(`Target path escapes validated root: ${agentsPath}`);
18159
18518
  }
18160
- const tmp = join3(basePath, `.${randomBytes(6).toString("hex")}.tmp`);
18519
+ const tmp = join4(basePath, `.${randomBytes(6).toString("hex")}.tmp`);
18161
18520
  try {
18162
18521
  writeFileSync(tmp, cleaned, "utf-8");
18163
18522
  renameSync(tmp, agentsPath);
@@ -18175,7 +18534,7 @@ class BaseConnector {
18175
18534
  generateHeader(sourcePath, targetName) {
18176
18535
  const name = targetName || this.name;
18177
18536
  const safe = (p) => p.replace(/[\n\r]/g, "");
18178
- const root = dirname2(sourcePath);
18537
+ const root = dirname3(sourcePath);
18179
18538
  return `# Auto-generated from ${safe(sourcePath)}
18180
18539
  # Source: ${safe(sourcePath)}
18181
18540
  # Generated: ${new Date().toISOString()}
@@ -18188,8 +18547,8 @@ class BaseConnector {
18188
18547
  const files = ["SOUL.md", "IDENTITY.md", "USER.md", "MEMORY.md"];
18189
18548
  const parts = [];
18190
18549
  for (const name of files) {
18191
- const filePath = join3(basePath, name);
18192
- if (!existsSync(filePath))
18550
+ const filePath = join4(basePath, name);
18551
+ if (!existsSync2(filePath))
18193
18552
  continue;
18194
18553
  try {
18195
18554
  const content = readFileSync(filePath, "utf-8").trim();
@@ -18206,7 +18565,7 @@ ${content}`);
18206
18565
  `);
18207
18566
  }
18208
18567
  isDetected() {
18209
- return existsSync(this.getConfigPath());
18568
+ return existsSync2(this.getConfigPath());
18210
18569
  }
18211
18570
  async inspectHealth() {
18212
18571
  try {
@@ -18258,7 +18617,7 @@ function containsSignetApiKey(content) {
18258
18617
  function keepSignetApiKeyFilePrivate(path) {
18259
18618
  let mode;
18260
18619
  try {
18261
- mode = statSync(path).mode & 511;
18620
+ mode = statSync3(path).mode & 511;
18262
18621
  } catch {
18263
18622
  return;
18264
18623
  }
@@ -18290,11 +18649,11 @@ function writeConfigText(path, content) {
18290
18649
  }
18291
18650
  }
18292
18651
  function atomicWriteText(path, content, mode) {
18293
- const tmp = join3(dirname2(path), `.${randomBytes(6).toString("hex")}.tmp`);
18652
+ const tmp = join4(dirname3(path), `.${randomBytes(6).toString("hex")}.tmp`);
18294
18653
  let writeMode = mode;
18295
18654
  if (writeMode === undefined) {
18296
18655
  try {
18297
- writeMode = statSync(path).mode & 511;
18656
+ writeMode = statSync3(path).mode & 511;
18298
18657
  } catch {}
18299
18658
  }
18300
18659
  if (containsSignetApiKey(content))
@@ -18313,60 +18672,15 @@ function atomicWriteJson(path, data, indent = 2) {
18313
18672
  atomicWriteText(path, `${JSON.stringify(data, null, indent)}
18314
18673
  `);
18315
18674
  }
18316
- var SIGNET_MCP_STDIO_WORKER_ENV = "SIGNET_MCP_STDIO_WORKER";
18317
- function resolveRunningNativeSignetBinary() {
18318
- const executable = process.execPath;
18319
- if (!/^signet(?:\.exe)?$/i.test(basename2(executable)))
18320
- return null;
18321
- try {
18322
- return statSync(executable).isFile() ? executable : null;
18323
- } catch {
18324
- return null;
18325
- }
18326
- }
18327
- function resolvePackagedSignetCommand(bareCommand, scriptDirectory, scriptName, warnOnFallback) {
18328
- if (process.platform !== "win32")
18329
- return { command: bareCommand, args: [] };
18330
- const cliEntry = process.argv[1] ?? "";
18331
- const scriptPath = join3(cliEntry, "..", "..", scriptDirectory, scriptName);
18332
- if (cliEntry && existsSync(scriptPath))
18333
- return { command: process.execPath, args: [scriptPath] };
18334
- if (warnOnFallback) {
18335
- console.warn(`[signet] Warning: could not resolve ${scriptName} from argv[1]="${cliEntry}". ` + `MCP server config will use "${bareCommand}" which may fail on Windows without shell:true.`);
18336
- }
18337
- return { command: bareCommand, args: [] };
18338
- }
18339
- function resolveSignetMcpCommand() {
18340
- const nativeBinary = resolveRunningNativeSignetBinary();
18341
- if (nativeBinary)
18342
- return { command: nativeBinary, args: [], env: { [SIGNET_MCP_STDIO_WORKER_ENV]: "1" } };
18343
- return resolvePackagedSignetCommand("signet-mcp", "dist", "mcp-stdio.js", true);
18344
- }
18345
- function resolveSignetCliCommand() {
18346
- return resolvePackagedSignetCommand("signet", "bin", "signet.js", false);
18347
- }
18348
18675
  var MANAGED_DAEMON_URL_DEFAULT = "http://127.0.0.1:3850";
18349
18676
  var MANAGED_AGENT_ID_DEFAULT = "default";
18350
- function isJsonObject(value) {
18351
- return typeof value === "object" && value !== null && !Array.isArray(value);
18352
- }
18353
18677
  function isChildOf(candidate, parent) {
18354
18678
  const rel = relative(parent, candidate);
18355
- return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
18356
- }
18357
- function readTrimmedEnv2(name) {
18358
- const value = process.env[name];
18359
- if (typeof value !== "string")
18360
- return;
18361
- const trimmed = value.trim().replace(/[\r\n]+/g, "");
18362
- return trimmed.length > 0 ? trimmed : undefined;
18363
- }
18364
- function readManagedTrimmedEnv(name) {
18365
- return readTrimmedEnv2(name);
18679
+ return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute2(rel);
18366
18680
  }
18367
18681
  function isExistingDirectory2(path) {
18368
18682
  try {
18369
- return statSync(path).isDirectory();
18683
+ return statSync3(path).isDirectory();
18370
18684
  } catch {
18371
18685
  return false;
18372
18686
  }
@@ -18383,12 +18697,29 @@ function resolveSignetAgentId() {
18383
18697
  function resolveSignetApiKey() {
18384
18698
  return readManagedTrimmedEnv("SIGNET_API_KEY") ?? readManagedTrimmedEnv("SIGNET_TOKEN");
18385
18699
  }
18700
+ async function resolveInstallApiKey() {
18701
+ const url = resolveSignetDaemonUrl2();
18702
+ try {
18703
+ const response = await fetch(`${url}/api/mode`, { signal: AbortSignal.timeout(1000), redirect: "error" });
18704
+ if (!response.ok)
18705
+ throw new Error(`HTTP ${response.status}`);
18706
+ const mode = await response.json();
18707
+ if (!isJsonObject(mode) || typeof mode.requiresAuth !== "boolean")
18708
+ throw new Error("response has no boolean requiresAuth");
18709
+ return mode.requiresAuth ? { apiKey: resolveSignetApiKey() } : {};
18710
+ } catch (error) {
18711
+ const reason = error instanceof Error ? error.message : String(error);
18712
+ return {
18713
+ warning: `Could not determine daemon auth requirement from ${url}/api/mode (${reason}); SIGNET_API_KEY was omitted. Check SIGNET_DAEMON_URL and daemon connectivity, then rerun signet sync.`
18714
+ };
18715
+ }
18716
+ }
18386
18717
  function buildSignetRuntimeEnv(opts = {}) {
18387
18718
  const env = {};
18388
18719
  if (opts.basePath)
18389
18720
  env.SIGNET_PATH = opts.basePath;
18390
18721
  const daemonUrl = readManagedTrimmedEnv("SIGNET_DAEMON_URL");
18391
- const apiKey = resolveSignetApiKey();
18722
+ const apiKey = opts.apiKey === undefined ? resolveSignetApiKey() : opts.apiKey;
18392
18723
  const agentId = readManagedTrimmedEnv("SIGNET_AGENT_ID");
18393
18724
  if (daemonUrl)
18394
18725
  env.SIGNET_DAEMON_URL = resolveSignetDaemonUrl2();
@@ -18405,7 +18736,7 @@ function buildManagedExtensionEnvBootstrap(env) {
18405
18736
  const daemonUrl = JSON.stringify(env.daemonUrl);
18406
18737
  const agentId = JSON.stringify(env.agentId);
18407
18738
  const apiKey = env.apiKey ? JSON.stringify(env.apiKey) : null;
18408
- const isDefaultWorkspace = env.signetPath === join3(homedir(), ".agents");
18739
+ const isDefaultWorkspace = env.signetPath === join4(homedir(), ".agents");
18409
18740
  const workspaceExists = isExistingDirectory2(env.signetPath);
18410
18741
  if (!isDefaultWorkspace && !workspaceExists) {
18411
18742
  console.warn(`[signet] resolved workspace "${env.signetPath}" does not exist; not embedding it in the managed extension to avoid propagating a stale path (issue #1016).`);
@@ -18436,7 +18767,7 @@ ${signetPathBlock} if (!__signetReadEnv("SIGNET_DAEMON_URL")) {
18436
18767
  }`;
18437
18768
  }
18438
18769
  function managedExtensionFilePath(agentDir, filename) {
18439
- return join3(agentDir, "extensions", filename);
18770
+ return join4(agentDir, "extensions", filename);
18440
18771
  }
18441
18772
  function buildManagedExtensionContent(params) {
18442
18773
  if (params.bundle.length === 0) {
@@ -18475,7 +18806,7 @@ function writeManagedExtensionFile(filePath, content) {
18475
18806
  atomicWriteText(filePath, content, 384);
18476
18807
  return true;
18477
18808
  }
18478
- if ((statSync(filePath).mode & 63) !== 0)
18809
+ if ((statSync3(filePath).mode & 63) !== 0)
18479
18810
  chmodSync(filePath, 384);
18480
18811
  return false;
18481
18812
  }
@@ -18561,7 +18892,7 @@ function runConnectorInstaller(harness, ConnectorClass, options = {}) {
18561
18892
  setConnectorInstallerEnv("SIGNET_DAEMON_URL", parsed.url);
18562
18893
  setConnectorInstallerEnv("SIGNET_API_KEY", parsed.apiKey);
18563
18894
  setConnectorInstallerEnv("SIGNET_AGENT_ID", parsed.agentId);
18564
- const basePath = parsed.path || process.env.SIGNET_PATH || join3(homedir(), ".agents");
18895
+ const basePath = parsed.path || process.env.SIGNET_PATH || join4(homedir(), ".agents");
18565
18896
  const connector = new ConnectorClass;
18566
18897
  if (parsed.command === "status") {
18567
18898
  console.log(connector.isInstalled() ? `${label}: installed` : `${label}: not installed`);
@@ -18595,15 +18926,24 @@ export {
18595
18926
  buildManagedExtensionContent,
18596
18927
  buildManagedExtensionEnvBootstrap,
18597
18928
  buildSignetRuntimeEnv,
18929
+ cliFromMcp,
18598
18930
  isChildOf,
18931
+ isExistingFile,
18599
18932
  isJsonObject,
18600
18933
  isManagedExtensionFile,
18934
+ isSignetCliLauncher,
18601
18935
  isSignetGeneratedFile,
18602
18936
  keepSignetApiKeyFilePrivate,
18603
18937
  managedExtensionFilePath,
18938
+ mcpFromCli,
18939
+ parseHookLauncher,
18940
+ quoteCommandArg,
18604
18941
  readManagedTrimmedEnv,
18605
- readTrimmedEnv2 as readTrimmedEnv,
18942
+ readMcpLauncher,
18943
+ readTrimmedEnv,
18606
18944
  removeManagedExtensionFile,
18945
+ renderCommand,
18946
+ resolveInstallApiKey,
18607
18947
  resolveRemoteDaemonUrl,
18608
18948
  resolveSignetAgentId,
18609
18949
  resolveSignetApiKey,