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.
Files changed (71) hide show
  1. second_source/__init__.py +3 -0
  2. second_source/action/__init__.py +4 -0
  3. second_source/action/commands.py +88 -0
  4. second_source/action/event.py +89 -0
  5. second_source/action/inputs.py +118 -0
  6. second_source/action/main.py +203 -0
  7. second_source/action/publish.py +184 -0
  8. second_source/action/setup.py +143 -0
  9. second_source/action/sweep.py +85 -0
  10. second_source/action/wait.py +49 -0
  11. second_source/benchmark/__init__.py +1 -0
  12. second_source/benchmark/aidev.py +248 -0
  13. second_source/benchmark/aidev_local.py +85 -0
  14. second_source/benchmark/golden.py +314 -0
  15. second_source/benchmark/redact.py +45 -0
  16. second_source/benchmark/rescore.py +388 -0
  17. second_source/benchmark/runner.py +159 -0
  18. second_source/benchmark/sample.py +243 -0
  19. second_source/benchmark/stats.py +363 -0
  20. second_source/cli/__init__.py +1 -0
  21. second_source/cli/bench.py +427 -0
  22. second_source/cli/main.py +182 -0
  23. second_source/core/__init__.py +4 -0
  24. second_source/core/aggregate.py +102 -0
  25. second_source/core/checks.py +470 -0
  26. second_source/core/engine.py +98 -0
  27. second_source/core/evidence.py +29 -0
  28. second_source/core/expr.py +206 -0
  29. second_source/core/hashing.py +41 -0
  30. second_source/core/model.py +112 -0
  31. second_source/core/pack.py +156 -0
  32. second_source/packs/__init__.py +1 -0
  33. second_source/packs/coding/__init__.py +16 -0
  34. second_source/packs/coding/checks/ci_config_caution.yaml +23 -0
  35. second_source/packs/coding/checks/ci_result.yaml +133 -0
  36. second_source/packs/coding/checks/ci_weakening_caution.yaml +27 -0
  37. second_source/packs/coding/checks/deployed.yaml +36 -0
  38. second_source/packs/coding/checks/docs_updated.yaml +22 -0
  39. second_source/packs/coding/checks/fixes_issue.yaml +58 -0
  40. second_source/packs/coding/checks/fixes_issue_durable.yaml +60 -0
  41. second_source/packs/coding/checks/integrity_guard.yaml +34 -0
  42. second_source/packs/coding/checks/integrity_inspection.yaml +21 -0
  43. second_source/packs/coding/checks/lint_caution.yaml +22 -0
  44. second_source/packs/coding/checks/matching_jobs_caution.yaml +22 -0
  45. second_source/packs/coding/checks/not_reverted.yaml +38 -0
  46. second_source/packs/coding/checks/tests_added.yaml +25 -0
  47. second_source/packs/coding/checks/tests_added_guard.yaml +26 -0
  48. second_source/packs/coding/checks/tests_removed_caution.yaml +23 -0
  49. second_source/packs/coding/detection.py +94 -0
  50. second_source/packs/coding/diff_facts.py +665 -0
  51. second_source/packs/coding/extract.py +911 -0
  52. second_source/packs/coding/functions.py +241 -0
  53. second_source/packs/coding/pack.yaml +33 -0
  54. second_source/packs/coding/trusted_rules.yaml +50 -0
  55. second_source/pipeline.py +112 -0
  56. second_source/report/__init__.py +1 -0
  57. second_source/report/render.py +503 -0
  58. second_source/sources/__init__.py +1 -0
  59. second_source/sources/github/__init__.py +4 -0
  60. second_source/sources/github/auth.py +48 -0
  61. second_source/sources/github/cache.py +67 -0
  62. second_source/sources/github/client.py +261 -0
  63. second_source/sources/github/mappers.py +454 -0
  64. second_source/sources/github/source.py +385 -0
  65. second_source/sources/github/urls.py +51 -0
  66. second_source-0.5.0.dist-info/METADATA +311 -0
  67. second_source-0.5.0.dist-info/RECORD +71 -0
  68. second_source-0.5.0.dist-info/WHEEL +4 -0
  69. second_source-0.5.0.dist-info/entry_points.txt +2 -0
  70. second_source-0.5.0.dist-info/licenses/LICENSE +202 -0
  71. 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]