Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·373 lines (316 loc) · 12.1 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·373 lines (316 loc) · 12.1 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/env bash
# ============================================================================
# ScienceClaw — One-Click Setup
# Make Research Easier Across All Disciplines
# ============================================================================
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
BOLD='\033[1m'
print_banner() {
echo -e "${CYAN}"
echo " ╔══════════════════════════════════════════════════════════╗"
echo " ║ ║"
echo " ║ 🦞 ScienceClaw — AI Research Gateway ║"
echo " ║ Make Research Easier Across All Disciplines ║"
echo " ║ ║"
echo " ╚══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
log_step() { echo -e "\n${BLUE}[$(date +%H:%M:%S)]${NC} ${BOLD}▶ $1${NC}"; }
log_ok() { echo -e " ${GREEN}✅ $1${NC}"; }
log_warn() { echo -e " ${YELLOW}⚠️ $1${NC}"; }
log_err() { echo -e " ${RED}❌ $1${NC}"; }
log_info() { echo -e " ${CYAN}ℹ️ $1${NC}"; }
# ---- Detect OS ----
detect_os() {
case "$(uname -s)" in
Darwin*) OS="macos" ;;
Linux*) OS="linux" ;;
*) OS="unknown" ;;
esac
echo "$OS"
}
# ---- Check and install prerequisites ----
check_command() {
if command -v "$1" &>/dev/null; then
log_ok "$1 found: $(command -v "$1")"
return 0
else
return 1
fi
}
install_brew() {
if ! check_command brew; then
log_step "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
install_node() {
if check_command node; then
NODE_VER=$(node -v | sed 's/v//' | cut -d. -f1)
if [ "$NODE_VER" -ge 20 ]; then
log_ok "Node.js v$(node -v) (>= 20 required)"
return
else
log_warn "Node.js $(node -v) is too old, need >= 20"
fi
fi
log_step "Installing Node.js 20+..."
if [ "$OS" = "macos" ]; then
brew install node@22
else
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
}
install_pnpm() {
if ! check_command pnpm; then
log_step "Installing pnpm..."
npm install -g pnpm
fi
}
install_python() {
if check_command python3; then
PY_VER=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
log_ok "Python $PY_VER found"
else
log_step "Installing Python 3..."
if [ "$OS" = "macos" ]; then
brew install python@3.12
else
sudo apt-get install -y python3 python3-pip python3-venv
fi
fi
}
install_uv() {
if ! check_command uv; then
log_step "Installing uv (Python package manager)..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
fi
}
# ---- Install Node.js dependencies ----
install_node_deps() {
log_step "Installing Node.js dependencies..."
pnpm install --no-frozen-lockfile 2>&1 | tail -5
log_ok "Node.js dependencies installed"
}
# ---- Install Python scientific packages ----
install_python_deps() {
log_step "Installing Python scientific packages..."
# Core scientific stack
CORE_PACKAGES=(
numpy scipy statsmodels scikit-learn matplotlib pandas
sympy networkx plotly seaborn polars pyarrow
)
# Bioinformatics & chemistry
BIO_PACKAGES=(
biopython pubchempy chembl_webresource_client
rcsb-api rcsbsearchapi reactome2py
)
# NLP & text
NLP_PACKAGES=(
jieba sentence-transformers
)
# Document processing
DOC_PACKAGES=(
pdfplumber pymupdf pylatexenc Pillow
defusedxml python-dotenv requests
)
# Data & visualization
VIZ_PACKAGES=(
kaleido dash folium cartopy
geopandas mapclassify contextily
)
# Statistics & ML
STAT_PACKAGES=(
lifelines shap scikit-bio semopy
)
# Research tools
RESEARCH_PACKAGES=(
scholarly crossref-commons bibtexparser
asreview bertopic litellm openai
Wikipedia-API GEOparse cdsapi
)
ALL_PACKAGES=("${CORE_PACKAGES[@]}" "${BIO_PACKAGES[@]}" "${NLP_PACKAGES[@]}" \
"${DOC_PACKAGES[@]}" "${VIZ_PACKAGES[@]}" "${STAT_PACKAGES[@]}" \
"${RESEARCH_PACKAGES[@]}")
log_info "Installing ${#ALL_PACKAGES[@]} Python packages..."
# Create a virtual environment for ScienceClaw's Python deps
VENV_DIR="$HOME/.scienceclaw/venv"
if [ ! -d "$VENV_DIR" ]; then
log_info "Creating Python virtual environment at $VENV_DIR..."
mkdir -p "$HOME/.scienceclaw"
uv venv "$VENV_DIR" 2>&1 | tail -1
fi
log_info "Installing packages into virtual environment..."
uv pip install --python "$VENV_DIR/bin/python" "${ALL_PACKAGES[@]}" 2>&1 | tail -5 || {
log_warn "Some packages failed, retrying individually..."
for pkg in "${ALL_PACKAGES[@]}"; do
uv pip install --python "$VENV_DIR/bin/python" "$pkg" 2>/dev/null || log_warn " $pkg failed (optional)"
done
}
log_info "To activate: source $VENV_DIR/bin/activate"
log_ok "Python scientific packages installed"
}
# ---- Install MCP servers ----
install_scienceclaw_engine() {
log_step "Installing the ScienceClaw engine and every tool of its library (packages, pretrained weights, upstream sources)..."
local py="${SCIENCECLAW_PYTHON:-python3}"
"$py" -m pip install --quiet -e "$PWD/packages/scienceclaw[all]" || { log_err "pip install of the engine failed"; return 1; }
if [ "${SCIENCECLAW_SKIP_TOOLS:-0}" = "1" ]; then
log_warn "SCIENCECLAW_SKIP_TOOLS=1: tools will be installed on first use instead (python -m scienceclaw.cli setup)"
return 0
fi
"$py" -m scienceclaw.cli setup --profile "${SCIENCECLAW_SETUP_PROFILE:-full}" \
&& log_ok "ScienceClaw tool library installed" \
|| { log_err "tool installation incomplete: see 'python -m scienceclaw.cli doctor' and ~/.scienceclaw/setup/*.log"; return 1; }
}
install_mcp_servers() {
log_step "Installing MCP servers for academic research..."
MCP_SERVERS=(
"academic-mcp"
"arxiv-mcp-server"
"biomcp"
"semantic-scholar-mcp"
"zotero-mcp"
"deep-research-mcp-server"
)
# MCP servers run via uvx on-demand (no pre-install needed)
# We just verify uvx can resolve them
for server in "${MCP_SERVERS[@]}"; do
log_info "Caching $server..."
uvx --quiet "$server" --help &>/dev/null && log_ok "$server cached" || log_warn "$server not available (will try at runtime)"
done
# Bundled MCP servers (not on PyPI, included in project)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$HOME/.scienceclaw/venv"
if [ -d "$SCRIPT_DIR/mcp-servers/chembl-mcp" ]; then
log_info "Installing ChEMBL MCP dependencies..."
uv pip install --python "$VENV_DIR/bin/python" -r "$SCRIPT_DIR/mcp-servers/chembl-mcp/requirements.txt" 2>&1 | tail -3 || true
log_ok "ChEMBL MCP server ready (bundled)"
fi
if [ -d "$SCRIPT_DIR/mcp-servers/arxiv-latex-mcp" ]; then
log_info "Installing arXiv LaTeX MCP dependencies..."
uv pip install --python "$VENV_DIR/bin/python" httpx "mcp[cli]" "arxiv-to-prompt>=0.10.0" 2>&1 | tail -3 || true
log_ok "arXiv LaTeX MCP server ready (bundled)"
fi
log_ok "MCP servers installed"
}
# ---- Configure ScienceClaw ----
configure_scienceclaw() {
log_step "Configuring ScienceClaw..."
CONFIG_DIR="$HOME/.openclaw"
CONFIG_FILE="$CONFIG_DIR/openclaw.json"
mkdir -p "$CONFIG_DIR"
if [ -f "$CONFIG_FILE" ]; then
log_info "Existing config found, creating backup..."
cp "$CONFIG_FILE" "$CONFIG_FILE.bak.$(date +%Y%m%d%H%M%S)"
fi
VENV_PYTHON="$HOME/.scienceclaw/venv/bin/python"
CHEMBL_SERVER="$HOME/clawd/mcp-servers/chembl-mcp/chembl_server.py"
cat > "$CONFIG_FILE" << JSONEOF
{
"gateway": {
"mode": "local"
},
"plugins": {
"slots": {
"memory": "memory-core"
},
"entries": {
"memory-core": { "enabled": true },
"memory-lancedb": { "enabled": true }
}
},
"agents": {
"defaults": {
"heartbeat": { "interval": 1800 }
}
}
}
JSONEOF
log_ok "Config written to $CONFIG_FILE"
# Run doctor to auto-fix any config issues
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
log_info "Running config validation..."
cd "$SCRIPT_DIR" && npx openclaw doctor --fix 2>&1 | tail -3 || true
log_ok "Config validated"
}
# ---- Setup workspace ----
setup_workspace() {
log_step "Setting up research workspace..."
WORKSPACE="$HOME/clawd"
mkdir -p "$WORKSPACE/skills" "$WORKSPACE/output" "$WORKSPACE/data"
# Copy skills to workspace
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -d "$SCRIPT_DIR/skills" ]; then
log_info "Copying skills to workspace..."
cp -rn "$SCRIPT_DIR/skills/"* "$WORKSPACE/skills/" 2>/dev/null || true
SKILL_COUNT=$(ls -1 "$WORKSPACE/skills/" 2>/dev/null | wc -l | tr -d ' ')
log_ok "$SKILL_COUNT skills available in workspace"
fi
# Copy bundled MCP servers to workspace
if [ -d "$SCRIPT_DIR/mcp-servers" ]; then
log_info "Copying bundled MCP servers..."
mkdir -p "$WORKSPACE/mcp-servers"
cp -rn "$SCRIPT_DIR/mcp-servers/"* "$WORKSPACE/mcp-servers/" 2>/dev/null || true
log_ok "Bundled MCP servers copied"
fi
log_ok "Workspace ready at $WORKSPACE"
}
# ---- Main ----
main() {
print_banner
OS=$(detect_os)
log_info "Detected OS: $OS"
if [ "$OS" = "unknown" ]; then
log_err "Unsupported OS. ScienceClaw supports macOS and Linux."
log_info "For Windows, use WSL2: https://docs.microsoft.com/en-us/windows/wsl/"
exit 1
fi
# Phase 1: Prerequisites
log_step "Phase 1/5: Checking prerequisites..."
[ "$OS" = "macos" ] && install_brew
install_node
install_pnpm
install_python
install_uv
# Phase 2: Node.js
log_step "Phase 2/5: Installing Node.js packages..."
install_node_deps
# Phase 3: Python
log_step "Phase 3/5: Installing Python scientific stack..."
install_python_deps
install_scienceclaw_engine
# Phase 4: MCP Servers
log_step "Phase 4/5: Installing MCP servers..."
install_mcp_servers
# Phase 5: Configure & Launch
log_step "Phase 5/5: Configuring ScienceClaw..."
configure_scienceclaw
setup_workspace
# Done
echo ""
echo -e "${GREEN}${BOLD}"
echo " ╔══════════════════════════════════════════════════════════╗"
echo " ║ ║"
echo " ║ 🦞 ScienceClaw setup complete! ║"
echo " ║ ║"
echo " ║ To start: ║"
echo " ║ npx openclaw onboard (first time) ║"
echo " ║ npx openclaw gateway (start gateway) ║"
echo " ║ ║"
echo " ║ Workspace: ~/clawd ║"
echo " ║ Config: ~/.openclaw/openclaw.json ║"
echo " ║ ║"
echo " ╚══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
main "$@"