@signetai/connector-hermes-agent 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
@@ -589,6 +589,8 @@ var require_Alias = __commonJS2((exports) => {
589
589
  });
590
590
  }
591
591
  resolve(doc, ctx) {
592
+ if (ctx?.maxAliasCount === 0)
593
+ throw new ReferenceError("Alias resolution is disabled");
592
594
  let nodes;
593
595
  if (ctx?.aliasResolveCache) {
594
596
  nodes = ctx.aliasResolveCache;
@@ -1618,18 +1620,18 @@ var require_merge = __commonJS2((exports) => {
1618
1620
  };
1619
1621
  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);
1620
1622
  function addMergeToJSMap(ctx, map, value) {
1621
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1622
- if (identity.isSeq(value))
1623
- for (const it of value.items)
1623
+ const source = resolveAliasValue(ctx, value);
1624
+ if (identity.isSeq(source))
1625
+ for (const it of source.items)
1624
1626
  mergeValue(ctx, map, it);
1625
- else if (Array.isArray(value))
1626
- for (const it of value)
1627
+ else if (Array.isArray(source))
1628
+ for (const it of source)
1627
1629
  mergeValue(ctx, map, it);
1628
1630
  else
1629
- mergeValue(ctx, map, value);
1631
+ mergeValue(ctx, map, source);
1630
1632
  }
1631
1633
  function mergeValue(ctx, map, value) {
1632
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1634
+ const source = resolveAliasValue(ctx, value);
1633
1635
  if (!identity.isMap(source))
1634
1636
  throw new Error("Merge sources must be maps or map aliases");
1635
1637
  const srcMap = source.toJSON(null, ctx, Map);
@@ -1650,6 +1652,9 @@ var require_merge = __commonJS2((exports) => {
1650
1652
  }
1651
1653
  return map;
1652
1654
  }
1655
+ function resolveAliasValue(ctx, value) {
1656
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1657
+ }
1653
1658
  exports.addMergeToJSMap = addMergeToJSMap;
1654
1659
  exports.isMergeKey = isMergeKey;
1655
1660
  exports.merge = merge;
@@ -2203,7 +2208,7 @@ var require_stringifyNumber = __commonJS2((exports) => {
2203
2208
  if (!isFinite(num))
2204
2209
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
2205
2210
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
2206
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
2211
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
2207
2212
  let i = n.indexOf(".");
2208
2213
  if (i < 0) {
2209
2214
  i = n.length;
@@ -4371,7 +4376,7 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4371
4376
  while (next === " " || next === "\t")
4372
4377
  next = source[++i + 1];
4373
4378
  } else if (next === "x" || next === "u" || next === "U") {
4374
- const length = { x: 2, u: 4, U: 8 }[next];
4379
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
4375
4380
  res += parseCharCode(source, i + 1, length, onError);
4376
4381
  i += length;
4377
4382
  } else {
@@ -4440,12 +4445,13 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4440
4445
  const cc = source.substr(offset, length);
4441
4446
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
4442
4447
  const code = ok ? parseInt(cc, 16) : NaN;
4443
- if (isNaN(code)) {
4448
+ try {
4449
+ return String.fromCodePoint(code);
4450
+ } catch {
4444
4451
  const raw = source.substr(offset - 2, length + 2);
4445
4452
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
4446
4453
  return raw;
4447
4454
  }
4448
- return String.fromCodePoint(code);
4449
4455
  }
4450
4456
  exports.resolveFlowScalar = resolveFlowScalar;
4451
4457
  });
@@ -4774,8 +4780,10 @@ ${cb}` : comment;
4774
4780
  }
4775
4781
  }
4776
4782
  if (afterDoc) {
4777
- Array.prototype.push.apply(doc.errors, this.errors);
4778
- Array.prototype.push.apply(doc.warnings, this.warnings);
4783
+ for (let i = 0;i < this.errors.length; ++i)
4784
+ doc.errors.push(this.errors[i]);
4785
+ for (let i = 0;i < this.warnings.length; ++i)
4786
+ doc.warnings.push(this.warnings[i]);
4779
4787
  } else {
4780
4788
  doc.errors = this.errors;
4781
4789
  doc.warnings = this.warnings;
@@ -5477,7 +5485,7 @@ var require_lexer = __commonJS2((exports) => {
5477
5485
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
5478
5486
  this.indentNext = this.indentValue + 1;
5479
5487
  this.indentValue += n;
5480
- return yield* this.parseBlockStart();
5488
+ return "block-start";
5481
5489
  }
5482
5490
  return "doc";
5483
5491
  }
@@ -5784,26 +5792,37 @@ var require_lexer = __commonJS2((exports) => {
5784
5792
  return 0;
5785
5793
  }
5786
5794
  *pushIndicators() {
5787
- switch (this.charAt(0)) {
5788
- case "!":
5789
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5790
- case "&":
5791
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5792
- case "-":
5793
- case "?":
5794
- case ":": {
5795
- const inFlow = this.flowLevel > 0;
5796
- const ch1 = this.charAt(1);
5797
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5798
- if (!inFlow)
5799
- this.indentNext = this.indentValue + 1;
5800
- else if (this.flowKey)
5801
- this.flowKey = false;
5802
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5795
+ let n = 0;
5796
+ loop:
5797
+ while (true) {
5798
+ switch (this.charAt(0)) {
5799
+ case "!":
5800
+ n += yield* this.pushTag();
5801
+ n += yield* this.pushSpaces(true);
5802
+ continue loop;
5803
+ case "&":
5804
+ n += yield* this.pushUntil(isNotAnchorChar);
5805
+ n += yield* this.pushSpaces(true);
5806
+ continue loop;
5807
+ case "-":
5808
+ case "?":
5809
+ case ":": {
5810
+ const inFlow = this.flowLevel > 0;
5811
+ const ch1 = this.charAt(1);
5812
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5813
+ if (!inFlow)
5814
+ this.indentNext = this.indentValue + 1;
5815
+ else if (this.flowKey)
5816
+ this.flowKey = false;
5817
+ n += yield* this.pushCount(1);
5818
+ n += yield* this.pushSpaces(true);
5819
+ continue loop;
5820
+ }
5821
+ }
5803
5822
  }
5823
+ break loop;
5804
5824
  }
5805
- }
5806
- return 0;
5825
+ return n;
5807
5826
  }
5808
5827
  *pushTag() {
5809
5828
  if (this.charAt(1) === "<") {
@@ -5954,6 +5973,13 @@ var require_parser = __commonJS2((exports) => {
5954
5973
  while (prev[++i]?.type === "space") {}
5955
5974
  return prev.splice(i, prev.length);
5956
5975
  }
5976
+ function arrayPushArray(target, source) {
5977
+ if (source.length < 1e5)
5978
+ Array.prototype.push.apply(target, source);
5979
+ else
5980
+ for (let i = 0;i < source.length; ++i)
5981
+ target.push(source[i]);
5982
+ }
5957
5983
  function fixFlowSeqItems(fc) {
5958
5984
  if (fc.start.type === "flow-seq-start") {
5959
5985
  for (const it of fc.items) {
@@ -5963,11 +5989,11 @@ var require_parser = __commonJS2((exports) => {
5963
5989
  delete it.key;
5964
5990
  if (isFlowToken(it.value)) {
5965
5991
  if (it.value.end)
5966
- Array.prototype.push.apply(it.value.end, it.sep);
5992
+ arrayPushArray(it.value.end, it.sep);
5967
5993
  else
5968
5994
  it.value.end = it.sep;
5969
5995
  } else
5970
- Array.prototype.push.apply(it.start, it.sep);
5996
+ arrayPushArray(it.start, it.sep);
5971
5997
  delete it.sep;
5972
5998
  }
5973
5999
  }
@@ -6307,7 +6333,7 @@ var require_parser = __commonJS2((exports) => {
6307
6333
  const prev = map.items[map.items.length - 2];
6308
6334
  const end = prev?.value?.end;
6309
6335
  if (Array.isArray(end)) {
6310
- Array.prototype.push.apply(end, it.start);
6336
+ arrayPushArray(end, it.start);
6311
6337
  end.push(this.sourceToken);
6312
6338
  map.items.pop();
6313
6339
  return;
@@ -6495,7 +6521,7 @@ var require_parser = __commonJS2((exports) => {
6495
6521
  const prev = seq.items[seq.items.length - 2];
6496
6522
  const end = prev?.value?.end;
6497
6523
  if (Array.isArray(end)) {
6498
- Array.prototype.push.apply(end, it.start);
6524
+ arrayPushArray(end, it.start);
6499
6525
  end.push(this.sourceToken);
6500
6526
  seq.items.pop();
6501
6527
  return;
@@ -6889,6 +6915,7 @@ var PIPELINE_PROVIDER_CHOICES = [
6889
6915
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
6890
6916
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
6891
6917
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
6918
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
6892
6919
  var MEMORIES_FTS_TOKENIZER = "unicode61";
6893
6920
  function normalizeSql(sql) {
6894
6921
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -9986,6 +10013,243 @@ function up92(db) {
9986
10013
  ON embeddings_staging(agent_id, source_type, source_id);
9987
10014
  `);
9988
10015
  }
10016
+ function up93(db) {
10017
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10018
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
10019
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
10020
+ }
10021
+ }
10022
+ var DERIVED_SOURCE_TYPES = DAEMON_DERIVED_MEMORY_SOURCE_TYPES;
10023
+ function hasColumn13(db, table, column) {
10024
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10025
+ return rows.some((r) => r.name === column);
10026
+ }
10027
+ function up94(db) {
10028
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
10029
+ if (tables.length === 0)
10030
+ return;
10031
+ if (!hasColumn13(db, "memories", "memory_kind")) {
10032
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
10033
+ }
10034
+ if (!hasColumn13(db, "memories", "evidence_meta")) {
10035
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
10036
+ }
10037
+ if (hasColumn13(db, "memories", "source_type")) {
10038
+ const placeholders = DERIVED_SOURCE_TYPES.map(() => "?").join(", ");
10039
+ db.prepare(`UPDATE memories
10040
+ SET memory_kind = 'episodic'
10041
+ WHERE memory_kind IS NULL
10042
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES);
10043
+ } else {
10044
+ db.exec(`UPDATE memories
10045
+ SET memory_kind = 'episodic'
10046
+ WHERE memory_kind IS NULL`);
10047
+ }
10048
+ }
10049
+ function hasColumn14(db, table, column) {
10050
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10051
+ }
10052
+ function up95(db) {
10053
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
10054
+ if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
10055
+ return;
10056
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
10057
+ }
10058
+ function up96(db) {
10059
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
10060
+ }
10061
+ function up97(db) {
10062
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10063
+ if (!columns.some((column) => column.name === "last_failure_at")) {
10064
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
10065
+ }
10066
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
10067
+ }
10068
+ function up98(db) {
10069
+ db.exec(`
10070
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
10071
+ agent_id TEXT NOT NULL,
10072
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
10073
+ source_id TEXT NOT NULL,
10074
+ reason TEXT NOT NULL,
10075
+ pass_id TEXT NOT NULL,
10076
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
10077
+ requeue_requested_at TEXT,
10078
+ resolved_at TEXT,
10079
+ PRIMARY KEY (agent_id, source_kind, source_id)
10080
+ );
10081
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
10082
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
10083
+ `);
10084
+ }
10085
+ function up99(db) {
10086
+ db.exec(`
10087
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
10088
+ id TEXT PRIMARY KEY,
10089
+ agent_id TEXT NOT NULL,
10090
+ pass_id TEXT NOT NULL,
10091
+ sequence INTEGER NOT NULL,
10092
+ tool_call_id TEXT,
10093
+ tool_name TEXT NOT NULL,
10094
+ input_json TEXT NOT NULL,
10095
+ output_json TEXT NOT NULL,
10096
+ success INTEGER NOT NULL,
10097
+ latency_ms INTEGER NOT NULL,
10098
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10099
+ UNIQUE(agent_id, pass_id, sequence)
10100
+ );
10101
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
10102
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
10103
+ `);
10104
+ }
10105
+ function up100(db) {
10106
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
10107
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
10108
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
10109
+ }
10110
+ if (!columns.some((column) => column.name === "runbook_json")) {
10111
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
10112
+ }
10113
+ }
10114
+ function up101(db) {
10115
+ db.exec(`
10116
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
10117
+ id TEXT PRIMARY KEY,
10118
+ agent_id TEXT NOT NULL,
10119
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
10120
+ subject_ref TEXT NOT NULL,
10121
+ details_json TEXT NOT NULL DEFAULT '{}',
10122
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
10123
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10124
+ generation INTEGER NOT NULL DEFAULT 0,
10125
+ resolved_at TEXT,
10126
+ resolved_by_pass_id TEXT,
10127
+ UNIQUE(agent_id, kind, subject_ref)
10128
+ );
10129
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
10130
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
10131
+ `);
10132
+ }
10133
+ function hasColumn15(db, table, column) {
10134
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10135
+ }
10136
+ function up102(db) {
10137
+ const requiredMemoryColumns = [
10138
+ "content_hash",
10139
+ "normalized_content",
10140
+ "memory_kind",
10141
+ "source_type",
10142
+ "source_path",
10143
+ "agent_id",
10144
+ "visibility",
10145
+ "is_deleted",
10146
+ "extraction_status"
10147
+ ];
10148
+ if (!hasColumn15(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn15(db, "memories", column))) {
10149
+ return;
10150
+ }
10151
+ db.exec(`
10152
+ INSERT OR IGNORE INTO memories
10153
+ (id, content, normalized_content, content_hash, who, why, project,
10154
+ importance, type, tags, pinned, is_deleted, extraction_status,
10155
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
10156
+ agent_id, visibility, memory_kind)
10157
+ SELECT attr.id, attr.content, attr.normalized_content,
10158
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
10159
+ attr.importance, 'semantic', 'semantic,attribute', 0,
10160
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
10161
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
10162
+ attr.agent_id, 'global', 'derived'
10163
+ FROM entity_attributes attr
10164
+ WHERE attr.memory_id IS NULL
10165
+ `);
10166
+ db.exec(`
10167
+ UPDATE entity_attributes
10168
+ SET memory_id = id
10169
+ WHERE memory_id IS NULL
10170
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
10171
+ `);
10172
+ db.exec(`
10173
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
10174
+ SELECT attr.memory_id, aspect.entity_id
10175
+ FROM entity_attributes attr
10176
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
10177
+ WHERE attr.memory_id IS NOT NULL
10178
+ `);
10179
+ db.exec(`
10180
+ UPDATE entities
10181
+ SET mentions = (
10182
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
10183
+ )
10184
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
10185
+ `);
10186
+ }
10187
+ function up103(db) {
10188
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
10189
+ if (tables.length !== 2)
10190
+ return;
10191
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
10192
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
10193
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
10194
+ return;
10195
+ db.exec(`
10196
+ UPDATE memories
10197
+ SET memory_kind = 'derived'
10198
+ WHERE memory_kind IS NULL
10199
+ AND id IN (
10200
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
10201
+ )
10202
+ `);
10203
+ }
10204
+ function tableExists(db, table) {
10205
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
10206
+ }
10207
+ function hasColumn16(db, table, column) {
10208
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10209
+ }
10210
+ function up104(db) {
10211
+ db.exec(`
10212
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
10213
+ derived_memory_id TEXT NOT NULL,
10214
+ source_kind TEXT NOT NULL,
10215
+ source_id TEXT NOT NULL,
10216
+ source_path TEXT,
10217
+ agent_id TEXT NOT NULL,
10218
+ created_at TEXT NOT NULL,
10219
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
10220
+ );
10221
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
10222
+ ON derived_memory_sources(agent_id, derived_memory_id);
10223
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
10224
+ ON derived_memory_sources(agent_id, source_kind, source_id);
10225
+ `);
10226
+ if (tableExists(db, "aggregate_evidence_sources")) {
10227
+ db.exec(`
10228
+ INSERT OR IGNORE INTO derived_memory_sources
10229
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10230
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
10231
+ FROM aggregate_evidence_sources
10232
+ `);
10233
+ }
10234
+ if (tableExists(db, "aggregate_memory_sources")) {
10235
+ db.exec(`
10236
+ INSERT OR IGNORE INTO derived_memory_sources
10237
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10238
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
10239
+ FROM aggregate_memory_sources
10240
+ `);
10241
+ }
10242
+ if (tableExists(db, "memories") && !hasColumn16(db, "memories", "stale_at")) {
10243
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
10244
+ }
10245
+ if (tableExists(db, "memories")) {
10246
+ db.exec(`
10247
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
10248
+ ON memories(agent_id, stale_at)
10249
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
10250
+ `);
10251
+ }
10252
+ }
9989
10253
  var MIGRATIONS = [
9990
10254
  {
9991
10255
  version: 1,
@@ -10070,7 +10334,6 @@ var MIGRATIONS = [
10070
10334
  name: "ingestion-tracking",
10071
10335
  up: up13,
10072
10336
  artifacts: {
10073
- tables: ["ingestion_jobs"],
10074
10337
  columns: [
10075
10338
  { table: "memories", column: "source_path" },
10076
10339
  { table: "memories", column: "source_section" }
@@ -10733,6 +10996,87 @@ var MIGRATIONS = [
10733
10996
  name: "embedding-staging-store",
10734
10997
  up: up92,
10735
10998
  artifacts: { tables: ["embeddings_staging"] }
10999
+ },
11000
+ {
11001
+ version: 93,
11002
+ name: "dreaming-evidence-cursor",
11003
+ up: up93,
11004
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
11005
+ },
11006
+ {
11007
+ version: 94,
11008
+ name: "memory-kind",
11009
+ up: up94,
11010
+ artifacts: {
11011
+ columns: [
11012
+ { table: "memories", column: "memory_kind" },
11013
+ { table: "memories", column: "evidence_meta" }
11014
+ ]
11015
+ }
11016
+ },
11017
+ {
11018
+ version: 95,
11019
+ name: "compaction-recall-projections",
11020
+ up: up95
11021
+ },
11022
+ {
11023
+ version: 96,
11024
+ name: "retire-legacy-ingestion",
11025
+ up: up96
11026
+ },
11027
+ {
11028
+ version: 97,
11029
+ name: "dreaming-failure-backoff",
11030
+ up: up97,
11031
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
11032
+ },
11033
+ {
11034
+ version: 98,
11035
+ name: "dreaming-evidence-exclusions",
11036
+ up: up98,
11037
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
11038
+ },
11039
+ {
11040
+ version: 99,
11041
+ name: "dreaming-tool-calls",
11042
+ up: up99,
11043
+ artifacts: { tables: ["dreaming_tool_calls"] }
11044
+ },
11045
+ {
11046
+ version: 100,
11047
+ name: "dreaming-runbook",
11048
+ up: up100,
11049
+ artifacts: {
11050
+ columns: [
11051
+ { table: "dreaming_passes", column: "evidence_window_json" },
11052
+ { table: "dreaming_passes", column: "runbook_json" }
11053
+ ]
11054
+ }
11055
+ },
11056
+ {
11057
+ version: 101,
11058
+ name: "dreaming-attention",
11059
+ up: up101,
11060
+ artifacts: { tables: ["dreaming_attention"] }
11061
+ },
11062
+ {
11063
+ version: 102,
11064
+ name: "attribute-semantic-memories",
11065
+ up: up102
11066
+ },
11067
+ {
11068
+ version: 103,
11069
+ name: "semantic-memory-kind",
11070
+ up: up103
11071
+ },
11072
+ {
11073
+ version: 104,
11074
+ name: "derived-memory-provenance",
11075
+ up: up104,
11076
+ artifacts: {
11077
+ tables: ["derived_memory_sources"],
11078
+ columns: [{ table: "memories", column: "stale_at" }]
11079
+ }
10736
11080
  }
10737
11081
  ];
10738
11082
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -10960,122 +11304,6 @@ function stripSignetBlock(content) {
10960
11304
  function escapeRegex(str) {
10961
11305
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10962
11306
  }
10963
- var SKIP_SUBTYPES = new Set([
10964
- "channel_join",
10965
- "channel_leave",
10966
- "channel_topic",
10967
- "channel_purpose",
10968
- "channel_name",
10969
- "channel_archive",
10970
- "channel_unarchive",
10971
- "group_join",
10972
- "group_leave",
10973
- "group_topic",
10974
- "group_purpose",
10975
- "group_name",
10976
- "group_archive",
10977
- "group_unarchive",
10978
- "pinned_item",
10979
- "unpinned_item",
10980
- "bot_add",
10981
- "bot_remove",
10982
- "tombstone",
10983
- "file_comment",
10984
- "sh_room_created",
10985
- "sh_room_shared"
10986
- ]);
10987
- var SKIP_TYPES = new Set([
10988
- "RecipientAdd",
10989
- "RecipientRemove",
10990
- "ChannelNameChange",
10991
- "ChannelIconChange",
10992
- "ChannelPinnedMessage",
10993
- "GuildMemberJoin",
10994
- "UserPremiumGuildSubscription",
10995
- "UserPremiumGuildSubscriptionTier1",
10996
- "UserPremiumGuildSubscriptionTier2",
10997
- "UserPremiumGuildSubscriptionTier3",
10998
- "ChannelFollowAdd",
10999
- "GuildDiscoveryDisqualified",
11000
- "GuildDiscoveryRequalified",
11001
- "GuildDiscoveryGracePeriodInitialWarning",
11002
- "GuildDiscoveryGracePeriodFinalWarning",
11003
- "ThreadCreated",
11004
- "ApplicationCommand"
11005
- ]);
11006
- var SKIP_DIRS = new Set([
11007
- "node_modules",
11008
- ".git",
11009
- "dist",
11010
- "build",
11011
- "out",
11012
- "target",
11013
- ".next",
11014
- ".nuxt",
11015
- "__pycache__",
11016
- ".tox",
11017
- ".mypy_cache",
11018
- ".pytest_cache",
11019
- "venv",
11020
- ".venv",
11021
- "env",
11022
- "vendor",
11023
- "coverage",
11024
- ".cache",
11025
- ".turbo"
11026
- ]);
11027
- var DOCUMENT_VALID_TYPES = new Set([
11028
- "fact",
11029
- "decision",
11030
- "rationale",
11031
- "preference",
11032
- "procedural",
11033
- "semantic",
11034
- "system",
11035
- "configuration",
11036
- "architectural",
11037
- "relationship",
11038
- "episodic",
11039
- "daily-log"
11040
- ]);
11041
- var ENTIRE_VALID_TYPES = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
11042
- var CHAT_VALID_TYPES = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
11043
- var MARKDOWN_EXTS = new Set([".md", ".mdx", ".markdown"]);
11044
- var TXT_EXTS = new Set([".txt", ".text", ".log", ".rst"]);
11045
- var PDF_EXTS = new Set([".pdf"]);
11046
- var CODE_EXTS = new Set([
11047
- ".ts",
11048
- ".tsx",
11049
- ".js",
11050
- ".jsx",
11051
- ".py",
11052
- ".rs",
11053
- ".go",
11054
- ".java",
11055
- ".rb",
11056
- ".php",
11057
- ".swift",
11058
- ".kt",
11059
- ".scala",
11060
- ".c",
11061
- ".cpp",
11062
- ".h",
11063
- ".hpp",
11064
- ".sh",
11065
- ".bash",
11066
- ".zsh",
11067
- ".sql",
11068
- ".yaml",
11069
- ".yml",
11070
- ".toml",
11071
- ".json",
11072
- ".xml",
11073
- ".css",
11074
- ".scss",
11075
- ".html",
11076
- ".htm"
11077
- ]);
11078
- var SKIP_FILES = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
11079
11307
 
11080
11308
  class BaseConnector {
11081
11309
  stripSignetBlock(content) {
@@ -11723,6 +11951,8 @@ var require_Alias2 = __commonJS((exports) => {
11723
11951
  });
11724
11952
  }
11725
11953
  resolve(doc, ctx) {
11954
+ if (ctx?.maxAliasCount === 0)
11955
+ throw new ReferenceError("Alias resolution is disabled");
11726
11956
  let nodes;
11727
11957
  if (ctx?.aliasResolveCache) {
11728
11958
  nodes = ctx.aliasResolveCache;
@@ -12752,18 +12982,18 @@ var require_merge2 = __commonJS((exports) => {
12752
12982
  };
12753
12983
  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);
12754
12984
  function addMergeToJSMap(ctx, map, value) {
12755
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
12756
- if (identity.isSeq(value))
12757
- for (const it of value.items)
12985
+ const source = resolveAliasValue(ctx, value);
12986
+ if (identity.isSeq(source))
12987
+ for (const it of source.items)
12758
12988
  mergeValue(ctx, map, it);
12759
- else if (Array.isArray(value))
12760
- for (const it of value)
12989
+ else if (Array.isArray(source))
12990
+ for (const it of source)
12761
12991
  mergeValue(ctx, map, it);
12762
12992
  else
12763
- mergeValue(ctx, map, value);
12993
+ mergeValue(ctx, map, source);
12764
12994
  }
12765
12995
  function mergeValue(ctx, map, value) {
12766
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
12996
+ const source = resolveAliasValue(ctx, value);
12767
12997
  if (!identity.isMap(source))
12768
12998
  throw new Error("Merge sources must be maps or map aliases");
12769
12999
  const srcMap = source.toJSON(null, ctx, Map);
@@ -12784,6 +13014,9 @@ var require_merge2 = __commonJS((exports) => {
12784
13014
  }
12785
13015
  return map;
12786
13016
  }
13017
+ function resolveAliasValue(ctx, value) {
13018
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
13019
+ }
12787
13020
  exports.addMergeToJSMap = addMergeToJSMap;
12788
13021
  exports.isMergeKey = isMergeKey;
12789
13022
  exports.merge = merge;
@@ -13337,7 +13570,7 @@ var require_stringifyNumber2 = __commonJS((exports) => {
13337
13570
  if (!isFinite(num))
13338
13571
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
13339
13572
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
13340
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
13573
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
13341
13574
  let i = n.indexOf(".");
13342
13575
  if (i < 0) {
13343
13576
  i = n.length;
@@ -15505,7 +15738,7 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15505
15738
  while (next === " " || next === "\t")
15506
15739
  next = source[++i + 1];
15507
15740
  } else if (next === "x" || next === "u" || next === "U") {
15508
- const length = { x: 2, u: 4, U: 8 }[next];
15741
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
15509
15742
  res += parseCharCode(source, i + 1, length, onError);
15510
15743
  i += length;
15511
15744
  } else {
@@ -15574,12 +15807,13 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15574
15807
  const cc = source.substr(offset, length);
15575
15808
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
15576
15809
  const code = ok ? parseInt(cc, 16) : NaN;
15577
- if (isNaN(code)) {
15810
+ try {
15811
+ return String.fromCodePoint(code);
15812
+ } catch {
15578
15813
  const raw = source.substr(offset - 2, length + 2);
15579
15814
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
15580
15815
  return raw;
15581
15816
  }
15582
- return String.fromCodePoint(code);
15583
15817
  }
15584
15818
  exports.resolveFlowScalar = resolveFlowScalar;
15585
15819
  });
@@ -15908,8 +16142,10 @@ ${cb}` : comment;
15908
16142
  }
