jarvis-ai-assistant 0.1.108__tar.gz → 0.1.109__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.
- {jarvis_ai_assistant-0.1.108/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.109}/PKG-INFO +12 -3
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/README.md +8 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/pyproject.toml +5 -4
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/setup.py +4 -3
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/__init__.py +1 -1
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/agent.py +3 -3
- jarvis_ai_assistant-0.1.109/src/jarvis/jarvis_code_agent/code_agent.py +197 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_code_agent/file_select.py +11 -10
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_code_agent/patch.py +19 -9
- jarvis_ai_assistant-0.1.109/src/jarvis/jarvis_code_agent/relevant_files.py +27 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_codebase/main.py +52 -57
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_rag/main.py +193 -267
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/registry.py +8 -7
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/utils.py +151 -12
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109/src/jarvis_ai_assistant.egg-info}/PKG-INFO +12 -3
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis_ai_assistant.egg-info/requires.txt +3 -2
- jarvis_ai_assistant-0.1.108/src/jarvis/jarvis_code_agent/code_agent.py +0 -345
- jarvis_ai_assistant-0.1.108/src/jarvis/jarvis_code_agent/relevant_files.py +0 -188
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/MANIFEST.in +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/setup.cfg +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_codebase/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/base.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/cpp.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/go.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/python.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/registry.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_lsp/rust.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/ai8.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/base.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/kimi.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/ollama.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/openai.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/oyi.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform/registry.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_platform_manager/main.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_rag/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_smart_shell/main.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/ask_user.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/base.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/chdir.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/code_review.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/create_code_agent.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/deep_thinking.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/deep_thinking_agent.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/execute_shell.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/file_operation.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/git_commiter.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_find_definition.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_find_references.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_prepare_rename.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/lsp_validate_edit.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/methodology.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/rag.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/read_code.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/read_webpage.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/search.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_tools/select_code_files.py +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/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.
|
|
3
|
+
Version: 0.1.109
|
|
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.
|
|
62
|
-
Requires-Dist: jedi>=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.
|
|
7
|
+
version = "0.1.109"
|
|
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.
|
|
44
|
-
"jedi>=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.
|
|
5
|
+
version="0.1.109",
|
|
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.
|
|
36
|
-
"jedi>=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": [
|
|
@@ -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_context_length, get_multiline_input, init_env, is_use_methodology
|
|
12
12
|
import os
|
|
13
13
|
|
|
14
14
|
class Agent:
|
|
@@ -322,7 +322,7 @@ 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 +=
|
|
325
|
+
self.conversation_length += get_context_token_count(self.prompt)
|
|
326
326
|
|
|
327
327
|
# 如果对话历史长度超过限制,在提示中添加提醒
|
|
328
328
|
if self.conversation_length > self.max_context_length:
|
|
@@ -331,7 +331,7 @@ Please continue the task based on the above information.
|
|
|
331
331
|
else:
|
|
332
332
|
current_response = self._call_model(self.prompt)
|
|
333
333
|
self.prompt = ""
|
|
334
|
-
self.conversation_length +=
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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):
|
{jarvis_ai_assistant-0.1.108 → jarvis_ai_assistant-0.1.109}/src/jarvis/jarvis_code_agent/patch.py
RENAMED
|
@@ -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 []
|