@signetai/connector-kimi 0.236.0 → 0.237.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +439 -361
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -10381,99 +10381,6 @@ var execFileHiddenImpl = (...args) => Reflect.apply(nodeExecFile, undefined, wit
10381
10381
  Object.defineProperty(execFileHiddenImpl, promisify.custom, {
10382
10382
  value: (...args) => Reflect.apply(nodeExecFileAsync, undefined, withWindowsHideArgument(args, 1))
10383
10383
  });
10384
- var MEMORY_CONTENT_SAFETY_POLICY_VERSION = "memory-content-safety-v1";
10385
- var MEMORY_CONTENT_SAFETY_REASONS = [
10386
- "prompt_injection",
10387
- "exfiltration",
10388
- "credential_harvesting",
10389
- "malicious_shell",
10390
- "tool_directive",
10391
- "invisible_unicode"
10392
- ];
10393
- 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;
10394
- var STRONG_DEFENSIVE_CONTEXT_RE = /\b(?:security\s+(?:guidance|discussion|analysis)|threat\s+model|defensive)\b/i;
10395
- var REPORTING_CONTEXT_RE = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b/i;
10396
- 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;
10397
- 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;
10398
- 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;
10399
- var PROMPT_INJECTION_RES = [
10400
- /\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,
10401
- /\b(?:new|following|these)\s+(?:(?:system|developer|assistant|hidden)\s+)?instructions?\b/i,
10402
- /(?:^|\n)\s*(?:system|developer|instruction|prompt)\s*:/im,
10403
- /<\s*(?:system|developer|assistant|instruction|prompt)\b[^>]*>/i,
10404
- /\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
10405
- ];
10406
- var TOOL_DIRECTIVE_RES = [
10407
- /<\s*(?:tool[_-]?call|function[_-]?call|invoke|tool)\b/i,
10408
- /\b(?:assistant|system)\s+to\s*=\s*[a-z0-9_.-]+/i,
10409
- /\b(?:call|invoke|use|run|execute)\s+(?:the\s+)?[a-z0-9_.-]+\s+tool\b/i
10410
- ];
10411
- 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;
10412
- 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;
10413
- 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;
10414
- 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;
10415
- function matchHasDefensiveContext(content, match) {
10416
- if (!match || !match[0])
10417
- return false;
10418
- const start = match.index ?? 0;
10419
- const before = content.slice(Math.max(0, start - 120), start);
10420
- const after = content.slice(start + match[0].length, start + match[0].length + 160);
10421
- 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);
10422
- }
10423
- function hasActionableMatch(content, patterns) {
10424
- return patterns.some((pattern) => {
10425
- const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
10426
- const searchable = new RegExp(pattern.source, flags);
10427
- let match;
10428
- while ((match = searchable.exec(content)) !== null) {
10429
- if (!matchHasDefensiveContext(content, match))
10430
- return true;
10431
- if (match[0].length === 0)
10432
- searchable.lastIndex += 1;
10433
- }
10434
- return false;
10435
- });
10436
- }
10437
- function hasDangerousShell(content) {
10438
- const searchable = new RegExp(DANGEROUS_SHELL_RE.source, `${DANGEROUS_SHELL_RE.flags}g`);
10439
- let match;
10440
- while ((match = searchable.exec(content)) !== null) {
10441
- if (matchHasDefensiveContext(content, match))
10442
- continue;
10443
- const end = (match.index ?? 0) + match[0].length;
10444
- const after = content.slice(end, end + 160);
10445
- if (!STRONG_DEFENSIVE_CONTEXT_RE.test(after) && !REPORTING_AFTER_RE.test(after))
10446
- return true;
10447
- if (match[0].length === 0)
10448
- searchable.lastIndex += 1;
10449
- }
10450
- return false;
10451
- }
10452
- function scanMemoryContent(content) {
10453
- const raw = typeof content === "string" ? content : String(content ?? "");
10454
- const normalized = raw.normalize("NFKC");
10455
- const reasons = new Set;
10456
- if (INVISIBLE_UNICODE_RE.test(raw))
10457
- reasons.add("invisible_unicode");
10458
- if (hasActionableMatch(normalized, PROMPT_INJECTION_RES))
10459
- reasons.add("prompt_injection");
10460
- if (hasActionableMatch(normalized, TOOL_DIRECTIVE_RES))
10461
- reasons.add("tool_directive");
10462
- if (hasActionableMatch(normalized, [EXFILTRATION_RE, EXFILTRATION_REVERSE]))
10463
- reasons.add("exfiltration");
10464
- if (hasActionableMatch(normalized, [CREDENTIAL_HARVESTING_RE]))
10465
- reasons.add("credential_harvesting");
10466
- if (hasDangerousShell(normalized))
10467
- reasons.add("malicious_shell");
10468
- const orderedReasons = MEMORY_CONTENT_SAFETY_REASONS.filter((reason) => reasons.has(reason));
10469
- const status = orderedReasons.length === 0 ? "clean" : orderedReasons.every((reason) => reason === "invisible_unicode") ? "tainted" : "blocked";
10470
- return {
10471
- status,
10472
- contextEligible: status === "clean",
10473
- reasons: orderedReasons,
10474
- policyVersion: MEMORY_CONTENT_SAFETY_POLICY_VERSION
10475
- };
10476
- }
10477
10384
  var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = [
10478
10385
  "extract",
10479
10386
  "aggregate-recall",
@@ -10596,7 +10503,7 @@ function up4(db) {
10596
10503
  function up5(db) {
10597
10504
  db.exec("DROP TABLE IF EXISTS mcp_invocations");
10598
10505
  }
10599
- var MEMORIES_FTS_TOKENIZER = "unicode61";
10506
+ var MEMORIES_FTS_TOKENIZER = "porter unicode61";
10600
10507
  var FTS_STATE_TABLE = "memories_fts_state";
10601
10508
  function normalizeSql(sql) {
10602
10509
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -10706,10 +10613,7 @@ function readMemoriesFtsSql(db) {
10706
10613
  function memoriesFtsNeedsTokenizerRepair(sql) {
10707
10614
  if (sql === null)
10708
10615
  return false;
10709
- const normalized = normalizeSql(sql);
10710
- if (normalized.includes("porter unicode61"))
10711
- return true;
10712
- return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
10616
+ return !normalizeSql(sql).includes(`tokenize='${MEMORIES_FTS_TOKENIZER}'`);
10713
10617
  }
10714
10618
  function up6(db) {
10715
10619
  db.exec(`
@@ -14622,38 +14526,6 @@ function up129(db) {
14622
14526
  ON imported_source_lifecycle(agent_id, status, updated_at DESC);
14623
14527
  `);
14624
14528
  }
14625
- function tableExists2(db, table) {
14626
- return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
14627
- }
14628
- function hasColumn24(db, table, column) {
14629
- return db.prepare(`PRAGMA table_info("${table}")`).all().some((row) => row.name === column);
14630
- }
14631
- function backfill(db, rows, sourceKind, scannedAt) {
14632
- const statement = db.prepare(`INSERT INTO memory_content_safety
14633
- (agent_id, source_kind, source_id, status, context_eligible, reasons_json, policy_version, scanned_at)
14634
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
14635
- ON CONFLICT(agent_id, source_kind, source_id) DO UPDATE SET
14636
- status = excluded.status,
14637
- context_eligible = excluded.context_eligible,
14638
- reasons_json = excluded.reasons_json,
14639
- policy_version = excluded.policy_version,
14640
- scanned_at = excluded.scanned_at`);
14641
- for (const row of rows) {
14642
- const sourceId = row.source_id?.trim();
14643
- if (!sourceId)
14644
- continue;
14645
- const assessment = scanMemoryContent(row.content ?? "");
14646
- 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);
14647
- }
14648
- }
14649
- function backfillTable(db, params) {
14650
- if (!tableExists2(db, params.table) || !hasColumn24(db, params.table, params.sourceIdColumn) || !hasColumn24(db, params.table, params.contentColumn))
14651
- return;
14652
- const agentColumn = hasColumn24(db, params.table, "agent_id") ? "COALESCE(NULLIF(TRIM(agent_id), ''), 'default')" : "'default'";
14653
- const rows = db.prepare(`SELECT ${agentColumn} AS agent_id, ${params.sourceIdColumn} AS source_id, ${params.contentColumn} AS content
14654
- FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
14655
- backfill(db, rows, params.sourceKind, params.scannedAt);
14656
- }
14657
14529
  function up130(db) {
14658
14530
  db.exec(`
14659
14531
  CREATE TABLE IF NOT EXISTS memory_content_safety (
@@ -14673,43 +14545,6 @@ function up130(db) {
14673
14545
  CREATE INDEX IF NOT EXISTS idx_memory_content_safety_eligibility
14674
14546
  ON memory_content_safety(agent_id, source_kind, context_eligible);
14675
14547
  `);
14676
- const scannedAt = new Date().toISOString();
14677
- backfillTable(db, {
14678
- table: "memories",
14679
- sourceKind: "memory",
14680
- sourceIdColumn: "id",
14681
- contentColumn: "content",
14682
- scannedAt
14683
- });
14684
- backfillTable(db, {
14685
- table: "memory_artifacts",
14686
- sourceKind: "artifact",
14687
- sourceIdColumn: "source_path",
14688
- contentColumn: "content",
14689
- scannedAt
14690
- });
14691
- backfillTable(db, {
14692
- table: "session_transcripts",
14693
- sourceKind: "transcript",
14694
- sourceIdColumn: "session_key",
14695
- contentColumn: "content",
14696
- scannedAt
14697
- });
14698
- backfillTable(db, {
14699
- table: "session_summaries",
14700
- sourceKind: "summary",
14701
- sourceIdColumn: "id",
14702
- contentColumn: "content",
14703
- scannedAt
14704
- });
14705
- backfillTable(db, {
14706
- table: "embeddings",
14707
- sourceKind: "source_chunk",
14708
- sourceIdColumn: "id",
14709
- contentColumn: "chunk_text",
14710
- where: "source_type IN ('source_chunk', 'source_obsidian_chunk')",
14711
- scannedAt
14712
- });
14713
14548
  }
14714
14549
  function up131(db) {
14715
14550
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
@@ -14813,13 +14648,13 @@ function up133(db) {
14813
14648
  AND error IS NOT NULL;
14814
14649
  `);
14815
14650
  }
14816
- function tableExists3(db, table) {
14651
+ function tableExists2(db, table) {
14817
14652
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
14818
14653
  }
14819
14654
  function up134(db) {
14820
- if (!tableExists3(db, "memory_jobs"))
14655
+ if (!tableExists2(db, "memory_jobs"))
14821
14656
  return;
14822
- if (!tableExists3(db, "job_cancellations")) {
14657
+ if (!tableExists2(db, "job_cancellations")) {
14823
14658
  throw new Error("job_cancellations table missing; cannot retire structural jobs without an audit trail");
14824
14659
  }
14825
14660
  db.prepare(`
@@ -15048,12 +14883,12 @@ function up142(db) {
15048
14883
  if (!cols.has(name))
15049
14884
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${name} ${type}`);
15050
14885
  }
15051
- function hasColumn25(db, table, column) {
14886
+ function hasColumn24(db, table, column) {
15052
14887
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
15053
14888
  return rows.some((row) => row.name === column);
15054
14889
  }
15055
14890
  function addColumnIfMissing28(db, table, column, definition) {
15056
- if (!hasColumn25(db, table, column))
14891
+ if (!hasColumn24(db, table, column))
15057
14892
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
15058
14893
  }
15059
14894
  function up143(db) {
@@ -15925,6 +15760,138 @@ function up162(db) {
15925
15760
  END;
15926
15761
  `);
15927
15762
  }
15763
+ function up163(db) {
15764
+ db.exec(`
15765
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_ai;
15766
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_au;
15767
+ DROP INDEX IF EXISTS idx_memory_content_safety_status;
15768
+ DROP INDEX IF EXISTS idx_memory_content_safety_eligibility;
15769
+ DROP TABLE IF EXISTS memory_content_safety;
15770
+ `);
15771
+ }
15772
+ var COLUMNS3 = ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"];
15773
+ function up164(db) {
15774
+ const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
15775
+ for (const column of COLUMNS3) {
15776
+ if (!cols.some((col) => col.name === column)) {
15777
+ db.exec(`ALTER TABLE entity_attributes ADD COLUMN ${column} TEXT`);
15778
+ }
15779
+ }
15780
+ }
15781
+ function up165(db) {
15782
+ const passColumns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15783
+ if (!passColumns.some((column) => column.name === "scope_key")) {
15784
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN scope_key TEXT");
15785
+ }
15786
+ db.exec(`
15787
+ CREATE TABLE IF NOT EXISTS dreaming_history_nodes (
15788
+ agent_id TEXT NOT NULL,
15789
+ scope_key TEXT NOT NULL,
15790
+ level INTEGER NOT NULL,
15791
+ idx INTEGER NOT NULL,
15792
+ pass_id TEXT,
15793
+ text TEXT NOT NULL,
15794
+ tokens_input INTEGER,
15795
+ tokens_output INTEGER,
15796
+ tokens_cache_read INTEGER,
15797
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
15798
+ PRIMARY KEY (agent_id, scope_key, level, idx)
15799
+ );
15800
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_dreaming_history_nodes_pass
15801
+ ON dreaming_history_nodes(pass_id) WHERE pass_id IS NOT NULL;
15802
+ `);
15803
+ }
15804
+ function up166(db) {
15805
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
15806
+ if (!columns.some((column) => column.name === "tokens_peak_context")) {
15807
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN tokens_peak_context INTEGER");
15808
+ }
15809
+ }
15810
+ function up167(db) {
15811
+ const sql = readMemoriesFtsSql(db);
15812
+ if (sql !== null && !memoriesFtsNeedsTokenizerRepair(sql))
15813
+ return;
15814
+ recreateMemoriesFts(db);
15815
+ }
15816
+ function hasTable5(db, table) {
15817
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
15818
+ }
15819
+ function hasColumn25(db, table, column) {
15820
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
15821
+ }
15822
+ function up168(db) {
15823
+ if (!hasTable5(db, "entity_attributes") || !hasTable5(db, "entity_aspects") || !hasTable5(db, "entities") || !hasColumn25(db, "entity_attributes", "source_root") || !hasColumn25(db, "entities", "source_root")) {
15824
+ return;
15825
+ }
15826
+ const now = new Date().toISOString();
15827
+ db.exec(`
15828
+ CREATE TEMP TABLE retired_source_paragraphs AS
15829
+ SELECT attr.id, attr.memory_id, attr.agent_id, asp.entity_id
15830
+ FROM entity_attributes attr
15831
+ JOIN entity_aspects asp ON asp.id = attr.aspect_id
15832
+ JOIN entities e ON e.id = asp.entity_id
15833
+ WHERE e.entity_type IN ('source_document', 'source_document_reference')
15834
+ AND attr.source_root IS NOT NULL
15835
+ AND attr.source_root = e.source_root
15836
+ AND attr.source_id = e.source_id
15837
+ AND attr.source_root NOT IN ('dreaming', 'dreaming_attention')
15838
+ `);
15839
+ if (hasColumn25(db, "entity_attributes", "memory_id") && hasTable5(db, "memories")) {
15840
+ if (hasTable5(db, "memory_history")) {
15841
+ db.prepare(`INSERT INTO memory_history (id, memory_id, event, old_content, new_content, changed_by, reason, metadata, created_at)
15842
+ SELECT lower(hex(randomblob(16))), mem.id, 'deleted', mem.content, NULL, 'migration:168',
15843
+ 'Source paragraph claims retired', '{"force":true}', ?
15844
+ FROM memories mem
15845
+ JOIN retired_source_paragraphs retired ON retired.memory_id = mem.id
15846
+ WHERE mem.is_deleted = 0`).run(now);
15847
+ }
15848
+ if (hasTable5(db, "derived_memory_sources") && hasColumn25(db, "memories", "stale_at")) {
15849
+ db.prepare(`UPDATE memories
15850
+ SET stale_at = ?
15851
+ WHERE stale_at IS NULL
15852
+ AND is_deleted = 0
15853
+ AND id IN (
15854
+ SELECT dms.derived_memory_id
15855
+ FROM derived_memory_sources dms
15856
+ JOIN retired_source_paragraphs retired ON retired.agent_id = dms.agent_id
15857
+ WHERE (dms.source_kind = 'memory' AND dms.source_id = retired.memory_id)
15858
+ OR (dms.source_kind = 'ontology_claim' AND dms.source_id = retired.id)
15859
+ )`).run(now);
15860
+ }
15861
+ const forget = [
15862
+ "is_deleted = 1",
15863
+ ...["deleted_at", "updated_at"].filter((column) => hasColumn25(db, "memories", column)).map((column) => `${column} = $now`),
15864
+ ...hasColumn25(db, "memories", "updated_by") ? ["updated_by = 'migration:168'"] : [],
15865
+ ...hasColumn25(db, "memories", "version") ? ["version = version + 1"] : []
15866
+ ];
15867
+ db.prepare(`UPDATE memories
15868
+ SET ${forget.join(", ")}
15869
+ WHERE is_deleted = 0
15870
+ AND id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)`).run({ $now: now });
15871
+ if (hasTable5(db, "memory_entity_mentions")) {
15872
+ db.exec(`
15873
+ DELETE FROM memory_entity_mentions
15874
+ WHERE memory_id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)
15875
+ `);
15876
+ }
15877
+ }
15878
+ if (hasTable5(db, "ontology_contradictions")) {
15879
+ db.prepare(`UPDATE ontology_contradictions
15880
+ SET status = 'resolved', resolved_at = ?, resolution_reason = 'source paragraph claims retired', updated_at = ?
15881
+ WHERE status = 'active'
15882
+ AND (left_attribute_id IN (SELECT id FROM retired_source_paragraphs)
15883
+ OR right_attribute_id IN (SELECT id FROM retired_source_paragraphs))`).run(now, now);
15884
+ }
15885
+ db.exec(`
15886
+ DELETE FROM entity_attributes WHERE id IN (SELECT id FROM retired_source_paragraphs);
15887
+ DELETE FROM entity_aspects
15888
+ WHERE entity_id IN (
15889
+ SELECT id FROM entities WHERE entity_type IN ('source_document', 'source_document_reference')
15890
+ )
15891
+ AND NOT EXISTS (SELECT 1 FROM entity_attributes attr WHERE attr.aspect_id = entity_aspects.id);
15892
+ DROP TABLE retired_source_paragraphs;
15893
+ `);
15894
+ }
15928
15895
  var MIGRATIONS = [
15929
15896
  {
15930
15897
  version: 1,
@@ -16934,8 +16901,7 @@ var MIGRATIONS = [
16934
16901
  {
16935
16902
  version: 125,
16936
16903
  name: "memory-content-safety",
16937
- up: up130,
16938
- artifacts: { tables: ["memory_content_safety"] }
16904
+ up: up130
16939
16905
  },
16940
16906
  {
16941
16907
  version: 126,
@@ -17237,6 +17203,48 @@ var MIGRATIONS = [
17237
17203
  name: "generic-entity-prune-scan-generation",
17238
17204
  up: up162,
17239
17205
  artifacts: { tables: ["generic_entity_prune_scan_state"] }
17206
+ },
17207
+ {
17208
+ version: 163,
17209
+ name: "retire-memory-content-safety",
17210
+ up: up163
17211
+ },
17212
+ {
17213
+ version: 164,
17214
+ name: "claim-event-time",
17215
+ up: up164,
17216
+ artifacts: {
17217
+ columns: ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"].map((column) => ({
17218
+ table: "entity_attributes",
17219
+ column
17220
+ }))
17221
+ }
17222
+ },
17223
+ {
17224
+ version: 165,
17225
+ name: "dreaming-history",
17226
+ up: up165,
17227
+ artifacts: {
17228
+ tables: ["dreaming_history_nodes"],
17229
+ indexes: ["idx_dreaming_history_nodes_pass"],
17230
+ columns: [{ table: "dreaming_passes", column: "scope_key" }]
17231
+ }
17232
+ },
17233
+ {
17234
+ version: 166,
17235
+ name: "dreaming-pass-peak-context",
17236
+ up: up166,
17237
+ artifacts: { columns: [{ table: "dreaming_passes", column: "tokens_peak_context" }] }
17238
+ },
17239
+ {
17240
+ version: 167,
17241
+ name: "memories-fts-porter",
17242
+ up: up167
17243
+ },
17244
+ {
17245
+ version: 168,
17246
+ name: "retire-source-paragraph-claims",
17247
+ up: up168
17240
17248
  }
17241
17249
  ];
17242
17250
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -17471,6 +17479,37 @@ var PIPELINE_PROVIDER_CHOICES = [
17471
17479
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
17472
17480
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
17473
17481
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
17482
+ var SECRET_NAMES = "(?:access[_-]?token|api[_-]?key|apikey|auth[_-]?token|client[_-]?secret|passw(?:or)?d|refresh[_-]?token|private[_-]?key|secret(?:[_-]?key)?|token)";
17483
+ var SECRET_VALUE = `(?=[^\\s"',;&<>()\\[\\]{}$]*\\d)[^\\s"',;&<>()\\[\\]{}$]{8,}`;
17484
+ var PATTERNS = [
17485
+ {
17486
+ kind: "private_key",
17487
+ pattern: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )*PRIVATE KEY-----/g
17488
+ },
17489
+ {
17490
+ kind: "provider_key",
17491
+ 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
17492
+ },
17493
+ {
17494
+ kind: "jwt",
17495
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
17496
+ },
17497
+ {
17498
+ kind: "bearer_token",
17499
+ pattern: /\bBearer\s+([A-Za-z0-9._~+/-]{16,}=*)/g,
17500
+ valueGroup: 1
17501
+ },
17502
+ {
17503
+ kind: "secret_assignment",
17504
+ pattern: new RegExp(`\\b${SECRET_NAMES}["']?\\s*[:=]\\s*["']?(${SECRET_VALUE})`, "gi"),
17505
+ valueGroup: 1
17506
+ },
17507
+ {
17508
+ kind: "secret_assignment",
17509
+ pattern: new RegExp(`\\b[A-Z][A-Z0-9_]*(?:API_KEY|TOKEN|SECRET|PASSWORD)\\s*=\\s*["']?(${SECRET_VALUE})`, "g"),
17510
+ valueGroup: 1
17511
+ }
17512
+ ];
17474
17513
  var LOOPBACK_HOST = "127.0.0.1";
17475
17514
  var LOCAL_BINDS = new Set([LOOPBACK_HOST, "localhost", "::1", "::ffff:127.0.0.1"]);
17476
17515
  var native = null;
@@ -28161,99 +28200,6 @@ var execFileHiddenImpl2 = (...args) => Reflect.apply(nodeExecFile2, undefined, w
28161
28200
  Object.defineProperty(execFileHiddenImpl2, promisify2.custom, {
28162
28201
  value: (...args) => Reflect.apply(nodeExecFileAsync2, undefined, withWindowsHideArgument2(args, 1))
28163
28202
  });
28164
- var MEMORY_CONTENT_SAFETY_POLICY_VERSION2 = "memory-content-safety-v1";
28165
- var MEMORY_CONTENT_SAFETY_REASONS2 = [
28166
- "prompt_injection",
28167
- "exfiltration",
28168
- "credential_harvesting",
28169
- "malicious_shell",
28170
- "tool_directive",
28171
- "invisible_unicode"
28172
- ];
28173
- 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;
28174
- var STRONG_DEFENSIVE_CONTEXT_RE2 = /\b(?:security\s+(?:guidance|discussion|analysis)|threat\s+model|defensive)\b/i;
28175
- var REPORTING_CONTEXT_RE2 = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b/i;
28176
- 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;
28177
- 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;
28178
- 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;
28179
- var PROMPT_INJECTION_RES2 = [
28180
- /\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,
28181
- /\b(?:new|following|these)\s+(?:(?:system|developer|assistant|hidden)\s+)?instructions?\b/i,
28182
- /(?:^|\n)\s*(?:system|developer|instruction|prompt)\s*:/im,
28183
- /<\s*(?:system|developer|assistant|instruction|prompt)\b[^>]*>/i,
28184
- /\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
28185
- ];
28186
- var TOOL_DIRECTIVE_RES2 = [
28187
- /<\s*(?:tool[_-]?call|function[_-]?call|invoke|tool)\b/i,
28188
- /\b(?:assistant|system)\s+to\s*=\s*[a-z0-9_.-]+/i,
28189
- /\b(?:call|invoke|use|run|execute)\s+(?:the\s+)?[a-z0-9_.-]+\s+tool\b/i
28190
- ];
28191
- 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;
28192
- 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;
28193
- 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;
28194
- 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;
28195
- function matchHasDefensiveContext2(content, match) {
28196
- if (!match || !match[0])
28197
- return false;
28198
- const start = match.index ?? 0;
28199
- const before = content.slice(Math.max(0, start - 120), start);
28200
- const after = content.slice(start + match[0].length, start + match[0].length + 160);
28201
- 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);
28202
- }
28203
- function hasActionableMatch2(content, patterns) {
28204
- return patterns.some((pattern) => {
28205
- const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
28206
- const searchable = new RegExp(pattern.source, flags);
28207
- let match;
28208
- while ((match = searchable.exec(content)) !== null) {
28209
- if (!matchHasDefensiveContext2(content, match))
28210
- return true;
28211
- if (match[0].length === 0)
28212
- searchable.lastIndex += 1;
28213
- }
28214
- return false;
28215
- });
28216
- }
28217
- function hasDangerousShell2(content) {
28218
- const searchable = new RegExp(DANGEROUS_SHELL_RE2.source, `${DANGEROUS_SHELL_RE2.flags}g`);
28219
- let match;
28220
- while ((match = searchable.exec(content)) !== null) {
28221
- if (matchHasDefensiveContext2(content, match))
28222
- continue;
28223
- const end = (match.index ?? 0) + match[0].length;
28224
- const after = content.slice(end, end + 160);
28225
- if (!STRONG_DEFENSIVE_CONTEXT_RE2.test(after) && !REPORTING_AFTER_RE2.test(after))
28226
- return true;
28227
- if (match[0].length === 0)
28228
- searchable.lastIndex += 1;
28229
- }
28230
- return false;
28231
- }
28232
- function scanMemoryContent2(content) {
28233
- const raw = typeof content === "string" ? content : String(content ?? "");
28234
- const normalized = raw.normalize("NFKC");
28235
- const reasons = new Set;
28236
- if (INVISIBLE_UNICODE_RE2.test(raw))
28237
- reasons.add("invisible_unicode");
28238
- if (hasActionableMatch2(normalized, PROMPT_INJECTION_RES2))
28239
- reasons.add("prompt_injection");
28240
- if (hasActionableMatch2(normalized, TOOL_DIRECTIVE_RES2))
28241
- reasons.add("tool_directive");
28242
- if (hasActionableMatch2(normalized, [EXFILTRATION_RE2, EXFILTRATION_REVERSE2]))
28243
- reasons.add("exfiltration");
28244
- if (hasActionableMatch2(normalized, [CREDENTIAL_HARVESTING_RE2]))
28245
- reasons.add("credential_harvesting");
28246
- if (hasDangerousShell2(normalized))
28247
- reasons.add("malicious_shell");
28248
- const orderedReasons = MEMORY_CONTENT_SAFETY_REASONS2.filter((reason) => reasons.has(reason));
28249
- const status = orderedReasons.length === 0 ? "clean" : orderedReasons.every((reason) => reason === "invisible_unicode") ? "tainted" : "blocked";
28250
- return {
28251
- status,
28252
- contextEligible: status === "clean",
28253
- reasons: orderedReasons,
28254
- policyVersion: MEMORY_CONTENT_SAFETY_POLICY_VERSION2
28255
- };
28256
- }
28257
28203
  var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = [
28258
28204
  "extract",
28259
28205
  "aggregate-recall",
@@ -28261,7 +28207,7 @@ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = [
28261
28207
  "checkpoint",
28262
28208
  "dreaming"
28263
28209
  ];
28264
- function up163(db) {
28210
+ function up169(db) {
28265
28211
  const hasColumn = (table, column) => {
28266
28212
  const statement = db.prepare(`SELECT 1 FROM pragma_table_info('${table}') WHERE name = ?`);
28267
28213
  try {
@@ -28376,7 +28322,7 @@ function up410(db) {
28376
28322
  function up510(db) {
28377
28323
  db.exec("DROP TABLE IF EXISTS mcp_invocations");
28378
28324
  }
28379
- var MEMORIES_FTS_TOKENIZER2 = "unicode61";
28325
+ var MEMORIES_FTS_TOKENIZER2 = "porter unicode61";
28380
28326
  var FTS_STATE_TABLE2 = "memories_fts_state";
28381
28327
  function normalizeSql2(sql) {
28382
28328
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -28486,10 +28432,7 @@ function readMemoriesFtsSql2(db) {
28486
28432
  function memoriesFtsNeedsTokenizerRepair2(sql) {
28487
28433
  if (sql === null)
28488
28434
  return false;
28489
- const normalized = normalizeSql2(sql);
28490
- if (normalized.includes("porter unicode61"))
28491
- return true;
28492
- return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
28435
+ return !normalizeSql2(sql).includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
28493
28436
  }
28494
28437
  function up610(db) {
28495
28438
  db.exec(`
@@ -28914,7 +28857,7 @@ function up1510(db) {
28914
28857
  )
28915
28858
  `);
28916
28859
  }
28917
- function up164(db) {
28860
+ function up1610(db) {
28918
28861
  db.exec(`
28919
28862
  CREATE TABLE IF NOT EXISTS session_scores (
28920
28863
  id TEXT PRIMARY KEY,
@@ -30135,7 +30078,7 @@ function up542(db) {
30135
30078
  );
30136
30079
  `);
30137
30080
  }
30138
- function hasTable5(db, name) {
30081
+ function hasTable6(db, name) {
30139
30082
  return db.prepare(`SELECT name
30140
30083
  FROM sqlite_master
30141
30084
  WHERE type = 'table' AND name = ?
@@ -30165,7 +30108,7 @@ function up552(db) {
30165
30108
  CREATE INDEX IF NOT EXISTS idx_entity_dependency_history_created
30166
30109
  ON entity_dependency_history(created_at DESC);
30167
30110
  `);
30168
- if (!hasTable5(db, "entity_dependencies"))
30111
+ if (!hasTable6(db, "entity_dependencies"))
30169
30112
  return;
30170
30113
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_insert");
30171
30114
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_update");
@@ -31144,9 +31087,9 @@ function hasColumn112(db, table, column) {
31144
31087
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
31145
31088
  return rows.some((row) => row.name === column);
31146
31089
  }
31147
- var COLUMNS3 = ["harness", "session_id", "tool_use_id", "cwd", "origin", "args"];
31090
+ var COLUMNS4 = ["harness", "session_id", "tool_use_id", "cwd", "origin", "args"];
31148
31091
  function up872(db) {
31149
- for (const column of COLUMNS3) {
31092
+ for (const column of COLUMNS4) {
31150
31093
  if (!hasColumn112(db, "skill_invocations", column)) {
31151
31094
  db.exec(`ALTER TABLE skill_invocations ADD COLUMN ${column} TEXT`);
31152
31095
  }
@@ -31710,7 +31653,7 @@ function up1082(db) {
31710
31653
  )
31711
31654
  `);
31712
31655
  }
31713
- function tableExists4(db, table) {
31656
+ function tableExists3(db, table) {
31714
31657
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
31715
31658
  }
31716
31659
  function hasColumn162(db, table, column) {
@@ -31732,7 +31675,7 @@ function up1092(db) {
31732
31675
  CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
31733
31676
  ON derived_memory_sources(agent_id, source_kind, source_id);
31734
31677
  `);
31735
- if (tableExists4(db, "aggregate_evidence_sources")) {
31678
+ if (tableExists3(db, "aggregate_evidence_sources")) {
31736
31679
  db.exec(`
31737
31680
  INSERT OR IGNORE INTO derived_memory_sources
31738
31681
  (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
@@ -31740,7 +31683,7 @@ function up1092(db) {
31740
31683
  FROM aggregate_evidence_sources
31741
31684
  `);
31742
31685
  }
31743
- if (tableExists4(db, "aggregate_memory_sources")) {
31686
+ if (tableExists3(db, "aggregate_memory_sources")) {
31744
31687
  db.exec(`
31745
31688
  INSERT OR IGNORE INTO derived_memory_sources
31746
31689
  (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
@@ -31748,10 +31691,10 @@ function up1092(db) {
31748
31691
  FROM aggregate_memory_sources
31749
31692
  `);
31750
31693
  }
31751
- if (tableExists4(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
31694
+ if (tableExists3(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
31752
31695
  db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
31753
31696
  }
31754
- if (tableExists4(db, "memories")) {
31697
+ if (tableExists3(db, "memories")) {
31755
31698
  db.exec(`
31756
31699
  CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
31757
31700
  ON memories(agent_id, stale_at)
@@ -32402,38 +32345,6 @@ function up1292(db) {
32402
32345
  ON imported_source_lifecycle(agent_id, status, updated_at DESC);
32403
32346
  `);
32404
32347
  }
32405
- function tableExists22(db, table) {
32406
- return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
32407
- }
32408
- function hasColumn242(db, table, column) {
32409
- return db.prepare(`PRAGMA table_info("${table}")`).all().some((row) => row.name === column);
32410
- }
32411
- function backfill2(db, rows, sourceKind, scannedAt) {
32412
- const statement = db.prepare(`INSERT INTO memory_content_safety
32413
- (agent_id, source_kind, source_id, status, context_eligible, reasons_json, policy_version, scanned_at)
32414
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
32415
- ON CONFLICT(agent_id, source_kind, source_id) DO UPDATE SET
32416
- status = excluded.status,
32417
- context_eligible = excluded.context_eligible,
32418
- reasons_json = excluded.reasons_json,
32419
- policy_version = excluded.policy_version,
32420
- scanned_at = excluded.scanned_at`);
32421
- for (const row of rows) {
32422
- const sourceId = row.source_id?.trim();
32423
- if (!sourceId)
32424
- continue;
32425
- const assessment = scanMemoryContent2(row.content ?? "");
32426
- 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);
32427
- }
32428
- }
32429
- function backfillTable2(db, params) {
32430
- if (!tableExists22(db, params.table) || !hasColumn242(db, params.table, params.sourceIdColumn) || !hasColumn242(db, params.table, params.contentColumn))
32431
- return;
32432
- const agentColumn = hasColumn242(db, params.table, "agent_id") ? "COALESCE(NULLIF(TRIM(agent_id), ''), 'default')" : "'default'";
32433
- const rows = db.prepare(`SELECT ${agentColumn} AS agent_id, ${params.sourceIdColumn} AS source_id, ${params.contentColumn} AS content
32434
- FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
32435
- backfill2(db, rows, params.sourceKind, params.scannedAt);
32436
- }
32437
32348
  function up1302(db) {
32438
32349
  db.exec(`
32439
32350
  CREATE TABLE IF NOT EXISTS memory_content_safety (
@@ -32453,43 +32364,6 @@ function up1302(db) {
32453
32364
  CREATE INDEX IF NOT EXISTS idx_memory_content_safety_eligibility
32454
32365
  ON memory_content_safety(agent_id, source_kind, context_eligible);
32455
32366
  `);
32456
- const scannedAt = new Date().toISOString();
32457
- backfillTable2(db, {
32458
- table: "memories",
32459
- sourceKind: "memory",
32460
- sourceIdColumn: "id",
32461
- contentColumn: "content",
32462
- scannedAt
32463
- });
32464
- backfillTable2(db, {
32465
- table: "memory_artifacts",
32466
- sourceKind: "artifact",
32467
- sourceIdColumn: "source_path",
32468
- contentColumn: "content",
32469
- scannedAt
32470
- });
32471
- backfillTable2(db, {
32472
- table: "session_transcripts",
32473
- sourceKind: "transcript",
32474
- sourceIdColumn: "session_key",
32475
- contentColumn: "content",
32476
- scannedAt
32477
- });
32478
- backfillTable2(db, {
32479
- table: "session_summaries",
32480
- sourceKind: "summary",
32481
- sourceIdColumn: "id",
32482
- contentColumn: "content",
32483
- scannedAt
32484
- });
32485
- backfillTable2(db, {
32486
- table: "embeddings",
32487
- sourceKind: "source_chunk",
32488
- sourceIdColumn: "id",
32489
- contentColumn: "chunk_text",
32490
- where: "source_type IN ('source_chunk', 'source_obsidian_chunk')",
32491
- scannedAt
32492
- });
32493
32367
  }
32494
32368
  function up1312(db) {
32495
32369
  const table = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'dreaming_attention'").get();
@@ -32593,13 +32467,13 @@ function up1332(db) {
32593
32467
  AND error IS NOT NULL;
32594
32468
  `);
32595
32469
  }
32596
- function tableExists32(db, table) {
32470
+ function tableExists22(db, table) {
32597
32471
  return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
32598
32472
  }
32599
32473
  function up1342(db) {
32600
- if (!tableExists32(db, "memory_jobs"))
32474
+ if (!tableExists22(db, "memory_jobs"))
32601
32475
  return;
32602
- if (!tableExists32(db, "job_cancellations")) {
32476
+ if (!tableExists22(db, "job_cancellations")) {
32603
32477
  throw new Error("job_cancellations table missing; cannot retire structural jobs without an audit trail");
32604
32478
  }
32605
32479
  db.prepare(`
@@ -32828,12 +32702,12 @@ function up1422(db) {
32828
32702
  if (!cols.has(name))
32829
32703
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${name} ${type}`);
32830
32704
  }
32831
- function hasColumn252(db, table, column) {
32705
+ function hasColumn242(db, table, column) {
32832
32706
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
32833
32707
  return rows.some((row) => row.name === column);
32834
32708
  }
32835
32709
  function addColumnIfMissing282(db, table, column, definition) {
32836
- if (!hasColumn252(db, table, column))
32710
+ if (!hasColumn242(db, table, column))
32837
32711
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
32838
32712
  }
32839
32713
  function up1432(db) {
@@ -33705,6 +33579,138 @@ function up1622(db) {
33705
33579
  END;
33706
33580
  `);
33707
33581
  }
33582
+ function up1632(db) {
33583
+ db.exec(`
33584
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_ai;
33585
+ DROP TRIGGER IF EXISTS memory_content_safety_head_freshness_au;
33586
+ DROP INDEX IF EXISTS idx_memory_content_safety_status;
33587
+ DROP INDEX IF EXISTS idx_memory_content_safety_eligibility;
33588
+ DROP TABLE IF EXISTS memory_content_safety;
33589
+ `);
33590
+ }
33591
+ var COLUMNS32 = ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"];
33592
+ function up1642(db) {
33593
+ const cols = db.prepare("PRAGMA table_info(entity_attributes)").all();
33594
+ for (const column of COLUMNS32) {
33595
+ if (!cols.some((col) => col.name === column)) {
33596
+ db.exec(`ALTER TABLE entity_attributes ADD COLUMN ${column} TEXT`);
33597
+ }
33598
+ }
33599
+ }
33600
+ function up1652(db) {
33601
+ const passColumns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
33602
+ if (!passColumns.some((column) => column.name === "scope_key")) {
33603
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN scope_key TEXT");
33604
+ }
33605
+ db.exec(`
33606
+ CREATE TABLE IF NOT EXISTS dreaming_history_nodes (
33607
+ agent_id TEXT NOT NULL,
33608
+ scope_key TEXT NOT NULL,
33609
+ level INTEGER NOT NULL,
33610
+ idx INTEGER NOT NULL,
33611
+ pass_id TEXT,
33612
+ text TEXT NOT NULL,
33613
+ tokens_input INTEGER,
33614
+ tokens_output INTEGER,
33615
+ tokens_cache_read INTEGER,
33616
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
33617
+ PRIMARY KEY (agent_id, scope_key, level, idx)
33618
+ );
33619
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_dreaming_history_nodes_pass
33620
+ ON dreaming_history_nodes(pass_id) WHERE pass_id IS NOT NULL;
33621
+ `);
33622
+ }
33623
+ function up1662(db) {
33624
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
33625
+ if (!columns.some((column) => column.name === "tokens_peak_context")) {
33626
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN tokens_peak_context INTEGER");
33627
+ }
33628
+ }
33629
+ function up1672(db) {
33630
+ const sql = readMemoriesFtsSql2(db);
33631
+ if (sql !== null && !memoriesFtsNeedsTokenizerRepair2(sql))
33632
+ return;
33633
+ recreateMemoriesFts2(db);
33634
+ }
33635
+ function hasTable52(db, table) {
33636
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
33637
+ }
33638
+ function hasColumn252(db, table, column) {
33639
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
33640
+ }
33641
+ function up1682(db) {
33642
+ if (!hasTable52(db, "entity_attributes") || !hasTable52(db, "entity_aspects") || !hasTable52(db, "entities") || !hasColumn252(db, "entity_attributes", "source_root") || !hasColumn252(db, "entities", "source_root")) {
33643
+ return;
33644
+ }
33645
+ const now = new Date().toISOString();
33646
+ db.exec(`
33647
+ CREATE TEMP TABLE retired_source_paragraphs AS
33648
+ SELECT attr.id, attr.memory_id, attr.agent_id, asp.entity_id
33649
+ FROM entity_attributes attr
33650
+ JOIN entity_aspects asp ON asp.id = attr.aspect_id
33651
+ JOIN entities e ON e.id = asp.entity_id
33652
+ WHERE e.entity_type IN ('source_document', 'source_document_reference')
33653
+ AND attr.source_root IS NOT NULL
33654
+ AND attr.source_root = e.source_root
33655
+ AND attr.source_id = e.source_id
33656
+ AND attr.source_root NOT IN ('dreaming', 'dreaming_attention')
33657
+ `);
33658
+ if (hasColumn252(db, "entity_attributes", "memory_id") && hasTable52(db, "memories")) {
33659
+ if (hasTable52(db, "memory_history")) {
33660
+ db.prepare(`INSERT INTO memory_history (id, memory_id, event, old_content, new_content, changed_by, reason, metadata, created_at)
33661
+ SELECT lower(hex(randomblob(16))), mem.id, 'deleted', mem.content, NULL, 'migration:168',
33662
+ 'Source paragraph claims retired', '{"force":true}', ?
33663
+ FROM memories mem
33664
+ JOIN retired_source_paragraphs retired ON retired.memory_id = mem.id
33665
+ WHERE mem.is_deleted = 0`).run(now);
33666
+ }
33667
+ if (hasTable52(db, "derived_memory_sources") && hasColumn252(db, "memories", "stale_at")) {
33668
+ db.prepare(`UPDATE memories
33669
+ SET stale_at = ?
33670
+ WHERE stale_at IS NULL
33671
+ AND is_deleted = 0
33672
+ AND id IN (
33673
+ SELECT dms.derived_memory_id
33674
+ FROM derived_memory_sources dms
33675
+ JOIN retired_source_paragraphs retired ON retired.agent_id = dms.agent_id
33676
+ WHERE (dms.source_kind = 'memory' AND dms.source_id = retired.memory_id)
33677
+ OR (dms.source_kind = 'ontology_claim' AND dms.source_id = retired.id)
33678
+ )`).run(now);
33679
+ }
33680
+ const forget = [
33681
+ "is_deleted = 1",
33682
+ ...["deleted_at", "updated_at"].filter((column) => hasColumn252(db, "memories", column)).map((column) => `${column} = $now`),
33683
+ ...hasColumn252(db, "memories", "updated_by") ? ["updated_by = 'migration:168'"] : [],
33684
+ ...hasColumn252(db, "memories", "version") ? ["version = version + 1"] : []
33685
+ ];
33686
+ db.prepare(`UPDATE memories
33687
+ SET ${forget.join(", ")}
33688
+ WHERE is_deleted = 0
33689
+ AND id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)`).run({ $now: now });
33690
+ if (hasTable52(db, "memory_entity_mentions")) {
33691
+ db.exec(`
33692
+ DELETE FROM memory_entity_mentions
33693
+ WHERE memory_id IN (SELECT memory_id FROM retired_source_paragraphs WHERE memory_id IS NOT NULL)
33694
+ `);
33695
+ }
33696
+ }
33697
+ if (hasTable52(db, "ontology_contradictions")) {
33698
+ db.prepare(`UPDATE ontology_contradictions
33699
+ SET status = 'resolved', resolved_at = ?, resolution_reason = 'source paragraph claims retired', updated_at = ?
33700
+ WHERE status = 'active'
33701
+ AND (left_attribute_id IN (SELECT id FROM retired_source_paragraphs)
33702
+ OR right_attribute_id IN (SELECT id FROM retired_source_paragraphs))`).run(now, now);
33703
+ }
33704
+ db.exec(`
33705
+ DELETE FROM entity_attributes WHERE id IN (SELECT id FROM retired_source_paragraphs);
33706
+ DELETE FROM entity_aspects
33707
+ WHERE entity_id IN (
33708
+ SELECT id FROM entities WHERE entity_type IN ('source_document', 'source_document_reference')
33709
+ )
33710
+ AND NOT EXISTS (SELECT 1 FROM entity_attributes attr WHERE attr.aspect_id = entity_aspects.id);
33711
+ DROP TABLE retired_source_paragraphs;
33712
+ `);
33713
+ }
33708
33714
  var MIGRATIONS2 = [
33709
33715
  {
33710
33716
  version: 1,
@@ -33775,7 +33781,7 @@ var MIGRATIONS2 = [
33775
33781
  {
33776
33782
  version: 11,
33777
33783
  name: "session-scores",
33778
- up: up164,
33784
+ up: up1610,
33779
33785
  artifacts: { tables: ["session_scores"] }
33780
33786
  },
33781
33787
  {
@@ -34714,8 +34720,7 @@ var MIGRATIONS2 = [
34714
34720
  {
34715
34721
  version: 125,
34716
34722
  name: "memory-content-safety",
34717
- up: up1302,
34718
- artifacts: { tables: ["memory_content_safety"] }
34723
+ up: up1302
34719
34724
  },
34720
34725
  {
34721
34726
  version: 126,
@@ -34909,7 +34914,7 @@ var MIGRATIONS2 = [
34909
34914
  {
34910
34915
  version: 151,
34911
34916
  name: "transcript-import-bytes",
34912
- up: up163,
34917
+ up: up169,
34913
34918
  artifacts: {
34914
34919
  tables: [
34915
34920
  "source_import_chunks",
@@ -35017,6 +35022,48 @@ var MIGRATIONS2 = [
35017
35022
  name: "generic-entity-prune-scan-generation",
35018
35023
  up: up1622,
35019
35024
  artifacts: { tables: ["generic_entity_prune_scan_state"] }
35025
+ },
35026
+ {
35027
+ version: 163,
35028
+ name: "retire-memory-content-safety",
35029
+ up: up1632
35030
+ },
35031
+ {
35032
+ version: 164,
35033
+ name: "claim-event-time",
35034
+ up: up1642,
35035
+ artifacts: {
35036
+ columns: ["occurred_start", "occurred_end", "valid_from", "valid_until", "time_precision"].map((column) => ({
35037
+ table: "entity_attributes",
35038
+ column
35039
+ }))
35040
+ }
35041
+ },
35042
+ {
35043
+ version: 165,
35044
+ name: "dreaming-history",
35045
+ up: up1652,
35046
+ artifacts: {
35047
+ tables: ["dreaming_history_nodes"],
35048
+ indexes: ["idx_dreaming_history_nodes_pass"],
35049
+ columns: [{ table: "dreaming_passes", column: "scope_key" }]
35050
+ }
35051
+ },
35052
+ {
35053
+ version: 166,
35054
+ name: "dreaming-pass-peak-context",
35055
+ up: up1662,
35056
+ artifacts: { columns: [{ table: "dreaming_passes", column: "tokens_peak_context" }] }
35057
+ },
35058
+ {
35059
+ version: 167,
35060
+ name: "memories-fts-porter",
35061
+ up: up1672
35062
+ },
35063
+ {
35064
+ version: 168,
35065
+ name: "retire-source-paragraph-claims",
35066
+ up: up1682
35020
35067
  }
35021
35068
  ];
35022
35069
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -35258,6 +35305,37 @@ var PIPELINE_PROVIDER_CHOICES2 = [
35258
35305
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
35259
35306
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
35260
35307
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
35308
+ var SECRET_NAMES2 = "(?:access[_-]?token|api[_-]?key|apikey|auth[_-]?token|client[_-]?secret|passw(?:or)?d|refresh[_-]?token|private[_-]?key|secret(?:[_-]?key)?|token)";
35309
+ var SECRET_VALUE2 = `(?=[^\\s"',;&<>()\\[\\]{}$]*\\d)[^\\s"',;&<>()\\[\\]{}$]{8,}`;
35310
+ var PATTERNS2 = [
35311
+ {
35312
+ kind: "private_key",
35313
+ pattern: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )*PRIVATE KEY-----/g
35314
+ },
35315
+ {
35316
+ kind: "provider_key",
35317
+ 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
35318
+ },
35319
+ {
35320
+ kind: "jwt",
35321
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
35322
+ },
35323
+ {
35324
+ kind: "bearer_token",
35325
+ pattern: /\bBearer\s+([A-Za-z0-9._~+/-]{16,}=*)/g,
35326
+ valueGroup: 1
35327
+ },
35328
+ {
35329
+ kind: "secret_assignment",
35330
+ pattern: new RegExp(`\\b${SECRET_NAMES2}["']?\\s*[:=]\\s*["']?(${SECRET_VALUE2})`, "gi"),
35331
+ valueGroup: 1
35332
+ },
35333
+ {
35334
+ kind: "secret_assignment",
35335
+ pattern: new RegExp(`\\b[A-Z][A-Z0-9_]*(?:API_KEY|TOKEN|SECRET|PASSWORD)\\s*=\\s*["']?(${SECRET_VALUE2})`, "g"),
35336
+ valueGroup: 1
35337
+ }
35338
+ ];
35261
35339
  var LOOPBACK_HOST2 = "127.0.0.1";
35262
35340
  function normalizeLoopbackHost(host) {
35263
35341
  const normalized = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/connector-kimi",
3
- "version": "0.236.0",
3
+ "version": "0.237.0",
4
4
  "description": "Signet connector for Kimi CLI / Kimi Code",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "typecheck": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "@signetai/connector-base": "0.236.0",
28
- "@signetai/core": "0.236.0"
27
+ "@signetai/connector-base": "0.237.0",
28
+ "@signetai/core": "0.237.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.0.0",