readthrough 0.4.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 (73) hide show
  1. readthrough/__init__.py +8 -0
  2. readthrough/__main__.py +3 -0
  3. readthrough/agents.py +344 -0
  4. readthrough/analyze.py +537 -0
  5. readthrough/assets/SKILL.md +86 -0
  6. readthrough/assets/defaults.toml +143 -0
  7. readthrough/assets/profile-reference.md +133 -0
  8. readthrough/assets/vendor/README.md +22 -0
  9. readthrough/assets/vendor/cose-base.js +3214 -0
  10. readthrough/assets/vendor/cytoscape-fcose.js +1549 -0
  11. readthrough/assets/vendor/cytoscape.min.js +31 -0
  12. readthrough/assets/vendor/layout-base.js +5230 -0
  13. readthrough/assets/vendor/licenses/cose-base-LICENSE +21 -0
  14. readthrough/assets/vendor/licenses/cytoscape-LICENSE +19 -0
  15. readthrough/assets/vendor/licenses/cytoscape-fcose-LICENSE +19 -0
  16. readthrough/assets/vendor/licenses/dompurify-LICENSE +202 -0
  17. readthrough/assets/vendor/licenses/layout-base-LICENSE +21 -0
  18. readthrough/assets/vendor/licenses/lucide-LICENSE +15 -0
  19. readthrough/assets/vendor/licenses/marked-LICENSE +44 -0
  20. readthrough/assets/vendor/lucide-icons.js +36 -0
  21. readthrough/assets/vendor/marked.umd.js +82 -0
  22. readthrough/assets/vendor/purify.min.js +7 -0
  23. readthrough/assets/web/dashboard.css +202 -0
  24. readthrough/assets/web/dashboard.html +48 -0
  25. readthrough/assets/web/dashboard.js +937 -0
  26. readthrough/assets/web/setup.css +57 -0
  27. readthrough/assets/web/setup.html +28 -0
  28. readthrough/assets/web/setup.js +342 -0
  29. readthrough/assets/web/theme.css +36 -0
  30. readthrough/assistants.py +699 -0
  31. readthrough/brief.py +145 -0
  32. readthrough/build.py +616 -0
  33. readthrough/ci.py +107 -0
  34. readthrough/cli.py +958 -0
  35. readthrough/config.py +533 -0
  36. readthrough/contract.py +394 -0
  37. readthrough/engine.py +230 -0
  38. readthrough/faults.py +92 -0
  39. readthrough/files.py +110 -0
  40. readthrough/forges/__init__.py +614 -0
  41. readthrough/forges/azure_devops.py +658 -0
  42. readthrough/forges/forgejo.py +300 -0
  43. readthrough/forges/github.py +487 -0
  44. readthrough/forges/gitlab.py +335 -0
  45. readthrough/ledger.py +61 -0
  46. readthrough/limits.py +26 -0
  47. readthrough/logs.py +169 -0
  48. readthrough/membership.py +76 -0
  49. readthrough/model.py +177 -0
  50. readthrough/onboard.py +551 -0
  51. readthrough/onboard_model.py +319 -0
  52. readthrough/process.py +169 -0
  53. readthrough/profile.py +699 -0
  54. readthrough/py.typed +0 -0
  55. readthrough/registry.py +157 -0
  56. readthrough/review.py +394 -0
  57. readthrough/rules.py +111 -0
  58. readthrough/runtimes/__init__.py +297 -0
  59. readthrough/runtimes/anthropic.py +278 -0
  60. readthrough/runtimes/copilot.py +313 -0
  61. readthrough/runtimes/openai.py +307 -0
  62. readthrough/serve.py +817 -0
  63. readthrough/study.py +327 -0
  64. readthrough/system.py +205 -0
  65. readthrough/terminals.py +168 -0
  66. readthrough/tuning.py +266 -0
  67. readthrough/usage.py +169 -0
  68. readthrough/web_setup.py +635 -0
  69. readthrough-0.4.0.dist-info/METADATA +123 -0
  70. readthrough-0.4.0.dist-info/RECORD +73 -0
  71. readthrough-0.4.0.dist-info/WHEEL +4 -0
  72. readthrough-0.4.0.dist-info/entry_points.txt +2 -0
  73. readthrough-0.4.0.dist-info/licenses/LICENSE +21 -0
