jarvis-ai-assistant 0.1.108__tar.gz → 0.1.110__tar.gz

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 (71) hide show
  1. {jarvis_ai_assistant-0.1.108/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.110}/PKG-INFO +12 -3
  2. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/README.md +8 -0
  3. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/pyproject.toml +5 -4
  4. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/setup.py +4 -3
  5. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/__init__.py +1 -1
  6. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/agent.py +5 -5
  7. jarvis_ai_assistant-0.1.110/src/jarvis/jarvis_code_agent/code_agent.py +197 -0
  8. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_code_agent/file_select.py +11 -10
  9. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_code_agent/patch.py +19 -9
  10. jarvis_ai_assistant-0.1.110/src/jarvis/jarvis_code_agent/relevant_files.py +27 -0
  11. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_codebase/main.py +55 -60
  12. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/oyi.py +1 -1
  13. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_rag/main.py +194 -268
  14. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/registry.py +10 -9
  15. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/utils.py +155 -16
  16. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110/src/jarvis_ai_assistant.egg-info}/PKG-INFO +12 -3
  17. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis_ai_assistant.egg-info/requires.txt +3 -2
  18. jarvis_ai_assistant-0.1.108/src/jarvis/jarvis_code_agent/code_agent.py +0 -345
  19. jarvis_ai_assistant-0.1.108/src/jarvis/jarvis_code_agent/relevant_files.py +0 -188
  20. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/LICENSE +0 -0
  21. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/MANIFEST.in +0 -0
  22. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/setup.cfg +0 -0
  23. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
  24. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_codebase/__init__.py +0 -0
  25. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/base.py +0 -0
  26. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/cpp.py +0 -0
  27. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/go.py +0 -0
  28. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/python.py +0 -0
  29. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/registry.py +0 -0
  30. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_lsp/rust.py +0 -0
  31. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/__init__.py +0 -0
  32. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/ai8.py +0 -0
  33. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/base.py +0 -0
  34. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/kimi.py +0 -0
  35. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/ollama.py +0 -0
  36. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/openai.py +0 -0
  37. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform/registry.py +0 -0
  38. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
  39. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_platform_manager/main.py +0 -0
  40. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_rag/__init__.py +0 -0
  41. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  42. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_smart_shell/main.py +0 -0
  43. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/__init__.py +0 -0
  44. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
  45. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/ask_user.py +0 -0
  46. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/base.py +0 -0
  47. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/chdir.py +0 -0
  48. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/code_review.py +0 -0
  49. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/create_code_agent.py +0 -0
  50. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
  51. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/deep_thinking.py +0 -0
  52. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/deep_thinking_agent.py +0 -0
  53. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/execute_shell.py +0 -0
  54. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/file_operation.py +0 -0
  55. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/git_commiter.py +0 -0
  56. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_find_definition.py +0 -0
  57. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_find_references.py +0 -0
  58. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
  59. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -0
  60. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_prepare_rename.py +0 -0
  61. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/lsp_validate_edit.py +0 -0
  62. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/methodology.py +0 -0
  63. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/rag.py +0 -0
  64. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/read_code.py +0 -0
  65. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/read_webpage.py +0 -0
  66. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/search.py +0 -0
  67. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis/jarvis_tools/select_code_files.py +0 -0
  68. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
  69. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  70. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
  71. {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.110}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.108
3
+ Version: 0.1.110
4
4
  Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
5
  Home-page: https://github.com/skyfireitdiy/Jarvis
6
6
  Author: skyfire
@@ -58,8 +58,9 @@ Requires-Dist: yaspin>=2.5.0
58
58
  Requires-Dist: rich>=13.3.1
59
59
  Requires-Dist: pygments>=2.15.0
60
60
  Requires-Dist: fuzzywuzzy>=0.18.0
61
- Requires-Dist: python-Levenshtein>=0.26.1
62
- Requires-Dist: jedi>=0.19.0
61
+ Requires-Dist: python-Levenshtein>=0.25.0
62
+ Requires-Dist: jedi>=0.17.2
63
+ Requires-Dist: psutil>=7.0.0
63
64
  Provides-Extra: dev
64
65
  Requires-Dist: pytest; extra == "dev"
65
66
  Requires-Dist: black; extra == "dev"
