klaude-code 1.2.1__py3-none-any.whl → 1.2.3__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 (140) hide show
  1. klaude_code/cli/main.py +9 -4
  2. klaude_code/cli/runtime.py +42 -43
  3. klaude_code/command/__init__.py +7 -5
  4. klaude_code/command/clear_cmd.py +6 -29
  5. klaude_code/command/command_abc.py +44 -8
  6. klaude_code/command/diff_cmd.py +33 -27
  7. klaude_code/command/export_cmd.py +18 -26
  8. klaude_code/command/help_cmd.py +10 -8
  9. klaude_code/command/model_cmd.py +11 -40
  10. klaude_code/command/{prompt-update-dev-doc.md → prompt-dev-docs-update.md} +3 -2
  11. klaude_code/command/{prompt-dev-doc.md → prompt-dev-docs.md} +3 -2
  12. klaude_code/command/prompt-init.md +2 -5
  13. klaude_code/command/prompt_command.py +6 -6
  14. klaude_code/command/refresh_cmd.py +4 -5
  15. klaude_code/command/registry.py +16 -19
  16. klaude_code/command/terminal_setup_cmd.py +12 -11
  17. klaude_code/config/__init__.py +4 -0
  18. klaude_code/config/config.py +25 -26
  19. klaude_code/config/list_model.py +8 -3
  20. klaude_code/config/select_model.py +1 -1
  21. klaude_code/const/__init__.py +1 -1
  22. klaude_code/core/__init__.py +0 -3
  23. klaude_code/core/agent.py +25 -50
  24. klaude_code/core/executor.py +268 -101
  25. klaude_code/core/prompt.py +12 -12
  26. klaude_code/core/{prompt → prompts}/prompt-gemini.md +1 -1
  27. klaude_code/core/reminders.py +76 -95
  28. klaude_code/core/task.py +21 -14
  29. klaude_code/core/tool/__init__.py +45 -11
  30. klaude_code/core/tool/file/apply_patch.py +5 -1
  31. klaude_code/core/tool/file/apply_patch_tool.py +11 -13
  32. klaude_code/core/tool/file/edit_tool.py +27 -23
  33. klaude_code/core/tool/file/multi_edit_tool.py +15 -17
  34. klaude_code/core/tool/file/read_tool.py +41 -36
  35. klaude_code/core/tool/file/write_tool.py +13 -15
  36. klaude_code/core/tool/memory/memory_tool.py +85 -68
  37. klaude_code/core/tool/memory/skill_tool.py +10 -12
  38. klaude_code/core/tool/shell/bash_tool.py +24 -22
  39. klaude_code/core/tool/shell/command_safety.py +12 -1
  40. klaude_code/core/tool/sub_agent_tool.py +11 -12
  41. klaude_code/core/tool/todo/todo_write_tool.py +21 -28
  42. klaude_code/core/tool/todo/update_plan_tool.py +14 -24
  43. klaude_code/core/tool/tool_abc.py +3 -4
  44. klaude_code/core/tool/tool_context.py +7 -7
  45. klaude_code/core/tool/tool_registry.py +30 -47
  46. klaude_code/core/tool/tool_runner.py +35 -43
  47. klaude_code/core/tool/truncation.py +14 -20
  48. klaude_code/core/tool/web/mermaid_tool.py +12 -14
  49. klaude_code/core/tool/web/web_fetch_tool.py +15 -17
  50. klaude_code/core/turn.py +19 -7
  51. klaude_code/llm/__init__.py +3 -4
  52. klaude_code/llm/anthropic/client.py +30 -46
  53. klaude_code/llm/anthropic/input.py +4 -11
  54. klaude_code/llm/client.py +29 -8
  55. klaude_code/llm/input_common.py +66 -36
  56. klaude_code/llm/openai_compatible/client.py +42 -84
  57. klaude_code/llm/openai_compatible/input.py +11 -16
  58. klaude_code/llm/openai_compatible/tool_call_accumulator.py +2 -2
  59. klaude_code/llm/openrouter/client.py +40 -289
  60. klaude_code/llm/openrouter/input.py +13 -35
  61. klaude_code/llm/openrouter/reasoning_handler.py +209 -0
  62. klaude_code/llm/registry.py +5 -75
  63. klaude_code/llm/responses/client.py +34 -55
  64. klaude_code/llm/responses/input.py +24 -26
  65. klaude_code/llm/usage.py +109 -0
  66. klaude_code/protocol/__init__.py +4 -0
  67. klaude_code/protocol/events.py +3 -2
  68. klaude_code/protocol/{llm_parameter.py → llm_param.py} +12 -32
  69. klaude_code/protocol/model.py +49 -4
  70. klaude_code/protocol/op.py +18 -16
  71. klaude_code/protocol/op_handler.py +28 -0
  72. klaude_code/{core → protocol}/sub_agent.py +7 -0
  73. klaude_code/session/export.py +150 -70
  74. klaude_code/session/session.py +28 -14
  75. klaude_code/session/templates/export_session.html +180 -42
  76. klaude_code/trace/__init__.py +2 -2
  77. klaude_code/trace/log.py +11 -5
  78. klaude_code/ui/__init__.py +91 -8
  79. klaude_code/ui/core/__init__.py +1 -0
  80. klaude_code/ui/core/display.py +103 -0
  81. klaude_code/ui/core/input.py +71 -0
  82. klaude_code/ui/modes/__init__.py +1 -0
  83. klaude_code/ui/modes/debug/__init__.py +1 -0
  84. klaude_code/ui/{base/debug_event_display.py → modes/debug/display.py} +9 -5
  85. klaude_code/ui/modes/exec/__init__.py +1 -0
  86. klaude_code/ui/{base/exec_display.py → modes/exec/display.py} +28 -2
  87. klaude_code/ui/{repl → modes/repl}/__init__.py +5 -6
  88. klaude_code/ui/modes/repl/clipboard.py +152 -0
  89. klaude_code/ui/modes/repl/completers.py +429 -0
  90. klaude_code/ui/modes/repl/display.py +60 -0
  91. klaude_code/ui/modes/repl/event_handler.py +375 -0
  92. klaude_code/ui/modes/repl/input_prompt_toolkit.py +198 -0
  93. klaude_code/ui/modes/repl/key_bindings.py +170 -0
  94. klaude_code/ui/{repl → modes/repl}/renderer.py +109 -132
  95. klaude_code/ui/renderers/assistant.py +21 -0
  96. klaude_code/ui/renderers/common.py +0 -16
  97. klaude_code/ui/renderers/developer.py +18 -18
  98. klaude_code/ui/renderers/diffs.py +36 -14
  99. klaude_code/ui/renderers/errors.py +1 -1
  100. klaude_code/ui/renderers/metadata.py +50 -27
  101. klaude_code/ui/renderers/sub_agent.py +43 -9
  102. klaude_code/ui/renderers/thinking.py +33 -1
  103. klaude_code/ui/renderers/tools.py +212 -20
  104. klaude_code/ui/renderers/user_input.py +19 -23
  105. klaude_code/ui/rich/__init__.py +1 -0
  106. klaude_code/ui/{rich_ext → rich}/searchable_text.py +3 -1
  107. klaude_code/ui/{renderers → rich}/status.py +29 -18
  108. klaude_code/ui/{base → rich}/theme.py +8 -2
  109. klaude_code/ui/terminal/__init__.py +1 -0
  110. klaude_code/ui/{base/terminal_color.py → terminal/color.py} +4 -1
  111. klaude_code/ui/{base/terminal_control.py → terminal/control.py} +1 -0
  112. klaude_code/ui/{base/terminal_notifier.py → terminal/notifier.py} +5 -2
  113. klaude_code/ui/utils/__init__.py +1 -0
  114. klaude_code/ui/{base/utils.py → utils/common.py} +35 -3
  115. {klaude_code-1.2.1.dist-info → klaude_code-1.2.3.dist-info}/METADATA +1 -1
  116. klaude_code-1.2.3.dist-info/RECORD +161 -0
  117. klaude_code/core/clipboard_manifest.py +0 -124
  118. klaude_code/llm/openrouter/tool_call_accumulator.py +0 -80
  119. klaude_code/ui/base/__init__.py +0 -1
  120. klaude_code/ui/base/display_abc.py +0 -36
  121. klaude_code/ui/base/input_abc.py +0 -20
  122. klaude_code/ui/repl/display.py +0 -36
  123. klaude_code/ui/repl/event_handler.py +0 -247
  124. klaude_code/ui/repl/input.py +0 -773
  125. klaude_code/ui/rich_ext/__init__.py +0 -1
  126. klaude_code-1.2.1.dist-info/RECORD +0 -151
  127. /klaude_code/core/{prompt → prompts}/prompt-claude-code.md +0 -0
  128. /klaude_code/core/{prompt → prompts}/prompt-codex.md +0 -0
  129. /klaude_code/core/{prompt → prompts}/prompt-subagent-explore.md +0 -0
  130. /klaude_code/core/{prompt → prompts}/prompt-subagent-oracle.md +0 -0
  131. /klaude_code/core/{prompt → prompts}/prompt-subagent-webfetch.md +0 -0
  132. /klaude_code/core/{prompt → prompts}/prompt-subagent.md +0 -0
  133. /klaude_code/ui/{base → core}/stage_manager.py +0 -0
  134. /klaude_code/ui/{rich_ext → rich}/live.py +0 -0
  135. /klaude_code/ui/{rich_ext → rich}/markdown.py +0 -0
  136. /klaude_code/ui/{rich_ext → rich}/quote.py +0 -0
  137. /klaude_code/ui/{base → terminal}/progress_bar.py +0 -0
  138. /klaude_code/ui/{base → utils}/debouncer.py +0 -0
  139. {klaude_code-1.2.1.dist-info → klaude_code-1.2.3.dist-info}/WHEEL +0 -0
  140. {klaude_code-1.2.1.dist-info → klaude_code-1.2.3.dist-info}/entry_points.txt +0 -0
