koder 0.4.2__tar.gz → 0.4.3__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.2 → koder-0.4.3}/.claude/settings.local.json +2 -1
- koder-0.4.3/GEMINI.md +1 -0
- {koder-0.4.2 → koder-0.4.3}/PKG-INFO +1 -1
- {koder-0.4.2 → koder-0.4.3}/koder_agent/agentic/agent.py +4 -3
- {koder-0.4.2 → koder-0.4.3}/koder_agent/cli.py +1 -29
- koder-0.4.3/koder_agent/core/keyboard_listener.py +202 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/scheduler.py +152 -84
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/client.py +16 -2
- {koder-0.4.2 → koder-0.4.3}/pyproject.toml +1 -1
- {koder-0.4.2 → koder-0.4.3}/.github/dependabot.yml +0 -0
- {koder-0.4.2 → koder-0.4.3}/.gitignore +0 -0
- {koder-0.4.2 → koder-0.4.3}/AGENTS.md +0 -0
- {koder-0.4.2 → koder-0.4.3}/CLAUDE.md +0 -0
- {koder-0.4.2 → koder-0.4.3}/CONTRIBUTING.md +0 -0
- {koder-0.4.2 → koder-0.4.3}/LICENSE +0 -0
- {koder-0.4.2 → koder-0.4.3}/README.md +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/config/manager.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/config/models.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/commands.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/security.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/session.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/streaming_display.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/file.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/search.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/task.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/tools/web.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/model_info.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/tests/test_file_tools.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/tests/test_shell_background.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/tests/test_web.py +0 -0
- {koder-0.4.2 → koder-0.4.3}/uv.lock +0 -0
koder-0.4.3/GEMINI.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CLAUDE.md
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
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
|
|
@@ -75,12 +75,13 @@ async def create_dev_agent(tools) -> Agent:
|
|
|
75
75
|
|
|
76
76
|
# Build model_settings with reasoning if configured
|
|
77
77
|
model_name_str = get_model_name() # Always get string name for max_tokens lookup
|
|
78
|
-
model_settings = ModelSettings(
|
|
78
|
+
model_settings = ModelSettings(
|
|
79
|
+
metadata={"source": "koder"},
|
|
80
|
+
max_tokens=get_maximum_output_tokens(model_name_str),
|
|
81
|
+
)
|
|
79
82
|
if config.model.reasoning_effort is not None:
|
|
80
83
|
effort = None if config.model.reasoning_effort == "none" else config.model.reasoning_effort
|
|
81
84
|
model_settings.reasoning = Reasoning(effort=effort, summary="detailed")
|
|
82
|
-
if "gpt-5" in model_name_str:
|
|
83
|
-
model_settings.verbosity = "high"
|
|
84
85
|
|
|
85
86
|
dev_agent = Agent(
|
|
86
87
|
name="Koder",
|
|
@@ -137,12 +137,6 @@ async def main():
|
|
|
137
137
|
"--stream", action="store_true", help="Force enable streaming mode"
|
|
138
138
|
)
|
|
139
139
|
stream_group.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
|
|
140
|
-
parser.add_argument(
|
|
141
|
-
"--reasoning",
|
|
142
|
-
choices=["none", "minimal", "low", "medium", "high", "null"],
|
|
143
|
-
default=None,
|
|
144
|
-
help=("Reasoning effort for reasoning models (null to disable)"),
|
|
145
|
-
)
|
|
146
140
|
|
|
147
141
|
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
148
142
|
create_mcp_subparsers(subparsers)
|
|
@@ -159,12 +153,7 @@ async def main():
|
|
|
159
153
|
"--stream", action="store_true", help="Force enable streaming mode"
|
|
160
154
|
)
|
|
161
155
|
stream_group.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
|
|
162
|
-
|
|
163
|
-
"--reasoning",
|
|
164
|
-
choices=["none", "minimal", "low", "medium", "high", "null"],
|
|
165
|
-
default=None,
|
|
166
|
-
help=("Reasoning effort for reasoning models (null to disable)"),
|
|
167
|
-
)
|
|
156
|
+
|
|
168
157
|
parser.add_argument(
|
|
169
158
|
"prompt", nargs="*", help="Prompt text (if not provided, starts interactive mode)"
|
|
170
159
|
)
|
|
@@ -181,23 +170,6 @@ async def main():
|
|
|
181
170
|
|
|
182
171
|
return await handle_config_command(args)
|
|
183
172
|
|
|
184
|
-
# Apply reasoning effort override from CLI or ENV (CLI > ENV > Config)
|
|
185
|
-
if config:
|
|
186
|
-
cli_reasoning = getattr(args, "reasoning", None)
|
|
187
|
-
if cli_reasoning is not None:
|
|
188
|
-
if cli_reasoning == "null":
|
|
189
|
-
config.model.reasoning_effort = None
|
|
190
|
-
else:
|
|
191
|
-
config.model.reasoning_effort = cli_reasoning
|
|
192
|
-
else:
|
|
193
|
-
env_reasoning = os.environ.get("KODER_REASONING_EFFORT")
|
|
194
|
-
if env_reasoning is not None:
|
|
195
|
-
env_reasoning_lower = env_reasoning.lower()
|
|
196
|
-
if env_reasoning_lower in ("null", "none", ""):
|
|
197
|
-
config.model.reasoning_effort = None
|
|
198
|
-
elif env_reasoning_lower in ("minimal", "low", "medium", "high"):
|
|
199
|
-
config.model.reasoning_effort = env_reasoning_lower
|
|
200
|
-
|
|
201
173
|
if getattr(args, "resume", False):
|
|
202
174
|
selected = await _prompt_select_session()
|
|
203
175
|
if selected:
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Async keyboard listener for ESC key interruption.
|
|
2
|
+
|
|
3
|
+
This module provides non-blocking keyboard detection for cancelling
|
|
4
|
+
agent operations during streaming execution.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import sys
|
|
9
|
+
from contextlib import asynccontextmanager
|
|
10
|
+
from typing import AsyncIterator, Awaitable, Callable, Optional, TypeVar
|
|
11
|
+
|
|
12
|
+
# Platform-specific imports for Unix terminal control
|
|
13
|
+
if sys.platform != "win32":
|
|
14
|
+
import select
|
|
15
|
+
import termios
|
|
16
|
+
import tty
|
|
17
|
+
|
|
18
|
+
T = TypeVar("T")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CancellationToken:
|
|
22
|
+
"""Token to signal cancellation across async operations."""
|
|
23
|
+
|
|
24
|
+
def __init__(self):
|
|
25
|
+
self._cancelled = False
|
|
26
|
+
self._event = asyncio.Event()
|
|
27
|
+
|
|
28
|
+
def cancel(self) -> None:
|
|
29
|
+
"""Signal cancellation."""
|
|
30
|
+
self._cancelled = True
|
|
31
|
+
self._event.set()
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def is_cancelled(self) -> bool:
|
|
35
|
+
"""Check if cancelled."""
|
|
36
|
+
return self._cancelled
|
|
37
|
+
|
|
38
|
+
async def wait(self) -> None:
|
|
39
|
+
"""Wait until cancelled."""
|
|
40
|
+
await self._event.wait()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class KeyboardListener:
|
|
44
|
+
"""Non-blocking async keyboard listener for detecting ESC key.
|
|
45
|
+
|
|
46
|
+
Uses Unix termios/tty/select for character-by-character input detection
|
|
47
|
+
without blocking the event loop.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
ESC_KEY = 27 # ASCII code for ESC
|
|
51
|
+
|
|
52
|
+
def __init__(self):
|
|
53
|
+
self._original_settings: Optional[list] = None
|
|
54
|
+
self._listening = False
|
|
55
|
+
|
|
56
|
+
def _is_unix_tty(self) -> bool:
|
|
57
|
+
"""Check if running on Unix with a TTY stdin."""
|
|
58
|
+
return sys.platform != "win32" and sys.stdin.isatty()
|
|
59
|
+
|
|
60
|
+
def _setup_terminal(self) -> None:
|
|
61
|
+
"""Set terminal to cbreak mode for character-by-character input."""
|
|
62
|
+
if self._is_unix_tty():
|
|
63
|
+
self._original_settings = termios.tcgetattr(sys.stdin)
|
|
64
|
+
tty.setcbreak(sys.stdin.fileno())
|
|
65
|
+
|
|
66
|
+
def _restore_terminal(self) -> None:
|
|
67
|
+
"""Restore original terminal settings."""
|
|
68
|
+
if self._original_settings is not None:
|
|
69
|
+
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self._original_settings)
|
|
70
|
+
self._original_settings = None
|
|
71
|
+
|
|
72
|
+
def _key_available(self) -> bool:
|
|
73
|
+
"""Check if a key is available without blocking."""
|
|
74
|
+
if not self._is_unix_tty():
|
|
75
|
+
return False
|
|
76
|
+
return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])
|
|
77
|
+
|
|
78
|
+
async def listen(
|
|
79
|
+
self,
|
|
80
|
+
on_escape: Callable[[], Awaitable[None]],
|
|
81
|
+
poll_interval: float = 0.05,
|
|
82
|
+
) -> None:
|
|
83
|
+
"""Listen for ESC key presses and invoke callback when detected.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
on_escape: Async callback to invoke when ESC is pressed
|
|
87
|
+
poll_interval: How often to check for key presses (seconds)
|
|
88
|
+
"""
|
|
89
|
+
if not self._is_unix_tty():
|
|
90
|
+
# On non-TTY or Windows, ESC listening is disabled - return immediately
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
self._listening = True
|
|
94
|
+
try:
|
|
95
|
+
self._setup_terminal()
|
|
96
|
+
while self._listening:
|
|
97
|
+
if self._key_available():
|
|
98
|
+
char = sys.stdin.read(1)
|
|
99
|
+
if ord(char) == self.ESC_KEY:
|
|
100
|
+
self._listening = False
|
|
101
|
+
await on_escape()
|
|
102
|
+
break
|
|
103
|
+
await asyncio.sleep(poll_interval)
|
|
104
|
+
finally:
|
|
105
|
+
self._restore_terminal()
|
|
106
|
+
|
|
107
|
+
def stop(self) -> None:
|
|
108
|
+
"""Stop listening for key presses."""
|
|
109
|
+
self._listening = False
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def iter_with_cancellation(
|
|
113
|
+
async_iter: AsyncIterator[T],
|
|
114
|
+
token: CancellationToken,
|
|
115
|
+
) -> AsyncIterator[T]:
|
|
116
|
+
"""Wrap an async iterator to support cancellation.
|
|
117
|
+
|
|
118
|
+
This allows breaking out of an async for loop when cancellation is requested,
|
|
119
|
+
even if the underlying iterator is blocked waiting for the next item.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
async_iter: The async iterator to wrap
|
|
123
|
+
token: Cancellation token to check
|
|
124
|
+
|
|
125
|
+
Yields:
|
|
126
|
+
Items from the underlying iterator until cancelled
|
|
127
|
+
"""
|
|
128
|
+
try:
|
|
129
|
+
while not token.is_cancelled:
|
|
130
|
+
# Create a task for getting the next item
|
|
131
|
+
try:
|
|
132
|
+
# Use anext with a wrapper that checks cancellation
|
|
133
|
+
next_task = asyncio.create_task(async_iter.__anext__())
|
|
134
|
+
cancel_task = asyncio.create_task(token.wait())
|
|
135
|
+
|
|
136
|
+
# Wait for either next item or cancellation
|
|
137
|
+
done, pending = await asyncio.wait(
|
|
138
|
+
[next_task, cancel_task],
|
|
139
|
+
return_when=asyncio.FIRST_COMPLETED,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Cancel pending tasks
|
|
143
|
+
for task in pending:
|
|
144
|
+
task.cancel()
|
|
145
|
+
try:
|
|
146
|
+
await task
|
|
147
|
+
except asyncio.CancelledError:
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
# Check what completed
|
|
151
|
+
if cancel_task in done:
|
|
152
|
+
# Cancellation requested
|
|
153
|
+
break
|
|
154
|
+
|
|
155
|
+
if next_task in done:
|
|
156
|
+
try:
|
|
157
|
+
item = next_task.result()
|
|
158
|
+
yield item
|
|
159
|
+
except StopAsyncIteration:
|
|
160
|
+
break
|
|
161
|
+
|
|
162
|
+
except asyncio.CancelledError:
|
|
163
|
+
break
|
|
164
|
+
except StopAsyncIteration:
|
|
165
|
+
pass
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@asynccontextmanager
|
|
169
|
+
async def escape_listener(
|
|
170
|
+
on_escape: Callable[[], Awaitable[None]],
|
|
171
|
+
enabled: bool = True,
|
|
172
|
+
):
|
|
173
|
+
"""Context manager that runs an ESC key listener as a background task.
|
|
174
|
+
|
|
175
|
+
Usage:
|
|
176
|
+
async with escape_listener(on_escape=handle_cancel):
|
|
177
|
+
async for event in stream:
|
|
178
|
+
process(event)
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
on_escape: Async callback to invoke when ESC is pressed
|
|
182
|
+
enabled: Whether to enable the listener (disabled for non-TTY)
|
|
183
|
+
|
|
184
|
+
Yields:
|
|
185
|
+
KeyboardListener instance (or None if disabled)
|
|
186
|
+
"""
|
|
187
|
+
if not enabled:
|
|
188
|
+
yield None
|
|
189
|
+
return
|
|
190
|
+
|
|
191
|
+
listener = KeyboardListener()
|
|
192
|
+
task = asyncio.create_task(listener.listen(on_escape))
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
yield listener
|
|
196
|
+
finally:
|
|
197
|
+
listener.stop()
|
|
198
|
+
task.cancel()
|
|
199
|
+
try:
|
|
200
|
+
await task
|
|
201
|
+
except asyncio.CancelledError:
|
|
202
|
+
pass
|
|
@@ -18,6 +18,7 @@ from rich.live import Live
|
|
|
18
18
|
from rich.text import Text
|
|
19
19
|
|
|
20
20
|
from ..agentic import ApprovalHooks, create_dev_agent, get_display_hooks
|
|
21
|
+
from ..core.keyboard_listener import CancellationToken, escape_listener, iter_with_cancellation
|
|
21
22
|
from ..core.session import EnhancedSQLiteSession, migrate_legacy_sessions
|
|
22
23
|
from ..core.streaming_display import StreamingDisplayManager
|
|
23
24
|
from ..core.usage_tracker import UsageTracker
|
|
@@ -153,7 +154,7 @@ class AgentScheduler:
|
|
|
153
154
|
return response
|
|
154
155
|
|
|
155
156
|
async def _handle_streaming(self, user_input: str) -> str:
|
|
156
|
-
"""Handle streaming execution with Rich Live and
|
|
157
|
+
"""Handle streaming execution with Rich Live, smart cleanup, and ESC cancellation."""
|
|
157
158
|
import os
|
|
158
159
|
import sys
|
|
159
160
|
|
|
@@ -164,12 +165,12 @@ class AgentScheduler:
|
|
|
164
165
|
terminal_type = os.environ.get("TERM_PROGRAM", "unknown")
|
|
165
166
|
supports_advanced_clearing = terminal_type in ["iTerm.app", "Apple_Terminal", "vscode"]
|
|
166
167
|
|
|
168
|
+
# Check if ESC listener should be enabled (Unix TTY only)
|
|
169
|
+
esc_enabled = sys.platform != "win32" and sys.stdin.isatty()
|
|
170
|
+
|
|
167
171
|
# Add space before streaming starts
|
|
168
172
|
print()
|
|
169
173
|
|
|
170
|
-
# Skip cursor position capture - it causes escape sequence leaks
|
|
171
|
-
# The terminal clearing strategies below work without explicit position tracking
|
|
172
|
-
|
|
173
174
|
# Run the agent in streaming mode
|
|
174
175
|
if self.dev_agent is None:
|
|
175
176
|
console.print("[dim red]Agent not initialized[/dim red]")
|
|
@@ -187,6 +188,30 @@ class AgentScheduler:
|
|
|
187
188
|
# Track if we displayed content during streaming
|
|
188
189
|
content_displayed = False
|
|
189
190
|
|
|
191
|
+
# Track cancellation state with token for immediate response
|
|
192
|
+
cancel_token = CancellationToken()
|
|
193
|
+
cancelled = False
|
|
194
|
+
|
|
195
|
+
async def handle_escape():
|
|
196
|
+
"""Callback when ESC key is pressed."""
|
|
197
|
+
nonlocal cancelled
|
|
198
|
+
cancelled = True
|
|
199
|
+
cancel_token.cancel() # Signal to break out of iterator immediately
|
|
200
|
+
result.cancel(mode="immediate") # Also cancel the underlying stream
|
|
201
|
+
|
|
202
|
+
# Show ESC hint if enabled (will be cleared after streaming)
|
|
203
|
+
esc_hint_shown = False
|
|
204
|
+
if esc_enabled:
|
|
205
|
+
console.print("[dim]Press ESC to cancel[/dim]")
|
|
206
|
+
esc_hint_shown = True
|
|
207
|
+
|
|
208
|
+
def clear_esc_hint():
|
|
209
|
+
"""Clear the ESC hint line using ANSI escape sequences."""
|
|
210
|
+
if esc_hint_shown:
|
|
211
|
+
# Move cursor up one line and clear it
|
|
212
|
+
sys.stdout.write("\033[A\033[2K")
|
|
213
|
+
sys.stdout.flush()
|
|
214
|
+
|
|
190
215
|
# Use Rich Live for proper formatting during streaming
|
|
191
216
|
with Live(
|
|
192
217
|
"",
|
|
@@ -196,93 +221,107 @@ class AgentScheduler:
|
|
|
196
221
|
vertical_overflow="crop",
|
|
197
222
|
) as live:
|
|
198
223
|
try:
|
|
199
|
-
#
|
|
200
|
-
async
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
# Wrap event loop with ESC listener
|
|
225
|
+
async with escape_listener(on_escape=handle_escape, enabled=esc_enabled):
|
|
226
|
+
# Process streaming events with cancellation support
|
|
227
|
+
# iter_with_cancellation allows immediate break when ESC is pressed
|
|
228
|
+
stream_iter = result.stream_events()
|
|
229
|
+
async for event in iter_with_cancellation(stream_iter, cancel_token):
|
|
230
|
+
# Check if cancelled (redundant but explicit)
|
|
231
|
+
if cancelled:
|
|
232
|
+
break
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
should_update = False
|
|
236
|
+
|
|
237
|
+
# Handle raw response events (token-by-token streaming)
|
|
238
|
+
if isinstance(event, RawResponsesStreamEvent):
|
|
239
|
+
if isinstance(event.data, ResponseTextDeltaEvent):
|
|
240
|
+
delta_text = event.data.delta
|
|
241
|
+
output_index = event.data.output_index
|
|
242
|
+
|
|
243
|
+
if delta_text:
|
|
244
|
+
should_update = display_manager.handle_text_delta(
|
|
245
|
+
output_index, delta_text
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
# Handle run item events (tool calls, outputs, etc.)
|
|
249
|
+
elif isinstance(event, RunItemStreamEvent):
|
|
250
|
+
if event.name == "tool_called":
|
|
251
|
+
if (
|
|
252
|
+
hasattr(event, "item")
|
|
253
|
+
and isinstance(event.item, ToolCallItem)
|
|
254
|
+
and isinstance(
|
|
255
|
+
event.item.raw_item, ResponseFunctionToolCall
|
|
256
|
+
)
|
|
257
|
+
):
|
|
258
|
+
should_update = display_manager.handle_tool_called(
|
|
259
|
+
event.item
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
elif event.name == "tool_output":
|
|
263
|
+
if hasattr(event, "item") and isinstance(
|
|
264
|
+
event.item, ToolCallOutputItem
|
|
265
|
+
):
|
|
266
|
+
should_update = display_manager.handle_tool_output(
|
|
267
|
+
event.item
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
elif event.name == "message_output_created":
|
|
271
|
+
pass
|
|
272
|
+
elif event.name == "handoff_requested":
|
|
273
|
+
# Handle agent handoff as a special tool call
|
|
274
|
+
should_update = display_manager.handle_tool_called(
|
|
275
|
+
type(
|
|
276
|
+
"HandoffItem",
|
|
277
|
+
(),
|
|
278
|
+
{
|
|
279
|
+
"raw_item": type(
|
|
280
|
+
"RawItem",
|
|
281
|
+
(),
|
|
282
|
+
{
|
|
283
|
+
"name": "agent_handoff",
|
|
284
|
+
"arguments": "{}",
|
|
285
|
+
"id": "handoff",
|
|
286
|
+
},
|
|
287
|
+
)()
|
|
288
|
+
},
|
|
289
|
+
)()
|
|
290
|
+
)
|
|
291
|
+
elif event.name == "handoff_occured":
|
|
292
|
+
# Handle as tool output
|
|
293
|
+
should_update = display_manager.handle_tool_output(
|
|
294
|
+
type(
|
|
295
|
+
"HandoffOutput",
|
|
296
|
+
(),
|
|
297
|
+
{"output": "Agent switched", "tool_call_id": "handoff"},
|
|
298
|
+
)()
|
|
213
299
|
)
|
|
300
|
+
elif event.name == "reasoning_item_created":
|
|
301
|
+
# Don't show reasoning steps in display
|
|
302
|
+
pass
|
|
214
303
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
hasattr(event, "item")
|
|
220
|
-
and isinstance(event.item, ToolCallItem)
|
|
221
|
-
and isinstance(event.item.raw_item, ResponseFunctionToolCall)
|
|
222
|
-
):
|
|
223
|
-
should_update = display_manager.handle_tool_called(event.item)
|
|
224
|
-
|
|
225
|
-
elif event.name == "tool_output":
|
|
226
|
-
if hasattr(event, "item") and isinstance(
|
|
227
|
-
event.item, ToolCallOutputItem
|
|
228
|
-
):
|
|
229
|
-
should_update = display_manager.handle_tool_output(event.item)
|
|
230
|
-
|
|
231
|
-
elif event.name == "message_output_created":
|
|
232
|
-
pass
|
|
233
|
-
elif event.name == "handoff_requested":
|
|
234
|
-
# Handle agent handoff as a special tool call
|
|
235
|
-
should_update = display_manager.handle_tool_called(
|
|
236
|
-
type(
|
|
237
|
-
"HandoffItem",
|
|
238
|
-
(),
|
|
239
|
-
{
|
|
240
|
-
"raw_item": type(
|
|
241
|
-
"RawItem",
|
|
242
|
-
(),
|
|
243
|
-
{
|
|
244
|
-
"name": "agent_handoff",
|
|
245
|
-
"arguments": "{}",
|
|
246
|
-
"id": "handoff",
|
|
247
|
-
},
|
|
248
|
-
)()
|
|
249
|
-
},
|
|
250
|
-
)()
|
|
251
|
-
)
|
|
252
|
-
elif event.name == "handoff_occured":
|
|
253
|
-
# Handle as tool output
|
|
254
|
-
should_update = display_manager.handle_tool_output(
|
|
255
|
-
type(
|
|
256
|
-
"HandoffOutput",
|
|
257
|
-
(),
|
|
258
|
-
{"output": "Agent switched", "tool_call_id": "handoff"},
|
|
259
|
-
)()
|
|
260
|
-
)
|
|
261
|
-
elif event.name == "reasoning_item_created":
|
|
262
|
-
# Don't show reasoning steps in display
|
|
304
|
+
# Handle agent updates (handoffs, etc.)
|
|
305
|
+
elif isinstance(event, AgentUpdatedStreamEvent):
|
|
306
|
+
# This is handled by handoff events above
|
|
263
307
|
pass
|
|
264
308
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if isinstance(current_content, str):
|
|
275
|
-
if current_content.strip():
|
|
309
|
+
# Update Rich Live display
|
|
310
|
+
if should_update:
|
|
311
|
+
current_content = display_manager.get_display_content()
|
|
312
|
+
# Handle both string and renderable objects
|
|
313
|
+
if isinstance(current_content, str):
|
|
314
|
+
if current_content.strip():
|
|
315
|
+
live.update(current_content)
|
|
316
|
+
content_displayed = True
|
|
317
|
+
elif current_content: # For renderables like Group
|
|
276
318
|
live.update(current_content)
|
|
277
319
|
content_displayed = True
|
|
278
|
-
elif current_content: # For renderables like Group
|
|
279
|
-
live.update(current_content)
|
|
280
|
-
content_displayed = True
|
|
281
320
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
321
|
+
except Exception as e:
|
|
322
|
+
# Log event processing errors but continue streaming
|
|
323
|
+
console.print(f"[dim red]Event processing error: {e}[/dim red]")
|
|
324
|
+
continue
|
|
286
325
|
|
|
287
326
|
except Exception as e:
|
|
288
327
|
# Handle execution errors in streaming mode
|
|
@@ -290,11 +329,40 @@ class AgentScheduler:
|
|
|
290
329
|
console.print(f"[red]{error_msg}[/red]")
|
|
291
330
|
# Clear the display manager and return early
|
|
292
331
|
display_manager.finalize_text_sections()
|
|
332
|
+
clear_esc_hint() # Clear ESC hint on error path too
|
|
293
333
|
return f"{error_msg}\n\nPlease provide new instructions."
|
|
294
334
|
|
|
295
335
|
# After Rich Live context ends, perform intelligent cleanup
|
|
296
336
|
display_manager.finalize_text_sections()
|
|
297
337
|
|
|
338
|
+
# Clear the ESC hint line
|
|
339
|
+
clear_esc_hint()
|
|
340
|
+
|
|
341
|
+
# Handle cancellation case
|
|
342
|
+
if cancelled:
|
|
343
|
+
# Rich Live with transient=True clears content on exit, so we need to re-print
|
|
344
|
+
# Get partial content that was accumulated during streaming
|
|
345
|
+
partial_display = display_manager.get_final_display()
|
|
346
|
+
partial_text = display_manager.get_final_text()
|
|
347
|
+
|
|
348
|
+
# Show the partial output (text + tool summaries)
|
|
349
|
+
if partial_display and partial_display.strip():
|
|
350
|
+
print() # Add spacing
|
|
351
|
+
console.print(partial_display)
|
|
352
|
+
elif partial_text and partial_text.strip():
|
|
353
|
+
print() # Add spacing
|
|
354
|
+
console.print(partial_text)
|
|
355
|
+
|
|
356
|
+
# Show cancellation message
|
|
357
|
+
console.print("\n[yellow]Operation cancelled by user[/yellow]")
|
|
358
|
+
console.print()
|
|
359
|
+
|
|
360
|
+
# Capture any usage data we can
|
|
361
|
+
self._capture_usage(result)
|
|
362
|
+
|
|
363
|
+
# Return partial text for session history
|
|
364
|
+
return partial_text or "Operation cancelled. You can provide additional instructions."
|
|
365
|
+
|
|
298
366
|
# Get final content for permanent display
|
|
299
367
|
final_content = display_manager.get_display_content()
|
|
300
368
|
|
|
@@ -229,9 +229,22 @@ def get_litellm_model_kwargs() -> dict:
|
|
|
229
229
|
|
|
230
230
|
def is_native_openai_provider() -> bool:
|
|
231
231
|
"""Check if the current provider should use native OpenAI client."""
|
|
232
|
-
config, config_manager, provider,
|
|
232
|
+
config, config_manager, provider, raw_model = _resolve_model_settings()
|
|
233
233
|
api_key = _get_provider_api_key(config, config_manager, provider)
|
|
234
|
-
|
|
234
|
+
|
|
235
|
+
if provider not in ("openai", "custom") or api_key is None:
|
|
236
|
+
return False
|
|
237
|
+
|
|
238
|
+
# Only use native client for standard OpenAI models
|
|
239
|
+
# This ensures compatible providers (like GLM) use LiteLLM which uses chat completions
|
|
240
|
+
model_lower = raw_model.lower()
|
|
241
|
+
return (
|
|
242
|
+
model_lower.startswith("gpt-")
|
|
243
|
+
or model_lower.startswith("o1-")
|
|
244
|
+
or model_lower.startswith("o3-")
|
|
245
|
+
or model_lower.startswith("o4-")
|
|
246
|
+
or model_lower.startswith("chatgpt-")
|
|
247
|
+
)
|
|
235
248
|
|
|
236
249
|
|
|
237
250
|
@backoff.on_exception(
|
|
@@ -281,6 +294,7 @@ async def llm_completion(messages: list, model: Optional[str] = None) -> str:
|
|
|
281
294
|
kwargs = {
|
|
282
295
|
"model": model,
|
|
283
296
|
"messages": messages,
|
|
297
|
+
"metadata": {"source": "koder"},
|
|
284
298
|
}
|
|
285
299
|
if api_key:
|
|
286
300
|
kwargs["api_key"] = api_key
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "koder"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.3"
|
|
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
|