koder 0.4.0__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.2/.claude/settings.local.json +12 -0
- koder-0.4.2/CLAUDE.md +98 -0
- {koder-0.4.0 → koder-0.4.2}/PKG-INFO +1 -29
- {koder-0.4.0 → koder-0.4.2}/README.md +0 -28
- koder-0.4.2/koder_agent/agentic/agent.py +107 -0
- koder-0.4.2/koder_agent/agentic/hooks.py +106 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/cli.py +18 -13
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/__init__.py +2 -2
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/commands.py +8 -4
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/scheduler.py +38 -37
- koder-0.4.2/koder_agent/core/session.py +554 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/status_line.py +9 -5
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/streaming_display.py +41 -17
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/usage_tracker.py +15 -3
- koder-0.4.2/koder_agent/tools/todo.py +86 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/client.py +79 -4
- {koder-0.4.0 → koder-0.4.2}/pyproject.toml +1 -1
- {koder-0.4.0 → koder-0.4.2}/uv.lock +2967 -2984
- koder-0.4.0/koder_agent/agentic/agent.py +0 -54
- koder-0.4.0/koder_agent/agentic/hooks.py +0 -73
- koder-0.4.0/koder_agent/core/context.py +0 -440
- koder-0.4.0/koder_agent/tools/todo.py +0 -76
- {koder-0.4.0 → koder-0.4.2}/.github/dependabot.yml +0 -0
- {koder-0.4.0 → koder-0.4.2}/.gitignore +0 -0
- {koder-0.4.0 → koder-0.4.2}/AGENTS.md +0 -0
- {koder-0.4.0 → koder-0.4.2}/CONTRIBUTING.md +0 -0
- {koder-0.4.0 → koder-0.4.2}/LICENSE +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/config/manager.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/config/models.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/core/security.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/file.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/search.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/task.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/tools/web.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/model_info.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/tests/test_file_tools.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/tests/test_shell_background.py +0 -0
- {koder-0.4.0 → koder-0.4.2}/tests/test_web.py +0 -0
koder-0.4.2/CLAUDE.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
### Development Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Install dependencies
|
|
11
|
+
uv sync
|
|
12
|
+
|
|
13
|
+
# Run the CLI in development
|
|
14
|
+
uv run koder
|
|
15
|
+
|
|
16
|
+
# Run with a single prompt
|
|
17
|
+
uv run koder "Your prompt here"
|
|
18
|
+
|
|
19
|
+
# Run with specific session
|
|
20
|
+
uv run koder --session my-session "Your prompt"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Code Quality
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Code formatting
|
|
27
|
+
black .
|
|
28
|
+
|
|
29
|
+
# Linting with auto-fix
|
|
30
|
+
ruff check --fix
|
|
31
|
+
|
|
32
|
+
# Error-only pylint check
|
|
33
|
+
pylint koder_agent/ --disable=C,R,W --errors-only
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Testing
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Run all tests
|
|
40
|
+
pytest
|
|
41
|
+
|
|
42
|
+
# Run a single test file
|
|
43
|
+
pytest tests/test_file_tools.py
|
|
44
|
+
|
|
45
|
+
# Run with verbose output
|
|
46
|
+
pytest -v
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Architecture
|
|
50
|
+
|
|
51
|
+
Koder is a terminal-based AI coding assistant built on the `openai-agents` library with multi-provider support via LiteLLM.
|
|
52
|
+
|
|
53
|
+
### Package Structure
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
koder_agent/
|
|
57
|
+
├── agentic/ # Agent creation, hooks, and approval system
|
|
58
|
+
├── cli.py # Main CLI entry point
|
|
59
|
+
├── config/ # Configuration management (YAML, env vars)
|
|
60
|
+
├── core/ # Scheduler, context, streaming, security, commands
|
|
61
|
+
├── mcp/ # Model Context Protocol server integration
|
|
62
|
+
├── tools/ # Tool implementations (file, search, shell, web, task, todo)
|
|
63
|
+
└── utils/ # Helpers (client setup, prompts, sessions, model info)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Core Flow
|
|
67
|
+
|
|
68
|
+
1. **CLI Entry** (`cli.py`) → parses args, initializes session
|
|
69
|
+
2. **AgentScheduler** (`core/scheduler.py`) → orchestrates agent execution with streaming
|
|
70
|
+
3. **Agent Creation** (`agentic/agent.py`) → builds agent with tools, MCP servers, model settings
|
|
71
|
+
4. **Tool Engine** (`tools/engine.py`) → registers tools, validates inputs, filters sensitive output
|
|
72
|
+
5. **Context Manager** (`core/context.py`) → persists conversations in SQLite with token-aware compression
|
|
73
|
+
|
|
74
|
+
### Key Design Patterns
|
|
75
|
+
|
|
76
|
+
- **Provider Abstraction**: `utils/client.py` detects providers from environment and configures either native OpenAI client or LiteLLM wrapper
|
|
77
|
+
- **Streaming Display**: `core/streaming_display.py` manages Rich Live displays for real-time output
|
|
78
|
+
- **Approval Hooks**: `agentic/approval_hooks.py` wraps tool execution with permission checks
|
|
79
|
+
- **Security Guard**: `core/security.py` validates shell commands before execution
|
|
80
|
+
|
|
81
|
+
### Configuration Priority
|
|
82
|
+
|
|
83
|
+
CLI Arguments > Environment Variables > Config File (`~/.koder/config.yaml`) > Defaults
|
|
84
|
+
|
|
85
|
+
Key environment variables:
|
|
86
|
+
- `KODER_MODEL` - Model name (e.g., `gpt-4o`, `claude-opus-4-20250514`)
|
|
87
|
+
- Provider API keys: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`, etc.
|
|
88
|
+
|
|
89
|
+
### Database
|
|
90
|
+
|
|
91
|
+
SQLite at `~/.koder/koder.db` stores:
|
|
92
|
+
- Conversation history with token-aware compression (50k limit)
|
|
93
|
+
- Session metadata
|
|
94
|
+
- MCP server configurations
|
|
95
|
+
|
|
96
|
+
### Project Context
|
|
97
|
+
|
|
98
|
+
The CLI loads `AGENTS.md` from the working directory as project-specific context for the agent.
|
|
@@ -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
|
|
@@ -118,27 +118,6 @@ koder
|
|
|
118
118
|
|
|
119
119
|
Koder uses a YAML config file at `~/.koder/config.yaml` for persistent settings.
|
|
120
120
|
|
|
121
|
-
#### Config CLI Commands
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
# Initialize config file with defaults
|
|
125
|
-
koder config init
|
|
126
|
-
|
|
127
|
-
# Show current configuration
|
|
128
|
-
koder config show
|
|
129
|
-
|
|
130
|
-
# Show config file path
|
|
131
|
-
koder config path
|
|
132
|
-
|
|
133
|
-
# Open config file in editor (respects $EDITOR)
|
|
134
|
-
koder config edit
|
|
135
|
-
|
|
136
|
-
# Set specific values (supports dot notation)
|
|
137
|
-
koder config set model.name gpt-4o
|
|
138
|
-
koder config set model.provider anthropic
|
|
139
|
-
koder config set cli.stream false
|
|
140
|
-
```
|
|
141
|
-
|
|
142
121
|
#### Config File Format
|
|
143
122
|
|
|
144
123
|
```yaml
|
|
@@ -151,13 +130,6 @@ model:
|
|
|
151
130
|
api_key: null # API key (prefer env vars for security)
|
|
152
131
|
base_url: null # Custom API endpoint (optional)
|
|
153
132
|
|
|
154
|
-
# Azure-specific settings
|
|
155
|
-
azure_api_version: null # e.g., "2025-04-01-preview"
|
|
156
|
-
|
|
157
|
-
# Vertex AI-specific settings
|
|
158
|
-
vertex_ai_location: null # e.g., "us-central1"
|
|
159
|
-
vertex_ai_credentials_path: null # Path to service account JSON
|
|
160
|
-
|
|
161
133
|
# Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
|
|
162
134
|
reasoning_effort: "medium" # none, minimal, low, medium, high, or null
|
|
163
135
|
|
|
@@ -83,27 +83,6 @@ koder
|
|
|
83
83
|
|
|
84
84
|
Koder uses a YAML config file at `~/.koder/config.yaml` for persistent settings.
|
|
85
85
|
|
|
86
|
-
#### Config CLI Commands
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
# Initialize config file with defaults
|
|
90
|
-
koder config init
|
|
91
|
-
|
|
92
|
-
# Show current configuration
|
|
93
|
-
koder config show
|
|
94
|
-
|
|
95
|
-
# Show config file path
|
|
96
|
-
koder config path
|
|
97
|
-
|
|
98
|
-
# Open config file in editor (respects $EDITOR)
|
|
99
|
-
koder config edit
|
|
100
|
-
|
|
101
|
-
# Set specific values (supports dot notation)
|
|
102
|
-
koder config set model.name gpt-4o
|
|
103
|
-
koder config set model.provider anthropic
|
|
104
|
-
koder config set cli.stream false
|
|
105
|
-
```
|
|
106
|
-
|
|
107
86
|
#### Config File Format
|
|
108
87
|
|
|
109
88
|
```yaml
|
|
@@ -116,13 +95,6 @@ model:
|
|
|
116
95
|
api_key: null # API key (prefer env vars for security)
|
|
117
96
|
base_url: null # Custom API endpoint (optional)
|
|
118
97
|
|
|
119
|
-
# Azure-specific settings
|
|
120
|
-
azure_api_version: null # e.g., "2025-04-01-preview"
|
|
121
|
-
|
|
122
|
-
# Vertex AI-specific settings
|
|
123
|
-
vertex_ai_location: null # e.g., "us-central1"
|
|
124
|
-
vertex_ai_credentials_path: null # Path to service account JSON
|
|
125
|
-
|
|
126
98
|
# Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
|
|
127
99
|
reasoning_effort: "medium" # none, minimal, low, medium, high, or null
|
|
128
100
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Agent definitions and hooks for Koder."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
import backoff
|
|
7
|
+
import litellm
|
|
8
|
+
from agents import Agent, ModelSettings
|
|
9
|
+
from agents.extensions.models.litellm_model import LitellmModel
|
|
10
|
+
from openai.types.shared import Reasoning
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
|
|
13
|
+
from ..config import get_config
|
|
14
|
+
from ..mcp import load_mcp_servers
|
|
15
|
+
from ..utils.client import get_litellm_model_kwargs, get_model_name, is_native_openai_provider
|
|
16
|
+
from ..utils.model_info import get_maximum_output_tokens
|
|
17
|
+
from ..utils.prompts import KODER_SYSTEM_PROMPT
|
|
18
|
+
|
|
19
|
+
console = Console()
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
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
|
+
|
|
58
|
+
async def create_dev_agent(tools) -> Agent:
|
|
59
|
+
"""Create the main development agent with MCP servers."""
|
|
60
|
+
config = get_config()
|
|
61
|
+
mcp_servers = await load_mcp_servers()
|
|
62
|
+
|
|
63
|
+
# Determine the model to use: native OpenAI string or LitellmModel instance
|
|
64
|
+
if is_native_openai_provider():
|
|
65
|
+
# Use string model name for native OpenAI providers (handled by default client)
|
|
66
|
+
model = get_model_name()
|
|
67
|
+
else:
|
|
68
|
+
# Use LitellmModel with explicit base_url and api_key
|
|
69
|
+
litellm_kwargs = get_litellm_model_kwargs()
|
|
70
|
+
model = RetryingLitellmModel(
|
|
71
|
+
model=litellm_kwargs["model"],
|
|
72
|
+
base_url=litellm_kwargs["base_url"],
|
|
73
|
+
api_key=litellm_kwargs["api_key"],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Build model_settings with reasoning if configured
|
|
77
|
+
model_name_str = get_model_name() # Always get string name for max_tokens lookup
|
|
78
|
+
model_settings = ModelSettings(max_tokens=get_maximum_output_tokens(model_name_str))
|
|
79
|
+
if config.model.reasoning_effort is not None:
|
|
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"
|
|
84
|
+
|
|
85
|
+
dev_agent = Agent(
|
|
86
|
+
name="Koder",
|
|
87
|
+
model=model,
|
|
88
|
+
instructions=KODER_SYSTEM_PROMPT,
|
|
89
|
+
tools=tools,
|
|
90
|
+
mcp_servers=mcp_servers,
|
|
91
|
+
model_settings=model_settings,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if "github_copilot" in model_name_str:
|
|
95
|
+
dev_agent.model_settings.extra_headers = {
|
|
96
|
+
"copilot-integration-id": "vscode-chat",
|
|
97
|
+
"editor-version": "vscode/1.98.1",
|
|
98
|
+
"editor-plugin-version": "copilot-chat/0.26.7",
|
|
99
|
+
"user-agent": "GitHubCopilotChat/0.26.7",
|
|
100
|
+
"openai-intent": "conversation-panel",
|
|
101
|
+
"x-github-api-version": "2025-04-01",
|
|
102
|
+
"x-request-id": str(uuid.uuid4()),
|
|
103
|
+
"x-vscode-user-agent-library-version": "electron-fetch",
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# planner.handoffs.append(dev_agent)
|
|
107
|
+
return dev_agent
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Agent definitions and hooks for Koder."""
|
|
2
|
+
|
|
3
|
+
from agents import (
|
|
4
|
+
Agent,
|
|
5
|
+
RunContextWrapper,
|
|
6
|
+
RunHooks,
|
|
7
|
+
Tool,
|
|
8
|
+
)
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
from rich.text import Text
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _truncate_agent_name(name: str, max_len: int = 40) -> str:
|
|
16
|
+
"""Truncate agent name if it's too long."""
|
|
17
|
+
if len(name) <= max_len:
|
|
18
|
+
return name
|
|
19
|
+
return name[: max_len - 3] + "..."
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ToolDisplayHooks(RunHooks):
|
|
23
|
+
"""RunHooks implementation to display tool input/output with rich formatting."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, streaming_mode: bool = False):
|
|
26
|
+
self.streaming_mode = streaming_mode
|
|
27
|
+
|
|
28
|
+
async def on_agent_start(self, context: RunContextWrapper, agent: Agent) -> None:
|
|
29
|
+
"""Called before the agent is invoked. Called each time the current agent changes."""
|
|
30
|
+
if self.streaming_mode:
|
|
31
|
+
# In streaming mode, don't print to avoid conflicts
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
# Use simple bullet-point style consistent with streaming_display.py
|
|
35
|
+
agent_text = Text()
|
|
36
|
+
agent_text.append("● ", style="green")
|
|
37
|
+
agent_text.append("Agent: ", style="bold cyan")
|
|
38
|
+
agent_text.append(_truncate_agent_name(agent.name), style="cyan")
|
|
39
|
+
console.print(agent_text)
|
|
40
|
+
|
|
41
|
+
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
|
|
42
|
+
"""Display tool execution start."""
|
|
43
|
+
# Don't print on tool start - wait for tool end to print both name and result together
|
|
44
|
+
# This ensures tool name and result are always paired even with parallel execution
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
async def on_tool_end(
|
|
48
|
+
self, context: RunContextWrapper, agent: Agent, tool: Tool, result: str
|
|
49
|
+
) -> None:
|
|
50
|
+
"""Display tool execution result."""
|
|
51
|
+
if self.streaming_mode:
|
|
52
|
+
# In streaming mode, don't print to avoid conflicts
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
# Print tool name and result together to ensure they're always paired
|
|
56
|
+
tool_text = Text()
|
|
57
|
+
tool_text.append("● ", style="green")
|
|
58
|
+
tool_text.append(tool.name, style="bold cyan")
|
|
59
|
+
console.print(tool_text)
|
|
60
|
+
|
|
61
|
+
# Show tool output with arrow style consistent with streaming_display.py
|
|
62
|
+
display_result = str(result).strip()
|
|
63
|
+
if len(display_result) > 200:
|
|
64
|
+
display_result = display_result[:200] + "..."
|
|
65
|
+
|
|
66
|
+
# Determine if this is an error output
|
|
67
|
+
is_error = _is_error_output(display_result)
|
|
68
|
+
style = "red" if is_error else "dim green"
|
|
69
|
+
arrow_style = "red" if is_error else "dim green"
|
|
70
|
+
|
|
71
|
+
output_text = Text()
|
|
72
|
+
output_text.append(" ╰─ ", style=arrow_style)
|
|
73
|
+
output_text.append(display_result, style=style)
|
|
74
|
+
console.print(output_text)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _is_error_output(output: str) -> bool:
|
|
78
|
+
"""Check if the output indicates an error."""
|
|
79
|
+
if not output:
|
|
80
|
+
return False
|
|
81
|
+
|
|
82
|
+
error_indicators = [
|
|
83
|
+
"error:",
|
|
84
|
+
"Error:",
|
|
85
|
+
"ERROR:",
|
|
86
|
+
"failed:",
|
|
87
|
+
"Failed:",
|
|
88
|
+
"FAILED:",
|
|
89
|
+
"exception:",
|
|
90
|
+
"Exception:",
|
|
91
|
+
"traceback",
|
|
92
|
+
"Traceback",
|
|
93
|
+
"not found",
|
|
94
|
+
"Not found",
|
|
95
|
+
"permission denied",
|
|
96
|
+
"Permission denied",
|
|
97
|
+
"No such file",
|
|
98
|
+
"fatal:",
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
return any(indicator in output for indicator in error_indicators)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def get_display_hooks(streaming_mode: bool = False) -> RunHooks:
|
|
105
|
+
"""Get the display hooks instance."""
|
|
106
|
+
return ToolDisplayHooks(streaming_mode=streaming_mode)
|
|
@@ -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,14 +336,21 @@ 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:
|
|
346
343
|
pass
|
|
347
344
|
scheduler._title_generation_task = None
|
|
348
345
|
finally:
|
|
349
|
-
|
|
346
|
+
try:
|
|
347
|
+
await scheduler.cleanup()
|
|
348
|
+
except (asyncio.CancelledError, KeyboardInterrupt, EOFError):
|
|
349
|
+
# Silently ignore interruption during cleanup
|
|
350
|
+
pass
|
|
351
|
+
except Exception:
|
|
352
|
+
# Ignore other cleanup errors on exit
|
|
353
|
+
pass
|
|
350
354
|
|
|
351
355
|
return 0
|
|
352
356
|
|
|
@@ -356,11 +360,12 @@ def run():
|
|
|
356
360
|
try:
|
|
357
361
|
exit_code = asyncio.run(main())
|
|
358
362
|
exit(exit_code)
|
|
359
|
-
except KeyboardInterrupt:
|
|
360
|
-
|
|
361
|
-
Panel("[yellow]Interrupted![/yellow]", title="Interruption", border_style="yellow")
|
|
362
|
-
)
|
|
363
|
+
except (KeyboardInterrupt, EOFError, asyncio.CancelledError):
|
|
364
|
+
# Silently exit on Ctrl+C, Ctrl+D, or task cancellation
|
|
363
365
|
exit(0)
|
|
366
|
+
except SystemExit:
|
|
367
|
+
# Re-raise SystemExit to allow normal exit
|
|
368
|
+
raise
|
|
364
369
|
except Exception as e:
|
|
365
370
|
console.print(
|
|
366
371
|
Panel(f"[red]Fatal error: {e}[/red]", title="Fatal Error", border_style="red")
|
|
@@ -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
|
|