klaude_code/core/agent.py CHANGED
@@ -5,34 +5,23 @@ from dataclasses import dataclass
5
5
  from typing import Protocol
6
6
 
7
7
  from klaude_code.core.prompt import get_system_prompt as load_system_prompt
8
- from klaude_code.core.reminders import (
9
- Reminder,
10
- get_main_agent_reminders,
11
- get_sub_agent_reminders,
12
- get_vanilla_reminders,
13
- )
14
- from klaude_code.core.sub_agent import get_sub_agent_profile
8
+ from klaude_code.core.reminders import Reminder, load_agent_reminders
15
9
  from klaude_code.core.task import TaskExecutionContext, TaskExecutor
16
- from klaude_code.core.tool.tool_context import TodoContext
17
- from klaude_code.core.tool.tool_registry import (
18
- get_main_agent_tools,
19
- get_registry,
20
- get_sub_agent_tools,
21
- get_vanilla_tools,
22
- )
23
- from klaude_code.llm.client import LLMClientABC
24
- from klaude_code.protocol import events, llm_parameter, model, tools
10
+ from klaude_code.core.tool import TodoContext, get_registry, load_agent_tools
11
+ from klaude_code.llm import LLMClientABC
12
+ from klaude_code.protocol import events, llm_param, model, tools
13
+ from klaude_code.protocol.model import UserInputPayload
25
14
  from klaude_code.session import Session
