agentguard-tool 1.0.5__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.
Files changed (37) hide show
  1. agentguard_tool-1.0.5/LICENSE +21 -0
  2. agentguard_tool-1.0.5/PKG-INFO +328 -0
  3. agentguard_tool-1.0.5/README.md +283 -0
  4. agentguard_tool-1.0.5/agentguard_tool.egg-info/PKG-INFO +328 -0
  5. agentguard_tool-1.0.5/agentguard_tool.egg-info/SOURCES.txt +35 -0
  6. agentguard_tool-1.0.5/agentguard_tool.egg-info/dependency_links.txt +1 -0
  7. agentguard_tool-1.0.5/agentguard_tool.egg-info/entry_points.txt +3 -0
  8. agentguard_tool-1.0.5/agentguard_tool.egg-info/requires.txt +2 -0
  9. agentguard_tool-1.0.5/agentguard_tool.egg-info/top_level.txt +1 -0
  10. agentguard_tool-1.0.5/pyproject.toml +43 -0
  11. agentguard_tool-1.0.5/qg/__init__.py +1 -0
  12. agentguard_tool-1.0.5/qg/__main__.py +20 -0
  13. agentguard_tool-1.0.5/qg/auditor.py +190 -0
  14. agentguard_tool-1.0.5/qg/committer.py +101 -0
  15. agentguard_tool-1.0.5/qg/config.py +154 -0
  16. agentguard_tool-1.0.5/qg/dashboard.py +137 -0
  17. agentguard_tool-1.0.5/qg/engine.py +94 -0
  18. agentguard_tool-1.0.5/qg/fixer.py +124 -0
  19. agentguard_tool-1.0.5/qg/main.py +351 -0
  20. agentguard_tool-1.0.5/qg/models.py +84 -0
  21. agentguard_tool-1.0.5/qg/reporter.py +73 -0
  22. agentguard_tool-1.0.5/qg/rules/__init__.py +0 -0
  23. agentguard_tool-1.0.5/qg/rules/ai_hallucination.py +114 -0
  24. agentguard_tool-1.0.5/qg/rules/bare_except.py +45 -0
  25. agentguard_tool-1.0.5/qg/rules/base.py +98 -0
  26. agentguard_tool-1.0.5/qg/rules/hardcoded_paths.py +56 -0
  27. agentguard_tool-1.0.5/qg/rules/ruff_blocker.py +52 -0
  28. agentguard_tool-1.0.5/qg/rules/ruff_fixable.py +56 -0
  29. agentguard_tool-1.0.5/qg/rules/secret_leak.py +134 -0
  30. agentguard_tool-1.0.5/qg/rules/syntax_check.py +37 -0
  31. agentguard_tool-1.0.5/qg/rules/unsafe_api.py +124 -0
  32. agentguard_tool-1.0.5/qg/scanner.py +123 -0
  33. agentguard_tool-1.0.5/qg/verifier.py +42 -0
  34. agentguard_tool-1.0.5/setup.cfg +4 -0
  35. agentguard_tool-1.0.5/tests/test_cli.py +39 -0
  36. agentguard_tool-1.0.5/tests/test_models.py +175 -0
  37. agentguard_tool-1.0.5/tests/test_rules.py +238 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hermes Labs
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,328 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentguard-tool
3
+ Version: 1.0.5
4
+ Summary: AI-native quality gate for agent-generated code โ€” scan, audit, auto-fix, trend
5
+ Author: Hermes Labs
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Hermes Labs
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/weijinsheng123456/agentguard
29
+ Project-URL: Issues, https://github.com/weijinsheng123456/agentguard/issues
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: Topic :: Software Development :: Quality Assurance
33
+ Classifier: Topic :: Software Development :: Testing
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Requires-Python: >=3.10
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: pyyaml>=6.0
43
+ Requires-Dist: ruff>=0.4.0
44
+ Dynamic: license-file
45
+
46
+ <p align="center">
47
+ <img src="https://img.shields.io/badge/AgentGuard-1.0.0-8A2BE2?style=for-the-badge&logo=python&logoColor=white" width="300" alt="AgentGuard">
48
+ </p>
49
+
50
+ <p align="center">
51
+ <em>AI-native quality gate for agent-generated code.</em>
52
+ <br>
53
+ Scan ยท Audit ยท Auto-fix ยท Track trends
54
+ </p>
55
+
56
+ <p align="center">
57
+ <a href="#features">Features</a> โ€ข
58
+ <a href="#quick-start">Quick Start</a> โ€ข
59
+ <a href="#commands">Commands</a> โ€ข
60
+ <a href="#demo">Demo</a> โ€ข
61
+ <a href="#rules">Rules</a> โ€ข
62
+ <a href="#write-custom-rules">Custom Rules</a>
63
+ </p>
64
+
65
+ <p align="center">
66
+ <a href="https://github.com/weijinsheng123456/agentguard/actions">
67
+ <img src="https://img.shields.io/github/actions/workflow/status/weijinsheng123456/agentguard/ci.yml?branch=main&label=CI&logo=github&color=success" alt="CI">
68
+ </a>
69
+ <a href="https://pypi.org/project/agentguard/">
70
+ <img src="https://img.shields.io/pypi/v/agentguard?label=PyPI&logo=pypi&color=blue" alt="PyPI">
71
+ </a>
72
+ <a href="LICENSE">
73
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
74
+ </a>
75
+ <a href="https://github.com/weijinsheng123456/agentguard/stargazers">
76
+ <img src="https://img.shields.io/github/stars/weijinsheng123456/agentguard?style=social" alt="Stars">
77
+ </a>
78
+ <a href="https://www.python.org/">
79
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue?logo=python" alt="Python">
80
+ </a>
81
+ <a href="https://github.com/weijinsheng123456/agentguard/blob/main/CHANGELOG.md">
82
+ <img src="https://img.shields.io/badge/version-1.0.0-8A2BE2" alt="Version">
83
+ </a>
84
+ </p>
85
+
86
+ ---
87
+
88
+ # ๐Ÿš€ Install in 3 seconds
89
+
90
+ ```bash
91
+ pip install agentguard-tool
92
+ cd your-project
93
+ gate run
94
+ ```
95
+
96
+ Done. AgentGuard scans your code, detects AI-specific issues (hardcoded secrets, unsafe APIs, hallucinations), auto-fixes what it can, and tracks quality trends over time.
97
+
98
+ ---
99
+
100
+ ## Why AgentGuard?
101
+
102
+ Traditional linters like SonarQube and CodeQL were built for **human-written code**. AI agents write code differently โ€” they hallucinate module names, leave placeholder comments, generate giant functions, and introduce patterns that human linters miss.
103
+
104
+ **AgentGuard is built for the age of AI-generated code.**
105
+
106
+ It understands the patterns, pitfalls, and security risks specific to code written by LLMs. It runs as a CI-ready CLI, a pre-commit hook, or a daily cron.
107
+
108
+ ---
109
+
110
+ ## Features
111
+
112
+ ### ๐Ÿ” AI-Specific Detection (3 rules)
113
+ | Rule | Severity | What It Finds |
114
+ |------|----------|---------------|
115
+ | `unsafe_api` | ๐Ÿšซ BLOCKER | `eval()`, `exec()`, `os.system()`, `subprocess(shell=True)`, `pickle.loads()` |
116
+ | `secret_leak` | ๐Ÿšซ BLOCKER | Hardcoded API keys, tokens, passwords in source code |
117
+ | `ai_hallucination` | โ„น๏ธ INFO | AI placeholder comments, suspicious module names, giant auto-generated functions |
118
+
119
+ ### ๐Ÿ“Š Agent Behavior Audit
120
+ Reads agent trace data and produces a daily report:
121
+ - Tool call frequency & ranking
122
+ - Error rate & anomaly detection
123
+ - Token consumption & cost estimates
124
+ - Model usage distribution
125
+
126
+ ### ๐Ÿ“ˆ Trend Dashboard
127
+ Text-based trend chart with zero external dependencies:
128
+ ```
129
+ โ”โ”โ” ๐Ÿ“ˆ Quality Trend (Last 14 days) โ”โ”โ”
130
+ 05/08 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 0 issues โœ…
131
+ 05/09 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘ 3 issues โš ๏ธ
132
+ 05/10 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 0 issues โœ…
133
+ ```
134
+ Data persists in SQLite. View anytime with `gate trend`.
135
+
136
+ ### ๐Ÿ”ง Auto-Fix Pipeline
137
+ Automatically fixes what it can, backed up and git-committed:
138
+ - Unused imports (`F401`) and variables (`F841`)
139
+ - Bare `except:` โ†’ `except Exception:`
140
+ - Hardcoded paths โ†’ `$HOME` references
141
+ - Ruff-safe auto-fixes
142
+
143
+ ### ๐Ÿงฉ Plugin Rule Architecture
144
+ Rules are Python classes. Adding a new rule = one file, one class, one decorator.
145
+ ```python
146
+ @register_rule
147
+ class MyRule(Rule):
148
+ name = "my_rule"
149
+ severity = Severity.BLOCKER
150
+
151
+ def diagnose(self, filepath: str) -> list[Issue]:
152
+ # Your detection logic here
153
+ ...
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Quick Start
159
+
160
+ ```bash
161
+ # ๐ŸŽฏ Scan your project
162
+ pip install agentguard-tool
163
+ cd your-project
164
+ gate run
165
+
166
+ # ๐Ÿ” Quick check (staged files only)
167
+ gate run --quick
168
+
169
+ # ๐Ÿ“Š Agent behavior audit
170
+ gate audit
171
+
172
+ # ๐Ÿ“ˆ View quality trends
173
+ gate trend
174
+
175
+ # ๐Ÿ”ง Install pre-commit hooks
176
+ gate install
177
+ ```
178
+
179
+ ### Run from source
180
+ ```bash
181
+ git clone https://github.com/weijinsheng123456/agentguard.git
182
+ cd agentguard
183
+ python gate.py run
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Commands
189
+
190
+ | Command | Description |
191
+ |---------|-------------|
192
+ | `gate run` | Full scan + auto-fix + commit + audit |
193
+ | `gate run --quick` | Pre-commit check (staged files only) |
194
+ | `gate run --fixme` | Auto-fix staged files |
195
+ | `gate audit` | Agent behavior audit only |
196
+ | `gate trend [N]` | Show last N days of quality trends |
197
+ | `gate install` | Install pre-commit hooks & cron |
198
+ | `gate version` | Show version |
199
+
200
+ ---
201
+
202
+ ## Rules
203
+
204
+ ### Built-in Rules (8 total)
205
+
206
+ **Code Quality (ported from ruff):**
207
+ | Rule | Code | Severity | Auto-fix |
208
+ |------|------|----------|:--------:|
209
+ | `syntax_check` | `SYNTAX` | BLOCKER | โŒ |
210
+ | `ruff_blocker` | `F821`, `E999` | BLOCKER | โŒ |
211
+ | `ruff_fixable` | `F401`, `F841`, `E711`, `E712` | FIXABLE | โœ… |
212
+ | `bare_except` | `E722` | FIXABLE | โœ… |
213
+ | `hardcoded_paths` | `HARDCODE` | FIXABLE | โœ… |
214
+
215
+ **AI-Specific:**
216
+ | Rule | Code | Severity | Auto-fix |
217
+ |------|------|----------|:--------:|
218
+ | `unsafe_api` | `UNSAFE_*` | BLOCKER | โŒ |
219
+ | `secret_leak` | `LEAK_SECRET` | BLOCKER | โŒ |
220
+ | `ai_hallucination` | `AI_*` | INFO | โŒ |
221
+
222
+ ---
223
+
224
+ ## Write Custom Rules
225
+
226
+ Create a new `.py` file in `qg/rules/`:
227
+
228
+ ```python
229
+ from qg.models import Issue, Severity
230
+ from qg.rules.base import Rule, register_rule
231
+
232
+ @register_rule
233
+ class MyCustomRule(Rule):
234
+ name = "my_custom_rule"
235
+ severity = Severity.FIXABLE
236
+ description = "Detects something specific"
237
+
238
+ def should_check(self, filepath: str) -> bool:
239
+ return filepath.endswith(".py")
240
+
241
+ def diagnose(self, filepath: str) -> list[Issue]:
242
+ issues = []
243
+ # Your detection logic...
244
+ return issues
245
+
246
+ def fix(self, filepath: str, issue: Issue) -> bool:
247
+ # Your fix logic...
248
+ return True
249
+ ```
250
+
251
+ Rules support two modes:
252
+ - **`Rule`** โ€” per-file scanning (for AST analysis, regex)
253
+ - **`BatchRule`** โ€” directory-level scanning (for ruff, 10-50x faster)
254
+
255
+ ---
256
+
257
+ ## Configuration
258
+
259
+ ```yaml
260
+ scan_dirs:
261
+ - "~/my-project/src"
262
+ - "~/my-project/scripts"
263
+
264
+ ignore_patterns:
265
+ - "*__pycache__*"
266
+ - "*/tests/*"
267
+
268
+ severity:
269
+ blocker_codes: ["F821", "E999", "SYNTAX"]
270
+ auto_fix_codes: ["F401", "F841", "E711", "E712", "E722", "HARDCODE"]
271
+
272
+ report:
273
+ to_wechat: true
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Architecture
279
+
280
+ ```
281
+ gate.py (CLI entry)
282
+ โ””โ”€โ”€ qg/
283
+ โ”œโ”€โ”€ scanner.py # File discovery
284
+ โ”œโ”€โ”€ engine.py # Diagnostic engine (rule dispatching)
285
+ โ”œโ”€โ”€ fixer.py # Auto-fix engine
286
+ โ”œโ”€โ”€ verifier.py # Post-fix verification
287
+ โ”œโ”€โ”€ committer.py # Git commit automation
288
+ โ”œโ”€โ”€ reporter.py # Report generation (console + log)
289
+ โ”œโ”€โ”€ auditor.py # Agent behavior audit
290
+ โ”œโ”€โ”€ dashboard.py # Trend tracking (SQLite)
291
+ โ”œโ”€โ”€ models.py # Data models
292
+ โ”œโ”€โ”€ config.py # Configuration loader
293
+ โ””โ”€โ”€ rules/ # Plugin rules (hot-pluggable)
294
+ โ”œโ”€โ”€ base.py # Rule + BatchRule base classes
295
+ โ”œโ”€โ”€ syntax_check.py
296
+ โ”œโ”€โ”€ ruff_blocker.py (BatchRule)
297
+ โ”œโ”€โ”€ ruff_fixable.py (BatchRule)
298
+ โ”œโ”€โ”€ bare_except.py
299
+ โ”œโ”€โ”€ hardcoded_paths.py
300
+ โ”œโ”€โ”€ unsafe_api.py
301
+ โ”œโ”€โ”€ secret_leak.py
302
+ โ””โ”€โ”€ ai_hallucination.py
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Roadmap
308
+
309
+ - [x] Phase 1: Python rewrite + plugin architecture
310
+ - [x] Phase 2: AI-specific rules + agent audit + trend dashboard
311
+ - [x] Phase 3: Open-source release + CI integration
312
+ - [ ] Phase 4: Security rules (OWASP Top 10 for AI code)
313
+ - [ ] Phase 5: GitHub Actions native action
314
+ - [ ] Phase 6: VS Code extension
315
+
316
+ ---
317
+
318
+ ## License
319
+
320
+ MIT License โ€” see [LICENSE](LICENSE)
321
+
322
+ ---
323
+
324
+ <p align="center">
325
+ Built for the age of AI-generated code.
326
+ <br>
327
+ <sub>Because code quality doesn't matter less when AI writes it โ€” it matters more.</sub>
328
+ </p>
@@ -0,0 +1,283 @@
1
+ <p align="center">
2
+ <img src="https://img.shields.io/badge/AgentGuard-1.0.0-8A2BE2?style=for-the-badge&logo=python&logoColor=white" width="300" alt="AgentGuard">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <em>AI-native quality gate for agent-generated code.</em>
7
+ <br>
8
+ Scan ยท Audit ยท Auto-fix ยท Track trends
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="#features">Features</a> โ€ข
13
+ <a href="#quick-start">Quick Start</a> โ€ข
14
+ <a href="#commands">Commands</a> โ€ข
15
+ <a href="#demo">Demo</a> โ€ข
16
+ <a href="#rules">Rules</a> โ€ข
17
+ <a href="#write-custom-rules">Custom Rules</a>
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="https://github.com/weijinsheng123456/agentguard/actions">
22
+ <img src="https://img.shields.io/github/actions/workflow/status/weijinsheng123456/agentguard/ci.yml?branch=main&label=CI&logo=github&color=success" alt="CI">
23
+ </a>
24
+ <a href="https://pypi.org/project/agentguard/">
25
+ <img src="https://img.shields.io/pypi/v/agentguard?label=PyPI&logo=pypi&color=blue" alt="PyPI">
26
+ </a>
27
+ <a href="LICENSE">
28
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
29
+ </a>
30
+ <a href="https://github.com/weijinsheng123456/agentguard/stargazers">
31
+ <img src="https://img.shields.io/github/stars/weijinsheng123456/agentguard?style=social" alt="Stars">
32
+ </a>
33
+ <a href="https://www.python.org/">
34
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue?logo=python" alt="Python">
35
+ </a>
36
+ <a href="https://github.com/weijinsheng123456/agentguard/blob/main/CHANGELOG.md">
37
+ <img src="https://img.shields.io/badge/version-1.0.0-8A2BE2" alt="Version">
38
+ </a>
39
+ </p>
40
+
41
+ ---
42
+
43
+ # ๐Ÿš€ Install in 3 seconds
44
+
45
+ ```bash
46
+ pip install agentguard-tool
47
+ cd your-project
48
+ gate run
49
+ ```
50
+
51
+ Done. AgentGuard scans your code, detects AI-specific issues (hardcoded secrets, unsafe APIs, hallucinations), auto-fixes what it can, and tracks quality trends over time.
52
+
53
+ ---
54
+
55
+ ## Why AgentGuard?
56
+
57
+ Traditional linters like SonarQube and CodeQL were built for **human-written code**. AI agents write code differently โ€” they hallucinate module names, leave placeholder comments, generate giant functions, and introduce patterns that human linters miss.
58
+
59
+ **AgentGuard is built for the age of AI-generated code.**
60
+
61
+ It understands the patterns, pitfalls, and security risks specific to code written by LLMs. It runs as a CI-ready CLI, a pre-commit hook, or a daily cron.
62
+
63
+ ---
64
+
65
+ ## Features
66
+
67
+ ### ๐Ÿ” AI-Specific Detection (3 rules)
68
+ | Rule | Severity | What It Finds |
69
+ |------|----------|---------------|
70
+ | `unsafe_api` | ๐Ÿšซ BLOCKER | `eval()`, `exec()`, `os.system()`, `subprocess(shell=True)`, `pickle.loads()` |
71
+ | `secret_leak` | ๐Ÿšซ BLOCKER | Hardcoded API keys, tokens, passwords in source code |
72
+ | `ai_hallucination` | โ„น๏ธ INFO | AI placeholder comments, suspicious module names, giant auto-generated functions |
73
+
74
+ ### ๐Ÿ“Š Agent Behavior Audit
75
+ Reads agent trace data and produces a daily report:
76
+ - Tool call frequency & ranking
77
+ - Error rate & anomaly detection
78
+ - Token consumption & cost estimates
79
+ - Model usage distribution
80
+
81
+ ### ๐Ÿ“ˆ Trend Dashboard
82
+ Text-based trend chart with zero external dependencies:
83
+ ```
84
+ โ”โ”โ” ๐Ÿ“ˆ Quality Trend (Last 14 days) โ”โ”โ”
85
+ 05/08 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 0 issues โœ…
86
+ 05/09 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘ 3 issues โš ๏ธ
87
+ 05/10 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 0 issues โœ…
88
+ ```
89
+ Data persists in SQLite. View anytime with `gate trend`.
90
+
91
+ ### ๐Ÿ”ง Auto-Fix Pipeline
92
+ Automatically fixes what it can, backed up and git-committed:
93
+ - Unused imports (`F401`) and variables (`F841`)
94
+ - Bare `except:` โ†’ `except Exception:`
95
+ - Hardcoded paths โ†’ `$HOME` references
96
+ - Ruff-safe auto-fixes
97
+
98
+ ### ๐Ÿงฉ Plugin Rule Architecture
99
+ Rules are Python classes. Adding a new rule = one file, one class, one decorator.
100
+ ```python
101
+ @register_rule
102
+ class MyRule(Rule):
103
+ name = "my_rule"
104
+ severity = Severity.BLOCKER
105
+
106
+ def diagnose(self, filepath: str) -> list[Issue]:
107
+ # Your detection logic here
108
+ ...
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Quick Start
114
+
115
+ ```bash
116
+ # ๐ŸŽฏ Scan your project
117
+ pip install agentguard-tool
118
+ cd your-project
119
+ gate run
120
+
121
+ # ๐Ÿ” Quick check (staged files only)
122
+ gate run --quick
123
+
124
+ # ๐Ÿ“Š Agent behavior audit
125
+ gate audit
126
+
127
+ # ๐Ÿ“ˆ View quality trends
128
+ gate trend
129
+
130
+ # ๐Ÿ”ง Install pre-commit hooks
131
+ gate install
132
+ ```
133
+
134
+ ### Run from source
135
+ ```bash
136
+ git clone https://github.com/weijinsheng123456/agentguard.git
137
+ cd agentguard
138
+ python gate.py run
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Commands
144
+
145
+ | Command | Description |
146
+ |---------|-------------|
147
+ | `gate run` | Full scan + auto-fix + commit + audit |
148
+ | `gate run --quick` | Pre-commit check (staged files only) |
149
+ | `gate run --fixme` | Auto-fix staged files |
150
+ | `gate audit` | Agent behavior audit only |
151
+ | `gate trend [N]` | Show last N days of quality trends |
152
+ | `gate install` | Install pre-commit hooks & cron |
153
+ | `gate version` | Show version |
154
+
155
+ ---
156
+
157
+ ## Rules
158
+
159
+ ### Built-in Rules (8 total)
160
+
161
+ **Code Quality (ported from ruff):**
162
+ | Rule | Code | Severity | Auto-fix |
163
+ |------|------|----------|:--------:|
164
+ | `syntax_check` | `SYNTAX` | BLOCKER | โŒ |
165
+ | `ruff_blocker` | `F821`, `E999` | BLOCKER | โŒ |
166
+ | `ruff_fixable` | `F401`, `F841`, `E711`, `E712` | FIXABLE | โœ… |
167
+ | `bare_except` | `E722` | FIXABLE | โœ… |
168
+ | `hardcoded_paths` | `HARDCODE` | FIXABLE | โœ… |
169
+
170
+ **AI-Specific:**
171
+ | Rule | Code | Severity | Auto-fix |
172
+ |------|------|----------|:--------:|
173
+ | `unsafe_api` | `UNSAFE_*` | BLOCKER | โŒ |
174
+ | `secret_leak` | `LEAK_SECRET` | BLOCKER | โŒ |
175
+ | `ai_hallucination` | `AI_*` | INFO | โŒ |
176
+
177
+ ---
178
+
179
+ ## Write Custom Rules
180
+
181
+ Create a new `.py` file in `qg/rules/`:
182
+
183
+ ```python
184
+ from qg.models import Issue, Severity
185
+ from qg.rules.base import Rule, register_rule
186
+
187
+ @register_rule
188
+ class MyCustomRule(Rule):
189
+ name = "my_custom_rule"
190
+ severity = Severity.FIXABLE
191
+ description = "Detects something specific"
192
+
193
+ def should_check(self, filepath: str) -> bool:
194
+ return filepath.endswith(".py")
195
+
196
+ def diagnose(self, filepath: str) -> list[Issue]:
197
+ issues = []
198
+ # Your detection logic...
199
+ return issues
200
+
201
+ def fix(self, filepath: str, issue: Issue) -> bool:
202
+ # Your fix logic...
203
+ return True
204
+ ```
205
+
206
+ Rules support two modes:
207
+ - **`Rule`** โ€” per-file scanning (for AST analysis, regex)
208
+ - **`BatchRule`** โ€” directory-level scanning (for ruff, 10-50x faster)
209
+
210
+ ---
211
+
212
+ ## Configuration
213
+
214
+ ```yaml
215
+ scan_dirs:
216
+ - "~/my-project/src"
217
+ - "~/my-project/scripts"
218
+
219
+ ignore_patterns:
220
+ - "*__pycache__*"
221
+ - "*/tests/*"
222
+
223
+ severity:
224
+ blocker_codes: ["F821", "E999", "SYNTAX"]
225
+ auto_fix_codes: ["F401", "F841", "E711", "E712", "E722", "HARDCODE"]
226
+
227
+ report:
228
+ to_wechat: true
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Architecture
234
+
235
+ ```
236
+ gate.py (CLI entry)
237
+ โ””โ”€โ”€ qg/
238
+ โ”œโ”€โ”€ scanner.py # File discovery
239
+ โ”œโ”€โ”€ engine.py # Diagnostic engine (rule dispatching)
240
+ โ”œโ”€โ”€ fixer.py # Auto-fix engine
241
+ โ”œโ”€โ”€ verifier.py # Post-fix verification
242
+ โ”œโ”€โ”€ committer.py # Git commit automation
243
+ โ”œโ”€โ”€ reporter.py # Report generation (console + log)
244
+ โ”œโ”€โ”€ auditor.py # Agent behavior audit
245
+ โ”œโ”€โ”€ dashboard.py # Trend tracking (SQLite)
246
+ โ”œโ”€โ”€ models.py # Data models
247
+ โ”œโ”€โ”€ config.py # Configuration loader
248
+ โ””โ”€โ”€ rules/ # Plugin rules (hot-pluggable)
249
+ โ”œโ”€โ”€ base.py # Rule + BatchRule base classes
250
+ โ”œโ”€โ”€ syntax_check.py
251
+ โ”œโ”€โ”€ ruff_blocker.py (BatchRule)
252
+ โ”œโ”€โ”€ ruff_fixable.py (BatchRule)
253
+ โ”œโ”€โ”€ bare_except.py
254
+ โ”œโ”€โ”€ hardcoded_paths.py
255
+ โ”œโ”€โ”€ unsafe_api.py
256
+ โ”œโ”€โ”€ secret_leak.py
257
+ โ””โ”€โ”€ ai_hallucination.py
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Roadmap
263
+
264
+ - [x] Phase 1: Python rewrite + plugin architecture
265
+ - [x] Phase 2: AI-specific rules + agent audit + trend dashboard
266
+ - [x] Phase 3: Open-source release + CI integration
267
+ - [ ] Phase 4: Security rules (OWASP Top 10 for AI code)
268
+ - [ ] Phase 5: GitHub Actions native action
269
+ - [ ] Phase 6: VS Code extension
270
+
271
+ ---
272
+
273
+ ## License
274
+
275
+ MIT License โ€” see [LICENSE](LICENSE)
276
+
277
+ ---
278
+
279
+ <p align="center">
280
+ Built for the age of AI-generated code.
281
+ <br>
282
+ <sub>Because code quality doesn't matter less when AI writes it โ€” it matters more.</sub>
283
+ </p>