@signetai/signet-memory-openclaw 0.216.7 → 0.217.3
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 +601 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16412,6 +16412,241 @@ function up145(db) {
|
|
|
16412
16412
|
ON dreaming_evidence_reviews (agent_id, reviewed_at DESC);
|
|
16413
16413
|
`);
|
|
16414
16414
|
}
|
|
16415
|
+
function up146(db) {
|
|
16416
|
+
db.exec(`
|
|
16417
|
+
CREATE TABLE IF NOT EXISTS source_import_jobs (
|
|
16418
|
+
id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind = 'import'), agent_id TEXT NOT NULL,
|
|
16419
|
+
schema_id TEXT NOT NULL, adapter_version INTEGER NOT NULL CHECK (adapter_version = 1),
|
|
16420
|
+
state TEXT NOT NULL CHECK (state IN ('staging','inventorying','queued','running','paused','completed','completed_with_rejections','cancelled','failed')),
|
|
16421
|
+
control_request TEXT CHECK (control_request IN ('pause','resume','retry','cancel') OR control_request IS NULL),
|
|
16422
|
+
generation INTEGER NOT NULL DEFAULT 0, total INTEGER NOT NULL DEFAULT 0, imported INTEGER NOT NULL DEFAULT 0,
|
|
16423
|
+
duplicate INTEGER NOT NULL DEFAULT 0, rejected INTEGER NOT NULL DEFAULT 0, pending INTEGER NOT NULL DEFAULT 0,
|
|
16424
|
+
lease_token TEXT, lease_expires_at TEXT, error TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16425
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')), started_at TEXT, completed_at TEXT, reconciled_at TEXT
|
|
16426
|
+
);
|
|
16427
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_jobs_agent_state ON source_import_jobs(agent_id, state);
|
|
16428
|
+
|
|
16429
|
+
CREATE TABLE IF NOT EXISTS source_import_files (
|
|
16430
|
+
id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
|
|
16431
|
+
source_id TEXT NOT NULL, agent_id TEXT NOT NULL, ordinal INTEGER NOT NULL, name TEXT NOT NULL,
|
|
16432
|
+
managed_path TEXT NOT NULL, size_bytes INTEGER NOT NULL DEFAULT 0, content_hash TEXT,
|
|
16433
|
+
state TEXT NOT NULL CHECK (state IN ('staging','ready','inventorying','completed','failed')),
|
|
16434
|
+
record_count INTEGER NOT NULL DEFAULT 0, blank_count INTEGER NOT NULL DEFAULT 0, malformed_count INTEGER NOT NULL DEFAULT 0,
|
|
16435
|
+
inventory_version INTEGER NOT NULL DEFAULT 1, checkpoint_ordinal INTEGER NOT NULL DEFAULT 0,
|
|
16436
|
+
checkpoint_byte_offset INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16437
|
+
UNIQUE(job_id, ordinal)
|
|
16438
|
+
);
|
|
16439
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state);
|
|
16440
|
+
|
|
16441
|
+
CREATE TABLE IF NOT EXISTS source_import_records (
|
|
16442
|
+
id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
|
|
16443
|
+
file_id TEXT NOT NULL REFERENCES source_import_files(id) ON DELETE CASCADE, source_id TEXT NOT NULL, agent_id TEXT NOT NULL,
|
|
16444
|
+
ordinal INTEGER NOT NULL, line_number INTEGER NOT NULL, byte_offset INTEGER NOT NULL, byte_length INTEGER NOT NULL,
|
|
16445
|
+
raw_hash TEXT NOT NULL, external_identity TEXT, conversation_fingerprint TEXT, status TEXT NOT NULL CHECK (status IN ('pending','imported','duplicate','rejected','cancelled')),
|
|
16446
|
+
canonical_id TEXT, canonical_key TEXT, rejection_code TEXT, attempt_count INTEGER NOT NULL DEFAULT 0,
|
|
16447
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16448
|
+
UNIQUE(file_id, ordinal), UNIQUE(file_id, byte_offset)
|
|
16449
|
+
);
|
|
16450
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_records_job_status ON source_import_records(job_id, status);
|
|
16451
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_records_source_status ON source_import_records(agent_id, source_id, status);
|
|
16452
|
+
|
|
16453
|
+
CREATE TABLE IF NOT EXISTS transcript_import_conversations (
|
|
16454
|
+
agent_id TEXT NOT NULL, external_identity TEXT NOT NULL, canonical_key TEXT NOT NULL,
|
|
16455
|
+
conversation_fingerprint TEXT NOT NULL, canonical_id TEXT NOT NULL, owner_source_id TEXT NOT NULL,
|
|
16456
|
+
owner_record_id TEXT NOT NULL, state TEXT NOT NULL CHECK (state IN ('committing','committed','removed')),
|
|
16457
|
+
content_hash TEXT NOT NULL, harness TEXT NOT NULL, timestamp TEXT NOT NULL,
|
|
16458
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16459
|
+
PRIMARY KEY (agent_id, external_identity), UNIQUE(agent_id, canonical_key)
|
|
16460
|
+
);
|
|
16461
|
+
CREATE INDEX IF NOT EXISTS idx_transcript_import_conversations_source ON transcript_import_conversations(agent_id, owner_source_id);
|
|
16462
|
+
|
|
16463
|
+
CREATE TABLE IF NOT EXISTS source_import_record_attempts (
|
|
16464
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT, agent_id TEXT NOT NULL, job_id TEXT NOT NULL, file_id TEXT NOT NULL,
|
|
16465
|
+
record_id TEXT NOT NULL, generation INTEGER NOT NULL, outcome TEXT NOT NULL, error_code TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
16466
|
+
);
|
|
16467
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_attempts_record ON source_import_record_attempts(agent_id, record_id, created_at);
|
|
16468
|
+
`);
|
|
16469
|
+
for (const column of ["source_id", "source_record_id", "source_meta_json"]) {
|
|
16470
|
+
const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info('session_transcripts') WHERE name = ?").get(column);
|
|
16471
|
+
if (exists == null)
|
|
16472
|
+
db.exec(`ALTER TABLE session_transcripts ADD COLUMN ${column} TEXT`);
|
|
16473
|
+
}
|
|
16474
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_session_transcripts_agent_source ON session_transcripts(agent_id, source_id)");
|
|
16475
|
+
}
|
|
16476
|
+
function up147(db) {
|
|
16477
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state)");
|
|
16478
|
+
}
|
|
16479
|
+
function up148(db) {
|
|
16480
|
+
const columns = db.prepare("PRAGMA table_info(source_import_record_attempts)").all();
|
|
16481
|
+
if (!columns.some((column) => column.name === "source_id")) {
|
|
16482
|
+
db.exec("ALTER TABLE source_import_record_attempts ADD COLUMN source_id TEXT");
|
|
16483
|
+
}
|
|
16484
|
+
}
|
|
16485
|
+
function up149(db) {
|
|
16486
|
+
const addColumn = (table, column, definition) => {
|
|
16487
|
+
const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info(?) WHERE name = ?").get(table, column);
|
|
16488
|
+
if (exists == null)
|
|
16489
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
16490
|
+
};
|
|
16491
|
+
addColumn("source_import_jobs", "duplicate_mode", "TEXT NOT NULL DEFAULT 'skip' CHECK (duplicate_mode IN ('skip','replace','reimport'))");
|
|
16492
|
+
addColumn("source_import_jobs", "next_attempt_at", "TEXT");
|
|
16493
|
+
addColumn("source_import_files", "error", "TEXT");
|
|
16494
|
+
}
|
|
16495
|
+
function addColumnIfMissing28(db, table, column, definition) {
|
|
16496
|
+
const columns = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
16497
|
+
if (!columns.some((row) => row.name === column))
|
|
16498
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
16499
|
+
}
|
|
16500
|
+
function up150(db) {
|
|
16501
|
+
addColumnIfMissing28(db, "memory_md_heads", "is_current", "INTEGER NOT NULL DEFAULT 0");
|
|
16502
|
+
addColumnIfMissing28(db, "dreaming_passes", "head_base_revision", "INTEGER");
|
|
16503
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_memory_head_revisions_content_hash ON memory_head_revisions(content_hash)");
|
|
16504
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_memory_md_heads_content_hash ON memory_md_heads(content_hash)");
|
|
16505
|
+
db.exec(`
|
|
16506
|
+
CREATE TRIGGER IF NOT EXISTS dreaming_passes_head_fence_ai
|
|
16507
|
+
AFTER INSERT ON dreaming_passes
|
|
16508
|
+
WHEN NEW.mode = 'incremental-content'
|
|
16509
|
+
BEGIN
|
|
16510
|
+
INSERT OR IGNORE INTO memory_md_heads (agent_id, content, content_hash, revision, updated_at, is_current)
|
|
16511
|
+
VALUES (NEW.agent_id, '', '', 0, datetime('now'), 0);
|
|
16512
|
+
UPDATE dreaming_passes
|
|
16513
|
+
SET head_base_revision = (SELECT revision FROM memory_md_heads WHERE agent_id = NEW.agent_id)
|
|
16514
|
+
WHERE id = NEW.id;
|
|
16515
|
+
END;
|
|
16516
|
+
|
|
16517
|
+
CREATE TRIGGER IF NOT EXISTS memories_head_freshness_au
|
|
16518
|
+
AFTER UPDATE OF content, superseded_by, stale_at, is_deleted, agent_id, visibility, scope, memory_kind ON memories
|
|
16519
|
+
WHEN OLD.content IS NOT NEW.content OR OLD.superseded_by IS NOT NEW.superseded_by
|
|
16520
|
+
OR OLD.stale_at IS NOT NEW.stale_at OR OLD.is_deleted IS NOT NEW.is_deleted
|
|
16521
|
+
OR OLD.agent_id IS NOT NEW.agent_id OR OLD.visibility IS NOT NEW.visibility OR OLD.scope IS NOT NEW.scope OR OLD.memory_kind IS NOT NEW.memory_kind
|
|
16522
|
+
BEGIN
|
|
16523
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16524
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
|
|
16525
|
+
OR (COALESCE(OLD.visibility, 'global') = 'global' OR COALESCE(NEW.visibility, 'global') = 'global')
|
|
16526
|
+
AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
16527
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
|
|
16528
|
+
(SELECT policy_group FROM agents WHERE id IN (OLD.agent_id, NEW.agent_id))));
|
|
16529
|
+
END;
|
|
16530
|
+
|
|
16531
|
+
CREATE TRIGGER IF NOT EXISTS memories_head_freshness_ad
|
|
16532
|
+
AFTER DELETE ON memories
|
|
16533
|
+
BEGIN
|
|
16534
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16535
|
+
WHERE agent_id = OLD.agent_id
|
|
16536
|
+
OR (COALESCE(OLD.visibility, 'global') = 'global'
|
|
16537
|
+
AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
16538
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
|
|
16539
|
+
(SELECT policy_group FROM agents WHERE id = OLD.agent_id))));
|
|
16540
|
+
END;
|
|
16541
|
+
|
|
16542
|
+
CREATE TRIGGER IF NOT EXISTS agents_head_freshness_ad
|
|
16543
|
+
AFTER DELETE ON agents
|
|
16544
|
+
BEGIN
|
|
16545
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16546
|
+
WHERE agent_id = OLD.id OR agent_id IN (SELECT id FROM agents WHERE read_policy='group' AND policy_group=OLD.policy_group);
|
|
16547
|
+
END;
|
|
16548
|
+
|
|
16549
|
+
CREATE TRIGGER IF NOT EXISTS agents_head_freshness_au
|
|
16550
|
+
AFTER UPDATE OF read_policy, policy_group ON agents
|
|
16551
|
+
WHEN OLD.read_policy IS NOT NEW.read_policy OR OLD.policy_group IS NOT NEW.policy_group
|
|
16552
|
+
BEGIN
|
|
16553
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16554
|
+
WHERE agent_id IN (OLD.id, NEW.id)
|
|
16555
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
16556
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN (OLD.policy_group, NEW.policy_group));
|
|
16557
|
+
END;
|
|
16558
|
+
`);
|
|
16559
|
+
for (const table of ["memory_artifacts", "session_transcripts"]) {
|
|
16560
|
+
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
16561
|
+
if (!exists)
|
|
16562
|
+
continue;
|
|
16563
|
+
const hasIsDeleted = db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === "is_deleted");
|
|
16564
|
+
const updateColumns = table === "session_transcripts" ? "content, agent_id, completed_at" : hasIsDeleted ? "content, agent_id, is_deleted" : "content, agent_id";
|
|
16565
|
+
const contentChanged = table === "session_transcripts" ? "OLD.completed_at IS NOT NULL AND (OLD.content IS NOT NEW.content OR NEW.completed_at IS NULL)" : `OLD.content IS NOT NEW.content${hasIsDeleted ? " OR OLD.is_deleted IS NOT NEW.is_deleted" : ""}`;
|
|
16566
|
+
db.exec(`
|
|
16567
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
|
|
16568
|
+
AFTER UPDATE OF ${updateColumns} ON ${table}
|
|
16569
|
+
WHEN OLD.agent_id IS NOT NEW.agent_id OR ${contentChanged}
|
|
16570
|
+
BEGIN
|
|
16571
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16572
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
16573
|
+
END;
|
|
16574
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
|
|
16575
|
+
AFTER DELETE ON ${table}
|
|
16576
|
+
BEGIN
|
|
16577
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
16578
|
+
END;
|
|
16579
|
+
`);
|
|
16580
|
+
}
|
|
16581
|
+
if (db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_summaries'").get()) {
|
|
16582
|
+
db.exec(`
|
|
16583
|
+
CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_au
|
|
16584
|
+
AFTER UPDATE OF content, source_ref, source_type, depth, agent_id ON session_summaries
|
|
16585
|
+
WHEN OLD.depth = 0 AND (OLD.content IS NOT NEW.content OR OLD.source_ref IS NOT NEW.source_ref OR OLD.source_type IS NOT NEW.source_type OR OLD.depth IS NOT NEW.depth OR OLD.agent_id IS NOT NEW.agent_id)
|
|
16586
|
+
BEGIN
|
|
16587
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
16588
|
+
END;
|
|
16589
|
+
CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_ad
|
|
16590
|
+
AFTER DELETE ON session_summaries
|
|
16591
|
+
WHEN OLD.depth = 0
|
|
16592
|
+
BEGIN
|
|
16593
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
16594
|
+
END;
|
|
16595
|
+
`);
|
|
16596
|
+
}
|
|
16597
|
+
const safetyExists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='memory_content_safety'").get();
|
|
16598
|
+
if (safetyExists) {
|
|
16599
|
+
db.exec(`
|
|
16600
|
+
CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_ai
|
|
16601
|
+
AFTER INSERT ON memory_content_safety
|
|
16602
|
+
WHEN NEW.status IS NOT 'clean' OR NEW.context_eligible IS NOT 1
|
|
16603
|
+
BEGIN
|
|
16604
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16605
|
+
WHERE agent_id IN (NEW.agent_id)
|
|
16606
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy IN ('shared', 'group'));
|
|
16607
|
+
END;
|
|
16608
|
+
|
|
16609
|
+
CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_au
|
|
16610
|
+
AFTER UPDATE OF context_eligible, agent_id, status ON memory_content_safety
|
|
16611
|
+
WHEN (OLD.context_eligible IS NOT NEW.context_eligible OR OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)
|
|
16612
|
+
AND (OLD.status IS NOT 'clean' OR NEW.status IS NOT 'clean' OR OLD.context_eligible IS NOT 1 OR NEW.context_eligible IS NOT 1)
|
|
16613
|
+
BEGIN
|
|
16614
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16615
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
|
|
16616
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
16617
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group');
|
|
16618
|
+
END;
|
|
16619
|
+
`);
|
|
16620
|
+
}
|
|
16621
|
+
for (const table of ["memory_artifact_tombstones", "imported_source_lifecycle"]) {
|
|
16622
|
+
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
16623
|
+
if (!exists)
|
|
16624
|
+
continue;
|
|
16625
|
+
const lifecycleClause = table === "imported_source_lifecycle" ? " WHEN NEW.status = 'unsupported'" : "";
|
|
16626
|
+
const updateColumns = table === "imported_source_lifecycle" ? "agent_id, status" : "agent_id";
|
|
16627
|
+
const lifecycleUpdateClause = table === "imported_source_lifecycle" ? " AND NEW.status = 'unsupported'" : "";
|
|
16628
|
+
const lifecycleWhen = table === "imported_source_lifecycle" ? `(OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)${lifecycleUpdateClause}` : "OLD.agent_id IS NOT NEW.agent_id";
|
|
16629
|
+
db.exec(`
|
|
16630
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ai
|
|
16631
|
+
AFTER INSERT ON ${table}${lifecycleClause}
|
|
16632
|
+
BEGIN
|
|
16633
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = NEW.agent_id;
|
|
16634
|
+
END;
|
|
16635
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
|
|
16636
|
+
AFTER UPDATE OF ${updateColumns} ON ${table}
|
|
16637
|
+
WHEN ${lifecycleWhen}
|
|
16638
|
+
BEGIN
|
|
16639
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
16640
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
16641
|
+
END;
|
|
16642
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
|
|
16643
|
+
AFTER DELETE ON ${table}
|
|
16644
|
+
BEGIN
|
|
16645
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
16646
|
+
END;
|
|
16647
|
+
`);
|
|
16648
|
+
}
|
|
16649
|
+
}
|
|
16415
16650
|
var MIGRATIONS = [
|
|
16416
16651
|
{
|
|
16417
16652
|
version: 1,
|
|
@@ -17561,6 +17796,60 @@ var MIGRATIONS = [
|
|
|
17561
17796
|
name: "dreaming-evidence-reviews",
|
|
17562
17797
|
up: up145,
|
|
17563
17798
|
artifacts: { tables: ["dreaming_evidence_reviews"] }
|
|
17799
|
+
},
|
|
17800
|
+
{
|
|
17801
|
+
version: 146,
|
|
17802
|
+
name: "source-transcript-import",
|
|
17803
|
+
up: up146,
|
|
17804
|
+
artifacts: {
|
|
17805
|
+
tables: [
|
|
17806
|
+
"source_import_jobs",
|
|
17807
|
+
"source_import_files",
|
|
17808
|
+
"source_import_records",
|
|
17809
|
+
"transcript_import_conversations",
|
|
17810
|
+
"source_import_record_attempts"
|
|
17811
|
+
],
|
|
17812
|
+
columns: [
|
|
17813
|
+
{ table: "session_transcripts", column: "source_id" },
|
|
17814
|
+
{ table: "session_transcripts", column: "source_record_id" },
|
|
17815
|
+
{ table: "session_transcripts", column: "source_meta_json" }
|
|
17816
|
+
]
|
|
17817
|
+
}
|
|
17818
|
+
},
|
|
17819
|
+
{
|
|
17820
|
+
version: 147,
|
|
17821
|
+
name: "source-import-replay-file-slots",
|
|
17822
|
+
up: up147,
|
|
17823
|
+
artifacts: { tables: ["source_import_files"] }
|
|
17824
|
+
},
|
|
17825
|
+
{
|
|
17826
|
+
version: 148,
|
|
17827
|
+
name: "source-import-attempt-provenance",
|
|
17828
|
+
up: up148,
|
|
17829
|
+
artifacts: { columns: [{ table: "source_import_record_attempts", column: "source_id" }] }
|
|
17830
|
+
},
|
|
17831
|
+
{
|
|
17832
|
+
version: 149,
|
|
17833
|
+
name: "transcript-import-state-machine",
|
|
17834
|
+
up: up149,
|
|
17835
|
+
artifacts: {
|
|
17836
|
+
columns: [
|
|
17837
|
+
{ table: "source_import_jobs", column: "duplicate_mode" },
|
|
17838
|
+
{ table: "source_import_jobs", column: "next_attempt_at" },
|
|
17839
|
+
{ table: "source_import_files", column: "error" }
|
|
17840
|
+
]
|
|
17841
|
+
}
|
|
17842
|
+
},
|
|
17843
|
+
{
|
|
17844
|
+
version: 150,
|
|
17845
|
+
name: "memory-head-freshness",
|
|
17846
|
+
up: up150,
|
|
17847
|
+
artifacts: {
|
|
17848
|
+
columns: [
|
|
17849
|
+
{ table: "memory_md_heads", column: "is_current" },
|
|
17850
|
+
{ table: "dreaming_passes", column: "head_base_revision" }
|
|
17851
|
+
]
|
|
17852
|
+
}
|
|
17564
17853
|
}
|
|
17565
17854
|
];
|
|
17566
17855
|
var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
|
|
@@ -29539,7 +29828,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
|
|
|
29539
29828
|
return true;
|
|
29540
29829
|
return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
|
|
29541
29830
|
}
|
|
29542
|
-
function
|
|
29831
|
+
function up151(db) {
|
|
29543
29832
|
db.exec(`
|
|
29544
29833
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
29545
29834
|
version INTEGER PRIMARY KEY,
|
|
@@ -29632,27 +29921,27 @@ function hasColumn26(db, table, column) {
|
|
|
29632
29921
|
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
29633
29922
|
return rows.some((r22) => r22.name === column);
|
|
29634
29923
|
}
|
|
29635
|
-
function
|
|
29924
|
+
function addColumnIfMissing29(db, table, column, definition) {
|
|
29636
29925
|
if (!hasColumn26(db, table, column)) {
|
|
29637
29926
|
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
29638
29927
|
}
|
|
29639
29928
|
}
|
|
29640
29929
|
function up210(db) {
|
|
29641
|
-
|
|
29642
|
-
|
|
29643
|
-
|
|
29644
|
-
|
|
29645
|
-
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29650
|
-
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
|
|
29655
|
-
|
|
29930
|
+
addColumnIfMissing29(db, "memories", "content_hash", "TEXT");
|
|
29931
|
+
addColumnIfMissing29(db, "memories", "normalized_content", "TEXT");
|
|
29932
|
+
addColumnIfMissing29(db, "memories", "is_deleted", "INTEGER DEFAULT 0");
|
|
29933
|
+
addColumnIfMissing29(db, "memories", "deleted_at", "TEXT");
|
|
29934
|
+
addColumnIfMissing29(db, "memories", "extraction_status", "TEXT DEFAULT 'none'");
|
|
29935
|
+
addColumnIfMissing29(db, "memories", "embedding_model", "TEXT");
|
|
29936
|
+
addColumnIfMissing29(db, "memories", "extraction_model", "TEXT");
|
|
29937
|
+
addColumnIfMissing29(db, "memories", "update_count", "INTEGER DEFAULT 0");
|
|
29938
|
+
addColumnIfMissing29(db, "memories", "who", "TEXT");
|
|
29939
|
+
addColumnIfMissing29(db, "memories", "why", "TEXT");
|
|
29940
|
+
addColumnIfMissing29(db, "memories", "project", "TEXT");
|
|
29941
|
+
addColumnIfMissing29(db, "memories", "pinned", "INTEGER DEFAULT 0");
|
|
29942
|
+
addColumnIfMissing29(db, "memories", "importance", "REAL DEFAULT 0.5");
|
|
29943
|
+
addColumnIfMissing29(db, "memories", "last_accessed", "TEXT");
|
|
29944
|
+
addColumnIfMissing29(db, "memories", "access_count", "INTEGER DEFAULT 0");
|
|
29656
29945
|
db.exec(`
|
|
29657
29946
|
CREATE TABLE IF NOT EXISTS memory_history (
|
|
29658
29947
|
id TEXT PRIMARY KEY,
|
|
@@ -29748,7 +30037,7 @@ function up210(db) {
|
|
|
29748
30037
|
ON memory_entity_mentions(entity_id);
|
|
29749
30038
|
`);
|
|
29750
30039
|
}
|
|
29751
|
-
function
|
|
30040
|
+
function addColumnIfMissing210(db, table, column, definition) {
|
|
29752
30041
|
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
29753
30042
|
if (rows.some((r22) => r22.name === column))
|
|
29754
30043
|
return false;
|
|
@@ -29756,8 +30045,8 @@ function addColumnIfMissing29(db, table, column, definition) {
|
|
|
29756
30045
|
return true;
|
|
29757
30046
|
}
|
|
29758
30047
|
function up310(db) {
|
|
29759
|
-
|
|
29760
|
-
|
|
30048
|
+
addColumnIfMissing210(db, "memories", "why", "TEXT");
|
|
30049
|
+
addColumnIfMissing210(db, "memories", "project", "TEXT");
|
|
29761
30050
|
db.exec(`DROP INDEX IF EXISTS idx_memories_content_hash`);
|
|
29762
30051
|
db.exec(`
|
|
29763
30052
|
UPDATE memories
|
|
@@ -30049,7 +30338,7 @@ function up1310(db) {
|
|
|
30049
30338
|
addColumnIfMissing52(db, "memories", "source_path", "TEXT");
|
|
30050
30339
|
addColumnIfMissing52(db, "memories", "source_section", "TEXT");
|
|
30051
30340
|
}
|
|
30052
|
-
function
|
|
30341
|
+
function up1410(db) {
|
|
30053
30342
|
db.exec(`
|
|
30054
30343
|
CREATE TABLE IF NOT EXISTS telemetry_events (
|
|
30055
30344
|
id TEXT PRIMARY KEY,
|
|
@@ -34312,11 +34601,246 @@ function up1452(db) {
|
|
|
34312
34601
|
ON dreaming_evidence_reviews (agent_id, reviewed_at DESC);
|
|
34313
34602
|
`);
|
|
34314
34603
|
}
|
|
34604
|
+
function up1462(db) {
|
|
34605
|
+
db.exec(`
|
|
34606
|
+
CREATE TABLE IF NOT EXISTS source_import_jobs (
|
|
34607
|
+
id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind = 'import'), agent_id TEXT NOT NULL,
|
|
34608
|
+
schema_id TEXT NOT NULL, adapter_version INTEGER NOT NULL CHECK (adapter_version = 1),
|
|
34609
|
+
state TEXT NOT NULL CHECK (state IN ('staging','inventorying','queued','running','paused','completed','completed_with_rejections','cancelled','failed')),
|
|
34610
|
+
control_request TEXT CHECK (control_request IN ('pause','resume','retry','cancel') OR control_request IS NULL),
|
|
34611
|
+
generation INTEGER NOT NULL DEFAULT 0, total INTEGER NOT NULL DEFAULT 0, imported INTEGER NOT NULL DEFAULT 0,
|
|
34612
|
+
duplicate INTEGER NOT NULL DEFAULT 0, rejected INTEGER NOT NULL DEFAULT 0, pending INTEGER NOT NULL DEFAULT 0,
|
|
34613
|
+
lease_token TEXT, lease_expires_at TEXT, error TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
34614
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')), started_at TEXT, completed_at TEXT, reconciled_at TEXT
|
|
34615
|
+
);
|
|
34616
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_jobs_agent_state ON source_import_jobs(agent_id, state);
|
|
34617
|
+
|
|
34618
|
+
CREATE TABLE IF NOT EXISTS source_import_files (
|
|
34619
|
+
id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
|
|
34620
|
+
source_id TEXT NOT NULL, agent_id TEXT NOT NULL, ordinal INTEGER NOT NULL, name TEXT NOT NULL,
|
|
34621
|
+
managed_path TEXT NOT NULL, size_bytes INTEGER NOT NULL DEFAULT 0, content_hash TEXT,
|
|
34622
|
+
state TEXT NOT NULL CHECK (state IN ('staging','ready','inventorying','completed','failed')),
|
|
34623
|
+
record_count INTEGER NOT NULL DEFAULT 0, blank_count INTEGER NOT NULL DEFAULT 0, malformed_count INTEGER NOT NULL DEFAULT 0,
|
|
34624
|
+
inventory_version INTEGER NOT NULL DEFAULT 1, checkpoint_ordinal INTEGER NOT NULL DEFAULT 0,
|
|
34625
|
+
checkpoint_byte_offset INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
34626
|
+
UNIQUE(job_id, ordinal)
|
|
34627
|
+
);
|
|
34628
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state);
|
|
34629
|
+
|
|
34630
|
+
CREATE TABLE IF NOT EXISTS source_import_records (
|
|
34631
|
+
id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
|
|
34632
|
+
file_id TEXT NOT NULL REFERENCES source_import_files(id) ON DELETE CASCADE, source_id TEXT NOT NULL, agent_id TEXT NOT NULL,
|
|
34633
|
+
ordinal INTEGER NOT NULL, line_number INTEGER NOT NULL, byte_offset INTEGER NOT NULL, byte_length INTEGER NOT NULL,
|
|
34634
|
+
raw_hash TEXT NOT NULL, external_identity TEXT, conversation_fingerprint TEXT, status TEXT NOT NULL CHECK (status IN ('pending','imported','duplicate','rejected','cancelled')),
|
|
34635
|
+
canonical_id TEXT, canonical_key TEXT, rejection_code TEXT, attempt_count INTEGER NOT NULL DEFAULT 0,
|
|
34636
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
34637
|
+
UNIQUE(file_id, ordinal), UNIQUE(file_id, byte_offset)
|
|
34638
|
+
);
|
|
34639
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_records_job_status ON source_import_records(job_id, status);
|
|
34640
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_records_source_status ON source_import_records(agent_id, source_id, status);
|
|
34641
|
+
|
|
34642
|
+
CREATE TABLE IF NOT EXISTS transcript_import_conversations (
|
|
34643
|
+
agent_id TEXT NOT NULL, external_identity TEXT NOT NULL, canonical_key TEXT NOT NULL,
|
|
34644
|
+
conversation_fingerprint TEXT NOT NULL, canonical_id TEXT NOT NULL, owner_source_id TEXT NOT NULL,
|
|
34645
|
+
owner_record_id TEXT NOT NULL, state TEXT NOT NULL CHECK (state IN ('committing','committed','removed')),
|
|
34646
|
+
content_hash TEXT NOT NULL, harness TEXT NOT NULL, timestamp TEXT NOT NULL,
|
|
34647
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
34648
|
+
PRIMARY KEY (agent_id, external_identity), UNIQUE(agent_id, canonical_key)
|
|
34649
|
+
);
|
|
34650
|
+
CREATE INDEX IF NOT EXISTS idx_transcript_import_conversations_source ON transcript_import_conversations(agent_id, owner_source_id);
|
|
34651
|
+
|
|
34652
|
+
CREATE TABLE IF NOT EXISTS source_import_record_attempts (
|
|
34653
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT, agent_id TEXT NOT NULL, job_id TEXT NOT NULL, file_id TEXT NOT NULL,
|
|
34654
|
+
record_id TEXT NOT NULL, generation INTEGER NOT NULL, outcome TEXT NOT NULL, error_code TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
34655
|
+
);
|
|
34656
|
+
CREATE INDEX IF NOT EXISTS idx_source_import_attempts_record ON source_import_record_attempts(agent_id, record_id, created_at);
|
|
34657
|
+
`);
|
|
34658
|
+
for (const column of ["source_id", "source_record_id", "source_meta_json"]) {
|
|
34659
|
+
const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info('session_transcripts') WHERE name = ?").get(column);
|
|
34660
|
+
if (exists == null)
|
|
34661
|
+
db.exec(`ALTER TABLE session_transcripts ADD COLUMN ${column} TEXT`);
|
|
34662
|
+
}
|
|
34663
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_session_transcripts_agent_source ON session_transcripts(agent_id, source_id)");
|
|
34664
|
+
}
|
|
34665
|
+
function up1472(db) {
|
|
34666
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state)");
|
|
34667
|
+
}
|
|
34668
|
+
function up1482(db) {
|
|
34669
|
+
const columns = db.prepare("PRAGMA table_info(source_import_record_attempts)").all();
|
|
34670
|
+
if (!columns.some((column) => column.name === "source_id")) {
|
|
34671
|
+
db.exec("ALTER TABLE source_import_record_attempts ADD COLUMN source_id TEXT");
|
|
34672
|
+
}
|
|
34673
|
+
}
|
|
34674
|
+
function up1492(db) {
|
|
34675
|
+
const addColumn = (table, column, definition) => {
|
|
34676
|
+
const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info(?) WHERE name = ?").get(table, column);
|
|
34677
|
+
if (exists == null)
|
|
34678
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
34679
|
+
};
|
|
34680
|
+
addColumn("source_import_jobs", "duplicate_mode", "TEXT NOT NULL DEFAULT 'skip' CHECK (duplicate_mode IN ('skip','replace','reimport'))");
|
|
34681
|
+
addColumn("source_import_jobs", "next_attempt_at", "TEXT");
|
|
34682
|
+
addColumn("source_import_files", "error", "TEXT");
|
|
34683
|
+
}
|
|
34684
|
+
function addColumnIfMissing282(db, table, column, definition) {
|
|
34685
|
+
const columns = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
34686
|
+
if (!columns.some((row) => row.name === column))
|
|
34687
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
34688
|
+
}
|
|
34689
|
+
function up1502(db) {
|
|
34690
|
+
addColumnIfMissing282(db, "memory_md_heads", "is_current", "INTEGER NOT NULL DEFAULT 0");
|
|
34691
|
+
addColumnIfMissing282(db, "dreaming_passes", "head_base_revision", "INTEGER");
|
|
34692
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_memory_head_revisions_content_hash ON memory_head_revisions(content_hash)");
|
|
34693
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_memory_md_heads_content_hash ON memory_md_heads(content_hash)");
|
|
34694
|
+
db.exec(`
|
|
34695
|
+
CREATE TRIGGER IF NOT EXISTS dreaming_passes_head_fence_ai
|
|
34696
|
+
AFTER INSERT ON dreaming_passes
|
|
34697
|
+
WHEN NEW.mode = 'incremental-content'
|
|
34698
|
+
BEGIN
|
|
34699
|
+
INSERT OR IGNORE INTO memory_md_heads (agent_id, content, content_hash, revision, updated_at, is_current)
|
|
34700
|
+
VALUES (NEW.agent_id, '', '', 0, datetime('now'), 0);
|
|
34701
|
+
UPDATE dreaming_passes
|
|
34702
|
+
SET head_base_revision = (SELECT revision FROM memory_md_heads WHERE agent_id = NEW.agent_id)
|
|
34703
|
+
WHERE id = NEW.id;
|
|
34704
|
+
END;
|
|
34705
|
+
|
|
34706
|
+
CREATE TRIGGER IF NOT EXISTS memories_head_freshness_au
|
|
34707
|
+
AFTER UPDATE OF content, superseded_by, stale_at, is_deleted, agent_id, visibility, scope, memory_kind ON memories
|
|
34708
|
+
WHEN OLD.content IS NOT NEW.content OR OLD.superseded_by IS NOT NEW.superseded_by
|
|
34709
|
+
OR OLD.stale_at IS NOT NEW.stale_at OR OLD.is_deleted IS NOT NEW.is_deleted
|
|
34710
|
+
OR OLD.agent_id IS NOT NEW.agent_id OR OLD.visibility IS NOT NEW.visibility OR OLD.scope IS NOT NEW.scope OR OLD.memory_kind IS NOT NEW.memory_kind
|
|
34711
|
+
BEGIN
|
|
34712
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34713
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
|
|
34714
|
+
OR (COALESCE(OLD.visibility, 'global') = 'global' OR COALESCE(NEW.visibility, 'global') = 'global')
|
|
34715
|
+
AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
34716
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
|
|
34717
|
+
(SELECT policy_group FROM agents WHERE id IN (OLD.agent_id, NEW.agent_id))));
|
|
34718
|
+
END;
|
|
34719
|
+
|
|
34720
|
+
CREATE TRIGGER IF NOT EXISTS memories_head_freshness_ad
|
|
34721
|
+
AFTER DELETE ON memories
|
|
34722
|
+
BEGIN
|
|
34723
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34724
|
+
WHERE agent_id = OLD.agent_id
|
|
34725
|
+
OR (COALESCE(OLD.visibility, 'global') = 'global'
|
|
34726
|
+
AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
34727
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
|
|
34728
|
+
(SELECT policy_group FROM agents WHERE id = OLD.agent_id))));
|
|
34729
|
+
END;
|
|
34730
|
+
|
|
34731
|
+
CREATE TRIGGER IF NOT EXISTS agents_head_freshness_ad
|
|
34732
|
+
AFTER DELETE ON agents
|
|
34733
|
+
BEGIN
|
|
34734
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34735
|
+
WHERE agent_id = OLD.id OR agent_id IN (SELECT id FROM agents WHERE read_policy='group' AND policy_group=OLD.policy_group);
|
|
34736
|
+
END;
|
|
34737
|
+
|
|
34738
|
+
CREATE TRIGGER IF NOT EXISTS agents_head_freshness_au
|
|
34739
|
+
AFTER UPDATE OF read_policy, policy_group ON agents
|
|
34740
|
+
WHEN OLD.read_policy IS NOT NEW.read_policy OR OLD.policy_group IS NOT NEW.policy_group
|
|
34741
|
+
BEGIN
|
|
34742
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34743
|
+
WHERE agent_id IN (OLD.id, NEW.id)
|
|
34744
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
34745
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN (OLD.policy_group, NEW.policy_group));
|
|
34746
|
+
END;
|
|
34747
|
+
`);
|
|
34748
|
+
for (const table of ["memory_artifacts", "session_transcripts"]) {
|
|
34749
|
+
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
34750
|
+
if (!exists)
|
|
34751
|
+
continue;
|
|
34752
|
+
const hasIsDeleted = db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === "is_deleted");
|
|
34753
|
+
const updateColumns = table === "session_transcripts" ? "content, agent_id, completed_at" : hasIsDeleted ? "content, agent_id, is_deleted" : "content, agent_id";
|
|
34754
|
+
const contentChanged = table === "session_transcripts" ? "OLD.completed_at IS NOT NULL AND (OLD.content IS NOT NEW.content OR NEW.completed_at IS NULL)" : `OLD.content IS NOT NEW.content${hasIsDeleted ? " OR OLD.is_deleted IS NOT NEW.is_deleted" : ""}`;
|
|
34755
|
+
db.exec(`
|
|
34756
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
|
|
34757
|
+
AFTER UPDATE OF ${updateColumns} ON ${table}
|
|
34758
|
+
WHEN OLD.agent_id IS NOT NEW.agent_id OR ${contentChanged}
|
|
34759
|
+
BEGIN
|
|
34760
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34761
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
34762
|
+
END;
|
|
34763
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
|
|
34764
|
+
AFTER DELETE ON ${table}
|
|
34765
|
+
BEGIN
|
|
34766
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
34767
|
+
END;
|
|
34768
|
+
`);
|
|
34769
|
+
}
|
|
34770
|
+
if (db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_summaries'").get()) {
|
|
34771
|
+
db.exec(`
|
|
34772
|
+
CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_au
|
|
34773
|
+
AFTER UPDATE OF content, source_ref, source_type, depth, agent_id ON session_summaries
|
|
34774
|
+
WHEN OLD.depth = 0 AND (OLD.content IS NOT NEW.content OR OLD.source_ref IS NOT NEW.source_ref OR OLD.source_type IS NOT NEW.source_type OR OLD.depth IS NOT NEW.depth OR OLD.agent_id IS NOT NEW.agent_id)
|
|
34775
|
+
BEGIN
|
|
34776
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
34777
|
+
END;
|
|
34778
|
+
CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_ad
|
|
34779
|
+
AFTER DELETE ON session_summaries
|
|
34780
|
+
WHEN OLD.depth = 0
|
|
34781
|
+
BEGIN
|
|
34782
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
34783
|
+
END;
|
|
34784
|
+
`);
|
|
34785
|
+
}
|
|
34786
|
+
const safetyExists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='memory_content_safety'").get();
|
|
34787
|
+
if (safetyExists) {
|
|
34788
|
+
db.exec(`
|
|
34789
|
+
CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_ai
|
|
34790
|
+
AFTER INSERT ON memory_content_safety
|
|
34791
|
+
WHEN NEW.status IS NOT 'clean' OR NEW.context_eligible IS NOT 1
|
|
34792
|
+
BEGIN
|
|
34793
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34794
|
+
WHERE agent_id IN (NEW.agent_id)
|
|
34795
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy IN ('shared', 'group'));
|
|
34796
|
+
END;
|
|
34797
|
+
|
|
34798
|
+
CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_au
|
|
34799
|
+
AFTER UPDATE OF context_eligible, agent_id, status ON memory_content_safety
|
|
34800
|
+
WHEN (OLD.context_eligible IS NOT NEW.context_eligible OR OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)
|
|
34801
|
+
AND (OLD.status IS NOT 'clean' OR NEW.status IS NOT 'clean' OR OLD.context_eligible IS NOT 1 OR NEW.context_eligible IS NOT 1)
|
|
34802
|
+
BEGIN
|
|
34803
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34804
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
|
|
34805
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
|
|
34806
|
+
OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group');
|
|
34807
|
+
END;
|
|
34808
|
+
`);
|
|
34809
|
+
}
|
|
34810
|
+
for (const table of ["memory_artifact_tombstones", "imported_source_lifecycle"]) {
|
|
34811
|
+
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
34812
|
+
if (!exists)
|
|
34813
|
+
continue;
|
|
34814
|
+
const lifecycleClause = table === "imported_source_lifecycle" ? " WHEN NEW.status = 'unsupported'" : "";
|
|
34815
|
+
const updateColumns = table === "imported_source_lifecycle" ? "agent_id, status" : "agent_id";
|
|
34816
|
+
const lifecycleUpdateClause = table === "imported_source_lifecycle" ? " AND NEW.status = 'unsupported'" : "";
|
|
34817
|
+
const lifecycleWhen = table === "imported_source_lifecycle" ? `(OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)${lifecycleUpdateClause}` : "OLD.agent_id IS NOT NEW.agent_id";
|
|
34818
|
+
db.exec(`
|
|
34819
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ai
|
|
34820
|
+
AFTER INSERT ON ${table}${lifecycleClause}
|
|
34821
|
+
BEGIN
|
|
34822
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = NEW.agent_id;
|
|
34823
|
+
END;
|
|
34824
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
|
|
34825
|
+
AFTER UPDATE OF ${updateColumns} ON ${table}
|
|
34826
|
+
WHEN ${lifecycleWhen}
|
|
34827
|
+
BEGIN
|
|
34828
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
|
|
34829
|
+
WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
|
|
34830
|
+
END;
|
|
34831
|
+
CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
|
|
34832
|
+
AFTER DELETE ON ${table}
|
|
34833
|
+
BEGIN
|
|
34834
|
+
UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
|
|
34835
|
+
END;
|
|
34836
|
+
`);
|
|
34837
|
+
}
|
|
34838
|
+
}
|
|
34315
34839
|
var MIGRATIONS2 = [
|
|
34316
34840
|
{
|
|
34317
34841
|
version: 1,
|
|
34318
34842
|
name: "baseline",
|
|
34319
|
-
up:
|
|
34843
|
+
up: up151,
|
|
34320
34844
|
artifacts: { tables: ["memories", "conversations", "embeddings"] }
|
|
34321
34845
|
},
|
|
34322
34846
|
{
|
|
@@ -34405,7 +34929,7 @@ var MIGRATIONS2 = [
|
|
|
34405
34929
|
{
|
|
34406
34930
|
version: 14,
|
|
34407
34931
|
name: "telemetry",
|
|
34408
|
-
up:
|
|
34932
|
+
up: up1410,
|
|
34409
34933
|
artifacts: { tables: ["telemetry_events"] }
|
|
34410
34934
|
},
|
|
34411
34935
|
{
|
|
@@ -35461,6 +35985,60 @@ var MIGRATIONS2 = [
|
|
|
35461
35985
|
name: "dreaming-evidence-reviews",
|
|
35462
35986
|
up: up1452,
|
|
35463
35987
|
artifacts: { tables: ["dreaming_evidence_reviews"] }
|
|
35988
|
+
},
|
|
35989
|
+
{
|
|
35990
|
+
version: 146,
|
|
35991
|
+
name: "source-transcript-import",
|
|
35992
|
+
up: up1462,
|
|
35993
|
+
artifacts: {
|
|
35994
|
+
tables: [
|
|
35995
|
+
"source_import_jobs",
|
|
35996
|
+
"source_import_files",
|
|
35997
|
+
"source_import_records",
|
|
35998
|
+
"transcript_import_conversations",
|
|
35999
|
+
"source_import_record_attempts"
|
|
36000
|
+
],
|
|
36001
|
+
columns: [
|
|
36002
|
+
{ table: "session_transcripts", column: "source_id" },
|
|
36003
|
+
{ table: "session_transcripts", column: "source_record_id" },
|
|
36004
|
+
{ table: "session_transcripts", column: "source_meta_json" }
|
|
36005
|
+
]
|
|
36006
|
+
}
|
|
36007
|
+
},
|
|
36008
|
+
{
|
|
36009
|
+
version: 147,
|
|
36010
|
+
name: "source-import-replay-file-slots",
|
|
36011
|
+
up: up1472,
|
|
36012
|
+
artifacts: { tables: ["source_import_files"] }
|
|
36013
|
+
},
|
|
36014
|
+
{
|
|
36015
|
+
version: 148,
|
|
36016
|
+
name: "source-import-attempt-provenance",
|
|
36017
|
+
up: up1482,
|
|
36018
|
+
artifacts: { columns: [{ table: "source_import_record_attempts", column: "source_id" }] }
|
|
36019
|
+
},
|
|
36020
|
+
{
|
|
36021
|
+
version: 149,
|
|
36022
|
+
name: "transcript-import-state-machine",
|
|
36023
|
+
up: up1492,
|
|
36024
|
+
artifacts: {
|
|
36025
|
+
columns: [
|
|
36026
|
+
{ table: "source_import_jobs", column: "duplicate_mode" },
|
|
36027
|
+
{ table: "source_import_jobs", column: "next_attempt_at" },
|
|
36028
|
+
{ table: "source_import_files", column: "error" }
|
|
36029
|
+
]
|
|
36030
|
+
}
|
|
36031
|
+
},
|
|
36032
|
+
{
|
|
36033
|
+
version: 150,
|
|
36034
|
+
name: "memory-head-freshness",
|
|
36035
|
+
up: up1502,
|
|
36036
|
+
artifacts: {
|
|
36037
|
+
columns: [
|
|
36038
|
+
{ table: "memory_md_heads", column: "is_current" },
|
|
36039
|
+
{ table: "dreaming_passes", column: "head_base_revision" }
|
|
36040
|
+
]
|
|
36041
|
+
}
|
|
35464
36042
|
}
|
|
35465
36043
|
];
|
|
35466
36044
|
var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
|