jarvis-ai-assistant 0.1.193__py3-none-any.whl → 0.1.195__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +45 -41
- jarvis/jarvis_agent/builtin_input_handler.py +26 -4
- jarvis/jarvis_agent/jarvis.py +30 -19
- jarvis/jarvis_agent/main.py +20 -12
- jarvis/jarvis_agent/output_handler.py +7 -7
- jarvis/jarvis_agent/shell_input_handler.py +14 -11
- jarvis/jarvis_code_agent/code_agent.py +81 -79
- jarvis/jarvis_code_agent/lint.py +92 -105
- jarvis/jarvis_code_analysis/checklists/__init__.py +1 -1
- jarvis/jarvis_code_analysis/checklists/c_cpp.py +1 -1
- jarvis/jarvis_code_analysis/checklists/csharp.py +1 -1
- jarvis/jarvis_code_analysis/checklists/data_format.py +1 -1
- jarvis/jarvis_code_analysis/checklists/devops.py +1 -1
- jarvis/jarvis_code_analysis/checklists/docs.py +1 -1
- jarvis/jarvis_code_analysis/checklists/go.py +1 -1
- jarvis/jarvis_code_analysis/checklists/infrastructure.py +1 -1
- jarvis/jarvis_code_analysis/checklists/java.py +1 -1
- jarvis/jarvis_code_analysis/checklists/javascript.py +1 -1
- jarvis/jarvis_code_analysis/checklists/kotlin.py +1 -1
- jarvis/jarvis_code_analysis/checklists/loader.py +31 -29
- jarvis/jarvis_code_analysis/checklists/php.py +1 -1
- jarvis/jarvis_code_analysis/checklists/python.py +1 -1
- jarvis/jarvis_code_analysis/checklists/ruby.py +1 -1
- jarvis/jarvis_code_analysis/checklists/rust.py +1 -1
- jarvis/jarvis_code_analysis/checklists/shell.py +1 -1
- jarvis/jarvis_code_analysis/checklists/sql.py +1 -1
- jarvis/jarvis_code_analysis/checklists/swift.py +1 -1
- jarvis/jarvis_code_analysis/checklists/web.py +1 -1
- jarvis/jarvis_code_analysis/code_review.py +292 -190
- jarvis/jarvis_dev/main.py +73 -56
- jarvis/jarvis_git_details/main.py +29 -33
- jarvis/jarvis_git_squash/main.py +13 -11
- jarvis/jarvis_git_utils/git_commiter.py +15 -5
- jarvis/jarvis_mcp/__init__.py +8 -10
- jarvis/jarvis_mcp/sse_mcp_client.py +182 -205
- jarvis/jarvis_mcp/stdio_mcp_client.py +93 -120
- jarvis/jarvis_mcp/streamable_mcp_client.py +117 -142
- jarvis/jarvis_methodology/main.py +71 -39
- jarvis/jarvis_multi_agent/__init__.py +24 -16
- jarvis/jarvis_multi_agent/main.py +10 -4
- jarvis/jarvis_platform/__init__.py +1 -1
- jarvis/jarvis_platform/base.py +44 -18
- jarvis/jarvis_platform/human.py +15 -3
- jarvis/jarvis_platform/kimi.py +117 -81
- jarvis/jarvis_platform/openai.py +23 -28
- jarvis/jarvis_platform/registry.py +43 -29
- jarvis/jarvis_platform/tongyi.py +16 -10
- jarvis/jarvis_platform/yuanbao.py +197 -144
- jarvis/jarvis_platform_manager/main.py +4 -2
- jarvis/jarvis_smart_shell/main.py +35 -30
- jarvis/jarvis_tools/ask_user.py +8 -16
- jarvis/jarvis_tools/base.py +3 -2
- jarvis/jarvis_tools/chdir.py +7 -19
- jarvis/jarvis_tools/cli/main.py +14 -10
- jarvis/jarvis_tools/code_plan.py +10 -31
- jarvis/jarvis_tools/create_code_agent.py +6 -11
- jarvis/jarvis_tools/create_sub_agent.py +10 -22
- jarvis/jarvis_tools/edit_file.py +98 -76
- jarvis/jarvis_tools/execute_script.py +46 -46
- jarvis/jarvis_tools/file_analyzer.py +22 -34
- jarvis/jarvis_tools/file_operation.py +69 -62
- jarvis/jarvis_tools/generate_new_tool.py +0 -2
- jarvis/jarvis_tools/methodology.py +19 -23
- jarvis/jarvis_tools/read_code.py +35 -35
- jarvis/jarvis_tools/read_webpage.py +7 -16
- jarvis/jarvis_tools/registry.py +63 -30
- jarvis/jarvis_tools/rewrite_file.py +26 -29
- jarvis/jarvis_tools/search_web.py +5 -8
- jarvis/jarvis_tools/virtual_tty.py +133 -122
- jarvis/jarvis_utils/__init__.py +0 -1
- jarvis/jarvis_utils/builtin_replace_map.py +9 -9
- jarvis/jarvis_utils/config.py +60 -37
- jarvis/jarvis_utils/embedding.py +24 -19
- jarvis/jarvis_utils/file_processors.py +16 -9
- jarvis/jarvis_utils/git_utils.py +157 -107
- jarvis/jarvis_utils/globals.py +1 -1
- jarvis/jarvis_utils/input.py +85 -52
- jarvis/jarvis_utils/jarvis_history.py +43 -0
- jarvis/jarvis_utils/methodology.py +31 -24
- jarvis/jarvis_utils/output.py +164 -80
- jarvis/jarvis_utils/tag.py +2 -1
- jarvis/jarvis_utils/utils.py +84 -52
- {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/METADATA +362 -230
- jarvis_ai_assistant-0.1.195.dist-info/RECORD +98 -0
- jarvis/jarvis_agent/file_input_handler.py +0 -112
- jarvis/jarvis_event/__init__.py +0 -0
- jarvis_ai_assistant-0.1.193.dist-info/RECORD +0 -99
- {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/top_level.txt +0 -0
@@ -10,35 +10,44 @@ from typing import Any, Dict
|
|
10
10
|
|
11
11
|
class VirtualTTYTool:
|
12
12
|
name = "virtual_tty"
|
13
|
-
description =
|
14
|
-
|
15
|
-
|
13
|
+
description = (
|
14
|
+
"控制虚拟终端执行各种操作,如启动终端、输入命令、获取输出等。"
|
15
|
+
+ "与execute_script不同,此工具会创建一个持久的虚拟终端会话,可以连续执行多个命令,并保持终端状态。"
|
16
|
+
+ "适用于需要交互式操作的场景,如运行需要用户输入的交互式程序(如:ssh连接、sftp传输、gdb/dlv调试等)。"
|
17
|
+
)
|
16
18
|
parameters = {
|
17
19
|
"type": "object",
|
18
20
|
"properties": {
|
19
21
|
"action": {
|
20
22
|
"type": "string",
|
21
23
|
"description": "要执行的终端操作类型",
|
22
|
-
"enum": [
|
24
|
+
"enum": [
|
25
|
+
"launch",
|
26
|
+
"send_keys",
|
27
|
+
"output",
|
28
|
+
"close",
|
29
|
+
"get_screen",
|
30
|
+
"list",
|
31
|
+
],
|
23
32
|
},
|
24
33
|
"keys": {
|
25
34
|
"type": "string",
|
26
|
-
"description": "要发送的按键序列(仅支持单行输入,当action为send_keys时有效)"
|
35
|
+
"description": "要发送的按键序列(仅支持单行输入,当action为send_keys时有效)",
|
27
36
|
},
|
28
37
|
"add_enter": {
|
29
38
|
"type": "boolean",
|
30
|
-
"description": "是否在单行命令末尾自动添加回车符(仅当action为send_keys时有效,默认为true)"
|
39
|
+
"description": "是否在单行命令末尾自动添加回车符(仅当action为send_keys时有效,默认为true)",
|
31
40
|
},
|
32
41
|
"timeout": {
|
33
42
|
"type": "number",
|
34
|
-
"description": "等待输出的超时时间(秒,仅当action为send_keys或output时有效,默认为5.0)"
|
43
|
+
"description": "等待输出的超时时间(秒,仅当action为send_keys或output时有效,默认为5.0)",
|
35
44
|
},
|
36
45
|
"tty_id": {
|
37
46
|
"type": "string",
|
38
|
-
"description": "虚拟终端的唯一标识符(默认为'default')"
|
39
|
-
}
|
47
|
+
"description": "虚拟终端的唯一标识符(默认为'default')",
|
48
|
+
},
|
40
49
|
},
|
41
|
-
"required": ["action"]
|
50
|
+
"required": ["action"],
|
42
51
|
}
|
43
52
|
|
44
53
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
@@ -56,38 +65,34 @@ class VirtualTTYTool:
|
|
56
65
|
# 获取agent对象
|
57
66
|
agent = args.get("agent")
|
58
67
|
if agent is None:
|
59
|
-
return {
|
60
|
-
|
61
|
-
"stdout": "",
|
62
|
-
"stderr": "未提供agent对象"
|
63
|
-
}
|
64
|
-
|
68
|
+
return {"success": False, "stdout": "", "stderr": "未提供agent对象"}
|
69
|
+
|
65
70
|
# 获取TTY ID,默认为"default"
|
66
71
|
tty_id = args.get("tty_id", "default")
|
67
|
-
|
72
|
+
|
68
73
|
# 确保agent有tty_sessions字典
|
69
74
|
if not hasattr(agent, "tty_sessions"):
|
70
75
|
agent.tty_sessions = {}
|
71
|
-
|
76
|
+
|
72
77
|
# 如果指定的tty_id不存在,为其创建一个新的tty_data
|
73
78
|
if tty_id not in agent.tty_sessions:
|
74
79
|
agent.tty_sessions[tty_id] = {
|
75
80
|
"master_fd": None,
|
76
81
|
"pid": None,
|
77
|
-
"shell": "/bin/bash"
|
82
|
+
"shell": "/bin/bash",
|
78
83
|
}
|
79
|
-
|
84
|
+
|
80
85
|
action = args.get("action", "").strip().lower()
|
81
|
-
|
86
|
+
|
82
87
|
# 验证操作类型
|
83
|
-
valid_actions = [
|
88
|
+
valid_actions = ["launch", "send_keys", "output", "close", "get_screen", "list"]
|
84
89
|
if action not in valid_actions:
|
85
90
|
return {
|
86
91
|
"success": False,
|
87
92
|
"stdout": "",
|
88
|
-
"stderr": f"不支持的操作: {action}。有效操作: {', '.join(valid_actions)}"
|
93
|
+
"stderr": f"不支持的操作: {action}。有效操作: {', '.join(valid_actions)}",
|
89
94
|
}
|
90
|
-
|
95
|
+
|
91
96
|
try:
|
92
97
|
if action == "launch":
|
93
98
|
if args.get("keys", "") != "":
|
@@ -95,7 +100,7 @@ class VirtualTTYTool:
|
|
95
100
|
return {
|
96
101
|
"success": False,
|
97
102
|
"stdout": "",
|
98
|
-
"stderr": "启动虚拟终端时,不能同时指定keys参数"
|
103
|
+
"stderr": "启动虚拟终端时,不能同时指定keys参数",
|
99
104
|
}
|
100
105
|
print(f"🚀 正在启动虚拟终端 [{tty_id}]...")
|
101
106
|
result = self._launch_tty(agent, tty_id)
|
@@ -148,40 +153,39 @@ class VirtualTTYTool:
|
|
148
153
|
else:
|
149
154
|
print("❌ 获取虚拟终端列表失败")
|
150
155
|
return result
|
151
|
-
return {
|
152
|
-
|
153
|
-
"stdout": "",
|
154
|
-
"stderr": "不支持的操作"
|
155
|
-
}
|
156
|
-
|
156
|
+
return {"success": False, "stdout": "", "stderr": "不支持的操作"}
|
157
|
+
|
157
158
|
except Exception as e:
|
158
159
|
return {
|
159
160
|
"success": False,
|
160
161
|
"stdout": "",
|
161
|
-
"stderr": f"执行终端操作出错: {str(e)}"
|
162
|
+
"stderr": f"执行终端操作出错: {str(e)}",
|
162
163
|
}
|
163
|
-
|
164
|
+
|
164
165
|
def _launch_tty(self, agent: Any, tty_id: str) -> Dict[str, Any]:
|
165
166
|
"""启动虚拟终端"""
|
166
167
|
try:
|
167
168
|
# 如果该ID的终端已经启动,先关闭它
|
168
169
|
if agent.tty_sessions[tty_id]["master_fd"] is not None:
|
169
170
|
self._close_tty(agent, tty_id)
|
170
|
-
|
171
|
+
|
171
172
|
# 创建伪终端
|
172
173
|
pid, master_fd = pty.fork()
|
173
|
-
|
174
|
+
|
174
175
|
if pid == 0: # 子进程
|
175
176
|
# 执行shell
|
176
|
-
os.execvp(
|
177
|
+
os.execvp(
|
178
|
+
agent.tty_sessions[tty_id]["shell"],
|
179
|
+
[agent.tty_sessions[tty_id]["shell"]],
|
180
|
+
)
|
177
181
|
else: # 父进程
|
178
182
|
# 设置非阻塞模式
|
179
183
|
fcntl.fcntl(master_fd, fcntl.F_SETFL, os.O_NONBLOCK)
|
180
|
-
|
184
|
+
|
181
185
|
# 保存终端状态
|
182
186
|
agent.tty_sessions[tty_id]["master_fd"] = master_fd
|
183
187
|
agent.tty_sessions[tty_id]["pid"] = pid
|
184
|
-
|
188
|
+
|
185
189
|
# 读取初始输出
|
186
190
|
output = ""
|
187
191
|
start_time = time.time()
|
@@ -194,26 +198,29 @@ class VirtualTTYTool:
|
|
194
198
|
output += data.decode()
|
195
199
|
except BlockingIOError:
|
196
200
|
continue
|
197
|
-
|
201
|
+
|
198
202
|
if output:
|
199
203
|
print(f"📤 终端 [{tty_id}]: {output}")
|
200
|
-
|
201
|
-
return {
|
202
|
-
|
203
|
-
"stdout": output,
|
204
|
-
"stderr": ""
|
205
|
-
}
|
206
|
-
|
204
|
+
|
205
|
+
return {"success": True, "stdout": output, "stderr": ""}
|
206
|
+
|
207
207
|
except Exception as e:
|
208
208
|
return {
|
209
209
|
"success": False,
|
210
210
|
"stdout": "",
|
211
|
-
"stderr": f"启动虚拟终端 [{tty_id}] 失败: {str(e)}"
|
211
|
+
"stderr": f"启动虚拟终端 [{tty_id}] 失败: {str(e)}",
|
212
212
|
}
|
213
|
-
|
214
|
-
def _input_command(
|
213
|
+
|
214
|
+
def _input_command(
|
215
|
+
self,
|
216
|
+
agent: Any,
|
217
|
+
tty_id: str,
|
218
|
+
command: str,
|
219
|
+
timeout: float,
|
220
|
+
add_enter: bool = True,
|
221
|
+
) -> Dict[str, Any]:
|
215
222
|
"""输入单行命令并等待输出
|
216
|
-
|
223
|
+
|
217
224
|
参数:
|
218
225
|
command: 要输入的单行命令
|
219
226
|
add_enter: 是否在命令末尾添加回车符
|
@@ -222,33 +229,31 @@ class VirtualTTYTool:
|
|
222
229
|
return {
|
223
230
|
"success": False,
|
224
231
|
"stdout": "",
|
225
|
-
"stderr": f"虚拟终端 [{tty_id}] 未启动"
|
232
|
+
"stderr": f"虚拟终端 [{tty_id}] 未启动",
|
226
233
|
}
|
227
|
-
|
234
|
+
|
228
235
|
# 严格检查并拒绝多行输入
|
229
236
|
if "\n" in command:
|
230
|
-
return {
|
231
|
-
|
232
|
-
"stdout": "",
|
233
|
-
"stderr": "错误:禁止多行输入"
|
234
|
-
}
|
235
|
-
|
237
|
+
return {"success": False, "stdout": "", "stderr": "错误:禁止多行输入"}
|
238
|
+
|
236
239
|
try:
|
237
240
|
# 根据add_enter参数决定是否添加回车符
|
238
241
|
if add_enter:
|
239
242
|
command = command + "\n"
|
240
|
-
|
243
|
+
|
241
244
|
# 发送按键序列
|
242
245
|
os.write(agent.tty_sessions[tty_id]["master_fd"], command.encode())
|
243
|
-
|
246
|
+
|
244
247
|
# 等待输出
|
245
248
|
output = ""
|
246
249
|
start_time = time.time()
|
247
|
-
|
250
|
+
|
248
251
|
while time.time() - start_time < timeout:
|
249
252
|
try:
|
250
253
|
# 使用select等待数据可读
|
251
|
-
r, _, _ = select.select(
|
254
|
+
r, _, _ = select.select(
|
255
|
+
[agent.tty_sessions[tty_id]["master_fd"]], [], [], 0.1
|
256
|
+
)
|
252
257
|
if r:
|
253
258
|
data = os.read(agent.tty_sessions[tty_id]["master_fd"], 1024)
|
254
259
|
if data:
|
@@ -256,39 +261,41 @@ class VirtualTTYTool:
|
|
256
261
|
except BlockingIOError:
|
257
262
|
continue
|
258
263
|
print(f"📤 终端 [{tty_id}]: {output}")
|
259
|
-
return {
|
260
|
-
|
261
|
-
"stdout": output,
|
262
|
-
"stderr": ""
|
263
|
-
}
|
264
|
-
|
264
|
+
return {"success": True, "stdout": output, "stderr": ""}
|
265
|
+
|
265
266
|
except Exception as e:
|
266
267
|
return {
|
267
268
|
"success": False,
|
268
269
|
"stdout": "",
|
269
|
-
"stderr": f"在终端 [{tty_id}] 执行命令失败: {str(e)}"
|
270
|
+
"stderr": f"在终端 [{tty_id}] 执行命令失败: {str(e)}",
|
270
271
|
}
|
271
|
-
|
272
|
-
def _get_output(
|
272
|
+
|
273
|
+
def _get_output(
|
274
|
+
self, agent: Any, tty_id: str, timeout: float = 5.0
|
275
|
+
) -> Dict[str, Any]:
|
273
276
|
"""获取终端输出"""
|
274
277
|
if agent.tty_sessions[tty_id]["master_fd"] is None:
|
275
278
|
return {
|
276
279
|
"success": False,
|
277
280
|
"stdout": "",
|
278
|
-
"stderr": f"虚拟终端 [{tty_id}] 未启动"
|
281
|
+
"stderr": f"虚拟终端 [{tty_id}] 未启动",
|
279
282
|
}
|
280
|
-
|
283
|
+
|
281
284
|
try:
|
282
285
|
output = ""
|
283
286
|
start_time = time.time()
|
284
|
-
|
287
|
+
|
285
288
|
while time.time() - start_time < timeout:
|
286
289
|
# 使用select等待数据可读
|
287
|
-
r, _, _ = select.select(
|
290
|
+
r, _, _ = select.select(
|
291
|
+
[agent.tty_sessions[tty_id]["master_fd"]], [], [], 0.1
|
292
|
+
)
|
288
293
|
if r:
|
289
294
|
while True:
|
290
295
|
try:
|
291
|
-
data = os.read(
|
296
|
+
data = os.read(
|
297
|
+
agent.tty_sessions[tty_id]["master_fd"], 1024
|
298
|
+
)
|
292
299
|
if data:
|
293
300
|
output += data.decode()
|
294
301
|
else:
|
@@ -296,55 +303,51 @@ class VirtualTTYTool:
|
|
296
303
|
except BlockingIOError:
|
297
304
|
break
|
298
305
|
print(f"📤 终端 [{tty_id}]: {output}")
|
299
|
-
|
300
|
-
return {
|
301
|
-
|
302
|
-
"stdout": output,
|
303
|
-
"stderr": ""
|
304
|
-
}
|
305
|
-
|
306
|
+
|
307
|
+
return {"success": True, "stdout": output, "stderr": ""}
|
308
|
+
|
306
309
|
except Exception as e:
|
307
310
|
return {
|
308
311
|
"success": False,
|
309
312
|
"stdout": "",
|
310
|
-
"stderr": f"获取终端 [{tty_id}] 输出失败: {str(e)}"
|
313
|
+
"stderr": f"获取终端 [{tty_id}] 输出失败: {str(e)}",
|
311
314
|
}
|
312
|
-
|
315
|
+
|
313
316
|
def _close_tty(self, agent: Any, tty_id: str) -> Dict[str, Any]:
|
314
317
|
"""关闭虚拟终端"""
|
315
318
|
if agent.tty_sessions[tty_id]["master_fd"] is None:
|
316
319
|
return {
|
317
320
|
"success": True,
|
318
321
|
"stdout": f"没有正在运行的虚拟终端 [{tty_id}]",
|
319
|
-
"stderr": ""
|
322
|
+
"stderr": "",
|
320
323
|
}
|
321
|
-
|
324
|
+
|
322
325
|
try:
|
323
326
|
# 关闭主文件描述符
|
324
327
|
os.close(agent.tty_sessions[tty_id]["master_fd"])
|
325
|
-
|
328
|
+
|
326
329
|
# 终止子进程
|
327
330
|
if agent.tty_sessions[tty_id]["pid"]:
|
328
331
|
os.kill(agent.tty_sessions[tty_id]["pid"], signal.SIGTERM)
|
329
|
-
|
332
|
+
|
330
333
|
# 重置终端数据
|
331
334
|
agent.tty_sessions[tty_id] = {
|
332
335
|
"master_fd": None,
|
333
336
|
"pid": None,
|
334
|
-
"shell": "/bin/bash"
|
337
|
+
"shell": "/bin/bash",
|
335
338
|
}
|
336
|
-
|
339
|
+
|
337
340
|
return {
|
338
341
|
"success": True,
|
339
342
|
"stdout": f"虚拟终端 [{tty_id}] 已关闭",
|
340
|
-
"stderr": ""
|
343
|
+
"stderr": "",
|
341
344
|
}
|
342
|
-
|
345
|
+
|
343
346
|
except Exception as e:
|
344
347
|
return {
|
345
348
|
"success": False,
|
346
349
|
"stdout": "",
|
347
|
-
"stderr": f"关闭虚拟终端 [{tty_id}] 失败: {str(e)}"
|
350
|
+
"stderr": f"关闭虚拟终端 [{tty_id}] 失败: {str(e)}",
|
348
351
|
}
|
349
352
|
|
350
353
|
def _get_screen(self, agent: Any, tty_id: str) -> Dict[str, Any]:
|
@@ -353,71 +356,79 @@ class VirtualTTYTool:
|
|
353
356
|
return {
|
354
357
|
"success": False,
|
355
358
|
"stdout": "",
|
356
|
-
"stderr": f"虚拟终端 [{tty_id}] 未启动"
|
359
|
+
"stderr": f"虚拟终端 [{tty_id}] 未启动",
|
357
360
|
}
|
358
|
-
|
361
|
+
|
359
362
|
try:
|
360
363
|
# 发送控制序列获取屏幕内容
|
361
|
-
os.write(
|
362
|
-
|
364
|
+
os.write(
|
365
|
+
agent.tty_sessions[tty_id]["master_fd"],
|
366
|
+
b"\x1b[2J\x1b[H\x1b[999;999H\x1b[6n",
|
367
|
+
)
|
368
|
+
|
363
369
|
# 读取响应
|
364
370
|
output = ""
|
365
371
|
start_time = time.time()
|
366
372
|
while time.time() - start_time < 2.0: # 最多等待2秒
|
367
373
|
try:
|
368
|
-
r, _, _ = select.select(
|
374
|
+
r, _, _ = select.select(
|
375
|
+
[agent.tty_sessions[tty_id]["master_fd"]], [], [], 0.1
|
376
|
+
)
|
369
377
|
if r:
|
370
378
|
data = os.read(agent.tty_sessions[tty_id]["master_fd"], 1024)
|
371
379
|
if data:
|
372
380
|
output += data.decode()
|
373
381
|
except BlockingIOError:
|
374
382
|
continue
|
375
|
-
|
383
|
+
|
376
384
|
# 清理控制字符
|
377
|
-
output =
|
378
|
-
|
379
|
-
|
380
|
-
"
|
381
|
-
"
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
+
output = (
|
386
|
+
output.replace("\x1b[2J", "")
|
387
|
+
.replace("\x1b[H", "")
|
388
|
+
.replace("\x1b[999;999H", "")
|
389
|
+
.replace("\x1b[6n", "")
|
390
|
+
)
|
391
|
+
|
392
|
+
return {"success": True, "stdout": output.strip(), "stderr": ""}
|
393
|
+
|
385
394
|
except Exception as e:
|
386
395
|
return {
|
387
396
|
"success": False,
|
388
397
|
"stdout": "",
|
389
|
-
"stderr": f"获取终端 [{tty_id}] 屏幕内容失败: {str(e)}"
|
398
|
+
"stderr": f"获取终端 [{tty_id}] 屏幕内容失败: {str(e)}",
|
390
399
|
}
|
391
|
-
|
400
|
+
|
392
401
|
def _list_ttys(self, agent: Any) -> Dict[str, Any]:
|
393
402
|
"""列出所有虚拟终端"""
|
394
403
|
try:
|
395
404
|
active_ttys = []
|
396
|
-
|
405
|
+
|
397
406
|
for tty_id, tty_data in agent.tty_sessions.items():
|
398
407
|
status = "活动" if tty_data["master_fd"] is not None else "关闭"
|
399
|
-
active_ttys.append(
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
408
|
+
active_ttys.append(
|
409
|
+
{
|
410
|
+
"id": tty_id,
|
411
|
+
"status": status,
|
412
|
+
"pid": tty_data["pid"] if tty_data["pid"] else None,
|
413
|
+
"shell": tty_data["shell"],
|
414
|
+
}
|
415
|
+
)
|
416
|
+
|
406
417
|
# 格式化输出
|
407
418
|
output = "虚拟终端列表:\n"
|
408
419
|
for tty in active_ttys:
|
409
420
|
output += f"ID: {tty['id']}, 状态: {tty['status']}, PID: {tty['pid']}, Shell: {tty['shell']}\n"
|
410
|
-
|
421
|
+
|
411
422
|
return {
|
412
423
|
"success": True,
|
413
424
|
"stdout": output,
|
414
425
|
"stderr": "",
|
415
|
-
"tty_list": active_ttys # 返回原始数据,方便程序处理
|
426
|
+
"tty_list": active_ttys, # 返回原始数据,方便程序处理
|
416
427
|
}
|
417
|
-
|
428
|
+
|
418
429
|
except Exception as e:
|
419
430
|
return {
|
420
431
|
"success": False,
|
421
432
|
"stdout": "",
|
422
|
-
"stderr": f"获取虚拟终端列表失败: {str(e)}"
|
433
|
+
"stderr": f"获取虚拟终端列表失败: {str(e)}",
|
423
434
|
}
|
jarvis/jarvis_utils/__init__.py
CHANGED
@@ -27,7 +27,7 @@ arguments:
|
|
27
27
|
4. xxx问题的解决方案有哪些?
|
28
28
|
5. xxx概念的详细解释是什么?
|
29
29
|
""",
|
30
|
-
"description": "网页搜索"
|
30
|
+
"description": "网页搜索",
|
31
31
|
},
|
32
32
|
"Plan": {
|
33
33
|
"append": True,
|
@@ -63,25 +63,25 @@ code_plan工具将:
|
|
63
63
|
4. 评估修改影响范围
|
64
64
|
5. 生成可执行的开发计划
|
65
65
|
""",
|
66
|
-
"description": "生成代码修改计划"
|
66
|
+
"description": "生成代码修改计划",
|
67
67
|
},
|
68
68
|
"FindRelatedFiles": {
|
69
69
|
"append": False,
|
70
70
|
"template": f"""
|
71
71
|
请使用工具在当前目录下查找与以下功能相关的文件:
|
72
|
-
"""
|
72
|
+
""",
|
73
73
|
},
|
74
74
|
"Dev": {
|
75
75
|
"append": False,
|
76
76
|
"template": f"""
|
77
77
|
请调用create_code_agent开发以下需求:
|
78
|
-
"""
|
78
|
+
""",
|
79
79
|
},
|
80
80
|
"Fix": {
|
81
81
|
"append": False,
|
82
82
|
"template": f"""
|
83
83
|
请修复以下问题:
|
84
|
-
"""
|
84
|
+
""",
|
85
85
|
},
|
86
86
|
"Check": {
|
87
87
|
"append": True,
|
@@ -94,7 +94,7 @@ code_plan工具将:
|
|
94
94
|
3. 检查完成后应报告结果
|
95
95
|
4. 确保使用项目对应的静态检查工具
|
96
96
|
""",
|
97
|
-
"description": "执行静态代码检查"
|
97
|
+
"description": "执行静态代码检查",
|
98
98
|
},
|
99
99
|
"ToolHelp": {
|
100
100
|
"append": False,
|
@@ -182,6 +182,6 @@ arguments:
|
|
182
182
|
</common_errors>
|
183
183
|
</tool_system_guide>
|
184
184
|
""",
|
185
|
-
"description": "工具使用系统"
|
186
|
-
}
|
187
|
-
}
|
185
|
+
"description": "工具使用系统",
|
186
|
+
},
|
187
|
+
}
|