feat(shell): enhance slash command completer and menu functionality#1431
feat(shell): enhance slash command completer and menu functionality#1431
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the interactive shell UX around slash commands by tightening when slash completion triggers, ensuring canonical command names are inserted/displayed, and rendering a custom full-width completions menu consistent with the shell styling.
Changes:
- Add
SlashCommandCompleter.should_complete()to restrict completion to the “root” slash token and use canonical/namefor inserted/displayed completions. - Introduce
SlashCommandMenuControlplus wrapping/truncation helpers to render a custom completions menu with optional expanded metadata lines. - Expand test coverage for slash completion activation rules, canonical display, wrapping/truncation behavior, and menu rendering when no item is selected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/kimi_cli/ui/shell/prompt.py |
Adds stricter slash completion gating and a custom prompt-toolkit menu control/float for slash completions. |
tests/ui_and_conv/test_slash_completer.py |
Adds new unit tests covering the updated completion logic and menu rendering helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| getattr(app.current_buffer, "complete_state", None) if app is not None else None | ||
| ) | ||
| if complete_state is None or not complete_state.completions: | ||
| return UIContent() |
| if isinstance(container.alternative_content, FloatContainer): | ||
| return container.alternative_content |
There was a problem hiding this comment.
🟡 _extract_float_container accesses non-existent alternative_content attribute on ConditionalContainer
ConditionalContainer from prompt_toolkit does not have an alternative_content attribute (confirmed with prompt_toolkit 3.0.28). If _extract_float_container encounters a ConditionalContainer whose .content is not a FloatContainer, the code at line 263 will crash with AttributeError: 'ConditionalContainer' object has no attribute 'alternative_content'. While currently unreachable in the default prompt_toolkit layout (the FloatContainer is found as child[0] of the HSplit), any layout change (e.g., a future prompt_toolkit version reordering children) would trigger the crash during prompt session initialization. The corresponding test test_find_prompt_float_container_supports_conditional_container_shape also fails with TypeError because ConditionalContainer.__init__() does not accept alternative_content as a keyword argument.
Prompt for agents
In src/kimi_cli/ui/shell/prompt.py lines 257-265, the _extract_float_container function references container.alternative_content on a ConditionalContainer, but prompt_toolkit's ConditionalContainer has no such attribute. Remove lines 263-264 (the alternative_content check) since ConditionalContainer only has a .content attribute. If you need to handle nested containers, recursively check child containers instead. Also fix the test in tests/ui_and_conv/test_slash_completer.py at line 159-171: test_find_prompt_float_container_supports_conditional_container_shape passes alternative_content= to ConditionalContainer which raises TypeError. Either remove this test or restructure it to test a valid ConditionalContainer layout (e.g., a ConditionalContainer whose .content IS a FloatContainer).
Was this helpful? React with 👍 or 👎 to provide feedback.
Description
Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.