fix(tools): align claude-memory insert with memory_20250818 line semantics#1309
Open
rohitsux wants to merge 1 commit into
Open
fix(tools): align claude-memory insert with memory_20250818 line semantics#1309rohitsux wants to merge 1 commit into
rohitsux wants to merge 1 commit into
Conversation
…ntics Anthropic's memory_20250818 spec defines insert as: insert_text is inserted AFTER line insert_line, 0 inserts at the beginning of the file, and the valid range is [0, n_lines]. The implementation treated insert_line as a 1-based insert-BEFORE index with range [1, n_lines + 1]. Since the caller of this tool is Claude itself, which is trained on the spec semantics, every model-driven insert landed one line earlier than intended, insert_line: 0 (insert at top of file) was rejected as invalid, and insert_line: n_lines (append) inserted before the last line instead of after it. Fix the validation range to [0, n_lines], splice at insert_line directly (0-based insert-after), and update the error and success messages to match. One existing tool-operations test encoded the old insert-before behavior; its insert_line is adjusted so its expected output is unchanged under spec semantics. Adds four regression tests covering top-of-file, middle, append, and both out-of-range directions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Anthropic's
memory_20250818tool spec defines theinsertcommand as:insert_textis inserted after lineinsert_line,0inserts at the beginning of the file, and the valid range is[0, n_lines].ClaudeMemoryTool.inserttreatedinsert_lineas a 1-based insert-before index with range[1, n_lines + 1]:The caller of this tool is Claude itself, which is trained on the spec semantics, so in practice:
insert_line: 0(insert at top of file) was rejected as invalid,insert_line: n_lines(append) inserted before the last line instead of after it.Same class of issue as #1285 (str_replace spec literalness), one command over.
Fix
Validate against
[0, lines.length], splice atinsert_linedirectly (0-based insert-after), and update the error and success messages to the spec's wording. One existing tool-operations test encoded the old insert-before behavior; itsinsert_lineis adjusted from 2 to 1 so its expected output stays byte-identical under spec semantics.Tests
New
insert line semanticsdescribe block inclaude-memory.test.tsusing the existing mock harness: top-of-file (insert_line: 0), middle insert-after, append atn_lines, and both out-of-range directions (negative andn_lines + 1, asserting no write occurs). All four fail on main and pass with the fix.Verification
bun run test claude-memory: 14 passed (10 existing + 4 new).packages/toolssuite: 87 passed, zero new failures (the two pre-existing file-level failures reproduce identically on unmodified main).bun run buildclean.Scope
Only the insert command's line-index semantics change (validation range, splice index, and its two messages). str_replace, view, create, delete, and rename are untouched.