dsh-plugin-xujie-memory 0.5.0 → 0.6.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.
- package/CHANGELOG.md +28 -1
- package/LICENSE +21 -21
- package/README.md +33 -8
- package/README_EN.md +27 -4
- package/cordis.patch.yml +49 -49
- package/lib/index.js +121 -0
- package/package.json +1 -1
- package/python/specs/characters/aloof.json +14 -14
- package/python/specs/characters/gentle.json +14 -14
- package/python/specs/characters/tsundere.json +14 -14
- package/python/specs/debt.v1.json +31 -31
- package/python/specs/nickname.v1.json +16 -16
- package/python/specs/preference.v1.json +16 -16
- package/python/xujie_memory/admission.py +211 -211
- package/python/xujie_memory/audit.py +377 -377
- package/python/xujie_memory/benchmark.py +281 -281
- package/python/xujie_memory/character.py +199 -199
- package/python/xujie_memory/console.py +41 -41
- package/python/xujie_memory/consolidate.py +356 -356
- package/python/xujie_memory/due.py +121 -121
- package/python/xujie_memory/emotion.py +573 -573
- package/python/xujie_memory/errors.py +98 -98
- package/python/xujie_memory/importance.py +104 -104
- package/python/xujie_memory/judge.py +350 -350
- package/python/xujie_memory/memory.py +55 -0
- package/python/xujie_memory/orchestrator.py +690 -666
- package/python/xujie_memory/phrasing.py +292 -292
- package/python/xujie_memory/server.py +24 -0
- package/python/xujie_memory/specs.py +170 -170
- package/python/xujie_memory/summary.py +238 -238
|
@@ -217,6 +217,61 @@ class Memory:
|
|
|
217
217
|
raise ValueError("trace_not_found")
|
|
218
218
|
return self.lifecycle.curve(trace_id, points=max(2, min(60, int(points))))
|
|
219
219
|
|
|
220
|
+
# ------------------------------------------------------------ 删除 / 统计
|
|
221
|
+
def forget(self, scope_id: str, trace_id: str) -> dict[str, Any]:
|
|
222
|
+
"""删一条记忆:内容清空、FTS 移除、依赖它的事件一起失效。
|
|
223
|
+
|
|
224
|
+
不是物理删行——行还在,`erased_at` 有值,审计能看见"删过什么"。
|
|
225
|
+
依赖传播(欠账、偏好等由它推出的事实)由 `Engine.erase_trace` 负责,
|
|
226
|
+
它会在同一事务里把受影响的状态重算干净。
|
|
227
|
+
"""
|
|
228
|
+
trace = self.engine.get_trace(trace_id)
|
|
229
|
+
if trace is None or trace.get("scope_id") != scope_id:
|
|
230
|
+
raise ValueError("trace_not_found")
|
|
231
|
+
already_erased = bool(trace.get("erased_at"))
|
|
232
|
+
result = {"state_keys": []} if already_erased else self.engine.erase_trace(trace_id)
|
|
233
|
+
|
|
234
|
+
# 状态重算后重新对账画像,避免已删除的事实继续出现在提示词中。
|
|
235
|
+
from .profile import ProfileStore
|
|
236
|
+
profiles = ProfileStore(self.engine)
|
|
237
|
+
accounts = self.engine._conn().execute(
|
|
238
|
+
"SELECT account_id FROM person_profiles WHERE scope_id=?", (scope_id,)
|
|
239
|
+
).fetchall()
|
|
240
|
+
for account in accounts:
|
|
241
|
+
profiles.derive_from_memory(scope_id, account["account_id"])
|
|
242
|
+
return {"trace_id": trace_id, "erased": True, "already_erased": already_erased,
|
|
243
|
+
"state_keys": result["state_keys"]}
|
|
244
|
+
|
|
245
|
+
def stats(self, scope_id: str) -> dict[str, Any]:
|
|
246
|
+
"""库里的账:有多少条、多少条被删过、多少条锚住。
|
|
247
|
+
|
|
248
|
+
透明度用:用户问"你到底记了我多少东西"时,这里给得出数。
|
|
249
|
+
"""
|
|
250
|
+
conn = self.engine._conn()
|
|
251
|
+
|
|
252
|
+
def count(sql: str, *args) -> int:
|
|
253
|
+
return int(conn.execute(sql, args).fetchone()[0])
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
"scope_id": scope_id,
|
|
257
|
+
"traces": count(
|
|
258
|
+
"SELECT COUNT(*) FROM traces WHERE scope_id=? AND erased_at IS NULL",
|
|
259
|
+
scope_id),
|
|
260
|
+
"traces_erased": count(
|
|
261
|
+
"SELECT COUNT(*) FROM traces WHERE scope_id=? AND erased_at IS NOT NULL",
|
|
262
|
+
scope_id),
|
|
263
|
+
"events": count(
|
|
264
|
+
"SELECT COUNT(*) FROM events WHERE scope_id=?", scope_id),
|
|
265
|
+
"states": count(
|
|
266
|
+
"SELECT COUNT(*) FROM states WHERE scope_id=?", scope_id),
|
|
267
|
+
"anchors": len(self.lifecycle.anchored(scope_id)),
|
|
268
|
+
"clarifications_open": count(
|
|
269
|
+
"SELECT COUNT(*) FROM clarifications"
|
|
270
|
+
" WHERE scope_id=? AND status='open'", scope_id),
|
|
271
|
+
"summaries": count(
|
|
272
|
+
"SELECT COUNT(*) FROM summaries WHERE scope_id=?", scope_id),
|
|
273
|
+
}
|
|
274
|
+
|
|
220
275
|
# ------------------------------------------------------------ 搜索
|
|
221
276
|
def search(self, scope_id: str, query: str, *, limit: int = 5) -> list[dict]:
|
|
222
277
|
return self.fuzzy.search(scope_id, query, limit=limit)
|