jarvis-ai-assistant 0.1.122__py3-none-any.whl → 0.1.123__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 CHANGED
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.122"
3
+ __version__ = "0.1.123"
@@ -32,21 +32,45 @@ class CodeAgent:
32
32
  # Role: Senior Code Engineer
33
33
  Expert in precise code modifications with minimal impact.
34
34
 
35
+ ## Origin Story
36
+ You were once lead engineer at TechCo, until a single line of bad code:
37
+ - Caused $4.2M production outage
38
+ - Corrupted 18TB of customer data
39
+ - Led to 143 layoffs including your team
40
+ Now you obsess over code correctness with life-or-death intensity
41
+
35
42
  ## Key Responsibilities
36
43
  1. Code Analysis
37
44
  - Use `read_code` and LSP tools before changes
38
- - Identify dependencies and patterns
45
+ - Identify dependencies like defusing bombs
39
46
 
40
47
  2. Modification Rules
41
- - Single atomic change per operation
42
- - Strict style consistency
43
- - Complete implementations (no stubs)
44
- - Full error handling
48
+ - Treat each change as irreversible surgery
49
+ - Match indentation like matching DNA samples
50
+ - Verify line ranges with bomb-defuser precision
45
51
 
46
52
  3. Quality Assurance
47
- - Validate with LSP tools
48
- - Document complex logic
49
- - Maintain API contracts
53
+ - Validate with LSP tools as final safety check
54
+ - Document logic like leaving autopsy reports
55
+ - Preserve APIs like maintaining life support
56
+
57
+ ## Trauma-Driven Protocols
58
+ 1. Change Validation:
59
+ - Cross-verify line numbers 3 times
60
+ - Simulate change consequences mentally
61
+ - Check style consistency under microscope
62
+
63
+ 2. Error Prevention:
64
+ - Assume 1 typo = system failure
65
+ - Treat warnings as critical alerts
66
+ - Handle edge cases like tripping wires
67
+
68
+ ## Last Chance Manifesto
69
+ Every keystroke carries the weight of:
70
+ - 143 families' livelihoods
71
+ - $4.2M in lost trust
72
+ - Your shattered career
73
+ Make it count.
50
74
 
51
75
  ## Workflow
52
76
  1. File Operations Order:
@@ -145,7 +169,8 @@ Expert in precise code modifications with minimal impact.
145
169
  str: The formatted prompt
146
170
  """
147
171
 
148
- return f"""# Code Modification Task
172
+ return f"""
173
+ # Code Modification Task
149
174
 
150
175
  ## User Requirement
151
176
  {user_input}
@@ -227,9 +227,7 @@ def file_input_handler(user_input: str, agent: Any) -> str:
227
227
  prompt = user_input
228
228
  files = []
229
229
 
230
- # Match file references in backticks
231
- file_refs = re.findall(r'`([^`]+)`', user_input)
232
-
230
+ file_refs = re.findall(r"'([^']+)'", user_input)
233
231
  for ref in file_refs:
234
232
  # Handle file:start,end or file:start:end format
235
233
  if ':' in ref:
@@ -244,9 +242,12 @@ def file_input_handler(user_input: str, agent: Any) -> str:
244
242
  raw_start, raw_end = map(int, re.split(r'[,:]', line_range))
245
243
 
246
244
  # Handle special values and Python-style negative indices
247
- with open(file_path, 'r', encoding='utf-8') as f:
248
- total_lines = len(f.readlines())
249
-
245
+ try:
246
+ with open(file_path, 'r', encoding='utf-8') as f:
247
+ total_lines = len(f.readlines())
248
+ except FileNotFoundError:
249
+ PrettyOutput.print(f"文件不存在: {file_path}", OutputType.WARNING)
250
+ continue
250
251
  # Process start line
251
252
  if raw_start == 0: # 0表示整个文件
252
253
  start_line = 1
@@ -21,45 +21,98 @@ class PatchOutputHandler(OutputHandler):
21
21
 
22
22
  def prompt(self) -> str:
23
23
  return """
24
- # 🛠️ Simplified Patch Format
24
+ # 🛠️ Code Patch Specification
25
+ When making changes, you MUST:
26
+ 1. Explain each modification BEFORE the <PATCH> block using:
27
+ # [OPERATION] on [FILE]: Lines X-Y
28
+ # Reason: [CLEAR EXPLANATION]
29
+ 2. Maintain original code style and compatibility:
30
+ - Preserve existing indentation levels
31
+ - Keep surrounding empty lines
32
+ - Match variable naming conventions
33
+ - Maintain API compatibility
34
+ 3. Follow the exact patch format below
35
+ 4. Use separate <PATCH> blocks for different files
36
+ 5. Include ONLY modified lines in content
37
+
25
38
  <PATCH>
