klaude-code 1.2.17__py3-none-any.whl → 1.2.19__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.
Files changed (70) hide show
  1. klaude_code/cli/config_cmd.py +1 -1
  2. klaude_code/cli/debug.py +1 -1
  3. klaude_code/cli/main.py +45 -31
  4. klaude_code/cli/runtime.py +49 -13
  5. klaude_code/{version.py → cli/self_update.py} +110 -2
  6. klaude_code/command/__init__.py +4 -1
  7. klaude_code/command/clear_cmd.py +2 -7
  8. klaude_code/command/command_abc.py +33 -5
  9. klaude_code/command/debug_cmd.py +79 -0
  10. klaude_code/command/diff_cmd.py +2 -6
  11. klaude_code/command/export_cmd.py +7 -7
  12. klaude_code/command/export_online_cmd.py +9 -8
  13. klaude_code/command/help_cmd.py +4 -9
  14. klaude_code/command/model_cmd.py +10 -6
  15. klaude_code/command/prompt_command.py +2 -6
  16. klaude_code/command/refresh_cmd.py +2 -7
  17. klaude_code/command/registry.py +69 -26
  18. klaude_code/command/release_notes_cmd.py +2 -6
  19. klaude_code/command/status_cmd.py +2 -7
  20. klaude_code/command/terminal_setup_cmd.py +2 -6
  21. klaude_code/command/thinking_cmd.py +16 -10
  22. klaude_code/config/select_model.py +81 -5
  23. klaude_code/const/__init__.py +1 -1
  24. klaude_code/core/executor.py +257 -110
  25. klaude_code/core/manager/__init__.py +2 -4
  26. klaude_code/core/prompts/prompt-claude-code.md +1 -1
  27. klaude_code/core/prompts/prompt-sub-agent-explore.md +14 -2
  28. klaude_code/core/prompts/prompt-sub-agent-web.md +8 -5
  29. klaude_code/core/reminders.py +9 -35
  30. klaude_code/core/task.py +9 -7
  31. klaude_code/core/tool/file/read_tool.md +1 -1
  32. klaude_code/core/tool/file/read_tool.py +41 -12
  33. klaude_code/core/tool/memory/skill_loader.py +12 -10
  34. klaude_code/core/tool/shell/bash_tool.py +22 -2
  35. klaude_code/core/tool/tool_registry.py +1 -1
  36. klaude_code/core/tool/tool_runner.py +26 -23
  37. klaude_code/core/tool/truncation.py +23 -9
  38. klaude_code/core/tool/web/web_fetch_tool.md +1 -1
  39. klaude_code/core/tool/web/web_fetch_tool.py +36 -1
  40. klaude_code/core/turn.py +28 -0
  41. klaude_code/llm/anthropic/client.py +25 -9
  42. klaude_code/llm/openai_compatible/client.py +5 -2
  43. klaude_code/llm/openrouter/client.py +7 -3
  44. klaude_code/llm/responses/client.py +6 -1
  45. klaude_code/protocol/commands.py +1 -0
  46. klaude_code/protocol/sub_agent/web.py +3 -2
  47. klaude_code/session/session.py +35 -15
  48. klaude_code/session/templates/export_session.html +45 -32
  49. klaude_code/trace/__init__.py +20 -2
  50. klaude_code/ui/modes/repl/completers.py +231 -73
  51. klaude_code/ui/modes/repl/event_handler.py +8 -6
  52. klaude_code/ui/modes/repl/input_prompt_toolkit.py +1 -1
  53. klaude_code/ui/modes/repl/renderer.py +2 -2
  54. klaude_code/ui/renderers/common.py +54 -0
  55. klaude_code/ui/renderers/developer.py +2 -3
  56. klaude_code/ui/renderers/errors.py +1 -1
  57. klaude_code/ui/renderers/metadata.py +12 -5
  58. klaude_code/ui/renderers/thinking.py +24 -8
  59. klaude_code/ui/renderers/tools.py +82 -14
  60. klaude_code/ui/rich/code_panel.py +112 -0
  61. klaude_code/ui/rich/markdown.py +3 -4
  62. klaude_code/ui/rich/status.py +0 -2
  63. klaude_code/ui/rich/theme.py +10 -1
  64. klaude_code/ui/utils/common.py +0 -18
  65. {klaude_code-1.2.17.dist-info → klaude_code-1.2.19.dist-info}/METADATA +32 -7
  66. {klaude_code-1.2.17.dist-info → klaude_code-1.2.19.dist-info}/RECORD +69 -68
  67. klaude_code/core/manager/agent_manager.py +0 -132
  68. /klaude_code/{config → cli}/list_model.py +0 -0
  69. {klaude_code-1.2.17.dist-info → klaude_code-1.2.19.dist-info}/WHEEL +0 -0
  70. {klaude_code-1.2.17.dist-info → klaude_code-1.2.19.dist-info}/entry_points.txt +0 -0
