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.
- readthrough/__init__.py +8 -0
- readthrough/__main__.py +3 -0
- readthrough/agents.py +344 -0
- readthrough/analyze.py +537 -0
- readthrough/assets/SKILL.md +86 -0
- readthrough/assets/defaults.toml +143 -0
- readthrough/assets/profile-reference.md +133 -0
- readthrough/assets/vendor/README.md +22 -0
- readthrough/assets/vendor/cose-base.js +3214 -0
- readthrough/assets/vendor/cytoscape-fcose.js +1549 -0
- readthrough/assets/vendor/cytoscape.min.js +31 -0
- readthrough/assets/vendor/layout-base.js +5230 -0
- readthrough/assets/vendor/licenses/cose-base-LICENSE +21 -0
- readthrough/assets/vendor/licenses/cytoscape-LICENSE +19 -0
- readthrough/assets/vendor/licenses/cytoscape-fcose-LICENSE +19 -0
- readthrough/assets/vendor/licenses/dompurify-LICENSE +202 -0
- readthrough/assets/vendor/licenses/layout-base-LICENSE +21 -0
- readthrough/assets/vendor/licenses/lucide-LICENSE +15 -0
- readthrough/assets/vendor/licenses/marked-LICENSE +44 -0
- readthrough/assets/vendor/lucide-icons.js +36 -0
- readthrough/assets/vendor/marked.umd.js +82 -0
- readthrough/assets/vendor/purify.min.js +7 -0
- readthrough/assets/web/dashboard.css +202 -0
- readthrough/assets/web/dashboard.html +48 -0
- readthrough/assets/web/dashboard.js +937 -0
- readthrough/assets/web/setup.css +57 -0
- readthrough/assets/web/setup.html +28 -0
- readthrough/assets/web/setup.js +342 -0
- readthrough/assets/web/theme.css +36 -0
- readthrough/assistants.py +699 -0
- readthrough/brief.py +145 -0
- readthrough/build.py +616 -0
- readthrough/ci.py +107 -0
- readthrough/cli.py +958 -0
- readthrough/config.py +533 -0
- readthrough/contract.py +394 -0
- readthrough/engine.py +230 -0
- readthrough/faults.py +92 -0
- readthrough/files.py +110 -0
- readthrough/forges/__init__.py +614 -0
- readthrough/forges/azure_devops.py +658 -0
- readthrough/forges/forgejo.py +300 -0
- readthrough/forges/github.py +487 -0
- readthrough/forges/gitlab.py +335 -0
- readthrough/ledger.py +61 -0
- readthrough/limits.py +26 -0
- readthrough/logs.py +169 -0
- readthrough/membership.py +76 -0
- readthrough/model.py +177 -0
- readthrough/onboard.py +551 -0
- readthrough/onboard_model.py +319 -0
- readthrough/process.py +169 -0
- readthrough/profile.py +699 -0
- readthrough/py.typed +0 -0
- readthrough/registry.py +157 -0
- readthrough/review.py +394 -0
- readthrough/rules.py +111 -0
- readthrough/runtimes/__init__.py +297 -0
- readthrough/runtimes/anthropic.py +278 -0
- readthrough/runtimes/copilot.py +313 -0
- readthrough/runtimes/openai.py +307 -0
- readthrough/serve.py +817 -0
- readthrough/study.py +327 -0
- readthrough/system.py +205 -0
- readthrough/terminals.py +168 -0
- readthrough/tuning.py +266 -0
- readthrough/usage.py +169 -0
- readthrough/web_setup.py +635 -0
- readthrough-0.4.0.dist-info/METADATA +123 -0
- readthrough-0.4.0.dist-info/RECORD +73 -0
- readthrough-0.4.0.dist-info/WHEEL +4 -0
- readthrough-0.4.0.dist-info/entry_points.txt +2 -0
- readthrough-0.4.0.dist-info/licenses/LICENSE +21 -0
readthrough/__init__.py
ADDED
readthrough/__main__.py
ADDED
readthrough/agents.py
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"""Deep-review agents: the coding agents a review session runs in, chosen by name.
|
|
2
|
+
|
|
3
|
+
A deep review is one persistent agent session per PR, started with a prompt that carries the PR's marker
|
|
4
|
+
and resumed by id after that. Two agents are built in, and ``agent = "auto"`` in ``config.toml`` takes the
|
|
5
|
+
first one installed:
|
|
6
|
+
|
|
7
|
+
- ``copilot``: the GitHub Copilot CLI. Sessions live under ``~/.copilot/session-state/<id>/`` and can be
|
|
8
|
+
opened in VS Code's agent window.
|
|
9
|
+
- ``claude``: Claude Code. Sessions are ``~/.claude/projects/<cwd>/<id>.jsonl``.
|
|
10
|
+
|
|
11
|
+
Each adapter knows how to start and resume a session, where its sessions are kept, how to read a session's
|
|
12
|
+
first user message (the marker in it links the session to a PR), whether a session is open right now when the
|
|
13
|
+
agent leaves a trace of that, and where its skills go, so ``readthrough install skill`` teaches every agent
|
|
14
|
+
you have. Anything an agent can't say (Claude Code leaves no "in use" mark) is reported as unknown, not as
|
|
15
|
+
"no". Others, such as Codex or Gemini CLI, are a registry entry away; what's shipped is what could be run.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sys
|
|
24
|
+
from collections.abc import Iterator
|
|
25
|
+
from dataclasses import dataclass, field
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import Any, ClassVar
|
|
28
|
+
|
|
29
|
+
from readthrough.process import installed, which
|
|
30
|
+
from readthrough.registry import Registry
|
|
31
|
+
from readthrough.tuning import default_tuning
|
|
32
|
+
|
|
33
|
+
AUTO = "auto"
|
|
34
|
+
AUTO_ORDER = ("copilot", "claude") # the first installed wins when agent = "auto"
|
|
35
|
+
SKILL_NAME = "readthrough"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class SessionRecord:
|
|
40
|
+
"""A session as found on disk, before anything is read from it."""
|
|
41
|
+
|
|
42
|
+
id: str
|
|
43
|
+
path: Path # the directory (Copilot) or file (Claude Code) holding it
|
|
44
|
+
updated: float # mtime, seconds since the epoch
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class SessionInfo:
|
|
49
|
+
id: str
|
|
50
|
+
exists: bool
|
|
51
|
+
updated: int | None = None
|
|
52
|
+
active: bool | None = None # None: this agent leaves no trace of whether the session is open
|
|
53
|
+
|
|
54
|
+
def payload(self) -> dict[str, Any]:
|
|
55
|
+
return {"id": self.id, "exists": self.exists, "updated": self.updated, "active": self.active}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class AgentOptions:
|
|
60
|
+
extra_args: list[str] = field(default_factory=list) # appended to every launch, after readthrough's own flags
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class Agent:
|
|
64
|
+
"""Base for agent adapters. Subclasses set the class attributes and implement the session methods."""
|
|
65
|
+
|
|
66
|
+
name: ClassVar[str] = ""
|
|
67
|
+
label: ClassVar[str] = ""
|
|
68
|
+
program: ClassVar[str] = "" # the executable, resolved through process.which
|
|
69
|
+
install_hint: ClassVar[str] = ""
|
|
70
|
+
|
|
71
|
+
def __init__(self, options: AgentOptions | None = None) -> None:
|
|
72
|
+
self.options = options or AgentOptions()
|
|
73
|
+
|
|
74
|
+
def available(self) -> bool:
|
|
75
|
+
return installed(self.program)
|
|
76
|
+
|
|
77
|
+
def executable(self) -> list[str]:
|
|
78
|
+
return which(self.program)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def skill_dir(self) -> Path:
|
|
82
|
+
"""Where this agent reads a skill named ``readthrough`` from."""
|
|
83
|
+
raise NotImplementedError
|
|
84
|
+
|
|
85
|
+
# ---- launching
|
|
86
|
+
|
|
87
|
+
def new_session_argv(
|
|
88
|
+
self, *, session_id: str, name: str, prompt: str, add_dirs: list[Path], extra: list[str] | None = None
|
|
89
|
+
) -> list[str]:
|
|
90
|
+
"""Start a session with this id and name, opened on ``prompt``. ``extra`` are the repo's own flags."""
|
|
91
|
+
raise NotImplementedError
|
|
92
|
+
|
|
93
|
+
def resume_argv(self, session_id: str, *, add_dirs: list[Path], extra: list[str] | None = None) -> list[str]:
|
|
94
|
+
raise NotImplementedError
|
|
95
|
+
|
|
96
|
+
def editor_url(self, session_id: str) -> str | None: # noqa: ARG002 - the default has no editor deep link
|
|
97
|
+
"""A link that opens the session in an editor, when the agent has one."""
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
# ---- sessions on disk
|
|
101
|
+
|
|
102
|
+
def sessions(self) -> Iterator[SessionRecord]:
|
|
103
|
+
raise NotImplementedError
|
|
104
|
+
|
|
105
|
+
def first_user_message(self, record: SessionRecord) -> str | None:
|
|
106
|
+
"""The first thing the user said, ``None`` while the session hasn't written it yet, ``""`` if it never will."""
|
|
107
|
+
raise NotImplementedError
|
|
108
|
+
|
|
109
|
+
def session_meta(self, record: SessionRecord) -> dict[str, str]: # noqa: ARG002 - the default records nothing
|
|
110
|
+
"""``client`` (what started it) and ``name`` when the agent records them."""
|
|
111
|
+
return {}
|
|
112
|
+
|
|
113
|
+
def session_info(self, session_id: str) -> SessionInfo:
|
|
114
|
+
raise NotImplementedError
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ---------------------------------------------------------------- GitHub Copilot CLI
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def copilot_home() -> Path:
|
|
121
|
+
return Path(os.environ.get("COPILOT_HOME", Path.home() / ".copilot"))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
AGENTS: Registry[type[Agent]] = Registry("agent")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@AGENTS.add("copilot", "GitHub Copilot CLI; sessions open in VS Code's agent window too", options=AgentOptions)
|
|
128
|
+
class Copilot(Agent):
|
|
129
|
+
name = "copilot"
|
|
130
|
+
label = "Copilot"
|
|
131
|
+
program = "copilot"
|
|
132
|
+
install_hint = "winget install GitHub.Copilot"
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def skill_dir(self) -> Path:
|
|
136
|
+
return Path.home() / ".agents" / "skills" / SKILL_NAME
|
|
137
|
+
|
|
138
|
+
def new_session_argv(
|
|
139
|
+
self, *, session_id: str, name: str, prompt: str, add_dirs: list[Path], extra: list[str] | None = None
|
|
140
|
+
) -> list[str]:
|
|
141
|
+
return [*self.executable(), f"--session-id={session_id}", f"--name={name}", "-i", prompt, *_dirs(add_dirs),
|
|
142
|
+
*self.options.extra_args, *(extra or [])] # fmt: skip
|
|
143
|
+
|
|
144
|
+
def resume_argv(self, session_id: str, *, add_dirs: list[Path], extra: list[str] | None = None) -> list[str]:
|
|
145
|
+
return [
|
|
146
|
+
*self.executable(),
|
|
147
|
+
f"--resume={session_id}",
|
|
148
|
+
*_dirs(add_dirs),
|
|
149
|
+
*self.options.extra_args,
|
|
150
|
+
*(extra or []),
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
def editor_url(self, session_id: str) -> str | None:
|
|
154
|
+
"""Open an existing Copilot CLI session in VS Code's Agents window (VS Code 1.138+)."""
|
|
155
|
+
return f"vscode://agents/agent-host-session/copilotcli/{session_id}"
|
|
156
|
+
|
|
157
|
+
def sessions(self) -> Iterator[SessionRecord]:
|
|
158
|
+
root = copilot_home() / "session-state"
|
|
159
|
+
try:
|
|
160
|
+
entries = list(os.scandir(root))
|
|
161
|
+
except FileNotFoundError:
|
|
162
|
+
return
|
|
163
|
+
for entry in entries:
|
|
164
|
+
if entry.is_dir():
|
|
165
|
+
events = Path(entry.path) / "events.jsonl"
|
|
166
|
+
stamp = (events if events.exists() else Path(entry.path)).stat().st_mtime
|
|
167
|
+
yield SessionRecord(entry.name, Path(entry.path), stamp)
|
|
168
|
+
|
|
169
|
+
def first_user_message(self, record: SessionRecord) -> str | None:
|
|
170
|
+
events = record.path / "events.jsonl"
|
|
171
|
+
if not events.exists():
|
|
172
|
+
return None
|
|
173
|
+
read = 0
|
|
174
|
+
with events.open("rb") as handle:
|
|
175
|
+
for raw in handle:
|
|
176
|
+
read += len(raw)
|
|
177
|
+
if read > default_tuning().sessions.first_message_bytes:
|
|
178
|
+
return ""
|
|
179
|
+
if b'"user.message"' not in raw:
|
|
180
|
+
continue
|
|
181
|
+
try:
|
|
182
|
+
event = json.loads(raw)
|
|
183
|
+
except ValueError:
|
|
184
|
+
return None # still being written
|
|
185
|
+
if event.get("type") == "user.message":
|
|
186
|
+
return str((event.get("data") or {}).get("content") or "")
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
def session_meta(self, record: SessionRecord) -> dict[str, str]:
|
|
190
|
+
path = record.path / "workspace.yaml"
|
|
191
|
+
if not path.exists():
|
|
192
|
+
return {}
|
|
193
|
+
fields = {}
|
|
194
|
+
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
195
|
+
key, sep, value = line.partition(":")
|
|
196
|
+
if sep and key in ("name", "client_name"):
|
|
197
|
+
fields["client" if key == "client_name" else key] = value.strip()
|
|
198
|
+
return fields
|
|
199
|
+
|
|
200
|
+
def session_info(self, session_id: str) -> SessionInfo:
|
|
201
|
+
folder = copilot_home() / "session-state" / session_id
|
|
202
|
+
if not folder.is_dir():
|
|
203
|
+
return SessionInfo(session_id, exists=False)
|
|
204
|
+
events = folder / "events.jsonl"
|
|
205
|
+
stamp = (events if events.exists() else folder).stat().st_mtime
|
|
206
|
+
# Copilot leaves inuse.<pid>.lock behind while a session is open; the process must still be running.
|
|
207
|
+
pids = (re.fullmatch(r"inuse\.(\d+)\.lock", p.name) for p in folder.glob("inuse.*.lock"))
|
|
208
|
+
active = any(pid_alive(int(m.group(1))) for m in pids if m)
|
|
209
|
+
return SessionInfo(session_id, exists=True, updated=round(stamp), active=active)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# ---------------------------------------------------------------- Claude Code
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def claude_home() -> Path:
|
|
216
|
+
return Path(os.environ.get("CLAUDE_CONFIG_DIR", Path.home() / ".claude"))
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@AGENTS.add("claude", "Claude Code; sessions are resumed by id in a terminal", options=AgentOptions)
|
|
220
|
+
class Claude(Agent):
|
|
221
|
+
name = "claude"
|
|
222
|
+
label = "Claude Code"
|
|
223
|
+
program = "claude"
|
|
224
|
+
install_hint = "npm install -g @anthropic-ai/claude-code"
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def skill_dir(self) -> Path:
|
|
228
|
+
return claude_home() / "skills" / SKILL_NAME
|
|
229
|
+
|
|
230
|
+
def new_session_argv(
|
|
231
|
+
self, *, session_id: str, name: str, prompt: str, add_dirs: list[Path], extra: list[str] | None = None
|
|
232
|
+
) -> list[str]:
|
|
233
|
+
return [*self.executable(), "--session-id", session_id, "--name", name, *_dirs(add_dirs),
|
|
234
|
+
*self.options.extra_args, *(extra or []), prompt] # fmt: skip
|
|
235
|
+
|
|
236
|
+
def resume_argv(self, session_id: str, *, add_dirs: list[Path], extra: list[str] | None = None) -> list[str]:
|
|
237
|
+
return [*self.executable(), "--resume", session_id, *_dirs(add_dirs), *self.options.extra_args, *(extra or [])]
|
|
238
|
+
|
|
239
|
+
def sessions(self) -> Iterator[SessionRecord]:
|
|
240
|
+
root = claude_home() / "projects"
|
|
241
|
+
if not root.is_dir():
|
|
242
|
+
return
|
|
243
|
+
for path in root.glob("*/*.jsonl"):
|
|
244
|
+
if _UUID_RE.fullmatch(path.stem):
|
|
245
|
+
yield SessionRecord(path.stem, path, path.stat().st_mtime)
|
|
246
|
+
|
|
247
|
+
def first_user_message(self, record: SessionRecord) -> str | None:
|
|
248
|
+
if not record.path.exists():
|
|
249
|
+
return None
|
|
250
|
+
read = 0
|
|
251
|
+
with record.path.open("rb") as handle:
|
|
252
|
+
for raw in handle:
|
|
253
|
+
read += len(raw)
|
|
254
|
+
if read > default_tuning().sessions.first_message_bytes:
|
|
255
|
+
return ""
|
|
256
|
+
if b'"type":"user"' not in raw and b'"type": "user"' not in raw:
|
|
257
|
+
continue
|
|
258
|
+
try:
|
|
259
|
+
event = json.loads(raw)
|
|
260
|
+
except ValueError:
|
|
261
|
+
return None # still being written
|
|
262
|
+
if event.get("type") == "user" and not event.get("isSidechain"):
|
|
263
|
+
content = (event.get("message") or {}).get("content")
|
|
264
|
+
if isinstance(content, list):
|
|
265
|
+
content = " ".join(str(p.get("text") or "") for p in content if isinstance(p, dict))
|
|
266
|
+
return str(content or "")
|
|
267
|
+
return None
|
|
268
|
+
|
|
269
|
+
def session_meta(self, record: SessionRecord) -> dict[str, str]: # noqa: ARG002 - Claude Code keeps no client name
|
|
270
|
+
return {"client": "claude"}
|
|
271
|
+
|
|
272
|
+
def session_info(self, session_id: str) -> SessionInfo:
|
|
273
|
+
matches = (
|
|
274
|
+
list((claude_home() / "projects").glob(f"*/{session_id}.jsonl")) if _UUID_RE.fullmatch(session_id) else []
|
|
275
|
+
)
|
|
276
|
+
if not matches:
|
|
277
|
+
return SessionInfo(session_id, exists=False)
|
|
278
|
+
# Claude Code leaves no mark of an open session, so whether it's open now can't be said.
|
|
279
|
+
return SessionInfo(session_id, exists=True, updated=round(max(p.stat().st_mtime for p in matches)), active=None)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
_UUID_RE = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _dirs(add_dirs: list[Path]) -> list[str]:
|
|
286
|
+
out: list[str] = []
|
|
287
|
+
for d in add_dirs:
|
|
288
|
+
out += ["--add-dir", str(d)]
|
|
289
|
+
return out
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def pid_alive(pid: int) -> bool:
|
|
293
|
+
if sys.platform == "win32":
|
|
294
|
+
import ctypes
|
|
295
|
+
|
|
296
|
+
kernel32 = ctypes.windll.kernel32
|
|
297
|
+
handle = kernel32.OpenProcess(0x1000, False, pid) # PROCESS_QUERY_LIMITED_INFORMATION
|
|
298
|
+
if not handle:
|
|
299
|
+
return False
|
|
300
|
+
code = ctypes.c_ulong()
|
|
301
|
+
ok = kernel32.GetExitCodeProcess(handle, ctypes.byref(code))
|
|
302
|
+
kernel32.CloseHandle(handle)
|
|
303
|
+
return bool(ok) and code.value == 259 # STILL_ACTIVE
|
|
304
|
+
try:
|
|
305
|
+
os.kill(pid, 0)
|
|
306
|
+
except ProcessLookupError:
|
|
307
|
+
return False
|
|
308
|
+
except PermissionError:
|
|
309
|
+
return True
|
|
310
|
+
return True
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
# ---------------------------------------------------------------- choosing
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def make(name: str, options: dict[str, Any] | None = None) -> Agent:
|
|
317
|
+
"""The agent ``name`` refers to, built with its options from ``[agents.<name>]``."""
|
|
318
|
+
cls = AGENTS.get(name).impl
|
|
319
|
+
opts = (options or {}).get(name) or AGENTS.defaults_for(name)
|
|
320
|
+
return cls(opts)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def resolve(name: str, options: dict[str, Any] | None = None) -> Agent:
|
|
324
|
+
"""The configured agent, or for ``auto`` the first installed one (Copilot before Claude Code).
|
|
325
|
+
|
|
326
|
+
When nothing is installed, ``auto`` still resolves to the first choice, so messages can say what to install.
|
|
327
|
+
"""
|
|
328
|
+
if name != AUTO:
|
|
329
|
+
return make(name, options)
|
|
330
|
+
agents = [make(n, options) for n in AUTO_ORDER]
|
|
331
|
+
return next((a for a in agents if a.available()), agents[0])
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def all_agents(options: dict[str, Any] | None = None) -> list[Agent]:
|
|
335
|
+
return [make(n, options) for n in AGENTS.names()]
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def describe(name: str, options: dict[str, Any] | None = None) -> str:
|
|
339
|
+
"""One line for ``doctor``: which agent reviews run in, and whether it's installed."""
|
|
340
|
+
agent = resolve(name, options)
|
|
341
|
+
chosen = ", chosen automatically" if name == AUTO else ""
|
|
342
|
+
if agent.available():
|
|
343
|
+
return f"{agent.label} ({agent.program}{chosen})"
|
|
344
|
+
return f"{agent.label}: {agent.program} isn't installed ({agent.install_hint})"
|