Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

feat(coding-agent): restore collapsed diff summaries (#543)

Sebastian Müllercc7fb119c5f5
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 75be1cb967..7e4123a265 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Changed collapsed edit and IPython tool calls to show compact per-file line-change summaries while keeping full diffs available when expanded.
- Fixed daemon startup failing when an interrupted supervisor left an empty ownership directory.
## [0.3.3] - 2026-07-23
diff --git a/packages/coding-agent/src/core/tools/edit.ts b/packages/coding-agent/src/core/tools/edit.ts
index 08d52f1fde..746d89da62 100644
--- a/packages/coding-agent/src/core/tools/edit.ts
+++ b/packages/coding-agent/src/core/tools/edit.ts
@@ -4,6 +4,7 @@ import { constants } from "fs";
import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
import { type Static, Type } from "typebox";
import { renderDiff } from "../../modes/interactive/components/diff.js";
+import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
import type { ToolDefinition } from "../extensions/types.js";
import {
applyEditsToNormalizedContent,
@@ -251,14 +252,25 @@ function buildEditCallComponent(
component: EditCallRenderComponent,
args: RenderableEditArgs | undefined,
theme: typeof import("../../modes/interactive/theme/theme.js").theme,
+ expanded: boolean,
+ showExpandHint: boolean,
): EditCallRenderComponent {
component.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));
component.clear();
- component.addChild(new Text(formatEditCall(args, theme), 0, 0));
+ const canExpand = component.preview !== undefined && !("error" in component.preview);
+ const expandHint =
+ canExpand && showExpandHint
+ ? `${theme.fg("dim", " · ")}${keyHint("app.tools.expand", expanded ? "to collapse" : "to expand")}`
+ : "";
+ component.addChild(new Text(`${formatEditCall(args, theme)}${expandHint}`, 0, 0));
const body =
component.preview &&
- ("error" in component.preview ? theme.fg("error", component.preview.error) : renderDiff(component.preview.diff));
+ ("error" in component.preview
+ ? theme.fg("error", component.preview.error)
+ : expanded
+ ? renderDiff(component.preview.diff)
+ : undefined);
if (body) {
component.addChild(new Spacer(1));
component.addChild(new Text(body, 0, 0));
@@ -437,7 +449,7 @@ export function createEditToolDefinition(
});
}
- return buildEditCallComponent(component, args, theme);
+ return buildEditCallComponent(component, args, theme, context.expanded, context.showExpandHint !== false);
},
renderResult(result, _options, theme, context) {
const callComponent = context.state.callComponent;
@@ -462,7 +474,13 @@ export function createEditToolDefinition(
changed = true;
}
if (changed) {
- buildEditCallComponent(callComponent, context.args as RenderableEditArgs | undefined, theme);
+ buildEditCallComponent(
+ callComponent,
+ context.args as RenderableEditArgs | undefined,
+ theme,
+ context.expanded,
+ context.showExpandHint !== false,
+ );
}
}
diff --git a/packages/coding-agent/src/modes/interactive/components/edit-summary.ts b/packages/coding-agent/src/modes/interactive/components/edit-summary.ts
index 7c79de4da5..2f8b142525 100644
--- a/packages/coding-agent/src/modes/interactive/components/edit-summary.ts
+++ b/packages/coding-agent/src/modes/interactive/components/edit-summary.ts
@@ -1,10 +1,12 @@
+import { isAbsolute } from "node:path";
import type { AgentMessage } from "@earendil-works/pi-agent-core";
import type { ToolResultMessage } from "@earendil-works/pi-ai";
+import { type Component, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
import type { EditToolDetails } from "../../../core/tools/edit.js";
import { generateDiffString } from "../../../core/tools/edit-diff.js";
import type { IpythonToolDetails } from "../../../core/tools/ipython.js";
import { resolveToCwd } from "../../../core/tools/path-utils.js";
-import { canonicalizePath } from "../../../utils/paths.js";
+import { canonicalizePath, formatPathRelativeToCwdOrAbsolute } from "../../../utils/paths.js";
import { theme } from "../theme/theme.js";
export interface FileChangeSummary {
@@ -81,6 +83,33 @@ function counts(change: Pick<FileChangeSummary, "added" | "removed">): string {
return `${theme.fg("toolDiffAdded", `+${change.added}`)} ${theme.fg("toolDiffRemoved", `-${change.removed}`)}`;
}
+function formatFileChangePath(path: string, cwd: string): string {
+ const resolvedPath = resolveToCwd(path, cwd);
+ const lexicalPath = formatPathRelativeToCwdOrAbsolute(resolvedPath, cwd);
+ if (!isAbsolute(lexicalPath)) return lexicalPath;
+ return formatPathRelativeToCwdOrAbsolute(canonicalizePath(resolvedPath), canonicalizePath(cwd));
+}
+
+export class FileChangeSummaryComponent implements Component {
+ constructor(
+ private readonly changes: readonly FileChangeSummary[],
+ private readonly cwd: string,
+ ) {}
+
+ render(width: number): string[] {
+ const safeWidth = Math.max(1, width);
+ const prefix = theme.fg("dim", " ╰─ ");
+ return this.changes.map((change) => {
+ const suffix = `${theme.fg("dim", " ")}${counts(change)}`;
+ const available = Math.max(1, safeWidth - visibleWidth(prefix) - visibleWidth(suffix));
+ const path = truncateToWidth(formatFileChangePath(change.path, this.cwd), available, "…");
+ return truncateToWidth(`${prefix}${theme.fg("muted", path)}${suffix}`, safeWidth, "");
+ });
+ }
+
+ invalidate(): void {}
+}
+
export function formatTotalChangeSummary(changes: readonly FileChangeSummary[]): string {
const totals = changes.reduce(
(sum, change) => ({ added: sum.added + change.added, removed: sum.removed + change.removed }),
diff --git a/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts b/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts
index 648de627b4..d80a62a1c6 100644
--- a/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts
+++ b/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts
@@ -359,7 +359,7 @@ export class IPythonCellComponent implements Component {
const lines = [truncateToWidth(` ${this.collapsedLine(details)}`, safeWidth, "")];
const hasCode = this.state.expanded ? this.renderCode(lines, safeWidth) : false;
- if ((details.diffs?.length ?? 0) > 0) {
+ if ((details.diffs?.length ?? 0) > 0 && this.state.expanded) {
this.renderDiffs(lines, safeWidth, details.diffs ?? [], this.marker(details));
}
if ((details.sentAgentMessages?.length ?? 0) > 0) {
diff --git a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
index 62e80c8197..9e85e1694c 100644
--- a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
+++ b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
@@ -9,6 +9,7 @@ import { getTextOutput as getRenderedTextOutput } from "../../../core/tools/rend
import type { AgentConnectionToolDefinition } from "../../agent-connection/index.js";
import { type Theme, theme } from "../theme/theme.js";
import { getWorkingPulseFrame, workingIconFrame } from "../theme/working-icon.js";
+import { FileChangeSummaryComponent, getToolFileChanges } from "./edit-summary.js";
import { getIpythonCodeFromArgs, IPythonCellComponent } from "./ipython-cell.js";
import { ToolPanel } from "./tool-panel.js";
@@ -387,6 +388,18 @@ export class ToolExecutionComponent extends Container {
}
}
+ const isBuiltInEdit =
+ this.toolName === "edit" &&
+ (this.toolDefinition === undefined || this.toolDefinition.replayBuiltInToolName === "edit");
+ if (!this.expanded && this.result && (isBuiltInEdit || this.shouldUseIpythonRenderer())) {
+ const changes = getToolFileChanges(this.toolName, this.args, this.result, this.cwd);
+ if (changes.length > 0) {
+ const container = this.usesSelfRenderShell() ? this.selfRenderContainer : this.contentPanel;
+ container.addChild(new FileChangeSummaryComponent(changes, this.cwd));
+ hasContent = true;
+ }
+ }
+
if (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {
this.hideComponent = true;
}
diff --git a/packages/coding-agent/test/ipython-cell-diff.test.ts b/packages/coding-agent/test/ipython-cell-diff.test.ts
index 4bd0e41694..ea0028012c 100644
--- a/packages/coding-agent/test/ipython-cell-diff.test.ts
+++ b/packages/coding-agent/test/ipython-cell-diff.test.ts
@@ -224,9 +224,9 @@ describe("IPythonCellComponent diff rendering", () => {
expanded: false,
});
expect(collapsed).toContain("to expand");
- expect(collapsed).toContain("big.py");
- expect(collapsed).toContain("old");
- expect(collapsed).toContain("NEW");
+ expect(collapsed).not.toContain("big.py");
+ expect(collapsed).not.toContain("old");
+ expect(collapsed).not.toContain("NEW");
});
it("hides edit source when collapsed and shows it when globally expanded", () => {
diff --git a/packages/coding-agent/test/tool-execution-component.test.ts b/packages/coding-agent/test/tool-execution-component.test.ts
index 92ee08403a..f86b284fdd 100644
--- a/packages/coding-agent/test/tool-execution-component.test.ts
+++ b/packages/coding-agent/test/tool-execution-component.test.ts
@@ -690,9 +690,9 @@ describe("ToolExecutionComponent parity", () => {
const collapsed = stripAnsi(component.render(120).join("\n"));
expect(collapsed).not.toContain("hidden_side_effect");
- expect(collapsed).toMatch(/✓ README\.md\s+\+1 -1/);
- expect(collapsed).toMatch(/1 - before/);
- expect(collapsed).toMatch(/1 \+ after/);
+ expect(collapsed).toContain("╰─ README.md +1 -1");
+ expect(collapsed).not.toMatch(/1 - before/);
+ expect(collapsed).not.toMatch(/1 \+ after/);
component.setExpanded(true);
const expanded = stripAnsi(component.render(120).join("\n"));