jarvis-ai-assistant 0.1.132__py3-none-any.whl → 0.1.138__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.

Files changed (82) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +330 -347
  3. jarvis/jarvis_agent/builtin_input_handler.py +16 -6
  4. jarvis/jarvis_agent/file_input_handler.py +9 -9
  5. jarvis/jarvis_agent/jarvis.py +143 -0
  6. jarvis/jarvis_agent/main.py +12 -13
  7. jarvis/jarvis_agent/output_handler.py +3 -3
  8. jarvis/jarvis_agent/patch.py +92 -64
  9. jarvis/jarvis_agent/shell_input_handler.py +5 -3
  10. jarvis/jarvis_code_agent/code_agent.py +263 -177
  11. jarvis/jarvis_code_agent/file_select.py +24 -24
  12. jarvis/jarvis_dev/main.py +45 -59
  13. jarvis/jarvis_git_details/__init__.py +0 -0
  14. jarvis/jarvis_git_details/main.py +179 -0
  15. jarvis/jarvis_git_squash/main.py +7 -7
  16. jarvis/jarvis_lsp/base.py +11 -53
  17. jarvis/jarvis_lsp/cpp.py +13 -28
  18. jarvis/jarvis_lsp/go.py +13 -28
  19. jarvis/jarvis_lsp/python.py +8 -27
  20. jarvis/jarvis_lsp/registry.py +21 -83
  21. jarvis/jarvis_lsp/rust.py +15 -30
  22. jarvis/jarvis_methodology/main.py +101 -0
  23. jarvis/jarvis_multi_agent/__init__.py +10 -51
  24. jarvis/jarvis_multi_agent/main.py +43 -0
  25. jarvis/jarvis_platform/__init__.py +1 -1
  26. jarvis/jarvis_platform/ai8.py +67 -89
  27. jarvis/jarvis_platform/base.py +14 -13
  28. jarvis/jarvis_platform/kimi.py +25 -28
  29. jarvis/jarvis_platform/ollama.py +24 -26
  30. jarvis/jarvis_platform/openai.py +15 -19
  31. jarvis/jarvis_platform/oyi.py +48 -50
  32. jarvis/jarvis_platform/registry.py +29 -44
  33. jarvis/jarvis_platform/yuanbao.py +39 -43
  34. jarvis/jarvis_platform_manager/main.py +81 -81
  35. jarvis/jarvis_platform_manager/openai_test.py +21 -21
  36. jarvis/jarvis_rag/file_processors.py +18 -18
  37. jarvis/jarvis_rag/main.py +262 -278
  38. jarvis/jarvis_smart_shell/main.py +12 -12
  39. jarvis/jarvis_tools/ask_codebase.py +85 -78
  40. jarvis/jarvis_tools/ask_user.py +8 -8
  41. jarvis/jarvis_tools/base.py +4 -4
  42. jarvis/jarvis_tools/chdir.py +9 -9
  43. jarvis/jarvis_tools/code_review.py +40 -21
  44. jarvis/jarvis_tools/create_code_agent.py +15 -15
  45. jarvis/jarvis_tools/create_sub_agent.py +0 -1
  46. jarvis/jarvis_tools/execute_python_script.py +3 -3
  47. jarvis/jarvis_tools/execute_shell.py +11 -11
  48. jarvis/jarvis_tools/execute_shell_script.py +3 -3
  49. jarvis/jarvis_tools/file_analyzer.py +116 -105
  50. jarvis/jarvis_tools/file_operation.py +22 -20
  51. jarvis/jarvis_tools/find_caller.py +105 -40
  52. jarvis/jarvis_tools/find_methodolopy.py +65 -0
  53. jarvis/jarvis_tools/find_symbol.py +123 -39
  54. jarvis/jarvis_tools/function_analyzer.py +140 -57
  55. jarvis/jarvis_tools/git_commiter.py +10 -10
  56. jarvis/jarvis_tools/lsp_get_diagnostics.py +19 -19
  57. jarvis/jarvis_tools/methodology.py +22 -67
  58. jarvis/jarvis_tools/project_analyzer.py +137 -53
  59. jarvis/jarvis_tools/rag.py +15 -20
  60. jarvis/jarvis_tools/read_code.py +25 -23
  61. jarvis/jarvis_tools/read_webpage.py +31 -31
  62. jarvis/jarvis_tools/registry.py +72 -52
  63. jarvis/jarvis_tools/search_web.py +23 -353
  64. jarvis/jarvis_tools/tool_generator.py +19 -19
  65. jarvis/jarvis_utils/config.py +36 -96
  66. jarvis/jarvis_utils/embedding.py +83 -83
  67. jarvis/jarvis_utils/git_utils.py +20 -20
  68. jarvis/jarvis_utils/globals.py +18 -6
  69. jarvis/jarvis_utils/input.py +10 -9
  70. jarvis/jarvis_utils/methodology.py +141 -140
  71. jarvis/jarvis_utils/output.py +13 -13
  72. jarvis/jarvis_utils/utils.py +23 -71
  73. {jarvis_ai_assistant-0.1.132.dist-info → jarvis_ai_assistant-0.1.138.dist-info}/METADATA +6 -15
  74. jarvis_ai_assistant-0.1.138.dist-info/RECORD +85 -0
  75. {jarvis_ai_assistant-0.1.132.dist-info → jarvis_ai_assistant-0.1.138.dist-info}/entry_points.txt +4 -3
  76. jarvis/jarvis_tools/lsp_find_definition.py +0 -150
  77. jarvis/jarvis_tools/lsp_find_references.py +0 -127
  78. jarvis/jarvis_tools/select_code_files.py +0 -62
  79. jarvis_ai_assistant-0.1.132.dist-info/RECORD +0 -82
  80. {jarvis_ai_assistant-0.1.132.dist-info → jarvis_ai_assistant-0.1.138.dist-info}/LICENSE +0 -0
  81. {jarvis_ai_assistant-0.1.132.dist-info → jarvis_ai_assistant-0.1.138.dist-info}/WHEEL +0 -0
  82. {jarvis_ai_assistant-0.1.132.dist-info → jarvis_ai_assistant-0.1.138.dist-info}/top_level.txt +0 -0