26
15
  from klaude_code.trace import DebugType, log_debug
27
16
 
28
17
 
29
18
  @dataclass(frozen=True)
30
19
  class AgentProfile:
31
- """Encapsulates the active LLM client plus prompt/tools/reminders."""
20
+ """Encapsulates the active LLM client plus prompts/tools/reminders."""
32
21
 
33
22
  llm_client: LLMClientABC
34
23
  system_prompt: str | None
35
- tools: list[llm_parameter.ToolSchema]
24
+ tools: list[llm_param.ToolSchema]
36
25
  reminders: list[Reminder]
37
26
 
38
27
 
@@ -47,7 +36,7 @@ class ModelProfileProvider(Protocol):
47
36
 
48
37
 
49
38
  class DefaultModelProfileProvider(ModelProfileProvider):
50
- """Default provider backed by global prompt/tool/reminder registries."""
39
+ """Default provider backed by global prompts/tool/reminder registries."""
51
40
 
52
41
  def build_profile(
53
42
  self,
@@ -55,23 +44,11 @@ class DefaultModelProfileProvider(ModelProfileProvider):
55
44
  sub_agent_type: tools.SubAgentType | None = None,
56
45
  ) -> AgentProfile:
57
46
  model_name = llm_client.model_name
58
-
59
- if sub_agent_type is None:
60
- prompt_key = "main"
61
- tool_list = get_main_agent_tools(model_name)
62
- reminders = get_main_agent_reminders(model_name)
63
- else:
64
- prompt_key = get_sub_agent_profile(sub_agent_type).name
65
- tool_list = get_sub_agent_tools(model_name, sub_agent_type)
66
- reminders = get_sub_agent_reminders(model_name)
67
-
68
- system_prompt = load_system_prompt(model_name, prompt_key)
69
-
70
47
  return AgentProfile(
71
48
  llm_client=llm_client,
72
- system_prompt=system_prompt,
73
- tools=tool_list,
74
- reminders=reminders,
49
+ system_prompt=load_system_prompt(model_name, sub_agent_type),
50
+ tools=load_agent_tools(model_name, sub_agent_type),
51
+ reminders=load_agent_reminders(model_name, sub_agent_type),
75
52
  )
