rigcode 0.1.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.
- rigcode/__init__.py +4 -0
- rigcode/__main__.py +4 -0
- rigcode/agent/__init__.py +0 -0
- rigcode/agent/loop.py +627 -0
- rigcode/agent/mentions.py +70 -0
- rigcode/agent/prompts.py +195 -0
- rigcode/agent/runtime.py +535 -0
- rigcode/agent/session.py +165 -0
- rigcode/agent/state.py +161 -0
- rigcode/cli.py +283 -0
- rigcode/config.py +284 -0
- rigcode/doctor.py +158 -0
- rigcode/extensions.py +275 -0
- rigcode/hooks.py +142 -0
- rigcode/llm/__init__.py +0 -0
- rigcode/llm/client.py +259 -0
- rigcode/llm/probe.py +229 -0
- rigcode/llm/stream.py +240 -0
- rigcode/llm/textmode.py +161 -0
- rigcode/llm/types.py +92 -0
- rigcode/llm/wire.py +76 -0
- rigcode/mcp.py +329 -0
- rigcode/permissions.py +221 -0
- rigcode/prompts/agents/coder.md +13 -0
- rigcode/prompts/agents/debugger.md +14 -0
- rigcode/prompts/agents/explore.md +22 -0
- rigcode/prompts/agents/plan.md +21 -0
- rigcode/prompts/agents/researcher.md +14 -0
- rigcode/prompts/agents/reviewer.md +18 -0
- rigcode/prompts/agents/verifier.md +15 -0
- rigcode/prompts/commit.md +5 -0
- rigcode/prompts/compact.md +24 -0
- rigcode/prompts/init.md +10 -0
- rigcode/prompts/system.md +27 -0
- rigcode/tools/__init__.py +0 -0
- rigcode/tools/base.py +245 -0
- rigcode/tools/bashsafety.py +262 -0
- rigcode/tools/editmatch.py +367 -0
- rigcode/tools/files.py +534 -0
- rigcode/tools/interact.py +69 -0
- rigcode/tools/search.py +309 -0
- rigcode/tools/shell.py +424 -0
- rigcode/tools/skill.py +37 -0
- rigcode/tools/task.py +54 -0
- rigcode/tools/todo.py +62 -0
- rigcode/tools/web.py +346 -0
- rigcode/ui/__init__.py +0 -0
- rigcode/ui/base.py +69 -0
- rigcode/ui/commands.py +581 -0
- rigcode/ui/plain.py +321 -0
- rigcode/ui/render.py +207 -0
- rigcode/ui/terminal.py +1154 -0
- rigcode/utils/__init__.py +0 -0
- rigcode/utils/files.py +176 -0
- rigcode/utils/frontmatter.py +38 -0
- rigcode/utils/globmatch.py +91 -0
- rigcode/utils/jsonrepair.py +110 -0
- rigcode/utils/paths.py +83 -0
- rigcode/utils/text.py +105 -0
- rigcode-0.1.0.dist-info/METADATA +203 -0
- rigcode-0.1.0.dist-info/RECORD +64 -0
- rigcode-0.1.0.dist-info/WHEEL +4 -0
- rigcode-0.1.0.dist-info/entry_points.txt +2 -0
- rigcode-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"""String-replacement engine for the Edit tools.
|
|
2
|
+
|
|
3
|
+
Design (informed by what broke in other harnesses): exact matching first, then
|
|
4
|
+
only *lossless* normalizations - Unicode punctuation look-alikes, trailing
|
|
5
|
+
whitespace, and a uniform indentation offset - plus recovery from two common
|
|
6
|
+
model slips (copied line-number prefixes, double-escaped strings). A match must
|
|
7
|
+
be unique; ambiguity at any tier stops the search instead of falling through to
|
|
8
|
+
a looser tier. Similarity scoring is used only to build error hints, never to
|
|
9
|
+
apply an edit.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from difflib import SequenceMatcher
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EditError(Exception):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class Span:
|
|
24
|
+
start: int # offsets into the LF-normalized content
|
|
25
|
+
end: int
|
|
26
|
+
replacement: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class EditOutcome:
|
|
31
|
+
content: str # new LF-normalized content
|
|
32
|
+
count: int
|
|
33
|
+
strategy: str
|
|
34
|
+
first_line: int # 1-based line of the first replacement
|
|
35
|
+
new_text: str # replacement actually inserted at the first span
|
|
36
|
+
spans: list[Span] = field(default_factory=list)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_UNICODE_MAP = str.maketrans({
|
|
40
|
+
"‘": "'", "’": "'", "‚": "'", "‛": "'",
|
|
41
|
+
"“": '"', "”": '"', "„": '"', "‟": '"',
|
|
42
|
+
"‐": "-", "‑": "-", "‒": "-", "–": "-", "—": "-", "―": "-", "−": "-",
|
|
43
|
+
" ": " ", " ": " ", " ": " ", " ": " ", " ": " ", " ": " ",
|
|
44
|
+
" ": " ", " ": " ", " ": " ", " ": " ", " ": " ", " ": " ", " ": " ",
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _line_of(content: str, offset: int) -> int:
|
|
49
|
+
return content.count("\n", 0, offset) + 1
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _find_all(haystack: str, needle: str) -> list[int]:
|
|
53
|
+
out, pos = [], haystack.find(needle)
|
|
54
|
+
while pos != -1:
|
|
55
|
+
out.append(pos)
|
|
56
|
+
pos = haystack.find(needle, pos + len(needle))
|
|
57
|
+
return out
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _lines_with_offsets(content: str) -> tuple[list[str], list[int]]:
|
|
61
|
+
lines = content.split("\n")
|
|
62
|
+
offsets, pos = [], 0
|
|
63
|
+
for line in lines:
|
|
64
|
+
offsets.append(pos)
|
|
65
|
+
pos += len(line) + 1
|
|
66
|
+
return lines, offsets
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ------------------------------------------------------------------ tiers
|
|
70
|
+
# Each tier returns a list of Spans (empty = no match).
|
|
71
|
+
|
|
72
|
+
def _tier_exact(content: str, old: str, new: str) -> list[Span]:
|
|
73
|
+
return [Span(p, p + len(old), new) for p in _find_all(content, old)]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _tier_unicode(content: str, old: str, new: str) -> list[Span]:
|
|
77
|
+
norm_old = old.translate(_UNICODE_MAP)
|
|
78
|
+
norm_content = content.translate(_UNICODE_MAP)
|
|
79
|
+
if norm_old == old and norm_content == content:
|
|
80
|
+
return []
|
|
81
|
+
# 1:1 character map, so offsets in the normalized text are valid in the original.
|
|
82
|
+
return [Span(p, p + len(old), new) for p in _find_all(norm_content, norm_old)]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _split_old(old: str) -> tuple[list[str], bool]:
|
|
86
|
+
old_lines = old.split("\n")
|
|
87
|
+
trailing_nl = len(old_lines) > 1 and old_lines[-1] == ""
|
|
88
|
+
if trailing_nl:
|
|
89
|
+
old_lines = old_lines[:-1]
|
|
90
|
+
return old_lines, trailing_nl
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _window_span(content: str, lines: list[str], offsets: list[int], i: int, k: int, trailing_nl: bool,
|
|
94
|
+
replacement: str) -> Span | None:
|
|
95
|
+
start = offsets[i]
|
|
96
|
+
end = offsets[i + k - 1] + len(lines[i + k - 1])
|
|
97
|
+
if trailing_nl:
|
|
98
|
+
if end >= len(content):
|
|
99
|
+
return None # old_string ended with a newline but the window is the last line
|
|
100
|
+
end += 1
|
|
101
|
+
if replacement and not replacement.endswith("\n"):
|
|
102
|
+
replacement += "\n"
|
|
103
|
+
return Span(start, end, replacement)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _tier_trailing_ws(content: str, old: str, new: str) -> list[Span]:
|
|
107
|
+
old_lines, trailing_nl = _split_old(old)
|
|
108
|
+
if not any(l.strip() for l in old_lines):
|
|
109
|
+
return []
|
|
110
|
+
lines, offsets = _lines_with_offsets(content)
|
|
111
|
+
key = lambda s: s.translate(_UNICODE_MAP).rstrip() # noqa: E731
|
|
112
|
+
okeys = [key(l) for l in old_lines]
|
|
113
|
+
k = len(okeys)
|
|
114
|
+
spans: list[Span] = []
|
|
115
|
+
last_end = -1
|
|
116
|
+
for i in range(0, len(lines) - k + 1):
|
|
117
|
+
if key(lines[i]) != okeys[0] or offsets[i] < last_end:
|
|
118
|
+
continue
|
|
119
|
+
if all(key(lines[i + j]) == okeys[j] for j in range(1, k)):
|
|
120
|
+
span = _window_span(content, lines, offsets, i, k, trailing_nl, new)
|
|
121
|
+
if span:
|
|
122
|
+
spans.append(span)
|
|
123
|
+
last_end = span.end
|
|
124
|
+
return spans
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _uniform_delta(window: list[str], old_lines: list[str]) -> tuple[str, int] | None:
|
|
128
|
+
"""If every non-blank line differs only by the same leading-whitespace
|
|
129
|
+
prefix, return (prefix, +1 if the file is more indented, -1 if less)."""
|
|
130
|
+
delta: str | None = None
|
|
131
|
+
direction = 0
|
|
132
|
+
for w, o in zip(window, old_lines):
|
|
133
|
+
ws, os_ = w.translate(_UNICODE_MAP).rstrip(), o.translate(_UNICODE_MAP).rstrip()
|
|
134
|
+
if not ws.strip() and not os_.strip():
|
|
135
|
+
continue
|
|
136
|
+
if not ws.strip() or not os_.strip():
|
|
137
|
+
return None
|
|
138
|
+
if len(ws) >= len(os_) and ws.endswith(os_) and not ws[: len(ws) - len(os_)].strip():
|
|
139
|
+
d, dirn = ws[: len(ws) - len(os_)], 1
|
|
140
|
+
elif os_.endswith(ws) and not os_[: len(os_) - len(ws)].strip():
|
|
141
|
+
d, dirn = os_[: len(os_) - len(ws)], -1
|
|
142
|
+
else:
|
|
143
|
+
return None
|
|
144
|
+
if not d:
|
|
145
|
+
dirn = 0
|
|
146
|
+
if delta is None:
|
|
147
|
+
delta, direction = d, dirn
|
|
148
|
+
elif d != delta or (dirn != direction and d):
|
|
149
|
+
return None
|
|
150
|
+
if not delta or direction == 0:
|
|
151
|
+
return None
|
|
152
|
+
return delta, direction
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _reindent(new: str, delta: str, direction: int) -> str:
|
|
156
|
+
out = []
|
|
157
|
+
for line in new.split("\n"):
|
|
158
|
+
if not line.strip():
|
|
159
|
+
out.append(line)
|
|
160
|
+
elif direction > 0:
|
|
161
|
+
out.append(delta + line)
|
|
162
|
+
elif line.startswith(delta):
|
|
163
|
+
out.append(line[len(delta):])
|
|
164
|
+
else:
|
|
165
|
+
lead = len(line) - len(line.lstrip(" \t"))
|
|
166
|
+
out.append(line[min(lead, len(delta)):])
|
|
167
|
+
return "\n".join(out)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _tier_indent(content: str, old: str, new: str) -> list[Span]:
|
|
171
|
+
old_lines, trailing_nl = _split_old(old)
|
|
172
|
+
nonblank = [l for l in old_lines if l.strip()]
|
|
173
|
+
if not nonblank:
|
|
174
|
+
return []
|
|
175
|
+
lines, offsets = _lines_with_offsets(content)
|
|
176
|
+
k = len(old_lines)
|
|
177
|
+
idx0 = old_lines.index(nonblank[0])
|
|
178
|
+
first_core = nonblank[0].translate(_UNICODE_MAP).strip()
|
|
179
|
+
spans: list[Span] = []
|
|
180
|
+
last_end = -1
|
|
181
|
+
for i in range(0, len(lines) - k + 1):
|
|
182
|
+
if offsets[i] < last_end:
|
|
183
|
+
continue
|
|
184
|
+
window = lines[i:i + k]
|
|
185
|
+
if window[idx0].translate(_UNICODE_MAP).strip() != first_core:
|
|
186
|
+
continue
|
|
187
|
+
found = _uniform_delta(window, old_lines)
|
|
188
|
+
if not found:
|
|
189
|
+
continue
|
|
190
|
+
delta, direction = found
|
|
191
|
+
span = _window_span(content, lines, offsets, i, k, trailing_nl, _reindent(new, delta, direction))
|
|
192
|
+
if span:
|
|
193
|
+
spans.append(span)
|
|
194
|
+
last_end = span.end
|
|
195
|
+
return spans
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
TIERS = [
|
|
199
|
+
("exact", _tier_exact),
|
|
200
|
+
("unicode-punctuation", _tier_unicode),
|
|
201
|
+
("trailing-whitespace", _tier_trailing_ws),
|
|
202
|
+
("indentation-offset", _tier_indent),
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
# ------------------------------------------------------------------ input repairs
|
|
206
|
+
|
|
207
|
+
_LINE_NUM_RE = re.compile(r"^\s*\d+(?:\t|→| \| |: )")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def strip_line_numbers(text: str) -> str | None:
|
|
211
|
+
"""Undo copied Read-output prefixes (' 12\\tcode'). Only if every non-blank line has one."""
|
|
212
|
+
lines = text.split("\n")
|
|
213
|
+
nonblank = [l for l in lines if l.strip()]
|
|
214
|
+
if not nonblank or not all(_LINE_NUM_RE.match(l) for l in nonblank):
|
|
215
|
+
return None
|
|
216
|
+
return "\n".join(_LINE_NUM_RE.sub("", l, count=1) for l in lines)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def unescape(text: str) -> str | None:
|
|
220
|
+
"""Undo double-escaping ('\\n' typed as two characters) when it looks systematic."""
|
|
221
|
+
if "\\n" not in text and "\\t" not in text and '\\"' not in text:
|
|
222
|
+
return None
|
|
223
|
+
if "\n" in text and text.count("\\n") < 2:
|
|
224
|
+
return None
|
|
225
|
+
return (text.replace("\\r\\n", "\n").replace("\\n", "\n").replace("\\t", "\t")
|
|
226
|
+
.replace('\\"', '"').replace("\\'", "'").replace("\\\\", "\\"))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# ------------------------------------------------------------------ omission guard
|
|
230
|
+
|
|
231
|
+
_COMMENT_RE = re.compile(r"^\s*(?:#+|//+|/\*+|\*+|<!--|--|;+|%+|rem\b|')\s*(.*?)\s*(?:\*+/|-->)?\s*$", re.I)
|
|
232
|
+
_KEYWORD_RE = re.compile(r"\b(rest|remaining|existing|unchanged|previous|other|same|omitted|elided|truncated|more)\b", re.I)
|
|
233
|
+
_PHRASE_RE = re.compile(
|
|
234
|
+
r"\b(rest of (the )?(code|file|function|method|class|implementation|content|module|body)|"
|
|
235
|
+
r"(existing|remaining|unchanged|previous|other) (code|content|methods|functions|implementation|lines|imports|logic|body))\b",
|
|
236
|
+
re.I)
|
|
237
|
+
_TRAIL_RE = re.compile(r"\b(unchanged|remains?|here|as before|omitted|goes here|stays the same)\b", re.I)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def find_omission_placeholder(new: str, old: str = "") -> str | None:
|
|
241
|
+
"""Detect 'lazy' placeholders like '// ... rest of the code ...' that would
|
|
242
|
+
delete real code. Lines that also appear in old_string are ignored."""
|
|
243
|
+
for line in new.split("\n"):
|
|
244
|
+
stripped = line.strip()
|
|
245
|
+
if not stripped or (old and stripped in old):
|
|
246
|
+
continue
|
|
247
|
+
m = _COMMENT_RE.match(line)
|
|
248
|
+
if m:
|
|
249
|
+
body = m.group(1)
|
|
250
|
+
elif stripped.startswith(("...", "…")):
|
|
251
|
+
body = stripped
|
|
252
|
+
else:
|
|
253
|
+
continue
|
|
254
|
+
has_ellipsis = "..." in body or "…" in body
|
|
255
|
+
if (has_ellipsis and _KEYWORD_RE.search(body)) or (_PHRASE_RE.search(body) and (has_ellipsis or _TRAIL_RE.search(body))):
|
|
256
|
+
return stripped
|
|
257
|
+
return None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
# ------------------------------------------------------------------ driver
|
|
261
|
+
|
|
262
|
+
def _apply_spans(content: str, spans: list[Span]) -> str:
|
|
263
|
+
out = content
|
|
264
|
+
for span in sorted(spans, key=lambda s: s.start, reverse=True):
|
|
265
|
+
out = out[: span.start] + span.replacement + out[span.end:]
|
|
266
|
+
return out
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _run_tiers(content: str, old: str, new: str, replace_all: bool, prefix: str = "") -> EditOutcome | None:
|
|
270
|
+
for name, tier in TIERS:
|
|
271
|
+
spans = tier(content, old, new)
|
|
272
|
+
if not spans:
|
|
273
|
+
continue
|
|
274
|
+
if len(spans) > 1 and not replace_all:
|
|
275
|
+
where = ", ".join(str(_line_of(content, s.start)) for s in spans[:12])
|
|
276
|
+
how = "" if name == "exact" else f" (after {name} normalization)"
|
|
277
|
+
raise EditError(
|
|
278
|
+
f"old_string matches {len(spans)} locations{how}, at lines {where}. Include more surrounding lines "
|
|
279
|
+
"so it matches exactly one place, or set replace_all=true to change every occurrence.")
|
|
280
|
+
new_content = _apply_spans(content, spans)
|
|
281
|
+
return EditOutcome(new_content, len(spans), prefix + name, _line_of(content, spans[0].start),
|
|
282
|
+
spans[0].replacement, spans)
|
|
283
|
+
return None
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def apply_edit(content: str, old: str, new: str, replace_all: bool = False) -> EditOutcome:
|
|
287
|
+
"""Apply one replacement to LF-normalized content. Raises EditError with a
|
|
288
|
+
self-correction hint when there is no unique match."""
|
|
289
|
+
old = old.replace("\r\n", "\n")
|
|
290
|
+
new = new.replace("\r\n", "\n")
|
|
291
|
+
if old == new:
|
|
292
|
+
raise EditError("old_string and new_string are identical; there is nothing to change.")
|
|
293
|
+
if not old:
|
|
294
|
+
raise EditError("old_string is empty. To create a file or replace all of it, use the Write tool.")
|
|
295
|
+
placeholder = find_omission_placeholder(new, old)
|
|
296
|
+
if placeholder:
|
|
297
|
+
raise EditError(
|
|
298
|
+
f"new_string contains a placeholder ('{placeholder}') standing in for code that is not in "
|
|
299
|
+
"old_string. Applying it would delete that code. Write out the complete replacement text instead.")
|
|
300
|
+
outcome = _run_tiers(content, old, new, replace_all)
|
|
301
|
+
if outcome is None:
|
|
302
|
+
stripped = strip_line_numbers(old)
|
|
303
|
+
if stripped is not None:
|
|
304
|
+
new_stripped = strip_line_numbers(new)
|
|
305
|
+
outcome = _run_tiers(content, stripped, new_stripped if new_stripped is not None else new,
|
|
306
|
+
replace_all, "line-number-prefixes+")
|
|
307
|
+
if outcome is None:
|
|
308
|
+
un_old = unescape(old)
|
|
309
|
+
if un_old is not None:
|
|
310
|
+
outcome = _run_tiers(content, un_old, unescape(new) or new, replace_all, "unescaped+")
|
|
311
|
+
if outcome is None:
|
|
312
|
+
raise EditError(no_match_message(content, old, new))
|
|
313
|
+
if outcome.content == content:
|
|
314
|
+
raise EditError("The edit would leave the file unchanged (new_string equals the matched text).")
|
|
315
|
+
return outcome
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def closest_region(content: str, old: str) -> tuple[int, int, float] | None:
|
|
319
|
+
"""(start_line, end_line, similarity) of the region most similar to `old`."""
|
|
320
|
+
lines = content.split("\n")
|
|
321
|
+
old_lines = old.strip("\n").split("\n")
|
|
322
|
+
k = len(old_lines)
|
|
323
|
+
if not lines or not old.strip():
|
|
324
|
+
return None
|
|
325
|
+
target = "\n".join(l.strip() for l in old_lines)
|
|
326
|
+
first_idx = next((i for i, l in enumerate(old_lines) if l.strip()), 0)
|
|
327
|
+
first = old_lines[first_idx].strip()
|
|
328
|
+
scored = []
|
|
329
|
+
for i, line in enumerate(lines):
|
|
330
|
+
s = line.strip()
|
|
331
|
+
if not s:
|
|
332
|
+
continue
|
|
333
|
+
sm = SequenceMatcher(None, first, s, autojunk=False)
|
|
334
|
+
if sm.real_quick_ratio() < 0.3 or sm.quick_ratio() < 0.3:
|
|
335
|
+
continue
|
|
336
|
+
scored.append((sm.ratio(), i))
|
|
337
|
+
scored.sort(reverse=True)
|
|
338
|
+
best = (0.0, 0)
|
|
339
|
+
for _, i in scored[:60]:
|
|
340
|
+
start = max(0, i - first_idx)
|
|
341
|
+
window = "\n".join(l.strip() for l in lines[start:start + k])
|
|
342
|
+
r = SequenceMatcher(None, target, window, autojunk=False).ratio()
|
|
343
|
+
if r > best[0]:
|
|
344
|
+
best = (r, start)
|
|
345
|
+
if best[0] <= 0:
|
|
346
|
+
return None
|
|
347
|
+
start = best[1]
|
|
348
|
+
return start + 1, min(len(lines), start + k), best[0]
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def no_match_message(content: str, old: str, new: str = "") -> str:
|
|
352
|
+
msg = ("old_string was not found in the file. It must match the current text exactly (whitespace and "
|
|
353
|
+
"indentation included, without Read's line-number prefixes).")
|
|
354
|
+
if new and len(new.strip()) > 10 and new.strip("\n") in content:
|
|
355
|
+
line = _line_of(content, content.find(new.strip("\n")))
|
|
356
|
+
msg += f" Note: new_string already appears in the file at line {line} - the edit may already be applied."
|
|
357
|
+
region = closest_region(content, old)
|
|
358
|
+
if region and region[2] >= 0.6:
|
|
359
|
+
a, b, sim = region
|
|
360
|
+
lines = content.split("\n")
|
|
361
|
+
shown = lines[a - 1: min(b, a - 1 + 20)]
|
|
362
|
+
snippet = "\n".join(f"{n:>6}\t{l}" for n, l in enumerate(shown, a))
|
|
363
|
+
msg += (f"\nThe most similar text ({sim:.0%} similar) is at lines {a}-{b}:\n{snippet}\n"
|
|
364
|
+
"Copy the exact text from there (without the line-number prefixes) and retry.")
|
|
365
|
+
else:
|
|
366
|
+
msg += " Re-read the relevant part of the file (it may have changed) and retry with its exact text."
|
|
367
|
+
return msg
|