koder 0.4.7__tar.gz → 0.4.8__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.7 → koder-0.4.8}/.claude/settings.local.json +3 -1
- koder-0.4.8/.uv-cache/.gitignore +1 -0
- koder-0.4.8/.uv-cache/CACHEDIR.TAG +1 -0
- koder-0.4.8/.uv-cache/interpreter-v4/aarch64/72afda6228b75bee.msgpack +1 -0
- koder-0.4.8/.uv-cache/sdists-v7/.git +0 -0
- koder-0.4.8/.uv-cache/sdists-v7/.gitignore +0 -0
- {koder-0.4.7 → koder-0.4.8}/PKG-INFO +12 -11
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/scheduler.py +41 -20
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/streaming_display.py +93 -31
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/file.py +173 -21
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/model_info.py +8 -0
- {koder-0.4.7 → koder-0.4.8}/pyproject.toml +12 -11
- koder-0.4.8/tests/test_capture_usage.py +217 -0
- koder-0.4.8/tests/test_file_tools.py +1071 -0
- koder-0.4.8/tests/test_model_info.py +144 -0
- koder-0.4.8/tests/test_streaming_display.py +381 -0
- koder-0.4.8/tests/test_usage_tracker.py +233 -0
- {koder-0.4.7 → koder-0.4.8}/uv.lock +135 -54
- koder-0.4.7/tests/test_file_tools.py +0 -496
- {koder-0.4.7 → koder-0.4.8}/.github/dependabot.yml +0 -0
- {koder-0.4.7 → koder-0.4.8}/.gitignore +0 -0
- {koder-0.4.7 → koder-0.4.8}/AGENTS.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/CLAUDE.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/CONTRIBUTING.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/GEMINI.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/LICENSE +0 -0
- {koder-0.4.7 → koder-0.4.8}/README.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/agentic/agent.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/agentic/skill_guardrail.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/cli.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/config/manager.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/config/models.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/commands.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/keyboard_listener.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/security.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/session.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/search.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/skill.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/skill_context.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/task.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/tools/web.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/client.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/fixtures/skills/large-skill/SKILL.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/fixtures/skills/large-skill/reference.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/fixtures/skills/medium-skill/SKILL.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/fixtures/skills/small-skill/SKILL.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/fixtures/skills/template-skill/SKILL.md +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_llm_completion_responses.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_model_resolution.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_shell_background.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_skill_loader.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_skill_restrictions.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_skill_token_efficiency.py +0 -0
- {koder-0.4.7 → koder-0.4.8}/tests/test_web.py +0 -0
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"Bash(uv run pip:*)",
|
|
15
15
|
"Bash(KODER_MODEL=\"github_copilot/gpt-5.1-codex\" uv run koder:*)",
|
|
16
16
|
"Bash(python3:*)",
|
|
17
|
-
"Bash(timeout 90 bash -c \"KODER_MODEL=''github_copilot/gpt-5.1-codex'' uv run koder ''respond with just hello''\")"
|
|
17
|
+
"Bash(timeout 90 bash -c \"KODER_MODEL=''github_copilot/gpt-5.1-codex'' uv run koder ''respond with just hello''\")",
|
|
18
|
+
"Bash(git add:*)",
|
|
19
|
+
"Bash(git commit:*)"
|
|
18
20
|
],
|
|
19
21
|
"deny": [],
|
|
20
22
|
"ask": []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Signature: 8a477f597d28d172789f06886806bc55
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
���g����*������macos�aarch64��implementation_name�cpython�implementation_version�3.13.1�os_name�posix�platform_machine�arm64�platform_python_implementation�CPython�platform_release�25.1.0�platform_system�Darwin�platform_version�eDarwin Kernel Version 25.1.0: Mon Oct 20 19:34:03 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8112�python_full_version�3.13.1�python_version�3.13�sys_platform�darwin��@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�'/Users/fei/coding-agent/koder/.venv/bin�#/Users/fei/coding-agent/koder/.venv�;/Users/fei/coding-agent/koder/.venv/include/site/python3.13��lib/python3.13/site-packages�lib/python3.13/site-packages�bin��include/site/python3.13��#/Users/fei/coding-agent/koder/.venv�C/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none�C/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/bin/python3.13�//Users/fei/coding-agent/koder/.venv/bin/python3��2/Users/fei/coding-agent/koder/.uv-cache/.tmpX75eW6�U/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python313.zip�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13�^/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13/lib-dynload�@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�/Users/fei/coding-agent/koder�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13â64�
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
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
|
|
@@ -8,30 +8,31 @@ Author: Pengfei Ni
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Keywords: agent,agentic,ai,copilot,litellm,openai,vibe coding
|
|
10
10
|
Requires-Python: >=3.10
|
|
11
|
-
Requires-Dist: aiosqlite>=0.
|
|
12
|
-
Requires-Dist: apscheduler>=3.11.
|
|
11
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
12
|
+
Requires-Dist: apscheduler>=3.11.2
|
|
13
13
|
Requires-Dist: backoff>=2.2.1
|
|
14
14
|
Requires-Dist: beautifulsoup4>=4.14.3
|
|
15
15
|
Requires-Dist: cryptography>=46.0.3
|
|
16
|
-
Requires-Dist: ddgs>=9.
|
|
17
|
-
Requires-Dist: fastapi-sso>=0.
|
|
18
|
-
Requires-Dist: fastapi>=0.
|
|
19
|
-
Requires-Dist: google-cloud-aiplatform>=1.
|
|
16
|
+
Requires-Dist: ddgs>=9.10.0
|
|
17
|
+
Requires-Dist: fastapi-sso>=0.19.0
|
|
18
|
+
Requires-Dist: fastapi>=0.127.0
|
|
19
|
+
Requires-Dist: google-cloud-aiplatform>=1.132.0
|
|
20
20
|
Requires-Dist: httpx[socks]>=0.28.1
|
|
21
|
-
Requires-Dist: litellm>=1.80.
|
|
22
|
-
Requires-Dist: openai-agents[litellm]>=0.6.
|
|
23
|
-
Requires-Dist: openai>=2.
|
|
21
|
+
Requires-Dist: litellm>=1.80.11
|
|
22
|
+
Requires-Dist: openai-agents[litellm]>=0.6.4
|
|
23
|
+
Requires-Dist: openai>=2.14.0
|
|
24
24
|
Requires-Dist: orjson>=3.11.5
|
|
25
25
|
Requires-Dist: prompt-toolkit>=3.0.52
|
|
26
26
|
Requires-Dist: pydantic>=2.12.5
|
|
27
27
|
Requires-Dist: pyjwt>=2.10.1
|
|
28
28
|
Requires-Dist: pynacl>=1.6.1
|
|
29
|
-
Requires-Dist: python-multipart>=0.0.
|
|
29
|
+
Requires-Dist: python-multipart>=0.0.21
|
|
30
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
|
|
34
34
|
Requires-Dist: websockets>=15.0.1
|
|
35
|
+
Requires-Dist: whatthepatch>=1.0.7
|
|
35
36
|
Description-Content-Type: text/markdown
|
|
36
37
|
|
|
37
38
|
# Koder
|
|
@@ -131,7 +131,7 @@ class AgentScheduler:
|
|
|
131
131
|
max_turns=50,
|
|
132
132
|
)
|
|
133
133
|
# Capture token usage from result
|
|
134
|
-
self._capture_usage(result)
|
|
134
|
+
await self._capture_usage(result)
|
|
135
135
|
|
|
136
136
|
# Filter output for security
|
|
137
137
|
response = self._filter_output(result.final_output)
|
|
@@ -358,7 +358,7 @@ class AgentScheduler:
|
|
|
358
358
|
console.print()
|
|
359
359
|
|
|
360
360
|
# Capture any usage data we can
|
|
361
|
-
self._capture_usage(result)
|
|
361
|
+
await self._capture_usage(result)
|
|
362
362
|
|
|
363
363
|
# Return partial text for session history
|
|
364
364
|
return partial_text or "Operation cancelled. You can provide additional instructions."
|
|
@@ -410,7 +410,7 @@ class AgentScheduler:
|
|
|
410
410
|
print() # Add spacing after
|
|
411
411
|
|
|
412
412
|
# Capture token usage from streaming result
|
|
413
|
-
self._capture_usage(result)
|
|
413
|
+
await self._capture_usage(result)
|
|
414
414
|
|
|
415
415
|
# Get final text response for context saving
|
|
416
416
|
final_response = display_manager.get_final_text()
|
|
@@ -461,28 +461,49 @@ class AgentScheduler:
|
|
|
461
461
|
)
|
|
462
462
|
return text
|
|
463
463
|
|
|
464
|
-
def _capture_usage(self, result) -> None:
|
|
465
|
-
"""Capture token usage from a Runner result.
|
|
464
|
+
async def _capture_usage(self, result) -> None:
|
|
465
|
+
"""Capture token usage from a Runner result.
|
|
466
|
+
|
|
467
|
+
If the API doesn't return usage data, falls back to tiktoken estimation
|
|
468
|
+
using the session's existing _estimate_tokens method.
|
|
469
|
+
"""
|
|
466
470
|
try:
|
|
471
|
+
input_tokens = 0
|
|
472
|
+
output_tokens = 0
|
|
473
|
+
context_tokens = None
|
|
474
|
+
|
|
475
|
+
# Try to get usage from the API response
|
|
467
476
|
if hasattr(result, "context_wrapper") and hasattr(result.context_wrapper, "usage"):
|
|
468
477
|
usage = result.context_wrapper.usage
|
|
469
478
|
input_tokens = getattr(usage, "input_tokens", 0) or 0
|
|
470
479
|
output_tokens = getattr(usage, "output_tokens", 0) or 0
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
480
|
+
|
|
481
|
+
if hasattr(usage, "request_usage_entries") and usage.request_usage_entries:
|
|
482
|
+
last_req = usage.request_usage_entries[-1]
|
|
483
|
+
context_tokens = last_req.total_tokens
|
|
484
|
+
|
|
485
|
+
# Fallback: estimate tokens using session's tiktoken encoder
|
|
486
|
+
if input_tokens <= 0 and output_tokens <= 0:
|
|
487
|
+
# Estimate output tokens from final_output
|
|
488
|
+
final_output = getattr(result, "final_output", None)
|
|
489
|
+
if final_output and hasattr(self.session, "encoder"):
|
|
490
|
+
output_text = str(final_output)
|
|
491
|
+
output_tokens = len(self.session.encoder.encode(output_text))
|
|
492
|
+
|
|
493
|
+
# Estimate input/context tokens from session history
|
|
494
|
+
try:
|
|
495
|
+
session_items = await self.session.get_items()
|
|
496
|
+
if session_items:
|
|
497
|
+
input_tokens = self.session._estimate_tokens(session_items)
|
|
498
|
+
context_tokens = input_tokens + output_tokens
|
|
499
|
+
except Exception:
|
|
500
|
+
pass
|
|
501
|
+
|
|
502
|
+
# Record usage if we have any tokens
|
|
503
|
+
if input_tokens > 0 or output_tokens > 0:
|
|
504
|
+
self.usage_tracker.record_usage(
|
|
505
|
+
input_tokens, output_tokens, context_tokens=context_tokens
|
|
506
|
+
)
|
|
486
507
|
except Exception:
|
|
487
508
|
# Silently ignore usage capture errors
|
|
488
509
|
pass
|
|
@@ -713,15 +713,38 @@ class StreamingDisplayManager:
|
|
|
713
713
|
else:
|
|
714
714
|
return f"Output {len(lines)} lines"
|
|
715
715
|
|
|
716
|
-
# Handle
|
|
717
|
-
elif tool_name
|
|
718
|
-
if "
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
716
|
+
# Handle edit_file tool (diff-based editing)
|
|
717
|
+
elif tool_name == "edit_file":
|
|
718
|
+
if "Successfully applied diff" in clean_output:
|
|
719
|
+
# Extract just the success message, diff content is shown separately
|
|
720
|
+
return "Diff applied"
|
|
721
|
+
elif "Failed to apply diff" in clean_output:
|
|
722
|
+
# Show error message
|
|
723
|
+
error_start = clean_output.find("Failed to apply diff")
|
|
724
|
+
error_msg = clean_output[error_start:].split("\n")[0]
|
|
725
|
+
return error_msg[:80]
|
|
726
|
+
elif "File not found" in clean_output:
|
|
727
|
+
return clean_output.split("\n")[0]
|
|
722
728
|
else:
|
|
723
729
|
return clean_output[:60] + ("..." if len(clean_output) > 60 else "")
|
|
724
730
|
|
|
731
|
+
# Handle write_file tool
|
|
732
|
+
elif tool_name == "write_file":
|
|
733
|
+
if "Created" in clean_output:
|
|
734
|
+
# Extract just the first line (e.g., "Created /path/file.txt (123 bytes)")
|
|
735
|
+
return clean_output.split("\n")[0]
|
|
736
|
+
elif "Updated" in clean_output:
|
|
737
|
+
return clean_output.split("\n")[0]
|
|
738
|
+
else:
|
|
739
|
+
return clean_output.split("\n")[0][:60]
|
|
740
|
+
|
|
741
|
+
# Handle append_file tool
|
|
742
|
+
elif tool_name == "append_file":
|
|
743
|
+
if "Appended" in clean_output:
|
|
744
|
+
return clean_output.split("\n")[0]
|
|
745
|
+
else:
|
|
746
|
+
return clean_output.split("\n")[0][:60]
|
|
747
|
+
|
|
725
748
|
# Handle todo_write - show full todo list with emoji
|
|
726
749
|
elif tool_name == "todo_write":
|
|
727
750
|
if "Todo list cleared" in clean_output:
|
|
@@ -921,52 +944,91 @@ class StreamingDisplayManager:
|
|
|
921
944
|
return False
|
|
922
945
|
|
|
923
946
|
def _extract_diff_content(self, tool_name: str, output: str) -> List:
|
|
924
|
-
"""Extract and format diff content for file updates."""
|
|
947
|
+
"""Extract and format diff content for file updates with git-style highlighting."""
|
|
925
948
|
renderables = []
|
|
926
949
|
|
|
927
|
-
# Only show diffs for file editing tools
|
|
928
|
-
if tool_name not in [
|
|
950
|
+
# Only show diffs for file editing/writing tools
|
|
951
|
+
if tool_name not in [
|
|
952
|
+
"Edit",
|
|
953
|
+
"MultiEdit",
|
|
954
|
+
"Write",
|
|
955
|
+
"edit_file",
|
|
956
|
+
"write_file",
|
|
957
|
+
"append_file",
|
|
958
|
+
]:
|
|
959
|
+
return renderables
|
|
960
|
+
|
|
961
|
+
# Check for our diff marker
|
|
962
|
+
diff_content = ""
|
|
963
|
+
if "---DIFF---" in output:
|
|
964
|
+
parts = output.split("---DIFF---", 1)
|
|
965
|
+
if len(parts) > 1:
|
|
966
|
+
diff_content = parts[1].strip()
|
|
967
|
+
else:
|
|
968
|
+
# Fallback: look for diff-like content directly
|
|
969
|
+
diff_content = output
|
|
970
|
+
|
|
971
|
+
if not diff_content:
|
|
929
972
|
return renderables
|
|
930
973
|
|
|
931
|
-
#
|
|
932
|
-
lines =
|
|
974
|
+
# Parse diff lines
|
|
975
|
+
lines = diff_content.split("\n")
|
|
933
976
|
diff_lines = []
|
|
934
|
-
in_diff = False
|
|
935
977
|
|
|
936
978
|
for line in lines:
|
|
937
|
-
#
|
|
938
|
-
if line.
|
|
939
|
-
in_diff = True
|
|
979
|
+
# Keep file headers for context
|
|
980
|
+
if line.startswith("--- ") or line.startswith("+++ "):
|
|
940
981
|
diff_lines.append(line)
|
|
941
|
-
|
|
982
|
+
# Keep hunk headers, additions, deletions, and context lines
|
|
983
|
+
elif line.startswith("@@") or line.startswith("+") or line.startswith("-"):
|
|
942
984
|
diff_lines.append(line)
|
|
943
|
-
elif
|
|
985
|
+
elif line.startswith(" "):
|
|
986
|
+
# Context line
|
|
944
987
|
diff_lines.append(line)
|
|
945
|
-
elif in_diff:
|
|
946
|
-
# End of diff section
|
|
947
|
-
break
|
|
948
988
|
|
|
949
989
|
# Format diff if found
|
|
950
990
|
if diff_lines:
|
|
951
|
-
|
|
952
|
-
|
|
991
|
+
# Count additions and deletions for summary
|
|
992
|
+
additions = sum(
|
|
993
|
+
1 for ln in diff_lines if ln.startswith("+") and not ln.startswith("+++")
|
|
994
|
+
)
|
|
995
|
+
deletions = sum(
|
|
996
|
+
1 for ln in diff_lines if ln.startswith("-") and not ln.startswith("---")
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
# Show summary line with change counts
|
|
1000
|
+
summary_text = Text()
|
|
1001
|
+
summary_text.append(" ", style="")
|
|
1002
|
+
if additions > 0:
|
|
1003
|
+
summary_text.append(f"+{additions}", style="bold green")
|
|
1004
|
+
if additions > 0 and deletions > 0:
|
|
1005
|
+
summary_text.append(" ", style="")
|
|
1006
|
+
if deletions > 0:
|
|
1007
|
+
summary_text.append(f"-{deletions}", style="bold red")
|
|
1008
|
+
renderables.append(summary_text)
|
|
1009
|
+
|
|
1010
|
+
# Show ALL diff lines with git-style coloring (no limit)
|
|
1011
|
+
for line in diff_lines:
|
|
953
1012
|
diff_text = Text()
|
|
954
|
-
|
|
955
|
-
|
|
1013
|
+
diff_text.append(" ", style="") # Indent
|
|
1014
|
+
|
|
1015
|
+
if line.startswith("+++") or line.startswith("---"):
|
|
1016
|
+
# File header: bold
|
|
1017
|
+
diff_text.append(line, style="bold")
|
|
1018
|
+
elif line.startswith("+"):
|
|
1019
|
+
# Addition: green (git style)
|
|
956
1020
|
diff_text.append(line, style="green")
|
|
957
1021
|
elif line.startswith("-"):
|
|
958
|
-
|
|
1022
|
+
# Deletion: red (git style)
|
|
959
1023
|
diff_text.append(line, style="red")
|
|
960
1024
|
elif line.startswith("@@"):
|
|
961
|
-
|
|
962
|
-
diff_text.append(line, style="cyan")
|
|
1025
|
+
# Hunk header: cyan/blue bold
|
|
1026
|
+
diff_text.append(line, style="cyan bold")
|
|
963
1027
|
else:
|
|
964
|
-
|
|
1028
|
+
# Context line: dim
|
|
965
1029
|
diff_text.append(line, style="dim")
|
|
966
|
-
renderables.append(diff_text)
|
|
967
1030
|
|
|
968
|
-
|
|
969
|
-
renderables.append(Text(" ...", style="dim"))
|
|
1031
|
+
renderables.append(diff_text)
|
|
970
1032
|
|
|
971
1033
|
return renderables
|
|
972
1034
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""File operation tools."""
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import List, Optional
|
|
4
|
+
from typing import List, Optional, Tuple
|
|
5
5
|
|
|
6
6
|
import tiktoken
|
|
7
|
+
import whatthepatch
|
|
7
8
|
from agents import function_tool
|
|
8
9
|
from pydantic import BaseModel
|
|
9
10
|
|
|
@@ -23,8 +24,56 @@ class FileReadModel(BaseModel):
|
|
|
23
24
|
|
|
24
25
|
class FileEditModel(BaseModel):
|
|
25
26
|
path: str
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
diff: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def apply_diff(content: str, diff_text: str) -> Tuple[str, Optional[str]]:
|
|
31
|
+
"""Apply a unified diff to file content using whatthepatch library.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
content: The original file content.
|
|
35
|
+
diff_text: The unified diff to apply.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Tuple of (new_content, error_message).
|
|
39
|
+
If successful, error_message is None.
|
|
40
|
+
"""
|
|
41
|
+
try:
|
|
42
|
+
# Parse the diff
|
|
43
|
+
diffs = list(whatthepatch.parse_patch(diff_text))
|
|
44
|
+
|
|
45
|
+
if not diffs:
|
|
46
|
+
return content, "No valid diff found in input"
|
|
47
|
+
|
|
48
|
+
# Split content into lines
|
|
49
|
+
original_lines = content.splitlines(keepends=False)
|
|
50
|
+
|
|
51
|
+
# Apply each diff (usually just one for a single file)
|
|
52
|
+
result_lines: Optional[List[str]] = original_lines
|
|
53
|
+
for diff in diffs:
|
|
54
|
+
if diff.changes is None:
|
|
55
|
+
continue
|
|
56
|
+
|
|
57
|
+
# Apply the diff using pure Python implementation (use_patch=False)
|
|
58
|
+
result_lines = whatthepatch.apply_diff(diff, result_lines, use_patch=False)
|
|
59
|
+
|
|
60
|
+
if result_lines is None:
|
|
61
|
+
return content, "Failed to apply diff: patch does not match file content"
|
|
62
|
+
|
|
63
|
+
if result_lines is None:
|
|
64
|
+
return content, "No changes were applied"
|
|
65
|
+
|
|
66
|
+
# Reconstruct the content, preserving original line ending style
|
|
67
|
+
result = "\n".join(result_lines)
|
|
68
|
+
|
|
69
|
+
# Preserve trailing newline if original had one
|
|
70
|
+
if content.endswith("\n"):
|
|
71
|
+
result += "\n"
|
|
72
|
+
|
|
73
|
+
return result, None
|
|
74
|
+
|
|
75
|
+
except Exception as e:
|
|
76
|
+
return content, f"Error applying diff: {str(e)}"
|
|
28
77
|
|
|
29
78
|
|
|
30
79
|
class LSModel(BaseModel):
|
|
@@ -129,6 +178,59 @@ def read_file(path: str, offset: Optional[int] = None, limit: Optional[int] = No
|
|
|
129
178
|
return f"Error reading file: {str(e)}"
|
|
130
179
|
|
|
131
180
|
|
|
181
|
+
def _generate_diff_output(
|
|
182
|
+
old_content: str, new_content: str, file_path: str, is_new_file: bool = False
|
|
183
|
+
) -> str:
|
|
184
|
+
"""Generate unified diff output for display.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
old_content: Original file content (empty string for new files).
|
|
188
|
+
new_content: New file content.
|
|
189
|
+
file_path: Path to the file for the diff header.
|
|
190
|
+
is_new_file: Whether this is a new file creation.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Unified diff formatted string.
|
|
194
|
+
"""
|
|
195
|
+
old_lines = old_content.splitlines(keepends=False) if old_content else []
|
|
196
|
+
new_lines = new_content.splitlines(keepends=False) if new_content else []
|
|
197
|
+
|
|
198
|
+
diff_lines = []
|
|
199
|
+
|
|
200
|
+
# Add file header
|
|
201
|
+
if is_new_file:
|
|
202
|
+
diff_lines.append("--- /dev/null")
|
|
203
|
+
diff_lines.append(f"+++ b/{file_path}")
|
|
204
|
+
else:
|
|
205
|
+
diff_lines.append(f"--- a/{file_path}")
|
|
206
|
+
diff_lines.append(f"+++ b/{file_path}")
|
|
207
|
+
|
|
208
|
+
# For simple cases, generate a basic unified diff
|
|
209
|
+
if is_new_file or not old_lines:
|
|
210
|
+
# New file: all lines are additions
|
|
211
|
+
if new_lines:
|
|
212
|
+
diff_lines.append(f"@@ -0,0 +1,{len(new_lines)} @@")
|
|
213
|
+
for line in new_lines:
|
|
214
|
+
diff_lines.append(f"+{line}")
|
|
215
|
+
else:
|
|
216
|
+
# File modification: show full diff using difflib
|
|
217
|
+
import difflib
|
|
218
|
+
|
|
219
|
+
diff = difflib.unified_diff(
|
|
220
|
+
old_lines,
|
|
221
|
+
new_lines,
|
|
222
|
+
fromfile=f"a/{file_path}",
|
|
223
|
+
tofile=f"b/{file_path}",
|
|
224
|
+
lineterm="",
|
|
225
|
+
)
|
|
226
|
+
# Skip the first two lines (we already added headers)
|
|
227
|
+
diff_list = list(diff)
|
|
228
|
+
if len(diff_list) > 2:
|
|
229
|
+
diff_lines = diff_list
|
|
230
|
+
|
|
231
|
+
return "\n".join(diff_lines)
|
|
232
|
+
|
|
233
|
+
|
|
132
234
|
@function_tool
|
|
133
235
|
def write_file(path: str, content: str) -> str:
|
|
134
236
|
"""Write content to a file.
|
|
@@ -140,8 +242,28 @@ def write_file(path: str, content: str) -> str:
|
|
|
140
242
|
try:
|
|
141
243
|
p = Path(path).resolve()
|
|
142
244
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
245
|
+
|
|
246
|
+
# Check if file exists and get old content for diff
|
|
247
|
+
is_new_file = not p.exists()
|
|
248
|
+
old_content = ""
|
|
249
|
+
if not is_new_file:
|
|
250
|
+
try:
|
|
251
|
+
old_content = p.read_text(encoding="utf-8")
|
|
252
|
+
except Exception:
|
|
253
|
+
old_content = ""
|
|
254
|
+
|
|
255
|
+
# Write the new content
|
|
143
256
|
p.write_text(content, "utf-8")
|
|
144
|
-
|
|
257
|
+
|
|
258
|
+
# Generate diff for display
|
|
259
|
+
filename = p.name
|
|
260
|
+
diff_output = _generate_diff_output(old_content, content, filename, is_new_file)
|
|
261
|
+
|
|
262
|
+
if is_new_file:
|
|
263
|
+
return f"Created {path} ({len(content)} bytes)\n---DIFF---\n{diff_output}"
|
|
264
|
+
else:
|
|
265
|
+
return f"Updated {path} ({len(content)} bytes)\n---DIFF---\n{diff_output}"
|
|
266
|
+
|
|
145
267
|
except PermissionError as e:
|
|
146
268
|
return str(e)
|
|
147
269
|
except Exception as e:
|
|
@@ -154,9 +276,27 @@ def append_file(path: str, content: str) -> str:
|
|
|
154
276
|
try:
|
|
155
277
|
p = Path(path).resolve()
|
|
156
278
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
279
|
+
|
|
280
|
+
# Get old content for diff (if file exists)
|
|
281
|
+
is_new_file = not p.exists()
|
|
282
|
+
old_content = ""
|
|
283
|
+
if not is_new_file:
|
|
284
|
+
try:
|
|
285
|
+
old_content = p.read_text(encoding="utf-8")
|
|
286
|
+
except Exception:
|
|
287
|
+
old_content = ""
|
|
288
|
+
|
|
289
|
+
# Append the content
|
|
157
290
|
with p.open("a", encoding="utf-8") as f:
|
|
158
291
|
f.write(content)
|
|
159
|
-
|
|
292
|
+
|
|
293
|
+
# Generate diff for display (showing appended content)
|
|
294
|
+
new_content = old_content + content
|
|
295
|
+
filename = p.name
|
|
296
|
+
diff_output = _generate_diff_output(old_content, new_content, filename, is_new_file)
|
|
297
|
+
|
|
298
|
+
return f"Appended {len(content)} bytes to {path}\n---DIFF---\n{diff_output}"
|
|
299
|
+
|
|
160
300
|
except PermissionError as e:
|
|
161
301
|
return str(e)
|
|
162
302
|
except Exception as e:
|
|
@@ -164,12 +304,28 @@ def append_file(path: str, content: str) -> str:
|
|
|
164
304
|
|
|
165
305
|
|
|
166
306
|
@function_tool
|
|
167
|
-
def edit_file(path: str,
|
|
168
|
-
"""
|
|
307
|
+
def edit_file(path: str, diff: str) -> str:
|
|
308
|
+
"""Apply a unified diff patch to a file.
|
|
309
|
+
|
|
310
|
+
The diff parameter should contain a unified diff format patch. This is useful
|
|
311
|
+
for making targeted changes to specific lines in a file. The diff format uses:
|
|
312
|
+
- Lines starting with '-' are removed
|
|
313
|
+
- Lines starting with '+' are added
|
|
314
|
+
- Lines starting with ' ' (space) are context (unchanged)
|
|
315
|
+
- @@ -start,count +start,count @@ marks each hunk
|
|
316
|
+
|
|
317
|
+
Example diff:
|
|
318
|
+
@@ -1,3 +1,3 @@
|
|
319
|
+
line1
|
|
320
|
+
-old line2
|
|
321
|
+
+new line2
|
|
322
|
+
line3
|
|
323
|
+
|
|
324
|
+
You must read the file first before editing.
|
|
169
325
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
326
|
+
Args:
|
|
327
|
+
path: Path to the file to edit.
|
|
328
|
+
diff: Unified diff to apply.
|
|
173
329
|
"""
|
|
174
330
|
try:
|
|
175
331
|
p = Path(path).resolve()
|
|
@@ -178,20 +334,16 @@ def edit_file(path: str, old_str: str, new_str: str) -> str:
|
|
|
178
334
|
|
|
179
335
|
content = p.read_text(encoding="utf-8")
|
|
180
336
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if count == 0:
|
|
185
|
-
return f"Text not found in file: {old_str[:100]}{'...' if len(old_str) > 100 else ''}"
|
|
186
|
-
|
|
187
|
-
if count > 1:
|
|
188
|
-
return f"Text appears {count} times in file - must be unique. Provide more context to make the match unique."
|
|
337
|
+
new_content, error = apply_diff(content, diff)
|
|
338
|
+
if error:
|
|
339
|
+
return f"Failed to apply diff: {error}"
|
|
189
340
|
|
|
190
|
-
# Perform single replacement
|
|
191
|
-
new_content = content.replace(old_str, new_str, 1)
|
|
192
341
|
p.write_text(new_content, encoding="utf-8")
|
|
193
342
|
|
|
194
|
-
|
|
343
|
+
# Return success message with diff for display
|
|
344
|
+
# Format: success message followed by the diff content
|
|
345
|
+
return f"Successfully applied diff to {path}\n---DIFF---\n{diff}"
|
|
346
|
+
|
|
195
347
|
except PermissionError as e:
|
|
196
348
|
return str(e)
|
|
197
349
|
except Exception as e:
|
|
@@ -29,6 +29,14 @@ def get_model_name_variants_for_lookup(model: str) -> list[str]:
|
|
|
29
29
|
provider_model = "/".join(parts[-2:])
|
|
30
30
|
names_to_try.extend([provider_model, provider_model.lower()])
|
|
31
31
|
|
|
32
|
+
# Add variants with dots replaced by hyphens (e.g., claude-opus-4.5 -> claude-opus-4-5)
|
|
33
|
+
# litellm uses hyphens in model names like "claude-opus-4-5"
|
|
34
|
+
dot_to_hyphen_variants = []
|
|
35
|
+
for name in names_to_try:
|
|
36
|
+
if "." in name:
|
|
37
|
+
dot_to_hyphen_variants.append(name.replace(".", "-"))
|
|
38
|
+
names_to_try.extend(dot_to_hyphen_variants)
|
|
39
|
+
|
|
32
40
|
# Remove duplicates while preserving order
|
|
33
41
|
return list(dict.fromkeys(names_to_try))
|
|
34
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "koder"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.8"
|
|
4
4
|
description = "An intuitive AI coding assistant and interactive CLI tool that boosts developer productivity with intelligent automation and context-aware support."
|
|
5
5
|
authors = [{ name = "Pengfei Ni" }]
|
|
6
6
|
readme = "README.md"
|
|
@@ -15,30 +15,31 @@ keywords = [
|
|
|
15
15
|
"litellm",
|
|
16
16
|
]
|
|
17
17
|
dependencies = [
|
|
18
|
-
"openai-agents[litellm]>=0.6.
|
|
19
|
-
"litellm>=1.80.
|
|
18
|
+
"openai-agents[litellm]>=0.6.4",
|
|
19
|
+
"litellm>=1.80.11",
|
|
20
20
|
"tiktoken>=0.12.0",
|
|
21
21
|
"requests>=2.32.5",
|
|
22
22
|
"beautifulsoup4>=4.14.3",
|
|
23
|
-
"ddgs>=9.
|
|
24
|
-
"aiosqlite>=0.
|
|
23
|
+
"ddgs>=9.10.0",
|
|
24
|
+
"aiosqlite>=0.22.1",
|
|
25
25
|
"pydantic>=2.12.5",
|
|
26
26
|
"httpx[socks]>=0.28.1",
|
|
27
|
-
"openai>=2.
|
|
27
|
+
"openai>=2.14.0",
|
|
28
28
|
"rich>=14.2.0",
|
|
29
|
-
"google-cloud-aiplatform>=1.
|
|
29
|
+
"google-cloud-aiplatform>=1.132.0",
|
|
30
30
|
"prompt-toolkit>=3.0.52",
|
|
31
31
|
"backoff>=2.2.1",
|
|
32
|
-
"fastapi>=0.
|
|
32
|
+
"fastapi>=0.127.0",
|
|
33
33
|
"orjson>=3.11.5",
|
|
34
|
-
"apscheduler>=3.11.
|
|
35
|
-
"fastapi-sso>=0.
|
|
34
|
+
"apscheduler>=3.11.2",
|
|
35
|
+
"fastapi-sso>=0.19.0",
|
|
36
36
|
"pyjwt>=2.10.1",
|
|
37
|
-
"python-multipart>=0.0.
|
|
37
|
+
"python-multipart>=0.0.21",
|
|
38
38
|
"cryptography>=46.0.3",
|
|
39
39
|
"pynacl>=1.6.1",
|
|
40
40
|
"websockets>=15.0.1",
|
|
41
41
|
"pyyaml>=6.0.3",
|
|
42
|
+
"whatthepatch>=1.0.7",
|
|
42
43
|
]
|
|
43
44
|
|
|
44
45
|
[project.urls]
|