vibe-engine 0.1.0__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.
- vibe_engine-0.1.0/.gitignore +13 -0
- vibe_engine-0.1.0/LICENSE +21 -0
- vibe_engine-0.1.0/PKG-INFO +127 -0
- vibe_engine-0.1.0/README.md +105 -0
- vibe_engine-0.1.0/pyproject.toml +42 -0
- vibe_engine-0.1.0/src/vibe_engine/__init__.py +1 -0
- vibe_engine-0.1.0/src/vibe_engine/agents.py +190 -0
- vibe_engine-0.1.0/src/vibe_engine/architecture.py +213 -0
- vibe_engine-0.1.0/src/vibe_engine/astgrep.py +151 -0
- vibe_engine-0.1.0/src/vibe_engine/baseline.py +121 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/__init__.py +0 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/banned.py +250 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/boundaries.py +53 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/comments.py +131 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/doclinks.py +155 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/jscomments.py +110 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/mypy.py +125 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/ruff.py +59 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/shared.py +36 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/shellcheck.py +52 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/shellcomments.py +99 -0
- vibe_engine-0.1.0/src/vibe_engine/checks/strings.py +74 -0
- vibe_engine-0.1.0/src/vibe_engine/cli.py +501 -0
- vibe_engine-0.1.0/src/vibe_engine/codex_status.py +81 -0
- vibe_engine-0.1.0/src/vibe_engine/config.py +734 -0
- vibe_engine-0.1.0/src/vibe_engine/detect.py +231 -0
- vibe_engine-0.1.0/src/vibe_engine/doctor.py +226 -0
- vibe_engine-0.1.0/src/vibe_engine/engine_dir.py +17 -0
- vibe_engine-0.1.0/src/vibe_engine/events.py +88 -0
- vibe_engine-0.1.0/src/vibe_engine/evidence.py +145 -0
- vibe_engine-0.1.0/src/vibe_engine/export.py +235 -0
- vibe_engine-0.1.0/src/vibe_engine/files.py +124 -0
- vibe_engine-0.1.0/src/vibe_engine/fixing.py +180 -0
- vibe_engine-0.1.0/src/vibe_engine/freeze.py +42 -0
- vibe_engine-0.1.0/src/vibe_engine/guard.py +196 -0
- vibe_engine-0.1.0/src/vibe_engine/hook.py +509 -0
- vibe_engine-0.1.0/src/vibe_engine/jsresolve.py +182 -0
- vibe_engine-0.1.0/src/vibe_engine/languages/__init__.py +19 -0
- vibe_engine-0.1.0/src/vibe_engine/languages/base.py +27 -0
- vibe_engine-0.1.0/src/vibe_engine/languages/js.py +131 -0
- vibe_engine-0.1.0/src/vibe_engine/languages/python.py +70 -0
- vibe_engine-0.1.0/src/vibe_engine/languages/shell.py +45 -0
- vibe_engine-0.1.0/src/vibe_engine/loosening.py +206 -0
- vibe_engine-0.1.0/src/vibe_engine/model.py +37 -0
- vibe_engine-0.1.0/src/vibe_engine/modules.py +34 -0
- vibe_engine-0.1.0/src/vibe_engine/onboarding.py +136 -0
- vibe_engine-0.1.0/src/vibe_engine/presets/test-integrity.toml +55 -0
- vibe_engine-0.1.0/src/vibe_engine/report.py +50 -0
- vibe_engine-0.1.0/src/vibe_engine/rules_edit.py +195 -0
- vibe_engine-0.1.0/src/vibe_engine/rules_table.py +122 -0
- vibe_engine-0.1.0/src/vibe_engine/rules_verify.py +125 -0
- vibe_engine-0.1.0/src/vibe_engine/runner.py +276 -0
- vibe_engine-0.1.0/src/vibe_engine/scaffold.py +232 -0
- vibe_engine-0.1.0/src/vibe_engine/staged.py +184 -0
- vibe_engine-0.1.0/src/vibe_engine/statefiles.py +50 -0
- vibe_engine-0.1.0/src/vibe_engine/stats.py +236 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/engine.toml +53 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/feature-map.md +26 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/report.html +796 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/skills/correction-to-rule/SKILL.md +104 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/skills/verify-feature/SKILL.md +30 -0
- vibe_engine-0.1.0/src/vibe_engine/templates/workflow.yml +28 -0
- vibe_engine-0.1.0/src/vibe_engine/touch.py +139 -0
- vibe_engine-0.1.0/src/vibe_engine/trend.py +53 -0
- vibe_engine-0.1.0/src/vibe_engine/verifying.py +84 -0
- vibe_engine-0.1.0/src/vibe_engine/webreport.py +51 -0
- vibe_engine-0.1.0/tests/conftest.py +62 -0
- vibe_engine-0.1.0/tests/test_agents.py +503 -0
- vibe_engine-0.1.0/tests/test_baseline.py +120 -0
- vibe_engine-0.1.0/tests/test_coverage_gaps.py +203 -0
- vibe_engine-0.1.0/tests/test_detect.py +115 -0
- vibe_engine-0.1.0/tests/test_development_regressions.py +354 -0
- vibe_engine-0.1.0/tests/test_doclinks.py +130 -0
- vibe_engine-0.1.0/tests/test_doctor.py +88 -0
- vibe_engine-0.1.0/tests/test_export.py +164 -0
- vibe_engine-0.1.0/tests/test_fixing.py +59 -0
- vibe_engine-0.1.0/tests/test_gates.py +418 -0
- vibe_engine-0.1.0/tests/test_js.py +385 -0
- vibe_engine-0.1.0/tests/test_languages.py +97 -0
- vibe_engine-0.1.0/tests/test_loop.py +153 -0
- vibe_engine-0.1.0/tests/test_loosening.py +229 -0
- vibe_engine-0.1.0/tests/test_mypy.py +219 -0
- vibe_engine-0.1.0/tests/test_review_fixes.py +328 -0
- vibe_engine-0.1.0/tests/test_review_round2.py +319 -0
- vibe_engine-0.1.0/tests/test_review_round3.py +659 -0
- vibe_engine-0.1.0/tests/test_rules.py +377 -0
- vibe_engine-0.1.0/tests/test_rules_proof.py +134 -0
- vibe_engine-0.1.0/tests/test_shared_rules.py +118 -0
- vibe_engine-0.1.0/tests/test_shell.py +316 -0
- vibe_engine-0.1.0/tests/test_single_file.py +146 -0
- vibe_engine-0.1.0/tests/test_verify_layer.py +168 -0
- vibe_engine-0.1.0/tests/test_webreport.py +137 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 code-engine contributors
|
|
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,127 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vibe-engine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 可复用的检查引擎:让 AI 写的代码在每个仓里都过同一套确定性检查
|
|
5
|
+
Project-URL: Repository, https://github.com/william-swl/vibe-engine
|
|
6
|
+
Project-URL: Documentation, https://github.com/william-swl/vibe-engine/tree/main/docs-site
|
|
7
|
+
Project-URL: Issues, https://github.com/william-swl/vibe-engine/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: ast-grep-cli>=0.51
|
|
12
|
+
Requires-Dist: ruff>=0.5
|
|
13
|
+
Requires-Dist: shellcheck-py>=0.10
|
|
14
|
+
Requires-Dist: tomli>=2; python_version < '3.11'
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: mypy==2.4.1; (python_version >= '3.10') and extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
18
|
+
Provides-Extra: docs
|
|
19
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
20
|
+
Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# vibe-engine
|
|
24
|
+
|
|
25
|
+
**让 AI 写的代码,在每个仓里都过同一套确定性检查。**
|
|
26
|
+
|
|
27
|
+
每个仓只放一份 `engine.toml`。AI Agent 收工、本地 Git 提交、远端 CI 三道关卡运行同一套规则与命令。核心目标是把“纠正 AI”变成确定性门禁,而不是往 `AGENTS.md` 里继续堆自然语言提醒。
|
|
28
|
+
|
|
29
|
+
支持 **Python、Shell、JS / TS**。默认只拦“这一轮新写出来的、会出错的问题”;可安全修复的交给 `vibe-engine fix`;Python 项目可启用原生 `[mypy]`,把类型错误记入基线并拦截新增。
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
你纠正 AI 一次 → 固化为规则(engine.toml)→ 收工 · 提交 · CI 三道关卡同一套规则
|
|
33
|
+
→ 违规被拦,报错写明 why + instead → AI 当场改对
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 它有什么不同
|
|
37
|
+
|
|
38
|
+
- **旧仓无痛接入**:先把存量违规按内容指纹记成基线,之后只拦新增,而且修掉存量自动收紧(只减不增)。
|
|
39
|
+
- **报错会教人怎么改**:每条自定义规则强制写 `why`(为什么禁)和 `instead`(改用什么),还能给 Ruff / ShellCheck / Mypy 外挂本仓改法。
|
|
40
|
+
- **防 AI 走捷径**:禁止 `# noqa` / `@ts-ignore` / `# pragma: no cover` 等就地屏蔽;放宽检查必须写 `[[loosened]]` 留痕,CI 的 `guard` 把关。
|
|
41
|
+
- **证明真的跑通了**:核心功能可用 `verify = true` 绑定文件内容哈希,改一个字节就必须重新跑通验证。
|
|
42
|
+
|
|
43
|
+
## 安装
|
|
44
|
+
|
|
45
|
+
支持 macOS 和 Linux。Windows 不受支持。引擎需要 Python 3.9 或更新版本。
|
|
46
|
+
|
|
47
|
+
从 PyPI 安装稳定版:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python -m pip install vibe-engine
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
从源码安装或参与开发:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/william-swl/vibe-engine.git
|
|
57
|
+
cd vibe-engine
|
|
58
|
+
python3 -m venv .venv
|
|
59
|
+
.venv/bin/pip install -e ".[dev]"
|
|
60
|
+
ln -s "$PWD/.venv/bin/vibe-engine" ~/.local/bin/vibe-engine
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
建议用比你仓里代码更新的 Python 建这个虚拟环境,原因和做法见 [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md)。
|
|
64
|
+
|
|
65
|
+
## 在一个仓里接入
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cd 你的仓
|
|
69
|
+
vibe-engine init --baseline
|
|
70
|
+
vibe-engine commands --apply
|
|
71
|
+
vibe-engine doctor
|
|
72
|
+
vibe-engine check
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`vibe-engine commands` 即使不带 `--apply` 也会执行探测到的脚本,请只在信任的仓库中运行。`--apply` 会把通过验证的命令写入 `engine.toml`。
|
|
76
|
+
|
|
77
|
+
使用 GitHub Actions 时,显式指定 CI 安装的版本:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
vibe-engine init --install-spec 'vibe-engine==0.1.0'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
提交生成的 `.github/workflows/vibe-engine.yml`。如果已接入测试或类型检查,在工作流的检查步骤前安装项目依赖。详见 [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md)。
|
|
84
|
+
|
|
85
|
+
## 开发本仓
|
|
86
|
+
|
|
87
|
+
CI 使用 Python 3.9 和 3.13 运行测试,并用 3.13 运行完整门禁。建议在本地用 3.13 创建并激活虚拟环境,让测试、Mypy 和命令行工具共享同一套依赖。
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python3.13 -m venv .venv
|
|
91
|
+
. .venv/bin/activate
|
|
92
|
+
python -m pip install -e ".[dev,docs]"
|
|
93
|
+
python -m pytest -q
|
|
94
|
+
vibe-engine check --gate ci
|
|
95
|
+
mkdocs build --strict
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`[dev]` 在 Python 3.10 及以上安装本仓锁定版本的 Mypy。已有多个虚拟环境时,先用 `.venv/bin/python -m mypy --version` 确认开发依赖装在 `.venv` 里,避免不知情地借用 `venv` 里的 Mypy。完整门禁会检查本仓 Markdown 的文件链接,严格构建还会检查 MkDocs 的导航和站内引用。
|
|
99
|
+
|
|
100
|
+
## 文档导航
|
|
101
|
+
|
|
102
|
+
完整文档在 `docs-site/`,用 MkDocs Material 构建:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
.venv/bin/pip install -e ".[docs]"
|
|
106
|
+
.venv/bin/mkdocs serve
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
然后打开 <http://127.0.0.1:8000>,也可以直接阅读源文件:
|
|
110
|
+
|
|
111
|
+
| 想了解 | 看这里 |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| 价值点、上下游工具关系、负责/不负责什么 | [价值点与上下游关系](https://github.com/william-swl/vibe-engine/blob/main/docs-site/overview/why-and-position.md) |
|
|
114
|
+
| 底层怎么实现(语言包、基线、快照、哈希) | [底层实现原理](https://github.com/william-swl/vibe-engine/blob/main/docs-site/overview/architecture.md) |
|
|
115
|
+
| 安装与 5 分钟快速接入 | [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md) |
|
|
116
|
+
| 规则写不全怎么办、`AGENTS.md` 怎么瘦身 | [旧仓落地与 AGENTS.md 瘦身](https://github.com/william-swl/vibe-engine/blob/main/docs-site/onboarding-workflow.md) |
|
|
117
|
+
| 收工 / 提交 / CI 三道关卡分别做什么 | [三道关卡](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/gates.md) |
|
|
118
|
+
| 旧仓基线自动收紧与 `guard` | [存量基线](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/baseline.md) |
|
|
119
|
+
| `banned` / `boundary` / `guidance` / `command` 区别与自证 | [规则体系与报错](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/rules.md) |
|
|
120
|
+
| 屏蔽禁令、注释禁令与三语言 Docstring | [屏蔽、注释与 Docstring](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/comments-and-suppressions.md) |
|
|
121
|
+
| `vibe-engine fix` 机制与为什么 `autofix` 默认关 | [自动修复与 Linter 边界](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/autofix-and-linters.md) |
|
|
122
|
+
| 类型检查、空值防御与单元测试约束 | [类型检查与单元测试](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/types-and-testing.md) |
|
|
123
|
+
| 怎么确认工具按预期生效、意愿冲突与故障排查 | [生效验证与排查](https://github.com/william-swl/vibe-engine/blob/main/docs-site/troubleshooting/verify-it-works.md) |
|
|
124
|
+
| Python / Shell / JS-TS 实现细节总对照 | [三语言实现总矩阵](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/language-matrix.md) |
|
|
125
|
+
| `engine.toml` 全字段与 TOML 语法说明 | [engine.toml 配置参考](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/engine-toml.md) |
|
|
126
|
+
| 所有 CLI 命令一览 | [CLI 命令参考](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/commands.md) |
|
|
127
|
+
| 现在做不到什么 | [已知局限](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/limitations.md) |
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# vibe-engine
|
|
2
|
+
|
|
3
|
+
**让 AI 写的代码,在每个仓里都过同一套确定性检查。**
|
|
4
|
+
|
|
5
|
+
每个仓只放一份 `engine.toml`。AI Agent 收工、本地 Git 提交、远端 CI 三道关卡运行同一套规则与命令。核心目标是把“纠正 AI”变成确定性门禁,而不是往 `AGENTS.md` 里继续堆自然语言提醒。
|
|
6
|
+
|
|
7
|
+
支持 **Python、Shell、JS / TS**。默认只拦“这一轮新写出来的、会出错的问题”;可安全修复的交给 `vibe-engine fix`;Python 项目可启用原生 `[mypy]`,把类型错误记入基线并拦截新增。
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
你纠正 AI 一次 → 固化为规则(engine.toml)→ 收工 · 提交 · CI 三道关卡同一套规则
|
|
11
|
+
→ 违规被拦,报错写明 why + instead → AI 当场改对
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 它有什么不同
|
|
15
|
+
|
|
16
|
+
- **旧仓无痛接入**:先把存量违规按内容指纹记成基线,之后只拦新增,而且修掉存量自动收紧(只减不增)。
|
|
17
|
+
- **报错会教人怎么改**:每条自定义规则强制写 `why`(为什么禁)和 `instead`(改用什么),还能给 Ruff / ShellCheck / Mypy 外挂本仓改法。
|
|
18
|
+
- **防 AI 走捷径**:禁止 `# noqa` / `@ts-ignore` / `# pragma: no cover` 等就地屏蔽;放宽检查必须写 `[[loosened]]` 留痕,CI 的 `guard` 把关。
|
|
19
|
+
- **证明真的跑通了**:核心功能可用 `verify = true` 绑定文件内容哈希,改一个字节就必须重新跑通验证。
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
支持 macOS 和 Linux。Windows 不受支持。引擎需要 Python 3.9 或更新版本。
|
|
24
|
+
|
|
25
|
+
从 PyPI 安装稳定版:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m pip install vibe-engine
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
从源码安装或参与开发:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/william-swl/vibe-engine.git
|
|
35
|
+
cd vibe-engine
|
|
36
|
+
python3 -m venv .venv
|
|
37
|
+
.venv/bin/pip install -e ".[dev]"
|
|
38
|
+
ln -s "$PWD/.venv/bin/vibe-engine" ~/.local/bin/vibe-engine
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
建议用比你仓里代码更新的 Python 建这个虚拟环境,原因和做法见 [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md)。
|
|
42
|
+
|
|
43
|
+
## 在一个仓里接入
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
cd 你的仓
|
|
47
|
+
vibe-engine init --baseline
|
|
48
|
+
vibe-engine commands --apply
|
|
49
|
+
vibe-engine doctor
|
|
50
|
+
vibe-engine check
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`vibe-engine commands` 即使不带 `--apply` 也会执行探测到的脚本,请只在信任的仓库中运行。`--apply` 会把通过验证的命令写入 `engine.toml`。
|
|
54
|
+
|
|
55
|
+
使用 GitHub Actions 时,显式指定 CI 安装的版本:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
vibe-engine init --install-spec 'vibe-engine==0.1.0'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
提交生成的 `.github/workflows/vibe-engine.yml`。如果已接入测试或类型检查,在工作流的检查步骤前安装项目依赖。详见 [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md)。
|
|
62
|
+
|
|
63
|
+
## 开发本仓
|
|
64
|
+
|
|
65
|
+
CI 使用 Python 3.9 和 3.13 运行测试,并用 3.13 运行完整门禁。建议在本地用 3.13 创建并激活虚拟环境,让测试、Mypy 和命令行工具共享同一套依赖。
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python3.13 -m venv .venv
|
|
69
|
+
. .venv/bin/activate
|
|
70
|
+
python -m pip install -e ".[dev,docs]"
|
|
71
|
+
python -m pytest -q
|
|
72
|
+
vibe-engine check --gate ci
|
|
73
|
+
mkdocs build --strict
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`[dev]` 在 Python 3.10 及以上安装本仓锁定版本的 Mypy。已有多个虚拟环境时,先用 `.venv/bin/python -m mypy --version` 确认开发依赖装在 `.venv` 里,避免不知情地借用 `venv` 里的 Mypy。完整门禁会检查本仓 Markdown 的文件链接,严格构建还会检查 MkDocs 的导航和站内引用。
|
|
77
|
+
|
|
78
|
+
## 文档导航
|
|
79
|
+
|
|
80
|
+
完整文档在 `docs-site/`,用 MkDocs Material 构建:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
.venv/bin/pip install -e ".[docs]"
|
|
84
|
+
.venv/bin/mkdocs serve
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
然后打开 <http://127.0.0.1:8000>,也可以直接阅读源文件:
|
|
88
|
+
|
|
89
|
+
| 想了解 | 看这里 |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| 价值点、上下游工具关系、负责/不负责什么 | [价值点与上下游关系](https://github.com/william-swl/vibe-engine/blob/main/docs-site/overview/why-and-position.md) |
|
|
92
|
+
| 底层怎么实现(语言包、基线、快照、哈希) | [底层实现原理](https://github.com/william-swl/vibe-engine/blob/main/docs-site/overview/architecture.md) |
|
|
93
|
+
| 安装与 5 分钟快速接入 | [快速开始](https://github.com/william-swl/vibe-engine/blob/main/docs-site/getting-started.md) |
|
|
94
|
+
| 规则写不全怎么办、`AGENTS.md` 怎么瘦身 | [旧仓落地与 AGENTS.md 瘦身](https://github.com/william-swl/vibe-engine/blob/main/docs-site/onboarding-workflow.md) |
|
|
95
|
+
| 收工 / 提交 / CI 三道关卡分别做什么 | [三道关卡](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/gates.md) |
|
|
96
|
+
| 旧仓基线自动收紧与 `guard` | [存量基线](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/baseline.md) |
|
|
97
|
+
| `banned` / `boundary` / `guidance` / `command` 区别与自证 | [规则体系与报错](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/rules.md) |
|
|
98
|
+
| 屏蔽禁令、注释禁令与三语言 Docstring | [屏蔽、注释与 Docstring](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/comments-and-suppressions.md) |
|
|
99
|
+
| `vibe-engine fix` 机制与为什么 `autofix` 默认关 | [自动修复与 Linter 边界](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/autofix-and-linters.md) |
|
|
100
|
+
| 类型检查、空值防御与单元测试约束 | [类型检查与单元测试](https://github.com/william-swl/vibe-engine/blob/main/docs-site/concepts/types-and-testing.md) |
|
|
101
|
+
| 怎么确认工具按预期生效、意愿冲突与故障排查 | [生效验证与排查](https://github.com/william-swl/vibe-engine/blob/main/docs-site/troubleshooting/verify-it-works.md) |
|
|
102
|
+
| Python / Shell / JS-TS 实现细节总对照 | [三语言实现总矩阵](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/language-matrix.md) |
|
|
103
|
+
| `engine.toml` 全字段与 TOML 语法说明 | [engine.toml 配置参考](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/engine-toml.md) |
|
|
104
|
+
| 所有 CLI 命令一览 | [CLI 命令参考](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/commands.md) |
|
|
105
|
+
| 现在做不到什么 | [已知局限](https://github.com/william-swl/vibe-engine/blob/main/docs-site/reference/limitations.md) |
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vibe-engine"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "可复用的检查引擎:让 AI 写的代码在每个仓里都过同一套确定性检查"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"ruff>=0.5",
|
|
15
|
+
"ast-grep-cli>=0.51",
|
|
16
|
+
"shellcheck-py>=0.10",
|
|
17
|
+
"tomli>=2; python_version < '3.11'",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
dev = ["pytest>=8", "mypy==2.4.1; python_version >= '3.10'"]
|
|
22
|
+
docs = ["mkdocs>=1.6,<2", "mkdocs-material>=9.5"]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Repository = "https://github.com/william-swl/vibe-engine"
|
|
26
|
+
Documentation = "https://github.com/william-swl/vibe-engine/tree/main/docs-site"
|
|
27
|
+
Issues = "https://github.com/william-swl/vibe-engine/issues"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
vibe-engine = "vibe_engine.cli:main"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/vibe_engine"]
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.sdist]
|
|
36
|
+
only-include = ["src/vibe_engine", "tests", "README.md", "LICENSE"]
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 120
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shlex
|
|
6
|
+
import shutil
|
|
7
|
+
import sys
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from .files import write_atomic
|
|
12
|
+
|
|
13
|
+
CLAUDE = "claude"
|
|
14
|
+
CODEX = "codex"
|
|
15
|
+
AGENTS = (CLAUDE, CODEX)
|
|
16
|
+
BARE_COMMAND = "vibe-engine hook stop"
|
|
17
|
+
BARE_PROMPT_COMMAND = "vibe-engine hook prompt"
|
|
18
|
+
BARE_SESSION_COMMAND = "vibe-engine hook session"
|
|
19
|
+
BARE_EDIT_COMMAND = "vibe-engine hook edit"
|
|
20
|
+
EDIT_MATCHER = "Write|Edit|MultiEdit"
|
|
21
|
+
EDIT_AGENTS = (CLAUDE,)
|
|
22
|
+
HOOK_WORDS = {
|
|
23
|
+
"Stop": "hook stop",
|
|
24
|
+
"UserPromptSubmit": "hook prompt",
|
|
25
|
+
"SessionStart": "hook session",
|
|
26
|
+
"PostToolUse": "hook edit",
|
|
27
|
+
"PreToolUse": "hook skill",
|
|
28
|
+
"UserPromptExpansion": "hook skill",
|
|
29
|
+
}
|
|
30
|
+
PROMPT_TIMEOUT = 30
|
|
31
|
+
TIMEOUT = 120
|
|
32
|
+
STATUS = "vibe-engine 检查"
|
|
33
|
+
MINIMAL_PATH = "/usr/bin:/bin:/usr/sbin:/sbin"
|
|
34
|
+
SKILL_DIRS = {CLAUDE: ".claude/skills", CODEX: ".agents/skills"}
|
|
35
|
+
SKILL_NAMES = ("correction-to-rule", "verify-feature")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def skill_path(agent: str, name: str) -> str:
|
|
39
|
+
return f"{SKILL_DIRS[agent]}/{name}/SKILL.md"
|
|
40
|
+
|
|
41
|
+
HOOK_FILES = {CLAUDE: ".claude/settings.json", CODEX: ".codex/hooks.json"}
|
|
42
|
+
TRUST_NOTE = "Codex 只在受信任的项目里读 .codex/hooks.json,并且要先审查钩子:CLI 里运行 /hooks,桌面应用在 设置 > 钩子。"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class HookState:
|
|
47
|
+
present: bool
|
|
48
|
+
command: str = ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def parse_agents(value: str | None) -> tuple[str, ...] | None:
|
|
52
|
+
if not value:
|
|
53
|
+
return None
|
|
54
|
+
names = tuple(part.strip() for part in value.split(",") if part.strip())
|
|
55
|
+
unknown = sorted(set(names) - set(AGENTS))
|
|
56
|
+
if unknown or not names:
|
|
57
|
+
raise ValueError(f"--agents 只能取 {', '.join(AGENTS)},收到:{value}")
|
|
58
|
+
return tuple(dict.fromkeys(names))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def detect_agents(root: Path) -> tuple[str, ...]:
|
|
62
|
+
found = []
|
|
63
|
+
if (root / ".claude").exists() or (root / "CLAUDE.md").exists():
|
|
64
|
+
found.append(CLAUDE)
|
|
65
|
+
if (root / ".codex").exists() or (root / ".agents").exists() or (root / "AGENTS.md").exists():
|
|
66
|
+
found.append(CODEX)
|
|
67
|
+
return tuple(found) or AGENTS
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def user_hook_file(agent: str) -> Path:
|
|
71
|
+
if agent == CLAUDE:
|
|
72
|
+
return Path(os.environ.get("CLAUDE_CONFIG_DIR") or Path.home() / ".claude") / "settings.json"
|
|
73
|
+
return Path(os.environ.get("CODEX_HOME") or Path.home() / ".codex") / "hooks.json"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def command_source() -> str:
|
|
77
|
+
claude = os.environ.get("CLAUDE_CODE_CHILD_SESSION") == "1" or os.environ.get("CLAUDECODE") == "1"
|
|
78
|
+
codex = bool(os.environ.get("CODEX_THREAD_ID"))
|
|
79
|
+
if claude == codex:
|
|
80
|
+
return "unknown"
|
|
81
|
+
return CLAUDE if claude else CODEX
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def absolute_command(event: str = "stop") -> str:
|
|
85
|
+
stable = Path.home() / ".local" / "bin" / "vibe-engine"
|
|
86
|
+
found = shutil.which("vibe-engine")
|
|
87
|
+
executable = str(stable) if stable.exists() else found
|
|
88
|
+
if executable:
|
|
89
|
+
return f"{shlex.quote(executable)} hook {event}"
|
|
90
|
+
return f"{shlex.quote(sys.executable)} -m vibe_engine.cli hook {event}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _is_ours(command: object, event: str = "Stop") -> bool:
|
|
94
|
+
word = HOOK_WORDS[event]
|
|
95
|
+
return isinstance(command, str) and ("vibe-engine" in command or "-m vibe_engine.cli" in command) and word in command
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _load(path: Path) -> dict | None:
|
|
99
|
+
if not path.exists():
|
|
100
|
+
return {}
|
|
101
|
+
try:
|
|
102
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
103
|
+
except (OSError, ValueError):
|
|
104
|
+
return None
|
|
105
|
+
return data if isinstance(data, dict) else None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def hook_entries(path: Path, event: str) -> list[tuple[int, int, dict, dict]]:
|
|
109
|
+
data = _load(path) or {}
|
|
110
|
+
hooks = data.get("hooks")
|
|
111
|
+
groups = hooks.get(event) if isinstance(hooks, dict) else None
|
|
112
|
+
found = []
|
|
113
|
+
for group_index, group in enumerate(groups if isinstance(groups, list) else []):
|
|
114
|
+
entries = group.get("hooks") if isinstance(group, dict) else None
|
|
115
|
+
for handler_index, entry in enumerate(entries if isinstance(entries, list) else []):
|
|
116
|
+
if isinstance(entry, dict) and _is_ours(entry.get("command"), event):
|
|
117
|
+
found.append((group_index, handler_index, group, entry))
|
|
118
|
+
return found
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def hook_state(path: Path, event: str = "Stop") -> HookState:
|
|
122
|
+
entries = hook_entries(path, event)
|
|
123
|
+
return HookState(True, entries[0][3]["command"]) if entries else HookState(False)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def ensure_hook(path: Path, agent: str, command: str, event: str = "Stop", dry_run: bool = False, matcher: str | None = None) -> str:
|
|
127
|
+
data = _load(path)
|
|
128
|
+
label = str(path)
|
|
129
|
+
name = event
|
|
130
|
+
manual = f"{label} 无法解析或结构不对,没有修改;请手动加入 {name} 钩子:{command}"
|
|
131
|
+
if data is None:
|
|
132
|
+
return manual
|
|
133
|
+
state = hook_state(path, event)
|
|
134
|
+
if state.present:
|
|
135
|
+
same = "已接入" if state.command == command else f"已接入(命令是 {state.command},没有改)"
|
|
136
|
+
return f"{label}:{name} {same}"
|
|
137
|
+
hooks = data.setdefault("hooks", {})
|
|
138
|
+
groups = hooks.setdefault(event, []) if isinstance(hooks, dict) else None
|
|
139
|
+
if not isinstance(groups, list):
|
|
140
|
+
return manual
|
|
141
|
+
entry: dict = {"type": "command", "command": command, "timeout": TIMEOUT if event == "Stop" else PROMPT_TIMEOUT}
|
|
142
|
+
if agent == CODEX and event == "Stop":
|
|
143
|
+
entry["statusMessage"] = STATUS
|
|
144
|
+
groups.append({"matcher": matcher, "hooks": [entry]} if matcher else {"hooks": [entry]})
|
|
145
|
+
if agent == CODEX and "description" not in data:
|
|
146
|
+
data = {"description": "vibe-engine:agent 结束前运行检查", **data}
|
|
147
|
+
if dry_run:
|
|
148
|
+
return f"{label}:将加入 {name} 钩子(试运行,没有写入)"
|
|
149
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
150
|
+
write_atomic(path, json.dumps(data, ensure_ascii=False, indent=2) + "\n")
|
|
151
|
+
return f"{label}:已加入 {name} 钩子"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def ensure_hooks(
|
|
155
|
+
path: Path,
|
|
156
|
+
agent: str,
|
|
157
|
+
stop_command: str,
|
|
158
|
+
prompt_command: str,
|
|
159
|
+
dry_run: bool = False,
|
|
160
|
+
session_command: str | None = None,
|
|
161
|
+
edit_command: str | None = None,
|
|
162
|
+
) -> list[str]:
|
|
163
|
+
lines = [
|
|
164
|
+
ensure_hook(path, agent, stop_command, "Stop", dry_run),
|
|
165
|
+
ensure_hook(path, agent, prompt_command, "UserPromptSubmit", dry_run),
|
|
166
|
+
]
|
|
167
|
+
if session_command:
|
|
168
|
+
lines.append(ensure_hook(path, agent, session_command, "SessionStart", dry_run))
|
|
169
|
+
if edit_command and agent in EDIT_AGENTS:
|
|
170
|
+
lines.append(ensure_hook(path, agent, edit_command, "PostToolUse", dry_run, EDIT_MATCHER))
|
|
171
|
+
if agent == CLAUDE:
|
|
172
|
+
command = "vibe-engine hook skill" if stop_command == BARE_COMMAND else absolute_command("skill")
|
|
173
|
+
lines.append(ensure_hook(path, agent, command, "PreToolUse", dry_run, "Skill"))
|
|
174
|
+
lines.append(ensure_hook(path, agent, command, "UserPromptExpansion", dry_run, "|".join(SKILL_NAMES)))
|
|
175
|
+
return lines
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def install_user(agents: tuple[str, ...], dry_run: bool = False) -> list[str]:
|
|
179
|
+
command = absolute_command()
|
|
180
|
+
lines = [f"钩子命令:{command}"]
|
|
181
|
+
for agent in agents:
|
|
182
|
+
lines += ensure_hooks(user_hook_file(agent), agent, command, absolute_command("prompt"), dry_run, absolute_command("session"), absolute_command("edit"))
|
|
183
|
+
if CODEX in agents:
|
|
184
|
+
lines.append("Codex 要先审查并信任这个钩子:CLI 里运行 /hooks,桌面应用在 设置 > 钩子;定义改动后要重新信任。")
|
|
185
|
+
lines.append("用户级钩子对所有仓生效,没有 engine.toml 的仓里它什么都不做。")
|
|
186
|
+
return lines
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def bare_command_findable() -> bool:
|
|
190
|
+
return shutil.which("vibe-engine", path=MINIMAL_PATH) is not None
|