Files
dsh_ai1net_server/.workbuddy/tools/guard-replay.py
T
admin ce8e6ceed9 chore(工作区): 纳入版本控制基线(回收 411 MB 过程产物)
回收 411 MB(470 M → 58.8 M),全部经回收站,可恢复:
- 待清理/(146.2 M,含 relay 分片 128 M 与 42 项过程目录)
- tmp/(32.4 M,按接续棒命名的过程临时区)
- .workbuddy/tmp/(39.5 M)
- 4 份 workbuddy.db 冗余副本(101 M,09-23 事故的坏副本 / 抢救产物)
- tmp/im16/gw/centrifugo 二进制(63.9 M,可重下)+ 缓存残留

入库范围:常驻规则(CODEBUDDY.md / README.md / state.py)、在途接续入口与
接续包、docs/、交付物/、交接单/、归档/、scripts/、.codebuddy/、
.workbuddy/memory/;共 398 件,其中 >60 KB 的 26 件全为文档。

排除(.gitignore):tmp/、待清理/、运行态日志与缓存、*.db 与 DB 备份整目录、
打包二进制(*.tar.gz / *.tgz)、记忆修复前备份。
2026-09-24 07:51:03 +08:00

80 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""回放测试:把今天所有会话的真实 Bash 命令灌进 bash-output-guard,统计误拦率。
只打印「摘要 + DENY 明细」,不 dump 全量命令。
"""
import collections
import glob
import importlib.util
import io
import json
import os
GUARD = r"D:\github\dsh_shenxian\dsh-server-docs\scripts\bash-output-guard.py"
PROJ = r"E:\ProgramData\.workbuddy\projects\e-ProgramData-AI技能-aliyun-dsh-server"
sp = importlib.util.spec_from_file_location("g", GUARD)
g = importlib.util.module_from_spec(sp)
sp.loader.exec_module(g)
cmds = []
for f in sorted(glob.glob(os.path.join(PROJ, "*.jsonl"))):
sid = os.path.basename(f)[:8]
for ln in io.open(f, encoding="utf-8", errors="replace"):
if '"function_call"' not in ln or '"Bash"' not in ln:
continue
try:
o = json.loads(ln)
except ValueError:
continue
if o.get("type") != "function_call" or o.get("name") != "Bash":
continue
try:
a = json.loads(o.get("arguments") or "{}")
except ValueError:
continue
c = a.get("command")
if isinstance(c, str) and c.strip():
cmds.append((sid, c))
by_sid = collections.Counter(s for s, _ in cmds)
print("=== 样本 ===")
print(" Bash 命令 %d 条 | 会话 %d 个" % (len(cmds), len(by_sid)))
for s, n in by_sid.most_common():
print(" %s %d 条" % (s, n))
den, safehit = [], 0
for sid, c in cmds:
if g.SAFE.search(c): # 真链路里 main() 先过 SAFE 就放行
safehit += 1
continue
why, fix = g.reason_for(c, hard=False)
if why:
den.append((sid, why, c))
print()
print("=== soft 档(默认)判定 ===")
print(" DENY = %d / %d = **%.2f%%** (被 SAFE 限流救回 %d 条)"
% (len(den), len(cmds), 100.0 * len(den) / max(len(cmds), 1), safehit))
for w, n in collections.Counter(w for _, w, _ in den).most_common():
print(" %-22s %d" % (w, n))
print()
print("=== DENY 明细(前 30 条 · 截 108 字符)===")
for sid, why, c in den[:30]:
print(" [%s] %-20s %s" % (sid, why, c.replace("\n", " ")[:108]))
if not den:
print(" (无 DENY —— 全部放行)")
print()
print("=== hard 档(仅参考)===")
denh = []
for sid, c in cmds:
if g.SAFE.search(c):
continue
why, _ = g.reason_for(c, hard=True)
if why:
denh.append((sid, why, c))
print(" DENY = %d / %d = %.2f%%" % (len(denh), len(cmds), 100.0 * len(denh) / max(len(cmds), 1)))
for w, n in collections.Counter(w for _, w, _ in denh).most_common():
print(" %-22s %d" % (w, n))