koder 0.4.1__tar.gz → 0.4.2__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.1 → koder-0.4.2}/.claude/settings.local.json +3 -1
- {koder-0.4.1 → koder-0.4.2}/PKG-INFO +1 -1
- {koder-0.4.1 → koder-0.4.2}/koder_agent/agentic/agent.py +43 -3
- {koder-0.4.1 → koder-0.4.2}/koder_agent/cli.py +5 -8
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/__init__.py +2 -2
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/commands.py +8 -4
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/scheduler.py +35 -40
- koder-0.4.2/koder_agent/core/session.py +554 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/status_line.py +9 -7
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/usage_tracker.py +15 -3
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/client.py +32 -6
- {koder-0.4.1 → koder-0.4.2}/pyproject.toml +1 -1
- {koder-0.4.1 → koder-0.4.2}/uv.lock +1 -1
- koder-0.4.1/koder_agent/core/context.py +0 -433
- {koder-0.4.1 → koder-0.4.2}/.github/dependabot.yml +0 -0
- {koder-0.4.1 → koder-0.4.2}/.gitignore +0 -0
- {koder-0.4.1 → koder-0.4.2}/AGENTS.md +0 -0
- {koder-0.4.1 → koder-0.4.2}/CLAUDE.md +0 -0
- {koder-0.4.1 → koder-0.4.2}/CONTRIBUTING.md +0 -0
- {koder-0.4.1 → koder-0.4.2}/LICENSE +0 -0
- {koder-0.4.1 → koder-0.4.2}/README.md +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/config/manager.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/config/models.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/security.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/core/streaming_display.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/file.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/search.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/task.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/tools/web.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/model_info.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/tests/test_file_tools.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/tests/test_shell_background.py +0 -0
- {koder-0.4.1 → koder-0.4.2}/tests/test_web.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.2
|
|
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
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
import uuid
|
|
5
5
|
|
|
6
|
+
import backoff
|
|
7
|
+
import litellm
|
|
6
8
|
from agents import Agent, ModelSettings
|
|
7
9
|
from agents.extensions.models.litellm_model import LitellmModel
|
|
8
10
|
from openai.types.shared import Reasoning
|
|
@@ -18,6 +20,41 @@ console = Console()
|
|
|
18
20
|
logger = logging.getLogger(__name__)
|
|
19
21
|
|
|
20
22
|
|
|
23
|
+
class RetryingLitellmModel(LitellmModel):
|
|
24
|
+
"""LitellmModel with backoff retry logic."""
|
|
25
|
+
|
|
26
|
+
@backoff.on_exception(
|
|
27
|
+
backoff.expo,
|
|
28
|
+
(
|
|
29
|
+
litellm.exceptions.ServiceUnavailableError,
|
|
30
|
+
litellm.exceptions.RateLimitError,
|
|
31
|
+
litellm.exceptions.APIConnectionError,
|
|
32
|
+
litellm.exceptions.Timeout,
|
|
33
|
+
litellm.exceptions.InternalServerError,
|
|
34
|
+
),
|
|
35
|
+
max_tries=3,
|
|
36
|
+
jitter=backoff.full_jitter,
|
|
37
|
+
)
|
|
38
|
+
async def get_response(self, *args, **kwargs):
|
|
39
|
+
return await super().get_response(*args, **kwargs)
|
|
40
|
+
|
|
41
|
+
@backoff.on_exception(
|
|
42
|
+
backoff.expo,
|
|
43
|
+
(
|
|
44
|
+
litellm.exceptions.ServiceUnavailableError,
|
|
45
|
+
litellm.exceptions.RateLimitError,
|
|
46
|
+
litellm.exceptions.APIConnectionError,
|
|
47
|
+
litellm.exceptions.Timeout,
|
|
48
|
+
litellm.exceptions.InternalServerError,
|
|
49
|
+
),
|
|
50
|
+
max_tries=5,
|
|
51
|
+
jitter=backoff.full_jitter,
|
|
52
|
+
)
|
|
53
|
+
async def stream_response(self, *args, **kwargs):
|
|
54
|
+
async for chunk in super().stream_response(*args, **kwargs):
|
|
55
|
+
yield chunk
|
|
56
|
+
|
|
57
|
+
|
|
21
58
|
async def create_dev_agent(tools) -> Agent:
|
|
22
59
|
"""Create the main development agent with MCP servers."""
|
|
23
60
|
config = get_config()
|
|
@@ -28,9 +65,9 @@ async def create_dev_agent(tools) -> Agent:
|
|
|
28
65
|
# Use string model name for native OpenAI providers (handled by default client)
|
|
29
66
|
model = get_model_name()
|
|
30
67
|
else:
|
|
31
|
-
# Use LitellmModel with explicit base_url and api_key
|
|
68
|
+
# Use LitellmModel with explicit base_url and api_key
|
|
32
69
|
litellm_kwargs = get_litellm_model_kwargs()
|
|
33
|
-
model =
|
|
70
|
+
model = RetryingLitellmModel(
|
|
34
71
|
model=litellm_kwargs["model"],
|
|
35
72
|
base_url=litellm_kwargs["base_url"],
|
|
36
73
|
api_key=litellm_kwargs["api_key"],
|
|
@@ -40,7 +77,10 @@ async def create_dev_agent(tools) -> Agent:
|
|
|
40
77
|
model_name_str = get_model_name() # Always get string name for max_tokens lookup
|
|
41
78
|
model_settings = ModelSettings(max_tokens=get_maximum_output_tokens(model_name_str))
|
|
42
79
|
if config.model.reasoning_effort is not None:
|
|
43
|
-
|
|
80
|
+
effort = None if config.model.reasoning_effort == "none" else config.model.reasoning_effort
|
|
81
|
+
model_settings.reasoning = Reasoning(effort=effort, summary="detailed")
|
|
82
|
+
if "gpt-5" in model_name_str:
|
|
83
|
+
model_settings.verbosity = "high"
|
|
44
84
|
|
|
45
85
|
dev_agent = Agent(
|
|
46
86
|
name="Koder",
|
|
@@ -12,9 +12,9 @@ from rich.panel import Panel
|
|
|
12
12
|
|
|
13
13
|
from .config import get_config, get_config_manager
|
|
14
14
|
from .core.commands import slash_handler
|
|
15
|
-
from .core.context import ContextManager
|
|
16
15
|
from .core.interactive import InteractivePrompt
|
|
17
16
|
from .core.scheduler import AgentScheduler
|
|
17
|
+
from .core.session import EnhancedSQLiteSession
|
|
18
18
|
from .utils import (
|
|
19
19
|
default_session_local_ms,
|
|
20
20
|
parse_session_dt,
|
|
@@ -28,8 +28,7 @@ console = get_adaptive_console()
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
async def _prompt_select_session() -> Optional[str]:
|
|
31
|
-
|
|
32
|
-
sessions_with_titles = await ctx.list_sessions_with_titles()
|
|
31
|
+
sessions_with_titles = await EnhancedSQLiteSession.list_sessions_with_titles()
|
|
33
32
|
if not sessions_with_titles:
|
|
34
33
|
console.print(Panel("No sessions found.", title="Sessions", border_style="yellow"))
|
|
35
34
|
return None
|
|
@@ -284,7 +283,7 @@ async def main():
|
|
|
284
283
|
# Check for completed title generation (might have finished while waiting for input)
|
|
285
284
|
if scheduler._title_generation_task and scheduler._title_generation_task.done():
|
|
286
285
|
try:
|
|
287
|
-
display_name = await scheduler.
|
|
286
|
+
display_name = await scheduler.session.get_display_name()
|
|
288
287
|
if interactive_prompt.status_line:
|
|
289
288
|
interactive_prompt.status_line.update_display_name(display_name)
|
|
290
289
|
except Exception:
|
|
@@ -313,9 +312,7 @@ async def main():
|
|
|
313
312
|
)
|
|
314
313
|
# Load existing title for the session if available
|
|
315
314
|
try:
|
|
316
|
-
display_name = (
|
|
317
|
-
await scheduler.context_manager.get_display_name()
|
|
318
|
-
)
|
|
315
|
+
display_name = await scheduler.session.get_display_name()
|
|
319
316
|
interactive_prompt.status_line.update_display_name(
|
|
320
317
|
display_name
|
|
321
318
|
)
|
|
@@ -339,7 +336,7 @@ async def main():
|
|
|
339
336
|
and scheduler._title_generation_task.done()
|
|
340
337
|
):
|
|
341
338
|
try:
|
|
342
|
-
display_name = await scheduler.
|
|
339
|
+
display_name = await scheduler.session.get_display_name()
|
|
343
340
|
if interactive_prompt.status_line:
|
|
344
341
|
interactive_prompt.status_line.update_display_name(display_name)
|
|
345
342
|
except Exception:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Core components for Koder Agent."""
|
|
2
2
|
|
|
3
|
-
from .context import ContextManager
|
|
4
3
|
from .scheduler import AgentScheduler
|
|
5
4
|
from .security import SecurityGuard
|
|
5
|
+
from .session import EnhancedSQLiteSession
|
|
6
6
|
|
|
7
|
-
__all__ = ["
|
|
7
|
+
__all__ = ["EnhancedSQLiteSession", "AgentScheduler", "SecurityGuard"]
|
|
@@ -109,15 +109,17 @@ class StatusCommand(SlashCommand):
|
|
|
109
109
|
model = get_model_name()
|
|
110
110
|
|
|
111
111
|
# Get session info
|
|
112
|
-
session_id = scheduler.
|
|
112
|
+
session_id = scheduler.session.session_id
|
|
113
113
|
streaming = scheduler.streaming
|
|
114
114
|
|
|
115
115
|
# Get session title for current session
|
|
116
|
-
session_title = await scheduler.
|
|
116
|
+
session_title = await scheduler.session.get_title()
|
|
117
117
|
session_display = session_title or session_id
|
|
118
118
|
|
|
119
119
|
# Get available sessions with titles
|
|
120
|
-
|
|
120
|
+
from .session import EnhancedSQLiteSession
|
|
121
|
+
|
|
122
|
+
sessions_with_titles = await EnhancedSQLiteSession.list_sessions_with_titles()
|
|
121
123
|
|
|
122
124
|
# Get tools count
|
|
123
125
|
tools = get_all_tools()
|
|
@@ -322,7 +324,9 @@ class SlashCommandHandler:
|
|
|
322
324
|
scheduler._title_generation_task = None
|
|
323
325
|
|
|
324
326
|
# Get sessions with titles and prompt for selection
|
|
325
|
-
|
|
327
|
+
from .session import EnhancedSQLiteSession
|
|
328
|
+
|
|
329
|
+
sessions_with_titles = await EnhancedSQLiteSession.list_sessions_with_titles()
|
|
326
330
|
if not sessions_with_titles:
|
|
327
331
|
return "No sessions found."
|
|
328
332
|
|
|
@@ -18,7 +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.
|
|
21
|
+
from ..core.session import EnhancedSQLiteSession, migrate_legacy_sessions
|
|
22
22
|
from ..core.streaming_display import StreamingDisplayManager
|
|
23
23
|
from ..core.usage_tracker import UsageTracker
|
|
24
24
|
from ..tools import BackgroundShellManager, get_all_tools
|
|
@@ -32,7 +32,7 @@ class AgentScheduler:
|
|
|
32
32
|
|
|
33
33
|
def __init__(self, session_id: str = "default", streaming: bool = False):
|
|
34
34
|
self.semaphore = asyncio.Semaphore(10)
|
|
35
|
-
self.
|
|
35
|
+
self.session = EnhancedSQLiteSession(session_id=session_id)
|
|
36
36
|
self.tools = get_all_tools()
|
|
37
37
|
self.dev_agent = None # Will be initialized in async method
|
|
38
38
|
self.streaming = streaming
|
|
@@ -43,6 +43,7 @@ class AgentScheduler:
|
|
|
43
43
|
self._mcp_servers = [] # Track MCP servers for cleanup
|
|
44
44
|
self.usage_tracker = UsageTracker() # Track token usage and cost
|
|
45
45
|
self._title_generation_task: asyncio.Task | None = None # Async title generation
|
|
46
|
+
self._migration_done = False # Track if migration has been performed
|
|
46
47
|
|
|
47
48
|
def _has_content(self, content) -> bool:
|
|
48
49
|
"""Check if Rich or string content has any content."""
|
|
@@ -67,7 +68,12 @@ class AgentScheduler:
|
|
|
67
68
|
return 50 # Conservative estimate
|
|
68
69
|
|
|
69
70
|
async def _ensure_agent_initialized(self):
|
|
70
|
-
"""Ensure the dev agent is initialized."""
|
|
71
|
+
"""Ensure the dev agent is initialized and migration is complete."""
|
|
72
|
+
# Run migration once per process
|
|
73
|
+
if not self._migration_done:
|
|
74
|
+
await migrate_legacy_sessions(self.session.db_path)
|
|
75
|
+
self._migration_done = True
|
|
76
|
+
|
|
71
77
|
if not self._agent_initialized:
|
|
72
78
|
self.dev_agent = await create_dev_agent(self.tools)
|
|
73
79
|
# Track MCP servers for cleanup
|
|
@@ -78,15 +84,15 @@ class AgentScheduler:
|
|
|
78
84
|
async def _generate_title_background(self, user_input: str) -> None:
|
|
79
85
|
"""Background task to generate and save session title."""
|
|
80
86
|
try:
|
|
81
|
-
title = await self.
|
|
87
|
+
title = await self.session.generate_title(user_input)
|
|
82
88
|
if title:
|
|
83
|
-
await self.
|
|
89
|
+
await self.session.set_title(title)
|
|
84
90
|
except Exception:
|
|
85
91
|
pass # Silent failure - best effort
|
|
86
92
|
|
|
87
93
|
async def handle(self, user_input: str) -> str:
|
|
88
94
|
"""Handle user input and execute agent."""
|
|
89
|
-
# Ensure agent is initialized with MCP servers
|
|
95
|
+
# Ensure agent is initialized with MCP servers and migration complete
|
|
90
96
|
await self._ensure_agent_initialized()
|
|
91
97
|
|
|
92
98
|
if self.dev_agent is None:
|
|
@@ -95,10 +101,8 @@ class AgentScheduler:
|
|
|
95
101
|
|
|
96
102
|
# Note: Input panel is now displayed in InteractivePrompt, so we skip showing it here
|
|
97
103
|
|
|
98
|
-
#
|
|
99
|
-
history = await self.
|
|
100
|
-
|
|
101
|
-
# Trigger async title generation on first message (empty history)
|
|
104
|
+
# Check if this is the first message for title generation
|
|
105
|
+
history = await self.session.get_items()
|
|
102
106
|
if not history and self._title_generation_task is None:
|
|
103
107
|
# Extract actual user request (strip context prefix if present)
|
|
104
108
|
actual_request = user_input
|
|
@@ -108,30 +112,19 @@ class AgentScheduler:
|
|
|
108
112
|
self._generate_title_background(actual_request)
|
|
109
113
|
)
|
|
110
114
|
|
|
115
|
+
console.print()
|
|
111
116
|
console.print("[dim]thinking...[/dim]")
|
|
112
117
|
|
|
113
|
-
#
|
|
114
|
-
context_str = ""
|
|
115
|
-
if history:
|
|
116
|
-
context_str = "Previous conversation:\n"
|
|
117
|
-
for msg in history:
|
|
118
|
-
role = msg["role"].capitalize()
|
|
119
|
-
content = msg["content"]
|
|
120
|
-
context_str += f"{role}: {content}\n"
|
|
121
|
-
context_str += "\nCurrent request:\n"
|
|
122
|
-
|
|
123
|
-
# Combine context with current user input
|
|
124
|
-
full_input = context_str + user_input if context_str else user_input
|
|
125
|
-
|
|
126
|
-
# Run the agent
|
|
118
|
+
# Run the agent with session - history is managed automatically
|
|
127
119
|
async with self.semaphore:
|
|
128
120
|
try:
|
|
129
121
|
if self.streaming:
|
|
130
|
-
response = await self._handle_streaming(
|
|
122
|
+
response = await self._handle_streaming(user_input)
|
|
131
123
|
else:
|
|
132
124
|
result = await Runner.run(
|
|
133
125
|
self.dev_agent,
|
|
134
|
-
|
|
126
|
+
user_input, # Just current input - session handles history
|
|
127
|
+
session=self.session, # Automatic history management
|
|
135
128
|
run_config=RunConfig(),
|
|
136
129
|
hooks=self.hooks,
|
|
137
130
|
max_turns=50,
|
|
@@ -154,21 +147,12 @@ class AgentScheduler:
|
|
|
154
147
|
console.print(response)
|
|
155
148
|
return response
|
|
156
149
|
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
current_token_count = self.usage_tracker.session_usage.last_input_tokens or None
|
|
160
|
-
await self.context_manager.save(
|
|
161
|
-
history
|
|
162
|
-
+ [
|
|
163
|
-
{"role": "user", "content": user_input},
|
|
164
|
-
{"role": "assistant", "content": response},
|
|
165
|
-
],
|
|
166
|
-
current_token_count=current_token_count,
|
|
167
|
-
)
|
|
150
|
+
# History is automatically saved by the session
|
|
151
|
+
# No manual save needed!
|
|
168
152
|
|
|
169
153
|
return response
|
|
170
154
|
|
|
171
|
-
async def _handle_streaming(self,
|
|
155
|
+
async def _handle_streaming(self, user_input: str) -> str:
|
|
172
156
|
"""Handle streaming execution with Rich Live and smart cleanup."""
|
|
173
157
|
import os
|
|
174
158
|
import sys
|
|
@@ -193,7 +177,8 @@ class AgentScheduler:
|
|
|
193
177
|
|
|
194
178
|
result = Runner.run_streamed(
|
|
195
179
|
self.dev_agent,
|
|
196
|
-
|
|
180
|
+
user_input, # Just current input - session handles history
|
|
181
|
+
session=self.session, # Automatic history management
|
|
197
182
|
run_config=RunConfig(),
|
|
198
183
|
hooks=self.hooks,
|
|
199
184
|
max_turns=50,
|
|
@@ -419,7 +404,17 @@ class AgentScheduler:
|
|
|
419
404
|
# f"[dim][Usage] input={input_tokens}, output={output_tokens}[/dim]"
|
|
420
405
|
# )
|
|
421
406
|
if input_tokens > 0 or output_tokens > 0:
|
|
422
|
-
|
|
407
|
+
# Calculate context tokens from the last request if available
|
|
408
|
+
context_tokens = None
|
|
409
|
+
if hasattr(usage, "request_usage_entries") and usage.request_usage_entries:
|
|
410
|
+
last_req = usage.request_usage_entries[-1]
|
|
411
|
+
# Context size is roughly input + output of the last request
|
|
412
|
+
# (Input includes history, Output becomes new history)
|
|
413
|
+
context_tokens = last_req.total_tokens
|
|
414
|
+
|
|
415
|
+
self.usage_tracker.record_usage(
|
|
416
|
+
input_tokens, output_tokens, context_tokens=context_tokens
|
|
417
|
+
)
|
|
423
418
|
except Exception:
|
|
424
419
|
# Silently ignore usage capture errors
|
|
425
420
|
pass
|