PBH生态的第一个果实工具 — AI生成代码缺陷静态检查器
Project description
harness-lint
PBH 生态的第一个果实工具 — 专门检测 AI 生成代码中典型坏习惯的静态检查器。
harness-lint 不替代 Ruff / Pylint / Flake8。那些工具关心"代码是否规范";harness-lint 关心**"AI 是否在假装完成了任务"**。
快速开始
pip install -e ".[dev]"
make verify
检查任意目录:
harness-lint # 检查当前目录,terminal 格式
harness-lint src/ # 检查指定路径
harness-lint --format json # 输出 JSON
harness-lint --format summary # 输出单行摘要
harness-lint --strict # 把 Warning 也视为退出码 1
harness-lint --version
退出码:
0— 无 Error;--strict关闭时 Warning/Info 也返回 01— 有 Error;或--strict启用且有 Warning
内置规则
当前共 9 条规则,全部默认启用。
| ID | 名称 | 严重级别 | 说明 |
|---|---|---|---|
| HL001 | 禁止使用 eval() | Error | 检测 eval(...) / builtins.eval(...) 直接调用 |
| HL002 | 禁止使用 exec() | Error | 检测 exec(...) 直接调用 |
| HL003 | 禁止使用 os.system() | Error | 引导改用 subprocess.run() |
| HL004 | 硬编码密钥检测 | Error | 检测 password = "xxx" / password: str = "xxx" 等带类型标注或裸赋值的硬编码密钥 |
| HL201 | 函数体长度超限 | Warning | 默认阈值 50 行,支持普通和 async 函数 |
| HL202 | 假异常处理 | Warning | 检测 except: pass、except Exception: pass 等无效异常处理 |
| HL301 | 公共函数无 docstring | Info | 公共 API 缺少 docstring |
| HL401 | 重复违规模式检测 | Warning | 同一文件出现 3+ 次相同反模式时升级为模式性偏差 |
| HL402 | 协议一致性检查 | Warning | 公共函数参数/返回值缺少类型标注 |
每条规则的违规报告都包含完整的归因链三要素:
- 现象 (phenomenon):违规的具体表现
- 归因 (attribution):为什么这是 AI 缺陷
- 归属 (agente_ref):违反了 AGENTS.md 的哪一条款
开发命令
| 命令 | 说明 |
|---|---|
make verify |
lint + 测试 + 覆盖率(提交前必须通过) |
make test |
仅运行测试 |
make lint |
仅运行代码风格检查 |
make fix |
自动修复风格问题 |
项目结构
harness-lint/
├── src/harness_lint/
│ ├── cli.py # CLI 入口(typer)
│ ├── checker.py # 文件遍历 + 规则调度
│ ├── reporter.py # terminal / json / summary 三种输出
│ ├── accumulator.py # 模式性偏差累积(重复违规升级)
│ ├── attribution.py # 归因链运行时校验
│ ├── pbh_adapter.py # 读取 .harness/progress.json
│ ├── degradation.py # 退化代价可见化
│ └── rules/
│ ├── base.py # Rule / Violation 抽象基类
│ └── hl0*.py / hl2*.py / hl3*.py / hl4*.py
├── tests/ # 单元测试 + 集成测试 + 自举测试
├── docs/ # 设计文档 / 项目地图 / ADR
├── tasks/ # 任务拆解(Spec Coding 容器)
├── .harness/ # PBH 阶段状态追踪
├── AGENTS.md # AI 协作协议
├── Makefile
└── pyproject.toml
AI 协作
本项目遵循 PBH 协议。AI 助手请阅读 AGENTS.md 了解项目规则和工作准则。深入架构请参考 docs/context.md,规则设计原则参考 docs/design.md。
生态关联
| 项目 | 说明 |
|---|---|
| Project Bootstrap Harness (PBH) | AI 辅助项目启动框架,定义了阶段感知、归因锚定等核心协议 |
| Harness Agent | PBH 协议的 AI Agent 运行时,负责执行计划、管理会话生命周期 |
harness-lint 是 PBH 生态中的质量守护工具,在 Agent 执行过程中对生成的代码进行静态检查。
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file harness_lint-0.2.0.tar.gz.
File metadata
- Download URL: harness_lint-0.2.0.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75beee6801bc443bf589c15b7e31b6bb7a9a6a9d2030ba34cb8c45966a26cd55
|
|
| MD5 |
270e796b23af30a6e97ff176f586a7ca
|
|
| BLAKE2b-256 |
d15ec08dce055331cd559114fc19ad4cce5f88cbc644f0f1f93fe5e856487854
|
Provenance
The following attestation bundles were made for harness_lint-0.2.0.tar.gz:
Publisher:
publish.yml on renjianguojinqianfan/harness-lint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
harness_lint-0.2.0.tar.gz -
Subject digest:
75beee6801bc443bf589c15b7e31b6bb7a9a6a9d2030ba34cb8c45966a26cd55 - Sigstore transparency entry: 1823868550
- Sigstore integration time:
-
Permalink:
renjianguojinqianfan/harness-lint@d26dc2b0d4ffc5123ee875b6c3599d3f06636ddb -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/renjianguojinqianfan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d26dc2b0d4ffc5123ee875b6c3599d3f06636ddb -
Trigger Event:
push
-
Statement type:
File details
Details for the file harness_lint-0.2.0-py3-none-any.whl.
File metadata
- Download URL: harness_lint-0.2.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15d38ff7a7e7e92c8ce9418b71a3095e1cb65313b41b474c93aeba4a8a3136e0
|
|
| MD5 |
b1f97a94abcfe3c53b0b7fe0c8ed2d18
|
|
| BLAKE2b-256 |
2dc3fb83770febb81366c058ca6ebcf664230750b081a7c68c9ac61567c8f460
|
Provenance
The following attestation bundles were made for harness_lint-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on renjianguojinqianfan/harness-lint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
harness_lint-0.2.0-py3-none-any.whl -
Subject digest:
15d38ff7a7e7e92c8ce9418b71a3095e1cb65313b41b474c93aeba4a8a3136e0 - Sigstore transparency entry: 1823868766
- Sigstore integration time:
-
Permalink:
renjianguojinqianfan/harness-lint@d26dc2b0d4ffc5123ee875b6c3599d3f06636ddb -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/renjianguojinqianfan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d26dc2b0d4ffc5123ee875b6c3599d3f06636ddb -
Trigger Event:
push
-
Statement type: