-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·440 lines (378 loc) · 14.1 KB
/
install.sh
File metadata and controls
executable file
·440 lines (378 loc) · 14.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/bash
# SmartAgent Installer — https://smartagent.org
#
# One command to a personal AI agent with decentralized inference:
# curl -fsSL https://smartagent.org/install.sh | bash
#
# What this does:
# 1. Checks/installs Node.js 22+
# 2. Installs OpenClaw (the AI agent framework)
# 3. Installs Everclaw (decentralized inference via Morpheus)
# 4. Bootstraps decentralized inference (Morpheus API Gateway — no API key needed)
# 5. Pre-configures your agent with sensible defaults
# 6. Starts the agent and opens WebChat in your browser
#
# Requirements: macOS 12+ or Linux (x86_64/arm64), ~500MB disk, internet
set -euo pipefail
# ─── Configuration ───────────────────────────────────────────────────────────
SMARTAGENT_VERSION="0.1.0"
NODE_MIN_VERSION="22"
EVERCLAW_REPO="https://github.com/profbernardoj/everclaw.git"
WORKSPACE="${OPENCLAW_WORKSPACE:-$HOME/.openclaw/workspace}"
SKILL_DIR="$WORKSPACE/skills/everclaw"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# ─── Helpers ─────────────────────────────────────────────────────────────────
log() { echo -e "${GREEN}[smartagent]${NC} $1"; }
warn() { echo -e "${YELLOW}[smartagent]${NC} ⚠️ $1"; }
err() { echo -e "${RED}[smartagent]${NC} ❌ $1"; }
info() { echo -e "${BLUE}[smartagent]${NC} $1"; }
bold() { echo -e "${BOLD}$1${NC}"; }
banner() {
echo ""
echo -e "${CYAN}"
echo " ╔═══════════════════════════════════════════════╗"
echo " ║ ║"
echo " ║ 🤖 SmartAgent v${SMARTAGENT_VERSION} ║"
echo " ║ Your Personal AI Agent ║"
echo " ║ ║"
echo " ║ Powered by OpenClaw + Morpheus ║"
echo " ║ ║"
echo " ╚═══════════════════════════════════════════════╝"
echo -e "${NC}"
echo ""
}
check_os() {
local os
os="$(uname -s)"
case "$os" in
Darwin) OS="macos" ;;
Linux) OS="linux" ;;
*)
err "Unsupported OS: $os"
err "SmartAgent supports macOS and Linux."
exit 1
;;
esac
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) ;; # supported
arm64|aarch64) ;; # supported
*)
err "Unsupported architecture: $arch"
exit 1
;;
esac
log "Detected: $OS ($arch)"
}
# ─── Step 1: Node.js ────────────────────────────────────────────────────────
check_node() {
log "Checking for Node.js ${NODE_MIN_VERSION}+..."
if command -v node &>/dev/null; then
local node_version
node_version="$(node -v | sed 's/v//' | cut -d. -f1)"
if [[ "$node_version" -ge "$NODE_MIN_VERSION" ]]; then
log "Node.js v$(node -v | sed 's/v//') ✓"
return 0
else
warn "Node.js v$(node -v | sed 's/v//') found, but v${NODE_MIN_VERSION}+ required."
fi
fi
install_node
}
install_node() {
log "Installing Node.js ${NODE_MIN_VERSION}..."
# Try fnm first (fast, Rust-based)
if command -v fnm &>/dev/null; then
fnm install "$NODE_MIN_VERSION" && fnm use "$NODE_MIN_VERSION"
return
fi
# Try nvm
if command -v nvm &>/dev/null || [[ -f "$HOME/.nvm/nvm.sh" ]]; then
[[ -f "$HOME/.nvm/nvm.sh" ]] && source "$HOME/.nvm/nvm.sh"
nvm install "$NODE_MIN_VERSION" && nvm use "$NODE_MIN_VERSION"
return
fi
# Install fnm + Node
log "Installing fnm (Node version manager)..."
if [[ "$OS" == "macos" ]] && command -v brew &>/dev/null; then
brew install fnm
else
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
export PATH="$HOME/.local/share/fnm:$PATH"
eval "$(fnm env)"
fi
fnm install "$NODE_MIN_VERSION"
fnm use "$NODE_MIN_VERSION"
# Add to shell config
local shell_config
if [[ -f "$HOME/.zshrc" ]]; then
shell_config="$HOME/.zshrc"
elif [[ -f "$HOME/.bashrc" ]]; then
shell_config="$HOME/.bashrc"
fi
if [[ -n "${shell_config:-}" ]]; then
if ! grep -q "fnm env" "$shell_config" 2>/dev/null; then
echo 'eval "$(fnm env --use-on-cd --shell '"$(basename "$SHELL")"')"' >> "$shell_config"
log "Added fnm to $shell_config"
fi
fi
log "Node.js $(node -v) installed ✓"
}
# ─── Step 2: OpenClaw ───────────────────────────────────────────────────────
check_openclaw() {
log "Checking for OpenClaw..."
if command -v openclaw &>/dev/null; then
local version
version="$(openclaw --version 2>/dev/null | head -1 || echo "unknown")"
log "OpenClaw $version ✓"
return 0
fi
install_openclaw
}
install_openclaw() {
log "Installing OpenClaw..."
# Use OpenClaw's official installer (handles npm + binary)
if curl -fsSL https://clawd.bot/install.sh | bash; then
log "OpenClaw installed ✓"
else
# Fallback to npm
warn "Official installer failed, trying npm..."
npm install -g openclaw
log "OpenClaw installed via npm ✓"
fi
}
# ─── Step 3: Everclaw ───────────────────────────────────────────────────────
install_everclaw() {
log "Installing Everclaw (decentralized inference)..."
if [[ -d "$SKILL_DIR/.git" ]]; then
log "Everclaw already installed, updating..."
cd "$SKILL_DIR" && git pull --quiet
log "Everclaw updated ✓"
return
fi
# Check for ClawHub collision
if [[ -d "$SKILL_DIR" ]]; then
if grep -q "Everclaw Vault\|everclaw.chong-eae.workers.dev" "$SKILL_DIR/SKILL.md" 2>/dev/null; then
warn "ClawHub collision detected — removing 'Everclaw Vault' imposter..."
rm -rf "$SKILL_DIR"
fi
fi
# Install via ClawHub or git
if command -v clawhub &>/dev/null; then
clawhub install everclaw-inference 2>/dev/null || {
warn "ClawHub install failed, falling back to git..."
mkdir -p "$(dirname "$SKILL_DIR")"
git clone --quiet "$EVERCLAW_REPO" "$SKILL_DIR"
}
else
mkdir -p "$(dirname "$SKILL_DIR")"
git clone --quiet "$EVERCLAW_REPO" "$SKILL_DIR"
fi
log "Everclaw installed ✓"
}
# ─── Step 4: Bootstrap Decentralized Inference ───────────────────────────────
bootstrap_inference() {
log "Bootstrapping decentralized inference via Morpheus API Gateway..."
local bootstrap_script="$SKILL_DIR/scripts/bootstrap-gateway.mjs"
if [[ -f "$bootstrap_script" ]]; then
if node "$bootstrap_script" 2>/dev/null; then
log "Decentralized inference configured ✓"
log "Using: mor-gateway/kimi-k2.5 (no API key needed)"
return 0
else
warn "Gateway bootstrap script returned an error"
fi
else
warn "Bootstrap script not found, configuring manually..."
fi
# Manual fallback: write a minimal config
configure_smartagent_defaults
}
# ─── Post-Bootstrap: Validate Config (v0.9.6) ────────────────────────────────
validate_config() {
local config_file="$HOME/.openclaw/openclaw.json"
[[ -f "$config_file" ]] || return 0
# Detect "everclaw/" provider prefix — the #1 misconfiguration
local bad
bad=$(python3 -c "
import json
try:
c = json.load(open('$config_file'))
bad = []
p = c.get('agents',{}).get('defaults',{}).get('model',{}).get('primary','')
if p.startswith('everclaw/'): bad.append(p)
for f in c.get('agents',{}).get('defaults',{}).get('model',{}).get('fallbacks',[]):
if f.startswith('everclaw/'): bad.append(f)
if 'everclaw' in c.get('models',{}).get('providers',{}): bad.append('provider:everclaw')
print(' '.join(bad))
except: pass
" 2>/dev/null)
if [[ -n "$bad" ]]; then
warn "═══════════════════════════════════════════════════"
warn " MISCONFIGURATION: 'everclaw/' is not a provider!"
warn "═══════════════════════════════════════════════════"
err ""
err "Your config uses 'everclaw/' as a model prefix."
err "Everclaw is a SKILL, not an inference provider."
err "This routes to Venice (billing errors) instead of Morpheus."
err ""
log "Fix: change your model to:"
info " mor-gateway/kimi-k2.5 — Morpheus API Gateway"
info " morpheus/kimi-k2.5 — Local Morpheus P2P"
err ""
log "Or re-run the bootstrap to auto-fix:"
info " node ~/.openclaw/workspace/skills/everclaw/scripts/bootstrap-gateway.mjs"
err ""
fi
}
# ─── Step 5: Configure Workspace ─────────────────────────────────────────────
configure_workspace() {
log "Configuring SmartAgent workspace..."
mkdir -p "$WORKSPACE/memory"
# Download SmartAgent workspace files (AGENTS.md, SOUL.md, etc.)
local config_url="https://raw.githubusercontent.com/SmartAgentProtocol/smartagent/main/config"
local files=("AGENTS.md" "SOUL.md" "BOOTSTRAP.md" "TOOLS.md" "USER.md" "IDENTITY.md" "HEARTBEAT.md")
for file in "${files[@]}"; do
if [[ ! -f "$WORKSPACE/$file" ]]; then
if curl -fsSL "$config_url/$file" -o "$WORKSPACE/$file" 2>/dev/null; then
log " Created $file"
else
warn " Could not download $file (will use OpenClaw defaults)"
fi
else
info " $file already exists, skipping"
fi
done
log "Workspace configured ✓"
}
configure_smartagent_defaults() {
# Write a minimal openclaw.json with Morpheus API Gateway
local config_file="$HOME/.openclaw/openclaw.json"
if [[ -f "$config_file" ]]; then
info "openclaw.json already exists, preserving..."
return
fi
mkdir -p "$HOME/.openclaw"
cat > "$config_file" << 'CONF'
{
"models": {
"mode": "merge",
"providers": {
"mor-gateway": {
"baseUrl": "https://api.mor.org/api/v1",
"api": "openai-completions",
"models": [
{ "id": "kimi-k2.5", "reasoning": false, "contextWindow": 131072, "maxTokens": 8192 },
{ "id": "glm-4.7-flash", "reasoning": false, "contextWindow": 131072, "maxTokens": 8192 }
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "mor-gateway/kimi-k2.5",
"fallbacks": ["mor-gateway/glm-4.7-flash"]
}
}
}
}
CONF
log "Default config written ✓"
}
# ─── Step 6: Start Agent ─────────────────────────────────────────────────────
start_agent() {
log "Starting SmartAgent..."
# Check if gateway is already running
if openclaw gateway status &>/dev/null 2>&1; then
info "Gateway already running"
else
openclaw gateway start 2>/dev/null || {
warn "Could not start gateway automatically"
info "Run manually: openclaw gateway start"
return 1
}
fi
log "Gateway started ✓"
return 0
}
open_webchat() {
# Give the gateway a moment to initialize
sleep 2
local webchat_url
webchat_url="$(openclaw webchat url 2>/dev/null || echo "")"
if [[ -z "$webchat_url" ]]; then
webchat_url="http://localhost:4200"
fi
echo ""
bold " ┌─────────────────────────────────────────────┐"
bold " │ │"
bold " │ 🎉 SmartAgent is ready! │"
bold " │ │"
bold " │ WebChat: ${webchat_url} │"
bold " │ │"
bold " │ Your agent is using Morpheus decentralized │"
bold " │ inference — no API key needed. │"
bold " │ │"
bold " │ Say hello to get started! │"
bold " │ │"
bold " └─────────────────────────────────────────────┘"
echo ""
# Open in browser
if [[ "$OS" == "macos" ]]; then
open "$webchat_url" 2>/dev/null || true
elif command -v xdg-open &>/dev/null; then
xdg-open "$webchat_url" 2>/dev/null || true
fi
info "To stop: openclaw gateway stop"
info "To restart: openclaw gateway restart"
info "Logs: openclaw gateway logs"
echo ""
info "Next steps:"
info " • Get your own API key at https://app.mor.org"
info " • Add Venice for premium models (Claude, GPT)"
info " • Stake MOR for self-sovereign inference"
info ""
info "Docs: https://smartagent.org"
info "GitHub: https://github.com/SmartAgentProtocol/smartagent"
}
# ─── Main ────────────────────────────────────────────────────────────────────
main() {
banner
check_os
echo ""
log "Step 1/6: Node.js"
check_node
echo ""
log "Step 2/6: OpenClaw"
check_openclaw
echo ""
log "Step 3/6: Everclaw"
install_everclaw
echo ""
log "Step 4/6: Decentralized Inference"
bootstrap_inference
validate_config
echo ""
log "Step 5/6: Workspace"
configure_workspace
echo ""
log "Step 6/6: Launch"
if start_agent; then
open_webchat
else
echo ""
bold " SmartAgent is installed! Start it with:"
bold " openclaw gateway start"
echo ""
fi
}
main "$@"