@signetai/connector-claude-code 0.157.5 → 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
@@ -587,6 +587,8 @@ var require_Alias = __commonJS2((exports) => {
587
587
  });
588
588
  }
589
589
  resolve(doc, ctx) {
590
+ if (ctx?.maxAliasCount === 0)
591
+ throw new ReferenceError("Alias resolution is disabled");
590
592
  let nodes;
591
593
  if (ctx?.aliasResolveCache) {
592
594
  nodes = ctx.aliasResolveCache;
@@ -1616,18 +1618,18 @@ var require_merge = __commonJS2((exports) => {
1616
1618
  };
1617
1619
  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);
1618
1620
  function addMergeToJSMap(ctx, map, value) {
1619
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1620
- if (identity.isSeq(value))
1621
- for (const it of value.items)
1621
+ const source = resolveAliasValue(ctx, value);
1622
+ if (identity.isSeq(source))
1623
+ for (const it of source.items)
1622
1624
  mergeValue(ctx, map, it);
1623
- else if (Array.isArray(value))
1624
- for (const it of value)
1625
+ else if (Array.isArray(source))
1626
+ for (const it of source)
1625
1627
  mergeValue(ctx, map, it);
1626
1628
  else
1627
- mergeValue(ctx, map, value);
1629
+ mergeValue(ctx, map, source);
1628
1630
  }
1629
1631
  function mergeValue(ctx, map, value) {
1630
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1632
+ const source = resolveAliasValue(ctx, value);
1631
1633
  if (!identity.isMap(source))
1632
1634
  throw new Error("Merge sources must be maps or map aliases");
1633
1635
  const srcMap = source.toJSON(null, ctx, Map);
@@ -1648,6 +1650,9 @@ var require_merge = __commonJS2((exports) => {
1648
1650
  }
1649
1651
  return map;
1650
1652
  }
1653
+ function resolveAliasValue(ctx, value) {
1654
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1655
+ }
1651
1656
  exports.addMergeToJSMap = addMergeToJSMap;
1652
1657
  exports.isMergeKey = isMergeKey;
1653
1658
  exports.merge = merge;
@@ -2201,7 +2206,7 @@ var require_stringifyNumber = __commonJS2((exports) => {
2201
2206
  if (!isFinite(num))
2202
2207
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
2203
2208
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
2204
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
2209
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
2205
2210
  let i = n.indexOf(".");
2206
2211
  if (i < 0) {
2207
2212
  i = n.length;
@@ -4369,7 +4374,7 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4369
4374
  while (next === " " || next === "\t")
4370
4375
  next = source[++i + 1];
4371
4376
  } else if (next === "x" || next === "u" || next === "U") {
4372
- const length = { x: 2, u: 4, U: 8 }[next];
4377
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
4373
4378
  res += parseCharCode(source, i + 1, length, onError);
4374
4379
  i += length;
4375
4380
  } else {
@@ -4438,12 +4443,13 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4438
4443
  const cc = source.substr(offset, length);
4439
4444
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
4440
4445
  const code = ok ? parseInt(cc, 16) : NaN;
4441
- if (isNaN(code)) {
4446
+ try {
4447
+ return String.fromCodePoint(code);
4448
+ } catch {
4442
4449
  const raw = source.substr(offset - 2, length + 2);
4443
4450
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
4444
4451
  return raw;
4445
4452
  }
4446
- return String.fromCodePoint(code);
4447
4453
  }
4448
4454
  exports.resolveFlowScalar = resolveFlowScalar;
4449
4455
  });
@@ -4772,8 +4778,10 @@ ${cb}` : comment;
4772
4778
  }
4773
4779
  }
4774
4780
  if (afterDoc) {
4775
- Array.prototype.push.apply(doc.errors, this.errors);
4776
- Array.prototype.push.apply(doc.warnings, this.warnings);
4781
+ for (let i = 0;i < this.errors.length; ++i)
4782
+ doc.errors.push(this.errors[i]);
4783
+ for (let i = 0;i < this.warnings.length; ++i)
4784
+ doc.warnings.push(this.warnings[i]);
4777
4785
  } else {
4778
4786
  doc.errors = this.errors;
4779
4787
  doc.warnings = this.warnings;
@@ -5475,7 +5483,7 @@ var require_lexer = __commonJS2((exports) => {
5475
5483
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
5476
5484
  this.indentNext = this.indentValue + 1;
5477
5485
  this.indentValue += n;
5478
- return yield* this.parseBlockStart();
5486
+ return "block-start";
5479
5487
  }
5480
5488
  return "doc";
5481
5489
  }
@@ -5782,26 +5790,37 @@ var require_lexer = __commonJS2((exports) => {
5782
5790
  return 0;
5783
5791
  }
5784
5792
  *pushIndicators() {
5785
- switch (this.charAt(0)) {
5786
- case "!":
5787
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5788
- case "&":
5789
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5790
- case "-":
5791
- case "?":
5792
- case ":": {
5793
- const inFlow = this.flowLevel > 0;
5794
- const ch1 = this.charAt(1);
5795
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5796
- if (!inFlow)
5797
- this.indentNext = this.indentValue + 1;
5798
- else if (this.flowKey)
5799
- this.flowKey = false;
5800
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5793
+ let n = 0;
5794
+ loop:
5795
+ while (true) {
5796
+ switch (this.charAt(0)) {
5797
+ case "!":
5798
+ n += yield* this.pushTag();
5799
+ n += yield* this.pushSpaces(true);
5800
+ continue loop;
5801
+ case "&":
5802
+ n += yield* this.pushUntil(isNotAnchorChar);
5803
+ n += yield* this.pushSpaces(true);
5804
+ continue loop;
5805
+ case "-":
5806
+ case "?":
5807
+ case ":": {
5808
+ const inFlow = this.flowLevel > 0;
5809
+ const ch1 = this.charAt(1);
5810
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5811
+ if (!inFlow)
5812
+ this.indentNext = this.indentValue + 1;
5813
+ else if (this.flowKey)
5814
+ this.flowKey = false;
5815
+ n += yield* this.pushCount(1);
5816
+ n += yield* this.pushSpaces(true);
5817
+ continue loop;
5818
+ }
5819
+ }
5801
5820
  }
5821
+ break loop;
5802
5822
  }
5803
- }
5804
- return 0;
5823
+ return n;
5805
5824
  }
5806
5825
  *pushTag() {
5807
5826
  if (this.charAt(1) === "<") {
@@ -5952,6 +5971,13 @@ var require_parser = __commonJS2((exports) => {
5952
5971
  while (prev[++i]?.type === "space") {}
5953
5972
  return prev.splice(i, prev.length);
5954
5973
  }
5974
+ function arrayPushArray(target, source) {
5975
+ if (source.length < 1e5)
5976
+ Array.prototype.push.apply(target, source);
5977
+ else
5978
+ for (let i = 0;i < source.length; ++i)
5979
+ target.push(source[i]);
5980
+ }
5955
5981
  function fixFlowSeqItems(fc) {
5956
5982
  if (fc.start.type === "flow-seq-start") {
5957
5983
  for (const it of fc.items) {
@@ -5961,11 +5987,11 @@ var require_parser = __commonJS2((exports) => {
5961
5987
  delete it.key;
5962
5988
  if (isFlowToken(it.value)) {
5963
5989
  if (it.value.end)
5964
- Array.prototype.push.apply(it.value.end, it.sep);
5990
+ arrayPushArray(it.value.end, it.sep);
5965
5991
  else
5966
5992
  it.value.end = it.sep;
5967
5993
  } else
5968
- Array.prototype.push.apply(it.start, it.sep);
5994
+ arrayPushArray(it.start, it.sep);
5969
5995
  delete it.sep;
5970
5996
  }
5971
5997
  }
@@ -6305,7 +6331,7 @@ var require_parser = __commonJS2((exports) => {
6305
6331
  const prev = map.items[map.items.length - 2];
6306
6332
  const end = prev?.value?.end;
6307
6333
  if (Array.isArray(end)) {
6308
- Array.prototype.push.apply(end, it.start);
6334
+ arrayPushArray(end, it.start);
6309
6335
  end.push(this.sourceToken);
6310
6336
  map.items.pop();
6311
6337
  return;
@@ -6493,7 +6519,7 @@ var require_parser = __commonJS2((exports) => {
6493
6519
  const prev = seq.items[seq.items.length - 2];
6494
6520
  const end = prev?.value?.end;
6495
6521
  if (Array.isArray(end)) {
6496
- Array.prototype.push.apply(end, it.start);
6522
+ arrayPushArray(end, it.start);
6497
6523
  end.push(this.sourceToken);
6498
6524
  seq.items.pop();
6499
6525
  return;
@@ -6887,6 +6913,7 @@ var PIPELINE_PROVIDER_CHOICES = [
6887
6913
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
6888
6914
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
6889
6915
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
6916
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
6890
6917
  var MEMORIES_FTS_TOKENIZER = "unicode61";
6891
6918
  function normalizeSql(sql) {
6892
6919
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -9984,6 +10011,243 @@ function up92(db) {
9984
10011
  ON embeddings_staging(agent_id, source_type, source_id);
9985
10012
  `);
9986
10013
  }
10014
+ function up93(db) {
10015
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10016
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
10017
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
10018
+ }
10019
+ }
10020
+ var DERIVED_SOURCE_TYPES = DAEMON_DERIVED_MEMORY_SOURCE_TYPES;
10021
+ function hasColumn13(db, table, column) {
10022
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10023
+ return rows.some((r) => r.name === column);
10024
+ }
10025
+ function up94(db) {
10026
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
10027
+ if (tables.length === 0)
10028
+ return;
10029
+ if (!hasColumn13(db, "memories", "memory_kind")) {
10030
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
10031
+ }
10032
+ if (!hasColumn13(db, "memories", "evidence_meta")) {
10033
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
10034
+ }
10035
+ if (hasColumn13(db, "memories", "source_type")) {
10036
+ const placeholders = DERIVED_SOURCE_TYPES.map(() => "?").join(", ");
10037
+ db.prepare(`UPDATE memories
10038
+ SET memory_kind = 'episodic'
10039
+ WHERE memory_kind IS NULL
10040
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES);
10041
+ } else {
10042
+ db.exec(`UPDATE memories
10043
+ SET memory_kind = 'episodic'
10044
+ WHERE memory_kind IS NULL`);
10045
+ }
10046
+ }
10047
+ function hasColumn14(db, table, column) {
10048
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10049
+ }
10050
+ function up95(db) {
10051
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
10052
+ if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
10053
+ return;
10054
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
10055
+ }
10056
+ function up96(db) {
10057
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
10058
+ }
10059
+ function up97(db) {
10060
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10061
+ if (!columns.some((column) => column.name === "last_failure_at")) {
10062
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
10063
+ }
10064
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
10065
+ }
10066
+ function up98(db) {
10067
+ db.exec(`
10068
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
10069
+ agent_id TEXT NOT NULL,
10070
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
10071
+ source_id TEXT NOT NULL,
10072
+ reason TEXT NOT NULL,
10073
+ pass_id TEXT NOT NULL,
10074
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
10075
+ requeue_requested_at TEXT,
10076
+ resolved_at TEXT,
10077
+ PRIMARY KEY (agent_id, source_kind, source_id)
10078
+ );
10079
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
10080
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
10081
+ `);
10082
+ }
10083
+ function up99(db) {
10084
+ db.exec(`
10085
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
10086
+ id TEXT PRIMARY KEY,
10087
+ agent_id TEXT NOT NULL,
10088
+ pass_id TEXT NOT NULL,
10089
+ sequence INTEGER NOT NULL,
10090
+ tool_call_id TEXT,
10091
+ tool_name TEXT NOT NULL,
10092
+ input_json TEXT NOT NULL,
10093
+ output_json TEXT NOT NULL,
10094
+ success INTEGER NOT NULL,
10095
+ latency_ms INTEGER NOT NULL,
10096
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10097
+ UNIQUE(agent_id, pass_id, sequence)
10098
+ );
10099
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
10100
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
10101
+ `);
10102
+ }
10103
+ function up100(db) {
10104
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
10105
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
10106
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
10107
+ }
10108
+ if (!columns.some((column) => column.name === "runbook_json")) {
10109
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
10110
+ }
10111
+ }
10112
+ function up101(db) {
10113
+ db.exec(`
10114
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
10115
+ id TEXT PRIMARY KEY,
10116
+ agent_id TEXT NOT NULL,
10117
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
10118
+ subject_ref TEXT NOT NULL,
10119
+ details_json TEXT NOT NULL DEFAULT '{}',
10120
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
10121
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10122
+ generation INTEGER NOT NULL DEFAULT 0,
10123
+ resolved_at TEXT,
10124
+ resolved_by_pass_id TEXT,
10125
+ UNIQUE(agent_id, kind, subject_ref)
10126
+ );
10127
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
10128
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
10129
+ `);
10130
+ }
10131
+ function hasColumn15(db, table, column) {
10132
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10133
+ }
10134
+ function up102(db) {
10135
+ const requiredMemoryColumns = [
10136
+ "content_hash",
10137
+ "normalized_content",
10138
+ "memory_kind",
10139
+ "source_type",
10140
+ "source_path",
10141
+ "agent_id",
10142
+ "visibility",
10143
+ "is_deleted",
10144
+ "extraction_status"
10145
+ ];
10146
+ if (!hasColumn15(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn15(db, "memories", column))) {
10147
+ return;
10148
+ }
10149
+ db.exec(`
10150
+ INSERT OR IGNORE INTO memories
10151
+ (id, content, normalized_content, content_hash, who, why, project,
10152
+ importance, type, tags, pinned, is_deleted, extraction_status,
10153
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
10154
+ agent_id, visibility, memory_kind)
10155
+ SELECT attr.id, attr.content, attr.normalized_content,
10156
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
10157
+ attr.importance, 'semantic', 'semantic,attribute', 0,
10158
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
10159
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
10160
+ attr.agent_id, 'global', 'derived'
10161
+ FROM entity_attributes attr
10162
+ WHERE attr.memory_id IS NULL
10163
+ `);
10164
+ db.exec(`
10165
+ UPDATE entity_attributes
10166
+ SET memory_id = id
10167
+ WHERE memory_id IS NULL
10168
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
10169
+ `);
10170
+ db.exec(`
10171
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
10172
+ SELECT attr.memory_id, aspect.entity_id
10173
+ FROM entity_attributes attr
10174
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
10175
+ WHERE attr.memory_id IS NOT NULL
10176
+ `);
10177
+ db.exec(`
10178
+ UPDATE entities
10179
+ SET mentions = (
10180
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
10181
+ )
10182
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
10183
+ `);
10184
+ }
10185
+ function up103(db) {
10186
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
10187
+ if (tables.length !== 2)
10188
+ return;
10189
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
10190
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
10191
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
10192
+ return;
10193
+ db.exec(`
10194
+ UPDATE memories
10195
+ SET memory_kind = 'derived'
10196
+ WHERE memory_kind IS NULL
10197
+ AND id IN (
10198
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
10199
+ )
10200
+ `);
10201
+ }
10202
+ function tableExists(db, table) {
10203
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
10204
+ }
10205
+ function hasColumn16(db, table, column) {
10206
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10207
+ }
10208
+ function up104(db) {
10209
+ db.exec(`
10210
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
10211
+ derived_memory_id TEXT NOT NULL,
10212
+ source_kind TEXT NOT NULL,
10213
+ source_id TEXT NOT NULL,
10214
+ source_path TEXT,
10215
+ agent_id TEXT NOT NULL,
10216
+ created_at TEXT NOT NULL,
10217
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
10218
+ );
10219
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
10220
+ ON derived_memory_sources(agent_id, derived_memory_id);
10221
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
10222
+ ON derived_memory_sources(agent_id, source_kind, source_id);
10223
+ `);
10224
+ if (tableExists(db, "aggregate_evidence_sources")) {
10225
+ db.exec(`
10226
+ INSERT OR IGNORE INTO derived_memory_sources
10227
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10228
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
10229
+ FROM aggregate_evidence_sources
10230
+ `);
10231
+ }
10232
+ if (tableExists(db, "aggregate_memory_sources")) {
10233
+ db.exec(`
10234
+ INSERT OR IGNORE INTO derived_memory_sources
10235
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10236
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
10237
+ FROM aggregate_memory_sources
10238
+ `);
10239
+ }
10240
+ if (tableExists(db, "memories") && !hasColumn16(db, "memories", "stale_at")) {
10241
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
10242
+ }
10243
+ if (tableExists(db, "memories")) {
10244
+ db.exec(`
10245
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
10246
+ ON memories(agent_id, stale_at)
10247
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
10248
+ `);
10249
+ }
10250
+ }
9987
10251
  var MIGRATIONS = [
9988
10252
  {
9989
10253
  version: 1,
@@ -10068,7 +10332,6 @@ var MIGRATIONS = [
10068
10332
  name: "ingestion-tracking",
10069
10333
  up: up13,
10070
10334
  artifacts: {
10071
- tables: ["ingestion_jobs"],
10072
10335
  columns: [
10073
10336
  { table: "memories", column: "source_path" },
10074
10337
  { table: "memories", column: "source_section" }
@@ -10731,6 +10994,87 @@ var MIGRATIONS = [
10731
10994
  name: "embedding-staging-store",
10732
10995
  up: up92,
10733
10996
  artifacts: { tables: ["embeddings_staging"] }
10997
+ },
10998
+ {
10999
+ version: 93,
11000
+ name: "dreaming-evidence-cursor",
11001
+ up: up93,
11002
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
11003
+ },
11004
+ {
11005
+ version: 94,
11006
+ name: "memory-kind",
11007
+ up: up94,
11008
+ artifacts: {
11009
+ columns: [
11010
+ { table: "memories", column: "memory_kind" },
11011
+ { table: "memories", column: "evidence_meta" }
11012
+ ]
11013
+ }
11014
+ },
11015
+ {
11016
+ version: 95,
11017
+ name: "compaction-recall-projections",
11018
+ up: up95
11019
+ },
11020
+ {
11021
+ version: 96,
11022
+ name: "retire-legacy-ingestion",
11023
+ up: up96
11024
+ },
11025
+ {
11026
+ version: 97,
11027
+ name: "dreaming-failure-backoff",
11028
+ up: up97,
11029
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
11030
+ },
11031
+ {
11032
+ version: 98,
11033
+ name: "dreaming-evidence-exclusions",
11034
+ up: up98,
11035
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
11036
+ },
11037
+ {
11038
+ version: 99,
11039
+ name: "dreaming-tool-calls",
11040
+ up: up99,
11041
+ artifacts: { tables: ["dreaming_tool_calls"] }
11042
+ },
11043
+ {
11044
+ version: 100,
11045
+ name: "dreaming-runbook",
11046
+ up: up100,
11047
+ artifacts: {
11048
+ columns: [
11049
+ { table: "dreaming_passes", column: "evidence_window_json" },
11050
+ { table: "dreaming_passes", column: "runbook_json" }
11051
+ ]
11052
+ }
11053
+ },
11054
+ {
11055
+ version: 101,
11056
+ name: "dreaming-attention",
11057
+ up: up101,
11058
+ artifacts: { tables: ["dreaming_attention"] }
11059
+ },
11060
+ {
11061
+ version: 102,
11062
+ name: "attribute-semantic-memories",
11063
+ up: up102
11064
+ },
11065
+ {
11066
+ version: 103,
11067
+ name: "semantic-memory-kind",
11068
+ up: up103
11069
+ },
11070
+ {
11071
+ version: 104,
11072
+ name: "derived-memory-provenance",
11073
+ up: up104,
11074
+ artifacts: {
11075
+ tables: ["derived_memory_sources"],
11076
+ columns: [{ table: "memories", column: "stale_at" }]
11077
+ }
10734
11078
  }
10735
11079
  ];
10736
11080
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -10958,122 +11302,6 @@ function stripSignetBlock(content) {
10958
11302
  function escapeRegex(str) {
10959
11303
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10960
11304
  }
10961
- var SKIP_SUBTYPES = new Set([
10962
- "channel_join",
10963
- "channel_leave",
10964
- "channel_topic",
10965
- "channel_purpose",
10966
- "channel_name",
10967
- "channel_archive",
10968
- "channel_unarchive",
10969
- "group_join",
10970
- "group_leave",
10971
- "group_topic",
10972
- "group_purpose",
10973
- "group_name",
10974
- "group_archive",
10975
- "group_unarchive",
10976
- "pinned_item",
10977
- "unpinned_item",
10978
- "bot_add",
10979
- "bot_remove",
10980
- "tombstone",
10981
- "file_comment",
10982
- "sh_room_created",
10983
- "sh_room_shared"
10984
- ]);
10985
- var SKIP_TYPES = new Set([
10986
- "RecipientAdd",
10987
- "RecipientRemove",
10988
- "ChannelNameChange",
10989
- "ChannelIconChange",
10990
- "ChannelPinnedMessage",
10991
- "GuildMemberJoin",
10992
- "UserPremiumGuildSubscription",
10993
- "UserPremiumGuildSubscriptionTier1",
10994
- "UserPremiumGuildSubscriptionTier2",
10995
- "UserPremiumGuildSubscriptionTier3",
10996
- "ChannelFollowAdd",
10997
- "GuildDiscoveryDisqualified",
10998
- "GuildDiscoveryRequalified",
10999
- "GuildDiscoveryGracePeriodInitialWarning",
11000
- "GuildDiscoveryGracePeriodFinalWarning",
11001
- "ThreadCreated",
11002
- "ApplicationCommand"
11003
- ]);
11004
- var SKIP_DIRS = new Set([
11005
- "node_modules",
11006
- ".git",
11007
- "dist",
11008
- "build",
11009
- "out",
11010
- "target",
11011
- ".next",
11012
- ".nuxt",
11013
- "__pycache__",
11014
- ".tox",
11015
- ".mypy_cache",
11016
- ".pytest_cache",
11017
- "venv",
11018
- ".venv",
11019
- "env",
11020
- "vendor",
11021
- "coverage",
11022
- ".cache",
11023
- ".turbo"
11024
- ]);
11025
- var DOCUMENT_VALID_TYPES = new Set([
11026
- "fact",
11027
- "decision",
11028
- "rationale",
11029
- "preference",
11030
- "procedural",
11031
- "semantic",
11032
- "system",
11033
- "configuration",
11034
- "architectural",
11035
- "relationship",
11036
- "episodic",
11037
- "daily-log"
11038
- ]);
11039
- var ENTIRE_VALID_TYPES = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
11040
- var CHAT_VALID_TYPES = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
11041
- var MARKDOWN_EXTS = new Set([".md", ".mdx", ".markdown"]);
11042
- var TXT_EXTS = new Set([".txt", ".text", ".log", ".rst"]);
11043
- var PDF_EXTS = new Set([".pdf"]);
11044
- var CODE_EXTS = new Set([
11045
- ".ts",
11046
- ".tsx",
11047
- ".js",
11048
- ".jsx",
11049
- ".py",
11050
- ".rs",
11051
- ".go",
11052
- ".java",
11053
- ".rb",
11054
- ".php",
11055
- ".swift",
11056
- ".kt",
11057
- ".scala",
11058
- ".c",
11059
- ".cpp",
11060
- ".h",
11061
- ".hpp",
11062
- ".sh",
11063
- ".bash",
11064
- ".zsh",
11065
- ".sql",
11066
- ".yaml",
11067
- ".yml",
11068
- ".toml",
11069
- ".json",
11070
- ".xml",
11071
- ".css",
11072
- ".scss",
11073
- ".html",
11074
- ".htm"
11075
- ]);
11076
- var SKIP_FILES = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
11077
11305
 
11078
11306
  class BaseConnector {
11079
11307
  stripSignetBlock(content) {
@@ -11759,6 +11987,8 @@ var require_Alias2 = __commonJS((exports) => {
11759
11987
  });
11760
11988
  }
11761
11989
  resolve(doc, ctx) {
11990
+ if (ctx?.maxAliasCount === 0)
11991
+ throw new ReferenceError("Alias resolution is disabled");
11762
11992
  let nodes;
11763
11993
  if (ctx?.aliasResolveCache) {
11764
11994
  nodes = ctx.aliasResolveCache;
@@ -12788,18 +13018,18 @@ var require_merge2 = __commonJS((exports) => {
12788
13018
  };
12789
13019
  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);
12790
13020
  function addMergeToJSMap(ctx, map, value) {
12791
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
12792
- if (identity.isSeq(value))
12793
- for (const it of value.items)
13021
+ const source = resolveAliasValue(ctx, value);
13022
+ if (identity.isSeq(source))
13023
+ for (const it of source.items)
12794
13024
  mergeValue(ctx, map, it);
12795
- else if (Array.isArray(value))
12796
- for (const it of value)
13025
+ else if (Array.isArray(source))
13026
+ for (const it of source)
12797
13027
  mergeValue(ctx, map, it);
12798
13028
  else
12799
- mergeValue(ctx, map, value);
13029
+ mergeValue(ctx, map, source);
12800
13030
  }
12801
13031
  function mergeValue(ctx, map, value) {
12802
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
13032
+ const source = resolveAliasValue(ctx, value);
12803
13033
  if (!identity.isMap(source))
12804
13034
  throw new Error("Merge sources must be maps or map aliases");
12805
13035
  const srcMap = source.toJSON(null, ctx, Map);
@@ -12820,6 +13050,9 @@ var require_merge2 = __commonJS((exports) => {
12820
13050
  }
12821
13051
  return map;
12822
13052
  }
13053
+ function resolveAliasValue(ctx, value) {
13054
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
13055
+ }
12823
13056
  exports.addMergeToJSMap = addMergeToJSMap;
12824
13057
  exports.isMergeKey = isMergeKey;
12825
13058
  exports.merge = merge;
@@ -13373,7 +13606,7 @@ var require_stringifyNumber2 = __commonJS((exports) => {
13373
13606
  if (!isFinite(num))
13374
13607
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
13375
13608
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
13376
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
13609
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
13377
13610
  let i = n.indexOf(".");
13378
13611
  if (i < 0) {
13379
13612
  i = n.length;
@@ -15541,7 +15774,7 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15541
15774
  while (next === " " || next === "\t")
15542
15775
  next = source[++i + 1];
15543
15776
  } else if (next === "x" || next === "u" || next === "U") {
15544
- const length = { x: 2, u: 4, U: 8 }[next];
15777
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
15545
15778
  res += parseCharCode(source, i + 1, length, onError);
15546
15779
  i += length;
15547
15780
  } else {
@@ -15610,12 +15843,13 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15610
15843
  const cc = source.substr(offset, length);
15611
15844
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
15612
15845
  const code = ok ? parseInt(cc, 16) : NaN;
15613
- if (isNaN(code)) {
15846
+ try {
15847
+ return String.fromCodePoint(code);
15848
+ } catch {
15614
15849
  const raw = source.substr(offset - 2, length + 2);
15615
15850
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
15616
15851
  return raw;
15617
15852
  }
15618
- return String.fromCodePoint(code);
15619
15853
  }
15620
15854
  exports.resolveFlowScalar = resolveFlowScalar;
15621
15855
  });
@@ -15944,8 +16178,10 @@ ${cb}` : comment;
15944
16178
  }
