margin-ai-code-detector 0.2.0__py3-none-any.whl → 0.2.2__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.
@@ -3,7 +3,7 @@
3
3
  from ai_code_detector.agent import AICodeDetector
4
4
  from ai_code_detector.models import DetectorInput, DetectorOutput, FileScore, SignalHit
5
5
 
6
- __version__ = "0.2.0"
6
+ __version__ = "0.2.2"
7
7
 
8
8
  __all__ = [
9
9
  "AICodeDetector",
ai_code_detector/agent.py CHANGED
@@ -21,7 +21,7 @@ class AICodeDetector(BaseAgent):
21
21
  "Estimates how likely a repository was written with AI assistance, as a range with a "
22
22
  "confidence level and the evidence for and against."
23
23
  )
24
- version = "0.2.0"
24
+ version = "0.2.2"
25
25
  InputModel = DetectorInput
26
26
  OutputModel = DetectorOutput
27
27
  primary_input = "target"
@@ -15,6 +15,11 @@ from ai_code_detector.methodology import Methodology
15
15
  from ai_code_detector.models import Confidence, FileScore, SignalHit
16
16
 
17
17
 
18
+ def _count(n: int, one: str, many: str) -> str:
19
+ """'1 file', '3 files'."""
20
+ return f"{n} {one if n == 1 else many}"
21
+
22
+
18
23
  def sigmoid(x: float) -> float:
19
24
  return 1.0 / (1.0 + math.exp(-x))
20
25
 
@@ -152,10 +157,11 @@ def confidence_level(
152
157
  c = methodology.section("confidence")
153
158
  high_checks = [
154
159
  (facts.families >= c["high_families"],
155
- f"evidence came from {facts.families} kinds of signals (high confidence needs "
156
- f"{c['high_families']})"),
160
+ f"evidence came from {_count(facts.families, 'kind', 'kinds')} of signals (high "
161
+ f"confidence needs {c['high_families']})"),
157
162
  (facts.files >= c["high_files"],
158
- f"{facts.files} files could be analysed (high confidence needs {c['high_files']})"),
163
+ f"{_count(facts.files, 'file', 'files')} could be analysed (high confidence needs "
164
+ f"{c['high_files']})"),
159
165
  (facts.width <= c["high_max_width"],
160
166
  f"the range is {facts.width:.2f} wide (high confidence needs "
161
167
  f"at most {c['high_max_width']})"),
@@ -164,8 +170,10 @@ def confidence_level(
164
170
  ] # fmt: skip
165
171
  medium_checks = [
166
172
  (facts.families >= c["medium_families"],
167
- f"evidence came from only {facts.families} kind(s) of signals"),
168
- (facts.files >= c["medium_files"], f"only {facts.files} files could be analysed"),
173
+ f"evidence came from only {_count(facts.families, 'kind', 'kinds')} of signal"
174
+ if facts.families else "no kind of signal gave any evidence"),
175
+ (facts.files >= c["medium_files"],
176
+ f"only {_count(facts.files, 'file', 'files')} could be analysed"),
169
177
  (facts.width <= c["medium_max_width"], f"the range is wide ({facts.width:.2f})"),
170
178
  ] # fmt: skip
