second-source 0.5.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.
- second_source/__init__.py +3 -0
- second_source/action/__init__.py +4 -0
- second_source/action/commands.py +88 -0
- second_source/action/event.py +89 -0
- second_source/action/inputs.py +118 -0
- second_source/action/main.py +203 -0
- second_source/action/publish.py +184 -0
- second_source/action/setup.py +143 -0
- second_source/action/sweep.py +85 -0
- second_source/action/wait.py +49 -0
- second_source/benchmark/__init__.py +1 -0
- second_source/benchmark/aidev.py +248 -0
- second_source/benchmark/aidev_local.py +85 -0
- second_source/benchmark/golden.py +314 -0
- second_source/benchmark/redact.py +45 -0
- second_source/benchmark/rescore.py +388 -0
- second_source/benchmark/runner.py +159 -0
- second_source/benchmark/sample.py +243 -0
- second_source/benchmark/stats.py +363 -0
- second_source/cli/__init__.py +1 -0
- second_source/cli/bench.py +427 -0
- second_source/cli/main.py +182 -0
- second_source/core/__init__.py +4 -0
- second_source/core/aggregate.py +102 -0
- second_source/core/checks.py +470 -0
- second_source/core/engine.py +98 -0
- second_source/core/evidence.py +29 -0
- second_source/core/expr.py +206 -0
- second_source/core/hashing.py +41 -0
- second_source/core/model.py +112 -0
- second_source/core/pack.py +156 -0
- second_source/packs/__init__.py +1 -0
- second_source/packs/coding/__init__.py +16 -0
- second_source/packs/coding/checks/ci_config_caution.yaml +23 -0
- second_source/packs/coding/checks/ci_result.yaml +133 -0
- second_source/packs/coding/checks/ci_weakening_caution.yaml +27 -0
- second_source/packs/coding/checks/deployed.yaml +36 -0
- second_source/packs/coding/checks/docs_updated.yaml +22 -0
- second_source/packs/coding/checks/fixes_issue.yaml +58 -0
- second_source/packs/coding/checks/fixes_issue_durable.yaml +60 -0
- second_source/packs/coding/checks/integrity_guard.yaml +34 -0
- second_source/packs/coding/checks/integrity_inspection.yaml +21 -0
- second_source/packs/coding/checks/lint_caution.yaml +22 -0
- second_source/packs/coding/checks/matching_jobs_caution.yaml +22 -0
- second_source/packs/coding/checks/not_reverted.yaml +38 -0
- second_source/packs/coding/checks/tests_added.yaml +25 -0
- second_source/packs/coding/checks/tests_added_guard.yaml +26 -0
- second_source/packs/coding/checks/tests_removed_caution.yaml +23 -0
- second_source/packs/coding/detection.py +94 -0
- second_source/packs/coding/diff_facts.py +665 -0
- second_source/packs/coding/extract.py +911 -0
- second_source/packs/coding/functions.py +241 -0
- second_source/packs/coding/pack.yaml +33 -0
- second_source/packs/coding/trusted_rules.yaml +50 -0
- second_source/pipeline.py +112 -0
- second_source/report/__init__.py +1 -0
- second_source/report/render.py +503 -0
- second_source/sources/__init__.py +1 -0
- second_source/sources/github/__init__.py +4 -0
- second_source/sources/github/auth.py +48 -0
- second_source/sources/github/cache.py +67 -0
- second_source/sources/github/client.py +261 -0
- second_source/sources/github/mappers.py +454 -0
- second_source/sources/github/source.py +385 -0
- second_source/sources/github/urls.py +51 -0
- second_source-0.5.0.dist-info/METADATA +311 -0
- second_source-0.5.0.dist-info/RECORD +71 -0
- second_source-0.5.0.dist-info/WHEEL +4 -0
- second_source-0.5.0.dist-info/entry_points.txt +2 -0
- second_source-0.5.0.dist-info/licenses/LICENSE +202 -0
- second_source-0.5.0.dist-info/licenses/NOTICE +9 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Detect which coding agent (if any) authored a pull request.
|
|
2
|
+
|
|
3
|
+
Detection is a list of data rules, checked in order of how reliable the signal is:
|
|
4
|
+
|
|
5
|
+
1. the PR author account (bots and apps have fixed logins),
|
|
6
|
+
2. markers the agent writes into the PR body,
|
|
7
|
+
3. ``Co-Authored-By`` trailers in commit messages,
|
|
8
|
+
4. the head branch prefix (weakest: a human can create a ``codex/...`` branch).
|
|
9
|
+
|
|
10
|
+
The first matching rule wins. Rules are versioned with the pack; the benchmark measures their
|
|
11
|
+
precision against the AIDev dataset's agent labels.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import re
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from dataclasses import dataclass, field
|
|
19
|
+
from enum import StrEnum
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Signal(StrEnum):
|
|
23
|
+
AUTHOR = "author"
|
|
24
|
+
BODY_MARKER = "body_marker"
|
|
25
|
+
COMMIT_TRAILER = "commit_trailer"
|
|
26
|
+
BRANCH_PREFIX = "branch_prefix"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class PullRequestSignals:
|
|
31
|
+
"""The facts about a PR that detection looks at. Sources fill this in."""
|
|
32
|
+
|
|
33
|
+
author_login: str
|
|
34
|
+
head_branch: str = ""
|
|
35
|
+
body: str = ""
|
|
36
|
+
commit_messages: Sequence[str] = field(default_factory=tuple)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class AgentMatch:
|
|
41
|
+
agent: str # stable agent id, e.g. "claude_code"
|
|
42
|
+
signal: Signal # which kind of evidence identified it
|
|
43
|
+
detail: str # the exact value that matched (for transparency in reports)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class _Rule:
|
|
48
|
+
agent: str
|
|
49
|
+
signal: Signal
|
|
50
|
+
pattern: re.Pattern[str]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _rule(agent: str, signal: Signal, pattern: str) -> _Rule:
|
|
54
|
+
return _Rule(agent, signal, re.compile(pattern, re.IGNORECASE))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# Ordered from most to least reliable. Logins are matched exactly (anchored).
|
|
58
|
+
RULES: tuple[_Rule, ...] = (
|
|
59
|
+
_rule("copilot", Signal.AUTHOR, r"^copilot$"),
|
|
60
|
+
_rule("devin", Signal.AUTHOR, r"^devin-ai-integration\[bot\]$"),
|
|
61
|
+
_rule("jules", Signal.AUTHOR, r"^google-labs-jules\[bot\]$"),
|
|
62
|
+
_rule("cursor", Signal.AUTHOR, r"^(cursor\[bot\]|cursoragent)$"),
|
|
63
|
+
_rule("claude_code", Signal.BODY_MARKER, r"generated with \[?claude code\]?"),
|
|
64
|
+
_rule("claude_code", Signal.COMMIT_TRAILER, r"^co-authored-by:\s*claude\b"),
|
|
65
|
+
_rule("codex", Signal.BRANCH_PREFIX, r"^codex/"),
|
|
66
|
+
_rule("copilot", Signal.BRANCH_PREFIX, r"^copilot/"),
|
|
67
|
+
_rule("cursor", Signal.BRANCH_PREFIX, r"^cursor/"),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
AGENTS = frozenset(rule.agent for rule in RULES)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def detect_agent(signals: PullRequestSignals) -> AgentMatch | None:
|
|
74
|
+
"""Return the agent that authored the PR, or None if no rule matches (likely a human)."""
|
|
75
|
+
for rule in RULES:
|
|
76
|
+
for candidate in _candidates(rule.signal, signals):
|
|
77
|
+
found = rule.pattern.search(candidate)
|
|
78
|
+
if found:
|
|
79
|
+
return AgentMatch(rule.agent, rule.signal, found.group(0).strip())
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _candidates(signal: Signal, signals: PullRequestSignals) -> list[str]:
|
|
84
|
+
"""The text values a rule of this signal kind should be tested against."""
|
|
85
|
+
if signal is Signal.AUTHOR:
|
|
86
|
+
return [signals.author_login]
|
|
87
|
+
if signal is Signal.BODY_MARKER:
|
|
88
|
+
return [signals.body]
|
|
89
|
+
if signal is Signal.COMMIT_TRAILER:
|
|
90
|
+
# Trailers are lines; test each line of each commit message on its own.
|
|
91
|
+
return [
|
|
92
|
+
line.strip() for message in signals.commit_messages for line in message.splitlines()
|
|
93
|
+
]
|
|
94
|
+
return [signals.head_branch]
|