jarvis-ai-assistant 0.1.178__py3-none-any.whl → 0.1.179__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.
Potentially problematic release.
This version of jarvis-ai-assistant might be problematic. Click here for more details.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +130 -79
- jarvis/jarvis_agent/builtin_input_handler.py +1 -1
- jarvis/jarvis_agent/jarvis.py +9 -13
- jarvis/jarvis_agent/main.py +4 -2
- jarvis/jarvis_code_agent/code_agent.py +34 -23
- jarvis/jarvis_code_agent/lint.py +164 -0
- jarvis/jarvis_code_analysis/checklists/loader.py +6 -20
- jarvis/jarvis_code_analysis/code_review.py +8 -6
- jarvis/jarvis_dev/main.py +1 -8
- jarvis/jarvis_git_details/main.py +1 -1
- jarvis/jarvis_git_squash/main.py +5 -3
- jarvis/jarvis_git_utils/git_commiter.py +24 -23
- jarvis/jarvis_mcp/sse_mcp_client.py +6 -4
- jarvis/jarvis_mcp/stdio_mcp_client.py +5 -4
- jarvis/jarvis_mcp/streamable_mcp_client.py +404 -0
- jarvis/jarvis_methodology/main.py +10 -9
- jarvis/jarvis_multi_agent/main.py +3 -1
- jarvis/jarvis_platform/base.py +14 -8
- jarvis/jarvis_platform/human.py +3 -1
- jarvis/jarvis_platform/kimi.py +10 -7
- jarvis/jarvis_platform/openai.py +4 -1
- jarvis/jarvis_platform/registry.py +6 -2
- jarvis/jarvis_platform/yuanbao.py +13 -10
- jarvis/jarvis_platform_manager/main.py +11 -9
- jarvis/jarvis_smart_shell/main.py +1 -0
- jarvis/jarvis_tools/ask_codebase.py +4 -3
- jarvis/jarvis_tools/ask_user.py +2 -1
- jarvis/jarvis_tools/base.py +3 -1
- jarvis/jarvis_tools/chdir.py +2 -1
- jarvis/jarvis_tools/cli/main.py +1 -0
- jarvis/jarvis_tools/code_plan.py +5 -3
- jarvis/jarvis_tools/create_code_agent.py +5 -2
- jarvis/jarvis_tools/create_sub_agent.py +1 -3
- jarvis/jarvis_tools/edit_file.py +3 -3
- jarvis/jarvis_tools/execute_script.py +1 -1
- jarvis/jarvis_tools/file_analyzer.py +5 -3
- jarvis/jarvis_tools/file_operation.py +4 -7
- jarvis/jarvis_tools/find_methodology.py +4 -2
- jarvis/jarvis_tools/generate_new_tool.py +2 -1
- jarvis/jarvis_tools/methodology.py +3 -4
- jarvis/jarvis_tools/read_code.py +2 -1
- jarvis/jarvis_tools/read_webpage.py +3 -1
- jarvis/jarvis_tools/registry.py +22 -13
- jarvis/jarvis_tools/rewrite_file.py +2 -1
- jarvis/jarvis_tools/search_web.py +1 -0
- jarvis/jarvis_tools/virtual_tty.py +5 -4
- jarvis/jarvis_utils/__init__.py +2 -0
- jarvis/jarvis_utils/builtin_replace_map.py +1 -1
- jarvis/jarvis_utils/config.py +31 -1
- jarvis/jarvis_utils/embedding.py +4 -3
- jarvis/jarvis_utils/file_processors.py +1 -0
- jarvis/jarvis_utils/git_utils.py +55 -25
- jarvis/jarvis_utils/globals.py +4 -2
- jarvis/jarvis_utils/input.py +14 -7
- jarvis/jarvis_utils/methodology.py +6 -4
- jarvis/jarvis_utils/output.py +10 -6
- jarvis/jarvis_utils/utils.py +89 -13
- {jarvis_ai_assistant-0.1.178.dist-info → jarvis_ai_assistant-0.1.179.dist-info}/METADATA +45 -33
- jarvis_ai_assistant-0.1.179.dist-info/RECORD +98 -0
- jarvis_ai_assistant-0.1.178.dist-info/RECORD +0 -96
- {jarvis_ai_assistant-0.1.178.dist-info → jarvis_ai_assistant-0.1.179.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.178.dist-info → jarvis_ai_assistant-0.1.179.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.178.dist-info → jarvis_ai_assistant-0.1.179.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.178.dist-info → jarvis_ai_assistant-0.1.179.dist-info}/top_level.txt +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
4
|
-
|
|
3
|
+
from typing import Any, Dict
|
|
5
4
|
|
|
6
5
|
from jarvis.jarvis_agent import Agent
|
|
7
6
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
8
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
9
7
|
from jarvis.jarvis_utils.git_utils import find_git_root
|
|
8
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
10
9
|
from jarvis.jarvis_utils.utils import init_env
|
|
11
10
|
|
|
11
|
+
|
|
12
12
|
class AskCodebaseTool:
|
|
13
13
|
"""用于智能代码库查询和分析的工具
|
|
14
14
|
|
|
@@ -258,6 +258,7 @@ def main():
|
|
|
258
258
|
"""
|
|
259
259
|
import argparse
|
|
260
260
|
import sys
|
|
261
|
+
|
|
261
262
|
from jarvis.jarvis_utils.input import get_multiline_input
|
|
262
263
|
|
|
263
264
|
init_env("欢迎使用 Jarvis-AskCodebase,您的智能代码库查询工具已准备就绪!")
|
jarvis/jarvis_tools/ask_user.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# 导入所需的类型注解模块
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Any, Dict
|
|
4
4
|
|
|
5
5
|
# 导入多行输入工具和输出工具
|
|
6
6
|
from jarvis.jarvis_utils.input import get_multiline_input
|
|
7
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
# 定义AskUserTool类,用于向用户提问
|
|
10
11
|
class AskUserTool:
|
|
11
12
|
name="ask_user"
|
jarvis/jarvis_tools/base.py
CHANGED
jarvis/jarvis_tools/chdir.py
CHANGED
jarvis/jarvis_tools/cli/main.py
CHANGED
jarvis/jarvis_tools/code_plan.py
CHANGED
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
4. 修改计划输出
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
from typing import Dict, Any
|
|
13
12
|
import os
|
|
14
|
-
from
|
|
13
|
+
from typing import Any, Dict
|
|
14
|
+
|
|
15
15
|
from jarvis.jarvis_agent import Agent
|
|
16
16
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
17
|
-
from jarvis.
|
|
17
|
+
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
18
18
|
from jarvis.jarvis_utils.git_utils import find_git_root
|
|
19
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
class CodePlanTool:
|
|
21
23
|
"""用于代码修改规划和需求分析的工具
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
4
5
|
from jarvis.jarvis_code_agent.code_agent import CodeAgent
|
|
5
6
|
from jarvis.jarvis_git_utils.git_commiter import GitCommitTool
|
|
6
|
-
from jarvis.jarvis_utils.git_utils import get_latest_commit_hash,
|
|
7
|
+
from jarvis.jarvis_utils.git_utils import (get_latest_commit_hash,
|
|
8
|
+
has_uncommitted_changes)
|
|
7
9
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
10
|
|
|
11
|
+
|
|
9
12
|
class CreateCodeAgentTool:
|
|
10
13
|
"""用于管理代码开发工作流的工具"""
|
|
11
14
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
4
|
-
|
|
3
|
+
from typing import Any, Dict
|
|
5
4
|
|
|
6
5
|
from jarvis.jarvis_agent import Agent, origin_agent_system_prompt
|
|
7
6
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
class SubAgentTool:
|
|
12
10
|
name = "create_sub_agent"
|
|
13
11
|
description = "创建子代理以处理特定任务,子代理将生成任务总结报告"
|
jarvis/jarvis_tools/edit_file.py
CHANGED
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
- 支持大文件处理(自动上传到模型平台)
|
|
18
18
|
- 提供3次重试机制确保操作可靠性
|
|
19
19
|
"""
|
|
20
|
-
from typing import List
|
|
21
20
|
import re
|
|
22
|
-
from typing import Any, Dict, Tuple
|
|
21
|
+
from typing import Any, Dict, List, Tuple
|
|
23
22
|
|
|
24
23
|
import yaml
|
|
25
24
|
from yaspin import yaspin
|
|
@@ -130,7 +129,8 @@ class FileSearchReplaceTool:
|
|
|
130
129
|
4. 保持原始代码的格式风格
|
|
131
130
|
"""
|
|
132
131
|
import os
|
|
133
|
-
|
|
132
|
+
|
|
133
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
134
134
|
|
|
135
135
|
stdout_messages = []
|
|
136
136
|
stderr_messages = []
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
5
|
+
from yaspin import yaspin # type: ignore
|
|
6
|
+
from yaspin.spinners import Spinners # type: ignore
|
|
4
7
|
|
|
5
8
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
6
9
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
|
-
|
|
8
|
-
from yaspin.spinners import Spinners # type: ignore
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
class FileAnalyzerTool:
|
|
11
13
|
name = "file_analyzer"
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
4
3
|
from pathlib import Path
|
|
4
|
+
from typing import Any, Dict
|
|
5
5
|
|
|
6
|
-
from yaspin import yaspin
|
|
6
|
+
from yaspin import yaspin # type: ignore
|
|
7
7
|
|
|
8
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
9
8
|
# 导入文件处理器
|
|
10
|
-
from jarvis.jarvis_utils.file_processors import
|
|
11
|
-
|
|
12
|
-
)
|
|
13
|
-
|
|
9
|
+
from jarvis.jarvis_utils.file_processors import TextFileProcessor
|
|
10
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
14
11
|
|
|
15
12
|
|
|
16
13
|
class FileOperationTool:
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
3
4
|
from yaspin import yaspin
|
|
4
5
|
|
|
5
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
6
6
|
from jarvis.jarvis_utils.methodology import load_methodology
|
|
7
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
class FindMethodologyTool:
|
|
9
11
|
name = "find_methodology"
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import re
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import
|
|
4
|
+
from typing import Any, Dict, Tuple
|
|
5
5
|
|
|
6
6
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
7
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
class generate_new_tool:
|
|
10
11
|
name = "generate_new_tool"
|
|
11
12
|
description = """
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
import os
|
|
3
|
-
import json
|
|
4
2
|
import hashlib
|
|
5
|
-
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any, Dict
|
|
6
6
|
|
|
7
7
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
8
8
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
class MethodologyTool:
|
|
13
12
|
"""经验管理工具"""
|
|
14
13
|
|
jarvis/jarvis_tools/read_code.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
3
|
+
from typing import Any, Dict
|
|
4
4
|
|
|
5
5
|
from yaspin import yaspin
|
|
6
6
|
|
|
7
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
class ReadCodeTool:
|
|
10
11
|
name = "read_code"
|
|
11
12
|
description = "代码阅读与分析工具,用于读取源代码文件并添加行号,针对代码文件优化,提供更好的格式化输出和行号显示,适用于代码分析、审查和理解代码实现的场景"
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Dict, Any
|
|
3
2
|
import os
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
4
5
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
5
6
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
6
7
|
|
|
8
|
+
|
|
7
9
|
class WebpageTool:
|
|
8
10
|
name = "read_webpage"
|
|
9
11
|
description = "读取网页内容,提取标题、文本和超链接"
|
jarvis/jarvis_tools/registry.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import json
|
|
3
|
-
|
|
3
|
+
import os
|
|
4
4
|
import re
|
|
5
5
|
import sys
|
|
6
6
|
import tempfile
|
|
7
|
-
import
|
|
8
|
-
from typing import Any, Callable, Dict, List, Optional,
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple
|
|
9
9
|
|
|
10
10
|
import yaml
|
|
11
11
|
|
|
12
|
+
from jarvis.jarvis_mcp import McpClient
|
|
13
|
+
from jarvis.jarvis_mcp.sse_mcp_client import SSEMcpClient
|
|
14
|
+
from jarvis.jarvis_mcp.stdio_mcp_client import StdioMcpClient
|
|
15
|
+
from jarvis.jarvis_mcp.streamable_mcp_client import StreamableMcpClient
|
|
12
16
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
13
17
|
from jarvis.jarvis_tools.base import Tool
|
|
14
18
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
15
19
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
20
|
+
from jarvis.jarvis_utils.tag import ct, ot
|
|
16
21
|
from jarvis.jarvis_utils.utils import init_env, is_context_overflow
|
|
17
|
-
from jarvis.jarvis_utils.tag import ot, ct
|
|
18
|
-
from jarvis.jarvis_mcp.stdio_mcp_client import StdioMcpClient
|
|
19
|
-
from jarvis.jarvis_mcp.sse_mcp_client import SSEMcpClient
|
|
20
|
-
from jarvis.jarvis_mcp import McpClient
|
|
21
|
-
|
|
22
22
|
|
|
23
23
|
tool_call_help = f"""
|
|
24
24
|
<tool_system_guide>
|
|
@@ -351,6 +351,12 @@ class ToolRegistry(OutputHandlerProtocol):
|
|
|
351
351
|
f"文件 {file_path} 缺少base_url字段", OutputType.WARNING
|
|
352
352
|
)
|
|
353
353
|
return False
|
|
354
|
+
elif config["type"] == "streamable":
|
|
355
|
+
if "base_url" not in config:
|
|
356
|
+
PrettyOutput.print(
|
|
357
|
+
f"文件 {file_path} 缺少base_url字段", OutputType.WARNING
|
|
358
|
+
)
|
|
359
|
+
return False
|
|
354
360
|
else:
|
|
355
361
|
PrettyOutput.print(
|
|
356
362
|
f"文件 {file_path} 类型错误: {config['type']}", OutputType.WARNING
|
|
@@ -358,11 +364,14 @@ class ToolRegistry(OutputHandlerProtocol):
|
|
|
358
364
|
return False
|
|
359
365
|
|
|
360
366
|
# 创建MCP客户端
|
|
361
|
-
|
|
362
|
-
StdioMcpClient(config)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
367
|
+
if config["type"] == "stdio":
|
|
368
|
+
mcp_client: McpClient = StdioMcpClient(config)
|
|
369
|
+
elif config["type"] == "sse":
|
|
370
|
+
mcp_client: McpClient = SSEMcpClient(config)
|
|
371
|
+
elif config["type"] == "streamable":
|
|
372
|
+
mcp_client: McpClient = StreamableMcpClient(config)
|
|
373
|
+
else:
|
|
374
|
+
raise ValueError(f"不支持的MCP客户端类型: {config['type']}")
|
|
366
375
|
|
|
367
376
|
# 获取工具信息
|
|
368
377
|
tools = mcp_client.get_tool_list()
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
2
|
+
import fcntl
|
|
3
3
|
import os
|
|
4
|
-
import time
|
|
5
4
|
import pty
|
|
6
|
-
import fcntl
|
|
7
|
-
import signal
|
|
8
5
|
import select
|
|
6
|
+
import signal
|
|
7
|
+
import time
|
|
8
|
+
from typing import Any, Dict
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
class VirtualTTYTool:
|
|
11
12
|
name = "virtual_tty"
|
jarvis/jarvis_utils/__init__.py
CHANGED
jarvis/jarvis_utils/config.py
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import os
|
|
3
3
|
from functools import lru_cache
|
|
4
|
+
|
|
4
5
|
import yaml
|
|
6
|
+
|
|
5
7
|
from jarvis.jarvis_utils.builtin_replace_map import BUILTIN_REPLACE_MAP
|
|
8
|
+
|
|
6
9
|
"""配置管理模块。
|
|
7
10
|
|
|
8
11
|
该模块提供了获取Jarvis系统各种配置设置的函数。
|
|
9
12
|
所有配置都从环境变量中读取,带有回退默认值。
|
|
10
13
|
"""
|
|
11
14
|
|
|
15
|
+
def get_git_commit_prompt() -> str:
|
|
16
|
+
"""
|
|
17
|
+
获取Git提交提示模板
|
|
18
|
+
|
|
19
|
+
返回:
|
|
20
|
+
str: Git提交信息生成提示模板,如果未配置则返回空字符串
|
|
21
|
+
"""
|
|
22
|
+
return os.getenv("JARVIS_GIT_COMMIT_PROMPT", "")
|
|
23
|
+
|
|
12
24
|
# 输出窗口预留大小
|
|
13
25
|
INPUT_WINDOW_REVERSE_SIZE = 2048
|
|
14
26
|
|
|
@@ -178,4 +190,22 @@ def is_use_methodology() -> bool:
|
|
|
178
190
|
返回:
|
|
179
191
|
bool: 如果启用方法论则返回True,默认为True
|
|
180
192
|
"""
|
|
181
|
-
return os.getenv('JARVIS_USE_METHODOLOGY', '
|
|
193
|
+
return os.getenv('JARVIS_USE_METHODOLOGY', 'false') == 'true'
|
|
194
|
+
|
|
195
|
+
def is_use_analysis() -> bool:
|
|
196
|
+
"""
|
|
197
|
+
获取是否启用任务分析。
|
|
198
|
+
|
|
199
|
+
返回:
|
|
200
|
+
bool: 如果启用任务分析则返回True,默认为True
|
|
201
|
+
"""
|
|
202
|
+
return os.getenv('JARVIS_USE_ANALYSIS', 'false') == 'true'
|
|
203
|
+
|
|
204
|
+
def is_print_prompt() -> bool:
|
|
205
|
+
"""
|
|
206
|
+
获取是否打印提示。
|
|
207
|
+
|
|
208
|
+
返回:
|
|
209
|
+
bool: 如果打印提示则返回True,默认为True
|
|
210
|
+
"""
|
|
211
|
+
return os.getenv('JARVIS_PRINT_PROMPT', 'false') == 'true'
|
jarvis/jarvis_utils/embedding.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
import functools
|
|
2
3
|
import os
|
|
3
|
-
from transformers import AutoTokenizer
|
|
4
4
|
from typing import List
|
|
5
|
-
import functools
|
|
6
5
|
|
|
7
|
-
from
|
|
6
|
+
from transformers import AutoTokenizer
|
|
7
|
+
|
|
8
8
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
9
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
9
10
|
|
|
10
11
|
# 全局缓存,避免重复加载模型
|
|
11
12
|
_global_tokenizers = {}
|
jarvis/jarvis_utils/git_utils.py
CHANGED
|
@@ -12,10 +12,14 @@ Git工具模块
|
|
|
12
12
|
import os
|
|
13
13
|
import re
|
|
14
14
|
import subprocess
|
|
15
|
-
from typing import List, Tuple
|
|
16
|
-
|
|
17
|
-
from jarvis.jarvis_utils.
|
|
15
|
+
from typing import Dict, List, Tuple
|
|
16
|
+
|
|
17
|
+
from jarvis.jarvis_utils.config import (get_auto_update,
|
|
18
|
+
is_confirm_before_apply_patch)
|
|
19
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
18
20
|
from jarvis.jarvis_utils.utils import user_confirm
|
|
21
|
+
|
|
22
|
+
|
|
19
23
|
def find_git_root(start_dir: str = ".") -> str:
|
|
20
24
|
"""
|
|
21
25
|
切换到给定路径的Git根目录,如果不是Git仓库则初始化。
|
|
@@ -101,42 +105,34 @@ def get_commits_between(start_hash: str, end_hash: str) -> List[Tuple[str, str]]
|
|
|
101
105
|
|
|
102
106
|
|
|
103
107
|
def get_diff() -> str:
|
|
104
|
-
"""使用git
|
|
105
|
-
import subprocess
|
|
106
|
-
|
|
107
|
-
# 初始化状态
|
|
108
|
-
need_reset = False
|
|
108
|
+
"""使用git获取工作区差异,包括修改和新增的文件内容
|
|
109
109
|
|
|
110
|
+
返回:
|
|
111
|
+
str: 差异内容或错误信息
|
|
112
|
+
"""
|
|
110
113
|
try:
|
|
111
|
-
#
|
|
112
|
-
subprocess.run(['git', 'add', '.'], check=True)
|
|
113
|
-
need_reset = True
|
|
114
|
+
# 暂存新增文件
|
|
115
|
+
subprocess.run(['git', 'add', '-N', '.'], check=True)
|
|
114
116
|
|
|
115
|
-
#
|
|
117
|
+
# 获取所有差异(包括新增文件)
|
|
116
118
|
result = subprocess.run(
|
|
117
|
-
['git', 'diff', '
|
|
119
|
+
['git', 'diff', 'HEAD'],
|
|
118
120
|
capture_output=True,
|
|
119
121
|
text=False,
|
|
120
122
|
check=True
|
|
121
123
|
)
|
|
122
124
|
|
|
123
|
-
# 解码输出
|
|
124
|
-
try:
|
|
125
|
-
ret = result.stdout.decode('utf-8')
|
|
126
|
-
except UnicodeDecodeError:
|
|
127
|
-
ret = result.stdout.decode('utf-8', errors='replace')
|
|
128
|
-
|
|
129
125
|
# 重置暂存区
|
|
130
|
-
subprocess.run(['git',
|
|
131
|
-
return ret
|
|
126
|
+
subprocess.run(['git', 'reset'], check=True)
|
|
132
127
|
|
|
128
|
+
try:
|
|
129
|
+
return result.stdout.decode('utf-8')
|
|
130
|
+
except UnicodeDecodeError:
|
|
131
|
+
return result.stdout.decode('utf-8', errors='replace')
|
|
132
|
+
|
|
133
133
|
except subprocess.CalledProcessError as e:
|
|
134
|
-
if need_reset:
|
|
135
|
-
subprocess.run(['git', "reset", "--mixed"], check=False)
|
|
136
134
|
return f"获取差异失败: {str(e)}"
|
|
137
135
|
except Exception as e:
|
|
138
|
-
if need_reset:
|
|
139
|
-
subprocess.run(['git', "reset", "--mixed"], check=False)
|
|
140
136
|
return f"发生意外错误: {str(e)}"
|
|
141
137
|
|
|
142
138
|
|
|
@@ -333,3 +329,37 @@ def check_and_update_git_repo(repo_path: str) -> bool:
|
|
|
333
329
|
return False
|
|
334
330
|
finally:
|
|
335
331
|
os.chdir(curr_dir)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def get_diff_file_list() -> List[str]:
|
|
335
|
+
"""获取HEAD到当前变更的文件列表,包括修改和新增的文件
|
|
336
|
+
|
|
337
|
+
返回:
|
|
338
|
+
List[str]: 修改和新增的文件路径列表
|
|
339
|
+
"""
|
|
340
|
+
try:
|
|
341
|
+
# 暂存新增文件
|
|
342
|
+
subprocess.run(['git', 'add', '-N', '.'], check=True)
|
|
343
|
+
|
|
344
|
+
# 获取所有差异文件(包括新增文件)
|
|
345
|
+
result = subprocess.run(
|
|
346
|
+
['git', 'diff', '--name-only', 'HEAD'],
|
|
347
|
+
capture_output=True,
|
|
348
|
+
text=True
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
# 重置暂存区
|
|
352
|
+
subprocess.run(['git', 'reset'], check=True)
|
|
353
|
+
|
|
354
|
+
if result.returncode != 0:
|
|
355
|
+
PrettyOutput.print(f"获取差异文件列表失败: {result.stderr}", OutputType.ERROR)
|
|
356
|
+
return []
|
|
357
|
+
|
|
358
|
+
return [f for f in result.stdout.splitlines() if f]
|
|
359
|
+
|
|
360
|
+
except subprocess.CalledProcessError as e:
|
|
361
|
+
PrettyOutput.print(f"获取差异文件列表失败: {str(e)}", OutputType.ERROR)
|
|
362
|
+
return []
|
|
363
|
+
except Exception as e:
|
|
364
|
+
PrettyOutput.print(f"获取差异文件列表异常: {str(e)}", OutputType.ERROR)
|
|
365
|
+
return []
|
jarvis/jarvis_utils/globals.py
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
- 带有自定义主题的控制台配置
|
|
8
8
|
- 环境初始化
|
|
9
9
|
"""
|
|
10
|
-
from typing import Any, Set, Dict
|
|
11
|
-
import colorama
|
|
12
10
|
import os
|
|
11
|
+
from typing import Any, Dict, Set
|
|
12
|
+
|
|
13
|
+
import colorama
|
|
13
14
|
from rich.console import Console
|
|
14
15
|
from rich.theme import Theme
|
|
16
|
+
|
|
15
17
|
# 初始化colorama以支持跨平台的彩色文本
|
|
16
18
|
colorama.init()
|
|
17
19
|
# 禁用tokenizers并行以避免多进程问题
|
jarvis/jarvis_utils/input.py
CHANGED
|
@@ -8,17 +8,21 @@
|
|
|
8
8
|
- 带有模糊匹配的文件路径补全
|
|
9
9
|
- 用于输入控制的自定义键绑定
|
|
10
10
|
"""
|
|
11
|
+
from colorama import Fore
|
|
12
|
+
from colorama import Style as ColoramaStyle
|
|
13
|
+
from fuzzywuzzy import process
|
|
11
14
|
from prompt_toolkit import PromptSession
|
|
12
|
-
from prompt_toolkit.styles import Style as PromptStyle
|
|
13
|
-
from prompt_toolkit.formatted_text import FormattedText
|
|
14
15
|
from prompt_toolkit.completion import Completer, Completion, PathCompleter
|
|
15
16
|
from prompt_toolkit.document import Document
|
|
17
|
+
from prompt_toolkit.formatted_text import FormattedText
|
|
16
18
|
from prompt_toolkit.key_binding import KeyBindings
|
|
17
|
-
from
|
|
18
|
-
|
|
19
|
-
from jarvis.jarvis_utils.output import PrettyOutput, OutputType
|
|
20
|
-
from jarvis.jarvis_utils.tag import ot
|
|
19
|
+
from prompt_toolkit.styles import Style as PromptStyle
|
|
20
|
+
|
|
21
21
|
from jarvis.jarvis_utils.config import get_replace_map
|
|
22
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
23
|
+
from jarvis.jarvis_utils.tag import ot
|
|
24
|
+
|
|
25
|
+
|
|
22
26
|
def get_single_line_input(tip: str) -> str:
|
|
23
27
|
"""
|
|
24
28
|
获取支持历史记录的单行输入。
|
|
@@ -176,9 +180,12 @@ def get_multiline_input(tip: str) -> str:
|
|
|
176
180
|
'prompt': 'ansicyan',
|
|
177
181
|
})
|
|
178
182
|
try:
|
|
183
|
+
import os
|
|
184
|
+
|
|
179
185
|
from prompt_toolkit.history import FileHistory
|
|
186
|
+
|
|
180
187
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
181
|
-
|
|
188
|
+
|
|
182
189
|
# 获取数据目录路径
|
|
183
190
|
history_dir = get_data_dir()
|
|
184
191
|
# 初始化带历史记录的会话
|