agent-code-guard 0.1.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.
Files changed (59) hide show
  1. agent_code_guard-0.3.0/PKG-INFO +276 -0
  2. agent_code_guard-0.3.0/README.md +262 -0
  3. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/pyproject.toml +1 -1
  4. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/SKILL.md +34 -9
  5. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/references/loc-policy.md +9 -0
  6. agent_code_guard-0.3.0/src/agent_code_guard/analysis/adapters.py +136 -0
  7. agent_code_guard-0.3.0/src/agent_code_guard/analysis/branch_normalization.py +195 -0
  8. agent_code_guard-0.3.0/src/agent_code_guard/analysis/callable_identity.py +329 -0
  9. agent_code_guard-0.3.0/src/agent_code_guard/analysis/csharp_compat.py +115 -0
  10. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/errors.py +4 -0
  11. agent_code_guard-0.3.0/src/agent_code_guard/analysis/pipeline.py +86 -0
  12. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/provider.py +5 -3
  13. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/regions.py +10 -3
  14. agent_code_guard-0.3.0/src/agent_code_guard/analysis/syntax_nodes.py +5 -0
  15. agent_code_guard-0.3.0/src/agent_code_guard/code_guard.py +491 -0
  16. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/config_validation.py +1 -0
  17. agent_code_guard-0.3.0/src/agent_code_guard/doctor.py +358 -0
  18. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/file_selection.py +5 -3
  19. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/loc.py +46 -5
  20. agent_code_guard-0.3.0/src/agent_code_guard/human_output.py +137 -0
  21. agent_code_guard-0.3.0/src/agent_code_guard/loc_baseline.py +297 -0
  22. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/result_model.py +8 -1
  23. agent_code_guard-0.3.0/src/agent_code_guard.egg-info/PKG-INFO +276 -0
  24. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard.egg-info/SOURCES.txt +7 -0
  25. agent_code_guard-0.1.0/PKG-INFO +0 -206
  26. agent_code_guard-0.1.0/README.md +0 -192
  27. agent_code_guard-0.1.0/src/agent_code_guard/analysis/adapters.py +0 -608
  28. agent_code_guard-0.1.0/src/agent_code_guard/analysis/pipeline.py +0 -37
  29. agent_code_guard-0.1.0/src/agent_code_guard/code_guard.py +0 -236
  30. agent_code_guard-0.1.0/src/agent_code_guard.egg-info/PKG-INFO +0 -206
  31. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/LICENSE +0 -0
  32. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/MANIFEST.in +0 -0
  33. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/setup.cfg +0 -0
  34. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/LICENSE.txt +0 -0
  35. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/agents/openai.yaml +0 -0
  36. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/references/callable-size-policy.md +0 -0
  37. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/references/complexity-policy.md +0 -0
  38. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/references/markdown-size-policy.md +0 -0
  39. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/skills/code-guard/references/nesting-policy.md +0 -0
  40. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/__init__.py +0 -0
  41. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/__init__.py +0 -0
  42. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/facts.py +0 -0
  43. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/analysis/language_specs.py +0 -0
  44. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/__init__.py +0 -0
  45. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/callable_size.py +0 -0
  46. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/complexity.py +0 -0
  47. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/markdown_document_size.py +0 -0
  48. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/markdown_section_size.py +0 -0
  49. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/guards/nesting.py +0 -0
  50. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/markdown/__init__.py +0 -0
  51. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/markdown/facts.py +0 -0
  52. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/markdown/scanner.py +0 -0
  53. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/path_matching.py +0 -0
  54. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/reporting.py +0 -0
  55. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard/skill_distribution.py +0 -0
  56. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard.egg-info/dependency_links.txt +0 -0
  57. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard.egg-info/entry_points.txt +0 -0
  58. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard.egg-info/requires.txt +0 -0
  59. {agent_code_guard-0.1.0 → agent_code_guard-0.3.0}/src/agent_code_guard.egg-info/top_level.txt +0 -0
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-code-guard
3
+ Version: 0.3.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
+ [![Production Analysis](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml/badge.svg)](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml)
25
+ [![PyPI](https://img.shields.io/pypi/v/agent-code-guard?logo=pypi&logoColor=white)](https://pypi.org/project/agent-code-guard/)
26
+ [![Python 3.10–3.14](https://img.shields.io/badge/Python-3.10%E2%80%933.14-3776AB?logo=python&logoColor=white)](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
27
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
+ > Adopt Agent Code Guard for this repository using the official project and
86
+ > documentation at https://github.com/stef-k/agent-code-guard. This prompt
87
+ > authorizes installing the published distribution in an isolated supported
88
+ > way, preferably with `pipx install agent-code-guard`, and persistently
89
+ > activating or exporting its installed, version-matched skill for the current
90
+ > agent environment. Verify `code-guard --version` and run `code-guard doctor`,
91
+ > then locate the skill with `code-guard --skill-path`. Follow the
92
+ > [skill activation guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md):
93
+ > activate that installed path when the platform supports it, or export it with
94
+ > `code-guard --export-skill <target-directory>` to the platform's documented
95
+ > skill directory. Do not guess a target or overwrite an existing export; verify
96
+ > that `.agent-code-guard-version` matches the installed distribution. Follow the
97
+ > [agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
98
+ > without creating a LOC baseline. After meaningful source or Markdown edits, run
99
+ > `code-guard . --changed-only --json --json-mode compact`; outside Git, pass the
100
+ > exact edited files. Inspect REVIEW and FAIL findings, make only genuine
101
+ > improvements, rerun the check, and report the result. Never weaken thresholds,
102
+ > exclusions, configuration, or baselines merely to silence findings. Code Guard
103
+ > does not install or enable hooks by default. Ask before configuring a post-edit
104
+ > or post-turn hook, or making unrelated persistent agent or platform changes.
105
+ > Finish by reporting the installed version, doctor status, activated skill
106
+ > location, first analysis result, and any REVIEW findings you accepted.
107
+
108
+ ## Five-minute start
109
+
110
+ From a Git worktree, inspect the current change:
111
+
112
+ ```bash
113
+ code-guard . --changed-only
114
+ ```
115
+
116
+ Git supplies the changed candidates; every enabled and applicable guard runs.
117
+ No configuration is needed. A REVIEW asks for inspection and judgment, not an
118
+ automatic refactor. Outside Git, pass the exact edited files instead, such as
119
+ `code-guard src/app.py docs/guide.md`.
120
+
121
+ See the [agent workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) for repeated human and
122
+ agent use.
123
+
124
+ ## Recommended workflow
125
+
126
+ ```text
127
+ edit supported code or Markdown
128
+
129
+ run Code Guard on changed scope
130
+
131
+ PASS → continue
132
+ REVIEW → inspect, justify or genuinely improve
133
+ FAIL → fix or obtain an explicitly authorized exception
134
+
135
+ rerun
136
+
137
+ report the result before completion
138
+ ```
139
+
140
+ Use `code-guard . --changed-only --json --json-mode compact` for a structured,
141
+ low-noise manual agent check. Hooks are optional, platform-owned, and require
142
+ user authorization; Code Guard does not install them. The
143
+ [workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) owns the complete manual and
144
+ hook-assisted process.
145
+
146
+ ## Interpreting results
147
+
148
+ - **PASS** — no special action; exit `0`.
149
+ - **REVIEW** — inspect and decide whether genuine structural improvement is
150
+ warranted; normally exit `1`.
151
+ - **Completed FAIL** — blocks normal completion until fixed or an explicitly
152
+ authorized exception applies; exit `2` with a completed report on stdout.
153
+ - **INCOMPLETE** — one or more requested syntax analyses are unavailable;
154
+ independent completed findings remain authoritative, but the run exits `3`.
155
+ - An argparse usage or invalid-choice error exits `2`, writes usage/error text
156
+ to stderr, and produces no completed report.
157
+ - Other Code Guard tool, configuration, scope, or unexpected errors exit `3`.
158
+
159
+ `--ci` makes REVIEW nonblocking at the process level by changing its exit to
160
+ `0`; it does not hide findings or change FAIL, INCOMPLETE, and tool-error exits.
161
+
162
+ **Never game a metric.** Do not create artificial helpers, files,
163
+ abstractions, formatting, exclusions, or policy changes merely to lower a
164
+ measurement. A REVIEW is not proof of a defect or a mandatory refactor.
165
+
166
+ ## Guard reference
167
+
168
+ | Guard | Default |
169
+ | --- | --- |
170
+ | File LOC | REVIEW >400, FAIL >600 |
171
+ | Callable size | REVIEW >80 physical LOC |
172
+ | Structural nesting | REVIEW >4 |
173
+ | Cyclomatic complexity | REVIEW >15 |
174
+ | Markdown document size | REVIEW >800 physical lines |
175
+ | Markdown direct-section size | REVIEW >200 physical lines |
176
+
177
+ Comparisons are strictly greater-than, so equality passes. All guards except
178
+ file LOC are REVIEW-only; only file LOC can FAIL. A new guard must provide
179
+ distinct, deterministic value rather than duplicate conventional tooling. See
180
+ [Guard admission](https://github.com/stef-k/agent-code-guard/blob/main/docs/guard-admission.md).
181
+
182
+ ### Result and JSON reference
183
+
184
+ Every completed analysis reports selected, analyzed, inapplicable, and
185
+ all-guard-excluded file counts. Bare `--json` is the compatible full output;
186
+ `--json-mode debug` is byte-identical for the same completed invocation, while
187
+ `--json-mode compact` removes only normalized `pass` findings and retains the
188
+ result, scope, required policies, guards, ordering, and actionable findings.
189
+ Named modes require `--json`. See [Usage](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md) for the schema and
190
+ option contract.
191
+
192
+ Known per-file syntax or provider failures instead produce `overall:
193
+ "incomplete"`, ordered structured `unavailable` records, and completed guard
194
+ evidence. Syntax guards identify unavailable paths; LOC and Markdown remain
195
+ complete. Full, debug, and compact JSON retain unavailable records unchanged,
196
+ and completed runs retain their existing schema.
197
+
198
+ ### Common scope commands
199
+
200
+ ```bash
201
+ # Current Git work
202
+ code-guard . --changed-only
203
+
204
+ # Pull request or branch comparison
205
+ code-guard . --base-ref origin/main --ci
206
+
207
+ # Deliberate full audit
208
+ code-guard .
209
+ ```
210
+
211
+ The base ref must exist in the chosen environment. Changed work is not a full
212
+ audit; do not repeatedly scan unrelated files after every edit.
213
+
214
+ ### Supported languages and formats
215
+
216
+ Syntax guards support Python, Go, Kotlin, C#, Java, JavaScript, TypeScript, JSX,
217
+ TSX, Vue JavaScript/TypeScript script regions, C++, Rust, PHP, Swift, and Dart.
218
+ Markdown guards apply to `.md` files.
219
+
220
+ Generic `.h` files are not syntax-dispatched; `.markdown` is not enabled; Vue
221
+ template and style regions are not executable syntax input; and unsupported
222
+ artifacts are inapplicable. Malformed applicable syntax or a required provider
223
+ failure is unavailable evidence, distinct from both an inapplicable file and a
224
+ completed FAIL finding. See [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md).
225
+
226
+ ### Skill integration
227
+
228
+ An installed distribution includes the matching Code Guard skill payload:
229
+
230
+ ```bash
231
+ code-guard --skill-path
232
+ code-guard --export-skill <target-directory>
233
+ ```
234
+
235
+ Skill activation is platform-specific and is not performed by pipx or Code
236
+ Guard. See [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md). The checkout
237
+ compatibility runner is for repository development, not normal installation.
238
+
239
+ ### Configuration
240
+
241
+ Built-in defaults require no configuration. Configure a project only for a
242
+ concrete policy reason; see the [configuration guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md).
243
+ The LOC baseline is an explicit adoption tool for established legacy
244
+ repositories, not an ordinary-use requirement or a way to silence findings.
245
+ Its default `ratchetAt: "fail"` policy freezes files above `failAt`; choose
246
+ `ratchetAt: "review"` only when every established file above `warnAt` must be
247
+ non-increasing while ordinary findings in that range remain REVIEW.
248
+
249
+ ## Trust, CI, and platform support
250
+
251
+ CI installs Agent Code Guard and analyzes its own real checkout. REVIEW findings
252
+ remain visible but non-blocking, while FAIL findings and tool errors block the
253
+ workflow; the repository intentionally uses no LOC baseline.
254
+
255
+ The maintained interpreter range is **CPython 3.10–3.14**. See
256
+ [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md) for supported binary platforms and
257
+ source-build boundaries.
258
+
259
+ ## Documentation
260
+
261
+ - [Documentation index](https://github.com/stef-k/agent-code-guard/blob/main/docs/README.md)
262
+ - [Agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
263
+ - [Usage and CLI reference](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md)
264
+ - [Configuration](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md)
265
+ - [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md)
266
+ - [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
267
+ - [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md)
268
+
269
+ ## Feedback, security, and license
270
+
271
+ Report defects through the [bug report form](https://github.com/stef-k/agent-code-guard/issues/new?template=bug-report.md),
272
+ propose measurements through the [candidate guard form](https://github.com/stef-k/agent-code-guard/issues/new?template=candidate-guard.md),
273
+ and follow the [security policy](https://github.com/stef-k/agent-code-guard/blob/main/SECURITY.md) for vulnerabilities.
274
+
275
+ Agent Code Guard grew from the Agent LOC Guard prototype and is now the
276
+ canonical implementation. Licensed under the [MIT License](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE).
@@ -0,0 +1,262 @@
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
+ [![Production Analysis](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml/badge.svg)](https://github.com/stef-k/agent-code-guard/actions/workflows/analysis.yml)
11
+ [![PyPI](https://img.shields.io/pypi/v/agent-code-guard?logo=pypi&logoColor=white)](https://pypi.org/project/agent-code-guard/)
12
+ [![Python 3.10–3.14](https://img.shields.io/badge/Python-3.10%E2%80%933.14-3776AB?logo=python&logoColor=white)](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
+ > Adopt Agent Code Guard for this repository using the official project and
72
+ > documentation at https://github.com/stef-k/agent-code-guard. This prompt
73
+ > authorizes installing the published distribution in an isolated supported
74
+ > way, preferably with `pipx install agent-code-guard`, and persistently
75
+ > activating or exporting its installed, version-matched skill for the current
76
+ > agent environment. Verify `code-guard --version` and run `code-guard doctor`,
77
+ > then locate the skill with `code-guard --skill-path`. Follow the
78
+ > [skill activation guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md):
79
+ > activate that installed path when the platform supports it, or export it with
80
+ > `code-guard --export-skill <target-directory>` to the platform's documented
81
+ > skill directory. Do not guess a target or overwrite an existing export; verify
82
+ > that `.agent-code-guard-version` matches the installed distribution. Follow the
83
+ > [agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
84
+ > without creating a LOC baseline. After meaningful source or Markdown edits, run
85
+ > `code-guard . --changed-only --json --json-mode compact`; outside Git, pass the
86
+ > exact edited files. Inspect REVIEW and FAIL findings, make only genuine
87
+ > improvements, rerun the check, and report the result. Never weaken thresholds,
88
+ > exclusions, configuration, or baselines merely to silence findings. Code Guard
89
+ > does not install or enable hooks by default. Ask before configuring a post-edit
90
+ > or post-turn hook, or making unrelated persistent agent or platform changes.
91
+ > Finish by reporting the installed version, doctor status, activated skill
92
+ > location, first analysis result, and any REVIEW findings you accepted.
93
+
94
+ ## Five-minute start
95
+
96
+ From a Git worktree, inspect the current change:
97
+
98
+ ```bash
99
+ code-guard . --changed-only
100
+ ```
101
+
102
+ Git supplies the changed candidates; every enabled and applicable guard runs.
103
+ No configuration is needed. A REVIEW asks for inspection and judgment, not an
104
+ automatic refactor. Outside Git, pass the exact edited files instead, such as
105
+ `code-guard src/app.py docs/guide.md`.
106
+
107
+ See the [agent workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) for repeated human and
108
+ agent use.
109
+
110
+ ## Recommended workflow
111
+
112
+ ```text
113
+ edit supported code or Markdown
114
+
115
+ run Code Guard on changed scope
116
+
117
+ PASS → continue
118
+ REVIEW → inspect, justify or genuinely improve
119
+ FAIL → fix or obtain an explicitly authorized exception
120
+
121
+ rerun
122
+
123
+ report the result before completion
124
+ ```
125
+
126
+ Use `code-guard . --changed-only --json --json-mode compact` for a structured,
127
+ low-noise manual agent check. Hooks are optional, platform-owned, and require
128
+ user authorization; Code Guard does not install them. The
129
+ [workflow guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md) owns the complete manual and
130
+ hook-assisted process.
131
+
132
+ ## Interpreting results
133
+
134
+ - **PASS** — no special action; exit `0`.
135
+ - **REVIEW** — inspect and decide whether genuine structural improvement is
136
+ warranted; normally exit `1`.
137
+ - **Completed FAIL** — blocks normal completion until fixed or an explicitly
138
+ authorized exception applies; exit `2` with a completed report on stdout.
139
+ - **INCOMPLETE** — one or more requested syntax analyses are unavailable;
140
+ independent completed findings remain authoritative, but the run exits `3`.
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 unexpected errors exit `3`.
144
+
145
+ `--ci` makes REVIEW nonblocking at the process level by changing its exit to
146
+ `0`; it does not hide findings or change FAIL, INCOMPLETE, 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
+ Known per-file syntax or provider failures instead produce `overall:
179
+ "incomplete"`, ordered structured `unavailable` records, and completed guard
180
+ evidence. Syntax guards identify unavailable paths; LOC and Markdown remain
181
+ complete. Full, debug, and compact JSON retain unavailable records unchanged,
182
+ and completed runs retain their existing schema.
183
+
184
+ ### Common scope commands
185
+
186
+ ```bash
187
+ # Current Git work
188
+ code-guard . --changed-only
189
+
190
+ # Pull request or branch comparison
191
+ code-guard . --base-ref origin/main --ci
192
+
193
+ # Deliberate full audit
194
+ code-guard .
195
+ ```
196
+
197
+ The base ref must exist in the chosen environment. Changed work is not a full
198
+ audit; do not repeatedly scan unrelated files after every edit.
199
+
200
+ ### Supported languages and formats
201
+
202
+ Syntax guards support Python, Go, Kotlin, C#, Java, JavaScript, TypeScript, JSX,
203
+ TSX, Vue JavaScript/TypeScript script regions, C++, Rust, PHP, Swift, and Dart.
204
+ Markdown guards apply to `.md` files.
205
+
206
+ Generic `.h` files are not syntax-dispatched; `.markdown` is not enabled; Vue
207
+ template and style regions are not executable syntax input; and unsupported
208
+ artifacts are inapplicable. Malformed applicable syntax or a required provider
209
+ failure is unavailable evidence, distinct from both an inapplicable file and a
210
+ completed FAIL finding. See [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md).
211
+
212
+ ### Skill integration
213
+
214
+ An installed distribution includes the matching Code Guard skill payload:
215
+
216
+ ```bash
217
+ code-guard --skill-path
218
+ code-guard --export-skill <target-directory>
219
+ ```
220
+
221
+ Skill activation is platform-specific and is not performed by pipx or Code
222
+ Guard. See [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md). The checkout
223
+ compatibility runner is for repository development, not normal installation.
224
+
225
+ ### Configuration
226
+
227
+ Built-in defaults require no configuration. Configure a project only for a
228
+ concrete policy reason; see the [configuration guide](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md).
229
+ The LOC baseline is an explicit adoption tool for established legacy
230
+ repositories, not an ordinary-use requirement or a way to silence findings.
231
+ Its default `ratchetAt: "fail"` policy freezes files above `failAt`; choose
232
+ `ratchetAt: "review"` only when every established file above `warnAt` must be
233
+ non-increasing while ordinary findings in that range remain REVIEW.
234
+
235
+ ## Trust, CI, and platform support
236
+
237
+ CI installs Agent Code Guard and analyzes its own real checkout. REVIEW findings
238
+ remain visible but non-blocking, while FAIL findings and tool errors block the
239
+ workflow; the repository intentionally uses no LOC baseline.
240
+
241
+ The maintained interpreter range is **CPython 3.10–3.14**. See
242
+ [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md) for supported binary platforms and
243
+ source-build boundaries.
244
+
245
+ ## Documentation
246
+
247
+ - [Documentation index](https://github.com/stef-k/agent-code-guard/blob/main/docs/README.md)
248
+ - [Agent workflow](https://github.com/stef-k/agent-code-guard/blob/main/docs/agent-workflow.md)
249
+ - [Usage and CLI reference](https://github.com/stef-k/agent-code-guard/blob/main/docs/usage.md)
250
+ - [Configuration](https://github.com/stef-k/agent-code-guard/blob/main/docs/configuration.md)
251
+ - [Language support](https://github.com/stef-k/agent-code-guard/blob/main/docs/language-support.md)
252
+ - [Platform support](https://github.com/stef-k/agent-code-guard/blob/main/docs/platform-support.md)
253
+ - [Skill distribution](https://github.com/stef-k/agent-code-guard/blob/main/docs/skill-distribution.md)
254
+
255
+ ## Feedback, security, and license
256
+
257
+ Report defects through the [bug report form](https://github.com/stef-k/agent-code-guard/issues/new?template=bug-report.md),
258
+ propose measurements through the [candidate guard form](https://github.com/stef-k/agent-code-guard/issues/new?template=candidate-guard.md),
259
+ and follow the [security policy](https://github.com/stef-k/agent-code-guard/blob/main/SECURITY.md) for vulnerabilities.
260
+
261
+ Agent Code Guard grew from the Agent LOC Guard prototype and is now the
262
+ canonical implementation. Licensed under the [MIT License](https://github.com/stef-k/agent-code-guard/blob/main/LICENSE).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "agent-code-guard"
7
- version = "0.1.0"
7
+ version = "0.3.0"
8
8
  description = "Deterministic cross-language guardrails for agent-assisted development"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -15,6 +15,7 @@ Code Guard provides deterministic measurements that act as anchors for agent jud
15
15
  - `PASS` — no special action is required.
16
16
  - `REVIEW` — inspect the finding and either accept it with a meaningful justification or improve the code when doing so improves real clarity, cohesion, or boundaries.
17
17
  - `FAIL` — do not declare normal completion until the condition is fixed or an explicitly permitted/user-approved exception applies.
18
+ - `INCOMPLETE` — known per-file syntax or provider evidence is unavailable; retain and report independent completed evidence, but do not declare normal completion.
18
19
 
19
20
  ## Universal rules
20
21
 
@@ -29,10 +30,12 @@ Code Guard provides deterministic measurements that act as anchors for agent jud
29
30
 
30
31
  ## Workflow
31
32
 
32
- With Git, run the installed Code Guard command after supported code or Markdown documentation edits:
33
+ After each meaningful turn that edits supported source code or Markdown, run
34
+ the installed Code Guard command. In Git, prefer changed-work scope and compact
35
+ JSON when structured, low-noise output helps:
33
36
 
34
37
  ```bash
35
- code-guard . --changed-only
38
+ code-guard . --changed-only --json --json-mode compact
36
39
  ```
37
40
 
38
41
  An installed Agent Code Guard distribution provides both the command and this
@@ -48,15 +51,17 @@ python3 skills/code-guard/scripts/code_guard.py . --changed-only
48
51
  ```
49
52
 
50
53
  `pyproject.toml` canonically owns the production pins. Tree-sitter remains
51
- dormant during LOC-only execution; failure to load a required provider or
52
- grammar is a deterministic tool error during normal zero-config syntax analysis.
53
- Disabling every syntax guard preserves the lazy no-Tree-sitter path. A strictly
54
- LOC-only result also requires both Markdown guards to be explicitly disabled.
54
+ dormant during LOC-only execution. A known per-file provider, grammar, or syntax
55
+ failure produces blocking `INCOMPLETE` output while retaining independent LOC,
56
+ Markdown, and unaffected syntax evidence. Disabling every syntax guard preserves
57
+ the lazy no-Tree-sitter path. A strictly LOC-only result also requires both
58
+ Markdown guards to be explicitly disabled.
55
59
 
56
- Without Git or another VCS that can provide changed scope, pass exactly the files you created or modified. You are responsible for supplying the complete edited-file set:
60
+ Without Git, pass exactly the files you created or modified. You are
61
+ responsible for supplying the complete edited-file set:
57
62
 
58
63
  ```bash
59
- code-guard src/Foo.py src/Bar.ts docs/guide.md
64
+ code-guard src/Foo.py src/Bar.ts docs/guide.md --json --json-mode compact
60
65
  ```
61
66
 
62
67
  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 +77,9 @@ project exclusions. LOC `--exclude` remains LOC-specific. Explicit files may
72
77
  intentionally inspect Git-ignored or built-in-pruned artifacts, unless Code
73
78
  Guard `scope.exclude` or `--scope-exclude` removes them.
74
79
 
75
- When all guards return `PASS`, no detailed policy file needs to be loaded.
80
+ Inspect every REVIEW and FAIL. Treat INCOMPLETE as blocking, preserve its
81
+ completed findings, and report its unavailable paths and failure context. When
82
+ all guards return `PASS`, no detailed policy file needs to be loaded.
76
83
 
77
84
  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
85
 
@@ -86,6 +93,24 @@ Policy references:
86
93
 
87
94
  Do not load unrelated guard policies merely because they exist.
88
95
 
96
+ After a genuine correction, rerun Code Guard. Report every accepted REVIEW
97
+ honestly with its justification, and run a final check over the complete
98
+ changed scope before declaring completion.
99
+
100
+ Agent Code Guard does not install or manage hooks. If the agent platform
101
+ supports a post-edit or post-turn hook, the user has authorized persistent
102
+ configuration, and visible output is retained, the hook may use:
103
+
104
+ ```bash
105
+ code-guard . --changed-only --ci --json --json-mode compact
106
+ ```
107
+
108
+ `--ci` makes REVIEW exit `0`, but REVIEW remains visible and requires
109
+ judgment; FAIL remains `2`, and INCOMPLETE and tool errors remain `3`. Outside
110
+ Git, a hook must supply the exact edited files. Do not install hooks, export
111
+ into persistent skill directories, or modify persistent user or repository
112
+ configuration without authorization.
113
+
89
114
  ## Scope
90
115
 
91
116
  Code Guard is intentionally limited to deterministic concerns that are broadly applicable across conventional programming languages.
@@ -27,6 +27,15 @@ Existing `allowedLargeFiles` entries may be honored with their configured reason
27
27
 
28
28
  Do not infer approval from inconvenience, historical size, a nearby exemption, time pressure, or a request to finish the coding task.
29
29
 
30
+ ## Source-controlled ratchets
31
+
32
+ An established repository may use `guards.loc.ratchetAt: "fail"` (the default)
33
+ to freeze only files already above `failAt`, or `"review"` to freeze every
34
+ recorded file above `warnAt` while retaining ordinary REVIEW semantics within
35
+ its allowance. Growth above a recorded allowance is always FAIL. Never switch
36
+ the policy, raise thresholds, add exclusions or exemptions, or increase/remove
37
+ allowances merely to silence growth.
38
+
30
39
  ## Do not game LOC
31
40
 
32
41
  Project formatting conventions take priority. Never combine independent statements, compress control flow or expressions unusually, minify handwritten code, remove useful comments/structure, or fight the formatter merely to lower physical LOC.