kimi-cli 0.43__py3-none-any.whl → 0.44__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kimi-cli might be problematic. Click here for more details.
- kimi_cli/CHANGELOG.md +10 -0
- kimi_cli/__init__.py +0 -192
- kimi_cli/app.py +195 -0
- kimi_cli/cli.py +6 -5
- kimi_cli/llm.py +6 -3
- kimi_cli/soul/agent.py +4 -2
- kimi_cli/soul/runtime.py +6 -4
- kimi_cli/ui/print/__init__.py +1 -4
- kimi_cli/ui/shell/prompt.py +1 -0
- kimi_cli/ui/shell/setup.py +1 -1
- {kimi_cli-0.43.dist-info → kimi_cli-0.44.dist-info}/METADATA +1 -1
- {kimi_cli-0.43.dist-info → kimi_cli-0.44.dist-info}/RECORD +14 -13
- {kimi_cli-0.43.dist-info → kimi_cli-0.44.dist-info}/WHEEL +0 -0
- {kimi_cli-0.43.dist-info → kimi_cli-0.44.dist-info}/entry_points.txt +0 -0
kimi_cli/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,16 @@ Internal builds may append content to the Unreleased section.
|
|
|
9
9
|
Only write entries that are worth mentioning to users.
|
|
10
10
|
-->
|
|
11
11
|
|
|
12
|
+
## [0.44] - 2025-10-30
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Improve startup time
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Fix potential invalid bytes in user input
|
|
21
|
+
|
|
12
22
|
## [0.43] - 2025-10-30
|
|
13
23
|
|
|
14
24
|
### Added
|
kimi_cli/__init__.py
CHANGED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import contextlib
|
|
2
|
-
import os
|
|
3
|
-
import warnings
|
|
4
|
-
from collections.abc import Generator
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
from pydantic import SecretStr
|
|
9
|
-
|
|
10
|
-
from kimi_cli.agentspec import DEFAULT_AGENT_FILE
|
|
11
|
-
from kimi_cli.config import LLMModel, LLMProvider, load_config
|
|
12
|
-
from kimi_cli.llm import augment_provider_with_env_vars, create_llm
|
|
13
|
-
from kimi_cli.session import Session
|
|
14
|
-
from kimi_cli.soul.agent import load_agent
|
|
15
|
-
from kimi_cli.soul.context import Context
|
|
16
|
-
from kimi_cli.soul.kimisoul import KimiSoul
|
|
17
|
-
from kimi_cli.soul.runtime import Runtime
|
|
18
|
-
from kimi_cli.ui.acp import ACPServer
|
|
19
|
-
from kimi_cli.ui.print import InputFormat, OutputFormat, PrintApp
|
|
20
|
-
from kimi_cli.ui.shell import ShellApp, WelcomeInfoItem
|
|
21
|
-
from kimi_cli.utils.logging import StreamToLogger, logger
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class KimiCLI:
|
|
25
|
-
@staticmethod
|
|
26
|
-
async def create(
|
|
27
|
-
session: Session,
|
|
28
|
-
*,
|
|
29
|
-
yolo: bool = False,
|
|
30
|
-
stream: bool = True, # TODO: remove this when we have a correct print mode impl
|
|
31
|
-
mcp_configs: list[dict[str, Any]] | None = None,
|
|
32
|
-
config_file: Path | None = None,
|
|
33
|
-
model_name: str | None = None,
|
|
34
|
-
agent_file: Path | None = None,
|
|
35
|
-
) -> "KimiCLI":
|
|
36
|
-
"""
|
|
37
|
-
Create a KimiCLI instance.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
session (Session): A session created by `Session.create` or `Session.continue_`.
|
|
41
|
-
yolo (bool, optional): Approve all actions without confirmation. Defaults to False.
|
|
42
|
-
stream (bool, optional): Use stream mode when calling LLM API. Defaults to True.
|
|
43
|
-
config_file (Path | None, optional): Path to the configuration file. Defaults to None.
|
|
44
|
-
model_name (str | None, optional): Name of the model to use. Defaults to None.
|
|
45
|
-
agent_file (Path | None, optional): Path to the agent file. Defaults to None.
|
|
46
|
-
|
|
47
|
-
Raises:
|
|
48
|
-
FileNotFoundError: When the agent file is not found.
|
|
49
|
-
ConfigError(KimiCLIException): When the configuration is invalid.
|
|
50
|
-
AgentSpecError(KimiCLIException): When the agent specification is invalid.
|
|
51
|
-
"""
|
|
52
|
-
config = load_config(config_file)
|
|
53
|
-
logger.info("Loaded config: {config}", config=config)
|
|
54
|
-
|
|
55
|
-
model: LLMModel | None = None
|
|
56
|
-
provider: LLMProvider | None = None
|
|
57
|
-
|
|
58
|
-
# try to use config file
|
|
59
|
-
if not model_name and config.default_model:
|
|
60
|
-
# no --model specified && default model is set in config
|
|
61
|
-
model = config.models[config.default_model]
|
|
62
|
-
provider = config.providers[model.provider]
|
|
63
|
-
if model_name and model_name in config.models:
|
|
64
|
-
# --model specified && model is set in config
|
|
65
|
-
model = config.models[model_name]
|
|
66
|
-
provider = config.providers[model.provider]
|
|
67
|
-
|
|
68
|
-
if not model:
|
|
69
|
-
model = LLMModel(provider="", model="", max_context_size=100_000)
|
|
70
|
-
provider = LLMProvider(type="kimi", base_url="", api_key=SecretStr(""))
|
|
71
|
-
|
|
72
|
-
# try overwrite with environment variables
|
|
73
|
-
assert provider is not None
|
|
74
|
-
assert model is not None
|
|
75
|
-
env_overrides = augment_provider_with_env_vars(provider, model)
|
|
76
|
-
|
|
77
|
-
if not provider.base_url or not model.model:
|
|
78
|
-
llm = None
|
|
79
|
-
else:
|
|
80
|
-
logger.info("Using LLM provider: {provider}", provider=provider)
|
|
81
|
-
logger.info("Using LLM model: {model}", model=model)
|
|
82
|
-
llm = create_llm(provider, model, stream=stream, session_id=session.id)
|
|
83
|
-
|
|
84
|
-
welcome_info = [
|
|
85
|
-
WelcomeInfoItem(name="Directory", value=str(session.work_dir)),
|
|
86
|
-
WelcomeInfoItem(name="Session", value=session.id),
|
|
87
|
-
]
|
|
88
|
-
if base_url := env_overrides.get("KIMI_BASE_URL"):
|
|
89
|
-
welcome_info.append(
|
|
90
|
-
WelcomeInfoItem(
|
|
91
|
-
name="API URL",
|
|
92
|
-
value=f"{base_url} (from KIMI_BASE_URL)",
|
|
93
|
-
level=WelcomeInfoItem.Level.WARN,
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
if not llm:
|
|
97
|
-
welcome_info.append(
|
|
98
|
-
WelcomeInfoItem(
|
|
99
|
-
name="Model",
|
|
100
|
-
value="not set, send /setup to configure",
|
|
101
|
-
level=WelcomeInfoItem.Level.WARN,
|
|
102
|
-
)
|
|
103
|
-
)
|
|
104
|
-
elif "KIMI_MODEL_NAME" in env_overrides:
|
|
105
|
-
welcome_info.append(
|
|
106
|
-
WelcomeInfoItem(
|
|
107
|
-
name="Model",
|
|
108
|
-
value=f"{model.model} (from KIMI_MODEL_NAME)",
|
|
109
|
-
level=WelcomeInfoItem.Level.WARN,
|
|
110
|
-
)
|
|
111
|
-
)
|
|
112
|
-
else:
|
|
113
|
-
welcome_info.append(
|
|
114
|
-
WelcomeInfoItem(
|
|
115
|
-
name="Model",
|
|
116
|
-
value=model.model,
|
|
117
|
-
level=WelcomeInfoItem.Level.INFO,
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
runtime = await Runtime.create(config, llm, session, yolo)
|
|
122
|
-
|
|
123
|
-
if agent_file is None:
|
|
124
|
-
agent_file = DEFAULT_AGENT_FILE
|
|
125
|
-
agent = await load_agent(agent_file, runtime, mcp_configs=mcp_configs or [])
|
|
126
|
-
|
|
127
|
-
context = Context(session.history_file)
|
|
128
|
-
await context.restore()
|
|
129
|
-
|
|
130
|
-
soul = KimiSoul(
|
|
131
|
-
agent,
|
|
132
|
-
runtime,
|
|
133
|
-
context=context,
|
|
134
|
-
)
|
|
135
|
-
return KimiCLI(soul, session, welcome_info)
|
|
136
|
-
|
|
137
|
-
def __init__(
|
|
138
|
-
self,
|
|
139
|
-
soul: KimiSoul,
|
|
140
|
-
session: Session,
|
|
141
|
-
welcome_info: list[WelcomeInfoItem],
|
|
142
|
-
) -> None:
|
|
143
|
-
self._soul = soul
|
|
144
|
-
self._session = session
|
|
145
|
-
self._welcome_info = welcome_info
|
|
146
|
-
|
|
147
|
-
@property
|
|
148
|
-
def soul(self) -> KimiSoul:
|
|
149
|
-
"""Get the KimiSoul instance."""
|
|
150
|
-
return self._soul
|
|
151
|
-
|
|
152
|
-
@property
|
|
153
|
-
def session(self) -> Session:
|
|
154
|
-
"""Get the Session instance."""
|
|
155
|
-
return self._session
|
|
156
|
-
|
|
157
|
-
@contextlib.contextmanager
|
|
158
|
-
def _app_env(self) -> Generator[None]:
|
|
159
|
-
original_cwd = Path.cwd()
|
|
160
|
-
os.chdir(self._session.work_dir)
|
|
161
|
-
try:
|
|
162
|
-
# to ignore possible warnings from dateparser
|
|
163
|
-
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
164
|
-
with contextlib.redirect_stderr(StreamToLogger()):
|
|
165
|
-
yield
|
|
166
|
-
finally:
|
|
167
|
-
os.chdir(original_cwd)
|
|
168
|
-
|
|
169
|
-
async def run_shell_mode(self, command: str | None = None) -> bool:
|
|
170
|
-
with self._app_env():
|
|
171
|
-
app = ShellApp(self._soul, welcome_info=self._welcome_info)
|
|
172
|
-
return await app.run(command)
|
|
173
|
-
|
|
174
|
-
async def run_print_mode(
|
|
175
|
-
self,
|
|
176
|
-
input_format: InputFormat,
|
|
177
|
-
output_format: OutputFormat,
|
|
178
|
-
command: str | None = None,
|
|
179
|
-
) -> bool:
|
|
180
|
-
with self._app_env():
|
|
181
|
-
app = PrintApp(
|
|
182
|
-
self._soul,
|
|
183
|
-
input_format,
|
|
184
|
-
output_format,
|
|
185
|
-
self._session.history_file,
|
|
186
|
-
)
|
|
187
|
-
return await app.run(command)
|
|
188
|
-
|
|
189
|
-
async def run_acp_server(self) -> bool:
|
|
190
|
-
with self._app_env():
|
|
191
|
-
app = ACPServer(self._soul)
|
|
192
|
-
return await app.run()
|
kimi_cli/app.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import os
|
|
3
|
+
import warnings
|
|
4
|
+
from collections.abc import Generator
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from pydantic import SecretStr
|
|
9
|
+
|
|
10
|
+
from kimi_cli.agentspec import DEFAULT_AGENT_FILE
|
|
11
|
+
from kimi_cli.cli import InputFormat, OutputFormat
|
|
12
|
+
from kimi_cli.config import LLMModel, LLMProvider, load_config
|
|
13
|
+
from kimi_cli.llm import augment_provider_with_env_vars, create_llm
|
|
14
|
+
from kimi_cli.session import Session
|
|
15
|
+
from kimi_cli.soul.agent import load_agent
|
|
16
|
+
from kimi_cli.soul.context import Context
|
|
17
|
+
from kimi_cli.soul.kimisoul import KimiSoul
|
|
18
|
+
from kimi_cli.soul.runtime import Runtime
|
|
19
|
+
from kimi_cli.utils.logging import StreamToLogger, logger
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class KimiCLI:
|
|
23
|
+
@staticmethod
|
|
24
|
+
async def create(
|
|
25
|
+
session: Session,
|
|
26
|
+
*,
|
|
27
|
+
yolo: bool = False,
|
|
28
|
+
stream: bool = True, # TODO: remove this when we have a correct print mode impl
|
|
29
|
+
mcp_configs: list[dict[str, Any]] | None = None,
|
|
30
|
+
config_file: Path | None = None,
|
|
31
|
+
model_name: str | None = None,
|
|
32
|
+
agent_file: Path | None = None,
|
|
33
|
+
) -> "KimiCLI":
|
|
34
|
+
"""
|
|
35
|
+
Create a KimiCLI instance.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
session (Session): A session created by `Session.create` or `Session.continue_`.
|
|
39
|
+
yolo (bool, optional): Approve all actions without confirmation. Defaults to False.
|
|
40
|
+
stream (bool, optional): Use stream mode when calling LLM API. Defaults to True.
|
|
41
|
+
config_file (Path | None, optional): Path to the configuration file. Defaults to None.
|
|
42
|
+
model_name (str | None, optional): Name of the model to use. Defaults to None.
|
|
43
|
+
agent_file (Path | None, optional): Path to the agent file. Defaults to None.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
FileNotFoundError: When the agent file is not found.
|
|
47
|
+
ConfigError(KimiCLIException): When the configuration is invalid.
|
|
48
|
+
AgentSpecError(KimiCLIException): When the agent specification is invalid.
|
|
49
|
+
"""
|
|
50
|
+
config = load_config(config_file)
|
|
51
|
+
logger.info("Loaded config: {config}", config=config)
|
|
52
|
+
|
|
53
|
+
model: LLMModel | None = None
|
|
54
|
+
provider: LLMProvider | None = None
|
|
55
|
+
|
|
56
|
+
# try to use config file
|
|
57
|
+
if not model_name and config.default_model:
|
|
58
|
+
# no --model specified && default model is set in config
|
|
59
|
+
model = config.models[config.default_model]
|
|
60
|
+
provider = config.providers[model.provider]
|
|
61
|
+
if model_name and model_name in config.models:
|
|
62
|
+
# --model specified && model is set in config
|
|
63
|
+
model = config.models[model_name]
|
|
64
|
+
provider = config.providers[model.provider]
|
|
65
|
+
|
|
66
|
+
if not model:
|
|
67
|
+
model = LLMModel(provider="", model="", max_context_size=100_000)
|
|
68
|
+
provider = LLMProvider(type="kimi", base_url="", api_key=SecretStr(""))
|
|
69
|
+
|
|
70
|
+
# try overwrite with environment variables
|
|
71
|
+
assert provider is not None
|
|
72
|
+
assert model is not None
|
|
73
|
+
env_overrides = augment_provider_with_env_vars(provider, model)
|
|
74
|
+
|
|
75
|
+
if not provider.base_url or not model.model:
|
|
76
|
+
llm = None
|
|
77
|
+
else:
|
|
78
|
+
logger.info("Using LLM provider: {provider}", provider=provider)
|
|
79
|
+
logger.info("Using LLM model: {model}", model=model)
|
|
80
|
+
llm = create_llm(provider, model, stream=stream, session_id=session.id)
|
|
81
|
+
|
|
82
|
+
runtime = await Runtime.create(config, llm, session, yolo)
|
|
83
|
+
|
|
84
|
+
if agent_file is None:
|
|
85
|
+
agent_file = DEFAULT_AGENT_FILE
|
|
86
|
+
agent = await load_agent(agent_file, runtime, mcp_configs=mcp_configs or [])
|
|
87
|
+
|
|
88
|
+
context = Context(session.history_file)
|
|
89
|
+
await context.restore()
|
|
90
|
+
|
|
91
|
+
soul = KimiSoul(
|
|
92
|
+
agent,
|
|
93
|
+
runtime,
|
|
94
|
+
context=context,
|
|
95
|
+
)
|
|
96
|
+
return KimiCLI(soul, runtime, env_overrides)
|
|
97
|
+
|
|
98
|
+
def __init__(
|
|
99
|
+
self,
|
|
100
|
+
_soul: KimiSoul,
|
|
101
|
+
_runtime: Runtime,
|
|
102
|
+
_env_overrides: dict[str, str],
|
|
103
|
+
) -> None:
|
|
104
|
+
self._soul = _soul
|
|
105
|
+
self._runtime = _runtime
|
|
106
|
+
self._env_overrides = _env_overrides
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def soul(self) -> KimiSoul:
|
|
110
|
+
"""Get the KimiSoul instance."""
|
|
111
|
+
return self._soul
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def session(self) -> Session:
|
|
115
|
+
"""Get the Session instance."""
|
|
116
|
+
return self._runtime.session
|
|
117
|
+
|
|
118
|
+
@contextlib.contextmanager
|
|
119
|
+
def _app_env(self) -> Generator[None]:
|
|
120
|
+
original_cwd = Path.cwd()
|
|
121
|
+
os.chdir(self._runtime.session.work_dir)
|
|
122
|
+
try:
|
|
123
|
+
# to ignore possible warnings from dateparser
|
|
124
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
125
|
+
with contextlib.redirect_stderr(StreamToLogger()):
|
|
126
|
+
yield
|
|
127
|
+
finally:
|
|
128
|
+
os.chdir(original_cwd)
|
|
129
|
+
|
|
130
|
+
async def run_shell_mode(self, command: str | None = None) -> bool:
|
|
131
|
+
from kimi_cli.ui.shell import ShellApp, WelcomeInfoItem
|
|
132
|
+
|
|
133
|
+
welcome_info = [
|
|
134
|
+
WelcomeInfoItem(name="Directory", value=str(self._runtime.session.work_dir)),
|
|
135
|
+
WelcomeInfoItem(name="Session", value=self._runtime.session.id),
|
|
136
|
+
]
|
|
137
|
+
if base_url := self._env_overrides.get("KIMI_BASE_URL"):
|
|
138
|
+
welcome_info.append(
|
|
139
|
+
WelcomeInfoItem(
|
|
140
|
+
name="API URL",
|
|
141
|
+
value=f"{base_url} (from KIMI_BASE_URL)",
|
|
142
|
+
level=WelcomeInfoItem.Level.WARN,
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
if not self._runtime.llm:
|
|
146
|
+
welcome_info.append(
|
|
147
|
+
WelcomeInfoItem(
|
|
148
|
+
name="Model",
|
|
149
|
+
value="not set, send /setup to configure",
|
|
150
|
+
level=WelcomeInfoItem.Level.WARN,
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
elif "KIMI_MODEL_NAME" in self._env_overrides:
|
|
154
|
+
welcome_info.append(
|
|
155
|
+
WelcomeInfoItem(
|
|
156
|
+
name="Model",
|
|
157
|
+
value=f"{self._soul.model} (from KIMI_MODEL_NAME)",
|
|
158
|
+
level=WelcomeInfoItem.Level.WARN,
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
else:
|
|
162
|
+
welcome_info.append(
|
|
163
|
+
WelcomeInfoItem(
|
|
164
|
+
name="Model",
|
|
165
|
+
value=self._soul.model,
|
|
166
|
+
level=WelcomeInfoItem.Level.INFO,
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
with self._app_env():
|
|
170
|
+
app = ShellApp(self._soul, welcome_info=welcome_info)
|
|
171
|
+
return await app.run(command)
|
|
172
|
+
|
|
173
|
+
async def run_print_mode(
|
|
174
|
+
self,
|
|
175
|
+
input_format: InputFormat,
|
|
176
|
+
output_format: OutputFormat,
|
|
177
|
+
command: str | None = None,
|
|
178
|
+
) -> bool:
|
|
179
|
+
from kimi_cli.ui.print import PrintApp
|
|
180
|
+
|
|
181
|
+
with self._app_env():
|
|
182
|
+
app = PrintApp(
|
|
183
|
+
self._soul,
|
|
184
|
+
input_format,
|
|
185
|
+
output_format,
|
|
186
|
+
self._runtime.session.history_file,
|
|
187
|
+
)
|
|
188
|
+
return await app.run(command)
|
|
189
|
+
|
|
190
|
+
async def run_acp_server(self) -> bool:
|
|
191
|
+
from kimi_cli.ui.acp import ACPServer
|
|
192
|
+
|
|
193
|
+
with self._app_env():
|
|
194
|
+
app = ACPServer(self._soul)
|
|
195
|
+
return await app.run()
|
kimi_cli/cli.py
CHANGED
|
@@ -7,12 +7,7 @@ from typing import Any, Literal, get_args
|
|
|
7
7
|
|
|
8
8
|
import click
|
|
9
9
|
|
|
10
|
-
from kimi_cli import KimiCLI
|
|
11
10
|
from kimi_cli.constant import VERSION
|
|
12
|
-
from kimi_cli.session import Session
|
|
13
|
-
from kimi_cli.share import get_share_dir
|
|
14
|
-
from kimi_cli.ui.print import InputFormat, OutputFormat
|
|
15
|
-
from kimi_cli.utils.logging import logger
|
|
16
11
|
|
|
17
12
|
|
|
18
13
|
class Reload(Exception):
|
|
@@ -22,6 +17,8 @@ class Reload(Exception):
|
|
|
22
17
|
|
|
23
18
|
|
|
24
19
|
UIMode = Literal["shell", "print", "acp"]
|
|
20
|
+
InputFormat = Literal["text", "stream-json"]
|
|
21
|
+
OutputFormat = Literal["text", "stream-json"]
|
|
25
22
|
|
|
26
23
|
|
|
27
24
|
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
|
|
@@ -156,6 +153,10 @@ def kimi(
|
|
|
156
153
|
yolo: bool,
|
|
157
154
|
):
|
|
158
155
|
"""Kimi, your next CLI agent."""
|
|
156
|
+
from kimi_cli.app import KimiCLI
|
|
157
|
+
from kimi_cli.session import Session
|
|
158
|
+
from kimi_cli.share import get_share_dir
|
|
159
|
+
from kimi_cli.utils.logging import logger
|
|
159
160
|
|
|
160
161
|
def _noop_echo(*args: Any, **kwargs: Any):
|
|
161
162
|
pass
|
kimi_cli/llm.py
CHANGED
|
@@ -2,9 +2,6 @@ import os
|
|
|
2
2
|
from typing import NamedTuple
|
|
3
3
|
|
|
4
4
|
from kosong.base.chat_provider import ChatProvider
|
|
5
|
-
from kosong.chat_provider.chaos import ChaosChatProvider, ChaosConfig
|
|
6
|
-
from kosong.chat_provider.kimi import Kimi
|
|
7
|
-
from kosong.chat_provider.openai_legacy import OpenAILegacy
|
|
8
5
|
from pydantic import SecretStr
|
|
9
6
|
|
|
10
7
|
from kimi_cli.config import LLMModel, LLMModelCapability, LLMProvider
|
|
@@ -68,6 +65,8 @@ def create_llm(
|
|
|
68
65
|
) -> LLM:
|
|
69
66
|
match provider.type:
|
|
70
67
|
case "kimi":
|
|
68
|
+
from kosong.chat_provider.kimi import Kimi
|
|
69
|
+
|
|
71
70
|
chat_provider = Kimi(
|
|
72
71
|
model=model.model,
|
|
73
72
|
base_url=provider.base_url,
|
|
@@ -81,6 +80,8 @@ def create_llm(
|
|
|
81
80
|
if session_id:
|
|
82
81
|
chat_provider = chat_provider.with_generation_kwargs(prompt_cache_key=session_id)
|
|
83
82
|
case "openai_legacy":
|
|
83
|
+
from kosong.chat_provider.openai_legacy import OpenAILegacy
|
|
84
|
+
|
|
84
85
|
chat_provider = OpenAILegacy(
|
|
85
86
|
model=model.model,
|
|
86
87
|
base_url=provider.base_url,
|
|
@@ -88,6 +89,8 @@ def create_llm(
|
|
|
88
89
|
stream=stream,
|
|
89
90
|
)
|
|
90
91
|
case "_chaos":
|
|
92
|
+
from kosong.chat_provider.chaos import ChaosChatProvider, ChaosConfig
|
|
93
|
+
|
|
91
94
|
chat_provider = ChaosChatProvider(
|
|
92
95
|
model=model.model,
|
|
93
96
|
base_url=provider.base_url,
|
kimi_cli/soul/agent.py
CHANGED
|
@@ -4,7 +4,6 @@ import string
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Any, NamedTuple
|
|
6
6
|
|
|
7
|
-
import fastmcp
|
|
8
7
|
from kosong.tooling import CallableTool, CallableTool2, Toolset
|
|
9
8
|
|
|
10
9
|
from kimi_cli.agentspec import ResolvedAgentSpec, load_agent_spec
|
|
@@ -14,7 +13,6 @@ from kimi_cli.soul.approval import Approval
|
|
|
14
13
|
from kimi_cli.soul.denwarenji import DenwaRenji
|
|
15
14
|
from kimi_cli.soul.runtime import BuiltinSystemPromptArgs, Runtime
|
|
16
15
|
from kimi_cli.soul.toolset import CustomToolset
|
|
17
|
-
from kimi_cli.tools.mcp import MCPTool
|
|
18
16
|
from kimi_cli.utils.logging import logger
|
|
19
17
|
|
|
20
18
|
|
|
@@ -143,6 +141,10 @@ async def _load_mcp_tools(
|
|
|
143
141
|
ValueError: If the MCP config is not valid.
|
|
144
142
|
RuntimeError: If the MCP server cannot be connected.
|
|
145
143
|
"""
|
|
144
|
+
import fastmcp
|
|
145
|
+
|
|
146
|
+
from kimi_cli.tools.mcp import MCPTool
|
|
147
|
+
|
|
146
148
|
for mcp_config in mcp_configs:
|
|
147
149
|
logger.info("Loading MCP tools from: {mcp_config}", mcp_config=mcp_config)
|
|
148
150
|
client = fastmcp.Client(mcp_config)
|
kimi_cli/soul/runtime.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import subprocess
|
|
2
3
|
import sys
|
|
3
4
|
from datetime import datetime
|
|
@@ -75,9 +76,10 @@ class Runtime(NamedTuple):
|
|
|
75
76
|
session: Session,
|
|
76
77
|
yolo: bool,
|
|
77
78
|
) -> "Runtime":
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
ls_output, agents_md = await asyncio.gather(
|
|
80
|
+
asyncio.to_thread(_list_work_dir, session.work_dir),
|
|
81
|
+
asyncio.to_thread(load_agents_md, session.work_dir),
|
|
82
|
+
)
|
|
81
83
|
|
|
82
84
|
return Runtime(
|
|
83
85
|
config=config,
|
|
@@ -87,7 +89,7 @@ class Runtime(NamedTuple):
|
|
|
87
89
|
KIMI_NOW=datetime.now().astimezone().isoformat(),
|
|
88
90
|
KIMI_WORK_DIR=session.work_dir,
|
|
89
91
|
KIMI_WORK_DIR_LS=ls_output,
|
|
90
|
-
KIMI_AGENTS_MD=agents_md,
|
|
92
|
+
KIMI_AGENTS_MD=agents_md or "",
|
|
91
93
|
),
|
|
92
94
|
denwa_renji=DenwaRenji(),
|
|
93
95
|
approval=Approval(yolo=yolo),
|
kimi_cli/ui/print/__init__.py
CHANGED
|
@@ -3,13 +3,13 @@ import json
|
|
|
3
3
|
import sys
|
|
4
4
|
from functools import partial
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Literal
|
|
7
6
|
|
|
8
7
|
import aiofiles
|
|
9
8
|
from kosong.base.message import Message
|
|
10
9
|
from kosong.chat_provider import ChatProviderError
|
|
11
10
|
from rich import print
|
|
12
11
|
|
|
12
|
+
from kimi_cli.cli import InputFormat, OutputFormat
|
|
13
13
|
from kimi_cli.soul import LLMNotSet, MaxStepsReached, RunCancelled, Soul, run_soul
|
|
14
14
|
from kimi_cli.utils.logging import logger
|
|
15
15
|
from kimi_cli.utils.message import message_extract_text
|
|
@@ -17,9 +17,6 @@ from kimi_cli.utils.signals import install_sigint_handler
|
|
|
17
17
|
from kimi_cli.wire import WireUISide
|
|
18
18
|
from kimi_cli.wire.message import StepInterrupted
|
|
19
19
|
|
|
20
|
-
InputFormat = Literal["text", "stream-json"]
|
|
21
|
-
OutputFormat = Literal["text", "stream-json"]
|
|
22
|
-
|
|
23
20
|
|
|
24
21
|
class PrintApp:
|
|
25
22
|
"""
|
kimi_cli/ui/shell/prompt.py
CHANGED
|
@@ -572,6 +572,7 @@ class CustomPromptSession:
|
|
|
572
572
|
async def prompt(self) -> UserInput:
|
|
573
573
|
with patch_stdout():
|
|
574
574
|
command = str(await self._session.prompt_async()).strip()
|
|
575
|
+
command = command.replace("\x00", "") # just in case null bytes are somehow inserted
|
|
575
576
|
self._append_history_entry(command)
|
|
576
577
|
|
|
577
578
|
# Parse rich content parts
|
kimi_cli/ui/shell/setup.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
kimi_cli/CHANGELOG.md,sha256=
|
|
2
|
-
kimi_cli/__init__.py,sha256=
|
|
1
|
+
kimi_cli/CHANGELOG.md,sha256=f3231982f148e227198bfab938f3878052366c02d80c3432e5ac48d3a9dbd234,8325
|
|
2
|
+
kimi_cli/__init__.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
|
|
3
3
|
kimi_cli/agents/default/agent.yaml,sha256=6e5c51987ef5cfc0c4c4e34cc20b6fc975953ee219623fccae81a19155aab7b3,709
|
|
4
4
|
kimi_cli/agents/default/sub.yaml,sha256=e0c1ea34fdb04b0d6dc635709f0f130aff25d7f9fb97e238470143c8145be251,634
|
|
5
5
|
kimi_cli/agents/default/system.md,sha256=1d8fd4956b2442215396b5e9651771c9da8f9505ccbd3b6d5e91b1ac4ff35418,5001
|
|
6
6
|
kimi_cli/agentspec.py,sha256=1148b5184ca610b2fb261ce365a63eb2fc9d09497330fe0ea4b2567fc98d5657,4307
|
|
7
|
-
kimi_cli/
|
|
7
|
+
kimi_cli/app.py,sha256=973684726d6c7bc0140f4c7940d1c3585899d828b5ab1c25b4e322c7fa6f7c35,7011
|
|
8
|
+
kimi_cli/cli.py,sha256=3c73fea4dd930a1c80b97ea4b8a71cdf482208d3a0304a769bd59b4e95c1c664,6713
|
|
8
9
|
kimi_cli/config.py,sha256=1bdd90554d33c45848d9ed9499a7914aecdf51e9166abe1b211d95aaa05a6382,4992
|
|
9
10
|
kimi_cli/constant.py,sha256=78e25b9304cca7b6f70bb08bf0e1fee4b066297a05386e56dd6935ba42027cd9,110
|
|
10
11
|
kimi_cli/exception.py,sha256=a3fec07566da7d2d34be8cc454fb825f34109bbde3cddf69e1ece6ab21b4b219,259
|
|
11
|
-
kimi_cli/llm.py,sha256=
|
|
12
|
+
kimi_cli/llm.py,sha256=d53be2d6f75bd8c92304df9841a236671d7e53ac325eb87293a22fadf90d6a18,3628
|
|
12
13
|
kimi_cli/metadata.py,sha256=9e9d4bc12ff26fc34e0e09d9068be989f2ff3c8b682ef453de69e442f8f672a1,1557
|
|
13
14
|
kimi_cli/prompts/__init__.py,sha256=6dc5ed2d841f145c09550075f30853cdc51f00d2f5d9aa1097f8edea770536e7,174
|
|
14
15
|
kimi_cli/prompts/compact.md,sha256=6655bd7d8270b24d8f97b51ef7c471cf71d686c56f8ec9a5cc9e47caa3aae87c,1877
|
|
@@ -17,14 +18,14 @@ kimi_cli/py.typed,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991
|
|
|
17
18
|
kimi_cli/session.py,sha256=c0623b0cec8ce311f1ddc7bb47e1e452499e13f816b7c3023342499a436dcfc5,2853
|
|
18
19
|
kimi_cli/share.py,sha256=4292df7f44177419c45c772a933b5f36e2b7533f8cef9842629a438bc7856dc0,204
|
|
19
20
|
kimi_cli/soul/__init__.py,sha256=9888a937570bf8bc6e49087a0694f121957210eaa14a7efb4042eb513e136caa,5499
|
|
20
|
-
kimi_cli/soul/agent.py,sha256=
|
|
21
|
+
kimi_cli/soul/agent.py,sha256=776e92f46cff2ac5ec0acd06acb445ddabbee05fcc358f9cde54d439e505d300,4843
|
|
21
22
|
kimi_cli/soul/approval.py,sha256=48cd230dff81dfd70bd85f1ad2b99604d5569cf617a4c79c444f9772bbc89ce6,2552
|
|
22
23
|
kimi_cli/soul/compaction.py,sha256=dab17979060fceeed4a7a344373833022dc7abac04282364f2a1b20e6edd4581,3558
|
|
23
24
|
kimi_cli/soul/context.py,sha256=541759a65f8f87a3424a6da160ffb2043046e6f6b714124d94d82a77635df9bc,5855
|
|
24
25
|
kimi_cli/soul/denwarenji.py,sha256=66b95f052a1fa844e2347972d34e1916a7be24d3e493701b451f5380b0375c9f,1384
|
|
25
26
|
kimi_cli/soul/kimisoul.py,sha256=68c65fe0f97700832a42018ae00892d38dc79f14759265042f47b707dbc0c749,11822
|
|
26
27
|
kimi_cli/soul/message.py,sha256=7a52a6d4d63ef1a3621d93d5ff86887baa7e67019bf2e9a08c374fc130b8d152,2541
|
|
27
|
-
kimi_cli/soul/runtime.py,sha256=
|
|
28
|
+
kimi_cli/soul/runtime.py,sha256=9421a3ce6882587a95ecdf77b3d75f3b7ecab55cf68dc57e3e563b93e5a02e46,2690
|
|
28
29
|
kimi_cli/soul/toolset.py,sha256=60166d89ef0efac690fa6866e88afe70fbe80ad862ba2524d70ddf657a730d14,744
|
|
29
30
|
kimi_cli/tools/__init__.py,sha256=4d612402814eede7182e0a55e7dd21c4532b5dd44700dc744763a8308c2f74f8,3280
|
|
30
31
|
kimi_cli/tools/bash/__init__.py,sha256=de21b19c714bda53f6c89e3348c4c82fb4278040130fed1d261b3ab203054e8c,3028
|
|
@@ -60,16 +61,16 @@ kimi_cli/tools/web/search.md,sha256=24049f9e90d37083e0fc78b8b2e3a5f6fadf09bea00f
|
|
|
60
61
|
kimi_cli/tools/web/search.py,sha256=85de343b20bc9e58de8a09aba7c3aac619d6fc6d30a6a5b565108faeb4500faf,4517
|
|
61
62
|
kimi_cli/ui/__init__.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
|
|
62
63
|
kimi_cli/ui/acp/__init__.py,sha256=a35e17273e943168882865f90d922180c5a1f01de0d128c899ffcfe55a9db3c3,17120
|
|
63
|
-
kimi_cli/ui/print/__init__.py,sha256=
|
|
64
|
+
kimi_cli/ui/print/__init__.py,sha256=ca402bec701a253acd6de5b57d59635ac0b05d4013cebc26877c5aa4aa2c27c7,5546
|
|
64
65
|
kimi_cli/ui/shell/__init__.py,sha256=aa30b512004be5ad9c8b8ab420bbdb574532dc90968067682dab58ff19e8b660,11289
|
|
65
66
|
kimi_cli/ui/shell/console.py,sha256=bcbf7efd214cba3d2259f2a2c1842250cde96d49e4f9f1e0b60273cf1c366be3,842
|
|
66
67
|
kimi_cli/ui/shell/debug.py,sha256=cd4e7259c83f099b5c6519713be5306580f30d3fa4944e07916d4468e960c9c7,5562
|
|
67
68
|
kimi_cli/ui/shell/keyboard.py,sha256=23e5fbc4b6acda4c0f3b5297a0ae6eb09a90f4b5b37b2e95b7ce86a2da0d5dca,5160
|
|
68
69
|
kimi_cli/ui/shell/liveview.py,sha256=f4e6ac37c446740b5c55cf37d5ebd327b5d41334d41d5e54ad8ad15445c1a492,14239
|
|
69
70
|
kimi_cli/ui/shell/metacmd.py,sha256=a0e52e9cbd8758c1ba13f025599341aa59dd5bc5e244840da2ff9bb71f952a20,7678
|
|
70
|
-
kimi_cli/ui/shell/prompt.py,sha256=
|
|
71
|
+
kimi_cli/ui/shell/prompt.py,sha256=d18003de33da0c9711bf54496cb4d5f6f5aa6b2179b1618e4475b1f020208f6c,25808
|
|
71
72
|
kimi_cli/ui/shell/replay.py,sha256=e54f58acebc46ad944e1a2cdf54d81559262d2cf8baf5da391ed903926f1ccf1,3767
|
|
72
|
-
kimi_cli/ui/shell/setup.py,sha256=
|
|
73
|
+
kimi_cli/ui/shell/setup.py,sha256=8fbf2935fc5b972d2c3946e8dc9f4a7e9d2953810b57c0fb6f22172abf3e6fb5,5369
|
|
73
74
|
kimi_cli/ui/shell/update.py,sha256=56dcb0bd1da82b98c22bfdddca717a2805bd8ac3e93bf23fb3b508549c41fae8,7340
|
|
74
75
|
kimi_cli/ui/shell/visualize.py,sha256=1abaa53cf78836f71b1f83085b6bfe3f86624951fa3297d5086a06bafa97f960,3884
|
|
75
76
|
kimi_cli/utils/aiohttp.py,sha256=f8f61e3beaf6439e949c33c3a10db3035bf88136e882b09c858ea92a4c888e00,245
|
|
@@ -82,7 +83,7 @@ kimi_cli/utils/signals.py,sha256=20e0d158a1043189d44815fe3624cd0bfe41e99620a18ac
|
|
|
82
83
|
kimi_cli/utils/string.py,sha256=0d437d3633199df1051813af8b49a2f808c6525547310cc5c3d427710d2eae06,593
|
|
83
84
|
kimi_cli/wire/__init__.py,sha256=9f1d7eb58f76885edaf76f769371c363ec801b46cada03883eeb3536fa2677f7,1896
|
|
84
85
|
kimi_cli/wire/message.py,sha256=72222d3f3d7228a323dbba7b1084f35018104c58e4bb2aa51d0827984791841d,2398
|
|
85
|
-
kimi_cli-0.
|
|
86
|
-
kimi_cli-0.
|
|
87
|
-
kimi_cli-0.
|
|
88
|
-
kimi_cli-0.
|
|
86
|
+
kimi_cli-0.44.dist-info/WHEEL,sha256=70ab3c2925fe316809860cb034f99ba13c4b49819b339959274aab755cc084a8,78
|
|
87
|
+
kimi_cli-0.44.dist-info/entry_points.txt,sha256=97e051756296e9db3167f6dce61d6c88e58d170314a2d63d18c84c73a5c1333b,44
|
|
88
|
+
kimi_cli-0.44.dist-info/METADATA,sha256=02a3d900f175956a579d59cc4a039fb64cc0409e8d4f3baf43289b312e6aeb32,5217
|
|
89
|
+
kimi_cli-0.44.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|