Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.

Commit 78aae8e

Browse files
authored
refactor(pyright): one more step towards fully strict mode (#86)
1 parent 13e65c4 commit 78aae8e

8 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
dev = [
2929
"inline-snapshot[black]>=0.30.1",
3030
"pyinstaller>=6.16.0",
31-
"pyright>=1.1.406",
31+
"pyright>=1.1.407",
3232
"pytest>=8.4.2",
3333
"pytest-asyncio>=1.2.0",
3434
"ruff>=0.14.1",

‎pyrightconfig.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
"**/__pycache__/**/*.py",
99
],
1010
"strict": [
11+
"src/kimi_cli/prompts",
1112
"src/kimi_cli/soul",
12-
"src/kimi_cli/utils"
13+
// "src/kimi_cli/tools",
14+
// "src/kimi_cli/ui/acp",
15+
"src/kimi_cli/ui/print",
16+
// "src/kimi_cli/ui/shell",
17+
"src/kimi_cli/utils",
18+
"src/kimi_cli/wire",
19+
"src/kimi_cli/*.py",
1320
]
1421
}

‎src/kimi_cli/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async def kimi_run(
6868
stream = ui != "print" # use non-streaming mode only for print UI
6969
llm = create_llm(provider, model, stream=stream, session_id=session.id)
7070

71+
yolo = yolo or (ui == "print") # print mode implies yolo
7172
agent_globals = await AgentGlobals.create(config, llm, session, yolo)
7273
try:
7374
agent = await load_agent_with_mcp(agent_file, agent_globals, mcp_configs or [])
@@ -106,7 +107,6 @@ async def kimi_run(
106107
with contextlib.redirect_stderr(StreamToLogger()):
107108
return await app.run(command)
108109
elif ui == "print":
109-
soul._approval.set_yolo(True) # print mode implies yolo mode
110110
app = PrintApp(
111111
soul,
112112
input_format or "text",

‎src/kimi_cli/cli.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import asyncio
22
import json
33
import sys
4+
from collections.abc import Callable
45
from pathlib import Path
6+
from typing import Any
57

68
import click
79

@@ -85,7 +87,7 @@ class Reload(Exception):
8587
"--print",
8688
"ui",
8789
flag_value="print",
88-
help="Run in print mode. Shortcut for `--ui print`.",
90+
help="Run in print mode. Shortcut for `--ui print`. Note: print mode implicitly adds `--yolo`.",
8991
)
9092
@click.option(
9193
"--acp",
@@ -153,7 +155,11 @@ def kimi(
153155
yolo: bool,
154156
):
155157
"""Kimi, your next CLI agent."""
156-
echo = click.echo if verbose else lambda *args, **kwargs: None
158+
159+
def _noop_echo(*args: Any, **kwargs: Any):
160+
pass
161+
162+
echo: Callable[..., None] = click.echo if verbose else _noop_echo
157163

158164
logger.add(
159165
get_share_dir() / "logs" / "kimi.log",

‎src/kimi_cli/metadata.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def sessions_dir(self) -> Path:
3333
class Metadata(BaseModel):
3434
"""Kimi metadata structure."""
3535

36-
work_dirs: list[WorkDirMeta] = Field(default_factory=list, description="Work directory list")
36+
work_dirs: list[WorkDirMeta] = Field(
37+
default_factory=list[WorkDirMeta], description="Work directory list"
38+
)
3739

3840

3941
def _load_metadata() -> Metadata:

‎src/kimi_cli/ui/print/__init__.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ async def _visualize_text(self, wire: WireUISide):
138138

139139
async def _visualize_stream_json(self, wire: WireUISide, start_position: int):
140140
# TODO: be aware of context compaction
141+
# FIXME: this is only a temporary impl, may miss the last lines of the context file
142+
if not self.context_file.exists():
143+
self.context_file.touch()
141144
try:
142145
async with aiofiles.open(self.context_file, encoding="utf-8") as f:
143146
await f.seek(start_position)
144147
while True:
145148
should_end = False
146-
while wire._queue.qsize() > 0:
147-
msg = wire._queue.get_nowait()
149+
while (msg := wire.receive_nowait()) is not None:
148150
if isinstance(msg, StepInterrupted):
149151
should_end = True
150152

‎src/kimi_cli/wire/__init__.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ async def receive(self) -> WireMessage:
5555
if not isinstance(msg, ContentPart | ToolCallPart):
5656
logger.debug("Receiving wire message: {msg}", msg=msg)
5757
return msg
58+
59+
def receive_nowait(self) -> WireMessage | None:
60+
"""
61+
Try receive a message without waiting. If no message is available, return None.
62+
"""
63+
try:
64+
msg = self._queue.get_nowait()
65+
except asyncio.QueueEmpty:
66+
return None
67+
if not isinstance(msg, ContentPart | ToolCallPart):
68+
logger.debug("Receiving wire message: {msg}", msg=msg)
69+
return msg

‎uv.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)