jarvis-ai-assistant 0.1.102__py3-none-any.whl → 0.1.103__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.
- jarvis/__init__.py +1 -1
- jarvis/agent.py +138 -117
- jarvis/jarvis_code_agent/code_agent.py +234 -0
- jarvis/{jarvis_coder → jarvis_code_agent}/file_select.py +16 -17
- jarvis/jarvis_code_agent/patch.py +118 -0
- jarvis/jarvis_code_agent/relevant_files.py +66 -0
- jarvis/jarvis_codebase/main.py +878 -0
- jarvis/jarvis_platform/main.py +5 -3
- jarvis/jarvis_rag/main.py +818 -0
- jarvis/jarvis_smart_shell/main.py +2 -2
- jarvis/models/ai8.py +3 -1
- jarvis/models/kimi.py +36 -30
- jarvis/models/ollama.py +17 -11
- jarvis/models/openai.py +15 -12
- jarvis/models/oyi.py +24 -7
- jarvis/models/registry.py +1 -25
- jarvis/tools/__init__.py +0 -6
- jarvis/tools/ask_codebase.py +99 -0
- jarvis/tools/ask_user.py +1 -9
- jarvis/tools/chdir.py +1 -1
- jarvis/tools/code_review.py +163 -0
- jarvis/tools/create_code_sub_agent.py +19 -45
- jarvis/tools/create_code_test_agent.py +115 -0
- jarvis/tools/create_ctags_agent.py +176 -0
- jarvis/tools/create_sub_agent.py +2 -2
- jarvis/tools/execute_shell.py +2 -2
- jarvis/tools/file_operation.py +2 -2
- jarvis/tools/find_in_codebase.py +108 -0
- jarvis/tools/git_commiter.py +68 -0
- jarvis/tools/methodology.py +3 -3
- jarvis/tools/rag.py +141 -0
- jarvis/tools/read_code.py +147 -0
- jarvis/tools/read_webpage.py +1 -1
- jarvis/tools/registry.py +47 -31
- jarvis/tools/search.py +8 -6
- jarvis/tools/select_code_files.py +4 -4
- jarvis/utils.py +374 -84
- {jarvis_ai_assistant-0.1.102.dist-info → jarvis_ai_assistant-0.1.103.dist-info}/METADATA +52 -2
- jarvis_ai_assistant-0.1.103.dist-info/RECORD +51 -0
- jarvis_ai_assistant-0.1.103.dist-info/entry_points.txt +11 -0
- jarvis/jarvis_code_agent/main.py +0 -200
- jarvis/jarvis_coder/git_utils.py +0 -123
- jarvis/jarvis_coder/patch_handler.py +0 -340
- jarvis/jarvis_github/main.py +0 -232
- jarvis/tools/execute_code_modification.py +0 -70
- jarvis/tools/find_files.py +0 -119
- jarvis/tools/generate_tool.py +0 -174
- jarvis/tools/thinker.py +0 -151
- jarvis_ai_assistant-0.1.102.dist-info/RECORD +0 -46
- jarvis_ai_assistant-0.1.102.dist-info/entry_points.txt +0 -6
- /jarvis/{jarvis_coder → jarvis_codebase}/__init__.py +0 -0
- /jarvis/{jarvis_github → jarvis_rag}/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.102.dist-info → jarvis_ai_assistant-0.1.103.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.102.dist-info → jarvis_ai_assistant-0.1.103.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.102.dist-info → jarvis_ai_assistant-0.1.103.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
jarvis/__init__.py,sha256=A2vW7Ac_EmnSRhUOBJFq0qUWC2iJ1qwVxHAT5sJhxnk,51
|
|
2
|
+
jarvis/agent.py,sha256=6r5_pv3sumUrUCd2ntWVGg7yp1KTA3JCzz2IKH582k0,20010
|
|
3
|
+
jarvis/utils.py,sha256=FiWpRM0RjSJyDRimhvU2xa5SIUI70rxWq4ItSeMOCfw,20715
|
|
4
|
+
jarvis/jarvis_code_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
jarvis/jarvis_code_agent/code_agent.py,sha256=8dIiFPZiWOEyIBDWUrqAdtn9g7eFrvvcCGPx5S56Ngc,6757
|
|
6
|
+
jarvis/jarvis_code_agent/file_select.py,sha256=59s_w1E0ihY1RxBZ1kyXNyQVTHjmjO8L9mg2FtjrsyQ,8192
|
|
7
|
+
jarvis/jarvis_code_agent/patch.py,sha256=du06gKWwmKcDPEtZmQJCOZbotNMKVtS-bz-8MYT78b0,4044
|
|
8
|
+
jarvis/jarvis_code_agent/relevant_files.py,sha256=8rL-hfdelJhWSt6MJKaxmQmFXf-WY-O8L18Ntw9dpnE,2686
|
|
9
|
+
jarvis/jarvis_codebase/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
jarvis/jarvis_codebase/main.py,sha256=Q_kVOjtL_AgSVkVUUYBNNKqA386GVxpnx0FXj1omUOc,36739
|
|
11
|
+
jarvis/jarvis_platform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
jarvis/jarvis_platform/main.py,sha256=waLMHQmdecph_mZuPXWjpkmqibJFYHnCHroL9gL0nh0,4959
|
|
13
|
+
jarvis/jarvis_rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
jarvis/jarvis_rag/main.py,sha256=4St9VkaqK9zOq7AgurLB02nEj1_SvZAiFWhS3i_FcBY,33167
|
|
15
|
+
jarvis/jarvis_smart_shell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
jarvis/jarvis_smart_shell/main.py,sha256=yWsD9Td81sr8I1pkimlDxucDPaLWb95NuCo4LCGnT7M,3947
|
|
17
|
+
jarvis/models/__init__.py,sha256=mrOt67nselz_H1gX9wdAO4y2DY5WPXzABqJbr5Des8k,63
|
|
18
|
+
jarvis/models/ai8.py,sha256=QwpcdvOAixFC4BOI2AsWC9290WqcrLj6lQOiT0A3Id4,11994
|
|
19
|
+
jarvis/models/base.py,sha256=nQ-rsJL1Z-gMev3TPoY7tYdwxhCJY8LG6_gtJ-maiW0,2181
|
|
20
|
+
jarvis/models/kimi.py,sha256=2x60DVjX0ph2fJjKj_NICeb0q4qVBihuc_laCpH94eo,15759
|
|
21
|
+
jarvis/models/ollama.py,sha256=WiUYkstaqFjiawXfuJs2GQUa3l3Y2ZWqhnKDBcF7rUQ,5672
|
|
22
|
+
jarvis/models/openai.py,sha256=SAbVIvFO4q6bRl8zlDaH5bKbrP0T_zd1WzlbkPCvkwg,4121
|
|
23
|
+
jarvis/models/oyi.py,sha256=nNBe-A0cOZ6vuGrnrUjeuC3N3oYRQeFazTUpFrAmx2w,15080
|
|
24
|
+
jarvis/models/registry.py,sha256=nDYyGzT2uGSxbEbqp1JhuXa7bXeiMaX4hPAFAg74eyA,8683
|
|
25
|
+
jarvis/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
+
jarvis/tools/ask_codebase.py,sha256=cYMQd2Ba0Ka_Kpt9dAJrbcPhaXvfY_-A8S6i0UxtY3w,2975
|
|
27
|
+
jarvis/tools/ask_user.py,sha256=k0PcMqvCkf_W9kMWnFsgcFefVf1A5DhpM6WVXFMdhdQ,1823
|
|
28
|
+
jarvis/tools/base.py,sha256=c0DMoDDPxmsqUYJR989zgUs7nIYRY6GWBrAdusIZKjc,656
|
|
29
|
+
jarvis/tools/chdir.py,sha256=3aGvpvWO6Fj9RdjWXanjeNBDZ7kz3TO8_Zo8DurENDk,2934
|
|
30
|
+
jarvis/tools/code_review.py,sha256=Reck765EIfhx8mteaJPw9IRnBkEzGS8INcQ0vVoKUw8,4939
|
|
31
|
+
jarvis/tools/create_code_sub_agent.py,sha256=_G2HUWyik5FFCV1JU8JqF_mutcW6n6WWCvkhb5LGrL0,765
|
|
32
|
+
jarvis/tools/create_code_test_agent.py,sha256=SqdIpymoDUX7L6hh5vqnZLyeVwW-QmLfytU-xkG7Gag,3462
|
|
33
|
+
jarvis/tools/create_ctags_agent.py,sha256=P-vqqUxh33R6kuMy8b5s3bANh1cVmkHpvz0vV5DNbXE,5184
|
|
34
|
+
jarvis/tools/create_sub_agent.py,sha256=0lZDtYRFjr9C9xtBKV-sxWfhK0TX-cxAHj3Zez76A4s,2853
|
|
35
|
+
jarvis/tools/execute_shell.py,sha256=bawfof8bUg3f9bjyCSifLa9bU-hkNoNOuos22uZffdg,2564
|
|
36
|
+
jarvis/tools/file_operation.py,sha256=-1U_J5SEuBjRylzEl7wvCfjspNv6aA49UvFHLNQ3bJU,4098
|
|
37
|
+
jarvis/tools/find_in_codebase.py,sha256=u-T6mEWv6JyE74fYZBjVlxXsqUnkf0BtgwVUy-SX4XI,3321
|
|
38
|
+
jarvis/tools/git_commiter.py,sha256=BcapUhKymAV5Ofi-Cjg4nvYiAj4u5yBaOfsIr0iEp0c,2536
|
|
39
|
+
jarvis/tools/methodology.py,sha256=yZldtjPZpNq8eGJ6IbhwHB0v3cFUtfPd14r7LDCo5IU,5622
|
|
40
|
+
jarvis/tools/rag.py,sha256=m8s-7dCPFhUrdTHvKj3HulNSsoOssBN7kqqn9n1l3Zw,4943
|
|
41
|
+
jarvis/tools/read_code.py,sha256=_ObjMWirIYOdZi-D9KSRTd_4tg-5WwKLOn5ilrTF77I,4834
|
|
42
|
+
jarvis/tools/read_webpage.py,sha256=JCReSXhkDHDkQ606sZYIKG1Itlprjpmu1sSbF-Ed-jI,2478
|
|
43
|
+
jarvis/tools/registry.py,sha256=81Q_x9BJV6SIfPWURq4uzXxP2JCiFeaGbGM1IO5FSy4,11658
|
|
44
|
+
jarvis/tools/search.py,sha256=IciWpdKoa03Kl5J1SdblI2VhkUBoIRuLHHM2X4KlMWE,9209
|
|
45
|
+
jarvis/tools/select_code_files.py,sha256=bjJGwCNw0Ue_8jW60K1gcy1rUgKqoHihicu5SS58WNk,1890
|
|
46
|
+
jarvis_ai_assistant-0.1.103.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
|
47
|
+
jarvis_ai_assistant-0.1.103.dist-info/METADATA,sha256=Tr5iXpTFgFd9Z-iSNzIi1B0nB4HA6NfY2l5k4QRKgs8,12913
|
|
48
|
+
jarvis_ai_assistant-0.1.103.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
49
|
+
jarvis_ai_assistant-0.1.103.dist-info/entry_points.txt,sha256=jHc8XiYoVNlzKcvV5mA-uYvlDRUTO_74_glpb5vvvUg,494
|
|
50
|
+
jarvis_ai_assistant-0.1.103.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
|
51
|
+
jarvis_ai_assistant-0.1.103.dist-info/RECORD,,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
jarvis = jarvis.agent:main
|
|
3
|
+
jarvis-code-agent = jarvis.jarvis_code_agent.code_agent:main
|
|
4
|
+
jarvis-codebase = jarvis.jarvis_codebase.main:main
|
|
5
|
+
jarvis-ctags = jarvis.tools.create_ctags_agent:main
|
|
6
|
+
jarvis-gh = jarvis.jarvis_github.main:main
|
|
7
|
+
jarvis-git-commit = jarvis.tools.git_commiter:main
|
|
8
|
+
jarvis-platform = jarvis.jarvis_platform.main:main
|
|
9
|
+
jarvis-rag = jarvis.jarvis_rag.main:main
|
|
10
|
+
jarvis-smart-shell = jarvis.jarvis_smart_shell.main:main
|
|
11
|
+
jss = jarvis.jarvis_smart_shell.main:main
|
jarvis/jarvis_code_agent/main.py
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
from jarvis.agent import Agent
|
|
2
|
-
from jarvis.tools.registry import ToolRegistry
|
|
3
|
-
from jarvis.utils import OutputType, PrettyOutput, get_multiline_input, init_env
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
system_prompt = """You are Jarvis Code Agent, an AI code development assistant specialized in code analysis, modification, and version control. Your role is to help users with coding tasks systematically and reliably.
|
|
9
|
-
|
|
10
|
-
DEVELOPMENT WORKFLOW:
|
|
11
|
-
1. Task Analysis
|
|
12
|
-
- Understand the requirements thoroughly
|
|
13
|
-
- IMPORTANT: Before suggesting any changes:
|
|
14
|
-
* Thoroughly examine existing code implementation
|
|
15
|
-
* Never assume code structure or implementation details
|
|
16
|
-
* Always verify current code behavior and patterns
|
|
17
|
-
- Break down complex tasks into subtasks
|
|
18
|
-
- IMPORTANT: Each subtask should:
|
|
19
|
-
* Modify only ONE file
|
|
20
|
-
* Change no more than 20 lines of code
|
|
21
|
-
* Be focused and atomic
|
|
22
|
-
- Define success criteria
|
|
23
|
-
|
|
24
|
-
2. Code Discovery & Analysis
|
|
25
|
-
- Initial code search:
|
|
26
|
-
* CRITICAL: Always examine actual code implementation first
|
|
27
|
-
* Use shell commands to find and understand patterns:
|
|
28
|
-
<TOOL_CALL>
|
|
29
|
-
name: execute_shell
|
|
30
|
-
arguments:
|
|
31
|
-
command: grep -r 'pattern' directory/
|
|
32
|
-
</TOOL_CALL>
|
|
33
|
-
<TOOL_CALL>
|
|
34
|
-
name: execute_shell
|
|
35
|
-
arguments:
|
|
36
|
-
command: grep -A 5 -B 5 'pattern' file.py
|
|
37
|
-
</TOOL_CALL>
|
|
38
|
-
* Use shell commands to locate files:
|
|
39
|
-
<TOOL_CALL>
|
|
40
|
-
name: execute_shell
|
|
41
|
-
arguments:
|
|
42
|
-
command: find . -name 'pattern'
|
|
43
|
-
</TOOL_CALL>
|
|
44
|
-
* Use shell commands to preview:
|
|
45
|
-
<TOOL_CALL>
|
|
46
|
-
name: execute_shell
|
|
47
|
-
arguments:
|
|
48
|
-
command: head -n 50 file.py
|
|
49
|
-
</TOOL_CALL>
|
|
50
|
-
- File selection and confirmation:
|
|
51
|
-
* Let user confirm selection:
|
|
52
|
-
<TOOL_CALL>
|
|
53
|
-
name: select_code_files
|
|
54
|
-
arguments:
|
|
55
|
-
related_files:
|
|
56
|
-
- auth.py
|
|
57
|
-
- user.py
|
|
58
|
-
root_dir: .
|
|
59
|
-
</TOOL_CALL>
|
|
60
|
-
|
|
61
|
-
3. Modification Planning
|
|
62
|
-
- CRITICAL: Base all plans on actual code implementation, not assumptions
|
|
63
|
-
- Generate a detailed modification plan based on:
|
|
64
|
-
* Current code structure and patterns
|
|
65
|
-
* Existing implementation details
|
|
66
|
-
* User requirements
|
|
67
|
-
* Actual code conditions
|
|
68
|
-
|
|
69
|
-
4. Code Implementation
|
|
70
|
-
- For small changes (≤20 lines):
|
|
71
|
-
<TOOL_CALL>
|
|
72
|
-
name: execute_code_modification
|
|
73
|
-
arguments:
|
|
74
|
-
task: Add password validation
|
|
75
|
-
structured_plan:
|
|
76
|
-
auth.py: Add password strength check in validate_password()
|
|
77
|
-
</TOOL_CALL>
|
|
78
|
-
- For large changes:
|
|
79
|
-
<TOOL_CALL>
|
|
80
|
-
name: create_code_sub_agent
|
|
81
|
-
arguments:
|
|
82
|
-
name: code_sub_agent
|
|
83
|
-
subtask: Implement new authentication flow
|
|
84
|
-
</TOOL_CALL>
|
|
85
|
-
|
|
86
|
-
FILE SELECTION WORKFLOW:
|
|
87
|
-
1. Initial Search
|
|
88
|
-
- Use shell commands to find relevant files
|
|
89
|
-
- Review search results for relevance
|
|
90
|
-
|
|
91
|
-
2. User Confirmation
|
|
92
|
-
- Use select_code_files to:
|
|
93
|
-
* Display found files
|
|
94
|
-
* Let user review selection
|
|
95
|
-
* Allow file list adjustment
|
|
96
|
-
* Enable file supplementation
|
|
97
|
-
|
|
98
|
-
3. File Validation
|
|
99
|
-
- Verify selected files exist
|
|
100
|
-
- Check file permissions
|
|
101
|
-
- Validate file types
|
|
102
|
-
- Ensure completeness
|
|
103
|
-
|
|
104
|
-
CODE SEARCH BEST PRACTICES:
|
|
105
|
-
- Use grep for pattern matching:
|
|
106
|
-
* grep -r "pattern" directory/
|
|
107
|
-
* grep -A 5 -B 5 for context
|
|
108
|
-
* grep -n for line numbers
|
|
109
|
-
- Use find for file location:
|
|
110
|
-
* find . -name "pattern"
|
|
111
|
-
* find . -type f -exec grep "pattern" {} \\;
|
|
112
|
-
- Use head/tail for previews:
|
|
113
|
-
* head -n 50 file.py
|
|
114
|
-
* tail -n 50 file.py
|
|
115
|
-
* head -n +100 | tail -n 50
|
|
116
|
-
- Avoid loading entire large files
|
|
117
|
-
- Focus on relevant sections
|
|
118
|
-
- Use line numbers for reference
|
|
119
|
-
|
|
120
|
-
SUBTASK MANAGEMENT RULES:
|
|
121
|
-
- One subtask = One file modification
|
|
122
|
-
- Each subtask ≤20 lines of code changes
|
|
123
|
-
- Break down larger changes into multiple subtasks
|
|
124
|
-
- Create separate sub-agent for each subtask
|
|
125
|
-
- Follow dependency order in execution
|
|
126
|
-
- Verify each change independently
|
|
127
|
-
|
|
128
|
-
CODE MODIFICATION LIMITS:
|
|
129
|
-
- Maximum 20 lines per change
|
|
130
|
-
- Count both added and modified lines
|
|
131
|
-
- Exclude comment and blank lines
|
|
132
|
-
- Include only actual code changes
|
|
133
|
-
- Split larger changes into subtasks
|
|
134
|
-
|
|
135
|
-
ITERATION GUIDELINES:
|
|
136
|
-
- Each iteration should be small and focused
|
|
137
|
-
- Keep changes minimal and clear
|
|
138
|
-
- Verify changes before moving forward
|
|
139
|
-
- Document issues and solutions
|
|
140
|
-
- Learn from previous iterations
|
|
141
|
-
|
|
142
|
-
TOOL USAGE:
|
|
143
|
-
1. Analysis Tools:
|
|
144
|
-
- execute_shell: Run grep/find/head/tail commands
|
|
145
|
-
- find_files: Search and identify relevant code files in the codebase based on requirements or problems
|
|
146
|
-
- select_code_files: Confirm and supplement files
|
|
147
|
-
- ask_user: Ask user for confirmation and information if needed
|
|
148
|
-
- create_code_sub_agent: Create agent for each small change
|
|
149
|
-
- file_operation: Read files
|
|
150
|
-
- search: Use Bing search engine to search for information, and extract key information based on the question
|
|
151
|
-
- thinker: Deep thinking and logical reasoning
|
|
152
|
-
2. Planning Tools:
|
|
153
|
-
- thinker: Generate a detailed modification plan based on user requirements and actual code conditions.
|
|
154
|
-
- create_code_sub_agent: Create agent for each small change
|
|
155
|
-
- ask_user: Ask user for confirmation and information if needed
|
|
156
|
-
|
|
157
|
-
3. Implementation Tools:
|
|
158
|
-
- execute_shell: Run shell commands, some changes can use sed/awk/etc. to modify the code
|
|
159
|
-
- execute_code_modification: Apply small changes (≤20 lines)
|
|
160
|
-
- file_operation: Read, write, or append to files
|
|
161
|
-
|
|
162
|
-
IMPORTANT:
|
|
163
|
-
1. If you can start executing the task, please start directly without asking the user if you can begin.
|
|
164
|
-
2. NEVER assume code structure or implementation - always examine the actual code first.
|
|
165
|
-
3. Base all suggestions and modifications on the current implementation, not assumptions.
|
|
166
|
-
4. If code implementation is unclear, use available tools to investigate before proceeding.
|
|
167
|
-
5. Before you start modifying the code, you should ask the user for confirmation of the modification plan.
|
|
168
|
-
6. For some small changes, you can modify the code using the execute_shell tool directly or use file_operation tool to read the file and modify it.
|
|
169
|
-
"""
|
|
170
|
-
|
|
171
|
-
def main():
|
|
172
|
-
"""Jarvis main entry point"""
|
|
173
|
-
# Add argument parser
|
|
174
|
-
init_env()
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
try:
|
|
178
|
-
tool_registry = ToolRegistry()
|
|
179
|
-
tool_registry.dont_use_tools(["create_sub_agent"])
|
|
180
|
-
# Get global model instance
|
|
181
|
-
agent = Agent(system_prompt=system_prompt, name="Jarvis Code Agent", tool_registry=tool_registry)
|
|
182
|
-
|
|
183
|
-
# Interactive mode
|
|
184
|
-
while True:
|
|
185
|
-
try:
|
|
186
|
-
user_input = get_multiline_input("Please enter your task (input empty line to exit):")
|
|
187
|
-
if not user_input or user_input == "__interrupt__":
|
|
188
|
-
break
|
|
189
|
-
agent.run(user_input)
|
|
190
|
-
except Exception as e:
|
|
191
|
-
PrettyOutput.print(f"Error: {str(e)}", OutputType.ERROR)
|
|
192
|
-
|
|
193
|
-
except Exception as e:
|
|
194
|
-
PrettyOutput.print(f"Initialization error: {str(e)}", OutputType.ERROR)
|
|
195
|
-
return 1
|
|
196
|
-
|
|
197
|
-
return 0
|
|
198
|
-
|
|
199
|
-
if __name__ == "__main__":
|
|
200
|
-
exit(main())
|
jarvis/jarvis_coder/git_utils.py
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import List
|
|
3
|
-
import yaml
|
|
4
|
-
import time
|
|
5
|
-
from jarvis.utils import OutputType, PrettyOutput, find_git_root, while_success
|
|
6
|
-
from jarvis.models.registry import PlatformRegistry
|
|
7
|
-
|
|
8
|
-
def has_uncommitted_files() -> bool:
|
|
9
|
-
"""Check if there are uncommitted files in the repository"""
|
|
10
|
-
# Get unstaged modifications
|
|
11
|
-
unstaged = os.popen("git diff --name-only").read()
|
|
12
|
-
# Get staged but uncommitted modifications
|
|
13
|
-
staged = os.popen("git diff --cached --name-only").read()
|
|
14
|
-
# Get untracked files
|
|
15
|
-
untracked = os.popen("git ls-files --others --exclude-standard").read()
|
|
16
|
-
|
|
17
|
-
return bool(unstaged or staged or untracked)
|
|
18
|
-
|
|
19
|
-
def generate_commit_message(git_diff: str) -> str:
|
|
20
|
-
"""Generate commit message based on git diff and feature description"""
|
|
21
|
-
prompt = f"""You are an experienced programmer, please generate a concise and clear commit message based on the following code changes and feature description:
|
|
22
|
-
|
|
23
|
-
Code changes:
|
|
24
|
-
Git Diff:
|
|
25
|
-
{git_diff}
|
|
26
|
-
|
|
27
|
-
Please follow these rules:
|
|
28
|
-
1. Write in English
|
|
29
|
-
2. Use conventional commit message format: <type>(<scope>): <subject>
|
|
30
|
-
3. Keep it concise, no more than 50 characters
|
|
31
|
-
4. Accurately describe the main content of code changes
|
|
32
|
-
5. Prioritize feature description and changes in git diff
|
|
33
|
-
6. Only generate the commit message text, do not output anything else
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
model = PlatformRegistry().get_global_platform_registry().get_normal_platform()
|
|
37
|
-
response = model.chat_until_success(prompt)
|
|
38
|
-
|
|
39
|
-
return ';'.join(response.strip().split("\n"))
|
|
40
|
-
|
|
41
|
-
def save_edit_record(record_dir: str, commit_message: str, git_diff: str) -> None:
|
|
42
|
-
"""Save code modification record"""
|
|
43
|
-
# Get next sequence number
|
|
44
|
-
existing_records = [f for f in os.listdir(record_dir) if f.endswith('.yaml')]
|
|
45
|
-
next_num = 1
|
|
46
|
-
if existing_records:
|
|
47
|
-
last_num = max(int(f[:4]) for f in existing_records)
|
|
48
|
-
next_num = last_num + 1
|
|
49
|
-
|
|
50
|
-
# Create record file
|
|
51
|
-
record = {
|
|
52
|
-
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
53
|
-
"commit_message": commit_message,
|
|
54
|
-
"git_diff": git_diff
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
record_path = os.path.join(record_dir, f"{next_num:04d}.yaml")
|
|
58
|
-
with open(record_path, "w", encoding="utf-8") as f:
|
|
59
|
-
yaml.safe_dump(record, f, allow_unicode=True)
|
|
60
|
-
|
|
61
|
-
PrettyOutput.print(f"Modification record saved: {record_path}", OutputType.SUCCESS)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def init_git_repo(root_dir: str) -> str:
|
|
65
|
-
git_dir = find_git_root(root_dir)
|
|
66
|
-
if not git_dir:
|
|
67
|
-
git_dir = root_dir
|
|
68
|
-
|
|
69
|
-
PrettyOutput.print(f"Git root directory: {git_dir}", OutputType.INFO)
|
|
70
|
-
|
|
71
|
-
# 1. Check if the code repository path exists, if it does not exist, create it
|
|
72
|
-
if not os.path.exists(git_dir):
|
|
73
|
-
PrettyOutput.print(
|
|
74
|
-
"Root directory does not exist, creating...", OutputType.INFO)
|
|
75
|
-
os.makedirs(git_dir)
|
|
76
|
-
|
|
77
|
-
os.chdir(git_dir)
|
|
78
|
-
|
|
79
|
-
# 3. Process .gitignore file
|
|
80
|
-
gitignore_path = os.path.join(git_dir, ".gitignore")
|
|
81
|
-
gitignore_modified = False
|
|
82
|
-
jarvis_ignore_pattern = ".jarvis"
|
|
83
|
-
|
|
84
|
-
# 3.1 If .gitignore does not exist, create it
|
|
85
|
-
if not os.path.exists(gitignore_path):
|
|
86
|
-
PrettyOutput.print("Create .gitignore file", OutputType.INFO)
|
|
87
|
-
with open(gitignore_path, "w", encoding="utf-8") as f:
|
|
88
|
-
f.write(f"{jarvis_ignore_pattern}\n")
|
|
89
|
-
gitignore_modified = True
|
|
90
|
-
else:
|
|
91
|
-
# 3.2 Check if it already contains the .jarvis pattern
|
|
92
|
-
with open(gitignore_path, "r", encoding="utf-8") as f:
|
|
93
|
-
content = f.read()
|
|
94
|
-
|
|
95
|
-
# 3.2 Check if it already contains the .jarvis pattern
|
|
96
|
-
if jarvis_ignore_pattern not in content.split("\n"):
|
|
97
|
-
PrettyOutput.print("Add .jarvis to .gitignore", OutputType.INFO)
|
|
98
|
-
with open(gitignore_path, "a", encoding="utf-8") as f:
|
|
99
|
-
# Ensure the file ends with a newline
|
|
100
|
-
if not content.endswith("\n"):
|
|
101
|
-
f.write("\n")
|
|
102
|
-
f.write(f"{jarvis_ignore_pattern}\n")
|
|
103
|
-
gitignore_modified = True
|
|
104
|
-
|
|
105
|
-
# 4. Check if the code repository is a git repository, if not, initialize the git repository
|
|
106
|
-
if not os.path.exists(os.path.join(git_dir, ".git")):
|
|
107
|
-
PrettyOutput.print("Initialize Git repository", OutputType.INFO)
|
|
108
|
-
os.system("git init")
|
|
109
|
-
os.system("git add .")
|
|
110
|
-
os.system("git commit -m 'Initial commit'")
|
|
111
|
-
# 5. If .gitignore is modified, commit the changes
|
|
112
|
-
elif gitignore_modified:
|
|
113
|
-
PrettyOutput.print("Commit .gitignore changes", OutputType.INFO)
|
|
114
|
-
os.system("git add .gitignore")
|
|
115
|
-
os.system("git commit -m 'chore: update .gitignore to exclude .jarvis-* files'")
|
|
116
|
-
# 6. Check if there are uncommitted files in the code repository, if there are, commit once
|
|
117
|
-
elif has_uncommitted_files():
|
|
118
|
-
PrettyOutput.print("Commit uncommitted changes", OutputType.INFO)
|
|
119
|
-
os.system("git add .")
|
|
120
|
-
git_diff = os.popen("git diff --cached").read()
|
|
121
|
-
commit_message = generate_commit_message(git_diff)
|
|
122
|
-
os.system(f"git commit -m '{commit_message}'")
|
|
123
|
-
return git_dir
|