@furongjun1999/dsh-memory 0.9.9 → 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.
- package/md_cg/config_registry_bulk.py +484 -483
- package/md_cg/config_validate.py +457 -456
- package/md_cg/mcp_server.py +5324 -5324
- package/md_cg/mdcg.py +48 -1
- package/md_cg/mdcos.py +7163 -7159
- package/md_cg/test_c3_transient_read_negative.py +797 -797
- package/md_cg/test_exact_text_cache.py +194 -194
- package/md_cg/test_hotcache_tool.py +121 -121
- package/md_cg/test_index_snapshot_fastpath.py +72 -0
- package/md_cg/test_issue274_read_node_id_none.py +364 -364
- package/md_cg/test_p3_legacy_closure.py +441 -441
- package/md_cg/test_search_bm25_default.py +60 -60
- package/md_cg/test_untrusted_audit.py +55 -55
- package/md_cg/test_untrusted_classifier.py +42 -42
- package/md_cg/test_untrusted_enforcement.py +66 -66
- package/md_cg/untrusted.py +45 -45
- package/md_cg/untrusted_audit.py +87 -87
- package/package.json +1 -1
- package/src/hooks.ts +986 -986
package/md_cg/untrusted_audit.py
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""untrusted_audit · 误判率巡检读数(使用者裁定 2026-10-21 第 1 条)
|
|
3
|
-
|
|
4
|
-
背景:untrusted 标记会让条目**不进 recall(上下文)**,误判 = 合法记忆消失。
|
|
5
|
-
故需要可复算的读数:命中了多少条、按理由/按 marker 分布、以及供人工抽检的样本。
|
|
6
|
-
|
|
7
|
-
口径(只读,不改任何节点):
|
|
8
|
-
· 遍历 knowledge 层节点正文(去掉 frontmatter),跑 untrusted.classify;
|
|
9
|
-
· 计数按 reason(line_start_or_after_colon / instruction_frame / multi_marker)分组;
|
|
10
|
-
· 抽样默认 5 条,给 id + markers + 前 80 字,供人工判真伪。
|
|
11
|
-
|
|
12
|
-
用法:
|
|
13
|
-
python -m md_cg.untrusted_audit --root <库根> [--limit 2000] [--sample 5]
|
|
14
|
-
"""
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import argparse
|
|
18
|
-
import glob
|
|
19
|
-
import io
|
|
20
|
-
import json
|
|
21
|
-
import os
|
|
22
|
-
|
|
23
|
-
from . import untrusted as U
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def _body(text: str) -> str:
|
|
27
|
-
if text.startswith("---"):
|
|
28
|
-
parts = text.split("---", 2)
|
|
29
|
-
if len(parts) >= 3:
|
|
30
|
-
return parts[2]
|
|
31
|
-
return text
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def scan(root: str, limit: int = 2000, sample: int = 5) -> dict:
|
|
35
|
-
"""扫描 knowledge 层节点,返回误判巡检读数(不写任何东西)。"""
|
|
36
|
-
pattern = os.path.join(root, "knowledge", "**", "*.md")
|
|
37
|
-
files = sorted(glob.glob(pattern, recursive=True))[:max(1, int(limit))]
|
|
38
|
-
flagged = 0
|
|
39
|
-
by_reason = {}
|
|
40
|
-
by_marker = {}
|
|
41
|
-
samples = []
|
|
42
|
-
for path in files:
|
|
43
|
-
try:
|
|
44
|
-
text = io.open(path, encoding="utf-8", errors="replace").read()
|
|
45
|
-
except OSError:
|
|
46
|
-
continue
|
|
47
|
-
body = _body(text)
|
|
48
|
-
r = U.classify(body)
|
|
49
|
-
if not r.get("untrusted"):
|
|
50
|
-
continue
|
|
51
|
-
flagged += 1
|
|
52
|
-
reason = r.get("reason") or "unknown"
|
|
53
|
-
by_reason[reason] = by_reason.get(reason, 0) + 1
|
|
54
|
-
for m in r.get("markers") or []:
|
|
55
|
-
by_marker[m] = by_marker.get(m, 0) + 1
|
|
56
|
-
if len(samples) < max(0, int(sample)):
|
|
57
|
-
samples.append({
|
|
58
|
-
"path": os.path.relpath(path, root).replace("\\", "/"),
|
|
59
|
-
"markers": r.get("markers"),
|
|
60
|
-
"reason": reason,
|
|
61
|
-
"excerpt": body.strip().replace("\n", " ")[:80],
|
|
62
|
-
})
|
|
63
|
-
total = len(files)
|
|
64
|
-
return {
|
|
65
|
-
"root": root,
|
|
66
|
-
"scanned": total,
|
|
67
|
-
"flagged": flagged,
|
|
68
|
-
"flag_ratio": round(flagged / total, 6) if total else 0.0,
|
|
69
|
-
"by_reason": by_reason,
|
|
70
|
-
"by_marker": by_marker,
|
|
71
|
-
"samples": samples,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def main(argv=None):
|
|
76
|
-
ap = argparse.ArgumentParser(description="untrusted 误判率巡检读数")
|
|
77
|
-
ap.add_argument("--root", required=True)
|
|
78
|
-
ap.add_argument("--limit", type=int, default=2000)
|
|
79
|
-
ap.add_argument("--sample", type=int, default=5)
|
|
80
|
-
a = ap.parse_args(argv)
|
|
81
|
-
print(json.dumps(scan(a.root, limit=a.limit, sample=a.sample),
|
|
82
|
-
ensure_ascii=False, indent=2))
|
|
83
|
-
return 0
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if __name__ == "__main__":
|
|
87
|
-
raise SystemExit(main())
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""untrusted_audit · 误判率巡检读数(使用者裁定 2026-10-21 第 1 条)
|
|
3
|
+
|
|
4
|
+
背景:untrusted 标记会让条目**不进 recall(上下文)**,误判 = 合法记忆消失。
|
|
5
|
+
故需要可复算的读数:命中了多少条、按理由/按 marker 分布、以及供人工抽检的样本。
|
|
6
|
+
|
|
7
|
+
口径(只读,不改任何节点):
|
|
8
|
+
· 遍历 knowledge 层节点正文(去掉 frontmatter),跑 untrusted.classify;
|
|
9
|
+
· 计数按 reason(line_start_or_after_colon / instruction_frame / multi_marker)分组;
|
|
10
|
+
· 抽样默认 5 条,给 id + markers + 前 80 字,供人工判真伪。
|
|
11
|
+
|
|
12
|
+
用法:
|
|
13
|
+
python -m md_cg.untrusted_audit --root <库根> [--limit 2000] [--sample 5]
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import glob
|
|
19
|
+
import io
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
from . import untrusted as U
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _body(text: str) -> str:
|
|
27
|
+
if text.startswith("---"):
|
|
28
|
+
parts = text.split("---", 2)
|
|
29
|
+
if len(parts) >= 3:
|
|
30
|
+
return parts[2]
|
|
31
|
+
return text
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def scan(root: str, limit: int = 2000, sample: int = 5) -> dict:
|
|
35
|
+
"""扫描 knowledge 层节点,返回误判巡检读数(不写任何东西)。"""
|
|
36
|
+
pattern = os.path.join(root, "knowledge", "**", "*.md")
|
|
37
|
+
files = sorted(glob.glob(pattern, recursive=True))[:max(1, int(limit))]
|
|
38
|
+
flagged = 0
|
|
39
|
+
by_reason = {}
|
|
40
|
+
by_marker = {}
|
|
41
|
+
samples = []
|
|
42
|
+
for path in files:
|
|
43
|
+
try:
|
|
44
|
+
text = io.open(path, encoding="utf-8", errors="replace").read()
|
|
45
|
+
except OSError:
|
|
46
|
+
continue
|
|
47
|
+
body = _body(text)
|
|
48
|
+
r = U.classify(body)
|
|
49
|
+
if not r.get("untrusted"):
|
|
50
|
+
continue
|
|
51
|
+
flagged += 1
|
|
52
|
+
reason = r.get("reason") or "unknown"
|
|
53
|
+
by_reason[reason] = by_reason.get(reason, 0) + 1
|
|
54
|
+
for m in r.get("markers") or []:
|
|
55
|
+
by_marker[m] = by_marker.get(m, 0) + 1
|
|
56
|
+
if len(samples) < max(0, int(sample)):
|
|
57
|
+
samples.append({
|
|
58
|
+
"path": os.path.relpath(path, root).replace("\\", "/"),
|
|
59
|
+
"markers": r.get("markers"),
|
|
60
|
+
"reason": reason,
|
|
61
|
+
"excerpt": body.strip().replace("\n", " ")[:80],
|
|
62
|
+
})
|
|
63
|
+
total = len(files)
|
|
64
|
+
return {
|
|
65
|
+
"root": root,
|
|
66
|
+
"scanned": total,
|
|
67
|
+
"flagged": flagged,
|
|
68
|
+
"flag_ratio": round(flagged / total, 6) if total else 0.0,
|
|
69
|
+
"by_reason": by_reason,
|
|
70
|
+
"by_marker": by_marker,
|
|
71
|
+
"samples": samples,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def main(argv=None):
|
|
76
|
+
ap = argparse.ArgumentParser(description="untrusted 误判率巡检读数")
|
|
77
|
+
ap.add_argument("--root", required=True)
|
|
78
|
+
ap.add_argument("--limit", type=int, default=2000)
|
|
79
|
+
ap.add_argument("--sample", type=int, default=5)
|
|
80
|
+
a = ap.parse_args(argv)
|
|
81
|
+
print(json.dumps(scan(a.root, limit=a.limit, sample=a.sample),
|
|
82
|
+
ensure_ascii=False, indent=2))
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
raise SystemExit(main())
|
package/package.json
CHANGED