gitarsenal-cli 1.4.5 → 1.4.6
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.
package/package.json
CHANGED
@@ -720,85 +720,85 @@ Do not provide any explanations, just the exact command to run.
|
|
720
720
|
print(f"❌ All model attempts failed. Last error: {last_error}")
|
721
721
|
return None
|
722
722
|
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
723
|
+
# Process the response
|
724
|
+
try:
|
725
|
+
fix_command = result["choices"][0]["message"]["content"].strip()
|
726
|
+
|
727
|
+
# Save the original response for debugging
|
728
|
+
original_response = fix_command
|
729
|
+
|
730
|
+
# Extract just the command if it's wrapped in backticks or explanation
|
731
|
+
if "```" in fix_command:
|
732
|
+
# Extract content between backticks
|
733
|
+
import re
|
734
|
+
code_blocks = re.findall(r'```(?:bash|sh)?\s*(.*?)\s*```', fix_command, re.DOTALL)
|
735
|
+
if code_blocks:
|
736
|
+
fix_command = code_blocks[0].strip()
|
737
|
+
print(f"✅ Extracted command from code block: {fix_command}")
|
738
|
+
|
739
|
+
# If the response still has explanatory text, try to extract just the command
|
740
|
+
if len(fix_command.split('\n')) > 1:
|
741
|
+
# First try to find lines that look like commands (start with common command prefixes)
|
742
|
+
command_prefixes = ['sudo', 'apt', 'pip', 'npm', 'yarn', 'git', 'cd', 'mv', 'cp', 'rm', 'mkdir', 'touch',
|
743
|
+
'chmod', 'chown', 'echo', 'cat', 'python', 'python3', 'node', 'export',
|
744
|
+
'curl', 'wget', 'docker', 'make', 'gcc', 'g++', 'javac', 'java',
|
745
|
+
'conda', 'uv', 'poetry', 'nvm', 'rbenv', 'pyenv', 'rustup']
|
729
746
|
|
730
|
-
#
|
731
|
-
|
732
|
-
|
733
|
-
import re
|
734
|
-
code_blocks = re.findall(r'```(?:bash|sh)?\s*(.*?)\s*```', fix_command, re.DOTALL)
|
735
|
-
if code_blocks:
|
736
|
-
fix_command = code_blocks[0].strip()
|
737
|
-
print(f"✅ Extracted command from code block: {fix_command}")
|
747
|
+
# Check for lines that start with common command prefixes
|
748
|
+
command_lines = [line.strip() for line in fix_command.split('\n')
|
749
|
+
if any(line.strip().startswith(prefix) for prefix in command_prefixes)]
|
738
750
|
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
# Check for lines that start with common command prefixes
|
751
|
+
if command_lines:
|
752
|
+
# Use the first command line found
|
753
|
+
fix_command = command_lines[0]
|
754
|
+
print(f"✅ Identified command by prefix: {fix_command}")
|
755
|
+
else:
|
756
|
+
# Try to find lines that look like commands (contain common shell patterns)
|
757
|
+
shell_patterns = [' | ', ' > ', ' >> ', ' && ', ' || ', ' ; ', '$(', '`', ' -y ', ' --yes ']
|
748
758
|
command_lines = [line.strip() for line in fix_command.split('\n')
|
749
|
-
|
759
|
+
if any(pattern in line for pattern in shell_patterns)]
|
750
760
|
|
751
761
|
if command_lines:
|
752
762
|
# Use the first command line found
|
753
763
|
fix_command = command_lines[0]
|
754
|
-
print(f"✅ Identified command by
|
764
|
+
print(f"✅ Identified command by shell pattern: {fix_command}")
|
755
765
|
else:
|
756
|
-
#
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
if len(fix_command.split('\n')) > 1 or len(fix_command) > 500:
|
793
|
-
print("⚠️ Extracted command appears invalid (multi-line or too long)")
|
794
|
-
print("🔍 Original response from LLM:")
|
795
|
-
print("-" * 60)
|
796
|
-
print(original_response)
|
797
|
-
print("-" * 60)
|
798
|
-
print("⚠️ Using best guess for command")
|
799
|
-
|
800
|
-
print(f"🔧 Suggested fix: {fix_command}")
|
801
|
-
return fix_command
|
766
|
+
# Fall back to the shortest non-empty line as it's likely the command
|
767
|
+
lines = [line.strip() for line in fix_command.split('\n') if line.strip()]
|
768
|
+
if lines:
|
769
|
+
# Exclude very short lines that are likely not commands
|
770
|
+
valid_lines = [line for line in lines if len(line) > 5]
|
771
|
+
if valid_lines:
|
772
|
+
fix_command = min(valid_lines, key=len)
|
773
|
+
else:
|
774
|
+
fix_command = min(lines, key=len)
|
775
|
+
print(f"✅ Selected shortest line as command: {fix_command}")
|
776
|
+
|
777
|
+
# Clean up the command - remove any trailing periods or quotes
|
778
|
+
fix_command = fix_command.rstrip('.;"\'')
|
779
|
+
|
780
|
+
# Remove common prefixes that LLMs sometimes add
|
781
|
+
prefixes_to_remove = [
|
782
|
+
"Run: ", "Execute: ", "Try: ", "Command: ", "Fix: ", "Solution: ",
|
783
|
+
"You should run: ", "You can run: ", "You need to run: "
|
784
|
+
]
|
785
|
+
for prefix in prefixes_to_remove:
|
786
|
+
if fix_command.startswith(prefix):
|
787
|
+
fix_command = fix_command[len(prefix):].strip()
|
788
|
+
print(f"✅ Removed prefix: {prefix}")
|
789
|
+
break
|
790
|
+
|
791
|
+
# If the command is still multi-line or very long, it might not be a valid command
|
792
|
+
if len(fix_command.split('\n')) > 1 or len(fix_command) > 500:
|
793
|
+
print("⚠️ Extracted command appears invalid (multi-line or too long)")
|
794
|
+
print("🔍 Original response from LLM:")
|
795
|
+
print("-" * 60)
|
796
|
+
print(original_response)
|
797
|
+
print("-" * 60)
|
798
|
+
print("⚠️ Using best guess for command")
|
799
|
+
|
800
|
+
print(f"🔧 Suggested fix: {fix_command}")
|
801
|
+
return fix_command
|
802
802
|
except Exception as e:
|
803
803
|
print(f"❌ Error processing OpenAI response: {e}")
|
804
804
|
return None
|