AIFeed

Show HN:Zmb-audit——零依赖的 Python AST 审计工具,用于检测 AI 生成的死代码

Translation(model translation, not the source's own text)

仓库文件导航

题图
题图

ZMB 独立代码库审计器(zmb_audit.py)

一个零依赖、仅用标准库的静态 AST 审计器,能捕捉 AI 编码代理在通过单元测试的同时引入的那些确切失效模式。

它能捕捉什么

  • 孤立模块:仓库中存在但从未被任何东西导入的非测试 Python 模块。
  • 未解析的仓库类属性调用:对仓库内定义的类进行的方法调用,而该方法并不存在(对标准库或第三方对象零误报)。
  • 静默异常回退:宽泛的 except Exception: / except: 块吞掉错误并返回 []、{}、None、"" 或 pass,把致命的运行时 bug 变成假绿的测试。
  • Git 预提交守卫状态:检查进程外的 pre-commit 保护是否处于激活状态。

要求

  • Python 3.8+(仅标准库——零 pip 依赖)。

用法


        # 审计当前目录
python zmb_audit.py

# 审计指定仓库路径
python zmb_audit.py /path/to/repository

# CI 模式:若检测到孤立模块或未解析的仓库类调用,则以退出码 1 退出
python zmb_audit.py /path/to/repository --strict

# 输出结构化 JSON
python zmb_audit.py /path/to/repository --json

# 排除自定义目录
python zmb_audit.py /path/to/repository --exclude legacy_code experimental
      

示例输出


        ================================================================
[AUDIT] ZMB STANDALONE REPOSITORY AUDIT: /path/to/repo
================================================================
[*] Health Score:        97/100
[*] Total Python Files:  42
[*] Pre-Commit Guard:    PROTECTED
----------------------------------------------------------------
[OK] Zero Orphan Modules detected.
[OK] Zero unresolved repo-class attribute calls.
[!] Silent Exception Fallbacks (1):
   - app/fetcher.py (line 44: broad except returns empty default)
================================================================
      

即插即用的 GitHub Actions CI


        name: Agent Code Audit
on: [pull_request]
jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: python zmb_audit.py . --strict
      

完整报告与 CI 治理套件

获取 10 章实证事后剖析(144+ 自主循环)、Python 3.14 sys.monitoring 实时路径可达性追踪器、pre-commit 加密守卫,以及双臂基准测试入门套件:

获取 ZMB 失效模式报告与治理套件

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