koder 0.4.5__tar.gz → 0.4.7__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.
Files changed (72) hide show
  1. {koder-0.4.5 → koder-0.4.7}/.claude/settings.local.json +6 -1
  2. {koder-0.4.5 → koder-0.4.7}/PKG-INFO +13 -13
  3. {koder-0.4.5 → koder-0.4.7}/README.md +1 -1
  4. koder-0.4.7/koder_agent/agentic/agent.py +409 -0
  5. {koder-0.4.5 → koder-0.4.7}/koder_agent/agentic/skill_guardrail.py +11 -2
  6. {koder-0.4.5 → koder-0.4.7}/koder_agent/cli.py +11 -17
  7. {koder-0.4.5 → koder-0.4.7}/koder_agent/config/models.py +1 -1
  8. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/__init__.py +19 -4
  9. koder-0.4.7/koder_agent/tools/skill_context.py +229 -0
  10. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/task.py +5 -1
  11. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/client.py +92 -0
  12. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/model_info.py +22 -0
  13. {koder-0.4.5 → koder-0.4.7}/pyproject.toml +12 -12
  14. koder-0.4.7/tests/test_llm_completion_responses.py +65 -0
  15. koder-0.4.7/tests/test_skill_restrictions.py +713 -0
  16. {koder-0.4.5 → koder-0.4.7}/uv.lock +347 -1132
  17. koder-0.4.5/koder_agent/agentic/agent.py +0 -150
  18. koder-0.4.5/koder_agent/tools/skill_context.py +0 -127
  19. koder-0.4.5/tests/test_skill_restrictions.py +0 -340
  20. {koder-0.4.5 → koder-0.4.7}/.github/dependabot.yml +0 -0
  21. {koder-0.4.5 → koder-0.4.7}/.gitignore +0 -0
  22. {koder-0.4.5 → koder-0.4.7}/AGENTS.md +0 -0
  23. {koder-0.4.5 → koder-0.4.7}/CLAUDE.md +0 -0
  24. {koder-0.4.5 → koder-0.4.7}/CONTRIBUTING.md +0 -0
  25. {koder-0.4.5 → koder-0.4.7}/GEMINI.md +0 -0
  26. {koder-0.4.5 → koder-0.4.7}/LICENSE +0 -0
  27. {koder-0.4.5 → koder-0.4.7}/koder_agent/__init__.py +0 -0
  28. {koder-0.4.5 → koder-0.4.7}/koder_agent/agentic/__init__.py +0 -0
  29. {koder-0.4.5 → koder-0.4.7}/koder_agent/agentic/approval_hooks.py +0 -0
  30. {koder-0.4.5 → koder-0.4.7}/koder_agent/agentic/hooks.py +0 -0
  31. {koder-0.4.5 → koder-0.4.7}/koder_agent/config/__init__.py +0 -0
  32. {koder-0.4.5 → koder-0.4.7}/koder_agent/config/cli_handler.py +0 -0
  33. {koder-0.4.5 → koder-0.4.7}/koder_agent/config/manager.py +0 -0
  34. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/__init__.py +0 -0
  35. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/commands.py +0 -0
  36. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/interactive.py +0 -0
  37. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/keyboard_listener.py +0 -0
  38. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/scheduler.py +0 -0
  39. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/security.py +0 -0
  40. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/session.py +0 -0
  41. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/status_line.py +0 -0
  42. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/streaming_display.py +0 -0
  43. {koder-0.4.5 → koder-0.4.7}/koder_agent/core/usage_tracker.py +0 -0
  44. {koder-0.4.5 → koder-0.4.7}/koder_agent/mcp/__init__.py +0 -0
  45. {koder-0.4.5 → koder-0.4.7}/koder_agent/mcp/cli_handler.py +0 -0
  46. {koder-0.4.5 → koder-0.4.7}/koder_agent/mcp/server_config.py +0 -0
  47. {koder-0.4.5 → koder-0.4.7}/koder_agent/mcp/server_factory.py +0 -0
  48. {koder-0.4.5 → koder-0.4.7}/koder_agent/mcp/server_manager.py +0 -0
  49. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/engine.py +0 -0
  50. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/file.py +0 -0
  51. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/search.py +0 -0
  52. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/shell.py +0 -0
  53. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/skill.py +0 -0
  54. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/todo.py +0 -0
  55. {koder-0.4.5 → koder-0.4.7}/koder_agent/tools/web.py +0 -0
  56. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/__init__.py +0 -0
  57. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/prompts.py +0 -0
  58. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/queue.py +0 -0
  59. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/sessions.py +0 -0
  60. {koder-0.4.5 → koder-0.4.7}/koder_agent/utils/terminal_theme.py +0 -0
  61. {koder-0.4.5 → koder-0.4.7}/scripts/upgrade_dependency.py +0 -0
  62. {koder-0.4.5 → koder-0.4.7}/tests/fixtures/skills/large-skill/SKILL.md +0 -0
  63. {koder-0.4.5 → koder-0.4.7}/tests/fixtures/skills/large-skill/reference.md +0 -0
  64. {koder-0.4.5 → koder-0.4.7}/tests/fixtures/skills/medium-skill/SKILL.md +0 -0
  65. {koder-0.4.5 → koder-0.4.7}/tests/fixtures/skills/small-skill/SKILL.md +0 -0
  66. {koder-0.4.5 → koder-0.4.7}/tests/fixtures/skills/template-skill/SKILL.md +0 -0
  67. {koder-0.4.5 → koder-0.4.7}/tests/test_file_tools.py +0 -0
  68. {koder-0.4.5 → koder-0.4.7}/tests/test_model_resolution.py +0 -0
  69. {koder-0.4.5 → koder-0.4.7}/tests/test_shell_background.py +0 -0
  70. {koder-0.4.5 → koder-0.4.7}/tests/test_skill_loader.py +0 -0
  71. {koder-0.4.5 → koder-0.4.7}/tests/test_skill_token_efficiency.py +0 -0
  72. {koder-0.4.5 → koder-0.4.7}/tests/test_web.py +0 -0
@@ -9,7 +9,12 @@
9
9
  "Bash(find:*)",
10
10
  "WebFetch(domain:www.anthropic.com)",
11
11
  "Bash(uv run ruff check:*)",
12
- "mcp__firecrawl__firecrawl_scrape"
12
+ "mcp__firecrawl__firecrawl_scrape",
13
+ "Bash(uv run:*)",
14
+ "Bash(uv run pip:*)",
15
+ "Bash(KODER_MODEL=\"github_copilot/gpt-5.1-codex\" uv run koder:*)",
16
+ "Bash(python3:*)",
17
+ "Bash(timeout 90 bash -c \"KODER_MODEL=''github_copilot/gpt-5.1-codex'' uv run koder ''respond with just hello''\")"
13
18
  ],
14
19
  "deny": [],
15
20
  "ask": []
@@ -1,33 +1,33 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koder
3
- Version: 0.4.5
3
+ Version: 0.4.7
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
7
7
  Author: Pengfei Ni
8
8
  License-File: LICENSE
9
9
  Keywords: agent,agentic,ai,copilot,litellm,openai,vibe coding
10
- Requires-Python: >=3.9
10
+ Requires-Python: >=3.10
11
11
  Requires-Dist: aiosqlite>=0.21.0
12
12
  Requires-Dist: apscheduler>=3.11.1
13
13
  Requires-Dist: backoff>=2.2.1
14
- Requires-Dist: beautifulsoup4>=4.14.2
14
+ Requires-Dist: beautifulsoup4>=4.14.3
15
15
  Requires-Dist: cryptography>=46.0.3
16
- Requires-Dist: ddgs>=8.0.1
16
+ Requires-Dist: ddgs>=9.9.3
17
17
  Requires-Dist: fastapi-sso>=0.18.0
18
- Requires-Dist: fastapi>=0.122.0
19
- Requires-Dist: google-cloud-aiplatform>=1.128.0
18
+ Requires-Dist: fastapi>=0.124.2
19
+ Requires-Dist: google-cloud-aiplatform>=1.130.0
20
20
  Requires-Dist: httpx[socks]>=0.28.1
21
- Requires-Dist: litellm>=1.80.5
22
- Requires-Dist: openai-agents[litellm]>=0.6.1
23
- Requires-Dist: openai>=2.8.1
24
- Requires-Dist: orjson>=3.11.4
21
+ Requires-Dist: litellm>=1.80.9
22
+ Requires-Dist: openai-agents[litellm]>=0.6.3
23
+ Requires-Dist: openai>=2.11.0
24
+ Requires-Dist: orjson>=3.11.5
25
25
  Requires-Dist: prompt-toolkit>=3.0.52
26
- Requires-Dist: pydantic>=2.12.4
26
+ Requires-Dist: pydantic>=2.12.5
27
27
  Requires-Dist: pyjwt>=2.10.1
28
28
  Requires-Dist: pynacl>=1.6.1
29
29
  Requires-Dist: python-multipart>=0.0.20
30
- Requires-Dist: pyyaml>=6.0
30
+ Requires-Dist: pyyaml>=6.0.3
31
31
  Requires-Dist: requests>=2.32.5
32
32
  Requires-Dist: rich>=14.2.0
33
33
  Requires-Dist: tiktoken>=0.12.0
@@ -133,7 +133,7 @@ model:
133
133
  base_url: null # Custom API endpoint (optional)
134
134
 
135
135
  # Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
136
- reasoning_effort: "medium" # none, minimal, low, medium, high, or null
136
+ reasoning_effort: null # none, minimal, low, medium, high, or null (default: null)
137
137
 
138
138
  # CLI defaults
139
139
  cli:
@@ -97,7 +97,7 @@ model:
97
97
  base_url: null # Custom API endpoint (optional)
98
98
 
99
99
  # Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
100
- reasoning_effort: "medium" # none, minimal, low, medium, high, or null
100
+ reasoning_effort: null # none, minimal, low, medium, high, or null (default: null)
101
101
 
102
102
  # CLI defaults
103
103
  cli:
