Skip to content

fix(shell): approval request text input should render caret correctly#2005

Merged
wbxl2000 merged 9 commits intoMoonshotAI:mainfrom
kermanx:fix/ApprovalRequestPanel
Apr 23, 2026
Merged

fix(shell): approval request text input should render caret correctly#2005
wbxl2000 merged 9 commits intoMoonshotAI:mainfrom
kermanx:fix/ApprovalRequestPanel

Conversation

@kermanx
Copy link
Copy Markdown
Contributor

@kermanx kermanx commented Apr 22, 2026

Related Issue

img_v3_02110_b1e98c4b-2bd0-4dbb-8c12-44428057d30g

Description

as title.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

Copilot AI review requested due to automatic review settings April 22, 2026 12:31
Signed-off-by: _Kerman <kermanx@qq.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes caret rendering for the shell’s approval-request inline feedback input so the “block cursor” appears at the actual cursor position (using reverse-video on the character under the cursor when mid-line), aligning the visual behavior with typical terminal cursors.

Changes:

  • Render inline feedback with a cursor-aware display (reverse-video at cursor, trailing block only at EOL).
  • Plumb cursor position from the prompt buffer into the approval panel rendering.
  • Add tests covering cursor-in-middle vs cursor-at-end rendering; update changelog entries.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/ui_and_conv/test_visualize_running_prompt.py Updates the delegate helper to provide (text, cursor) and adds assertions for reverse-video vs trailing block cursor behavior.
src/kimi_cli/ui/shell/visualize/_approval_panel.py Introduces cursor-aware rendering helper and threads cursor info through ApprovalRequestPanel.render() and ApprovalPromptDelegate.
src/kimi_cli/ui/shell/init.py Provides a default (text, cursor) provider from the prompt buffer for the approval modal.
docs/zh/release-notes/changelog.md Adds a Chinese changelog entry describing the cursor rendering fix.
docs/en/release-notes/changelog.md Adds the English changelog entry for the cursor rendering fix.
CHANGELOG.md Adds the root changelog entry for the cursor rendering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 345 to 352
def __init__(
self,
request: ApprovalRequest,
*,
on_response: Callable[[ApprovalRequest, ApprovalResponse.Kind, str], None],
buffer_text_provider: Callable[[], str] | None = None,
buffer_text_provider: Callable[[], tuple[str, int]] | None = None,
text_expander: Callable[[str], str] | None = None,
) -> None:
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApprovalPromptDelegate is re-exported as a public name (see ui/shell/visualize/__init__.py), but this change makes buffer_text_provider a breaking API change (callers previously returning str will now cause an unpacking error in render_running_prompt_body). Consider keeping backward compatibility by accepting both Callable[[], str] and Callable[[], tuple[str, int]] (or adding a new optional cursor provider) and normalizing the return value internally.

Copilot uses AI. Check for mistakes.
@kermanx
Copy link
Copy Markdown
Contributor Author

kermanx commented Apr 22, 2026

@codex

@kermanx kermanx closed this Apr 22, 2026
@kermanx kermanx reopened this Apr 22, 2026
@kermanx
Copy link
Copy Markdown
Contributor Author

kermanx commented Apr 22, 2026

@codex

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Signed-off-by: _Kerman <kermanx@qq.com>
@wbxl2000
Copy link
Copy Markdown
Collaborator

wbxl2000 commented Apr 23, 2026

补充一个跨平台信息:这个 bug 不仅在 Linux/Windows 上存在,Mac 上同样会复现——它是 app 层渲染逻辑问题(之前 被硬编码在行尾),跟终端实现无关。Mac 上的 Terminal.app / iTerm2 / Ghostty / Alacritty 都会出现光标块固定在行尾的现象。

修复用的 ANSI reverse video (SGR 7) 和 Unicode (U+2588) 在 Mac 所有主流终端里都原生支持,不会有兼容性问题。


Adding cross-platform information: This bug not only exists on Linux/Windows, but also on Mac - it is an app layer rendering logic problem (previously was hard-coded at the end of the line) and has nothing to do with the terminal implementation. Terminal.app / iTerm2 / Ghostty / Alacritty on Mac will have the cursor block fixed at the end of the line.

The ANSI reverse video (SGR 7) and Unicode (U+2588) used for repair are natively supported in all mainstream Mac terminals, and there will be no compatibility issues.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 382c93f254

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +53 to +55
at_cursor = escape(text[cursor])
after = escape(text[cursor + 1 :])
return f"{before}[reverse]{at_cursor}[/reverse]{after}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape backslash before wrapping cursor glyph in reverse markup

When the cursor sits on a backslash character (e.g. feedback like C:\temp), escape(text[cursor]) leaves \ unchanged, so the generated snippet becomes ...[reverse]\[/reverse].... In Rich markup, that \[ escapes the closing tag, which turns [/reverse] into literal text and leaves reverse styling open for the rest of the line. This regresses rendering for common inputs containing backslashes and makes the inline approval prompt display corrupted cursor/text state.

Useful? React with 👍 / 👎.

@kermanx
Copy link
Copy Markdown
Contributor Author

kermanx commented Apr 23, 2026

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 606d3236e9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

from kimi_cli.ui.shell.visualize._approval_panel import _render_feedback_with_cursor

# Cursor at position 2 ("he|llo world" — on the first 'l').
assert _render_feedback_with_cursor("hello world", 2) == "he[reverse]l[/reverse]lo world"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Compare cursor helper output as Text objects

_render_feedback_with_cursor now returns a rich.text.Text instance, but this test compares it to markup/plain strings, which will evaluate false (Text.__eq__ only handles Text). As a result, the new cursor tests fail even when rendering is correct, which can block CI and mask real regressions; assertions should inspect Text.plain / spans (or compare against Text(...)) instead of string literals with markup tags.

Useful? React with 👍 / 👎.

devin-ai-integration[bot]

This comment was marked as resolved.

@wbxl2000
Copy link
Copy Markdown
Collaborator

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000 wbxl2000 merged commit 248463c into MoonshotAI:main Apr 23, 2026
15 checks passed
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.

3 participants