klaude-code 2.6.0__py3-none-any.whl → 2.8.0__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 (82) hide show
  1. klaude_code/app/runtime.py +1 -1
  2. klaude_code/auth/AGENTS.md +325 -0
  3. klaude_code/auth/__init__.py +17 -1
  4. klaude_code/auth/antigravity/__init__.py +20 -0
  5. klaude_code/auth/antigravity/exceptions.py +17 -0
  6. klaude_code/auth/antigravity/oauth.py +320 -0
  7. klaude_code/auth/antigravity/pkce.py +25 -0
  8. klaude_code/auth/antigravity/token_manager.py +45 -0
  9. klaude_code/auth/base.py +4 -0
  10. klaude_code/auth/claude/oauth.py +29 -9
  11. klaude_code/auth/codex/exceptions.py +4 -0
  12. klaude_code/auth/env.py +19 -15
  13. klaude_code/cli/auth_cmd.py +54 -4
  14. klaude_code/cli/cost_cmd.py +83 -160
  15. klaude_code/cli/list_model.py +50 -0
  16. klaude_code/cli/main.py +99 -9
  17. klaude_code/config/assets/builtin_config.yaml +108 -0
  18. klaude_code/config/builtin_config.py +5 -11
  19. klaude_code/config/config.py +24 -10
  20. klaude_code/const.py +11 -1
  21. klaude_code/core/agent.py +5 -1
  22. klaude_code/core/agent_profile.py +28 -32
  23. klaude_code/core/compaction/AGENTS.md +112 -0
  24. klaude_code/core/compaction/__init__.py +11 -0
  25. klaude_code/core/compaction/compaction.py +707 -0
  26. klaude_code/core/compaction/overflow.py +30 -0
  27. klaude_code/core/compaction/prompts.py +97 -0
  28. klaude_code/core/executor.py +103 -2
  29. klaude_code/core/manager/llm_clients.py +5 -0
  30. klaude_code/core/manager/llm_clients_builder.py +14 -2
  31. klaude_code/core/prompts/prompt-antigravity.md +80 -0
  32. klaude_code/core/prompts/prompt-codex-gpt-5-2.md +335 -0
  33. klaude_code/core/reminders.py +11 -7
  34. klaude_code/core/task.py +126 -0
  35. klaude_code/core/tool/todo/todo_write_tool.py +1 -1
  36. klaude_code/core/turn.py +3 -1
  37. klaude_code/llm/antigravity/__init__.py +3 -0
  38. klaude_code/llm/antigravity/client.py +558 -0
  39. klaude_code/llm/antigravity/input.py +261 -0
  40. klaude_code/llm/registry.py +1 -0
  41. klaude_code/protocol/commands.py +0 -1
  42. klaude_code/protocol/events.py +18 -0
  43. klaude_code/protocol/llm_param.py +1 -0
  44. klaude_code/protocol/message.py +23 -1
  45. klaude_code/protocol/op.py +15 -1
  46. klaude_code/protocol/op_handler.py +5 -0
  47. klaude_code/session/session.py +36 -0
  48. klaude_code/skill/assets/create-plan/SKILL.md +6 -6
  49. klaude_code/skill/loader.py +12 -13
  50. klaude_code/skill/manager.py +3 -3
  51. klaude_code/tui/command/__init__.py +4 -4
  52. klaude_code/tui/command/compact_cmd.py +32 -0
  53. klaude_code/tui/command/copy_cmd.py +1 -1
  54. klaude_code/tui/command/fork_session_cmd.py +114 -18
  55. klaude_code/tui/command/model_picker.py +5 -1
  56. klaude_code/tui/command/thinking_cmd.py +1 -1
  57. klaude_code/tui/commands.py +6 -0
  58. klaude_code/tui/components/command_output.py +1 -1
  59. klaude_code/tui/components/rich/markdown.py +117 -1
  60. klaude_code/tui/components/rich/theme.py +18 -2
  61. klaude_code/tui/components/tools.py +39 -25
  62. klaude_code/tui/components/user_input.py +39 -28
  63. klaude_code/tui/input/AGENTS.md +44 -0
  64. klaude_code/tui/input/__init__.py +5 -2
  65. klaude_code/tui/input/completers.py +10 -14
  66. klaude_code/tui/input/drag_drop.py +146 -0
  67. klaude_code/tui/input/images.py +227 -0
  68. klaude_code/tui/input/key_bindings.py +183 -19
  69. klaude_code/tui/input/paste.py +71 -0
  70. klaude_code/tui/input/prompt_toolkit.py +32 -9
  71. klaude_code/tui/machine.py +26 -1
  72. klaude_code/tui/renderer.py +67 -4
  73. klaude_code/tui/runner.py +19 -3
  74. klaude_code/tui/terminal/image.py +103 -10
  75. klaude_code/tui/terminal/selector.py +81 -7
  76. {klaude_code-2.6.0.dist-info → klaude_code-2.8.0.dist-info}/METADATA +10 -10
  77. {klaude_code-2.6.0.dist-info → klaude_code-2.8.0.dist-info}/RECORD +79 -61
  78. klaude_code/core/prompts/prompt-codex-gpt-5-1-codex-max.md +0 -117
  79. klaude_code/tui/command/terminal_setup_cmd.py +0 -248
  80. klaude_code/tui/input/clipboard.py +0 -152
  81. {klaude_code-2.6.0.dist-info → klaude_code-2.8.0.dist-info}/WHEEL +0 -0
  82. {klaude_code-2.6.0.dist-info → klaude_code-2.8.0.dist-info}/entry_points.txt +0 -0
