Skip to content

fix(approval): show file content/diff and open full-screen preview on ctrl+e - #139

Merged
liruifengv merged 3 commits into
mainfrom
fix-write-approve
May 28, 2026
Merged

fix(approval): show file content/diff and open full-screen preview on ctrl+e#139
liruifengv merged 3 commits into
mainfrom
fix-write-approve

Conversation

@liruifengv

@liruifengv liruifengv commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

fix #132

Problem

After the recent permission decision policies rework, the Write and Edit input display was reduced to {kind: 'file_io', operation, path}, dropping the args the previous generic-fallback path carried. The approval prompt could then only show the path — no file content for Write, no diff hunk for Edit — and ctrl+e expanded to the same one-liner.

Even with the data restored, pressing ctrl+e on a non-trivial Edit / Write inflated the panel past one viewport. That collided with the TUI's inline differential renderer and the terminal's default "snap to bottom on stdout" behavior: scrolling back glitched, the screen flickered, and the only stable position was the very bottom. Worse, the diff was recomputed with an O(m·n) LCS DP every frame the panel was visible, so each spinner tick paid the cost again.

What changed

Restore content on the data side: extend the file_io input display with optional content / before / after. Write attaches its full content and Edit attaches its old_string/new_string; the adapter promotes these into the file_content / diff display blocks the panel already knows how to render, matching what the old generic-fallback path produced.

Replace inline expand on the UI side: ctrl+e now hands off to a dedicated full-screen viewer (modeled after the task output viewer). The viewer builds its body lines once at construction and slices them on scroll, so per-frame cost stays O(viewport) regardless of payload size. The approval panel keeps its compact cluster view and forwards ctrl+e to the host, falling through to the existing plan-expand toggle when there is nothing to preview. The panel instance is preserved across open/close so selection and feedback state survive.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

After #26 the WriteTool/EditTool input display was reduced to
`{kind: 'file_io', operation, path}`, dropping the args carried by the
previous generic fallback. The approval panel then only had a path to
show — no file content for Write, no diff hunk for Edit — and ctrl+e
expanded to the same one-liner.

Extend the file_io display with optional `content` / `before` / `after`
fields so Write can attach its full content and Edit can attach its
old_string/new_string hunk. The adapter promotes file_io+content to a
file_content block and file_io+before/after to a diff block, matching
what the panel renders for the legacy generic-fallback path.
Inline ctrl+e expand-in-place inflated the approval panel past one
viewport for any non-trivial Edit / Write, which collided with pi-tui's
inline differential renderer and the terminal's "snap to bottom on
stdout" reflex: scrolling back glitched and the screen flickered. On
top of that, the diff renderer's O(m·n) LCS DP ran every frame the
panel was visible, so each spinner tick re-paid the cost.

Make ctrl+e hand off to a dedicated full-screen viewer instead. The
viewer renders all body lines once at construction and slices them on
scroll, so per-frame cost is O(viewport) regardless of payload size.
It uses the same nested-takeover pattern as TaskOutputViewer; the
approval panel instance is preserved and refocused on close so the
selection / feedback state survives.

The panel itself drops its local `expanded` toggle and always renders
the compact cluster view; ctrl+e now exclusively forwards to the host
when there is something to preview, and falls through to the existing
plan-expand toggle otherwise.
@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4530d43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented May 28, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@4530d43
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4530d43

commit: 4530d43

@liruifengv
liruifengv merged commit 50251a1 into main May 28, 2026
8 checks passed
@liruifengv
liruifengv deleted the fix-write-approve branch May 28, 2026 05:22
@github-actions github-actions Bot mentioned this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write审核时缺失完整修改内容的预览功能

1 participant