vibe-engine 0.2.0__tar.gz → 0.3.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.2.0 → vibe_engine-0.3.0}/PKG-INFO +3 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/README.md +2 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/pyproject.toml +1 -1
- vibe_engine-0.3.0/src/vibe_engine/__init__.py +1 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/agents.py +40 -17
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/comments.py +24 -8
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/mypy.py +4 -2
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/ruff.py +3 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/cli.py +102 -18
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/codex_status.py +7 -3
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/config.py +73 -4
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/detect.py +2 -2
- vibe_engine-0.3.0/src/vibe_engine/development_plans.py +170 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/doctor.py +69 -13
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/export.py +4 -2
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/files.py +23 -22
- vibe_engine-0.3.0/src/vibe_engine/git_workflow.py +367 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/guard.py +3 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/hook.py +50 -5
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/init_wizard.py +144 -23
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/install_state.py +77 -9
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/jsresolve.py +14 -9
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/languages/base.py +11 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/languages/js.py +3 -3
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/languages/python.py +3 -4
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/languages/shell.py +2 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/loosening.py +16 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/onboarding.py +6 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/rules_edit.py +3 -2
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/rules_table.py +3 -4
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/rules_verify.py +13 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/scaffold.py +167 -13
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/staged.py +15 -3
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/stats.py +36 -21
- vibe_engine-0.3.0/src/vibe_engine/templates/commit-msg +16 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/report.html +7 -4
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/workflow.yml +5 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/uninstall.py +34 -82
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/conftest.py +5 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_agents.py +34 -0
- vibe_engine-0.3.0/tests/test_cli_contracts.py +113 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_coverage_gaps.py +8 -1
- vibe_engine-0.3.0/tests/test_development_plans.py +157 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_doctor.py +51 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_gates.py +6 -0
- vibe_engine-0.3.0/tests/test_git_workflow.py +284 -0
- vibe_engine-0.3.0/tests/test_init_wizard.py +335 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_js.py +11 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_languages.py +32 -1
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_loop.py +29 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_loosening.py +13 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_mypy.py +52 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_review_round3.py +12 -2
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_rules.py +15 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_shared_rules.py +33 -0
- vibe_engine-0.3.0/tests/test_source_read_errors.py +35 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_uninstall.py +26 -1
- vibe_engine-0.2.0/src/vibe_engine/__init__.py +0 -1
- vibe_engine-0.2.0/tests/test_init_wizard.py +0 -150
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/.gitignore +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/LICENSE +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/architecture.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/astgrep.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/baseline.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/__init__.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/banned.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/boundaries.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/doclinks.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/jscomments.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/shared.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/shellcheck.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/shellcomments.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/checks/strings.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/engine_dir.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/events.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/evidence.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/fixing.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/freeze.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/init_toml.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/languages/__init__.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/model.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/modules.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/presets/js-debugging.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/presets/js-explicit-any.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/presets/js-test-integrity.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/presets/python-test-integrity.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/presets/test-integrity.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/report.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/runner.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/statefiles.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/engine.toml +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/feature-map.md +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/skills/correction-to-rule/SKILL.md +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/templates/skills/verify-feature/SKILL.md +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/touch.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/trend.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/verifying.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/src/vibe_engine/webreport.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_baseline.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_detect.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_development_regressions.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_doclinks.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_export.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_fixing.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_review_fixes.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_review_round2.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_rules_proof.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_shell.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_single_file.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_verify_layer.py +0 -0
- {vibe_engine-0.2.0 → vibe_engine-0.3.0}/tests/test_webreport.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vibe-engine
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: 可复用的检查引擎:让 AI 写的代码在每个仓里都过同一套确定性检查
|
|
5
5
|
Project-URL: Repository, https://github.com/william-swl/vibe-engine
|
|
6
6
|
Project-URL: Documentation, https://william-swl.github.io/vibe-engine/
|
|
@@ -57,6 +57,8 @@ pipx install vibe-engine
|
|
|
57
57
|
|
|
58
58
|
如果已激活项目的虚拟环境,也可以运行 `python -m pip install vibe-engine`。要为 pipx 指定 Python 版本,见 [快速开始](https://william-swl.github.io/vibe-engine/getting-started/)。
|
|
59
59
|
|
|
60
|
+
已经在使用 0.2?见 [0.3 升级说明](https://william-swl.github.io/vibe-engine/releases/0.3/),了解如何同步本地与 CI 版本,以及哪些配置变更现在需要留痕。
|
|
61
|
+
|
|
60
62
|
## 在一个仓里接入
|
|
61
63
|
|
|
62
64
|
```bash
|
|
@@ -32,6 +32,8 @@ pipx install vibe-engine
|
|
|
32
32
|
|
|
33
33
|
如果已激活项目的虚拟环境,也可以运行 `python -m pip install vibe-engine`。要为 pipx 指定 Python 版本,见 [快速开始](https://william-swl.github.io/vibe-engine/getting-started/)。
|
|
34
34
|
|
|
35
|
+
已经在使用 0.2?见 [0.3 升级说明](https://william-swl.github.io/vibe-engine/releases/0.3/),了解如何同步本地与 CI 版本,以及哪些配置变更现在需要留痕。
|
|
36
|
+
|
|
35
37
|
## 在一个仓里接入
|
|
36
38
|
|
|
37
39
|
```bash
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -18,6 +18,8 @@ BARE_PROMPT_COMMAND = "vibe-engine hook prompt"
|
|
|
18
18
|
BARE_SESSION_COMMAND = "vibe-engine hook session"
|
|
19
19
|
BARE_EDIT_COMMAND = "vibe-engine hook edit"
|
|
20
20
|
EDIT_MATCHER = "Write|Edit|MultiEdit"
|
|
21
|
+
PREPARE_MATCHER = "Write|Edit|MultiEdit|NotebookEdit"
|
|
22
|
+
PREPARE_COMMAND = "vibe-engine hook prepare"
|
|
21
23
|
EDIT_AGENTS = (CLAUDE,)
|
|
22
24
|
HOOK_WORDS = {
|
|
23
25
|
"Stop": "hook stop",
|
|
@@ -28,6 +30,7 @@ HOOK_WORDS = {
|
|
|
28
30
|
"UserPromptExpansion": "hook skill",
|
|
29
31
|
}
|
|
30
32
|
PROMPT_TIMEOUT = 30
|
|
33
|
+
PREPARE_TIMEOUT = 45
|
|
31
34
|
TIMEOUT = 120
|
|
32
35
|
STATUS = "vibe-engine 检查"
|
|
33
36
|
MINIMAL_PATH = "/usr/bin:/bin:/usr/sbin:/sbin"
|
|
@@ -44,7 +47,7 @@ TRUST_NOTE = "Codex 只在受信任的项目里读 .codex/hooks.json,并且要
|
|
|
44
47
|
|
|
45
48
|
@dataclass(frozen=True)
|
|
46
49
|
class HookState:
|
|
47
|
-
present: bool
|
|
50
|
+
present: bool | None
|
|
48
51
|
command: str = ""
|
|
49
52
|
|
|
50
53
|
|
|
@@ -84,42 +87,53 @@ def command_source() -> str:
|
|
|
84
87
|
def absolute_command(event: str = "stop") -> str:
|
|
85
88
|
stable = Path.home() / ".local" / "bin" / "vibe-engine"
|
|
86
89
|
found = shutil.which("vibe-engine")
|
|
87
|
-
|
|
90
|
+
try:
|
|
91
|
+
executable = str(stable) if stable.exists() else found
|
|
92
|
+
except OSError:
|
|
93
|
+
executable = found
|
|
88
94
|
if executable:
|
|
89
95
|
return f"{shlex.quote(executable)} hook {event}"
|
|
90
96
|
return f"{shlex.quote(sys.executable)} -m vibe_engine.cli hook {event}"
|
|
91
97
|
|
|
92
98
|
|
|
93
|
-
def _is_ours(command: object, event: str = "Stop") -> bool:
|
|
94
|
-
word = HOOK_WORDS[event]
|
|
99
|
+
def _is_ours(command: object, event: str = "Stop", command_word: str | None = None) -> bool:
|
|
100
|
+
word = command_word or HOOK_WORDS[event]
|
|
95
101
|
return isinstance(command, str) and ("vibe-engine" in command or "-m vibe_engine.cli" in command) and word in command
|
|
96
102
|
|
|
97
103
|
|
|
98
104
|
def _load(path: Path) -> dict | None:
|
|
99
|
-
if not path.exists():
|
|
100
|
-
return {}
|
|
101
105
|
try:
|
|
102
106
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
107
|
+
except FileNotFoundError:
|
|
108
|
+
return {}
|
|
103
109
|
except (OSError, ValueError):
|
|
104
110
|
return None
|
|
105
111
|
return data if isinstance(data, dict) else None
|
|
106
112
|
|
|
107
113
|
|
|
108
|
-
def hook_entries(path: Path, event: str) -> list[tuple[int, int, dict, dict]]:
|
|
109
|
-
|
|
114
|
+
def hook_entries(path: Path, event: str, command_word: str | None = None, matcher: str | None = None) -> list[tuple[int, int, dict, dict]]:
|
|
115
|
+
return _entries(_load(path) or {}, event, command_word, matcher)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _entries(data: dict, event: str, command_word: str | None = None, matcher: str | None = None) -> list[tuple[int, int, dict, dict]]:
|
|
110
119
|
hooks = data.get("hooks")
|
|
111
120
|
groups = hooks.get(event) if isinstance(hooks, dict) else None
|
|
112
121
|
found = []
|
|
113
122
|
for group_index, group in enumerate(groups if isinstance(groups, list) else []):
|
|
114
123
|
entries = group.get("hooks") if isinstance(group, dict) else None
|
|
124
|
+
if matcher is not None and (not isinstance(group, dict) or group.get("matcher") != matcher):
|
|
125
|
+
continue
|
|
115
126
|
for handler_index, entry in enumerate(entries if isinstance(entries, list) else []):
|
|
116
|
-
if isinstance(entry, dict) and _is_ours(entry.get("command"), event):
|
|
127
|
+
if isinstance(entry, dict) and _is_ours(entry.get("command"), event, command_word):
|
|
117
128
|
found.append((group_index, handler_index, group, entry))
|
|
118
129
|
return found
|
|
119
130
|
|
|
120
131
|
|
|
121
132
|
def hook_state(path: Path, event: str = "Stop") -> HookState:
|
|
122
|
-
|
|
133
|
+
data = _load(path)
|
|
134
|
+
if data is None:
|
|
135
|
+
return HookState(None)
|
|
136
|
+
entries = _entries(data, event)
|
|
123
137
|
return HookState(True, entries[0][3]["command"]) if entries else HookState(False)
|
|
124
138
|
|
|
125
139
|
|
|
@@ -127,7 +141,10 @@ CODEX_DESCRIPTION = "vibe-engine:agent 结束前运行检查"
|
|
|
127
141
|
|
|
128
142
|
|
|
129
143
|
def hook_group(agent: str, command: str, event: str, matcher: str | None) -> dict:
|
|
130
|
-
|
|
144
|
+
timeout = TIMEOUT if event == "Stop" else PROMPT_TIMEOUT
|
|
145
|
+
if event == "PreToolUse" and matcher == PREPARE_MATCHER:
|
|
146
|
+
timeout = PREPARE_TIMEOUT
|
|
147
|
+
entry: dict = {"type": "command", "command": command, "timeout": timeout}
|
|
131
148
|
if agent == CODEX and event == "Stop":
|
|
132
149
|
entry["statusMessage"] = STATUS
|
|
133
150
|
return {"matcher": matcher, "hooks": [entry]} if matcher else {"hooks": [entry]}
|
|
@@ -135,22 +152,26 @@ def hook_group(agent: str, command: str, event: str, matcher: str | None) -> dic
|
|
|
135
152
|
|
|
136
153
|
def project_groups(agent: str) -> dict[str, list[dict]]:
|
|
137
154
|
matchers = {"PostToolUse": EDIT_MATCHER, "PreToolUse": "Skill", "UserPromptExpansion": "|".join(SKILL_NAMES)}
|
|
138
|
-
|
|
155
|
+
groups = {
|
|
139
156
|
event: [hook_group(agent, f"vibe-engine {command}", event, matchers.get(event))]
|
|
140
157
|
for event, command in HOOK_WORDS.items() if event not in matchers or agent == CLAUDE
|
|
141
158
|
}
|
|
159
|
+
if agent == CLAUDE:
|
|
160
|
+
groups["PreToolUse"].append(hook_group(agent, PREPARE_COMMAND, "PreToolUse", PREPARE_MATCHER))
|
|
161
|
+
return groups
|
|
142
162
|
|
|
143
163
|
|
|
144
|
-
def ensure_hook(path: Path, agent: str, command: str, event: str = "Stop", dry_run: bool = False, matcher: str | None = None) -> str:
|
|
164
|
+
def ensure_hook(path: Path, agent: str, command: str, event: str = "Stop", dry_run: bool = False, matcher: str | None = None, command_word: str | None = None) -> str:
|
|
145
165
|
data = _load(path)
|
|
146
166
|
label = str(path)
|
|
147
167
|
name = event
|
|
148
|
-
manual = f"{label}
|
|
168
|
+
manual = f"{label} 无法读取、无法解析或结构不对,没有修改;请手动加入 {name} 钩子:{command}"
|
|
149
169
|
if data is None:
|
|
150
170
|
return manual
|
|
151
|
-
|
|
152
|
-
if
|
|
153
|
-
|
|
171
|
+
entries = _entries(data, event, command_word, matcher if command_word else None)
|
|
172
|
+
if entries:
|
|
173
|
+
existing = entries[0][3]["command"]
|
|
174
|
+
same = "已接入" if existing == command else f"已接入(命令是 {existing},没有改)"
|
|
154
175
|
return f"{label}:{name} {same}"
|
|
155
176
|
hooks = data.setdefault("hooks", {})
|
|
156
177
|
groups = hooks.setdefault(event, []) if isinstance(hooks, dict) else None
|
|
@@ -186,6 +207,8 @@ def ensure_hooks(
|
|
|
186
207
|
if agent == CLAUDE:
|
|
187
208
|
command = "vibe-engine hook skill" if stop_command == BARE_COMMAND else absolute_command("skill")
|
|
188
209
|
lines.append(ensure_hook(path, agent, command, "PreToolUse", dry_run, "Skill"))
|
|
210
|
+
prepare = PREPARE_COMMAND if stop_command == BARE_COMMAND else absolute_command("prepare")
|
|
211
|
+
lines.append(ensure_hook(path, agent, prepare, "PreToolUse", dry_run, PREPARE_MATCHER, "hook prepare"))
|
|
189
212
|
lines.append(ensure_hook(path, agent, command, "UserPromptExpansion", dry_run, "|".join(SKILL_NAMES)))
|
|
190
213
|
return lines
|
|
191
214
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import ast
|
|
4
|
+
import codecs
|
|
4
5
|
import io
|
|
5
6
|
import re
|
|
6
7
|
import tokenize
|
|
@@ -53,10 +54,25 @@ _DIRECTIVE = re.compile(
|
|
|
53
54
|
)
|
|
54
55
|
_FUNCTIONAL = re.compile(r"#\s*%%(?:\s.*)?|#\s*(?:end)?region\b.*|#:.*", re.IGNORECASE)
|
|
55
56
|
_TYPE_COMMENT = re.compile(r"#\s*type:\s*(.+)")
|
|
56
|
-
_ENCODING = re.compile(r"
|
|
57
|
+
_ENCODING = re.compile(r"^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)", re.ASCII)
|
|
57
58
|
_NOT_CODE = (ast.Global, ast.Nonlocal)
|
|
58
59
|
|
|
59
60
|
|
|
61
|
+
def _encoding_row(lines: list[str]) -> int | None:
|
|
62
|
+
for row, line in enumerate(lines[:2], 1):
|
|
63
|
+
cookie = _ENCODING.match(line)
|
|
64
|
+
if cookie:
|
|
65
|
+
try:
|
|
66
|
+
codecs.lookup(cookie.group(1))
|
|
67
|
+
except LookupError:
|
|
68
|
+
return None
|
|
69
|
+
return row
|
|
70
|
+
content = line.strip(" \t\f\r")
|
|
71
|
+
if content and not content.startswith("#"):
|
|
72
|
+
break
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
|
|
60
76
|
def _parses(text: str, mode: str) -> bool:
|
|
61
77
|
try:
|
|
62
78
|
ast.parse(text, mode=mode)
|
|
@@ -98,13 +114,11 @@ def comment_message(comment: str) -> str:
|
|
|
98
114
|
return message_for(comment.lstrip("#").strip(), _is_dead_code)
|
|
99
115
|
|
|
100
116
|
|
|
101
|
-
def _classify(comment: str,
|
|
102
|
-
if
|
|
103
|
-
return None
|
|
104
|
-
if line <= 2 and _ENCODING.match(comment):
|
|
105
|
-
return None
|
|
106
|
-
if _SUPPRESSION.search(comment) or _TYPE_SUPPRESSION.match(comment):
|
|
117
|
+
def _classify(comment: str, header: bool, allowed: list) -> str | None:
|
|
118
|
+
if _SUPPRESSION.search(comment) or _TYPE_SUPPRESSION.search(comment):
|
|
107
119
|
return NO_SUPPRESSION
|
|
120
|
+
if header:
|
|
121
|
+
return None
|
|
108
122
|
if _FUNCTIONAL.fullmatch(comment) or _is_directive(comment) or any(pattern.search(comment) for pattern in allowed):
|
|
109
123
|
return None
|
|
110
124
|
return COMMENT_BAN
|
|
@@ -115,13 +129,15 @@ def check(rel: str, text: str, lines: list[str], config: Config) -> list[Violati
|
|
|
115
129
|
if not any(enabled.values()):
|
|
116
130
|
return []
|
|
117
131
|
allowed = [re.compile(pattern) for pattern in config.allow_comment_patterns]
|
|
132
|
+
encoding_row = _encoding_row(lines)
|
|
118
133
|
found = []
|
|
119
134
|
try:
|
|
120
135
|
for token in tokenize.generate_tokens(io.StringIO(text).readline):
|
|
121
136
|
if token.type != tokenize.COMMENT:
|
|
122
137
|
continue
|
|
123
138
|
row = token.start[0]
|
|
124
|
-
|
|
139
|
+
header = row == encoding_row or (token.start == (1, 0) and token.string.startswith("#!"))
|
|
140
|
+
rule = _classify(token.string, header, allowed)
|
|
125
141
|
if not rule or not enabled[rule]:
|
|
126
142
|
continue
|
|
127
143
|
message = SUPPRESSION_MESSAGE if rule == NO_SUPPRESSION else comment_message(token.string)
|
|
@@ -8,6 +8,7 @@ import subprocess
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
10
|
from ..config import Config, under
|
|
11
|
+
from ..files import python_inputs
|
|
11
12
|
from ..model import Violation
|
|
12
13
|
|
|
13
14
|
PREFIX = "mypy:"
|
|
@@ -73,9 +74,10 @@ def _run(config: Config, env: dict[str, str], argv: list[str]) -> subprocess.Com
|
|
|
73
74
|
def check(
|
|
74
75
|
config: Config, files: set[str], env: dict[str, str], snapshot: bool,
|
|
75
76
|
) -> tuple[list[Violation], str | None, list[str]]:
|
|
76
|
-
if
|
|
77
|
+
sources = files if config.mypy.targets_from_paths else python_inputs(config)
|
|
78
|
+
targets = [name for name in config.mypy.targets if any(under(path, name) for path in sources)]
|
|
79
|
+
if not targets:
|
|
77
80
|
return [], None, []
|
|
78
|
-
targets = [name for name in config.mypy.targets if any(under(path, name) for path in files)]
|
|
79
81
|
argv = list(command(config))
|
|
80
82
|
if snapshot:
|
|
81
83
|
argv += ["--cache-dir", os.devnull]
|
|
@@ -27,7 +27,9 @@ def check(config: Config, sources: dict[str, list[str]]) -> tuple[list[Violation
|
|
|
27
27
|
|
|
28
28
|
def _check(config: Config, sources: dict[str, list[str]], paths: list[str]) -> tuple[list[Violation], str | None]:
|
|
29
29
|
command = [sys.executable, "-m", "ruff", "check", "--output-format", "json", "--exit-zero", "--force-exclude", "--no-fix"]
|
|
30
|
-
if config.ruff_select
|
|
30
|
+
if config.ruff_select == ():
|
|
31
|
+
command += ["--config", "lint.select=[]"]
|
|
32
|
+
elif config.ruff_select is not None:
|
|
31
33
|
command += ["--select", ",".join(config.ruff_select)]
|
|
32
34
|
if config.ruff_extend_select:
|
|
33
35
|
command += ["--extend-select", ",".join(config.ruff_extend_select)]
|
|
@@ -13,14 +13,17 @@ from . import (
|
|
|
13
13
|
agents,
|
|
14
14
|
baseline,
|
|
15
15
|
detect,
|
|
16
|
+
development_plans,
|
|
16
17
|
doctor,
|
|
17
18
|
events,
|
|
18
19
|
export,
|
|
19
20
|
fixing,
|
|
21
|
+
git_workflow,
|
|
20
22
|
hook,
|
|
21
23
|
init_toml,
|
|
22
24
|
init_wizard,
|
|
23
25
|
install_state,
|
|
26
|
+
onboarding,
|
|
24
27
|
rules_edit,
|
|
25
28
|
rules_table,
|
|
26
29
|
rules_verify,
|
|
@@ -115,7 +118,7 @@ def _write_baseline(args: argparse.Namespace, root: Path) -> int:
|
|
|
115
118
|
print(f"检查器出错:{error}", file=sys.stderr)
|
|
116
119
|
return 1
|
|
117
120
|
current = baseline.count(violations)
|
|
118
|
-
existing =
|
|
121
|
+
existing = None if args.reset else baseline.load(config.root)
|
|
119
122
|
|
|
120
123
|
def chosen(rule: str) -> bool:
|
|
121
124
|
return any(rule.startswith(prefix) for prefix in args.rule)
|
|
@@ -255,11 +258,17 @@ def _report(args: argparse.Namespace) -> int:
|
|
|
255
258
|
def _fix(args: argparse.Namespace) -> int:
|
|
256
259
|
config = load_config(_root(args))
|
|
257
260
|
before = run_check(config, "ci", with_commands=False, check_rules=False, with_mypy=False)
|
|
261
|
+
if before.errors:
|
|
262
|
+
print(render(before), file=sys.stderr)
|
|
263
|
+
return 1
|
|
258
264
|
report = fixing.apply(config, before.violations, args.rule, args.path, args.dry_run)
|
|
259
265
|
print("\n".join(report.lines))
|
|
260
266
|
if args.dry_run or not report.attempted:
|
|
261
267
|
return 0
|
|
262
268
|
after = run_check(config, None, with_commands=False, with_mypy=False)
|
|
269
|
+
if after.errors:
|
|
270
|
+
print(render(after), file=sys.stderr)
|
|
271
|
+
return 1
|
|
263
272
|
before_fixes = baseline.count(fixing.selected_fixes(before.violations, args.rule, args.path))
|
|
264
273
|
after_fixes = baseline.count(fixing.selected_fixes(after.violations, args.rule, args.path))
|
|
265
274
|
remaining = sum((before_fixes & after_fixes).values())
|
|
@@ -319,6 +328,31 @@ def _init(args: argparse.Namespace) -> int:
|
|
|
319
328
|
return 130
|
|
320
329
|
|
|
321
330
|
|
|
331
|
+
def _confirm_installation(before: Config, after: Config, names: tuple[str, ...] | None, force: bool) -> bool:
|
|
332
|
+
notes = []
|
|
333
|
+
if before.git_workflow != after.git_workflow:
|
|
334
|
+
policy = after.git_workflow
|
|
335
|
+
if policy.mode == "off":
|
|
336
|
+
notes.append("Git 工作流:关闭。撤销仍由引擎管理的 pre-push 钩子。")
|
|
337
|
+
else:
|
|
338
|
+
notes.append(f"Git 工作流:{init_wizard.GIT_MODES[policy.mode]} · {policy.remote}/{policy.base}。接入 pre-push 钩子。")
|
|
339
|
+
if before.init_commit_msg != after.init_commit_msg:
|
|
340
|
+
action = "接入" if after.init_commit_msg else "撤销仍由引擎管理的"
|
|
341
|
+
notes.append(f"提交标题校验:{action} commit-msg 钩子。")
|
|
342
|
+
if before.development_plans != after.development_plans:
|
|
343
|
+
notes.append("开发计划:" + development_plans.preview_ignore(after) + "。")
|
|
344
|
+
if before.init_agents != after.init_agents:
|
|
345
|
+
selected = ", ".join(scaffold.selected_agents(after, names)) or "无"
|
|
346
|
+
notes.append(f"接入项目钩子和 Skill 的 Agent:{selected}。")
|
|
347
|
+
if before.init_generate_ci != after.init_generate_ci or force:
|
|
348
|
+
ci_action = "生成或覆盖模板" if force else "缺少时生成模板"
|
|
349
|
+
notes.append("CI:" + (ci_action if after.init_generate_ci else "沿用已有 CI") + "。")
|
|
350
|
+
if not notes:
|
|
351
|
+
return True
|
|
352
|
+
print("\n安装变更", *(f"\n {line}" for line in notes), sep="")
|
|
353
|
+
return input("应用以上安装变更?[y/N] ").strip().lower() in ("y", "yes")
|
|
354
|
+
|
|
355
|
+
|
|
322
356
|
def _run_init(args: argparse.Namespace, root: Path, names: tuple[str, ...] | None) -> int:
|
|
323
357
|
path = root / CONFIG_NAME
|
|
324
358
|
fresh = not path.is_file()
|
|
@@ -326,14 +360,17 @@ def _run_init(args: argparse.Namespace, root: Path, names: tuple[str, ...] | Non
|
|
|
326
360
|
interactive = not args.yes and sys.stdin.isatty() and sys.stdout.isatty()
|
|
327
361
|
config = parse_config(text, root)
|
|
328
362
|
candidates = {item.name: item for item in detect.candidates(root)}
|
|
329
|
-
updated, auto_mypy,
|
|
330
|
-
text, config, candidates, fresh=fresh, interactive=interactive, explicit_mypy=args.with_mypy,
|
|
363
|
+
updated, auto_mypy, notes = init_wizard.select(
|
|
364
|
+
text, config, candidates, fresh=fresh, interactive=interactive, explicit_mypy=args.with_mypy, agent_override=names,
|
|
331
365
|
)
|
|
332
366
|
if not fresh and updated != text:
|
|
333
367
|
updated = init_wizard.record_loosening(updated, config)
|
|
334
368
|
planned = parse_config(updated, root)
|
|
369
|
+
if interactive and not _confirm_installation(config, planned, names, args.force):
|
|
370
|
+
print("已取消接入。")
|
|
371
|
+
return 130
|
|
335
372
|
run_commands = not args.no_commands
|
|
336
|
-
pending = [item.run for item in candidates.values() if item.name not in (*
|
|
373
|
+
pending = [item.run for item in candidates.values() if item.name not in (*planned.init_skip_commands, "mypy")
|
|
337
374
|
and detect.configured_command(planned, item) is None]
|
|
338
375
|
runs = list(dict.fromkeys([*(item.run for item in planned.commands), *pending]))
|
|
339
376
|
if interactive and run_commands and runs:
|
|
@@ -344,7 +381,8 @@ def _run_init(args: argparse.Namespace, root: Path, names: tuple[str, ...] | Non
|
|
|
344
381
|
if (original is not None if fresh else original is None or original.text != text):
|
|
345
382
|
raise ConfigError("engine.toml 在交互期间已被其他进程修改,请重新运行 init。")
|
|
346
383
|
if not fresh and updated != text:
|
|
347
|
-
|
|
384
|
+
update_ignore = development_plans.updating_ignore(planned) if config.development_plans != planned.development_plans else nullcontext()
|
|
385
|
+
with state.track(CONFIG_NAME, BASELINE_NAME), update_ignore:
|
|
348
386
|
notes += init_wizard.save_changes(path, text, updated, config, planned, args.baseline)
|
|
349
387
|
lines = scaffold.apply_init(
|
|
350
388
|
state, args.install_spec, args.force, names, args.profile,
|
|
@@ -355,18 +393,24 @@ def _run_init(args: argparse.Namespace, root: Path, names: tuple[str, ...] | Non
|
|
|
355
393
|
if run_commands:
|
|
356
394
|
print("\n接入仓库命令", flush=True)
|
|
357
395
|
with state.track(CONFIG_NAME):
|
|
358
|
-
print("\n".join(detect.run(load_config(root), apply=True
|
|
396
|
+
print("\n".join(detect.run(load_config(root), apply=True)))
|
|
359
397
|
else:
|
|
360
398
|
print("\n跳过探测和执行仓库命令。")
|
|
361
399
|
if args.baseline:
|
|
362
400
|
with state.track(BASELINE_NAME):
|
|
363
401
|
print(scaffold.record_existing_baseline(root))
|
|
364
402
|
config = load_config(root)
|
|
365
|
-
|
|
403
|
+
diagnostics = doctor.diagnose(config)
|
|
404
|
+
lines, _ = doctor.report(config, data=diagnostics)
|
|
366
405
|
print("\n环境诊断\n" + "\n".join(lines), flush=True)
|
|
406
|
+
if onboarding.signature_checks_enabled(config):
|
|
407
|
+
print('如需豁免测试目录的签名注解检查,可在 Ruff 的 per-file-ignores 中为 "tests/**" 配置 ["ANN001", "ANN201"]。')
|
|
367
408
|
with state.track(BASELINE_NAME):
|
|
368
409
|
result = run_check(config, with_commands=run_commands)
|
|
369
410
|
print("\n首次检查\n" + render(result))
|
|
411
|
+
gates_ready = all(gate["status"] in {"active", "configured", "skipped"} for gate in diagnostics["gates"].values())
|
|
412
|
+
if result.ok and diagnostics["status"] == "ok" and not diagnostics["tasks"] and gates_ready:
|
|
413
|
+
print("接入完整。")
|
|
370
414
|
return 0 if result.ok else 1
|
|
371
415
|
|
|
372
416
|
|
|
@@ -405,17 +449,38 @@ def _hook_skill(args: argparse.Namespace) -> int:
|
|
|
405
449
|
return hook.skill("" if sys.stdin.isatty() else sys.stdin.read())
|
|
406
450
|
|
|
407
451
|
|
|
452
|
+
def _hook_prepare(args: argparse.Namespace) -> int:
|
|
453
|
+
return hook.prepare("" if sys.stdin.isatty() else sys.stdin.read())
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def _git_sync(args: argparse.Namespace) -> int:
|
|
457
|
+
return git_workflow.sync(load_config(_root(args)))
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _git_start(args: argparse.Namespace) -> int:
|
|
461
|
+
return git_workflow.start(load_config(_root(args)), args.branch)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def _git_finish(args: argparse.Namespace) -> int:
|
|
465
|
+
return git_workflow.finish(load_config(_root(args)), args.push)
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def _git_pre_push(args: argparse.Namespace) -> int:
|
|
469
|
+
root = find_root(Path.cwd())
|
|
470
|
+
return git_workflow.pre_push(load_config(root), args.remote, sys.stdin.read()) if root else 0
|
|
471
|
+
|
|
472
|
+
|
|
408
473
|
def _stats(args: argparse.Namespace) -> int:
|
|
409
474
|
root = _root(args)
|
|
410
475
|
recorded = events.load(root)
|
|
476
|
+
if args.attention:
|
|
477
|
+
found = stats.attention(load_config(root), recorded, by_agent=args.by_agent)
|
|
478
|
+
print(json.dumps(found, ensure_ascii=False, indent=2) if args.json else stats.render_attention(found))
|
|
479
|
+
return 0
|
|
411
480
|
if args.by_agent:
|
|
412
481
|
found = stats.activity(recorded)
|
|
413
482
|
print(json.dumps(found, ensure_ascii=False, indent=2) if args.json else stats.render_activity(found))
|
|
414
483
|
return 0
|
|
415
|
-
if args.attention:
|
|
416
|
-
found = stats.attention(load_config(root), recorded)
|
|
417
|
-
print(json.dumps(found, ensure_ascii=False, indent=2) if args.json else stats.render_attention(found))
|
|
418
|
-
return 0
|
|
419
484
|
if args.trial:
|
|
420
485
|
found = stats.trial(load_config(root), recorded)
|
|
421
486
|
print(json.dumps(found, ensure_ascii=False, indent=2) if args.json else stats.render_trial(found))
|
|
@@ -428,8 +493,8 @@ def _stats(args: argparse.Namespace) -> int:
|
|
|
428
493
|
def _feedback(args: argparse.Namespace) -> int:
|
|
429
494
|
root = _root(args)
|
|
430
495
|
config = load_config(root)
|
|
431
|
-
|
|
432
|
-
if not (args.rule in
|
|
496
|
+
declared = rules_verify.diagnostic_ids(config)
|
|
497
|
+
if not (any(args.rule in ids for ids in declared.values()) or args.rule.startswith(("engine:", "ruff:", "shellcheck:", "command:", "mypy:", "docs:", "frozen:"))):
|
|
433
498
|
raise ConfigError(f"不认识的规则:{args.rule}。运行 `vibe-engine rules` 看现有规则。")
|
|
434
499
|
events.record(root, {"kind": stats.FEEDBACK, "rule": args.rule, "false_positive": args.false_positive, "note": args.note})
|
|
435
500
|
print(f"已记录对 {args.rule} 的反馈" + ("(误拦)。" if args.false_positive else "。"))
|
|
@@ -452,8 +517,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
452
517
|
check.set_defaults(handler=_check)
|
|
453
518
|
|
|
454
519
|
record = commands.add_parser("baseline", parents=[shared], help="把存量违规记入基线")
|
|
455
|
-
record.
|
|
456
|
-
|
|
520
|
+
scope = record.add_mutually_exclusive_group()
|
|
521
|
+
scope.add_argument("--rule", action="append", default=[], help="只为这个规则前缀记录存量,可重复")
|
|
522
|
+
scope.add_argument("--reset", action="store_true", help="整体重建基线")
|
|
457
523
|
record.set_defaults(handler=_baseline)
|
|
458
524
|
|
|
459
525
|
graph = commands.add_parser("graph", parents=[shared], help="将仓内导入图输出为 Mermaid")
|
|
@@ -465,6 +531,21 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
465
531
|
guard.add_argument("--base", required=True, help="基准 git ref,例如 origin/main")
|
|
466
532
|
guard.set_defaults(handler=_guard)
|
|
467
533
|
|
|
534
|
+
workflow = commands.add_parser("git", help="同步基准、创建功能分支和交付")
|
|
535
|
+
operations = workflow.add_subparsers(dest="operation", required=True)
|
|
536
|
+
sync = operations.add_parser("sync", parents=[shared], help="获取远程基准并安全快进本地基准")
|
|
537
|
+
sync.set_defaults(handler=_git_sync)
|
|
538
|
+
start = operations.add_parser("start", parents=[shared], help="从最新远程基准创建功能分支")
|
|
539
|
+
start.add_argument("branch", help="功能分支名")
|
|
540
|
+
start.set_defaults(handler=_git_start)
|
|
541
|
+
finish = operations.add_parser("finish", parents=[shared], help="验证并交付当前分支")
|
|
542
|
+
finish.add_argument("--push", action="store_true", help="推送已验证的提交;PR 模式同时创建或复用 PR")
|
|
543
|
+
finish.set_defaults(handler=_git_finish)
|
|
544
|
+
pre_push = operations.add_parser("pre-push", help="供 Git pre-push 钩子使用")
|
|
545
|
+
pre_push.add_argument("remote")
|
|
546
|
+
pre_push.add_argument("url")
|
|
547
|
+
pre_push.set_defaults(handler=_git_pre_push)
|
|
548
|
+
|
|
468
549
|
rule = commands.add_parser("rule", help="把一次纠正写成规则")
|
|
469
550
|
kinds = rule.add_subparsers(dest="kind", required=True)
|
|
470
551
|
ban = kinds.add_parser("ban", parents=[shared], help="禁用某个 API、命令、导入、调用或写法")
|
|
@@ -512,8 +593,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
512
593
|
base.add_argument("--baseline", action="store_true", default=True, help="接入后记录存量基线(默认,兼容旧用法)")
|
|
513
594
|
base.add_argument("--no-baseline", dest="baseline", action="store_false", help="跳过接入时记录存量基线")
|
|
514
595
|
init.add_argument("--no-commands", action="store_true", help="跳过探测和执行仓库命令")
|
|
515
|
-
init.add_argument("--yes", action="store_true", help="
|
|
516
|
-
init.add_argument("--agents", help="
|
|
596
|
+
init.add_argument("--yes", action="store_true", help="跳过交互,首次使用推荐值,重跑沿用已保存的选择")
|
|
597
|
+
init.add_argument("--agents", help="覆盖本次接入的 Agent,逗号分隔:claude、codex(省略时使用已保存的选择或自动探测)")
|
|
517
598
|
init.add_argument("--with-mypy", action="store_true", help="接入 Mypy 并记录已有类型违规,必要时用 uv 添加开发依赖")
|
|
518
599
|
init.add_argument("--package", help="把 Mypy 添加到指定的 uv 工作区成员")
|
|
519
600
|
init.add_argument("--dry-run", action="store_true", help="预览 --with-mypy 的变更")
|
|
@@ -574,13 +655,16 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
574
655
|
submit = hook_events.add_parser("prompt", help="agent 收到用户消息时记下当时的改动,收工时只检查这一轮新改的文件")
|
|
575
656
|
submit.set_defaults(handler=_hook_prompt)
|
|
576
657
|
|
|
658
|
+
preparation = hook_events.add_parser("prepare", help="首次编辑前验证当前 Git 分支")
|
|
659
|
+
preparation.set_defaults(handler=_hook_prepare)
|
|
660
|
+
|
|
577
661
|
skill = hook_events.add_parser("skill", help="记录本仓 skill 的一次触发")
|
|
578
662
|
skill.set_defaults(handler=_hook_skill)
|
|
579
663
|
|
|
580
664
|
summary = commands.add_parser("stats", parents=[shared], help="收工钩子拦了什么、修好了多少")
|
|
581
665
|
summary.add_argument("--json", action="store_true", help="输出 JSON")
|
|
582
666
|
summary.add_argument("--attention", action="store_true", help="列出值得看一眼的规则:被放行过的、反复被拦的、从没拦过的、没有示例的")
|
|
583
|
-
summary.add_argument("--by-agent", action="store_true", help="
|
|
667
|
+
summary.add_argument("--by-agent", action="store_true", help="按关卡和执行环境汇总规则触犯记录;与 --attention 同用时按 Agent 拆分反复违规")
|
|
584
668
|
summary.add_argument("--trial", action="store_true", help="对照两周试用的标准给出是否达标(误拦比例、连拦 3 次放行、同一会话内改好的比例)")
|
|
585
669
|
summary.set_defaults(handler=_stats)
|
|
586
670
|
return parser
|
|
@@ -44,9 +44,13 @@ def inspect(root: Path) -> dict:
|
|
|
44
44
|
flag = _table(data, "features").get("hooks", True) if user is not None else None
|
|
45
45
|
flag = flag if isinstance(flag, bool) else None
|
|
46
46
|
projects = _table(data, "projects")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
resolved = root.resolve()
|
|
48
|
+
project = "unknown"
|
|
49
|
+
for directory in (resolved, *resolved.parents):
|
|
50
|
+
trust = _table(projects, str(directory)).get("trust_level")
|
|
51
|
+
if trust in ("trusted", "untrusted"):
|
|
52
|
+
project = trust
|
|
53
|
+
break
|
|
50
54
|
state = _table(_table(data, "hooks"), "state")
|
|
51
55
|
rows = []
|
|
52
56
|
for scope, path in (("project", root / agents.HOOK_FILES[agents.CODEX]), ("user", agents.user_hook_file(agents.CODEX))):
|