engine7 7.1.151 → 7.1.153

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.
@@ -801,7 +801,22 @@ function cjkBigrams(text2) {
801
801
  function tokenizeCjk(text2) {
802
802
  return [...tokenize(text2), ...cjkBigrams(text2)];
803
803
  }
804
- var DEFAULT_STOPWORDS, MIN_TOKEN_LENGTH, jieba;
804
+ function invisibleCjkNeedles(candidates) {
805
+ return [...new Set(candidates.map((token) => token.trim()))].filter((token) => /^[\u4e00-\u9fff]{2,}$/.test(token) && tokenize(token).length === 0).slice(0, 8);
806
+ }
807
+ function literalQueryNeedles(text2) {
808
+ const chars = shortCjkCharCount(text2);
809
+ if (!chars || chars > 6) return null;
810
+ const names = invisibleCjkNeedles(engine().cut(String(text2 ?? ""), true));
811
+ return names.length ? names : queryBigramNeedles(text2);
812
+ }
813
+ function queryBigramNeedles(text2) {
814
+ const chars = shortCjkCharCount(text2);
815
+ if (!chars || chars > 6) return null;
816
+ const grams = [...new Set(cjkBigrams(text2))].slice(0, 8);
817
+ return grams.length ? grams : null;
818
+ }
819
+ var DEFAULT_STOPWORDS, MIN_TOKEN_LENGTH, jieba, shortCjkCharCount;
805
820
  var init_tokenizer = __esm({
806
821
  "src/mem7/core/tokenizer.ts"() {
807
822
  "use strict";
@@ -874,6 +889,7 @@ var init_tokenizer = __esm({
874
889
  ]);
875
890
  MIN_TOKEN_LENGTH = 2;
876
891
  jieba = null;
892
+ shortCjkCharCount = (text2) => (String(text2 ?? "").match(/[\u4e00-\u9fff]/g) ?? []).length;
877
893
  }
878
894
  });
879
895
 
@@ -2690,6 +2706,7 @@ __export(index_exports, {
2690
2706
  topicMatchesYear: () => topicMatchesYear,
2691
2707
  topicQueryYear: () => topicQueryYear,
2692
2708
  topicsHistoryNeedsFallback: () => topicsHistoryNeedsFallback,
2709
+ topicsHistoryRefsCurrent: () => topicsHistoryRefsCurrent,
2693
2710
  topicsHistoryRoot: () => topicsHistoryRoot,
2694
2711
  topicsScope: () => topicsScope
2695
2712
  });
@@ -2789,6 +2806,27 @@ function hasTopicsHistory(b) {
2789
2806
  db.close();
2790
2807
  return true;
2791
2808
  }
2809
+ function topicsHistoryRefsCurrent(b) {
2810
+ const db = openIndex(b);
2811
+ if (!db) return false;
2812
+ try {
2813
+ const expected = rootKey(b);
2814
+ const meta = db.prepare("SELECT value FROM metadata WHERE key='rootKey'").get();
2815
+ if (meta) return meta.value === expected;
2816
+ const rows = db.prepare("SELECT ref FROM (SELECT ref,id FROM entries ORDER BY id LIMIT 1) UNION ALL SELECT ref FROM (SELECT ref,id FROM entries ORDER BY id DESC LIMIT 1)").all();
2817
+ return rows.every((row) => {
2818
+ try {
2819
+ return JSON.parse(row.ref).rootKey === expected;
2820
+ } catch {
2821
+ return false;
2822
+ }
2823
+ });
2824
+ } catch {
2825
+ return false;
2826
+ } finally {
2827
+ db.close();
2828
+ }
2829
+ }
2792
2830
  async function topicsHistoryNeedsFallback(b) {
2793
2831
  const cached = fallbackChecks.get(key(b));
2794
2832
  if (cached && cached.expiresAt > Date.now()) return cached.value;
@@ -2940,6 +2978,7 @@ async function publishTopicsIndex(bundle, cleaned, b) {
2940
2978
  CREATE VIRTUAL TABLE documents USING fts5(source_path UNINDEXED,original_hash UNINDEXED,terms);
2941
2979
  CREATE VIRTUAL TABLE search USING fts5(id UNINDEXED,terms);`);
2942
2980
  db.prepare("INSERT INTO metadata VALUES(?,?)").run("binding", canonical({ scope: topicsScope(b), root: resolve6(b.topicsDir) }));
2981
+ db.prepare("INSERT INTO metadata VALUES(?,?)").run("rootKey", rootKey(b));
2943
2982
  const sourceInsert = db.prepare("INSERT INTO sources VALUES(?,?,?,?)");
2944
2983
  for (const record of snapshot.manifest.records) sourceInsert.run(record.path, record.sha256, record.bytes, record.mtimeMs);
2945
2984
  const insert = db.prepare("INSERT INTO entries VALUES(?,?,?,?,?,?,?,?,?)"), search = db.prepare("INSERT INTO search VALUES(?,?)");
@@ -3866,8 +3905,9 @@ function invalidateDerivedDependencies(db, event) {
3866
3905
  }
3867
3906
  return invalidateChildren(db, event.scopeId, pending2, event.kind);
3868
3907
  }
3869
- function invalidateScopeDependencies(db, scope, parent, reason) {
3870
- const children = db.prepare("SELECT child_kind,child_id FROM memory_dependencies WHERE scope_id=? AND parent_kind='scope' AND parent_id=?").all(scope, parent);
3908
+ function invalidateScopeDependencies(db, scope, parent, reason, options = {}) {
3909
+ let children = db.prepare("SELECT child_kind,child_id FROM memory_dependencies WHERE scope_id=? AND parent_kind='scope' AND parent_id=?").all(scope, parent);
3910
+ if (options.skipKinds?.size) children = children.filter((child) => !options.skipKinds.has(child.child_kind));
3871
3911
  invalidateChildren(db, scope, children, reason);
3872
3912
  }
3873
3913
  function invalidateChildren(db, scope, pending2, reason) {
@@ -3887,7 +3927,7 @@ function invalidateChildren(db, scope, pending2, reason) {
3887
3927
  }
3888
3928
  const state = child.deleted ? "deleted" : "needs_revalidation";
3889
3929
  db.prepare(`UPDATE memory_derivations SET state=?,reason=?,updated_at=?
3890
- WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation','invalid') AND state<>?`).run(state, reason, (/* @__PURE__ */ new Date()).toISOString(), scope, child.child_kind, child.child_id, state);
3930
+ WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation') AND state<>?`).run(state, reason, (/* @__PURE__ */ new Date()).toISOString(), scope, child.child_kind, child.child_id, state);
3891
3931
  result.push(child.child_id);
3892
3932
  pending2.push(...db.prepare("SELECT child_kind,child_id,role FROM memory_dependencies WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?").all(scope, child.child_id).map((row) => ({ ...row, deleted: child.deleted && row.role === "supports" })));
3893
3933
  }
@@ -4403,7 +4443,7 @@ function textColumnOf(kind) {
4403
4443
  return "fact";
4404
4444
  }
4405
4445
  }
4406
- var isIntelMac, lancePromise, mem7VectorWarning, arrowPromise, Mem7VectorUnavailableError, VECTOR_DIM, BM25_FIELDS, RRF_K, warnedFts, warnedVecIdx, incompatibleIndexSegments, bootAt, schemasCache, Mem7VectorStore;
4446
+ var isIntelMac, lancePromise, mem7VectorWarning, arrowPromise, Mem7VectorUnavailableError, VECTOR_DIM, BM25_FIELDS, BM25_TEXT_FIELDS, sqlLiteral, RRF_K, warnedFts, warnedVecIdx, incompatibleIndexSegments, bootAt, schemasCache, Mem7VectorStore;
4407
4447
  var init_vector_store = __esm({
4408
4448
  "src/mem7/core/vector-store.ts"() {
4409
4449
  "use strict";
@@ -4434,6 +4474,14 @@ var init_vector_store = __esm({
4434
4474
  agent_case: ["task_intent_tokens", "approach_tokens"],
4435
4475
  agent_skill: ["description_tokens", "content_tokens"]
4436
4476
  };
4477
+ BM25_TEXT_FIELDS = {
4478
+ foresight: ["foresight", "evidence"],
4479
+ episode: ["episode"],
4480
+ atomic_fact: ["fact"],
4481
+ agent_case: ["task_intent", "approach"],
4482
+ agent_skill: ["description", "content"]
4483
+ };
4484
+ sqlLiteral = (value) => value.replace(/'/g, "''");
4437
4485
  RRF_K = 60;
4438
4486
  warnedFts = /* @__PURE__ */ new Set();
4439
4487
  warnedVecIdx = /* @__PURE__ */ new Set();
@@ -5031,6 +5079,47 @@ var init_vector_store = __esm({
5031
5079
  if (!cur || score > Number(cur._score ?? 0)) best.set(rid, r);
5032
5080
  }
5033
5081
  }
5082
+ const textCols = BM25_TEXT_FIELDS[kind];
5083
+ const scan = async (terms, op, limit) => {
5084
+ const expr = op === "AND" ? terms.map((g) => `(${textCols.map((col) => `contains(${col}, '${sqlLiteral(g)}')`).join(" OR ")})`).join(" AND ") : textCols.map((col) => `(${terms.map((g) => `contains(${col}, '${sqlLiteral(g)}')`).join(" OR ")})`).join(" OR ");
5085
+ const where2 = compileFilter(opts.filter);
5086
+ return await tbl.query().where(where2 ? `(${where2}) AND (${expr})` : expr).limit(limit).toArray();
5087
+ };
5088
+ const maxScore = [...best.values()].reduce((max, r) => Math.max(max, Number(r._score ?? 0)), 0);
5089
+ const scoreLiteral = (needles2, rows) => {
5090
+ const terms = [.../* @__PURE__ */ new Set([...needles2, ...tokenizeToField(queryText).split(/\s+/).filter(Boolean)])];
5091
+ const occurrences2 = (text2, term) => text2.split(term).length - 1;
5092
+ for (const r of rows) {
5093
+ const rid = String(r.id ?? "");
5094
+ if (!rid) continue;
5095
+ const text2 = textCols.map((col) => String(r[col] ?? "")).join(" ");
5096
+ const matched = terms.filter((term) => text2.includes(term));
5097
+ if (!matched.length || matched.every((term) => !needles2.includes(term))) continue;
5098
+ const full = matched.length === terms.length;
5099
+ const density = matched.reduce((sum, term) => sum + occurrences2(text2, term), 0) / Math.max(text2.length, 1) * 1e3;
5100
+ const score = full ? maxScore + 1 + Math.min(0.99, density / 10) : maxScore > 0 ? maxScore * (0.5 + 0.5 * matched.length / terms.length) : matched.length / terms.length;
5101
+ const cur = best.get(rid);
5102
+ if (cur) {
5103
+ if (full) cur._score = Math.max(Number(cur._score ?? 0), score);
5104
+ } else best.set(rid, { ...r, _score: score });
5105
+ }
5106
+ };
5107
+ const needles = literalQueryNeedles(queryText);
5108
+ if (needles) {
5109
+ try {
5110
+ const terms = [.../* @__PURE__ */ new Set([...needles, ...tokenizeToField(queryText).split(/\s+/).filter(Boolean)])];
5111
+ const [all, any] = await Promise.all([
5112
+ terms.length > 1 ? scan(terms, "AND", topK * 10) : Promise.resolve([]),
5113
+ scan(needles, "OR", topK * 3)
5114
+ ]);
5115
+ scoreLiteral(needles, [...all, ...any]);
5116
+ if (![...best.values()].some((r) => Number(r._score ?? 0) > maxScore)) {
5117
+ const bigrams = [...new Set(needles.flatMap((name) => queryBigramNeedles(name) ?? []))].slice(0, 8);
5118
+ if (bigrams.length && JSON.stringify(bigrams) !== JSON.stringify(needles)) scoreLiteral(bigrams, await scan(bigrams, "OR", topK * 3));
5119
+ }
5120
+ } catch {
5121
+ }
5122
+ }
5034
5123
  return this.visibleRows(kind, [...best.values()]).filter((r) => Number(r._score ?? 0) > 0).sort((a, b) => Number(b._score ?? 0) - Number(a._score ?? 0)).slice(0, topK).map((r) => ({ ...this.toHit(kind, r), distance: 0, score: Number(r._score ?? 0) }));
5035
5124
  } catch (err) {
5036
5125
  const msg = String(err?.message ?? err);
@@ -5555,7 +5644,7 @@ import { createHash as createHash8 } from "node:crypto";
5555
5644
  function projectedSourceIdFromScopeId(id, originKey, sourceVersion) {
5556
5645
  return "src_" + digest2([id, originKey, sourceVersion]);
5557
5646
  }
5558
- var SOURCE_SCHEMA, SOURCE_ALIAS_SCHEMA, digest2, SourceStore;
5647
+ var RECEIVED_INVALIDATION_SKIP, SOURCE_SCHEMA, SOURCE_ALIAS_SCHEMA, digest2, SourceStore;
5559
5648
  var init_source_store = __esm({
5560
5649
  "src/mem7/core/source-store.ts"() {
5561
5650
  "use strict";
@@ -5567,6 +5656,7 @@ var init_source_store = __esm({
5567
5656
  init_watermarks();
5568
5657
  init_interpretation_impact();
5569
5658
  init_conversation_text();
5659
+ RECEIVED_INVALIDATION_SKIP = /* @__PURE__ */ new Set(["foresight"]);
5570
5660
  SOURCE_SCHEMA = `
5571
5661
  CREATE TABLE memory_scopes (
5572
5662
  scope_id TEXT PRIMARY KEY, owner_id TEXT NOT NULL, app_id TEXT NOT NULL, project_id TEXT NOT NULL,
@@ -5748,8 +5838,8 @@ CREATE TABLE IF NOT EXISTS memory_source_aliases (
5748
5838
  if (this.db.prepare("SELECT 1 FROM memory_sources WHERE scope_id=? AND origin_key=? AND interpretation_status='deleted'").get(id, input.originKey)) throw new Error("DELETED_EVIDENCE");
5749
5839
  if (version !== Number(latest.version ?? 0) + 1) throw new Error("SOURCE_VERSION_CONFLICT: edits must follow the previous version");
5750
5840
  this.db.prepare("UPDATE memory_scopes SET source_seq=source_seq+1,context_revision=context_revision+1 WHERE scope_id=?").run(id);
5751
- invalidateScopeDependencies(this.db, id, "sources", "source.received");
5752
- invalidateScopeDependencies(this.db, id, "context", "source.received");
5841
+ invalidateScopeDependencies(this.db, id, "sources", "source.received", { skipKinds: RECEIVED_INVALIDATION_SKIP });
5842
+ invalidateScopeDependencies(this.db, id, "context", "source.received", { skipKinds: RECEIVED_INVALIDATION_SKIP });
5753
5843
  const seq = Number(this.db.prepare("SELECT source_seq FROM memory_scopes WHERE scope_id=?").get(id).source_seq);
5754
5844
  const sourceId = projectedSourceIdFromScopeId(id, input.originKey, version);
5755
5845
  const receiptId = "rcpt_" + digest2([id, sourceId]);
@@ -10985,7 +11075,7 @@ function contentHash(text2) {
10985
11075
  function mem7Root(stateDir) {
10986
11076
  return join18(stateDir, "mem7");
10987
11077
  }
10988
- var STALE_ARTIFACT_FORCE_MS, SCHEMA, AGENT_SCHEMA, Mem7Store;
11078
+ var STALE_ARTIFACT_FORCE_MS, STARVATION_GRACE_MS, SCHEMA, AGENT_SCHEMA, Mem7Store;
10989
11079
  var init_store = __esm({
10990
11080
  "src/mem7/core/store.ts"() {
10991
11081
  "use strict";
@@ -11023,6 +11113,7 @@ var init_store = __esm({
11023
11113
  init_job_retention();
11024
11114
  init_retire_graph_audits();
11025
11115
  STALE_ARTIFACT_FORCE_MS = 2 * 36e5;
11116
+ STARVATION_GRACE_MS = 36e5;
11026
11117
  SCHEMA = `
11027
11118
  CREATE TABLE IF NOT EXISTS memcells (
11028
11119
  id TEXT PRIMARY KEY,
@@ -12113,7 +12204,7 @@ ${e.outcome}
12113
12204
  return this.transaction(() => {
12114
12205
  const kindFilter = options.kinds ? ` AND kind IN (${options.kinds.map(() => "?").join(",")})` : "";
12115
12206
  const scopeFilter = options.scopeId !== void 0 ? " AND scope_id=?" : "";
12116
- const rows = this.db.prepare(`SELECT * FROM ome_jobs j INDEXED BY ${options.scopeId !== void 0 && options.kinds?.length === 1 ? "idx_jobs_scope_priority" : "idx_jobs_runnable_priority"}
12207
+ const base = `SELECT * FROM ome_jobs j INDEXED BY ${options.scopeId !== void 0 && options.kinds?.length === 1 ? "idx_jobs_scope_priority" : "idx_jobs_runnable_priority"}
12117
12208
  WHERE status IN ('pending','running') AND NOT EXISTS (SELECT 1 FROM memory_job_holds h WHERE h.job_id=j.id AND h.released_at IS NULL)
12118
12209
  AND ((status='pending' AND next_run_at<=?)
12119
12210
  OR (status='running' AND COALESCE(lease_until,0)<=?))${kindFilter}${scopeFilter}
@@ -12133,40 +12224,48 @@ ${e.outcome}
12133
12224
  -- Cognition rebuilds its read set at claim time; delayed old work must not fence fresh judgments.
12134
12225
  AND (kind IN ('social.interpret','source.interpret','relationship.cognition') OR scope_id NOT LIKE 'resource:%' OR NOT EXISTS (SELECT 1 FROM ome_jobs prior
12135
12226
  WHERE prior.scope_id=j.scope_id AND prior.id<j.id AND prior.status IN ('pending','running')
12136
- AND NOT EXISTS (SELECT 1 FROM memory_job_holds h WHERE h.job_id=prior.id AND h.released_at IS NULL)) OR scope_id IS NULL)
12137
- -- Retrying an old deferred job must not reserve the next stage budget.
12138
- -- Boundary/resource predecessor predicates above still enforce ordering.
12139
- ORDER BY priority,next_run_at,id LIMIT ?`).all(now2, now2, ...options.kinds ?? [], ...options.scopeId !== void 0 ? [options.scopeId] : [], now2, limit);
12140
- const claimedScopes = /* @__PURE__ */ new Set();
12141
- return rows.flatMap((row) => {
12142
- if (!this.jobProvenance.prepareForClaim(row.id, now2)) return [];
12143
- const updated = this.db.prepare("SELECT * FROM ome_jobs WHERE id=?").get(row.id);
12144
- if (updated.scope_id !== row.scope_id && updated.scope_id) {
12145
- const conflict = this.db.prepare(`SELECT 1 FROM ome_jobs j WHERE j.scope_id=? AND j.id<>?
12146
- AND (j.status='running' AND j.lease_until>? OR ? LIKE 'resource:%' AND j.id<? AND j.status IN ('pending','running')
12147
- AND NOT EXISTS (SELECT 1 FROM memory_job_holds h WHERE h.job_id=j.id AND h.released_at IS NULL))`).get(updated.scope_id, updated.id, now2, updated.scope_id, updated.id);
12148
- if (conflict) return [];
12149
- }
12150
- return [updated];
12151
- }).filter((row) => {
12152
- if (!row.scope_id) return true;
12153
- if (claimedScopes.has(row.scope_id)) return false;
12154
- claimedScopes.add(row.scope_id);
12155
- return true;
12156
- }).map((row) => {
12157
- const leaseToken = randomUUID13();
12158
- this.db.prepare("UPDATE ome_jobs SET status='running',lease_token=?,lease_until=? WHERE id=?").run(leaseToken, now2 + leaseMs, row.id);
12159
- return {
12160
- id: row.id,
12161
- kind: row.kind,
12162
- payload: JSON.parse(row.payload),
12163
- attempts: row.attempts,
12164
- leaseToken,
12165
- inputVersion: row.input_version,
12166
- scopeId: row.scope_id ?? void 0,
12167
- result: row.result_json === null ? void 0 : JSON.parse(row.result_json)
12168
- };
12169
- });
12227
+ AND NOT EXISTS (SELECT 1 FROM memory_job_holds h WHERE h.job_id=prior.id AND h.released_at IS NULL)) OR scope_id IS NULL)`;
12228
+ const select = (starved2) => {
12229
+ const sql = `${base}${starved2 ? " AND status='pending' AND next_run_at<=?" : ""}
12230
+ ORDER BY priority,next_run_at,id LIMIT ?`;
12231
+ const args = starved2 ? [now2, now2, ...options.kinds ?? [], ...options.scopeId !== void 0 ? [options.scopeId] : [], now2, now2 - STARVATION_GRACE_MS, limit] : [now2, now2, ...options.kinds ?? [], ...options.scopeId !== void 0 ? [options.scopeId] : [], now2, limit];
12232
+ return this.db.prepare(sql).all(...args);
12233
+ };
12234
+ const claim = (rows) => {
12235
+ const claimedScopes = /* @__PURE__ */ new Set();
12236
+ return rows.flatMap((row) => {
12237
+ if (!this.jobProvenance.prepareForClaim(row.id, now2)) return [];
12238
+ const updated = this.db.prepare("SELECT * FROM ome_jobs WHERE id=?").get(row.id);
12239
+ if (updated.scope_id !== row.scope_id && updated.scope_id) {
12240
+ const conflict = this.db.prepare(`SELECT 1 FROM ome_jobs j WHERE j.scope_id=? AND j.id<>?
12241
+ AND (j.status='running' AND j.lease_until>? OR ? LIKE 'resource:%' AND j.id<? AND j.status IN ('pending','running')
12242
+ AND NOT EXISTS (SELECT 1 FROM memory_job_holds h WHERE h.job_id=j.id AND h.released_at IS NULL))`).get(updated.scope_id, updated.id, now2, updated.scope_id, updated.id);
12243
+ if (conflict) return [];
12244
+ }
12245
+ return [updated];
12246
+ }).filter((row) => {
12247
+ if (!row.scope_id) return true;
12248
+ if (claimedScopes.has(row.scope_id)) return false;
12249
+ claimedScopes.add(row.scope_id);
12250
+ return true;
12251
+ }).map((row) => {
12252
+ const leaseToken = randomUUID13();
12253
+ this.db.prepare("UPDATE ome_jobs SET status='running',lease_token=?,lease_until=? WHERE id=?").run(leaseToken, now2 + leaseMs, row.id);
12254
+ return {
12255
+ id: row.id,
12256
+ kind: row.kind,
12257
+ payload: JSON.parse(row.payload),
12258
+ attempts: row.attempts,
12259
+ leaseToken,
12260
+ inputVersion: row.input_version,
12261
+ scopeId: row.scope_id ?? void 0,
12262
+ result: row.result_json === null ? void 0 : JSON.parse(row.result_json)
12263
+ };
12264
+ });
12265
+ };
12266
+ if (options.staleOnly) return claim(select(true));
12267
+ const starved = claim(select(true));
12268
+ return starved.length ? starved : claim(select(false));
12170
12269
  });
12171
12270
  }
12172
12271
  /** Compatibility entry point: only expired leases can be recovered. */
@@ -13953,7 +14052,7 @@ async function runTopicsBackground(options) {
13953
14052
  } catch {
13954
14053
  }
13955
14054
  }
13956
- if (hasTopicsHistory(b)) {
14055
+ if (hasTopicsHistory(b) && topicsHistoryRefsCurrent(b)) {
13957
14056
  topicsBackgroundStatus(b, { phase: "complete", sources: records.length, mem7StartDate: before, version: current2.version, ...droppedStatus() });
13958
14057
  const embedded = await augmentVectors(records.length);
13959
14058
  return { status: "complete", version: current2.version, drained: embedded === 0 };
@@ -3836,7 +3836,7 @@ function invalidateChildren(db, scope, pending, reason) {
3836
3836
  }
3837
3837
  const state2 = child.deleted ? "deleted" : "needs_revalidation";
3838
3838
  db.prepare(`UPDATE memory_derivations SET state=?,reason=?,updated_at=?
3839
- WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation','invalid') AND state<>?`).run(state2, reason, (/* @__PURE__ */ new Date()).toISOString(), scope, child.child_kind, child.child_id, state2);
3839
+ WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation') AND state<>?`).run(state2, reason, (/* @__PURE__ */ new Date()).toISOString(), scope, child.child_kind, child.child_id, state2);
3840
3840
  result.push(child.child_id);
3841
3841
  pending.push(...db.prepare("SELECT child_kind,child_id,role FROM memory_dependencies WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?").all(scope, child.child_id).map((row) => ({ ...row, deleted: child.deleted && row.role === "supports" })));
3842
3842
  }