@@ -12,7 +12,7 @@ from klaude_code.trace import log
12
12
 
13
13
  def list_models() -> None:
14
14
  """List all models and providers configuration"""
15
- from klaude_code.config.list_model import display_models_and_providers
15
+ from klaude_code.cli.list_model import display_models_and_providers
16
16
  from klaude_code.ui.terminal.color import is_light_terminal_background
17
17
 
18
18
  config = load_config()
klaude_code/cli/debug.py CHANGED
@@ -48,7 +48,7 @@ def open_log_file_in_editor(path: Path) -> None:
48
48
  editor = os.environ.get("EDITOR")
49
49
 
50
50
  if not editor:
51
- for cmd in ["open", "xdg-open", "code", "nvim", "vim", "nano"]:
51
+ for cmd in ["open", "xdg-open", "code", "TextEdit", "notepad"]:
52
52
  try:
53
53
  subprocess.run(["which", cmd], check=True, capture_output=True)
54
54
  editor = cmd
klaude_code/cli/main.py CHANGED
@@ -1,8 +1,6 @@
1
1
  import asyncio
2
2
  import os
3
3
  import sys
4
- from importlib.metadata import PackageNotFoundError
5
- from importlib.metadata import version as pkg_version
6
4
  from pathlib import Path
7
5
 
8
6
  import typer
@@ -10,8 +8,8 @@ import typer
10
8
  from klaude_code.cli.auth_cmd import register_auth_commands
11
9
  from klaude_code.cli.config_cmd import register_config_commands
12
10
  from klaude_code.cli.debug import DEBUG_FILTER_HELP, open_log_file_in_editor, resolve_debug_settings
11
+ from klaude_code.cli.self_update import register_self_update_commands, version_option_callback
13
12
  from klaude_code.cli.session_cmd import register_session_commands
14
- from klaude_code.config import load_config
15
13
  from klaude_code.session import Session, resume_select_session
16
14
  from klaude_code.trace import DebugType, prepare_debug_log_file
17
15
 
@@ -22,10 +20,13 @@ def set_terminal_title(title: str) -> None:
22
20
  sys.stdout.flush()
23
21
 
24
22
 
25
- def setup_terminal_title() -> None:
26
- """Set terminal title to current folder name."""
23
+ def update_terminal_title(model_name: str | None = None) -> None:
24
+ """Update terminal title with folder name and optional model name."""
27
25
  folder_name = os.path.basename(os.getcwd())
28
- set_terminal_title(f"{folder_name}: klaude")
26
+ if model_name:
27
+ set_terminal_title(f"{folder_name}: klaude ✳ {model_name}")
28
+ else:
29
+ set_terminal_title(f"{folder_name}: klaude")
29
30
 
30
31
 
31
32
  def prepare_debug_logging(debug: bool, debug_filter: str | None) -> tuple[bool, set[DebugType] | None, Path | None]:
@@ -79,20 +80,6 @@ def read_input_content(cli_argument: str) -> str | None:
79
80
  return content
80
81
 
81
82
 
82
- def _version_callback(value: bool) -> None:
83
- """Show version and exit."""
84
- if value:
85
- try:
86
- ver = pkg_version("klaude-code")
87
- except PackageNotFoundError:
88
- # Package is not installed or has no metadata; show a generic version string.
89
- ver = "unknown"
90
- except Exception:
91
- ver = "unknown"
92
- print(f"klaude-code {ver}")
93
- raise typer.Exit(0)
94
-
95
-
96
83
  app = typer.Typer(
97
84
  add_completion=False,
98
85
  pretty_exceptions_enable=False,
@@ -104,6 +91,8 @@ register_session_commands(app)
104
91
  register_auth_commands(app)
105
92
  register_config_commands(app)
106
93
 
94
+ register_self_update_commands(app)
95
+
107
96
 
108
97
  @app.command("exec")
109
98
  def exec_command(
@@ -147,7 +136,7 @@ def exec_command(
147
136
  ),
148
137
  ) -> None:
149
138
  """Execute non-interactively with provided input."""
150
- setup_terminal_title()
139
+ update_terminal_title()
151
140
 
152
141
  merged_input = read_input_content(input_content)
153
142
  if merged_input is None:
@@ -157,13 +146,8 @@ def exec_command(
157
146
  from klaude_code.config.select_model import select_model_from_config
158
147
 
159
148
  chosen_model = model
160
- if select_model:
161
- # Prefer the explicitly provided model as default; otherwise main model
162
- config = load_config()
163
- if config is None:
164
- raise typer.Exit(1)
165
- default_name = model or config.main_model
166
- chosen_model = select_model_from_config(preferred=default_name)
149
+ if model or select_model:
150
+ chosen_model = select_model_from_config(preferred=model)
167
151
  if chosen_model is None:
168
152
  return
169
153
 
@@ -196,8 +180,9 @@ def main_callback(
196
180
  False,
197
181
  "--version",
198
182
  "-V",
183
+ "-v",
199
184
  help="Show version and exit",
200
- callback=_version_callback,
185
+ callback=version_option_callback,
201
186
  is_eager=True,
202
187
  ),
203
188
  model: str | None = typer.Option(
@@ -240,10 +225,10 @@ def main_callback(
240
225
  from klaude_code.cli.runtime import AppInitConfig, run_interactive
241
226
  from klaude_code.config.select_model import select_model_from_config
242
227
 
243
- setup_terminal_title()
228
+ update_terminal_title()
244
229
 
245
230
  chosen_model = model
246
- if select_model:
231
+ if model or select_model:
247
232
  chosen_model = select_model_from_config(preferred=model)
248
233
  if chosen_model is None:
249
234
  return
@@ -260,6 +245,35 @@ def main_callback(
260
245
  session_id = Session.most_recent_session_id()
261
246
  # If still no session_id, leave as None to create a new session
262
247
 
248
+ if session_id is not None and chosen_model is None:
249
+ from klaude_code.config import load_config
250
+ from klaude_code.trace import log
251
+
252
+ session_meta = Session.load_meta(session_id)
253
+ cfg = load_config()
254
+
255
+ if cfg is not None and session_meta.model_config_name:
256
+ if any(m.model_name == session_meta.model_config_name for m in cfg.model_list):
257
+ chosen_model = session_meta.model_config_name
258
+ else:
259
+ log(
260
+ (
261
+ f"Warning: session model '{session_meta.model_config_name}' is not defined in config; falling back to default",
262
+ "yellow",
263
+ )
264
+ )
265
+
266
+ if cfg is not None and chosen_model is None and session_meta.model_name:
267
+ raw_model = session_meta.model_name.strip()
268
+ if raw_model:
269
+ matches = [
270
+ m.model_name
271
+ for m in cfg.model_list
272
+ if (m.model_params.model or "").strip().lower() == raw_model.lower()
273
+ ]
274
+ if len(matches) == 1:
275
+ chosen_model = matches[0]
276
+
263
277
  debug_enabled, debug_filters, log_path = prepare_debug_logging(debug, debug_filter)
264
278
 
265
279
  init_config = AppInitConfig(
@@ -8,6 +8,8 @@ import typer
8
8
  from rich.text import Text
9
9
 
10
10
  from klaude_code import ui
11
+ from klaude_code.cli.main import update_terminal_title
12
+ from klaude_code.cli.self_update import get_update_message
11
13
  from klaude_code.command import has_interactive_command
12
14
  from klaude_code.config import Config, load_config
13
15
  from klaude_code.core.agent import Agent, DefaultModelProfileProvider, VanillaModelProfileProvider
@@ -21,7 +23,6 @@ from klaude_code.ui.modes.repl.input_prompt_toolkit import REPLStatusSnapshot
21
23
  from klaude_code.ui.terminal.color import is_light_terminal_background
22
24
  from klaude_code.ui.terminal.control import install_sigint_double_press_exit, start_esc_interrupt_monitor
23
25
  from klaude_code.ui.terminal.progress_bar import OSC94States, emit_osc94
24
- from klaude_code.version import get_update_message
25
26
 
26
27
 
27
28
  class PrintCapable(Protocol):
@@ -92,14 +93,20 @@ async def initialize_app_components(init_config: AppInitConfig) -> AppComponents
92
93
  event_queue,
93
94
  llm_clients,
94
95
  model_profile_provider=model_profile_provider,
96
+ on_model_change=update_terminal_title,
95
97
  )
96
98
 
99
+ # Update terminal title with initial model name
100
+ update_terminal_title(llm_clients.main.model_name)
101
+
97
102
  # Start executor in background
98
103
  executor_task = asyncio.create_task(executor.start())
99
104
 
100
105
  theme: str | None = config.theme
101
- if theme is None:
106
+ if theme is None and not init_config.is_exec_mode:
102
107
  # Auto-detect theme from terminal background when config does not specify a theme.
108
+ # Skip detection in exec mode to avoid TTY race conditions with parent process's
109
+ # ESC monitor when running as a subprocess.
103
110
  detected = is_light_terminal_background()
104
111
  if detected is True:
105
112
  theme = "light"
@@ -145,8 +152,30 @@ async def initialize_session(
145
152
  await executor.submit_and_wait(op.InitAgentOperation(session_id=session_id))
146
153
  await event_queue.join()
147
154
 
148
- active_session_ids = executor.context.agent_manager.active_session_ids()
149
- return active_session_ids[0] if active_session_ids else session_id
155
+ active_session_id = executor.context.current_session_id()
156
+ return active_session_id or session_id
157
+
158
+
159
+ def _backfill_session_model_config(
160
+ agent: Agent | None,
161
+ model_override: str | None,
162
+ default_model: str,
163
+ is_new_session: bool,
164
+ ) -> None:
165
+ """Backfill model_config_name and model_thinking on newly created sessions."""
166
+ if agent is None or agent.session.model_config_name is not None:
167
+ return
168
+
169
+ if model_override is not None:
170
+ agent.session.model_config_name = model_override
171
+ elif is_new_session:
172
+ agent.session.model_config_name = default_model
173
+ else:
174
+ return
175
+
176
+ if agent.session.model_thinking is None and agent.profile:
177
+ agent.session.model_thinking = agent.profile.llm_client.get_llm_config().thinking
178
+ # Don't save here - session will be saved when first message is sent via append_history()
150
179
 
151
180
 
152
181
  async def cleanup_app_components(components: AppComponents) -> None:
@@ -190,6 +219,12 @@ async def run_exec(init_config: AppInitConfig, input_content: str) -> None:
190
219
 
191
220
  try:
192
221
  session_id = await initialize_session(components.executor, components.event_queue)
222
+ _backfill_session_model_config(
223
+ components.executor.context.current_agent,
224
+ init_config.model,
225
+ components.config.main_model,
226
+ is_new_session=True,
227
+ )
193
228
 
194
229
  # Submit the input content directly
195
230
  await components.executor.submit_and_wait(
@@ -214,16 +249,12 @@ async def run_interactive(init_config: AppInitConfig, session_id: str | None = N
214
249
 
215
250
  # Create status provider for bottom toolbar
216
251
  def _status_provider() -> REPLStatusSnapshot:
217
- agent: Agent | None = None
218
- # Get the first active agent (there should only be one in interactive mode)
219
- active_agents = components.executor.context.active_agents
220
- if active_agents:
221
- agent = next(iter(active_agents.values()), None)
222
-
223
252
  # Check for updates (returns None if uv not available)
224
253
  update_message = get_update_message()
225
254
 
226
- return build_repl_status_snapshot(agent=agent, update_message=update_message)
255
+ return build_repl_status_snapshot(
256
+ agent=components.executor.context.current_agent, update_message=update_message
257
+ )
227
258
 
228
259
  # Set up input provider for interactive mode
229
260
  input_provider: ui.InputProviderABC = ui.PromptToolkitInput(status_provider=_status_provider)
@@ -262,14 +293,19 @@ async def run_interactive(init_config: AppInitConfig, session_id: str | None = N
262
293
 
263
294
  try:
264
295
  await initialize_session(components.executor, components.event_queue, session_id=session_id)
296
+ _backfill_session_model_config(
297
+ components.executor.context.current_agent,
298
+ init_config.model,
299
+ components.config.main_model,
300
+ is_new_session=session_id is None,
301
+ )
265
302
 
266
303
  def _get_active_session_id() -> str | None:
267
304
  """Get the current active session ID dynamically.
268
305
 
269
306
  This is necessary because /clear command creates a new session with a different ID.
270
307
  """
271
- active_ids = components.executor.context.agent_manager.active_session_ids()
272
- return active_ids[0] if active_ids else None
308
+ return components.executor.context.current_session_id()
273
309
 
274
310
  # Input
275
311
  await input_provider.start()
@@ -1,4 +1,4 @@
1
- """Version checking utilities for klaude-code."""
1
+ """Self-update and version utilities for klaude-code."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -8,8 +8,14 @@ import subprocess
8
8
  import threading
9
9
  import time
10
10
  import urllib.request
11
+ from importlib.metadata import PackageNotFoundError
12
+ from importlib.metadata import version as pkg_version
11
13
  from typing import NamedTuple
12
14
 
15
+ import typer
16
+
17
+ from klaude_code.trace import log
18
+
13
19
  PACKAGE_NAME = "klaude-code"
14
20
  PYPI_URL = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
15
21
  CHECK_INTERVAL_SECONDS = 3600 # Check at most once per hour
@@ -160,4 +166,106 @@ def get_update_message() -> str | None:
160
166
  info = check_for_updates()
161
167
  if info is None or not info.update_available:
162
168
  return None
163
- return f"New version available: {info.latest}. Please run `uv tool upgrade {PACKAGE_NAME}` to upgrade."
169
+ return f"New version available: {info.latest}. Please run `klaude upgrade` to upgrade."
170
+
171
+
172
+ def _print_version() -> None:
173
+ try:
174
+ ver = pkg_version(PACKAGE_NAME)
175
+ except PackageNotFoundError:
176
+ ver = "unknown"
177
+ except Exception:
178
+ ver = "unknown"
179
+ print(f"{PACKAGE_NAME} {ver}")
180
+
181
+
182
+ def version_option_callback(value: bool) -> None:
183
+ """Show version and exit."""
184
+ if value:
185
+ _print_version()
186
+ raise typer.Exit(0)
187
+
188
+
189
+ def version_command() -> None:
190
+ """Show version and exit."""
191
+
192
+ _print_version()
193
+
194
+
195
+ def update_command(
196
+ check: bool = typer.Option(
197
+ False,
198
+ "--check",
199
+ help="Check for updates and exit without upgrading",
200
+ ),
201
+ ) -> None:
202
+ """Upgrade klaude-code when installed via `uv tool`."""
203
+
204
+ info = check_for_updates_blocking()
205
+
206
+ if check:
207
+ if info is None:
208
+ log(("Error: `uv` is not available; cannot check for updates.", "red"))
209
+ log(f"Install uv, then run `uv tool upgrade {PACKAGE_NAME}`.")
210
+ raise typer.Exit(1)
211
+
212
+ installed_display = info.installed or "unknown"
213
+ latest_display = info.latest or "unknown"
214
+ status = "update available" if info.update_available else "up to date"
215
+
216
+ log(f"{PACKAGE_NAME} installed: {installed_display}")
217
+ log(f"{PACKAGE_NAME} latest: {latest_display}")
218
+ log(f"Status: {status}")
219
+
220
+ if info.update_available:
221
+ log("Run `klaude upgrade` to upgrade.")
222
+
223
+ return
224
+
225
+ if shutil.which("uv") is None:
226
+ log(("Error: `uv` not found in PATH.", "red"))
227
+ log(f"To update, install uv and run `uv tool upgrade {PACKAGE_NAME}`.")
228
+ raise typer.Exit(1)
229
+
230
+ log(f"Running `uv tool upgrade {PACKAGE_NAME}`...")
231
+ result = subprocess.run(["uv", "tool", "upgrade", PACKAGE_NAME], check=False)
232
+ if result.returncode != 0:
233
+ log((f"Error: update failed (exit code {result.returncode}).", "red"))
234
+ raise typer.Exit(result.returncode or 1)
235
+
236
+ log("Update complete. Please re-run `klaude` to use the new version.")
237
+
238
+
239
+ def register_self_update_commands(app: typer.Typer) -> None:
240
+ """Register self-update and version subcommands to the given Typer app."""
241
+
242
+ app.command("update")(update_command)
243
+ app.command("upgrade", help="Alias for `klaude update`.")(update_command)
244
+ app.command("version", help="Alias for `klaude --version`.")(version_command)
245
+
246
+
247
+ def check_for_updates_blocking() -> VersionInfo | None:
248
+ """Check for updates to klaude-code synchronously.
249
+
250
+ This is intended for CLI commands (e.g. `klaude update --check`) that need
251
+ a deterministic result instead of the async cached behavior.
252
+
253
+ Returns:
254
+ VersionInfo if uv is available, otherwise None.
255
+ """
256
+
257
+ if not _has_uv():
258
+ return None
259
+
260
+ installed = _get_installed_version()
261
+ latest = _get_latest_version()
262
+
263
+ update_available = False
264
+ if installed and latest:
265
+ update_available = _compare_versions(installed, latest)
266
+
267
+ return VersionInfo(
268
+ installed=installed,
269
+ latest=latest,
270
+ update_available=update_available,
271
+ )
@@ -28,6 +28,7 @@ def ensure_commands_loaded() -> None:
28
28
 
29
29
  # Import and register commands in display order
30
30
  from .clear_cmd import ClearCommand
31
+ from .debug_cmd import DebugCommand
31
32
  from .diff_cmd import DiffCommand
32
33
  from .export_cmd import ExportCommand
33
34
  from .export_online_cmd import ExportOnlineCommand
@@ -46,12 +47,13 @@ def ensure_commands_loaded() -> None:
46
47
  register(ThinkingCommand())
47
48
  register(ModelCommand())
48
49
  load_prompt_commands()
49
- register(ClearCommand())
50
50
  register(StatusCommand())
51
51
  register(DiffCommand())
52
52
  register(HelpCommand())
53
53
  register(ReleaseNotesCommand())
54
54
  register(TerminalSetupCommand())
55
+ register(DebugCommand())
56
+ register(ClearCommand())
55
57
 
56
58
  # Load prompt-based commands (appended after built-in commands)
57
59
 
@@ -60,6 +62,7 @@ def ensure_commands_loaded() -> None:
60
62
  def __getattr__(name: str) -> object:
61
63
  _commands_map = {
62
64
  "ClearCommand": "clear_cmd",
65
+ "DebugCommand": "debug_cmd",
63
66
  "DiffCommand": "diff_cmd",
64
67
  "ExportCommand": "export_cmd",
65
68
  "ExportOnlineCommand": "export_online_cmd",
@@ -1,11 +1,6 @@
1
- from typing import TYPE_CHECKING
2
-
3
- from klaude_code.command.command_abc import CommandABC, CommandResult, InputAction
1
+ from klaude_code.command.command_abc import Agent, CommandABC, CommandResult, InputAction
4
2
  from klaude_code.protocol import commands
5
3
 
6
- if TYPE_CHECKING:
7
- from klaude_code.core.agent import Agent
8
-
9
4
 
10
5
  class ClearCommand(CommandABC):
11
6
  """Clear current session and start a new conversation"""
@@ -18,5 +13,5 @@ class ClearCommand(CommandABC):
18
13
  def summary(self) -> str:
19
14
  return "Clear conversation history and free up context"
20
15
 
21
- async def run(self, raw: str, agent: "Agent") -> CommandResult:
16
+ async def run(self, raw: str, agent: Agent) -> CommandResult:
22
17
  return CommandResult(actions=[InputAction.clear()])
@@ -1,14 +1,37 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from enum import Enum
3
- from typing import TYPE_CHECKING
3
+ from typing import Protocol
4
4
 
5
5
  from pydantic import BaseModel
6
6
 
7
- from klaude_code.protocol import commands
7
+ from klaude_code.llm import LLMClientABC
8
+ from klaude_code.protocol import commands, llm_param
8
9
  from klaude_code.protocol import events as protocol_events
10
+ from klaude_code.session.session import Session
9
11
 
10
- if TYPE_CHECKING:
11
- from klaude_code.core.agent import Agent
12
+
13
+ class AgentProfile(Protocol):
14
+ """Protocol for the agent's active model profile."""
15
+
16
+ @property
17
+ def llm_client(self) -> LLMClientABC: ...
18
+
19
+ @property
20
+ def system_prompt(self) -> str | None: ...
21
+
22
+ @property
23
+ def tools(self) -> list[llm_param.ToolSchema]: ...
24
+
25
+
26
+ class Agent(Protocol):
27
+ """Protocol for Agent objects passed to commands."""
28
+
29
+ session: Session
30
+
31
+ @property
32
+ def profile(self) -> AgentProfile | None: ...
33
+
34
+ def get_llm_client(self) -> LLMClientABC: ...
12
35
 
13
36
 
14
37
  class InputActionType(str, Enum):
@@ -80,8 +103,13 @@ class CommandABC(ABC):
80
103
  """Whether this command support additional parameters."""
81
104
  return False
82
105
 
106
+ @property
107
+ def placeholder(self) -> str:
108
+ """Placeholder text for additional parameters in help display."""
109
+ return "additional instructions"
110
+
83
111
  @abstractmethod
84
- async def run(self, raw: str, agent: "Agent") -> CommandResult:
112
+ async def run(self, raw: str, agent: Agent) -> CommandResult:
85
113
  """
86
114
  Execute the command.
87
115
 
@@ -0,0 +1,79 @@
1
+ from klaude_code.command.command_abc import Agent, CommandABC, CommandResult
2
+ from klaude_code.protocol import commands, events, model
3
+ from klaude_code.trace import DebugType, get_current_log_file, is_debug_enabled, set_debug_logging
4
+
5
+
6
+ def _format_status() -> str:
7
+ """Format the current debug status for display."""
8
+ if not is_debug_enabled():
9
+ return "Debug: OFF"
10
+
11
+ log_file = get_current_log_file()
12
+ log_path_str = str(log_file) if log_file else "(console)"
13
+ return f"Debug: ON\nLog file: {log_path_str}"
14
+
15
+
16
+ def _parse_debug_filters(raw: str) -> set[DebugType] | None:
17
+ filters: set[DebugType] = set()
18
+ for chunk in raw.split(","):
19
+ normalized = chunk.strip().lower().replace("-", "_")
20
+ if not normalized:
21
+ continue
22
+ try:
23
+ filters.add(DebugType(normalized))
24
+ except ValueError as exc:
25
+ raise ValueError(normalized) from exc
26
+ return filters or None
27
+
28
+
29
+ class DebugCommand(CommandABC):
30
+ """Toggle debug mode and configure debug filters."""
31
+
32
+ @property
33
+ def name(self) -> commands.CommandName:
34
+ return commands.CommandName.DEBUG
35
+
36
+ @property
37
+ def summary(self) -> str:
38
+ return "Toggle debug mode (optional: filter types)"
39
+
40
+ @property
41
+ def support_addition_params(self) -> bool:
42
+ return True
43
+
44
+ @property
45
+ def placeholder(self) -> str:
46
+ return "filter types"
47
+
48
+ async def run(self, raw: str, agent: Agent) -> CommandResult:
49
+ raw = raw.strip()
50
+
51
+ # /debug (no args) - enable debug
52
+ if not raw:
53
+ set_debug_logging(True, write_to_file=True)
54
+ return self._message_result(agent, _format_status())
55
+
56
+ # /debug <filters> - enable with filters
57
+ try:
58
+ filters = _parse_debug_filters(raw)
59
+ if filters:
60
+ set_debug_logging(True, write_to_file=True, filters=filters)
61
+ filter_names = ", ".join(sorted(dt.value for dt in filters))
62
+ return self._message_result(agent, f"Filters: {filter_names}\n{_format_status()}")
63
+ except ValueError:
64
+ pass
65
+
66
+ return self._message_result(agent, f"Invalid filter: {raw}\nValid: {', '.join(dt.value for dt in DebugType)}")
67
+
68
+ def _message_result(self, agent: "Agent", content: str) -> CommandResult:
69
+ return CommandResult(
70
+ events=[
71
+ events.DeveloperMessageEvent(
72
+ session_id=agent.session.id,
73
+ item=model.DeveloperMessageItem(
74
+ content=content,
75
+ command_output=model.CommandOutput(command_name=self.name),
76
+ ),
77
+ )
78
+ ]
79
+ )
@@ -1,13 +1,9 @@
1
1
  import subprocess
2
2
  from pathlib import Path
3
- from typing import TYPE_CHECKING
4
3
 
5
- from klaude_code.command.command_abc import CommandABC, CommandResult
4
+ from klaude_code.command.command_abc import Agent, CommandABC, CommandResult
6
5
  from klaude_code.protocol import commands, events, model
7
6
 
8
- if TYPE_CHECKING:
9
- from klaude_code.core.agent import Agent
10
-
11
7
 
12
8
  class DiffCommand(CommandABC):
13
9
  """Show git diff for the current repository."""
@@ -20,7 +16,7 @@ class DiffCommand(CommandABC):
20
16
  def summary(self) -> str:
21
17
  return "Show git diff"
22
18
 
23
- async def run(self, raw: str, agent: "Agent") -> CommandResult:
19
+ async def run(self, raw: str, agent: Agent) -> CommandResult:
24
20
  try:
25
21
  # Check if current directory is in a git repository
26
22
  git_check = subprocess.run(
@@ -2,15 +2,11 @@ from __future__ import annotations
2
2
 
3
3
  import subprocess
4
4
  from pathlib import Path
5
- from typing import TYPE_CHECKING
6
5
 
7
- from klaude_code.command.command_abc import CommandABC, CommandResult
6
+ from klaude_code.command.command_abc import Agent, CommandABC, CommandResult
8
7
  from klaude_code.protocol import commands, events, model
9
8
  from klaude_code.session.export import build_export_html, get_default_export_path
10
9
 
11
- if TYPE_CHECKING:
12
- from klaude_code.core.agent import Agent
13
-
14
10
 
15
11
  class ExportCommand(CommandABC):
16
12
  """Export the current session into a standalone HTML transcript."""
@@ -25,7 +21,11 @@ class ExportCommand(CommandABC):
25
21
 
26
22
  @property
27
23
  def support_addition_params(self) -> bool:
28
- return False
24
+ return True
25
+
26
+ @property
27
+ def placeholder(self) -> str:
28
+ return "output path"
29
29
 
30
30
  @property
31
31
  def is_interactive(self) -> bool:
@@ -33,7 +33,7 @@ class ExportCommand(CommandABC):
33
33
 
34
34
  async def run(self, raw: str, agent: Agent) -> CommandResult:
35
35
  try:
36
- output_path = self._resolve_output_path("", agent)
36
+ output_path = self._resolve_output_path(raw, agent)
37
37
  html_doc = self._build_html(agent)
38
38
  output_path.parent.mkdir(parents=True, exist_ok=True)
39
39
  output_path.write_text(html_doc, encoding="utf-8")