agent-code-guard 0.1.0__tar.gz → 0.2.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.
- agent_code_guard-0.2.0/PKG-INFO +252 -0
- agent_code_guard-0.2.0/README.md +238 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/pyproject.toml +1 -1
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/SKILL.md +27 -5
- agent_code_guard-0.2.0/src/agent_code_guard/analysis/adapters.py +136 -0
- agent_code_guard-0.2.0/src/agent_code_guard/analysis/branch_normalization.py +195 -0
- agent_code_guard-0.2.0/src/agent_code_guard/analysis/callable_identity.py +329 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/regions.py +1 -0
- agent_code_guard-0.2.0/src/agent_code_guard/analysis/syntax_nodes.py +5 -0
- agent_code_guard-0.2.0/src/agent_code_guard/code_guard.py +433 -0
- agent_code_guard-0.2.0/src/agent_code_guard/doctor.py +358 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/file_selection.py +5 -3
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/loc.py +27 -5
- agent_code_guard-0.2.0/src/agent_code_guard/human_output.py +122 -0
- agent_code_guard-0.2.0/src/agent_code_guard/loc_baseline.py +295 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/result_model.py +8 -1
- agent_code_guard-0.2.0/src/agent_code_guard.egg-info/PKG-INFO +252 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard.egg-info/SOURCES.txt +6 -0
- agent_code_guard-0.1.0/PKG-INFO +0 -206
- agent_code_guard-0.1.0/README.md +0 -192
- agent_code_guard-0.1.0/src/agent_code_guard/analysis/adapters.py +0 -608
- agent_code_guard-0.1.0/src/agent_code_guard/code_guard.py +0 -236
- agent_code_guard-0.1.0/src/agent_code_guard.egg-info/PKG-INFO +0 -206
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/LICENSE +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/MANIFEST.in +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/setup.cfg +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/LICENSE.txt +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/agents/openai.yaml +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/references/callable-size-policy.md +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/references/complexity-policy.md +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/references/loc-policy.md +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/references/markdown-size-policy.md +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/skills/code-guard/references/nesting-policy.md +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/__init__.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/__init__.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/errors.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/facts.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/language_specs.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/pipeline.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/analysis/provider.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/config_validation.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/__init__.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/callable_size.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/complexity.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/markdown_document_size.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/markdown_section_size.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/guards/nesting.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/markdown/__init__.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/markdown/facts.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/markdown/scanner.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/path_matching.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/reporting.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard/skill_distribution.py +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard.egg-info/dependency_links.txt +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard.egg-info/entry_points.txt +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard.egg-info/requires.txt +0 -0
- {agent_code_guard-0.1.0 → agent_code_guard-0.2.0}/src/agent_code_guard.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-code-guard
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Deterministic cross-language guardrails for agent-assisted development
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Source, https://github.com/stef-k/agent-code-guard
|
|
7
|
+
Project-URL: Issues, https://github.com/stef-k/agent-code-guard/issues
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: tree-sitter==0.26.0
|
|
12
|
+
Requires-Dist: tree-sitter-language-pack==1.14.3
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Agent Code Guard
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="https://raw.githubusercontent.com/stef-k/agent-code-guard/main/assets/agent-code-guard-mark.svg" width="180" alt="Agent Code Guard project mark">
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
Deterministic maintainability guardrails for source code and Markdown changed by
|
|
22
|
+
a human or coding agent.
|
|
23
|
+
|
|
24
|
+
[](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml)
|
|
25
|
+
[](https://pypi.org/project/agent-code-guard/)
|
|
26
|
+
[](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
|
|
27
|
+
[](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE)
|
|
28
|
+
|
|
29
|
+
Agent Code Guard measures file size, callable size, structural nesting,
|
|
30
|
+
cyclomatic complexity, Markdown document size, and Markdown section size. It
|
|
31
|
+
reports deterministic **PASS**, **REVIEW**, or **FAIL** results without
|
|
32
|
+
rewriting your files.
|
|
33
|
+
|
|
34
|
+
It complements rather than replaces tests, compilers, linters, formatters,
|
|
35
|
+
security tools, and design judgment.
|
|
36
|
+
|
|
37
|
+
## Why it is useful
|
|
38
|
+
|
|
39
|
+
Code Guard surfaces files and callables that are becoming difficult to review,
|
|
40
|
+
deep nesting and complex decision logic, and Markdown specifications that are
|
|
41
|
+
losing navigability. It gives humans and agents the same repeatable review
|
|
42
|
+
point after edits and can prevent silent LOC growth beyond an explicit project
|
|
43
|
+
policy.
|
|
44
|
+
|
|
45
|
+
### What humans gain
|
|
46
|
+
|
|
47
|
+
- Consistent signals across supported languages and Markdown, whether a change
|
|
48
|
+
came from a person or an agent.
|
|
49
|
+
- A shared PASS/REVIEW/FAIL vocabulary: continue, inspect with judgment, or
|
|
50
|
+
block pending correction or an authorized exception.
|
|
51
|
+
- The same checks locally and in CI, with no configuration required for
|
|
52
|
+
ordinary use and no automatic source mutation.
|
|
53
|
+
|
|
54
|
+
### What agents gain
|
|
55
|
+
|
|
56
|
+
- Deterministic feedback after edits and consistent process exits.
|
|
57
|
+
- Changed-file scope instead of unnecessary full-repository scans.
|
|
58
|
+
- Compact JSON that omits normalized pass noise while retaining actionable
|
|
59
|
+
findings and result structure.
|
|
60
|
+
- Named required policies, so only relevant guidance needs to be loaded, plus a
|
|
61
|
+
version-matched bundled skill with REVIEW-judgment and anti-gaming rules.
|
|
62
|
+
|
|
63
|
+
This workflow is designed to reduce unnecessary output and policy loading. It
|
|
64
|
+
still requires the source context needed to understand and judge each finding;
|
|
65
|
+
it makes no claim about measured token savings.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
[pipx](https://pipx.pypa.io/) isolates the command from project environments:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pipx install agent-code-guard
|
|
73
|
+
code-guard --version
|
|
74
|
+
code-guard doctor
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`--version` confirms the installed distribution identity. `doctor` checks the
|
|
78
|
+
active installation's health. See the [usage guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md) for virtual
|
|
79
|
+
environment, uv, and developer alternatives.
|
|
80
|
+
|
|
81
|
+
### Ask your agent to adopt it
|
|
82
|
+
|
|
83
|
+
Copy this prompt to a coding agent:
|
|
84
|
+
|
|
85
|
+
> Consult the official Agent Code Guard repository and documentation. Install
|
|
86
|
+
> the published distribution in an isolated supported way, preferably with
|
|
87
|
+
> pipx; verify `code-guard --version` and run `code-guard doctor`. Locate the
|
|
88
|
+
> installed version-matched skill with `code-guard --skill-path`, and use or
|
|
89
|
+
> export only that skill through the documented mechanism. Inspect this
|
|
90
|
+
> repository without creating a LOC baseline and use changed-work scope. Ask
|
|
91
|
+
> before exporting into a persistent skill directory, changing persistent
|
|
92
|
+
> agent or platform configuration, or configuring hooks.
|
|
93
|
+
> Never weaken thresholds, exclusions, configuration, or baselines merely to
|
|
94
|
+
> silence findings.
|
|
95
|
+
|
|
96
|
+
## Five-minute start
|
|
97
|
+
|
|
98
|
+
From a Git worktree, inspect the current change:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
code-guard . --changed-only
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Git supplies the changed candidates; every enabled and applicable guard runs.
|
|
105
|
+
No configuration is needed. A REVIEW asks for inspection and judgment, not an
|
|
106
|
+
automatic refactor. Outside Git, pass the exact edited files instead, such as
|
|
107
|
+
`code-guard src/app.py docs/guide.md`.
|
|
108
|
+
|
|
109
|
+
See the [agent workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) for repeated human and
|
|
110
|
+
agent use.
|
|
111
|
+
|
|
112
|
+
## Recommended workflow
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
edit supported code or Markdown
|
|
116
|
+
↓
|
|
117
|
+
run Code Guard on changed scope
|
|
118
|
+
↓
|
|
119
|
+
PASS → continue
|
|
120
|
+
REVIEW → inspect, justify or genuinely improve
|
|
121
|
+
FAIL → fix or obtain an explicitly authorized exception
|
|
122
|
+
↓
|
|
123
|
+
rerun
|
|
124
|
+
↓
|
|
125
|
+
report the result before completion
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Use `code-guard . --changed-only --json --json-mode compact` for a structured,
|
|
129
|
+
low-noise manual agent check. Hooks are optional, platform-owned, and require
|
|
130
|
+
user authorization; Code Guard does not install them. The
|
|
131
|
+
[workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) owns the complete manual and
|
|
132
|
+
hook-assisted process.
|
|
133
|
+
|
|
134
|
+
## Interpreting results
|
|
135
|
+
|
|
136
|
+
- **PASS** — no special action; exit `0`.
|
|
137
|
+
- **REVIEW** — inspect and decide whether genuine structural improvement is
|
|
138
|
+
warranted; normally exit `1`.
|
|
139
|
+
- **Completed FAIL** — blocks normal completion until fixed or an explicitly
|
|
140
|
+
authorized exception applies; exit `2` with a completed report on stdout.
|
|
141
|
+
- An argparse usage or invalid-choice error exits `2`, writes usage/error text
|
|
142
|
+
to stderr, and produces no completed report.
|
|
143
|
+
- Other Code Guard tool, configuration, scope, or provider errors exit `3`.
|
|
144
|
+
|
|
145
|
+
`--ci` makes REVIEW nonblocking at the process level by changing its exit to
|
|
146
|
+
`0`; it does not hide the findings or change FAIL and tool-error exits.
|
|
147
|
+
|
|
148
|
+
**Never game a metric.** Do not create artificial helpers, files,
|
|
149
|
+
abstractions, formatting, exclusions, or policy changes merely to lower a
|
|
150
|
+
measurement. A REVIEW is not proof of a defect or a mandatory refactor.
|
|
151
|
+
|
|
152
|
+
## Guard reference
|
|
153
|
+
|
|
154
|
+
| Guard | Default |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| File LOC | REVIEW >400, FAIL >600 |
|
|
157
|
+
| Callable size | REVIEW >80 physical LOC |
|
|
158
|
+
| Structural nesting | REVIEW >4 |
|
|
159
|
+
| Cyclomatic complexity | REVIEW >15 |
|
|
160
|
+
| Markdown document size | REVIEW >800 physical lines |
|
|
161
|
+
| Markdown direct-section size | REVIEW >200 physical lines |
|
|
162
|
+
|
|
163
|
+
Comparisons are strictly greater-than, so equality passes. All guards except
|
|
164
|
+
file LOC are REVIEW-only; only file LOC can FAIL. A new guard must provide
|
|
165
|
+
distinct, deterministic value rather than duplicate conventional tooling. See
|
|
166
|
+
[Guard admission](https://github.com/stef-k/agent-code-guard/blob/main/docs/guard-admission.md).
|
|
167
|
+
|
|
168
|
+
### Result and JSON reference
|
|
169
|
+
|
|
170
|
+
Every completed analysis reports selected, analyzed, inapplicable, and
|
|
171
|
+
all-guard-excluded file counts. Bare `--json` is the compatible full output;
|
|
172
|
+
`--json-mode debug` is byte-identical for the same completed invocation, while
|
|
173
|
+
`--json-mode compact` removes only normalized `pass` findings and retains the
|
|
174
|
+
result, scope, required policies, guards, ordering, and actionable findings.
|
|
175
|
+
Named modes require `--json`. See [Usage](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md) for the schema and
|
|
176
|
+
option contract.
|
|
177
|
+
|
|
178
|
+
### Common scope commands
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Current Git work
|
|
182
|
+
code-guard . --changed-only
|
|
183
|
+
|
|
184
|
+
# Pull request or branch comparison
|
|
185
|
+
code-guard . --base-ref origin/main --ci
|
|
186
|
+
|
|
187
|
+
# Deliberate full audit
|
|
188
|
+
code-guard .
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The base ref must exist in the chosen environment. Changed work is not a full
|
|
192
|
+
audit; do not repeatedly scan unrelated files after every edit.
|
|
193
|
+
|
|
194
|
+
### Supported languages and formats
|
|
195
|
+
|
|
196
|
+
Syntax guards support Python, Go, Kotlin, C#, Java, JavaScript, TypeScript, JSX,
|
|
197
|
+
TSX, Vue JavaScript/TypeScript script regions, C++, Rust, PHP, Swift, and Dart.
|
|
198
|
+
Markdown guards apply to `.md` files.
|
|
199
|
+
|
|
200
|
+
Generic `.h` files are not syntax-dispatched; `.markdown` is not enabled; Vue
|
|
201
|
+
template and style regions are not executable syntax input; and unsupported
|
|
202
|
+
artifacts are inapplicable. Malformed applicable syntax or a required provider
|
|
203
|
+
failure is a fail-closed tool error. See [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md).
|
|
204
|
+
|
|
205
|
+
### Skill integration
|
|
206
|
+
|
|
207
|
+
An installed distribution includes the matching Code Guard skill payload:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
code-guard --skill-path
|
|
211
|
+
code-guard --export-skill <target-directory>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Skill activation is platform-specific and is not performed by pipx or Code
|
|
215
|
+
Guard. See [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md). The checkout
|
|
216
|
+
compatibility runner is for repository development, not normal installation.
|
|
217
|
+
|
|
218
|
+
### Configuration
|
|
219
|
+
|
|
220
|
+
Built-in defaults require no configuration. Configure a project only for a
|
|
221
|
+
concrete policy reason; see the [configuration guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md).
|
|
222
|
+
The LOC baseline is an explicit adoption tool for established legacy
|
|
223
|
+
repositories, not an ordinary-use requirement or a way to silence findings.
|
|
224
|
+
|
|
225
|
+
## Trust, CI, and platform support
|
|
226
|
+
|
|
227
|
+
CI installs Agent Code Guard and analyzes its own real checkout. REVIEW findings
|
|
228
|
+
remain visible but non-blocking, while FAIL findings and tool errors block the
|
|
229
|
+
workflow; the repository intentionally uses no LOC baseline.
|
|
230
|
+
|
|
231
|
+
The maintained interpreter range is **CPython 3.10–3.14**. See
|
|
232
|
+
[Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md) for supported binary platforms and
|
|
233
|
+
source-build boundaries.
|
|
234
|
+
|
|
235
|
+
## Documentation
|
|
236
|
+
|
|
237
|
+
- [Documentation index](https://github.com/stef-k/agent-code-guard/blob/main/docs/README.md)
|
|
238
|
+
- [Agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
|
|
239
|
+
- [Usage and CLI reference](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md)
|
|
240
|
+
- [Configuration](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md)
|
|
241
|
+
- [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md)
|
|
242
|
+
- [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
|
|
243
|
+
- [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md)
|
|
244
|
+
|
|
245
|
+
## Feedback, security, and license
|
|
246
|
+
|
|
247
|
+
Report defects through the [bug report form](https://github.com/stef-k/agent-code-guard/issues/new?template=bug-report.md),
|
|
248
|
+
propose measurements through the [candidate guard form](https://github.com/stef-k/agent-code-guard/issues/new?template=candidate-guard.md),
|
|
249
|
+
and follow the [security policy](https://github.com/stef-k/agent-code-guard/blob/main/SECURITY.md) for vulnerabilities.
|
|
250
|
+
|
|
251
|
+
Agent Code Guard grew from the Agent LOC Guard prototype and is now the
|
|
252
|
+
canonical implementation. Licensed under the [MIT License](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE).
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Agent Code Guard
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/stef-k/agent-code-guard/main/assets/agent-code-guard-mark.svg" width="180" alt="Agent Code Guard project mark">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
Deterministic maintainability guardrails for source code and Markdown changed by
|
|
8
|
+
a human or coding agent.
|
|
9
|
+
|
|
10
|
+
[](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml)
|
|
11
|
+
[](https://pypi.org/project/agent-code-guard/)
|
|
12
|
+
[](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
|
|
13
|
+
[](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE)
|
|
14
|
+
|
|
15
|
+
Agent Code Guard measures file size, callable size, structural nesting,
|
|
16
|
+
cyclomatic complexity, Markdown document size, and Markdown section size. It
|
|
17
|
+
reports deterministic **PASS**, **REVIEW**, or **FAIL** results without
|
|
18
|
+
rewriting your files.
|
|
19
|
+
|
|
20
|
+
It complements rather than replaces tests, compilers, linters, formatters,
|
|
21
|
+
security tools, and design judgment.
|
|
22
|
+
|
|
23
|
+
## Why it is useful
|
|
24
|
+
|
|
25
|
+
Code Guard surfaces files and callables that are becoming difficult to review,
|
|
26
|
+
deep nesting and complex decision logic, and Markdown specifications that are
|
|
27
|
+
losing navigability. It gives humans and agents the same repeatable review
|
|
28
|
+
point after edits and can prevent silent LOC growth beyond an explicit project
|
|
29
|
+
policy.
|
|
30
|
+
|
|
31
|
+
### What humans gain
|
|
32
|
+
|
|
33
|
+
- Consistent signals across supported languages and Markdown, whether a change
|
|
34
|
+
came from a person or an agent.
|
|
35
|
+
- A shared PASS/REVIEW/FAIL vocabulary: continue, inspect with judgment, or
|
|
36
|
+
block pending correction or an authorized exception.
|
|
37
|
+
- The same checks locally and in CI, with no configuration required for
|
|
38
|
+
ordinary use and no automatic source mutation.
|
|
39
|
+
|
|
40
|
+
### What agents gain
|
|
41
|
+
|
|
42
|
+
- Deterministic feedback after edits and consistent process exits.
|
|
43
|
+
- Changed-file scope instead of unnecessary full-repository scans.
|
|
44
|
+
- Compact JSON that omits normalized pass noise while retaining actionable
|
|
45
|
+
findings and result structure.
|
|
46
|
+
- Named required policies, so only relevant guidance needs to be loaded, plus a
|
|
47
|
+
version-matched bundled skill with REVIEW-judgment and anti-gaming rules.
|
|
48
|
+
|
|
49
|
+
This workflow is designed to reduce unnecessary output and policy loading. It
|
|
50
|
+
still requires the source context needed to understand and judge each finding;
|
|
51
|
+
it makes no claim about measured token savings.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
[pipx](https://pipx.pypa.io/) isolates the command from project environments:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pipx install agent-code-guard
|
|
59
|
+
code-guard --version
|
|
60
|
+
code-guard doctor
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`--version` confirms the installed distribution identity. `doctor` checks the
|
|
64
|
+
active installation's health. See the [usage guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md) for virtual
|
|
65
|
+
environment, uv, and developer alternatives.
|
|
66
|
+
|
|
67
|
+
### Ask your agent to adopt it
|
|
68
|
+
|
|
69
|
+
Copy this prompt to a coding agent:
|
|
70
|
+
|
|
71
|
+
> Consult the official Agent Code Guard repository and documentation. Install
|
|
72
|
+
> the published distribution in an isolated supported way, preferably with
|
|
73
|
+
> pipx; verify `code-guard --version` and run `code-guard doctor`. Locate the
|
|
74
|
+
> installed version-matched skill with `code-guard --skill-path`, and use or
|
|
75
|
+
> export only that skill through the documented mechanism. Inspect this
|
|
76
|
+
> repository without creating a LOC baseline and use changed-work scope. Ask
|
|
77
|
+
> before exporting into a persistent skill directory, changing persistent
|
|
78
|
+
> agent or platform configuration, or configuring hooks.
|
|
79
|
+
> Never weaken thresholds, exclusions, configuration, or baselines merely to
|
|
80
|
+
> silence findings.
|
|
81
|
+
|
|
82
|
+
## Five-minute start
|
|
83
|
+
|
|
84
|
+
From a Git worktree, inspect the current change:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
code-guard . --changed-only
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Git supplies the changed candidates; every enabled and applicable guard runs.
|
|
91
|
+
No configuration is needed. A REVIEW asks for inspection and judgment, not an
|
|
92
|
+
automatic refactor. Outside Git, pass the exact edited files instead, such as
|
|
93
|
+
`code-guard src/app.py docs/guide.md`.
|
|
94
|
+
|
|
95
|
+
See the [agent workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) for repeated human and
|
|
96
|
+
agent use.
|
|
97
|
+
|
|
98
|
+
## Recommended workflow
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
edit supported code or Markdown
|
|
102
|
+
↓
|
|
103
|
+
run Code Guard on changed scope
|
|
104
|
+
↓
|
|
105
|
+
PASS → continue
|
|
106
|
+
REVIEW → inspect, justify or genuinely improve
|
|
107
|
+
FAIL → fix or obtain an explicitly authorized exception
|
|
108
|
+
↓
|
|
109
|
+
rerun
|
|
110
|
+
↓
|
|
111
|
+
report the result before completion
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Use `code-guard . --changed-only --json --json-mode compact` for a structured,
|
|
115
|
+
low-noise manual agent check. Hooks are optional, platform-owned, and require
|
|
116
|
+
user authorization; Code Guard does not install them. The
|
|
117
|
+
[workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) owns the complete manual and
|
|
118
|
+
hook-assisted process.
|
|
119
|
+
|
|
120
|
+
## Interpreting results
|
|
121
|
+
|
|
122
|
+
- **PASS** — no special action; exit `0`.
|
|
123
|
+
- **REVIEW** — inspect and decide whether genuine structural improvement is
|
|
124
|
+
warranted; normally exit `1`.
|
|
125
|
+
- **Completed FAIL** — blocks normal completion until fixed or an explicitly
|
|
126
|
+
authorized exception applies; exit `2` with a completed report on stdout.
|
|
127
|
+
- An argparse usage or invalid-choice error exits `2`, writes usage/error text
|
|
128
|
+
to stderr, and produces no completed report.
|
|
129
|
+
- Other Code Guard tool, configuration, scope, or provider errors exit `3`.
|
|
130
|
+
|
|
131
|
+
`--ci` makes REVIEW nonblocking at the process level by changing its exit to
|
|
132
|
+
`0`; it does not hide the findings or change FAIL and tool-error exits.
|
|
133
|
+
|
|
134
|
+
**Never game a metric.** Do not create artificial helpers, files,
|
|
135
|
+
abstractions, formatting, exclusions, or policy changes merely to lower a
|
|
136
|
+
measurement. A REVIEW is not proof of a defect or a mandatory refactor.
|
|
137
|
+
|
|
138
|
+
## Guard reference
|
|
139
|
+
|
|
140
|
+
| Guard | Default |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| File LOC | REVIEW >400, FAIL >600 |
|
|
143
|
+
| Callable size | REVIEW >80 physical LOC |
|
|
144
|
+
| Structural nesting | REVIEW >4 |
|
|
145
|
+
| Cyclomatic complexity | REVIEW >15 |
|
|
146
|
+
| Markdown document size | REVIEW >800 physical lines |
|
|
147
|
+
| Markdown direct-section size | REVIEW >200 physical lines |
|
|
148
|
+
|
|
149
|
+
Comparisons are strictly greater-than, so equality passes. All guards except
|
|
150
|
+
file LOC are REVIEW-only; only file LOC can FAIL. A new guard must provide
|
|
151
|
+
distinct, deterministic value rather than duplicate conventional tooling. See
|
|
152
|
+
[Guard admission](https://github.com/stef-k/agent-code-guard/blob/main/docs/guard-admission.md).
|
|
153
|
+
|
|
154
|
+
### Result and JSON reference
|
|
155
|
+
|
|
156
|
+
Every completed analysis reports selected, analyzed, inapplicable, and
|
|
157
|
+
all-guard-excluded file counts. Bare `--json` is the compatible full output;
|
|
158
|
+
`--json-mode debug` is byte-identical for the same completed invocation, while
|
|
159
|
+
`--json-mode compact` removes only normalized `pass` findings and retains the
|
|
160
|
+
result, scope, required policies, guards, ordering, and actionable findings.
|
|
161
|
+
Named modes require `--json`. See [Usage](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md) for the schema and
|
|
162
|
+
option contract.
|
|
163
|
+
|
|
164
|
+
### Common scope commands
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Current Git work
|
|
168
|
+
code-guard . --changed-only
|
|
169
|
+
|
|
170
|
+
# Pull request or branch comparison
|
|
171
|
+
code-guard . --base-ref origin/main --ci
|
|
172
|
+
|
|
173
|
+
# Deliberate full audit
|
|
174
|
+
code-guard .
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The base ref must exist in the chosen environment. Changed work is not a full
|
|
178
|
+
audit; do not repeatedly scan unrelated files after every edit.
|
|
179
|
+
|
|
180
|
+
### Supported languages and formats
|
|
181
|
+
|
|
182
|
+
Syntax guards support Python, Go, Kotlin, C#, Java, JavaScript, TypeScript, JSX,
|
|
183
|
+
TSX, Vue JavaScript/TypeScript script regions, C++, Rust, PHP, Swift, and Dart.
|
|
184
|
+
Markdown guards apply to `.md` files.
|
|
185
|
+
|
|
186
|
+
Generic `.h` files are not syntax-dispatched; `.markdown` is not enabled; Vue
|
|
187
|
+
template and style regions are not executable syntax input; and unsupported
|
|
188
|
+
artifacts are inapplicable. Malformed applicable syntax or a required provider
|
|
189
|
+
failure is a fail-closed tool error. See [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md).
|
|
190
|
+
|
|
191
|
+
### Skill integration
|
|
192
|
+
|
|
193
|
+
An installed distribution includes the matching Code Guard skill payload:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
code-guard --skill-path
|
|
197
|
+
code-guard --export-skill <target-directory>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Skill activation is platform-specific and is not performed by pipx or Code
|
|
201
|
+
Guard. See [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md). The checkout
|
|
202
|
+
compatibility runner is for repository development, not normal installation.
|
|
203
|
+
|
|
204
|
+
### Configuration
|
|
205
|
+
|
|
206
|
+
Built-in defaults require no configuration. Configure a project only for a
|
|
207
|
+
concrete policy reason; see the [configuration guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md).
|
|
208
|
+
The LOC baseline is an explicit adoption tool for established legacy
|
|
209
|
+
repositories, not an ordinary-use requirement or a way to silence findings.
|
|
210
|
+
|
|
211
|
+
## Trust, CI, and platform support
|
|
212
|
+
|
|
213
|
+
CI installs Agent Code Guard and analyzes its own real checkout. REVIEW findings
|
|
214
|
+
remain visible but non-blocking, while FAIL findings and tool errors block the
|
|
215
|
+
workflow; the repository intentionally uses no LOC baseline.
|
|
216
|
+
|
|
217
|
+
The maintained interpreter range is **CPython 3.10–3.14**. See
|
|
218
|
+
[Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md) for supported binary platforms and
|
|
219
|
+
source-build boundaries.
|
|
220
|
+
|
|
221
|
+
## Documentation
|
|
222
|
+
|
|
223
|
+
- [Documentation index](https://github.com/stef-k/agent-code-guard/blob/main/docs/README.md)
|
|
224
|
+
- [Agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
|
|
225
|
+
- [Usage and CLI reference](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md)
|
|
226
|
+
- [Configuration](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md)
|
|
227
|
+
- [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md)
|
|
228
|
+
- [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
|
|
229
|
+
- [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md)
|
|
230
|
+
|
|
231
|
+
## Feedback, security, and license
|
|
232
|
+
|
|
233
|
+
Report defects through the [bug report form](https://github.com/stef-k/agent-code-guard/issues/new?template=bug-report.md),
|
|
234
|
+
propose measurements through the [candidate guard form](https://github.com/stef-k/agent-code-guard/issues/new?template=candidate-guard.md),
|
|
235
|
+
and follow the [security policy](https://github.com/stef-k/agent-code-guard/blob/main/SECURITY.md) for vulnerabilities.
|
|
236
|
+
|
|
237
|
+
Agent Code Guard grew from the Agent LOC Guard prototype and is now the
|
|
238
|
+
canonical implementation. Licensed under the [MIT License](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE).
|
|
@@ -29,10 +29,12 @@ Code Guard provides deterministic measurements that act as anchors for agent jud
|
|
|
29
29
|
|
|
30
30
|
## Workflow
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
After each meaningful turn that edits supported source code or Markdown, run
|
|
33
|
+
the installed Code Guard command. In Git, prefer changed-work scope and compact
|
|
34
|
+
JSON when structured, low-noise output helps:
|
|
33
35
|
|
|
34
36
|
```bash
|
|
35
|
-
code-guard . --changed-only
|
|
37
|
+
code-guard . --changed-only --json --json-mode compact
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
An installed Agent Code Guard distribution provides both the command and this
|
|
@@ -53,10 +55,11 @@ grammar is a deterministic tool error during normal zero-config syntax analysis.
|
|
|
53
55
|
Disabling every syntax guard preserves the lazy no-Tree-sitter path. A strictly
|
|
54
56
|
LOC-only result also requires both Markdown guards to be explicitly disabled.
|
|
55
57
|
|
|
56
|
-
Without Git
|
|
58
|
+
Without Git, pass exactly the files you created or modified. You are
|
|
59
|
+
responsible for supplying the complete edited-file set:
|
|
57
60
|
|
|
58
61
|
```bash
|
|
59
|
-
code-guard src/Foo.py src/Bar.ts docs/guide.md
|
|
62
|
+
code-guard src/Foo.py src/Bar.ts docs/guide.md --json --json-mode compact
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
Do not create a manifest or temporary scope file. Specific positional files mean “inspect these artifacts.” A directory or `.` means a deliberate recursive audit when no Git selector is used. Positional files/directories bound the candidates selected by `--changed-only`, `--staged`, or `--base-ref`; Git selection fails outside a Git repository and never falls back to an audit.
|
|
@@ -72,7 +75,8 @@ project exclusions. LOC `--exclude` remains LOC-specific. Explicit files may
|
|
|
72
75
|
intentionally inspect Git-ignored or built-in-pruned artifacts, unless Code
|
|
73
76
|
Guard `scope.exclude` or `--scope-exclude` removes them.
|
|
74
77
|
|
|
75
|
-
When all guards return `PASS`, no detailed
|
|
78
|
+
Inspect every REVIEW and FAIL. When all guards return `PASS`, no detailed
|
|
79
|
+
policy file needs to be loaded.
|
|
76
80
|
|
|
77
81
|
When a guard returns `REVIEW` or `FAIL`, read only the policy file named by that finding. The runner returns required policy identifiers/files in both human-readable and JSON output.
|
|
78
82
|
|
|
@@ -86,6 +90,24 @@ Policy references:
|
|
|
86
90
|
|
|
87
91
|
Do not load unrelated guard policies merely because they exist.
|
|
88
92
|
|
|
93
|
+
After a genuine correction, rerun Code Guard. Report every accepted REVIEW
|
|
94
|
+
honestly with its justification, and run a final check over the complete
|
|
95
|
+
changed scope before declaring completion.
|
|
96
|
+
|
|
97
|
+
Agent Code Guard does not install or manage hooks. If the agent platform
|
|
98
|
+
supports a post-edit or post-turn hook, the user has authorized persistent
|
|
99
|
+
configuration, and visible output is retained, the hook may use:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
code-guard . --changed-only --ci --json --json-mode compact
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`--ci` makes REVIEW exit `0`, but REVIEW remains visible and requires
|
|
106
|
+
judgment; FAIL remains `2` and tool errors remain `3`. Outside Git, a hook
|
|
107
|
+
must supply the exact edited files. Do not install hooks, export into persistent
|
|
108
|
+
skill directories, or modify persistent user or repository configuration
|
|
109
|
+
without authorization.
|
|
110
|
+
|
|
89
111
|
## Scope
|
|
90
112
|
|
|
91
113
|
Code Guard is intentionally limited to deterministic concerns that are broadly applicable across conventional programming languages.
|