15945
16179
  }
15946
16180
  if (afterDoc) {
15947
- Array.prototype.push.apply(doc.errors, this.errors);
15948
- Array.prototype.push.apply(doc.warnings, this.warnings);
16181
+ for (let i = 0;i < this.errors.length; ++i)
16182
+ doc.errors.push(this.errors[i]);
16183
+ for (let i = 0;i < this.warnings.length; ++i)
16184
+ doc.warnings.push(this.warnings[i]);
15949
16185
  } else {
15950
16186
  doc.errors = this.errors;
15951
16187
  doc.warnings = this.warnings;
@@ -16647,7 +16883,7 @@ var require_lexer2 = __commonJS((exports) => {
16647
16883
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
16648
16884
  this.indentNext = this.indentValue + 1;
16649
16885
  this.indentValue += n;
16650
- return yield* this.parseBlockStart();
16886
+ return "block-start";
16651
16887
  }
16652
16888
  return "doc";
16653
16889
  }
@@ -16954,26 +17190,37 @@ var require_lexer2 = __commonJS((exports) => {
16954
17190
  return 0;
16955
17191
  }
16956
17192
  *pushIndicators() {
16957
- switch (this.charAt(0)) {
16958
- case "!":
16959
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
16960
- case "&":
16961
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
16962
- case "-":
16963
- case "?":
16964
- case ":": {
16965
- const inFlow = this.flowLevel > 0;
16966
- const ch1 = this.charAt(1);
16967
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
16968
- if (!inFlow)
16969
- this.indentNext = this.indentValue + 1;
16970
- else if (this.flowKey)
16971
- this.flowKey = false;
16972
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
17193
+ let n = 0;
17194
+ loop:
17195
+ while (true) {
17196
+ switch (this.charAt(0)) {
17197
+ case "!":
17198
+ n += yield* this.pushTag();
17199
+ n += yield* this.pushSpaces(true);
17200
+ continue loop;
17201
+ case "&":
17202
+ n += yield* this.pushUntil(isNotAnchorChar);
17203
+ n += yield* this.pushSpaces(true);
17204
+ continue loop;
17205
+ case "-":
17206
+ case "?":
17207
+ case ":": {
17208
+ const inFlow = this.flowLevel > 0;
17209
+ const ch1 = this.charAt(1);
17210
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
17211
+ if (!inFlow)
17212
+ this.indentNext = this.indentValue + 1;
17213
+ else if (this.flowKey)
17214
+ this.flowKey = false;
17215
+ n += yield* this.pushCount(1);
17216
+ n += yield* this.pushSpaces(true);
17217
+ continue loop;
17218
+ }
17219
+ }
16973
17220
  }
17221
+ break loop;
16974
17222
  }
16975
- }
16976
- return 0;
17223
+ return n;
16977
17224
  }
16978
17225
  *pushTag() {
16979
17226
  if (this.charAt(1) === "<") {
@@ -17124,6 +17371,13 @@ var require_parser2 = __commonJS((exports) => {
17124
17371
  while (prev[++i]?.type === "space") {}
17125
17372
  return prev.splice(i, prev.length);
17126
17373
  }
17374
+ function arrayPushArray(target, source) {
17375
+ if (source.length < 1e5)
17376
+ Array.prototype.push.apply(target, source);
17377
+ else
17378
+ for (let i = 0;i < source.length; ++i)
17379
+ target.push(source[i]);
17380
+ }
17127
17381
  function fixFlowSeqItems(fc) {
17128
17382
  if (fc.start.type === "flow-seq-start") {
17129
17383
  for (const it of fc.items) {
@@ -17133,11 +17387,11 @@ var require_parser2 = __commonJS((exports) => {
17133
17387
  delete it.key;
17134
17388
  if (isFlowToken(it.value)) {
17135
17389
  if (it.value.end)
17136
- Array.prototype.push.apply(it.value.end, it.sep);
17390
+ arrayPushArray(it.value.end, it.sep);
17137
17391
  else
17138
17392
  it.value.end = it.sep;
17139
17393
  } else
17140
- Array.prototype.push.apply(it.start, it.sep);
17394
+ arrayPushArray(it.start, it.sep);
17141
17395
  delete it.sep;
17142
17396
  }
17143
17397
  }
@@ -17477,7 +17731,7 @@ var require_parser2 = __commonJS((exports) => {
17477
17731
  const prev = map.items[map.items.length - 2];
17478
17732
  const end = prev?.value?.end;
17479
17733
  if (Array.isArray(end)) {
17480
- Array.prototype.push.apply(end, it.start);
17734
+ arrayPushArray(end, it.start);
17481
17735
  end.push(this.sourceToken);
17482
17736
  map.items.pop();
17483
17737
  return;
@@ -17665,7 +17919,7 @@ var require_parser2 = __commonJS((exports) => {
17665
17919
  const prev = seq.items[seq.items.length - 2];
17666
17920
  const end = prev?.value?.end;
17667
17921
  if (Array.isArray(end)) {
17668
- Array.prototype.push.apply(end, it.start);
17922
+ arrayPushArray(end, it.start);
17669
17923
  end.push(this.sourceToken);
17670
17924
  seq.items.pop();
17671
17925
  return;
@@ -18059,6 +18313,7 @@ var PIPELINE_PROVIDER_CHOICES2 = [
18059
18313
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
18060
18314
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
18061
18315
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
18316
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
18062
18317
  var MEMORIES_FTS_TOKENIZER2 = "unicode61";
18063
18318
  function normalizeSql2(sql) {
18064
18319
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -18109,7 +18364,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
18109
18364
  return true;
18110
18365
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
18111
18366
  }
18112
- function up93(db) {
18367
+ function up105(db) {
18113
18368
  db.exec(`
18114
18369
  CREATE TABLE IF NOT EXISTS schema_migrations (
18115
18370
  version INTEGER PRIMARY KEY,
@@ -18198,12 +18453,12 @@ function up93(db) {
18198
18453
  } catch {}
18199
18454
  createMemoriesFts2(db);
18200
18455
  }
18201
- function hasColumn13(db, table, column) {
18456
+ function hasColumn17(db, table, column) {
18202
18457
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
18203
18458
  return rows.some((r) => r.name === column);
18204
18459
  }
18205
18460
  function addColumnIfMissing23(db, table, column, definition) {
18206
- if (!hasColumn13(db, table, column)) {
18461
+ if (!hasColumn17(db, table, column)) {
18207
18462
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
18208
18463
  }
18209
18464
  }
@@ -18501,7 +18756,7 @@ function up810(db) {
18501
18756
  ON embeddings(content_hash)
18502
18757
  `);
18503
18758
  }
18504
- function up94(db) {
18759
+ function up910(db) {
18505
18760
  db.exec(`
18506
18761
  CREATE TABLE IF NOT EXISTS summary_jobs (
18507
18762
  id TEXT PRIMARY KEY,
@@ -18521,7 +18776,7 @@ function up94(db) {
18521
18776
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
18522
18777
  ON summary_jobs(status)`);
18523
18778
  }
18524
- function up102(db) {
18779
+ function up106(db) {
18525
18780
  db.exec(`
18526
18781
  CREATE TABLE IF NOT EXISTS umap_cache (
18527
18782
  id INTEGER PRIMARY KEY,
@@ -21156,11 +21411,248 @@ function up922(db) {
21156
21411
  ON embeddings_staging(agent_id, source_type, source_id);
21157
21412
  `);
21158
21413
  }
21414
+ function up932(db) {
21415
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21416
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
21417
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
21418
+ }
21419
+ }
21420
+ var DERIVED_SOURCE_TYPES2 = DAEMON_DERIVED_MEMORY_SOURCE_TYPES2;
21421
+ function hasColumn132(db, table, column) {
21422
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
21423
+ return rows.some((r) => r.name === column);
21424
+ }
21425
+ function up942(db) {
21426
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
21427
+ if (tables.length === 0)
21428
+ return;
21429
+ if (!hasColumn132(db, "memories", "memory_kind")) {
21430
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
21431
+ }
21432
+ if (!hasColumn132(db, "memories", "evidence_meta")) {
21433
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
21434
+ }
21435
+ if (hasColumn132(db, "memories", "source_type")) {
21436
+ const placeholders = DERIVED_SOURCE_TYPES2.map(() => "?").join(", ");
21437
+ db.prepare(`UPDATE memories
21438
+ SET memory_kind = 'episodic'
21439
+ WHERE memory_kind IS NULL
21440
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES2);
21441
+ } else {
21442
+ db.exec(`UPDATE memories
21443
+ SET memory_kind = 'episodic'
21444
+ WHERE memory_kind IS NULL`);
21445
+ }
21446
+ }
21447
+ function hasColumn142(db, table, column) {
21448
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21449
+ }
21450
+ function up952(db) {
21451
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
21452
+ if (!hasMemories || !hasColumn142(db, "memories", "memory_kind") || !hasColumn142(db, "memories", "type"))
21453
+ return;
21454
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
21455
+ }
21456
+ function up962(db) {
21457
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
21458
+ }
21459
+ function up972(db) {
21460
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21461
+ if (!columns.some((column) => column.name === "last_failure_at")) {
21462
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
21463
+ }
21464
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
21465
+ }
21466
+ function up982(db) {
21467
+ db.exec(`
21468
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
21469
+ agent_id TEXT NOT NULL,
21470
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
21471
+ source_id TEXT NOT NULL,
21472
+ reason TEXT NOT NULL,
21473
+ pass_id TEXT NOT NULL,
21474
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
21475
+ requeue_requested_at TEXT,
21476
+ resolved_at TEXT,
21477
+ PRIMARY KEY (agent_id, source_kind, source_id)
21478
+ );
21479
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
21480
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
21481
+ `);
21482
+ }
21483
+ function up992(db) {
21484
+ db.exec(`
21485
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
21486
+ id TEXT PRIMARY KEY,
21487
+ agent_id TEXT NOT NULL,
21488
+ pass_id TEXT NOT NULL,
21489
+ sequence INTEGER NOT NULL,
21490
+ tool_call_id TEXT,
21491
+ tool_name TEXT NOT NULL,
21492
+ input_json TEXT NOT NULL,
21493
+ output_json TEXT NOT NULL,
21494
+ success INTEGER NOT NULL,
21495
+ latency_ms INTEGER NOT NULL,
21496
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21497
+ UNIQUE(agent_id, pass_id, sequence)
21498
+ );
21499
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
21500
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
21501
+ `);
21502
+ }
21503
+ function up1002(db) {
21504
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
21505
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
21506
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
21507
+ }
21508
+ if (!columns.some((column) => column.name === "runbook_json")) {
21509
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
21510
+ }
21511
+ }
21512
+ function up1012(db) {
21513
+ db.exec(`
21514
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
21515
+ id TEXT PRIMARY KEY,
21516
+ agent_id TEXT NOT NULL,
21517
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
21518
+ subject_ref TEXT NOT NULL,
21519
+ details_json TEXT NOT NULL DEFAULT '{}',
21520
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
21521
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21522
+ generation INTEGER NOT NULL DEFAULT 0,
21523
+ resolved_at TEXT,
21524
+ resolved_by_pass_id TEXT,
21525
+ UNIQUE(agent_id, kind, subject_ref)
21526
+ );
21527
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
21528
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
21529
+ `);
21530
+ }
21531
+ function hasColumn152(db, table, column) {
21532
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21533
+ }
21534
+ function up1022(db) {
21535
+ const requiredMemoryColumns = [
21536
+ "content_hash",
21537
+ "normalized_content",
21538
+ "memory_kind",
21539
+ "source_type",
21540
+ "source_path",
21541
+ "agent_id",
21542
+ "visibility",
21543
+ "is_deleted",
21544
+ "extraction_status"
21545
+ ];
21546
+ if (!hasColumn152(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn152(db, "memories", column))) {
21547
+ return;
21548
+ }
21549
+ db.exec(`
21550
+ INSERT OR IGNORE INTO memories
21551
+ (id, content, normalized_content, content_hash, who, why, project,
21552
+ importance, type, tags, pinned, is_deleted, extraction_status,
21553
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
21554
+ agent_id, visibility, memory_kind)
21555
+ SELECT attr.id, attr.content, attr.normalized_content,
21556
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
21557
+ attr.importance, 'semantic', 'semantic,attribute', 0,
21558
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
21559
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
21560
+ attr.agent_id, 'global', 'derived'
21561
+ FROM entity_attributes attr
21562
+ WHERE attr.memory_id IS NULL
21563
+ `);
21564
+ db.exec(`
21565
+ UPDATE entity_attributes
21566
+ SET memory_id = id
21567
+ WHERE memory_id IS NULL
21568
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
21569
+ `);
21570
+ db.exec(`
21571
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
21572
+ SELECT attr.memory_id, aspect.entity_id
21573
+ FROM entity_attributes attr
21574
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
21575
+ WHERE attr.memory_id IS NOT NULL
21576
+ `);
21577
+ db.exec(`
21578
+ UPDATE entities
21579
+ SET mentions = (
21580
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
21581
+ )
21582
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
21583
+ `);
21584
+ }
21585
+ function up1032(db) {
21586
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
21587
+ if (tables.length !== 2)
21588
+ return;
21589
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
21590
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
21591
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
21592
+ return;
21593
+ db.exec(`
21594
+ UPDATE memories
21595
+ SET memory_kind = 'derived'
21596
+ WHERE memory_kind IS NULL
21597
+ AND id IN (
21598
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
21599
+ )
21600
+ `);
21601
+ }
21602
+ function tableExists2(db, table) {
21603
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
21604
+ }
21605
+ function hasColumn162(db, table, column) {
21606
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21607
+ }
21608
+ function up1042(db) {
21609
+ db.exec(`
21610
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
21611
+ derived_memory_id TEXT NOT NULL,
21612
+ source_kind TEXT NOT NULL,
21613
+ source_id TEXT NOT NULL,
21614
+ source_path TEXT,
21615
+ agent_id TEXT NOT NULL,
21616
+ created_at TEXT NOT NULL,
21617
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
21618
+ );
21619
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
21620
+ ON derived_memory_sources(agent_id, derived_memory_id);
21621
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
21622
+ ON derived_memory_sources(agent_id, source_kind, source_id);
21623
+ `);
21624
+ if (tableExists2(db, "aggregate_evidence_sources")) {
21625
+ db.exec(`
21626
+ INSERT OR IGNORE INTO derived_memory_sources
21627
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21628
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
21629
+ FROM aggregate_evidence_sources
21630
+ `);
21631
+ }
21632
+ if (tableExists2(db, "aggregate_memory_sources")) {
21633
+ db.exec(`
21634
+ INSERT OR IGNORE INTO derived_memory_sources
21635
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21636
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
21637
+ FROM aggregate_memory_sources
21638
+ `);
21639
+ }
21640
+ if (tableExists2(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
21641
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
21642
+ }
21643
+ if (tableExists2(db, "memories")) {
21644
+ db.exec(`
21645
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
21646
+ ON memories(agent_id, stale_at)
21647
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
21648
+ `);
21649
+ }
21650
+ }
21159
21651
  var MIGRATIONS2 = [
21160
21652
  {
21161
21653
  version: 1,
21162
21654
  name: "baseline",
21163
- up: up93,
21655
+ up: up105,
21164
21656
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
21165
21657
  },
21166
21658
  {
@@ -21214,13 +21706,13 @@ var MIGRATIONS2 = [
21214
21706
  {
21215
21707
  version: 9,
21216
21708
  name: "summary-jobs",
21217
- up: up94,
21709
+ up: up910,
21218
21710
  artifacts: { tables: ["summary_jobs"] }
21219
21711
  },
21220
21712
  {
21221
21713
  version: 10,
21222
21714
  name: "umap-cache",
21223
- up: up102,
21715
+ up: up106,
21224
21716
  artifacts: { tables: ["umap_cache"] }
21225
21717
  },
21226
21718
  {
@@ -21240,7 +21732,6 @@ var MIGRATIONS2 = [
21240
21732
  name: "ingestion-tracking",
21241
21733
  up: up132,
21242
21734
  artifacts: {
21243
- tables: ["ingestion_jobs"],
21244
21735
  columns: [
21245
21736
  { table: "memories", column: "source_path" },
21246
21737
  { table: "memories", column: "source_section" }
@@ -21903,6 +22394,87 @@ var MIGRATIONS2 = [
21903
22394
  name: "embedding-staging-store",
21904
22395
  up: up922,
21905
22396
  artifacts: { tables: ["embeddings_staging"] }
22397
+ },
22398
+ {
22399
+ version: 93,
22400
+ name: "dreaming-evidence-cursor",
22401
+ up: up932,
22402
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
22403
+ },
22404
+ {
22405
+ version: 94,
22406
+ name: "memory-kind",
22407
+ up: up942,
22408
+ artifacts: {
22409
+ columns: [
22410
+ { table: "memories", column: "memory_kind" },
22411
+ { table: "memories", column: "evidence_meta" }
22412
+ ]
22413
+ }
22414
+ },
22415
+ {
22416
+ version: 95,
22417
+ name: "compaction-recall-projections",
22418
+ up: up952
22419
+ },
22420
+ {
22421
+ version: 96,
22422
+ name: "retire-legacy-ingestion",
22423
+ up: up962
22424
+ },
22425
+ {
22426
+ version: 97,
22427
+ name: "dreaming-failure-backoff",
22428
+ up: up972,
22429
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
22430
+ },
22431
+ {
22432
+ version: 98,
22433
+ name: "dreaming-evidence-exclusions",
22434
+ up: up982,
22435
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
22436
+ },
22437
+ {
22438
+ version: 99,
22439
+ name: "dreaming-tool-calls",
22440
+ up: up992,
22441
+ artifacts: { tables: ["dreaming_tool_calls"] }
22442
+ },
22443
+ {
22444
+ version: 100,
22445
+ name: "dreaming-runbook",
22446
+ up: up1002,
22447
+ artifacts: {
22448
+ columns: [
22449
+ { table: "dreaming_passes", column: "evidence_window_json" },
22450
+ { table: "dreaming_passes", column: "runbook_json" }
22451
+ ]
22452
+ }
22453
+ },
22454
+ {
22455
+ version: 101,
22456
+ name: "dreaming-attention",
22457
+ up: up1012,
22458
+ artifacts: { tables: ["dreaming_attention"] }
22459
+ },
22460
+ {
22461
+ version: 102,
22462
+ name: "attribute-semantic-memories",
22463
+ up: up1022
22464
+ },
22465
+ {
22466
+ version: 103,
22467
+ name: "semantic-memory-kind",
22468
+ up: up1032
22469
+ },
22470
+ {
22471
+ version: 104,
22472
+ name: "derived-memory-provenance",
22473
+ up: up1042,
22474
+ artifacts: {
22475
+ tables: ["derived_memory_sources"],
22476
+ columns: [{ table: "memories", column: "stale_at" }]
22477
+ }
21906
22478
  }
21907
22479
  ];
21908
22480
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -22075,122 +22647,6 @@ function resolvePromptSubmitTimeoutMs(raw) {
22075
22647
  return ms;
22076
22648
  }
22077
22649
  var home2 = homedir82();
22078
- var SKIP_SUBTYPES2 = new Set([
22079
- "channel_join",
22080
- "channel_leave",
22081
- "channel_topic",
22082
- "channel_purpose",
22083
- "channel_name",
22084
- "channel_archive",
22085
- "channel_unarchive",
22086
- "group_join",
22087
- "group_leave",
22088
- "group_topic",
22089
- "group_purpose",
22090
- "group_name",
22091
- "group_archive",
22092
- "group_unarchive",
22093
- "pinned_item",
22094
- "unpinned_item",
22095
- "bot_add",
22096
- "bot_remove",
22097
- "tombstone",
22098
- "file_comment",
22099
- "sh_room_created",
22100
- "sh_room_shared"
22101
- ]);
22102
- var SKIP_TYPES2 = new Set([
22103
- "RecipientAdd",
22104
- "RecipientRemove",
22105
- "ChannelNameChange",
22106
- "ChannelIconChange",
22107
- "ChannelPinnedMessage",
22108
- "GuildMemberJoin",
22109
- "UserPremiumGuildSubscription",
22110
- "UserPremiumGuildSubscriptionTier1",
22111
- "UserPremiumGuildSubscriptionTier2",
22112
- "UserPremiumGuildSubscriptionTier3",
22113
- "ChannelFollowAdd",
22114
- "GuildDiscoveryDisqualified",
22115
- "GuildDiscoveryRequalified",
22116
- "GuildDiscoveryGracePeriodInitialWarning",
22117
- "GuildDiscoveryGracePeriodFinalWarning",
22118
- "ThreadCreated",
22119
- "ApplicationCommand"
22120
- ]);
22121
- var SKIP_DIRS2 = new Set([
22122
- "node_modules",
22123
- ".git",
22124
- "dist",
22125
- "build",
22126
- "out",
22127
- "target",
22128
- ".next",
22129
- ".nuxt",
22130
- "__pycache__",
22131
- ".tox",
22132
- ".mypy_cache",
22133
- ".pytest_cache",
22134
- "venv",
22135
- ".venv",
22136
- "env",
22137
- "vendor",
22138
- "coverage",
22139
- ".cache",
22140
- ".turbo"
22141
- ]);
22142
- var DOCUMENT_VALID_TYPES2 = new Set([
22143
- "fact",
22144
- "decision",
22145
- "rationale",
22146
- "preference",
22147
- "procedural",
22148
- "semantic",
22149
- "system",
22150
- "configuration",
22151
- "architectural",
22152
- "relationship",
22153
- "episodic",
22154
- "daily-log"
22155
- ]);
22156
- var ENTIRE_VALID_TYPES2 = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
22157
- var CHAT_VALID_TYPES2 = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
22158
- var MARKDOWN_EXTS2 = new Set([".md", ".mdx", ".markdown"]);
22159
- var TXT_EXTS2 = new Set([".txt", ".text", ".log", ".rst"]);
22160
- var PDF_EXTS2 = new Set([".pdf"]);
22161
- var CODE_EXTS2 = new Set([
22162
- ".ts",
22163
- ".tsx",
22164
- ".js",
22165
- ".jsx",
22166
- ".py",
22167
- ".rs",
22168
- ".go",
22169
- ".java",
22170
- ".rb",
22171
- ".php",
22172
- ".swift",
22173
- ".kt",
22174
- ".scala",
22175
- ".c",
22176
- ".cpp",
22177
- ".h",
22178
- ".hpp",
22179
- ".sh",
22180
- ".bash",
22181
- ".zsh",
22182
- ".sql",
22183
- ".yaml",
22184
- ".yml",
22185
- ".toml",
22186
- ".json",
22187
- ".xml",
22188
- ".css",
22189
- ".scss",
22190
- ".html",
22191
- ".htm"
22192
- ]);
22193
- var SKIP_FILES2 = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
22194
22650
 
22195
22651
  // src/index.ts
22196
22652
  var SESSION_END_FIRE_AND_FORGET_SCRIPT = `