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.
- package/dist/bg-worker.mjs +978 -424
- package/dist/cli.mjs +1209 -728
- package/dist/engine-startup.mjs +1775 -1169
- package/dist/main.mjs +1729 -1123
- package/dist/recall-worker.mjs +162 -52
- package/dist/sqlite-maintenance-worker.mjs +1 -1
- package/dist/topics-worker.mjs +144 -45
- package/dist/travel-data.mjs +1 -1
- package/dist/travel-gateway.mjs +608 -255
- package/dist/travel-host.mjs +659 -404
- package/dist/travel-initial-baseline.mjs +1 -1
- package/dist/travel-node-data.mjs +1 -1
- package/dist/travel-node.mjs +124 -41
- package/dist/travel-pairing.mjs +637 -284
- package/package.json +1 -1
- package/templates/skills/sop/SKILL.md +42 -150
|
@@ -3458,7 +3458,7 @@ function invalidateChildren(db, scope, pending, reason) {
|
|
|
3458
3458
|
}
|
|
3459
3459
|
const state = child.deleted ? "deleted" : "needs_revalidation";
|
|
3460
3460
|
db.prepare(`UPDATE memory_derivations SET state=?,reason=?,updated_at=?
|
|
3461
|
-
WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation'
|
|
3461
|
+
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);
|
|
3462
3462
|
result.push(child.child_id);
|
|
3463
3463
|
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" })));
|
|
3464
3464
|
}
|
|
@@ -2750,7 +2750,7 @@ function invalidateChildren(db, scope, pending, reason) {
|
|
|
2750
2750
|
}
|
|
2751
2751
|
const state = child.deleted ? "deleted" : "needs_revalidation";
|
|
2752
2752
|
db.prepare(`UPDATE memory_derivations SET state=?,reason=?,updated_at=?
|
|
2753
|
-
WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation'
|
|
2753
|
+
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);
|
|
2754
2754
|
result.push(child.child_id);
|
|
2755
2755
|
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" })));
|
|
2756
2756
|
}
|
package/dist/travel-node.mjs
CHANGED
|
@@ -1800,7 +1800,29 @@ function tokenize(text2) {
|
|
|
1800
1800
|
function tokenizeToField(text2) {
|
|
1801
1801
|
return tokenize(text2).join(" ");
|
|
1802
1802
|
}
|
|
1803
|
-
|
|
1803
|
+
function cjkBigrams(text2) {
|
|
1804
|
+
const out = [];
|
|
1805
|
+
for (const seg of String(text2 ?? "").match(/[\u4e00-\u9fff]{2,}/g) ?? []) {
|
|
1806
|
+
for (let i = 0; i + 1 < seg.length; i++) out.push(seg.slice(i, i + 2));
|
|
1807
|
+
}
|
|
1808
|
+
return out;
|
|
1809
|
+
}
|
|
1810
|
+
function invisibleCjkNeedles(candidates) {
|
|
1811
|
+
return [...new Set(candidates.map((token) => token.trim()))].filter((token) => /^[\u4e00-\u9fff]{2,}$/.test(token) && tokenize(token).length === 0).slice(0, 8);
|
|
1812
|
+
}
|
|
1813
|
+
function literalQueryNeedles(text2) {
|
|
1814
|
+
const chars = shortCjkCharCount(text2);
|
|
1815
|
+
if (!chars || chars > 6) return null;
|
|
1816
|
+
const names = invisibleCjkNeedles(engine().cut(String(text2 ?? ""), true));
|
|
1817
|
+
return names.length ? names : queryBigramNeedles(text2);
|
|
1818
|
+
}
|
|
1819
|
+
function queryBigramNeedles(text2) {
|
|
1820
|
+
const chars = shortCjkCharCount(text2);
|
|
1821
|
+
if (!chars || chars > 6) return null;
|
|
1822
|
+
const grams = [...new Set(cjkBigrams(text2))].slice(0, 8);
|
|
1823
|
+
return grams.length ? grams : null;
|
|
1824
|
+
}
|
|
1825
|
+
var DEFAULT_STOPWORDS, MIN_TOKEN_LENGTH, jieba, shortCjkCharCount;
|
|
1804
1826
|
var init_tokenizer = __esm({
|
|
1805
1827
|
"src/mem7/core/tokenizer.ts"() {
|
|
1806
1828
|
"use strict";
|
|
@@ -1873,6 +1895,7 @@ var init_tokenizer = __esm({
|
|
|
1873
1895
|
]);
|
|
1874
1896
|
MIN_TOKEN_LENGTH = 2;
|
|
1875
1897
|
jieba = null;
|
|
1898
|
+
shortCjkCharCount = (text2) => (String(text2 ?? "").match(/[\u4e00-\u9fff]/g) ?? []).length;
|
|
1876
1899
|
}
|
|
1877
1900
|
});
|
|
1878
1901
|
|
|
@@ -4734,8 +4757,9 @@ function invalidateDerivedDependencies(db, event) {
|
|
|
4734
4757
|
}
|
|
4735
4758
|
return invalidateChildren(db, event.scopeId, pending, event.kind);
|
|
4736
4759
|
}
|
|
4737
|
-
function invalidateScopeDependencies(db, scope, parent, reason) {
|
|
4738
|
-
|
|
4760
|
+
function invalidateScopeDependencies(db, scope, parent, reason, options = {}) {
|
|
4761
|
+
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);
|
|
4762
|
+
if (options.skipKinds?.size) children = children.filter((child) => !options.skipKinds.has(child.child_kind));
|
|
4739
4763
|
invalidateChildren(db, scope, children, reason);
|
|
4740
4764
|
}
|
|
4741
4765
|
function invalidateChildren(db, scope, pending, reason) {
|
|
@@ -4755,7 +4779,7 @@ function invalidateChildren(db, scope, pending, reason) {
|
|
|
4755
4779
|
}
|
|
4756
4780
|
const state2 = child.deleted ? "deleted" : "needs_revalidation";
|
|
4757
4781
|
db.prepare(`UPDATE memory_derivations SET state=?,reason=?,updated_at=?
|
|
4758
|
-
WHERE scope_id=? AND child_kind=? AND child_id=? AND state IN ('current','needs_revalidation'
|
|
4782
|
+
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);
|
|
4759
4783
|
result.push(child.child_id);
|
|
4760
4784
|
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" })));
|
|
4761
4785
|
}
|
|
@@ -5387,6 +5411,7 @@ function isConversationScaffold(text2) {
|
|
|
5387
5411
|
}
|
|
5388
5412
|
|
|
5389
5413
|
// src/mem7/core/source-store.ts
|
|
5414
|
+
var RECEIVED_INVALIDATION_SKIP = /* @__PURE__ */ new Set(["foresight"]);
|
|
5390
5415
|
var SOURCE_SCHEMA = `
|
|
5391
5416
|
CREATE TABLE memory_scopes (
|
|
5392
5417
|
scope_id TEXT PRIMARY KEY, owner_id TEXT NOT NULL, app_id TEXT NOT NULL, project_id TEXT NOT NULL,
|
|
@@ -5571,8 +5596,8 @@ var SourceStore = class {
|
|
|
5571
5596
|
if (this.db.prepare("SELECT 1 FROM memory_sources WHERE scope_id=? AND origin_key=? AND interpretation_status='deleted'").get(id2, input.originKey)) throw new Error("DELETED_EVIDENCE");
|
|
5572
5597
|
if (version !== Number(latest.version ?? 0) + 1) throw new Error("SOURCE_VERSION_CONFLICT: edits must follow the previous version");
|
|
5573
5598
|
this.db.prepare("UPDATE memory_scopes SET source_seq=source_seq+1,context_revision=context_revision+1 WHERE scope_id=?").run(id2);
|
|
5574
|
-
invalidateScopeDependencies(this.db, id2, "sources", "source.received");
|
|
5575
|
-
invalidateScopeDependencies(this.db, id2, "context", "source.received");
|
|
5599
|
+
invalidateScopeDependencies(this.db, id2, "sources", "source.received", { skipKinds: RECEIVED_INVALIDATION_SKIP });
|
|
5600
|
+
invalidateScopeDependencies(this.db, id2, "context", "source.received", { skipKinds: RECEIVED_INVALIDATION_SKIP });
|
|
5576
5601
|
const seq = Number(this.db.prepare("SELECT source_seq FROM memory_scopes WHERE scope_id=?").get(id2).source_seq);
|
|
5577
5602
|
const sourceId = projectedSourceIdFromScopeId(id2, input.originKey, version);
|
|
5578
5603
|
const receiptId = "rcpt_" + digest([id2, sourceId]);
|
|
@@ -6931,6 +6956,14 @@ var BM25_FIELDS = {
|
|
|
6931
6956
|
agent_case: ["task_intent_tokens", "approach_tokens"],
|
|
6932
6957
|
agent_skill: ["description_tokens", "content_tokens"]
|
|
6933
6958
|
};
|
|
6959
|
+
var BM25_TEXT_FIELDS = {
|
|
6960
|
+
foresight: ["foresight", "evidence"],
|
|
6961
|
+
episode: ["episode"],
|
|
6962
|
+
atomic_fact: ["fact"],
|
|
6963
|
+
agent_case: ["task_intent", "approach"],
|
|
6964
|
+
agent_skill: ["description", "content"]
|
|
6965
|
+
};
|
|
6966
|
+
var sqlLiteral = (value2) => value2.replace(/'/g, "''");
|
|
6934
6967
|
var RRF_K = 60;
|
|
6935
6968
|
var warnedFts = /* @__PURE__ */ new Set();
|
|
6936
6969
|
var warnedVecIdx = /* @__PURE__ */ new Set();
|
|
@@ -7624,6 +7657,47 @@ var Mem7VectorStore = class {
|
|
|
7624
7657
|
if (!cur || score > Number(cur._score ?? 0)) best.set(rid, r);
|
|
7625
7658
|
}
|
|
7626
7659
|
}
|
|
7660
|
+
const textCols = BM25_TEXT_FIELDS[kind];
|
|
7661
|
+
const scan = async (terms, op, limit) => {
|
|
7662
|
+
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 ");
|
|
7663
|
+
const where2 = compileFilter(opts.filter);
|
|
7664
|
+
return await tbl.query().where(where2 ? `(${where2}) AND (${expr})` : expr).limit(limit).toArray();
|
|
7665
|
+
};
|
|
7666
|
+
const maxScore = [...best.values()].reduce((max, r) => Math.max(max, Number(r._score ?? 0)), 0);
|
|
7667
|
+
const scoreLiteral = (needles2, rows) => {
|
|
7668
|
+
const terms = [.../* @__PURE__ */ new Set([...needles2, ...tokenizeToField(queryText).split(/\s+/).filter(Boolean)])];
|
|
7669
|
+
const occurrences2 = (text2, term) => text2.split(term).length - 1;
|
|
7670
|
+
for (const r of rows) {
|
|
7671
|
+
const rid = String(r.id ?? "");
|
|
7672
|
+
if (!rid) continue;
|
|
7673
|
+
const text2 = textCols.map((col) => String(r[col] ?? "")).join(" ");
|
|
7674
|
+
const matched = terms.filter((term) => text2.includes(term));
|
|
7675
|
+
if (!matched.length || matched.every((term) => !needles2.includes(term))) continue;
|
|
7676
|
+
const full = matched.length === terms.length;
|
|
7677
|
+
const density = matched.reduce((sum, term) => sum + occurrences2(text2, term), 0) / Math.max(text2.length, 1) * 1e3;
|
|
7678
|
+
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;
|
|
7679
|
+
const cur = best.get(rid);
|
|
7680
|
+
if (cur) {
|
|
7681
|
+
if (full) cur._score = Math.max(Number(cur._score ?? 0), score);
|
|
7682
|
+
} else best.set(rid, { ...r, _score: score });
|
|
7683
|
+
}
|
|
7684
|
+
};
|
|
7685
|
+
const needles = literalQueryNeedles(queryText);
|
|
7686
|
+
if (needles) {
|
|
7687
|
+
try {
|
|
7688
|
+
const terms = [.../* @__PURE__ */ new Set([...needles, ...tokenizeToField(queryText).split(/\s+/).filter(Boolean)])];
|
|
7689
|
+
const [all, any] = await Promise.all([
|
|
7690
|
+
terms.length > 1 ? scan(terms, "AND", topK * 10) : Promise.resolve([]),
|
|
7691
|
+
scan(needles, "OR", topK * 3)
|
|
7692
|
+
]);
|
|
7693
|
+
scoreLiteral(needles, [...all, ...any]);
|
|
7694
|
+
if (![...best.values()].some((r) => Number(r._score ?? 0) > maxScore)) {
|
|
7695
|
+
const bigrams = [...new Set(needles.flatMap((name) => queryBigramNeedles(name) ?? []))].slice(0, 8);
|
|
7696
|
+
if (bigrams.length && JSON.stringify(bigrams) !== JSON.stringify(needles)) scoreLiteral(bigrams, await scan(bigrams, "OR", topK * 3));
|
|
7697
|
+
}
|
|
7698
|
+
} catch {
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7627
7701
|
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) }));
|
|
7628
7702
|
} catch (err) {
|
|
7629
7703
|
const msg = String(err?.message ?? err);
|
|
@@ -10408,6 +10482,7 @@ function mem7Root(stateDir) {
|
|
|
10408
10482
|
return join15(stateDir, "mem7");
|
|
10409
10483
|
}
|
|
10410
10484
|
var STALE_ARTIFACT_FORCE_MS = 2 * 36e5;
|
|
10485
|
+
var STARVATION_GRACE_MS = 36e5;
|
|
10411
10486
|
var SCHEMA = `
|
|
10412
10487
|
CREATE TABLE IF NOT EXISTS memcells (
|
|
10413
10488
|
id TEXT PRIMARY KEY,
|
|
@@ -11498,7 +11573,7 @@ ${e.outcome}
|
|
|
11498
11573
|
return this.transaction(() => {
|
|
11499
11574
|
const kindFilter = options.kinds ? ` AND kind IN (${options.kinds.map(() => "?").join(",")})` : "";
|
|
11500
11575
|
const scopeFilter = options.scopeId !== void 0 ? " AND scope_id=?" : "";
|
|
11501
|
-
const
|
|
11576
|
+
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"}
|
|
11502
11577
|
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)
|
|
11503
11578
|
AND ((status='pending' AND next_run_at<=?)
|
|
11504
11579
|
OR (status='running' AND COALESCE(lease_until,0)<=?))${kindFilter}${scopeFilter}
|
|
@@ -11518,40 +11593,48 @@ ${e.outcome}
|
|
|
11518
11593
|
-- Cognition rebuilds its read set at claim time; delayed old work must not fence fresh judgments.
|
|
11519
11594
|
AND (kind IN ('social.interpret','source.interpret','relationship.cognition') OR scope_id NOT LIKE 'resource:%' OR NOT EXISTS (SELECT 1 FROM ome_jobs prior
|
|
11520
11595
|
WHERE prior.scope_id=j.scope_id AND prior.id<j.id AND prior.status IN ('pending','running')
|
|
11521
|
-
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)
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
if (
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
|
|
11596
|
+
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)`;
|
|
11597
|
+
const select = (starved2) => {
|
|
11598
|
+
const sql = `${base}${starved2 ? " AND status='pending' AND next_run_at<=?" : ""}
|
|
11599
|
+
ORDER BY priority,next_run_at,id LIMIT ?`;
|
|
11600
|
+
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];
|
|
11601
|
+
return this.db.prepare(sql).all(...args);
|
|
11602
|
+
};
|
|
11603
|
+
const claim = (rows) => {
|
|
11604
|
+
const claimedScopes = /* @__PURE__ */ new Set();
|
|
11605
|
+
return rows.flatMap((row) => {
|
|
11606
|
+
if (!this.jobProvenance.prepareForClaim(row.id, now2)) return [];
|
|
11607
|
+
const updated = this.db.prepare("SELECT * FROM ome_jobs WHERE id=?").get(row.id);
|
|
11608
|
+
if (updated.scope_id !== row.scope_id && updated.scope_id) {
|
|
11609
|
+
const conflict = this.db.prepare(`SELECT 1 FROM ome_jobs j WHERE j.scope_id=? AND j.id<>?
|
|
11610
|
+
AND (j.status='running' AND j.lease_until>? OR ? LIKE 'resource:%' AND j.id<? AND j.status IN ('pending','running')
|
|
11611
|
+
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);
|
|
11612
|
+
if (conflict) return [];
|
|
11613
|
+
}
|
|
11614
|
+
return [updated];
|
|
11615
|
+
}).filter((row) => {
|
|
11616
|
+
if (!row.scope_id) return true;
|
|
11617
|
+
if (claimedScopes.has(row.scope_id)) return false;
|
|
11618
|
+
claimedScopes.add(row.scope_id);
|
|
11619
|
+
return true;
|
|
11620
|
+
}).map((row) => {
|
|
11621
|
+
const leaseToken = randomUUID9();
|
|
11622
|
+
this.db.prepare("UPDATE ome_jobs SET status='running',lease_token=?,lease_until=? WHERE id=?").run(leaseToken, now2 + leaseMs, row.id);
|
|
11623
|
+
return {
|
|
11624
|
+
id: row.id,
|
|
11625
|
+
kind: row.kind,
|
|
11626
|
+
payload: JSON.parse(row.payload),
|
|
11627
|
+
attempts: row.attempts,
|
|
11628
|
+
leaseToken,
|
|
11629
|
+
inputVersion: row.input_version,
|
|
11630
|
+
scopeId: row.scope_id ?? void 0,
|
|
11631
|
+
result: row.result_json === null ? void 0 : JSON.parse(row.result_json)
|
|
11632
|
+
};
|
|
11633
|
+
});
|
|
11634
|
+
};
|
|
11635
|
+
if (options.staleOnly) return claim(select(true));
|
|
11636
|
+
const starved = claim(select(true));
|
|
11637
|
+
return starved.length ? starved : claim(select(false));
|
|
11555
11638
|
});
|
|
11556
11639
|
}
|
|
11557
11640
|
/** Compatibility entry point: only expired leases can be recovered. */
|