@@ -178,6 +178,6 @@ async def handle_keyboard_interrupt(executor: Executor) -> None:
178
178
  log("Bye!")
179
179
  session_id = executor.context.current_session_id()
180
180
  if session_id and Session.exists(session_id):
181
- log(("Resume with:", "dim"), (f"klaude --resume-by-id {session_id}", "green"))
181
+ log(("Resume with:", "dim"), (f"klaude --resume {session_id}", "green"))
182
182
  with contextlib.suppress(Exception):
183
183
  await executor.submit(op.InterruptOperation(target_session_id=None))
@@ -0,0 +1,325 @@
1
+ # Adding a New OAuth Provider
2
+
3
+ This document describes all the files and changes required to add a new OAuth-based authentication provider (like `antigravity`, `codex`, or `claude`).
4
+
5
+ ## Overview
6
+
7
+ Adding a new OAuth provider requires changes in these areas:
8
+
9
+ 1. **Protocol Registration** - Register the new protocol enum
10
+ 2. **Auth Module** - Create OAuth flow, token manager, and exceptions
11
+ 3. **LLM Client** - Implement the LLM client for the new protocol
12
+ 4. **Config Integration** - Update config validation to recognize OAuth protocols
13
+ 5. **CLI Commands** - Add login/logout support
14
+ 6. **Model List Display** - Show OAuth status in `klaude list`
15
+ 7. **Builtin Config** - Add provider and models to builtin config
16
+
17
+ ---
18
+
19
+ ## 1. Protocol Registration
20
+
21
+ ### `src/klaude_code/protocol/llm_param.py`
22
+
23
+ Add the new protocol to the `LLMClientProtocol` enum:
24
+
25
+ ```python
26
+ class LLMClientProtocol(Enum):
27
+ # ... existing protocols ...
28
+ ANTIGRAVITY = "antigravity" # Add new protocol
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 2. Auth Module
34
+
35
+ Create a new directory under `src/klaude_code/auth/<provider_name>/` with these files:
36
+
37
+ ### `src/klaude_code/auth/<provider>/pkce.py` (if using PKCE)
38
+
39
+ PKCE utilities for OAuth flow:
40
+
41
+ ```python
42
+ def generate_pkce() -> tuple[str, str]:
43
+ """Generate PKCE code verifier and challenge.
44
+ Returns: Tuple of (verifier, challenge).
45
+ """
46
+ ```
47
+
48
+ ### `src/klaude_code/auth/<provider>/exceptions.py`
49
+
50
+ Define provider-specific exceptions:
51
+
52
+ ```python
53
+ class <Provider>AuthError(Exception): ...
54
+ class <Provider>NotLoggedInError(<Provider>AuthError): ...
55
+ class <Provider>TokenExpiredError(<Provider>AuthError): ...
56
+ class <Provider>OAuthError(<Provider>AuthError): ...
57
+ ```
58
+
59
+ ### `src/klaude_code/auth/<provider>/token_manager.py`
60
+
61
+ Token storage using base classes:
62
+
63
+ ```python
64
+ from klaude_code.auth.base import BaseAuthState, BaseTokenManager
65
+
66
+ class <Provider>AuthState(BaseAuthState):
67
+ """Add provider-specific fields like project_id, email, etc."""
68
+ project_id: str
69
+ email: str | None = None
70
+
71
+ class <Provider>TokenManager(BaseTokenManager[<Provider>AuthState]):
72
+ @property
73
+ def storage_key(self) -> str:
74
+ return "<provider>" # Key in ~/.klaude/klaude-auth.json
75
+ ```
76
+
77
+ ### `src/klaude_code/auth/<provider>/oauth.py`
78
+
79
+ OAuth flow implementation:
80
+
81
+ ```python
82
+ class <Provider>OAuth:
83
+ def login(self) -> <Provider>AuthState: ...
84
+ def refresh(self) -> <Provider>AuthState: ...
85
+ def ensure_valid_token(self) -> tuple[str, str]: ...
86
+ def get_api_key_json(self) -> str: ... # For JSON-encoded credentials
87
+ ```
88
+
89
+ ### `src/klaude_code/auth/<provider>/__init__.py`
90
+
91
+ Export public API:
92
+
93
+ ```python
94
+ from klaude_code.auth.<provider>.exceptions import ...
95
+ from klaude_code.auth.<provider>.oauth import <Provider>OAuth
96
+ from klaude_code.auth.<provider>.token_manager import <Provider>AuthState, <Provider>TokenManager
97
+
98
+ __all__ = [...]
99
+ ```
100
+
101
+ ### `src/klaude_code/auth/__init__.py`
102
+
103
+ Add exports for the new provider.
104
+
105
+ ---
106
+
107
+ ## 3. LLM Client
108
+
109
+ Create a new directory under `src/klaude_code/llm/<provider>/` with these files:
110
+
111
+ ### `src/klaude_code/llm/<provider>/input.py`
112
+
113
+ Message conversion to the provider's API format.
114
+
115
+ ### `src/klaude_code/llm/<provider>/client.py`
116
+
117
+ LLM client implementation:
118
+
119
+ ```python
120
+ from klaude_code.llm.client import LLMClientABC, LLMStreamABC
121
+ from klaude_code.llm.registry import register
122
+
123
+ @register(llm_param.LLMClientProtocol.<PROVIDER>)
124
+ class <Provider>Client(LLMClientABC):
125
+ def __init__(self, config: llm_param.LLMConfigParameter):
126
+ # Initialize token manager and OAuth
127
+ self._token_manager = <Provider>TokenManager()
128
+ self._oauth = <Provider>OAuth(self._token_manager)
129
+
130
+ def _get_credentials(self) -> tuple[str, str]:
131
+ """Get credentials, auto-refreshing if needed."""
132
+ return self._oauth.ensure_valid_token()
133
+
134
+ async def call(self, param: llm_param.LLMCallParameter) -> LLMStreamABC:
135
+ # Get credentials, make API call, return stream
136
+ ```
137
+
138
+ ### `src/klaude_code/llm/<provider>/__init__.py`
139
+
140
+ Export the client class.
141
+
142
+ ### `src/klaude_code/llm/registry.py`
143
+
144
+ Register the protocol to module mapping:
145
+
146
+ ```python
147
+ _PROTOCOL_MODULES: dict[llm_param.LLMClientProtocol, str] = {
148
+ # ... existing mappings ...
149
+ llm_param.LLMClientProtocol.<PROVIDER>: "klaude_code.llm.<provider>",
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 4. Config Integration
156
+
157
+ ### `src/klaude_code/config/config.py`
158
+
159
+ #### `ProviderConfig.is_api_key_missing()`
160
+
161
+ Add the new protocol to the OAuth check:
162
+
163
+ ```python
164
+ def is_api_key_missing(self) -> bool:
165
+ # ... existing checks ...
166
+
167
+ if self.protocol == LLMClientProtocol.<PROVIDER>:
168
+ from klaude_code.auth.<provider>.token_manager import <Provider>TokenManager
169
+ token_manager = <Provider>TokenManager()
170
+ state = token_manager.get_state()
171
+ return state is None
172
+ ```
173
+
174
+ #### `Config.resolve_model_location_prefer_available()`
175
+
176
+ Add the protocol to the "no API key required" set:
177
+
178
+ ```python
179
+ if (
180
+ provider.protocol
181
+ not in {
182
+ llm_param.LLMClientProtocol.CODEX_OAUTH,
183
+ llm_param.LLMClientProtocol.CLAUDE_OAUTH,
184
+ llm_param.LLMClientProtocol.<PROVIDER>, # Add here
185
+ llm_param.LLMClientProtocol.BEDROCK,
186
+ }
187
+ and not api_key
188
+ ):
189
+ ```
190
+
191
+ #### `Config.get_model_config()`
192
+
193
+ Same change as above - add protocol to the set.
194
+
195
+ ---
196
+
197
+ ## 5. CLI Commands
198
+
199
+ ### `src/klaude_code/cli/auth_cmd.py`
200
+
201
+ #### `_select_provider()`
202
+
203
+ Add to the provider selection menu:
204
+
205
+ ```python
206
+ SelectItem(
207
+ title=[("", "<Provider Name> "), ("ansibrightblack", "[OAuth]\n")],
208
+ value="<provider>",
209
+ search_text="<provider>",
210
+ ),
211
+ ```
212
+
213
+ #### `_build_provider_help()`
214
+
215
+ Add provider name to help text:
216
+
217
+ ```python
218
+ names = ["codex", "claude", "<provider>"] + [...]
219
+ ```
220
+
221
+ #### `login_command()`
222
+
223
+ Add login case:
224
+
225
+ ```python
226
+ case "<provider>":
227
+ from klaude_code.auth.<provider>.oauth import <Provider>OAuth
228
+ from klaude_code.auth.<provider>.token_manager import <Provider>TokenManager
229
+
230
+ token_manager = <Provider>TokenManager()
231
+ # Check existing login, run OAuth flow, display result
232
+ ```
233
+
234
+ #### `logout_command()`
235
+
236
+ Add logout case and update help text:
237
+
238
+ ```python
239
+ provider: str = typer.Argument("codex", help="Provider to logout (codex|claude|<provider>)")
240
+
241
+ case "<provider>":
242
+ from klaude_code.auth.<provider>.token_manager import <Provider>TokenManager
243
+ token_manager = <Provider>TokenManager()
244
+ # Check login status, confirm, delete tokens
245
+ ```
246
+
247
+ ---
248
+
249
+ ## 6. Model List Display
250
+
251
+ ### `src/klaude_code/cli/list_model.py`
252
+
253
+ #### Add status display function
254
+
255
+ ```python
256
+ def _get_<provider>_status_rows() -> list[tuple[Text, Text]]:
257
+ """Get <Provider> OAuth login status as (label, value) tuples."""
258
+ from klaude_code.auth.<provider>.token_manager import <Provider>TokenManager
259
+
260
+ rows: list[tuple[Text, Text]] = []
261
+ token_manager = <Provider>TokenManager()
262
+ state = token_manager.get_state()
263
+
264
+ if state is None:
265
+ # Show "Not logged in" with hint
266
+ elif state.is_expired():
267
+ # Show "Token expired" with hint
268
+ else:
269
+ # Show "Logged in" with details (email, project, expires)
270
+
271
+ return rows
272
+ ```
273
+
274
+ #### `_build_provider_info_panel()`
275
+
276
+ Add status display:
277
+
278
+ ```python
279
+ if provider.protocol == LLMClientProtocol.<PROVIDER>:
280
+ for label, value in _get_<provider>_status_rows():
281
+ info_table.add_row(label, value)
282
+ ```
283
+
284
+ ---
285
+
286
+ ## 7. Builtin Config
287
+
288
+ ### `src/klaude_code/config/assets/builtin_config.yaml`
289
+
290
+ Add provider and models:
291
+
292
+ ```yaml
293
+ - provider_name: <provider>
294
+ protocol: <provider>
295
+ model_list:
296
+ - model_name: model-a
297
+ model_id: actual-model-id
298
+ context_limit: 200000
299
+ max_tokens: 64000
300
+ thinking:
301
+ type: enabled
302
+ budget_tokens: 10240
303
+ - model_name: model-b
304
+ model_id: another-model-id
305
+ context_limit: 1048576
306
+ ```
307
+
308
+ ---
309
+
310
+ ## Checklist
311
+
312
+ When adding a new OAuth provider, ensure you've completed:
313
+
314
+ - [ ] Add protocol enum to `llm_param.py`
315
+ - [ ] Create `auth/<provider>/` module (pkce, exceptions, token_manager, oauth, __init__)
316
+ - [ ] Update `auth/__init__.py` exports
317
+ - [ ] Create `llm/<provider>/` module (input, client, __init__)
318
+ - [ ] Register protocol in `llm/registry.py`
319
+ - [ ] Update `config.py` - `is_api_key_missing()` method
320
+ - [ ] Update `config.py` - `resolve_model_location_prefer_available()` method
321
+ - [ ] Update `config.py` - `get_model_config()` method
322
+ - [ ] Update `auth_cmd.py` - provider selection, login, logout
323
+ - [ ] Update `list_model.py` - status display function and panel
324
+ - [ ] Add provider/models to `builtin_config.yaml`
325
+ - [ ] Run `make lint` to verify all changes
@@ -1,8 +1,17 @@
1
1
  """Authentication module.
2
2
 
3
- Currently includes Codex OAuth helpers in ``klaude_code.auth.codex``.
3
+ Includes Codex and Antigravity OAuth helpers.
4
4
  """
5
5
 
6
+ from klaude_code.auth.antigravity import (
7
+ AntigravityAuthError,
8
+ AntigravityAuthState,
9
+ AntigravityNotLoggedInError,
10
+ AntigravityOAuth,
11
+ AntigravityOAuthError,
12
+ AntigravityTokenExpiredError,
13
+ AntigravityTokenManager,
14
+ )
6
15
  from klaude_code.auth.codex import (
7
16
  CodexAuthError,
8
17
  CodexAuthState,
@@ -20,6 +29,13 @@ from klaude_code.auth.env import (
20
29
  )
21
30
 
22
31
  __all__ = [
32
+ "AntigravityAuthError",
33
+ "AntigravityAuthState",
34
+ "AntigravityNotLoggedInError",
35
+ "AntigravityOAuth",
36
+ "AntigravityOAuthError",
37
+ "AntigravityTokenExpiredError",
38
+ "AntigravityTokenManager",
23
39
  "CodexAuthError",
24
40
  "CodexAuthState",
25
41
  "CodexNotLoggedInError",
@@ -0,0 +1,20 @@
1
+ """Antigravity authentication helpers."""
2
+
3
+ from klaude_code.auth.antigravity.exceptions import (
4
+ AntigravityAuthError,
5
+ AntigravityNotLoggedInError,
6
+ AntigravityOAuthError,
7
+ AntigravityTokenExpiredError,
8
+ )
9
+ from klaude_code.auth.antigravity.oauth import AntigravityOAuth
10
+ from klaude_code.auth.antigravity.token_manager import AntigravityAuthState, AntigravityTokenManager
11
+
12
+ __all__ = [
13
+ "AntigravityAuthError",
14
+ "AntigravityAuthState",
15
+ "AntigravityNotLoggedInError",
16
+ "AntigravityOAuth",
17
+ "AntigravityOAuthError",
18
+ "AntigravityTokenExpiredError",
19
+ "AntigravityTokenManager",
20
+ ]
@@ -0,0 +1,17 @@
1
+ """Exceptions for Antigravity authentication."""
2
+
3
+
4
+ class AntigravityAuthError(Exception):
5
+ """Base exception for Antigravity authentication errors."""
6
+
7
+
8
+ class AntigravityNotLoggedInError(AntigravityAuthError):
9
+ """User has not logged in to Antigravity."""
10
+
11
+
12
+ class AntigravityTokenExpiredError(AntigravityAuthError):
13
+ """Token expired and refresh failed."""
14
+
15
+
16
+ class AntigravityOAuthError(AntigravityAuthError):
17
+ """OAuth flow failed."""