readthrough/model.py ADDED
@@ -0,0 +1,177 @@
1
+ """The pull request as readthrough sees it, whichever forge it came from.
2
+
3
+ Every forge adapter maps its own API into these records, and the analysis reads only these. The fields are
4
+ the concepts the analysis consumes, not a union of every forge's schema. Where forges disagree on what a
5
+ value means, the record keeps the distinction (an approval is not the same fact as "mergeable").
6
+
7
+ A value a forge may not be able to supply is a ``Capability``: ``known`` (including a known empty value),
8
+ ``unsupported`` (this forge has no such concept, or no API for it), or ``unavailable`` (it has one, but the
9
+ call failed this time). The build turns the last two into a warning and a per-PR signal, so a missing
10
+ answer is never read as "none".
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import re
16
+ from dataclasses import dataclass, field
17
+ from typing import Generic, TypeVar
18
+
19
+ T = TypeVar("T")
20
+
21
+ # One segment of a repo's path on its forge: owner, group, project, or name. Azure DevOps projects may be
22
+ # called "Delivery Team", so single spaces between words are allowed; every forge's own rule is stricter.
23
+ PATH_SEGMENT = r"[\w.-]+(?: [\w.-]+)*"
24
+ REPO_PATH_RE = re.compile(rf"{PATH_SEGMENT}(?:/{PATH_SEGMENT})+")
25
+ # A PR number as it may appear in a URL or a marker. GitHub numbers per repo (six digits on the busiest);
26
+ # Azure DevOps numbers per organization, and a big one is past 17 million. Bounded so inputs stay strict.
27
+ PR_NUMBER = r"\d{1,9}"
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class Capability(Generic[T]):
32
+ """A value the forge may or may not have been able to provide."""
33
+
34
+ kind: str # known | unsupported | unavailable
35
+ value: T | None = None
36
+ reason: str = ""
37
+
38
+ @property
39
+ def known(self) -> bool:
40
+ return self.kind == "known"
41
+
42
+ def get(self, default: T) -> T:
43
+ """The value when known, otherwise ``default``. Callers must have reported the gap first."""
44
+ return self.value if self.kind == "known" and self.value is not None else default
45
+
46
+
47
+ def known(value: T) -> Capability[T]:
48
+ return Capability("known", value)
49
+
50
+
51
+ def unsupported(reason: str) -> Capability[T]:
52
+ return Capability("unsupported", reason=reason)
53
+
54
+
55
+ def unavailable(reason: str) -> Capability[T]:
56
+ return Capability("unavailable", reason=reason)
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class Author:
61
+ login: str
62
+ bot: bool = False
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class ChangedFile:
67
+ path: str
68
+ additions: int
69
+ deletions: int
70
+ change: str = "MODIFIED" # ADDED | MODIFIED | DELETED | RENAMED | COPIED | CHANGED
71
+
72
+
73
+ @dataclass(frozen=True)
74
+ class Review:
75
+ author: str
76
+ state: str # APPROVED | CHANGES_REQUESTED | COMMENTED | DISMISSED | PENDING
77
+ submitted: str | None = None # ISO 8601
78
+
79
+
80
+ @dataclass(frozen=True)
81
+ class Thread:
82
+ """One review discussion, with its first comment."""
83
+
84
+ author: str
85
+ body: str
86
+ body_html: str = ""
87
+ path: str | None = None
88
+ line: int | None = None
89
+ resolved: bool = False
90
+ outdated: bool = False
91
+
92
+
93
+ @dataclass(frozen=True)
94
+ class Check:
95
+ """One CI check or commit status on the head commit."""
96
+
97
+ name: str
98
+ status: str # COMPLETED | IN_PROGRESS | QUEUED | PENDING
99
+ conclusion: str | None = (
100
+ None # SUCCESS | FAILURE | NEUTRAL | CANCELLED | SKIPPED | TIMED_OUT | ACTION_REQUIRED | ERROR
101
+ )
102
+ url: str | None = None
103
+ started: str | None = None
104
+ completed: str | None = None
105
+
106
+
107
+ @dataclass(frozen=True)
108
+ class Issue:
109
+ number: int
110
+ title: str
111
+ url: str
112
+
113
+
114
+ # Author associations, in GitHub's vocabulary, which the profile's [authors] rules are written against.
115
+ # Adapters for forges with other vocabularies map into it (a GitLab Maintainer is a MEMBER, say).
116
+ ASSOCIATIONS = ("OWNER", "MEMBER", "COLLABORATOR", "CONTRIBUTOR", "FIRST_TIME_CONTRIBUTOR", "FIRST_TIMER", "NONE")
117
+
118
+ # The review decision: the forge's own verdict on whether the PR has the approvals it needs.
119
+ DECISIONS = ("APPROVED", "CHANGES_REQUESTED", "REVIEW_REQUIRED", "NONE")
120
+
121
+
122
+ @dataclass
123
+ class PullRequest:
124
+ number: int
125
+ title: str
126
+ url: str
127
+ body: str
128
+ draft: bool
129
+ created: str
130
+ updated: str
131
+ additions: int
132
+ deletions: int
133
+ changed_files: int
134
+ head: str
135
+ base: str
136
+ author: Author
137
+ files: list[ChangedFile]
138
+ body_html: str = ""
139
+ labels: list[str] = field(default_factory=list)
140
+ requested: list[str] = field(default_factory=list) # logins or team names asked to review
141
+ reviews: list[Review] = field(default_factory=list) # the latest review per reviewer
142
+ comments: int = 0
143
+ last_commit: str | None = None # when the head commit was committed
144
+ issues: list[Issue] = field(default_factory=list) # issues this PR closes
145
+ association: Capability[str] = field(default_factory=lambda: unsupported("author association"))
146
+ decision: Capability[str] = field(default_factory=lambda: unsupported("review decision"))
147
+ mergeable: Capability[str] = field(
148
+ default_factory=lambda: unsupported("merge state")
149
+ ) # MERGEABLE | CONFLICTING | UNKNOWN
150
+ threads: Capability[list[Thread]] = field(default_factory=lambda: unsupported("review threads"))
151
+ checks: Capability[list[Check]] = field(default_factory=lambda: unsupported("CI checks"))
152
+ # Whether the per-file additions and deletions mean anything. A forge without line counts (Azure DevOps)
153
+ # marks this unsupported, and the analysis weighs files by count instead of by lines.
154
+ line_counts: Capability[bool] = field(default_factory=lambda: known(True))
155
+ truncated: dict[str, tuple[int, int]] = field(default_factory=dict) # field -> (have, of) when a list was cut short
156
+
157
+ def gaps(self) -> list[tuple[str, Capability]]:
158
+ """The capabilities this record couldn't fill, for warnings and signals."""
159
+ out = []
160
+ for name in GAP_FIELDS:
161
+ cap: Capability = getattr(self, name)
162
+ if not cap.known:
163
+ out.append((name, cap))
164
+ return out
165
+
166
+
167
+ GAP_FIELDS = ("association", "decision", "mergeable", "threads", "checks", "line_counts")
168
+
169
+
170
+ @dataclass(frozen=True)
171
+ class MergedPullRequest:
172
+ """What onboarding needs from a recently merged PR: who, and which files."""
173
+
174
+ number: int
175
+ author: Author
176
+ association: Capability[str]
177
+ files: list[ChangedFile]