@furongjun1999/dsh-memory 0.9.7 → 0.9.9

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 (68) hide show
  1. package/README.md +150 -662
  2. package/codebuddy/CODEBUDDY.md +337 -204
  3. package/docs/README.md +21 -0
  4. package/docs/discipline/harnesses.yaml +11 -3
  5. package/docs/discipline/templates/compact.txt.tmpl +20 -18
  6. package/docs/discipline/templates/full.md.tmpl +63 -61
  7. package/docs/discipline/templates/rules.mdc.tmpl +5 -3
  8. package/docs/discipline/templates/skill.md.tmpl +25 -23
  9. package/docs/discipline/templates/spec.txt.tmpl +1 -1
  10. package/docs/discipline/templates/zcode-user.md.tmpl +1 -1
  11. 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
  12. package/dsh/cordis.yml.example +2 -2
  13. package/lib/hooks.d.ts +11 -1
  14. package/lib/hooks.js +59 -4
  15. package/lib/index.d.ts +1 -1
  16. package/lib/index.js +11 -5
  17. package/lib/init.js +28 -4
  18. package/lib/lib/hook_audit.d.ts +3 -0
  19. package/lib/lib/hook_audit.js +63 -0
  20. package/md_cg/autonomy.py +1 -1
  21. package/md_cg/config_registry.py +329 -329
  22. package/md_cg/config_registry_bulk.py +483 -482
  23. package/md_cg/config_render.py +27 -0
  24. package/md_cg/config_validate.py +456 -455
  25. package/md_cg/conflict_surface.py +127 -0
  26. package/md_cg/mcp_server.py +5324 -5227
  27. package/md_cg/mdcg.py +12 -1
  28. package/md_cg/mdcos.py +7159 -7108
  29. package/md_cg/pooling.py +487 -485
  30. package/md_cg/qmd_llm.py +334 -334
  31. package/md_cg/reach.py +10 -4
  32. package/md_cg/sleep.py +2 -2
  33. package/md_cg/sustain.py +13 -4
  34. package/md_cg/test_auto_defaults.py +463 -463
  35. package/md_cg/test_autonomy_emotion.py +328 -328
  36. package/md_cg/test_bm25_default.py +56 -0
  37. package/md_cg/test_c3_transient_read_negative.py +7 -3
  38. package/md_cg/test_conflict_surface.py +75 -0
  39. package/md_cg/test_conflict_value_untrusted.py +63 -0
  40. package/md_cg/test_exact_text_cache.py +194 -191
  41. package/md_cg/test_heartbeat_ledger.py +563 -557
  42. package/md_cg/test_hotcache_tool.py +121 -0
  43. package/md_cg/test_issue274_read_node_id_none.py +364 -341
  44. package/md_cg/test_issue561_pending_review.py +89 -5
  45. package/md_cg/test_issue578_service_info_gate.py +264 -0
  46. package/md_cg/test_n184_keys_concurrent_provision.py +1 -1
  47. package/md_cg/test_p3_legacy_closure.py +441 -438
  48. package/md_cg/test_p43_pooling.py +419 -412
  49. package/md_cg/test_reach.py +5 -1
  50. package/md_cg/test_reach_exits.py +54 -0
  51. package/md_cg/test_reach_single_char.py +74 -0
  52. package/md_cg/test_read_scope_b27.py +2 -2
  53. package/md_cg/test_search_bm25_default.py +60 -0
  54. package/md_cg/test_security_audit_v21.py +249 -249
  55. package/md_cg/test_sleep_p1.py +1032 -1032
  56. package/md_cg/test_sustain_bad_stamp.py +178 -0
  57. package/md_cg/test_untrusted_audit.py +55 -0
  58. package/md_cg/test_untrusted_classifier.py +42 -0
  59. package/md_cg/test_untrusted_enforcement.py +66 -0
  60. package/md_cg/untrusted.py +45 -0
  61. package/md_cg/untrusted_audit.py +87 -0
  62. package/md_cg/value_conflict.py +71 -0
  63. package/package.json +7 -7
  64. package/src/hooks.ts +986 -932
  65. package/src/index.ts +20 -14
  66. package/src/init.ts +21 -4
  67. package/src/lib/hook_audit.ts +334 -282
  68. package/zcode/AGENTS.md +337 -204
@@ -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())
@@ -7,7 +7,7 @@
7
7
  (跳过个人敏感信息不入明文);
8
8
  - 子代理(worker):read_file 收敛到工作区(job_dir)+ 定制工作目录
9
9
  (spec.workdir / spec.read_roots)——其他会话与越界内容拒读(fail-closed,
10
- 无根即无文件读权限);lingshu_cg 读面默认密级 internal——**错误处置标记
10
+ 无根即无文件读权限);cg 读面默认密级 internal——**错误处置标记
11
11
  (private,错误相关/待排查内容限制平级扩散,非个人隐私)与 secret 拒读**。
12
12
  错误处置链路(设计者/上级节点/验证单元)必读 private 不受此限——verify
13
13
  面当前 clearance_cap=internal 的缺口已登记(安全审计实锚文档)。
@@ -106,7 +106,7 @@ def main():
106
106
  plain = "普通技术文档:quick sort 复杂度 O(n log n),蜂群调度正常。"
107
107
  check("B27-3x 普通文本不误伤", hx._redact_pii(plain) == plain)
108
108
 
109
- print("== lingshu_cg 密级分级(worker=internal 拒读 private/secret)==")
109
+ print("== cg 密级分级(worker=internal 拒读 private/secret)==")
110
110
  from md_cg.mdcos import MdCGSecure
111
111
  from md_cg.security import Principal
112
112
  root = tempfile.mkdtemp(prefix="b27_cg_")
@@ -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())