@furongjun1999/dsh-memory 0.9.8 → 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.
- package/README.md +1 -1
- package/codebuddy/CODEBUDDY.md +4 -0
- package/docs/README.md +3 -0
- 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
- package/dsh/cordis.yml.example +2 -2
- package/lib/hooks.d.ts +11 -1
- package/lib/hooks.js +58 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/init.js +11 -2
- package/lib/lib/hook_audit.d.ts +3 -0
- package/lib/lib/hook_audit.js +37 -0
- package/md_cg/autonomy.py +1 -1
- package/md_cg/config_registry.py +329 -329
- package/md_cg/config_registry_bulk.py +483 -482
- package/md_cg/config_render.py +27 -0
- package/md_cg/config_validate.py +456 -455
- package/md_cg/conflict_surface.py +127 -0
- package/md_cg/mcp_server.py +5324 -5227
- package/md_cg/mdcg.py +12 -1
- package/md_cg/mdcos.py +7159 -7108
- package/md_cg/pooling.py +487 -485
- package/md_cg/qmd_llm.py +334 -334
- package/md_cg/reach.py +10 -4
- package/md_cg/sleep.py +2 -2
- package/md_cg/sustain.py +3 -3
- package/md_cg/test_auto_defaults.py +463 -463
- package/md_cg/test_autonomy_emotion.py +328 -328
- package/md_cg/test_bm25_default.py +56 -0
- package/md_cg/test_c3_transient_read_negative.py +7 -3
- package/md_cg/test_conflict_surface.py +75 -0
- package/md_cg/test_conflict_value_untrusted.py +63 -0
- package/md_cg/test_exact_text_cache.py +194 -191
- package/md_cg/test_hotcache_tool.py +121 -0
- package/md_cg/test_issue274_read_node_id_none.py +364 -341
- package/md_cg/test_issue561_pending_review.py +89 -5
- package/md_cg/test_issue578_service_info_gate.py +264 -0
- package/md_cg/test_p3_legacy_closure.py +441 -438
- package/md_cg/test_p43_pooling.py +419 -412
- package/md_cg/test_reach.py +5 -1
- package/md_cg/test_reach_exits.py +54 -0
- package/md_cg/test_reach_single_char.py +74 -0
- package/md_cg/test_search_bm25_default.py +60 -0
- package/md_cg/test_sleep_p1.py +1032 -1032
- package/md_cg/test_untrusted_audit.py +55 -0
- package/md_cg/test_untrusted_classifier.py +42 -0
- package/md_cg/test_untrusted_enforcement.py +66 -0
- package/md_cg/untrusted.py +45 -0
- package/md_cg/untrusted_audit.py +87 -0
- package/md_cg/value_conflict.py +71 -0
- package/package.json +7 -7
- package/src/hooks.ts +59 -5
- package/src/index.ts +2 -2
- package/src/init.ts +7 -2
- package/src/lib/hook_audit.ts +32 -0
- package/zcode/AGENTS.md +4 -0
|
@@ -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
|