@@ -0,0 +1,409 @@
1
+ """Agent definitions and hooks for Koder."""
2
+
3
+ import logging
4
+ import uuid
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import backoff
9
+ import litellm
10
+ from agents import Agent, ModelSettings
11
+ from agents.extensions.models.litellm_model import LitellmModel
12
+ from agents.items import ItemHelpers, ModelResponse, TResponseStreamEvent
13
+ from agents.models.openai_responses import Converter as ResponsesConverter
14
+ from agents.tracing import generation_span
15
+ from agents.usage import Usage
16
+ from agents.util._json import _to_dump_compatible
17
+ from openai import omit
18
+ from openai._models import construct_type
19
+ from openai.types.shared import Reasoning
20
+ from rich.console import Console
21
+
22
+ from ..config import get_config
23
+ from ..mcp import load_mcp_servers
24
+ from ..tools.skill import SkillLoader
25
+ from ..utils.client import get_litellm_model_kwargs, get_model_name, is_native_openai_provider
26
+ from ..utils.model_info import get_maximum_output_tokens, should_use_reasoning_param
27
+ from ..utils.prompts import KODER_SYSTEM_PROMPT
28
+
29
+ console = Console()
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class RetryingLitellmModel(LitellmModel):
34
+ """LitellmModel with backoff retry logic."""
35
+
36
+ _EXC = getattr(litellm, "exceptions", litellm)
37
+ _EXC_TUPLE = (
38
+ getattr(_EXC, "ServiceUnavailableError", Exception),
39
+ getattr(_EXC, "RateLimitError", Exception),
40
+ getattr(_EXC, "APIConnectionError", Exception),
41
+ getattr(_EXC, "Timeout", Exception),
42
+ getattr(_EXC, "InternalServerError", Exception),
43
+ )
44
+
45
+ def _should_use_responses_api(self) -> bool:
46
+ """
47
+ GitHub Copilot Codex models are not accessible via /chat/completions.
48
+ Route them through LiteLLM's Responses API instead.
49
+ """
50
+ model_lower = str(self.model).lower()
51
+ return "github_copilot/" in model_lower and "codex" in model_lower
52
+
53
+ async def _fetch_responses_api(
54
+ self,
55
+ system_instructions: str | None,
56
+ input: str | list,
57
+ model_settings: ModelSettings,
58
+ tools: list,
59
+ output_schema,
60
+ handoffs: list,
61
+ *,
62
+ previous_response_id: str | None,
63
+ stream: bool,
64
+ prompt: Any | None,
65
+ ):
66
+ if not hasattr(litellm, "aresponses"):
67
+ raise RuntimeError(
68
+ "GitHub Copilot Codex models require LiteLLM Responses API support. "
69
+ "Please upgrade litellm to a version that provides `aresponses`."
70
+ )
71
+ list_input = ItemHelpers.input_to_new_input_list(input)
72
+ list_input = _to_dump_compatible(list_input)
73
+
74
+ if model_settings.parallel_tool_calls and tools:
75
+ parallel_tool_calls: bool | None = True
76
+ elif model_settings.parallel_tool_calls is False:
77
+ parallel_tool_calls = False
78
+ else:
79
+ parallel_tool_calls = None
80
+
81
+ tool_choice = ResponsesConverter.convert_tool_choice(model_settings.tool_choice)
82
+ if tool_choice is omit:
83
+ tool_choice = None
84
+
85
+ converted_tools = ResponsesConverter.convert_tools(tools, handoffs)
86
+ tools_payload = _to_dump_compatible(converted_tools.tools)
87
+ if not tools_payload:
88
+ tools_payload = None
89
+
90
+ text_param = ResponsesConverter.get_response_format(output_schema)
91
+ if text_param is omit:
92
+ text_param = None
93
+
94
+ include_set = set(converted_tools.includes)
95
+ response_include = getattr(model_settings, "response_include", None)
96
+ if response_include is not None:
97
+ include_set.update(response_include)
98
+ top_logprobs = getattr(model_settings, "top_logprobs", None)
99
+ if top_logprobs is not None:
100
+ include_set.add("message.output_text.logprobs")
101
+ include = list(include_set) if include_set else None
102
+
103
+ extra_args: dict[str, Any] = dict(model_settings.extra_args or {})
104
+ if top_logprobs is not None:
105
+ extra_args["top_logprobs"] = top_logprobs
106
+ verbosity = getattr(model_settings, "verbosity", None)
107
+ if verbosity is not None:
108
+ if text_param is not None and isinstance(text_param, dict):
109
+ text_param["verbosity"] = verbosity
110
+ else:
111
+ text_param = {"verbosity": verbosity}
112
+
113
+ aresponses_kwargs: dict[str, Any] = {
114
+ "model": self.model,
115
+ "input": list_input,
116
+ "include": include,
117
+ "instructions": system_instructions,
118
+ "tools": tools_payload,
119
+ "tool_choice": tool_choice,
120
+ "parallel_tool_calls": parallel_tool_calls,
121
+ "temperature": model_settings.temperature,
122
+ "top_p": model_settings.top_p,
123
+ "truncation": getattr(model_settings, "truncation", None),
124
+ "max_output_tokens": model_settings.max_tokens,
125
+ "reasoning": getattr(model_settings, "reasoning", None),
126
+ "metadata": model_settings.metadata,
127
+ "previous_response_id": previous_response_id,
128
+ "prompt": prompt,
129
+ "stream": stream,
130
+ "extra_headers": self._merge_headers(model_settings),
131
+ "extra_query": model_settings.extra_query,
132
+ "extra_body": model_settings.extra_body,
133
+ **extra_args,
134
+ }
135
+ if self.api_key:
136
+ aresponses_kwargs["api_key"] = self.api_key
137
+ if self.base_url:
138
+ aresponses_kwargs["base_url"] = self.base_url
139
+
140
+ return await litellm.aresponses(**aresponses_kwargs)
141
+
142
+ @backoff.on_exception(
143
+ backoff.expo,
144
+ _EXC_TUPLE,
145
+ max_tries=3,
146
+ jitter=backoff.full_jitter,
147
+ )
148
+ async def get_response(
149
+ self,
150
+ system_instructions: str | None,
151
+ input: str | list,
152
+ model_settings: ModelSettings,
153
+ tools: list,
154
+ output_schema,
155
+ handoffs: list,
156
+ tracing,
157
+ previous_response_id: str | None = None,
158
+ conversation_id: str | None = None, # unused for LiteLLM responses
159
+ prompt: Any | None = None,
160
+ ) -> ModelResponse:
161
+ if not self._should_use_responses_api():
162
+ return await super().get_response(
163
+ system_instructions,
164
+ input,
165
+ model_settings,
166
+ tools,
167
+ output_schema,
168
+ handoffs,
169
+ tracing,
170
+ previous_response_id=previous_response_id,
171
+ conversation_id=conversation_id,
172
+ prompt=prompt,
173
+ )
174
+
175
+ with generation_span(
176
+ model=str(self.model),
177
+ model_config=model_settings.to_json_dict()
178
+ | {"base_url": str(self.base_url or ""), "model_impl": "litellm-responses"},
179
+ disabled=tracing.is_disabled(),
180
+ ) as span_generation:
181
+ response = await self._fetch_responses_api(
182
+ system_instructions,
183
+ input,
184
+ model_settings,
185
+ tools,
186
+ output_schema,
187
+ handoffs,
188
+ previous_response_id=previous_response_id,
189
+ stream=False,
190
+ prompt=prompt,
191
+ )
192
+
193
+ response_usage = getattr(response, "usage", None)
194
+ if response_usage:
195
+ usage_kwargs: dict[str, Any] = {
196
+ "requests": 1,
197
+ "input_tokens": getattr(response_usage, "input_tokens", 0) or 0,
198
+ "output_tokens": getattr(response_usage, "output_tokens", 0) or 0,
199
+ "total_tokens": getattr(response_usage, "total_tokens", 0) or 0,
200
+ }
201
+ usage = Usage(**usage_kwargs)
202
+ span_generation.span_data.usage = {
203
+ "input_tokens": usage.input_tokens,
204
+ "output_tokens": usage.output_tokens,
205
+ }
206
+ else:
207
+ usage = Usage()
208
+
209
+ if tracing.include_data():
210
+ try:
211
+ span_generation.span_data.output = (
212
+ [response.model_dump()] if hasattr(response, "model_dump") else [response]
213
+ )
214
+ except Exception:
215
+ pass
216
+
217
+ return ModelResponse(
218
+ output=getattr(response, "output", []) or [],
219
+ usage=usage,
220
+ response_id=getattr(response, "id", None),
221
+ )
222
+
223
+ @backoff.on_exception(
224
+ backoff.expo,
225
+ _EXC_TUPLE,
226
+ max_tries=5,
227
+ jitter=backoff.full_jitter,
228
+ )
229
+ async def stream_response(
230
+ self,
231
+ system_instructions: str | None,
232
+ input: str | list,
233
+ model_settings: ModelSettings,
234
+ tools: list,
235
+ output_schema,
236
+ handoffs: list,
237
+ tracing,
238
+ previous_response_id: str | None = None,
239
+ conversation_id: str | None = None, # unused for LiteLLM responses
240
+ prompt: Any | None = None,
241
+ ):
242
+ if not self._should_use_responses_api():
243
+ async for chunk in super().stream_response(
244
+ system_instructions,
245
+ input,
246
+ model_settings,
247
+ tools,
248
+ output_schema,
249
+ handoffs,
250
+ tracing,
251
+ previous_response_id=previous_response_id,
252
+ conversation_id=conversation_id,
253
+ prompt=prompt,
254
+ ):
255
+ yield chunk
256
+ return
257
+
258
+ with generation_span(
259
+ model=str(self.model),
260
+ model_config=model_settings.to_json_dict()
261
+ | {"base_url": str(self.base_url or ""), "model_impl": "litellm-responses"},
262
+ disabled=tracing.is_disabled(),
263
+ ) as span_generation:
264
+ stream = await self._fetch_responses_api(
265
+ system_instructions,
266
+ input,
267
+ model_settings,
268
+ tools,
269
+ output_schema,
270
+ handoffs,
271
+ previous_response_id=previous_response_id,
272
+ stream=True,
273
+ prompt=prompt,
274
+ )
275
+
276
+ final_response = None
277
+ async for chunk in stream:
278
+ if hasattr(chunk, "model_dump"):
279
+ try:
280
+ data = chunk.model_dump()
281
+ except Exception:
282
+ data = chunk
283
+ else:
284
+ data = chunk
285
+
286
+ if isinstance(data, dict):
287
+ event_type = data.get("type")
288
+ if hasattr(event_type, "value"):
289
+ data["type"] = event_type.value
290
+ elif not isinstance(event_type, str):
291
+ data["type"] = str(event_type)
292
+ event = construct_type(value=data, type_=TResponseStreamEvent)
293
+ else:
294
+ event = chunk
295
+
296
+ if getattr(event, "type", None) == "response.completed":
297
+ final_response = getattr(event, "response", None)
298
+ yield event
299
+
300
+ if final_response is not None and getattr(final_response, "usage", None):
301
+ usage_obj = final_response.usage
302
+ span_generation.span_data.usage = {
303
+ "input_tokens": getattr(usage_obj, "input_tokens", 0) or 0,
304
+ "output_tokens": getattr(usage_obj, "output_tokens", 0) or 0,
305
+ }
306
+ if tracing.include_data() and final_response is not None:
307
+ try:
308
+ span_generation.span_data.output = (
309
+ [final_response.model_dump()]
310
+ if hasattr(final_response, "model_dump")
311
+ else [final_response]
312
+ )
313
+ except Exception:
314
+ pass
315
+
316
+
317
+ def _get_skills_metadata(config) -> str:
318
+ """Load and return skills metadata from configured directories.
319
+
320
+ Priority: project skills directory > user skills directory.
321
+ Skills with the same name in project dir override user dir.
322
+ """
323
+ if not config.skills.enabled:
324
+ return "Skills are disabled."
325
+
326
+ all_skills = {}
327
+
328
+ # Load user skills first (lower priority)
329
+ user_dir = Path(config.skills.user_skills_dir).expanduser()
330
+ if user_dir.exists():
331
+ user_loader = SkillLoader(user_dir)
332
+ for skill in user_loader.discover_skills():
333
+ all_skills[skill.name] = skill
334
+
335
+ # Load project skills (higher priority - overrides user skills)
336
+ project_dir = Path(config.skills.project_skills_dir)
337
+ if project_dir.exists():
338
+ project_loader = SkillLoader(project_dir)
339
+ for skill in project_loader.discover_skills():
340
+ all_skills[skill.name] = skill
341
+
342
+ if not all_skills:
343
+ return "No skills are currently available."
344
+
345
+ lines = ["Available skills:", ""]
346
+ for skill in sorted(all_skills.values(), key=lambda s: s.name.lower()):
347
+ description = skill.description.strip()
348
+ lines.append(f"- {skill.name}: {description}")
349
+
350
+ return "\n".join(lines)
351
+
352
+
353
+ async def create_dev_agent(tools) -> Agent:
354
+ """Create the main development agent with MCP servers."""
355
+ config = get_config()
356
+ mcp_servers = await load_mcp_servers()
357
+
358
+ # Determine the model to use: native OpenAI string or LitellmModel instance
359
+ if is_native_openai_provider():
360
+ # Use string model name for native OpenAI providers (handled by default client)
361
+ model = get_model_name()
362
+ else:
363
+ # Use LitellmModel with explicit base_url and api_key
364
+ litellm_kwargs = get_litellm_model_kwargs()
365
+ model = RetryingLitellmModel(
366
+ model=litellm_kwargs["model"],
367
+ base_url=litellm_kwargs["base_url"],
368
+ api_key=litellm_kwargs["api_key"],
369
+ )
370
+
371
+ # Build model_settings with reasoning if configured
372
+ model_name_str = get_model_name() # Always get string name for max_tokens lookup
373
+ model_settings = ModelSettings(
374
+ metadata={"source": "koder"},
375
+ max_tokens=get_maximum_output_tokens(model_name_str),
376
+ )
377
+ # Only set reasoning parameter for native OpenAI providers
378
+ # LiteLLM-based providers (GitHub Copilot, Anthropic, etc.) don't support the Reasoning object
379
+ if config.model.reasoning_effort is not None and should_use_reasoning_param():
380
+ effort = None if config.model.reasoning_effort == "none" else config.model.reasoning_effort
381
+ model_settings.reasoning = Reasoning(effort=effort, summary="detailed")
382
+
383
+ # Build system prompt with skills metadata (Progressive Disclosure Level 1)
384
+ skills_metadata = _get_skills_metadata(config)
385
+ system_prompt = KODER_SYSTEM_PROMPT.replace("{SKILLS_METADATA}", skills_metadata)
386
+
387
+ dev_agent = Agent(
388
+ name="Koder",
389
+ model=model,
390
+ instructions=system_prompt,
391
+ tools=tools,
392
+ mcp_servers=mcp_servers,
393
+ model_settings=model_settings,
394
+ )
395
+
396
+ if "github_copilot" in model_name_str:
397
+ dev_agent.model_settings.extra_headers = {
398
+ "copilot-integration-id": "vscode-chat",
399
+ "editor-version": "vscode/1.98.1",
400
+ "editor-plugin-version": "copilot-chat/0.26.7",
401
+ "user-agent": "GitHubCopilotChat/0.26.7",
402
+ "openai-intent": "conversation-panel",
403
+ "x-github-api-version": "2025-04-01",
404
+ "x-request-id": str(uuid.uuid4()),
405
+ "x-vscode-user-agent-library-version": "electron-fetch",
406
+ }
407
+
408
+ # planner.handoffs.append(dev_agent)
409
+ return dev_agent
@@ -26,6 +26,12 @@ def skill_tool_restriction_guardrail(
26
26
  (plus always-allowed tools like get_skill, todo_read, todo_write)
27
27
  can be used.
28
28
 
29
+ Supports pattern matching for fine-grained control:
30
+ - "read_file" - Exact tool name match
31
+ - "run_shell:git *" - Shell commands matching glob pattern
32
+ - "run_shell:*" - All shell commands allowed
33
+ - "*" - Wildcard, all tools allowed
34
+
29
35
  Args:
30
36
  data: The guardrail input data containing tool context
31
37
 
@@ -47,8 +53,11 @@ def skill_tool_restriction_guardrail(
47
53
  output_info={"error": "missing_tool_name"},
48
54
  )
49
55
 
50
- # Check if tool is allowed
51
- if restrictions.is_tool_allowed(tool_name):
56
+ # Get tool arguments for pattern matching (e.g., shell command matching)
57
+ tool_args = getattr(data.context, "tool_arguments", None)
58
+
59
+ # Check if tool is allowed (with pattern matching support)
60
+ if restrictions.is_tool_allowed(tool_name, tool_args):
52
61
  return ToolGuardrailFunctionOutput.allow()
53
62
 
54
63
  # Tool is not allowed - reject with informative message
@@ -132,11 +132,8 @@ async def main():
132
132
  parser.add_argument(
133
133
  "--resume", action="store_true", help="List and select a previous session to resume"
134
134
  )
135
- stream_group = parser.add_mutually_exclusive_group()
136
- stream_group.add_argument(
137
- "--stream", action="store_true", help="Force enable streaming mode"
138
- )
139
- stream_group.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
135
+ parser.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
136
+ parser.add_argument("--debug", action="store_true", help="Enable debug logging")
140
137
 
141
138
  subparsers = parser.add_subparsers(dest="command", help="Available commands")
142
139
  create_mcp_subparsers(subparsers)
@@ -148,11 +145,8 @@ async def main():
148
145
  parser.add_argument(
149
146
  "--resume", action="store_true", help="List and select a previous session to resume"
150
147
  )
151
- stream_group = parser.add_mutually_exclusive_group()
152
- stream_group.add_argument(
153
- "--stream", action="store_true", help="Force enable streaming mode"
154
- )
155
- stream_group.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
148
+ parser.add_argument("--no-stream", action="store_true", help="Disable streaming mode")
149
+ parser.add_argument("--debug", action="store_true", help="Enable debug logging")
156
150
 
157
151
  parser.add_argument(
158
152
  "prompt", nargs="*", help="Prompt text (if not provided, starts interactive mode)"
@@ -160,6 +154,11 @@ async def main():
160
154
 
161
155
  args = parser.parse_args()
162
156
 
157
+ # Configure logging level based on --debug flag
158
+ if args.debug:
159
+ logging.getLogger().setLevel(logging.DEBUG)
160
+ logging.debug("Debug logging enabled")
161
+
163
162
  # Set command to None for prompt mode
164
163
  if not hasattr(args, "command"):
165
164
  args.command = None
@@ -195,13 +194,8 @@ async def main():
195
194
 
196
195
  context = await load_context()
197
196
 
198
- # Determine streaming setting: CLI flag overrides config
199
- if args.stream:
200
- streaming = True
201
- elif args.no_stream:
202
- streaming = False
203
- else:
204
- streaming = config.cli.stream
197
+ # Determine streaming setting: --no-stream overrides config default
198
+ streaming = config.cli.stream and not args.no_stream
205
199
 
206
200
  scheduler = AgentScheduler(session_id=args.session, streaming=streaming)
207
201
 
@@ -39,7 +39,7 @@ class ModelConfig(BaseModel):
39
39
 
40
40
  # NEW: Reasoning effort setting
41
41
  reasoning_effort: Optional[Literal["none", "minimal", "low", "medium", "high"]] = Field(
42
- default="medium",
42
+ default=None,
43
43
  description=(
44
44
  "Reasoning effort for reasoning models (none, minimal, low, medium, high, or null to"
45
45
  " not set)"
@@ -2,8 +2,9 @@
2
2
 
3
3
  from typing import List
4
4
 
5
- from agents import Tool
5
+ from agents import FunctionTool, Tool
6
6
 
7
+ from ..agentic.skill_guardrail import skill_restriction_guardrail
7
8
  from .engine import ToolEngine
8
9
  from .file import (
9
10
  FileEditModel,
@@ -64,7 +65,11 @@ tool_engine.register(GitModel)(git_command)
64
65
 
65
66
 
66
67
  def get_all_tools() -> List[Tool]:
67
- """Get all registered tools as a list."""
68
+ """Get all registered tools as a list.
69
+
70
+ Each FunctionTool is configured with the skill_restriction_guardrail
71
+ to enforce skill-based tool restrictions when skills are active.
72
+ """
68
73
  # Collect all @function_tool decorated functions directly
69
74
  tools = [
70
75
  read_file,
@@ -86,8 +91,18 @@ def get_all_tools() -> List[Tool]:
86
91
  get_skill,
87
92
  ]
88
93
 
89
- # Filter to only include properly decorated tools
90
- return [tool for tool in tools if hasattr(tool, "name")]
94
+ # Filter to only include properly decorated tools and attach guardrails
95
+ result = []
96
+ for tool in tools:
97
+ if hasattr(tool, "name"):
98
+ # Attach skill restriction guardrail to each FunctionTool
99
+ if isinstance(tool, FunctionTool):
100
+ if tool.tool_input_guardrails is None:
101
+ tool.tool_input_guardrails = [skill_restriction_guardrail]
102
+ elif skill_restriction_guardrail not in tool.tool_input_guardrails:
103
+ tool.tool_input_guardrails.append(skill_restriction_guardrail)
104
+ result.append(tool)
105
+ return result
91
106
 
92
107
 
93
108
  __all__ = [