@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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@furongjun1999/dsh-memory",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "description": "灵枢(Lingshu·líng shū)DeepSeek Harness 插件:完整大脑——长期记忆/知识飞轮/自我认知/递归反思接入 DSH,对话自动沉淀进 md_cg 认知图(md 文档)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",