feat(coding-agent): added matching bracket context lines to read and edit previews

- Added matching-bracket utilities to locate partner lines for visible spans.
- Added read tool output to use displayContent text and startLine for bracket-aware previews.
- Added matching-bracket context rows to generateDiffString and generateUnifiedDiffString.
- Adjusted diff row insertion to deduplicate and keep contiguous changed groups together.
This commit is contained in:
can1357
2026-06-08 14:00:54 +02:00
parent 2de70263d8
commit b8eecfffde
9 changed files with 573 additions and 36 deletions
@@ -69,6 +69,57 @@ describe("read tool multi-range selector", () => {
expect(text).toContain("…");
});
it("includes the matching closing bracket line outside a forward range", async () => {
const filePath = path.join(tmpDir, "brackets.ts");
await fs.writeFile(
filePath,
[
"function outer() {",
" const one = 1;",
" const two = 2;",
" const three = 3;",
" const four = 4;",
" return one + two + three + four;",
"}",
"after();",
].join("\n"),
);
const tool = new ReadTool(createSession(tmpDir));
const text = textOutput(await tool.execute("call-bracket-close", { path: `${filePath}:1-1` }));
expect(text).toContain("function outer() {");
expect(text).toContain("…");
expect(text).toContain("}");
expect(text).not.toContain("const four");
expect(text).not.toContain("return one + two");
});
it("includes the matching opening bracket line outside a reverse range", async () => {
const filePath = path.join(tmpDir, "brackets.ts");
await fs.writeFile(
filePath,
[
"function outer() {",
" const one = 1;",
" const two = 2;",
" const three = 3;",
" const four = 4;",
" return one + two + three + four;",
"}",
"after();",
].join("\n"),
);
const tool = new ReadTool(createSession(tmpDir));
const text = textOutput(await tool.execute("call-bracket-open", { path: `${filePath}:7-7` }));
expect(text.indexOf("function outer() {")).toBeLessThan(text.indexOf("}"));
expect(text).toContain("…");
expect(text).not.toContain("const one = 1");
expect(text).not.toContain("const four = 4");
});
it("merges overlapping ranges into a single contiguous block", async () => {
const filePath = path.join(tmpDir, "numbered.txt");
await fs.writeFile(filePath, makeNumberedContent(20));