margin-ai-code-detector 0.2.0__py3-none-any.whl
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.
- ai_code_detector/__init__.py +15 -0
- ai_code_detector/agent.py +56 -0
- ai_code_detector/aggregate.py +183 -0
- ai_code_detector/judge/__init__.py +1 -0
- ai_code_detector/judge/llm_judge.py +358 -0
- ai_code_detector/judge/prompts/__init__.py +1 -0
- ai_code_detector/judge/prompts/judge_v1.md +28 -0
- ai_code_detector/judge/prompts/judge_v2.md +28 -0
- ai_code_detector/judge/sampler.py +40 -0
- ai_code_detector/markers/__init__.py +108 -0
- ai_code_detector/markers/v1.toml +98 -0
- ai_code_detector/methodology/__init__.py +71 -0
- ai_code_detector/methodology/v0.toml +119 -0
- ai_code_detector/methodology/v1.toml +141 -0
- ai_code_detector/models.py +197 -0
- ai_code_detector/pipeline.py +457 -0
- ai_code_detector/py.typed +1 -0
- ai_code_detector/report.py +179 -0
- ai_code_detector/signals/__init__.py +7 -0
- ai_code_detector/signals/base.py +64 -0
- ai_code_detector/signals/file.py +277 -0
- ai_code_detector/signals/repo.py +183 -0
- ai_code_detector/source/__init__.py +95 -0
- ai_code_detector/source/javascript.py +227 -0
- ai_code_detector/source/python.py +129 -0
- margin_ai_code_detector-0.2.0.dist-info/METADATA +137 -0
- margin_ai_code_detector-0.2.0.dist-info/RECORD +30 -0
- margin_ai_code_detector-0.2.0.dist-info/WHEEL +4 -0
- margin_ai_code_detector-0.2.0.dist-info/entry_points.txt +2 -0
- margin_ai_code_detector-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: margin-ai-code-detector
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Estimates how likely a codebase was written with AI assistance, as a range with the evidence for and against.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Waddah0-0/margin
|
|
6
|
+
Project-URL: Source, https://github.com/Waddah0-0/margin/tree/main/agents/ai_code_detector
|
|
7
|
+
Project-URL: Issues, https://github.com/Waddah0-0/margin/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Waddah0-0/margin/blob/main/agents/ai_code_detector/CHANGELOG.md
|
|
9
|
+
Author: Waddah Ali
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai-detection,code-analysis,llm
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: margin-core<0.2,>=0.1.0
|
|
23
|
+
Requires-Dist: tree-sitter-javascript>=0.23
|
|
24
|
+
Requires-Dist: tree-sitter-typescript>=0.23
|
|
25
|
+
Requires-Dist: tree-sitter<0.26,>=0.24
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# AI Code Detector
|
|
29
|
+
|
|
30
|
+
Estimates how likely it is that a repository, or parts of it, was written with AI
|
|
31
|
+
assistance, and always shows the reasons behind the estimate.
|
|
32
|
+
|
|
33
|
+
> **Status: experimental.** Methodology v1 combines heuristic signals with a local LLM judge,
|
|
34
|
+
> with weights fitted on 44 repositories. On 13 held-out repositories it ranked every AI
|
|
35
|
+
> repository it scored above 0.5 higher than every human one (AUC 1.00, no false positives
|
|
36
|
+
> at 0.5), but that test set is small and the scores are not calibrated, so confidence never
|
|
37
|
+
> goes above medium. Without a model it falls back to much weaker signals (test AUC 0.79,
|
|
38
|
+
> 29% false positives). Read [how it scores](https://github.com/Waddah0-0/margin/blob/main/docs/methodology.md)
|
|
39
|
+
> before relying on any number.
|
|
40
|
+
|
|
41
|
+
## What it does
|
|
42
|
+
|
|
43
|
+
Given a GitHub repository URL or a local path, the detector looks for evidence of AI
|
|
44
|
+
assistance in the code and its history. It returns a range with a confidence level, plus
|
|
45
|
+
the evidence for and against, so a person can judge the result for themselves.
|
|
46
|
+
|
|
47
|
+
## How it works
|
|
48
|
+
|
|
49
|
+
It combines two kinds of evidence. The first is a set of quick checks on the repository
|
|
50
|
+
itself, such as:
|
|
51
|
+
|
|
52
|
+
- config files left behind by AI coding tools, such as `CLAUDE.md`, `.cursorrules` or
|
|
53
|
+
`.github/copilot-instructions.md`;
|
|
54
|
+
- `Co-authored-by` trailers that name an AI assistant;
|
|
55
|
+
- a whole project arriving in a single commit;
|
|
56
|
+
- comments that only restate the line below them.
|
|
57
|
+
|
|
58
|
+
Some signals point the other way: a long, messy history, personal TODOs and leftover debug
|
|
59
|
+
code are all evidence of human authorship, and they count too.
|
|
60
|
+
|
|
61
|
+
The second is a language model acting as a judge. A local model (`qwen3.5:9b` through Ollama
|
|
62
|
+
by default) reads up to 20 files, points at the lines behind its opinion, and lists what
|
|
63
|
+
argues against it. The quotes in the report come from the file, so evidence cannot be invented.
|
|
64
|
+
It never sees the signal scores. It runs automatically when a model is available, because in
|
|
65
|
+
evaluation it was the only evidence that worked on recent code.
|
|
66
|
+
|
|
67
|
+
The two are combined into one estimate for the repository, with weights fitted on data.
|
|
68
|
+
Commit history and README style are shown as context but not scored: in evaluation they
|
|
69
|
+
told old projects from new ones, not people from AI.
|
|
70
|
+
|
|
71
|
+
## Input
|
|
72
|
+
|
|
73
|
+
| Field | Default | Meaning |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `target` | required | GitHub URL (`https://github.com/<owner>/<repo>`) or local path. The primary input. |
|
|
76
|
+
| `paths` | all files | Restrict the analysis to these files or folders. |
|
|
77
|
+
| `branch` | default branch | Branch to analyse (GitHub only). |
|
|
78
|
+
| `use_llm_judge` | when a model is available | Ask a model to judge a sample of files. `false` skips it (weak, low confidence); `true` requires it. |
|
|
79
|
+
| `include_tests` | off | Score test files too (they are reported separately). |
|
|
80
|
+
|
|
81
|
+
`margin info ai-code-detector` shows the rest, including the judge's limits on files, time
|
|
82
|
+
and cost.
|
|
83
|
+
|
|
84
|
+
## Output
|
|
85
|
+
|
|
86
|
+
The headline is an estimate with a range and a confidence level, for example "0.55 to 0.80,
|
|
87
|
+
medium confidence", never a bare percentage. When confidence is low, the report says why:
|
|
88
|
+
few signals fired, few files could be read, or the evidence pulled both ways.
|
|
89
|
+
|
|
90
|
+
If the repository's own metadata names an AI tool (a `Co-authored-by` trailer, say), the
|
|
91
|
+
report says so separately. That proves the tool was used, not how much of the code it wrote,
|
|
92
|
+
so it doesn't move the estimate.
|
|
93
|
+
|
|
94
|
+
Then comes the evidence: what points toward AI and what points toward a person, each item
|
|
95
|
+
tied to a file, a line range or a commit. Every file gets its own score with the signals that
|
|
96
|
+
fired and, if the judge read it, the lines it quoted. The report also includes short excerpts
|
|
97
|
+
of the code around each marked line (at most 80 lines per file and 800 overall), so you can
|
|
98
|
+
check it without opening the repository.
|
|
99
|
+
|
|
100
|
+
Finally there's the history: each commit's date, subject, the number of files it touched,
|
|
101
|
+
any AI tool it names, and whether it was unusually large. Author names are left out on
|
|
102
|
+
purpose. The report is about code, not about people. It also lists every file that wasn't
|
|
103
|
+
scored and why (another language, a test file, too small, a lockfile and so on).
|
|
104
|
+
|
|
105
|
+
## Limits
|
|
106
|
+
|
|
107
|
+
No tool can prove that code was written by AI. Clean human code can look machine-made, and
|
|
108
|
+
edited AI code can look human. The detector is tuned to avoid false accusations, even if
|
|
109
|
+
that means it misses some AI-written code.
|
|
110
|
+
|
|
111
|
+
It reads Python, JavaScript and TypeScript; other languages lower the confidence. Projects
|
|
112
|
+
with large generated-looking data files (such as locale tables) can score high. It has not
|
|
113
|
+
been tested on code written with light AI help or on AI code edited by people.
|
|
114
|
+
|
|
115
|
+
Use it to inform a conversation. It must not be the sole basis for accusing a student,
|
|
116
|
+
a contractor or a job candidate.
|
|
117
|
+
|
|
118
|
+
## Usage
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
margin run ai-code-detector https://github.com/owner/repo --format markdown
|
|
122
|
+
margin run ai-code-detector ./path/to/project --format json --out report.json
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
This agent lives in the [margin](https://github.com/Waddah0-0/margin) monorepo, in
|
|
128
|
+
[`agents/ai_code_detector`](https://github.com/Waddah0-0/margin/tree/main/agents/ai_code_detector).
|
|
129
|
+
It is mirrored, read-only, to
|
|
130
|
+
[Waddah0-0/margin-ai-code-detector](https://github.com/Waddah0-0/margin-ai-code-detector);
|
|
131
|
+
open issues and pull requests in the main repository.
|
|
132
|
+
|
|
133
|
+
The evaluation harness lives in `eval/`: `eval/run.py` scores a dataset manifest,
|
|
134
|
+
`eval/fit.py` fits and compares methodologies, `eval/tools/compare_judges.py` compares judge
|
|
135
|
+
models, and `eval/datasets/*/README.md` describe each dataset and its biases.
|
|
136
|
+
|
|
137
|
+
Run its tests with `uv run pytest agents/ai_code_detector`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
ai_code_detector/__init__.py,sha256=5vgHXulZOHb4djQwrHNVPqZ01tUM-p8avNOkMZYrZ20,383
|
|
2
|
+
ai_code_detector/agent.py,sha256=B7FeRFrnxZI-dc50620vlOYOf5D8R5ReR57ZoEyIQo4,2151
|
|
3
|
+
ai_code_detector/aggregate.py,sha256=P16voiZtVhlSLPcbmX06TQqA0TvhhMwsb-7WNjKahg4,7661
|
|
4
|
+
ai_code_detector/models.py,sha256=ahq9uezghEfUR-v1COg-UGj8jtDYC8G98GmuVuArVCI,6806
|
|
5
|
+
ai_code_detector/pipeline.py,sha256=nUewRN_KlAze-IcqrGgnEXU-tNA0QSaYaTS8mZwDCIY,18447
|
|
6
|
+
ai_code_detector/py.typed,sha256=8PjyZ1aVoQpRVvt71muvuq5qE-jTFZkK-GLHkhdebmc,26
|
|
7
|
+
ai_code_detector/report.py,sha256=cilHVkzpjyHi91F4kEGlp1VpUUOZTVcWOAnzzs-wa7Q,6694
|
|
8
|
+
ai_code_detector/judge/__init__.py,sha256=m6b81MAl5UroLgKxZ30RazedvmDiCbzvmVe4hwSZIk0,87
|
|
9
|
+
ai_code_detector/judge/llm_judge.py,sha256=MIYieKcqRITcyK9_89DPFunOgHM7YIG2hVSvDrXMevU,14673
|
|
10
|
+
ai_code_detector/judge/sampler.py,sha256=jyLNeSuV0z6zdkkfI83DfiVbfk07LKaiI9KEgPfSmiw,1463
|
|
11
|
+
ai_code_detector/judge/prompts/__init__.py,sha256=omYOoiDIHBE1JpFCA0riX4BDxjVNzyLRgfAoxnml5ug,31
|
|
12
|
+
ai_code_detector/judge/prompts/judge_v1.md,sha256=mbLLcmzdwkOhowb20DVeVuVlLEyN6u6XaUyiyYfZAg8,1432
|
|
13
|
+
ai_code_detector/judge/prompts/judge_v2.md,sha256=PkTC5Gxs2Ibm5H5nBYkpNROBiBBN_qsyfTAIbJQg7Xg,1416
|
|
14
|
+
ai_code_detector/markers/__init__.py,sha256=r3zqdqKtqpUBduMKrr4IM1t_dYd6Xzx-T6DelQ83a3w,3792
|
|
15
|
+
ai_code_detector/markers/v1.toml,sha256=v3TnSv7TxTWjRDcLOvGpISaWsLJCnCfM4Gt0Wp_WljI,2411
|
|
16
|
+
ai_code_detector/methodology/__init__.py,sha256=MUQFGzB6lfOqk_lgZ1l4WXmT6Odu9htibFOX0WViRCg,2234
|
|
17
|
+
ai_code_detector/methodology/v0.toml,sha256=LZ49AOVexpRlV9mYxFrCL5-UU0uZrwOjqFBG_UEiJrk,3288
|
|
18
|
+
ai_code_detector/methodology/v1.toml,sha256=17GSjX5H8I5Y-QSzdHuwZu2IDknqumEbVYR2rq40kvU,4453
|
|
19
|
+
ai_code_detector/signals/__init__.py,sha256=t8OJ0flR_JmZZQqFKjS_hlD_R-eubxS5opmAvJlx6cY,357
|
|
20
|
+
ai_code_detector/signals/base.py,sha256=gwvhnFDIoQLn-dyZ9IsgPhcCz62PA6NIl4Rfp3rNdFY,1923
|
|
21
|
+
ai_code_detector/signals/file.py,sha256=dGmS-UFqdA_rCwdu6V-5eVHbcDSWeHmh4RGr_BgZesU,11617
|
|
22
|
+
ai_code_detector/signals/repo.py,sha256=kcDolCDfZv2_RbvizvcLjEIMG7dN1ERVfwrfXw94lSo,7296
|
|
23
|
+
ai_code_detector/source/__init__.py,sha256=w4xC32dVA90I_ZWzwrNDpbxVnaMlqeyJjP_tzrVtlfs,3248
|
|
24
|
+
ai_code_detector/source/javascript.py,sha256=2JyLnwNF0XcRSFTay3P5NT-tHtpu7zTrR0W818swZYE,8974
|
|
25
|
+
ai_code_detector/source/python.py,sha256=-UjqqLwC8ET2yEvmtym-87V30cQFsQJ-AX9tjI_q-cc,4980
|
|
26
|
+
margin_ai_code_detector-0.2.0.dist-info/METADATA,sha256=vwsh9u0AlnG0uKyZ-l46Hv9mtW50qr2rgFpRYRiSark,6856
|
|
27
|
+
margin_ai_code_detector-0.2.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
28
|
+
margin_ai_code_detector-0.2.0.dist-info/entry_points.txt,sha256=t4oYggZbemGjCj1cXWCmsU570fAN43APr-pJUcuNo7A,73
|
|
29
|
+
margin_ai_code_detector-0.2.0.dist-info/licenses/LICENSE,sha256=7dCPJ4m91LD52BnTk6tiuMOiQU5i6aoIfpSzGgb9mVY,1076
|
|
30
|
+
margin_ai_code_detector-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 margin contributors
|
|
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.
|