@signetai/connector-openclaw 0.157.4 → 0.158.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 +770 -314
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -586,6 +586,8 @@ var require_Alias = __commonJS2((exports) => {
586
586
  });
587
587
  }
588
588
  resolve(doc, ctx) {
589
+ if (ctx?.maxAliasCount === 0)
590
+ throw new ReferenceError("Alias resolution is disabled");
589
591
  let nodes;
590
592
  if (ctx?.aliasResolveCache) {
591
593
  nodes = ctx.aliasResolveCache;
@@ -1615,18 +1617,18 @@ var require_merge = __commonJS2((exports) => {
1615
1617
  };
1616
1618
  var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
1617
1619
  function addMergeToJSMap(ctx, map, value) {
1618
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1619
- if (identity.isSeq(value))
1620
- for (const it of value.items)
1620
+ const source = resolveAliasValue(ctx, value);
1621
+ if (identity.isSeq(source))
1622
+ for (const it of source.items)
1621
1623
  mergeValue(ctx, map, it);
1622
- else if (Array.isArray(value))
1623
- for (const it of value)
1624
+ else if (Array.isArray(source))
1625
+ for (const it of source)
1624
1626
  mergeValue(ctx, map, it);
1625
1627
  else
1626
- mergeValue(ctx, map, value);
1628
+ mergeValue(ctx, map, source);
1627
1629
  }
1628
1630
  function mergeValue(ctx, map, value) {
1629
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1631
+ const source = resolveAliasValue(ctx, value);
1630
1632
  if (!identity.isMap(source))
1631
1633
  throw new Error("Merge sources must be maps or map aliases");
1632
1634
  const srcMap = source.toJSON(null, ctx, Map);
@@ -1647,6 +1649,9 @@ var require_merge = __commonJS2((exports) => {
1647
1649
  }
1648
1650
  return map;
1649
1651
  }
1652
+ function resolveAliasValue(ctx, value) {
1653
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1654
+ }
1650
1655
  exports.addMergeToJSMap = addMergeToJSMap;
1651
1656
  exports.isMergeKey = isMergeKey;
1652
1657
  exports.merge = merge;
@@ -2200,7 +2205,7 @@ var require_stringifyNumber = __commonJS2((exports) => {
2200
2205
  if (!isFinite(num))
2201
2206
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
2202
2207
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
2203
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
2208
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
2204
2209
  let i = n.indexOf(".");
2205
2210
  if (i < 0) {
2206
2211
  i = n.length;
@@ -4368,7 +4373,7 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4368
4373
  while (next === " " || next === "\t")
4369
4374
  next = source[++i + 1];
4370
4375
  } else if (next === "x" || next === "u" || next === "U") {
4371
- const length = { x: 2, u: 4, U: 8 }[next];
4376
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
4372
4377
  res += parseCharCode(source, i + 1, length, onError);
4373
4378
  i += length;
4374
4379
  } else {
@@ -4437,12 +4442,13 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4437
4442
  const cc = source.substr(offset, length);
4438
4443
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
4439
4444
  const code = ok ? parseInt(cc, 16) : NaN;
4440
- if (isNaN(code)) {
4445
+ try {
4446
+ return String.fromCodePoint(code);
4447
+ } catch {
4441
4448
  const raw = source.substr(offset - 2, length + 2);
4442
4449
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
4443
4450
  return raw;
4444
4451
  }
4445
- return String.fromCodePoint(code);
4446
4452
  }
4447
4453
  exports.resolveFlowScalar = resolveFlowScalar;
4448
4454
  });
@@ -4771,8 +4777,10 @@ ${cb}` : comment;
4771
4777
  }
4772
4778
  }
4773
4779
  if (afterDoc) {
4774
- Array.prototype.push.apply(doc.errors, this.errors);
4775
- Array.prototype.push.apply(doc.warnings, this.warnings);
4780
+ for (let i = 0;i < this.errors.length; ++i)
4781
+ doc.errors.push(this.errors[i]);
4782
+ for (let i = 0;i < this.warnings.length; ++i)
4783
+ doc.warnings.push(this.warnings[i]);
4776
4784
  } else {
4777
4785
  doc.errors = this.errors;
4778
4786
  doc.warnings = this.warnings;
@@ -5474,7 +5482,7 @@ var require_lexer = __commonJS2((exports) => {
5474
5482
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
5475
5483
  this.indentNext = this.indentValue + 1;
5476
5484
  this.indentValue += n;
5477
- return yield* this.parseBlockStart();
5485
+ return "block-start";
5478
5486
  }
5479
5487
  return "doc";
5480
5488
  }
@@ -5781,26 +5789,37 @@ var require_lexer = __commonJS2((exports) => {
5781
5789
  return 0;
5782
5790
  }
5783
5791
  *pushIndicators() {
5784
- switch (this.charAt(0)) {
5785
- case "!":
5786
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5787
- case "&":
5788
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5789
- case "-":
5790
- case "?":
5791
- case ":": {
5792
- const inFlow = this.flowLevel > 0;
5793
- const ch1 = this.charAt(1);
5794
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5795
- if (!inFlow)
5796
- this.indentNext = this.indentValue + 1;
5797
- else if (this.flowKey)
5798
- this.flowKey = false;
5799
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5792
+ let n = 0;
5793
+ loop:
5794
+ while (true) {
5795
+ switch (this.charAt(0)) {
5796
+ case "!":
5797
+ n += yield* this.pushTag();
5798
+ n += yield* this.pushSpaces(true);
5799
+ continue loop;
5800
+ case "&":
5801
+ n += yield* this.pushUntil(isNotAnchorChar);
5802
+ n += yield* this.pushSpaces(true);
5803
+ continue loop;
5804
+ case "-":
5805
+ case "?":
5806
+ case ":": {
5807
+ const inFlow = this.flowLevel > 0;
5808
+ const ch1 = this.charAt(1);
5809
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5810
+ if (!inFlow)
5811
+ this.indentNext = this.indentValue + 1;
5812
+ else if (this.flowKey)
5813
+ this.flowKey = false;
5814
+ n += yield* this.pushCount(1);
5815
+ n += yield* this.pushSpaces(true);
5816
+ continue loop;
5817
+ }
5818
+ }
5800
5819
  }
5820
+ break loop;
5801
5821
  }
5802
- }
5803
- return 0;
5822
+ return n;
5804
5823
  }
5805
5824
  *pushTag() {
5806
5825
  if (this.charAt(1) === "<") {
@@ -5951,6 +5970,13 @@ var require_parser = __commonJS2((exports) => {
5951
5970
  while (prev[++i]?.type === "space") {}
5952
5971
  return prev.splice(i, prev.length);
5953
5972
  }
5973
+ function arrayPushArray(target, source) {
5974
+ if (source.length < 1e5)
5975
+ Array.prototype.push.apply(target, source);
5976
+ else
5977
+ for (let i = 0;i < source.length; ++i)
5978
+ target.push(source[i]);
5979
+ }
5954
5980
  function fixFlowSeqItems(fc) {
5955
5981
  if (fc.start.type === "flow-seq-start") {
5956
5982
  for (const it of fc.items) {
@@ -5960,11 +5986,11 @@ var require_parser = __commonJS2((exports) => {
5960
5986
  delete it.key;
5961
5987
  if (isFlowToken(it.value)) {
5962
5988
  if (it.value.end)
5963
- Array.prototype.push.apply(it.value.end, it.sep);
5989
+ arrayPushArray(it.value.end, it.sep);
5964
5990
  else
5965
5991
  it.value.end = it.sep;
5966
5992
  } else
5967
- Array.prototype.push.apply(it.start, it.sep);
5993
+ arrayPushArray(it.start, it.sep);
5968
5994
  delete it.sep;
5969
5995
  }
5970
5996
  }
@@ -6304,7 +6330,7 @@ var require_parser = __commonJS2((exports) => {
6304
6330
  const prev = map.items[map.items.length - 2];
6305
6331
  const end = prev?.value?.end;
6306
6332
  if (Array.isArray(end)) {
6307
- Array.prototype.push.apply(end, it.start);
6333
+ arrayPushArray(end, it.start);
6308
6334
  end.push(this.sourceToken);
6309
6335
  map.items.pop();
6310
6336
  return;
@@ -6492,7 +6518,7 @@ var require_parser = __commonJS2((exports) => {
6492
6518
  const prev = seq.items[seq.items.length - 2];
6493
6519
  const end = prev?.value?.end;
6494
6520
  if (Array.isArray(end)) {
6495
- Array.prototype.push.apply(end, it.start);
6521
+ arrayPushArray(end, it.start);
6496
6522
  end.push(this.sourceToken);
6497
6523
  seq.items.pop();
6498
6524
  return;
@@ -6886,6 +6912,7 @@ var PIPELINE_PROVIDER_CHOICES = [
6886
6912
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
6887
6913
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
6888
6914
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
6915
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
6889
6916
  var MEMORIES_FTS_TOKENIZER = "unicode61";
6890
6917
  function normalizeSql(sql) {
6891
6918
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -9983,6 +10010,243 @@ function up92(db) {
9983
10010
  ON embeddings_staging(agent_id, source_type, source_id);
9984
10011
  `);
9985
10012
  }
10013
+ function up93(db) {
10014
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10015
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
10016
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
10017
+ }
10018
+ }
10019
+ var DERIVED_SOURCE_TYPES = DAEMON_DERIVED_MEMORY_SOURCE_TYPES;
10020
+ function hasColumn13(db, table, column) {
10021
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10022
+ return rows.some((r) => r.name === column);
10023
+ }
10024
+ function up94(db) {
10025
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
10026
+ if (tables.length === 0)
10027
+ return;
10028
+ if (!hasColumn13(db, "memories", "memory_kind")) {
10029
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
10030
+ }
10031
+ if (!hasColumn13(db, "memories", "evidence_meta")) {
10032
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
10033
+ }
10034
+ if (hasColumn13(db, "memories", "source_type")) {
10035
+ const placeholders = DERIVED_SOURCE_TYPES.map(() => "?").join(", ");
10036
+ db.prepare(`UPDATE memories
10037
+ SET memory_kind = 'episodic'
10038
+ WHERE memory_kind IS NULL
10039
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES);
10040
+ } else {
10041
+ db.exec(`UPDATE memories
10042
+ SET memory_kind = 'episodic'
10043
+ WHERE memory_kind IS NULL`);
10044
+ }
10045
+ }
10046
+ function hasColumn14(db, table, column) {
10047
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10048
+ }
10049
+ function up95(db) {
10050
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
10051
+ if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
10052
+ return;
10053
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
10054
+ }
10055
+ function up96(db) {
10056
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
10057
+ }
10058
+ function up97(db) {
10059
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10060
+ if (!columns.some((column) => column.name === "last_failure_at")) {
10061
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
10062
+ }
10063
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
10064
+ }
10065
+ function up98(db) {
10066
+ db.exec(`
10067
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
10068
+ agent_id TEXT NOT NULL,
10069
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
10070
+ source_id TEXT NOT NULL,
10071
+ reason TEXT NOT NULL,
10072
+ pass_id TEXT NOT NULL,
10073
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
10074
+ requeue_requested_at TEXT,
10075
+ resolved_at TEXT,
10076
+ PRIMARY KEY (agent_id, source_kind, source_id)
10077
+ );
10078
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
10079
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
10080
+ `);
10081
+ }
10082
+ function up99(db) {
10083
+ db.exec(`
10084
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
10085
+ id TEXT PRIMARY KEY,
10086
+ agent_id TEXT NOT NULL,
10087
+ pass_id TEXT NOT NULL,
10088
+ sequence INTEGER NOT NULL,
10089
+ tool_call_id TEXT,
10090
+ tool_name TEXT NOT NULL,
10091
+ input_json TEXT NOT NULL,
10092
+ output_json TEXT NOT NULL,
10093
+ success INTEGER NOT NULL,
10094
+ latency_ms INTEGER NOT NULL,
10095
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10096
+ UNIQUE(agent_id, pass_id, sequence)
10097
+ );
10098
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
10099
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
10100
+ `);
10101
+ }
10102
+ function up100(db) {
10103
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
10104
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
10105
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
10106
+ }
10107
+ if (!columns.some((column) => column.name === "runbook_json")) {
10108
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
10109
+ }
10110
+ }
10111
+ function up101(db) {
10112
+ db.exec(`
10113
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
10114
+ id TEXT PRIMARY KEY,
10115
+ agent_id TEXT NOT NULL,
10116
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
10117
+ subject_ref TEXT NOT NULL,
10118
+ details_json TEXT NOT NULL DEFAULT '{}',
10119
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
10120
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10121
+ generation INTEGER NOT NULL DEFAULT 0,
10122
+ resolved_at TEXT,
10123
+ resolved_by_pass_id TEXT,
10124
+ UNIQUE(agent_id, kind, subject_ref)
10125
+ );
10126
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
10127
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
10128
+ `);
10129
+ }
10130
+ function hasColumn15(db, table, column) {
10131
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10132
+ }
10133
+ function up102(db) {
10134
+ const requiredMemoryColumns = [
10135
+ "content_hash",
10136
+ "normalized_content",
10137
+ "memory_kind",
10138
+ "source_type",
10139
+ "source_path",
10140
+ "agent_id",
10141
+ "visibility",
10142
+ "is_deleted",
10143
+ "extraction_status"
10144
+ ];
10145
+ if (!hasColumn15(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn15(db, "memories", column))) {
10146
+ return;
10147
+ }
10148
+ db.exec(`
10149
+ INSERT OR IGNORE INTO memories
10150
+ (id, content, normalized_content, content_hash, who, why, project,
10151
+ importance, type, tags, pinned, is_deleted, extraction_status,
10152
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
10153
+ agent_id, visibility, memory_kind)
10154
+ SELECT attr.id, attr.content, attr.normalized_content,
10155
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
10156
+ attr.importance, 'semantic', 'semantic,attribute', 0,
10157
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
10158
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
10159
+ attr.agent_id, 'global', 'derived'
10160
+ FROM entity_attributes attr
10161
+ WHERE attr.memory_id IS NULL
10162
+ `);
10163
+ db.exec(`
10164
+ UPDATE entity_attributes
10165
+ SET memory_id = id
10166
+ WHERE memory_id IS NULL
10167
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
10168
+ `);
10169
+ db.exec(`
10170
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
10171
+ SELECT attr.memory_id, aspect.entity_id
10172
+ FROM entity_attributes attr
10173
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
10174
+ WHERE attr.memory_id IS NOT NULL
10175
+ `);
10176
+ db.exec(`
10177
+ UPDATE entities
10178
+ SET mentions = (
10179
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
10180
+ )
10181
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
10182
+ `);
10183
+ }
10184
+ function up103(db) {
10185
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
10186
+ if (tables.length !== 2)
10187
+ return;
10188
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
10189
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
10190
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
10191
+ return;
10192
+ db.exec(`
10193
+ UPDATE memories
10194
+ SET memory_kind = 'derived'
10195
+ WHERE memory_kind IS NULL
10196
+ AND id IN (
10197
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
10198
+ )
10199
+ `);
10200
+ }
10201
+ function tableExists(db, table) {
10202
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
10203
+ }
10204
+ function hasColumn16(db, table, column) {
10205
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10206
+ }
10207
+ function up104(db) {
10208
+ db.exec(`
10209
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
10210
+ derived_memory_id TEXT NOT NULL,
10211
+ source_kind TEXT NOT NULL,
10212
+ source_id TEXT NOT NULL,
10213
+ source_path TEXT,
10214
+ agent_id TEXT NOT NULL,
10215
+ created_at TEXT NOT NULL,
10216
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
10217
+ );
10218
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
10219
+ ON derived_memory_sources(agent_id, derived_memory_id);
10220
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
10221
+ ON derived_memory_sources(agent_id, source_kind, source_id);
10222
+ `);
10223
+ if (tableExists(db, "aggregate_evidence_sources")) {
10224
+ db.exec(`
10225
+ INSERT OR IGNORE INTO derived_memory_sources
10226
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10227
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
10228
+ FROM aggregate_evidence_sources
10229
+ `);
10230
+ }
10231
+ if (tableExists(db, "aggregate_memory_sources")) {
10232
+ db.exec(`
10233
+ INSERT OR IGNORE INTO derived_memory_sources
10234
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10235
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
10236
+ FROM aggregate_memory_sources
10237
+ `);
10238
+ }
10239
+ if (tableExists(db, "memories") && !hasColumn16(db, "memories", "stale_at")) {
10240
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
10241
+ }
10242
+ if (tableExists(db, "memories")) {
10243
+ db.exec(`
10244
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
10245
+ ON memories(agent_id, stale_at)
10246
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
10247
+ `);
10248
+ }
10249
+ }
9986
10250
  var MIGRATIONS = [
9987
10251
  {
9988
10252
  version: 1,
@@ -10067,7 +10331,6 @@ var MIGRATIONS = [
10067
10331
  name: "ingestion-tracking",
10068
10332
  up: up13,
10069
10333
  artifacts: {
10070
- tables: ["ingestion_jobs"],
10071
10334
  columns: [
10072
10335
  { table: "memories", column: "source_path" },
10073
10336
  { table: "memories", column: "source_section" }
@@ -10730,6 +10993,87 @@ var MIGRATIONS = [
10730
10993
  name: "embedding-staging-store",
10731
10994
  up: up92,
10732
10995
  artifacts: { tables: ["embeddings_staging"] }
10996
+ },
10997
+ {
10998
+ version: 93,
10999
+ name: "dreaming-evidence-cursor",
11000
+ up: up93,
11001
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
11002
+ },
11003
+ {
11004
+ version: 94,
11005
+ name: "memory-kind",
11006
+ up: up94,
11007
+ artifacts: {
11008
+ columns: [
11009
+ { table: "memories", column: "memory_kind" },
11010
+ { table: "memories", column: "evidence_meta" }
11011
+ ]
11012
+ }
11013
+ },
11014
+ {
11015
+ version: 95,
11016
+ name: "compaction-recall-projections",
11017
+ up: up95
11018
+ },
11019
+ {
11020
+ version: 96,
11021
+ name: "retire-legacy-ingestion",
11022
+ up: up96
11023
+ },
11024
+ {
11025
+ version: 97,
11026
+ name: "dreaming-failure-backoff",
11027
+ up: up97,
11028
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
11029
+ },
11030
+ {
11031
+ version: 98,
11032
+ name: "dreaming-evidence-exclusions",
11033
+ up: up98,
11034
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
11035
+ },
11036
+ {
11037
+ version: 99,
11038
+ name: "dreaming-tool-calls",
11039
+ up: up99,
11040
+ artifacts: { tables: ["dreaming_tool_calls"] }
11041
+ },
11042
+ {
11043
+ version: 100,
11044
+ name: "dreaming-runbook",
11045
+ up: up100,
11046
+ artifacts: {
11047
+ columns: [
11048
+ { table: "dreaming_passes", column: "evidence_window_json" },
11049
+ { table: "dreaming_passes", column: "runbook_json" }
11050
+ ]
11051
+ }
11052
+ },
11053
+ {
11054
+ version: 101,
11055
+ name: "dreaming-attention",
11056
+ up: up101,
11057
+ artifacts: { tables: ["dreaming_attention"] }
11058
+ },
11059
+ {
11060
+ version: 102,
11061
+ name: "attribute-semantic-memories",
11062
+ up: up102
11063
+ },
11064
+ {
11065
+ version: 103,
11066
+ name: "semantic-memory-kind",
11067
+ up: up103
11068
+ },
11069
+ {
11070
+ version: 104,
11071
+ name: "derived-memory-provenance",
11072
+ up: up104,
11073
+ artifacts: {
11074
+ tables: ["derived_memory_sources"],
11075
+ columns: [{ table: "memories", column: "stale_at" }]
11076
+ }
10733
11077
  }
10734
11078
  ];
10735
11079
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -10957,122 +11301,6 @@ function stripSignetBlock(content) {
10957
11301
  function escapeRegex(str) {
10958
11302
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10959
11303
  }
10960
- var SKIP_SUBTYPES = new Set([
10961
- "channel_join",
10962
- "channel_leave",
10963
- "channel_topic",
10964
- "channel_purpose",
10965
- "channel_name",
10966
- "channel_archive",
10967
- "channel_unarchive",
10968
- "group_join",
10969
- "group_leave",
10970
- "group_topic",
10971
- "group_purpose",
10972
- "group_name",
10973
- "group_archive",
10974
- "group_unarchive",
10975
- "pinned_item",
10976
- "unpinned_item",
10977
- "bot_add",
10978
- "bot_remove",
10979
- "tombstone",
10980
- "file_comment",
10981
- "sh_room_created",
10982
- "sh_room_shared"
10983
- ]);
10984
- var SKIP_TYPES = new Set([
10985
- "RecipientAdd",
10986
- "RecipientRemove",
10987
- "ChannelNameChange",
10988
- "ChannelIconChange",
10989
- "ChannelPinnedMessage",
10990
- "GuildMemberJoin",
10991
- "UserPremiumGuildSubscription",
10992
- "UserPremiumGuildSubscriptionTier1",
10993
- "UserPremiumGuildSubscriptionTier2",
10994
- "UserPremiumGuildSubscriptionTier3",
10995
- "ChannelFollowAdd",
10996
- "GuildDiscoveryDisqualified",
10997
- "GuildDiscoveryRequalified",
10998
- "GuildDiscoveryGracePeriodInitialWarning",
10999
- "GuildDiscoveryGracePeriodFinalWarning",
11000
- "ThreadCreated",
11001
- "ApplicationCommand"
11002
- ]);
11003
- var SKIP_DIRS = new Set([
11004
- "node_modules",
11005
- ".git",
11006
- "dist",
11007
- "build",
11008
- "out",
11009
- "target",
11010
- ".next",
11011
- ".nuxt",
11012
- "__pycache__",
11013
- ".tox",
11014
- ".mypy_cache",
11015
- ".pytest_cache",
11016
- "venv",
11017
- ".venv",
11018
- "env",
11019
- "vendor",
11020
- "coverage",
11021
- ".cache",
11022
- ".turbo"
11023
- ]);
11024
- var DOCUMENT_VALID_TYPES = new Set([
11025
- "fact",
11026
- "decision",
11027
- "rationale",
11028
- "preference",
11029
- "procedural",
11030
- "semantic",
11031
- "system",
11032
- "configuration",
11033
- "architectural",
11034
- "relationship",
11035
- "episodic",
11036
- "daily-log"
11037
- ]);
11038
- var ENTIRE_VALID_TYPES = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
11039
- var CHAT_VALID_TYPES = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
11040
- var MARKDOWN_EXTS = new Set([".md", ".mdx", ".markdown"]);
11041
- var TXT_EXTS = new Set([".txt", ".text", ".log", ".rst"]);
11042
- var PDF_EXTS = new Set([".pdf"]);
11043
- var CODE_EXTS = new Set([
11044
- ".ts",
11045
- ".tsx",
11046
- ".js",
11047
- ".jsx",
11048
- ".py",
11049
- ".rs",
11050
- ".go",
11051
- ".java",
11052
- ".rb",
11053
- ".php",
11054
- ".swift",
11055
- ".kt",
11056
- ".scala",
11057
- ".c",
11058
- ".cpp",
11059
- ".h",
11060
- ".hpp",
11061
- ".sh",
11062
- ".bash",
11063
- ".zsh",
11064
- ".sql",
11065
- ".yaml",
11066
- ".yml",
11067
- ".toml",
11068
- ".json",
11069
- ".xml",
11070
- ".css",
11071
- ".scss",
11072
- ".html",
11073
- ".htm"
11074
- ]);
11075
- var SKIP_FILES = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
11076
11304
 
11077
11305
  class BaseConnector {
11078
11306
  stripSignetBlock(content) {
@@ -13729,6 +13957,8 @@ var require_Alias2 = __commonJS3((exports) => {
13729
13957
  });
13730
13958
  }
13731
13959
  resolve(doc, ctx) {
13960
+ if (ctx?.maxAliasCount === 0)
13961
+ throw new ReferenceError("Alias resolution is disabled");
13732
13962
  let nodes;
13733
13963
  if (ctx?.aliasResolveCache) {
13734
13964
  nodes = ctx.aliasResolveCache;
@@ -14758,18 +14988,18 @@ var require_merge2 = __commonJS3((exports) => {
14758
14988
  };
14759
14989
  var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
14760
14990
  function addMergeToJSMap(ctx, map, value) {
14761
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
14762
- if (identity.isSeq(value))
14763
- for (const it of value.items)
14991
+ const source = resolveAliasValue(ctx, value);
14992
+ if (identity.isSeq(source))
14993
+ for (const it of source.items)
14764
14994
  mergeValue(ctx, map, it);
14765
- else if (Array.isArray(value))
14766
- for (const it of value)
14995
+ else if (Array.isArray(source))
14996
+ for (const it of source)
14767
14997
  mergeValue(ctx, map, it);
14768
14998
  else
14769
- mergeValue(ctx, map, value);
14999
+ mergeValue(ctx, map, source);
14770
15000
  }
14771
15001
  function mergeValue(ctx, map, value) {
14772
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
15002
+ const source = resolveAliasValue(ctx, value);
14773
15003
  if (!identity.isMap(source))
14774
15004
  throw new Error("Merge sources must be maps or map aliases");
14775
15005
  const srcMap = source.toJSON(null, ctx, Map);
@@ -14790,6 +15020,9 @@ var require_merge2 = __commonJS3((exports) => {
14790
15020
  }
14791
15021
  return map;
14792
15022
  }
15023
+ function resolveAliasValue(ctx, value) {
15024
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
15025
+ }
14793
15026
  exports.addMergeToJSMap = addMergeToJSMap;
14794
15027
  exports.isMergeKey = isMergeKey;
14795
15028
  exports.merge = merge;
@@ -15343,7 +15576,7 @@ var require_stringifyNumber2 = __commonJS3((exports) => {
15343
15576
  if (!isFinite(num))
15344
15577
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
15345
15578
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
15346
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
15579
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
15347
15580
  let i = n.indexOf(".");
15348
15581
  if (i < 0) {
15349
15582
  i = n.length;
@@ -17511,7 +17744,7 @@ var require_resolve_flow_scalar2 = __commonJS3((exports) => {
17511
17744
  while (next === " " || next === "\t")
17512
17745
  next = source[++i + 1];
17513
17746
  } else if (next === "x" || next === "u" || next === "U") {
17514
- const length = { x: 2, u: 4, U: 8 }[next];
17747
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
17515
17748
  res += parseCharCode(source, i + 1, length, onError);
17516
17749
  i += length;
17517
17750
  } else {
@@ -17580,12 +17813,13 @@ var require_resolve_flow_scalar2 = __commonJS3((exports) => {
17580
17813
  const cc = source.substr(offset, length);
17581
17814
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
17582
17815
  const code = ok ? parseInt(cc, 16) : NaN;
17583
- if (isNaN(code)) {
17816
+ try {
17817
+ return String.fromCodePoint(code);
17818
+ } catch {
17584
17819
  const raw = source.substr(offset - 2, length + 2);
17585
17820
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
17586
17821
  return raw;
17587
17822
  }
17588
- return String.fromCodePoint(code);
17589
17823
  }
17590
17824
  exports.resolveFlowScalar = resolveFlowScalar;
17591
17825
  });
@@ -17914,8 +18148,10 @@ ${cb}` : comment;
17914
18148
  }
