mlai-code 0.3.3 → 0.3.4
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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/checkpoints.mjs +217 -0
- package/src/cli.mjs +153 -26
- package/src/cloud.mjs +2 -0
- package/src/engine.mjs +1 -1
- package/src/headless.mjs +25 -9
- package/src/home.mjs +3 -2
- package/src/host.mjs +141 -13
- package/src/ide-quick.mjs +147 -0
- package/src/ide.mjs +182 -0
- package/src/netbox.mjs +1 -1
- package/src/parity.mjs +17 -0
- package/src/relay.mjs +1 -1
- package/src/render.mjs +9 -2
- package/src/runtime.mjs +2 -0
- package/src/server.mjs +46 -7
- package/src/session.mjs +31 -8
- package/src/tui/acp.mjs +121 -19
- package/src/tui/app.mjs +2 -1
- package/src/tui/chat.mjs +35 -10
- package/src/tui/cmd-config.mjs +3 -1
- package/src/tui/cmd-core.mjs +9 -5
- package/src/tui/cmd-extensibility.mjs +5 -0
- package/src/tui/extensions-local.mjs +2 -0
- package/src/tui/mcp-config.mjs +22 -4
- package/src/tui/review-cli.mjs +15 -4
- package/src/tui/snapshots.mjs +57 -16
- package/src/two-words.mjs +14 -8
- package/src/view-sync.mjs +48 -0
- package/src/winenv.mjs +1 -1
- package/src/workspace-api.mjs +21 -4
- package/vendor/client-sdk/index.cjs +2 -1
- package/vendor/cloud-cli/mlai.mjs +23 -11
- package/worker/architecture_worker.py +33 -4
- package/worker/browser_tool.py +19 -1
- package/worker/chat_fork.py +4 -1
- package/worker/checkpoints.py +71 -8
- package/worker/command_safety.py +56 -3
- package/worker/connected_turn.py +30 -0
- package/worker/conversation.py +81 -11
- package/worker/git_sync.py +4 -4
- package/worker/image_generation.py +2 -2
- package/worker/kimi_bridge.py +247 -27
- package/worker/kimi_gates.py +25 -6
- package/worker/kimi_hook.py +153 -12
- package/worker/media_tools.py +4 -1
- package/worker/mlai_hooks.py +222 -3
- package/worker/mlai_mcp.py +26 -6
- package/worker/mlai_review/README.md +35 -0
- package/worker/mlai_review/__init__.py +1 -0
- package/worker/mlai_review/__main__.py +261 -0
- package/worker/mlai_review/_compat.py +29 -0
- package/worker/mlai_review/analysis/__init__.py +3 -0
- package/worker/mlai_review/analysis/detect.py +50 -0
- package/worker/mlai_review/analysis/main.py +128 -0
- package/worker/mlai_review/analysis/messages.py +8 -0
- package/worker/mlai_review/analysis/tools.py +194 -0
- package/worker/mlai_review/application/__init__.py +1 -0
- package/worker/mlai_review/application/asking.py +53 -0
- package/worker/mlai_review/application/challengers.py +142 -0
- package/worker/mlai_review/application/context_builder.py +194 -0
- package/worker/mlai_review/application/errors.py +17 -0
- package/worker/mlai_review/application/feedback.py +52 -0
- package/worker/mlai_review/application/matching.py +46 -0
- package/worker/mlai_review/application/messages.py +41 -0
- package/worker/mlai_review/application/ports.py +222 -0
- package/worker/mlai_review/application/prompts.py +342 -0
- package/worker/mlai_review/application/review_service.py +200 -0
- package/worker/mlai_review/application/reviewers.py +438 -0
- package/worker/mlai_review/application/streaming.py +91 -0
- package/worker/mlai_review/application/tools.py +138 -0
- package/worker/mlai_review/application/usage.py +145 -0
- package/worker/mlai_review/application/write_check.py +46 -0
- package/worker/mlai_review/contracts/__init__.py +5 -0
- package/worker/mlai_review/contracts/analysis.py +57 -0
- package/worker/mlai_review/contracts/review.py +42 -0
- package/worker/mlai_review/domain/__init__.py +4 -0
- package/worker/mlai_review/domain/changes.py +77 -0
- package/worker/mlai_review/domain/context.py +147 -0
- package/worker/mlai_review/domain/diagnostics.py +239 -0
- package/worker/mlai_review/domain/feedback.py +216 -0
- package/worker/mlai_review/domain/findings.py +505 -0
- package/worker/mlai_review/domain/lifecycle.py +85 -0
- package/worker/mlai_review/domain/partition.py +42 -0
- package/worker/mlai_review/domain/relations.py +166 -0
- package/worker/mlai_review/domain/relevance.py +202 -0
- package/worker/mlai_review/domain/report.py +99 -0
- package/worker/mlai_review/domain/structure.py +56 -0
- package/worker/mlai_review/domain/writes.py +86 -0
- package/worker/mlai_review/eval.py +221 -0
- package/worker/mlai_review/eval_cases/clean-rename.json +11 -0
- package/worker/mlai_review/eval_cases/missing-ownership-check.json +22 -0
- package/worker/mlai_review/eval_cases/off-by-one.json +22 -0
- package/worker/mlai_review/eval_cases/sql-injection.json +20 -0
- package/worker/mlai_review/feedback_report.py +60 -0
- package/worker/mlai_review/infrastructure/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/analysis/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/analysis/none.py +12 -0
- package/worker/mlai_review/infrastructure/analysis/translate.py +17 -0
- package/worker/mlai_review/infrastructure/github/__init__.py +0 -0
- package/worker/mlai_review/infrastructure/github/client.py +445 -0
- package/worker/mlai_review/infrastructure/github/feedback.py +212 -0
- package/worker/mlai_review/infrastructure/github/http.py +31 -0
- package/worker/mlai_review/infrastructure/github/rendering.py +398 -0
- package/worker/mlai_review/infrastructure/github/token.py +20 -0
- package/worker/mlai_review/infrastructure/local/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/local/analyzer.py +48 -0
- package/worker/mlai_review/infrastructure/local/events.py +100 -0
- package/worker/mlai_review/infrastructure/local/git_reader.py +233 -0
- package/worker/mlai_review/infrastructure/local/publisher.py +138 -0
- package/worker/mlai_review/infrastructure/messages.py +54 -0
- package/worker/mlai_review/infrastructure/models/__init__.py +0 -0
- package/worker/mlai_review/infrastructure/models/openai_compatible.py +269 -0
- package/worker/mlai_review/infrastructure/structure/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/structure/heuristic.py +186 -0
- package/worker/mlai_review/infrastructure/structure/tree_sitter.py +186 -0
- package/worker/mlai_review/infrastructure/workspace/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/workspace/local.py +105 -0
- package/worker/mlai_review/infrastructure/workspace/memory.py +77 -0
- package/worker/mlai_review/infrastructure/workspace/paths.py +17 -0
- package/worker/mlai_review/pipeline.py +89 -0
- package/worker/mlai_review/runtime.py +194 -0
- package/worker/mlai_review/settings.py +139 -0
- package/worker/preview.py +15 -0
- package/worker/product_facts.py +3 -1
- package/worker/repo_policy.py +5 -0
- package/worker/roles.py +29 -2
- package/worker/runner.py +126 -18
- package/worker/runtime_control.py +64 -3
- package/worker/secret_scan.py +3 -2
- package/worker/server_memory.py +122 -0
- package/worker/subagents.py +6 -2
- package/worker/tool_catalog.py +1 -1
- package/worker/verification.py +113 -8
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""The change to review, read from a git checkout on this machine: the uncommitted work, a
|
|
2
|
+
commit range, or (for a security scan) the repository's own source files as one big change."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from mlai_review.application.errors import PermanentReviewError
|
|
13
|
+
from mlai_review.application.ports import PullRequestReader
|
|
14
|
+
from mlai_review.contracts.review import ReviewPullRequestInput
|
|
15
|
+
from mlai_review.domain.changes import ChangeSet, FileChange
|
|
16
|
+
from mlai_review.domain.context import PullRequestInfo
|
|
17
|
+
from mlai_review.domain.relevance import is_noise, is_source, is_test
|
|
18
|
+
|
|
19
|
+
GIT_TIMEOUT_SECONDS = 120
|
|
20
|
+
# A repository scan reads at most this much source: the most security-relevant files first.
|
|
21
|
+
SCAN_MAX_FILES = 80
|
|
22
|
+
SCAN_MAX_LINES = 12_000
|
|
23
|
+
SCAN_MAX_FILE_BYTES = 120_000
|
|
24
|
+
# Untracked files larger than this are left out of an uncommitted review.
|
|
25
|
+
MAX_UNTRACKED_BYTES = 400_000
|
|
26
|
+
_SENSITIVE = re.compile(
|
|
27
|
+
r"auth|login|session|token|secret|password|crypt|key|permission|role|admin|acl|policy|"
|
|
28
|
+
r"route|api|controller|handler|middleware|server|webhook|upload|download|file|path|exec|"
|
|
29
|
+
r"shell|command|sql|query|db|database|model|orm|config|settings|env|payment|billing|user",
|
|
30
|
+
re.I,
|
|
31
|
+
)
|
|
32
|
+
_DIFF_HEADER = re.compile(r"^diff --git a/(?P<a>.+?) b/(?P<b>.+)$")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class LocalGitReader(PullRequestReader):
|
|
36
|
+
"""scope: "changes" (working tree against HEAD, untracked files included), "range" (base to
|
|
37
|
+
head, or base to the working tree when head is empty), or "repo" (every source file)."""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
root: Path,
|
|
42
|
+
*,
|
|
43
|
+
scope: str = "changes",
|
|
44
|
+
base: str = "",
|
|
45
|
+
head: str = "",
|
|
46
|
+
title: str = "",
|
|
47
|
+
body: str = "",
|
|
48
|
+
paths: tuple[str, ...] = (),
|
|
49
|
+
) -> None:
|
|
50
|
+
self._root = root
|
|
51
|
+
self._scope = scope
|
|
52
|
+
self._base = base
|
|
53
|
+
self._head = head
|
|
54
|
+
self._title = title
|
|
55
|
+
self._body = body
|
|
56
|
+
self._paths = paths
|
|
57
|
+
|
|
58
|
+
async def pull_request(self, target: ReviewPullRequestInput) -> PullRequestInfo:
|
|
59
|
+
if self._title:
|
|
60
|
+
return PullRequestInfo(self._title, self._body)
|
|
61
|
+
title = {
|
|
62
|
+
"changes": "Uncommitted changes",
|
|
63
|
+
"range": "Changes since " + (self._base[:12] or "the base"),
|
|
64
|
+
"repo": "Repository scan",
|
|
65
|
+
}.get(self._scope, "Changes")
|
|
66
|
+
return PullRequestInfo(title, self._body)
|
|
67
|
+
|
|
68
|
+
async def head(self, target: ReviewPullRequestInput) -> tuple[str, str]:
|
|
69
|
+
head = await self._rev(self._head or "HEAD")
|
|
70
|
+
base = await self._rev(self._base) if self._base else head
|
|
71
|
+
return head, base
|
|
72
|
+
|
|
73
|
+
async def changed_files(
|
|
74
|
+
self, target: ReviewPullRequestInput, *, since: str | None = None
|
|
75
|
+
) -> ChangeSet:
|
|
76
|
+
if self._scope == "repo":
|
|
77
|
+
return await asyncio.to_thread(self._repository)
|
|
78
|
+
if self._scope == "range":
|
|
79
|
+
spec = [f"{since or self._base}...{self._head}"] if self._head else [since or self._base]
|
|
80
|
+
changes = await self._diff(spec)
|
|
81
|
+
return ChangeSet(files=changes, since=since)
|
|
82
|
+
if not await self._rev("HEAD"): # no commit yet: everything is new
|
|
83
|
+
files = await asyncio.to_thread(self._untracked, set(), True)
|
|
84
|
+
return ChangeSet(files=tuple(files))
|
|
85
|
+
files = list(await self._diff(["HEAD"]))
|
|
86
|
+
files += await asyncio.to_thread(self._untracked, {f.path for f in files})
|
|
87
|
+
return ChangeSet(files=tuple(files))
|
|
88
|
+
|
|
89
|
+
async def _rev(self, ref: str) -> str:
|
|
90
|
+
if not ref:
|
|
91
|
+
return ""
|
|
92
|
+
out = await self._git(
|
|
93
|
+
["rev-parse", "--verify", "--quiet", ref + "^{commit}"], ok=(0, 1, 128)
|
|
94
|
+
)
|
|
95
|
+
return out.strip()
|
|
96
|
+
|
|
97
|
+
async def _diff(self, spec: list[str]) -> tuple[FileChange, ...]:
|
|
98
|
+
args = ["diff", "--no-color", "--no-ext-diff", "-M", "--unified=3", *spec, "--"]
|
|
99
|
+
args += list(self._paths)
|
|
100
|
+
return parse_git_diff(await self._git(args))
|
|
101
|
+
|
|
102
|
+
async def _git(self, args: list[str], ok: tuple[int, ...] = (0,)) -> str:
|
|
103
|
+
return await asyncio.to_thread(_run_git, self._root, args, ok)
|
|
104
|
+
|
|
105
|
+
def _untracked(self, known: set[str], staged: bool = False) -> list[FileChange]:
|
|
106
|
+
args = ["ls-files", "--others", "--exclude-standard", "-z"]
|
|
107
|
+
if staged:
|
|
108
|
+
args.insert(1, "--cached")
|
|
109
|
+
listing = _run_git(self._root, args, (0,))
|
|
110
|
+
out = []
|
|
111
|
+
for path in sorted(p for p in listing.split("\0") if p and p not in known):
|
|
112
|
+
if self._paths and not any(path.startswith(p.rstrip("/")) for p in self._paths):
|
|
113
|
+
continue
|
|
114
|
+
text = _read(self._root / path, MAX_UNTRACKED_BYTES)
|
|
115
|
+
if text is None:
|
|
116
|
+
continue
|
|
117
|
+
out.append(added_file(path, text))
|
|
118
|
+
return out
|
|
119
|
+
|
|
120
|
+
def _repository(self) -> ChangeSet:
|
|
121
|
+
listing = _run_git(self._root, ["ls-files", "-z"], (0,)).split("\0")
|
|
122
|
+
candidates = [
|
|
123
|
+
p
|
|
124
|
+
for p in listing
|
|
125
|
+
if p
|
|
126
|
+
and is_source(p)
|
|
127
|
+
and not is_noise(p)
|
|
128
|
+
and (not self._paths or any(p.startswith(x.rstrip("/")) for x in self._paths))
|
|
129
|
+
]
|
|
130
|
+
candidates.sort(key=lambda p: (is_test(p), not _SENSITIVE.search(p), p.count("/"), p))
|
|
131
|
+
files: list[FileChange] = []
|
|
132
|
+
lines = 0
|
|
133
|
+
for path in candidates:
|
|
134
|
+
if len(files) >= SCAN_MAX_FILES:
|
|
135
|
+
break
|
|
136
|
+
text = _read(self._root / path, SCAN_MAX_FILE_BYTES)
|
|
137
|
+
if not text or not text.strip():
|
|
138
|
+
continue
|
|
139
|
+
count = len(text.splitlines())
|
|
140
|
+
if lines + count > SCAN_MAX_LINES:
|
|
141
|
+
continue
|
|
142
|
+
files.append(added_file(path, text))
|
|
143
|
+
lines += count
|
|
144
|
+
return ChangeSet(files=tuple(files))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def added_file(path: str, text: str) -> FileChange:
|
|
148
|
+
"""A whole file shown as added, so every line can carry a finding."""
|
|
149
|
+
body = text.splitlines()
|
|
150
|
+
patch = f"@@ -0,0 +1,{len(body)} @@\n" + "\n".join("+" + line for line in body)
|
|
151
|
+
return FileChange(path=path, status="added", additions=len(body), deletions=0, patch=patch)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def parse_git_diff(text: str) -> tuple[FileChange, ...]:
|
|
155
|
+
"""`git diff` output split per file, in the shape the pull request API reports."""
|
|
156
|
+
files: list[FileChange] = []
|
|
157
|
+
current: dict[str, object] | None = None
|
|
158
|
+
hunks: list[str] = []
|
|
159
|
+
|
|
160
|
+
def flush() -> None:
|
|
161
|
+
if current is None:
|
|
162
|
+
return
|
|
163
|
+
patch = "\n".join(hunks) if hunks else None
|
|
164
|
+
added = sum(1 for h in hunks if h.startswith("+") and not h.startswith("+++"))
|
|
165
|
+
removed = sum(1 for h in hunks if h.startswith("-") and not h.startswith("---"))
|
|
166
|
+
files.append(
|
|
167
|
+
FileChange(
|
|
168
|
+
path=str(current["path"]),
|
|
169
|
+
status=str(current["status"]),
|
|
170
|
+
additions=added,
|
|
171
|
+
deletions=removed,
|
|
172
|
+
patch=patch,
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
in_hunks = False
|
|
177
|
+
for line in text.splitlines():
|
|
178
|
+
header = _DIFF_HEADER.match(line)
|
|
179
|
+
if header:
|
|
180
|
+
flush()
|
|
181
|
+
current = {"path": header["b"], "status": "modified"}
|
|
182
|
+
hunks = []
|
|
183
|
+
in_hunks = False
|
|
184
|
+
continue
|
|
185
|
+
if current is None:
|
|
186
|
+
continue
|
|
187
|
+
if not in_hunks:
|
|
188
|
+
if line.startswith("new file mode"):
|
|
189
|
+
current["status"] = "added"
|
|
190
|
+
elif line.startswith("deleted file mode"):
|
|
191
|
+
current["status"] = "removed"
|
|
192
|
+
elif line.startswith("rename to "):
|
|
193
|
+
current["status"] = "renamed"
|
|
194
|
+
current["path"] = line[len("rename to ") :]
|
|
195
|
+
elif line.startswith("+++ ") and line[4:] != "/dev/null":
|
|
196
|
+
current["path"] = line[6:] if line.startswith("+++ b/") else line[4:]
|
|
197
|
+
elif line.startswith("--- ") and current["status"] == "removed":
|
|
198
|
+
current["path"] = line[6:] if line.startswith("--- a/") else current["path"]
|
|
199
|
+
elif line.startswith("@@"):
|
|
200
|
+
in_hunks = True
|
|
201
|
+
hunks.append(line)
|
|
202
|
+
continue
|
|
203
|
+
hunks.append(line)
|
|
204
|
+
flush()
|
|
205
|
+
return tuple(files)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _run_git(root: Path, args: list[str], ok: tuple[int, ...]) -> str:
|
|
209
|
+
env = {**os.environ, "GIT_TERMINAL_PROMPT": "0", "GIT_OPTIONAL_LOCKS": "0"}
|
|
210
|
+
try:
|
|
211
|
+
done = subprocess.run(
|
|
212
|
+
["git", "-C", str(root), "-c", "core.quotepath=off", *args],
|
|
213
|
+
capture_output=True,
|
|
214
|
+
text=True,
|
|
215
|
+
errors="replace",
|
|
216
|
+
env=env,
|
|
217
|
+
timeout=GIT_TIMEOUT_SECONDS,
|
|
218
|
+
)
|
|
219
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
220
|
+
raise PermanentReviewError(f"git {args[0]}: {exc}") from exc
|
|
221
|
+
if done.returncode not in ok:
|
|
222
|
+
detail = (done.stderr or "").strip().splitlines()
|
|
223
|
+
raise PermanentReviewError(f"git {args[0]}: {detail[-1] if detail else done.returncode}")
|
|
224
|
+
return done.stdout
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _read(file: Path, max_bytes: int) -> str | None:
|
|
228
|
+
try:
|
|
229
|
+
if file.is_symlink() or not file.is_file() or file.stat().st_size > max_bytes:
|
|
230
|
+
return None
|
|
231
|
+
return file.read_bytes().decode("utf-8")
|
|
232
|
+
except (OSError, UnicodeDecodeError):
|
|
233
|
+
return None
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Publishes a review of a local checkout to the event log instead of a pull request. Earlier
|
|
2
|
+
reviews of the same chat stand in for earlier comments: their findings are not repeated, and
|
|
3
|
+
those whose lines have changed and are no longer reported "look resolved"."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from mlai_review.application.ports import ReviewPublisher
|
|
11
|
+
from mlai_review.contracts.review import ReviewPullRequestInput
|
|
12
|
+
from mlai_review.domain.feedback import Dismissal
|
|
13
|
+
from mlai_review.domain.findings import Finding
|
|
14
|
+
from mlai_review.domain.lifecycle import PriorFinding
|
|
15
|
+
from mlai_review.domain.report import ReviewReport
|
|
16
|
+
from mlai_review.infrastructure.local.events import EventLog, finding_json, report_json
|
|
17
|
+
|
|
18
|
+
MAX_PRIOR_FILES = 20
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class EventPublisher(ReviewPublisher):
|
|
22
|
+
def __init__(self, log: EventLog, root: Path, *, prior: tuple[Path, ...] = ()) -> None:
|
|
23
|
+
self._log = log
|
|
24
|
+
self._root = root
|
|
25
|
+
self._prior_files = prior
|
|
26
|
+
self._posted: list[PriorFinding] = [] # by this run: a retried step must not repeat them
|
|
27
|
+
self.report: ReviewReport | None = None
|
|
28
|
+
|
|
29
|
+
async def start(self, target: ReviewPullRequestInput) -> int:
|
|
30
|
+
self._log.emit("progress", stage="reviewing", message="Reading the changes")
|
|
31
|
+
return 1
|
|
32
|
+
|
|
33
|
+
async def acknowledge(self, target: ReviewPullRequestInput) -> None:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
async def post_finding(self, target: ReviewPullRequestInput, finding: Finding) -> None:
|
|
37
|
+
event = finding_json(finding, line_text=self._line(finding))
|
|
38
|
+
self._log.emit("finding", finding=event)
|
|
39
|
+
self._posted.append(
|
|
40
|
+
PriorFinding(
|
|
41
|
+
str(event["fingerprint"]), finding.path, -1, finding.line, title=finding.title
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def complete(
|
|
46
|
+
self, target: ReviewPullRequestInput, publication_id: int, report: ReviewReport
|
|
47
|
+
) -> None:
|
|
48
|
+
self.report = report
|
|
49
|
+
for prior in report.resolved:
|
|
50
|
+
self._log.emit(
|
|
51
|
+
"resolved",
|
|
52
|
+
prior={"fingerprint": prior.fingerprint, "path": prior.path, "title": prior.title},
|
|
53
|
+
message="This looks resolved: the lines changed and the issue is no longer reported.",
|
|
54
|
+
)
|
|
55
|
+
self._log.emit("done", report=report_json(report))
|
|
56
|
+
|
|
57
|
+
async def reviewed(self, target: ReviewPullRequestInput, sha: str) -> bool:
|
|
58
|
+
return False # a local review always looks at the whole change it is given
|
|
59
|
+
|
|
60
|
+
async def prior_findings(self, target: ReviewPullRequestInput) -> tuple[PriorFinding, ...]:
|
|
61
|
+
found: list[PriorFinding] = []
|
|
62
|
+
for n, event in enumerate(read_findings(self._prior_files)):
|
|
63
|
+
path = str(event.get("path") or "")
|
|
64
|
+
line = int(event.get("line") or 0)
|
|
65
|
+
# The host says when a comment's lines changed; here the line's text does.
|
|
66
|
+
current = self._text_at(path, line)
|
|
67
|
+
moved = current is None or current != event.get("lineText", current)
|
|
68
|
+
found.append(
|
|
69
|
+
PriorFinding(
|
|
70
|
+
fingerprint=str(event.get("fingerprint") or ""),
|
|
71
|
+
path=path,
|
|
72
|
+
comment_id=n + 1,
|
|
73
|
+
line=None if moved else line,
|
|
74
|
+
title=str(event.get("title") or ""),
|
|
75
|
+
explanation=str(event.get("explanation") or ""),
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
return (*found, *self._posted)
|
|
79
|
+
|
|
80
|
+
def _line(self, finding: Finding) -> str | None:
|
|
81
|
+
return self._text_at(finding.path, finding.line)
|
|
82
|
+
|
|
83
|
+
def _text_at(self, path: str, line: int) -> str | None:
|
|
84
|
+
try:
|
|
85
|
+
file = (self._root / path).resolve()
|
|
86
|
+
if not file.is_relative_to(self._root.resolve()) or line < 1:
|
|
87
|
+
return None
|
|
88
|
+
lines = file.read_text(encoding="utf-8").splitlines()
|
|
89
|
+
except (OSError, UnicodeDecodeError, ValueError):
|
|
90
|
+
return None
|
|
91
|
+
return lines[line - 1] if line <= len(lines) else None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def read_findings(files: tuple[Path, ...]) -> list[dict]:
|
|
95
|
+
"""Findings published by earlier reviews (their event logs), newest review last."""
|
|
96
|
+
out: list[dict] = []
|
|
97
|
+
seen: set[str] = set()
|
|
98
|
+
for file in files[-MAX_PRIOR_FILES:]:
|
|
99
|
+
try:
|
|
100
|
+
lines = file.read_text(encoding="utf-8").splitlines()
|
|
101
|
+
except OSError:
|
|
102
|
+
continue
|
|
103
|
+
for raw in lines:
|
|
104
|
+
try:
|
|
105
|
+
event = json.loads(raw)
|
|
106
|
+
except json.JSONDecodeError:
|
|
107
|
+
continue
|
|
108
|
+
if event.get("type") != "finding" or not isinstance(event.get("finding"), dict):
|
|
109
|
+
continue
|
|
110
|
+
finding = event["finding"]
|
|
111
|
+
key = str(finding.get("fingerprint") or "")
|
|
112
|
+
if key and key not in seen:
|
|
113
|
+
seen.add(key)
|
|
114
|
+
out.append(finding)
|
|
115
|
+
return out
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def read_dismissals(file: Path | None) -> tuple[Dismissal, ...]:
|
|
119
|
+
"""Findings dismissed in the app ("Not useful"), newest first: never raised again in the
|
|
120
|
+
same file, and named to the model as what this team does not want."""
|
|
121
|
+
if file is None:
|
|
122
|
+
return ()
|
|
123
|
+
try:
|
|
124
|
+
items = json.loads(file.read_text(encoding="utf-8"))
|
|
125
|
+
except (OSError, json.JSONDecodeError):
|
|
126
|
+
return ()
|
|
127
|
+
out = []
|
|
128
|
+
for item in items if isinstance(items, list) else []:
|
|
129
|
+
if isinstance(item, dict) and item.get("fingerprint") and item.get("path"):
|
|
130
|
+
out.append(
|
|
131
|
+
Dismissal(
|
|
132
|
+
fingerprint=str(item["fingerprint"]),
|
|
133
|
+
path=str(item["path"]),
|
|
134
|
+
title=str(item.get("title") or ""),
|
|
135
|
+
reason=str(item.get("reason") or "marked as not useful"),
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
return tuple(reversed(out))[:20]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Wording for failures raised by the orchestrator's adapters. Templates use str.format with the
|
|
2
|
+
named fields shown."""
|
|
3
|
+
|
|
4
|
+
# GitHub: one template for every failed call, plus the operation descriptions it is filled with.
|
|
5
|
+
GITHUB_CALL_FAILED = "{operation}: GitHub returned {status}"
|
|
6
|
+
OP_ISSUE_TOKEN = "issue token for installation {installation_id}"
|
|
7
|
+
OP_READ_PULL_REQUEST = "read pull request {number}"
|
|
8
|
+
OP_LIST_FILES = "list files of {repository}"
|
|
9
|
+
OP_COMPARE = "compare {since} with {head}"
|
|
10
|
+
OP_LIST_CHECKS = "list check runs on {sha}"
|
|
11
|
+
OP_CREATE_CHECK = "create check on {repository}"
|
|
12
|
+
OP_COMPLETE_CHECK = "complete check {check_id}"
|
|
13
|
+
OP_LIST_COMMENTS = "list review comments of pull request {number}"
|
|
14
|
+
OP_LOCATE = "locate {repository}"
|
|
15
|
+
OP_POST_COMMENT = "comment on {path}"
|
|
16
|
+
OP_LIST_ISSUE_COMMENTS = "list conversation comments of pull request {number}"
|
|
17
|
+
OP_WRITE_OVERVIEW = "write the overview comment on pull request {number}"
|
|
18
|
+
OVERVIEW_FAILED = "could not write the overview comment on pull request %s: %s"
|
|
19
|
+
STATUS_SKIPPED = "no check or commit status on pull request %s: the token may not write them"
|
|
20
|
+
ACKNOWLEDGE_SKIPPED = "could not react to comment %s (GitHub returned %s)" # %-style
|
|
21
|
+
OP_LIST_REPO_COMMENTS = "list review comments of {repository}"
|
|
22
|
+
OP_LIST_PULLS = "list pull requests of {repository}"
|
|
23
|
+
OP_LIST_COMMITS = "list commits of pull request {number}"
|
|
24
|
+
OP_READ_THREADS = "read review threads of pull request {number}"
|
|
25
|
+
RESOLVE_SKIPPED = "could not resolve the thread of comment %s (GitHub returned %s)" # %-style
|
|
26
|
+
|
|
27
|
+
# Workspace (git checkout on this worker)
|
|
28
|
+
OP_CLONE = "check out {repository} at {sha}"
|
|
29
|
+
GIT_FAILED = "{operation}: git {command} exited with {code}: {reason}"
|
|
30
|
+
GIT_TIMEOUT = "{operation}: git {command} took longer than {seconds:.0f}s"
|
|
31
|
+
PATH_OUTSIDE_WORKSPACE = "refused to read {path!r}: outside the checkout"
|
|
32
|
+
|
|
33
|
+
# Outlines
|
|
34
|
+
GRAMMAR_UNAVAILABLE = "no outline for %s files (grammar unavailable: %s); using windows" # %-style
|
|
35
|
+
|
|
36
|
+
# Static-analysis sandbox job
|
|
37
|
+
ANALYSIS_JOB_REJECTED = "could not start the analysis job: Azure returned {status}"
|
|
38
|
+
ANALYSIS_JOB_ENDED = "analysis job ended as {status} without a result"
|
|
39
|
+
ANALYSIS_JOB_TIMED_OUT = "analysis job produced no result within {seconds:.0f}s"
|
|
40
|
+
ANALYSIS_RESULT_UNREADABLE = "analysis result unreadable: {error}"
|
|
41
|
+
|
|
42
|
+
# Language model
|
|
43
|
+
MODEL_UNREACHABLE = "model endpoint unreachable: {error}"
|
|
44
|
+
MODEL_RETRYABLE_STATUS = "model returned {status}"
|
|
45
|
+
MODEL_RETRYING = "%s; retrying in %.0fs"
|
|
46
|
+
MODEL_REJECTED = "model rejected the request: {status}"
|
|
47
|
+
MODEL_NOT_JSON = "model did not return valid JSON"
|
|
48
|
+
MODEL_ASKING_AGAIN = "%s; asking the model again"
|
|
49
|
+
MODEL_OUT_OF_TOKENS = (
|
|
50
|
+
"model used its whole output budget ({max_tokens} tokens, {reasoning} on reasoning) "
|
|
51
|
+
"before finishing the answer"
|
|
52
|
+
)
|
|
53
|
+
MODEL_NOT_OBJECT = "model returned JSON that is not an object"
|
|
54
|
+
MODEL_CALL_LOG = "model=%s ms=%.0f prompt_tokens=%s cached=%s completion_tokens=%s finish=%s"
|
|
File without changes
|