koder 0.4.3__tar.gz → 0.4.5__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.3 → koder-0.4.5}/.claude/settings.local.json +5 -1
- {koder-0.4.3 → koder-0.4.5}/CLAUDE.md +6 -6
- {koder-0.4.3 → koder-0.4.5}/PKG-INFO +83 -3
- {koder-0.4.3 → koder-0.4.5}/README.md +81 -2
- {koder-0.4.3 → koder-0.4.5}/koder_agent/agentic/agent.py +57 -15
- koder-0.4.5/koder_agent/agentic/skill_guardrail.py +79 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/config/models.py +13 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/__init__.py +19 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/engine.py +1 -0
- koder-0.4.5/koder_agent/tools/skill.py +403 -0
- koder-0.4.5/koder_agent/tools/skill_context.py +127 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/client.py +96 -43
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/prompts.py +18 -14
- {koder-0.4.3 → koder-0.4.5}/pyproject.toml +2 -1
- koder-0.4.5/tests/fixtures/skills/large-skill/SKILL.md +106 -0
- koder-0.4.5/tests/fixtures/skills/large-skill/reference.md +24 -0
- koder-0.4.5/tests/fixtures/skills/medium-skill/SKILL.md +74 -0
- koder-0.4.5/tests/fixtures/skills/small-skill/SKILL.md +56 -0
- koder-0.4.5/tests/fixtures/skills/template-skill/SKILL.md +20 -0
- koder-0.4.5/tests/test_model_resolution.py +129 -0
- koder-0.4.5/tests/test_skill_loader.py +518 -0
- koder-0.4.5/tests/test_skill_restrictions.py +340 -0
- koder-0.4.5/tests/test_skill_token_efficiency.py +241 -0
- {koder-0.4.3 → koder-0.4.5}/uv.lock +3 -1
- {koder-0.4.3 → koder-0.4.5}/.github/dependabot.yml +0 -0
- {koder-0.4.3 → koder-0.4.5}/.gitignore +0 -0
- {koder-0.4.3 → koder-0.4.5}/AGENTS.md +0 -0
- {koder-0.4.3 → koder-0.4.5}/CONTRIBUTING.md +0 -0
- {koder-0.4.3 → koder-0.4.5}/GEMINI.md +0 -0
- {koder-0.4.3 → koder-0.4.5}/LICENSE +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/cli.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/config/manager.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/commands.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/keyboard_listener.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/scheduler.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/security.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/session.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/streaming_display.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/file.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/search.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/task.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/tools/web.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/model_info.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/tests/test_file_tools.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/tests/test_shell_background.py +0 -0
- {koder-0.4.3 → koder-0.4.5}/tests/test_web.py +0 -0
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
"Bash(cat:*)",
|
|
6
6
|
"Bash(python -m py_compile:*)",
|
|
7
7
|
"Bash(uv run pytest:*)",
|
|
8
|
-
"mcp__plugin_claude-code-settings_exa__get_code_context_exa"
|
|
8
|
+
"mcp__plugin_claude-code-settings_exa__get_code_context_exa",
|
|
9
|
+
"Bash(find:*)",
|
|
10
|
+
"WebFetch(domain:www.anthropic.com)",
|
|
11
|
+
"Bash(uv run ruff check:*)",
|
|
12
|
+
"mcp__firecrawl__firecrawl_scrape"
|
|
9
13
|
],
|
|
10
14
|
"deny": [],
|
|
11
15
|
"ask": []
|
|
@@ -24,26 +24,26 @@ uv run koder --session my-session "Your prompt"
|
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
# Code formatting
|
|
27
|
-
black .
|
|
27
|
+
uv run black .
|
|
28
28
|
|
|
29
29
|
# Linting with auto-fix
|
|
30
|
-
ruff check --fix
|
|
30
|
+
uv run ruff check --fix
|
|
31
31
|
|
|
32
32
|
# Error-only pylint check
|
|
33
|
-
pylint koder_agent/ --disable=C,R,W --errors-only
|
|
33
|
+
uv run pylint koder_agent/ --disable=C,R,W --errors-only
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
### Testing
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# Run all tests
|
|
40
|
-
pytest
|
|
40
|
+
uv run pytest
|
|
41
41
|
|
|
42
42
|
# Run a single test file
|
|
43
|
-
pytest tests/test_file_tools.py
|
|
43
|
+
uv run pytest tests/test_file_tools.py
|
|
44
44
|
|
|
45
45
|
# Run with verbose output
|
|
46
|
-
pytest -v
|
|
46
|
+
uv run pytest -v
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Architecture
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.5
|
|
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
|
|
@@ -18,6 +18,7 @@ Requires-Dist: fastapi-sso>=0.18.0
|
|
|
18
18
|
Requires-Dist: fastapi>=0.122.0
|
|
19
19
|
Requires-Dist: google-cloud-aiplatform>=1.128.0
|
|
20
20
|
Requires-Dist: httpx[socks]>=0.28.1
|
|
21
|
+
Requires-Dist: litellm>=1.80.5
|
|
21
22
|
Requires-Dist: openai-agents[litellm]>=0.6.1
|
|
22
23
|
Requires-Dist: openai>=2.8.1
|
|
23
24
|
Requires-Dist: orjson>=3.11.4
|
|
@@ -39,14 +40,15 @@ Description-Content-Type: text/markdown
|
|
|
39
40
|
|
|
40
41
|
Koder is an experimental, universal AI coding assistant designed to explore how to build an advanced terminal-based AI coding assistant. Written entirely in Python, it serves as both a functional tool and a learning playground for AI agent development.
|
|
41
42
|
|
|
42
|
-
**🎯 Project Status**:
|
|
43
|
+
**🎯 Project Status**: Alpha! This is a learning-focused project where we explore building AI coding agents.
|
|
43
44
|
|
|
44
45
|
## ✨ Features
|
|
45
46
|
|
|
46
47
|
- **🤖 Universal AI Support**: Works with OpenAI, Anthropic, Google, GitHub Copilot, and 100+ providers via LiteLLM with intelligent auto-detection
|
|
47
48
|
- **💾 Smart Context Management**: Persistent sessions with SQLite storage and automatic token-aware compression (50k token limit)
|
|
48
49
|
- **🔄 Real-time Streaming**: Rich Live displays with intelligent terminal cleanup for responsive user experience
|
|
49
|
-
- **🛠️ Comprehensive Toolset**: file operations, search, shell, task delegation and
|
|
50
|
+
- **🛠️ Comprehensive Toolset**: file operations, search, shell, task delegation, todos, and skills
|
|
51
|
+
- **📚 Progressive Disclosure Skills**: Load specialized knowledge on-demand with 90%+ token savings
|
|
50
52
|
- **🔌 MCP Integration**: Model Context Protocol support with stdio, SSE, and HTTP transports for extensible tool ecosystem
|
|
51
53
|
- **🛡️ Enterprise Security**: SecurityGuard validation, output filtering, permission system, and input sanitization
|
|
52
54
|
- **🎯 Zero Configuration**: Automatic provider detection with fallback defaults
|
|
@@ -349,6 +351,84 @@ mcp_servers:
|
|
|
349
351
|
url: "http://localhost:9000/sse"
|
|
350
352
|
```
|
|
351
353
|
|
|
354
|
+
### Skills
|
|
355
|
+
|
|
356
|
+
Skills provide specialized knowledge and guidance that Koder can load on-demand. This uses a **Progressive Disclosure** pattern to minimize token usage - only skill metadata is loaded at startup, with full content fetched when needed.
|
|
357
|
+
|
|
358
|
+
#### Skills Directory Structure
|
|
359
|
+
|
|
360
|
+
Skills are loaded from two locations (project skills take priority):
|
|
361
|
+
|
|
362
|
+
1. **Project skills**: `.koder/skills/` in your current directory
|
|
363
|
+
2. **User skills**: `~/.koder/skills/` for personal skills
|
|
364
|
+
|
|
365
|
+
Each skill lives in its own directory with a `SKILL.md` file:
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
.koder/skills/
|
|
369
|
+
├── api-design/
|
|
370
|
+
│ └── SKILL.md
|
|
371
|
+
├── code-review/
|
|
372
|
+
│ ├── SKILL.md
|
|
373
|
+
│ └── checklist.md # Supplementary resource
|
|
374
|
+
└── testing/
|
|
375
|
+
└── SKILL.md
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### Creating a Skill
|
|
379
|
+
|
|
380
|
+
Create a `SKILL.md` file with YAML frontmatter:
|
|
381
|
+
|
|
382
|
+
```markdown
|
|
383
|
+
---
|
|
384
|
+
name: api-design
|
|
385
|
+
description: Best practices for designing RESTful APIs
|
|
386
|
+
allowed_tools:
|
|
387
|
+
- read_file
|
|
388
|
+
- write_file
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
# API Design Guidelines
|
|
392
|
+
|
|
393
|
+
## RESTful Principles
|
|
394
|
+
|
|
395
|
+
Use nouns for resources, HTTP verbs for actions...
|
|
396
|
+
|
|
397
|
+
## Versioning
|
|
398
|
+
|
|
399
|
+
Always version your APIs using URL path (`/v1/users`)...
|
|
400
|
+
|
|
401
|
+
## Error Handling
|
|
402
|
+
|
|
403
|
+
Return consistent error responses with status codes...
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
#### Frontmatter Fields
|
|
407
|
+
|
|
408
|
+
| Field | Required | Description |
|
|
409
|
+
|-------|----------|-------------|
|
|
410
|
+
| `name` | Yes | Unique skill identifier |
|
|
411
|
+
| `description` | Yes | Brief description (shown in metadata) |
|
|
412
|
+
| `allowed_tools` | No | Tools the skill recommends using |
|
|
413
|
+
|
|
414
|
+
#### How Skills Work
|
|
415
|
+
|
|
416
|
+
1. **Startup**: Only skill names and descriptions are loaded (Level 1 - minimal tokens)
|
|
417
|
+
2. **On-demand**: When Koder needs a skill, it calls `get_skill(name)` to load full content (Level 2)
|
|
418
|
+
3. **Supplementary**: Skills can reference additional files that Koder reads with `read_file` (Level 3)
|
|
419
|
+
|
|
420
|
+
This progressive approach saves **90%+ tokens** compared to loading all skill content at startup.
|
|
421
|
+
|
|
422
|
+
#### Skills Configuration
|
|
423
|
+
|
|
424
|
+
```yaml
|
|
425
|
+
# ~/.koder/config.yaml
|
|
426
|
+
skills:
|
|
427
|
+
enabled: true # Enable/disable skills (default: true)
|
|
428
|
+
project_skills_dir: ".koder/skills" # Project skills location
|
|
429
|
+
user_skills_dir: "~/.koder/skills" # User skills location
|
|
430
|
+
```
|
|
431
|
+
|
|
352
432
|
### Example Configurations
|
|
353
433
|
|
|
354
434
|
<details>
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
Koder is an experimental, universal AI coding assistant designed to explore how to build an advanced terminal-based AI coding assistant. Written entirely in Python, it serves as both a functional tool and a learning playground for AI agent development.
|
|
6
6
|
|
|
7
|
-
**🎯 Project Status**:
|
|
7
|
+
**🎯 Project Status**: Alpha! This is a learning-focused project where we explore building AI coding agents.
|
|
8
8
|
|
|
9
9
|
## ✨ Features
|
|
10
10
|
|
|
11
11
|
- **🤖 Universal AI Support**: Works with OpenAI, Anthropic, Google, GitHub Copilot, and 100+ providers via LiteLLM with intelligent auto-detection
|
|
12
12
|
- **💾 Smart Context Management**: Persistent sessions with SQLite storage and automatic token-aware compression (50k token limit)
|
|
13
13
|
- **🔄 Real-time Streaming**: Rich Live displays with intelligent terminal cleanup for responsive user experience
|
|
14
|
-
- **🛠️ Comprehensive Toolset**: file operations, search, shell, task delegation and
|
|
14
|
+
- **🛠️ Comprehensive Toolset**: file operations, search, shell, task delegation, todos, and skills
|
|
15
|
+
- **📚 Progressive Disclosure Skills**: Load specialized knowledge on-demand with 90%+ token savings
|
|
15
16
|
- **🔌 MCP Integration**: Model Context Protocol support with stdio, SSE, and HTTP transports for extensible tool ecosystem
|
|
16
17
|
- **🛡️ Enterprise Security**: SecurityGuard validation, output filtering, permission system, and input sanitization
|
|
17
18
|
- **🎯 Zero Configuration**: Automatic provider detection with fallback defaults
|
|
@@ -314,6 +315,84 @@ mcp_servers:
|
|
|
314
315
|
url: "http://localhost:9000/sse"
|
|
315
316
|
```
|
|
316
317
|
|
|
318
|
+
### Skills
|
|
319
|
+
|
|
320
|
+
Skills provide specialized knowledge and guidance that Koder can load on-demand. This uses a **Progressive Disclosure** pattern to minimize token usage - only skill metadata is loaded at startup, with full content fetched when needed.
|
|
321
|
+
|
|
322
|
+
#### Skills Directory Structure
|
|
323
|
+
|
|
324
|
+
Skills are loaded from two locations (project skills take priority):
|
|
325
|
+
|
|
326
|
+
1. **Project skills**: `.koder/skills/` in your current directory
|
|
327
|
+
2. **User skills**: `~/.koder/skills/` for personal skills
|
|
328
|
+
|
|
329
|
+
Each skill lives in its own directory with a `SKILL.md` file:
|
|
330
|
+
|
|
331
|
+
```
|
|
332
|
+
.koder/skills/
|
|
333
|
+
├── api-design/
|
|
334
|
+
│ └── SKILL.md
|
|
335
|
+
├── code-review/
|
|
336
|
+
│ ├── SKILL.md
|
|
337
|
+
│ └── checklist.md # Supplementary resource
|
|
338
|
+
└── testing/
|
|
339
|
+
└── SKILL.md
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Creating a Skill
|
|
343
|
+
|
|
344
|
+
Create a `SKILL.md` file with YAML frontmatter:
|
|
345
|
+
|
|
346
|
+
```markdown
|
|
347
|
+
---
|
|
348
|
+
name: api-design
|
|
349
|
+
description: Best practices for designing RESTful APIs
|
|
350
|
+
allowed_tools:
|
|
351
|
+
- read_file
|
|
352
|
+
- write_file
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
# API Design Guidelines
|
|
356
|
+
|
|
357
|
+
## RESTful Principles
|
|
358
|
+
|
|
359
|
+
Use nouns for resources, HTTP verbs for actions...
|
|
360
|
+
|
|
361
|
+
## Versioning
|
|
362
|
+
|
|
363
|
+
Always version your APIs using URL path (`/v1/users`)...
|
|
364
|
+
|
|
365
|
+
## Error Handling
|
|
366
|
+
|
|
367
|
+
Return consistent error responses with status codes...
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### Frontmatter Fields
|
|
371
|
+
|
|
372
|
+
| Field | Required | Description |
|
|
373
|
+
|-------|----------|-------------|
|
|
374
|
+
| `name` | Yes | Unique skill identifier |
|
|
375
|
+
| `description` | Yes | Brief description (shown in metadata) |
|
|
376
|
+
| `allowed_tools` | No | Tools the skill recommends using |
|
|
377
|
+
|
|
378
|
+
#### How Skills Work
|
|
379
|
+
|
|
380
|
+
1. **Startup**: Only skill names and descriptions are loaded (Level 1 - minimal tokens)
|
|
381
|
+
2. **On-demand**: When Koder needs a skill, it calls `get_skill(name)` to load full content (Level 2)
|
|
382
|
+
3. **Supplementary**: Skills can reference additional files that Koder reads with `read_file` (Level 3)
|
|
383
|
+
|
|
384
|
+
This progressive approach saves **90%+ tokens** compared to loading all skill content at startup.
|
|
385
|
+
|
|
386
|
+
#### Skills Configuration
|
|
387
|
+
|
|
388
|
+
```yaml
|
|
389
|
+
# ~/.koder/config.yaml
|
|
390
|
+
skills:
|
|
391
|
+
enabled: true # Enable/disable skills (default: true)
|
|
392
|
+
project_skills_dir: ".koder/skills" # Project skills location
|
|
393
|
+
user_skills_dir: "~/.koder/skills" # User skills location
|
|
394
|
+
```
|
|
395
|
+
|
|
317
396
|
### Example Configurations
|
|
318
397
|
|
|
319
398
|
<details>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
import uuid
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
|
|
6
7
|
import backoff
|
|
7
8
|
import litellm
|
|
@@ -12,9 +13,11 @@ from rich.console import Console
|
|
|
12
13
|
|
|
13
14
|
from ..config import get_config
|
|
14
15
|
from ..mcp import load_mcp_servers
|
|
16
|
+
from ..tools.skill import SkillLoader
|
|
15
17
|
from ..utils.client import get_litellm_model_kwargs, get_model_name, is_native_openai_provider
|
|
16
18
|
from ..utils.model_info import get_maximum_output_tokens
|
|
17
19
|
from ..utils.prompts import KODER_SYSTEM_PROMPT
|
|
20
|
+
from .skill_guardrail import skill_restriction_guardrail
|
|
18
21
|
|
|
19
22
|
console = Console()
|
|
20
23
|
logger = logging.getLogger(__name__)
|
|
@@ -23,15 +26,18 @@ logger = logging.getLogger(__name__)
|
|
|
23
26
|
class RetryingLitellmModel(LitellmModel):
|
|
24
27
|
"""LitellmModel with backoff retry logic."""
|
|
25
28
|
|
|
29
|
+
_EXC = getattr(litellm, "exceptions", litellm)
|
|
30
|
+
_EXC_TUPLE = (
|
|
31
|
+
getattr(_EXC, "ServiceUnavailableError", Exception),
|
|
32
|
+
getattr(_EXC, "RateLimitError", Exception),
|
|
33
|
+
getattr(_EXC, "APIConnectionError", Exception),
|
|
34
|
+
getattr(_EXC, "Timeout", Exception),
|
|
35
|
+
getattr(_EXC, "InternalServerError", Exception),
|
|
36
|
+
)
|
|
37
|
+
|
|
26
38
|
@backoff.on_exception(
|
|
27
39
|
backoff.expo,
|
|
28
|
-
|
|
29
|
-
litellm.exceptions.ServiceUnavailableError,
|
|
30
|
-
litellm.exceptions.RateLimitError,
|
|
31
|
-
litellm.exceptions.APIConnectionError,
|
|
32
|
-
litellm.exceptions.Timeout,
|
|
33
|
-
litellm.exceptions.InternalServerError,
|
|
34
|
-
),
|
|
40
|
+
_EXC_TUPLE,
|
|
35
41
|
max_tries=3,
|
|
36
42
|
jitter=backoff.full_jitter,
|
|
37
43
|
)
|
|
@@ -40,13 +46,7 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
40
46
|
|
|
41
47
|
@backoff.on_exception(
|
|
42
48
|
backoff.expo,
|
|
43
|
-
|
|
44
|
-
litellm.exceptions.ServiceUnavailableError,
|
|
45
|
-
litellm.exceptions.RateLimitError,
|
|
46
|
-
litellm.exceptions.APIConnectionError,
|
|
47
|
-
litellm.exceptions.Timeout,
|
|
48
|
-
litellm.exceptions.InternalServerError,
|
|
49
|
-
),
|
|
49
|
+
_EXC_TUPLE,
|
|
50
50
|
max_tries=5,
|
|
51
51
|
jitter=backoff.full_jitter,
|
|
52
52
|
)
|
|
@@ -55,6 +55,42 @@ class RetryingLitellmModel(LitellmModel):
|
|
|
55
55
|
yield chunk
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
def _get_skills_metadata(config) -> str:
|
|
59
|
+
"""Load and return skills metadata from configured directories.
|
|
60
|
+
|
|
61
|
+
Priority: project skills directory > user skills directory.
|
|
62
|
+
Skills with the same name in project dir override user dir.
|
|
63
|
+
"""
|
|
64
|
+
if not config.skills.enabled:
|
|
65
|
+
return "Skills are disabled."
|
|
66
|
+
|
|
67
|
+
all_skills = {}
|
|
68
|
+
|
|
69
|
+
# Load user skills first (lower priority)
|
|
70
|
+
user_dir = Path(config.skills.user_skills_dir).expanduser()
|
|
71
|
+
if user_dir.exists():
|
|
72
|
+
user_loader = SkillLoader(user_dir)
|
|
73
|
+
for skill in user_loader.discover_skills():
|
|
74
|
+
all_skills[skill.name] = skill
|
|
75
|
+
|
|
76
|
+
# Load project skills (higher priority - overrides user skills)
|
|
77
|
+
project_dir = Path(config.skills.project_skills_dir)
|
|
78
|
+
if project_dir.exists():
|
|
79
|
+
project_loader = SkillLoader(project_dir)
|
|
80
|
+
for skill in project_loader.discover_skills():
|
|
81
|
+
all_skills[skill.name] = skill
|
|
82
|
+
|
|
83
|
+
if not all_skills:
|
|
84
|
+
return "No skills are currently available."
|
|
85
|
+
|
|
86
|
+
lines = ["Available skills:", ""]
|
|
87
|
+
for skill in sorted(all_skills.values(), key=lambda s: s.name.lower()):
|
|
88
|
+
description = skill.description.strip()
|
|
89
|
+
lines.append(f"- {skill.name}: {description}")
|
|
90
|
+
|
|
91
|
+
return "\n".join(lines)
|
|
92
|
+
|
|
93
|
+
|
|
58
94
|
async def create_dev_agent(tools) -> Agent:
|
|
59
95
|
"""Create the main development agent with MCP servers."""
|
|
60
96
|
config = get_config()
|
|
@@ -83,13 +119,19 @@ async def create_dev_agent(tools) -> Agent:
|
|
|
83
119
|
effort = None if config.model.reasoning_effort == "none" else config.model.reasoning_effort
|
|
84
120
|
model_settings.reasoning = Reasoning(effort=effort, summary="detailed")
|
|
85
121
|
|
|
122
|
+
# Build system prompt with skills metadata (Progressive Disclosure Level 1)
|
|
123
|
+
skills_metadata = _get_skills_metadata(config)
|
|
124
|
+
system_prompt = KODER_SYSTEM_PROMPT.replace("{SKILLS_METADATA}", skills_metadata)
|
|
125
|
+
|
|
86
126
|
dev_agent = Agent(
|
|
87
127
|
name="Koder",
|
|
88
128
|
model=model,
|
|
89
|
-
instructions=
|
|
129
|
+
instructions=system_prompt,
|
|
90
130
|
tools=tools,
|
|
91
131
|
mcp_servers=mcp_servers,
|
|
92
132
|
model_settings=model_settings,
|
|
133
|
+
# Add skill-based tool restriction enforcement
|
|
134
|
+
input_guardrails=[skill_restriction_guardrail],
|
|
93
135
|
)
|
|
94
136
|
|
|
95
137
|
if "github_copilot" in model_name_str:
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Guardrail for enforcing skill-based tool restrictions.
|
|
2
|
+
|
|
3
|
+
This module provides a ToolInputGuardrail that intercepts tool calls and
|
|
4
|
+
rejects those not permitted by the currently active skill restrictions.
|
|
5
|
+
|
|
6
|
+
When a skill with `allowed_tools` is loaded via get_skill(), subsequent
|
|
7
|
+
tool calls are validated against the allowed list. Tools not in the list
|
|
8
|
+
are rejected with an informative message.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from agents import (
|
|
12
|
+
ToolGuardrailFunctionOutput,
|
|
13
|
+
ToolInputGuardrail,
|
|
14
|
+
ToolInputGuardrailData,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from ..tools.skill_context import get_active_restrictions
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def skill_tool_restriction_guardrail(
|
|
21
|
+
data: ToolInputGuardrailData,
|
|
22
|
+
) -> ToolGuardrailFunctionOutput:
|
|
23
|
+
"""Guardrail that enforces skill-declared tool restrictions.
|
|
24
|
+
|
|
25
|
+
When a skill is loaded with `allowed_tools`, only those tools
|
|
26
|
+
(plus always-allowed tools like get_skill, todo_read, todo_write)
|
|
27
|
+
can be used.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
data: The guardrail input data containing tool context
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
ToolGuardrailFunctionOutput indicating whether to allow or reject
|
|
34
|
+
"""
|
|
35
|
+
restrictions = get_active_restrictions()
|
|
36
|
+
|
|
37
|
+
# No active restrictions - allow all tools
|
|
38
|
+
if restrictions is None:
|
|
39
|
+
return ToolGuardrailFunctionOutput.allow()
|
|
40
|
+
|
|
41
|
+
# Guard against missing or empty tool_name (defensive coding)
|
|
42
|
+
tool_name = getattr(data.context, "tool_name", "") or ""
|
|
43
|
+
if not tool_name:
|
|
44
|
+
# Unknown tool - reject with clear message
|
|
45
|
+
return ToolGuardrailFunctionOutput.reject_content(
|
|
46
|
+
message="Unable to verify tool: tool name is missing or empty",
|
|
47
|
+
output_info={"error": "missing_tool_name"},
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Check if tool is allowed
|
|
51
|
+
if restrictions.is_tool_allowed(tool_name):
|
|
52
|
+
return ToolGuardrailFunctionOutput.allow()
|
|
53
|
+
|
|
54
|
+
# Tool is not allowed - reject with informative message
|
|
55
|
+
allowed_list = ", ".join(sorted(restrictions.allowed_tools))
|
|
56
|
+
skills_list = ", ".join(restrictions.loaded_skills)
|
|
57
|
+
|
|
58
|
+
message = (
|
|
59
|
+
f"Tool '{tool_name}' is not permitted while skill(s) [{skills_list}] "
|
|
60
|
+
f"are active with tool restrictions. "
|
|
61
|
+
f"Allowed tools: {allowed_list}. "
|
|
62
|
+
f"You can load a skill without restrictions to clear these limits."
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return ToolGuardrailFunctionOutput.reject_content(
|
|
66
|
+
message=message,
|
|
67
|
+
output_info={
|
|
68
|
+
"blocked_tool": tool_name,
|
|
69
|
+
"active_skills": restrictions.loaded_skills,
|
|
70
|
+
"allowed_tools": list(restrictions.allowed_tools),
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Create the guardrail instance for use in agent configuration
|
|
76
|
+
skill_restriction_guardrail = ToolInputGuardrail(
|
|
77
|
+
guardrail_function=skill_tool_restriction_guardrail,
|
|
78
|
+
name="skill_tool_restrictions",
|
|
79
|
+
)
|
|
@@ -71,9 +71,22 @@ class MCPServerConfigYaml(BaseModel):
|
|
|
71
71
|
blocked_tools: Optional[List[str]] = Field(default=None, description="Blocked tools blacklist")
|
|
72
72
|
|
|
73
73
|
|
|
74
|
+
class SkillsConfig(BaseModel):
|
|
75
|
+
"""Skills configuration settings for progressive disclosure."""
|
|
76
|
+
|
|
77
|
+
enabled: bool = Field(default=True, description="Enable skills feature")
|
|
78
|
+
project_skills_dir: str = Field(
|
|
79
|
+
default=".koder/skills", description="Project-level skills directory"
|
|
80
|
+
)
|
|
81
|
+
user_skills_dir: str = Field(
|
|
82
|
+
default="~/.koder/skills", description="User-level skills directory"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
74
86
|
class KoderConfig(BaseModel):
|
|
75
87
|
"""Root configuration model for Koder CLI."""
|
|
76
88
|
|
|
77
89
|
model: ModelConfig = Field(default_factory=ModelConfig)
|
|
78
90
|
cli: CLIConfig = Field(default_factory=CLIConfig)
|
|
79
91
|
mcp_servers: List[MCPServerConfigYaml] = Field(default_factory=list)
|
|
92
|
+
skills: SkillsConfig = Field(default_factory=SkillsConfig)
|
|
@@ -28,6 +28,14 @@ from .shell import (
|
|
|
28
28
|
shell_kill,
|
|
29
29
|
shell_output,
|
|
30
30
|
)
|
|
31
|
+
from .skill import Skill, SkillLoader, SkillModel, get_skill
|
|
32
|
+
from .skill_context import (
|
|
33
|
+
SkillRestrictions,
|
|
34
|
+
add_skill_restrictions,
|
|
35
|
+
clear_restrictions,
|
|
36
|
+
get_active_restrictions,
|
|
37
|
+
has_active_restrictions,
|
|
38
|
+
)
|
|
31
39
|
from .task import TaskDelegateModel, TaskModel, task_delegate
|
|
32
40
|
from .todo import TodoModel, TodoWriteModel, todo_read, todo_write
|
|
33
41
|
from .web import SearchModel, WebFetchModel, web_fetch, web_search
|
|
@@ -49,6 +57,7 @@ tool_engine.register(GrepModel)(grep_search)
|
|
|
49
57
|
tool_engine.register(LSModel)(list_directory)
|
|
50
58
|
# TODO tools are already registered via @function_tool decorator
|
|
51
59
|
# Removing duplicate registration to avoid naming conflicts
|
|
60
|
+
tool_engine.register(SkillModel)(get_skill)
|
|
52
61
|
tool_engine.register(WebFetchModel)(web_fetch)
|
|
53
62
|
tool_engine.register(TaskDelegateModel)(task_delegate)
|
|
54
63
|
tool_engine.register(GitModel)(git_command)
|
|
@@ -74,6 +83,7 @@ def get_all_tools() -> List[Tool]:
|
|
|
74
83
|
todo_read,
|
|
75
84
|
todo_write,
|
|
76
85
|
task_delegate,
|
|
86
|
+
get_skill,
|
|
77
87
|
]
|
|
78
88
|
|
|
79
89
|
# Filter to only include properly decorated tools
|
|
@@ -98,6 +108,14 @@ __all__ = [
|
|
|
98
108
|
"WebFetchModel",
|
|
99
109
|
"GlobModel",
|
|
100
110
|
"GrepModel",
|
|
111
|
+
"Skill",
|
|
112
|
+
"SkillLoader",
|
|
113
|
+
"SkillModel",
|
|
114
|
+
"SkillRestrictions",
|
|
115
|
+
"add_skill_restrictions",
|
|
116
|
+
"clear_restrictions",
|
|
117
|
+
"get_active_restrictions",
|
|
118
|
+
"has_active_restrictions",
|
|
101
119
|
"TodoModel",
|
|
102
120
|
"TodoWriteModel",
|
|
103
121
|
"TaskModel",
|
|
@@ -119,4 +137,5 @@ __all__ = [
|
|
|
119
137
|
"todo_read",
|
|
120
138
|
"todo_write",
|
|
121
139
|
"task_delegate",
|
|
140
|
+
"get_skill",
|
|
122
141
|
]
|