From b928f616e8146363e6cef8e1035b978f22c49ae2 Mon Sep 17 00:00:00 2001 From: Mikey Date: Wed, 2 Sep 2026 14:21:20 -0700 Subject: [PATCH] Support relative and absolute path keys in fileWindows lookup --- sdk/src/__tests__/read-files.test.ts | 51 ++++++++++++++++++++++++++++ sdk/src/tools/read-files.ts | 5 ++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/sdk/src/__tests__/read-files.test.ts b/sdk/src/__tests__/read-files.test.ts index 9448c0f00b..7128febe0a 100644 --- a/sdk/src/__tests__/read-files.test.ts +++ b/sdk/src/__tests__/read-files.test.ts @@ -848,5 +848,56 @@ describe('getFiles', () => { expect(result['src/big.ts']).toContain('showing lines 10-14 of 3000') expect(result['src/big.ts']).toContain('showing lines 2500-2504 of 3000') }) + + test('resolves fileWindows keyed by relative path when filePaths has leading dot-slash', async () => { + const mockFs = createMockFs({ + files: { '/project/src/big.ts': { content: bigFile } }, + }) + + const result = await getFiles({ + filePaths: ['./src/big.ts'], + cwd: '/project', + fs: mockFs, + fileWindows: { 'src/big.ts': [{ offset: 2500, limit: 10 }] }, + }) + + expect(result['src/big.ts']).toContain('line 2500') + expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000') + expect(result['src/big.ts']).not.toContain('line 100\n') + }) + + test('resolves fileWindows keyed by relative path when filePaths has absolute path', async () => { + const mockFs = createMockFs({ + files: { '/project/src/big.ts': { content: bigFile } }, + }) + + const result = await getFiles({ + filePaths: ['/project/src/big.ts'], + cwd: '/project', + fs: mockFs, + fileWindows: { 'src/big.ts': [{ offset: 2500, limit: 10 }] }, + }) + + expect(result['src/big.ts']).toContain('line 2500') + expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000') + expect(result['src/big.ts']).not.toContain('line 100\n') + }) + + test('resolves fileWindows keyed by absolute path when filePaths has relative path', async () => { + const mockFs = createMockFs({ + files: { '/project/src/big.ts': { content: bigFile } }, + }) + + const result = await getFiles({ + filePaths: ['src/big.ts'], + cwd: '/project', + fs: mockFs, + fileWindows: { '/project/src/big.ts': [{ offset: 2500, limit: 10 }] }, + }) + + expect(result['src/big.ts']).toContain('line 2500') + expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000') + expect(result['src/big.ts']).not.toContain('line 100\n') + }) }) }) diff --git a/sdk/src/tools/read-files.ts b/sdk/src/tools/read-files.ts index 1a9c217919..a113a28cf0 100644 --- a/sdk/src/tools/read-files.ts +++ b/sdk/src/tools/read-files.ts @@ -116,7 +116,10 @@ export async function getFiles(params: { const content = await fs.readFile(fullPath, 'utf8') - const windows = fileWindows?.[filePath] + const windows = + fileWindows?.[filePath] ?? + fileWindows?.[relativePath] ?? + (fullPath ? fileWindows?.[fullPath] : undefined) const windowedContent = limitContent && fileWindows !== undefined ? (windows?.length ? windows : [{}])