17915
18149
  }
17916
18150
  if (afterDoc) {
17917
- Array.prototype.push.apply(doc.errors, this.errors);
17918
- Array.prototype.push.apply(doc.warnings, this.warnings);
18151
+ for (let i = 0;i < this.errors.length; ++i)
18152
+ doc.errors.push(this.errors[i]);
18153
+ for (let i = 0;i < this.warnings.length; ++i)
18154
+ doc.warnings.push(this.warnings[i]);
17919
18155
  } else {
17920
18156
  doc.errors = this.errors;
17921
18157
  doc.warnings = this.warnings;
@@ -18617,7 +18853,7 @@ var require_lexer2 = __commonJS3((exports) => {
18617
18853
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
18618
18854
  this.indentNext = this.indentValue + 1;
18619
18855
  this.indentValue += n;
18620
- return yield* this.parseBlockStart();
18856
+ return "block-start";
18621
18857
  }
18622
18858
  return "doc";
18623
18859
  }
@@ -18924,26 +19160,37 @@ var require_lexer2 = __commonJS3((exports) => {
18924
19160
  return 0;
18925
19161
  }
18926
19162
  *pushIndicators() {
18927
- switch (this.charAt(0)) {
18928
- case "!":
18929
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
18930
- case "&":
18931
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
18932
- case "-":
18933
- case "?":
18934
- case ":": {
18935
- const inFlow = this.flowLevel > 0;
18936
- const ch1 = this.charAt(1);
18937
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
18938
- if (!inFlow)
18939
- this.indentNext = this.indentValue + 1;
18940
- else if (this.flowKey)
18941
- this.flowKey = false;
18942
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
19163
+ let n = 0;
19164
+ loop:
19165
+ while (true) {
19166
+ switch (this.charAt(0)) {
19167
+ case "!":
19168
+ n += yield* this.pushTag();
19169
+ n += yield* this.pushSpaces(true);
19170
+ continue loop;
19171
+ case "&":
19172
+ n += yield* this.pushUntil(isNotAnchorChar);
19173
+ n += yield* this.pushSpaces(true);
19174
+ continue loop;
19175
+ case "-":
19176
+ case "?":
19177
+ case ":": {
19178
+ const inFlow = this.flowLevel > 0;
19179
+ const ch1 = this.charAt(1);
19180
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
19181
+ if (!inFlow)
19182
+ this.indentNext = this.indentValue + 1;
19183
+ else if (this.flowKey)
19184
+ this.flowKey = false;
19185
+ n += yield* this.pushCount(1);
19186
+ n += yield* this.pushSpaces(true);
19187
+ continue loop;
19188
+ }
19189
+ }
18943
19190
  }
19191
+ break loop;
18944
19192
  }
18945
- }
18946
- return 0;
19193
+ return n;
18947
19194
  }
18948
19195
  *pushTag() {
18949
19196
  if (this.charAt(1) === "<") {
@@ -19094,6 +19341,13 @@ var require_parser2 = __commonJS3((exports) => {
19094
19341
  while (prev[++i]?.type === "space") {}
19095
19342
  return prev.splice(i, prev.length);
19096
19343
  }
19344
+ function arrayPushArray(target, source) {
19345
+ if (source.length < 1e5)
19346
+ Array.prototype.push.apply(target, source);
19347
+ else
19348
+ for (let i = 0;i < source.length; ++i)
19349
+ target.push(source[i]);
19350
+ }
19097
19351
  function fixFlowSeqItems(fc) {
19098
19352
  if (fc.start.type === "flow-seq-start") {
19099
19353
  for (const it of fc.items) {
@@ -19103,11 +19357,11 @@ var require_parser2 = __commonJS3((exports) => {
19103
19357
  delete it.key;
19104
19358
  if (isFlowToken(it.value)) {
19105
19359
  if (it.value.end)
19106
- Array.prototype.push.apply(it.value.end, it.sep);
19360
+ arrayPushArray(it.value.end, it.sep);
19107
19361
  else
19108
19362
  it.value.end = it.sep;
19109
19363
  } else
19110
- Array.prototype.push.apply(it.start, it.sep);
19364
+ arrayPushArray(it.start, it.sep);
19111
19365
  delete it.sep;
19112
19366
  }
19113
19367
  }
@@ -19447,7 +19701,7 @@ var require_parser2 = __commonJS3((exports) => {
19447
19701
  const prev = map.items[map.items.length - 2];
19448
19702
  const end = prev?.value?.end;
19449
19703
  if (Array.isArray(end)) {
19450
- Array.prototype.push.apply(end, it.start);
19704
+ arrayPushArray(end, it.start);
19451
19705
  end.push(this.sourceToken);
19452
19706
  map.items.pop();
19453
19707
  return;
@@ -19635,7 +19889,7 @@ var require_parser2 = __commonJS3((exports) => {
19635
19889
  const prev = seq.items[seq.items.length - 2];
19636
19890
  const end = prev?.value?.end;
19637
19891
  if (Array.isArray(end)) {
19638
- Array.prototype.push.apply(end, it.start);
19892
+ arrayPushArray(end, it.start);
19639
19893
  end.push(this.sourceToken);
19640
19894
  seq.items.pop();
19641
19895
  return;
@@ -20029,6 +20283,7 @@ var PIPELINE_PROVIDER_CHOICES2 = [
20029
20283
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
20030
20284
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
20031
20285
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
20286
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
20032
20287
  var MEMORIES_FTS_TOKENIZER2 = "unicode61";
20033
20288
  function normalizeSql2(sql) {
20034
20289
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -20079,7 +20334,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
20079
20334
  return true;
20080
20335
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
20081
20336
  }
20082
- function up93(db) {
20337
+ function up105(db) {
20083
20338
  db.exec(`
20084
20339
  CREATE TABLE IF NOT EXISTS schema_migrations (
20085
20340
  version INTEGER PRIMARY KEY,
@@ -20168,12 +20423,12 @@ function up93(db) {
20168
20423
  } catch {}
20169
20424
  createMemoriesFts2(db);
20170
20425
  }
20171
- function hasColumn13(db, table, column) {
20426
+ function hasColumn17(db, table, column) {
20172
20427
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
20173
20428
  return rows.some((r) => r.name === column);
20174
20429
  }
20175
20430
  function addColumnIfMissing23(db, table, column, definition) {
20176
- if (!hasColumn13(db, table, column)) {
20431
+ if (!hasColumn17(db, table, column)) {
20177
20432
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
20178
20433
  }
20179
20434
  }
@@ -20471,7 +20726,7 @@ function up810(db) {
20471
20726
  ON embeddings(content_hash)
20472
20727
  `);
20473
20728
  }
20474
- function up94(db) {
20729
+ function up910(db) {
20475
20730
  db.exec(`
20476
20731
  CREATE TABLE IF NOT EXISTS summary_jobs (
20477
20732
  id TEXT PRIMARY KEY,
@@ -20491,7 +20746,7 @@ function up94(db) {
20491
20746
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
20492
20747
  ON summary_jobs(status)`);
20493
20748
  }
20494
- function up102(db) {
20749
+ function up106(db) {
20495
20750
  db.exec(`
20496
20751
  CREATE TABLE IF NOT EXISTS umap_cache (
20497
20752
  id INTEGER PRIMARY KEY,
@@ -23126,11 +23381,248 @@ function up922(db) {
23126
23381
  ON embeddings_staging(agent_id, source_type, source_id);
23127
23382
  `);
23128
23383
  }
23384
+ function up932(db) {
23385
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
23386
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
23387
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
23388
+ }
23389
+ }
23390
+ var DERIVED_SOURCE_TYPES2 = DAEMON_DERIVED_MEMORY_SOURCE_TYPES2;
23391
+ function hasColumn132(db, table, column) {
23392
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
23393
+ return rows.some((r) => r.name === column);
23394
+ }
23395
+ function up942(db) {
23396
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
23397
+ if (tables.length === 0)
23398
+ return;
23399
+ if (!hasColumn132(db, "memories", "memory_kind")) {
23400
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
23401
+ }
23402
+ if (!hasColumn132(db, "memories", "evidence_meta")) {
23403
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
23404
+ }
23405
+ if (hasColumn132(db, "memories", "source_type")) {
23406
+ const placeholders = DERIVED_SOURCE_TYPES2.map(() => "?").join(", ");
23407
+ db.prepare(`UPDATE memories
23408
+ SET memory_kind = 'episodic'
23409
+ WHERE memory_kind IS NULL
23410
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES2);
23411
+ } else {
23412
+ db.exec(`UPDATE memories
23413
+ SET memory_kind = 'episodic'
23414
+ WHERE memory_kind IS NULL`);
23415
+ }
23416
+ }
23417
+ function hasColumn142(db, table, column) {
23418
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
23419
+ }
23420
+ function up952(db) {
23421
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
23422
+ if (!hasMemories || !hasColumn142(db, "memories", "memory_kind") || !hasColumn142(db, "memories", "type"))
23423
+ return;
23424
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
23425
+ }
23426
+ function up962(db) {
23427
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
23428
+ }
23429
+ function up972(db) {
23430
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
23431
+ if (!columns.some((column) => column.name === "last_failure_at")) {
23432
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
23433
+ }
23434
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
23435
+ }
23436
+ function up982(db) {
23437
+ db.exec(`
23438
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
23439
+ agent_id TEXT NOT NULL,
23440
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
23441
+ source_id TEXT NOT NULL,
23442
+ reason TEXT NOT NULL,
23443
+ pass_id TEXT NOT NULL,
23444
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
23445
+ requeue_requested_at TEXT,
23446
+ resolved_at TEXT,
23447
+ PRIMARY KEY (agent_id, source_kind, source_id)
23448
+ );
23449
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
23450
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
23451
+ `);
23452
+ }
23453
+ function up992(db) {
23454
+ db.exec(`
23455
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
23456
+ id TEXT PRIMARY KEY,
23457
+ agent_id TEXT NOT NULL,
23458
+ pass_id TEXT NOT NULL,
23459
+ sequence INTEGER NOT NULL,
23460
+ tool_call_id TEXT,
23461
+ tool_name TEXT NOT NULL,
23462
+ input_json TEXT NOT NULL,
23463
+ output_json TEXT NOT NULL,
23464
+ success INTEGER NOT NULL,
23465
+ latency_ms INTEGER NOT NULL,
23466
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
23467
+ UNIQUE(agent_id, pass_id, sequence)
23468
+ );
23469
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
23470
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
23471
+ `);
23472
+ }
23473
+ function up1002(db) {
23474
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
23475
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
23476
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
23477
+ }
23478
+ if (!columns.some((column) => column.name === "runbook_json")) {
23479
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
23480
+ }
23481
+ }
23482
+ function up1012(db) {
23483
+ db.exec(`
23484
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
23485
+ id TEXT PRIMARY KEY,
23486
+ agent_id TEXT NOT NULL,
23487
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
23488
+ subject_ref TEXT NOT NULL,
23489
+ details_json TEXT NOT NULL DEFAULT '{}',
23490
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
23491
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
23492
+ generation INTEGER NOT NULL DEFAULT 0,
23493
+ resolved_at TEXT,
23494
+ resolved_by_pass_id TEXT,
23495
+ UNIQUE(agent_id, kind, subject_ref)
23496
+ );
23497
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
23498
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
23499
+ `);
23500
+ }
23501
+ function hasColumn152(db, table, column) {
23502
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
23503
+ }
23504
+ function up1022(db) {
23505
+ const requiredMemoryColumns = [
23506
+ "content_hash",
23507
+ "normalized_content",
23508
+ "memory_kind",
23509
+ "source_type",
23510
+ "source_path",
23511
+ "agent_id",
23512
+ "visibility",
23513
+ "is_deleted",
23514
+ "extraction_status"
23515
+ ];
23516
+ if (!hasColumn152(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn152(db, "memories", column))) {
23517
+ return;
23518
+ }
23519
+ db.exec(`
23520
+ INSERT OR IGNORE INTO memories
23521
+ (id, content, normalized_content, content_hash, who, why, project,
23522
+ importance, type, tags, pinned, is_deleted, extraction_status,
23523
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
23524
+ agent_id, visibility, memory_kind)
23525
+ SELECT attr.id, attr.content, attr.normalized_content,
23526
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
23527
+ attr.importance, 'semantic', 'semantic,attribute', 0,
23528
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
23529
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
23530
+ attr.agent_id, 'global', 'derived'
23531
+ FROM entity_attributes attr
23532
+ WHERE attr.memory_id IS NULL
23533
+ `);
23534
+ db.exec(`
23535
+ UPDATE entity_attributes
23536
+ SET memory_id = id
23537
+ WHERE memory_id IS NULL
23538
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
23539
+ `);
23540
+ db.exec(`
23541
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
23542
+ SELECT attr.memory_id, aspect.entity_id
23543
+ FROM entity_attributes attr
23544
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
23545
+ WHERE attr.memory_id IS NOT NULL
23546
+ `);
23547
+ db.exec(`
23548
+ UPDATE entities
23549
+ SET mentions = (
23550
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
23551
+ )
23552
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
23553
+ `);
23554
+ }
23555
+ function up1032(db) {
23556
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
23557
+ if (tables.length !== 2)
23558
+ return;
23559
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
23560
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
23561
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
23562
+ return;
23563
+ db.exec(`
23564
+ UPDATE memories
23565
+ SET memory_kind = 'derived'
23566
+ WHERE memory_kind IS NULL
23567
+ AND id IN (
23568
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
23569
+ )
23570
+ `);
23571
+ }
23572
+ function tableExists2(db, table) {
23573
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
23574
+ }
23575
+ function hasColumn162(db, table, column) {
23576
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
23577
+ }
23578
+ function up1042(db) {
23579
+ db.exec(`
23580
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
23581
+ derived_memory_id TEXT NOT NULL,
23582
+ source_kind TEXT NOT NULL,
23583
+ source_id TEXT NOT NULL,
23584
+ source_path TEXT,
23585
+ agent_id TEXT NOT NULL,
23586
+ created_at TEXT NOT NULL,
23587
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
23588
+ );
23589
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
23590
+ ON derived_memory_sources(agent_id, derived_memory_id);
23591
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
23592
+ ON derived_memory_sources(agent_id, source_kind, source_id);
23593
+ `);
23594
+ if (tableExists2(db, "aggregate_evidence_sources")) {
23595
+ db.exec(`
23596
+ INSERT OR IGNORE INTO derived_memory_sources
23597
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
23598
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
23599
+ FROM aggregate_evidence_sources
23600
+ `);
23601
+ }
23602
+ if (tableExists2(db, "aggregate_memory_sources")) {
23603
+ db.exec(`
23604
+ INSERT OR IGNORE INTO derived_memory_sources
23605
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
23606
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
23607
+ FROM aggregate_memory_sources
23608
+ `);
23609
+ }
23610
+ if (tableExists2(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
23611
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
23612
+ }
23613
+ if (tableExists2(db, "memories")) {
23614
+ db.exec(`
23615
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
23616
+ ON memories(agent_id, stale_at)
23617
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
23618
+ `);
23619
+ }
23620
+ }
23129
23621
  var MIGRATIONS2 = [
23130
23622
  {
23131
23623
  version: 1,
23132
23624
  name: "baseline",
23133
- up: up93,
23625
+ up: up105,
23134
23626
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
23135
23627
  },
23136
23628
  {
@@ -23184,13 +23676,13 @@ var MIGRATIONS2 = [
23184
23676
  {
23185
23677
  version: 9,
23186
23678
  name: "summary-jobs",
23187
- up: up94,
23679
+ up: up910,
23188
23680
  artifacts: { tables: ["summary_jobs"] }
23189
23681
  },
23190
23682
  {
23191
23683
  version: 10,
23192
23684
  name: "umap-cache",
23193
- up: up102,
23685
+ up: up106,
23194
23686
  artifacts: { tables: ["umap_cache"] }
23195
23687
  },
23196
23688
  {
@@ -23210,7 +23702,6 @@ var MIGRATIONS2 = [
23210
23702
  name: "ingestion-tracking",
23211
23703
  up: up132,
23212
23704
  artifacts: {
23213
- tables: ["ingestion_jobs"],
23214
23705
  columns: [
23215
23706
  { table: "memories", column: "source_path" },
23216
23707
  { table: "memories", column: "source_section" }
@@ -23873,6 +24364,87 @@ var MIGRATIONS2 = [
23873
24364
  name: "embedding-staging-store",
23874
24365
  up: up922,
23875
24366
  artifacts: { tables: ["embeddings_staging"] }
24367
+ },
24368
+ {
24369
+ version: 93,
24370
+ name: "dreaming-evidence-cursor",
24371
+ up: up932,
24372
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
24373
+ },
24374
+ {
24375
+ version: 94,
24376
+ name: "memory-kind",
24377
+ up: up942,
24378
+ artifacts: {
24379
+ columns: [
24380
+ { table: "memories", column: "memory_kind" },
24381
+ { table: "memories", column: "evidence_meta" }
24382
+ ]
24383
+ }
24384
+ },
24385
+ {
24386
+ version: 95,
24387
+ name: "compaction-recall-projections",
24388
+ up: up952
24389
+ },
24390
+ {
24391
+ version: 96,
24392
+ name: "retire-legacy-ingestion",
24393
+ up: up962
24394
+ },
24395
+ {
24396
+ version: 97,
24397
+ name: "dreaming-failure-backoff",
24398
+ up: up972,
24399
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
24400
+ },
24401
+ {
24402
+ version: 98,
24403
+ name: "dreaming-evidence-exclusions",
24404
+ up: up982,
24405
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
24406
+ },
24407
+ {
24408
+ version: 99,
24409
+ name: "dreaming-tool-calls",
24410
+ up: up992,
24411
+ artifacts: { tables: ["dreaming_tool_calls"] }
24412
+ },
24413
+ {
24414
+ version: 100,
24415
+ name: "dreaming-runbook",
24416
+ up: up1002,
24417
+ artifacts: {
24418
+ columns: [
24419
+ { table: "dreaming_passes", column: "evidence_window_json" },
24420
+ { table: "dreaming_passes", column: "runbook_json" }
24421
+ ]
24422
+ }
24423
+ },
24424
+ {
24425
+ version: 101,
24426
+ name: "dreaming-attention",
24427
+ up: up1012,
24428
+ artifacts: { tables: ["dreaming_attention"] }
24429
+ },
24430
+ {
24431
+ version: 102,
24432
+ name: "attribute-semantic-memories",
24433
+ up: up1022
24434
+ },
24435
+ {
24436
+ version: 103,
24437
+ name: "semantic-memory-kind",
24438
+ up: up1032
24439
+ },
24440
+ {
24441
+ version: 104,
24442
+ name: "derived-memory-provenance",
24443
+ up: up1042,
24444
+ artifacts: {
24445
+ tables: ["derived_memory_sources"],
24446
+ columns: [{ table: "memories", column: "stale_at" }]
24447
+ }
23876
24448
  }
23877
24449
  ];
23878
24450
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -24025,122 +24597,6 @@ var IDENTITY_FILES2 = {
24025
24597
  var REQUIRED_IDENTITY_KEYS2 = Object.entries(IDENTITY_FILES2).filter(([, spec]) => !spec.optional).map(([key]) => key);
24026
24598
  var OPTIONAL_IDENTITY_KEYS2 = Object.entries(IDENTITY_FILES2).filter(([, spec]) => spec.optional).map(([key]) => key);
24027
24599
  var home2 = homedir82();
24028
- var SKIP_SUBTYPES2 = new Set([
24029
- "channel_join",
24030
- "channel_leave",
24031
- "channel_topic",
24032
- "channel_purpose",
24033
- "channel_name",
24034
- "channel_archive",
24035
- "channel_unarchive",
24036
- "group_join",
24037
- "group_leave",
24038
- "group_topic",
24039
- "group_purpose",
24040
- "group_name",
24041
- "group_archive",
24042
- "group_unarchive",
24043
- "pinned_item",
24044
- "unpinned_item",
24045
- "bot_add",
24046
- "bot_remove",
24047
- "tombstone",
24048
- "file_comment",
24049
- "sh_room_created",
24050
- "sh_room_shared"
24051
- ]);
24052
- var SKIP_TYPES2 = new Set([
24053
- "RecipientAdd",
24054
- "RecipientRemove",
24055
- "ChannelNameChange",
24056
- "ChannelIconChange",
24057
- "ChannelPinnedMessage",
24058
- "GuildMemberJoin",
24059
- "UserPremiumGuildSubscription",
24060
- "UserPremiumGuildSubscriptionTier1",
24061
- "UserPremiumGuildSubscriptionTier2",
24062
- "UserPremiumGuildSubscriptionTier3",
24063
- "ChannelFollowAdd",
24064
- "GuildDiscoveryDisqualified",
24065
- "GuildDiscoveryRequalified",
24066
- "GuildDiscoveryGracePeriodInitialWarning",
24067
- "GuildDiscoveryGracePeriodFinalWarning",
24068
- "ThreadCreated",
24069
- "ApplicationCommand"
24070
- ]);
24071
- var SKIP_DIRS2 = new Set([
24072
- "node_modules",
24073
- ".git",
24074
- "dist",
24075
- "build",
24076
- "out",
24077
- "target",
24078
- ".next",
24079
- ".nuxt",
24080
- "__pycache__",
24081
- ".tox",
24082
- ".mypy_cache",
24083
- ".pytest_cache",
24084
- "venv",
24085
- ".venv",
24086
- "env",
24087
- "vendor",
24088
- "coverage",
24089
- ".cache",
24090
- ".turbo"
24091
- ]);
24092
- var DOCUMENT_VALID_TYPES2 = new Set([
24093
- "fact",
24094
- "decision",
24095
- "rationale",
24096
- "preference",
24097
- "procedural",
24098
- "semantic",
24099
- "system",
24100
- "configuration",
24101
- "architectural",
24102
- "relationship",
24103
- "episodic",
24104
- "daily-log"
24105
- ]);
24106
- var ENTIRE_VALID_TYPES2 = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
24107
- var CHAT_VALID_TYPES2 = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
24108
- var MARKDOWN_EXTS2 = new Set([".md", ".mdx", ".markdown"]);
24109
- var TXT_EXTS2 = new Set([".txt", ".text", ".log", ".rst"]);
24110
- var PDF_EXTS2 = new Set([".pdf"]);
24111
- var CODE_EXTS2 = new Set([
24112
- ".ts",
24113
- ".tsx",
24114
- ".js",
24115
- ".jsx",
24116
- ".py",
24117
- ".rs",
24118
- ".go",
24119
- ".java",
24120
- ".rb",
24121
- ".php",
24122
- ".swift",
24123
- ".kt",
24124
- ".scala",
24125
- ".c",
24126
- ".cpp",
24127
- ".h",
24128
- ".hpp",
24129
- ".sh",
24130
- ".bash",
24131
- ".zsh",
24132
- ".sql",
24133
- ".yaml",
24134
- ".yml",
24135
- ".toml",
24136
- ".json",
24137
- ".xml",
24138
- ".css",
24139
- ".scss",
24140
- ".html",
24141
- ".htm"
24142
- ]);
24143
- var SKIP_FILES2 = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
24144
24600
 
24145
24601
  // src/index.ts
24146
24602
  var OPENCLAW_PARSE_OPTIONS = { label: "OpenClaw config" };