@furongjun1999/dsh-memory 0.9.8 → 0.9.10

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 (57) hide show
  1. package/README.md +1 -1
  2. package/codebuddy/CODEBUDDY.md +4 -0
  3. package/docs/README.md +3 -0
  4. package/docs//350/247/204/350/214/203/AI/347/274/226/347/250/213/351/200/232/347/224/250/350/247/204/350/214/203.md +4 -0
  5. package/dsh/cordis.yml.example +2 -2
  6. package/lib/hooks.d.ts +11 -1
  7. package/lib/hooks.js +58 -3
  8. package/lib/index.d.ts +1 -1
  9. package/lib/index.js +2 -2
  10. package/lib/init.js +11 -2
  11. package/lib/lib/hook_audit.d.ts +3 -0
  12. package/lib/lib/hook_audit.js +37 -0
  13. package/md_cg/autonomy.py +1 -1
  14. package/md_cg/config_registry.py +329 -329
  15. package/md_cg/config_registry_bulk.py +2 -0
  16. package/md_cg/config_render.py +27 -0
  17. package/md_cg/config_validate.py +10 -8
  18. package/md_cg/conflict_surface.py +127 -0
  19. package/md_cg/mcp_server.py +105 -8
  20. package/md_cg/mdcg.py +60 -2
  21. package/md_cg/mdcos.py +61 -6
  22. package/md_cg/pooling.py +487 -485
  23. package/md_cg/qmd_llm.py +334 -334
  24. package/md_cg/reach.py +10 -4
  25. package/md_cg/sleep.py +2 -2
  26. package/md_cg/sustain.py +3 -3
  27. package/md_cg/test_auto_defaults.py +463 -463
  28. package/md_cg/test_autonomy_emotion.py +328 -328
  29. package/md_cg/test_bm25_default.py +56 -0
  30. package/md_cg/test_c3_transient_read_negative.py +797 -793
  31. package/md_cg/test_conflict_surface.py +75 -0
  32. package/md_cg/test_conflict_value_untrusted.py +63 -0
  33. package/md_cg/test_exact_text_cache.py +3 -0
  34. package/md_cg/test_hotcache_tool.py +121 -0
  35. package/md_cg/test_index_snapshot_fastpath.py +72 -0
  36. package/md_cg/test_issue274_read_node_id_none.py +29 -6
  37. package/md_cg/test_issue561_pending_review.py +89 -5
  38. package/md_cg/test_issue578_service_info_gate.py +264 -0
  39. package/md_cg/test_p3_legacy_closure.py +5 -2
  40. package/md_cg/test_p43_pooling.py +419 -412
  41. package/md_cg/test_reach.py +5 -1
  42. package/md_cg/test_reach_exits.py +54 -0
  43. package/md_cg/test_reach_single_char.py +74 -0
  44. package/md_cg/test_search_bm25_default.py +60 -0
  45. package/md_cg/test_sleep_p1.py +1032 -1032
  46. package/md_cg/test_untrusted_audit.py +55 -0
  47. package/md_cg/test_untrusted_classifier.py +42 -0
  48. package/md_cg/test_untrusted_enforcement.py +66 -0
  49. package/md_cg/untrusted.py +45 -0
  50. package/md_cg/untrusted_audit.py +87 -0
  51. package/md_cg/value_conflict.py +71 -0
  52. package/package.json +7 -7
  53. package/src/hooks.ts +986 -932
  54. package/src/index.ts +2 -2
  55. package/src/init.ts +7 -2
  56. package/src/lib/hook_audit.ts +32 -0
  57. package/zcode/AGENTS.md +4 -0
@@ -144,7 +144,11 @@ def main():
144
144
  ok(got is None and meta.get("reach") == "off", "(4) MDCG_REACH=0 → 不收敛", str(meta))
145
145
  _env(True)
146
146
  got, meta = reach.narrow(cg, entries, ["白"], bigrams("白"), None, q="白")
147
- ok(got is None and meta.get("reach") == "short_term", "(4) 单字符 term → 不收敛", str(meta))
147
+ # issue #611:单字符 term 不再整段跳过——用「含该字的 bigram」并集做超集收敛
148
+ # issue #611:判定口径改为「不再因单字符整段跳过」——后续可能 converged,
149
+ # 也可能因该字在库中无命中而 empty_converge;但绝不能再是 short_term。
150
+ ok(meta.get("reach") != "short_term",
151
+ "(4) 单字符 term 不再整段跳过(#611 新契约)", str(meta))
148
152
  saved = reach._index
