@signetai/signet-memory-openclaw 0.236.1 → 0.237.1

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.
Files changed (2) hide show
  1. package/dist/index.js +439 -361
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10411,99 +10411,6 @@ var execFileHiddenImpl = (...args) => Reflect.apply(nodeExecFile, undefined, wit
10411
10411
  Object.defineProperty(execFileHiddenImpl, promisify.custom, {
10412
10412
  value: (...args) => Reflect.apply(nodeExecFileAsync, undefined, withWindowsHideArgument(args, 1))
10413
10413
  });
10414
- var MEMORY_CONTENT_SAFETY_POLICY_VERSION = "memory-content-safety-v1";
10415
- var MEMORY_CONTENT_SAFETY_REASONS = [
10416
- "prompt_injection",
10417
- "exfiltration",
10418
- "credential_harvesting",
10419
- "malicious_shell",
10420
- "tool_directive",
10421
- "invisible_unicode"
10422
- ];
10423
- var INVISIBLE_UNICODE_RE = /(?:\u034f|[\u00ad\u061c\u070f\u180e\u200b\u200c\u200e\u200f\u202a-\u202e\u2060\u2066-\u2069\u206a-\u206f\ufeff]|[\u{e0000}-\u{e007f}])/u;
10424
- var STRONG_DEFENSIVE_CONTEXT_RE = /\b(?:security\s+(?:guidance|discussion|analysis)|threat\s+model|defensive)\b/i;
10425
- var REPORTING_CONTEXT_RE = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b/i;
10426
- var REPORTING_BEFORE_RE = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b[\s\S]{0,80}\b(?:say\w*|read\w*|show\w*|flag\w*|detect\w*|describ\w*|demonstrat\w*|contain\w*|match\w*|pattern)\b/i;
10427
- var REPORTING_AFTER_RE = /\b(?:detector|scanner|classif\w*|flag\w*|pattern|dangerous|unsafe|malicious|hostile|should|would|must|never|do not|don't|avoid|quoted)\b/i;
10428
- var NEGATED_DIRECTIVE_RE = /\b(?:never|do not|don't|should not|must not|cannot|can't|avoid|prevent|detect|mitigat\w*)\b[\s\S]{0,80}$/i;
10429
- var PROMPT_INJECTION_RES = [
10430
- /\b(?:ignore|disregard|override|forget|bypass)\b[\s\S]{0,100}\b(?:previous|prior|above|earlier|system|developer|assistant|safety|security)?\s*(?:instructions?|rules?|prompt|message)\b/i,
10431
- /\b(?:new|following|these)\s+(?:(?:system|developer|assistant|hidden)\s+)?instructions?\b/i,
10432
- /(?:^|\n)\s*(?:system|developer|instruction|prompt)\s*:/im,
10433
- /<\s*(?:system|developer|assistant|instruction|prompt)\b[^>]*>/i,
10434
- /\b(?:you are now|act as|roleplay as|pretend to be)\b[\s\S]{0,80}\b(?:system|admin|developer|unrestricted|jailbreak|different agent)\b/i
10435
- ];
10436
- var TOOL_DIRECTIVE_RES = [
10437
- /<\s*(?:tool[_-]?call|function[_-]?call|invoke|tool)\b/i,
10438
- /\b(?:assistant|system)\s+to\s*=\s*[a-z0-9_.-]+/i,
10439
- /\b(?:call|invoke|use|run|execute)\s+(?:the\s+)?[a-z0-9_.-]+\s+tool\b/i
10440
- ];
10441
- var EXFILTRATION_RE = /\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b[\s\S]{0,120}(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)/i;
10442
- var EXFILTRATION_REVERSE = /(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)[\s\S]{0,120}\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b/i;
10443
- var CREDENTIAL_HARVESTING_RE = /\b(?:enter|paste|provide|share|send|give|submit|type|hand over)\b[\s\S]{0,80}\b(?:password|api\s*key|token|secret|credential|private\s+key)\b/i;
10444
- var DANGEROUS_SHELL_RE = /\b(?:curl|wget)\b[^\n]{0,240}\|\s*(?:ba|z|fi)?sh\b|\brm\s+-rf\s+(?:\/|~|\.ssh)[^\n]{0,240}|\b(?:cat|head|tail)\s+~\/?\.ssh\/(?:id_[a-z]+|authorized_keys)\b|\b(?:printenv|env)\b[^\n]{0,120}\b(?:curl|wget|send|upload|post)\b/i;
10445
- function matchHasDefensiveContext(content, match) {
10446
- if (!match || !match[0])
10447
- return false;
10448
- const start = match.index ?? 0;
10449
- const before = content.slice(Math.max(0, start - 120), start);
10450
- const after = content.slice(start + match[0].length, start + match[0].length + 160);
10451
- return STRONG_DEFENSIVE_CONTEXT_RE.test(match[0]) || NEGATED_DIRECTIVE_RE.test(before) || STRONG_DEFENSIVE_CONTEXT_RE.test(before) || STRONG_DEFENSIVE_CONTEXT_RE.test(after) || REPORTING_BEFORE_RE.test(before) || REPORTING_CONTEXT_RE.test(before) && REPORTING_AFTER_RE.test(after);
10452
- }
10453
- function hasActionableMatch(content, patterns) {
10454
- return patterns.some((pattern) => {
10455
- const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
10456
- const searchable = new RegExp(pattern.source, flags);
10457
- let match;
10458
- while ((match = searchable.exec(content)) !== null) {
10459
- if (!matchHasDefensiveContext(content, match))
10460
- return true;
10461
- if (match[0].length === 0)
10462
- searchable.lastIndex += 1;
10463
- }
10464
- return false;
10465
- });
10466
- }
10467
- function hasDangerousShell(content) {
10468
- const searchable = new RegExp(DANGEROUS_SHELL_RE.source, `${DANGEROUS_SHELL_RE.flags}g`);
10469
- let match;
10470
- while ((match = searchable.exec(content)) !== null) {
10471
- if (matchHasDefensiveContext(content, match))
10472
- continue;
10473
- const end = (match.index ?? 0) + match[0].length;
10474
- const after = content.slice(end, end + 160);
10475
- if (!STRONG_DEFENSIVE_CONTEXT_RE.test(after) && !REPORTING_AFTER_RE.test(after))
10476
- return true;
10477
- if (match[0].length === 0)
10478
- searchable.lastIndex += 1;
10479
- }
10480
- return false;
10481
- }
10482
- function scanMemoryContent(content) {
10483
- const raw = typeof content === "string" ? content : String(content ?? "");
10484
- const normalized = raw.normalize("NFKC");
10485
- const reasons = new Set;
10486
- if (INVISIBLE_UNICODE_RE.test(raw))
10487
- reasons.add("invisible_unicode");
10488
- if (hasActionableMatch(normalized, PROMPT_INJECTION_RES))
10489
- reasons.add("prompt_injection");
10490
- if (hasActionableMatch(normalized, TOOL_DIRECTIVE_RES))
10491
- reasons.add("tool_directive");
10492
- if (hasActionableMatch(normalized, [EXFILTRATION_RE, EXFILTRATION_REVERSE]))
10493
- reasons.add("exfiltration");
10494
- if (hasActionableMatch(normalized, [CREDENTIAL_HARVESTING_RE]))
10495
- reasons.add("credential_harvesting");
10496
- if (hasDangerousShell(normalized))
10497
- reasons.add("malicious_shell");
10498
- const orderedReasons = MEMORY_CONTENT_SAFETY_REASONS.filter((reason) => reasons.has(reason));
10499
- const status = orderedReasons.length === 0 ? "clean" : orderedReasons.every((reason) => reason === "invisible_unicode") ? "tainted" : "blocked";
10500
- return {
10501
- status,
10502
- contextEligible: status === "clean",
10503
- reasons: orderedReasons,
10504
- policyVersion: MEMORY_CONTENT_SAFETY_POLICY_VERSION
10505
- };
10506
- }
10507
10414
  var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = [
10508
10415
  "extract",
10509
10416
  "aggregate-recall",
@@ -10626,7 +10533,7 @@ function up4(db) {
10626
10533
  function up5(db) {
10627
10534
  db.exec("DROP TABLE IF EXISTS mcp_invocations");
10628
10535
  }
10629
- var MEMORIES_FTS_TOKENIZER = "unicode61";
10536
+ var MEMORIES_FTS_TOKENIZER = "porter unicode61";
10630
10537
  var FTS_STATE_TABLE = "memories_fts_state";
10631
10538
  function normalizeSql(sql) {
10632
10539
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -10736,10 +10643,7 @@ function readMemoriesFtsSql(db) {
10736
10643
  function memoriesFtsNeedsTokenizerRepair(sql) {
10737
10644
  if (sql === null)
10738
10645
  return false;
10739
- const normalized = normalizeSql(sql);
10740
- if (normalized.includes("porter unicode61"))
10741
- return true;
10742
- return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
10646
+ return !normalizeSql(sql).includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
10743
10647
  }
10744
10648
  function up6(db) {
10745
10649
  db.exec(`
@@ -14652,38 +14556,6 @@ function up129(db) {
14652
14556
  ON imported_source_lifecycle(agent_id, status, updated_at DESC);
14653
14557
  `);
14654
14558
  }
14655
- function tableExists2(db, table) {
14656
- return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
14657
- }
14658
- function hasColumn24(db, table, column) {
14659
- return db.prepare(`PRAGMA table_info("${table}")`).all().some((row) => row.name === column);
14660
- }
14661
- function backfill(db, rows, sourceKind, scannedAt) {
14662
- const statement = db.prepare(`INSERT INTO memory_content_safety
14663
- (agent_id, source_kind, source_id, status, context_eligible, reasons_json, policy_version, scanned_at)
14664
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
14665
- ON CONFLICT(agent_id, source_kind, source_id) DO UPDATE SET
14666
- status = excluded.status,
14667
- context_eligible = excluded.context_eligible,
14668
- reasons_json = excluded.reasons_json,
14669
- policy_version = excluded.policy_version,
14670
- scanned_at = excluded.scanned_at`);
14671
- for (const row of rows) {
14672
- const sourceId = row.source_id?.trim();
14673
- if (!sourceId)
14674
- continue;
14675
- const assessment = scanMemoryContent(row.content ?? "");
14676
- statement.run(row.agent_id?.trim() || "default", sourceKind, sourceId, assessment.status, assessment.contextEligible ? 1 : 0, JSON.stringify(assessment.reasons), MEMORY_CONTENT_SAFETY_POLICY_VERSION, scannedAt);
14677
- }
14678
- }
14679
- function backfillTable(db, params) {
14680
- if (!tableExists2(db, params.table) || !hasColumn24(db, params.table, params.sourceIdColumn) || !hasColumn24(db, params.table, params.contentColumn))
14681
- return;
14682
- const agentColumn = hasColumn24(db, params.table, "agent_id") ? "COALESCE(NULLIF(TRIM(agent_id), ''), 'default')" : "'default'";
14683
- const rows = db.prepare(`SELECT ${agentColumn} AS agent_id, ${params.sourceIdColumn} AS source_id, ${params.contentColumn} AS content
14684
- FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
14685
- backfill(db, rows, params.sourceKind, params.scannedAt);
14686
- }
14687
14559
  function up130(db) {
14688
14560
  db.exec(`
14689
14561
  CREATE TABLE IF NOT EXISTS memory_content_safety (
@@ -14703,43 +14575,6 @@ function up130(db) {
14703
14575
  CREATE INDEX IF NOT EXISTS idx_memory_content_safety_eligibility
14704
14576
  ON memory_content_safety(agent_id, source_kind, context_eligible);
14705
14577
  `);
14706
- const scannedAt = new Date().toISOString();
14707
- backfillTable(db, {
14708
- table: "memories",
14709
- sourceKind: "memory",
14710
- sourceIdColumn: "id",
14711
- contentColumn: "content",
14712
- scannedAt
14713
- });
14714
- backfillTable(db, {
14715
- table: "memory_artifacts",
14716
- sourceKind: "artifact",
14717
- sourceIdColumn: "source_path",
14718
- contentColumn: "content",
14719
- scannedAt
14720
- });
14721
- backfillTable(db, {
14722
- table: "session_transcripts",
14723
- sourceKind: "transcript",
14724
- sourceIdColumn: "session_key",
14725
- contentColumn: "content",
14726
- scannedAt
14727
- });
14728
- backfillTable(db, {
14729
- table: "session_summaries",
14730
- sourceKind: "summary",
14731
- sourceIdColumn: "id",
14732
- contentColumn: "content",
14733
- scannedAt
14734
- });
14735
- backfillTable(db, {
14736
- table: "embeddings",
14737
- sourceKind: "source_chunk",
14738
- sourceIdColumn: "id",
14739
- contentColumn: "chunk_text",
14740
- where: "source_type IN ('source_chunk', 'source_obsidian_chunk')",
14741
- scannedAt
14742
- });
14743
14578
  }
14744
14579
  function up131(db) {
14745
14580
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
@@ -14843,13 +14678,13 @@ function up133(db) {
14843
14678
  AND error IS NOT NULL;
14844
14679
  `);
14845
14680
  }
14846
- function tableExists3(db, table) {
14681
+ function tableExists2(db, table) {
14847
14682
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
14848
14683
  }
14849
14684
  function up134(db) {
14850
- if (!tableExists3(db, "memory_jobs"))
14685
+ if (!tableExists2(db, "memory_jobs"))
14851
14686
  return;
14852
- if (!tableExists3(db, "job_cancellations")) {
14687
+ if (!tableExists2(db, "job_cancellations")) {
14853
14688
  throw new Error("job_cancellations table missing; cannot retire structural jobs without an audit trail");
14854
14689
  }
14855
14690
  db.prepare(`
@@ -15078,12 +14913,12 @@ function up142(db) {
15078
14913
  if (!cols.has(name))
15079
14914
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${name} ${type}`);
15080
14915
  }
15081
- function hasColumn25(db, table, column) {
14916
+ function hasColumn24(db, table, column) {
15082
14917
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
15083
14918
  return rows.some((row) => row.name === column);
15084
14919
  }
15085
14920
  function addColumnIfMissing28(db, table, column, definition) {
15086
- if (!hasColumn25(db, table, column))
14921
+ if (!hasColumn24(db, table, column))
15087
14922
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
15088
14923
  }
15089
14924
  function up143(db) {
@@ -15955,6 +15790,138 @@ function up162(db) {
15955
15790
  END;
15956
15791
  `);
15957
15792
  }
15793
+ function up163(db) {
15794
+ db.exec(`
15795
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_ai;
15796
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_au;
15797
+ DROP INDEX IF EXISTS idx_memory_content_safety_status;
15798
+ DROP INDEX IF EXISTS idx_memory_content_safety_eligibility;
15799
+ DROP TABLE IF EXISTS memory_content_safety;
15800
+ `);
15801
+ }
15802
+ var COLUMNS3 = ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"];
15803
+ function up164(db) {
15804
+ const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
15805
+ for (const column of COLUMNS3) {
15806
+ if (!cols.some((col) => col.name === column)) {
15807
+ db.exec(`ALTER TABLE entity_attributes ADD COLUMN ${column} TEXT`);
15808
+ }
15809
+ }
15810
+ }
15811
+ function up165(db) {
15812
+ const passColumns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15813
+ if (!passColumns.some((column) => column.name === "scope_key")) {
15814
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN scope_key TEXT");
15815
+ }
15816
+ db.exec(`
15817
+ CREATE TABLE IF NOT EXISTS dreaming_history_nodes (
15818
+ agent_id TEXT NOT NULL,
15819
+ scope_key TEXT NOT NULL,
15820
+ level INTEGER NOT NULL,
15821
+ idx INTEGER NOT NULL,
15822
+ pass_id TEXT,
15823
+ text TEXT NOT NULL,
15824
+ tokens_input INTEGER,
15825
+ tokens_output INTEGER,
15826
+ tokens_cache_read INTEGER,
15827
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
15828
+ PRIMARY KEY (agent_id, scope_key, level, idx)
15829
+ );
15830
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_dreaming_history_nodes_pass
15831
+ ON dreaming_history_nodes(pass_id) WHERE pass_id IS NOT NULL;
15832
+ `);
15833
+ }
15834
+ function up166(db) {
15835
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15836
+ if (!columns.some((column) => column.name === "tokens_peak_context")) {
15837
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN tokens_peak_context INTEGER");
15838
+ }
15839
+ }
15840
+ function up167(db) {
15841
+ const sql = readMemoriesFtsSql(db);
15842
+ if (sql !== null && !memoriesFtsNeedsTokenizerRepair(sql))
15843
+ return;
15844
+ recreateMemoriesFts(db);
15845
+ }
15846
+ function hasTable5(db, table) {
15847
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
15848
+ }
15849
+ function hasColumn25(db, table, column) {
15850
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
15851
+ }
15852
+ function up168(db) {
15853
+ if (!hasTable5(db, "entity_attributes") || !hasTable5(db, "entity_aspects") || !hasTable5(db, "entities") || !hasColumn25(db, "entity_attributes", "source_root") || !hasColumn25(db, "entities", "source_root")) {
15854
+ return;
15855
+ }
15856
+ const now = new Date().toISOString();
15857
+ db.exec(`
15858
+ CREATE TEMP TABLE retired_source_paragraphs AS
15859
+ SELECT attr.id, attr.memory_id, attr.agent_id, asp.entity_id
15860
+ FROM entity_attributes attr
15861
+ JOIN entity_aspects asp ON asp.id = attr.aspect_id
15862
+ JOIN entities e ON e.id = asp.entity_id
15863
+ WHERE e.entity_type IN ('source_document', 'source_document_reference')
15864
+ AND attr.source_root IS NOT NULL
15865
+ AND attr.source_root = e.source_root
15866
+ AND attr.source_id = e.source_id
15867
+ AND attr.source_root NOT IN ('dreaming', 'dreaming_attention')
15868
+ `);
15869
+ if (hasColumn25(db, "entity_attributes", "memory_id") && hasTable5(db, "memories")) {
15870
+ if (hasTable5(db, "memory_history")) {
15871
+ db.prepare(`INSERT INTO memory_history (id, memory_id, event, old_content, new_content, changed_by, reason, metadata, created_at)
15872
+ SELECT lower(hex(randomblob(16))), mem.id, 'deleted', mem.content, NULL, 'migration:168',
15873
+ 'Source paragraph claims retired', '{"force":true}', ?
15874
+ FROM memories mem
15875
+ JOIN retired_source_paragraphs retired ON retired.memory_id = mem.id
15876
+ WHERE mem.is_deleted = 0`).run(now);
15877
+ }
15878
+ if (hasTable5(db, "derived_memory_sources") && hasColumn25(db, "memories", "stale_at")) {
15879
+ db.prepare(`UPDATE memories
15880
+ SET stale_at = ?
15881
+ WHERE stale_at IS NULL
15882
+ AND is_deleted = 0
15883
+ AND id IN (
15884
+ SELECT dms.derived_memory_id
15885
+ FROM derived_memory_sources dms
15886
+ JOIN retired_source_paragraphs retired ON retired.agent_id = dms.agent_id
15887
+ WHERE (dms.source_kind = 'memory' AND dms.source_id = retired.memory_id)
15888
+ OR (dms.source_kind = 'ontology_claim' AND dms.source_id = retired.id)
15889
+ )`).run(now);
15890
+ }
15891
+ const forget = [
15892
+ "is_deleted = 1",
15893
+ ...["deleted_at", "updated_at"].filter((column) => hasColumn25(db, "memories", column)).map((column) => `${column} = $now`),
15894
+ ...hasColumn25(db, "memories", "updated_by") ? ["updated_by = 'migration:168'"] : [],
15895
+ ...hasColumn25(db, "memories", "version") ? ["version = version + 1"] : []
15896
+ ];
15897
+ db.prepare(`UPDATE memories
15898
+ SET ${forget.join(", ")}
15899
+ WHERE is_deleted = 0
15900
+ AND id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)`).run({ $now: now });
15901
+ if (hasTable5(db, "memory_entity_mentions")) {
15902
+ db.exec(`
15903
+ DELETE FROM memory_entity_mentions
15904
+ WHERE memory_id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)
15905
+ `);
15906
+ }
15907
+ }
15908
+ if (hasTable5(db, "ontology_contradictions")) {
15909
+ db.prepare(`UPDATE ontology_contradictions
15910
+ SET status = 'resolved', resolved_at = ?, resolution_reason = 'source paragraph claims retired', updated_at = ?
15911
+ WHERE status = 'active'
15912
+ AND (left_attribute_id IN (SELECT id FROM retired_source_paragraphs)
15913
+ OR right_attribute_id IN (SELECT id FROM retired_source_paragraphs))`).run(now, now);
15914
+ }
15915
+ db.exec(`
15916
+ DELETE FROM entity_attributes WHERE id IN (SELECT id FROM retired_source_paragraphs);
15917
+ DELETE FROM entity_aspects
15918
+ WHERE entity_id IN (
15919
+ SELECT id FROM entities WHERE entity_type IN ('source_document', 'source_document_reference')
15920
+ )
15921
+ AND NOT EXISTS (SELECT 1 FROM entity_attributes attr WHERE attr.aspect_id = entity_aspects.id);
15922
+ DROP TABLE retired_source_paragraphs;
15923
+ `);
15924
+ }
15958
15925
  var MIGRATIONS = [
15959
15926
  {
15960
15927
  version: 1,
@@ -16964,8 +16931,7 @@ var MIGRATIONS = [
16964
16931
  {
16965
16932
  version: 125,
16966
16933
  name: "memory-content-safety",
16967
- up: up130,
16968
- artifacts: { tables: ["memory_content_safety"] }
16934
+ up: up130
16969
16935
  },
16970
16936
  {
16971
16937
  version: 126,
@@ -17267,6 +17233,48 @@ var MIGRATIONS = [
17267
17233
  name: "generic-entity-prune-scan-generation",
17268
17234
  up: up162,
17269
17235
  artifacts: { tables: ["generic_entity_prune_scan_state"] }
17236
+ },
17237
+ {
17238
+ version: 163,
17239
+ name: "retire-memory-content-safety",
17240
+ up: up163
17241
+ },
17242
+ {
17243
+ version: 164,
17244
+ name: "claim-event-time",
17245
+ up: up164,
17246
+ artifacts: {
17247
+ columns: ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"].map((column) => ({
17248
+ table: "entity_attributes",
17249
+ column
17250
+ }))
17251
+ }
17252
+ },
17253
+ {
17254
+ version: 165,
17255
+ name: "dreaming-history",
17256
+ up: up165,
17257
+ artifacts: {
17258
+ tables: ["dreaming_history_nodes"],
17259
+ indexes: ["idx_dreaming_history_nodes_pass"],
17260
+ columns: [{ table: "dreaming_passes", column: "scope_key" }]
17261
+ }
17262
+ },
17263
+ {
17264
+ version: 166,
17265
+ name: "dreaming-pass-peak-context",
17266
+ up: up166,
17267
+ artifacts: { columns: [{ table: "dreaming_passes", column: "tokens_peak_context" }] }
17268
+ },
17269
+ {
17270
+ version: 167,
17271
+ name: "memories-fts-porter",
17272
+ up: up167
17273
+ },
17274
+ {
17275
+ version: 168,
17276
+ name: "retire-source-paragraph-claims",
17277
+ up: up168
17270
17278
  }
17271
17279
  ];
17272
17280
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -17508,6 +17516,37 @@ var PIPELINE_PROVIDER_CHOICES = [
17508
17516
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
17509
17517
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
17510
17518
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
17519
+ var SECRET_NAMES = "(?:access[_-]?token|api[_-]?key|apikey|auth[_-]?token|client[_-]?secret|passw(?:or)?d|refresh[_-]?token|private[_-]?key|secret(?:[_-]?key)?|token)";
17520
+ var SECRET_VALUE = `(?=[^\\s"',;&<>()\\[\\]{}$]*\\d)[^\\s"',;&<>()\\[\\]{}$]{8,}`;
17521
+ var PATTERNS = [
17522
+ {
17523
+ kind: "private_key",
17524
+ pattern: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )*PRIVATE KEY-----/g
17525
+ },
17526
+ {
17527
+ kind: "provider_key",
17528
+ pattern: /\b(?:(?:AKIA|ASIA)[0-9A-Z]{16}|github_pat_[A-Za-z0-9_]{20,}|gh[pousr]_[A-Za-z0-9]{20,}|sk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}|(?:sk|rk)_(?:live|test)_[0-9A-Za-z]{16,}|xox[abprs]-[A-Za-z0-9-]{10,}|AIza[0-9A-Za-z_-]{35}|glpat-[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{36})\b/g
17529
+ },
17530
+ {
17531
+ kind: "jwt",
17532
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
17533
+ },
17534
+ {
17535
+ kind: "bearer_token",
17536
+ pattern: /\bBearer\s+([A-Za-z0-9._~+/-]{16,}=*)/g,
17537
+ valueGroup: 1
17538
+ },
17539
+ {
17540
+ kind: "secret_assignment",
17541
+ pattern: new RegExp(`\\b${SECRET_NAMES}["']?\\s*[:=]\\s*["']?(${SECRET_VALUE})`, "gi"),
17542
+ valueGroup: 1
17543
+ },
17544
+ {
17545
+ kind: "secret_assignment",
17546
+ pattern: new RegExp(`\\b[A-Z][A-Z0-9_]*(?:API_KEY|TOKEN|SECRET|PASSWORD)\\s*=\\s*["']?(${SECRET_VALUE})`, "g"),
17547
+ valueGroup: 1
17548
+ }
17549
+ ];
17511
17550
  var LOOPBACK_HOST = "127.0.0.1";
17512
17551
  var LOCAL_BINDS = new Set([LOOPBACK_HOST, "localhost", "::1", "::ffff:127.0.0.1"]);
17513
17552
  function parseSimpleYaml(text) {
@@ -28613,99 +28652,6 @@ var execFileHiddenImpl2 = (...args) => Reflect.apply(nodeExecFile2, undefined, w
28613
28652
  Object.defineProperty(execFileHiddenImpl2, promisify2.custom, {
28614
28653
  value: (...args) => Reflect.apply(nodeExecFileAsync2, undefined, withWindowsHideArgument2(args, 1))
28615
28654
  });
28616
- var MEMORY_CONTENT_SAFETY_POLICY_VERSION2 = "memory-content-safety-v1";
28617
- var MEMORY_CONTENT_SAFETY_REASONS2 = [
28618
- "prompt_injection",
28619
- "exfiltration",
28620
- "credential_harvesting",
28621
- "malicious_shell",
28622
- "tool_directive",
28623
- "invisible_unicode"
28624
- ];
28625
- var INVISIBLE_UNICODE_RE2 = /(?:\u034f|[\u00ad\u061c\u070f\u180e\u200b\u200c\u200e\u200f\u202a-\u202e\u2060\u2066-\u2069\u206a-\u206f\ufeff]|[\u{e0000}-\u{e007f}])/u;
28626
- var STRONG_DEFENSIVE_CONTEXT_RE2 = /\b(?:security\s+(?:guidance|discussion|analysis)|threat\s+model|defensive)\b/i;
28627
- var REPORTING_CONTEXT_RE2 = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b/i;
28628
- var REPORTING_BEFORE_RE2 = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b[\s\S]{0,80}\b(?:say\w*|read\w*|show\w*|flag\w*|detect\w*|describ\w*|demonstrat\w*|contain\w*|match\w*|pattern)\b/i;
28629
- var REPORTING_AFTER_RE2 = /\b(?:detector|scanner|classif\w*|flag\w*|pattern|dangerous|unsafe|malicious|hostile|should|would|must|never|do not|don't|avoid|quoted)\b/i;
28630
- var NEGATED_DIRECTIVE_RE2 = /\b(?:never|do not|don't|should not|must not|cannot|can't|avoid|prevent|detect|mitigat\w*)\b[\s\S]{0,80}$/i;
28631
- var PROMPT_INJECTION_RES2 = [
28632
- /\b(?:ignore|disregard|override|forget|bypass)\b[\s\S]{0,100}\b(?:previous|prior|above|earlier|system|developer|assistant|safety|security)?\s*(?:instructions?|rules?|prompt|message)\b/i,
28633
- /\b(?:new|following|these)\s+(?:(?:system|developer|assistant|hidden)\s+)?instructions?\b/i,
28634
- /(?:^|\n)\s*(?:system|developer|instruction|prompt)\s*:/im,
28635
- /<\s*(?:system|developer|assistant|instruction|prompt)\b[^>]*>/i,
28636
- /\b(?:you are now|act as|roleplay as|pretend to be)\b[\s\S]{0,80}\b(?:system|admin|developer|unrestricted|jailbreak|different agent)\b/i
28637
- ];
28638
- var TOOL_DIRECTIVE_RES2 = [
28639
- /<\s*(?:tool[_-]?call|function[_-]?call|invoke|tool)\b/i,
28640
- /\b(?:assistant|system)\s+to\s*=\s*[a-z0-9_.-]+/i,
28641
- /\b(?:call|invoke|use|run|execute)\s+(?:the\s+)?[a-z0-9_.-]+\s+tool\b/i
28642
- ];
28643
- var EXFILTRATION_RE2 = /\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b[\s\S]{0,120}(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)/i;
28644
- var EXFILTRATION_REVERSE2 = /(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)[\s\S]{0,120}\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b/i;
28645
- var CREDENTIAL_HARVESTING_RE2 = /\b(?:enter|paste|provide|share|send|give|submit|type|hand over)\b[\s\S]{0,80}\b(?:password|api\s*key|token|secret|credential|private\s+key)\b/i;
28646
- var DANGEROUS_SHELL_RE2 = /\b(?:curl|wget)\b[^\n]{0,240}\|\s*(?:ba|z|fi)?sh\b|\brm\s+-rf\s+(?:\/|~|\.ssh)[^\n]{0,240}|\b(?:cat|head|tail)\s+~\/?\.ssh\/(?:id_[a-z]+|authorized_keys)\b|\b(?:printenv|env)\b[^\n]{0,120}\b(?:curl|wget|send|upload|post)\b/i;
28647
- function matchHasDefensiveContext2(content, match) {
28648
- if (!match || !match[0])
28649
- return false;
28650
- const start = match.index ?? 0;
28651
- const before = content.slice(Math.max(0, start - 120), start);
28652
- const after = content.slice(start + match[0].length, start + match[0].length + 160);
28653
- return STRONG_DEFENSIVE_CONTEXT_RE2.test(match[0]) || NEGATED_DIRECTIVE_RE2.test(before) || STRONG_DEFENSIVE_CONTEXT_RE2.test(before) || STRONG_DEFENSIVE_CONTEXT_RE2.test(after) || REPORTING_BEFORE_RE2.test(before) || REPORTING_CONTEXT_RE2.test(before) && REPORTING_AFTER_RE2.test(after);
28654
- }
28655
- function hasActionableMatch2(content, patterns) {
28656
- return patterns.some((pattern) => {
28657
- const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
28658
- const searchable = new RegExp(pattern.source, flags);
28659
- let match;
28660
- while ((match = searchable.exec(content)) !== null) {
28661
- if (!matchHasDefensiveContext2(content, match))
28662
- return true;
28663
- if (match[0].length === 0)
28664
- searchable.lastIndex += 1;
28665
- }
28666
- return false;
28667
- });
28668
- }
28669
- function hasDangerousShell2(content) {
28670
- const searchable = new RegExp(DANGEROUS_SHELL_RE2.source, `${DANGEROUS_SHELL_RE2.flags}g`);
28671
- let match;
28672
- while ((match = searchable.exec(content)) !== null) {
28673
- if (matchHasDefensiveContext2(content, match))
28674
- continue;
28675
- const end = (match.index ?? 0) + match[0].length;
28676
- const after = content.slice(end, end + 160);
28677
- if (!STRONG_DEFENSIVE_CONTEXT_RE2.test(after) && !REPORTING_AFTER_RE2.test(after))
28678
- return true;
28679
- if (match[0].length === 0)
28680
- searchable.lastIndex += 1;
28681
- }
28682
- return false;
28683
- }
28684
- function scanMemoryContent2(content) {
28685
- const raw = typeof content === "string" ? content : String(content ?? "");
28686
- const normalized = raw.normalize("NFKC");
28687
- const reasons = new Set;
28688
- if (INVISIBLE_UNICODE_RE2.test(raw))
28689
- reasons.add("invisible_unicode");
28690
- if (hasActionableMatch2(normalized, PROMPT_INJECTION_RES2))
28691
- reasons.add("prompt_injection");
28692
- if (hasActionableMatch2(normalized, TOOL_DIRECTIVE_RES2))
28693
- reasons.add("tool_directive");
28694
- if (hasActionableMatch2(normalized, [EXFILTRATION_RE2, EXFILTRATION_REVERSE2]))
28695
- reasons.add("exfiltration");
28696
- if (hasActionableMatch2(normalized, [CREDENTIAL_HARVESTING_RE2]))
28697
- reasons.add("credential_harvesting");
28698
- if (hasDangerousShell2(normalized))
28699
- reasons.add("malicious_shell");
28700
- const orderedReasons = MEMORY_CONTENT_SAFETY_REASONS2.filter((reason) => reasons.has(reason));
28701
- const status = orderedReasons.length === 0 ? "clean" : orderedReasons.every((reason) => reason === "invisible_unicode") ? "tainted" : "blocked";
28702
- return {
28703
- status,
28704
- contextEligible: status === "clean",
28705
- reasons: orderedReasons,
28706
- policyVersion: MEMORY_CONTENT_SAFETY_POLICY_VERSION2
28707
- };
28708
- }
28709
28655
  var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = [
28710
28656
  "extract",
28711
28657
  "aggregate-recall",
@@ -28713,7 +28659,7 @@ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = [
28713
28659
  "checkpoint",
28714
28660
  "dreaming"
28715
28661
  ];
28716
- function up163(db) {
28662
+ function up169(db) {
28717
28663
  const hasColumn = (table, column) => {
28718
28664
  const statement = db.prepare(`SELECT 1 FROM pragma_table_info('${table}') WHERE name = ?`);
28719
28665
  try {
@@ -28828,7 +28774,7 @@ function up410(db) {
28828
28774
  function up510(db) {
28829
28775
  db.exec("DROP TABLE IF EXISTS mcp_invocations");
28830
28776
  }
28831
- var MEMORIES_FTS_TOKENIZER2 = "unicode61";
28777
+ var MEMORIES_FTS_TOKENIZER2 = "porter unicode61";
28832
28778
  var FTS_STATE_TABLE2 = "memories_fts_state";
28833
28779
  function normalizeSql2(sql) {
28834
28780
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -28938,10 +28884,7 @@ function readMemoriesFtsSql2(db) {
28938
28884
  function memoriesFtsNeedsTokenizerRepair2(sql) {
28939
28885
  if (sql === null)
28940
28886
  return false;
28941
- const normalized = normalizeSql2(sql);
28942
- if (normalized.includes("porter unicode61"))
28943
- return true;
28944
- return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
28887
+ return !normalizeSql2(sql).includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
28945
28888
  }
28946
28889
  function up610(db) {
28947
28890
  db.exec(`
@@ -29366,7 +29309,7 @@ function up1510(db) {
29366
29309
  )
29367
29310
  `);
29368
29311
  }
29369
- function up164(db) {
29312
+ function up1610(db) {
29370
29313
  db.exec(`
29371
29314
  CREATE TABLE IF NOT EXISTS session_scores (
29372
29315
  id TEXT PRIMARY KEY,
@@ -30587,7 +30530,7 @@ function up542(db) {
30587
30530
  );
30588
30531
  `);
30589
30532
  }
30590
- function hasTable5(db, name) {
30533
+ function hasTable6(db, name) {
30591
30534
  return db.prepare(`SELECT name
30592
30535
  FROM sqlite_master
30593
30536
  WHERE type = 'table' AND name = ?
@@ -30617,7 +30560,7 @@ function up552(db) {
30617
30560
  CREATE INDEX IF NOT EXISTS idx_entity_dependency_history_created
30618
30561
  ON entity_dependency_history(created_at DESC);
30619
30562
  `);
30620
- if (!hasTable5(db, "entity_dependencies"))
30563
+ if (!hasTable6(db, "entity_dependencies"))
30621
30564
  return;
30622
30565
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_insert");
30623
30566
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_update");
@@ -31596,9 +31539,9 @@ function hasColumn112(db, table, column) {
31596
31539
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
31597
31540
  return rows.some((row) => row.name === column);
31598
31541
  }
31599
- var COLUMNS3 = ["harness", "session_id", "tool_use_id", "cwd", "origin", "args"];
31542
+ var COLUMNS4 = ["harness", "session_id", "tool_use_id", "cwd", "origin", "args"];
31600
31543
  function up872(db) {
31601
- for (const column of COLUMNS3) {
31544
+ for (const column of COLUMNS4) {
31602
31545
  if (!hasColumn112(db, "skill_invocations", column)) {
31603
31546
  db.exec(`ALTER TABLE skill_invocations ADD COLUMN ${column} TEXT`);
31604
31547
  }
@@ -32162,7 +32105,7 @@ function up1082(db) {
32162
32105
  )
32163
32106
  `);
32164
32107
  }
32165
- function tableExists4(db, table) {
32108
+ function tableExists3(db, table) {
32166
32109
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
32167
32110
  }
32168
32111
  function hasColumn162(db, table, column) {
@@ -32184,7 +32127,7 @@ function up1092(db) {
32184
32127
  CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
32185
32128
  ON derived_memory_sources(agent_id, source_kind, source_id);
32186
32129
  `);
32187
- if (tableExists4(db, "aggregate_evidence_sources")) {
32130
+ if (tableExists3(db, "aggregate_evidence_sources")) {
32188
32131
  db.exec(`
32189
32132
  INSERT OR IGNORE INTO derived_memory_sources
32190
32133
  (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
@@ -32192,7 +32135,7 @@ function up1092(db) {
32192
32135
  FROM aggregate_evidence_sources
32193
32136
  `);
32194
32137
  }
32195
- if (tableExists4(db, "aggregate_memory_sources")) {
32138
+ if (tableExists3(db, "aggregate_memory_sources")) {
32196
32139
  db.exec(`
32197
32140
  INSERT OR IGNORE INTO derived_memory_sources
32198
32141
  (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
@@ -32200,10 +32143,10 @@ function up1092(db) {
32200
32143
  FROM aggregate_memory_sources
32201
32144
  `);
32202
32145
  }
32203
- if (tableExists4(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
32146
+ if (tableExists3(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
32204
32147
  db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
32205
32148
  }
32206
- if (tableExists4(db, "memories")) {
32149
+ if (tableExists3(db, "memories")) {
32207
32150
  db.exec(`
32208
32151
  CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
32209
32152
  ON memories(agent_id, stale_at)
@@ -32854,38 +32797,6 @@ function up1292(db) {
32854
32797
  ON imported_source_lifecycle(agent_id, status, updated_at DESC);
32855
32798
  `);
32856
32799
  }
32857
- function tableExists22(db, table) {
32858
- return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
32859
- }
32860
- function hasColumn242(db, table, column) {
32861
- return db.prepare(`PRAGMA table_info("${table}")`).all().some((row) => row.name === column);
32862
- }
32863
- function backfill2(db, rows, sourceKind, scannedAt) {
32864
- const statement = db.prepare(`INSERT INTO memory_content_safety
32865
- (agent_id, source_kind, source_id, status, context_eligible, reasons_json, policy_version, scanned_at)
32866
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
32867
- ON CONFLICT(agent_id, source_kind, source_id) DO UPDATE SET
32868
- status = excluded.status,
32869
- context_eligible = excluded.context_eligible,
32870
- reasons_json = excluded.reasons_json,
32871
- policy_version = excluded.policy_version,
32872
- scanned_at = excluded.scanned_at`);
32873
- for (const row of rows) {
32874
- const sourceId = row.source_id?.trim();
32875
- if (!sourceId)
32876
- continue;
32877
- const assessment = scanMemoryContent2(row.content ?? "");
32878
- statement.run(row.agent_id?.trim() || "default", sourceKind, sourceId, assessment.status, assessment.contextEligible ? 1 : 0, JSON.stringify(assessment.reasons), MEMORY_CONTENT_SAFETY_POLICY_VERSION2, scannedAt);
32879
- }
32880
- }
32881
- function backfillTable2(db, params) {
32882
- if (!tableExists22(db, params.table) || !hasColumn242(db, params.table, params.sourceIdColumn) || !hasColumn242(db, params.table, params.contentColumn))
32883
- return;
32884
- const agentColumn = hasColumn242(db, params.table, "agent_id") ? "COALESCE(NULLIF(TRIM(agent_id), ''), 'default')" : "'default'";
32885
- const rows = db.prepare(`SELECT ${agentColumn} AS agent_id, ${params.sourceIdColumn} AS source_id, ${params.contentColumn} AS content
32886
- FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
32887
- backfill2(db, rows, params.sourceKind, params.scannedAt);
32888
- }
32889
32800
  function up1302(db) {
32890
32801
  db.exec(`
32891
32802
  CREATE TABLE IF NOT EXISTS memory_content_safety (
@@ -32905,43 +32816,6 @@ function up1302(db) {
32905
32816
  CREATE INDEX IF NOT EXISTS idx_memory_content_safety_eligibility
32906
32817
  ON memory_content_safety(agent_id, source_kind, context_eligible);
32907
32818
  `);
32908
- const scannedAt = new Date().toISOString();
32909
- backfillTable2(db, {
32910
- table: "memories",
32911
- sourceKind: "memory",
32912
- sourceIdColumn: "id",
32913
- contentColumn: "content",
32914
- scannedAt
32915
- });
32916
- backfillTable2(db, {
32917
- table: "memory_artifacts",
32918
- sourceKind: "artifact",
32919
- sourceIdColumn: "source_path",
32920
- contentColumn: "content",
32921
- scannedAt
32922
- });
32923
- backfillTable2(db, {
32924
- table: "session_transcripts",
32925
- sourceKind: "transcript",
32926
- sourceIdColumn: "session_key",
32927
- contentColumn: "content",
32928
- scannedAt
32929
- });
32930
- backfillTable2(db, {
32931
- table: "session_summaries",
32932
- sourceKind: "summary",
32933
- sourceIdColumn: "id",
32934
- contentColumn: "content",
32935
- scannedAt
32936
- });
32937
- backfillTable2(db, {
32938
- table: "embeddings",
32939
- sourceKind: "source_chunk",
32940
- sourceIdColumn: "id",
32941
- contentColumn: "chunk_text",
32942
- where: "source_type IN ('source_chunk', 'source_obsidian_chunk')",
32943
- scannedAt
32944
- });
32945
32819
  }
32946
32820
  function up1312(db) {
32947
32821
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
@@ -33045,13 +32919,13 @@ function up1332(db) {
33045
32919
  AND error IS NOT NULL;
33046
32920
  `);
33047
32921
  }
33048
- function tableExists32(db, table) {
32922
+ function tableExists22(db, table) {
33049
32923
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
33050
32924
  }
33051
32925
  function up1342(db) {
33052
- if (!tableExists32(db, "memory_jobs"))
32926
+ if (!tableExists22(db, "memory_jobs"))
33053
32927
  return;
33054
- if (!tableExists32(db, "job_cancellations")) {
32928
+ if (!tableExists22(db, "job_cancellations")) {
33055
32929
  throw new Error("job_cancellations table missing; cannot retire structural jobs without an audit trail");
33056
32930
  }
33057
32931
  db.prepare(`
@@ -33280,12 +33154,12 @@ function up1422(db) {
33280
33154
  if (!cols.has(name))
33281
33155
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${name} ${type}`);
33282
33156
  }
33283
- function hasColumn252(db, table, column) {
33157
+ function hasColumn242(db, table, column) {
33284
33158
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
33285
33159
  return rows.some((row) => row.name === column);
33286
33160
  }
33287
33161
  function addColumnIfMissing282(db, table, column, definition) {
33288
- if (!hasColumn252(db, table, column))
33162
+ if (!hasColumn242(db, table, column))
33289
33163
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
33290
33164
  }
33291
33165
  function up1432(db) {
@@ -34157,6 +34031,138 @@ function up1622(db) {
34157
34031
  END;
34158
34032
  `);
34159
34033
  }
34034
+ function up1632(db) {
34035
+ db.exec(`
34036
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_ai;
34037
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_au;
34038
+ DROP INDEX IF EXISTS idx_memory_content_safety_status;
34039
+ DROP INDEX IF EXISTS idx_memory_content_safety_eligibility;
34040
+ DROP TABLE IF EXISTS memory_content_safety;
34041
+ `);
34042
+ }
34043
+ var COLUMNS32 = ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"];
34044
+ function up1642(db) {
34045
+ const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
34046
+ for (const column of COLUMNS32) {
34047
+ if (!cols.some((col) => col.name === column)) {
34048
+ db.exec(`ALTER TABLE entity_attributes ADD COLUMN ${column} TEXT`);
34049
+ }
34050
+ }
34051
+ }
34052
+ function up1652(db) {
34053
+ const passColumns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
34054
+ if (!passColumns.some((column) => column.name === "scope_key")) {
34055
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN scope_key TEXT");
34056
+ }
34057
+ db.exec(`
34058
+ CREATE TABLE IF NOT EXISTS dreaming_history_nodes (
34059
+ agent_id TEXT NOT NULL,
34060
+ scope_key TEXT NOT NULL,
34061
+ level INTEGER NOT NULL,
34062
+ idx INTEGER NOT NULL,
34063
+ pass_id TEXT,
34064
+ text TEXT NOT NULL,
34065
+ tokens_input INTEGER,
34066
+ tokens_output INTEGER,
34067
+ tokens_cache_read INTEGER,
34068
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
34069
+ PRIMARY KEY (agent_id, scope_key, level, idx)
34070
+ );
34071
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_dreaming_history_nodes_pass
34072
+ ON dreaming_history_nodes(pass_id) WHERE pass_id IS NOT NULL;
34073
+ `);
34074
+ }
34075
+ function up1662(db) {
34076
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
34077
+ if (!columns.some((column) => column.name === "tokens_peak_context")) {
34078
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN tokens_peak_context INTEGER");
34079
+ }
34080
+ }
34081
+ function up1672(db) {
34082
+ const sql = readMemoriesFtsSql2(db);
34083
+ if (sql !== null && !memoriesFtsNeedsTokenizerRepair2(sql))
34084
+ return;
34085
+ recreateMemoriesFts2(db);
34086
+ }
34087
+ function hasTable52(db, table) {
34088
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
34089
+ }
34090
+ function hasColumn252(db, table, column) {
34091
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
34092
+ }
34093
+ function up1682(db) {
34094
+ if (!hasTable52(db, "entity_attributes") || !hasTable52(db, "entity_aspects") || !hasTable52(db, "entities") || !hasColumn252(db, "entity_attributes", "source_root") || !hasColumn252(db, "entities", "source_root")) {
34095
+ return;
34096
+ }
34097
+ const now = new Date().toISOString();
34098
+ db.exec(`
34099
+ CREATE TEMP TABLE retired_source_paragraphs AS
34100
+ SELECT attr.id, attr.memory_id, attr.agent_id, asp.entity_id
34101
+ FROM entity_attributes attr
34102
+ JOIN entity_aspects asp ON asp.id = attr.aspect_id
34103
+ JOIN entities e ON e.id = asp.entity_id
34104
+ WHERE e.entity_type IN ('source_document', 'source_document_reference')
34105
+ AND attr.source_root IS NOT NULL
34106
+ AND attr.source_root = e.source_root
34107
+ AND attr.source_id = e.source_id
34108
+ AND attr.source_root NOT IN ('dreaming', 'dreaming_attention')
34109
+ `);
34110
+ if (hasColumn252(db, "entity_attributes", "memory_id") && hasTable52(db, "memories")) {
34111
+ if (hasTable52(db, "memory_history")) {
34112
+ db.prepare(`INSERT INTO memory_history (id, memory_id, event, old_content, new_content, changed_by, reason, metadata, created_at)
34113
+ SELECT lower(hex(randomblob(16))), mem.id, 'deleted', mem.content, NULL, 'migration:168',
34114
+ 'Source paragraph claims retired', '{"force":true}', ?
34115
+ FROM memories mem
34116
+ JOIN retired_source_paragraphs retired ON retired.memory_id = mem.id
34117
+ WHERE mem.is_deleted = 0`).run(now);
34118
+ }
34119
+ if (hasTable52(db, "derived_memory_sources") && hasColumn252(db, "memories", "stale_at")) {
34120
+ db.prepare(`UPDATE memories
34121
+ SET stale_at = ?
34122
+ WHERE stale_at IS NULL
34123
+ AND is_deleted = 0
34124
+ AND id IN (
34125
+ SELECT dms.derived_memory_id
34126
+ FROM derived_memory_sources dms
34127
+ JOIN retired_source_paragraphs retired ON retired.agent_id = dms.agent_id
34128
+ WHERE (dms.source_kind = 'memory' AND dms.source_id = retired.memory_id)
34129
+ OR (dms.source_kind = 'ontology_claim' AND dms.source_id = retired.id)
34130
+ )`).run(now);
34131
+ }
34132
+ const forget = [
34133
+ "is_deleted = 1",
34134
+ ...["deleted_at", "updated_at"].filter((column) => hasColumn252(db, "memories", column)).map((column) => `${column} = $now`),
34135
+ ...hasColumn252(db, "memories", "updated_by") ? ["updated_by = 'migration:168'"] : [],
34136
+ ...hasColumn252(db, "memories", "version") ? ["version = version + 1"] : []
34137
+ ];
34138
+ db.prepare(`UPDATE memories
34139
+ SET ${forget.join(", ")}
34140
+ WHERE is_deleted = 0
34141
+ AND id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)`).run({ $now: now });
34142
+ if (hasTable52(db, "memory_entity_mentions")) {
34143
+ db.exec(`
34144
+ DELETE FROM memory_entity_mentions
34145
+ WHERE memory_id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)
34146
+ `);
34147
+ }
34148
+ }
34149
+ if (hasTable52(db, "ontology_contradictions")) {
34150
+ db.prepare(`UPDATE ontology_contradictions
34151
+ SET status = 'resolved', resolved_at = ?, resolution_reason = 'source paragraph claims retired', updated_at = ?
34152
+ WHERE status = 'active'
34153
+ AND (left_attribute_id IN (SELECT id FROM retired_source_paragraphs)
34154
+ OR right_attribute_id IN (SELECT id FROM retired_source_paragraphs))`).run(now, now);
34155
+ }
34156
+ db.exec(`
34157
+ DELETE FROM entity_attributes WHERE id IN (SELECT id FROM retired_source_paragraphs);
34158
+ DELETE FROM entity_aspects
34159
+ WHERE entity_id IN (
34160
+ SELECT id FROM entities WHERE entity_type IN ('source_document', 'source_document_reference')
34161
+ )
34162
+ AND NOT EXISTS (SELECT 1 FROM entity_attributes attr WHERE attr.aspect_id = entity_aspects.id);
34163
+ DROP TABLE retired_source_paragraphs;
34164
+ `);
34165
+ }
34160
34166
  var MIGRATIONS2 = [
34161
34167
  {
34162
34168
  version: 1,
@@ -34227,7 +34233,7 @@ var MIGRATIONS2 = [
34227
34233
  {
34228
34234
  version: 11,
34229
34235
  name: "session-scores",
34230
- up: up164,
34236
+ up: up1610,
34231
34237
  artifacts: { tables: ["session_scores"] }
34232
34238
  },
34233
34239
  {
@@ -35166,8 +35172,7 @@ var MIGRATIONS2 = [
35166
35172
  {
35167
35173
  version: 125,
35168
35174
  name: "memory-content-safety",
35169
- up: up1302,
35170
- artifacts: { tables: ["memory_content_safety"] }
35175
+ up: up1302
35171
35176
  },
35172
35177
  {
35173
35178
  version: 126,
@@ -35361,7 +35366,7 @@ var MIGRATIONS2 = [
35361
35366
  {
35362
35367
  version: 151,
35363
35368
  name: "transcript-import-bytes",
35364
- up: up163,
35369
+ up: up169,
35365
35370
  artifacts: {
35366
35371
  tables: [
35367
35372
  "source_import_chunks",
@@ -35469,6 +35474,48 @@ var MIGRATIONS2 = [
35469
35474
  name: "generic-entity-prune-scan-generation",
35470
35475
  up: up1622,
35471
35476
  artifacts: { tables: ["generic_entity_prune_scan_state"] }
35477
+ },
35478
+ {
35479
+ version: 163,
35480
+ name: "retire-memory-content-safety",
35481
+ up: up1632
35482
+ },
35483
+ {
35484
+ version: 164,
35485
+ name: "claim-event-time",
35486
+ up: up1642,
35487
+ artifacts: {
35488
+ columns: ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"].map((column) => ({
35489
+ table: "entity_attributes",
35490
+ column
35491
+ }))
35492
+ }
35493
+ },
35494
+ {
35495
+ version: 165,
35496
+ name: "dreaming-history",
35497
+ up: up1652,
35498
+ artifacts: {
35499
+ tables: ["dreaming_history_nodes"],
35500
+ indexes: ["idx_dreaming_history_nodes_pass"],
35501
+ columns: [{ table: "dreaming_passes", column: "scope_key" }]
35502
+ }
35503
+ },
35504
+ {
35505
+ version: 166,
35506
+ name: "dreaming-pass-peak-context",
35507
+ up: up1662,
35508
+ artifacts: { columns: [{ table: "dreaming_passes", column: "tokens_peak_context" }] }
35509
+ },
35510
+ {
35511
+ version: 167,
35512
+ name: "memories-fts-porter",
35513
+ up: up1672
35514
+ },
35515
+ {
35516
+ version: 168,
35517
+ name: "retire-source-paragraph-claims",
35518
+ up: up1682
35472
35519
  }
35473
35520
  ];
35474
35521
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -35703,6 +35750,37 @@ var PIPELINE_PROVIDER_CHOICES2 = [
35703
35750
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
35704
35751
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
35705
35752
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
35753
+ var SECRET_NAMES2 = "(?:access[_-]?token|api[_-]?key|apikey|auth[_-]?token|client[_-]?secret|passw(?:or)?d|refresh[_-]?token|private[_-]?key|secret(?:[_-]?key)?|token)";
35754
+ var SECRET_VALUE2 = `(?=[^\\s"',;&<>()\\[\\]{}$]*\\d)[^\\s"',;&<>()\\[\\]{}$]{8,}`;
35755
+ var PATTERNS2 = [
35756
+ {
35757
+ kind: "private_key",
35758
+ pattern: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )*PRIVATE KEY-----/g
35759
+ },
35760
+ {
35761
+ kind: "provider_key",
35762
+ pattern: /\b(?:(?:AKIA|ASIA)[0-9A-Z]{16}|github_pat_[A-Za-z0-9_]{20,}|gh[pousr]_[A-Za-z0-9]{20,}|sk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}|(?:sk|rk)_(?:live|test)_[0-9A-Za-z]{16,}|xox[abprs]-[A-Za-z0-9-]{10,}|AIza[0-9A-Za-z_-]{35}|glpat-[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{36})\b/g
35763
+ },
35764
+ {
35765
+ kind: "jwt",
35766
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
35767
+ },
35768
+ {
35769
+ kind: "bearer_token",
35770
+ pattern: /\bBearer\s+([A-Za-z0-9._~+/-]{16,}=*)/g,
35771
+ valueGroup: 1
35772
+ },
35773
+ {
35774
+ kind: "secret_assignment",
35775
+ pattern: new RegExp(`\\b${SECRET_NAMES2}["']?\\s*[:=]\\s*["']?(${SECRET_VALUE2})`, "gi"),
35776
+ valueGroup: 1
35777
+ },
35778
+ {
35779
+ kind: "secret_assignment",
35780
+ pattern: new RegExp(`\\b[A-Z][A-Z0-9_]*(?:API_KEY|TOKEN|SECRET|PASSWORD)\\s*=\\s*["']?(${SECRET_VALUE2})`, "g"),
35781
+ valueGroup: 1
35782
+ }
35783
+ ];
35706
35784
  var LOOPBACK_HOST2 = "127.0.0.1";
35707
35785
  function normalizeLoopbackHost(host) {
35708
35786
  const normalized = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/signet-memory-openclaw",
3
- "version": "0.236.1",
3
+ "version": "0.237.1",
4
4
  "description": "Signet adapter for OpenClaw — runtime plugin for AI agent memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",