mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 23:47:54 +08:00
core/tools: edit_lineno unread error names the read window
The boundary overguard (read offset=50 shows lines 51+, then editing
line 50 fails) forced blind re-reads. The error now reports the read
window ("this turn read lines 51-86") and advises reading with a margin
around the target range; read_file's description says the same.
This commit is contained in:
@@ -111,13 +111,20 @@ async def edit_lineno(path: str, start_line: int, end_line: int, new_content: st
|
||||
if err is not None:
|
||||
return err
|
||||
|
||||
unread = _unread_lines_in_range(lineno_read_lines(str(target)), start_line, end_line, len(lines))
|
||||
read_lines = lineno_read_lines(str(target))
|
||||
unread = _unread_lines_in_range(read_lines, start_line, end_line, len(lines))
|
||||
if unread:
|
||||
preview = unread[:_UNREAD_PREVIEW]
|
||||
head = ", ".join(str(i) for i in preview)
|
||||
if len(unread) > _UNREAD_PREVIEW:
|
||||
head += f", … ({len(unread)} total)"
|
||||
return f"error: lines {head} not read; call read_file(path, with_lineno=true) first to see current line numbers"
|
||||
window = ""
|
||||
if read_lines:
|
||||
window = f" (this turn read lines {min(read_lines)}-{max(read_lines)})"
|
||||
return (
|
||||
f"error: lines {head} not read{window}; call read_file(path, with_lineno=true) "
|
||||
"first — read with a small margin around the lines you plan to edit"
|
||||
)
|
||||
|
||||
recorded_mtime = lineno_read_mtime(str(target))
|
||||
if recorded_mtime is not None:
|
||||
|
||||
@@ -64,6 +64,8 @@ async def read_file(
|
||||
(None = rest of file). When ``with_lineno`` is true, each line is prefixed
|
||||
with its 1-based file line number (`` N|…``), matching ``edit_lineno``
|
||||
numbering, and those lines are marked readable for ``edit_lineno`` this turn.
|
||||
Only the displayed lines become editable, so read with a small margin around
|
||||
any range you plan to edit with ``edit_lineno``.
|
||||
|
||||
``max_chars`` caps the returned slice (default: the agent's tool-result cap,
|
||||
``DEFAULT_TOOL_RESULT_MAX_CHARS``); a ``truncate_token`` is appended when cut
|
||||
|
||||
Reference in New Issue
Block a user