-
Notifications
You must be signed in to change notification settings - Fork 306
refactor: enable Pyright strict type checking for kimi_cli/ui/shell #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…Pyright strict mode requirements - Add public run_soul_command() method in ShellApp - Update metacmd to use public interface instead of protected _run_soul_command()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the codebase to expose private attributes through public properties, improving encapsulation and enabling strict type checking with Pyright. The changes convert direct access of private attributes (prefixed with _) to use public property accessors instead.
Key changes:
- Added public properties (
agent,runtime,context,file_backend) to expose private attributes inKimiSoulandContextclasses - Updated all callsites to use the new public properties instead of accessing private attributes directly
- Enabled strict type checking for the
src/kimi_cli/ui/shelldirectory in Pyright configuration - Added explicit type annotations where needed for type checker compliance
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/kimi_cli/soul/kimisoul.py | Added agent and runtime properties to expose _agent and _runtime private attributes |
| src/kimi_cli/soul/context.py | Added file_backend property to expose _file_backend private attribute |
| src/kimi_cli/ui/shell/init.py | Added public run_soul_command method that delegates to private _run_soul_command |
| src/kimi_cli/ui/shell/metacmd.py | Updated to use new public properties; cleaned up import noqa comments |
| src/kimi_cli/ui/shell/debug.py | Updated to use new public properties; added explicit type annotation for content_items |
| src/kimi_cli/ui/shell/setup.py | Added explicit type annotation for session variable |
| pyrightconfig.json | Enabled type checking for entire src/kimi_cli/ui/shell directory |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/kimi_cli/soul/kimisoul.py
Outdated
| @property | ||
| def agent(self) -> Agent: | ||
| return self._agent | ||
|
|
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace found on line 101. Remove the trailing whitespace after the property definition to maintain code cleanliness.
|
|
||
|
|
||
| async def run_soul_command(self, user_input: str | list[ContentPart]) -> bool: | ||
| """public method to run soul command.""" |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring 'public method to run soul command.' should follow PEP 257 conventions. It should start with a capital letter and provide more detail about the method's purpose, parameters, and return value. Consider: 'Run a soul command with the given user input. Returns True if successful, False otherwise.'
| """public method to run soul command.""" | |
| """ | |
| Run a soul command with the given user input. | |
| Args: | |
| user_input (str | list[ContentPart]): The user input to process. | |
| Returns: | |
| bool: True if the command was successful, False otherwise. | |
| """ |
- Add type parameters to generic types (Task[None]) - Add type hints for method parameters and returns - Add # pyright: ignore annotations for decorator patterns"
| @meta_command(kimi_soul_only=True) | ||
| async def compact(app: "ShellApp", args: list[str]): | ||
| """Compact the context""" | ||
| assert isinstance(app.soul, KimiSoul) | ||
|
|
||
| if app.soul._context.n_checkpoints == 0: | ||
| if app.soul.context.n_checkpoints == 0: | ||
| console.print("[yellow]Context is empty.[/yellow]") | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm planning to move all kimi-soul-only meta commands into kimisoul, which means to introduce soul-level meta commands. Will delay this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it seems I don't have bandwidth to design soul-level meta commands in recent week. What about let's enable strict mode for all shell files except metacmd.py in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
#168
Summary
Enable Pyright strict type checking for the shell UI and soul modules by:
PromptSession[str],asyncio.Task[None])reportPrivateUsagechecksChanges
Commit 1: Type Annotations
src/kimi_cli/ui/shell/directory in pyrightconfig.json__all__export list in metacmd.py to resolve import warningsCommit 2: Public Interfaces
KimiSoul:agent,runtimeContext:file_backendShellApp:run_soul_command()