minion-code 0.1.0__py3-none-any.whl
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.
- examples/advance_tui.py +508 -0
- examples/agent_with_todos.py +165 -0
- examples/file_freshness_example.py +97 -0
- examples/file_watching_example.py +110 -0
- examples/interruptible_tui.py +5 -0
- examples/message_response_children_demo.py +226 -0
- examples/rich_example.py +4 -0
- examples/simple_file_watching.py +57 -0
- examples/simple_tui.py +267 -0
- examples/simple_usage.py +69 -0
- minion_code/__init__.py +16 -0
- minion_code/agents/__init__.py +11 -0
- minion_code/agents/code_agent.py +320 -0
- minion_code/cli.py +502 -0
- minion_code/commands/__init__.py +90 -0
- minion_code/commands/clear_command.py +70 -0
- minion_code/commands/help_command.py +90 -0
- minion_code/commands/history_command.py +104 -0
- minion_code/commands/quit_command.py +32 -0
- minion_code/commands/status_command.py +115 -0
- minion_code/commands/tools_command.py +86 -0
- minion_code/commands/version_command.py +104 -0
- minion_code/components/Message.py +304 -0
- minion_code/components/MessageResponse.py +188 -0
- minion_code/components/PromptInput.py +534 -0
- minion_code/components/__init__.py +29 -0
- minion_code/screens/REPL.py +925 -0
- minion_code/screens/__init__.py +4 -0
- minion_code/services/__init__.py +50 -0
- minion_code/services/event_system.py +108 -0
- minion_code/services/file_freshness_service.py +582 -0
- minion_code/tools/__init__.py +69 -0
- minion_code/tools/bash_tool.py +58 -0
- minion_code/tools/file_edit_tool.py +238 -0
- minion_code/tools/file_read_tool.py +73 -0
- minion_code/tools/file_write_tool.py +36 -0
- minion_code/tools/glob_tool.py +58 -0
- minion_code/tools/grep_tool.py +105 -0
- minion_code/tools/ls_tool.py +65 -0
- minion_code/tools/multi_edit_tool.py +271 -0
- minion_code/tools/python_interpreter_tool.py +105 -0
- minion_code/tools/todo_read_tool.py +100 -0
- minion_code/tools/todo_write_tool.py +234 -0
- minion_code/tools/user_input_tool.py +53 -0
- minion_code/types.py +88 -0
- minion_code/utils/__init__.py +44 -0
- minion_code/utils/mcp_loader.py +211 -0
- minion_code/utils/todo_file_utils.py +110 -0
- minion_code/utils/todo_storage.py +149 -0
- minion_code-0.1.0.dist-info/METADATA +350 -0
- minion_code-0.1.0.dist-info/RECORD +59 -0
- minion_code-0.1.0.dist-info/WHEEL +5 -0
- minion_code-0.1.0.dist-info/entry_points.txt +4 -0
- minion_code-0.1.0.dist-info/licenses/LICENSE +661 -0
- minion_code-0.1.0.dist-info/top_level.txt +3 -0
- tests/__init__.py +1 -0
- tests/test_basic.py +20 -0
- tests/test_readonly_tools.py +102 -0
- tests/test_tools.py +83 -0
tests/test_basic.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Basic tests for the minion-code package."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
# 添加 minion 框架路径
|
|
8
|
+
sys.path.insert(0, "/Users/femtozheng/python-project/minion1")
|
|
9
|
+
|
|
10
|
+
from minion_code import __init__
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_package_imports():
|
|
14
|
+
"""Test that the package can be imported."""
|
|
15
|
+
assert __init__ is not None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_basic_functionality():
|
|
19
|
+
"""Basic test to ensure CI pipeline works."""
|
|
20
|
+
assert 1 + 1 == 2
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Tests for readonly tools functionality."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
# 添加 minion 框架路径
|
|
6
|
+
sys.path.insert(0, "/Users/femtozheng/python-project/minion1")
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from minion_code.tools import (
|
|
10
|
+
FileReadTool,
|
|
11
|
+
FileWriteTool,
|
|
12
|
+
BashTool,
|
|
13
|
+
GrepTool,
|
|
14
|
+
GlobTool,
|
|
15
|
+
LsTool,
|
|
16
|
+
PythonInterpreterTool,
|
|
17
|
+
WebSearchTool,
|
|
18
|
+
WikipediaSearchTool,
|
|
19
|
+
VisitWebpageTool,
|
|
20
|
+
UserInputTool,
|
|
21
|
+
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_readonly_tools():
|
|
26
|
+
"""测试只读工具的 readonly 属性"""
|
|
27
|
+
readonly_tools = [
|
|
28
|
+
FileReadTool(),
|
|
29
|
+
GrepTool(),
|
|
30
|
+
GlobTool(),
|
|
31
|
+
LsTool(),
|
|
32
|
+
WebSearchTool(),
|
|
33
|
+
WikipediaSearchTool(),
|
|
34
|
+
VisitWebpageTool(),
|
|
35
|
+
UserInputTool(),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
for tool in readonly_tools:
|
|
39
|
+
assert tool.readonly is True, f"{tool.__class__.__name__} 应该是只读工具"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_readwrite_tools():
|
|
43
|
+
"""测试读写工具的 readonly 属性"""
|
|
44
|
+
readwrite_tools = [
|
|
45
|
+
FileWriteTool(),
|
|
46
|
+
BashTool(),
|
|
47
|
+
PythonInterpreterTool(),
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
for tool in readwrite_tools:
|
|
51
|
+
assert tool.readonly is False, f"{tool.__class__.__name__} 应该是读写工具"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_web_search_tool():
|
|
55
|
+
"""测试网络搜索工具"""
|
|
56
|
+
tool = WebSearchTool()
|
|
57
|
+
result = tool.forward("Python")
|
|
58
|
+
assert "搜索查询: Python" in result
|
|
59
|
+
assert "找到" in result
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_wikipedia_search_tool():
|
|
63
|
+
"""测试 Wikipedia 搜索工具"""
|
|
64
|
+
tool = WikipediaSearchTool()
|
|
65
|
+
result = tool.forward("Python", "zh")
|
|
66
|
+
assert "Wikipedia 搜索结果" in result
|
|
67
|
+
assert "Python" in result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_visit_webpage_tool():
|
|
71
|
+
"""测试网页访问工具"""
|
|
72
|
+
tool = VisitWebpageTool()
|
|
73
|
+
result = tool.forward("https://www.example.com")
|
|
74
|
+
assert "网页访问结果" in result
|
|
75
|
+
assert "https://www.example.com" in result
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_tool_inheritance():
|
|
80
|
+
"""测试所有工具都正确继承了 BaseTool"""
|
|
81
|
+
from minion.tools import BaseTool
|
|
82
|
+
|
|
83
|
+
tools = [
|
|
84
|
+
FileReadTool(),
|
|
85
|
+
FileWriteTool(),
|
|
86
|
+
BashTool(),
|
|
87
|
+
GrepTool(),
|
|
88
|
+
GlobTool(),
|
|
89
|
+
LsTool(),
|
|
90
|
+
PythonInterpreterTool(),
|
|
91
|
+
WebSearchTool(),
|
|
92
|
+
WikipediaSearchTool(),
|
|
93
|
+
VisitWebpageTool(),
|
|
94
|
+
UserInputTool(),
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
for tool in tools:
|
|
98
|
+
assert isinstance(tool, BaseTool)
|
|
99
|
+
assert hasattr(tool, "readonly")
|
|
100
|
+
assert hasattr(tool, "name")
|
|
101
|
+
assert hasattr(tool, "description")
|
|
102
|
+
assert hasattr(tool, "forward")
|
tests/test_tools.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Tests for minion-code tools."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
# 添加 minion 框架路径
|
|
9
|
+
sys.path.insert(0, "/Users/femtozheng/python-project/minion1")
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
from minion_code.tools import FileReadTool, FileWriteTool, BashTool, TOOL_MAPPING
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_tool_mapping():
|
|
16
|
+
"""测试工具映射是否正确"""
|
|
17
|
+
assert "file_read" in TOOL_MAPPING
|
|
18
|
+
assert "file_write" in TOOL_MAPPING
|
|
19
|
+
assert "bash" in TOOL_MAPPING
|
|
20
|
+
assert len(TOOL_MAPPING) == 7 # 应该有7个工具
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_file_read_tool():
|
|
24
|
+
"""测试文件读取工具"""
|
|
25
|
+
tool = FileReadTool()
|
|
26
|
+
|
|
27
|
+
# 创建临时文件
|
|
28
|
+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as f:
|
|
29
|
+
f.write("Hello\nWorld\nTest")
|
|
30
|
+
temp_file = f.name
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
# 测试读取文件
|
|
34
|
+
result = tool.forward(temp_file)
|
|
35
|
+
assert "Hello" in result
|
|
36
|
+
assert "World" in result
|
|
37
|
+
assert "Test" in result
|
|
38
|
+
assert "总行数:3" in result
|
|
39
|
+
finally:
|
|
40
|
+
os.unlink(temp_file)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_file_write_tool():
|
|
44
|
+
"""测试文件写入工具"""
|
|
45
|
+
tool = FileWriteTool()
|
|
46
|
+
|
|
47
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
48
|
+
test_file = Path(temp_dir) / "test.txt"
|
|
49
|
+
content = "Hello, World!"
|
|
50
|
+
|
|
51
|
+
# 测试写入文件
|
|
52
|
+
result = tool.forward(str(test_file), content)
|
|
53
|
+
assert "成功写入文件" in result
|
|
54
|
+
assert str(test_file) in result
|
|
55
|
+
|
|
56
|
+
# 验证文件内容
|
|
57
|
+
assert test_file.exists()
|
|
58
|
+
assert test_file.read_text() == content
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_bash_tool():
|
|
62
|
+
"""测试 Bash 工具"""
|
|
63
|
+
tool = BashTool()
|
|
64
|
+
|
|
65
|
+
# 测试简单命令
|
|
66
|
+
result = tool.forward("echo 'Hello World'")
|
|
67
|
+
assert "Hello World" in result
|
|
68
|
+
assert "退出码:0" in result
|
|
69
|
+
|
|
70
|
+
# 测试危险命令被阻止
|
|
71
|
+
result = tool.forward("rm -rf /")
|
|
72
|
+
assert "错误:禁止执行危险命令" in result
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_tool_inheritance():
|
|
76
|
+
"""测试工具是否正确继承了 BaseTool"""
|
|
77
|
+
from minion.tools import BaseTool
|
|
78
|
+
|
|
79
|
+
tool = FileReadTool()
|
|
80
|
+
assert isinstance(tool, BaseTool)
|
|
81
|
+
assert hasattr(tool, "forward")
|
|
82
|
+
assert hasattr(tool, "name")
|
|
83
|
+
assert hasattr(tool, "description")
|