jarvis-ai-assistant 0.1.123__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 (67) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +19 -21
  3. jarvis/jarvis_code_agent/code_agent.py +205 -119
  4. jarvis/jarvis_code_agent/file_select.py +6 -105
  5. jarvis/jarvis_code_agent/patch.py +192 -259
  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 +20 -25
  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 +25 -1
  30. jarvis/jarvis_tools/code_review.py +13 -14
  31. jarvis/jarvis_tools/create_code_agent.py +4 -7
  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 +58 -0
  35. jarvis/jarvis_tools/file_operation.py +3 -2
  36. jarvis/jarvis_tools/git_commiter.py +26 -17
  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 -3
  49. jarvis/jarvis_tools/select_code_files.py +1 -1
  50. jarvis/jarvis_utils/__init__.py +19 -941
  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.123.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/WHEEL +1 -1
  62. {jarvis_ai_assistant-0.1.123.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/entry_points.txt +1 -0
  63. jarvis/jarvis_code_agent/relevant_files.py +0 -117
  64. jarvis_ai_assistant-0.1.123.dist-info/METADATA +0 -461
  65. jarvis_ai_assistant-0.1.123.dist-info/RECORD +0 -65
  66. {jarvis_ai_assistant-0.1.123.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/LICENSE +0 -0
  67. {jarvis_ai_assistant-0.1.123.dist-info → jarvis_ai_assistant-0.1.125.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,3 @@
1
- import os
2
1
  import re
3
2
  import shlex
4
3
  import subprocess
@@ -6,15 +5,28 @@ from typing import Dict, Any
6
5
  import tempfile
7
6
  import yaml
8
7
  from jarvis.jarvis_platform.registry import PlatformRegistry
9
- from jarvis.jarvis_utils import OutputType, PrettyOutput, has_uncommitted_changes, init_env
10
8
  import sys
9
+ import argparse
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
11
14
 
12
15
 
13
16
  class GitCommitTool:
14
17
  name = "git_commit_agent"
15
18
  description = "Automatically generate and execute git commits based on code changes"
16
- parameters = {"properties": {}, "required": []}
17
-
19
+ parameters = {
20
+ "type": "object",
21
+ "properties": {
22
+ "lang": {
23
+ "type": "string",
24
+ "description": "Language for commit message",
25
+ "default": "Chinese"
26
+ }
27
+ },
28
+ "required": []
29
+ }
18
30
  def _extract_commit_message(self, message):
19
31
  """Raw extraction preserving all characters"""
20
32
  r = re.search(
@@ -58,27 +70,21 @@ class GitCommitTool:
58
70
  diff = process.communicate()[0].decode()
59
71
  PrettyOutput.print(diff, OutputType.CODE, lang="diff")
60
72
 
61
- prompt = f'''Generate commit message with the paranoia of someone who's lost production data:
62
-
63
- # Format Enforcement Protocol
64
- FAILURE TO WRAP MESSAGE IN <COMMIT_MESSAGE> TAGS WILL CAUSE SYSTEM REJECTION
65
-
73
+ prompt = f'''Generate commit message by the following rules:
74
+ You should write commit message in {args.get('lang', 'Chinese')}
66
75
  # Required Structure
67
76
  YOU MUST USE EXACTLY THIS FORMAT:
68
-
69
77
  <COMMIT_MESSAGE>
70
78
  <type>(<scope>): <subject>
71
-
72
- [Body description in imperative mood]
79
+ Body description in imperative mood
73
80
  </COMMIT_MESSAGE>
74
-
75
81
  # Format Rules
76
82
  1. Types: fix, feat, docs, style, refactor, test, chore
77
83
  2. Scope indicates module (e.g. auth, database)
78
84
  3. Subject line <= 72 chars, no period
79
- 4. Body explains WHAT and WHY, using present tense
80
-
81
- # Analysis Material (DO NOT INCLUDE IN OUTPUT)
85
+ 4. Body explains WHAT and WHY for every change, using present tense
86
+ 5. Do not omit any changes
87
+ # Analysis Material
82
88
  {diff}
83
89
  '''
84
90
 
@@ -121,8 +127,11 @@ YOU MUST USE EXACTLY THIS FORMAT:
121
127
 
122
128
  def main():
123
129
  init_env()
130
+ parser = argparse.ArgumentParser(description='Git commit tool')
131
+ parser.add_argument('--lang', type=str, default='Chinese', help='Language for commit messages')
132
+ args = parser.parse_args()
124
133
  tool = GitCommitTool()
125
- tool.execute({})
134
+ tool.execute({"lang": args.lang if hasattr(args, 'lang') else 'Chinese'})
126
135
 
127
136
  if __name__ == "__main__":
128
137
  sys.exit(main())
@@ -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",
@@ -65,7 +65,7 @@ class LSPFindReferencesTool:
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",
@@ -1,12 +1,14 @@
1
1
  import os
2
2
  from typing import Dict, Any
3
3
  from jarvis.jarvis_lsp.registry import LSPRegistry
4
-
5
4
  class LSPGetDiagnosticsTool:
6
5
  """Tool for getting diagnostics (errors, warnings) from code using LSP."""
7
6
 
7
+ # 工具名称
8
8
  name = "lsp_get_diagnostics"
9
+ # 工具描述
9
10
  description = "Get diagnostic information (errors, warnings) from code files"
11
+ # 工具参数定义
10
12
  parameters = {
11
13
  "file_path": "Path to the file to analyze",
12
14
  "language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
@@ -14,16 +16,16 @@ class LSPGetDiagnosticsTool:
14
16
 
15
17
  @staticmethod
16
18
  def check() -> bool:
17
- """Check if any LSP server is available."""
19
+ """检查是否有可用的LSP服务器"""
18
20
  registry = LSPRegistry.get_global_lsp_registry()
19
21
  return len(registry.get_supported_languages()) > 0
20
22
 
21
23
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
22
- """Execute the tool."""
24
+ """执行工具的主要逻辑"""
23
25
  file_path = args.get("file_path", "")
24
26
  language = args.get("language", "")
25
27
 
26
- # Validate inputs
28
+ # 验证输入参数
27
29
  if not all([file_path, language]):
28
30
  return {
29
31
  "success": False,
@@ -31,6 +33,7 @@ class LSPGetDiagnosticsTool:
31
33
  "stdout": ""
32
34
  }
33
35
 
36
+ # 检查文件是否存在
34
37
  if not os.path.exists(file_path):
35
38
  return {
36
39
  "success": False,
@@ -38,10 +41,11 @@ class LSPGetDiagnosticsTool:
38
41
  "stdout": ""
39
42
  }
40
43
 
41
- # Get LSP instance
44
+ # 获取LSP实例
42
45
  registry = LSPRegistry.get_global_lsp_registry()
43
46
  lsp = registry.create_lsp(language)
44
47
 
48
+ # 检查语言是否支持
45
49
  if not lsp:
46
50
  return {
47
51
  "success": False,
@@ -50,17 +54,18 @@ class LSPGetDiagnosticsTool:
50
54
  }
51
55
 
52
56
  try:
53
- # Initialize LSP
54
- if not lsp.initialize(os.path.dirname(os.path.abspath(file_path))):
57
+ # 初始化LSP
58
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
55
59
  return {
56
60
  "success": False,
57
61
  "stderr": "LSP initialization failed",
58
62
  "stdout": ""
59
63
  }
60
64
 
61
- # Get diagnostics
65
+ # 获取诊断信息
62
66
  diagnostics = lsp.get_diagnostics(file_path)
63
67
 
68
+ # 如果没有诊断信息
64
69
  if not diagnostics:
65
70
  return {
66
71
  "success": True,
@@ -68,16 +73,18 @@ class LSPGetDiagnosticsTool:
68
73
  "stderr": ""
69
74
  }
70
75
 
71
- # Format output
76
+ # 格式化输出
72
77
  output = ["Diagnostics:"]
78
+ # 严重程度映射
73
79
  severity_map = {1: "Error", 2: "Warning", 3: "Info", 4: "Hint"}
74
80
 
75
- # Sort diagnostics by severity and line number
81
+ # 按严重程度和行号排序诊断信息
76
82
  sorted_diagnostics = sorted(
77
83
  diagnostics,
78
84
  key=lambda x: (x["severity"], x["range"]["start"]["line"])
79
85
  )
80
86
 
87
+ # 处理每个诊断信息
81
88
  for diag in sorted_diagnostics:
82
89
  severity = severity_map.get(diag["severity"], "Unknown")
83
90
  start = diag["range"]["start"]
@@ -90,7 +97,7 @@ class LSPGetDiagnosticsTool:
90
97
  "-" * 60
91
98
  ])
92
99
 
93
- # Add related information if available
100
+ # 处理相关附加信息
94
101
  if diag.get("relatedInformation"):
95
102
  output.append("Related information:")
96
103
  for info in diag["relatedInformation"]:
@@ -117,5 +124,6 @@ class LSPGetDiagnosticsTool:
117
124
  "stdout": ""
118
125
  }
119
126
  finally:
127
+ # 确保关闭LSP连接
120
128
  if lsp:
121
129
  lsp.shutdown()
@@ -50,7 +50,7 @@ class LSPGetDocumentSymbolsTool:
50
50
 
51
51
  try:
52
52
  # Initialize LSP
53
- if not lsp.initialize(os.path.dirname(os.path.abspath(file_path))):
53
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
54
54
  return {
55
55
  "success": False,
56
56
  "stderr": "LSP initialization failed",
@@ -65,7 +65,7 @@ class LSPPrepareRenameTool:
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",
@@ -74,7 +74,7 @@ class LSPValidateEditTool:
74
74
 
75
75
  try:
76
76
  # Initialize LSP
77
- if not lsp.initialize(os.path.dirname(os.path.abspath(file_path))):
77
+ if not lsp.initialize(os.path.abspath(os.getcwd())):
78
78
  return {
79
79
  "success": False,
80
80
  "stderr": "LSP initialization failed",
@@ -1,7 +1,10 @@
1
1
  import os
2
2
  import yaml
3
3
  from typing import Dict, Optional, Any
4
- from jarvis.jarvis_utils import OutputType, PrettyOutput, is_use_methodology
4
+
5
+ from jarvis.jarvis_utils.config import is_use_methodology
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
+
5
8
 
6
9
 
7
10
  class MethodologyTool:
@@ -1,7 +1,8 @@
1
1
  from typing import Dict, Any
2
2
  import os
3
- from jarvis.jarvis_utils import OutputType, PrettyOutput, dont_use_local_model
4
3
  from jarvis.jarvis_rag.main import RAGTool as RAGCore
4
+ from jarvis.jarvis_utils.config import dont_use_local_model
5
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
5
6
 
6
7
  class RAGTool:
7
8
  name = "rag"
@@ -48,25 +49,28 @@ class RAGTool:
48
49
  return self.rag_instances[dir_path]
49
50
 
50
51
  def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
51
- """Execute document question and answer
52
+ """执行文档问答
52
53
 
53
54
  Args:
54
- args: A dictionary containing parameters
55
- - dir: The document directory path
56
- - question: The question to ask
57
- - rebuild_index: Whether to rebuild the index
55
+ args: 包含参数的字典
56
+ - dir: 文档目录路径
57
+ - question: 要询问的问题
58
+ - rebuild_index: 是否重建索引
58
59
 
59
60
  Returns:
60
- Dict[str, Any]: The execution result
61
+ Dict[str, Any]: 执行结果,包含以下字段:
62
+ - success: 布尔值,表示操作是否成功
63
+ - stdout: 如果成功,包含问题的答案
64
+ - stderr: 如果失败,包含错误信息
61
65
  """
62
66
  try:
63
- # Get parameters
64
- dir_path = os.path.expanduser(args["dir"]) # Expand ~ paths
65
- dir_path = os.path.abspath(dir_path) # Convert to absolute path
67
+ # 获取参数
68
+ dir_path = os.path.expanduser(args["dir"])
69
+ dir_path = os.path.abspath(dir_path)
66
70
  question = args["question"]
67
71
  rebuild_index = args.get("rebuild_index", False)
68
72
 
69
- # Check if the directory exists
73
+ # 检查目录是否存在
70
74
  if not os.path.exists(dir_path):
71
75
  return {
72
76
  "success": False,
@@ -74,7 +78,7 @@ class RAGTool:
74
78
  "stderr": f"Directory does not exist: {dir_path}"
75
79
  }
76
80
 
77
- # Check if it is a directory
81
+ # 检查路径是否为目录
78
82
  if not os.path.isdir(dir_path):
79
83
  return {
80
84
  "success": False,
@@ -82,18 +86,19 @@ class RAGTool:
82
86
  "stderr": f"The path is not a directory: {dir_path}"
83
87
  }
84
88
 
85
- # Get RAG instance
89
+ # 获取RAG实例
86
90
  rag = self._get_rag_instance(dir_path)
87
91
 
88
- # If you need to rebuild the index or the index does not exist
92
+ # 如果需要重建索引或索引不存在
89
93
  if rebuild_index or not rag.is_index_built():
90
94
  PrettyOutput.print("正在构建文档索引...", OutputType.INFO)
91
95
  rag.build_index(dir_path)
92
96
 
93
- # Execute question and answer
97
+ # 执行问答
94
98
  PrettyOutput.print(f"问题: {question}", OutputType.INFO)
95
99
  response = rag.ask(question)
96
100
 
101
+ # 处理未找到相关文档的情况
97
102
  if response is None:
98
103
  return {
99
104
  "success": False,
@@ -101,6 +106,7 @@ class RAGTool:
101
106
  "stderr": "Failed to get answer, possibly no relevant documents found"
102
107
  }
103
108
 
109
+ # 返回成功响应
104
110
  return {
105
111
  "success": True,
106
112
  "stdout": response,
@@ -108,6 +114,7 @@ class RAGTool:
108
114
  }
109
115
 
110
116
  except Exception as e:
117
+ # 处理任何意外错误
111
118
  PrettyOutput.print(f"文档问答失败:{str(e)}", OutputType.ERROR)
112
119
  return {
113
120
  "success": False,
@@ -1,6 +1,7 @@
1
- from typing import Dict, Any, List
1
+ from typing import Dict, Any
2
2
  import os
3
- from jarvis.jarvis_utils import OutputType, PrettyOutput
3
+
4
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
4
5
 
5
6
 
6
7
  class ReadCodeTool:
@@ -119,7 +120,7 @@ class ReadCodeTool:
119
120
  formatted_lines.append(f"{line_num:>5}:{line}")
120
121
 
121
122
  content = "".join(formatted_lines)
122
- output = f"\n\nFile: {filepath}\nLines: [{start_line}, {end_line}]\n{content}"
123
+ output = f"\n\nFile: {filepath}\nLines: [{start_line}, {end_line}]\n{content} \n\n" + "="*80 + "\n\n"
123
124
  return {
124
125
  "success": True,
125
126
  "stdout": output,
@@ -1,7 +1,8 @@
1
1
  from typing import Dict, Any
2
2
  import requests
3
3
  from bs4 import BeautifulSoup
4
- from jarvis.jarvis_utils import PrettyOutput, OutputType
4
+
5
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
5
6
 
6
7
  class WebpageTool:
7
8
  name = "read_webpage"
@@ -9,7 +9,10 @@ import yaml
9
9
  from jarvis.jarvis_agent.output_handler import OutputHandler
10
10
  from jarvis.jarvis_platform.registry import PlatformRegistry
11
11
  from jarvis.jarvis_tools.base import Tool
12
- from jarvis.jarvis_utils import OutputType, PrettyOutput, get_context_token_count, get_max_token_count
12
+ from jarvis.jarvis_utils.config import get_max_token_count
13
+ from jarvis.jarvis_utils.embedding import get_context_token_count
14
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
15
+
13
16
 
14
17
 
15
18
  tool_call_help = """
@@ -1,10 +1,13 @@
1
1
  from typing import Dict, Any, List
2
2
  from jarvis.jarvis_platform.registry import PlatformRegistry
3
- from jarvis.jarvis_utils import PrettyOutput, OutputType, get_context_token_count, get_max_token_count
4
3
  from jarvis.jarvis_tools.read_webpage import WebpageTool
5
4
  from playwright.sync_api import sync_playwright
6
5
  from urllib.parse import quote
7
6
 
7
+ from jarvis.jarvis_utils.config import get_max_token_count
8
+ from jarvis.jarvis_utils.embedding import get_context_token_count
9
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
10
+
8
11
  def bing_search(query):
9
12
  try:
10
13
  with sync_playwright() as p:
@@ -62,7 +65,7 @@ def bing_search(query):
62
65
  return None
63
66
 
64
67
  class SearchTool:
65
- name = "search"
68
+ name = "search_web"
66
69
  description = "Use Bing search engine to search for information, and extract key information based on the question"
67
70
  parameters = {
68
71
  "type": "object",
@@ -212,7 +215,6 @@ Please synthesize a final answer that:
212
215
  "stderr": "No search results found"
213
216
  }
214
217
 
215
- # Collect webpage content
216
218
  contents = []
217
219
  for i, result in enumerate(results, 1):
218
220
  try:
@@ -1,7 +1,7 @@
1
1
  from typing import Dict, Any
2
2
 
3
- from jarvis.jarvis_utils import OutputType, PrettyOutput
4
3
  from jarvis.jarvis_code_agent.file_select import select_files
4
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
5
5
 
6
6
 
7
7
  class CodeFileSelecterTool: