kragg 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 (68) hide show
  1. kragg-0.3.0/.gitignore +28 -0
  2. kragg-0.3.0/.kragg/mutants.baseline +65 -0
  3. kragg-0.3.0/.python-version +1 -0
  4. kragg-0.3.0/AGENTS.md +134 -0
  5. kragg-0.3.0/CRITICALITY.md +37 -0
  6. kragg-0.3.0/LICENSE +21 -0
  7. kragg-0.3.0/PKG-INFO +189 -0
  8. kragg-0.3.0/README.md +152 -0
  9. kragg-0.3.0/pyproject.toml +121 -0
  10. kragg-0.3.0/src/kragg/__init__.py +5 -0
  11. kragg-0.3.0/src/kragg/__main__.py +4 -0
  12. kragg-0.3.0/src/kragg/brief.py +127 -0
  13. kragg-0.3.0/src/kragg/catalog.py +456 -0
  14. kragg-0.3.0/src/kragg/changes.py +81 -0
  15. kragg-0.3.0/src/kragg/check.py +82 -0
  16. kragg-0.3.0/src/kragg/cli.py +150 -0
  17. kragg-0.3.0/src/kragg/commands.py +464 -0
  18. kragg-0.3.0/src/kragg/coverage.py +162 -0
  19. kragg-0.3.0/src/kragg/critical.py +108 -0
  20. kragg-0.3.0/src/kragg/environment.py +165 -0
  21. kragg-0.3.0/src/kragg/flaky.py +143 -0
  22. kragg-0.3.0/src/kragg/gates/__init__.py +1 -0
  23. kragg-0.3.0/src/kragg/gates/architecture.py +121 -0
  24. kragg-0.3.0/src/kragg/gates/critical_coverage.py +43 -0
  25. kragg-0.3.0/src/kragg/gates/critical_tests.py +120 -0
  26. kragg-0.3.0/src/kragg/gates/criticality.py +451 -0
  27. kragg-0.3.0/src/kragg/gates/halstead.py +80 -0
  28. kragg-0.3.0/src/kragg/gates/secrets.py +86 -0
  29. kragg-0.3.0/src/kragg/gates/test_quality.py +129 -0
  30. kragg-0.3.0/src/kragg/gates/type_complexity.py +171 -0
  31. kragg-0.3.0/src/kragg/hooks.py +168 -0
  32. kragg-0.3.0/src/kragg/journal.py +156 -0
  33. kragg-0.3.0/src/kragg/mapping.py +127 -0
  34. kragg-0.3.0/src/kragg/models.py +78 -0
  35. kragg-0.3.0/src/kragg/mutation.py +392 -0
  36. kragg-0.3.0/src/kragg/parsers.py +181 -0
  37. kragg-0.3.0/src/kragg/policy.py +105 -0
  38. kragg-0.3.0/src/kragg/py.typed +0 -0
  39. kragg-0.3.0/src/kragg/report.py +336 -0
  40. kragg-0.3.0/src/kragg/runner.py +26 -0
  41. kragg-0.3.0/src/kragg/scaffold.py +409 -0
  42. kragg-0.3.0/src/kragg/spec.py +177 -0
  43. kragg-0.3.0/src/kragg/templates.py +267 -0
  44. kragg-0.3.0/tests/test_architecture.py +98 -0
  45. kragg-0.3.0/tests/test_brief.py +87 -0
  46. kragg-0.3.0/tests/test_changes.py +123 -0
  47. kragg-0.3.0/tests/test_check_pipeline.py +58 -0
  48. kragg-0.3.0/tests/test_cli.py +296 -0
  49. kragg-0.3.0/tests/test_coverage.py +110 -0
  50. kragg-0.3.0/tests/test_critical.py +125 -0
  51. kragg-0.3.0/tests/test_critical_coverage.py +66 -0
  52. kragg-0.3.0/tests/test_critical_tests.py +93 -0
  53. kragg-0.3.0/tests/test_criticality.py +100 -0
  54. kragg-0.3.0/tests/test_environment.py +162 -0
  55. kragg-0.3.0/tests/test_flaky.py +174 -0
  56. kragg-0.3.0/tests/test_hooks.py +178 -0
  57. kragg-0.3.0/tests/test_journal.py +63 -0
  58. kragg-0.3.0/tests/test_mapping.py +76 -0
  59. kragg-0.3.0/tests/test_mutation.py +294 -0
  60. kragg-0.3.0/tests/test_parsers.py +152 -0
  61. kragg-0.3.0/tests/test_policy.py +70 -0
  62. kragg-0.3.0/tests/test_report.py +221 -0
  63. kragg-0.3.0/tests/test_scaffold.py +141 -0
  64. kragg-0.3.0/tests/test_secrets.py +23 -0
  65. kragg-0.3.0/tests/test_spec.py +120 -0
  66. kragg-0.3.0/tests/test_test_quality.py +99 -0
  67. kragg-0.3.0/tests/test_type_complexity.py +13 -0
  68. kragg-0.3.0/uv.lock +1734 -0
