Compare commits

...
Author SHA1 Message Date
Cursor Agentand陈大猫 80fe4c19c7 fix(vault): treat empty vault_notes_get query as omitted
Models pass query: "" on range reads. Accept that as no search so
vault_notes_get does not fail and retry.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-10-23 08:49:34 +00:00
2 changed files with 13 additions and 2 deletions

No files matched your search

+11 -1
View File
@@ -57,6 +57,16 @@ test('invalid ranges, queries and changed notes fail explicitly', () => {
for (const params of [
{ offset: -1 }, { offset: 0.5 }, { offset: 9 }, { offset: 2 }, { offset: '1' },
{ maxChars: 0 }, { maxChars: NaN }, { maxChars: Infinity },
{ query: '' }, { query: 'a'.repeat(201) }, { query: 1 }, { expectedUpdatedAt: 1 },
{ query: 'a'.repeat(201) }, { query: 1 }, { expectedUpdatedAt: 1 },
]) assert.equal(readVaultNote(source, params).ok, false, JSON.stringify(params));
});
test('empty query is a range read, same as omitting query', () => {
const source = { ...note, content: 'hello note' };
const omitted = read(source, { offset: 1, maxChars: 4 });
const empty = read(source, { query: '', offset: 1, maxChars: 4 });
assert.equal(empty.note?.content, omitted.note?.content);
assert.equal(empty.offset, omitted.offset);
assert.equal(empty.nextOffset, omitted.nextOffset);
assert.equal('matchOffset' in empty, false);
});
+2 -1
View File
@@ -7,7 +7,8 @@ export const MAX_NOTE_READ_CHARS = 6000;
export function readVaultNote(note: VaultNote, params: Record<string, unknown>) {
const offset = params.offset ?? 0;
const maxChars = params.maxChars ?? MAX_NOTE_READ_CHARS;
const query = params.query;
// Models often send query: "" with a range read. Empty means omit, not an invalid search.
const query = params.query === '' ? undefined : params.query;
if (typeof offset !== 'number' || !Number.isSafeInteger(offset) || offset < 0 || offset > note.content.length) {
return { ok: false, error: 'offset must be an integer within the note content.' };
}