Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/fix-read-tool-symlink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix the web backend's file-reading tools mishandling symbolic links: Read rejected them as not regular files, and media size checks measured the link instead of its target.
2 changes: 1 addition & 1 deletion packages/agent-core-v2/src/agent/media/tools/read-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
};
}

const stat = await this.fs.stat(safePath);
const stat = await this.fs.stat(safePath, { followSymlinks: true });
if (stat.size === 0) {
return { isError: true, output: `"${args.path}" is empty.` };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class ReadTool implements BuiltinTool<ReadInput> {
try {
let stat: Awaited<ReturnType<IHostFileSystem['stat']>>;
try {
stat = await this.fs.stat(safePath);
stat = await this.fs.stat(safePath, { followSymlinks: true });
} catch (error) {
if (isFileNotFoundError(error)) {
return { isError: true, output: `"${args.path}" does not exist.` };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ describe('ReadTool', () => {
});
});

it('stats with followSymlinks so symlinked files stay readable', async () => {
const { fs, stat } = createSpiedFs('alpha\n');
const tool = new ReadTool(fs, createTestEnv(), PERMISSIVE_WORKSPACE);

const result = await execute(tool, { path: '/tmp/a.txt' });

expect(result.isError).not.toBe(true);
expect(stat).toHaveBeenCalledWith('/tmp/a.txt', { followSymlinks: true });
});

it('normalizes pure CRLF files to the LF model view', async () => {
const tool = toolWithContent('alpha\r\nbeta\r\n');

Expand Down
Loading