feat: 增强编码能力 - 新增代码编辑器、代码搜索、Git集成
- 新增 plugins/code_editor.py: 精准代码编辑(搜索替换、批量编辑、diff对比) - 新增 plugins/code_search.py: 代码搜索与理解(跨文件搜索、符号提取、依赖分析) - 新增 plugins/git_tools.py: Git 版本控制(status/diff/log/commit/branch) - 新增 core/ 模块: 配置管理、引擎管理、对话处理、显示输出、代码沙箱 - 修复 requirements.txt: 使用正确的 pip 包名(Pillow、opencv-python 等) - 更新 unified_tool_manager.py: 兼容 Plugin 和 Liugin 两种类名 - 更新系统提示词: 增强编程工作流指导 本次更新由 mimo 自动化执行,与开发者无关。
This commit is contained in:
commit
e22652fbbb
53 files changed
+20067
No files matched your search
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
工具搜索插件 - 支持按需发现工具
|
||||
"""
|
||||
import json
|
||||
|
||||
|
||||
class Liugin:
|
||||
"""工具搜索插件 - 允许 AI 按需搜索和发现可用工具"""
|
||||
|
||||
def __init__(self):
|
||||
self.usage = """工具搜索使用方法:
|
||||
tool_search <关键词> - 根据关键词搜索可用工具
|
||||
|
||||
例如:
|
||||
- tool_search 文件 - 搜索与文件相关的工具
|
||||
- tool_search 网络 - 搜索与网络相关的工具
|
||||
- tool_search 图片 - 搜索与图片相关的工具
|
||||
|
||||
此插件帮助 AI 在需要特定功能时快速找到合适的工具,
|
||||
而不是预加载所有工具到上下文中。"""
|
||||
self.cli = None
|
||||
|
||||
def set_cli(self, cli):
|
||||
"""设置 CLI 实例引用"""
|
||||
self.cli = cli
|
||||
|
||||
def get_tool_info(self):
|
||||
return {
|
||||
"name": "tool_search",
|
||||
"description": "工具搜索插件,支持按需发现和搜索可用工具。当你不确定有哪些工具可用时,可以使用此工具搜索相关功能的工具。",
|
||||
"keywords": ["搜索", "工具", "发现", "search", "tool", "find", "可用工具", "工具列表"],
|
||||
"usage": """tool_search 工具使用说明:
|
||||
JSON格式示例:
|
||||
{"action": "use_tool", "tool": "tool_search", "args": "文件"} - 搜索与文件相关的工具
|
||||
{"action": "use_tool", "tool": "tool_search", "args": "网络"} - 搜索与网络相关的工具
|
||||
{"action": "use_tool", "tool": "tool_search", "args": "图片"} - 搜索与图片相关的工具
|
||||
|
||||
功能说明:
|
||||
- 支持关键词匹配(工具名称、描述、关键词)
|
||||
- 返回匹配度最高的前 5 个工具
|
||||
- 包含工具的详细使用说明
|
||||
- 帮助 AI 快速找到合适的工具而不需要预加载所有工具"""
|
||||
}
|
||||
|
||||
def handle(self, args):
|
||||
"""处理工具搜索请求"""
|
||||
try:
|
||||
# 解析参数
|
||||
query = args.strip()
|
||||
|
||||
if not query:
|
||||
return "错误:请提供搜索关键词。格式: tool_search <关键词>"
|
||||
|
||||
# 搜索工具
|
||||
if self.cli and hasattr(self.cli, 'liugin_manager'):
|
||||
matches = self.cli.liugin_manager.search_tools(query, limit=5)
|
||||
|
||||
if not matches:
|
||||
return f"未找到与 '{query}' 相关的工具。"
|
||||
|
||||
# 格式化搜索结果
|
||||
result_lines = [f"找到 {len(matches)} 个与 '{query}' 相关的工具:\n"]
|
||||
|
||||
for i, match in enumerate(matches, 1):
|
||||
result_lines.append(f"{i}. {match['name']}")
|
||||
result_lines.append(f" 描述: {match['description']}")
|
||||
|
||||
# 显示协议类型
|
||||
protocol = match.get('protocol', 'liugin')
|
||||
result_lines.append(f" 协议: {protocol}")
|
||||
|
||||
# 关键词
|
||||
keywords = match.get('keywords', [])
|
||||
if keywords:
|
||||
result_lines.append(f" 关键词: {', '.join(keywords)}")
|
||||
|
||||
# 根据协议类型显示不同的使用说明
|
||||
if protocol == 'skill':
|
||||
# Skill 协议:显示完整指令
|
||||
instance = match.get('instance')
|
||||
if instance:
|
||||
instructions = getattr(instance, 'instructions', '')
|
||||
if instructions:
|
||||
# 限制长度
|
||||
if len(instructions) > 1500:
|
||||
instructions = instructions[:1500] + "\n...(内容已截断)"
|
||||
result_lines.append(f" 指令:\n{instructions}")
|
||||
else:
|
||||
usage = match.get('usage', '')
|
||||
if usage:
|
||||
result_lines.append(f" 用法: {usage}")
|
||||
else:
|
||||
# Plugin 协议:显示 usage
|
||||
if match.get('usage'):
|
||||
usage = match['usage']
|
||||
if len(usage) > 500:
|
||||
usage = usage[:500] + "..."
|
||||
result_lines.append(f" 用法: {usage}")
|
||||
|
||||
result_lines.append("")
|
||||
|
||||
return "\n".join(result_lines)
|
||||
else:
|
||||
return "错误:无法访问插件管理器。"
|
||||
|
||||
except Exception as e:
|
||||
return f"工具搜索失败: {str(e)}"
|
||||
Reference in new issue
Block a user