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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +23 -9
- jarvis/jarvis_agent/builtin_input_handler.py +73 -0
- jarvis/{jarvis_code_agent → jarvis_agent}/file_input_handler.py +1 -1
- jarvis/jarvis_agent/main.py +1 -1
- jarvis/{jarvis_code_agent → jarvis_agent}/patch.py +23 -19
- jarvis/{jarvis_code_agent → jarvis_agent}/shell_input_handler.py +0 -1
- jarvis/jarvis_code_agent/code_agent.py +20 -16
- jarvis/jarvis_codebase/main.py +5 -5
- jarvis/jarvis_dev/main.py +1 -1
- jarvis/jarvis_git_squash/main.py +1 -1
- jarvis/jarvis_lsp/base.py +2 -26
- jarvis/jarvis_lsp/cpp.py +2 -14
- jarvis/jarvis_lsp/go.py +0 -13
- jarvis/jarvis_lsp/python.py +1 -30
- jarvis/jarvis_lsp/registry.py +10 -14
- jarvis/jarvis_lsp/rust.py +0 -12
- jarvis/jarvis_multi_agent/__init__.py +1 -1
- jarvis/jarvis_platform/registry.py +1 -1
- jarvis/jarvis_platform_manager/main.py +3 -3
- jarvis/jarvis_rag/main.py +1 -1
- jarvis/jarvis_tools/ask_codebase.py +40 -20
- jarvis/jarvis_tools/code_review.py +180 -143
- jarvis/jarvis_tools/create_code_agent.py +76 -72
- jarvis/jarvis_tools/create_sub_agent.py +32 -15
- jarvis/jarvis_tools/execute_shell.py +2 -2
- jarvis/jarvis_tools/execute_shell_script.py +1 -1
- jarvis/jarvis_tools/file_operation.py +2 -2
- jarvis/jarvis_tools/git_commiter.py +87 -68
- jarvis/jarvis_tools/lsp_find_definition.py +83 -67
- jarvis/jarvis_tools/lsp_find_references.py +62 -46
- jarvis/jarvis_tools/lsp_get_diagnostics.py +90 -74
- jarvis/jarvis_tools/methodology.py +3 -3
- jarvis/jarvis_tools/read_code.py +1 -1
- jarvis/jarvis_tools/search_web.py +18 -20
- jarvis/jarvis_tools/tool_generator.py +1 -1
- jarvis/jarvis_tools/treesitter_analyzer.py +331 -0
- jarvis/jarvis_treesitter/README.md +104 -0
- jarvis/jarvis_treesitter/__init__.py +20 -0
- jarvis/jarvis_treesitter/database.py +258 -0
- jarvis/jarvis_treesitter/example.py +115 -0
- jarvis/jarvis_treesitter/grammar_builder.py +182 -0
- jarvis/jarvis_treesitter/language.py +117 -0
- jarvis/jarvis_treesitter/symbol.py +31 -0
- jarvis/jarvis_treesitter/tools_usage.md +121 -0
- jarvis/jarvis_utils/git_utils.py +10 -2
- jarvis/jarvis_utils/input.py +3 -1
- jarvis/jarvis_utils/methodology.py +1 -1
- jarvis/jarvis_utils/utils.py +3 -3
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/METADATA +2 -4
- jarvis_ai_assistant-0.1.131.dist-info/RECORD +85 -0
- jarvis/jarvis_c2rust/c2rust.yaml +0 -734
- jarvis/jarvis_code_agent/builtin_input_handler.py +0 -43
- jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -87
- jarvis/jarvis_tools/lsp_prepare_rename.py +0 -130
- jarvis_ai_assistant-0.1.130.dist-info/RECORD +0 -79
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/entry_points.txt +0 -0
- {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
|
-
#
|
|
56
|
-
|
|
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
|
-
#
|
|
68
|
-
|
|
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
|
|
75
|
+
"stderr": f"No LSP support for language: {language}",
|
|
72
76
|
"stdout": ""
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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":
|
|
135
|
+
"stdout": "\n".join(output),
|
|
91
136
|
"stderr": ""
|
|
92
137
|
}
|
|
93
138
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
-
#
|
|
56
|
-
|
|
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
|
-
#
|
|
68
|
-
|
|
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
|
|
75
|
+
"stderr": f"No LSP support for language: {language}",
|
|
72
76
|
"stdout": ""
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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"
|
|
119
|
+
"stderr": f"Error finding references: {str(e)}",
|
|
81
120
|
"stdout": ""
|
|
82
121
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
#
|
|
45
|
-
|
|
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
|
-
#
|
|
58
|
-
|
|
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
|
|
65
|
+
"stderr": f"No LSP support for language: {language}",
|
|
62
66
|
"stdout": ""
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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": "
|
|
129
|
+
"stdout": "\n".join(output),
|
|
73
130
|
"stderr": ""
|
|
74
131
|
}
|
|
75
132
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
#
|
|
128
|
-
|
|
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)
|
jarvis/jarvis_tools/read_code.py
CHANGED
|
@@ -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
|
-
|
|
172
|
-
|
|
173
|
-
prompt = f"""Please analyze these search results to answer the question: {question}
|
|
171
|
+
prompt = f"""请根据以下搜索结果回答以下问题:{question}
|
|
174
172
|
|
|
175
|
-
|
|
173
|
+
搜索结果内容 (第 {i} 批/{len(batches)}):
|
|
176
174
|
{'-' * 40}
|
|
177
175
|
{''.join(batch)}
|
|
178
176
|
{'-' * 40}
|
|
179
177
|
|
|
180
|
-
|
|
181
|
-
1.
|
|
182
|
-
2.
|
|
183
|
-
3.
|
|
184
|
-
4.
|
|
178
|
+
请提取与问题相关的关键信息。重点关注:
|
|
179
|
+
1. 相关事实和细节
|
|
180
|
+
2. 保持客观性
|
|
181
|
+
3. 在适当的时候引用来源
|
|
182
|
+
4. 注明任何不确定性
|
|
185
183
|
|
|
186
|
-
|
|
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"""
|
|
197
|
+
synthesis_prompt = f"""请通过综合多个批次的搜索结果,为原始问题提供一个全面的回答。
|
|
200
198
|
|
|
201
|
-
|
|
199
|
+
原始问题: {question}
|
|
202
200
|
|
|
203
|
-
|
|
201
|
+
各批次的发现:
|
|
204
202
|
{separator}
|
|
205
203
|
{batch_findings}
|
|
206
204
|
{separator}
|
|
207
205
|
|
|
208
|
-
|
|
209
|
-
1.
|
|
210
|
-
2.
|
|
211
|
-
3.
|
|
212
|
-
4.
|
|
213
|
-
5.
|
|
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"
|
|
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("✅")
|