diffguard-ai 0.1.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.
- diffguard_ai-0.1.0/.diffguard.yml +20 -0
- diffguard_ai-0.1.0/.gitignore +13 -0
- diffguard_ai-0.1.0/CHANGELOG.md +49 -0
- diffguard_ai-0.1.0/LICENSE +202 -0
- diffguard_ai-0.1.0/PKG-INFO +141 -0
- diffguard_ai-0.1.0/README.md +102 -0
- diffguard_ai-0.1.0/action/action.yml +213 -0
- diffguard_ai-0.1.0/benchmarks/README.md +30 -0
- diffguard_ai-0.1.0/benchmarks/RESULTS.md +43 -0
- diffguard_ai-0.1.0/benchmarks/__init__.py +0 -0
- diffguard_ai-0.1.0/benchmarks/corpus.py +719 -0
- diffguard_ai-0.1.0/benchmarks/mine_real_repos.py +47 -0
- diffguard_ai-0.1.0/benchmarks/run.py +194 -0
- diffguard_ai-0.1.0/docs/api.md +61 -0
- diffguard_ai-0.1.0/docs/architecture.md +178 -0
- diffguard_ai-0.1.0/docs/cli.md +54 -0
- diffguard_ai-0.1.0/docs/configuration.md +78 -0
- diffguard_ai-0.1.0/docs/github-actions.md +44 -0
- diffguard_ai-0.1.0/docs/publishing.md +29 -0
- diffguard_ai-0.1.0/docs/rules.md +85 -0
- diffguard_ai-0.1.0/docs/security.md +50 -0
- diffguard_ai-0.1.0/docs/verification.md +34 -0
- diffguard_ai-0.1.0/examples/demo.py +58 -0
- diffguard_ai-0.1.0/examples/policies/audit-only.yml +9 -0
- diffguard_ai-0.1.0/examples/policies/payments-task.yml +23 -0
- diffguard_ai-0.1.0/examples/policies/strict.yml +17 -0
- diffguard_ai-0.1.0/pyproject.toml +78 -0
- diffguard_ai-0.1.0/schemas/report-v1.schema.json +65 -0
- diffguard_ai-0.1.0/src/diffguard/__init__.py +39 -0
- diffguard_ai-0.1.0/src/diffguard/__main__.py +4 -0
- diffguard_ai-0.1.0/src/diffguard/baselines/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/baselines/manager.py +97 -0
- diffguard_ai-0.1.0/src/diffguard/cli/__init__.py +1 -0
- diffguard_ai-0.1.0/src/diffguard/cli/main.py +323 -0
- diffguard_ai-0.1.0/src/diffguard/core/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/core/enums.py +103 -0
- diffguard_ai-0.1.0/src/diffguard/core/exceptions.py +57 -0
- diffguard_ai-0.1.0/src/diffguard/core/interfaces.py +20 -0
- diffguard_ai-0.1.0/src/diffguard/core/models.py +301 -0
- diffguard_ai-0.1.0/src/diffguard/engine/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/engine/evaluator.py +42 -0
- diffguard_ai-0.1.0/src/diffguard/engine/orchestrator.py +74 -0
- diffguard_ai-0.1.0/src/diffguard/engine/registry.py +142 -0
- diffguard_ai-0.1.0/src/diffguard/engine/scanner.py +141 -0
- diffguard_ai-0.1.0/src/diffguard/git/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/git/client.py +179 -0
- diffguard_ai-0.1.0/src/diffguard/git/diff_parser.py +298 -0
- diffguard_ai-0.1.0/src/diffguard/git/repository.py +174 -0
- diffguard_ai-0.1.0/src/diffguard/policies/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/policies/loader.py +75 -0
- diffguard_ai-0.1.0/src/diffguard/policies/schema.py +292 -0
- diffguard_ai-0.1.0/src/diffguard/py.typed +0 -0
- diffguard_ai-0.1.0/src/diffguard/reporting/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/reporting/json_report.py +104 -0
- diffguard_ai-0.1.0/src/diffguard/reporting/markdown_report.py +96 -0
- diffguard_ai-0.1.0/src/diffguard/reporting/text_report.py +43 -0
- diffguard_ai-0.1.0/src/diffguard/rules/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/rules/base.py +248 -0
- diffguard_ai-0.1.0/src/diffguard/rules/configuration.py +98 -0
- diffguard_ai-0.1.0/src/diffguard/rules/dangerous_patterns.py +290 -0
- diffguard_ai-0.1.0/src/diffguard/rules/dependencies.py +375 -0
- diffguard_ai-0.1.0/src/diffguard/rules/filetypes.py +49 -0
- diffguard_ai-0.1.0/src/diffguard/rules/scope.py +108 -0
- diffguard_ai-0.1.0/src/diffguard/rules/secret_patterns.py +195 -0
- diffguard_ai-0.1.0/src/diffguard/rules/secrets.py +118 -0
- diffguard_ai-0.1.0/src/diffguard/rules/test_removal.py +253 -0
- diffguard_ai-0.1.0/src/diffguard/suppressions/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/suppressions/manager.py +81 -0
- diffguard_ai-0.1.0/src/diffguard/utils/__init__.py +0 -0
- diffguard_ai-0.1.0/src/diffguard/utils/logging.py +23 -0
- diffguard_ai-0.1.0/src/diffguard/utils/paths.py +131 -0
- diffguard_ai-0.1.0/src/diffguard/version.py +1 -0
- diffguard_ai-0.1.0/tests/__init__.py +0 -0
- diffguard_ai-0.1.0/tests/conftest.py +95 -0
- diffguard_ai-0.1.0/tests/integration/__init__.py +0 -0
- diffguard_ai-0.1.0/tests/integration/test_benchmark.py +34 -0
- diffguard_ai-0.1.0/tests/integration/test_cli.py +149 -0
- diffguard_ai-0.1.0/tests/integration/test_git_scans.py +202 -0
- diffguard_ai-0.1.0/tests/unit/__init__.py +0 -0
- diffguard_ai-0.1.0/tests/unit/test_dependency_parsers.py +126 -0
- diffguard_ai-0.1.0/tests/unit/test_diff_parser.py +121 -0
- diffguard_ai-0.1.0/tests/unit/test_engine.py +294 -0
- diffguard_ai-0.1.0/tests/unit/test_fill_placeholders.py +108 -0
- diffguard_ai-0.1.0/tests/unit/test_paths.py +65 -0
- diffguard_ai-0.1.0/tests/unit/test_policy.py +138 -0
- diffguard_ai-0.1.0/tests/unit/test_release_gate.py +42 -0
- diffguard_ai-0.1.0/tests/unit/test_rules.py +395 -0
- diffguard_ai-0.1.0/tests/unit/test_set_distribution_name.py +68 -0
- diffguard_ai-0.1.0/tools/check_release_ready.py +77 -0
- diffguard_ai-0.1.0/tools/fill_placeholders.py +97 -0
- diffguard_ai-0.1.0/tools/set_distribution_name.py +81 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# diffguard dogfooding policy for this repository.
|
|
2
|
+
version: 1
|
|
3
|
+
task:
|
|
4
|
+
protected_paths:
|
|
5
|
+
- ".github/workflows/**"
|
|
6
|
+
- ".diffguard.yml"
|
|
7
|
+
- "LICENSE"
|
|
8
|
+
max_changed_lines: 2000
|
|
9
|
+
rules:
|
|
10
|
+
secrets:
|
|
11
|
+
options:
|
|
12
|
+
allowlist_paths:
|
|
13
|
+
- "tests/**"
|
|
14
|
+
dangerous_patterns:
|
|
15
|
+
options:
|
|
16
|
+
ignore_paths:
|
|
17
|
+
- "tests/**"
|
|
18
|
+
enforcement:
|
|
19
|
+
fail_on:
|
|
20
|
+
- error
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are documented here. The project follows [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-12-01
|
|
6
|
+
|
|
7
|
+
First Community-edition release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Git diff ingestion: working tree (including untracked files), staged, `--base/--head`
|
|
11
|
+
(merge-base semantics), and bare unified diffs (file or stdin).
|
|
12
|
+
- Unified diff parser: add/modify/delete/rename/copy, mode changes, binary files, quoted and
|
|
13
|
+
unicode paths, strict rejection of malformed input.
|
|
14
|
+
- YAML policy engine with schema validation, duplicate-key rejection, conflict detection,
|
|
15
|
+
unambiguous glob semantics, severity overrides, suppressions (with expiry) and baselines.
|
|
16
|
+
- Rules: `scope`, `secrets`, `dangerous_patterns`, `dependency_changes`, `test_removal`,
|
|
17
|
+
`config_changes`.
|
|
18
|
+
- JSON (schema v1.0), Markdown and text reports; stable exit codes 0/1/2/3.
|
|
19
|
+
- CLI: `scan`, `init`, `validate`, `rules`, `version`.
|
|
20
|
+
- GitHub composite Action, CI and release workflows (third-party actions pinned to commit SHAs), Python public API.
|
|
21
|
+
- Rule plugins via the `diffguard.rules` entry-point group (loaded only from the Python environment).
|
|
22
|
+
- Static guard rejecting catastrophic-backtracking (nested unbounded quantifier) regexes in policies.
|
|
23
|
+
- `core.fsmonitor` disabled on every Git call; symlinked manifests reported as not analyzed.
|
|
24
|
+
|
|
25
|
+
### Changed after real CI runs
|
|
26
|
+
- PyPI distribution name is `diffguard-ai` because `diffguard` is already taken on PyPI. The import name and the
|
|
27
|
+
command remain `diffguard`.
|
|
28
|
+
- The composite action no longer fails inside the scan step: the scan always records its outputs
|
|
29
|
+
(`exit-code`, `json-report`, `markdown-report`) and a separate final step enforces the exit code. This keeps the
|
|
30
|
+
outputs available to callers when the scan reports a violation.
|
|
31
|
+
- The action self-test now runs the action in an isolated temporary repository on ubuntu, windows and macos.
|
|
32
|
+
- The self-test now checks the report's `findings` array (the `rules` metadata always lists every check ID, so a
|
|
33
|
+
text search could never fail) and that the fake secret never appears in the report.
|
|
34
|
+
- `tools/set_distribution_name.py` only replaces the project's current name as a whole token (it previously could
|
|
35
|
+
rewrite `pip install .`).
|
|
36
|
+
|
|
37
|
+
### Validation performed before release
|
|
38
|
+
- 209 tests on Linux with Python 3.11, 3.12 and 3.13; ruff and strict mypy clean.
|
|
39
|
+
- 360 real commits (1,153 files) from three public Python repositories, and 900 sampled commits authored by
|
|
40
|
+
the Aider AI coding agent, scanned without crashes or rule errors. Findings were reviewed by hand and
|
|
41
|
+
three noise sources fixed: multi-version lock files, conditional test skips, and renamed tests reported as
|
|
42
|
+
removed (now "removed or renamed" at low confidence). Dangerous patterns inside test files are low confidence.
|
|
43
|
+
- Labelled detection benchmark (`benchmarks/`, 183 cases incl. hard negatives and documented known misses) run in CI;
|
|
44
|
+
it found and fixed two real bugs (`it.skip` read as a removed test; assertions moved between files counted as removed).
|
|
45
|
+
- `action-selftest` workflow (action verified on ubuntu/windows/macos runners), portable Python detection in the action.
|
|
46
|
+
- `tools/fill_placeholders.py`, `docs/verification.md`, `docs/publishing.md`.
|
|
47
|
+
- `tools/check_release_ready.py` release gate (placeholders, project URLs, final version, changelog entry),
|
|
48
|
+
run first in the release workflow.
|
|
49
|
+
- Windows and macOS are covered by the CI matrix but were **not** executed by the author.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: diffguard-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Guard every AI-generated diff before it reaches a human: policy enforcement for Git changes.
|
|
5
|
+
Project-URL: Homepage, https://github.com/LakshyaDhouchak/diffguard
|
|
6
|
+
Project-URL: Repository, https://github.com/LakshyaDhouchak/diffguard
|
|
7
|
+
Project-URL: Issues, https://github.com/LakshyaDhouchak/diffguard/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/LakshyaDhouchak/diffguard/blob/main/CHANGELOG.md
|
|
9
|
+
Author: diffguard contributors
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,ci,code-review,diff,git,governance,policy,security
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Security
|
|
23
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
24
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: pyyaml<7,>=6.0
|
|
28
|
+
Requires-Dist: typer<1,>=0.12
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1; extra == 'dev'
|
|
31
|
+
Requires-Dist: jsonschema>=4; extra == 'dev'
|
|
32
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
36
|
+
Requires-Dist: twine>=5; extra == 'dev'
|
|
37
|
+
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# diffguard
|
|
41
|
+
|
|
42
|
+
**Guard every AI-generated diff before it reaches a human.**
|
|
43
|
+
|
|
44
|
+
diffguard is an open-source (Apache-2.0) Python library and CLI that checks a Git diff against an
|
|
45
|
+
explicit policy *before* human review: Which files changed? Were they in scope? Were protected paths
|
|
46
|
+
touched? Were secrets, dangerous code, dependency changes, removed tests or sensitive configuration
|
|
47
|
+
introduced? The answer is a deterministic, explainable `pass` / `warn` / `fail` decision with stable exit
|
|
48
|
+
codes for CI.
|
|
49
|
+
|
|
50
|
+
> Status: `0.1.0` (Initial community release candidate). Tested on Linux with Python 3.11-3.13. The CI matrix also covers
|
|
51
|
+
> Windows and macOS, but those platforms had not been executed when this version was cut: check CI results
|
|
52
|
+
> before relying on them. See `docs/architecture.md` for details.
|
|
53
|
+
|
|
54
|
+
## Why it exists
|
|
55
|
+
AI coding agents modify repositories autonomously: they edit files outside their task, loosen security
|
|
56
|
+
settings, delete tests and add dependencies. Code review evaluates quality *after* the fact. diffguard
|
|
57
|
+
adds a policy layer that enforces boundaries up front, locally, with no cloud, API key or model.
|
|
58
|
+
|
|
59
|
+
## How it works
|
|
60
|
+
`Git diff + .diffguard.yml policy -> parse -> rules -> findings -> suppressions/baseline -> decision -> reports`
|
|
61
|
+
|
|
62
|
+
Every finding says what happened, where, which rule fired, why it matters and how to fix it.
|
|
63
|
+
Secret values are redacted everywhere.
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
```bash
|
|
67
|
+
pip install diffguard-ai # after publication; from a checkout: pip install .
|
|
68
|
+
```
|
|
69
|
+
The PyPI package is **`diffguard-ai`**; the command and the Python import name are `diffguard`
|
|
70
|
+
(`pip install diffguard-ai` -> `diffguard scan` / `import diffguard`).
|
|
71
|
+
Requires Python 3.11+ and Git.
|
|
72
|
+
|
|
73
|
+
## Quick start
|
|
74
|
+
```bash
|
|
75
|
+
diffguard init # writes .diffguard.yml
|
|
76
|
+
diffguard validate # checks the policy
|
|
77
|
+
diffguard scan # working tree (incl. untracked) vs HEAD
|
|
78
|
+
diffguard scan --staged
|
|
79
|
+
diffguard scan --base main # branch changes since the merge base
|
|
80
|
+
git diff main... | diffguard scan --diff-file -
|
|
81
|
+
diffguard scan --base main -f json -o report.json
|
|
82
|
+
```
|
|
83
|
+
Try the end-to-end demo: `python examples/demo.py`.
|
|
84
|
+
|
|
85
|
+
## Policy
|
|
86
|
+
```yaml
|
|
87
|
+
version: 1
|
|
88
|
+
task:
|
|
89
|
+
id: "PAY-102"
|
|
90
|
+
allowed_paths: ["src/payments/**", "tests/payments/**"]
|
|
91
|
+
protected_paths: ["src/auth/**", "infrastructure/**", ".github/workflows/**", ".diffguard.yml"]
|
|
92
|
+
max_changed_lines: 150
|
|
93
|
+
rules:
|
|
94
|
+
scope: {severity: error}
|
|
95
|
+
secrets: {severity: error}
|
|
96
|
+
dangerous_patterns: {severity: warning}
|
|
97
|
+
enforcement:
|
|
98
|
+
fail_on: [error]
|
|
99
|
+
```
|
|
100
|
+
See [docs/configuration.md](docs/configuration.md) and `examples/policies/`.
|
|
101
|
+
|
|
102
|
+
## Rules
|
|
103
|
+
`scope`, `secrets`, `dangerous_patterns`, `dependency_changes`, `test_removal`, `config_changes`
|
|
104
|
+
(run `diffguard rules`; details in [docs/rules.md](docs/rules.md)). Suppressions, baselines and per-rule
|
|
105
|
+
severity are supported.
|
|
106
|
+
|
|
107
|
+
## Python API
|
|
108
|
+
```python
|
|
109
|
+
from diffguard import Scanner, ScanRequest
|
|
110
|
+
|
|
111
|
+
result = Scanner.from_config(".diffguard.yml").scan(ScanRequest(repository=".", base="main"))
|
|
112
|
+
print(result.decision.outcome, int(result.exit_code))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## JSON report
|
|
116
|
+
Versioned (`schema_version: "1.0"`, [schema](schemas/report-v1.schema.json)): scanner version, timestamp,
|
|
117
|
+
repository metadata, policy, decision, summary counts, findings (with suppression info), rule metadata,
|
|
118
|
+
execution errors and warnings.
|
|
119
|
+
|
|
120
|
+
## GitHub Actions
|
|
121
|
+
Composite action in `action/` running the same scanner; see [docs/github-actions.md](docs/github-actions.md).
|
|
122
|
+
|
|
123
|
+
## Exit codes
|
|
124
|
+
`0` no blocking findings, `1` policy violation, `2` invalid config/input, `3` internal/execution failure
|
|
125
|
+
(an incomplete scan never reports success). Details: [docs/cli.md](docs/cli.md).
|
|
126
|
+
|
|
127
|
+
## Security and privacy
|
|
128
|
+
Local-only, no telemetry, never executes repository code, redacts secrets. Read
|
|
129
|
+
[docs/security.md](docs/security.md) for the threat model.
|
|
130
|
+
|
|
131
|
+
## Limitations
|
|
132
|
+
Heuristic detection (not complete secret/vulnerability scanning); binary and non-UTF-8 files are not
|
|
133
|
+
inspected; Git-style diffs only; dependency parsing covers a fixed list of formats. Details in
|
|
134
|
+
`docs/security.md` and `docs/rules.md`.
|
|
135
|
+
|
|
136
|
+
## Detection quality
|
|
137
|
+
A labelled benchmark with documented known misses lives in [benchmarks/](benchmarks/README.md) (hand-written corpus: a
|
|
138
|
+
regression guard, not an accuracy claim). Limits of each rule are listed in [docs/rules.md](docs/rules.md).
|
|
139
|
+
|
|
140
|
+
## Contributing
|
|
141
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). License: [Apache-2.0](LICENSE).
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# diffguard
|
|
2
|
+
|
|
3
|
+
**Guard every AI-generated diff before it reaches a human.**
|
|
4
|
+
|
|
5
|
+
diffguard is an open-source (Apache-2.0) Python library and CLI that checks a Git diff against an
|
|
6
|
+
explicit policy *before* human review: Which files changed? Were they in scope? Were protected paths
|
|
7
|
+
touched? Were secrets, dangerous code, dependency changes, removed tests or sensitive configuration
|
|
8
|
+
introduced? The answer is a deterministic, explainable `pass` / `warn` / `fail` decision with stable exit
|
|
9
|
+
codes for CI.
|
|
10
|
+
|
|
11
|
+
> Status: `0.1.0` (Initial community release candidate). Tested on Linux with Python 3.11-3.13. The CI matrix also covers
|
|
12
|
+
> Windows and macOS, but those platforms had not been executed when this version was cut: check CI results
|
|
13
|
+
> before relying on them. See `docs/architecture.md` for details.
|
|
14
|
+
|
|
15
|
+
## Why it exists
|
|
16
|
+
AI coding agents modify repositories autonomously: they edit files outside their task, loosen security
|
|
17
|
+
settings, delete tests and add dependencies. Code review evaluates quality *after* the fact. diffguard
|
|
18
|
+
adds a policy layer that enforces boundaries up front, locally, with no cloud, API key or model.
|
|
19
|
+
|
|
20
|
+
## How it works
|
|
21
|
+
`Git diff + .diffguard.yml policy -> parse -> rules -> findings -> suppressions/baseline -> decision -> reports`
|
|
22
|
+
|
|
23
|
+
Every finding says what happened, where, which rule fired, why it matters and how to fix it.
|
|
24
|
+
Secret values are redacted everywhere.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
```bash
|
|
28
|
+
pip install diffguard-ai # after publication; from a checkout: pip install .
|
|
29
|
+
```
|
|
30
|
+
The PyPI package is **`diffguard-ai`**; the command and the Python import name are `diffguard`
|
|
31
|
+
(`pip install diffguard-ai` -> `diffguard scan` / `import diffguard`).
|
|
32
|
+
Requires Python 3.11+ and Git.
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
35
|
+
```bash
|
|
36
|
+
diffguard init # writes .diffguard.yml
|
|
37
|
+
diffguard validate # checks the policy
|
|
38
|
+
diffguard scan # working tree (incl. untracked) vs HEAD
|
|
39
|
+
diffguard scan --staged
|
|
40
|
+
diffguard scan --base main # branch changes since the merge base
|
|
41
|
+
git diff main... | diffguard scan --diff-file -
|
|
42
|
+
diffguard scan --base main -f json -o report.json
|
|
43
|
+
```
|
|
44
|
+
Try the end-to-end demo: `python examples/demo.py`.
|
|
45
|
+
|
|
46
|
+
## Policy
|
|
47
|
+
```yaml
|
|
48
|
+
version: 1
|
|
49
|
+
task:
|
|
50
|
+
id: "PAY-102"
|
|
51
|
+
allowed_paths: ["src/payments/**", "tests/payments/**"]
|
|
52
|
+
protected_paths: ["src/auth/**", "infrastructure/**", ".github/workflows/**", ".diffguard.yml"]
|
|
53
|
+
max_changed_lines: 150
|
|
54
|
+
rules:
|
|
55
|
+
scope: {severity: error}
|
|
56
|
+
secrets: {severity: error}
|
|
57
|
+
dangerous_patterns: {severity: warning}
|
|
58
|
+
enforcement:
|
|
59
|
+
fail_on: [error]
|
|
60
|
+
```
|
|
61
|
+
See [docs/configuration.md](docs/configuration.md) and `examples/policies/`.
|
|
62
|
+
|
|
63
|
+
## Rules
|
|
64
|
+
`scope`, `secrets`, `dangerous_patterns`, `dependency_changes`, `test_removal`, `config_changes`
|
|
65
|
+
(run `diffguard rules`; details in [docs/rules.md](docs/rules.md)). Suppressions, baselines and per-rule
|
|
66
|
+
severity are supported.
|
|
67
|
+
|
|
68
|
+
## Python API
|
|
69
|
+
```python
|
|
70
|
+
from diffguard import Scanner, ScanRequest
|
|
71
|
+
|
|
72
|
+
result = Scanner.from_config(".diffguard.yml").scan(ScanRequest(repository=".", base="main"))
|
|
73
|
+
print(result.decision.outcome, int(result.exit_code))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## JSON report
|
|
77
|
+
Versioned (`schema_version: "1.0"`, [schema](schemas/report-v1.schema.json)): scanner version, timestamp,
|
|
78
|
+
repository metadata, policy, decision, summary counts, findings (with suppression info), rule metadata,
|
|
79
|
+
execution errors and warnings.
|
|
80
|
+
|
|
81
|
+
## GitHub Actions
|
|
82
|
+
Composite action in `action/` running the same scanner; see [docs/github-actions.md](docs/github-actions.md).
|
|
83
|
+
|
|
84
|
+
## Exit codes
|
|
85
|
+
`0` no blocking findings, `1` policy violation, `2` invalid config/input, `3` internal/execution failure
|
|
86
|
+
(an incomplete scan never reports success). Details: [docs/cli.md](docs/cli.md).
|
|
87
|
+
|
|
88
|
+
## Security and privacy
|
|
89
|
+
Local-only, no telemetry, never executes repository code, redacts secrets. Read
|
|
90
|
+
[docs/security.md](docs/security.md) for the threat model.
|
|
91
|
+
|
|
92
|
+
## Limitations
|
|
93
|
+
Heuristic detection (not complete secret/vulnerability scanning); binary and non-UTF-8 files are not
|
|
94
|
+
inspected; Git-style diffs only; dependency parsing covers a fixed list of formats. Details in
|
|
95
|
+
`docs/security.md` and `docs/rules.md`.
|
|
96
|
+
|
|
97
|
+
## Detection quality
|
|
98
|
+
A labelled benchmark with documented known misses lives in [benchmarks/](benchmarks/README.md) (hand-written corpus: a
|
|
99
|
+
regression guard, not an accuracy claim). Limits of each rule are listed in [docs/rules.md](docs/rules.md).
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). License: [Apache-2.0](LICENSE).
|