From 569e0cf7a1a048584146496d8464ce8f8ed438f8 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 16 May 2026 23:58:44 -0700 Subject: [PATCH] Fix read_files normalized path results --- common/src/tools/params/tool/read-files.ts | 2 +- .../get-file-reading-updates.test.ts | 59 +++++++++++++++++++ .../src/get-file-reading-updates.ts | 10 ++-- 3 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts diff --git a/common/src/tools/params/tool/read-files.ts b/common/src/tools/params/tool/read-files.ts index bc366dd883..23814bc0e1 100644 --- a/common/src/tools/params/tool/read-files.ts +++ b/common/src/tools/params/tool/read-files.ts @@ -28,7 +28,7 @@ const inputSchema = z .string() .min(1, 'Paths cannot be empty') .describe( - `File path to read relative to the **project root**. Absolute file paths will not work.`, + `File path to read. Prefer paths relative to the **project root**; absolute paths inside the project are accepted, but paths outside the project will not work.`, ), ), ) diff --git a/packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts b/packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts new file mode 100644 index 0000000000..0d1ed85396 --- /dev/null +++ b/packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts @@ -0,0 +1,59 @@ +import { describe, expect, test } from 'bun:test' + +import { getFileReadingUpdates } from '../get-file-reading-updates' + +describe('getFileReadingUpdates', () => { + test('returns files keyed by the requested paths', async () => { + const files = await getFileReadingUpdates({ + requestedFiles: ['src/index.ts'], + requestFiles: async () => ({ + 'src/index.ts': 'console.log("hello")', + }), + }) + + expect(files).toEqual([ + { + path: 'src/index.ts', + content: 'console.log("hello")', + }, + ]) + }) + + test('keeps files returned under normalized paths', async () => { + const files = await getFileReadingUpdates({ + requestedFiles: ['/project/src/index.ts', './src/util.ts'], + requestFiles: async () => ({ + 'src/index.ts': 'console.log("hello")', + 'src/util.ts': 'export const util = true', + }), + }) + + expect(files).toEqual([ + { + path: 'src/index.ts', + content: 'console.log("hello")', + }, + { + path: 'src/util.ts', + content: 'export const util = true', + }, + ]) + }) + + test('omits null file results', async () => { + const files = await getFileReadingUpdates({ + requestedFiles: ['missing.ts', 'src/index.ts'], + requestFiles: async () => ({ + 'missing.ts': null, + 'src/index.ts': 'content', + }), + }) + + expect(files).toEqual([ + { + path: 'src/index.ts', + content: 'content', + }, + ]) + }) +}) diff --git a/packages/agent-runtime/src/get-file-reading-updates.ts b/packages/agent-runtime/src/get-file-reading-updates.ts index c66bca927f..3aad058eec 100644 --- a/packages/agent-runtime/src/get-file-reading-updates.ts +++ b/packages/agent-runtime/src/get-file-reading-updates.ts @@ -16,13 +16,11 @@ export async function getFileReadingUpdates(params: { const allFilePaths = uniq(requestedFiles) const loadedFiles = await requestFiles({ filePaths: allFilePaths }) - const addedFiles = allFilePaths - .filter( - (path) => loadedFiles[path] != null && loadedFiles[path] !== undefined, - ) - .map((path) => ({ + const addedFiles = Object.entries(loadedFiles) + .filter((entry): entry is [string, string] => typeof entry[1] === 'string') + .map(([path, content]) => ({ path, - content: loadedFiles[path]!, + content, })) return addedFiles