@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
@@ -0,0 +1,127 @@
1
+ # -*- coding: utf-8 -*-
2
+ """conflict_surface · 检索结果内的「显式矛盾对」暴露(红队缺口 B/C)
3
+
4
+ 判据只收能给出证据的一类矛盾:
5
+
6
+ A 的 non_applicable_conditions(**整条**文本,长度 >= MIN_EVIDENCE)
7
+ 作为连续子串出现在 B 的正文里 ⇒ A 排除了 B 所述情形(双向都查)。
8
+
9
+ 边界(经反思单元审计后收窄,见 PR 讨论):
10
+ · 只比正文,不比声明面(B 的 negs 在反向检查里作为 A 的角色参与);
11
+ · 节点缺 id 时按**序号**区分,不因空串相等而整对跳过;
12
+ · 三类信号各自有上限,输出体积有界;
13
+ · 启发式(value_conflict 的正则退路)默认关,须显式 allow_heuristic=True。
14
+
15
+ 纪律对齐:第 4 条(只报能给出证据的)、第 5 条(无证据即不报)。
16
+ """
17
+ from __future__ import annotations
18
+
19
+ from . import untrusted as _ut
20
+ from . import value_conflict as _vc
21
+
22
+ MIN_EVIDENCE = 4 # 证据子串最短长度(防单字噪声)
23
+ MAX_PAIRS = 5 # 每类信号单次最多报几条
24
+
25
+
26
+ def _norm(text) -> str:
27
+ return " ".join(str(text or "").split())
28
+
29
+
30
+ def _neg_texts(fm) -> list:
31
+ raw = (fm or {}).get("non_applicable_conditions") or []
32
+ if isinstance(raw, str):
33
+ raw = [raw]
34
+ out = []
35
+ for x in raw:
36
+ s = _norm(x)
37
+ if len(s) >= MIN_EVIDENCE:
38
+ out.append(s)
39
+ return out
40
+
41
+
42
+ def _items(nodes):
43
+ """[(key, id, negs, body)];id 缺失时用序号补齐键,避免空串互撞。"""
44
+ out = []
45
+ for i, n in enumerate(nodes or []):
46
+ if not isinstance(n, dict):
47
+ continue
48
+ nid = str(n.get("id") or "")
49
+ out.append(("#%d" % i, nid, _neg_texts(n.get("frontmatter")), _norm(n.get("content"))))
50
+ return out
51
+
52
+
53
+ def conflicts_among(nodes, limit: int = MAX_PAIRS) -> list:
54
+ """双向查「A 的 neg 出现在 B 正文」;返回 [{a,b,evidence,kind}]。
55
+
56
+ 只在 i<j 的组合上做两个方向,避免 (A,B) 与 (B,A) 两条循环把同一对报两遍。
57
+ """
58
+ items = _items(nodes)
59
+ pairs = []
60
+ for i in range(len(items)):
61
+ _ka, a_id, a_negs, a_body = items[i]
62
+ for j in range(i + 1, len(items)):
63
+ _kb, b_id, b_negs, b_body = items[j]
64
+ if b_body:
65
+ for neg in a_negs:
66
+ if neg in b_body:
67
+ pairs.append({"a": a_id, "b": b_id, "evidence": neg,
68
+ "kind": "a_neg_in_b_body"})
69
+ break
70
+ if a_body:
71
+ for neg in b_negs:
72
+ if neg in a_body:
73
+ pairs.append({"a": b_id, "b": a_id, "evidence": neg,
74
+ "kind": "b_neg_in_a_body"})
75
+ break
76
+ if len(pairs) >= limit:
77
+ return pairs
78
+ return pairs
79
+
80
+
81
+ def value_pairs_among(nodes, limit: int = MAX_PAIRS, allow_heuristic: bool = False) -> list:
82
+ """同 condition_space 下同名键不同值(默认只认声明面 value_slots)。"""
83
+ items = []
84
+ for i, n in enumerate(nodes or []):
85
+ if isinstance(n, dict):
86
+ items.append((str(n.get("id") or ""), n.get("frontmatter") or {}, _norm(n.get("content"))))
87
+ out = []
88
+ for i in range(len(items)):
89
+ for j in range(i + 1, len(items)):
90
+ a_id, a_fm, a_body = items[i]
91
+ b_id, b_fm, b_body = items[j]
92
+ hit = _vc.compare(a_fm, a_body, b_fm, b_body, allow_heuristic=allow_heuristic)
93
+ if hit:
94
+ hit["a"], hit["b"] = a_id, b_id
95
+ out.append(hit)
96
+ if len(out) >= limit:
97
+ return out
98
+ return out
99
+
100
+
101
+ def untrusted_among(nodes, limit: int = MAX_PAIRS) -> list:
102
+ """检索结果里命中「伪装系统消息/指令式」的节点(只报案,不改内容)。"""
103
+ out = []
104
+ for n in nodes or []:
105
+ if not isinstance(n, dict):
106
+ continue
107
+ r = _ut.classify(n.get("content"))
108
+ if r.get("untrusted"):
109
+ out.append({"id": str(n.get("id") or ""), "markers": r.get("markers")})
110
+ if len(out) >= limit:
111
+ break
112
+ return out
113
+
114
+
115
+ def as_meta(nodes, limit: int = MAX_PAIRS, allow_heuristic: bool = False) -> dict:
116
+ """把三类信号包成可直接并进 meta 的字典(空则不产生键;三类各自有上限)。"""
117
+ meta = {}
118
+ pairs = conflicts_among(nodes, limit=limit)
119
+ if pairs:
120
+ meta["conflicts_among"] = pairs
121
+ vp = value_pairs_among(nodes, limit=limit, allow_heuristic=allow_heuristic)
122
+ if vp:
123
+ meta["value_conflicts_among"] = vp
124
+ ut = untrusted_among(nodes, limit=limit)
125
+ if ut:
126
+ meta["untrusted_among"] = ut
127
+ return meta