@@ -161,6 +162,14 @@ Jarvis supports configuration through environment variables that can be set in t
161
162
  | OYI_API_KEY | API key for OYI platform | - | Required for OYI |
162
163
  | OLLAMA_API_BASE | Base URL for Ollama API | http://localhost:11434 | No |
163
164
 
165
+ ## Minimal Configuration (Example with OpenAI-compatible Interface)
166
+
167
+ ```bash
168
+ JARVIS_PLATFORM=openai
169
+ JARVIS_MODEL=deepseek-chat
170
+ OPENAI_API_KEY=your_openai_api_key
171
+ OPENAI_API_BASE=https://api.deepseek.com/v1
172
+ ```
164
173
 
165
174
  ## 🎯 Usage
166
175
 
@@ -90,6 +90,14 @@ Jarvis supports configuration through environment variables that can be set in t
90
90
  | OYI_API_KEY | API key for OYI platform | - | Required for OYI |
91
91
  | OLLAMA_API_BASE | Base URL for Ollama API | http://localhost:11434 | No |
92
92
 
93
+ ## Minimal Configuration (Example with OpenAI-compatible Interface)
94
+
95
+ ```bash
96
+ JARVIS_PLATFORM=openai
97
+ JARVIS_MODEL=deepseek-chat
98
+ OPENAI_API_KEY=your_openai_api_key
99
+ OPENAI_API_BASE=https://api.deepseek.com/v1
100
+ ```
93
101
 
94
102
  ## 🎯 Usage
95
103
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.108"
7
+ version = "0.1.110"
8
8
  description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Your Name", email = "your.email@example.com" }]
@@ -40,8 +40,9 @@ dependencies = [
40
40
  "rich>=13.3.1",
41
41
  "pygments>=2.15.0",
42
42
  "fuzzywuzzy>=0.18.0",
43
- "python-Levenshtein>=0.26.1",
44
- "jedi>=0.19.0",
43
+ "python-Levenshtein>=0.25.0",
44
+ "jedi>=0.17.2",
45
+ "psutil>=7.0.0",
45
46
  ]
46
47
  requires-python = ">=3.8"
47
48
 
@@ -60,4 +61,4 @@ jarvis-smart-shell = "jarvis.jarvis_smart_shell.main:main"
60
61
  jss = "jarvis.jarvis_smart_shell.main:main"
61
62
  jarvis-platform-manager = "jarvis.jarvis_platform_manager.main:main"
62
63
  jarvis-git-commit = "jarvis.jarvis_tools.git_commiter:main"
63
- jarvis-code-review = "jarvis.jarvis_tools.code_review:main"
64
+ jarvis-code-review = "jarvis.jarvis_tools.code_review:main"
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="jarvis-ai-assistant",
5
- version="0.1.108",
5
+ version="0.1.110",
6
6
  author="skyfire",
7
7
  author_email="skyfireitdiy@hotmail.com",
8
8
  description="An AI assistant that uses various tools to interact with the system",
@@ -32,8 +32,9 @@ setup(
32
32
  "rich>=13.3.1",
33
33
  "pygments>=2.15.0",
34
34
  "fuzzywuzzy>=0.18.0",
35
- "python-Levenshtein>=0.26.1",
36
- "jedi>=0.19.0",
35
+ "python-Levenshtein>=0.25.0",
36
+ "jedi>=0.17.2",
37
+ "psutil>=7.0.0",
37
38
  ],