76
53
 
77
54
 
@@ -83,11 +60,12 @@ class VanillaModelProfileProvider(ModelProfileProvider):
83
60
  llm_client: LLMClientABC,
84
61
  sub_agent_type: tools.SubAgentType | None = None,
85
62
  ) -> AgentProfile:
63
+ model_name = llm_client.model_name
86
64
  return AgentProfile(
87
65
  llm_client=llm_client,
88
66
  system_prompt=None,
89
- tools=get_vanilla_tools(),
90
- reminders=get_vanilla_reminders(),
67
+ tools=load_agent_tools(model_name, vanilla=True),
68
+ reminders=load_agent_reminders(model_name, vanilla=True),
91
69
  )
92
70
 
93
71
 
@@ -96,11 +74,8 @@ class Agent:
96
74
  self,
97
75
  session: Session,
98
76
  profile: AgentProfile,
99
- *,
100
- model_profile_provider: ModelProfileProvider | None = None,
101
77
  ):
102
78
  self.session: Session = session
103
- self.model_profile_provider: ModelProfileProvider = model_profile_provider or DefaultModelProfileProvider()
104
79
  self.profile: AgentProfile | None = None
105
80
  # Active task executor, if any
106
81
  self._current_task: TaskExecutor | None = None
@@ -124,9 +99,13 @@ class Agent:
124
99
 
125
100
  # Record an interrupt marker in the session history
126
101
  self.session.append_history([model.InterruptItem()])
127
- log_debug(f"Session {self.session.id} interrupted", style="yellow", debug_type=DebugType.EXECUTION)
102
+ log_debug(
103
+ f"Session {self.session.id} interrupted",
104
+ style="yellow",
105
+ debug_type=DebugType.EXECUTION,
106
+ )
128
107
 
129
- async def run_task(self, user_input: str) -> AsyncGenerator[events.Event, None]:
108
+ async def run_task(self, user_input: UserInputPayload) -> AsyncGenerator[events.Event, None]:
130
109
  context = TaskExecutionContext(
131
110
  session_id=self.session.id,
132
111
  profile=self._require_profile(),
@@ -158,7 +137,9 @@ class Agent:
158
137
  return
159
138
 
160
139
  yield events.ReplayHistoryEvent(
161
- events=list(self.session.get_history_item()), updated_at=self.session.updated_at, session_id=self.session.id
140
+ events=list(self.session.get_history_item()),
141
+ updated_at=self.session.updated_at,
142
+ session_id=self.session.id,
162
143
  )
163
144
 
164
145
  async def _process_reminder(self, reminder: Reminder) -> AsyncGenerator[events.DeveloperMessageEvent, None]:
@@ -172,14 +153,8 @@ class Agent:
172
153
  """Apply a fully constructed profile to the agent."""
173
154
 
174
155
  self.profile = profile
175
- self.session.model_name = profile.llm_client.model_name
176
-
177
- def build_model_profile(
178
- self,
179
- llm_client: LLMClientABC,
180
- sub_agent_type: tools.SubAgentType | None = None,
181
- ) -> AgentProfile:
182
- return self.model_profile_provider.build_profile(llm_client, sub_agent_type)
156
+ if not self.session.model_name:
157
+ self.session.model_name = profile.llm_client.model_name
183
158
 
184
159
  def get_llm_client(self) -> LLMClientABC:
185
160
  return self._require_profile().llm_client