171
179
  uncalibrated = (
@@ -227,6 +227,10 @@ class Judge:
227
227
  system = build_system_prompt(open_marker, close_marker, rubric_seed)
228
228
  start, end = self._fit_window(lines, flagged, system)
229
229
  window_text = numbered(lines, start, end)
230
+ while boundary in window_text: # astronomically unlikely, but the fence must hold
231
+ boundary = secrets.token_hex(6)
232
+ open_marker, close_marker = f"<<<CODE-{boundary}", f"CODE-{boundary}>>>"
233
+ system = build_system_prompt(open_marker, close_marker, rubric_seed)
230
234
  variant = f"rubric:{rubric_seed}"
231
235
  key = _cache_key(self.llm, window_text, variant)
232
236
  cache_file = _cache_dir() / f"{key}.json"
@@ -238,7 +242,9 @@ class Judge:
238
242
 
239
243
  scope = "the whole file" if (start, end) == (1, len(lines)) else f"lines {start}-{end}"
240
244
  prompt = (
241
- f"File: {path} ({scope} of {len(lines)} lines)\n\n"
245
+ # the name comes from the repository too: quoted and escaped, so it cannot add
246
+ # lines or instructions of its own outside the markers
247
+ f"File: {json.dumps(path[:200])} ({scope} of {len(lines)} lines)\n\n"
242
248
  f"{open_marker}\n{window_text}\n{close_marker}"
243
249
  )
244
250
  answer = await self.llm.complete_structured(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: margin-ai-code-detector
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Estimates how likely a codebase was written with AI assistance, as a range with the evidence for and against.
5
5
  Project-URL: Homepage, https://github.com/Waddah0-0/margin
6
6
  Project-URL: Source, https://github.com/Waddah0-0/margin/tree/main/agents/ai_code_detector
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.12
19
19
  Classifier: Topic :: Software Development :: Quality Assurance
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: >=3.11
22
- Requires-Dist: margin-core<0.2,>=0.1.0
22
+ Requires-Dist: margin-core<0.2,>=0.1.1
23
23
  Requires-Dist: tree-sitter-javascript>=0.23
24
24
  Requires-Dist: tree-sitter-typescript>=0.23
25
25
  Requires-Dist: tree-sitter<0.26,>=0.24
@@ -118,10 +118,16 @@ a contractor or a job candidate.
118
118
  ## Usage
119
119
 
120
120
  ```bash
121
+ pip install margin-cli margin-ai-code-detector
121
122
  margin run ai-code-detector https://github.com/owner/repo --format markdown
122
123
  margin run ai-code-detector ./path/to/project --format json --out report.json
123
124
  ```
124
125
 
126
+ For the web UI, install `margin-api` as well and run `margin-api`. The detector has its own
127
+ results page there, with the evidence side by side and the flagged lines marked in the code.
128
+ To use Anthropic or OpenAI instead of a local model, pick it on the Settings page, or pass
129
+ `--provider` and `--model` to `margin run`.
130
+
125
131
  ## Development
126
132
 
127
133
  This agent lives in the [margin](https://github.com/Waddah0-0/margin) monorepo, in
@@ -1,12 +1,12 @@
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
1
+ ai_code_detector/__init__.py,sha256=gR8DgPZUrX2sQwV5YXboTE-C7rQ24QsZIuWNOg4BAow,383
2
+ ai_code_detector/agent.py,sha256=Bn2Y2w2TY308Zr2YHnfE8Gs8OUwo7D7-nVyzjzOlWHM,2151
3
+ ai_code_detector/aggregate.py,sha256=L550ErgyAt6R3vwqIUDtLPFi1N-yORj0rdZoYavOFuM,7951
4
4
  ai_code_detector/models.py,sha256=ahq9uezghEfUR-v1COg-UGj8jtDYC8G98GmuVuArVCI,6806
5
5
  ai_code_detector/pipeline.py,sha256=nUewRN_KlAze-IcqrGgnEXU-tNA0QSaYaTS8mZwDCIY,18447
6
6
  ai_code_detector/py.typed,sha256=8PjyZ1aVoQpRVvt71muvuq5qE-jTFZkK-GLHkhdebmc,26
7
7
  ai_code_detector/report.py,sha256=cilHVkzpjyHi91F4kEGlp1VpUUOZTVcWOAnzzs-wa7Q,6694
8
8
  ai_code_detector/judge/__init__.py,sha256=m6b81MAl5UroLgKxZ30RazedvmDiCbzvmVe4hwSZIk0,87
9
- ai_code_detector/judge/llm_judge.py,sha256=MIYieKcqRITcyK9_89DPFunOgHM7YIG2hVSvDrXMevU,14673
9
+ ai_code_detector/judge/llm_judge.py,sha256=1VWtx2AXHFuzv7uhhhoh_Q4GFnsZ2n_V6wo82nFgXD8,15150
10
10
  ai_code_detector/judge/sampler.py,sha256=jyLNeSuV0z6zdkkfI83DfiVbfk07LKaiI9KEgPfSmiw,1463
11
11
  ai_code_detector/judge/prompts/__init__.py,sha256=omYOoiDIHBE1JpFCA0riX4BDxjVNzyLRgfAoxnml5ug,31
12
12
  ai_code_detector/judge/prompts/judge_v1.md,sha256=mbLLcmzdwkOhowb20DVeVuVlLEyN6u6XaUyiyYfZAg8,1432
@@ -23,8 +23,8 @@ ai_code_detector/signals/repo.py,sha256=kcDolCDfZv2_RbvizvcLjEIMG7dN1ERVfwrfXw94
23
23
  ai_code_detector/source/__init__.py,sha256=w4xC32dVA90I_ZWzwrNDpbxVnaMlqeyJjP_tzrVtlfs,3248
24
24
  ai_code_detector/source/javascript.py,sha256=2JyLnwNF0XcRSFTay3P5NT-tHtpu7zTrR0W818swZYE,8974
25
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,,
26
+ margin_ai_code_detector-0.2.2.dist-info/METADATA,sha256=gakQlH6oav-N5MbQqxxvDN52xQbFOJ1yspQi6tsIi_4,7224
27
+ margin_ai_code_detector-0.2.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
28
+ margin_ai_code_detector-0.2.2.dist-info/entry_points.txt,sha256=t4oYggZbemGjCj1cXWCmsU570fAN43APr-pJUcuNo7A,73
29
+ margin_ai_code_detector-0.2.2.dist-info/licenses/LICENSE,sha256=7dCPJ4m91LD52BnTk6tiuMOiQU5i6aoIfpSzGgb9mVY,1076
30
+ margin_ai_code_detector-0.2.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any