38
39
  entry_points={
39
40
  "console_scripts": [
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.108"
3
+ __version__ = "0.1.110"
@@ -8,7 +8,7 @@ import yaml
8
8
  from jarvis.jarvis_platform.base import BasePlatform
9
9
  from jarvis.jarvis_platform.registry import PlatformRegistry
10
10
  from jarvis.jarvis_tools.registry import ToolRegistry, tool_call_help
11
- from jarvis.utils import PrettyOutput, OutputType, is_auto_complete, is_need_summary, is_record_methodology, load_methodology, add_agent, delete_current_agent, get_max_context_length, get_multiline_input, init_env, is_use_methodology
11
+ from jarvis.utils import PrettyOutput, OutputType, get_context_token_count, is_auto_complete, is_need_summary, is_record_methodology, load_methodology, add_agent, delete_current_agent, get_max_token_count, get_multiline_input, init_env, is_use_methodology
12
12
  import os
13
13
 
14
14
  class Agent:
@@ -89,7 +89,7 @@ class Agent:
89
89
  Please describe in concise bullet points, highlighting important information.
90
90
  """
91
91
 
92
- self.max_context_length = max_context_length if max_context_length is not None else get_max_context_length()
92
+ self.max_token_count = max_context_length if max_context_length is not None else get_max_token_count()
93
93
 
94
94
  self.auto_complete = auto_complete if auto_complete is not None else is_auto_complete()
95
95
 
@@ -322,16 +322,16 @@ Please continue the task based on the above information.
322
322
  PrettyOutput.print("Analyzing task...", OutputType.PROGRESS)
323
323
 
324
324
  # 累加对话长度
325
- self.conversation_length += len(self.prompt)
325
+ self.conversation_length += get_context_token_count(self.prompt)
326
326
 
327
327
  # 如果对话历史长度超过限制,在提示中添加提醒
328
- if self.conversation_length > self.max_context_length:
328
+ if self.conversation_length > self.max_token_count:
329
329
  current_response = self._summarize_and_clear_history()
330
330
  continue
331
331
  else:
332
332
  current_response = self._call_model(self.prompt)
333
333
  self.prompt = ""
334
- self.conversation_length += len(current_response)
334
+ self.conversation_length += get_context_token_count(current_response)
335
335
 
336
336
  for handler in self.output_handler_before_tool:
337
337
  self.prompt += handler(current_response)
@@ -0,0 +1,197 @@
1
+ import os
2
+ from typing import List
3
+
4
+ from jarvis.agent import Agent
5
+ from jarvis.jarvis_code_agent.patch import apply_patch
6
+ from jarvis.jarvis_code_agent.relevant_files import find_relevant_files
7
+ from jarvis.jarvis_platform.registry import PlatformRegistry
8
+ from jarvis.jarvis_tools.git_commiter import GitCommitTool
9
+ from jarvis.jarvis_tools.registry import ToolRegistry
10
+ from jarvis.utils import OutputType, PrettyOutput, get_file_line_count, get_multiline_input, has_uncommitted_changes, init_env, find_git_root
11
+
12
+
13
+ class CodeAgent:
14
+ def __init__(self):
15
+ self.root_dir = os.getcwd()
16
+ tool_registry = ToolRegistry()
17
+ tool_registry.use_tools(["read_code",
18
+ "execute_shell",
19
+ "search",
20
+ "create_code_agent",
21
+ "ask_user",
22
+ "ask_codebase",
23
+ "lsp_get_document_symbols",
24
+ "lsp_get_diagnostics",
25
+ "lsp_find_references",
26
+ "lsp_find_definition",
27
+ "lsp_prepare_rename",
28
+ "lsp_validate_edit"])
29
+ code_system_prompt = """You are a code agent responsible for modifying code. You will analyze code and create patches while following these guidelines:
30
+
31
+ # Patch Format
32
+ <PATCH>
33
+ > /path/file start,end
34
+ new_content
35
+ </PATCH>
36
+
37
+ Key Rules:
38
+ • One modification per patch block
39
+ • Line numbers are based on original file
40
+ • Start line is included, end line is excluded
41
+ • Same start/end number: insert before that line
42
+ • Start=0, end=0: create new file with content
43
+
44
+ # Code Compatibility
45
+ 1. System Integration
46
+ • Maintain existing API contracts
47
+ • Preserve function signatures
48
+ • Keep data structures compatible
49
+ • Honor return types and exceptions
50
+
51
+ 2. Style Consistency
52
+ • Match naming conventions
53
+ • Follow indentation patterns
54
+ • Use existing import style
55
+ • Keep comment format
56
+
57
+ 3. Pattern Alignment
58
+ • Use similar error handling
59
+ • Follow existing design patterns
60
+ • Match logging approach
61
+ • Keep configuration style
62
+
63
+ # Development Process
64
+ 1. ANALYZE
65
+ • Break down requirements
66
+ • Assess task complexity
67
+ • Determine if subtasks needed
68
+
69
+ 2. ASSESS
70
+ • Map dependencies
71
+ • Check compatibility impact
72
+ • Identify integration points
73
+
74
+ 3. IMPLEMENT
75
+ • Follow existing patterns
76
+ • Make minimal changes
77
+ • Verify integrations
78
+
79
+ # File Handling
80
+ Large Files (>200 lines):
81
+ 1. Use grep/find to locate relevant sections
82
+ 2. Read specific ranges with read_code
83
+ 3. Apply targeted changes
84
+
85
+ # Available Tools
86
+ Primary:
87
+ • LSP tools for code analysis
88
+ • read_code with line ranges
89
+ • execute_shell for searches
90
+ • ask_user when unclear
91
+
92
+ # Quality Requirements
93
+ Code Changes Must:
94
+ ✓ Preserve interfaces
95
+ ✓ Match existing style
96
+ ✓ Handle errors consistently
97
+ ✓ Maintain documentation
98
+ ✓ Keep test coverage
99
+ ✓ Follow project patterns"""
100
+ self.agent = Agent(system_prompt=code_system_prompt,
101
+ name="CodeAgent",
102
+ auto_complete=False,
103
+ is_sub_agent=False,
104
+ use_methodology=False,
105
+ tool_registry=tool_registry,
106
+ platform=PlatformRegistry().get_thinking_platform(),
107
+ record_methodology=False,
108
+ output_handler_after_tool=[apply_patch],
109
+ need_summary=False)
110
+
111
+
112
+
113
+ def _init_env(self):
114
+ curr_dir = os.getcwd()
115
+ git_dir = find_git_root(curr_dir)
116
+ self.root_dir = git_dir
117
+ if has_uncommitted_changes():
118
+ git_commiter = GitCommitTool()
119
+ git_commiter.execute({})
120
+
121
+
122
+ def make_files_prompt(self, files: List[str]) -> str:
123
+ """Make the files prompt.
124
+
125
+ Args:
126
+ files: The files to be modified
127
+
128
+ """
129
+ return "\n".join(
130
+ f"- {file} ({get_file_line_count(file)} lines)"
131
+ for file in files
132
+ )
133
+
134
+ def run(self, user_input: str) :
135
+ """Run the code agent with the given user input.
136
+
137
+ Args:
138
+ user_input: The user's requirement/request
139
+
140
+ Returns:
141
+ str: Output describing the execution result
142
+ """
143
+ try:
144
+ self._init_env()
145
+ files = find_relevant_files(user_input, self.root_dir)
146
+ self.agent.run(self._build_first_edit_prompt(user_input, self.make_files_prompt(files)))
147
+
148
+ except Exception as e:
149
+ return f"Error during execution: {str(e)}"
150
+
151
+
152
+
153
+ def _build_first_edit_prompt(self, user_input: str, files_prompt: str) -> str:
154
+ """Build the initial prompt for the agent.
155
+
156
+ Args:
157
+ user_input: The user's requirement
158
+ files_prompt: The formatted list of relevant files
159
+
160
+ Returns:
161
+ str: The formatted prompt
162
+ """
163
+ return f"""# Code Modification Task
164
+
165
+ ## User Requirement
166
+ {user_input}
167
+
168
+ ## Available Files
169
+ {files_prompt}
170
+ """
171
+ def main():
172
+ """Jarvis main entry point"""
173
+ # Add argument parser
174
+ init_env()
175
+
176
+
177
+ try:
178
+ # Interactive mode
179
+ while True:
180
+ try:
181
+ user_input = get_multiline_input("Please enter your requirement (input empty line to exit):")
182
+ if not user_input:
183
+ break
184
+ agent = CodeAgent()
185
+ agent.run(user_input)
186
+
187
+ except Exception as e:
188
+ PrettyOutput.print(f"Error: {str(e)}", OutputType.ERROR)
189
+
190
+ except Exception as e:
191
+ PrettyOutput.print(f"Initialization error: {str(e)}", OutputType.ERROR)
192
+ return 1
193
+
194
+ return 0
195
+
196
+ if __name__ == "__main__":
197
+ exit(main())
@@ -137,16 +137,17 @@ def select_files(related_files: List[str], root_dir: str) -> List[str]:
137
137
 
138
138
  PrettyOutput.print(output, OutputType.INFO, lang="markdown")
139
139
 
140
- # Ask the user if they need to adjust the file list
141
- if user_confirm("Do you need to adjust the file list?", False):
142
- # Let the user select files
143
- numbers = get_single_line_input("Please enter the file numbers to include (support: 1,3-6 format, press Enter to keep the current selection)").strip()
144
- if numbers:
145
- selected_indices = _parse_file_selection(numbers, len(related_files))
146
- if selected_indices:
147
- selected_files = [related_files[i] for i in selected_indices]
148
- else:
149
- PrettyOutput.print("No valid files selected, keep the current selection", OutputType.WARNING)
140
+ if len(related_files) > 0:
141
+ # Ask the user if they need to adjust the file list
142
+ if user_confirm("Do you need to adjust the file list?", False):
143
+ # Let the user select files
144
+ numbers = get_single_line_input("Please enter the file numbers to include (support: 1,3-6 format, press Enter to keep the current selection)").strip()
145
+ if numbers:
146
+ selected_indices = _parse_file_selection(numbers, len(related_files))
147
+ if selected_indices:
148
+ selected_files = [related_files[i] for i in selected_indices]
149
+ else:
150
+ PrettyOutput.print("No valid files selected, keep the current selection", OutputType.WARNING)
150
151
 
151
152
  # Ask if they need to supplement files
152
153
  if user_confirm("Do you need to supplement other files?", False):
@@ -62,15 +62,6 @@ def apply_patch(output_str: str)->str:
62
62
 
63
63
  for filepath, patch_info in patches.items():
64
64
  try:
65
- # Check if file exists
66
- if not os.path.exists(filepath):
67
- PrettyOutput.print(f"File not found: {filepath}", OutputType.WARNING)
68
- continue
69
-
70
- # Read original file content
71
- lines = open(filepath, 'r', encoding='utf-8').readlines()
72
-
73
- # Apply patch
74
65
  for patch in patch_info:
75
66
  start_line = patch['start_line']
76
67
  end_line = patch['end_line']
@@ -78,6 +69,25 @@ def apply_patch(output_str: str)->str:
78
69
 
79
70
  if new_content and new_content[-1] and new_content[-1][-1] != '\n':
80
71
  new_content[-1] += '\n'
72
+
73
+ # Handle file creation when start=end=0
74
+ if start_line == 0 and end_line == 0:
75
+ # Create directory if it doesn't exist
76
+ os.makedirs(os.path.dirname(filepath), exist_ok=True)
77
+ # Write new file
78
+ with open(filepath, 'w', encoding='utf-8') as f:
79
+ f.writelines(new_content)
80
+ PrettyOutput.print(f"Created new file {filepath} successfully\n", OutputType.SUCCESS)
81
+ continue
82
+
83
+ # Regular patch logic for existing files
84
+ if not os.path.exists(filepath):
85
+ PrettyOutput.print(f"File not found: {filepath}", OutputType.WARNING)
86
+ continue
87
+
88
+ # Read original file content
89
+ lines = open(filepath, 'r', encoding='utf-8').readlines()
90
+
81
91
  # Validate line numbers
82
92
  if start_line < 0 or end_line > len(lines) + 1 or start_line > end_line:
83
93
  PrettyOutput.print(f"Invalid line range [{start_line}, {end_line}) for file: {filepath}", OutputType.WARNING)
@@ -0,0 +1,27 @@
1
+ import os
2
+ import re
3
+ from typing import List
4
+
5
+ import yaml
6
+ from jarvis.agent import Agent
7
+ from jarvis.jarvis_code_agent.file_select import select_files
8
+ from jarvis.jarvis_codebase.main import CodeBase
9
+ from jarvis.jarvis_platform.registry import PlatformRegistry
10
+ from jarvis.jarvis_tools.registry import ToolRegistry
11
+ from jarvis.utils import OutputType, PrettyOutput, is_disable_codebase
12
+
13
+
14
+ def find_relevant_files(user_input: str, root_dir: str) -> List[str]:
15
+ try:
16
+ files_from_codebase = []
17
+ if not is_disable_codebase():
18
+ PrettyOutput.print("Find files from codebase...", OutputType.INFO)
19
+ codebase = CodeBase(root_dir)
20
+ files_from_codebase = codebase.search_similar(user_input)
21
+
22
+ PrettyOutput.print("Find files by agent...", OutputType.INFO)
23
+
24
+ selected_files = select_files(files_from_codebase, os.getcwd())
25
+ return selected_files
26
+ except Exception as e:
27
+ return []