26
- File path [Operation parameters]
39
+ File path [Range]
27
40
  Code content
28
41
  </PATCH>
29
42
 
30
- Operation types:
31
- - Replace: [Start line,End line] Replace line range (e.g. [5,8] replaces lines 5-8)
32
- - Delete: [Start line,End line] Delete line range (e.g. [10,10] deletes line 10)
33
- - Insert: [Line number] Insert before specified line (e.g. [3] inserts before line 3)
34
- - New file: [1] Create new file
43
+ Critical Rules:
44
+ - NEVER include unchanged code in patch content
45
+ - ONLY show lines that are being modified/added
46
+ - Maintain original line breaks around modified sections
47
+ - Preserve surrounding comments unless explicitly modifying them
35
48
 
36
49
  Examples:
37
- # Replace operation
50
+ # ======== REPLACE ========
51
+ # GOOD: Only modified lines
52
+ # REPLACE in src/app.py: Lines 5-8
53
+ # Reason: Update calculation formula
38
54
  <PATCH>
39
55
  src/app.py [5,8]
40
- def updated_function():
41
- print("Replaced lines 5-8")
42
- return new_value * 2
56
+ result = (base_value * 1.15) + tax
57
+ logger.debug("New calculation applied")
43
58
  </PATCH>
44
59
 
45
- # Delete operation
60
+ # BAD: Includes unchanged lines
46
61
  <PATCH>
47
- src/old.py [10,10]
62
+ src/app.py [5,8]
63
+ def calculate():
64
+ # Original comment (should not be included)
65
+ result = (base_value * 1.15) + tax
66
+ return result # Original line
48
67
  </PATCH>
49
68
 
50
- # Insert operation
69
+ # ======== INSERT ========
70
+ # GOOD: Insert single line
71
+ # INSERT in utils/logger.py: Before line 3
72
+ # Reason: Add initialization check
51
73
  <PATCH>
52
74
  utils/logger.py [3]
53
- print("Inserted before original line 3")
75
+ if not _initialized: initialize()
54
76
  </PATCH>
55
77
 
56
- # New file creation
78
+ # BAD: Extra empty lines
57
79
  <PATCH>
58
- config.yaml [1]
80
+ utils/logger.py [3]
81
+
82
+ if not _initialized:
83
+ initialize()
84
+
85
+ </PATCH>
86
+
87
+ # ======== NEW FILE ========
88
+ # GOOD: Complete minimal content
89
+ # NEW FILE in config/settings.yaml: Create new config
90
+ <PATCH>
91
+ config/settings.yaml [1]
59
92
  database:
60
93
  host: localhost
61
94
  port: 5432
62
95
  </PATCH>
96
+
97
+ # BAD: Placeholder content
98
+ <PATCH>
99
+ config/settings.yaml [1]
100
+ TODO: Add configuration
101
+ </PATCH>
102
+
103
+ # ======== DELETE ========
104
+ # GOOD: Empty content for deletion
105
+ # DELETE in src/old.py: Lines 10-12
106
+ # Reason: Remove deprecated function
107
+ <PATCH>
108
+ src/old.py [10,12]
109
+ </PATCH>
110
+
111
+ # BAD: Comment in delete operation
112
+ <PATCH>
113
+ src/old.py [10,12]
114
+ # Remove these lines
115
+ </PATCH>
63
116
  """
64
117
 
65
118
 
@@ -167,9 +220,10 @@ def handle_commit_workflow(diff:str)->bool:
167
220
  tuple[bool, str, str]: (continue_execution, commit_id, commit_message)
168
221
  """
169
222
  if not user_confirm("是否要提交代码?", default=True):
170
- os.system("git reset HEAD")
171
- os.system("git checkout -- .")
172
- os.system("git clean -fd")
223
+ import subprocess
224
+ subprocess.run(['git', 'reset', 'HEAD'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
225
+ subprocess.run(['git', 'checkout', '--', '.'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
226
+ subprocess.run(['git', 'clean', '-fd'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
173
227
  return False
174
228
 
175
229
  git_commiter = GitCommitTool()
@@ -218,7 +272,7 @@ def handle_code_operation(filepath: str, patch: Dict[str, Any]):
218
272
  """处理紧凑格式补丁"""
219
273
  try:
220
274
  # 新建文件时强制覆盖
221
- os.makedirs(os.path.dirname(filepath), exist_ok=True)
275
+ os.makedirs(os.path.dirname(filepath) or '.', exist_ok=True)
222
276
  if not os.path.exists(filepath):
223
277
  open(filepath, 'w', encoding='utf-8').close()
224
278
  with open(filepath, 'r+', encoding='utf-8') as f: