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.
Files changed (92) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +45 -41
  3. jarvis/jarvis_agent/builtin_input_handler.py +26 -4
  4. jarvis/jarvis_agent/jarvis.py +30 -19
  5. jarvis/jarvis_agent/main.py +20 -12
  6. jarvis/jarvis_agent/output_handler.py +7 -7
  7. jarvis/jarvis_agent/shell_input_handler.py +14 -11
  8. jarvis/jarvis_code_agent/code_agent.py +81 -79
  9. jarvis/jarvis_code_agent/lint.py +92 -105
  10. jarvis/jarvis_code_analysis/checklists/__init__.py +1 -1
  11. jarvis/jarvis_code_analysis/checklists/c_cpp.py +1 -1
  12. jarvis/jarvis_code_analysis/checklists/csharp.py +1 -1
  13. jarvis/jarvis_code_analysis/checklists/data_format.py +1 -1
  14. jarvis/jarvis_code_analysis/checklists/devops.py +1 -1
  15. jarvis/jarvis_code_analysis/checklists/docs.py +1 -1
  16. jarvis/jarvis_code_analysis/checklists/go.py +1 -1
  17. jarvis/jarvis_code_analysis/checklists/infrastructure.py +1 -1
  18. jarvis/jarvis_code_analysis/checklists/java.py +1 -1
  19. jarvis/jarvis_code_analysis/checklists/javascript.py +1 -1
  20. jarvis/jarvis_code_analysis/checklists/kotlin.py +1 -1
  21. jarvis/jarvis_code_analysis/checklists/loader.py +31 -29
  22. jarvis/jarvis_code_analysis/checklists/php.py +1 -1
  23. jarvis/jarvis_code_analysis/checklists/python.py +1 -1
  24. jarvis/jarvis_code_analysis/checklists/ruby.py +1 -1
  25. jarvis/jarvis_code_analysis/checklists/rust.py +1 -1
  26. jarvis/jarvis_code_analysis/checklists/shell.py +1 -1
  27. jarvis/jarvis_code_analysis/checklists/sql.py +1 -1
  28. jarvis/jarvis_code_analysis/checklists/swift.py +1 -1
  29. jarvis/jarvis_code_analysis/checklists/web.py +1 -1
  30. jarvis/jarvis_code_analysis/code_review.py +292 -190
  31. jarvis/jarvis_dev/main.py +73 -56
  32. jarvis/jarvis_git_details/main.py +29 -33
  33. jarvis/jarvis_git_squash/main.py +13 -11
  34. jarvis/jarvis_git_utils/git_commiter.py +15 -5
  35. jarvis/jarvis_mcp/__init__.py +8 -10
  36. jarvis/jarvis_mcp/sse_mcp_client.py +182 -205
  37. jarvis/jarvis_mcp/stdio_mcp_client.py +93 -120
  38. jarvis/jarvis_mcp/streamable_mcp_client.py +117 -142
  39. jarvis/jarvis_methodology/main.py +71 -39
  40. jarvis/jarvis_multi_agent/__init__.py +24 -16
  41. jarvis/jarvis_multi_agent/main.py +10 -4
  42. jarvis/jarvis_platform/__init__.py +1 -1
  43. jarvis/jarvis_platform/base.py +44 -18
  44. jarvis/jarvis_platform/human.py +15 -3
  45. jarvis/jarvis_platform/kimi.py +117 -81
  46. jarvis/jarvis_platform/openai.py +23 -28
  47. jarvis/jarvis_platform/registry.py +43 -29
  48. jarvis/jarvis_platform/tongyi.py +16 -10
  49. jarvis/jarvis_platform/yuanbao.py +197 -144
  50. jarvis/jarvis_platform_manager/main.py +4 -2
  51. jarvis/jarvis_smart_shell/main.py +35 -30
  52. jarvis/jarvis_tools/ask_user.py +8 -16
  53. jarvis/jarvis_tools/base.py +3 -2
  54. jarvis/jarvis_tools/chdir.py +7 -19
  55. jarvis/jarvis_tools/cli/main.py +14 -10
  56. jarvis/jarvis_tools/code_plan.py +10 -31
  57. jarvis/jarvis_tools/create_code_agent.py +6 -11
  58. jarvis/jarvis_tools/create_sub_agent.py +10 -22
  59. jarvis/jarvis_tools/edit_file.py +98 -76
  60. jarvis/jarvis_tools/execute_script.py +46 -46
  61. jarvis/jarvis_tools/file_analyzer.py +22 -34
  62. jarvis/jarvis_tools/file_operation.py +69 -62
  63. jarvis/jarvis_tools/generate_new_tool.py +0 -2
  64. jarvis/jarvis_tools/methodology.py +19 -23
  65. jarvis/jarvis_tools/read_code.py +35 -35
  66. jarvis/jarvis_tools/read_webpage.py +7 -16
  67. jarvis/jarvis_tools/registry.py +63 -30
  68. jarvis/jarvis_tools/rewrite_file.py +26 -29
  69. jarvis/jarvis_tools/search_web.py +5 -8
  70. jarvis/jarvis_tools/virtual_tty.py +133 -122
  71. jarvis/jarvis_utils/__init__.py +0 -1
  72. jarvis/jarvis_utils/builtin_replace_map.py +9 -9
  73. jarvis/jarvis_utils/config.py +60 -37
  74. jarvis/jarvis_utils/embedding.py +24 -19
  75. jarvis/jarvis_utils/file_processors.py +16 -9
  76. jarvis/jarvis_utils/git_utils.py +157 -107
  77. jarvis/jarvis_utils/globals.py +1 -1
  78. jarvis/jarvis_utils/input.py +85 -52
  79. jarvis/jarvis_utils/jarvis_history.py +43 -0
  80. jarvis/jarvis_utils/methodology.py +31 -24
  81. jarvis/jarvis_utils/output.py +164 -80
  82. jarvis/jarvis_utils/tag.py +2 -1
  83. jarvis/jarvis_utils/utils.py +84 -52
  84. {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/METADATA +362 -230
  85. jarvis_ai_assistant-0.1.195.dist-info/RECORD +98 -0
  86. jarvis/jarvis_agent/file_input_handler.py +0 -112
  87. jarvis/jarvis_event/__init__.py +0 -0
  88. jarvis_ai_assistant-0.1.193.dist-info/RECORD +0 -99
  89. {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/WHEEL +0 -0
  90. {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/entry_points.txt +0 -0
  91. {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/licenses/LICENSE +0 -0
  92. {jarvis_ai_assistant-0.1.193.dist-info → jarvis_ai_assistant-0.1.195.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
- import os
3
2
  from typing import Any, Dict
4
3
 
5
4
  from jarvis.jarvis_platform.registry import PlatformRegistry
@@ -12,26 +11,22 @@ class WebpageTool:
12
11
  parameters = {
13
12
  "type": "object",
14
13
  "properties": {
15
- "url": {
16
- "type": "string",
17
- "description": "要读取的网页URL"
18
- },
14
+ "url": {"type": "string", "description": "要读取的网页URL"},
19
15
  "want": {
20
16
  "type": "string",
21
17
  "description": "具体想要从网页获取的信息或回答的问题",
22
- "default": "请总结这个网页的主要内容"
23
- }
18
+ "default": "请总结这个网页的主要内容",
19
+ },
24
20
  },
25
- "required": ["url"]
21
+ "required": ["url"],
26
22
  }
27
23
 
28
-
29
24
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
30
25
  """Read webpage content using Yuanbao model"""
31
26
  try:
32
27
  url = args["url"].strip()
33
28
  want = args.get("want", "请总结这个网页的主要内容")
34
-
29
+
35
30
  # Create Yuanbao model instance
36
31
  model = PlatformRegistry().get_normal_platform()
37
32
  model.set_web(True)
@@ -48,18 +43,14 @@ class WebpageTool:
48
43
  # Get response from Yuanbao model
49
44
  response = model.chat_until_success(prompt) # type: ignore
50
45
 
51
- return {
52
- "success": True,
53
- "stdout": response,
54
- "stderr": ""
55
- }
46
+ return {"success": True, "stdout": response, "stderr": ""}
56
47
 
57
48
  except Exception as e:
58
49
  PrettyOutput.print(f"读取网页失败: {str(e)}", OutputType.ERROR)
59
50
  return {
60
51
  "success": False,
61
52
  "stdout": "",
62
- "stderr": f"Failed to parse webpage: {str(e)}"
53
+ "stderr": f"Failed to parse webpage: {str(e)}",
63
54
  }
64
55
 
65
56
  @staticmethod
@@ -7,14 +7,12 @@ import tempfile
7
7
  from pathlib import Path
8
8
  from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple
9
9
 
10
- from numpy import place
11
10
  import yaml
12
11
 
13
12
  from jarvis.jarvis_mcp import McpClient
14
13
  from jarvis.jarvis_mcp.sse_mcp_client import SSEMcpClient
15
14
  from jarvis.jarvis_mcp.stdio_mcp_client import StdioMcpClient
16
15
  from jarvis.jarvis_mcp.streamable_mcp_client import StreamableMcpClient
17
- from jarvis.jarvis_platform.registry import PlatformRegistry
18
16
  from jarvis.jarvis_tools.base import Tool
19
17
  from jarvis.jarvis_utils.config import get_data_dir
20
18
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
@@ -113,6 +111,7 @@ class OutputHandlerProtocol(Protocol):
113
111
  def prompt(self) -> str: ...
114
112
  def handle(self, response: str, agent: Any) -> Tuple[bool, Any]: ...
115
113
 
114
+
116
115
  class ToolRegistry(OutputHandlerProtocol):
117
116
 
118
117
  def name(self) -> str:
@@ -202,9 +201,7 @@ class ToolRegistry(OutputHandlerProtocol):
202
201
  with open(stats_file, "w", encoding="utf-8") as f:
203
202
  yaml.safe_dump(stats, f, allow_unicode=True)
204
203
  except Exception as e:
205
- PrettyOutput.print(
206
- f"保存工具调用统计失败: {str(e)}", OutputType.WARNING
207
- )
204
+ PrettyOutput.print(f"保存工具调用统计失败: {str(e)}", OutputType.WARNING)
208
205
 
209
206
  def use_tools(self, name: List[str]) -> None:
210
207
  """使用指定工具
@@ -218,7 +215,11 @@ class ToolRegistry(OutputHandlerProtocol):
218
215
  f"工具 {missing_tools} 不存在,可用的工具有: {', '.join(self.tools.keys())}",
219
216
  OutputType.WARNING,
220
217
  )
221
- self.tools = {tool_name: self.tools[tool_name] for tool_name in name if tool_name in self.tools}
218
+ self.tools = {
219
+ tool_name: self.tools[tool_name]
220
+ for tool_name in name
221
+ if tool_name in self.tools
222
+ }
222
223
 
223
224
  def dont_use_tools(self, names: List[str]) -> None:
224
225
  """从注册表中移除指定工具
@@ -233,7 +234,7 @@ class ToolRegistry(OutputHandlerProtocol):
233
234
  def _load_mcp_tools(self) -> None:
234
235
  """加载MCP工具,优先从配置获取,其次从目录扫描"""
235
236
  from jarvis.jarvis_utils.config import get_mcp_config
236
-
237
+
237
238
  # 优先从配置获取MCP工具配置
238
239
  mcp_configs = get_mcp_config()
239
240
  if mcp_configs:
@@ -249,7 +250,7 @@ class ToolRegistry(OutputHandlerProtocol):
249
250
  # 添加警告信息
250
251
  PrettyOutput.print(
251
252
  "警告: 从文件目录加载MCP工具的方式将在未来版本中废弃,请尽快迁移到JARVIS_MCP配置方式",
252
- OutputType.WARNING
253
+ OutputType.WARNING,
253
254
  )
254
255
 
255
256
  # 遍历目录中的所有.yaml文件
@@ -299,12 +300,17 @@ class ToolRegistry(OutputHandlerProtocol):
299
300
  """
300
301
  try:
301
302
  if "type" not in config:
302
- PrettyOutput.print(f"配置{config.get('name', '')}缺少type字段", OutputType.WARNING)
303
+ PrettyOutput.print(
304
+ f"配置{config.get('name', '')}缺少type字段", OutputType.WARNING
305
+ )
303
306
  return False
304
307
 
305
308
  # 检查enable标志
306
309
  if not config.get("enable", True):
307
- PrettyOutput.print(f"MCP配置{config.get('name', '')}已禁用(enable=false),跳过注册", OutputType.INFO)
310
+ PrettyOutput.print(
311
+ f"MCP配置{config.get('name', '')}已禁用(enable=false),跳过注册",
312
+ OutputType.INFO,
313
+ )
308
314
  return False
309
315
 
310
316
  name = config.get("name", "mcp")
@@ -317,7 +323,8 @@ class ToolRegistry(OutputHandlerProtocol):
317
323
  args.pop("want", None)
318
324
  ret = client.get_resource_list()
319
325
  PrettyOutput.print(
320
- f"MCP {name} 资源列表:\n{yaml.safe_dump(ret, allow_unicode=True)}", OutputType.TOOL
326
+ f"MCP {name} 资源列表:\n{yaml.safe_dump(ret, allow_unicode=True)}",
327
+ OutputType.TOOL,
321
328
  )
322
329
  return {
323
330
  "success": True,
@@ -340,7 +347,8 @@ class ToolRegistry(OutputHandlerProtocol):
340
347
  }
341
348
  ret = client.get_resource(args["uri"])
342
349
  PrettyOutput.print(
343
- f"MCP {name} 获取资源:\n{yaml.safe_dump(ret, allow_unicode=True)}", OutputType.TOOL
350
+ f"MCP {name} 获取资源:\n{yaml.safe_dump(ret, allow_unicode=True)}",
351
+ OutputType.TOOL,
344
352
  )
345
353
  return ret
346
354
 
@@ -362,18 +370,29 @@ class ToolRegistry(OutputHandlerProtocol):
362
370
 
363
371
  if config["type"] == "stdio":
364
372
  if "command" not in config:
365
- PrettyOutput.print(f"配置{config.get('name', '')}缺少command字段", OutputType.WARNING)
373
+ PrettyOutput.print(
374
+ f"配置{config.get('name', '')}缺少command字段",
375
+ OutputType.WARNING,
376
+ )
366
377
  return False
367
378
  elif config["type"] == "sse":
368
379
  if "base_url" not in config:
369
- PrettyOutput.print(f"配置{config.get('name', '')}缺少base_url字段", OutputType.WARNING)
380
+ PrettyOutput.print(
381
+ f"配置{config.get('name', '')}缺少base_url字段",
382
+ OutputType.WARNING,
383
+ )
370
384
  return False
371
385
  elif config["type"] == "streamable":
372
386
  if "base_url" not in config:
373
- PrettyOutput.print(f"配置{config.get('name', '')}缺少base_url字段", OutputType.WARNING)
387
+ PrettyOutput.print(
388
+ f"配置{config.get('name', '')}缺少base_url字段",
389
+ OutputType.WARNING,
390
+ )
374
391
  return False
375
392
  else:
376
- PrettyOutput.print(f"不支持的MCP客户端类型: {config['type']}", OutputType.WARNING)
393
+ PrettyOutput.print(
394
+ f"不支持的MCP客户端类型: {config['type']}", OutputType.WARNING
395
+ )
377
396
  return False
378
397
 
379
398
  # 创建MCP客户端
@@ -389,7 +408,10 @@ class ToolRegistry(OutputHandlerProtocol):
389
408
  # 获取工具信息
390
409
  tools = mcp_client.get_tool_list()
391
410
  if not tools:
392
- PrettyOutput.print(f"从配置{config.get('name', '')}获取工具列表失败", OutputType.WARNING)
411
+ PrettyOutput.print(
412
+ f"从配置{config.get('name', '')}获取工具列表失败",
413
+ OutputType.WARNING,
414
+ )
393
415
  return False
394
416
 
395
417
  # 注册每个工具
@@ -427,7 +449,9 @@ class ToolRegistry(OutputHandlerProtocol):
427
449
  return True
428
450
 
429
451
  except Exception as e:
430
- PrettyOutput.print(f"MCP配置{config.get('name', '')}加载失败: {str(e)}", OutputType.WARNING)
452
+ PrettyOutput.print(
453
+ f"MCP配置{config.get('name', '')}加载失败: {str(e)}", OutputType.WARNING
454
+ )
431
455
  return False
432
456
 
433
457
  def register_tool_by_file(self, file_path: str) -> bool:
@@ -604,10 +628,10 @@ class ToolRegistry(OutputHandlerProtocol):
604
628
  "stderr": f"工具 {name} 不存在,可用的工具有: {', '.join(self.tools.keys())}",
605
629
  "stdout": "",
606
630
  }
607
-
631
+
608
632
  # 更新工具调用统计
609
633
  self._update_tool_stats(name)
610
-
634
+
611
635
  return tool.execute(arguments)
612
636
 
613
637
  def _format_tool_output(self, stdout: str, stderr: str) -> str:
@@ -630,16 +654,18 @@ class ToolRegistry(OutputHandlerProtocol):
630
654
 
631
655
  def _truncate_output(self, output: str) -> str:
632
656
  """截断过长的输出内容
633
-
657
+
634
658
  参数:
635
659
  output: 要截断的输出内容
636
-
660
+
637
661
  返回:
638
662
  截断后的内容,如果内容不超过60行则返回原内容
639
663
  """
640
664
  if len(output.splitlines()) > 60:
641
665
  lines = output.splitlines()
642
- return '\n'.join(lines[:30] + ['\n...内容太长,已截取前后30行...\n'] + lines[-30:])
666
+ return "\n".join(
667
+ lines[:30] + ["\n...内容太长,已截取前后30行...\n"] + lines[-30:]
668
+ )
643
669
  return output
644
670
 
645
671
  def handle_tool_calls(self, tool_call: Dict[str, Any], agent: Any) -> str:
@@ -650,7 +676,8 @@ class ToolRegistry(OutputHandlerProtocol):
650
676
  args["agent"] = agent
651
677
 
652
678
  from jarvis.jarvis_agent import Agent
653
- agent_instance: Agent = agent
679
+
680
+ agent_instance: Agent = agent
654
681
 
655
682
  if isinstance(args, str):
656
683
  try:
@@ -671,19 +698,26 @@ class ToolRegistry(OutputHandlerProtocol):
671
698
 
672
699
  # 检查内容是否过大
673
700
  is_large_content = is_context_overflow(output)
674
-
701
+
675
702
  if is_large_content:
676
703
  # 创建临时文件
677
- with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as tmp_file:
704
+ with tempfile.NamedTemporaryFile(
705
+ mode="w", suffix=".txt", delete=False
706
+ ) as tmp_file:
678
707
  output_file = tmp_file.name
679
708
  tmp_file.write(output)
680
709
  tmp_file.flush()
681
-
710
+
682
711
  try:
683
- if agent_instance.model and agent_instance.model.support_upload_files():
712
+ if (
713
+ agent_instance.model
714
+ and agent_instance.model.support_upload_files()
715
+ ):
684
716
  summary = agent_instance.generate_summary()
685
717
  agent_instance.clear_history()
686
- upload_success = agent_instance.model.upload_files([output_file])
718
+ upload_success = agent_instance.model.upload_files(
719
+ [output_file]
720
+ )
687
721
  if upload_success:
688
722
  # 删除args的agent键
689
723
  args.pop("agent", None)
@@ -714,4 +748,3 @@ class ToolRegistry(OutputHandlerProtocol):
714
748
  except Exception as e:
715
749
  PrettyOutput.print(f"工具执行失败:{str(e)}", OutputType.ERROR)
716
750
  return f"工具调用失败: {str(e)}"
717
-
@@ -47,16 +47,13 @@ class FileRewriteTool:
47
47
  parameters = {
48
48
  "type": "object",
49
49
  "properties": {
50
- "file": {
51
- "type": "string",
52
- "description": "需要重写的文件路径"
53
- },
50
+ "file": {"type": "string", "description": "需要重写的文件路径"},
54
51
  "content": {
55
52
  "type": "string",
56
- "description": "新的文件内容,将完全替换原文件内容"
57
- }
53
+ "description": "新的文件内容,将完全替换原文件内容",
54
+ },
58
55
  },
59
- "required": ["file", "content"]
56
+ "required": ["file", "content"],
60
57
  }
61
58
 
62
59
  def __init__(self):
@@ -82,41 +79,41 @@ class FileRewriteTool:
82
79
  import os
83
80
 
84
81
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
85
-
82
+
86
83
  stdout_messages = []
87
84
  stderr_messages = []
88
85
  success = True
89
-
86
+
90
87
  file_path = args["file"]
91
88
  new_content = args["content"]
92
-
89
+
93
90
  # 创建已处理文件变量,用于失败时回滚
94
91
  original_content = None
95
92
  processed = False
96
93
 
97
94
  try:
98
95
  file_exists = os.path.exists(file_path)
99
-
96
+
100
97
  try:
101
98
  # 如果文件存在,则读取原内容用于回滚
102
99
  if file_exists:
103
- with open(file_path, 'r', encoding='utf-8') as f:
100
+ with open(file_path, "r", encoding="utf-8") as f:
104
101
  original_content = f.read()
105
-
102
+
106
103
  # 确保目录存在
107
104
  os.makedirs(os.path.dirname(os.path.abspath(file_path)), exist_ok=True)
108
-
105
+
109
106
  # 写入新内容
110
- with open(file_path, 'w', encoding='utf-8') as f:
107
+ with open(file_path, "w", encoding="utf-8") as f:
111
108
  f.write(new_content)
112
-
109
+
113
110
  processed = True
114
-
111
+
115
112
  action = "创建并写入" if not file_exists else "成功重写"
116
113
  stdout_message = f"文件 {file_path} {action}"
117
114
  stdout_messages.append(stdout_message)
118
115
  PrettyOutput.print(stdout_message, OutputType.SUCCESS)
119
-
116
+
120
117
  except Exception as e:
121
118
  stderr_message = f"处理文件 {file_path} 时出错: {str(e)}"
122
119
  stderr_messages.append(stderr_message)
@@ -128,7 +125,7 @@ class FileRewriteTool:
128
125
  rollback_message = "操作失败,正在回滚修改..."
129
126
  stderr_messages.append(rollback_message)
130
127
  PrettyOutput.print(rollback_message, OutputType.WARNING)
131
-
128
+
132
129
  try:
133
130
  if original_content is None:
134
131
  # 如果是新创建的文件,则删除
@@ -137,10 +134,10 @@ class FileRewriteTool:
137
134
  rollback_file_message = f"已删除新创建的文件: {file_path}"
138
135
  else:
139
136
  # 如果是修改的文件,则恢复原内容
140
- with open(file_path, 'w', encoding='utf-8') as f:
137
+ with open(file_path, "w", encoding="utf-8") as f:
141
138
  f.write(original_content)
142
139
  rollback_file_message = f"已回滚文件: {file_path}"
143
-
140
+
144
141
  stderr_messages.append(rollback_file_message)
145
142
  PrettyOutput.print(rollback_file_message, OutputType.INFO)
146
143
  except Exception as e:
@@ -151,19 +148,19 @@ class FileRewriteTool:
151
148
  return {
152
149
  "success": success,
153
150
  "stdout": "\n".join(stdout_messages),
154
- "stderr": "\n".join(stderr_messages)
151
+ "stderr": "\n".join(stderr_messages),
155
152
  }
156
-
153
+
157
154
  except Exception as e:
158
155
  error_msg = f"文件重写操作失败: {str(e)}"
159
156
  PrettyOutput.print(error_msg, OutputType.WARNING)
160
-
157
+
161
158
  # 如果有已修改的文件,尝试回滚
162
159
  if processed:
163
160
  rollback_message = "操作失败,正在回滚修改..."
164
161
  stderr_messages.append(rollback_message)
165
162
  PrettyOutput.print(rollback_message, OutputType.WARNING)
166
-
163
+
167
164
  try:
168
165
  if original_content is None:
169
166
  # 如果是新创建的文件,则删除
@@ -172,14 +169,14 @@ class FileRewriteTool:
172
169
  stderr_messages.append(f"已删除新创建的文件: {file_path}")
173
170
  else:
174
171
  # 如果是修改的文件,则恢复原内容
175
- with open(file_path, 'w', encoding='utf-8') as f:
172
+ with open(file_path, "w", encoding="utf-8") as f:
176
173
  f.write(original_content)
177
174
  stderr_messages.append(f"已回滚文件: {file_path}")
178
175
  except:
179
176
  stderr_messages.append(f"回滚文件失败: {file_path}")
180
-
177
+
181
178
  return {
182
179
  "success": False,
183
180
  "stdout": "",
184
- "stderr": error_msg + "\n" + "\n".join(stderr_messages)
185
- }
181
+ "stderr": error_msg + "\n" + "\n".join(stderr_messages),
182
+ }
@@ -1,5 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
- import os
3
2
  from typing import Any, Dict
4
3
 
5
4
  from jarvis.jarvis_platform.registry import PlatformRegistry
@@ -10,18 +9,16 @@ class SearchWebTool:
10
9
  description = "搜索互联网上的信息"
11
10
  parameters = {
12
11
  "type": "object",
13
- "properties": {
14
- "query": {"type": "string", "description": "具体的问题"}
15
- }
12
+ "properties": {"query": {"type": "string", "description": "具体的问题"}},
16
13
  }
17
14
 
18
- def execute(self, args: Dict[str, Any]) -> Dict[str, Any]: # type: ignore
15
+ def execute(self, args: Dict[str, Any]) -> Dict[str, Any]: # type: ignore
19
16
  query = args.get("query")
20
17
  model = PlatformRegistry().get_normal_platform()
21
18
  model.set_web(True)
22
- model.set_suppress_output(False) # type: ignore
19
+ model.set_suppress_output(False) # type: ignore
23
20
  return {
24
- "stdout": model.chat_until_success(query), # type: ignore
21
+ "stdout": model.chat_until_success(query), # type: ignore
25
22
  "stderr": "",
26
23
  "success": True,
27
24
  }
@@ -29,4 +26,4 @@ class SearchWebTool:
29
26
  @staticmethod
30
27
  def check() -> bool:
31
28
  """检查当前平台是否支持web功能"""
32
- return PlatformRegistry().get_normal_platform().support_web()
29
+ return PlatformRegistry().get_normal_platform().support_web()