fix(coding-agent): stabilize edit diff previews closes #3134

This commit is contained in:
Mario Zechner
2026-04-15 23:08:23 +02:00
parent ae6d493fcb
commit f7cd613ee4
6 changed files with 332 additions and 35 deletions

View File

@@ -1763,7 +1763,25 @@ export default function (pi: ExtensionAPI) {
Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
Tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
By default, tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
Set `renderShell: "self"` when the tool should render its own shell instead of using the default `Box`. This is useful for tools that need complete control over framing or background behavior, for example large previews that must stay visually stable after the tool settles.
```typescript
pi.registerTool({
name: "my_tool",
label: "My Tool",
description: "Custom shell example",
parameters: Type.Object({}),
renderShell: "self",
async execute() {
return { content: [{ type: "text", text: "ok" }], details: undefined };
},
renderCall(args, theme, context) {
return new Text(theme.fg("accent", "my custom shell"), 0, 0);
},
});
```
`renderCall` and `renderResult` each receive a `context` object with:
- `args` - the current tool call arguments
@@ -1850,7 +1868,7 @@ Custom editors and `ctx.ui.custom()` components receive `keybindings: Keybinding
#### Best Practices
- Use `Text` with padding `(0, 0)`. The Box handles padding.
- Use `Text` with padding `(0, 0)`. The default Box handles padding.
- Use `\n` for multi-line content.
- Handle `isPartial` for streaming progress.
- Support `expanded` for detail on demand.
@@ -1858,6 +1876,7 @@ Custom editors and `ctx.ui.custom()` components receive `keybindings: Keybinding
- Read `context.args` in `renderResult` instead of copying args into `context.state`.
- Use `context.state` only for data that must be shared across call and result slots.
- Reuse `context.lastComponent` when the same component instance can be updated in place.
- Use `renderShell: "self"` only when the default boxed shell gets in the way. In self-shell mode the tool is responsible for its own framing, padding, and background.
#### Fallback