kimi-cli 0.35__tar.gz → 0.37__tar.gz

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.

Files changed (83) hide show
  1. kimi_cli-0.37/PKG-INFO +150 -0
  2. kimi_cli-0.37/README.md +127 -0
  3. {kimi_cli-0.35 → kimi_cli-0.37}/pyproject.toml +2 -2
  4. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/CHANGELOG.md +20 -0
  5. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/__init__.py +15 -2
  6. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/__init__.py +1 -1
  7. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/approval.py +3 -2
  8. kimi_cli-0.37/src/kimi_cli/soul/compaction.py +105 -0
  9. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/kimisoul.py +94 -38
  10. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/wire.py +29 -4
  11. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/bash/__init__.py +3 -1
  12. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/__init__.py +8 -0
  13. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/patch.py +13 -1
  14. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/replace.py +13 -1
  15. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/write.py +13 -1
  16. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/__init__.py +1 -0
  17. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/print/__init__.py +1 -0
  18. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/shell/__init__.py +49 -103
  19. kimi_cli-0.37/src/kimi_cli/ui/shell/console.py +29 -0
  20. kimi_cli-0.37/src/kimi_cli/ui/shell/debug.py +187 -0
  21. kimi_cli-0.37/src/kimi_cli/ui/shell/keyboard.py +115 -0
  22. kimi_cli-0.37/src/kimi_cli/ui/shell/liveview.py +377 -0
  23. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/shell/metacmd.py +25 -67
  24. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/shell/setup.py +3 -6
  25. kimi_cli-0.37/src/kimi_cli/ui/shell/visualize.py +105 -0
  26. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/provider.py +9 -1
  27. kimi_cli-0.35/PKG-INFO +0 -24
  28. kimi_cli-0.35/README.md +0 -1
  29. kimi_cli-0.35/src/kimi_cli/ui/shell/console.py +0 -3
  30. kimi_cli-0.35/src/kimi_cli/ui/shell/liveview.py +0 -158
  31. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/agent.py +0 -0
  32. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/agents/koder/README.md +0 -0
  33. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/agents/koder/agent.yaml +0 -0
  34. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/agents/koder/sub.yaml +0 -0
  35. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/agents/koder/system.md +0 -0
  36. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/config.py +0 -0
  37. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/llm.py +0 -0
  38. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/metadata.py +0 -0
  39. {kimi_cli-0.35/src/kimi_cli/prompts/metacmds → kimi_cli-0.37/src/kimi_cli/prompts}/__init__.py +0 -0
  40. {kimi_cli-0.35/src/kimi_cli/prompts/metacmds → kimi_cli-0.37/src/kimi_cli/prompts}/compact.md +0 -0
  41. {kimi_cli-0.35/src/kimi_cli/prompts/metacmds → kimi_cli-0.37/src/kimi_cli/prompts}/init.md +0 -0
  42. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/py.typed +0 -0
  43. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/share.py +0 -0
  44. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/context.py +0 -0
  45. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/denwarenji.py +0 -0
  46. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/message.py +0 -0
  47. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/soul/toolset.py +0 -0
  48. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/__init__.py +0 -0
  49. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/bash/bash.md +0 -0
  50. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/dmail/__init__.py +0 -0
  51. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/dmail/dmail.md +0 -0
  52. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/glob.md +0 -0
  53. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/glob.py +0 -0
  54. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/grep.md +0 -0
  55. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/grep.py +0 -0
  56. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/patch.md +0 -0
  57. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/read.md +0 -0
  58. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/read.py +0 -0
  59. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/replace.md +0 -0
  60. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/file/write.md +0 -0
  61. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/mcp.py +0 -0
  62. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/task/__init__.py +0 -0
  63. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/task/task.md +0 -0
  64. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/test.py +0 -0
  65. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/think/__init__.py +0 -0
  66. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/think/think.md +0 -0
  67. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/todo/__init__.py +0 -0
  68. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/todo/set_todo_list.md +0 -0
  69. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/utils.py +0 -0
  70. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/web/__init__.py +0 -0
  71. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/web/fetch.md +0 -0
  72. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/web/fetch.py +0 -0
  73. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/web/search.md +0 -0
  74. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/tools/web/search.py +0 -0
  75. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/acp/__init__.py +0 -0
  76. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/shell/prompt.py +0 -0
  77. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/ui/shell/update.py +0 -0
  78. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/changelog.py +0 -0
  79. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/logging.py +0 -0
  80. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/message.py +0 -0
  81. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/path.py +0 -0
  82. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/pyinstaller.py +0 -0
  83. {kimi_cli-0.35 → kimi_cli-0.37}/src/kimi_cli/utils/string.py +0 -0
kimi_cli-0.37/PKG-INFO ADDED
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.3
2
+ Name: kimi-cli
3
+ Version: 0.37
4
+ Summary: Kimi CLI is your next CLI agent.
5
+ Requires-Dist: agent-client-protocol>=0.4.9
6
+ Requires-Dist: aiofiles>=25.1.0
7
+ Requires-Dist: aiohttp>=3.13.1
8
+ Requires-Dist: click>=8.3.0
9
+ Requires-Dist: kosong>=0.15.0
10
+ Requires-Dist: loguru>=0.7.3
11
+ Requires-Dist: patch-ng>=1.19.0
12
+ Requires-Dist: prompt-toolkit>=3.0.52
13
+ Requires-Dist: pyyaml>=6.0.3
14
+ Requires-Dist: rich>=14.2.0
15
+ Requires-Dist: ripgrepy>=2.2.0
16
+ Requires-Dist: streamingjson>=0.0.5
17
+ Requires-Dist: trafilatura>=2.0.0
18
+ Requires-Dist: tenacity>=9.1.2
19
+ Requires-Dist: fastmcp>=2.12.5
20
+ Requires-Dist: pydantic>=2.12.3
21
+ Requires-Python: >=3.13
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Kimi CLI
25
+
26
+ [中文](https://www.kimi.com/coding/docs/kimi-cli.html)
27
+
28
+ Kimi CLI is a new CLI agent that can help you with your software development tasks and terminal operations.
29
+
30
+ > [!IMPORTANT]
31
+ > Kimi CLI is currently in technical preview.
32
+
33
+ ## Key features
34
+
35
+ - Shell-like UI and raw shell command execution
36
+ - Zsh integration
37
+ - [Agent Client Protocol] support
38
+ - MCP support
39
+ - And more to come...
40
+
41
+ [Agent Client Protocol]: https://github.com/agentclientprotocol/agent-client-protocol
42
+
43
+ ## Installation
44
+
45
+ Kimi CLI is published as a Python package on PyPI. We highly recommend installing it with [uv](https://docs.astral.sh/uv/). If you have not installed uv yet, please follow the instructions [here](https://docs.astral.sh/uv/getting-started/installation/) to install it first.
46
+
47
+ Once uv is installed, you can install Kimi CLI with:
48
+
49
+ ```sh
50
+ uv tool install --python 3.13 kimi-cli
51
+ ```
52
+
53
+ Run `kimi --help` to check if Kimi CLI is installed successfully.
54
+
55
+ > [!IMPORTANT]
56
+ > Due to the security checks on macOS, the first time you run `kimi` command may take 10 seconds or more depending on your system environment.
57
+
58
+ ## Upgrading
59
+
60
+ Upgrade Kimi CLI to the latest version with:
61
+
62
+ ```sh
63
+ uv tool upgrade kimi-cli --no-cache
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ Run `kimi` command in the directory you want to work on, then send `/setup` to setup Kimi CLI:
69
+
70
+ ![](./docs/images/setup.png)
71
+
72
+ After setup is complete, Kimi CLI will be ready to use. You can send `/help` to get more information.
73
+
74
+ ## Features
75
+
76
+ ### Shell mode
77
+
78
+ Kimi CLI is not only a coding agent, but also a shell. You can switch the mode by pressing `Ctrl-K`. In shell mode, you can directly run shell commands without leaving Kimi CLI.
79
+
80
+ > [!NOTE]
81
+ > Built-in shell commands like `cd` are not supported yet.
82
+
83
+ ### Zsh integration
84
+
85
+ You can use Kimi CLI together with Zsh, to empower your shell experience with AI agent capabilities.
86
+
87
+ Install the [zsh-kimi-cli](https://github.com/MoonshotAI/zsh-kimi-cli) plugin via:
88
+
89
+ ```sh
90
+ git clone https://github.com/MoonshotAI/zsh-kimi-cli.git \
91
+ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/kimi-cli
92
+ ```
93
+
94
+ > [!NOTE]
95
+ > If you are using a plugin manager other than Oh My Zsh, you may need to refer to the plugin's README for installation instructions.
96
+
97
+ Then add `kimi-cli` to your Zsh plugin list in `~/.zshrc`:
98
+
99
+ ```sh
100
+ plugins=(... kimi-cli)
101
+ ```
102
+
103
+ After restarting Zsh, you can switch to agent mode by pressing `Ctrl-K`.
104
+
105
+ ### ACP support
106
+
107
+ Kimi CLI supports [Agent Client Protocol] out of the box. You can use it together with any ACP-compatible editors or IDEs.
108
+
109
+ For example, to use Kimi CLI with [Zed](https://zed.dev/), add the following configuration to your `~/.config/zed/settings.json`:
110
+
111
+ ```json
112
+ {
113
+ "agent_servers": {
114
+ "Kimi CLI": {
115
+ "command": "kimi",
116
+ "args": ["--acp"],
117
+ "env": {}
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ Then you can create Kimi CLI threads in Zed's agent panel.
124
+
125
+ ### Using MCP tools
126
+
127
+ Kimi CLI supports the well-established MCP config convention. For example:
128
+
129
+ ```json
130
+ {
131
+ "mcpServers": {
132
+ "context7": {
133
+ "url": "https://mcp.context7.com/mcp",
134
+ "headers": {
135
+ "CONTEXT7_API_KEY": "YOUR_API_KEY"
136
+ }
137
+ },
138
+ "chrome-devtools": {
139
+ "command": "npx",
140
+ "args": ["-y", "chrome-devtools-mcp@latest"]
141
+ }
142
+ }
143
+ }
144
+ ```
145
+
146
+ Run `kimi` with `--mcp-config-file` option to connect to the specified MCP servers:
147
+
148
+ ```sh
149
+ kimi --mcp-config-file /path/to/mcp.json
150
+ ```
@@ -0,0 +1,127 @@
1
+ # Kimi CLI
2
+
3
+ [中文](https://www.kimi.com/coding/docs/kimi-cli.html)
4
+
5
+ Kimi CLI is a new CLI agent that can help you with your software development tasks and terminal operations.
6
+
7
+ > [!IMPORTANT]
8
+ > Kimi CLI is currently in technical preview.
9
+
10
+ ## Key features
11
+
12
+ - Shell-like UI and raw shell command execution
13
+ - Zsh integration
14
+ - [Agent Client Protocol] support
15
+ - MCP support
16
+ - And more to come...
17
+
18
+ [Agent Client Protocol]: https://github.com/agentclientprotocol/agent-client-protocol
19
+
20
+ ## Installation
21
+
22
+ Kimi CLI is published as a Python package on PyPI. We highly recommend installing it with [uv](https://docs.astral.sh/uv/). If you have not installed uv yet, please follow the instructions [here](https://docs.astral.sh/uv/getting-started/installation/) to install it first.
23
+
24
+ Once uv is installed, you can install Kimi CLI with:
25
+
26
+ ```sh
27
+ uv tool install --python 3.13 kimi-cli
28
+ ```
29
+
30
+ Run `kimi --help` to check if Kimi CLI is installed successfully.
31
+
32
+ > [!IMPORTANT]
33
+ > Due to the security checks on macOS, the first time you run `kimi` command may take 10 seconds or more depending on your system environment.
34
+
35
+ ## Upgrading
36
+
37
+ Upgrade Kimi CLI to the latest version with:
38
+
39
+ ```sh
40
+ uv tool upgrade kimi-cli --no-cache
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ Run `kimi` command in the directory you want to work on, then send `/setup` to setup Kimi CLI:
46
+
47
+ ![](./docs/images/setup.png)
48
+
49
+ After setup is complete, Kimi CLI will be ready to use. You can send `/help` to get more information.
50
+
51
+ ## Features
52
+
53
+ ### Shell mode
54
+
55
+ Kimi CLI is not only a coding agent, but also a shell. You can switch the mode by pressing `Ctrl-K`. In shell mode, you can directly run shell commands without leaving Kimi CLI.
56
+
57
+ > [!NOTE]
58
+ > Built-in shell commands like `cd` are not supported yet.
59
+
60
+ ### Zsh integration
61
+
62
+ You can use Kimi CLI together with Zsh, to empower your shell experience with AI agent capabilities.
63
+
64
+ Install the [zsh-kimi-cli](https://github.com/MoonshotAI/zsh-kimi-cli) plugin via:
65
+
66
+ ```sh
67
+ git clone https://github.com/MoonshotAI/zsh-kimi-cli.git \
68
+ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/kimi-cli
69
+ ```
70
+
71
+ > [!NOTE]
72
+ > If you are using a plugin manager other than Oh My Zsh, you may need to refer to the plugin's README for installation instructions.
73
+
74
+ Then add `kimi-cli` to your Zsh plugin list in `~/.zshrc`:
75
+
76
+ ```sh
77
+ plugins=(... kimi-cli)
78
+ ```
79
+
80
+ After restarting Zsh, you can switch to agent mode by pressing `Ctrl-K`.
81
+
82
+ ### ACP support
83
+
84
+ Kimi CLI supports [Agent Client Protocol] out of the box. You can use it together with any ACP-compatible editors or IDEs.
85
+
86
+ For example, to use Kimi CLI with [Zed](https://zed.dev/), add the following configuration to your `~/.config/zed/settings.json`:
87
+
88
+ ```json
89
+ {
90
+ "agent_servers": {
91
+ "Kimi CLI": {
92
+ "command": "kimi",
93
+ "args": ["--acp"],
94
+ "env": {}
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ Then you can create Kimi CLI threads in Zed's agent panel.
101
+
102
+ ### Using MCP tools
103
+
104
+ Kimi CLI supports the well-established MCP config convention. For example:
105
+
106
+ ```json
107
+ {
108
+ "mcpServers": {
109
+ "context7": {
110
+ "url": "https://mcp.context7.com/mcp",
111
+ "headers": {
112
+ "CONTEXT7_API_KEY": "YOUR_API_KEY"
113
+ }
114
+ },
115
+ "chrome-devtools": {
116
+ "command": "npx",
117
+ "args": ["-y", "chrome-devtools-mcp@latest"]
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ Run `kimi` with `--mcp-config-file` option to connect to the specified MCP servers:
124
+
125
+ ```sh
126
+ kimi --mcp-config-file /path/to/mcp.json
127
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kimi-cli"
3
- version = "0.35"
3
+ version = "0.37"
4
4
  description = "Kimi CLI is your next CLI agent."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -9,7 +9,7 @@ dependencies = [
9
9
  "aiofiles>=25.1.0",
10
10
  "aiohttp>=3.13.1",
11
11
  "click>=8.3.0",
12
- "kosong>=0.14.1",
12
+ "kosong>=0.15.0",
13
13
  "loguru>=0.7.3",
14
14
  "patch-ng>=1.19.0",
15
15
  "prompt-toolkit>=3.0.52",
@@ -9,6 +9,26 @@ 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.37] - 2025-10-24
13
+
14
+ ### Fixed
15
+
16
+ - Fix update checking
17
+
18
+ ## [0.36] - 2025-10-24
19
+
20
+ ### Added
21
+
22
+ - Add `/debug` meta command to debug the context
23
+ - Add auto context compaction
24
+ - Add approval request mechanism
25
+ - Add `--yolo` option to automatically approve all actions
26
+ - Render markdown content for better readability
27
+
28
+ ### Fixed
29
+
30
+ - Fix "unknown error" message when interrupting a meta command
31
+
12
32
  ## [0.35] - 2025-10-22
13
33
 
14
34
  ### Changed
@@ -152,6 +152,16 @@ UIMode = Literal["shell", "print", "acp"]
152
152
  "Default: none."
153
153
  ),
154
154
  )
155
+ @click.option(
156
+ "--yolo",
157
+ "--yes",
158
+ "-y",
159
+ "--auto-approve",
160
+ "yolo",
161
+ is_flag=True,
162
+ default=False,
163
+ help="Automatically approve all actions. Default: no.",
164
+ )
155
165
  def kimi(
156
166
  verbose: bool,
157
167
  debug: bool,
@@ -165,6 +175,7 @@ def kimi(
165
175
  output_format: OutputFormat | None,
166
176
  mcp_config_file: list[Path],
167
177
  mcp_config: list[str],
178
+ yolo: bool,
168
179
  ):
169
180
  """Kimi, your next CLI agent."""
170
181
  echo = click.echo if verbose else lambda *args, **kwargs: None
@@ -232,6 +243,7 @@ def kimi(
232
243
  input_format=input_format,
233
244
  output_format=output_format,
234
245
  mcp_configs=mcp_configs,
246
+ yolo=yolo,
235
247
  )
236
248
  )
237
249
  if not succeeded:
@@ -254,6 +266,7 @@ async def kimi_run(
254
266
  input_format: InputFormat | None = None,
255
267
  output_format: OutputFormat | None = None,
256
268
  mcp_configs: list[dict[str, Any]] | None = None,
269
+ yolo: bool = False,
257
270
  ) -> bool:
258
271
  """Run Kimi CLI."""
259
272
  echo = click.echo if verbose else lambda *args, **kwargs: None
@@ -286,7 +299,7 @@ async def kimi_run(
286
299
  echo(f"✓ Using LLM provider: {provider}")
287
300
  echo(f"✓ Using LLM model: {model}")
288
301
  stream = ui != "print" # use non-streaming mode only for print UI
289
- llm = create_llm(provider, model, stream=stream)
302
+ llm = create_llm(provider, model, stream=stream, session_id=session.id)
290
303
 
291
304
  # TODO: support Windows
292
305
  ls = subprocess.run(["ls", "-la"], capture_output=True, text=True)
@@ -305,7 +318,7 @@ async def kimi_run(
305
318
  ),
306
319
  denwa_renji=DenwaRenji(),
307
320
  session=session,
308
- approval=Approval(),
321
+ approval=Approval(yolo=yolo),
309
322
  )
310
323
  try:
311
324
  agent = await load_agent_with_mcp(agent_file, agent_globals, mcp_configs or [])
@@ -51,7 +51,7 @@ class Soul(Protocol):
51
51
  wire (Wire): The wire to send events and requests to the UI loop.
52
52
 
53
53
  Raises:
54
- ChatProviderNotSet: When the chat provider is not set.
54
+ LLMNotSet: When the LLM is not set.
55
55
  ChatProviderError: When the LLM provider returns an error.
56
56
  MaxStepsReached: When the maximum number of steps is reached.
57
57
  asyncio.CancelledError: When the run is cancelled by user.
@@ -15,11 +15,12 @@ class Approval:
15
15
  def set_yolo(self, yolo: bool) -> None:
16
16
  self._yolo = yolo
17
17
 
18
- async def request(self, action: str, description: str) -> bool:
18
+ async def request(self, sender: str, action: str, description: str) -> bool:
19
19
  """
20
20
  Request approval for the given action. Intended to be called by tools.
21
21
 
22
22
  Args:
23
+ sender (str): The name of the sender.
23
24
  action (str): The action to request approval for.
24
25
  This is used to identify the action for auto-approval.
25
26
  description (str): The description of the action. This is used to display to the user.
@@ -47,7 +48,7 @@ class Approval:
47
48
  if action in self._auto_approve_actions:
48
49
  return True
49
50
 
50
- request = ApprovalRequest(tool_call.id, action, description)
51
+ request = ApprovalRequest(tool_call.id, sender, action, description)
51
52
  self._request_queue.put_nowait(request)
52
53
  response = await request.wait()
53
54
  logger.debug("Received approval response: {response}", response=response)
@@ -0,0 +1,105 @@
1
+ from collections.abc import Sequence
2
+ from string import Template
3
+ from typing import Protocol, runtime_checkable
4
+
5
+ from kosong.base import generate
6
+ from kosong.base.message import ContentPart, Message, TextPart
7
+
8
+ import kimi_cli.prompts as prompts
9
+ from kimi_cli.llm import LLM
10
+ from kimi_cli.soul.message import system
11
+ from kimi_cli.utils.logging import logger
12
+
13
+ MAX_PRESERVED_MESSAGES = 2
14
+
15
+
16
+ @runtime_checkable
17
+ class Compaction(Protocol):
18
+ async def compact(self, messages: Sequence[Message], llm: LLM) -> Sequence[Message]:
19
+ """
20
+ Compact a sequence of messages into a new sequence of messages.
21
+
22
+ Args:
23
+ messages (Sequence[Message]): The messages to compact.
24
+ llm (LLM): The LLM to use for compaction.
25
+
26
+ Returns:
27
+ Sequence[Message]: The compacted messages.
28
+
29
+ Raises:
30
+ ChatProviderError: When the chat provider returns an error.
31
+ """
32
+ ...
33
+
34
+
35
+ class SimpleCompaction:
36
+ async def compact(self, messages: Sequence[Message], llm: LLM) -> Sequence[Message]:
37
+ history = list(messages)
38
+ if not history:
39
+ return history
40
+
41
+ preserve_start_index = len(history)
42
+ n_preserved = 0
43
+ for index in range(len(history) - 1, -1, -1):
44
+ if history[index].role in {"user", "assistant"}:
45
+ n_preserved += 1
46
+ if n_preserved == MAX_PRESERVED_MESSAGES:
47
+ preserve_start_index = index
48
+ break
49
+
50
+ if n_preserved < MAX_PRESERVED_MESSAGES:
51
+ return history
52
+
53
+ to_compact = history[:preserve_start_index]
54
+ to_preserve = history[preserve_start_index:]
55
+
56
+ if not to_compact:
57
+ # Let's hope this won't exceed the context size limit
58
+ return to_preserve
59
+
60
+ # Convert history to string for the compact prompt
61
+ history_text = "\n\n".join(
62
+ f"## Message {i + 1}\nRole: {msg.role}\nContent: {msg.content}"
63
+ for i, msg in enumerate(to_compact)
64
+ )
65
+
66
+ # Build the compact prompt using string template
67
+ compact_template = Template(prompts.COMPACT)
68
+ compact_prompt = compact_template.substitute(CONTEXT=history_text)
69
+
70
+ # Create input message for compaction
71
+ compact_message = Message(role="user", content=compact_prompt)
72
+
73
+ # Call generate to get the compacted context
74
+ # TODO: set max completion tokens
75
+ logger.debug("Compacting context...")
76
+ compacted_msg, usage = await generate(
77
+ chat_provider=llm.chat_provider,
78
+ system_prompt="You are a helpful assistant that compacts conversation context.",
79
+ tools=[],
80
+ history=[compact_message],
81
+ )
82
+ if usage:
83
+ logger.debug(
84
+ "Compaction used {input} input tokens and {output} output tokens",
85
+ input=usage.input,
86
+ output=usage.output,
87
+ )
88
+
89
+ content: list[ContentPart] = [
90
+ system("Previous context has been compacted. Here is the compaction output:")
91
+ ]
92
+ content.extend(
93
+ [TextPart(text=compacted_msg.content)]
94
+ if isinstance(compacted_msg.content, str)
95
+ else compacted_msg.content
96
+ )
97
+ compacted_messages: list[Message] = [Message(role="assistant", content=content)]
98
+ compacted_messages.extend(to_preserve)
99
+ return compacted_messages
100
+
101
+
102
+ def __static_type_check(
103
+ simple: SimpleCompaction,
104
+ ):
105
+ _: Compaction = simple