149
153
  reach._index = lambda *a, **k: None
150
154
  try:
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ """reach 不再产生 short_term 的静态+动态守卫(issue #611 回归)。
3
+
4
+ S1 静态:md_cg/reach.py 源码中不再出现 short_term 字样(防注释/代码漂移回潮)
5
+ S2 动态:单字符 term 调用 narrow 不得返回 short_term
6
+ S3 出口清单:允许的 reach 值集合固定(converged/off/index_unavailable/hash_incomplete/
7
+ no_tokens/empty_converge/fresh_overflow)
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import io
12
+ import os
13
+ import tempfile
14
+
15
+ from . import reach as R
16
+ from .mdcg import MdCG
17
+
18
+ ALLOWED = {"converged", "off", "index_unavailable", "hash_incomplete",
19
+ "no_tokens", "empty_converge", "fresh_overflow"}
20
+
21
+
22
+ def main():
23
+ os.environ["MDCG_REACH"] = "1"
24
+ ok = 0
25
+ bad = 0
26
+
27
+ def chk(cond, label):
28
+ nonlocal ok, bad
29
+ if cond:
30
+ ok += 1
31
+ print(" PASS", label)
32
+ else:
33
+ bad += 1
34
+ print(" FAIL", label)
35
+
36
+ src = io.open(os.path.join(os.path.dirname(__file__), "reach.py"), encoding="utf-8").read()
37
+ chk("short_term" not in src, "S1 源码中不再出现 short_term(#611 已修)")
38
+
39
+ root = tempfile.mkdtemp(prefix="reach_exits_")
40
+ cg = MdCG(root)
41
+ for i, txt in enumerate(("灵枢 记忆库 记录", "记 单字 样本", "无关 内容")):
42
+ cg.add("x%d" % i, txt, layer="knowledge")
43
+ entries = list(cg.index["nodes"].values())
44
+ _got, meta = R.narrow(cg, entries, ["记"], set(), q="记")
45
+ chk(meta.get("reach") != "short_term", "S2 单字符 term 不再返回 short_term(实得 %s)" % meta.get("reach"))
46
+ chk(meta.get("reach") in ALLOWED, "S3 出口值在允许集合内")
47
+
48
+ print("=" * 60)
49
+ print("reach 出口守卫:%d 通过 / %d 失败" % (ok, bad))
50
+ return 0 if bad == 0 else 1
51
+
52
+
53
+ if __name__ == "__main__":
54
+ raise SystemExit(main())
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ """reach 单字符 term 收敛守卫(issue #611)。
3
+
4
+ R1 含单字符 term 时不再整段跳过(meta.reach 不是 short_term)
5
+ R2 召回不丢:同一查询在 reach 开/关下,命中集合一致(单字符 bigram 并集是超集口径)
6
+ R3 仍能收敛:含单字符 term 时 scanned 小于全量候选数
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import tempfile
12
+
13
+ from .mdcg import MdCG
14
+ from . import reach as R
15
+
16
+
17
+ def _mk():
18
+ root = tempfile.mkdtemp(prefix="reach_sc_")
19
+ cg = MdCG(root)
20
+ docs = [
21
+ ("a1", "灵枢 记忆库 的第一条记录"),
22
+ ("a2", "灵枢 的 记 字单独出现 也无所谓"),
23
+ ("a3", "记忆库 与 灵枢 的组合内容"),
24
+ ("a4", "完全无关的 数据 一条"),
25
+ ("a5", "记 录 单字 命中 样本"),
26
+ ]
27
+ for nid, txt in docs:
28
+ cg.add(nid, txt, layer="knowledge")
29
+ return cg
30
+
31
+
32
+ def main():
33
+ os.environ["MDCG_REACH"] = "1"
34
+ ok = 0
35
+ bad = 0
36
+
37
+ def chk(cond, label):
38
+ nonlocal ok, bad
39
+ if cond:
40
+ ok += 1
41
+ print(" PASS", label)
42
+ else:
43
+ bad += 1
44
+ print(" FAIL", label)
45
+
46
+ cg = _mk()
47
+ entries = list(cg.index["nodes"].values())
48
+ terms = ["灵枢", "记"]
49
+ got, meta = R.narrow(cg, entries, terms, set(), q="灵枢 记")
50
+ chk(meta.get("reach") != "short_term", "R1 单字符 term 不再整段跳过(reach=%s)" % meta.get("reach"))
51
+ chk(got is not None, "R1b 返回收敛集而非 None")
52
+ if got is not None:
53
+ chk(len(got) < len(entries), "R3 确有收敛(%d < %d)" % (len(got), len(entries)))
54
+ # R2:收敛集必须覆盖「含灵枢 或 含记」的全部文档
55
+ full = [e for e in entries
56
+ if any(t in cg.get(e.get("path", "").rsplit("/", 1)[-1][:-3] or "") for t in [])] if False else None
57
+ pathes = {e.get("path") for e in got}
58
+ # 用 LIKE 语义核对:凡正文含 "灵枢" 或 "记" 的节点都应在收敛集内
59
+ for e in entries:
60
+ node = cg.get(str(e.get("id") or ""))
61
+ body = (node or {}).get("content", "") if isinstance(node, dict) else ""
62
+ if ("灵枢" in body or "记" in body) and e.get("path") not in pathes:
63
+ chk(False, "R2 召回丢失:%s 未进收敛集" % e.get("path"))
64
+ break
65
+ else:
66
+ chk(True, "R2 召回不丢(含灵枢/记的节点全在收敛集内)")
67
+
68
+ print("=" * 60)
69
+ print("reach 单字符守卫:%d 通过 / %d 失败" % (ok, bad))
70
+ return 0 if bad == 0 else 1
71
+
72
+
73
+ if __name__ == "__main__":
74
+ raise SystemExit(main())
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ """默认检索接入 BM25 的守卫(融合统一,2026-10-21)。
3
+
4
+ B1 召回不变:同一查询在 MDCG_BM25=0/1 下返回的 id 集合相同(BM25 只改排序强度)
5
+ B2 不崩:两种模式下都返回非空结果与 meta
6
+ B3 集成点在位:md_cg/mdcos.py 的 search 里存在 BM25 接线标记
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import io
11
+ import os
12
+ import tempfile
13
+
14
+ from .mdcos import MdCGSecure
15
+
16
+
17
+ def _search(flag):
18
+ os.environ["MDCG_BM25"] = flag
19
+ root = tempfile.mkdtemp(prefix="bmdef_")
20
+ cg = MdCGSecure(root)
21
+ cg.add("n1", "灵枢 记忆库 说明 文档 通用 内容", layer="knowledge")
22
+ cg.add("n2", "灵枢 记忆库 说明 文档 通用 内容 阿洛芬希德 专有名词", layer="knowledge")
23
+ cg.add("n3", "灵枢 记忆库 说明 文档 通用 内容 常见词 反复", layer="knowledge")
24
+ res, meta = cg.search("灵枢 记忆库 说明", k=3)
25
+ ids = []
26
+ for row in res:
27
+ doc = row[0] if isinstance(row, tuple) else row
28
+ if isinstance(doc, dict):
29
+ ids.append(doc.get("id"))
30
+ return ids, meta
31
+
32
+
33
+ def main():
34
+ ok = 0
35
+ bad = 0
36
+
37
+ def chk(cond, label):
38
+ nonlocal ok, bad
39
+ if cond:
40
+ ok += 1
41
+ print(" PASS", label)
42
+ else:
43
+ bad += 1
44
+ print(" FAIL", label)
45
+
46
+ ids_off, meta_off = _search("0")
47
+ ids_on, meta_on = _search("1")
48
+ chk(bool(ids_off) and bool(ids_on), "B2 两种模式都返回非空结果(off=%d on=%d)" % (len(ids_off), len(ids_on)))
49
+ chk(set(ids_off) == set(ids_on), "B1 召回集合一致(BM25 只改排序): %s vs %s" % (ids_off, ids_on))
50
+ chk(isinstance(meta_on, dict) and isinstance(meta_off, dict), "B2b meta 形态不变")
51
+ src = io.open(os.path.join(os.path.dirname(__file__), "mdcos.py"), encoding="utf-8").read()
52
+ chk("MDCG_BM25" in src and "_bm_for(docs)" in src, "B3 集成点在位(search 内 BM25 接线)")
53
+
54
+ print("=" * 60)
55
+ print("BM25 默认接入守卫:%d 通过 / %d 失败" % (ok, bad))
56
+ return 0 if bad == 0 else 1
57
+
58
+
59
+ if __name__ == "__main__":
60
+ raise SystemExit(main())