koder 0.4.10__tar.gz → 0.4.11__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.
- {koder-0.4.10 → koder-0.4.11}/PKG-INFO +19 -5
- {koder-0.4.10 → koder-0.4.11}/README.md +18 -4
- {koder-0.4.10 → koder-0.4.11}/koder_agent/agentic/agent.py +41 -4
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/client_integration.py +10 -20
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/litellm_oauth.py +2 -2
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/tool_utils.py +16 -13
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/commands.py +4 -4
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/scheduler.py +19 -30
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/client.py +31 -21
- {koder-0.4.10 → koder-0.4.11}/pyproject.toml +1 -1
- {koder-0.4.10 → koder-0.4.11}/.gitignore +0 -0
- {koder-0.4.10 → koder-0.4.11}/LICENSE +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/agentic/skill_guardrail.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/base.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/callback_server.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/cli_handler.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/codex_prompts.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/constants.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/providers/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/providers/antigravity.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/providers/chatgpt.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/providers/claude.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/providers/google.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/auth/token_storage.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/cli.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/config/manager.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/config/models.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/keyboard_listener.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/security.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/session.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/streaming_display.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/file.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/search.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/skill.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/skill_context.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/task.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/tools/web.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/model_info.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.10 → koder-0.4.11}/koder_agent/utils/terminal_theme.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.11
|
|
4
4
|
Summary: An intuitive AI coding assistant and interactive CLI tool that boosts developer productivity with intelligent automation and context-aware support.
|
|
5
5
|
Project-URL: Homepage, https://github.com/feiskyer/koder
|
|
6
6
|
Project-URL: Repository, https://github.com/feiskyer/koder
|
|
@@ -74,14 +74,14 @@ pip install koder
|
|
|
74
74
|
## Quick Start
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
|
-
# 1. Set your API key
|
|
78
|
-
export
|
|
77
|
+
# 1. Set your API key (works with any provider)
|
|
78
|
+
export KODER_API_KEY="your-api-key"
|
|
79
79
|
|
|
80
80
|
# 2. Run Koder
|
|
81
81
|
koder
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
That's it!
|
|
84
|
+
That's it! `KODER_API_KEY` works with any provider - no need to remember provider-specific variable names.
|
|
85
85
|
|
|
86
86
|
### Basic Usage
|
|
87
87
|
|
|
@@ -104,13 +104,27 @@ KODER_MODEL="claude-opus-4-20250514" koder "your prompt"
|
|
|
104
104
|
Koder can be configured via (in priority order):
|
|
105
105
|
|
|
106
106
|
1. **CLI arguments** - Highest priority
|
|
107
|
-
2. **Environment variables** - `
|
|
107
|
+
2. **Environment variables** - Universal `KODER_*` vars override everything
|
|
108
108
|
3. **Config file** - `~/.koder/config.yaml`
|
|
109
109
|
|
|
110
|
+
### Environment Variables
|
|
111
|
+
|
|
112
|
+
| Variable | Description | Example |
|
|
113
|
+
|----------|-------------|---------|
|
|
114
|
+
| `KODER_API_KEY` | Universal API key (works with any provider) | `sk-...` |
|
|
115
|
+
| `KODER_MODEL` | Model to use | `gpt-4o`, `claude-opus-4-20250514` |
|
|
116
|
+
| `KODER_BASE_URL` | Custom API endpoint | `http://localhost:8080/v1` |
|
|
117
|
+
| `KODER_REASONING_EFFORT` | For reasoning models | `low`, `medium`, `high` |
|
|
118
|
+
|
|
119
|
+
`KODER_API_KEY` and `KODER_BASE_URL` take priority over provider-specific variables (like `OPENAI_API_KEY`) and config file settings.
|
|
120
|
+
|
|
110
121
|
### Providers
|
|
111
122
|
|
|
123
|
+
Use `KODER_API_KEY` for any provider, or provider-specific variables:
|
|
124
|
+
|
|
112
125
|
| Provider | Environment Variable | Model Example |
|
|
113
126
|
|----------|---------------------|---------------|
|
|
127
|
+
| Any | `KODER_API_KEY` | Works with all providers |
|
|
114
128
|
| OpenAI | `OPENAI_API_KEY` | `gpt-4o`, `gpt-4.1` |
|
|
115
129
|
| Anthropic | `ANTHROPIC_API_KEY` | `claude-opus-4-20250514` |
|
|
116
130
|
| Google | `GOOGLE_API_KEY` | `gemini/gemini-2.5-pro` |
|
|
@@ -36,14 +36,14 @@ pip install koder
|
|
|
36
36
|
## Quick Start
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
# 1. Set your API key
|
|
40
|
-
export
|
|
39
|
+
# 1. Set your API key (works with any provider)
|
|
40
|
+
export KODER_API_KEY="your-api-key"
|
|
41
41
|
|
|
42
42
|
# 2. Run Koder
|
|
43
43
|
koder
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
That's it!
|
|
46
|
+
That's it! `KODER_API_KEY` works with any provider - no need to remember provider-specific variable names.
|
|
47
47
|
|
|
48
48
|
### Basic Usage
|
|
49
49
|
|
|
@@ -66,13 +66,27 @@ KODER_MODEL="claude-opus-4-20250514" koder "your prompt"
|
|
|
66
66
|
Koder can be configured via (in priority order):
|
|
67
67
|
|
|
68
68
|
1. **CLI arguments** - Highest priority
|
|
69
|
-
2. **Environment variables** - `
|
|
69
|
+
2. **Environment variables** - Universal `KODER_*` vars override everything
|
|
70
70
|
3. **Config file** - `~/.koder/config.yaml`
|
|
71
71
|
|
|
72
|
+
### Environment Variables
|
|
73
|
+
|
|
74
|
+
| Variable | Description | Example |
|
|
75
|
+
|----------|-------------|---------|
|
|
76
|
+
| `KODER_API_KEY` | Universal API key (works with any provider) | `sk-...` |
|
|
77
|
+
| `KODER_MODEL` | Model to use | `gpt-4o`, `claude-opus-4-20250514` |
|
|
78
|
+
| `KODER_BASE_URL` | Custom API endpoint | `http://localhost:8080/v1` |
|
|
79
|
+
| `KODER_REASONING_EFFORT` | For reasoning models | `low`, `medium`, `high` |
|
|
80
|
+
|
|
81
|
+
`KODER_API_KEY` and `KODER_BASE_URL` take priority over provider-specific variables (like `OPENAI_API_KEY`) and config file settings.
|
|
82
|
+
|
|
72
83
|
### Providers
|
|
73
84
|
|
|
85
|
+
Use `KODER_API_KEY` for any provider, or provider-specific variables:
|
|
86
|
+
|
|
74
87
|
| Provider | Environment Variable | Model Example |
|
|
75
88
|
|----------|---------------------|---------------|
|
|
89
|
+
| Any | `KODER_API_KEY` | Works with all providers |
|
|
76
90
|
| OpenAI | `OPENAI_API_KEY` | `gpt-4o`, `gpt-4.1` |
|
|
77
91
|
| Anthropic | `ANTHROPIC_API_KEY` | `claude-opus-4-20250514` |
|
|
78
92
|
| Google | `GOOGLE_API_KEY` | `gemini/gemini-2.5-pro` |
|
|
@@ -19,6 +19,7 @@ from openai._models import construct_type
|
|
|
19
19
|
from openai.types.shared import Reasoning
|
|
20
20
|
from rich.console import Console
|
|
21
21
|
|
|
22
|
+
from ..auth.tool_utils import clean_json_schema
|
|
22
23
|
from ..config import get_config
|
|
23
24
|
from ..mcp import load_mcp_servers
|
|
24
25
|
from ..tools.skill import SkillLoader
|
|
@@ -42,6 +43,36 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
42
43
|
getattr(_EXC, "InternalServerError", Exception),
|
|
43
44
|
)
|
|
44
45
|
|
|
46
|
+
def _is_github_copilot(self) -> bool:
|
|
47
|
+
"""Check if the current model is using GitHub Copilot."""
|
|
48
|
+
return "github_copilot" in str(self.model).lower()
|
|
49
|
+
|
|
50
|
+
def _clean_tools_for_github_copilot(self, tools: list) -> list:
|
|
51
|
+
"""Clean tool schemas for GitHub Copilot compatibility.
|
|
52
|
+
|
|
53
|
+
GitHub Copilot doesn't support $ref/$defs in JSON schemas.
|
|
54
|
+
"""
|
|
55
|
+
if not tools or not self._is_github_copilot():
|
|
56
|
+
return tools
|
|
57
|
+
|
|
58
|
+
for tool in tools:
|
|
59
|
+
if not hasattr(tool, "params_json_schema"):
|
|
60
|
+
continue
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
tool.params_json_schema = clean_json_schema(tool.params_json_schema)
|
|
64
|
+
if hasattr(tool, "strict_json_schema"):
|
|
65
|
+
tool.strict_json_schema = False
|
|
66
|
+
|
|
67
|
+
except Exception as exc:
|
|
68
|
+
logger.debug(
|
|
69
|
+
"Failed to clean tool schema for %s: %s",
|
|
70
|
+
getattr(tool, "name", "unknown"),
|
|
71
|
+
exc,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
return tools
|
|
75
|
+
|
|
45
76
|
def _should_use_responses_api(self) -> bool:
|
|
46
77
|
"""
|
|
47
78
|
GitHub Copilot Codex models are not accessible via /chat/completions.
|
|
@@ -158,12 +189,15 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
158
189
|
conversation_id: str | None = None, # unused for LiteLLM responses
|
|
159
190
|
prompt: Any | None = None,
|
|
160
191
|
) -> ModelResponse:
|
|
192
|
+
# Clean tools for GitHub Copilot compatibility
|
|
193
|
+
cleaned_tools = self._clean_tools_for_github_copilot(tools)
|
|
194
|
+
|
|
161
195
|
if not self._should_use_responses_api():
|
|
162
196
|
return await super().get_response(
|
|
163
197
|
system_instructions,
|
|
164
198
|
input,
|
|
165
199
|
model_settings,
|
|
166
|
-
|
|
200
|
+
cleaned_tools,
|
|
167
201
|
output_schema,
|
|
168
202
|
handoffs,
|
|
169
203
|
tracing,
|
|
@@ -182,7 +216,7 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
182
216
|
system_instructions,
|
|
183
217
|
input,
|
|
184
218
|
model_settings,
|
|
185
|
-
|
|
219
|
+
cleaned_tools,
|
|
186
220
|
output_schema,
|
|
187
221
|
handoffs,
|
|
188
222
|
previous_response_id=previous_response_id,
|
|
@@ -239,12 +273,15 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
239
273
|
conversation_id: str | None = None, # unused for LiteLLM responses
|
|
240
274
|
prompt: Any | None = None,
|
|
241
275
|
):
|
|
276
|
+
# Clean tools for GitHub Copilot compatibility
|
|
277
|
+
cleaned_tools = self._clean_tools_for_github_copilot(tools)
|
|
278
|
+
|
|
242
279
|
if not self._should_use_responses_api():
|
|
243
280
|
async for chunk in super().stream_response(
|
|
244
281
|
system_instructions,
|
|
245
282
|
input,
|
|
246
283
|
model_settings,
|
|
247
|
-
|
|
284
|
+
cleaned_tools,
|
|
248
285
|
output_schema,
|
|
249
286
|
handoffs,
|
|
250
287
|
tracing,
|
|
@@ -265,7 +302,7 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
265
302
|
system_instructions,
|
|
266
303
|
input,
|
|
267
304
|
model_settings,
|
|
268
|
-
|
|
305
|
+
cleaned_tools,
|
|
269
306
|
output_schema,
|
|
270
307
|
handoffs,
|
|
271
308
|
previous_response_id=previous_response_id,
|
|
@@ -216,27 +216,17 @@ def get_provider_auth_info(provider: str) -> Tuple[Optional[str], Optional[Dict[
|
|
|
216
216
|
def map_provider_to_oauth(model_provider: str) -> Optional[str]:
|
|
217
217
|
"""Map a model provider name to OAuth provider name.
|
|
218
218
|
|
|
219
|
+
Only OAuth providers (google, claude, chatgpt, antigravity) return themselves.
|
|
220
|
+
API-based providers (anthropic, openai, gemini, azure, etc.) return None.
|
|
221
|
+
|
|
219
222
|
Args:
|
|
220
|
-
model_provider: Provider name from model config
|
|
223
|
+
model_provider: Provider name from model config
|
|
221
224
|
|
|
222
225
|
Returns:
|
|
223
|
-
OAuth provider name or None if
|
|
224
|
-
|
|
225
|
-
Note:
|
|
226
|
-
OAuth providers use different names than API key providers:
|
|
227
|
-
- google (OAuth) vs gemini (API key)
|
|
228
|
-
- claude (OAuth) vs anthropic (API key)
|
|
229
|
-
- chatgpt (OAuth) vs openai (API key)
|
|
226
|
+
OAuth provider name or None if not an OAuth provider
|
|
230
227
|
"""
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
"claude": "claude",
|
|
237
|
-
"openai": "chatgpt",
|
|
238
|
-
"chatgpt": "chatgpt",
|
|
239
|
-
"antigravity": "antigravity",
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return provider_map.get(model_provider.lower())
|
|
228
|
+
if not model_provider:
|
|
229
|
+
return None
|
|
230
|
+
oauth_providers = {"google", "claude", "chatgpt", "antigravity"}
|
|
231
|
+
provider = model_provider.strip().lower()
|
|
232
|
+
return provider if provider in oauth_providers else None
|
|
@@ -704,7 +704,7 @@ class ClaudeOAuthLLM(CustomLLM):
|
|
|
704
704
|
**kwargs: Any,
|
|
705
705
|
) -> Dict[str, Any]:
|
|
706
706
|
"""Build Anthropic API request body."""
|
|
707
|
-
from .tool_utils import
|
|
707
|
+
from .tool_utils import clean_json_schema, ensure_tool_has_properties
|
|
708
708
|
|
|
709
709
|
# Extract system messages and build anthropic messages
|
|
710
710
|
system_parts = []
|
|
@@ -853,7 +853,7 @@ class ClaudeOAuthLLM(CustomLLM):
|
|
|
853
853
|
else:
|
|
854
854
|
continue
|
|
855
855
|
# Clean schema for Claude
|
|
856
|
-
cleaned_params =
|
|
856
|
+
cleaned_params = clean_json_schema(params)
|
|
857
857
|
cleaned_params = ensure_tool_has_properties(cleaned_params)
|
|
858
858
|
anthropic_tools.append(
|
|
859
859
|
{
|
|
@@ -246,8 +246,9 @@ UNSUPPORTED_KEYWORDS = [
|
|
|
246
246
|
|
|
247
247
|
|
|
248
248
|
# =============================================================================
|
|
249
|
-
# JSON SCHEMA CLEANING FOR
|
|
250
|
-
#
|
|
249
|
+
# JSON SCHEMA CLEANING FOR LLM TOOL CALLS
|
|
250
|
+
# Cleans JSON schemas for providers that don't support advanced features
|
|
251
|
+
# like $ref/$defs (GitHub Copilot, Antigravity, etc.)
|
|
251
252
|
# =============================================================================
|
|
252
253
|
|
|
253
254
|
|
|
@@ -487,8 +488,12 @@ def _fix_required_fields(schema: Any) -> Any:
|
|
|
487
488
|
return result
|
|
488
489
|
|
|
489
490
|
|
|
490
|
-
def
|
|
491
|
-
"""Clean JSON schema for
|
|
491
|
+
def clean_json_schema(schema: Any) -> Dict[str, Any]:
|
|
492
|
+
"""Clean JSON schema for LLM providers that don't support advanced features.
|
|
493
|
+
|
|
494
|
+
Some providers (GitHub Copilot, Antigravity, etc.) don't support $ref/$defs
|
|
495
|
+
or other advanced JSON Schema features. This function cleans the schema
|
|
496
|
+
by converting unsupported features to description hints.
|
|
492
497
|
|
|
493
498
|
Applies the following transformations:
|
|
494
499
|
1a. Convert $ref to description hints
|
|
@@ -497,14 +502,14 @@ def clean_json_schema_for_antigravity(schema: Any) -> Dict[str, Any]:
|
|
|
497
502
|
1d. Add additionalProperties hints
|
|
498
503
|
1e. Move unsupported constraints to description
|
|
499
504
|
2a. Merge allOf schemas
|
|
500
|
-
3. Remove unsupported keywords
|
|
505
|
+
3. Remove unsupported keywords ($ref, $defs, additionalProperties, etc.)
|
|
501
506
|
4. Fix required fields referencing non-existent properties
|
|
502
507
|
|
|
503
508
|
Args:
|
|
504
509
|
schema: JSON schema to clean
|
|
505
510
|
|
|
506
511
|
Returns:
|
|
507
|
-
Cleaned schema
|
|
512
|
+
Cleaned schema compatible with all LLM providers
|
|
508
513
|
"""
|
|
509
514
|
if not schema or not isinstance(schema, dict):
|
|
510
515
|
return {"type": "object", "properties": {}}
|
|
@@ -610,7 +615,7 @@ def convert_tools_to_gemini_format(tools: List[Dict[str, Any]]) -> List[Dict[str
|
|
|
610
615
|
}
|
|
611
616
|
if "parameters" in func:
|
|
612
617
|
# Clean schema for Gemini compatibility
|
|
613
|
-
cleaned_params =
|
|
618
|
+
cleaned_params = clean_json_schema(func["parameters"])
|
|
614
619
|
declaration["parameters"] = cleaned_params
|
|
615
620
|
function_declarations.append(declaration)
|
|
616
621
|
|
|
@@ -623,7 +628,7 @@ def convert_tools_to_gemini_format(tools: List[Dict[str, Any]]) -> List[Dict[str
|
|
|
623
628
|
params = tool.get("parameters") or tool.get("input_schema") or tool.get("inputSchema")
|
|
624
629
|
if params:
|
|
625
630
|
# Clean schema for Gemini compatibility
|
|
626
|
-
cleaned_params =
|
|
631
|
+
cleaned_params = clean_json_schema(params)
|
|
627
632
|
declaration["parameters"] = cleaned_params
|
|
628
633
|
function_declarations.append(declaration)
|
|
629
634
|
|
|
@@ -633,9 +638,7 @@ def convert_tools_to_gemini_format(tools: List[Dict[str, Any]]) -> List[Dict[str
|
|
|
633
638
|
for decl in tool["functionDeclarations"]:
|
|
634
639
|
cleaned_decl = dict(decl)
|
|
635
640
|
if "parameters" in cleaned_decl:
|
|
636
|
-
cleaned_decl["parameters"] =
|
|
637
|
-
cleaned_decl["parameters"]
|
|
638
|
-
)
|
|
641
|
+
cleaned_decl["parameters"] = clean_json_schema(cleaned_decl["parameters"])
|
|
639
642
|
function_declarations.append(cleaned_decl)
|
|
640
643
|
|
|
641
644
|
if not function_declarations:
|
|
@@ -682,7 +685,7 @@ def convert_tools_to_claude_format(
|
|
|
682
685
|
for decl in tool["functionDeclarations"]:
|
|
683
686
|
cleaned = dict(decl)
|
|
684
687
|
if "parameters" in cleaned:
|
|
685
|
-
cleaned["parameters"] =
|
|
688
|
+
cleaned["parameters"] = clean_json_schema(cleaned["parameters"])
|
|
686
689
|
cleaned["parameters"] = ensure_tool_has_properties(cleaned["parameters"])
|
|
687
690
|
function_declarations.append(cleaned)
|
|
688
691
|
continue
|
|
@@ -703,7 +706,7 @@ def convert_tools_to_claude_format(
|
|
|
703
706
|
)
|
|
704
707
|
|
|
705
708
|
# Clean schema
|
|
706
|
-
cleaned_params =
|
|
709
|
+
cleaned_params = clean_json_schema(params)
|
|
707
710
|
cleaned_params = ensure_tool_has_properties(cleaned_params)
|
|
708
711
|
|
|
709
712
|
# Optionally inject parameter signatures into description (tool hardening)
|
|
@@ -71,16 +71,16 @@ class ClearCommand(SlashCommand):
|
|
|
71
71
|
|
|
72
72
|
new_sid = default_session_local_ms()
|
|
73
73
|
|
|
74
|
-
# Clear screen
|
|
75
74
|
try:
|
|
76
75
|
import sys as _sys
|
|
77
76
|
|
|
78
|
-
_sys.stdout.
|
|
79
|
-
|
|
77
|
+
if _sys.stdout.isatty():
|
|
78
|
+
_sys.stdout.write("\033[2J\033[H")
|
|
79
|
+
_sys.stdout.flush()
|
|
80
80
|
except Exception:
|
|
81
81
|
pass
|
|
82
82
|
|
|
83
|
-
return f"session_switch:{new_sid}"
|
|
83
|
+
return f"session_switch:{new_sid}"
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
class StatusCommand(SlashCommand):
|
|
@@ -188,6 +188,7 @@ class AgentScheduler:
|
|
|
188
188
|
# Track cancellation state with token for immediate response
|
|
189
189
|
cancel_token = CancellationToken()
|
|
190
190
|
cancelled = False
|
|
191
|
+
execution_error = None # Track errors for handling after Live context exits
|
|
191
192
|
|
|
192
193
|
async def handle_escape():
|
|
193
194
|
"""Callback when ESC key is pressed."""
|
|
@@ -203,11 +204,14 @@ class AgentScheduler:
|
|
|
203
204
|
esc_hint_shown = True
|
|
204
205
|
|
|
205
206
|
def clear_esc_hint():
|
|
206
|
-
|
|
207
|
-
if esc_hint_shown:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
nonlocal esc_hint_shown
|
|
208
|
+
if esc_hint_shown and sys.stdout.isatty():
|
|
209
|
+
try:
|
|
210
|
+
sys.stdout.write("\033[A\033[2K")
|
|
211
|
+
sys.stdout.flush()
|
|
212
|
+
except Exception:
|
|
213
|
+
pass
|
|
214
|
+
esc_hint_shown = False
|
|
211
215
|
|
|
212
216
|
# Use Rich Live for proper formatting during streaming
|
|
213
217
|
with Live(
|
|
@@ -218,20 +222,15 @@ class AgentScheduler:
|
|
|
218
222
|
vertical_overflow="crop",
|
|
219
223
|
) as live:
|
|
220
224
|
try:
|
|
221
|
-
# Wrap event loop with ESC listener
|
|
222
225
|
async with escape_listener(on_escape=handle_escape, enabled=esc_enabled):
|
|
223
|
-
# Process streaming events with cancellation support
|
|
224
|
-
# iter_with_cancellation allows immediate break when ESC is pressed
|
|
225
226
|
stream_iter = result.stream_events()
|
|
226
227
|
async for event in iter_with_cancellation(stream_iter, cancel_token):
|
|
227
|
-
# Check if cancelled (redundant but explicit)
|
|
228
228
|
if cancelled:
|
|
229
229
|
break
|
|
230
230
|
|
|
231
231
|
try:
|
|
232
232
|
should_update = False
|
|
233
233
|
|
|
234
|
-
# Handle raw response events (token-by-token streaming)
|
|
235
234
|
if isinstance(event, RawResponsesStreamEvent):
|
|
236
235
|
if isinstance(event.data, ResponseTextDeltaEvent):
|
|
237
236
|
delta_text = event.data.delta
|
|
@@ -242,7 +241,6 @@ class AgentScheduler:
|
|
|
242
241
|
output_index, delta_text
|
|
243
242
|
)
|
|
244
243
|
|
|
245
|
-
# Handle run item events (tool calls, outputs, etc.)
|
|
246
244
|
elif isinstance(event, RunItemStreamEvent):
|
|
247
245
|
if event.name == "tool_called":
|
|
248
246
|
if (
|
|
@@ -267,7 +265,6 @@ class AgentScheduler:
|
|
|
267
265
|
elif event.name == "message_output_created":
|
|
268
266
|
pass
|
|
269
267
|
elif event.name == "handoff_requested":
|
|
270
|
-
# Handle agent handoff as a special tool call
|
|
271
268
|
should_update = display_manager.handle_tool_called(
|
|
272
269
|
type(
|
|
273
270
|
"HandoffItem",
|
|
@@ -286,7 +283,6 @@ class AgentScheduler:
|
|
|
286
283
|
)()
|
|
287
284
|
)
|
|
288
285
|
elif event.name == "handoff_occured":
|
|
289
|
-
# Handle as tool output
|
|
290
286
|
should_update = display_manager.handle_tool_output(
|
|
291
287
|
type(
|
|
292
288
|
"HandoffOutput",
|
|
@@ -295,44 +291,37 @@ class AgentScheduler:
|
|
|
295
291
|
)()
|
|
296
292
|
)
|
|
297
293
|
elif event.name == "reasoning_item_created":
|
|
298
|
-
# Don't show reasoning steps in display
|
|
299
294
|
pass
|
|
300
295
|
|
|
301
|
-
# Handle agent updates (handoffs, etc.)
|
|
302
296
|
elif isinstance(event, AgentUpdatedStreamEvent):
|
|
303
|
-
# This is handled by handoff events above
|
|
304
297
|
pass
|
|
305
298
|
|
|
306
|
-
# Update Rich Live display
|
|
307
299
|
if should_update:
|
|
308
300
|
current_content = display_manager.get_display_content()
|
|
309
|
-
# Handle both string and renderable objects
|
|
310
301
|
if isinstance(current_content, str):
|
|
311
302
|
if current_content.strip():
|
|
312
303
|
live.update(current_content)
|
|
313
|
-
elif current_content:
|
|
304
|
+
elif current_content:
|
|
314
305
|
live.update(current_content)
|
|
315
306
|
|
|
316
307
|
except Exception as e:
|
|
317
|
-
# Log event processing errors but continue streaming
|
|
318
308
|
console.print(f"[dim red]Event processing error: {e}[/dim red]")
|
|
319
|
-
continue
|
|
320
309
|
|
|
321
310
|
except Exception as e:
|
|
322
|
-
|
|
323
|
-
error_msg = f"Execution error: {str(e)}"
|
|
324
|
-
console.print(f"[red]{error_msg}[/red]")
|
|
325
|
-
# Clear the display manager and return early
|
|
326
|
-
display_manager.finalize_text_sections()
|
|
327
|
-
clear_esc_hint() # Clear ESC hint on error path too
|
|
328
|
-
return f"{error_msg}\n\nPlease provide new instructions."
|
|
311
|
+
execution_error = e
|
|
329
312
|
|
|
330
313
|
# After Rich Live context ends, perform intelligent cleanup
|
|
331
314
|
display_manager.finalize_text_sections()
|
|
332
315
|
|
|
333
|
-
# Clear the ESC hint line
|
|
316
|
+
# Clear the ESC hint line (now outside Live context)
|
|
334
317
|
clear_esc_hint()
|
|
335
318
|
|
|
319
|
+
# Handle execution error after Live context has properly closed
|
|
320
|
+
if execution_error is not None:
|
|
321
|
+
error_msg = f"Execution error: {str(execution_error)}"
|
|
322
|
+
console.print(f"[red]{error_msg}[/red]")
|
|
323
|
+
return f"{error_msg}\n\nPlease provide new instructions."
|
|
324
|
+
|
|
336
325
|
# Handle cancellation case
|
|
337
326
|
if cancelled:
|
|
338
327
|
# Rich Live with transient=True clears content on exit, so we need to re-print
|
|
@@ -367,7 +356,7 @@ class AgentScheduler:
|
|
|
367
356
|
|
|
368
357
|
if has_content:
|
|
369
358
|
# Strategy 1: For advanced terminals, clear the scroll buffer region
|
|
370
|
-
if supports_advanced_clearing:
|
|
359
|
+
if supports_advanced_clearing and sys.stdout.isatty():
|
|
371
360
|
try:
|
|
372
361
|
# Clear recent lines from scrollback (terminal-specific)
|
|
373
362
|
if terminal_type == "iTerm.app":
|
|
@@ -190,11 +190,11 @@ def _resolve_model_settings():
|
|
|
190
190
|
|
|
191
191
|
|
|
192
192
|
def _get_provider_api_key(config, config_manager, provider: str):
|
|
193
|
-
"""Get
|
|
193
|
+
"""Get API key with priority: KODER_API_KEY > OAuth > ENV > Config."""
|
|
194
|
+
koder_api_key = os.environ.get("KODER_API_KEY")
|
|
195
|
+
if koder_api_key:
|
|
196
|
+
return koder_api_key
|
|
194
197
|
|
|
195
|
-
Priority: OAuth tokens > Config > Environment variables
|
|
196
|
-
"""
|
|
197
|
-
# Check for OAuth tokens first
|
|
198
198
|
try:
|
|
199
199
|
from ..auth.client_integration import get_oauth_api_key, map_provider_to_oauth
|
|
200
200
|
|
|
@@ -204,9 +204,8 @@ def _get_provider_api_key(config, config_manager, provider: str):
|
|
|
204
204
|
if oauth_key:
|
|
205
205
|
return oauth_key
|
|
206
206
|
except ImportError:
|
|
207
|
-
pass
|
|
207
|
+
pass
|
|
208
208
|
|
|
209
|
-
# Fall back to config/env vars
|
|
210
209
|
env_var_name = _get_provider_env_var_name(provider)
|
|
211
210
|
config_value = config.model.api_key if config.model.provider.lower() == provider else None
|
|
212
211
|
return config_manager.get_effective_value(config_value, env_var_name)
|
|
@@ -373,15 +372,18 @@ def get_model_name():
|
|
|
373
372
|
|
|
374
373
|
|
|
375
374
|
def get_api_key():
|
|
376
|
-
"""Get
|
|
375
|
+
"""Get API key with priority: KODER_API_KEY > OAuth > ENV > Config."""
|
|
377
376
|
config, config_manager, provider, _, _ = _resolve_model_settings()
|
|
378
377
|
return _get_provider_api_key(config, config_manager, provider)
|
|
379
378
|
|
|
380
379
|
|
|
381
380
|
def get_base_url():
|
|
382
|
-
"""Get
|
|
381
|
+
"""Get base URL with priority: KODER_BASE_URL > ENV > Config."""
|
|
382
|
+
koder_base_url = os.environ.get("KODER_BASE_URL")
|
|
383
|
+
if koder_base_url:
|
|
384
|
+
return koder_base_url
|
|
385
|
+
|
|
383
386
|
config, config_manager, provider, _, _ = _resolve_model_settings()
|
|
384
|
-
# Get the provider-specific base_url env var, or fall back to a generic pattern
|
|
385
387
|
base_url_env_var = PROVIDER_ENV_VARS.get(provider, {}).get(
|
|
386
388
|
"base_url", f"{provider.upper()}_BASE_URL"
|
|
387
389
|
)
|
|
@@ -430,15 +432,19 @@ def get_litellm_model_kwargs() -> dict:
|
|
|
430
432
|
if model.startswith("litellm/"):
|
|
431
433
|
model = model[len("litellm/") :]
|
|
432
434
|
|
|
433
|
-
# Get API key
|
|
434
435
|
api_key = _get_provider_api_key(config, config_manager, provider)
|
|
435
436
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
437
|
+
koder_base_url = os.environ.get("KODER_BASE_URL")
|
|
438
|
+
if koder_base_url:
|
|
439
|
+
base_url = koder_base_url
|
|
440
|
+
else:
|
|
441
|
+
base_url_env_var = PROVIDER_ENV_VARS.get(provider, {}).get(
|
|
442
|
+
"base_url", f"{provider.upper()}_BASE_URL"
|
|
443
|
+
)
|
|
444
|
+
base_url_config = (
|
|
445
|
+
config.model.base_url if config.model.provider.lower() == provider else None
|
|
446
|
+
)
|
|
447
|
+
base_url = config_manager.get_effective_value(base_url_config, base_url_env_var)
|
|
442
448
|
|
|
443
449
|
kwargs = {
|
|
444
450
|
"model": model,
|
|
@@ -632,12 +638,16 @@ def setup_openai_client():
|
|
|
632
638
|
config, config_manager, provider, raw_model, model_from_env
|
|
633
639
|
)
|
|
634
640
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
641
|
+
koder_base_url = os.environ.get("KODER_BASE_URL")
|
|
642
|
+
if koder_base_url:
|
|
643
|
+
base_url = koder_base_url
|
|
644
|
+
else:
|
|
645
|
+
base_url_env_var = PROVIDER_ENV_VARS.get(provider, {}).get("base_url", "OPENAI_BASE_URL")
|
|
646
|
+
base_url_config = (
|
|
647
|
+
config.model.base_url if config.model.provider.lower() == provider else None
|
|
648
|
+
)
|
|
649
|
+
base_url = config_manager.get_effective_value(base_url_config, base_url_env_var)
|
|
639
650
|
|
|
640
|
-
# Use OpenAI native integration for openai/custom providers with API key
|
|
641
651
|
if use_native:
|
|
642
652
|
client = AsyncOpenAI(
|
|
643
653
|
api_key=api_key,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "koder"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.11"
|
|
4
4
|
description = "An intuitive AI coding assistant and interactive CLI tool that boosts developer productivity with intelligent automation and context-aware support."
|
|
5
5
|
authors = [{ name = "Pengfei Ni" }]
|
|
6
6
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|