-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·277 lines (251 loc) · 11.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·277 lines (251 loc) · 11.3 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
#!/usr/bin/env bash
# install.sh — Synapse_COR + Forge Bundle Smart Installer v3.2.0
#
# Zero-config design: auto-detects available LLM providers so the bundle
# works immediately without requiring the user to set any env vars.
#
# Usage:
# bash install.sh — full install with provider detection
# bash install.sh --dry-run — show what would be done, no changes
# bash install.sh --non-interactive — CI mode: skip all prompts, exit 0
set -euo pipefail
INSTALL_DIR="${SYNAPSE_FORGE_HOME:-$HOME/.synapse-forge}"
BIN_DIR="$INSTALL_DIR/bin"
LIB_DIR="$INSTALL_DIR/lib"
TEMPLATES_DIR="$INSTALL_DIR/templates"
STATE_DIR="$INSTALL_DIR/state"
DRY_RUN=0
NON_INTERACTIVE=0
# ── Parse args ─────────────────────────────────────────────────────────────────
for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=1 ;;
--non-interactive) NON_INTERACTIVE=1 ;;
--help)
echo "Usage: bash install.sh [--dry-run] [--non-interactive]"
echo " --dry-run Show what would be installed without making changes"
echo " --non-interactive CI mode: skip interactive prompts, exit 0"
exit 0
;;
esac
done
# ── Colors ─────────────────────────────────────────────────────────────────────
CYAN='\033[0;36m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; RESET='\033[0m'
info() { printf "${CYAN}[install]${RESET} %s\n" "$*"; }
ok() { printf "${GREEN}[install] OK:${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}[install] WARN:${RESET} %s\n" "$*"; }
err() { printf "${RED}[install] ERR:${RESET} %s\n" "$*"; }
dryrun() { printf "${YELLOW}[dry-run]${RESET} would: %s\n" "$*"; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
info "Synapse_COR Engine v3.2.1 — Smart Installer"
info "Install target: $INSTALL_DIR"
[[ $DRY_RUN -eq 1 ]] && warn "DRY RUN mode — no changes will be made"
[[ $NON_INTERACTIVE -eq 1 ]] && info "Non-interactive mode — skipping prompts"
# ── Check Python 3 ─────────────────────────────────────────────────────────────
PYTHON=""
for py in python3 python; do
if command -v "$py" &>/dev/null && "$py" -c "import sys; sys.exit(0 if sys.version_info >= (3,9) else 1)" 2>/dev/null; then
PYTHON="$py"
break
fi
done
if [[ -z "$PYTHON" ]]; then
warn "Python 3.9+ not found — synapse_forge.py will not run. Install Python 3.9+ to proceed."
else
ok "Python found: $($PYTHON --version 2>&1)"
fi
# ── Create directories ─────────────────────────────────────────────────────────
for d in "$INSTALL_DIR" "$BIN_DIR" "$LIB_DIR" "$TEMPLATES_DIR" "$STATE_DIR"; do
if [[ $DRY_RUN -eq 1 ]]; then
dryrun "mkdir -p $d"
else
mkdir -p "$d"
fi
done
# ── Install core engine ────────────────────────────────────────────────────────
if [[ $DRY_RUN -eq 1 ]]; then
dryrun "cp synapse_forge.py $LIB_DIR/synapse_forge.py"
dryrun "cp -r synapse_forge/ $LIB_DIR/synapse_forge/"
dryrun "cp synapse_forge_cli $BIN_DIR/synapse-forge"
dryrun "chmod +x $BIN_DIR/synapse-forge"
else
cp "$SCRIPT_DIR/synapse_forge.py" "$LIB_DIR/synapse_forge.py"
cp -r "$SCRIPT_DIR/synapse_forge/" "$LIB_DIR/synapse_forge/"
cp "$SCRIPT_DIR/synapse_forge_cli" "$BIN_DIR/synapse-forge"
chmod +x "$BIN_DIR/synapse-forge"
ok "Core engine installed to $LIB_DIR/synapse_forge.py"
ok "Detect module installed to $LIB_DIR/synapse_forge/"
ok "CLI wrapper installed to $BIN_DIR/synapse-forge"
fi
# ── Install adapters ───────────────────────────────────────────────────────────
if [[ $DRY_RUN -eq 1 ]]; then
dryrun "cp -r adapters/ $INSTALL_DIR/adapters/"
else
cp -r "$SCRIPT_DIR/adapters/" "$INSTALL_DIR/adapters/"
ok "Adapters installed (including gemini-cli-free)"
fi
# ── Install templates ──────────────────────────────────────────────────────────
for tmpl in "$SCRIPT_DIR"/templates/*; do
fname="$(basename "$tmpl")"
if [[ $DRY_RUN -eq 1 ]]; then
dryrun "cp templates/$fname $TEMPLATES_DIR/$fname"
else
cp "$tmpl" "$TEMPLATES_DIR/$fname"
ok "Template installed: $fname"
fi
done
# ── Initialize empty specialists registry if not present ──────────────────────
if [[ ! -f "$INSTALL_DIR/specialists.json" ]]; then
if [[ $DRY_RUN -eq 1 ]]; then
dryrun "create $INSTALL_DIR/specialists.json (empty registry)"
else
"$PYTHON" -c "
import json, datetime
reg = {'schema_version': '1.0', 'created': str(datetime.date.today()), 'specialists': []}
with open('$INSTALL_DIR/specialists.json', 'w') as f:
json.dump(reg, f, indent=2)
" 2>/dev/null || true
ok "Specialists registry initialized: $INSTALL_DIR/specialists.json"
fi
fi
# ── Provider auto-detection ────────────────────────────────────────────────────
AUTH_CONFIG="$INSTALL_DIR/auth-config.json"
if [[ $DRY_RUN -eq 0 ]] && [[ -n "$PYTHON" ]]; then
echo ""
info "Scanning for available LLM providers..."
# Run detect.py via the installed lib path
DETECT_OUTPUT=$("$PYTHON" - <<'PYEOF' 2>/dev/null || echo '{"available":[],"missing_recommended":[]}'
import sys, json
sys.path.insert(0, '$LIB_DIR')
try:
from synapse_forge.detect import detect_providers
result = detect_providers(verbose=False)
print(json.dumps(result))
except Exception as e:
print(json.dumps({"available": [], "missing_recommended": [], "error": str(e)}))
PYEOF
)
# Save auth-config.json
echo "$DETECT_OUTPUT" > "$AUTH_CONFIG"
ok "Provider config written: $AUTH_CONFIG"
# Parse and display results (pure bash, no jq required)
PROVIDER_COUNT=$("$PYTHON" -c "
import json, sys
d = json.loads(sys.stdin.read())
print(len(d.get('available', [])))
" <<< "$DETECT_OUTPUT" 2>/dev/null || echo "0")
FIRST_PROVIDER=$("$PYTHON" -c "
import json, sys
d = json.loads(sys.stdin.read())
ps = d.get('available', [])
print(ps[0]['id'] if ps else 'none')
" <<< "$DETECT_OUTPUT" 2>/dev/null || echo "none")
FIRST_COST=$("$PYTHON" -c "
import json, sys
d = json.loads(sys.stdin.read())
ps = d.get('available', [])
print(ps[0].get('cost', 'unknown') if ps else 'none')
" <<< "$DETECT_OUTPUT" 2>/dev/null || echo "unknown")
if [[ "$PROVIDER_COUNT" -gt 0 ]] 2>/dev/null; then
echo ""
ok "Providers found: $PROVIDER_COUNT"
ok "Best provider: $FIRST_PROVIDER (cost: $FIRST_COST)"
echo ""
info "Bundle ready. Run: synapse-cor run \"your goal here\""
else
# Zero providers — guide the user
echo ""
warn "No LLM providers detected. The bundle will run in stub mode."
echo ""
info "Three easy ways to unlock a free LLM (pick one):"
echo ""
echo " 1. EASIEST — Gemini CLI free mode (no sign-in):"
echo " npm install -g @google/gemini-cli"
echo " (Gemini CLI's --free flag uses an unofficial endpoint — no account needed)"
echo ""
echo " 2. FREE ACCOUNT — Gemini keyless OAuth (1000 req/day):"
echo " npm install -g @google/gemini-cli"
echo " gemini # sign in once with your Google account"
echo ""
echo " 3. LOCAL — Ollama (runs models on your machine):"
echo " https://ollama.com → ollama pull llama3"
echo ""
echo " 4. API KEY (fastest if you have one):"
echo " export GEMINI_API_KEY=AIza... # Google AI Studio (free tier)"
echo " export OPENAI_API_KEY=sk-... # OpenAI"
echo " export GROQ_API_KEY=gsk_... # Groq (free tier)"
echo ""
if [[ $NON_INTERACTIVE -eq 0 ]]; then
echo " Or paste a key now and we'll save it for you:"
echo " [G] GEMINI_API_KEY [O] OPENAI_API_KEY [R] GROQ_API_KEY [S] skip"
printf " Choice: "
read -r CHOICE 2>/dev/null || CHOICE="s"
CHOICE="${CHOICE,,}" # lowercase
case "$CHOICE" in
g|gemini)
printf " Paste your GEMINI_API_KEY: "
read -r KEY_VAL 2>/dev/null || KEY_VAL=""
if [[ -n "$KEY_VAL" ]]; then
echo "export GEMINI_API_KEY=$KEY_VAL" >> "$HOME/.synapse-forge-keys.sh"
ok "Key saved to ~/.synapse-forge-keys.sh — source it or add to your shell rc"
info "Add to ~/.zshrc or ~/.bashrc: source ~/.synapse-forge-keys.sh"
fi
;;
o|openai)
printf " Paste your OPENAI_API_KEY: "
read -r KEY_VAL 2>/dev/null || KEY_VAL=""
if [[ -n "$KEY_VAL" ]]; then
echo "export OPENAI_API_KEY=$KEY_VAL" >> "$HOME/.synapse-forge-keys.sh"
ok "Key saved to ~/.synapse-forge-keys.sh"
info "Add to ~/.zshrc or ~/.bashrc: source ~/.synapse-forge-keys.sh"
fi
;;
r|groq)
printf " Paste your GROQ_API_KEY: "
read -r KEY_VAL 2>/dev/null || KEY_VAL=""
if [[ -n "$KEY_VAL" ]]; then
echo "export GROQ_API_KEY=$KEY_VAL" >> "$HOME/.synapse-forge-keys.sh"
ok "Key saved to ~/.synapse-forge-keys.sh"
info "Add to ~/.zshrc or ~/.bashrc: source ~/.synapse-forge-keys.sh"
fi
;;
*)
info "Skipped. Configure a provider later and re-run: bash install.sh"
;;
esac
fi
fi
elif [[ $DRY_RUN -eq 1 ]]; then
dryrun "run detect_providers() → write $AUTH_CONFIG"
fi
# ── FUTRON auto-wire detection (optional integration) ─────────────────────────
FUTRON_BIN="${HOME}/.openclaw/bin"
FUTRON_DETECTED=0
if [[ -d "$FUTRON_BIN" ]] && { command -v futron-forge &>/dev/null 2>&1 || [[ -f "$FUTRON_BIN/futron-forge" ]]; }; then
FUTRON_DETECTED=1
fi
if [[ $FUTRON_DETECTED -eq 1 ]]; then
info "FUTRON installation detected — integration available:"
if [[ $DRY_RUN -eq 0 ]]; then
echo " export SYNAPSE_FORGE_URL=http://127.0.0.1:9055"
echo " export SYNAPSE_FORGE_REGISTRY=$HOME/.openclaw/state/futron-forge/specialists.json"
fi
fi
# ── PATH suggestion ────────────────────────────────────────────────────────────
if [[ $DRY_RUN -eq 0 ]]; then
echo ""
ok "Installation complete! v3.2.1"
echo ""
info "Add to PATH if not already present:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
echo ""
info "Verify everything works:"
echo " synapse-cor detect # show detected providers"
echo " synapse-cor status # registry + best provider"
echo " synapse-cor run \"hello\" # end-to-end test"
echo ""
info "Documentation: $SCRIPT_DIR/docs/quickstart.md"
else
ok "Dry run complete — no changes made."
info "Run without --dry-run to install."
fi