fix: steer models to replace_range in the replace_note_content tool description (#30048)

Asked to add a section or change a few lines, models answer with a whole-note
replace_note_content call and the rest of the note is gone, with nothing to
undo because the editor only records versions on chat inserts. The tool
already supports replace_range operations with an expected guard, but its
description never said when to use them or how the offsets work, so models
defaulted to sending the whole note back.

The docstring, which is the description every model receives for this tool
in note chats and normal chats alike, now states the preference for range
edits and the offset, overlap and expected rules the handler enforces.
Verified the text lands in the generated tool spec unchanged and that range
edits, the expected mismatch rejection and whole-note replace behave as
described against a sqlite data dir.
This commit is contained in:
Classic298 2026-09-16 04:51:49 +02:00 committed by GitHub
parent 06d9d2e7c7
commit 3d6598fccb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1342,6 +1342,14 @@ async def replace_note_content(
"""
Update an existing note by replacing the whole markdown content or applying range operations.
Prefer "replace_range" when only part of the note changes.
A "replace" operation must be the only operation in the request.
start and end are 0-indexed character offsets into the markdown content from view_note.
end is exclusive.
Offsets never shift as operations are applied.
Ranges must not overlap.
expected is optional. When set, the request is rejected if the range's current text does not match it.
:param note_id: The ID of the note to update
:param content: The new markdown content for a whole-note update
:param operations: Optional note operations: