mlai-code 0.3.2 → 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.
Files changed (157) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/checkpoints.mjs +217 -0
  4. package/src/cli.mjs +178 -31
  5. package/src/cloud.mjs +2 -0
  6. package/src/engine.mjs +1 -1
  7. package/src/headless.mjs +25 -9
  8. package/src/home.mjs +3 -2
  9. package/src/host.mjs +141 -13
  10. package/src/ide-quick.mjs +147 -0
  11. package/src/ide.mjs +182 -0
  12. package/src/netbox.mjs +1 -1
  13. package/src/parity.mjs +20 -1
  14. package/src/relay.mjs +1 -1
  15. package/src/render.mjs +12 -3
  16. package/src/runtime.mjs +23 -1
  17. package/src/sandbox.mjs +19 -3
  18. package/src/server.mjs +46 -7
  19. package/src/session.mjs +53 -10
  20. package/src/shared-data.mjs +1 -1
  21. package/src/tui/acp.mjs +121 -19
  22. package/src/tui/app.mjs +24 -5
  23. package/src/tui/chat.mjs +43 -16
  24. package/src/tui/cmd-config.mjs +3 -1
  25. package/src/tui/cmd-core.mjs +11 -7
  26. package/src/tui/cmd-extensibility.mjs +13 -2
  27. package/src/tui/commands.mjs +2 -1
  28. package/src/tui/extensions-local.mjs +2 -0
  29. package/src/tui/mcp-config.mjs +22 -4
  30. package/src/tui/review-cli.mjs +15 -4
  31. package/src/tui/snapshots.mjs +57 -16
  32. package/src/tui/statusline.mjs +2 -1
  33. package/src/two-words.mjs +14 -8
  34. package/src/view-sync.mjs +48 -0
  35. package/src/wakeups.mjs +2 -2
  36. package/src/winenv.mjs +1 -1
  37. package/src/workspace-api.mjs +21 -4
  38. package/vendor/client-sdk/index.cjs +5 -4
  39. package/vendor/cloud-cli/mlai.mjs +184 -28
  40. package/worker/architecture_worker.py +33 -4
  41. package/worker/browser_tool.py +19 -1
  42. package/worker/build_planner.py +75 -7
  43. package/worker/chat_fork.py +4 -1
  44. package/worker/checkpoints.py +71 -8
  45. package/worker/cloud_pty.py +91 -2
  46. package/worker/command_safety.py +80 -3
  47. package/worker/compaction_brief.py +186 -0
  48. package/worker/connected_turn.py +30 -0
  49. package/worker/context_manager.py +6 -0
  50. package/worker/conversation.py +139 -12
  51. package/worker/deck_render.js +11 -0
  52. package/worker/deck_tools.py +825 -0
  53. package/worker/git_sync.py +42 -17
  54. package/worker/goals.py +4 -0
  55. package/worker/image_generation.py +102 -23
  56. package/worker/kimi_bridge.py +580 -52
  57. package/worker/kimi_gates.py +74 -6
  58. package/worker/kimi_hook.py +213 -19
  59. package/worker/media_tools.py +182 -0
  60. package/worker/memory.py +2 -2
  61. package/worker/mlai_hooks.py +314 -5
  62. package/worker/mlai_mcp.py +49 -11
  63. package/worker/mlai_review/README.md +35 -0
  64. package/worker/mlai_review/__init__.py +1 -0
  65. package/worker/mlai_review/__main__.py +261 -0
  66. package/worker/mlai_review/_compat.py +29 -0
  67. package/worker/mlai_review/analysis/__init__.py +3 -0
  68. package/worker/mlai_review/analysis/detect.py +50 -0
  69. package/worker/mlai_review/analysis/main.py +128 -0
  70. package/worker/mlai_review/analysis/messages.py +8 -0
  71. package/worker/mlai_review/analysis/tools.py +194 -0
  72. package/worker/mlai_review/application/__init__.py +1 -0
  73. package/worker/mlai_review/application/asking.py +53 -0
  74. package/worker/mlai_review/application/challengers.py +142 -0
  75. package/worker/mlai_review/application/context_builder.py +194 -0
  76. package/worker/mlai_review/application/errors.py +17 -0
  77. package/worker/mlai_review/application/feedback.py +52 -0
  78. package/worker/mlai_review/application/matching.py +46 -0
  79. package/worker/mlai_review/application/messages.py +41 -0
  80. package/worker/mlai_review/application/ports.py +222 -0
  81. package/worker/mlai_review/application/prompts.py +342 -0
  82. package/worker/mlai_review/application/review_service.py +200 -0
  83. package/worker/mlai_review/application/reviewers.py +438 -0
  84. package/worker/mlai_review/application/streaming.py +91 -0
  85. package/worker/mlai_review/application/tools.py +138 -0
  86. package/worker/mlai_review/application/usage.py +145 -0
  87. package/worker/mlai_review/application/write_check.py +46 -0
  88. package/worker/mlai_review/contracts/__init__.py +5 -0
  89. package/worker/mlai_review/contracts/analysis.py +57 -0
  90. package/worker/mlai_review/contracts/review.py +42 -0
  91. package/worker/mlai_review/domain/__init__.py +4 -0
  92. package/worker/mlai_review/domain/changes.py +77 -0
  93. package/worker/mlai_review/domain/context.py +147 -0
  94. package/worker/mlai_review/domain/diagnostics.py +239 -0
  95. package/worker/mlai_review/domain/feedback.py +216 -0
  96. package/worker/mlai_review/domain/findings.py +505 -0
  97. package/worker/mlai_review/domain/lifecycle.py +85 -0
  98. package/worker/mlai_review/domain/partition.py +42 -0
  99. package/worker/mlai_review/domain/relations.py +166 -0
  100. package/worker/mlai_review/domain/relevance.py +202 -0
  101. package/worker/mlai_review/domain/report.py +99 -0
  102. package/worker/mlai_review/domain/structure.py +56 -0
  103. package/worker/mlai_review/domain/writes.py +86 -0
  104. package/worker/mlai_review/eval.py +221 -0
  105. package/worker/mlai_review/eval_cases/clean-rename.json +11 -0
  106. package/worker/mlai_review/eval_cases/missing-ownership-check.json +22 -0
  107. package/worker/mlai_review/eval_cases/off-by-one.json +22 -0
  108. package/worker/mlai_review/eval_cases/sql-injection.json +20 -0
  109. package/worker/mlai_review/feedback_report.py +60 -0
  110. package/worker/mlai_review/infrastructure/__init__.py +1 -0
  111. package/worker/mlai_review/infrastructure/analysis/__init__.py +1 -0
  112. package/worker/mlai_review/infrastructure/analysis/none.py +12 -0
  113. package/worker/mlai_review/infrastructure/analysis/translate.py +17 -0
  114. package/worker/mlai_review/infrastructure/github/__init__.py +0 -0
  115. package/worker/mlai_review/infrastructure/github/client.py +445 -0
  116. package/worker/mlai_review/infrastructure/github/feedback.py +212 -0
  117. package/worker/mlai_review/infrastructure/github/http.py +31 -0
  118. package/worker/mlai_review/infrastructure/github/rendering.py +398 -0
  119. package/worker/mlai_review/infrastructure/github/token.py +20 -0
  120. package/worker/mlai_review/infrastructure/local/__init__.py +1 -0
  121. package/worker/mlai_review/infrastructure/local/analyzer.py +48 -0
  122. package/worker/mlai_review/infrastructure/local/events.py +100 -0
  123. package/worker/mlai_review/infrastructure/local/git_reader.py +233 -0
  124. package/worker/mlai_review/infrastructure/local/publisher.py +138 -0
  125. package/worker/mlai_review/infrastructure/messages.py +54 -0
  126. package/worker/mlai_review/infrastructure/models/__init__.py +0 -0
  127. package/worker/mlai_review/infrastructure/models/openai_compatible.py +269 -0
  128. package/worker/mlai_review/infrastructure/structure/__init__.py +1 -0
  129. package/worker/mlai_review/infrastructure/structure/heuristic.py +186 -0
  130. package/worker/mlai_review/infrastructure/structure/tree_sitter.py +186 -0
  131. package/worker/mlai_review/infrastructure/workspace/__init__.py +1 -0
  132. package/worker/mlai_review/infrastructure/workspace/local.py +105 -0
  133. package/worker/mlai_review/infrastructure/workspace/memory.py +77 -0
  134. package/worker/mlai_review/infrastructure/workspace/paths.py +17 -0
  135. package/worker/mlai_review/pipeline.py +89 -0
  136. package/worker/mlai_review/runtime.py +194 -0
  137. package/worker/mlai_review/settings.py +139 -0
  138. package/worker/model_stream.py +21 -7
  139. package/worker/offline_guard.py +1 -1
  140. package/worker/preview.py +62 -4
  141. package/worker/product_facts.py +20 -0
  142. package/worker/project_context.py +33 -7
  143. package/worker/reply_language.py +92 -10
  144. package/worker/repo_policy.py +5 -0
  145. package/worker/roles.json +199 -37
  146. package/worker/roles.py +271 -9
  147. package/worker/runner.py +366 -53
  148. package/worker/runtime_control.py +64 -3
  149. package/worker/secret_scan.py +3 -2
  150. package/worker/server_memory.py +122 -0
  151. package/worker/site_check.py +279 -0
  152. package/worker/skill_library.py +15 -3
  153. package/worker/skill_pack.py +170 -16
  154. package/worker/subagents.py +6 -2
  155. package/worker/tool_catalog.py +4 -3
  156. package/worker/verification.py +156 -19
  157. package/worker/wakeups.py +56 -4
@@ -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"