kragg-0.3.0/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+
9
+ # tooling
10
+ .pytest_cache/
11
+ .coverage
12
+ htmlcov/
13
+ .mypy_cache/
14
+ .ruff_cache/
15
+ .hypothesis/
16
+
17
+ # env
18
+ .env
19
+ .env.*
20
+ !.env.example
21
+
22
+ # OS
23
+ .DS_Store
24
+
25
+ # kragg local artifacts (journal, coverage, criticality, mutation sessions)
26
+ .kragg/*
27
+ # ...but the reviewed equivalent-mutant baseline is meant to be committed
28
+ !.kragg/mutants.baseline
@@ -0,0 +1,65 @@
1
+ [
2
+ "src/kragg/changes.py::core/ExceptionReplacer::0",
3
+ "src/kragg/changes.py::core/ReplaceComparisonOperator_Eq_Gt::0",
4
+ "src/kragg/changes.py::core/ReplaceComparisonOperator_Eq_GtE::0",
5
+ "src/kragg/changes.py::core/ReplaceComparisonOperator_Eq_Is::0",
6
+ "src/kragg/critical.py::core/NumberReplacer::3",
7
+ "src/kragg/critical.py::core/NumberReplacer::4",
8
+ "src/kragg/critical.py::core/NumberReplacer::5",
9
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_Add::0",
10
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_BitOr::0",
11
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_BitXor::0",
12
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_FloorDiv::0",
13
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_LShift::0",
14
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_Mul::0",
15
+ "src/kragg/critical.py::core/ReplaceBinaryOperator_Sub_Pow::0",
16
+ "src/kragg/critical.py::core/ReplaceTrueWithFalse::0",
17
+ "src/kragg/report.py::core/ExceptionReplacer::0",
18
+ "src/kragg/report.py::core/NumberReplacer::10",
19
+ "src/kragg/report.py::core/NumberReplacer::11",
20
+ "src/kragg/report.py::core/NumberReplacer::12",
21
+ "src/kragg/report.py::core/NumberReplacer::13",
22
+ "src/kragg/report.py::core/NumberReplacer::14",
23
+ "src/kragg/report.py::core/NumberReplacer::15",
24
+ "src/kragg/report.py::core/NumberReplacer::17",
25
+ "src/kragg/report.py::core/NumberReplacer::30",
26
+ "src/kragg/report.py::core/NumberReplacer::31",
27
+ "src/kragg/report.py::core/NumberReplacer::32",
28
+ "src/kragg/report.py::core/NumberReplacer::33",
29
+ "src/kragg/report.py::core/ReplaceAndWithOr::0",
30
+ "src/kragg/report.py::core/ReplaceAndWithOr::1",
31
+ "src/kragg/report.py::core/ReplaceAndWithOr::2",
32
+ "src/kragg/report.py::core/ReplaceAndWithOr::5",
33
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_Add::0",
34
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_BitAnd::0",
35
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_BitOr::0",
36
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_BitXor::0",
37
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_FloorDiv::0",
38
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_LShift::0",
39
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_Mod::0",
40
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_Mul::0",
41
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_Pow::0",
42
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_RShift::0",
43
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Div_Sub::0",
44
+ "src/kragg/report.py::core/ReplaceBinaryOperator_Sub_RShift::2",
45
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Eq_LtE::0",
46
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_Eq::1",
47
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_GtE::0",
48
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_GtE::1",
49
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_Is::1",
50
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_IsNot::0",
51
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Gt_NotEq::0",
52
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Lt_IsNot::0",
53
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Lt_LtE::0",
54
+ "src/kragg/report.py::core/ReplaceComparisonOperator_Lt_NotEq::0",
55
+ "src/kragg/report.py::core/ReplaceTrueWithFalse::0",
56
+ "src/kragg/report.py::core/ReplaceTrueWithFalse::1",
57
+ "src/kragg/report.py::core/ReplaceUnaryOperator_Delete_USub::0",
58
+ "src/kragg/report.py::core/ReplaceUnaryOperator_Delete_USub::1",
59
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_Invert::0",
60
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_Invert::1",
61
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_Not::0",
62
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_Not::1",
63
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_UAdd::0",
64
+ "src/kragg/report.py::core/ReplaceUnaryOperator_USub_UAdd::1"
65
+ ]
@@ -0,0 +1 @@
1
+ 3.12
kragg-0.3.0/AGENTS.md ADDED
@@ -0,0 +1,134 @@
1
+ # AGENTS.md
2
+
3
+ ## Mission
4
+
5
+ This repository builds `kragg`, an opinionated Python guardrails framework and CLI for AI-assisted Python projects. Optimize changes for correctness, safety, and minimal disruption to the public CLI/package behavior.
6
+
7
+ ## Priority Order
8
+
9
+ When tradeoffs conflict, use this order:
10
+
11
+ 1. Correctness.
12
+ 2. Data safety.
13
+ 3. Minimal diff.
14
+ 4. Existing project conventions.
15
+ 5. Performance.
16
+ 6. Elegance.
17
+
18
+ Do not optimize for elegance by expanding scope. Do not optimize for performance unless the task is performance-related or a measured bottleneck exists.
19
+
20
+ ## Operating Rules
21
+
22
+ - Do exactly what the user asked.
23
+ - Prefer small, local changes.
24
+ - Prefer modifying existing functions over adding helper layers when the change is local.
25
+ - Preserve existing architecture unless explicitly asked to change it.
26
+ - Read nearby code before editing.
27
+ - Match existing naming, structure, typing, and error-handling patterns.
28
+ - Do not refactor unrelated code.
29
+ - Do not rewrite unrelated files.
30
+ - Do not reformat untouched files.
31
+ - Preserve public APIs and CLI behavior unless the task explicitly requires changing them.
32
+ - Do not introduce new abstractions unless they remove duplicated behavior in the changed files.
33
+ - Do not introduce new dependencies without explicit user approval.
34
+ - When blocked, report the blocker and propose the smallest next step.
35
+
36
+ ## Project Map
37
+
38
+ - `src/kragg/cli.py`: CLI argument parsing and dispatch.
39
+ - `src/kragg/commands.py`: command handlers behind each subcommand.
40
+ - `src/kragg/scaffold.py`: generated project files and initialization logic.
41
+ - `src/kragg/gates/`: built-in guardrail checks for complexity, type/architecture constraints, secrets, criticality, and test quality/coverage.
42
+ - `src/kragg/policy.py`: `kragg.toml` / `[tool.kragg]` policy loading and defaults.
43
+ - `src/kragg/models.py`: shared result/context data types.
44
+ - `src/kragg/runner.py`: external command execution wrapper.
45
+ - `src/kragg/environment.py`: project-interpreter resolution for environment-dependent tools (pytest, mypy, pip-audit, deptry).
46
+ - `src/kragg/check.py`: gate pipeline engine (GateSpec, run_gates, fast/slow tiers).
47
+ - `src/kragg/catalog.py`: assembles the concrete check/security pipelines from the gates.
48
+ - `src/kragg/parsers.py`: tool output parsers producing structured violations.
49
+ - `src/kragg/report.py`: consolidated reports, JSON schema, text rendering, exit codes.
50
+ - `src/kragg/critical.py`: resolves public critical functions to source file + coverage key; shared by coverage and mutation surfaces.
51
+ - `src/kragg/coverage.py`: reads coverage.py JSON, surfaces criticality-ranked coverage gaps (`kragg coverage`).
52
+ - `src/kragg/mutation.py`: targeted mutation testing via cosmic-ray over changed critical files (`kragg mutation`).
53
+ - `src/kragg/spec.py`: extracts the test suite's name/docstring tree and flags critical functions lacking property-based tests (`kragg spec`).
54
+ - `src/kragg/changes.py`: git-based changed-file detection plus HEAD sha and dirty-tree metadata.
55
+ - `src/kragg/flaky.py`: flaky detection — passive journal mining and active suite reruns (`kragg flaky [--rerun N]`).
56
+ - `src/kragg/journal.py`: `.kragg/history.jsonl` run journal backing `kragg status`.
57
+ - `src/kragg/hooks.py`: harness hook adapters (`kragg hook claude`).
58
+ - `src/kragg/mapping.py`: public-symbol inventory backing `kragg map`.
59
+ - `src/kragg/brief.py`: reviewable change digest backing `kragg brief`.
60
+ - `src/kragg/templates.py`: generated source for project kinds and `kragg gen module`.
61
+ - `tests/`: focused unit and CLI tests.
62
+ - `pyproject.toml`: package metadata, CLI entry point, dependencies, and tool configuration.
63
+
64
+ Update this section when the repo structure changes.
65
+
66
+ ## Commands
67
+
68
+ - Install: `uv sync`
69
+ - Run CLI: `uv run kragg --help`
70
+ - Test: `uv run pytest`
71
+ - Typecheck: `uv run mypy src tests`
72
+ - Lint: `uv run ruff check src tests`
73
+ - Format check: `uv run ruff format --check src tests`
74
+ - Format: `uv run ruff format src tests`
75
+ - Focused guardrail check: `uv run kragg check --file <path>`
76
+ - Coverage gaps / spec / flaky: `uv run kragg coverage`, `uv run kragg spec`, `uv run kragg flaky`
77
+ - Mutation test (on-demand, slow; needs cosmic-ray): `uv run kragg mutation --all`
78
+
79
+ Use the narrowest relevant command first. Run broader validation before claiming completion when practical.
80
+
81
+ ## Code Standards
82
+
83
+ - Python target is 3.12.
84
+ - Keep strict typing clean; do not weaken types to silence errors.
85
+ - Prefer explicit return types at module boundaries and public functions.
86
+ - Prefer existing utilities over new abstractions.
87
+ - Keep functions small, but do not split code just for aesthetics.
88
+ - Handle errors explicitly. Do not hide failures.
89
+ - Keep generated scaffold content readable and minimal.
90
+ - Use Mermaid only for execution flow, ownership boundaries, or data flow, and keep diagrams small.
91
+
92
+ ## Testing Rules
93
+
94
+ - Add or update tests for changed behavior.
95
+ - Prefer focused tests near the changed code.
96
+ - Run the narrowest relevant test first.
97
+ - Run `uv run pytest`, `uv run ruff check src tests`, and `uv run mypy src tests` before claiming completion when practical.
98
+ - Do not delete failing tests unless they are obsolete and the reason is explained.
99
+ - If tests cannot be run, state exactly why.
100
+
101
+ ## Stop Conditions
102
+
103
+ Stop and ask before:
104
+
105
+ - adding a production dependency,
106
+ - changing public CLI commands or importable public APIs,
107
+ - changing generated CI, deployment, or secrets handling,
108
+ - changing authentication or authorization behavior,
109
+ - changing billing or payment behavior,
110
+ - changing database schema or migrations,
111
+ - deleting data,
112
+ - making broad architectural changes,
113
+ - replacing working code with a new pattern just because it is cleaner.
114
+
115
+ Before changing database schema in any future project that has one, inspect existing migrations and update tests. After changing API behavior in any future API layer, update or add request/response tests.
116
+
117
+ ## Do Not
118
+
119
+ - Do not rewrite unrelated files.
120
+ - Do not rename symbols for style only.
121
+ - Do not reformat untouched files.
122
+ - Do not weaken types to silence errors.
123
+ - Do not add caching, retries, queues, or concurrency unless requested.
124
+ - Do not replace working code with a new pattern just because it is cleaner.
125
+ - Do not claim success without validation.
126
+
127
+ ## Definition of Done
128
+
129
+ A task is complete when:
130
+
131
+ - the requested behavior is implemented,
132
+ - relevant tests are added or updated,
133
+ - validation commands have been run when practical,
134
+ - the final response lists changed files, validation results, and any remaining risks.
@@ -0,0 +1,37 @@
1
+ # Critical Functions
2
+
3
+ > Auto-generated by `kragg criticality --write`. Do not edit by hand.
4
+
5
+ Functions marked critical have high fan-in or betweenness centrality.
6
+ When editing them, full types, docstrings, and tests are mandatory.
7
+
8
+ ## Critical
9
+
10
+ | Function | Fan-in | Fan-out | Centrality | Risk |
11
+ | --- | ---: | ---: | ---: | --- |
12
+ | `kragg.critical.critical_functions` | 3 | 4 | 0.0011 | MED |
13
+ | `kragg.policy.load_policy` | 17 | 5 | 0.0010 | HIGH |
14
+ | `kragg.report.to_payload` | 3 | 5 | 0.0006 | MED |
15
+ | `kragg.changes.changed_python_files` | 4 | 4 | 0.0006 | MED |
16
+
17
+ ## Non-critical
18
+
19
+ | Function | Fan-in | Fan-out | Centrality | Risk |
20
+ | --- | ---: | ---: | ---: | --- |
21
+ | `kragg.catalog.build_check_gates` | 2 | 15 | 0.0053 | low |
22
+ | `kragg.hooks._run_check` | 2 | 9 | 0.0050 | low |
23
+ | `kragg.hooks._dispatch` | 1 | 4 | 0.0027 | low |
24
+ | `kragg.hooks._post_edit` | 1 | 4 | 0.0018 | low |
25
+ | `kragg.hooks._stop` | 1 | 4 | 0.0018 | low |
26
+ | `kragg.coverage.critical_gaps` | 2 | 4 | 0.0015 | low |
27
+ | `kragg.hooks.run_claude_hook` | 1 | 1 | 0.0014 | low |
28
+ | `kragg.gates.critical_coverage.check_critical_coverage` | 1 | 2 | 0.0014 | low |
29
+ | `kragg.catalog._critical_coverage_gate` | 1 | 2 | 0.0013 | low |
30
+ | `kragg.gates.critical_tests.check_critical_tests` | 1 | 4 | 0.0007 | low |
31
+ | `kragg.catalog._project_tool_gate` | 2 | 8 | 0.0007 | low |
32
+ | `kragg.gates.test_quality.check_tests` | 1 | 3 | 0.0006 | low |
33
+ | `kragg.catalog._test_quality_gate` | 1 | 2 | 0.0006 | low |
34
+ | `kragg.catalog._critical_tests_gate` | 1 | 2 | 0.0006 | low |
35
+ | `kragg.gates.criticality.build_call_graph` | 1 | 4 | 0.0006 | low |
36
+ | `kragg.commands._run_pipeline` | 2 | 8 | 0.0006 | low |
37
+
kragg-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Torta Studios, LLC (tortastudios.com)
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.
kragg-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: kragg
3
+ Version: 0.3.0
4
+ Summary: Agent-first guardrails framework for AI-assisted Python projects
5
+ Project-URL: Homepage, https://tortastudios.com
6
+ Project-URL: Repository, https://github.com/tortastudios/kragg
7
+ Project-URL: Issues, https://github.com/tortastudios/kragg/issues
8
+ Author-email: "Torta Studios, LLC" <tech@tortastudios.com>
9
+ Maintainer-email: "Torta Studios, LLC" <tech@tortastudios.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,ai,claude-code,code-quality,guardrails,linting,scaffolding
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Code Generators
22
+ Classifier: Topic :: Software Development :: Quality Assurance
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: bandit>=1.8.3
26
+ Requires-Dist: deptry>=0.24.0
27
+ Requires-Dist: detect-secrets>=1.5.0
28
+ Requires-Dist: mypy>=1.19.1
29
+ Requires-Dist: networkx>=3.4.2
30
+ Requires-Dist: pip-audit>=2.9.0
31
+ Requires-Dist: pytest-cov>=7.0.0
32
+ Requires-Dist: pytest>=9.0.2
33
+ Requires-Dist: radon>=6.0.1
34
+ Requires-Dist: ruff>=0.15.5
35
+ Requires-Dist: vulture>=2.15
36
+ Description-Content-Type: text/markdown
37
+
38
+ # kragg
39
+
40
+ `kragg` is an opinionated guardrails framework for AI-assisted Python projects.
41
+ It is agent-first: coding agents (Claude Code, Codex, Cursor, Gemini CLI, …)
42
+ are the primary users, running check → fix loops. kragg gives them one command,
43
+ structured results, meaningful exit codes, and copy-pasteable fixes.
44
+
45
+ ## Install modes
46
+
47
+ **Dev dependency (recommended).** kragg runs inside the project environment, so
48
+ every tool sees the project's packages:
49
+
50
+ ```bash
51
+ uv add --dev kragg
52
+ uv run kragg check
53
+ ```
54
+
55
+ **Global tool (pipx / uv tool).** kragg runs from its own environment, but
56
+ environment-dependent gates (pytest, mypy, pip-audit, deptry) are always
57
+ executed on the *project's* interpreter, resolved in this order:
58
+
59
+ 1. `KRAGG_PROJECT_PYTHON` environment variable (explicit override)
60
+ 2. `<project>/.venv`
61
+ 3. an active `VIRTUAL_ENV` (ignored when it is kragg's own environment)
62
+ 4. `uv run --project <project>` as a fallback
63
+
64
+ If no project environment exists, those gates fail loudly with the exact fix
65
+ (`uv sync`, `uv add --dev mypy`, …) instead of silently running in the wrong
66
+ environment. `kragg doctor` shows which interpreter was resolved and which
67
+ tools are missing.
68
+
69
+ ## Commands
70
+
71
+ ```bash
72
+ kragg new my-app --kind cli # layered skeleton (cli | api | worker) + uv sync
73
+ kragg gen module payments # service/domain/test slots in the layout
74
+ kragg init . # add guardrails to an existing project
75
+ kragg check # all gates, consolidated report
76
+ kragg check --changed # only files changed in git (cheap inner loop)
77
+ kragg check --since main # changed vs merge-base with a ref
78
+ kragg check --file src/foo.py --file src/bar.py
79
+ kragg check --format json # stable machine-readable schema
80
+ kragg fix # auto-fix formatting and safe lint
81
+ kragg map # public symbol inventory (what already exists)
82
+ kragg spec # test suite rendered as a readable spec tree
83
+ kragg coverage # uncovered lines in critical functions (ranked)
84
+ kragg mutation # mutation-test changed critical files (cosmic-ray)
85
+ kragg mutation --all # mutation-test every critical file
86
+ kragg mutation --update-baseline # accept current survivors (equivalent mutants)
87
+ kragg brief # reviewable digest of the change set
88
+ kragg security
89
+ kragg audit
90
+ kragg criticality --write # call-graph risk -> CRITICALITY.md + .kragg/
91
+ kragg status # what failed last run, without re-running
92
+ kragg flaky # gates that flipped pass/fail on an unchanged commit
93
+ kragg flaky --rerun 20 # re-run the suite N times, rank tests by failure ratio
94
+ kragg hook claude # harness hook adapter (reads hook JSON on stdin)
95
+ kragg doctor # environment diagnostics with exact fixes
96
+ kragg policy show
97
+ ```
98
+
99
+ ## Gates
100
+
101
+ Fast (always all run): ruff, mypy, radon-cc, radon-mi, halstead,
102
+ type-complexity, **boundaries** (layered import contract from
103
+ `[tool.kragg] layers`), **structure** (file/symbol budgets),
104
+ **critical-tests** (critical functions cannot change without test changes),
105
+ **test-quality** (no assertion-free tests; critical functions must be
106
+ referenced by tests), bandit, detect-secrets.
107
+ Slow (skipped while fast gates fail): pytest+coverage, **critical-coverage**
108
+ (public critical functions must have no uncovered lines), pip-audit.
109
+
110
+ ## Test depth
111
+
112
+ Green checkmarks are easy to fake, so kragg looks past them with layered,
113
+ mostly-deterministic signals — each a harder-to-game answer to "do the tests
114
+ actually defend behavior":
115
+
116
+ - **what's run** — `kragg coverage` surfaces uncovered lines in critical
117
+ functions, ranked by fan-in, instead of a gameable global percentage; the
118
+ `critical-coverage` gate fails on any uncovered line in a critical function.
119
+ - **what's defended** — `kragg mutation` runs cosmic-ray over the changed
120
+ critical files (the criticality graph and git diff keep it cheap) and reports
121
+ surviving mutants as `file:line` fixes. Accept equivalent mutants with
122
+ `kragg mutation --update-baseline`.
123
+ - **what's claimed** — `kragg spec` renders test names and docstrings as a
124
+ documentation tree and flags critical functions that have only example-based
125
+ tests (property-based tests, via Hypothesis, kill more mutants).
126
+ - **what's trustworthy** — `kragg flaky` mines the run journal for gates that
127
+ flipped on an unchanged commit; `--rerun N` re-runs the suite and ranks tests
128
+ by failure ratio (for cron/CI, never the inner loop).
129
+
130
+ Mutation and active flaky runs are deliberately outside `kragg check`: they are
131
+ on-demand or CI surfaces, not inner-loop gates.
132
+
133
+ `kragg mutation` runs cosmic-ray on the project interpreter, so add it to the
134
+ project being checked (`uv add --dev cosmic-ray`); kragg prints the exact
135
+ command if it is missing. Property-based tests use Hypothesis
136
+ (`uv add --dev hypothesis`). Mutation needs an editable/source install so it
137
+ mutates the code the tests import.
138
+
139
+ ## Agent-native design
140
+
141
+ Agents drift where they have freedom, so the scaffold removes the freedom:
142
+ every kind ships one layered layout (`entrypoints/` → `services/` →
143
+ `domain/`) with the `boundaries` gate enforcing dependency direction from
144
+ the first commit, and `kragg gen module` creates new code in the one place
145
+ it belongs. The tool holds the memory the agent lacks: `kragg map` is the
146
+ inventory of what exists (injected at session start so nothing gets
147
+ reinvented), `.kragg/history.jsonl` remembers runs, `CRITICALITY.md`
148
+ remembers risk, and `kragg brief` renders the change set legible to the
149
+ human reviewer.
150
+
151
+ ## Agent loop design
152
+
153
+ - `kragg check` runs **all static gates** and reports every failure in one run
154
+ (one loop iteration instead of one per gate). Slow gates (pytest, pip-audit)
155
+ are skipped while static gates fail; `--fail-fast` and `--all` override.
156
+ - Output is token-efficient: violations are deduplicated, capped per gate
157
+ (`--max-violations`, policy `max_violations_per_gate`), and reported as
158
+ `file:line` pointers with fix hints instead of raw tool dumps.
159
+ - Exit codes are branchable without parsing: `0` pass, `1` gate failures,
160
+ `2` usage error, `3` environment broken.
161
+ - Every run appends a slim line to `.kragg/history.jsonl`; `kragg status` answers
162
+ "what failed last run" for a few tokens.
163
+ - Scaffolding emits `AGENTS.md` as the canonical agent contract (read by
164
+ Codex, Cursor, Gemini CLI, and Claude Code via a `CLAUDE.md` pointer), plus
165
+ hooks that run `kragg check --changed` after edits.
166
+
167
+ ## Configuration
168
+
169
+ Configure kragg in `pyproject.toml` under `[tool.kragg]`, or in a standalone
170
+ `kragg.toml` (top-level keys, takes precedence when present):
171
+
172
+ ```toml
173
+ [tool.kragg]
174
+ profile = "strict-ai-python"
175
+ source_paths = ["src"]
176
+ test_paths = ["tests"]
177
+ coverage_fail_under = 80
178
+ type_max_nesting_depth = 2
179
+ type_max_length = 40
180
+ max_violations_per_gate = 25
181
+ ```
182
+
183
+ ## V1 scope
184
+
185
+ `kragg` models agentic workflow support as policy packs, not as an LLM runtime.
186
+ A policy pack defines the gates, thresholds, generated agent instructions, and
187
+ project wrappers that keep AI-authored Python code inside known constraints.
188
+
189
+ The default policy pack is `strict-ai-python`.
kragg-0.3.0/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # kragg
2
+
3
+ `kragg` is an opinionated guardrails framework for AI-assisted Python projects.
4
+ It is agent-first: coding agents (Claude Code, Codex, Cursor, Gemini CLI, …)
5
+ are the primary users, running check → fix loops. kragg gives them one command,
6
+ structured results, meaningful exit codes, and copy-pasteable fixes.
7
+
8
+ ## Install modes
9
+
10
+ **Dev dependency (recommended).** kragg runs inside the project environment, so
11
+ every tool sees the project's packages:
12
+
13
+ ```bash
14
+ uv add --dev kragg
15
+ uv run kragg check
16
+ ```
17
+
18
+ **Global tool (pipx / uv tool).** kragg runs from its own environment, but
19
+ environment-dependent gates (pytest, mypy, pip-audit, deptry) are always
20
+ executed on the *project's* interpreter, resolved in this order:
21
+
22
+ 1. `KRAGG_PROJECT_PYTHON` environment variable (explicit override)
23
+ 2. `<project>/.venv`
24
+ 3. an active `VIRTUAL_ENV` (ignored when it is kragg's own environment)
25
+ 4. `uv run --project <project>` as a fallback
26
+
27
+ If no project environment exists, those gates fail loudly with the exact fix
28
+ (`uv sync`, `uv add --dev mypy`, …) instead of silently running in the wrong
29
+ environment. `kragg doctor` shows which interpreter was resolved and which
30
+ tools are missing.
31
+
32
+ ## Commands
33
+
34
+ ```bash
35
+ kragg new my-app --kind cli # layered skeleton (cli | api | worker) + uv sync
36
+ kragg gen module payments # service/domain/test slots in the layout
37
+ kragg init . # add guardrails to an existing project
38
+ kragg check # all gates, consolidated report
39
+ kragg check --changed # only files changed in git (cheap inner loop)
40
+ kragg check --since main # changed vs merge-base with a ref
41
+ kragg check --file src/foo.py --file src/bar.py
42
+ kragg check --format json # stable machine-readable schema
43
+ kragg fix # auto-fix formatting and safe lint
44
+ kragg map # public symbol inventory (what already exists)
45
+ kragg spec # test suite rendered as a readable spec tree
46
+ kragg coverage # uncovered lines in critical functions (ranked)
47
+ kragg mutation # mutation-test changed critical files (cosmic-ray)
48
+ kragg mutation --all # mutation-test every critical file
49
+ kragg mutation --update-baseline # accept current survivors (equivalent mutants)
50
+ kragg brief # reviewable digest of the change set
51
+ kragg security
52
+ kragg audit
53
+ kragg criticality --write # call-graph risk -> CRITICALITY.md + .kragg/
54
+ kragg status # what failed last run, without re-running
55
+ kragg flaky # gates that flipped pass/fail on an unchanged commit
56
+ kragg flaky --rerun 20 # re-run the suite N times, rank tests by failure ratio
57
+ kragg hook claude # harness hook adapter (reads hook JSON on stdin)
58
+ kragg doctor # environment diagnostics with exact fixes
59
+ kragg policy show
60
+ ```
61
+
62
+ ## Gates
63
+
64
+ Fast (always all run): ruff, mypy, radon-cc, radon-mi, halstead,
65
+ type-complexity, **boundaries** (layered import contract from
66
+ `[tool.kragg] layers`), **structure** (file/symbol budgets),
67
+ **critical-tests** (critical functions cannot change without test changes),
68
+ **test-quality** (no assertion-free tests; critical functions must be
69
+ referenced by tests), bandit, detect-secrets.
70
+ Slow (skipped while fast gates fail): pytest+coverage, **critical-coverage**
71
+ (public critical functions must have no uncovered lines), pip-audit.
72
+
73
+ ## Test depth
74
+
75
+ Green checkmarks are easy to fake, so kragg looks past them with layered,
76
+ mostly-deterministic signals — each a harder-to-game answer to "do the tests
77
+ actually defend behavior":
78
+
79
+ - **what's run** — `kragg coverage` surfaces uncovered lines in critical
80
+ functions, ranked by fan-in, instead of a gameable global percentage; the
81
+ `critical-coverage` gate fails on any uncovered line in a critical function.
82
+ - **what's defended** — `kragg mutation` runs cosmic-ray over the changed
83
+ critical files (the criticality graph and git diff keep it cheap) and reports
84
+ surviving mutants as `file:line` fixes. Accept equivalent mutants with
85
+ `kragg mutation --update-baseline`.
86
+ - **what's claimed** — `kragg spec` renders test names and docstrings as a
87
+ documentation tree and flags critical functions that have only example-based
88
+ tests (property-based tests, via Hypothesis, kill more mutants).
89
+ - **what's trustworthy** — `kragg flaky` mines the run journal for gates that
90
+ flipped on an unchanged commit; `--rerun N` re-runs the suite and ranks tests
91
+ by failure ratio (for cron/CI, never the inner loop).
92
+
93
+ Mutation and active flaky runs are deliberately outside `kragg check`: they are
94
+ on-demand or CI surfaces, not inner-loop gates.
95
+
96
+ `kragg mutation` runs cosmic-ray on the project interpreter, so add it to the
97
+ project being checked (`uv add --dev cosmic-ray`); kragg prints the exact
98
+ command if it is missing. Property-based tests use Hypothesis
99
+ (`uv add --dev hypothesis`). Mutation needs an editable/source install so it
100
+ mutates the code the tests import.
101
+
102
+ ## Agent-native design
103
+
104
+ Agents drift where they have freedom, so the scaffold removes the freedom:
105
+ every kind ships one layered layout (`entrypoints/` → `services/` →
106
+ `domain/`) with the `boundaries` gate enforcing dependency direction from
107
+ the first commit, and `kragg gen module` creates new code in the one place
108
+ it belongs. The tool holds the memory the agent lacks: `kragg map` is the
109
+ inventory of what exists (injected at session start so nothing gets
110
+ reinvented), `.kragg/history.jsonl` remembers runs, `CRITICALITY.md`
111
+ remembers risk, and `kragg brief` renders the change set legible to the
112
+ human reviewer.
113
+
114
+ ## Agent loop design
115
+
116
+ - `kragg check` runs **all static gates** and reports every failure in one run
117
+ (one loop iteration instead of one per gate). Slow gates (pytest, pip-audit)
118
+ are skipped while static gates fail; `--fail-fast` and `--all` override.
119
+ - Output is token-efficient: violations are deduplicated, capped per gate
120
+ (`--max-violations`, policy `max_violations_per_gate`), and reported as
121
+ `file:line` pointers with fix hints instead of raw tool dumps.
122
+ - Exit codes are branchable without parsing: `0` pass, `1` gate failures,
123
+ `2` usage error, `3` environment broken.
124
+ - Every run appends a slim line to `.kragg/history.jsonl`; `kragg status` answers
125
+ "what failed last run" for a few tokens.
126
+ - Scaffolding emits `AGENTS.md` as the canonical agent contract (read by
127
+ Codex, Cursor, Gemini CLI, and Claude Code via a `CLAUDE.md` pointer), plus
128
+ hooks that run `kragg check --changed` after edits.
129
+
130
+ ## Configuration
131
+
132
+ Configure kragg in `pyproject.toml` under `[tool.kragg]`, or in a standalone
133
+ `kragg.toml` (top-level keys, takes precedence when present):
134
+
135
+ ```toml
136
+ [tool.kragg]
137
+ profile = "strict-ai-python"
138
+ source_paths = ["src"]
139
+ test_paths = ["tests"]
140
+ coverage_fail_under = 80
141
+ type_max_nesting_depth = 2
142
+ type_max_length = 40
143
+ max_violations_per_gate = 25
144
+ ```
145
+
146
+ ## V1 scope
147
+
148
+ `kragg` models agentic workflow support as policy packs, not as an LLM runtime.
149
+ A policy pack defines the gates, thresholds, generated agent instructions, and
150
+ project wrappers that keep AI-authored Python code inside known constraints.
151
+
152
+ The default policy pack is `strict-ai-python`.