Skip to content

Conversation

@2725244134
Copy link
Contributor

@2725244134 2725244134 commented Nov 6, 2025

#168

Summary

Enable Pyright strict type checking for the shell UI and soul modules by:

  1. Adding explicit type annotations (e.g., PromptSession[str], asyncio.Task[None])
  2. Creating public interfaces for protected members to satisfy reportPrivateUsage checks

Changes

Commit 1: Type Annotations

  • Enable strict type checking for src/kimi_cli/ui/shell/ directory in pyrightconfig.json
  • Add explicit type parameters to generic types
  • Add __all__ export list in metacmd.py to resolve import warnings

Commit 2: Public Interfaces

  • Add public properties to KimiSoul: agent, runtime
  • Add public property to Context: file_backend
  • Add public method to ShellApp: run_soul_command()
  • Update all usages to use public interfaces instead of protected members

…Pyright strict mode requirements

- Add public run_soul_command() method in ShellApp
- Update metacmd to use public interface instead of protected _run_soul_command()
Copilot AI review requested due to automatic review settings November 6, 2025 13:54
Copy link
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

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 in KimiSoul and Context classes
  • 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/shell directory 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.

@property
def agent(self) -> Agent:
return self._agent

Copy link

Copilot AI Nov 6, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.


async def run_soul_command(self, user_input: str | list[ContentPart]) -> bool:
"""public method to run soul command."""
Copy link

Copilot AI Nov 6, 2025

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.'

Suggested change
"""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.
"""

Copilot uses AI. Check for mistakes.
- Add type parameters to generic types (Task[None])
- Add type hints for method parameters and returns
- Add # pyright: ignore annotations for decorator patterns"
Comment on lines 243 to 250
@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
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get it

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

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.

2 participants