Skip to content

Commit b0cd9db

Browse files
committed
format
1 parent 96dada3 commit b0cd9db

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/kimi_cli/ui/shell/prompt.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ def toast(message: str, duration: float = 5.0) -> None:
394394
_toast_queue.put_nowait((message, duration))
395395

396396

397+
# Matches both image and text placeholders:
398+
# [image:id,640x480] or [text:id,60 lines]
397399
_ATTACHMENT_PLACEHOLDER_RE = re.compile(
398400
r"\[(?P<type>image|text):(?P<id>[a-zA-Z0-9_\-\.]+)"
399401
r"(?:,(?P<width>\d+)x(?P<height>\d+)|,(?P<line_count>\d+) lines)?\]"
@@ -474,10 +476,7 @@ def _delete_placeholder_at_cursor(buff, is_backspace: bool) -> bool:
474476

475477
# Backspace: delete if cursor is inside OR right after placeholder
476478
# Delete: delete if cursor is inside OR right before placeholder
477-
if is_backspace:
478-
should_delete = start < cursor <= end
479-
else:
480-
should_delete = start <= cursor < end
479+
should_delete = start < cursor <= end if is_backspace else start <= cursor < end
481480

482481
if should_delete:
483482
attachment_id = match.group("id")
@@ -490,14 +489,14 @@ def _delete_placeholder_at_cursor(buff, is_backspace: bool) -> bool:
490489

491490
@_kb.add("backspace", eager=True)
492491
def _smart_backspace(event: KeyPressEvent) -> None:
493-
"""Delete entire placeholder if cursor is within/after one, otherwise backspace normally."""
492+
"""Delete entire placeholder if cursor is within/after one, else backspace normally."""
494493
if not _delete_placeholder_at_cursor(event.current_buffer, is_backspace=True):
495494
event.current_buffer.delete_before_cursor(1)
496495
self._last_buffer_text = event.current_buffer.text
497496

498497
@_kb.add("delete", eager=True)
499498
def _smart_delete(event: KeyPressEvent) -> None:
500-
"""Delete entire placeholder if cursor is within/before one, otherwise delete normally."""
499+
"""Delete entire placeholder if cursor is within/before one, else delete normally."""
501500
if not _delete_placeholder_at_cursor(event.current_buffer, is_backspace=False):
502501
event.current_buffer.delete(1)
503502
self._last_buffer_text = event.current_buffer.text
@@ -663,8 +662,8 @@ def _check_and_replace_large_paste(self, buffer) -> None:
663662
if not current_text.startswith(previous_text):
664663
return
665664

666-
inserted_text = current_text[len(previous_text):]
667-
inserted_line_count = inserted_text.count('\n') + 1
665+
inserted_text = current_text[len(previous_text) :]
666+
inserted_line_count = inserted_text.count("\n") + 1
668667

669668
if inserted_line_count <= LARGE_PASTE_LINE_THRESHOLD:
670669
return

src/kimi_cli/ui/shell/replay.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ async def replay_recent_history(history: Sequence[Message]) -> None:
4242
for run in runs:
4343
wire = Wire()
4444
console.print(
45-
f"{getpass.getuser()}{PROMPT_SYMBOL} {message_stringify(run.user_message, context='replay')}"
45+
f"{getpass.getuser()}{PROMPT_SYMBOL} "
46+
f"{message_stringify(run.user_message, context='replay')}"
4647
)
4748
ui_task = asyncio.create_task(
4849
visualize(wire.ui_side, initial_status=StatusSnapshot(context_usage=0.0))

src/kimi_cli/utils/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _maybe_collapse(text: str) -> str:
1818
"""Collapse text if it exceeds threshold (except in replay context)."""
1919
if context == "replay":
2020
return text
21-
line_count = text.count('\n') + 1
21+
line_count = text.count("\n") + 1
2222
if line_count > LARGE_PASTE_LINE_THRESHOLD:
2323
return f"[pasted {line_count} lines]"
2424
return text

tests/test_message_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def test_extract_text_from_empty_string():
103103
assert result == ""
104104

105105

106-
# New tests for large paste collapse feature
107106
def test_stringify_collapses_large_text_by_default():
108107
"""Test that large text is collapsed in default context."""
109108
large_text = "\n".join(["line"] * 60)

tests/test_prompt_placeholders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import re
44

5-
from kimi_cli.utils.message import LARGE_PASTE_LINE_THRESHOLD
6-
75
# The regex pattern from prompt.py
86
_ATTACHMENT_PLACEHOLDER_RE = re.compile(
97
r"\[(?P<type>image|text):(?P<id>[a-zA-Z0-9_\-\.]+)"
@@ -18,6 +16,7 @@ def test_backspace_boundary_conditions(self):
1816
"""Test backspace deletes when cursor is after placeholder, not before."""
1917
text = "prefix [text:abc12345,60 lines]"
2018
match = _ATTACHMENT_PLACEHOLDER_RE.search(text)
19+
assert match is not None
2120
start, end = match.span()
2221

2322
# Backspace with cursor right after placeholder should delete (the bug fix)
@@ -34,6 +33,7 @@ def test_delete_boundary_conditions(self):
3433
"""Test delete key deletes when cursor is before placeholder, not after."""
3534
text = "prefix [text:abc12345,60 lines]"
3635
match = _ATTACHMENT_PLACEHOLDER_RE.search(text)
36+
assert match is not None
3737
start, end = match.span()
3838

3939
# Delete with cursor before placeholder should delete

0 commit comments

Comments
 (0)