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