@@ -33,10 +33,10 @@ def execute_command(command: str) -> None:
33
33
 
34
34
  def process_request(request: str) -> Optional[str]:
35
35
  """Process user request and return corresponding shell command
36
-
36
+
37
37
  Args:
38
38
  request: User's natural language request
39
-
39
+
40
40
  Returns:
41
41
  Optional[str]: Corresponding shell command, return None if processing fails
42
42
  """
@@ -46,7 +46,7 @@ def process_request(request: str) -> Optional[str]:
46
46
 
47
47
  shell = get_shell_name()
48
48
  current_path = os.getcwd()
49
-
49
+
50
50
  # Set system prompt
51
51
  system_message = """
52
52
  # 🤖 Role Definition
@@ -96,18 +96,18 @@ Output: find . -name "*.py"
96
96
 
97
97
  prefix = f"Current path: {current_path}\n"
98
98
  prefix += f"Current shell: {shell}\n"
99
-
99
+
100
100
  with yaspin(text="正在生成命令...", color="cyan") as spinner:
101
101
  result = model.chat_until_success(prefix + request)
102
102
  spinner.ok("✅ 命令生成成功")
103
-
103
+
104
104
  # 提取命令
105
105
  if result and isinstance(result, str):
106
106
  command = result.strip()
107
107
  return command
108
-
108
+
109
109
  return None
110
-
110
+
111
111
  except Exception as e:
112
112
  PrettyOutput.print(f"处理请求失败: {str(e)}", OutputType.WARNING)
113
113
  return None
@@ -124,25 +124,25 @@ Example:
124
124
  %(prog)s "Compress all jpg images"
125
125
  %(prog)s "Find documents modified in the last week"
126
126
  """)
127
-
127
+
128
128
  # 修改为可选参数,添加从stdin读取的支持
129
129
  parser.add_argument(
130
130
  "request",
131
131
  nargs='?', # 设置为可选参数
132
132
  help="描述您想要执行的操作(用自然语言描述),如果未提供则从标准输入读取"
133
133
  )
134
-
134
+
135
135
  # 解析参数
136
136
  args = parser.parse_args()
137
-
137
+
138
138
  # 添加标准输入处理
139
139
  if not args.request:
140
140
  # 检查是否在交互式终端中运行
141
141
  args.request = get_multiline_input(tip="请输入您要执行的功能:")
142
-
142
+
143
143
  # 处理请求
144
144
  command = process_request(args.request)
145
-
145
+
146
146
  # 输出结果
147
147
  if command:
148
148
  execute_command(command) # 显示并执行命令
@@ -1,24 +1,21 @@
1
1
  from typing import Dict, Any
2
2
  import os
3
- import pathlib
4
3
 
5
- from colorama import init
6
4
 
7
5
  from jarvis.jarvis_agent import Agent
8
6
  from jarvis.jarvis_platform.registry import PlatformRegistry
9
7
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
10
8
  from jarvis.jarvis_utils.git_utils import find_git_root
11
- from jarvis.jarvis_utils.config import dont_use_local_model
12
9
  from jarvis.jarvis_utils.utils import init_env
13
10
 
14
11
  class AskCodebaseTool:
15
12
  """用于智能代码库查询和分析的工具
16
-
13
+
17
14
  适用场景:
18
- - 查询特定功能所在的文件位置
19
- - 了解单个功能点的实现原理
20
- - 查找特定API或接口的用法
21
-
15
+ - 查询特定功能所在的文件位置(支持所有文件类型)
16
+ - 了解单个功能点的实现原理(支持所有文件类型)
17
+ - 查找特定API或接口的用法(支持所有文件类型)
18
+
22
19
  不适用场景:
23
20
  - 跨越多文件的大范围分析
24
21
  - 复杂系统架构的全面评估
@@ -43,26 +40,25 @@ class AskCodebaseTool:
43
40
  "required": ["question"]
44
41
  }
45
42
 
46
- @staticmethod
47
- def check() -> bool:
48
- return not dont_use_local_model()
43
+ def __init__(self, auto_complete: bool = True):
44
+ self.auto_complete = auto_complete
49
45
 
50
46
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
51
47
  """Execute codebase analysis using an Agent with execute_shell and rag tools
52
-
48
+
53
49
  Args:
54
50
  args: Dictionary containing:
55
51
  - question: The question to answer, preferably about locating functionality
56
52
  or understanding implementation details of a specific feature
57
53
  - top_k: Optional number of files to analyze
58
54
  - root_dir: Optional root directory of the codebase
59
-
55
+
60
56
  Returns:
61
57
  Dict containing:
62
58
  - success: Boolean indicating success
63
59
  - stdout: Analysis result
64
60
  - stderr: Error message if any
65
-
61
+
66
62
  Note:
67
63
  This tool works best for focused questions about specific features or implementations.
68
64
  It is not designed for comprehensive multi-file analysis or complex architectural questions.
@@ -70,48 +66,44 @@ class AskCodebaseTool:
70
66
  try:
71
67
  question = args["question"]
72
68
  root_dir = args.get("root_dir", ".")
73
-
69
+
74
70
  # Store current directory
75
71
  original_dir = os.getcwd()
76
-
72
+
77
73
  try:
78
74
  # Change to root_dir
79
75
  os.chdir(root_dir)
80
-
76
+
81
77
  # Get git root directory
82
78
  git_root = find_git_root() or os.getcwd()
83
-
79
+
84
80
  # Create system prompt for the Agent
85
81
  system_prompt = self._create_system_prompt(question, git_root)
86
-
82
+
87
83
  # Create summary prompt for the Agent
88
84
  summary_prompt = self._create_summary_prompt(question)
89
-
85
+
90
86
  # Create tools registry
91
87
  from jarvis.jarvis_tools.registry import ToolRegistry
92
88
  tool_registry = ToolRegistry()
93
89
  tool_registry.use_tools(["execute_shell", "read_code", "rag"])
94
-
90
+
95
91
  # Create and run Agent
96
92
  analyzer_agent = Agent(
97
93
  system_prompt=system_prompt,
98
94
  name=f"CodebaseAnalyzer",
99
95
  description=f"分析代码库中的功能实现和定位",
100
96
  summary_prompt=summary_prompt,
101
- platform=PlatformRegistry().get_codegen_platform(),
97
+ platform=PlatformRegistry().get_normal_platform(),
102
98
  output_handler=[tool_registry],
103
- need_summary=True,
104
- is_sub_agent=True,
105
- use_methodology=False,
106
- record_methodology=False,
107
99
  execute_tool_confirm=False,
108
- auto_complete=True
100
+ auto_complete=self.auto_complete
109
101
  )
110
-
102
+
111
103
  # Run agent and get result
112
104
  task_input = f"回答关于代码库的问题: {question}"
113
105
  result = analyzer_agent.run(task_input)
114
-
106
+
115
107
  return {
116
108
  "success": True,
117
109
  "stdout": result,
@@ -128,14 +120,14 @@ class AskCodebaseTool:
128
120
  "stdout": "",
129
121
  "stderr": error_msg
130
122
  }
131
-
123
+
132
124
  def _create_system_prompt(self, question: str, git_root: str) -> str:
133
125
  """创建Agent的system prompt
134
-
126
+
135
127
  Args:
136
128
  question: 用户问题
137
129
  git_root: Git仓库根目录
138
-
130
+
139
131
  Returns:
140
132
  系统提示文本
141
133
  """
@@ -149,70 +141,75 @@ class AskCodebaseTool:
149
141
  - 代码库根目录: {git_root}
150
142
 
151
143
  ## 工具使用优先级
152
- 1. **优先使用 execute_shell**: 首先使用shell命令查找和分析相关文件
153
- 2. **优先使用 read_code**: 找到相关文件后优先使用read_code读取文件内容
154
- 3. **谨慎使用 rag**: 仅在shell命令和直接文件读取无法解决问题时作为辅助手段
144
+ 1. **绝对优先使用 execute_shell**:
145
+ - 使用 fd 查找文件: `fd -t f -e py` 查找Python文件等
146
+ - 使用 rg 搜索代码: `rg "pattern" --type py` 在Python文件中搜索等
147
+ - 使用 loc 统计代码: `loc"` 统计代码量
148
+
149
+ 2. **优先使用 read_code**:
150
+ - 找到相关文件后优先使用read_code读取文件内容
151
+ - 对大文件使用行范围参数读取指定区域
152
+
153
+ 3. **避免使用 rag**:
154
+ - 仅在fd、rg和read_code无法解决问题时作为最后手段
155
+ - 使用rag前必须先尝试使用shell命令解决问题
155
156
 
156
157
  ## 分析策略
157
158
  1. 首先理解问题,确定需要查找的关键信息和代码组件
158
- 2. 使用shell命令(execute_shell)搜索和查找可能相关的文件
159
- 3. 使用read_code工具直接读取和分析相关文件内容
160
- 4. 只有在必要时才使用RAG工具作为辅助手段
161
- 5. 根据文件内容提供具体、准确的回答
159
+ 2. 使用fd命令查找可能相关的文件
160
+ 3. 使用rg命令搜索关键词和代码模式
161
+ 4. 使用read_code工具直接读取和分析相关文件内容
162
+ 5. 只有在fd、rg和read_code都无法解决问题时才考虑使用RAG工具
163
+ 6. 根据文件内容提供具体、准确的回答
164
+ 7. 确保分析的完整性,收集充分的信息后再得出结论
165
+ 8. 优先查阅README文件、文档目录和项目文档
162
166
 
163
167
  ## 分析步骤
164
- 1. **探索代码库结构**:
165
- - 使用shell命令了解目录结构,找出可能包含相关功能的位置
166
- - 识别主要模块和组件
167
-
168
- 2. **定位相关文件**:
169
- - 优先使用grep、find等shell命令查找关键词
170
- - 使用文件名、关键词搜索找到潜在相关文件
171
-
172
- 3. **深入分析代码**:
168
+ 1. **确定项目的编程语言**:
169
+ - 使用loc命令: `loc` 统计各类文件数量
170
+ - 查看构建文件和配置文件
171
+ - 了解项目使用的框架和主要依赖
172
+
173
+ 2. **探索代码库结构**:
174
+ - 使用 `fd -t d` 了解目录结构
175
+ - 使用 `fd README.md` 查找README文件
176
+ - 使用 `fd -e md -g "doc*"` 查找文档文件
177
+
178
+ 3. **定位相关文件**:
179
+ - 使用fd和rg命令查找关键词
180
+ - 示例: `rg -w "登录|login" --type py` 查找登录相关代码
181
+ - 示例: `fd -e py -g "*auth*"` 查找认证相关文件
182
+
183
+ 4. **深入分析代码**:
173
184
  - 使用read_code工具直接读取文件内容
174
185
  - 分析关键文件的实现细节
175
- - 识别功能的实现方式和关键逻辑
186
+ - 使用rg识别功能的实现方式和关键逻辑
176
187
 
177
- 4. **回答问题**:
188
+ 5. **回答问题**:
178
189
  - 提供基于直接分析代码的具体回答
179
190
  - 引用具体文件和代码片段作为依据
180
191
 
181
192
  ## 关于RAG工具使用
182
- - RAG工具应作为最后选择,仅在shell命令和直接文件读取无法解决问题时使用
183
- - RAG工具返回的信息可能存在偏差或不准确之处
193
+ - RAG工具应作为最后选择,仅在fd、rg和read_code都无法解决问题时使用
184
194
  - 必须通过查看实际代码文件验证RAG返回的每条重要信息
185
195
  - 对于关键发现,始终使用`read_code`工具查看原始文件内容进行求证
186
196
  - 如发现RAG结果与实际代码不符,以实际代码为准
187
197
 
188
- ## 探索命令示例
189
- ```bash
190
- # 查看目录结构
191
- find . -type d -not -path "*/\\.*" | sort
192
-
193
- # 搜索与问题相关的文件
194
- find . -type f -name "*.py" -o -name "*.js" | xargs grep -l "关键词"
195
- grep -r "关键词" --include="*.py" .
196
-
197
- # 查看文件内容
198
- cat 文件路径
199
- ```
200
-
201
-
202
198
  ## 输出要求
203
199
  - 提供准确、具体的回答,避免模糊不清的描述
204
200
  - 引用具体文件路径和代码片段作为依据
205
201
  - 如果无法找到答案,明确说明并提供原因
206
202
  - 组织信息的逻辑清晰,便于理解
207
203
  - 对复杂概念提供简明解释
204
+ - 确保全面收集相关信息后再形成结论
208
205
  - 明确区分已验证的信息和待验证的信息"""
209
206
 
210
207
  def _create_summary_prompt(self, question: str) -> str:
211
208
  """创建Agent的summary prompt
212
-
209
+
213
210
  Args:
214
211
  question: 用户问题
215
-
212
+
216
213
  Returns:
217
214
  总结提示文本
218
215
  """
@@ -225,32 +222,42 @@ cat 文件路径
225
222
 
226
223
  报告应包含:
227
224
 
228
- 1. **问题回答**:
225
+ 1. **项目基本信息**:
226
+ - 项目的主要编程语言和技术栈
227
+ - 项目的主要框架和依赖
228
+ - 项目的基本结构
229
+
230
+ 2. **问题回答**:
229
231
  - 直接、具体地回答问题
230
232
  - 基于代码库中的实际代码
231
233
  - 避免模糊或推测性的回答
232
234
 
233
- 2. **核心发现**:
235
+ 3. **核心发现**:
234
236
  - 相关文件和代码位置
235
237
  - 关键实现细节
236
238
  - 功能运作机制
237
239
 
238
- 3. **证据引用**:
240
+ 4. **证据引用**:
239
241
  - 引用具体文件路径
240
242
  - 包含关键代码片段
241
243
  - 解释代码如何支持你的回答
242
244
 
243
- 4. **局限性**(如有):
245
+ 5. **局限性**(如有):
244
246
  - 指出分析的任何局限
245
247
  - 说明任何无法确定的信息
246
248
 
249
+ 6. **分析完整性**:
250
+ - 确保在得出结论前已全面收集和分析相关信息
251
+ - 避免基于部分信息形成不完整或偏颇的判断
252
+ - 明确标识哪些是已确认的结论,哪些可能需要进一步验证
253
+
247
254
  使用清晰的Markdown格式,重点突出对问题的回答和支持证据。"""
248
255
 
249
256
 
250
257
  def main():
251
258
  """
252
259
  命令行入口点,允许将ask_codebase作为独立脚本运行
253
-
260
+
254
261
  用法示例:
255
262
  ```
256
263
  python -m jarvis.jarvis_tools.ask_codebase "登录功能在哪个文件实现?" --root_dir /path/to/codebase
@@ -260,22 +267,22 @@ def main():
260
267
  import sys
261
268
 
262
269
  init_env()
263
-
270
+
264
271
  # 创建命令行参数解析器
265
272
  parser = argparse.ArgumentParser(description="智能代码库查询工具")
266
273
  parser.add_argument("question", help="关于代码库的问题")
267
274
  parser.add_argument("--root_dir", "-d", default=".", help="代码库根目录路径")
268
-
275
+
269
276
  # 解析命令行参数
270
277
  args = parser.parse_args()
271
-
278
+
272
279
  # 创建并执行工具
273
- tool = AskCodebaseTool()
280
+ tool = AskCodebaseTool(auto_complete=False)
274
281
  result = tool.execute({
275
282
  "question": args.question,
276
283
  "root_dir": args.root_dir
277
284
  })
278
-
285
+
279
286
  # 输出结果
280
287
  if result["success"]:
281
288
  PrettyOutput.print(result["stdout"], OutputType.SUCCESS)
@@ -16,35 +16,35 @@ class AskUserTool:
16
16
  },
17
17
  "required": ["question"]
18
18
  }
19
-
19
+
20
20
 
21
21
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
22
22
  """Execute the operation of asking the user
23
-
23
+
24
24
  Args:
25
25
  args: A dictionary containing the question
26
-
26
+
27
27
  Returns:
28
28
  Dict: A dictionary containing the user's response
29
29
  """
30
30
  try:
31
31
  question = args["question"]
32
-
32
+
33
33
  # Display the question
34
34
  PrettyOutput.print(f"问题: {question}", OutputType.SYSTEM)
35
-
35
+
36
36
  # Get user input
37
37
  user_response = get_multiline_input("请输入您的答案 (输入空行结束)")
38
-
38
+
39
39
  return {
40
40
  "success": True,
41
41
  "stdout": user_response,
42
42
  "stderr": ""
43
43
  }
44
-
44
+
45
45
  except Exception as e:
46
46
  return {
47
47
  "success": False,
48
48
  "stdout": "",
49
49
  "stderr": f"Failed to ask user: {str(e)}"
50
- }
50
+ }
@@ -2,11 +2,11 @@ from typing import Dict, Any, Callable
2
2
  import json
3
3
  class Tool:
4
4
  """工具类,用于封装工具的基本信息和执行方法"""
5
-
5
+
6
6
  def __init__(self, name: str, description: str, parameters: Dict, func: Callable):
7
7
  """
8
8
  初始化工具对象
9
-
9
+
10
10
  参数:
11
11
  name (str): 工具名称
12
12
  description (str): 工具描述
@@ -27,10 +27,10 @@ class Tool:
27
27
  def execute(self, arguments: Dict) -> Dict[str, Any]:
28
28
  """
29
29
  执行工具函数
30
-
30
+
31
31
  参数:
32
32
  arguments (Dict): 工具执行所需的参数
33
-
33
+
34
34
  返回:
35
35
  Dict[str, Any]: 工具执行结果
36
36
  """
@@ -14,19 +14,19 @@ class ChdirTool:
14
14
  },
15
15
  "required": ["path"]
16
16
  }
17
-
17
+
18
18
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
19
19
  """执行目录切换操作,并提供全面的错误处理。
20
-
20
+
21
21
  参数:
22
22
  args: 包含 'path' 键的字典,目标目录路径
23
-
23
+
24
24
  返回:
25
25
  字典,包含以下内容:
26
26
  - success: 布尔值,表示操作状态
27
27
  - stdout: 成功消息或空字符串
28
28
  - stderr: 错误消息或空字符串
29
-
29
+
30
30
  异常处理:
31
31
  处理并返回适当的错误消息:
32
32
  - 不存在的路径
@@ -39,7 +39,7 @@ class ChdirTool:
39
39
  # 规范化并展开输入路径(处理 ~ 和相对路径)
40
40
  path = os.path.expanduser(args["path"].strip())
41
41
  path = os.path.abspath(path)
42
-
42
+
43
43
  # 验证目标路径是否存在
44
44
  if not os.path.exists(path):
45
45
  return {
@@ -47,7 +47,7 @@ class ChdirTool:
47
47
  "stdout": "",
48
48
  "stderr": f"目录不存在: {path}"
49
49
  }
50
-
50
+
51
51
  # 确保路径指向的是目录,而不是文件
52
52
  if not os.path.isdir(path):
53
53
  return {
@@ -55,17 +55,17 @@ class ChdirTool:
55
55
  "stdout": "",
56
56
  "stderr": f"路径不是目录: {path}"
57
57
  }
58
-
58
+
59
59
  # 获取当前目录并尝试切换到新路径
60
60
  old_path = os.getcwd()
61
61
  os.chdir(path)
62
-
62
+
63
63
  return {
64
64
  "success": True,
65
65
  "stdout": f"成功切换工作目录:\n原目录: {old_path}\n新目录: {path}",
66
66
  "stderr": ""
67
67
  }
68
-
68
+
69
69
  # 处理用户没有目录访问权限的情况
70
70
  except PermissionError:
71
71
  return {