15909
16143
  }
15910
16144
  if (afterDoc) {
15911
- Array.prototype.push.apply(doc.errors, this.errors);
15912
- Array.prototype.push.apply(doc.warnings, this.warnings);
16145
+ for (let i = 0;i < this.errors.length; ++i)
16146
+ doc.errors.push(this.errors[i]);
16147
+ for (let i = 0;i < this.warnings.length; ++i)
16148
+ doc.warnings.push(this.warnings[i]);
15913
16149
  } else {
15914
16150
  doc.errors = this.errors;
15915
16151
  doc.warnings = this.warnings;
@@ -16611,7 +16847,7 @@ var require_lexer2 = __commonJS((exports) => {
16611
16847
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
16612
16848
  this.indentNext = this.indentValue + 1;
16613
16849
  this.indentValue += n;
16614
- return yield* this.parseBlockStart();
16850
+ return "block-start";
16615
16851
  }
16616
16852
  return "doc";
16617
16853
  }
@@ -16918,26 +17154,37 @@ var require_lexer2 = __commonJS((exports) => {
16918
17154
  return 0;
16919
17155
  }
16920
17156
  *pushIndicators() {
16921
- switch (this.charAt(0)) {
16922
- case "!":
16923
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
16924
- case "&":
16925
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
16926
- case "-":
16927
- case "?":
16928
- case ":": {
16929
- const inFlow = this.flowLevel > 0;
16930
- const ch1 = this.charAt(1);
16931
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
16932
- if (!inFlow)
16933
- this.indentNext = this.indentValue + 1;
16934
- else if (this.flowKey)
16935
- this.flowKey = false;
16936
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
17157
+ let n = 0;
17158
+ loop:
17159
+ while (true) {
17160
+ switch (this.charAt(0)) {
17161
+ case "!":
17162
+ n += yield* this.pushTag();
17163
+ n += yield* this.pushSpaces(true);
17164
+ continue loop;
17165
+ case "&":
17166
+ n += yield* this.pushUntil(isNotAnchorChar);
17167
+ n += yield* this.pushSpaces(true);
17168
+ continue loop;
17169
+ case "-":
17170
+ case "?":
17171
+ case ":": {
17172
+ const inFlow = this.flowLevel > 0;
17173
+ const ch1 = this.charAt(1);
17174
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
17175
+ if (!inFlow)
17176
+ this.indentNext = this.indentValue + 1;
17177
+ else if (this.flowKey)
17178
+ this.flowKey = false;
17179
+ n += yield* this.pushCount(1);
17180
+ n += yield* this.pushSpaces(true);
17181
+ continue loop;
17182
+ }
17183
+ }
16937
17184
  }
17185
+ break loop;
16938
17186
  }
16939
- }
16940
- return 0;
17187
+ return n;
16941
17188
  }
16942
17189
  *pushTag() {
16943
17190
  if (this.charAt(1) === "<") {
@@ -17088,6 +17335,13 @@ var require_parser2 = __commonJS((exports) => {
17088
17335
  while (prev[++i]?.type === "space") {}
17089
17336
  return prev.splice(i, prev.length);
17090
17337
  }
17338
+ function arrayPushArray(target, source) {
17339
+ if (source.length < 1e5)
17340
+ Array.prototype.push.apply(target, source);
17341
+ else
17342
+ for (let i = 0;i < source.length; ++i)
17343
+ target.push(source[i]);
17344
+ }
17091
17345
  function fixFlowSeqItems(fc) {
17092
17346
  if (fc.start.type === "flow-seq-start") {
17093
17347
  for (const it of fc.items) {
@@ -17097,11 +17351,11 @@ var require_parser2 = __commonJS((exports) => {
17097
17351
  delete it.key;
17098
17352
  if (isFlowToken(it.value)) {
17099
17353
  if (it.value.end)
17100
- Array.prototype.push.apply(it.value.end, it.sep);
17354
+ arrayPushArray(it.value.end, it.sep);
17101
17355
  else
17102
17356
  it.value.end = it.sep;
17103
17357
  } else
17104
- Array.prototype.push.apply(it.start, it.sep);
17358
+ arrayPushArray(it.start, it.sep);
17105
17359
  delete it.sep;
17106
17360
  }
17107
17361
  }
@@ -17441,7 +17695,7 @@ var require_parser2 = __commonJS((exports) => {
17441
17695
  const prev = map.items[map.items.length - 2];
17442
17696
  const end = prev?.value?.end;
17443
17697
  if (Array.isArray(end)) {
17444
- Array.prototype.push.apply(end, it.start);
17698
+ arrayPushArray(end, it.start);
17445
17699
  end.push(this.sourceToken);
17446
17700
  map.items.pop();
17447
17701
  return;
@@ -17629,7 +17883,7 @@ var require_parser2 = __commonJS((exports) => {
17629
17883
  const prev = seq.items[seq.items.length - 2];
17630
17884
  const end = prev?.value?.end;
17631
17885
  if (Array.isArray(end)) {
17632
- Array.prototype.push.apply(end, it.start);
17886
+ arrayPushArray(end, it.start);
17633
17887
  end.push(this.sourceToken);
17634
17888
  seq.items.pop();
17635
17889
  return;
@@ -18023,6 +18277,7 @@ var PIPELINE_PROVIDER_CHOICES2 = [
18023
18277
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
18024
18278
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
18025
18279
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
18280
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
18026
18281
  var MEMORIES_FTS_TOKENIZER2 = "unicode61";
18027
18282
  function normalizeSql2(sql) {
18028
18283
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -18073,7 +18328,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
18073
18328
  return true;
18074
18329
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
18075
18330
  }
18076
- function up93(db) {
18331
+ function up105(db) {
18077
18332
  db.exec(`
18078
18333
  CREATE TABLE IF NOT EXISTS schema_migrations (
18079
18334
  version INTEGER PRIMARY KEY,
@@ -18162,12 +18417,12 @@ function up93(db) {
18162
18417
  } catch {}
18163
18418
  createMemoriesFts2(db);
18164
18419
  }
18165
- function hasColumn13(db, table, column) {
18420
+ function hasColumn17(db, table, column) {
18166
18421
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
18167
18422
  return rows.some((r) => r.name === column);
18168
18423
  }
18169
18424
  function addColumnIfMissing23(db, table, column, definition) {
18170
- if (!hasColumn13(db, table, column)) {
18425
+ if (!hasColumn17(db, table, column)) {
18171
18426
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
18172
18427
  }
18173
18428
  }
@@ -18465,7 +18720,7 @@ function up810(db) {
18465
18720
  ON embeddings(content_hash)
18466
18721
  `);
18467
18722
  }
18468
- function up94(db) {
18723
+ function up910(db) {
18469
18724
  db.exec(`
18470
18725
  CREATE TABLE IF NOT EXISTS summary_jobs (
18471
18726
  id TEXT PRIMARY KEY,
@@ -18485,7 +18740,7 @@ function up94(db) {
18485
18740
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
18486
18741
  ON summary_jobs(status)`);
18487
18742
  }
18488
- function up102(db) {
18743
+ function up106(db) {
18489
18744
  db.exec(`
18490
18745
  CREATE TABLE IF NOT EXISTS umap_cache (
18491
18746
  id INTEGER PRIMARY KEY,
@@ -21120,11 +21375,248 @@ function up922(db) {
21120
21375
  ON embeddings_staging(agent_id, source_type, source_id);
21121
21376
  `);
21122
21377
  }
21378
+ function up932(db) {
21379
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21380
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
21381
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
21382
+ }
21383
+ }
21384
+ var DERIVED_SOURCE_TYPES2 = DAEMON_DERIVED_MEMORY_SOURCE_TYPES2;
21385
+ function hasColumn132(db, table, column) {
21386
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
21387
+ return rows.some((r) => r.name === column);
21388
+ }
21389
+ function up942(db) {
21390
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
21391
+ if (tables.length === 0)
21392
+ return;
21393
+ if (!hasColumn132(db, "memories", "memory_kind")) {
21394
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
21395
+ }
21396
+ if (!hasColumn132(db, "memories", "evidence_meta")) {
21397
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
21398
+ }
21399
+ if (hasColumn132(db, "memories", "source_type")) {
21400
+ const placeholders = DERIVED_SOURCE_TYPES2.map(() => "?").join(", ");
21401
+ db.prepare(`UPDATE memories
21402
+ SET memory_kind = 'episodic'
21403
+ WHERE memory_kind IS NULL
21404
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES2);
21405
+ } else {
21406
+ db.exec(`UPDATE memories
21407
+ SET memory_kind = 'episodic'
21408
+ WHERE memory_kind IS NULL`);
21409
+ }
21410
+ }
21411
+ function hasColumn142(db, table, column) {
21412
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21413
+ }
21414
+ function up952(db) {
21415
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
21416
+ if (!hasMemories || !hasColumn142(db, "memories", "memory_kind") || !hasColumn142(db, "memories", "type"))
21417
+ return;
21418
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
21419
+ }
21420
+ function up962(db) {
21421
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
21422
+ }
21423
+ function up972(db) {
21424
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21425
+ if (!columns.some((column) => column.name === "last_failure_at")) {
21426
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
21427
+ }
21428
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
21429
+ }
21430
+ function up982(db) {
21431
+ db.exec(`
21432
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
21433
+ agent_id TEXT NOT NULL,
21434
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
21435
+ source_id TEXT NOT NULL,
21436
+ reason TEXT NOT NULL,
21437
+ pass_id TEXT NOT NULL,
21438
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
21439
+ requeue_requested_at TEXT,
21440
+ resolved_at TEXT,
21441
+ PRIMARY KEY (agent_id, source_kind, source_id)
21442
+ );
21443
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
21444
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
21445
+ `);
21446
+ }
21447
+ function up992(db) {
21448
+ db.exec(`
21449
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
21450
+ id TEXT PRIMARY KEY,
21451
+ agent_id TEXT NOT NULL,
21452
+ pass_id TEXT NOT NULL,
21453
+ sequence INTEGER NOT NULL,
21454
+ tool_call_id TEXT,
21455
+ tool_name TEXT NOT NULL,
21456
+ input_json TEXT NOT NULL,
21457
+ output_json TEXT NOT NULL,
21458
+ success INTEGER NOT NULL,
21459
+ latency_ms INTEGER NOT NULL,
21460
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21461
+ UNIQUE(agent_id, pass_id, sequence)
21462
+ );
21463
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
21464
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
21465
+ `);
21466
+ }
21467
+ function up1002(db) {
21468
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
21469
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
21470
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
21471
+ }
21472
+ if (!columns.some((column) => column.name === "runbook_json")) {
21473
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
21474
+ }
21475
+ }
21476
+ function up1012(db) {
21477
+ db.exec(`
21478
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
21479
+ id TEXT PRIMARY KEY,
21480
+ agent_id TEXT NOT NULL,
21481
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
21482
+ subject_ref TEXT NOT NULL,
21483
+ details_json TEXT NOT NULL DEFAULT '{}',
21484
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
21485
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21486
+ generation INTEGER NOT NULL DEFAULT 0,
21487
+ resolved_at TEXT,
21488
+ resolved_by_pass_id TEXT,
21489
+ UNIQUE(agent_id, kind, subject_ref)
21490
+ );
21491
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
21492
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
21493
+ `);
21494
+ }
21495
+ function hasColumn152(db, table, column) {
21496
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21497
+ }
21498
+ function up1022(db) {
21499
+ const requiredMemoryColumns = [
21500
+ "content_hash",
21501
+ "normalized_content",
21502
+ "memory_kind",
21503
+ "source_type",
21504
+ "source_path",
21505
+ "agent_id",
21506
+ "visibility",
21507
+ "is_deleted",
21508
+ "extraction_status"
21509
+ ];
21510
+ if (!hasColumn152(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn152(db, "memories", column))) {
21511
+ return;
21512
+ }
21513
+ db.exec(`
21514
+ INSERT OR IGNORE INTO memories
21515
+ (id, content, normalized_content, content_hash, who, why, project,
21516
+ importance, type, tags, pinned, is_deleted, extraction_status,
21517
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
21518
+ agent_id, visibility, memory_kind)
21519
+ SELECT attr.id, attr.content, attr.normalized_content,
21520
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
21521
+ attr.importance, 'semantic', 'semantic,attribute', 0,
21522
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
21523
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
21524
+ attr.agent_id, 'global', 'derived'
21525
+ FROM entity_attributes attr
21526
+ WHERE attr.memory_id IS NULL
21527
+ `);
21528
+ db.exec(`
21529
+ UPDATE entity_attributes
21530
+ SET memory_id = id
21531
+ WHERE memory_id IS NULL
21532
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
21533
+ `);
21534
+ db.exec(`
21535
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
21536
+ SELECT attr.memory_id, aspect.entity_id
21537
+ FROM entity_attributes attr
21538
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
21539
+ WHERE attr.memory_id IS NOT NULL
21540
+ `);
21541
+ db.exec(`
21542
+ UPDATE entities
21543
+ SET mentions = (
21544
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
21545
+ )
21546
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
21547
+ `);
21548
+ }
21549
+ function up1032(db) {
21550
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
21551
+ if (tables.length !== 2)
21552
+ return;
21553
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
21554
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
21555
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
21556
+ return;
21557
+ db.exec(`
21558
+ UPDATE memories
21559
+ SET memory_kind = 'derived'
21560
+ WHERE memory_kind IS NULL
21561
+ AND id IN (
21562
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
21563
+ )
21564
+ `);
21565
+ }
21566
+ function tableExists2(db, table) {
21567
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
21568
+ }
21569
+ function hasColumn162(db, table, column) {
21570
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21571
+ }
21572
+ function up1042(db) {
21573
+ db.exec(`
21574
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
21575
+ derived_memory_id TEXT NOT NULL,
21576
+ source_kind TEXT NOT NULL,
21577
+ source_id TEXT NOT NULL,
21578
+ source_path TEXT,
21579
+ agent_id TEXT NOT NULL,
21580
+ created_at TEXT NOT NULL,
21581
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
21582
+ );
21583
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
21584
+ ON derived_memory_sources(agent_id, derived_memory_id);
21585
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
21586
+ ON derived_memory_sources(agent_id, source_kind, source_id);
21587
+ `);
21588
+ if (tableExists2(db, "aggregate_evidence_sources")) {
21589
+ db.exec(`
21590
+ INSERT OR IGNORE INTO derived_memory_sources
21591
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21592
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
21593
+ FROM aggregate_evidence_sources
21594
+ `);
21595
+ }
21596
+ if (tableExists2(db, "aggregate_memory_sources")) {
21597
+ db.exec(`
21598
+ INSERT OR IGNORE INTO derived_memory_sources
21599
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21600
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
21601
+ FROM aggregate_memory_sources
21602
+ `);
21603
+ }
21604
+ if (tableExists2(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
21605
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
21606
+ }
21607
+ if (tableExists2(db, "memories")) {
21608
+ db.exec(`
21609
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
21610
+ ON memories(agent_id, stale_at)
21611
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
21612
+ `);
21613
+ }
21614
+ }
21123
21615
  var MIGRATIONS2 = [
21124
21616
  {
21125
21617
  version: 1,
21126
21618
  name: "baseline",
21127
- up: up93,
21619
+ up: up105,
21128
21620
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
21129
21621
  },
21130
21622
  {
@@ -21178,13 +21670,13 @@ var MIGRATIONS2 = [
21178
21670
  {
21179
21671
  version: 9,
21180
21672
  name: "summary-jobs",
21181
- up: up94,
21673
+ up: up910,
21182
21674
  artifacts: { tables: ["summary_jobs"] }
21183
21675
  },
21184
21676
  {
21185
21677
  version: 10,
21186
21678
  name: "umap-cache",
21187
- up: up102,
21679
+ up: up106,
21188
21680
  artifacts: { tables: ["umap_cache"] }
21189
21681
  },
21190
21682
  {
@@ -21204,7 +21696,6 @@ var MIGRATIONS2 = [
21204
21696
  name: "ingestion-tracking",
21205
21697
  up: up132,
21206
21698
  artifacts: {
21207
- tables: ["ingestion_jobs"],
21208
21699
  columns: [
21209
21700
  { table: "memories", column: "source_path" },
21210
21701
  { table: "memories", column: "source_section" }
@@ -21867,6 +22358,87 @@ var MIGRATIONS2 = [
21867
22358
  name: "embedding-staging-store",
21868
22359
  up: up922,
21869
22360
  artifacts: { tables: ["embeddings_staging"] }
22361
+ },
22362
+ {
22363
+ version: 93,
22364
+ name: "dreaming-evidence-cursor",
22365
+ up: up932,
22366
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
22367
+ },
22368
+ {
22369
+ version: 94,
22370
+ name: "memory-kind",
22371
+ up: up942,
22372
+ artifacts: {
22373
+ columns: [
22374
+ { table: "memories", column: "memory_kind" },
22375
+ { table: "memories", column: "evidence_meta" }
22376
+ ]
22377
+ }
22378
+ },
22379
+ {
22380
+ version: 95,
22381
+ name: "compaction-recall-projections",
22382
+ up: up952
22383
+ },
22384
+ {
22385
+ version: 96,
22386
+ name: "retire-legacy-ingestion",
22387
+ up: up962
22388
+ },
22389
+ {
22390
+ version: 97,
22391
+ name: "dreaming-failure-backoff",
22392
+ up: up972,
22393
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
22394
+ },
22395
+ {
22396
+ version: 98,
22397
+ name: "dreaming-evidence-exclusions",
22398
+ up: up982,
22399
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
22400
+ },
22401
+ {
22402
+ version: 99,
22403
+ name: "dreaming-tool-calls",
22404
+ up: up992,
22405
+ artifacts: { tables: ["dreaming_tool_calls"] }
22406
+ },
22407
+ {
22408
+ version: 100,
22409
+ name: "dreaming-runbook",
22410
+ up: up1002,
22411
+ artifacts: {
22412
+ columns: [
22413
+ { table: "dreaming_passes", column: "evidence_window_json" },
22414
+ { table: "dreaming_passes", column: "runbook_json" }
22415
+ ]
22416
+ }
22417
+ },
22418
+ {
22419
+ version: 101,
22420
+ name: "dreaming-attention",
22421
+ up: up1012,
22422
+ artifacts: { tables: ["dreaming_attention"] }
22423
+ },
22424
+ {
22425
+ version: 102,
22426
+ name: "attribute-semantic-memories",
22427
+ up: up1022
22428
+ },
22429
+ {
22430
+ version: 103,
22431
+ name: "semantic-memory-kind",
22432
+ up: up1032
22433
+ },
22434
+ {
22435
+ version: 104,
22436
+ name: "derived-memory-provenance",
22437
+ up: up1042,
22438
+ artifacts: {
22439
+ tables: ["derived_memory_sources"],
22440
+ columns: [{ table: "memories", column: "stale_at" }]
22441
+ }
21870
22442
  }
21871
22443
  ];
21872
22444
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -22061,122 +22633,6 @@ function resolveHermesRepoPath() {
22061
22633
  return null;
22062
22634
  }
22063
22635
  var home2 = homedir82();
22064
- var SKIP_SUBTYPES2 = new Set([
22065
- "channel_join",
22066
- "channel_leave",
22067
- "channel_topic",
22068
- "channel_purpose",
22069
- "channel_name",
22070
- "channel_archive",
22071
- "channel_unarchive",
22072
- "group_join",
22073
- "group_leave",
22074
- "group_topic",
22075
- "group_purpose",
22076
- "group_name",
22077
- "group_archive",
22078
- "group_unarchive",
22079
- "pinned_item",
22080
- "unpinned_item",
22081
- "bot_add",
22082
- "bot_remove",
22083
- "tombstone",
22084
- "file_comment",
22085
- "sh_room_created",
22086
- "sh_room_shared"
22087
- ]);
22088
- var SKIP_TYPES2 = new Set([
22089
- "RecipientAdd",
22090
- "RecipientRemove",
22091
- "ChannelNameChange",
22092
- "ChannelIconChange",
22093
- "ChannelPinnedMessage",
22094
- "GuildMemberJoin",
22095
- "UserPremiumGuildSubscription",
22096
- "UserPremiumGuildSubscriptionTier1",
22097
- "UserPremiumGuildSubscriptionTier2",
22098
- "UserPremiumGuildSubscriptionTier3",
22099
- "ChannelFollowAdd",
22100
- "GuildDiscoveryDisqualified",
22101
- "GuildDiscoveryRequalified",
22102
- "GuildDiscoveryGracePeriodInitialWarning",
22103
- "GuildDiscoveryGracePeriodFinalWarning",
22104
- "ThreadCreated",
22105
- "ApplicationCommand"
22106
- ]);
22107
- var SKIP_DIRS2 = new Set([
22108
- "node_modules",
22109
- ".git",
22110
- "dist",
22111
- "build",
22112
- "out",
22113
- "target",
22114
- ".next",
22115
- ".nuxt",
22116
- "__pycache__",
22117
- ".tox",
22118
- ".mypy_cache",
22119
- ".pytest_cache",
22120
- "venv",
22121
- ".venv",
22122
- "env",
22123
- "vendor",
22124
- "coverage",
22125
- ".cache",
22126
- ".turbo"
22127
- ]);
22128
- var DOCUMENT_VALID_TYPES2 = new Set([
22129
- "fact",
22130
- "decision",
22131
- "rationale",
22132
- "preference",
22133
- "procedural",
22134
- "semantic",
22135
- "system",
22136
- "configuration",
22137
- "architectural",
22138
- "relationship",
22139
- "episodic",
22140
- "daily-log"
22141
- ]);
22142
- var ENTIRE_VALID_TYPES2 = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
22143
- var CHAT_VALID_TYPES2 = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
22144
- var MARKDOWN_EXTS2 = new Set([".md", ".mdx", ".markdown"]);
22145
- var TXT_EXTS2 = new Set([".txt", ".text", ".log", ".rst"]);
22146
- var PDF_EXTS2 = new Set([".pdf"]);
22147
- var CODE_EXTS2 = new Set([
22148
- ".ts",
22149
- ".tsx",
22150
- ".js",
22151
- ".jsx",
22152
- ".py",
22153
- ".rs",
22154
- ".go",
22155
- ".java",
22156
- ".rb",
22157
- ".php",
22158
- ".swift",
22159
- ".kt",
22160
- ".scala",
22161
- ".c",
22162
- ".cpp",
22163
- ".h",
22164
- ".hpp",
22165
- ".sh",
22166
- ".bash",
22167
- ".zsh",
22168
- ".sql",
22169
- ".yaml",
22170
- ".yml",
22171
- ".toml",
22172
- ".json",
22173
- ".xml",
22174
- ".css",
22175
- ".scss",
22176
- ".html",
22177
- ".htm"
22178
- ]);
22179
- var SKIP_FILES2 = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
22180
22636
 
22181
22637
  // src/index.ts
22182
22638
  var __dirname3 = dirname5(fileURLToPath3(import.meta.url));