A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
Add Ctrl+J to toggle edit diffs independently of tool output (#1388)
Sebastian Müllere64fbcbf33c8
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 60589450e1..929ee361ea 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -2,6 +2,7 @@## [Unreleased]+- Added `app.edits.expand` (`ctrl+j`) to toggle edit diffs; diffs are now shown only by this toggle, and `ctrl+o` no longer affects them.- Fixed fullscreen wheel scrolling in Ghostty while retaining application link clicks; set `terminal.fullscreenMouse` to `false` to use native Cmd-click instead.- Changed the agents view to sort idle and inactive sessions by last message time, newest first, while keeping running agents in stable creation order.- Fixed `openai-codex` models being invisible to `rlm` subagents and `find_models` because model discovery reported Prime Agent's own version as the Codex client version ([#1375](https://github.com/PrimeIntellect-ai/prime-agent/pull/1375) by [@bilelrais](https://github.com/bilelrais)).diff --git a/packages/coding-agent/docs/keybindings.md b/packages/coding-agent/docs/keybindings.mdindex a2a492f7d2..94248e10da 100644--- a/packages/coding-agent/docs/keybindings.md+++ b/packages/coding-agent/docs/keybindings.md@@ -131,6 +131,7 @@ Use `tab` to cycle forward and `shift+tab` to cycle backward through Providers,|--------|---------|-------------|| `app.tools.expand` | `ctrl+o` | Collapse or expand tool output || `app.messages.expand` | `ctrl+p` | Collapse or expand agent-to-agent messages |+| `app.edits.expand` | `ctrl+j` | Collapse or expand edit diffs || `app.message.followUp` | `alt+enter` | Queue follow-up message || `app.message.navigateOlder` | `alt+up` | Select the next older pending message || `app.message.navigateNewer` | `alt+down` | Select the next newer pending message or restore the draft |diff --git a/packages/coding-agent/src/core/extensions/runner.ts b/packages/coding-agent/src/core/extensions/runner.tsindex 17cc02e561..21c739c16a 100644--- a/packages/coding-agent/src/core/extensions/runner.ts+++ b/packages/coding-agent/src/core/extensions/runner.ts@@ -67,6 +67,7 @@ const RESERVED_KEYBINDINGS_FOR_EXTENSION_CONFLICTS = ["app.model.select","app.tools.expand","app.messages.expand",+ "app.edits.expand","app.thinking.toggle","app.subagents.focus","app.editor.external",diff --git a/packages/coding-agent/src/core/keybindings.ts b/packages/coding-agent/src/core/keybindings.tsindex 60b579a674..6c451d53e6 100644--- a/packages/coding-agent/src/core/keybindings.ts+++ b/packages/coding-agent/src/core/keybindings.ts@@ -22,6 +22,7 @@ export interface AppKeybindings {"app.configuration.previousTab": true;"app.tools.expand": true;"app.messages.expand": true;+ "app.edits.expand": true;"app.thinking.toggle": true;"app.subagents.focus": true;"app.heartbeats.open": true;@@ -92,6 +93,7 @@ export const KEYBINDINGS = {description: "Toggle agent message expansion",defaultKeyScope: "editor",},+ "app.edits.expand": { defaultKeys: "ctrl+j", description: "Toggle edit diffs", defaultKeyScope: "editor" },"app.thinking.toggle": {defaultKeys: "ctrl+t",description: "Toggle thinking blocks",diff --git a/packages/coding-agent/src/core/tools/edit.ts b/packages/coding-agent/src/core/tools/edit.tsindex 2582ead14a..229ea1cb04 100644--- a/packages/coding-agent/src/core/tools/edit.ts+++ b/packages/coding-agent/src/core/tools/edit.ts@@ -141,6 +141,7 @@ type EditCallRenderComponent = Box & {previewArgsKey?: string;previewPending?: boolean;settledError?: boolean;+ resultSettled?: boolean;};function createEditCallRenderComponent(): EditCallRenderComponent {@@ -149,6 +150,7 @@ function createEditCallRenderComponent(): EditCallRenderComponent {previewArgsKey: undefined as string | undefined,previewPending: false,settledError: false,+ resultSettled: false,});}@@ -258,8 +260,15 @@ function buildEditCallComponent(component.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));component.clear();const canExpand = component.preview !== undefined && !("error" in component.preview);+ // Collapsed rows normally carry the ctrl+j hint on the `╰─ path +N -M`+ // summary line instead of the header — but that summary only mounts after a+ // settled successful result. Until then (preview-only) and on error rows the+ // header keeps the hint, so an expandable diff always advertises the key.+ const hasSummaryLine = component.resultSettled === true;const expandHint =- canExpand && showExpandHint ? `${theme.fg("dim", " · ")}${expandCollapseHint("app.tools.expand", expanded)}` : "";+ canExpand && showExpandHint && (expanded || !hasSummaryLine)+ ? `${theme.fg("dim", " · ")}${expandCollapseHint("app.edits.expand", expanded)}`+ : "";component.addChild(new Text(`${formatEditCall(args, theme)}${expandHint}`, 0, 0));const body =@@ -471,6 +480,13 @@ export function createEditToolDefinition(callComponent.settledError = context.isError;changed = true;}+ // Mirrors the FileChangeSummaryComponent mount condition: any result+ // with a countable diff and no error mounts the summary line.+ const summaryMounts = !context.isError && typeof resultDiff === "string";+ if (callComponent.resultSettled !== summaryMounts) {+ callComponent.resultSettled = summaryMounts;+ changed = true;+ }if (changed) {buildEditCallComponent(callComponent,diff --git a/packages/coding-agent/src/modes/interactive/components/conversation-components.ts b/packages/coding-agent/src/modes/interactive/components/conversation-components.tsindex cad454d071..dd2bb456e7 100644--- a/packages/coding-agent/src/modes/interactive/components/conversation-components.ts+++ b/packages/coding-agent/src/modes/interactive/components/conversation-components.ts@@ -38,6 +38,7 @@ export interface ConversationComponentsOptions {hiddenThinkingLabel?: string;toolsExpanded?: boolean;agentMessagesExpanded?: boolean;+ editDiffsExpanded?: boolean;isRecognizedSlashCommand?: (name: string) => boolean;}@@ -71,6 +72,7 @@ export function buildConversationComponents(const pendingTools = new Map<string, ToolExecutionComponent>();const expanded = options.toolsExpanded ?? false;const agentMessagesExpanded = options.agentMessagesExpanded ?? false;+ const editDiffsExpanded = options.editDiffsExpanded ?? false;for (const message of messages) {if (message.role === "assistant") {@@ -103,6 +105,7 @@ export function buildConversationComponents();tool.setExpanded(expanded);tool.setAgentMessagesExpanded(agentMessagesExpanded);+ tool.setEditDiffsExpanded(editDiffsExpanded);tool.markExecutionStarted();tool.setArgsComplete();selectLatestToolExpandHint(components, tool);diff --git a/packages/coding-agent/src/modes/interactive/components/edit-summary.ts b/packages/coding-agent/src/modes/interactive/components/edit-summary.tsindex 2f8b142525..97c03c1e62 100644--- a/packages/coding-agent/src/modes/interactive/components/edit-summary.ts+++ b/packages/coding-agent/src/modes/interactive/components/edit-summary.ts@@ -8,6 +8,7 @@ import type { IpythonToolDetails } from "../../../core/tools/ipython.js";import { resolveToCwd } from "../../../core/tools/path-utils.js";import { canonicalizePath, formatPathRelativeToCwdOrAbsolute } from "../../../utils/paths.js";import { theme } from "../theme/theme.js";+import { expandCollapseHint } from "./keybinding-hints.js";export interface FileChangeSummary {path: string;@@ -94,13 +95,18 @@ export class FileChangeSummaryComponent implements Component {constructor(private readonly changes: readonly FileChangeSummary[],private readonly cwd: string,+ private readonly diffsExpanded?: boolean,) {}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 hint =+ this.diffsExpanded === undefined+ ? ""+ : `${theme.fg("dim", " · ")}${expandCollapseHint("app.edits.expand", this.diffsExpanded)}`;+ return this.changes.map((change, index) => {+ const suffix = `${theme.fg("dim", " ")}${counts(change)}${index === this.changes.length - 1 ? hint : ""}`;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, "");diff --git a/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts b/packages/coding-agent/src/modes/interactive/components/ipython-cell.tsindex b7c0f30798..98986ab16e 100644--- a/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts+++ b/packages/coding-agent/src/modes/interactive/components/ipython-cell.ts@@ -33,6 +33,7 @@ export interface IPythonCellState {isError?: boolean;expanded?: boolean;agentMessagesExpanded?: boolean;+ editDiffsExpanded?: boolean;showExpandHint?: boolean;executionStarted?: boolean;argsComplete?: boolean;@@ -383,7 +384,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 && this.state.expanded) {+ if ((details.diffs?.length ?? 0) > 0 && this.state.editDiffsExpanded) {this.renderDiffs(lines, safeWidth, details.diffs ?? [], this.marker(details));}if ((details.sentAgentMessages?.length ?? 0) > 0) {@@ -428,6 +429,11 @@ export class IPythonCellComponent implements Component {if (this.state.showExpandHint !== false) {parts.push(expandCollapseHint("app.tools.expand", this.state.expanded === true));+ // Expanded diffs replace the summary line that normally carries the+ // ctrl+j cue, so the header advertises the collapse key instead.+ if (this.state.editDiffsExpanded && (details.diffs?.length ?? 0) > 0) {+ parts.push(expandCollapseHint("app.edits.expand", true));+ }}return parts.join(theme.fg("dim", " · "));}diff --git a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts b/packages/coding-agent/src/modes/interactive/components/tool-execution.tsindex 9c8ccc5650..0182bfbd42 100644--- a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts+++ b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts@@ -80,6 +80,7 @@ export class ToolExecutionComponent extends Container {private args: any;private expanded = false;private agentMessagesExpanded = false;+ private editDiffsExpanded = false;private showExpandHint = true;private showImages: boolean;private includeImageDimensions: boolean;@@ -175,6 +176,13 @@ export class ToolExecutionComponent extends Container {return this.toolName === "ipython" && !this.toolDefinition?.renderCall && !this.toolDefinition?.renderResult;}+ private isBuiltInEditTool(): boolean {+ return (+ this.toolName === "edit" &&+ (this.toolDefinition === undefined || this.toolDefinition.replayBuiltInToolName === "edit")+ );+ }+private getRenderContext(lastComponent: Component | undefined): ToolRenderContext {return {args: this.args,@@ -189,7 +197,7 @@ export class ToolExecutionComponent extends Container {executionStarted: this.executionStarted,argsComplete: this.argsComplete,isPartial: this.isPartial,- expanded: this.expanded,+ expanded: this.isBuiltInEditTool() ? this.editDiffsExpanded : this.expanded,showExpandHint: this.showExpandHint,showImages: this.showImages,includeImageDimensions: this.includeImageDimensions,@@ -276,6 +284,14 @@ export class ToolExecutionComponent extends Container {this.updateDisplay();}+ setEditDiffsExpanded(expanded: boolean): void {+ if (this.editDiffsExpanded === expanded) {+ return;+ }+ this.editDiffsExpanded = expanded;+ this.updateDisplay();+ }+setShowExpandHint(show: boolean): void {if (this.showExpandHint === show) {return;@@ -341,6 +357,7 @@ export class ToolExecutionComponent extends Container {isError: this.result?.isError ?? false,expanded: this.expanded,agentMessagesExpanded: this.agentMessagesExpanded,+ editDiffsExpanded: this.editDiffsExpanded,executionStarted: this.executionStarted,argsComplete: this.argsComplete,showExpandHint: this.showExpandHint,@@ -398,14 +415,17 @@ 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())) {+ if (!this.editDiffsExpanded && this.result && (this.isBuiltInEditTool() || 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));+ container.addChild(+ new FileChangeSummaryComponent(+ changes,+ this.cwd,+ this.showExpandHint ? this.editDiffsExpanded : undefined,+ ),+ );hasContent = true;}}diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.tsindex db3d89d006..d84e99a15d 100644--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts@@ -334,6 +334,19 @@ function hasAgentMessagesExpansion(obj: unknown): obj is AgentMessagesExpandable);}+interface EditDiffsExpandable {+ setEditDiffsExpanded(expanded: boolean): void;+}++function hasEditDiffsExpansion(obj: unknown): obj is EditDiffsExpandable {+ return (+ typeof obj === "object" &&+ obj !== null &&+ "setEditDiffsExpanded" in obj &&+ typeof (obj as EditDiffsExpandable).setEditDiffsExpanded === "function"+ );+}+class ExpandableText extends Text implements Expandable {constructor(private readonly getCollapsedText: () => string,@@ -963,6 +976,7 @@ export class InteractiveMode {// Tool output expansion stateprivate toolOutputExpanded = false;private agentMessagesExpanded = false;+ private editDiffsExpanded = false;// Thinking block visibility stateprivate hideThinkingBlock = false;@@ -1391,6 +1405,7 @@ export class InteractiveMode {hint("app.model.select", "to select model"),hint("app.tools.expand", "to expand tools"),hint("app.messages.expand", "to expand agent messages"),+ hint("app.edits.expand", "to expand edit diffs"),hint("app.thinking.toggle", "to expand thinking"),hint("app.subagents.focus", "to inspect subagents"),hint("app.editor.external", "for external editor"),@@ -3033,6 +3048,7 @@ export class InteractiveMode {);component.setExpanded(this.toolOutputExpanded);component.setAgentMessagesExpanded(this.agentMessagesExpanded);+ component.setEditDiffsExpanded(this.editDiffsExpanded);if (this.startedToolCalls.has(latestToolCall.id)) {component.markExecutionStarted();}@@ -4180,6 +4196,7 @@ export class InteractiveMode {this.defaultEditor.onAction("app.model.select", () => this.showModelSelector());this.defaultEditor.onAction("app.tools.expand", () => this.toggleToolOutputExpansion());this.defaultEditor.onAction("app.messages.expand", () => this.toggleAgentMessageExpansion());+ this.defaultEditor.onAction("app.edits.expand", () => this.toggleEditDiffExpansion());this.defaultEditor.onAction("app.thinking.toggle", () => this.toggleThinkingBlockVisibility());this.defaultEditor.onAction("app.subagents.focus", () => this.focusSubagentSummary());this.defaultEditor.onAction("app.heartbeats.open", () => {@@ -6004,6 +6021,10 @@ export class InteractiveMode {this.toggleAgentMessageExpansion();return;}+ if (this.keybindings.matches(data, "app.edits.expand")) {+ this.toggleEditDiffExpansion();+ return;+ }if (this.keybindings.matches(data, "app.thinking.toggle")) {this.toggleThinkingBlockVisibility();return;@@ -6520,6 +6541,7 @@ export class InteractiveMode {);component.setExpanded(this.toolOutputExpanded);component.setAgentMessagesExpanded(this.agentMessagesExpanded);+ component.setEditDiffsExpanded(this.editDiffsExpanded);selectLatestToolExpandHint(this.chatContainer.children, component);this.chatContainer.addChild(component);this.registerIpythonToolComponent(content.name, content.id, component);@@ -7270,6 +7292,11 @@ export class InteractiveMode {this.applyChatExpansion();}+ private toggleEditDiffExpansion(): void {+ this.editDiffsExpanded = !this.editDiffsExpanded;+ this.applyChatExpansion();+ }+private setToolsExpanded(expanded: boolean): void {this.toolOutputExpanded = expanded;this.applyChatExpansion();@@ -7292,6 +7319,9 @@ export class InteractiveMode {if (hasAgentMessagesExpansion(child)) {child.setAgentMessagesExpanded(this.agentMessagesExpanded);}+ if (hasEditDiffsExpansion(child)) {+ child.setEditDiffsExpanded(this.editDiffsExpanded);+ }}// Expanding/collapsing changes blocks above the viewport, which would// otherwise force a full redraw that scrolls to the top and replays the@@ -9731,6 +9761,7 @@ export class InteractiveMode {const selectModel = this.getAppKeyDisplay("app.model.select");const expandTools = this.getAppKeyDisplay("app.tools.expand");const expandMessages = this.getAppKeyDisplay("app.messages.expand");+ const expandEdits = this.getAppKeyDisplay("app.edits.expand");const toggleThinking = this.getAppKeyDisplay("app.thinking.toggle");const externalEditor = this.getAppKeyDisplay("app.editor.external");const promptStash = this.getAppKeyDisplay("app.prompt.stash");@@ -9744,7 +9775,7 @@ export class InteractiveMode {**Controls**\`${selectModel}\` select model · \`/effort\` set reasoning · \`${expandTools}\` tool output-\`${expandMessages}\` agent messages · \`${toggleThinking}\` thinking blocks · \`${promptStash}\` stash prompt · \`${externalEditor}\` edit in \`$EDITOR\`+\`${expandMessages}\` agent messages · \`${expandEdits}\` edit diffs · \`${toggleThinking}\` thinking blocks · \`${promptStash}\` stash prompt · \`${externalEditor}\` edit in \`$EDITOR\`\`${pasteImage}\` paste image**Help**@@ -9783,6 +9814,7 @@ ${shortcutsKey ? `\`${shortcutsKey}\` quick shortcuts · ` : ""}\`/hotkeys\` fulconst selectModel = this.getAppKeyDisplay("app.model.select");const expandTools = this.getAppKeyDisplay("app.tools.expand");const expandMessages = this.getAppKeyDisplay("app.messages.expand");+ const expandEdits = this.getAppKeyDisplay("app.edits.expand");const toggleThinking = this.getAppKeyDisplay("app.thinking.toggle");const focusSubagents = this.getAppKeyDisplay("app.subagents.focus");const manageHeartbeats = this.getAppKeyDisplay("app.heartbeats.open");@@ -9832,6 +9864,7 @@ ${interrupt ? `| \`${interrupt}\` | Interrupt current operation |\n` : ""}${shor| \`${selectModel}\` | Open model selector || \`${expandTools}\` | Toggle tool output expansion || \`${expandMessages}\` | Toggle agent message expansion |+| \`${expandEdits}\` | Toggle edit diff expansion || \`${toggleThinking}\` | Toggle thinking block visibility || \`${focusSubagents}\` | Focus the subagent summary / open the scoped agents view || \`${manageHeartbeats}\` | Manage heartbeats |diff --git a/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts b/packages/coding-agent/test/edit-tool-no-full-redraw.test.tsindex e346f5c0a4..36983c76c7 100644--- a/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts+++ b/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts@@ -126,7 +126,7 @@ describe("edit tool TUI rendering", () => {tui.start();await waitForRender();- component.setExpanded(true);+ component.setEditDiffsExpanded(true);component.setArgsComplete();tui.requestRender();await waitForRender();@@ -196,7 +196,7 @@ describe("edit tool TUI rendering", () => {tui.start();await waitForRender();- component.setExpanded(true);+ component.setEditDiffsExpanded(true);component.updateResult({content: [{ type: "text", text: `Successfully replaced ${edits.length} block(s) in ${filePath}.` }],diff --git a/packages/coding-agent/test/interactive-mode-status.test.ts b/packages/coding-agent/test/interactive-mode-status.test.tsindex 3d8ae677ec..165d219d8d 100644--- a/packages/coding-agent/test/interactive-mode-status.test.ts+++ b/packages/coding-agent/test/interactive-mode-status.test.ts@@ -4209,6 +4209,7 @@ describe("InteractiveMode.setToolsExpanded", () => {const fakeThis: any = {toolOutputExpanded: false,agentMessagesExpanded: false,+ editDiffsExpanded: false,customHeader: undefined,builtInHeader: { setExpanded: vi.fn() },chatContainer: { children: chatChildren },@@ -4237,7 +4238,7 @@ describe("InteractiveMode.setToolsExpanded", () => {test("toggles agent messages separately from tools", () => {const toolChild = { setExpanded: vi.fn() };- const ipythonChild = { setExpanded: vi.fn(), setAgentMessagesExpanded: vi.fn() };+ const ipythonChild = { setExpanded: vi.fn(), setAgentMessagesExpanded: vi.fn(), setEditDiffsExpanded: vi.fn() };const messageChild = new AgentMessageComponent({role: "custom",customType: "agent_message",@@ -4266,6 +4267,26 @@ describe("InteractiveMode.setToolsExpanded", () => {expect(ipythonChild.setAgentMessagesExpanded).toHaveBeenLastCalledWith(true);expect(fakeThis.agentMessagesExpanded).toBe(true);});++ test("toggles edit diffs separately from tools and agent messages", () => {+ const child = { setExpanded: vi.fn(), setAgentMessagesExpanded: vi.fn(), setEditDiffsExpanded: vi.fn() };+ const fakeThis = createExpansionFakeThis([child]);++ fakeThis.toggleEditDiffExpansion();++ expect(fakeThis.editDiffsExpanded).toBe(true);+ expect(fakeThis.toolOutputExpanded).toBe(false);+ expect(fakeThis.agentMessagesExpanded).toBe(false);+ expect(child.setEditDiffsExpanded).toHaveBeenCalledWith(true);+ expect(child.setExpanded).toHaveBeenCalledWith(false);+ expect(child.setAgentMessagesExpanded).toHaveBeenCalledWith(false);++ fakeThis.setToolsExpanded(true);++ expect(fakeThis.editDiffsExpanded).toBe(true);+ expect(child.setEditDiffsExpanded).toHaveBeenLastCalledWith(true);+ expect(child.setExpanded).toHaveBeenLastCalledWith(true);+ });});describe("InteractiveMode.createExtensionUIContext setTheme", () => {diff --git a/packages/coding-agent/test/ipython-cell-diff.test.ts b/packages/coding-agent/test/ipython-cell-diff.test.tsindex ce62599882..de525987d7 100644--- a/packages/coding-agent/test/ipython-cell-diff.test.ts+++ b/packages/coding-agent/test/ipython-cell-diff.test.ts@@ -51,6 +51,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,});// Header carries the path (no "edit" label) and the +/- line counts.@@ -67,6 +68,36 @@ describe("IPythonCellComponent diff rendering", () => {expect(out).toContain('await edit(path="sample.py", old_str="gamma", new_str="GAMMA")');});+ it("shows diffs on collapsed cells when edit diffs are expanded", () => {+ const state = {+ code: 'await edit(path="sample.py", old_str="gamma", new_str="GAMMA")\nprint("edit-done-marker")',+ details: {+ status: "ok",+ durationMs: 12,+ result: "'Edited sample.py'",+ stdout: "unrelated stdout line",+ diffs: [{ path: "sample.py", oldStr: "alpha\ngamma\ndelta", newStr: "alpha\nGAMMA\ndelta", startLine: 10 }],+ },+ executionStarted: true,+ argsComplete: true,+ };++ const collapsedWithDiffs = renderCell({ ...state, expanded: false, editDiffsExpanded: true });+ expect(collapsedWithDiffs).toMatch(/11 - .*gamma/);+ expect(collapsedWithDiffs).toMatch(/11 \+ .*GAMMA/);+ // The cell stays collapsed otherwise: no code body beyond the summary preview, no stdout.+ expect(collapsedWithDiffs).not.toContain('print("edit-done-marker")');+ expect(collapsedWithDiffs).not.toContain("unrelated stdout line");++ const collapsed = renderCell({ ...state, expanded: false, editDiffsExpanded: false });+ expect(collapsed).not.toMatch(/11 - .*gamma/);+ expect(collapsed).not.toMatch(/11 \+ .*GAMMA/);++ const expanded = renderCell({ ...state, expanded: true, editDiffsExpanded: false });+ expect(expanded).not.toMatch(/11 - .*gamma/);+ expect(expanded).toContain('print("edit-done-marker")');+ });+it("renders diff rows as full-width colored blocks", () => {const width = 72;const lines = new IPythonCellComponent({@@ -78,6 +109,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).render(width);const diffRows = lines.filter((line) => /alpha|gamma|GAMMA/.test(stripAnsi(line)));expect(diffRows.length).toBeGreaterThan(0);@@ -93,6 +125,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).split("\n");// Summary line and header share the same single-space indent.expect(done[0]).toMatch(/^ ✓ python/);@@ -104,6 +137,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,isError: true,});expect(failed).toMatch(/✗ a\.ts/);@@ -118,6 +152,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,});expect(inside).toContain("src/app.ts");expect(inside).not.toContain(`${cwd}/src/app.ts`);@@ -129,6 +164,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,});expect(outside).toContain("/etc/hosts");});@@ -142,6 +178,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).render(width);// No rendered row may exceed the terminal width (the TUI throws if one does).@@ -163,12 +200,46 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).render(width);expect(lines.every((line) => visibleWidth(line) <= width)).toBe(true);const header = lines.map(stripAnsi).find((line) => line.includes("…"));expect(header).toBeDefined();// The +/- counts survive truncation; only the path is shortened.- expect(header).toMatch(/\+1 -1\s*$/);+ expect(header).toMatch(/\+1 -1/);+ });++ it("advertises the collapse key on the cell header when diffs are expanded", () => {+ const render = (editDiffsExpanded: boolean) =>+ new IPythonCellComponent({+ code: "await edit(...)",+ details: { status: "ok", diffs: [{ path: "a.ts", oldStr: "x", newStr: "X", startLine: 1 }] },+ executionStarted: true,+ argsComplete: true,+ expanded: false,+ editDiffsExpanded,+ }).render(120);+ const header = (lines: string[]) => stripAnsi(lines[0] ?? "");+ // Expanded diffs: the header carries the ctrl+j cue (the summary line is gone).+ expect(header(render(true)).match(/to collapse/g)).toHaveLength(1);+ // Collapsed diffs: no ctrl+j cue on the header (the summary line carries it).+ expect(header(render(false))).not.toContain("to collapse");+ });++ it("never overflows a narrow pane when expanded diffs add the header hint", () => {+ const width = 24;+ const lines = new IPythonCellComponent({+ code: "await edit(...)",+ details: {+ status: "ok",+ diffs: [{ path: "src/some/dir/file.ts", oldStr: "x", newStr: "X", startLine: 1 }],+ },+ executionStarted: true,+ argsComplete: true,+ expanded: true,+ editDiffsExpanded: true,+ }).render(width);+ expect(lines.every((line) => visibleWidth(line) <= width)).toBe(true);});it("renders a large diff without spreading the row array (no RangeError)", () => {@@ -182,6 +253,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).render(80),).not.toThrow();});@@ -194,6 +266,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).split("\n");const addedRows = out.filter((line) => /arg\d/.test(line));expect(addedRows.length).toBeGreaterThan(1);@@ -208,6 +281,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,}).split("\n");expect(out[0]).toContain("to collapse");expect(out[1].trim()).toBe("");@@ -237,7 +311,7 @@ describe("IPythonCellComponent diff rendering", () => {argsComplete: true,};const collapsed = renderCell({ ...state, expanded: false });- const expanded = renderCell({ ...state, expanded: true });+ const expanded = renderCell({ ...state, expanded: true, editDiffsExpanded: true });expect(collapsed).not.toContain("hidden_side_effect");expect(collapsed).toContain("a.py");@@ -267,6 +341,7 @@ describe("IPythonCellComponent diff rendering", () => {const out = renderCell({code: "await edit(...); await edit(...); await edit(...)",expanded: true,+ editDiffsExpanded: true,details: {status: "ok",diffs: [@@ -320,6 +395,7 @@ describe("IPythonCellComponent diff rendering", () => {executionStarted: true,argsComplete: true,expanded: true,+ editDiffsExpanded: true,});expect(out).toContain("a.ts");expect(out).not.toContain("no output");diff --git a/packages/coding-agent/test/tool-execution-component.test.ts b/packages/coding-agent/test/tool-execution-component.test.tsindex f86b284fdd..57688465dd 100644--- a/packages/coding-agent/test/tool-execution-component.test.ts+++ b/packages/coding-agent/test/tool-execution-component.test.ts@@ -1,7 +1,10 @@+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";import { Container, resetCapabilitiesCache, setCapabilities, Text, TUI } from "@earendil-works/pi-tui";import stripAnsi from "strip-ansi";import { Type } from "typebox";-import { beforeAll, describe, expect, test } from "vitest";+import { beforeAll, describe, expect, test, vi } from "vitest";import { VirtualTerminal } from "../../tui/test/virtual-terminal.js";import type { ToolDefinition } from "../src/core/extensions/types.js";import { type BashOperations, createBashTool, createBashToolDefinition } from "../src/core/tools/bash.js";@@ -428,6 +431,79 @@ describe("ToolExecutionComponent parity", () => {expect(rendered.match(/\bedit\b/g)?.length ?? 0).toBe(1);});+ test("shows the built-in edit diff on collapsed tool calls when edit diffs are expanded", () => {+ const component = new ToolExecutionComponent(+ "edit",+ "tool-4e",+ { path: "README.md", oldText: "before", newText: "after" },+ {},+ createEditToolDefinition(process.cwd()),+ createFakeTui(),+ process.cwd(),+ );+ component.updateResult(+ { content: [], details: { diff: "-1 before\n+1 after", firstChangedLine: 1 }, isError: false },+ false,+ );++ const collapsed = stripAnsi(component.render(120).join("\n"));+ expect(collapsed).not.toContain("-1 before");+ expect(collapsed).toContain("+1 -1");+ // The collapsed `╰─ path +N -M` summary line carries the ctrl+j hint —+ // and it is the only carrier: the header must not duplicate it.+ expect(collapsed.split("\n").find((line) => line.includes("╰─"))).toContain("to expand");+ expect(collapsed.split("to expand").length - 1).toBe(1);++ component.setEditDiffsExpanded(true);+ const withDiffs = stripAnsi(component.render(120).join("\n"));+ expect(withDiffs).toContain("-1 before");+ expect(withDiffs).toContain("+1 after");+ expect(withDiffs).not.toContain("+1 -1");++ component.setEditDiffsExpanded(false);+ const collapsedAgain = stripAnsi(component.render(120).join("\n"));+ expect(collapsedAgain).not.toContain("-1 before");+ expect(collapsedAgain).toContain("+1 -1");+ });++ test("keeps the ctrl+j hint on the header while no summary line renders", async () => {+ const dir = mkdtempSync(join(tmpdir(), "edit-hint-"));+ const filePath = join(dir, "sample.txt");+ writeFileSync(filePath, "before\n");+ try {+ const component = new ToolExecutionComponent(+ "edit",+ "tool-4h",+ { path: filePath, oldText: "before", newText: "after" },+ {},+ createEditToolDefinition(dir),+ createFakeTui(),+ dir,+ );+ component.setArgsComplete();+ component.render(120);+ // The preview computes asynchronously; poll until it lands.+ await vi.waitFor(() => {+ expect(stripAnsi(component.render(120).join("\n"))).toContain("to expand");+ });+ // Pre-result: no summary line exists yet, so the header carries the hint.+ const preResult = stripAnsi(component.render(120).join("\n"));+ expect(preResult).not.toContain("╰─");+ expect(preResult.split("to expand").length - 1).toBe(1);++ // Once a successful result lands, the summary line takes over the hint.+ component.updateResult(+ { content: [], details: { diff: "-1 before\n+1 after", firstChangedLine: 1 }, isError: false },+ false,+ );+ const settled = stripAnsi(component.render(120).join("\n"));+ expect(settled.split("\n").find((line) => line.includes("╰─"))).toContain("to expand");+ expect(settled.split("to expand").length - 1).toBe(1);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+test("uses the generic result fallback for legacy-named custom tools", () => {const overrideDefinition: ToolDefinition = {...createBaseToolDefinition("bash"),@@ -694,14 +770,19 @@ describe("ToolExecutionComponent parity", () => {expect(collapsed).not.toMatch(/1 - before/);expect(collapsed).not.toMatch(/1 \+ after/);+ // Tool expansion shows the full source but never the diff; that belongs to ctrl+j.component.setExpanded(true);const expanded = stripAnsi(component.render(120).join("\n"));expect(expanded).toContain('hidden_side_effect = "only in full source"');- expect(expanded).toContain("before");- expect(expanded).toContain("after");- const expandedLines = expanded.split("\n");- expect(expandedLines.findIndex((line) => line.includes("hidden_side_effect ="))).toBeLessThan(- expandedLines.findIndex((line) => /✓ README\.md\s+\+1 -1/.test(line)),+ expect(expanded).toContain("╰─ README.md +1 -1");+ expect(expanded).not.toMatch(/1 - before/);++ component.setEditDiffsExpanded(true);+ const withDiffs = stripAnsi(component.render(120).join("\n"));+ const withDiffLines = withDiffs.split("\n");+ expect(withDiffLines.findIndex((line) => line.includes("hidden_side_effect ="))).toBeLessThan(+ withDiffLines.findIndex((line) => /✓ README\.md\s+\+1 -1/.test(line)),);+ expect(withDiffs).not.toContain("╰─ README.md +1 -1");});});