Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/tools/params/tool/read-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
),
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
},
])
})
})
10 changes: 4 additions & 6 deletions packages/agent-runtime/src/get-file-reading-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading