jarvis-ai-assistant 0.1.130__py3-none-any.whl → 0.1.131__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 (60) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +23 -9
  3. jarvis/jarvis_agent/builtin_input_handler.py +73 -0
  4. jarvis/{jarvis_code_agent → jarvis_agent}/file_input_handler.py +1 -1
  5. jarvis/jarvis_agent/main.py +1 -1
  6. jarvis/{jarvis_code_agent → jarvis_agent}/patch.py +23 -19
  7. jarvis/{jarvis_code_agent → jarvis_agent}/shell_input_handler.py +0 -1
  8. jarvis/jarvis_code_agent/code_agent.py +20 -16
  9. jarvis/jarvis_codebase/main.py +5 -5
  10. jarvis/jarvis_dev/main.py +1 -1
  11. jarvis/jarvis_git_squash/main.py +1 -1
  12. jarvis/jarvis_lsp/base.py +2 -26
  13. jarvis/jarvis_lsp/cpp.py +2 -14
  14. jarvis/jarvis_lsp/go.py +0 -13
  15. jarvis/jarvis_lsp/python.py +1 -30
  16. jarvis/jarvis_lsp/registry.py +10 -14
  17. jarvis/jarvis_lsp/rust.py +0 -12
  18. jarvis/jarvis_multi_agent/__init__.py +1 -1
  19. jarvis/jarvis_platform/registry.py +1 -1
  20. jarvis/jarvis_platform_manager/main.py +3 -3
  21. jarvis/jarvis_rag/main.py +1 -1
  22. jarvis/jarvis_tools/ask_codebase.py +40 -20
  23. jarvis/jarvis_tools/code_review.py +180 -143
  24. jarvis/jarvis_tools/create_code_agent.py +76 -72
  25. jarvis/jarvis_tools/create_sub_agent.py +32 -15
  26. jarvis/jarvis_tools/execute_shell.py +2 -2
  27. jarvis/jarvis_tools/execute_shell_script.py +1 -1
  28. jarvis/jarvis_tools/file_operation.py +2 -2
  29. jarvis/jarvis_tools/git_commiter.py +87 -68
  30. jarvis/jarvis_tools/lsp_find_definition.py +83 -67
  31. jarvis/jarvis_tools/lsp_find_references.py +62 -46
  32. jarvis/jarvis_tools/lsp_get_diagnostics.py +90 -74
  33. jarvis/jarvis_tools/methodology.py +3 -3
  34. jarvis/jarvis_tools/read_code.py +1 -1
  35. jarvis/jarvis_tools/search_web.py +18 -20
  36. jarvis/jarvis_tools/tool_generator.py +1 -1
  37. jarvis/jarvis_tools/treesitter_analyzer.py +331 -0
  38. jarvis/jarvis_treesitter/README.md +104 -0
  39. jarvis/jarvis_treesitter/__init__.py +20 -0
  40. jarvis/jarvis_treesitter/database.py +258 -0
  41. jarvis/jarvis_treesitter/example.py +115 -0
  42. jarvis/jarvis_treesitter/grammar_builder.py +182 -0
  43. jarvis/jarvis_treesitter/language.py +117 -0
  44. jarvis/jarvis_treesitter/symbol.py +31 -0
  45. jarvis/jarvis_treesitter/tools_usage.md +121 -0
  46. jarvis/jarvis_utils/git_utils.py +10 -2
  47. jarvis/jarvis_utils/input.py +3 -1
  48. jarvis/jarvis_utils/methodology.py +1 -1
  49. jarvis/jarvis_utils/utils.py +3 -3
  50. {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/METADATA +2 -4
  51. jarvis_ai_assistant-0.1.131.dist-info/RECORD +85 -0
  52. jarvis/jarvis_c2rust/c2rust.yaml +0 -734
  53. jarvis/jarvis_code_agent/builtin_input_handler.py +0 -43
  54. jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -87
  55. jarvis/jarvis_tools/lsp_prepare_rename.py +0 -130
  56. jarvis_ai_assistant-0.1.130.dist-info/RECORD +0 -79
  57. {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/LICENSE +0 -0
  58. {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/WHEEL +0 -0
  59. {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/entry_points.txt +0 -0
  60. {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/top_level.txt +0 -0
@@ -11,7 +11,12 @@ class LSPFindDefinitionTool:
11
11
  "file_path": "包含符号的文件路径",
12
12
  "line": "符号所在的行号(从0开始)",
13
13
  "character": "符号在行中的字符位置",
14
- "language": f"文件的编程语言({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
14
+ "language": f"文件的编程语言({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})",
15
+ "root_dir": {
16
+ "type": "string",
17
+ "description": "LSP操作的根目录路径(可选)",
18
+ "default": "."
19
+ }
15
20
  }
16
21
 
17
22
  @staticmethod
@@ -26,6 +31,7 @@ class LSPFindDefinitionTool:
26
31
  line = args.get("line", None)
27
32
  character = args.get("character", None)
28
33
  language = args.get("language", "")
34
+ root_dir = args.get("root_dir", ".")
29
35
 
30
36
  # Validate inputs
31
37
  if not all([file_path, line is not None, character is not None, language]):
@@ -52,83 +58,93 @@ class LSPFindDefinitionTool:
52
58
  "stdout": ""
53
59
  }
54
60
 
55
- # Get LSP instance
56
- registry = LSPRegistry.get_global_lsp_registry()
57
- lsp = registry.create_lsp(language)
61
+ # Store current directory
62
+ original_dir = os.getcwd()
58
63
 
59
- if not lsp:
60
- return {
61
- "success": False,
62
- "stderr": f"No LSP support for language: {language}",
63
- "stdout": ""
64
- }
65
-
66
64
  try:
67
- # Initialize LSP
68
- if not lsp.initialize(os.path.abspath(os.getcwd())):
65
+ # Change to root_dir
66
+ os.chdir(root_dir)
67
+
68
+ # Get LSP instance
69
+ registry = LSPRegistry.get_global_lsp_registry()
70
+ lsp = registry.create_lsp(language)
71
+
72
+ if not lsp:
69
73
  return {
70
74
  "success": False,
71
- "stderr": "LSP initialization failed",
75
+ "stderr": f"No LSP support for language: {language}",
72
76
  "stdout": ""
73
77
  }
74
78
 
75
- # Get symbol at position
76
- symbol = LSPRegistry.get_text_at_position(file_path, line, character)
77
- if not symbol:
78
- return {
79
- "success": False,
80
- "stderr": f"No symbol found at position {line}:{character}",
81
- "stdout": ""
82
- }
79
+ try:
80
+ # Initialize LSP
81
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
82
+ return {
83
+ "success": False,
84
+ "stderr": "LSP initialization failed",
85
+ "stdout": ""
86
+ }
87
+
88
+ # Get symbol at position
89
+ symbol = LSPRegistry.get_text_at_position(file_path, line, character)
90
+ if not symbol:
91
+ return {
92
+ "success": False,
93
+ "stderr": f"No symbol found at position {line}:{character}",
94
+ "stdout": ""
95
+ }
96
+
97
+ # Find definition
98
+ defn = lsp.find_definition(file_path, (line, character))
99
+
100
+ if not defn:
101
+ return {
102
+ "success": True,
103
+ "stdout": f"No definition found for '{symbol}'",
104
+ "stderr": ""
105
+ }
106
+
107
+ # Format output
108
+ def_line = defn["range"]["start"]["line"]
109
+ def_char = defn["range"]["start"]["character"]
110
+ context = LSPRegistry.get_line_at_position(defn["uri"], def_line).strip()
111
+
112
+ output = [
113
+ f"Definition of '{symbol}':",
114
+ f"File: {defn['uri']}",
115
+ f"Line {def_line + 1}, Col {def_char + 1}: {context}"
116
+ ]
117
+
118
+ # Get a few lines of context around the definition
119
+ try:
120
+ with open(defn["uri"], 'r', errors="ignore") as f:
121
+ lines = f.readlines()
122
+ start = max(0, def_line - 2)
123
+ end = min(len(lines), def_line + 3)
124
+
125
+ if start < def_line:
126
+ output.append("\nContext:")
127
+ for i in range(start, end):
128
+ prefix = ">" if i == def_line else " "
129
+ output.append(f"{prefix} {i+1:4d} | {lines[i].rstrip()}")
130
+ except Exception:
131
+ pass
83
132
 
84
- # Find definition
85
- defn = lsp.find_definition(file_path, (line, character))
86
-
87
- if not defn:
88
133
  return {
89
134
  "success": True,
90
- "stdout": f"No definition found for '{symbol}'",
135
+ "stdout": "\n".join(output),
91
136
  "stderr": ""
92
137
  }
93
138
 
94
- # Format output
95
- def_line = defn["range"]["start"]["line"]
96
- def_char = defn["range"]["start"]["character"]
97
- context = LSPRegistry.get_line_at_position(defn["uri"], def_line).strip()
98
-
99
- output = [
100
- f"Definition of '{symbol}':",
101
- f"File: {defn['uri']}",
102
- f"Line {def_line + 1}, Col {def_char + 1}: {context}"
103
- ]
104
-
105
- # Get a few lines of context around the definition
106
- try:
107
- with open(defn["uri"], 'r') as f:
108
- lines = f.readlines()
109
- start = max(0, def_line - 2)
110
- end = min(len(lines), def_line + 3)
111
-
112
- if start < def_line:
113
- output.append("\nContext:")
114
- for i in range(start, end):
115
- prefix = ">" if i == def_line else " "
116
- output.append(f"{prefix} {i+1:4d} | {lines[i].rstrip()}")
117
- except Exception:
118
- pass
119
-
120
- return {
121
- "success": True,
122
- "stdout": "\n".join(output),
123
- "stderr": ""
124
- }
125
-
126
- except Exception as e:
127
- return {
128
- "success": False,
129
- "stderr": f"Error finding definition: {str(e)}",
130
- "stdout": ""
131
- }
139
+ except Exception as e:
140
+ return {
141
+ "success": False,
142
+ "stderr": f"Error finding definition: {str(e)}",
143
+ "stdout": ""
144
+ }
145
+ finally:
146
+ if lsp:
147
+ lsp.shutdown()
132
148
  finally:
133
- if lsp:
134
- lsp.shutdown()
149
+ # Always restore original directory
150
+ os.chdir(original_dir)
@@ -11,7 +11,12 @@ class LSPFindReferencesTool:
11
11
  "file_path": "Path to the file containing the symbol",
12
12
  "line": "Line number (0-based) of the symbol",
13
13
  "character": "Character position in the line",
14
- "language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
14
+ "language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})",
15
+ "root_dir": {
16
+ "type": "string",
17
+ "description": "Root directory for LSP operations (optional)",
18
+ "default": "."
19
+ }
15
20
  }
16
21
 
17
22
  @staticmethod
@@ -26,6 +31,7 @@ class LSPFindReferencesTool:
26
31
  line = args.get("line", None)
27
32
  character = args.get("character", None)
28
33
  language = args.get("language", "")
34
+ root_dir = args.get("root_dir", ".")
29
35
 
30
36
  # Validate inputs
31
37
  if not all([file_path, line is not None, character is not None, language]):
@@ -52,60 +58,70 @@ class LSPFindReferencesTool:
52
58
  "stdout": ""
53
59
  }
54
60
 
55
- # Get LSP instance
56
- registry = LSPRegistry.get_global_lsp_registry()
57
- lsp = registry.create_lsp(language)
61
+ # Store current directory
62
+ original_dir = os.getcwd()
58
63
 
59
- if not lsp:
60
- return {
61
- "success": False,
62
- "stderr": f"No LSP support for language: {language}",
63
- "stdout": ""
64
- }
65
-
66
64
  try:
67
- # Initialize LSP
68
- if not lsp.initialize(os.path.abspath(os.getcwd())):
65
+ # Change to root_dir
66
+ os.chdir(root_dir)
67
+
68
+ # Get LSP instance
69
+ registry = LSPRegistry.get_global_lsp_registry()
70
+ lsp = registry.create_lsp(language)
71
+
72
+ if not lsp:
69
73
  return {
70
74
  "success": False,
71
- "stderr": "LSP initialization failed",
75
+ "stderr": f"No LSP support for language: {language}",
72
76
  "stdout": ""
73
77
  }
74
78
 
75
- # Get symbol at position
76
- symbol = LSPRegistry.get_text_at_position(file_path, line, character)
77
- if not symbol:
79
+ try:
80
+ # Initialize LSP
81
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
82
+ return {
83
+ "success": False,
84
+ "stderr": "LSP initialization failed",
85
+ "stdout": ""
86
+ }
87
+
88
+ # Get symbol at position
89
+ symbol = LSPRegistry.get_text_at_position(file_path, line, character)
90
+ if not symbol:
91
+ return {
92
+ "success": False,
93
+ "stderr": f"No symbol found at position {line}:{character}",
94
+ "stdout": ""
95
+ }
96
+
97
+ # Find references
98
+ refs = lsp.find_references(file_path, (line, character))
99
+
100
+ # Format output
101
+ output = [f"References to '{symbol}':\n"]
102
+ for ref in refs:
103
+ ref_line = ref["range"]["start"]["line"]
104
+ ref_char = ref["range"]["start"]["character"]
105
+ context = LSPRegistry.get_line_at_position(ref["uri"], ref_line).strip()
106
+ output.append(f"File: {ref['uri']}")
107
+ output.append(f"Line {ref_line + 1}, Col {ref_char + 1}: {context}")
108
+ output.append("-" * 40)
109
+
110
+ return {
111
+ "success": True,
112
+ "stdout": "\n".join(output) if len(refs) > 0 else f"No references found for '{symbol}'",
113
+ "stderr": ""
114
+ }
115
+
116
+ except Exception as e:
78
117
  return {
79
118
  "success": False,
80
- "stderr": f"No symbol found at position {line}:{character}",
119
+ "stderr": f"Error finding references: {str(e)}",
81
120
  "stdout": ""
82
121
  }
83
-
84
- # Find references
85
- refs = lsp.find_references(file_path, (line, character))
86
-
87
- # Format output
88
- output = [f"References to '{symbol}':\n"]
89
- for ref in refs:
90
- ref_line = ref["range"]["start"]["line"]
91
- ref_char = ref["range"]["start"]["character"]
92
- context = LSPRegistry.get_line_at_position(ref["uri"], ref_line).strip()
93
- output.append(f"File: {ref['uri']}")
94
- output.append(f"Line {ref_line + 1}, Col {ref_char + 1}: {context}")
95
- output.append("-" * 40)
96
-
97
- return {
98
- "success": True,
99
- "stdout": "\n".join(output) if len(refs) > 0 else f"No references found for '{symbol}'",
100
- "stderr": ""
101
- }
102
-
103
- except Exception as e:
104
- return {
105
- "success": False,
106
- "stderr": f"Error finding references: {str(e)}",
107
- "stdout": ""
108
- }
122
+ finally:
123
+ if lsp:
124
+ lsp.shutdown()
109
125
  finally:
110
- if lsp:
111
- lsp.shutdown()
126
+ # Always restore original directory
127
+ os.chdir(original_dir)
@@ -11,7 +11,12 @@ class LSPGetDiagnosticsTool:
11
11
  # 工具参数定义
12
12
  parameters = {
13
13
  "file_path": "Path to the file to analyze",
14
- "language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
14
+ "language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})",
15
+ "root_dir": {
16
+ "type": "string",
17
+ "description": "Root directory for LSP operations (optional)",
18
+ "default": "."
19
+ }
15
20
  }
16
21
 
17
22
  @staticmethod
@@ -24,6 +29,7 @@ class LSPGetDiagnosticsTool:
24
29
  """执行工具的主要逻辑"""
25
30
  file_path = args.get("file_path", "")
26
31
  language = args.get("language", "")
32
+ root_dir = args.get("root_dir", ".")
27
33
 
28
34
  # 验证输入参数
29
35
  if not all([file_path, language]):
@@ -41,89 +47,99 @@ class LSPGetDiagnosticsTool:
41
47
  "stdout": ""
42
48
  }
43
49
 
44
- # 获取LSP实例
45
- registry = LSPRegistry.get_global_lsp_registry()
46
- lsp = registry.create_lsp(language)
50
+ # 存储当前目录
51
+ original_dir = os.getcwd()
47
52
 
48
- # 检查语言是否支持
49
- if not lsp:
50
- return {
51
- "success": False,
52
- "stderr": f"No LSP support for language: {language}",
53
- "stdout": ""
54
- }
55
-
56
53
  try:
57
- # 初始化LSP
58
- if not lsp.initialize(os.path.abspath(os.getcwd())):
54
+ # 切换到root_dir
55
+ os.chdir(root_dir)
56
+
57
+ # 获取LSP实例
58
+ registry = LSPRegistry.get_global_lsp_registry()
59
+ lsp = registry.create_lsp(language)
60
+
61
+ # 检查语言是否支持
62
+ if not lsp:
59
63
  return {
60
64
  "success": False,
61
- "stderr": "LSP initialization failed",
65
+ "stderr": f"No LSP support for language: {language}",
62
66
  "stdout": ""
63
67
  }
64
68
 
65
- # 获取诊断信息
66
- diagnostics = lsp.get_diagnostics(file_path)
67
-
68
- # 如果没有诊断信息
69
- if not diagnostics:
69
+ try:
70
+ # 初始化LSP
71
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
72
+ return {
73
+ "success": False,
74
+ "stderr": "LSP initialization failed",
75
+ "stdout": ""
76
+ }
77
+
78
+ # 获取诊断信息
79
+ diagnostics = lsp.get_diagnostics(file_path)
80
+
81
+ # 如果没有诊断信息
82
+ if not diagnostics:
83
+ return {
84
+ "success": True,
85
+ "stdout": "No issues found in the file",
86
+ "stderr": ""
87
+ }
88
+
89
+ # 格式化输出
90
+ output = ["Diagnostics:"]
91
+ # 严重程度映射
92
+ severity_map = {1: "Error", 2: "Warning", 3: "Info", 4: "Hint"}
93
+
94
+ # 按严重程度和行号排序诊断信息
95
+ sorted_diagnostics = sorted(
96
+ diagnostics,
97
+ key=lambda x: (x["severity"], x["range"]["start"]["line"])
98
+ )
99
+
100
+ # 处理每个诊断信息
101
+ for diag in sorted_diagnostics:
102
+ severity = severity_map.get(diag["severity"], "Unknown")
103
+ start = diag["range"]["start"]
104
+ line = LSPRegistry.get_line_at_position(file_path, start["line"]).strip()
105
+
106
+ output.extend([
107
+ f"\n{severity} at line {start['line'] + 1}, column {start['character'] + 1}:",
108
+ f"Message: {diag['message']}",
109
+ f"Code: {line}",
110
+ "-" * 60
111
+ ])
112
+
113
+ # 处理相关附加信息
114
+ if diag.get("relatedInformation"):
115
+ output.append("Related information:")
116
+ for info in diag["relatedInformation"]:
117
+ info_line = LSPRegistry.get_line_at_position(
118
+ info["location"]["uri"],
119
+ info["location"]["range"]["start"]["line"]
120
+ ).strip()
121
+ output.extend([
122
+ f" - {info['message']}",
123
+ f" at {info['location']['uri']}:{info['location']['range']['start']['line'] + 1}",
124
+ f" {info_line}"
125
+ ])
126
+
70
127
  return {
71
128
  "success": True,
72
- "stdout": "No issues found in the file",
129
+ "stdout": "\n".join(output),
73
130
  "stderr": ""
74
131
  }
75
132
 
76
- # 格式化输出
77
- output = ["Diagnostics:"]
78
- # 严重程度映射
79
- severity_map = {1: "Error", 2: "Warning", 3: "Info", 4: "Hint"}
80
-
81
- # 按严重程度和行号排序诊断信息
82
- sorted_diagnostics = sorted(
83
- diagnostics,
84
- key=lambda x: (x["severity"], x["range"]["start"]["line"])
85
- )
86
-
87
- # 处理每个诊断信息
88
- for diag in sorted_diagnostics:
89
- severity = severity_map.get(diag["severity"], "Unknown")
90
- start = diag["range"]["start"]
91
- line = LSPRegistry.get_line_at_position(file_path, start["line"]).strip()
92
-
93
- output.extend([
94
- f"\n{severity} at line {start['line'] + 1}, column {start['character'] + 1}:",
95
- f"Message: {diag['message']}",
96
- f"Code: {line}",
97
- "-" * 60
98
- ])
99
-
100
- # 处理相关附加信息
101
- if diag.get("relatedInformation"):
102
- output.append("Related information:")
103
- for info in diag["relatedInformation"]:
104
- info_line = LSPRegistry.get_line_at_position(
105
- info["location"]["uri"],
106
- info["location"]["range"]["start"]["line"]
107
- ).strip()
108
- output.extend([
109
- f" - {info['message']}",
110
- f" at {info['location']['uri']}:{info['location']['range']['start']['line'] + 1}",
111
- f" {info_line}"
112
- ])
113
-
114
- return {
115
- "success": True,
116
- "stdout": "\n".join(output),
117
- "stderr": ""
118
- }
119
-
120
- except Exception as e:
121
- return {
122
- "success": False,
123
- "stderr": f"Error getting diagnostics: {str(e)}",
124
- "stdout": ""
125
- }
133
+ except Exception as e:
134
+ return {
135
+ "success": False,
136
+ "stderr": f"Error getting diagnostics: {str(e)}",
137
+ "stdout": ""
138
+ }
139
+ finally:
140
+ # 确保关闭LSP连接
141
+ if lsp:
142
+ lsp.shutdown()
126
143
  finally:
127
- # 确保关闭LSP连接
128
- if lsp:
129
- lsp.shutdown()
144
+ # 恢复原始目录
145
+ os.chdir(original_dir)
@@ -47,7 +47,7 @@ class MethodologyTool:
47
47
  """Ensure the methodology file exists"""
48
48
  if not os.path.exists(self.methodology_file):
49
49
  try:
50
- with open(self.methodology_file, 'w', encoding='utf-8') as f:
50
+ with open(self.methodology_file, 'w', encoding='utf-8', errors="ignore") as f:
51
51
  yaml.safe_dump({}, f, allow_unicode=True)
52
52
  except Exception as e:
53
53
  PrettyOutput.print(f"创建方法论文件失败:{str(e)}", OutputType.ERROR)
@@ -55,7 +55,7 @@ class MethodologyTool:
55
55
  def _load_methodologies(self) -> Dict:
56
56
  """Load all methodologies"""
57
57
  try:
58
- with open(self.methodology_file, 'r', encoding='utf-8') as f:
58
+ with open(self.methodology_file, 'r', encoding='utf-8', errors="ignore") as f:
59
59
  return yaml.safe_load(f) or {}
60
60
  except Exception as e:
61
61
  PrettyOutput.print(f"加载方法论失败: {str(e)}", OutputType.ERROR)
@@ -64,7 +64,7 @@ class MethodologyTool:
64
64
  def _save_methodologies(self, methodologies: Dict):
65
65
  """Save all methodologies"""
66
66
  try:
67
- with open(self.methodology_file, 'w', encoding='utf-8') as f:
67
+ with open(self.methodology_file, 'w', encoding='utf-8', errors="ignore") as f:
68
68
  yaml.safe_dump(methodologies, f, allow_unicode=True)
69
69
  except Exception as e:
70
70
  PrettyOutput.print(f"保存方法论失败: {str(e)}", OutputType.ERROR)
@@ -49,7 +49,7 @@ class ReadCodeTool:
49
49
  }
50
50
 
51
51
  # 读取文件内容
52
- with open(abs_path, 'r', encoding='utf-8') as f:
52
+ with open(abs_path, 'r', encoding='utf-8', errors="ignore") as f:
53
53
  lines = f.readlines()
54
54
 
55
55
  total_lines = len(lines)
@@ -168,22 +168,20 @@ class SearchTool:
168
168
  # Process each batch
169
169
  batch_results = []
170
170
  for i, batch in enumerate(batches, 1):
171
- PrettyOutput.print(f"正在处理批次 {i}/{len(batches)}...", OutputType.PROGRESS)
172
-
173
- prompt = f"""Please analyze these search results to answer the question: {question}
171
+ prompt = f"""请根据以下搜索结果回答以下问题:{question}
174
172
 
175
- Search results content (Batch {i}/{len(batches)}):
173
+ 搜索结果内容 ( {i} 批/{len(batches)}):
176
174
  {'-' * 40}
177
175
  {''.join(batch)}
178
176
  {'-' * 40}
179
177
 
180
- Please extract key information related to the question. Focus on:
181
- 1. Relevant facts and details
182
- 2. Maintaining objectivity
183
- 3. Citing sources when appropriate
184
- 4. Noting any uncertainties
178
+ 请提取与问题相关的关键信息。重点关注:
179
+ 1. 相关事实和细节
180
+ 2. 保持客观性
181
+ 3. 在适当的时候引用来源
182
+ 4. 注明任何不确定性
185
183
 
186
- Format your response as a clear summary of findings from this batch."""
184
+ 请将您的回答格式化为对本批次搜索结果的清晰总结。"""
187
185
 
188
186
  response = self.model.chat_until_success(prompt)
189
187
  batch_results.append(response)
@@ -196,27 +194,27 @@ Format your response as a clear summary of findings from this batch."""
196
194
  batch_findings = '\n\n'.join(f'Batch {i+1}:\n{result}' for i, result in enumerate(batch_results))
197
195
  separator = '-' * 40
198
196
 
199
- synthesis_prompt = f"""Please provide a comprehensive answer to the original question by synthesizing the findings from multiple batches of search results.
197
+ synthesis_prompt = f"""请通过综合多个批次的搜索结果,为原始问题提供一个全面的回答。
200
198
 
201
- Original Question: {question}
199
+ 原始问题: {question}
202
200
 
203
- Findings from each batch:
201
+ 各批次的发现:
204
202
  {separator}
205
203
  {batch_findings}
206
204
  {separator}
207
205
 
208
- Please synthesize a final answer that:
209
- 1. Combines key insights from all batches
210
- 2. Resolves any contradictions between sources
211
- 3. Maintains clear source attribution
212
- 4. Acknowledges any remaining uncertainties
213
- 5. Provides a coherent and complete response to the original question"""
206
+ 请综合出一个最终答案,要求:
207
+ 1. 整合所有批次的关键见解
208
+ 2. 解决不同来源之间的矛盾
209
+ 3. 保持清晰的来源归属
210
+ 4. 承认任何剩余的不确定性
211
+ 5. 提供对原始问题的连贯完整的回答"""
214
212
 
215
213
  final_response = self.model.chat_until_success(synthesis_prompt)
216
214
  return final_response
217
215
 
218
216
  except Exception as e:
219
- return f"Information extraction failed: {str(e)}"
217
+ return f"信息提取失败:{str(e)}"
220
218
 
221
219
  def execute(self, args: Dict) -> Dict[str, Any]:
222
220
  """Execute search and extract information"""
@@ -84,7 +84,7 @@ class ToolGenerator:
84
84
  tools_dir.mkdir(parents=True, exist_ok=True)
85
85
  tool_file = tools_dir / f"{tool_name}.py"
86
86
 
87
- with open(tool_file, "w") as f:
87
+ with open(tool_file, "w", errors="ignore") as f:
88
88
  f.write(implementation)
89
89
  spinner.text = "工具保存完成"
90
90
  spinner.ok("✅")