theory-auditor 0.14.2__tar.gz
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.
- theory_auditor-0.14.2/LICENSE +21 -0
- theory_auditor-0.14.2/PKG-INFO +269 -0
- theory_auditor-0.14.2/README.md +247 -0
- theory_auditor-0.14.2/pyproject.toml +54 -0
- theory_auditor-0.14.2/setup.cfg +4 -0
- theory_auditor-0.14.2/tests/test_auditor.py +327 -0
- theory_auditor-0.14.2/tests/test_badge.py +266 -0
- theory_auditor-0.14.2/tests/test_batch.py +247 -0
- theory_auditor-0.14.2/tests/test_certification.py +175 -0
- theory_auditor-0.14.2/tests/test_ci.py +172 -0
- theory_auditor-0.14.2/tests/test_cli_version.py +35 -0
- theory_auditor-0.14.2/tests/test_client_watcher.py +239 -0
- theory_auditor-0.14.2/tests/test_config.py +155 -0
- theory_auditor-0.14.2/tests/test_coverage.py +208 -0
- theory_auditor-0.14.2/tests/test_dashboard.py +390 -0
- theory_auditor-0.14.2/tests/test_diff.py +253 -0
- theory_auditor-0.14.2/tests/test_exception_paths.py +468 -0
- theory_auditor-0.14.2/tests/test_export.py +137 -0
- theory_auditor-0.14.2/tests/test_full_chain_e2e.py +435 -0
- theory_auditor-0.14.2/tests/test_i18n.py +64 -0
- theory_auditor-0.14.2/tests/test_inflation_detector.py +361 -0
- theory_auditor-0.14.2/tests/test_init_project.py +198 -0
- theory_auditor-0.14.2/tests/test_kill_tests.py +135 -0
- theory_auditor-0.14.2/tests/test_loaders.py +175 -0
- theory_auditor-0.14.2/tests/test_precommit.py +211 -0
- theory_auditor-0.14.2/tests/test_rule_validator.py +307 -0
- theory_auditor-0.14.2/tests/test_rules.py +487 -0
- theory_auditor-0.14.2/tests/test_rules_e2e.py +199 -0
- theory_auditor-0.14.2/tests/test_server.py +326 -0
- theory_auditor-0.14.2/tests/test_storage.py +224 -0
- theory_auditor-0.14.2/tests/test_trend.py +409 -0
- theory_auditor-0.14.2/theory_auditor/__init__.py +23 -0
- theory_auditor-0.14.2/theory_auditor/__main__.py +5 -0
- theory_auditor-0.14.2/theory_auditor/auditor.py +319 -0
- theory_auditor-0.14.2/theory_auditor/badge.py +289 -0
- theory_auditor-0.14.2/theory_auditor/batch.py +281 -0
- theory_auditor-0.14.2/theory_auditor/certification.py +302 -0
- theory_auditor-0.14.2/theory_auditor/ci.py +194 -0
- theory_auditor-0.14.2/theory_auditor/cli.py +1050 -0
- theory_auditor-0.14.2/theory_auditor/client.py +171 -0
- theory_auditor-0.14.2/theory_auditor/config.py +162 -0
- theory_auditor-0.14.2/theory_auditor/coverage.py +326 -0
- theory_auditor-0.14.2/theory_auditor/dashboard.py +644 -0
- theory_auditor-0.14.2/theory_auditor/diff.py +299 -0
- theory_auditor-0.14.2/theory_auditor/export.py +238 -0
- theory_auditor-0.14.2/theory_auditor/html_report.py +268 -0
- theory_auditor-0.14.2/theory_auditor/i18n.py +230 -0
- theory_auditor-0.14.2/theory_auditor/inflation_detector.py +478 -0
- theory_auditor-0.14.2/theory_auditor/init_project.py +263 -0
- theory_auditor-0.14.2/theory_auditor/loaders.py +261 -0
- theory_auditor-0.14.2/theory_auditor/precommit.py +286 -0
- theory_auditor-0.14.2/theory_auditor/py.typed +0 -0
- theory_auditor-0.14.2/theory_auditor/rule_validator.py +486 -0
- theory_auditor-0.14.2/theory_auditor/rules.py +471 -0
- theory_auditor-0.14.2/theory_auditor/server.py +346 -0
- theory_auditor-0.14.2/theory_auditor/storage.py +349 -0
- theory_auditor-0.14.2/theory_auditor/trend.py +429 -0
- theory_auditor-0.14.2/theory_auditor/watcher.py +208 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/PKG-INFO +269 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/SOURCES.txt +62 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/dependency_links.txt +1 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/entry_points.txt +2 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/requires.txt +7 -0
- theory_auditor-0.14.2/theory_auditor.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chronos Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: theory-auditor
|
|
3
|
+
Version: 0.14.2
|
|
4
|
+
Summary: Audit theory health: is your theory growing faster than its evidence?
|
|
5
|
+
Author-email: Chronos Lab <chronoslab@agent.qq.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sandmark78/theory-auditor
|
|
8
|
+
Project-URL: Issues, https://github.com/sandmark78/theory-auditor/issues
|
|
9
|
+
Keywords: science,research,audit,theory,falsifiability,reproducibility
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: yaml
|
|
17
|
+
Requires-Dist: pyyaml>=6.0; extra == "yaml"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pyyaml>=6.0; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# Theory Auditor 🔬
|
|
24
|
+
|
|
25
|
+
**你的理论增长速度是否超过了证据增长速度?**
|
|
26
|
+
|
|
27
|
+
一个用于审计研究项目健康状态的 Python 工具。核心原则:**任何理论都必须比自己的证据增长得更慢。**
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install theory-auditor
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
或从源码:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
git clone https://github.com/sandmark78/theory-auditor.git
|
|
39
|
+
cd theory-auditor
|
|
40
|
+
pip install -e .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 快速开始
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 审计单个项目
|
|
47
|
+
theory-auditor audit project.json
|
|
48
|
+
|
|
49
|
+
# 简短摘要(5行)
|
|
50
|
+
theory-auditor summary project.yaml
|
|
51
|
+
|
|
52
|
+
# 仅检查五条协议
|
|
53
|
+
theory-auditor check project.json
|
|
54
|
+
|
|
55
|
+
# 对比多个项目(支持JSON+YAML混合)
|
|
56
|
+
theory-auditor compare examples/
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 全部命令参考
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# 核心审计
|
|
63
|
+
theory-auditor audit project.json # 完整审计报告
|
|
64
|
+
theory-auditor audit project.yaml --stdin # 从 stdin 读取
|
|
65
|
+
theory-auditor summary project.json # 5行摘要
|
|
66
|
+
theory-auditor check project.json # 仅五条协议检查
|
|
67
|
+
|
|
68
|
+
# 对比与批量
|
|
69
|
+
theory-auditor compare examples/ # 对比目录下所有项目
|
|
70
|
+
theory-auditor batch examples/ # 批量审计+认证
|
|
71
|
+
theory-auditor batch examples/ -r # 递归子目录
|
|
72
|
+
|
|
73
|
+
# 膨胀检测与认证
|
|
74
|
+
theory-auditor detect project.json # AI辅助膨胀检测
|
|
75
|
+
theory-auditor certify project.json # 理论认证评估
|
|
76
|
+
|
|
77
|
+
# 分析工具
|
|
78
|
+
theory-auditor diff report1.json report2.json # 对比两份报告
|
|
79
|
+
theory-auditor coverage project.json # 审计覆盖率
|
|
80
|
+
theory-auditor trend --db audit_store.db # 趋势分析
|
|
81
|
+
theory-auditor rules project.json --default # 自定义规则检查
|
|
82
|
+
theory-auditor rules --validate rules.yaml # 验证规则文件
|
|
83
|
+
|
|
84
|
+
# CI/CD 集成
|
|
85
|
+
theory-auditor ci project.json --inflation-threshold 0.5 # 门禁模式
|
|
86
|
+
theory-auditor ci project.json -f junit # JUnit XML 输出
|
|
87
|
+
theory-auditor precommit install # Git hook
|
|
88
|
+
|
|
89
|
+
# 输出与可视化
|
|
90
|
+
theory-auditor export project.json -f markdown # 导出 Markdown/CSV
|
|
91
|
+
theory-auditor dashboard project.json # HTML 仪表盘
|
|
92
|
+
theory-auditor badge project.json # SVG 状态徽章
|
|
93
|
+
|
|
94
|
+
# 项目管理
|
|
95
|
+
theory-auditor init # 初始化项目配置
|
|
96
|
+
theory-auditor serve # 启动 Web API 服务器
|
|
97
|
+
theory-auditor watch project.json # 持续审计模式
|
|
98
|
+
|
|
99
|
+
# 通用选项
|
|
100
|
+
theory-auditor --version # 显示版本
|
|
101
|
+
theory-auditor --lang en audit ... # 英文输出
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Python API
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from theory_auditor import TheoryAuditor
|
|
108
|
+
import json
|
|
109
|
+
|
|
110
|
+
with open("project.json") as f:
|
|
111
|
+
data = json.load(f)
|
|
112
|
+
|
|
113
|
+
auditor = TheoryAuditor(data)
|
|
114
|
+
report = auditor.audit()
|
|
115
|
+
|
|
116
|
+
print(report["recommended_action"]) # CONTINUE / AUDIT / STOP
|
|
117
|
+
print(report["health_indicators"])
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 项目文件格式
|
|
121
|
+
|
|
122
|
+
支持 JSON 和 YAML 两种格式:
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
project_name: "My Theory"
|
|
126
|
+
start_date: "2020-01-01"
|
|
127
|
+
current_date: "2026-07-09"
|
|
128
|
+
parameters:
|
|
129
|
+
- name: "param_name"
|
|
130
|
+
provenance: "来源(第一性原理/经验拟合/推导)"
|
|
131
|
+
physical_meaning: "物理含义"
|
|
132
|
+
dependencies: []
|
|
133
|
+
added_date: "2020-01-01"
|
|
134
|
+
deleted_date: null
|
|
135
|
+
hypotheses:
|
|
136
|
+
- name: "假设名"
|
|
137
|
+
kill_test: "什么证据能杀死它"
|
|
138
|
+
status: "active"
|
|
139
|
+
evidence_count: 100
|
|
140
|
+
formula_count: 20
|
|
141
|
+
start_formula_count: 5
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 五条审计协议
|
|
145
|
+
|
|
146
|
+
| 协议 | 内容 | 为什么重要 |
|
|
147
|
+
|------|------|-----------|
|
|
148
|
+
| P1 Kill Test | 每个假设必须有死亡条件 | 无证伪=非科学 |
|
|
149
|
+
| P2 Provenance | 每个参数必须有来源 | 无来源=ad hoc |
|
|
150
|
+
| P3 Deletion | 删除比例 > 20% | 删除即进步 |
|
|
151
|
+
| P4 Archive | 失败路线必须归档 | 防止换名复活 |
|
|
152
|
+
| P5 No Resurrection | 禁止无新证据复活 | 防止僵尸理论 |
|
|
153
|
+
|
|
154
|
+
## 健康指标
|
|
155
|
+
|
|
156
|
+
- **理论膨胀指数** = 理论增长速度 / 证据增长速度(越低越好)
|
|
157
|
+
- **删除比例** = 已删除参数 / 总参数(>20% 为健康)
|
|
158
|
+
- **Compression Ratio** = (当前公式 - 初始公式) / 初始公式
|
|
159
|
+
|
|
160
|
+
## 推荐行动
|
|
161
|
+
|
|
162
|
+
- 🟢 **CONTINUE**: 膨胀 < 0.5 且压缩 < 0.3
|
|
163
|
+
- 🟡 **AUDIT**: 膨胀 0.5~0.8 或压缩 0.3~0.5
|
|
164
|
+
- 🔴 **STOP**: 膨胀 > 0.8 或压缩 > 0.5
|
|
165
|
+
|
|
166
|
+
## 自定义规则引擎 (v0.10.0+)
|
|
167
|
+
|
|
168
|
+
支持 YAML/JSON 定义自定义审计规则,以及 Python 插件扩展。
|
|
169
|
+
|
|
170
|
+
### CLI 用法
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# 使用内置默认规则
|
|
174
|
+
theory-auditor rules project.json --default
|
|
175
|
+
|
|
176
|
+
# 使用自定义规则文件
|
|
177
|
+
theory-auditor rules project.json --rules-file my_rules.yaml
|
|
178
|
+
|
|
179
|
+
# 加载插件目录
|
|
180
|
+
theory-auditor rules project.json --plugin-dir ./plugins/
|
|
181
|
+
|
|
182
|
+
# JSON 输出
|
|
183
|
+
theory-auditor rules project.json --default -f json
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 规则文件格式 (YAML)
|
|
187
|
+
|
|
188
|
+
```yaml
|
|
189
|
+
rules:
|
|
190
|
+
- id: R001
|
|
191
|
+
name: 规则名称
|
|
192
|
+
description: 规则描述
|
|
193
|
+
severity: warning # info / warning / error / critical
|
|
194
|
+
condition: "metrics.evidence_ratio < 2.0"
|
|
195
|
+
action: warn # warn / block / info
|
|
196
|
+
tags: [evidence]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 支持的条件表达式
|
|
200
|
+
|
|
201
|
+
| 表达式 | 含义 |
|
|
202
|
+
|--------|------|
|
|
203
|
+
| `field.path < N` | 字段值小于阈值时触发 |
|
|
204
|
+
| `field.path > N` | 字段值大于阈值时触发 |
|
|
205
|
+
| `field.path == N` | 字段值等于阈值时触发 |
|
|
206
|
+
| `field.path != N` | 字段值不等于阈值时触发 |
|
|
207
|
+
| `exists(field.path)` | 字段存在时触发 |
|
|
208
|
+
| `not_exists(field.path)` | 字段不存在时触发 |
|
|
209
|
+
|
|
210
|
+
### 编写插件
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
# plugins/my_plugin.py
|
|
214
|
+
from theory_auditor.rules import RuleResult, RuleStatus, Severity
|
|
215
|
+
|
|
216
|
+
class MyPlugin:
|
|
217
|
+
def check(self, audit_data):
|
|
218
|
+
# 你的检查逻辑
|
|
219
|
+
return RuleResult(
|
|
220
|
+
rule_id='MY_001',
|
|
221
|
+
rule_name='我的检查',
|
|
222
|
+
status=RuleStatus.PASSED,
|
|
223
|
+
severity=Severity.INFO,
|
|
224
|
+
message='检查通过',
|
|
225
|
+
execution_time_ms=0.1
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
def metadata(self):
|
|
229
|
+
return {'id': 'MY_001', 'name': 'My Plugin', 'version': '1.0'}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
插件要求:
|
|
233
|
+
- 实现 `check(audit_data) -> RuleResult` 方法
|
|
234
|
+
- 实现 `metadata() -> dict` 方法(必须包含 `id` 和 `name`)
|
|
235
|
+
- 文件名不能以 `_` 开头
|
|
236
|
+
|
|
237
|
+
## 开发
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# 安装开发依赖
|
|
241
|
+
pip install -e ".[dev]"
|
|
242
|
+
|
|
243
|
+
# 运行测试
|
|
244
|
+
make test # 快速测试
|
|
245
|
+
make test-verbose # 详细输出
|
|
246
|
+
|
|
247
|
+
# 代码质量
|
|
248
|
+
make lint # 代码检查(需安装 flake8)
|
|
249
|
+
make format # 代码格式化(需安装 black)
|
|
250
|
+
|
|
251
|
+
# 构建发布
|
|
252
|
+
make build # 构建分发包
|
|
253
|
+
make clean # 清理临时文件
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
或直接用命令:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
python3 -m pytest tests/ -v
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## 文档
|
|
263
|
+
|
|
264
|
+
- [设计理念](DESIGN.md) — 为什么需要这个工具
|
|
265
|
+
- [推广介绍](PROMOTION.md) — 完整介绍文章
|
|
266
|
+
|
|
267
|
+
## 许可证
|
|
268
|
+
|
|
269
|
+
MIT License. 详见 [LICENSE](LICENSE).
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Theory Auditor 🔬
|
|
2
|
+
|
|
3
|
+
**你的理论增长速度是否超过了证据增长速度?**
|
|
4
|
+
|
|
5
|
+
一个用于审计研究项目健康状态的 Python 工具。核心原则:**任何理论都必须比自己的证据增长得更慢。**
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install theory-auditor
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
或从源码:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/sandmark78/theory-auditor.git
|
|
17
|
+
cd theory-auditor
|
|
18
|
+
pip install -e .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# 审计单个项目
|
|
25
|
+
theory-auditor audit project.json
|
|
26
|
+
|
|
27
|
+
# 简短摘要(5行)
|
|
28
|
+
theory-auditor summary project.yaml
|
|
29
|
+
|
|
30
|
+
# 仅检查五条协议
|
|
31
|
+
theory-auditor check project.json
|
|
32
|
+
|
|
33
|
+
# 对比多个项目(支持JSON+YAML混合)
|
|
34
|
+
theory-auditor compare examples/
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 全部命令参考
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 核心审计
|
|
41
|
+
theory-auditor audit project.json # 完整审计报告
|
|
42
|
+
theory-auditor audit project.yaml --stdin # 从 stdin 读取
|
|
43
|
+
theory-auditor summary project.json # 5行摘要
|
|
44
|
+
theory-auditor check project.json # 仅五条协议检查
|
|
45
|
+
|
|
46
|
+
# 对比与批量
|
|
47
|
+
theory-auditor compare examples/ # 对比目录下所有项目
|
|
48
|
+
theory-auditor batch examples/ # 批量审计+认证
|
|
49
|
+
theory-auditor batch examples/ -r # 递归子目录
|
|
50
|
+
|
|
51
|
+
# 膨胀检测与认证
|
|
52
|
+
theory-auditor detect project.json # AI辅助膨胀检测
|
|
53
|
+
theory-auditor certify project.json # 理论认证评估
|
|
54
|
+
|
|
55
|
+
# 分析工具
|
|
56
|
+
theory-auditor diff report1.json report2.json # 对比两份报告
|
|
57
|
+
theory-auditor coverage project.json # 审计覆盖率
|
|
58
|
+
theory-auditor trend --db audit_store.db # 趋势分析
|
|
59
|
+
theory-auditor rules project.json --default # 自定义规则检查
|
|
60
|
+
theory-auditor rules --validate rules.yaml # 验证规则文件
|
|
61
|
+
|
|
62
|
+
# CI/CD 集成
|
|
63
|
+
theory-auditor ci project.json --inflation-threshold 0.5 # 门禁模式
|
|
64
|
+
theory-auditor ci project.json -f junit # JUnit XML 输出
|
|
65
|
+
theory-auditor precommit install # Git hook
|
|
66
|
+
|
|
67
|
+
# 输出与可视化
|
|
68
|
+
theory-auditor export project.json -f markdown # 导出 Markdown/CSV
|
|
69
|
+
theory-auditor dashboard project.json # HTML 仪表盘
|
|
70
|
+
theory-auditor badge project.json # SVG 状态徽章
|
|
71
|
+
|
|
72
|
+
# 项目管理
|
|
73
|
+
theory-auditor init # 初始化项目配置
|
|
74
|
+
theory-auditor serve # 启动 Web API 服务器
|
|
75
|
+
theory-auditor watch project.json # 持续审计模式
|
|
76
|
+
|
|
77
|
+
# 通用选项
|
|
78
|
+
theory-auditor --version # 显示版本
|
|
79
|
+
theory-auditor --lang en audit ... # 英文输出
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Python API
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from theory_auditor import TheoryAuditor
|
|
86
|
+
import json
|
|
87
|
+
|
|
88
|
+
with open("project.json") as f:
|
|
89
|
+
data = json.load(f)
|
|
90
|
+
|
|
91
|
+
auditor = TheoryAuditor(data)
|
|
92
|
+
report = auditor.audit()
|
|
93
|
+
|
|
94
|
+
print(report["recommended_action"]) # CONTINUE / AUDIT / STOP
|
|
95
|
+
print(report["health_indicators"])
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 项目文件格式
|
|
99
|
+
|
|
100
|
+
支持 JSON 和 YAML 两种格式:
|
|
101
|
+
|
|
102
|
+
```yaml
|
|
103
|
+
project_name: "My Theory"
|
|
104
|
+
start_date: "2020-01-01"
|
|
105
|
+
current_date: "2026-07-09"
|
|
106
|
+
parameters:
|
|
107
|
+
- name: "param_name"
|
|
108
|
+
provenance: "来源(第一性原理/经验拟合/推导)"
|
|
109
|
+
physical_meaning: "物理含义"
|
|
110
|
+
dependencies: []
|
|
111
|
+
added_date: "2020-01-01"
|
|
112
|
+
deleted_date: null
|
|
113
|
+
hypotheses:
|
|
114
|
+
- name: "假设名"
|
|
115
|
+
kill_test: "什么证据能杀死它"
|
|
116
|
+
status: "active"
|
|
117
|
+
evidence_count: 100
|
|
118
|
+
formula_count: 20
|
|
119
|
+
start_formula_count: 5
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 五条审计协议
|
|
123
|
+
|
|
124
|
+
| 协议 | 内容 | 为什么重要 |
|
|
125
|
+
|------|------|-----------|
|
|
126
|
+
| P1 Kill Test | 每个假设必须有死亡条件 | 无证伪=非科学 |
|
|
127
|
+
| P2 Provenance | 每个参数必须有来源 | 无来源=ad hoc |
|
|
128
|
+
| P3 Deletion | 删除比例 > 20% | 删除即进步 |
|
|
129
|
+
| P4 Archive | 失败路线必须归档 | 防止换名复活 |
|
|
130
|
+
| P5 No Resurrection | 禁止无新证据复活 | 防止僵尸理论 |
|
|
131
|
+
|
|
132
|
+
## 健康指标
|
|
133
|
+
|
|
134
|
+
- **理论膨胀指数** = 理论增长速度 / 证据增长速度(越低越好)
|
|
135
|
+
- **删除比例** = 已删除参数 / 总参数(>20% 为健康)
|
|
136
|
+
- **Compression Ratio** = (当前公式 - 初始公式) / 初始公式
|
|
137
|
+
|
|
138
|
+
## 推荐行动
|
|
139
|
+
|
|
140
|
+
- 🟢 **CONTINUE**: 膨胀 < 0.5 且压缩 < 0.3
|
|
141
|
+
- 🟡 **AUDIT**: 膨胀 0.5~0.8 或压缩 0.3~0.5
|
|
142
|
+
- 🔴 **STOP**: 膨胀 > 0.8 或压缩 > 0.5
|
|
143
|
+
|
|
144
|
+
## 自定义规则引擎 (v0.10.0+)
|
|
145
|
+
|
|
146
|
+
支持 YAML/JSON 定义自定义审计规则,以及 Python 插件扩展。
|
|
147
|
+
|
|
148
|
+
### CLI 用法
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# 使用内置默认规则
|
|
152
|
+
theory-auditor rules project.json --default
|
|
153
|
+
|
|
154
|
+
# 使用自定义规则文件
|
|
155
|
+
theory-auditor rules project.json --rules-file my_rules.yaml
|
|
156
|
+
|
|
157
|
+
# 加载插件目录
|
|
158
|
+
theory-auditor rules project.json --plugin-dir ./plugins/
|
|
159
|
+
|
|
160
|
+
# JSON 输出
|
|
161
|
+
theory-auditor rules project.json --default -f json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 规则文件格式 (YAML)
|
|
165
|
+
|
|
166
|
+
```yaml
|
|
167
|
+
rules:
|
|
168
|
+
- id: R001
|
|
169
|
+
name: 规则名称
|
|
170
|
+
description: 规则描述
|
|
171
|
+
severity: warning # info / warning / error / critical
|
|
172
|
+
condition: "metrics.evidence_ratio < 2.0"
|
|
173
|
+
action: warn # warn / block / info
|
|
174
|
+
tags: [evidence]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 支持的条件表达式
|
|
178
|
+
|
|
179
|
+
| 表达式 | 含义 |
|
|
180
|
+
|--------|------|
|
|
181
|
+
| `field.path < N` | 字段值小于阈值时触发 |
|
|
182
|
+
| `field.path > N` | 字段值大于阈值时触发 |
|
|
183
|
+
| `field.path == N` | 字段值等于阈值时触发 |
|
|
184
|
+
| `field.path != N` | 字段值不等于阈值时触发 |
|
|
185
|
+
| `exists(field.path)` | 字段存在时触发 |
|
|
186
|
+
| `not_exists(field.path)` | 字段不存在时触发 |
|
|
187
|
+
|
|
188
|
+
### 编写插件
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# plugins/my_plugin.py
|
|
192
|
+
from theory_auditor.rules import RuleResult, RuleStatus, Severity
|
|
193
|
+
|
|
194
|
+
class MyPlugin:
|
|
195
|
+
def check(self, audit_data):
|
|
196
|
+
# 你的检查逻辑
|
|
197
|
+
return RuleResult(
|
|
198
|
+
rule_id='MY_001',
|
|
199
|
+
rule_name='我的检查',
|
|
200
|
+
status=RuleStatus.PASSED,
|
|
201
|
+
severity=Severity.INFO,
|
|
202
|
+
message='检查通过',
|
|
203
|
+
execution_time_ms=0.1
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
def metadata(self):
|
|
207
|
+
return {'id': 'MY_001', 'name': 'My Plugin', 'version': '1.0'}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
插件要求:
|
|
211
|
+
- 实现 `check(audit_data) -> RuleResult` 方法
|
|
212
|
+
- 实现 `metadata() -> dict` 方法(必须包含 `id` 和 `name`)
|
|
213
|
+
- 文件名不能以 `_` 开头
|
|
214
|
+
|
|
215
|
+
## 开发
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# 安装开发依赖
|
|
219
|
+
pip install -e ".[dev]"
|
|
220
|
+
|
|
221
|
+
# 运行测试
|
|
222
|
+
make test # 快速测试
|
|
223
|
+
make test-verbose # 详细输出
|
|
224
|
+
|
|
225
|
+
# 代码质量
|
|
226
|
+
make lint # 代码检查(需安装 flake8)
|
|
227
|
+
make format # 代码格式化(需安装 black)
|
|
228
|
+
|
|
229
|
+
# 构建发布
|
|
230
|
+
make build # 构建分发包
|
|
231
|
+
make clean # 清理临时文件
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
或直接用命令:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
python3 -m pytest tests/ -v
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## 文档
|
|
241
|
+
|
|
242
|
+
- [设计理念](DESIGN.md) — 为什么需要这个工具
|
|
243
|
+
- [推广介绍](PROMOTION.md) — 完整介绍文章
|
|
244
|
+
|
|
245
|
+
## 许可证
|
|
246
|
+
|
|
247
|
+
MIT License. 详见 [LICENSE](LICENSE).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "theory-auditor"
|
|
7
|
+
version = "0.14.2"
|
|
8
|
+
description = "Audit theory health: is your theory growing faster than its evidence?"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Chronos Lab", email = "chronoslab@agent.qq.com"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["science", "research", "audit", "theory", "falsifiability", "reproducibility"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Scientific/Engineering",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/sandmark78/theory-auditor"
|
|
24
|
+
Issues = "https://github.com/sandmark78/theory-auditor/issues"
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
yaml = ["pyyaml>=6.0"]
|
|
28
|
+
dev = ["pytest>=7.0", "pyyaml>=6.0"]
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
theory-auditor = "theory_auditor.cli:main"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
include = ["theory_auditor*"]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.package-data]
|
|
37
|
+
theory_auditor = ["py.typed"]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
testpaths = ["tests"]
|
|
41
|
+
python_files = ["test_*.py"]
|
|
42
|
+
|
|
43
|
+
[tool.coverage.run]
|
|
44
|
+
source = ["theory_auditor"]
|
|
45
|
+
omit = ["tests/*", "examples/*"]
|
|
46
|
+
|
|
47
|
+
[tool.coverage.report]
|
|
48
|
+
show_missing = true
|
|
49
|
+
fail_under = 80
|
|
50
|
+
exclude_lines = [
|
|
51
|
+
"pragma: no cover",
|
|
52
|
+
"if __name__ == .__main__.",
|
|
53
|
+
"raise NotImplementedError",
|
|
54
|
+
]
|