@signetai/connector-forge 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
@@ -602,6 +602,8 @@ var require_Alias = __commonJS2((exports) => {
602
602
  });
603
603
  }
604
604
  resolve(doc, ctx) {
605
+ if (ctx?.maxAliasCount === 0)
606
+ throw new ReferenceError("Alias resolution is disabled");
605
607
  let nodes;
606
608
  if (ctx?.aliasResolveCache) {
607
609
  nodes = ctx.aliasResolveCache;
@@ -1631,18 +1633,18 @@ var require_merge = __commonJS2((exports) => {
1631
1633
  };
1632
1634
  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);
1633
1635
  function addMergeToJSMap(ctx, map, value) {
1634
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1635
- if (identity.isSeq(value))
1636
- for (const it of value.items)
1636
+ const source = resolveAliasValue(ctx, value);
1637
+ if (identity.isSeq(source))
1638
+ for (const it of source.items)
1637
1639
  mergeValue(ctx, map, it);
1638
- else if (Array.isArray(value))
1639
- for (const it of value)
1640
+ else if (Array.isArray(source))
1641
+ for (const it of source)
1640
1642
  mergeValue(ctx, map, it);
1641
1643
  else
1642
- mergeValue(ctx, map, value);
1644
+ mergeValue(ctx, map, source);
1643
1645
  }
1644
1646
  function mergeValue(ctx, map, value) {
1645
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1647
+ const source = resolveAliasValue(ctx, value);
1646
1648
  if (!identity.isMap(source))
1647
1649
  throw new Error("Merge sources must be maps or map aliases");
1648
1650
  const srcMap = source.toJSON(null, ctx, Map);
@@ -1663,6 +1665,9 @@ var require_merge = __commonJS2((exports) => {
1663
1665
  }
1664
1666
  return map;
1665
1667
  }
1668
+ function resolveAliasValue(ctx, value) {
1669
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1670
+ }
1666
1671
  exports.addMergeToJSMap = addMergeToJSMap;
1667
1672
  exports.isMergeKey = isMergeKey;
1668
1673
  exports.merge = merge;
@@ -2216,7 +2221,7 @@ var require_stringifyNumber = __commonJS2((exports) => {
2216
2221
  if (!isFinite(num))
2217
2222
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
2218
2223
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
2219
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
2224
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
2220
2225
  let i = n.indexOf(".");
2221
2226
  if (i < 0) {
2222
2227
  i = n.length;
@@ -4384,7 +4389,7 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4384
4389
  while (next === " " || next === "\t")
4385
4390
  next = source[++i + 1];
4386
4391
  } else if (next === "x" || next === "u" || next === "U") {
4387
- const length = { x: 2, u: 4, U: 8 }[next];
4392
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
4388
4393
  res += parseCharCode(source, i + 1, length, onError);
4389
4394
  i += length;
4390
4395
  } else {
@@ -4453,12 +4458,13 @@ var require_resolve_flow_scalar = __commonJS2((exports) => {
4453
4458
  const cc = source.substr(offset, length);
4454
4459
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
4455
4460
  const code = ok ? parseInt(cc, 16) : NaN;
4456
- if (isNaN(code)) {
4461
+ try {
4462
+ return String.fromCodePoint(code);
4463
+ } catch {
4457
4464
  const raw = source.substr(offset - 2, length + 2);
4458
4465
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
4459
4466
  return raw;
4460
4467
  }
4461
- return String.fromCodePoint(code);
4462
4468
  }
4463
4469
  exports.resolveFlowScalar = resolveFlowScalar;
4464
4470
  });
@@ -4787,8 +4793,10 @@ ${cb}` : comment;
4787
4793
  }
4788
4794
  }
4789
4795
  if (afterDoc) {
4790
- Array.prototype.push.apply(doc.errors, this.errors);
4791
- Array.prototype.push.apply(doc.warnings, this.warnings);
4796
+ for (let i = 0;i < this.errors.length; ++i)
4797
+ doc.errors.push(this.errors[i]);
4798
+ for (let i = 0;i < this.warnings.length; ++i)
4799
+ doc.warnings.push(this.warnings[i]);
4792
4800
  } else {
4793
4801
  doc.errors = this.errors;
4794
4802
  doc.warnings = this.warnings;
@@ -5490,7 +5498,7 @@ var require_lexer = __commonJS2((exports) => {
5490
5498
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
5491
5499
  this.indentNext = this.indentValue + 1;
5492
5500
  this.indentValue += n;
5493
- return yield* this.parseBlockStart();
5501
+ return "block-start";
5494
5502
  }
5495
5503
  return "doc";
5496
5504
  }
@@ -5797,26 +5805,37 @@ var require_lexer = __commonJS2((exports) => {
5797
5805
  return 0;
5798
5806
  }
5799
5807
  *pushIndicators() {
5800
- switch (this.charAt(0)) {
5801
- case "!":
5802
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5803
- case "&":
5804
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
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
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
5808
+ let n = 0;
5809
+ loop:
5810
+ while (true) {
5811
+ switch (this.charAt(0)) {
5812
+ case "!":
5813
+ n += yield* this.pushTag();
5814
+ n += yield* this.pushSpaces(true);
5815
+ continue loop;
5816
+ case "&":
5817
+ n += yield* this.pushUntil(isNotAnchorChar);
5818
+ n += yield* this.pushSpaces(true);
5819
+ continue loop;
5820
+ case "-":
5821
+ case "?":
5822
+ case ":": {
5823
+ const inFlow = this.flowLevel > 0;
5824
+ const ch1 = this.charAt(1);
5825
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
5826
+ if (!inFlow)
5827
+ this.indentNext = this.indentValue + 1;
5828
+ else if (this.flowKey)
5829
+ this.flowKey = false;
5830
+ n += yield* this.pushCount(1);
5831
+ n += yield* this.pushSpaces(true);
5832
+ continue loop;
5833
+ }
5834
+ }
5816
5835
  }
5836
+ break loop;
5817
5837
  }
5818
- }
5819
- return 0;
5838
+ return n;
5820
5839
  }
5821
5840
  *pushTag() {
5822
5841
  if (this.charAt(1) === "<") {
@@ -5967,6 +5986,13 @@ var require_parser = __commonJS2((exports) => {
5967
5986
  while (prev[++i]?.type === "space") {}
5968
5987
  return prev.splice(i, prev.length);
5969
5988
  }
5989
+ function arrayPushArray(target, source) {
5990
+ if (source.length < 1e5)
5991
+ Array.prototype.push.apply(target, source);
5992
+ else
5993
+ for (let i = 0;i < source.length; ++i)
5994
+ target.push(source[i]);
5995
+ }
5970
5996
  function fixFlowSeqItems(fc) {
5971
5997
  if (fc.start.type === "flow-seq-start") {
5972
5998
  for (const it of fc.items) {
@@ -5976,11 +6002,11 @@ var require_parser = __commonJS2((exports) => {
5976
6002
  delete it.key;
5977
6003
  if (isFlowToken(it.value)) {
5978
6004
  if (it.value.end)
5979
- Array.prototype.push.apply(it.value.end, it.sep);
6005
+ arrayPushArray(it.value.end, it.sep);
5980
6006
  else
5981
6007
  it.value.end = it.sep;
5982
6008
  } else
5983
- Array.prototype.push.apply(it.start, it.sep);
6009
+ arrayPushArray(it.start, it.sep);
5984
6010
  delete it.sep;
5985
6011
  }
5986
6012
  }
@@ -6320,7 +6346,7 @@ var require_parser = __commonJS2((exports) => {
6320
6346
  const prev = map.items[map.items.length - 2];
6321
6347
  const end = prev?.value?.end;
6322
6348
  if (Array.isArray(end)) {
6323
- Array.prototype.push.apply(end, it.start);
6349
+ arrayPushArray(end, it.start);
6324
6350
  end.push(this.sourceToken);
6325
6351
  map.items.pop();
6326
6352
  return;
@@ -6508,7 +6534,7 @@ var require_parser = __commonJS2((exports) => {
6508
6534
  const prev = seq.items[seq.items.length - 2];
6509
6535
  const end = prev?.value?.end;
6510
6536
  if (Array.isArray(end)) {
6511
- Array.prototype.push.apply(end, it.start);
6537
+ arrayPushArray(end, it.start);
6512
6538
  end.push(this.sourceToken);
6513
6539
  seq.items.pop();
6514
6540
  return;
@@ -6902,6 +6928,7 @@ var PIPELINE_PROVIDER_CHOICES = [
6902
6928
  var SYNTHESIS_PROVIDER_CHOICES = PIPELINE_PROVIDER_CHOICES.filter((provider) => provider !== "command");
6903
6929
  var PIPELINE_PROVIDER_SET = new Set(PIPELINE_PROVIDER_CHOICES);
6904
6930
  var SYNTHESIS_PROVIDER_SET = new Set(SYNTHESIS_PROVIDER_CHOICES);
6931
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
6905
6932
  var MEMORIES_FTS_TOKENIZER = "unicode61";
6906
6933
  function normalizeSql(sql) {
6907
6934
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -9999,6 +10026,243 @@ function up92(db) {
9999
10026
  ON embeddings_staging(agent_id, source_type, source_id);
10000
10027
  `);
10001
10028
  }
10029
+ function up93(db) {
10030
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10031
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
10032
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
10033
+ }
10034
+ }
10035
+ var DERIVED_SOURCE_TYPES = DAEMON_DERIVED_MEMORY_SOURCE_TYPES;
10036
+ function hasColumn13(db, table, column) {
10037
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10038
+ return rows.some((r) => r.name === column);
10039
+ }
10040
+ function up94(db) {
10041
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
10042
+ if (tables.length === 0)
10043
+ return;
10044
+ if (!hasColumn13(db, "memories", "memory_kind")) {
10045
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
10046
+ }
10047
+ if (!hasColumn13(db, "memories", "evidence_meta")) {
10048
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
10049
+ }
10050
+ if (hasColumn13(db, "memories", "source_type")) {
10051
+ const placeholders = DERIVED_SOURCE_TYPES.map(() => "?").join(", ");
10052
+ db.prepare(`UPDATE memories
10053
+ SET memory_kind = 'episodic'
10054
+ WHERE memory_kind IS NULL
10055
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES);
10056
+ } else {
10057
+ db.exec(`UPDATE memories
10058
+ SET memory_kind = 'episodic'
10059
+ WHERE memory_kind IS NULL`);
10060
+ }
10061
+ }
10062
+ function hasColumn14(db, table, column) {
10063
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10064
+ }
10065
+ function up95(db) {
10066
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
10067
+ if (!hasMemories || !hasColumn14(db, "memories", "memory_kind") || !hasColumn14(db, "memories", "type"))
10068
+ return;
10069
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
10070
+ }
10071
+ function up96(db) {
10072
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
10073
+ }
10074
+ function up97(db) {
10075
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
10076
+ if (!columns.some((column) => column.name === "last_failure_at")) {
10077
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
10078
+ }
10079
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
10080
+ }
10081
+ function up98(db) {
10082
+ db.exec(`
10083
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
10084
+ agent_id TEXT NOT NULL,
10085
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
10086
+ source_id TEXT NOT NULL,
10087
+ reason TEXT NOT NULL,
10088
+ pass_id TEXT NOT NULL,
10089
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
10090
+ requeue_requested_at TEXT,
10091
+ resolved_at TEXT,
10092
+ PRIMARY KEY (agent_id, source_kind, source_id)
10093
+ );
10094
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
10095
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
10096
+ `);
10097
+ }
10098
+ function up99(db) {
10099
+ db.exec(`
10100
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
10101
+ id TEXT PRIMARY KEY,
10102
+ agent_id TEXT NOT NULL,
10103
+ pass_id TEXT NOT NULL,
10104
+ sequence INTEGER NOT NULL,
10105
+ tool_call_id TEXT,
10106
+ tool_name TEXT NOT NULL,
10107
+ input_json TEXT NOT NULL,
10108
+ output_json TEXT NOT NULL,
10109
+ success INTEGER NOT NULL,
10110
+ latency_ms INTEGER NOT NULL,
10111
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10112
+ UNIQUE(agent_id, pass_id, sequence)
10113
+ );
10114
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
10115
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
10116
+ `);
10117
+ }
10118
+ function up100(db) {
10119
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
10120
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
10121
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
10122
+ }
10123
+ if (!columns.some((column) => column.name === "runbook_json")) {
10124
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
10125
+ }
10126
+ }
10127
+ function up101(db) {
10128
+ db.exec(`
10129
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
10130
+ id TEXT PRIMARY KEY,
10131
+ agent_id TEXT NOT NULL,
10132
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
10133
+ subject_ref TEXT NOT NULL,
10134
+ details_json TEXT NOT NULL DEFAULT '{}',
10135
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
10136
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10137
+ generation INTEGER NOT NULL DEFAULT 0,
10138
+ resolved_at TEXT,
10139
+ resolved_by_pass_id TEXT,
10140
+ UNIQUE(agent_id, kind, subject_ref)
10141
+ );
10142
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
10143
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
10144
+ `);
10145
+ }
10146
+ function hasColumn15(db, table, column) {
10147
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10148
+ }
10149
+ function up102(db) {
10150
+ const requiredMemoryColumns = [
10151
+ "content_hash",
10152
+ "normalized_content",
10153
+ "memory_kind",
10154
+ "source_type",
10155
+ "source_path",
10156
+ "agent_id",
10157
+ "visibility",
10158
+ "is_deleted",
10159
+ "extraction_status"
10160
+ ];
10161
+ if (!hasColumn15(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn15(db, "memories", column))) {
10162
+ return;
10163
+ }
10164
+ db.exec(`
10165
+ INSERT OR IGNORE INTO memories
10166
+ (id, content, normalized_content, content_hash, who, why, project,
10167
+ importance, type, tags, pinned, is_deleted, extraction_status,
10168
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
10169
+ agent_id, visibility, memory_kind)
10170
+ SELECT attr.id, attr.content, attr.normalized_content,
10171
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
10172
+ attr.importance, 'semantic', 'semantic,attribute', 0,
10173
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
10174
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
10175
+ attr.agent_id, 'global', 'derived'
10176
+ FROM entity_attributes attr
10177
+ WHERE attr.memory_id IS NULL
10178
+ `);
10179
+ db.exec(`
10180
+ UPDATE entity_attributes
10181
+ SET memory_id = id
10182
+ WHERE memory_id IS NULL
10183
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
10184
+ `);
10185
+ db.exec(`
10186
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
10187
+ SELECT attr.memory_id, aspect.entity_id
10188
+ FROM entity_attributes attr
10189
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
10190
+ WHERE attr.memory_id IS NOT NULL
10191
+ `);
10192
+ db.exec(`
10193
+ UPDATE entities
10194
+ SET mentions = (
10195
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
10196
+ )
10197
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
10198
+ `);
10199
+ }
10200
+ function up103(db) {
10201
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
10202
+ if (tables.length !== 2)
10203
+ return;
10204
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
10205
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
10206
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
10207
+ return;
10208
+ db.exec(`
10209
+ UPDATE memories
10210
+ SET memory_kind = 'derived'
10211
+ WHERE memory_kind IS NULL
10212
+ AND id IN (
10213
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
10214
+ )
10215
+ `);
10216
+ }
10217
+ function tableExists(db, table) {
10218
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
10219
+ }
10220
+ function hasColumn16(db, table, column) {
10221
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
10222
+ }
10223
+ function up104(db) {
10224
+ db.exec(`
10225
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
10226
+ derived_memory_id TEXT NOT NULL,
10227
+ source_kind TEXT NOT NULL,
10228
+ source_id TEXT NOT NULL,
10229
+ source_path TEXT,
10230
+ agent_id TEXT NOT NULL,
10231
+ created_at TEXT NOT NULL,
10232
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
10233
+ );
10234
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
10235
+ ON derived_memory_sources(agent_id, derived_memory_id);
10236
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
10237
+ ON derived_memory_sources(agent_id, source_kind, source_id);
10238
+ `);
10239
+ if (tableExists(db, "aggregate_evidence_sources")) {
10240
+ db.exec(`
10241
+ INSERT OR IGNORE INTO derived_memory_sources
10242
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10243
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
10244
+ FROM aggregate_evidence_sources
10245
+ `);
10246
+ }
10247
+ if (tableExists(db, "aggregate_memory_sources")) {
10248
+ db.exec(`
10249
+ INSERT OR IGNORE INTO derived_memory_sources
10250
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
10251
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
10252
+ FROM aggregate_memory_sources
10253
+ `);
10254
+ }
10255
+ if (tableExists(db, "memories") && !hasColumn16(db, "memories", "stale_at")) {
10256
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
10257
+ }
10258
+ if (tableExists(db, "memories")) {
10259
+ db.exec(`
10260
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
10261
+ ON memories(agent_id, stale_at)
10262
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
10263
+ `);
10264
+ }
10265
+ }
10002
10266
  var MIGRATIONS = [
10003
10267
  {
10004
10268
  version: 1,
@@ -10083,7 +10347,6 @@ var MIGRATIONS = [
10083
10347
  name: "ingestion-tracking",
10084
10348
  up: up13,
10085
10349
  artifacts: {
10086
- tables: ["ingestion_jobs"],
10087
10350
  columns: [
10088
10351
  { table: "memories", column: "source_path" },
10089
10352
  { table: "memories", column: "source_section" }
@@ -10746,6 +11009,87 @@ var MIGRATIONS = [
10746
11009
  name: "embedding-staging-store",
10747
11010
  up: up92,
10748
11011
  artifacts: { tables: ["embeddings_staging"] }
11012
+ },
11013
+ {
11014
+ version: 93,
11015
+ name: "dreaming-evidence-cursor",
11016
+ up: up93,
11017
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
11018
+ },
11019
+ {
11020
+ version: 94,
11021
+ name: "memory-kind",
11022
+ up: up94,
11023
+ artifacts: {
11024
+ columns: [
11025
+ { table: "memories", column: "memory_kind" },
11026
+ { table: "memories", column: "evidence_meta" }
11027
+ ]
11028
+ }
11029
+ },
11030
+ {
11031
+ version: 95,
11032
+ name: "compaction-recall-projections",
11033
+ up: up95
11034
+ },
11035
+ {
11036
+ version: 96,
11037
+ name: "retire-legacy-ingestion",
11038
+ up: up96
11039
+ },
11040
+ {
11041
+ version: 97,
11042
+ name: "dreaming-failure-backoff",
11043
+ up: up97,
11044
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
11045
+ },
11046
+ {
11047
+ version: 98,
11048
+ name: "dreaming-evidence-exclusions",
11049
+ up: up98,
11050
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
11051
+ },
11052
+ {
11053
+ version: 99,
11054
+ name: "dreaming-tool-calls",
11055
+ up: up99,
11056
+ artifacts: { tables: ["dreaming_tool_calls"] }
11057
+ },
11058
+ {
11059
+ version: 100,
11060
+ name: "dreaming-runbook",
11061
+ up: up100,
11062
+ artifacts: {
11063
+ columns: [
11064
+ { table: "dreaming_passes", column: "evidence_window_json" },
11065
+ { table: "dreaming_passes", column: "runbook_json" }
11066
+ ]
11067
+ }
11068
+ },
11069
+ {
11070
+ version: 101,
11071
+ name: "dreaming-attention",
11072
+ up: up101,
11073
+ artifacts: { tables: ["dreaming_attention"] }
11074
+ },
11075
+ {
11076
+ version: 102,
11077
+ name: "attribute-semantic-memories",
11078
+ up: up102
11079
+ },
11080
+ {
11081
+ version: 103,
11082
+ name: "semantic-memory-kind",
11083
+ up: up103
11084
+ },
11085
+ {
11086
+ version: 104,
11087
+ name: "derived-memory-provenance",
11088
+ up: up104,
11089
+ artifacts: {
11090
+ tables: ["derived_memory_sources"],
11091
+ columns: [{ table: "memories", column: "stale_at" }]
11092
+ }
10749
11093
  }
10750
11094
  ];
10751
11095
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -11083,122 +11427,6 @@ function stripSignetBlock(content) {
11083
11427
  function escapeRegex(str) {
11084
11428
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11085
11429
  }
11086
- var SKIP_SUBTYPES = new Set([
11087
- "channel_join",
11088
- "channel_leave",
11089
- "channel_topic",
11090
- "channel_purpose",
11091
- "channel_name",
11092
- "channel_archive",
11093
- "channel_unarchive",
11094
- "group_join",
11095
- "group_leave",
11096
- "group_topic",
11097
- "group_purpose",
11098
- "group_name",
11099
- "group_archive",
11100
- "group_unarchive",
11101
- "pinned_item",
11102
- "unpinned_item",
11103
- "bot_add",
11104
- "bot_remove",
11105
- "tombstone",
11106
- "file_comment",
11107
- "sh_room_created",
11108
- "sh_room_shared"
11109
- ]);
11110
- var SKIP_TYPES = new Set([
11111
- "RecipientAdd",
11112
- "RecipientRemove",
11113
- "ChannelNameChange",
11114
- "ChannelIconChange",
11115
- "ChannelPinnedMessage",
11116
- "GuildMemberJoin",
11117
- "UserPremiumGuildSubscription",
11118
- "UserPremiumGuildSubscriptionTier1",
11119
- "UserPremiumGuildSubscriptionTier2",
11120
- "UserPremiumGuildSubscriptionTier3",
11121
- "ChannelFollowAdd",
11122
- "GuildDiscoveryDisqualified",
11123
- "GuildDiscoveryRequalified",
11124
- "GuildDiscoveryGracePeriodInitialWarning",
11125
- "GuildDiscoveryGracePeriodFinalWarning",
11126
- "ThreadCreated",
11127
- "ApplicationCommand"
11128
- ]);
11129
- var SKIP_DIRS = new Set([
11130
- "node_modules",
11131
- ".git",
11132
- "dist",
11133
- "build",
11134
- "out",
11135
- "target",
11136
- ".next",
11137
- ".nuxt",
11138
- "__pycache__",
11139
- ".tox",
11140
- ".mypy_cache",
11141
- ".pytest_cache",
11142
- "venv",
11143
- ".venv",
11144
- "env",
11145
- "vendor",
11146
- "coverage",
11147
- ".cache",
11148
- ".turbo"
11149
- ]);
11150
- var DOCUMENT_VALID_TYPES = new Set([
11151
- "fact",
11152
- "decision",
11153
- "rationale",
11154
- "preference",
11155
- "procedural",
11156
- "semantic",
11157
- "system",
11158
- "configuration",
11159
- "architectural",
11160
- "relationship",
11161
- "episodic",
11162
- "daily-log"
11163
- ]);
11164
- var ENTIRE_VALID_TYPES = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
11165
- var CHAT_VALID_TYPES = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
11166
- var MARKDOWN_EXTS = new Set([".md", ".mdx", ".markdown"]);
11167
- var TXT_EXTS = new Set([".txt", ".text", ".log", ".rst"]);
11168
- var PDF_EXTS = new Set([".pdf"]);
11169
- var CODE_EXTS = new Set([
11170
- ".ts",
11171
- ".tsx",
11172
- ".js",
11173
- ".jsx",
11174
- ".py",
11175
- ".rs",
11176
- ".go",
11177
- ".java",
11178
- ".rb",
11179
- ".php",
11180
- ".swift",
11181
- ".kt",
11182
- ".scala",
11183
- ".c",
11184
- ".cpp",
11185
- ".h",
11186
- ".hpp",
11187
- ".sh",
11188
- ".bash",
11189
- ".zsh",
11190
- ".sql",
11191
- ".yaml",
11192
- ".yml",
11193
- ".toml",
11194
- ".json",
11195
- ".xml",
11196
- ".css",
11197
- ".scss",
11198
- ".html",
11199
- ".htm"
11200
- ]);
11201
- var SKIP_FILES = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
11202
11430
 
11203
11431
  class BaseConnector {
11204
11432
  stripSignetBlock(content) {
@@ -11899,6 +12127,8 @@ var require_Alias2 = __commonJS((exports) => {
11899
12127
  });
11900
12128
  }
11901
12129
  resolve(doc, ctx) {
12130
+ if (ctx?.maxAliasCount === 0)
12131
+ throw new ReferenceError("Alias resolution is disabled");
11902
12132
  let nodes;
11903
12133
  if (ctx?.aliasResolveCache) {
11904
12134
  nodes = ctx.aliasResolveCache;
@@ -12928,18 +13158,18 @@ var require_merge2 = __commonJS((exports) => {
12928
13158
  };
12929
13159
  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);
12930
13160
  function addMergeToJSMap(ctx, map, value) {
12931
- value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
12932
- if (identity.isSeq(value))
12933
- for (const it of value.items)
13161
+ const source = resolveAliasValue(ctx, value);
13162
+ if (identity.isSeq(source))
13163
+ for (const it of source.items)
12934
13164
  mergeValue(ctx, map, it);
12935
- else if (Array.isArray(value))
12936
- for (const it of value)
13165
+ else if (Array.isArray(source))
13166
+ for (const it of source)
12937
13167
  mergeValue(ctx, map, it);
12938
13168
  else
12939
- mergeValue(ctx, map, value);
13169
+ mergeValue(ctx, map, source);
12940
13170
  }
12941
13171
  function mergeValue(ctx, map, value) {
12942
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
13172
+ const source = resolveAliasValue(ctx, value);
12943
13173
  if (!identity.isMap(source))
12944
13174
  throw new Error("Merge sources must be maps or map aliases");
12945
13175
  const srcMap = source.toJSON(null, ctx, Map);
@@ -12960,6 +13190,9 @@ var require_merge2 = __commonJS((exports) => {
12960
13190
  }
12961
13191
  return map;
12962
13192
  }
13193
+ function resolveAliasValue(ctx, value) {
13194
+ return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
13195
+ }
12963
13196
  exports.addMergeToJSMap = addMergeToJSMap;
12964
13197
  exports.isMergeKey = isMergeKey;
12965
13198
  exports.merge = merge;
@@ -13513,7 +13746,7 @@ var require_stringifyNumber2 = __commonJS((exports) => {
13513
13746
  if (!isFinite(num))
13514
13747
  return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
13515
13748
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
13516
- if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
13749
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
13517
13750
  let i = n.indexOf(".");
13518
13751
  if (i < 0) {
13519
13752
  i = n.length;
@@ -15681,7 +15914,7 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15681
15914
  while (next === " " || next === "\t")
15682
15915
  next = source[++i + 1];
15683
15916
  } else if (next === "x" || next === "u" || next === "U") {
15684
- const length = { x: 2, u: 4, U: 8 }[next];
15917
+ const length = next === "x" ? 2 : next === "u" ? 4 : 8;
15685
15918
  res += parseCharCode(source, i + 1, length, onError);
15686
15919
  i += length;
15687
15920
  } else {
@@ -15750,12 +15983,13 @@ var require_resolve_flow_scalar2 = __commonJS((exports) => {
15750
15983
  const cc = source.substr(offset, length);
15751
15984
  const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
15752
15985
  const code = ok ? parseInt(cc, 16) : NaN;
15753
- if (isNaN(code)) {
15986
+ try {
15987
+ return String.fromCodePoint(code);
15988
+ } catch {
15754
15989
  const raw = source.substr(offset - 2, length + 2);
15755
15990
  onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
15756
15991
  return raw;
15757
15992
  }
15758
- return String.fromCodePoint(code);
15759
15993
  }
15760
15994
  exports.resolveFlowScalar = resolveFlowScalar;
15761
15995
  });
@@ -16084,8 +16318,10 @@ ${cb}` : comment;
16084
16318
  }
16085
16319
  }
16086
16320
  if (afterDoc) {
16087
- Array.prototype.push.apply(doc.errors, this.errors);
16088
- Array.prototype.push.apply(doc.warnings, this.warnings);
16321
+ for (let i = 0;i < this.errors.length; ++i)
16322
+ doc.errors.push(this.errors[i]);
16323
+ for (let i = 0;i < this.warnings.length; ++i)
16324
+ doc.warnings.push(this.warnings[i]);
16089
16325
  } else {
16090
16326
  doc.errors = this.errors;
16091
16327
  doc.warnings = this.warnings;
@@ -16787,7 +17023,7 @@ var require_lexer2 = __commonJS((exports) => {
16787
17023
  const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
16788
17024
  this.indentNext = this.indentValue + 1;
16789
17025
  this.indentValue += n;
16790
- return yield* this.parseBlockStart();
17026
+ return "block-start";
16791
17027
  }
16792
17028
  return "doc";
16793
17029
  }
@@ -17094,26 +17330,37 @@ var require_lexer2 = __commonJS((exports) => {
17094
17330
  return 0;
17095
17331
  }
17096
17332
  *pushIndicators() {
17097
- switch (this.charAt(0)) {
17098
- case "!":
17099
- return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
17100
- case "&":
17101
- return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
17102
- case "-":
17103
- case "?":
17104
- case ":": {
17105
- const inFlow = this.flowLevel > 0;
17106
- const ch1 = this.charAt(1);
17107
- if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
17108
- if (!inFlow)
17109
- this.indentNext = this.indentValue + 1;
17110
- else if (this.flowKey)
17111
- this.flowKey = false;
17112
- return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
17333
+ let n = 0;
17334
+ loop:
17335
+ while (true) {
17336
+ switch (this.charAt(0)) {
17337
+ case "!":
17338
+ n += yield* this.pushTag();
17339
+ n += yield* this.pushSpaces(true);
17340
+ continue loop;
17341
+ case "&":
17342
+ n += yield* this.pushUntil(isNotAnchorChar);
17343
+ n += yield* this.pushSpaces(true);
17344
+ continue loop;
17345
+ case "-":
17346
+ case "?":
17347
+ case ":": {
17348
+ const inFlow = this.flowLevel > 0;
17349
+ const ch1 = this.charAt(1);
17350
+ if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
17351
+ if (!inFlow)
17352
+ this.indentNext = this.indentValue + 1;
17353
+ else if (this.flowKey)
17354
+ this.flowKey = false;
17355
+ n += yield* this.pushCount(1);
17356
+ n += yield* this.pushSpaces(true);
17357
+ continue loop;
17358
+ }
17359
+ }
17113
17360
  }
17361
+ break loop;
17114
17362
  }
17115
- }
17116
- return 0;
17363
+ return n;
17117
17364
  }
17118
17365
  *pushTag() {
17119
17366
  if (this.charAt(1) === "<") {
@@ -17264,6 +17511,13 @@ var require_parser2 = __commonJS((exports) => {
17264
17511
  while (prev[++i]?.type === "space") {}
17265
17512
  return prev.splice(i, prev.length);
17266
17513
  }
17514
+ function arrayPushArray(target, source) {
17515
+ if (source.length < 1e5)
17516
+ Array.prototype.push.apply(target, source);
17517
+ else
17518
+ for (let i = 0;i < source.length; ++i)
17519
+ target.push(source[i]);
17520
+ }
17267
17521
  function fixFlowSeqItems(fc) {
17268
17522
  if (fc.start.type === "flow-seq-start") {
17269
17523
  for (const it of fc.items) {
@@ -17273,11 +17527,11 @@ var require_parser2 = __commonJS((exports) => {
17273
17527
  delete it.key;
17274
17528
  if (isFlowToken(it.value)) {
17275
17529
  if (it.value.end)
17276
- Array.prototype.push.apply(it.value.end, it.sep);
17530
+ arrayPushArray(it.value.end, it.sep);
17277
17531
  else
17278
17532
  it.value.end = it.sep;
17279
17533
  } else
17280
- Array.prototype.push.apply(it.start, it.sep);
17534
+ arrayPushArray(it.start, it.sep);
17281
17535
  delete it.sep;
17282
17536
  }
17283
17537
  }
@@ -17617,7 +17871,7 @@ var require_parser2 = __commonJS((exports) => {
17617
17871
  const prev = map.items[map.items.length - 2];
17618
17872
  const end = prev?.value?.end;
17619
17873
  if (Array.isArray(end)) {
17620
- Array.prototype.push.apply(end, it.start);
17874
+ arrayPushArray(end, it.start);
17621
17875
  end.push(this.sourceToken);
17622
17876
  map.items.pop();
17623
17877
  return;
@@ -17805,7 +18059,7 @@ var require_parser2 = __commonJS((exports) => {
17805
18059
  const prev = seq.items[seq.items.length - 2];
17806
18060
  const end = prev?.value?.end;
17807
18061
  if (Array.isArray(end)) {
17808
- Array.prototype.push.apply(end, it.start);
18062
+ arrayPushArray(end, it.start);
17809
18063
  end.push(this.sourceToken);
17810
18064
  seq.items.pop();
17811
18065
  return;
@@ -18199,6 +18453,7 @@ var PIPELINE_PROVIDER_CHOICES2 = [
18199
18453
  var SYNTHESIS_PROVIDER_CHOICES2 = PIPELINE_PROVIDER_CHOICES2.filter((provider) => provider !== "command");
18200
18454
  var PIPELINE_PROVIDER_SET2 = new Set(PIPELINE_PROVIDER_CHOICES2);
18201
18455
  var SYNTHESIS_PROVIDER_SET2 = new Set(SYNTHESIS_PROVIDER_CHOICES2);
18456
+ var DAEMON_DERIVED_MEMORY_SOURCE_TYPES2 = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
18202
18457
  var MEMORIES_FTS_TOKENIZER2 = "unicode61";
18203
18458
  function normalizeSql2(sql) {
18204
18459
  return sql.replace(/\s+/g, " ").trim().toLowerCase();
@@ -18249,7 +18504,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
18249
18504
  return true;
18250
18505
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
18251
18506
  }
18252
- function up93(db) {
18507
+ function up105(db) {
18253
18508
  db.exec(`
18254
18509
  CREATE TABLE IF NOT EXISTS schema_migrations (
18255
18510
  version INTEGER PRIMARY KEY,
@@ -18338,12 +18593,12 @@ function up93(db) {
18338
18593
  } catch {}
18339
18594
  createMemoriesFts2(db);
18340
18595
  }
18341
- function hasColumn13(db, table, column) {
18596
+ function hasColumn17(db, table, column) {
18342
18597
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
18343
18598
  return rows.some((r) => r.name === column);
18344
18599
  }
18345
18600
  function addColumnIfMissing23(db, table, column, definition) {
18346
- if (!hasColumn13(db, table, column)) {
18601
+ if (!hasColumn17(db, table, column)) {
18347
18602
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
18348
18603
  }
18349
18604
  }
@@ -18641,7 +18896,7 @@ function up810(db) {
18641
18896
  ON embeddings(content_hash)
18642
18897
  `);
18643
18898
  }
18644
- function up94(db) {
18899
+ function up910(db) {
18645
18900
  db.exec(`
18646
18901
  CREATE TABLE IF NOT EXISTS summary_jobs (
18647
18902
  id TEXT PRIMARY KEY,
@@ -18661,7 +18916,7 @@ function up94(db) {
18661
18916
  db.exec(`CREATE INDEX IF NOT EXISTS idx_summary_jobs_status
18662
18917
  ON summary_jobs(status)`);
18663
18918
  }
18664
- function up102(db) {
18919
+ function up106(db) {
18665
18920
  db.exec(`
18666
18921
  CREATE TABLE IF NOT EXISTS umap_cache (
18667
18922
  id INTEGER PRIMARY KEY,
@@ -21296,11 +21551,248 @@ function up922(db) {
21296
21551
  ON embeddings_staging(agent_id, source_type, source_id);
21297
21552
  `);
21298
21553
  }
21554
+ function up932(db) {
21555
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21556
+ if (!columns.some((column) => column.name === "evidence_cursor")) {
21557
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN evidence_cursor TEXT");
21558
+ }
21559
+ }
21560
+ var DERIVED_SOURCE_TYPES2 = DAEMON_DERIVED_MEMORY_SOURCE_TYPES2;
21561
+ function hasColumn132(db, table, column) {
21562
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
21563
+ return rows.some((r) => r.name === column);
21564
+ }
21565
+ function up942(db) {
21566
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'memories'").all();
21567
+ if (tables.length === 0)
21568
+ return;
21569
+ if (!hasColumn132(db, "memories", "memory_kind")) {
21570
+ db.exec("ALTER TABLE memories ADD COLUMN memory_kind TEXT");
21571
+ }
21572
+ if (!hasColumn132(db, "memories", "evidence_meta")) {
21573
+ db.exec("ALTER TABLE memories ADD COLUMN evidence_meta TEXT");
21574
+ }
21575
+ if (hasColumn132(db, "memories", "source_type")) {
21576
+ const placeholders = DERIVED_SOURCE_TYPES2.map(() => "?").join(", ");
21577
+ db.prepare(`UPDATE memories
21578
+ SET memory_kind = 'episodic'
21579
+ WHERE memory_kind IS NULL
21580
+ AND (source_type IS NULL OR source_type NOT IN (${placeholders}))`).run(...DERIVED_SOURCE_TYPES2);
21581
+ } else {
21582
+ db.exec(`UPDATE memories
21583
+ SET memory_kind = 'episodic'
21584
+ WHERE memory_kind IS NULL`);
21585
+ }
21586
+ }
21587
+ function hasColumn142(db, table, column) {
21588
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21589
+ }
21590
+ function up952(db) {
21591
+ const hasMemories = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'memories'").get();
21592
+ if (!hasMemories || !hasColumn142(db, "memories", "memory_kind") || !hasColumn142(db, "memories", "type"))
21593
+ return;
21594
+ db.exec("UPDATE memories SET memory_kind = NULL WHERE type = 'session_summary'");
21595
+ }
21596
+ function up962(db) {
21597
+ db.exec("DROP TABLE IF EXISTS ingestion_jobs");
21598
+ }
21599
+ function up972(db) {
21600
+ const columns = db.prepare("PRAGMA table_info(dreaming_state)").all();
21601
+ if (!columns.some((column) => column.name === "last_failure_at")) {
21602
+ db.exec("ALTER TABLE dreaming_state ADD COLUMN last_failure_at TEXT");
21603
+ }
21604
+ db.exec("UPDATE dreaming_state SET last_failure_at = updated_at WHERE consecutive_failures > 0 AND last_failure_at IS NULL");
21605
+ }
21606
+ function up982(db) {
21607
+ db.exec(`
21608
+ CREATE TABLE IF NOT EXISTS dreaming_evidence_exclusions (
21609
+ agent_id TEXT NOT NULL,
21610
+ source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary')),
21611
+ source_id TEXT NOT NULL,
21612
+ reason TEXT NOT NULL,
21613
+ pass_id TEXT NOT NULL,
21614
+ excluded_at TEXT NOT NULL DEFAULT (datetime('now')),
21615
+ requeue_requested_at TEXT,
21616
+ resolved_at TEXT,
21617
+ PRIMARY KEY (agent_id, source_kind, source_id)
21618
+ );
21619
+ CREATE INDEX IF NOT EXISTS idx_dreaming_evidence_exclusions_active
21620
+ ON dreaming_evidence_exclusions (agent_id, resolved_at, requeue_requested_at, excluded_at DESC);
21621
+ `);
21622
+ }
21623
+ function up992(db) {
21624
+ db.exec(`
21625
+ CREATE TABLE IF NOT EXISTS dreaming_tool_calls (
21626
+ id TEXT PRIMARY KEY,
21627
+ agent_id TEXT NOT NULL,
21628
+ pass_id TEXT NOT NULL,
21629
+ sequence INTEGER NOT NULL,
21630
+ tool_call_id TEXT,
21631
+ tool_name TEXT NOT NULL,
21632
+ input_json TEXT NOT NULL,
21633
+ output_json TEXT NOT NULL,
21634
+ success INTEGER NOT NULL,
21635
+ latency_ms INTEGER NOT NULL,
21636
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21637
+ UNIQUE(agent_id, pass_id, sequence)
21638
+ );
21639
+ CREATE INDEX IF NOT EXISTS idx_dreaming_tool_calls_pass
21640
+ ON dreaming_tool_calls (agent_id, pass_id, sequence ASC);
21641
+ `);
21642
+ }
21643
+ function up1002(db) {
21644
+ const columns = db.prepare("PRAGMA table_info(dreaming_passes)").all();
21645
+ if (!columns.some((column) => column.name === "evidence_window_json")) {
21646
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN evidence_window_json TEXT");
21647
+ }
21648
+ if (!columns.some((column) => column.name === "runbook_json")) {
21649
+ db.exec("ALTER TABLE dreaming_passes ADD COLUMN runbook_json TEXT");
21650
+ }
21651
+ }
21652
+ function up1012(db) {
21653
+ db.exec(`
21654
+ CREATE TABLE IF NOT EXISTS dreaming_attention (
21655
+ id TEXT PRIMARY KEY,
21656
+ agent_id TEXT NOT NULL,
21657
+ kind TEXT NOT NULL CHECK (kind IN ('review_due', 'hygiene', 'contested_claim', 'evidence_requeue')),
21658
+ subject_ref TEXT NOT NULL,
21659
+ details_json TEXT NOT NULL DEFAULT '{}',
21660
+ priority INTEGER NOT NULL DEFAULT 0 CHECK (priority >= 0 AND priority <= 100),
21661
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
21662
+ generation INTEGER NOT NULL DEFAULT 0,
21663
+ resolved_at TEXT,
21664
+ resolved_by_pass_id TEXT,
21665
+ UNIQUE(agent_id, kind, subject_ref)
21666
+ );
21667
+ CREATE INDEX IF NOT EXISTS idx_dreaming_attention_pending
21668
+ ON dreaming_attention (agent_id, resolved_at, priority DESC, created_at ASC);
21669
+ `);
21670
+ }
21671
+ function hasColumn152(db, table, column) {
21672
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21673
+ }
21674
+ function up1022(db) {
21675
+ const requiredMemoryColumns = [
21676
+ "content_hash",
21677
+ "normalized_content",
21678
+ "memory_kind",
21679
+ "source_type",
21680
+ "source_path",
21681
+ "agent_id",
21682
+ "visibility",
21683
+ "is_deleted",
21684
+ "extraction_status"
21685
+ ];
21686
+ if (!hasColumn152(db, "entity_attributes", "memory_id") || !requiredMemoryColumns.every((column) => hasColumn152(db, "memories", column))) {
21687
+ return;
21688
+ }
21689
+ db.exec(`
21690
+ INSERT OR IGNORE INTO memories
21691
+ (id, content, normalized_content, content_hash, who, why, project,
21692
+ importance, type, tags, pinned, is_deleted, extraction_status,
21693
+ created_at, updated_at, updated_by, source_type, source_id, source_path,
21694
+ agent_id, visibility, memory_kind)
21695
+ SELECT attr.id, attr.content, attr.normalized_content,
21696
+ 'semantic-attribute:' || attr.id, 'dreaming', 'Derived semantic attribute', NULL,
21697
+ attr.importance, 'semantic', 'semantic,attribute', 0,
21698
+ CASE WHEN attr.status = 'active' THEN 0 ELSE 1 END, 'completed',
21699
+ attr.created_at, attr.updated_at, 'dreaming', 'dreaming', attr.source_id, attr.source_path,
21700
+ attr.agent_id, 'global', 'derived'
21701
+ FROM entity_attributes attr
21702
+ WHERE attr.memory_id IS NULL
21703
+ `);
21704
+ db.exec(`
21705
+ UPDATE entity_attributes
21706
+ SET memory_id = id
21707
+ WHERE memory_id IS NULL
21708
+ AND EXISTS (SELECT 1 FROM memories WHERE memories.id = entity_attributes.id)
21709
+ `);
21710
+ db.exec(`
21711
+ INSERT OR IGNORE INTO memory_entity_mentions (memory_id, entity_id)
21712
+ SELECT attr.memory_id, aspect.entity_id
21713
+ FROM entity_attributes attr
21714
+ JOIN entity_aspects aspect ON aspect.id = attr.aspect_id AND aspect.agent_id = attr.agent_id
21715
+ WHERE attr.memory_id IS NOT NULL
21716
+ `);
21717
+ db.exec(`
21718
+ UPDATE entities
21719
+ SET mentions = (
21720
+ SELECT COUNT(*) FROM memory_entity_mentions WHERE entity_id = entities.id
21721
+ )
21722
+ WHERE EXISTS (SELECT 1 FROM memory_entity_mentions WHERE entity_id = entities.id)
21723
+ `);
21724
+ }
21725
+ function up1032(db) {
21726
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('memories', 'entity_attributes')").all();
21727
+ if (tables.length !== 2)
21728
+ return;
21729
+ const memoryColumns = db.prepare("PRAGMA table_info(memories)").all().map((row) => row.name);
21730
+ const attributeColumns = db.prepare("PRAGMA table_info(entity_attributes)").all().map((row) => row.name);
21731
+ if (!memoryColumns.includes("memory_kind") || !attributeColumns.includes("memory_id"))
21732
+ return;
21733
+ db.exec(`
21734
+ UPDATE memories
21735
+ SET memory_kind = 'derived'
21736
+ WHERE memory_kind IS NULL
21737
+ AND id IN (
21738
+ SELECT memory_id FROM entity_attributes WHERE memory_id IS NOT NULL
21739
+ )
21740
+ `);
21741
+ }
21742
+ function tableExists2(db, table) {
21743
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
21744
+ }
21745
+ function hasColumn162(db, table, column) {
21746
+ return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
21747
+ }
21748
+ function up1042(db) {
21749
+ db.exec(`
21750
+ CREATE TABLE IF NOT EXISTS derived_memory_sources (
21751
+ derived_memory_id TEXT NOT NULL,
21752
+ source_kind TEXT NOT NULL,
21753
+ source_id TEXT NOT NULL,
21754
+ source_path TEXT,
21755
+ agent_id TEXT NOT NULL,
21756
+ created_at TEXT NOT NULL,
21757
+ PRIMARY KEY (derived_memory_id, source_kind, source_id)
21758
+ );
21759
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_derived
21760
+ ON derived_memory_sources(agent_id, derived_memory_id);
21761
+ CREATE INDEX IF NOT EXISTS idx_derived_memory_sources_source
21762
+ ON derived_memory_sources(agent_id, source_kind, source_id);
21763
+ `);
21764
+ if (tableExists2(db, "aggregate_evidence_sources")) {
21765
+ db.exec(`
21766
+ INSERT OR IGNORE INTO derived_memory_sources
21767
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21768
+ SELECT aggregate_memory_id, source_kind, source_id, source_path, agent_id, created_at
21769
+ FROM aggregate_evidence_sources
21770
+ `);
21771
+ }
21772
+ if (tableExists2(db, "aggregate_memory_sources")) {
21773
+ db.exec(`
21774
+ INSERT OR IGNORE INTO derived_memory_sources
21775
+ (derived_memory_id, source_kind, source_id, source_path, agent_id, created_at)
21776
+ SELECT aggregate_memory_id, 'memory', source_memory_id, NULL, agent_id, created_at
21777
+ FROM aggregate_memory_sources
21778
+ `);
21779
+ }
21780
+ if (tableExists2(db, "memories") && !hasColumn162(db, "memories", "stale_at")) {
21781
+ db.exec("ALTER TABLE memories ADD COLUMN stale_at TEXT");
21782
+ }
21783
+ if (tableExists2(db, "memories")) {
21784
+ db.exec(`
21785
+ CREATE INDEX IF NOT EXISTS idx_memories_stale_derived
21786
+ ON memories(agent_id, stale_at)
21787
+ WHERE stale_at IS NOT NULL AND is_deleted = 0
21788
+ `);
21789
+ }
21790
+ }
21299
21791
  var MIGRATIONS2 = [
21300
21792
  {
21301
21793
  version: 1,
21302
21794
  name: "baseline",
21303
- up: up93,
21795
+ up: up105,
21304
21796
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
21305
21797
  },
21306
21798
  {
@@ -21354,13 +21846,13 @@ var MIGRATIONS2 = [
21354
21846
  {
21355
21847
  version: 9,
21356
21848
  name: "summary-jobs",
21357
- up: up94,
21849
+ up: up910,
21358
21850
  artifacts: { tables: ["summary_jobs"] }
21359
21851
  },
21360
21852
  {
21361
21853
  version: 10,
21362
21854
  name: "umap-cache",
21363
- up: up102,
21855
+ up: up106,
21364
21856
  artifacts: { tables: ["umap_cache"] }
21365
21857
  },
21366
21858
  {
@@ -21380,7 +21872,6 @@ var MIGRATIONS2 = [
21380
21872
  name: "ingestion-tracking",
21381
21873
  up: up132,
21382
21874
  artifacts: {
21383
- tables: ["ingestion_jobs"],
21384
21875
  columns: [
21385
21876
  { table: "memories", column: "source_path" },
21386
21877
  { table: "memories", column: "source_section" }
@@ -22043,6 +22534,87 @@ var MIGRATIONS2 = [
22043
22534
  name: "embedding-staging-store",
22044
22535
  up: up922,
22045
22536
  artifacts: { tables: ["embeddings_staging"] }
22537
+ },
22538
+ {
22539
+ version: 93,
22540
+ name: "dreaming-evidence-cursor",
22541
+ up: up932,
22542
+ artifacts: { columns: [{ table: "dreaming_state", column: "evidence_cursor" }] }
22543
+ },
22544
+ {
22545
+ version: 94,
22546
+ name: "memory-kind",
22547
+ up: up942,
22548
+ artifacts: {
22549
+ columns: [
22550
+ { table: "memories", column: "memory_kind" },
22551
+ { table: "memories", column: "evidence_meta" }
22552
+ ]
22553
+ }
22554
+ },
22555
+ {
22556
+ version: 95,
22557
+ name: "compaction-recall-projections",
22558
+ up: up952
22559
+ },
22560
+ {
22561
+ version: 96,
22562
+ name: "retire-legacy-ingestion",
22563
+ up: up962
22564
+ },
22565
+ {
22566
+ version: 97,
22567
+ name: "dreaming-failure-backoff",
22568
+ up: up972,
22569
+ artifacts: { columns: [{ table: "dreaming_state", column: "last_failure_at" }] }
22570
+ },
22571
+ {
22572
+ version: 98,
22573
+ name: "dreaming-evidence-exclusions",
22574
+ up: up982,
22575
+ artifacts: { tables: ["dreaming_evidence_exclusions"] }
22576
+ },
22577
+ {
22578
+ version: 99,
22579
+ name: "dreaming-tool-calls",
22580
+ up: up992,
22581
+ artifacts: { tables: ["dreaming_tool_calls"] }
22582
+ },
22583
+ {
22584
+ version: 100,
22585
+ name: "dreaming-runbook",
22586
+ up: up1002,
22587
+ artifacts: {
22588
+ columns: [
22589
+ { table: "dreaming_passes", column: "evidence_window_json" },
22590
+ { table: "dreaming_passes", column: "runbook_json" }
22591
+ ]
22592
+ }
22593
+ },
22594
+ {
22595
+ version: 101,
22596
+ name: "dreaming-attention",
22597
+ up: up1012,
22598
+ artifacts: { tables: ["dreaming_attention"] }
22599
+ },
22600
+ {
22601
+ version: 102,
22602
+ name: "attribute-semantic-memories",
22603
+ up: up1022
22604
+ },
22605
+ {
22606
+ version: 103,
22607
+ name: "semantic-memory-kind",
22608
+ up: up1032
22609
+ },
22610
+ {
22611
+ version: 104,
22612
+ name: "derived-memory-provenance",
22613
+ up: up1042,
22614
+ artifacts: {
22615
+ tables: ["derived_memory_sources"],
22616
+ columns: [{ table: "memories", column: "stale_at" }]
22617
+ }
22046
22618
  }
22047
22619
  ];
22048
22620
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
@@ -22321,122 +22893,6 @@ function loadIdentityMode(agentsDir) {
22321
22893
  }
22322
22894
  }
22323
22895
  var home2 = homedir82();
22324
- var SKIP_SUBTYPES2 = new Set([
22325
- "channel_join",
22326
- "channel_leave",
22327
- "channel_topic",
22328
- "channel_purpose",
22329
- "channel_name",
22330
- "channel_archive",
22331
- "channel_unarchive",
22332
- "group_join",
22333
- "group_leave",
22334
- "group_topic",
22335
- "group_purpose",
22336
- "group_name",
22337
- "group_archive",
22338
- "group_unarchive",
22339
- "pinned_item",
22340
- "unpinned_item",
22341
- "bot_add",
22342
- "bot_remove",
22343
- "tombstone",
22344
- "file_comment",
22345
- "sh_room_created",
22346
- "sh_room_shared"
22347
- ]);
22348
- var SKIP_TYPES2 = new Set([
22349
- "RecipientAdd",
22350
- "RecipientRemove",
22351
- "ChannelNameChange",
22352
- "ChannelIconChange",
22353
- "ChannelPinnedMessage",
22354
- "GuildMemberJoin",
22355
- "UserPremiumGuildSubscription",
22356
- "UserPremiumGuildSubscriptionTier1",
22357
- "UserPremiumGuildSubscriptionTier2",
22358
- "UserPremiumGuildSubscriptionTier3",
22359
- "ChannelFollowAdd",
22360
- "GuildDiscoveryDisqualified",
22361
- "GuildDiscoveryRequalified",
22362
- "GuildDiscoveryGracePeriodInitialWarning",
22363
- "GuildDiscoveryGracePeriodFinalWarning",
22364
- "ThreadCreated",
22365
- "ApplicationCommand"
22366
- ]);
22367
- var SKIP_DIRS2 = new Set([
22368
- "node_modules",
22369
- ".git",
22370
- "dist",
22371
- "build",
22372
- "out",
22373
- "target",
22374
- ".next",
22375
- ".nuxt",
22376
- "__pycache__",
22377
- ".tox",
22378
- ".mypy_cache",
22379
- ".pytest_cache",
22380
- "venv",
22381
- ".venv",
22382
- "env",
22383
- "vendor",
22384
- "coverage",
22385
- ".cache",
22386
- ".turbo"
22387
- ]);
22388
- var DOCUMENT_VALID_TYPES2 = new Set([
22389
- "fact",
22390
- "decision",
22391
- "rationale",
22392
- "preference",
22393
- "procedural",
22394
- "semantic",
22395
- "system",
22396
- "configuration",
22397
- "architectural",
22398
- "relationship",
22399
- "episodic",
22400
- "daily-log"
22401
- ]);
22402
- var ENTIRE_VALID_TYPES2 = new Set(["skill", "preference", "decision", "rationale", "procedural", "semantic", "fact"]);
22403
- var CHAT_VALID_TYPES2 = new Set(["fact", "decision", "rationale", "preference", "procedural", "semantic", "system"]);
22404
- var MARKDOWN_EXTS2 = new Set([".md", ".mdx", ".markdown"]);
22405
- var TXT_EXTS2 = new Set([".txt", ".text", ".log", ".rst"]);
22406
- var PDF_EXTS2 = new Set([".pdf"]);
22407
- var CODE_EXTS2 = new Set([
22408
- ".ts",
22409
- ".tsx",
22410
- ".js",
22411
- ".jsx",
22412
- ".py",
22413
- ".rs",
22414
- ".go",
22415
- ".java",
22416
- ".rb",
22417
- ".php",
22418
- ".swift",
22419
- ".kt",
22420
- ".scala",
22421
- ".c",
22422
- ".cpp",
22423
- ".h",
22424
- ".hpp",
22425
- ".sh",
22426
- ".bash",
22427
- ".zsh",
22428
- ".sql",
22429
- ".yaml",
22430
- ".yml",
22431
- ".toml",
22432
- ".json",
22433
- ".xml",
22434
- ".css",
22435
- ".scss",
22436
- ".html",
22437
- ".htm"
22438
- ]);
22439
- var SKIP_FILES2 = new Set([".DS_Store", "Thumbs.db", ".gitkeep", "node_modules", ".git", ".env", ".env.local"]);
22440
22896
 
22441
22897
  // src/index.ts
22442
22898
  var SIGNET_FORGE_MARKER = "Managed by Signet (@signetai/connector-forge)";