refactor(coding-agent): changed file headers to display only filenames

- Updated `formatReadHashlineHeader` to use `path.basename` instead of the full path.
- Applied the new formatter across record and display functions in the read tool.
- Added and updated tests to verify that hashline headers now contain only the filename for nested files.
This commit is contained in:
can1357
2026-06-27 01:10:09 +02:00
parent 14c8e09e26
commit 0ef82d8518
4 changed files with 29 additions and 6 deletions
@@ -48,13 +48,29 @@ describe("read tool multi-range selector", () => {
await fs.rm(tmpDir, { recursive: true, force: true });
});
it("uses only the filename in hashline headers for nested files", async () => {
const filePath = path.join(tmpDir, "src", "nested", "numbered.txt");
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, "alpha\nbeta\n");
const tool = new ReadTool(createSession(tmpDir));
const text = textOutput(await tool.execute("call-filename-header", { path: filePath }));
const firstLine = text.split("\n")[0];
expect(firstLine).toMatch(/^\[numbered\.txt#[0-9A-F]{4}\]$/);
expect(firstLine).not.toContain("src");
});
it("returns both ranges separated by an elision marker", async () => {
const filePath = path.join(tmpDir, "numbered.txt");
const filePath = path.join(tmpDir, "src", "numbered.txt");
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, makeNumberedContent(50));
const tool = new ReadTool(createSession(tmpDir));
const result = await tool.execute("call-multi", { path: `${filePath}:3-5,20-22` });
const text = textOutput(result);
const firstLine = text.split("\n")[0];
expect(firstLine).toMatch(/^\[numbered\.txt#[0-9A-F]{4}\]$/);
expect(text).toContain("line 3");
expect(text).toContain("line 4");