feat: list turn-written files under each reply and open HTML in preview - #378
Open
thy950523 wants to merge 4 commits into
Open
feat: list turn-written files under each reply and open HTML in preview#378thy950523 wants to merge 4 commits into
thy950523 wants to merge 4 commits into
Conversation
extractTurnWrittenFiles collects the distinct files an assistant turn wrote, keeping only write/edit tool calls whose result arrived and did not error, resolving each path against cwd and deduping by absolute path. The tool call is the evidence that a file was written. A path the assistant merely mentions in its reply is not, so the reply text is never scanned; tests cover that case explicitly. lib/tool-names.ts holds the write/edit name predicates so this and the chat views stay in agreement. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Renders one button per file, labelled with the basename and titled with the full path, opening the file in the preview pane on click. Labels are localized in en and zh-CN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Session preprocessing gives each tool call its own assistant entry, so the final answer alone has no record of what the turn wrote. ChatWindow aggregates the turn's assistant blocks, derives the file list, and passes it to MessageView, which renders the row below the reply. MessageView also drops its local isEditToolName in favour of the shared predicate in lib/tool-names.ts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A generated page is usually more useful viewed than read as source, so HTML now defaults to preview like markdown. Both already had a preview mode; the source tab stays one click away. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
thy950523
marked this pull request as ready for review
August 4, 2026 08:02
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
When the agent writes files during a turn (generated reports, HTML pages, edited source), there is no easy way to open them from the chat. The reply usually omits the path, and even when a path appears it is plain text — nothing to click. The user has to switch to the file browser and locate the file manually.
This PR adds two things so that produced files are one click away:
write/edittool calls, shown under the final reply. Works even when the reply never names the file. The file list is derived entirely from tool calls; the reply text is never scanned..htmlfiles open in rendered-preview mode (live page via the existing preview pane), matching how markdown is already handled. Source view remains one click away.Changes
New:
lib/turn-written-files.ts—extractTurnWrittenFiles(content, toolResults, cwd): walks the turn's tool-call blocks, keepswrite/editcalls whose result arrived without error, resolves paths againstcwd, deduplicates in first-seen order.lib/tool-names.ts—isWriteToolName/isEditToolNamepredicates; recognizes Pi's built-in plain names plus common MCP-namespaced forms (mcp__server__write,str_replace,replace_editor).components/TurnWrittenFiles.tsx— leaf component: one<button>per file → the existing preview path.lib/turn-written-files.test.mjs+components/TurnWrittenFiles.test.mjs— 14 focused unit tests.Edited:
components/ChatWindow.tsx— aggregate the turn's assistant blocks before rendering the final reply and pass the derived file list through (Pi stores each tool call as its own entry, so the extractor must see the whole turn).components/MessageView.tsx— thread awrittenFilesprop to the assistant view; renderTurnWrittenFilesunder the reply.components/FileViewer.tsx— one-clause change: treathtmlalongsidemarkdownin the preview-by-default branch.lib/i18n/messages/{en,zh-CN}.ts— two new strings.Net: 10 files, +332 / −15.
Testing
node --test lib/turn-written-files.test.mjs components/TurnWrittenFiles.test.mjs— 14/14 pass.ScreenShot