jarvis-ai-assistant 0.1.124__py3-none-any.whl → 0.1.125__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 (66) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +18 -20
  3. jarvis/jarvis_code_agent/code_agent.py +195 -45
  4. jarvis/jarvis_code_agent/file_select.py +6 -19
  5. jarvis/jarvis_code_agent/patch.py +189 -310
  6. jarvis/jarvis_codebase/main.py +6 -2
  7. jarvis/jarvis_dev/main.py +6 -4
  8. jarvis/jarvis_git_squash/__init__.py +0 -0
  9. jarvis/jarvis_git_squash/main.py +81 -0
  10. jarvis/jarvis_lsp/cpp.py +1 -1
  11. jarvis/jarvis_lsp/go.py +1 -1
  12. jarvis/jarvis_lsp/registry.py +2 -2
  13. jarvis/jarvis_lsp/rust.py +1 -1
  14. jarvis/jarvis_multi_agent/__init__.py +1 -1
  15. jarvis/jarvis_platform/ai8.py +2 -1
  16. jarvis/jarvis_platform/base.py +19 -24
  17. jarvis/jarvis_platform/kimi.py +2 -3
  18. jarvis/jarvis_platform/ollama.py +3 -1
  19. jarvis/jarvis_platform/openai.py +1 -1
  20. jarvis/jarvis_platform/oyi.py +2 -1
  21. jarvis/jarvis_platform/registry.py +2 -1
  22. jarvis/jarvis_platform_manager/main.py +4 -6
  23. jarvis/jarvis_platform_manager/openai_test.py +0 -1
  24. jarvis/jarvis_rag/main.py +5 -2
  25. jarvis/jarvis_smart_shell/main.py +9 -4
  26. jarvis/jarvis_tools/ask_codebase.py +12 -7
  27. jarvis/jarvis_tools/ask_user.py +3 -2
  28. jarvis/jarvis_tools/base.py +21 -7
  29. jarvis/jarvis_tools/chdir.py +0 -1
  30. jarvis/jarvis_tools/code_review.py +13 -14
  31. jarvis/jarvis_tools/create_code_agent.py +2 -2
  32. jarvis/jarvis_tools/create_sub_agent.py +2 -2
  33. jarvis/jarvis_tools/execute_shell.py +3 -1
  34. jarvis/jarvis_tools/execute_shell_script.py +4 -4
  35. jarvis/jarvis_tools/file_operation.py +3 -2
  36. jarvis/jarvis_tools/git_commiter.py +5 -2
  37. jarvis/jarvis_tools/lsp_find_definition.py +1 -1
  38. jarvis/jarvis_tools/lsp_find_references.py +1 -1
  39. jarvis/jarvis_tools/lsp_get_diagnostics.py +19 -11
  40. jarvis/jarvis_tools/lsp_get_document_symbols.py +1 -1
  41. jarvis/jarvis_tools/lsp_prepare_rename.py +1 -1
  42. jarvis/jarvis_tools/lsp_validate_edit.py +1 -1
  43. jarvis/jarvis_tools/methodology.py +4 -1
  44. jarvis/jarvis_tools/rag.py +22 -15
  45. jarvis/jarvis_tools/read_code.py +4 -3
  46. jarvis/jarvis_tools/read_webpage.py +2 -1
  47. jarvis/jarvis_tools/registry.py +4 -1
  48. jarvis/jarvis_tools/{search.py → search_web.py} +5 -2
  49. jarvis/jarvis_tools/select_code_files.py +1 -1
  50. jarvis/jarvis_utils/__init__.py +19 -982
  51. jarvis/jarvis_utils/config.py +138 -0
  52. jarvis/jarvis_utils/embedding.py +201 -0
  53. jarvis/jarvis_utils/git_utils.py +120 -0
  54. jarvis/jarvis_utils/globals.py +82 -0
  55. jarvis/jarvis_utils/input.py +161 -0
  56. jarvis/jarvis_utils/methodology.py +128 -0
  57. jarvis/jarvis_utils/output.py +235 -0
  58. jarvis/jarvis_utils/utils.py +150 -0
  59. jarvis_ai_assistant-0.1.125.dist-info/METADATA +291 -0
  60. jarvis_ai_assistant-0.1.125.dist-info/RECORD +75 -0
  61. {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/entry_points.txt +1 -0
  62. jarvis_ai_assistant-0.1.124.dist-info/METADATA +0 -460
  63. jarvis_ai_assistant-0.1.124.dist-info/RECORD +0 -65
  64. {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/LICENSE +0 -0
  65. {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/WHEEL +0 -0
  66. {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,81 @@
1
+ import sys
2
+ import argparse
3
+ from typing import Dict, Any
4
+ from jarvis.jarvis_tools.git_commiter import GitCommitTool
5
+ import subprocess
6
+
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
+ from jarvis.jarvis_utils.utils import init_env, user_confirm
9
+ class GitSquashTool:
10
+ name = "git_squash_agent"
11
+ description = "Squash commits interactively using a base commit hash"
12
+
13
+ def _confirm_squash(self) -> bool:
14
+ """Prompt user for confirmation to squash commits"""
15
+ return user_confirm("是否确认压缩提交?", default=True)
16
+
17
+ def _reset_to_commit(self, commit_hash: str) -> bool:
18
+ """Perform soft reset to specified commit hash"""
19
+ try:
20
+ subprocess.Popen(
21
+ ["git", "reset", "--soft", commit_hash],
22
+ stdout=subprocess.DEVNULL,
23
+ stderr=subprocess.DEVNULL
24
+ ).wait()
25
+ return True
26
+ except Exception:
27
+ return False
28
+
29
+ def execute(self, args: Dict) -> Dict[str, Any]:
30
+ """Execute the squash operation"""
31
+ try:
32
+ if not self._confirm_squash():
33
+ return {
34
+ "success": False,
35
+ "stdout": "Operation cancelled",
36
+ "stderr": ""
37
+ }
38
+
39
+ if not self._reset_to_commit(args['commit_hash']):
40
+ return {
41
+ "success": False,
42
+ "stdout": "",
43
+ "stderr": "Failed to reset to specified commit"
44
+ }
45
+
46
+ # Use existing GitCommitTool for new commit
47
+ commit_tool = GitCommitTool()
48
+ result = commit_tool.execute({"lang": args.get('lang', 'Chinese')})
49
+
50
+ return {
51
+ "success": result['success'],
52
+ "stdout": result['stdout'],
53
+ "stderr": result['stderr']
54
+ }
55
+
56
+ except Exception as e:
57
+ return {
58
+ "success": False,
59
+ "stdout": "",
60
+ "stderr": f"Squash failed: {str(e)}"
61
+ }
62
+ def main():
63
+ init_env()
64
+ parser = argparse.ArgumentParser(description='Git squash tool')
65
+ parser.add_argument('commit_hash', type=str, help='Base commit hash to squash from')
66
+ parser.add_argument('--lang', type=str, default='Chinese', help='Language for commit messages')
67
+ args = parser.parse_args()
68
+
69
+ tool = GitSquashTool()
70
+ result = tool.execute({
71
+ 'commit_hash': args.commit_hash,
72
+ 'lang': args.lang
73
+ })
74
+
75
+ if not result['success']:
76
+ PrettyOutput.print(result['stderr'], OutputType.ERROR)
77
+ sys.exit(1)
78
+
79
+ PrettyOutput.print(result['stdout'], OutputType.SUCCESS)
80
+ if __name__ == "__main__":
81
+ sys.exit(main())
jarvis/jarvis_lsp/cpp.py CHANGED
@@ -4,7 +4,7 @@ import subprocess
4
4
  from typing import List, Dict, Optional, Tuple, Any
5
5
  import json
6
6
  from jarvis.jarvis_lsp.base import BaseLSP
7
- from jarvis.jarvis_utils import PrettyOutput, OutputType
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
8
 
9
9
  class CPPLSP(BaseLSP):
10
10
  """C++ LSP implementation using clangd."""
jarvis/jarvis_lsp/go.py CHANGED
@@ -4,7 +4,7 @@ import subprocess
4
4
  from typing import List, Dict, Optional, Tuple, Any
5
5
  import json
6
6
  from jarvis.jarvis_lsp.base import BaseLSP
7
- from jarvis.jarvis_utils import PrettyOutput, OutputType
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
8
 
9
9
  class GoLSP(BaseLSP):
10
10
  """Go LSP implementation using gopls."""
@@ -5,7 +5,7 @@ import re
5
5
  import sys
6
6
  from typing import Dict, Type, Optional, List
7
7
  from jarvis.jarvis_lsp.base import BaseLSP
8
- from jarvis.jarvis_utils import PrettyOutput, OutputType
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
9
 
10
10
  REQUIRED_METHODS = [
11
11
  ('initialize', ['workspace_path']),
@@ -189,7 +189,7 @@ def main():
189
189
  PrettyOutput.print(f"没有 LSP 支持的语言: {args.language}", OutputType.WARNING)
190
190
  return 1
191
191
 
192
- if not lsp.initialize(os.path.dirname(os.path.abspath(args.file))):
192
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
193
193
  PrettyOutput.print("LSP 初始化失败", OutputType.WARNING)
194
194
  return 1
195
195
 
jarvis/jarvis_lsp/rust.py CHANGED
@@ -4,7 +4,7 @@ import subprocess
4
4
  from typing import List, Dict, Optional, Tuple, Any
5
5
  import json
6
6
  from jarvis.jarvis_lsp.base import BaseLSP
7
- from jarvis.jarvis_utils import PrettyOutput, OutputType
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
8
 
9
9
  class RustLSP(BaseLSP):
10
10
  """Rust LSP implementation using rust-analyzer."""
@@ -5,7 +5,7 @@ import yaml
5
5
 
6
6
  from jarvis.jarvis_agent import Agent
7
7
  from jarvis.jarvis_agent.output_handler import OutputHandler
8
- from jarvis.jarvis_utils import OutputType, PrettyOutput
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
9
 
10
10
 
11
11
  class AgentConfig:
@@ -1,11 +1,12 @@
1
1
  import os
2
2
  from typing import Dict, List, Tuple
3
3
  from jarvis.jarvis_platform.base import BasePlatform
4
- from jarvis.jarvis_utils import PrettyOutput, OutputType
5
4
  import requests
6
5
  import json
7
6
  import base64
8
7
 
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
+
9
10
  class AI8Model(BasePlatform):
10
11
  """AI8 model implementation"""
11
12
 
@@ -1,10 +1,8 @@
1
1
  from abc import ABC, abstractmethod
2
2
  import re
3
3
  from typing import Dict, List, Tuple
4
-
5
- from jarvis.jarvis_utils import OutputType, PrettyOutput, while_success, while_true
6
- from yaspin import yaspin
7
- from yaspin.spinners import Spinners
4
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
5
+ from jarvis.jarvis_utils.utils import get_context_token_count, while_success, while_true
8
6
 
9
7
 
10
8
  class BasePlatform(ABC):
@@ -34,27 +32,24 @@ class BasePlatform(ABC):
34
32
  start_time = time.time()
35
33
  response = self.chat(message)
36
34
 
37
- # Calculate statistics
38
- if not self.suppress_output:
39
- end_time = time.time()
40
- duration = end_time - start_time
41
- char_count = len(response)
42
-
43
- # Calculate token count and tokens per second
44
- try:
45
- from jarvis.jarvis_utils import get_context_token_count
46
- token_count = get_context_token_count(response)
47
- tokens_per_second = token_count / duration if duration > 0 else 0
48
- except Exception as e:
49
- PrettyOutput.print(f"Tokenization failed: {str(e)}", OutputType.WARNING)
50
- token_count = 0
51
- tokens_per_second = 0
35
+ end_time = time.time()
36
+ duration = end_time - start_time
37
+ char_count = len(response)
38
+
39
+ # Calculate token count and tokens per second
40
+ try:
41
+ token_count = get_context_token_count(response)
42
+ tokens_per_second = token_count / duration if duration > 0 else 0
43
+ except Exception as e:
44
+ PrettyOutput.print(f"Tokenization failed: {str(e)}", OutputType.WARNING)
45
+ token_count = 0
46
+ tokens_per_second = 0
52
47
 
53
- # Print statistics
54
- PrettyOutput.print(
55
- f"对话完成 - 耗时: {duration:.2f}秒, 输出字符数: {char_count}, 输出Token数量: {token_count}, 每秒Token数量: {tokens_per_second:.2f}",
56
- OutputType.INFO,
57
- )
48
+ # Print statistics
49
+ PrettyOutput.print(
50
+ f"对话完成 - 耗时: {duration:.2f}秒, 输出字符数: {char_count}, 输出Token数量: {token_count}, 每秒Token数量: {tokens_per_second:.2f}",
51
+ OutputType.INFO,
52
+ )
58
53
 
59
54
  # Keep original think tag handling
60
55
  response = re.sub(r'<think>.*?</think>', '', response, flags=re.DOTALL)
@@ -5,9 +5,8 @@ import os
5
5
  import mimetypes
6
6
  import time
7
7
  from jarvis.jarvis_platform.base import BasePlatform
8
- from jarvis.jarvis_utils import PrettyOutput, OutputType
9
- from jarvis.jarvis_utils import while_success
10
-
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
+ from jarvis.jarvis_utils.utils import while_success
11
10
  class KimiModel(BasePlatform):
12
11
  """Kimi model implementation"""
13
12
 
@@ -1,10 +1,12 @@
1
1
  import requests
2
2
  from typing import List, Dict, Tuple
3
3
  from jarvis.jarvis_platform.base import BasePlatform
4
- from jarvis.jarvis_utils import OutputType, PrettyOutput, get_single_line_input
5
4
  import os
6
5
  import json
7
6
 
7
+ from jarvis.jarvis_utils.input import get_single_line_input
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
+
8
10
  class OllamaPlatform(BasePlatform):
9
11
  """Ollama platform implementation"""
10
12
 
@@ -2,7 +2,7 @@ from typing import Dict, List, Tuple
2
2
  import os
3
3
  from openai import OpenAI
4
4
  from jarvis.jarvis_platform.base import BasePlatform
5
- from jarvis.jarvis_utils import PrettyOutput, OutputType
5
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
6
6
 
7
7
  class OpenAIModel(BasePlatform):
8
8
  platform_name = "openai"
@@ -2,10 +2,11 @@ import mimetypes
2
2
  import os
3
3
  from typing import Dict, List, Tuple
4
4
  from jarvis.jarvis_platform.base import BasePlatform
5
- from jarvis.jarvis_utils import PrettyOutput, OutputType
6
5
  import requests
7
6
  import json
8
7
 
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
+
9
10
  class OyiModel(BasePlatform):
10
11
  """Oyi model implementation"""
11
12
 
@@ -4,7 +4,8 @@ import os
4
4
  import sys
5
5
  from typing import Dict, Type, Optional, List
6
6
  from jarvis.jarvis_platform.base import BasePlatform
7
- from jarvis.jarvis_utils import PrettyOutput, OutputType, get_cheap_model_name, get_cheap_platform_name, get_codegen_model_name, get_codegen_platform_name, get_normal_model_name, get_normal_platform_name, get_thinking_model_name, get_thinking_platform_name
7
+ from jarvis.jarvis_utils.config import get_cheap_model_name, get_cheap_platform_name, get_codegen_model_name, get_codegen_platform_name, get_normal_model_name, get_normal_platform_name, get_thinking_model_name, get_thinking_platform_name
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
9
 
9
10
  REQUIRED_METHODS = [
10
11
  ('chat', ['message']), # 方法名和参数列表
@@ -1,18 +1,16 @@
1
1
  from jarvis.jarvis_platform.registry import PlatformRegistry
2
- from jarvis.jarvis_utils import PrettyOutput, OutputType, init_env, get_multiline_input
3
2
  import asyncio
4
3
  from fastapi import FastAPI, HTTPException
5
4
  from fastapi.responses import StreamingResponse
6
5
  from pydantic import BaseModel, Field
7
6
  from typing import List, Dict, Any, Optional
8
7
  import uvicorn
9
- import io
10
- from contextlib import redirect_stdout
11
- import json
12
- import os
13
- from datetime import datetime
14
8
  from fastapi.middleware.cors import CORSMiddleware
15
9
 
10
+ from jarvis.jarvis_utils.input import get_multiline_input
11
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
12
+ from jarvis.jarvis_utils.utils import init_env
13
+
16
14
  def list_platforms():
17
15
  """List all supported platforms and models"""
18
16
  registry = PlatformRegistry.get_global_platform_registry()
@@ -4,7 +4,6 @@ Test script for Jarvis OpenAI-compatible API service.
4
4
  """
5
5
 
6
6
  import argparse
7
- import os
8
7
  import sys
9
8
  from openai import OpenAI
10
9
 
jarvis/jarvis_rag/main.py CHANGED
@@ -3,8 +3,6 @@ import numpy as np
3
3
  import faiss
4
4
  from typing import List, Tuple, Optional, Dict
5
5
  import pickle
6
- from jarvis.jarvis_utils import OutputType, PrettyOutput, get_context_token_count, get_embedding, get_embedding_batch, get_file_md5, get_max_token_count, get_max_paragraph_length, get_min_paragraph_length, get_thread_count, init_gpu_config, load_embedding_model
7
- from jarvis.jarvis_utils import init_env
8
6
  from dataclasses import dataclass
9
7
  from tqdm import tqdm
10
8
  import fitz # PyMuPDF for PDF files
@@ -15,6 +13,11 @@ import lzma # 添加 lzma 导入
15
13
  from threading import Lock
16
14
  import hashlib
17
15
 
16
+ from jarvis.jarvis_utils.config import get_max_paragraph_length, get_max_token_count, get_min_paragraph_length, get_thread_count
17
+ from jarvis.jarvis_utils.embedding import get_context_token_count, get_embedding, get_embedding_batch, load_embedding_model
18
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
19
+ from jarvis.jarvis_utils.utils import get_file_md5, init_env, init_gpu_config
20
+
18
21
  @dataclass
19
22
  class Document:
20
23
  """Document class, for storing document content and metadata"""
@@ -4,11 +4,14 @@ import os
4
4
  import sys
5
5
  import readline
6
6
  from typing import Optional
7
- from yaspin import yaspin # type: ignore
8
- from yaspin.spinners import Spinners # type: ignore
7
+
8
+ from yaspin import yaspin
9
9
 
10
10
  from jarvis.jarvis_platform.registry import PlatformRegistry
11
- from jarvis.jarvis_utils import PrettyOutput, OutputType, get_multiline_input, get_shell_name, init_env
11
+ from jarvis.jarvis_utils.config import get_shell_name
12
+ from jarvis.jarvis_utils.input import get_multiline_input
13
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
14
+ from jarvis.jarvis_utils.utils import init_env
12
15
 
13
16
  def execute_command(command: str) -> None:
14
17
  """Show command and allow user to edit, then execute, Ctrl+C to cancel"""
@@ -95,7 +98,9 @@ Output: find . -name "*.py"
95
98
  prefix = f"Current path: {current_path}\n"
96
99
  prefix += f"Current shell: {shell}\n"
97
100
 
98
- result = model.chat_until_success(prefix + request)
101
+ with yaspin(text="正在生成命令...", color="cyan") as spinner:
102
+ result = model.chat_until_success(prefix + request)
103
+ spinner.ok("✅ 命令生成成功")
99
104
 
100
105
  # 提取命令
101
106
  if result and isinstance(result, str):
@@ -1,6 +1,8 @@
1
1
  from typing import Dict, Any
2
- from jarvis.jarvis_utils import OutputType, PrettyOutput, dont_use_local_model, find_git_root
3
2
  from jarvis.jarvis_codebase.main import CodeBase
3
+ from jarvis.jarvis_utils.config import dont_use_local_model
4
+ from jarvis.jarvis_utils.git_utils import find_git_root
5
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
4
6
 
5
7
  class AskCodebaseTool:
6
8
  """Tool for intelligent codebase querying and analysis using CodeBase"""
@@ -52,14 +54,20 @@ class AskCodebaseTool:
52
54
  codebase = CodeBase(git_root)
53
55
 
54
56
  # Use ask_codebase method
55
- _, response = codebase.ask_codebase(question, top_k)
56
-
57
+ files, response = codebase.ask_codebase(question, top_k)
58
+
59
+ # Print found files
60
+ if files:
61
+ output = "找到的相关文件:\n"
62
+ for file in files:
63
+ output += f"- {file['file']} ({file['reason']})\n"
64
+ PrettyOutput.print(output, OutputType.INFO, lang="markdown")
65
+
57
66
  return {
58
67
  "success": True,
59
68
  "stdout": response,
60
69
  "stderr": ""
61
70
  }
62
-
63
71
  except Exception as e:
64
72
  error_msg = f"分析代码库失败: {str(e)}"
65
73
  PrettyOutput.print(error_msg, OutputType.WARNING)
@@ -68,8 +76,6 @@ class AskCodebaseTool:
68
76
  "stdout": "",
69
77
  "stderr": error_msg
70
78
  }
71
-
72
-
73
79
  def main():
74
80
  """Command line interface for the tool"""
75
81
  import argparse
@@ -79,7 +85,6 @@ def main():
79
85
  parser.add_argument('--top-k', type=int, help='Number of files to analyze', default=20)
80
86
 
81
87
  args = parser.parse_args()
82
-
83
88
  tool = AskCodebaseTool()
84
89
  result = tool.execute({
85
90
  "question": args.question,
@@ -1,6 +1,7 @@
1
1
  from typing import Dict, Any
2
- from jarvis.jarvis_tools.base import Tool
3
- from jarvis.jarvis_utils import get_multiline_input, PrettyOutput, OutputType
2
+
3
+ from jarvis.jarvis_utils.input import get_multiline_input
4
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
4
5
 
5
6
  class AskUserTool:
6
7
  name="ask_user"
@@ -1,23 +1,37 @@
1
1
  from typing import Dict, Any, Callable
2
2
  import json
3
-
4
-
5
-
6
3
  class Tool:
4
+ """工具类,用于封装工具的基本信息和执行方法"""
5
+
7
6
  def __init__(self, name: str, description: str, parameters: Dict, func: Callable):
7
+ """
8
+ 初始化工具对象
9
+
10
+ Args:
11
+ name (str): 工具名称
12
+ description (str): 工具描述
13
+ parameters (Dict): 工具参数定义
14
+ func (Callable): 工具执行函数
15
+ """
8
16
  self.name = name
9
17
  self.description = description
10
18
  self.parameters = parameters
11
19
  self.func = func
12
-
13
20
  def to_dict(self) -> Dict:
14
- """Convert to tool format"""
21
+ """将工具对象转换为字典格式,主要用于序列化"""
15
22
  return {
16
23
  "name": self.name,
17
24
  "description": self.description,
18
25
  "parameters": json.dumps(self.parameters, ensure_ascii=False)
19
26
  }
20
-
21
27
  def execute(self, arguments: Dict) -> Dict[str, Any]:
22
- """Execute tool function"""
28
+ """
29
+ 执行工具函数
30
+
31
+ Args:
32
+ arguments (Dict): 工具执行所需的参数
33
+
34
+ Returns:
35
+ Dict[str, Any]: 工具执行结果
36
+ """
23
37
  return self.func(arguments)
@@ -1,6 +1,5 @@
1
1
  from typing import Dict, Any
2
2
  import os
3
- from jarvis.jarvis_utils import PrettyOutput, OutputType
4
3
 
5
4
  class ChdirTool:
6
5
  name = "chdir"
@@ -1,12 +1,13 @@
1
- from typing import Dict, Any, List
1
+ from typing import Dict, Any
2
2
  import subprocess
3
- import yaml
4
3
  from jarvis.jarvis_platform.registry import PlatformRegistry
5
4
  from jarvis.jarvis_tools.registry import ToolRegistry
6
- from jarvis.jarvis_utils import OutputType, PrettyOutput, init_env, find_git_root
7
5
  from jarvis.jarvis_agent import Agent
8
6
  import re
9
7
 
8
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
+ from jarvis.jarvis_utils.utils import init_env
10
+
10
11
  class CodeReviewTool:
11
12
  name = "code_review"
12
13
  description = "Autonomous code review agent for code changes analysis"
@@ -35,10 +36,6 @@ class CodeReviewTool:
35
36
  "required": []
36
37
  }
37
38
 
38
- def __init__(self):
39
- init_env()
40
- self.repo_root = find_git_root()
41
-
42
39
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
43
40
  try:
44
41
  review_type = args.get("review_type", "current").strip()
@@ -170,13 +167,13 @@ PROPOSED DEFENSE:
170
167
  agent = Agent(
171
168
  system_prompt=system_prompt,
172
169
  name="Code Review Agent",
173
- summary_prompt="""Please generate a concise summary report of the code review, format as yaml:
170
+ summary_prompt="""Please generate a concise summary report of the code review in Chinese, format as follows:
174
171
  <REPORT>
175
- - file: xxxx.py
176
- location: [start_line_number, end_line_number]
177
- description: # Only describe issues directly observable in the diff
178
- severity: # Critical/Major/Minor based on concrete evidence
179
- suggestion: # Specific, actionable improvements for the observed code
172
+ - 文件: xxxx.py
173
+ 位置: [起始行号, 结束行号]
174
+ 描述: # 仅描述在差异中直接观察到的问题
175
+ 严重程度: # 根据具体证据分为严重/重要/次要
176
+ 建议: # 针对观察到的代码的具体改进建议
180
177
  </REPORT>""",
181
178
  is_sub_agent=True,
182
179
  output_handler=[tool_registry],
@@ -207,6 +204,8 @@ def extract_code_report(result: str) -> str:
207
204
  def main():
208
205
  """CLI entry point"""
209
206
  import argparse
207
+
208
+ init_env()
210
209
 
211
210
  parser = argparse.ArgumentParser(description='Autonomous code review tool')
212
211
  parser.add_argument('--type', choices=['commit', 'current', 'range'], default='current',
@@ -236,7 +235,7 @@ def main():
236
235
  result = tool.execute(tool_args)
237
236
 
238
237
  if result["success"]:
239
- PrettyOutput.section("Autonomous Review Result:", OutputType.SUCCESS)
238
+ PrettyOutput.section("自动代码审查结果:", OutputType.SUCCESS)
240
239
  report = extract_code_report(result["stdout"])
241
240
  PrettyOutput.print(report, OutputType.SUCCESS, lang="yaml")
242
241
 
@@ -1,9 +1,9 @@
1
- import os
2
1
  from typing import Dict, Any
3
2
  from jarvis.jarvis_code_agent.code_agent import CodeAgent
4
3
  from jarvis.jarvis_tools.git_commiter import GitCommitTool
5
4
  from jarvis.jarvis_tools.code_review import CodeReviewTool, extract_code_report
6
- from jarvis.jarvis_utils import OutputType, PrettyOutput, has_uncommitted_changes, get_latest_commit_hash
5
+ from jarvis.jarvis_utils.git_utils import get_latest_commit_hash, has_uncommitted_changes
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
7
 
8
8
  class CreateCodeAgentTool:
9
9
  """Tool for managing the code development workflow."""
@@ -2,8 +2,8 @@ from typing import Dict, Any
2
2
 
3
3
 
4
4
  from jarvis.jarvis_agent import Agent, origin_agent_system_prompt
5
- from jarvis.jarvis_tools.registry import ToolRegistry
6
- from jarvis.jarvis_utils import OutputType, PrettyOutput
5
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
6
+
7
7
 
8
8
 
9
9
  class SubAgentTool:
@@ -3,7 +3,9 @@ import os
3
3
  import tempfile
4
4
  from pathlib import Path
5
5
 
6
- from jarvis.jarvis_utils import OutputType, PrettyOutput
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
+
8
+
7
9
 
8
10
 
9
11
  class ShellTool:
@@ -2,7 +2,9 @@ from typing import Dict, Any
2
2
  import os
3
3
  import tempfile
4
4
  from pathlib import Path
5
- from jarvis.jarvis_utils import OutputType, PrettyOutput
5
+
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
+
6
8
 
7
9
  class ShellScriptTool:
8
10
  name = "execute_shell_script"
@@ -33,12 +35,10 @@ class ShellScriptTool:
33
35
  try:
34
36
  with open(script_path, 'w', encoding='utf-8') as f:
35
37
  f.write(script_content)
36
- os.chmod(script_path, 0o755) # Make script executable
37
-
38
38
  # Use execute_shell to run the script
39
39
  from jarvis.jarvis_tools.execute_shell import ShellTool
40
40
  shell_tool = ShellTool()
41
- result = shell_tool.execute({"command": script_path})
41
+ result = shell_tool.execute({"command": f"bash {script_path}"})
42
42
 
43
43
  return {
44
44
  "success": result["success"],
@@ -1,7 +1,8 @@
1
- from typing import Dict, Any, List, Union
1
+ from typing import Dict, Any
2
2
  import os
3
3
 
4
- from jarvis.jarvis_utils import OutputType, PrettyOutput
4
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
5
+
5
6
 
6
7
 
7
8
  class FileOperationTool:
@@ -5,10 +5,13 @@ from typing import Dict, Any
5
5
  import tempfile
6
6
  import yaml
7
7
  from jarvis.jarvis_platform.registry import PlatformRegistry
8
- from jarvis.jarvis_utils import OutputType, PrettyOutput, has_uncommitted_changes, init_env
9
8
  import sys
10
9
  import argparse
11
10
 
11
+ from jarvis.jarvis_utils.git_utils import has_uncommitted_changes
12
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
13
+ from jarvis.jarvis_utils.utils import init_env
14
+
12
15
 
13
16
  class GitCommitTool:
14
17
  name = "git_commit_agent"
@@ -67,7 +70,7 @@ class GitCommitTool:
67
70
  diff = process.communicate()[0].decode()
68
71
  PrettyOutput.print(diff, OutputType.CODE, lang="diff")
69
72
 
70
- prompt = f'''Generate commit message with the paranoia of someone who's lost production data:
73
+ prompt = f'''Generate commit message by the following rules:
71
74
  You should write commit message in {args.get('lang', 'Chinese')}
72
75
  # Required Structure
73
76
  YOU MUST USE EXACTLY THIS FORMAT:
@@ -65,7 +65,7 @@ class LSPFindDefinitionTool:
65
65
 
66
66
  try:
67
67
  # Initialize LSP
68
- if not lsp.initialize(os.path.dirname(os.path.abspath(file_path))):
68
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
69
69
  return {
70
70
  "success": False,
71
71
  "stderr": "LSP initialization failed",