feat: add pi-toolview — compact tool output display - #11
Open
smarzban wants to merge 11 commits into
Open
Conversation
Replaces pi's verbose built-in tool rendering with one-line summaries, expandable on demand (ctrl+o). Execution delegates to originals so the LLM still sees complete output. Features: - Smart paths: relative inside cwd, ~/ under HOME, absolute otherwise - Bash timing: parses duration from raw output (✓ · 42 lines · 12.3s) - Write file size: byte count for sanity checks (156 lines · 4.2 KB) - Error emphasis: ✗ prefix with red for exit codes and error keywords - Edit context hint: extracts enclosing function/class from diff - /toolview command: toggle on/off globally or per-tool, persisted - Falls back to original verbose rendering when disabled
Timing: pi never puts duration in the output text; the built-in tracks it
via render state. Now uses the same context.state startedAt/endedAt
mechanism, so durations actually show (e.g. '· 12.3s').
Errors: non-zero exits arrive as isError results with a status suffix,
not 'exit code:' in text. Switch bash/read/edit/write to context.isError
and parse the real status line ('Command exited with code N').
Truncation markers: match pi's actual suffixes ([Showing lines X-Y...],
Command aborted/timed out) instead of made-up ones.
Command clip: keep head + tail with middle ellipsis so long env
assignments or 'cd /long/path &&' prefixes don't hide the real command.
Also: find shows '0 results' for no-match, grep/ls/read fallbacks pass
the real render context.
Switch all 7 tools to renderShell: 'self', dropping the default Box's paddingY (one blank line top + bottom of each pill). Re-apply the success/error/pending background color manually on each row so blocks stay colored but sit tighter together. Pi hardcodes a Spacer(1) above every tool block in the component constructor, so one separator line between blocks remains and cannot be removed by an extension.
Two related fixes: Instant toggle (no reload): pi caches already-rendered tool blocks, so a toggle only affected newly-rendered tools. The handler now calls ctx.ui.setToolsExpanded(getToolsExpanded()) after each state change, which re-runs renderCall/renderResult on every existing block. Toggling applies immediately. Original spacing when off: revert renderShell:'self' back to the default tool Box. The self shell dropped the pill padding but also meant turning toolview off rendered the original content in the tight frame instead of the native box. With the default shell, off restores pi's exact original look. Trade-off: 'on' uses the standard pill padding rather than the extra tight self shell.
Re-apply renderShell:'self' on all 7 tools to drop the pill padding for the tight look, with the success/error/pending background re-applied manually. Keeps the instant-toggle refresh() so /toolview applies without a reload. Trade-off noted: with the self shell, turning a tool off renders the original content in the tight frame rather than the native pill.
The off path called originals.X.renderCall, but createXTool returns an AgentTool whose wrapToolDefinition drops renderCall/renderResult, so the delegation threw 'renderCall is not a function' and pi silently fell back to the bare tool name. Turning a tool off appeared to do nothing. Use createXToolDefinition (which carries renderCall/renderResult) for the off-fallback. Execution/description/parameters still come from the AgentTool. Verified all 7 definitions expose both renderers.
… tools The native bash/read/grep/find/ls renderers reuse context.lastComponent and call container methods on it (.clear/.addChild). After a compact render that slot holds toolview's plain Text, so the off-fallback threw 'component.clear is not a function' and pi fell back to the bare tool name. Only edit survived because it is self-shell native and builds fresh components. Clear context.lastComponent before each off delegation so the native renderer constructs a fresh component. Verified bash/grep/find/ls now render original output; read/write/edit follow their native collapsed/expanded behavior.
The native per-tool renderResult functions are built for the Box shell and render with no background or padding when drawn in the tight self frame, so toggled-off tools hugged the left edge (read most visibly, since its content is indented). Verified all seven native renderers lose their pill bg in the self container. Stop delegating off-mode to the native renderers. Each tool now draws its full result content through the same row() pill (bg + padding): bash/grep/find/ls output, read file content, write message, and edit's colored diff. Drop the createXToolDefinition renderers and lastComponent clearing they required. Compact (on) rendering is unchanged.
/toolview on only set enabled=true, leaving per-tool false entries in state.tools, and isOn() checks both. So tools toggled off individually stayed off after /toolview on. Both on and off now reset the per-tool map so the global toggle is a true 'everything' toggle.
The on/off verbs were confusing since toolview itself is always active; the toggle is between compact summaries and full output. compact/full are now the primary verbs; on/off remain as aliases for compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces pi's verbose built-in tool rendering with one-line summaries, expandable on demand (
ctrl+o). Execution fully delegates to the originals, so the LLM still sees complete output.Features
src/utils.tsinside project,~/code/file.tsunder HOME, absolute otherwise✓ · 42 lines · 12.3s— duration parsed from raw output(156 lines · 4.2 KB)— catch accidental huge writes✗ exit 1in red — also detects error keywords in output+12 / -4 in parseConfig— enclosing function from diff/toolview bash off— that tool reverts to verbose originalCommands
/toolview— show status ·/toolview off— all verbose ·/toolview <tool> off— one tool verbose · state persists in~/.pi/agent/toolview.jsonBefore / after
Default pi shows full tool output inline — every line of bash, every file read, full diffs.
With pi-toolview:
Design notes
execute()delegates to originalcreate*Tool(cwd)— onlyrenderCall/renderResultare customresult.content; session state untouched/toolview