This repository was archived by the owner on Apr 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·146 lines (122 loc) · 4.72 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·146 lines (122 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# CodeStruct Setup Script
# Creates a virtual environment and installs all dependencies
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "=== CodeStruct Setup ==="
echo ""
# 1. Check Python version
PYTHON_CMD=""
for cmd in python3.11 python3.12 python3; do
if command -v "$cmd" &>/dev/null; then
version=$("$cmd" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
if [ "$major" -eq 3 ] && [ "$minor" -ge 11 ]; then
PYTHON_CMD="$cmd"
break
fi
fi
done
if [ -z "$PYTHON_CMD" ]; then
echo "❌ Error: Python >= 3.11 is required but not found."
echo " Available: $(python3 --version 2>&1 || echo 'none')"
echo " Please install Python 3.11+ and try again."
exit 1
fi
echo "✅ Using Python: $PYTHON_CMD ($($PYTHON_CMD --version 2>&1))"
# 2. Create virtual environment
if [ -d "venv" ]; then
echo "ℹ️ Virtual environment already exists at venv/"
echo " To recreate, run: rm -rf venv && ./setup.sh"
else
echo "📦 Creating virtual environment..."
"$PYTHON_CMD" -m venv venv
echo "✅ Virtual environment created at venv/"
fi
# 3. Activate venv
source venv/bin/activate
echo "✅ Activated virtual environment (Python $(python --version 2>&1))"
# 4. Upgrade pip
echo "📦 Upgrading pip..."
pip install --upgrade pip -q
# 5. Install tree-sitter dependencies (CRITICAL: must be installed BEFORE SWE-agent)
echo "📦 Installing tree-sitter dependencies (version-pinned)..."
pip install "tree-sitter==0.21.3" "tree-sitter-languages==1.10.2" -q
echo "✅ tree-sitter 0.21.3 + tree-sitter-languages 1.10.2 installed"
# 6. Install SWE-agent
echo "📦 Installing SWE-agent..."
cd SWE-agent
mkdir -p trajectories
pip install -e . -q
cd ..
echo "✅ SWE-agent installed"
# 7. Install swebench for evaluation
echo "📦 Installing swebench..."
pip install swebench -q
echo "✅ swebench installed"
# 8. Verify installation
echo ""
echo "=== Verifying Installation ==="
python -c "
import warnings
warnings.filterwarnings('ignore')
from tree_sitter_languages import get_parser
p = get_parser('python')
tree = p.parse(b'def hello(): return 42')
assert tree.root_node.type == 'module', 'tree-sitter parse failed'
print(' ✅ tree-sitter + tree-sitter-languages: OK')
import sweagent
print(f' ✅ SWE-agent: v{sweagent.__version__}')
import swerex
print(f' ✅ SWE-ReX: available')
import swebench
print(f' ✅ swebench: available')
"
# 9. Test AST tools
echo ""
echo "=== Testing AST Tools ==="
# Test readCode
output=$(python SWE-agent/tools/ast_read/bin/readCode SWE-agent/tools/ast_edit/lib/ast_utils.py 2>&1)
if echo "$output" | grep -q "Signatures in"; then
echo " ✅ readCode: signatures extraction works"
else
echo " ❌ readCode: FAILED"
echo " Output: $output"
fi
# Test readCode selector
output=$(python SWE-agent/tools/ast_read/bin/readCode SWE-agent/tools/ast_edit/lib/ast_utils.py --selector is_class_node 2>&1)
if echo "$output" | grep -q "Found"; then
echo " ✅ readCode: selector search works"
else
echo " ❌ readCode selector: FAILED"
fi
# Test editCode
cat > /tmp/_codestruct_test.py << 'TESTEOF'
class Foo:
def bar(self):
return 1
TESTEOF
PYTHONPATH=SWE-agent/tools/ast_edit/lib python SWE-agent/tools/ast_edit/bin/editCode /tmp/_codestruct_test.py insert_node Foo --replacement "def baz(self):
return 2" 2>&1 | grep -q "Successfully" && echo " ✅ editCode: insert_node works" || echo " ❌ editCode insert_node: FAILED"
PYTHONPATH=SWE-agent/tools/ast_edit/lib python SWE-agent/tools/ast_edit/bin/editCode /tmp/_codestruct_test.py delete_node baz 2>&1 | grep -q "Successfully" && echo " ✅ editCode: delete_node works" || echo " ❌ editCode delete_node: FAILED"
PYTHONPATH=SWE-agent/tools/ast_edit/lib python SWE-agent/tools/ast_edit/bin/editCode /tmp/_codestruct_test.py replace_node bar --replacement "def bar(self):
return 42" 2>&1 | grep -q "Successfully" && echo " ✅ editCode: replace_node works" || echo " ❌ editCode replace_node: FAILED"
rm -f /tmp/_codestruct_test.py
echo ""
echo "=== Setup Complete ==="
echo ""
echo "To activate the environment:"
echo " source venv/bin/activate"
echo ""
echo "To run experiments (after setting API keys):"
echo " cd SWE-agent"
echo " python -m sweagent run-batch \\"
echo " --instances.type swe_bench --instances.subset verified --instances.split test \\"
echo " --config config/default_with_readcode_batch.yaml \\"
echo " --agent.model.name gpt-5-mini \\"
echo " --agent.model.per_instance_cost_limit 3.00 \\"
echo " --instances.slice :5 --num_workers 5"
echo ""
echo "See REPRODUCE.md for full instructions."