-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·302 lines (256 loc) · 10.6 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·302 lines (256 loc) · 10.6 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
#!/usr/bin/env bash
# Ralph Ultra — Installer
# Installs to $HOME/.ralph-ultra/ (user space, no sudo required)
# Usage: ./install.sh [--prefix DIR] [--no-symlink] [--plugin]
set -euo pipefail
# ─── Configuration ──────────────────────────────────────────────────────────────
INSTALL_DIR="${HOME}/.ralph-ultra"
BIN_DIR="${HOME}/.local/bin"
VERSION="1.0.0"
CREATE_SYMLINK=true
INSTALL_PLUGIN=false
# ─── Colors ─────────────────────────────────────────────────────────────────────
if [[ -t 1 ]] && [[ -z "${NO_COLOR:-}" ]]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
else
RED='' GREEN='' YELLOW='' BLUE='' BOLD='' NC=''
fi
# ─── Helpers ────────────────────────────────────────────────────────────────────
info() { printf "${GREEN}[INFO]${NC} %s\n" "$1"; }
warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$1"; }
error() { printf "${RED}[ERROR]${NC} %s\n" "$1" >&2; }
fatal() { error "$1"; exit 1; }
# ─── Parse Arguments ────────────────────────────────────────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--prefix)
INSTALL_DIR="${2:?--prefix requires a directory}"
shift 2
;;
--bin-dir)
BIN_DIR="${2:?--bin-dir requires a directory}"
shift 2
;;
--no-symlink)
CREATE_SYMLINK=false
shift
;;
--plugin)
INSTALL_PLUGIN=true
shift
;;
--help|-h)
printf "${BOLD}Ralph Ultra Installer v%s${NC}\n\n" "$VERSION"
echo "Usage: ./install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --prefix DIR Install to DIR (default: ~/.ralph-ultra)"
echo " --bin-dir DIR Symlink binary to DIR (default: ~/.local/bin)"
echo " --no-symlink Skip creating symlink in PATH"
echo " --plugin Also install Claude Code plugin"
echo " -h, --help Show this help"
exit 0
;;
*)
fatal "Unknown option: $1. Use --help for usage."
;;
esac
done
# ─── Pre-flight Checks ─────────────────────────────────────────────────────────
printf "\n${BOLD}Ralph Ultra Installer v%s${NC}\n" "$VERSION"
printf "════════════════════════════════════════\n\n"
# Get the directory where install.sh lives (the repo root)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check required tools
MISSING_DEPS=()
if ! command -v jq >/dev/null 2>&1; then
MISSING_DEPS+=("jq")
fi
if ! command -v git >/dev/null 2>&1; then
MISSING_DEPS+=("git")
fi
if [[ ${#MISSING_DEPS[@]} -gt 0 ]]; then
error "Missing required dependencies: ${MISSING_DEPS[*]}"
echo ""
echo "Install them first:"
case "$(uname -s)" in
Darwin)
echo " brew install ${MISSING_DEPS[*]}"
;;
Linux)
echo " sudo apt-get install ${MISSING_DEPS[*]}"
echo " # or: sudo yum install ${MISSING_DEPS[*]}"
;;
esac
exit 1
fi
# Check bash version (need 4+ for associative arrays)
BASH_MAJOR="${BASH_VERSINFO[0]}"
if [[ "$BASH_MAJOR" -lt 4 ]]; then
warn "Bash $BASH_VERSION detected. Some features need bash 4+."
case "$(uname -s)" in
Darwin)
warn "macOS ships with bash 3.x. For full features:"
echo " brew install bash"
;;
esac
fi
info "Pre-flight checks passed"
# ─── Check for Existing Installation ────────────────────────────────────────────
if [[ -d "$INSTALL_DIR" ]]; then
warn "Existing installation found at $INSTALL_DIR"
if [[ -f "$INSTALL_DIR/VERSION" ]]; then
EXISTING_VERSION="$(cat "$INSTALL_DIR/VERSION")"
info "Upgrading: $EXISTING_VERSION → $VERSION"
fi
# Backup existing config
if [[ -f "$INSTALL_DIR/config.json" ]]; then
cp "$INSTALL_DIR/config.json" "$INSTALL_DIR/config.json.backup.$(date +%s)"
info "Backed up existing config"
fi
fi
# ─── Install ────────────────────────────────────────────────────────────────────
info "Installing Ralph Ultra to $INSTALL_DIR"
# Create install directory structure
mkdir -p "$INSTALL_DIR"/{bin,lib/core,lib/skills,lib/observability,templates,docs}
# Copy core libraries
info "Copying core libraries..."
CORE_COUNT=0
for f in platform.sh json.sh logger.sh security.sh loop.sh init.sh; do
if [[ -f "$SCRIPT_DIR/lib/core/$f" ]]; then
cp "$SCRIPT_DIR/lib/core/$f" "$INSTALL_DIR/lib/core/$f"
CORE_COUNT=$((CORE_COUNT + 1))
else
warn "Missing: lib/core/$f (skipping)"
fi
done
info "Installed $CORE_COUNT core modules"
# Copy skills
info "Copying skills..."
SKILL_COUNT=0
for f in "$SCRIPT_DIR"/lib/skills/*.sh; do
if [[ -f "$f" ]]; then
cp "$f" "$INSTALL_DIR/lib/skills/$(basename "$f")"
SKILL_COUNT=$((SKILL_COUNT + 1))
fi
done
info "Installed $SKILL_COUNT skills"
# Copy observability
info "Copying observability modules..."
OBS_COUNT=0
for f in "$SCRIPT_DIR"/lib/observability/*.sh; do
if [[ -f "$f" ]]; then
cp "$f" "$INSTALL_DIR/lib/observability/$(basename "$f")"
OBS_COUNT=$((OBS_COUNT + 1))
fi
done
info "Installed $OBS_COUNT observability modules"
# Copy CLI binary
info "Installing CLI binary..."
if [[ -f "$SCRIPT_DIR/bin/ralph-ultra" ]]; then
cp "$SCRIPT_DIR/bin/ralph-ultra" "$INSTALL_DIR/bin/ralph-ultra"
chmod +x "$INSTALL_DIR/bin/ralph-ultra"
else
fatal "bin/ralph-ultra not found in source"
fi
# Copy templates (recursive to include subdirectories)
info "Copying templates..."
if [[ -d "$SCRIPT_DIR/templates" ]]; then
cp -R "$SCRIPT_DIR"/templates/* "$INSTALL_DIR/templates/" 2>/dev/null || true
TEMPLATE_COUNT=$(find "$INSTALL_DIR/templates" -type f | wc -l | tr -d ' ')
else
TEMPLATE_COUNT=0
fi
info "Installed $TEMPLATE_COUNT templates"
# Copy docs (recursive to include subdirectories like diagrams/)
if [[ -d "$SCRIPT_DIR/docs" ]]; then
cp -R "$SCRIPT_DIR"/docs/* "$INSTALL_DIR/docs/" 2>/dev/null || true
fi
# Write version file
echo "$VERSION" > "$INSTALL_DIR/VERSION"
# Write default global config if none exists
if [[ ! -f "$INSTALL_DIR/config.json" ]]; then
jq -n \
--arg version "$VERSION" \
'{
version: $version,
defaults: {
security_mode: "standard",
tool: "claude",
max_iterations: 10
},
cost: {
rates: {
"claude-sonnet": { input_per_mtok: 3.0, output_per_mtok: 15.0 },
"claude-opus": { input_per_mtok: 15.0, output_per_mtok: 75.0 },
"claude-haiku": { input_per_mtok: 0.25, output_per_mtok: 1.25 },
"gpt-4o": { input_per_mtok: 2.5, output_per_mtok: 10.0 },
"gpt-4-turbo": { input_per_mtok: 10.0, output_per_mtok: 30.0 }
}
}
}' > "$INSTALL_DIR/config.json"
info "Created default global config"
fi
# ─── Create Symlink ─────────────────────────────────────────────────────────────
if [[ "$CREATE_SYMLINK" == "true" ]]; then
mkdir -p "$BIN_DIR"
# Remove old symlink if exists
if [[ -L "$BIN_DIR/ralph-ultra" ]]; then
rm "$BIN_DIR/ralph-ultra"
fi
ln -s "$INSTALL_DIR/bin/ralph-ultra" "$BIN_DIR/ralph-ultra"
info "Symlinked ralph-ultra → $BIN_DIR/ralph-ultra"
# Check if BIN_DIR is in PATH
if ! echo "$PATH" | tr ':' '\n' | grep -q "^${BIN_DIR}$"; then
warn "$BIN_DIR is not in your PATH"
echo ""
echo " Add to your shell profile (~/.bashrc, ~/.zshrc):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
fi
fi
# ─── Install Claude Code Plugin (Optional) ──────────────────────────────────────
if [[ "$INSTALL_PLUGIN" == "true" ]]; then
CLAUDE_DIR="${HOME}/.claude"
if [[ -d "$CLAUDE_DIR" ]]; then
info "Installing Claude Code plugin..."
mkdir -p "$CLAUDE_DIR/commands"
cat > "$CLAUDE_DIR/commands/ralph-ultra.md" << 'PLUGIN_EOF'
# Ralph Ultra Integration
Run Ralph Ultra autonomous development loop from Claude Code.
## Usage
- `ralph-ultra init <name>` — Initialize a new project
- `ralph-ultra run` — Start the autonomous loop
- `ralph-ultra fix` — Fix an existing project
- `ralph-ultra skill <name>` — Run a specific skill
- `ralph-ultra status` — Show project status
- `ralph-ultra dashboard` — Open live dashboard
PLUGIN_EOF
info "Claude Code plugin installed"
else
warn "Claude Code not found (~/.claude/). Skipping plugin."
fi
fi
# ─── Summary ────────────────────────────────────────────────────────────────────
printf "\n${GREEN}${BOLD}Ralph Ultra v%s installed successfully!${NC}\n\n" "$VERSION"
printf " %-20s %s\n" "Install directory:" "$INSTALL_DIR"
if [[ "$CREATE_SYMLINK" == "true" ]]; then
printf " %-20s %s\n" "CLI binary:" "$BIN_DIR/ralph-ultra"
fi
printf " %-20s %s\n" "Core modules:" "$CORE_COUNT"
printf " %-20s %s\n" "Skills:" "$SKILL_COUNT"
printf " %-20s %s\n" "Templates:" "$TEMPLATE_COUNT"
printf " %-20s %s\n" "Security:" "standard (default-safe)"
printf "\n${BOLD}Quick start:${NC}\n"
echo " ralph-ultra init my-project --template nextjs"
echo " cd my-project"
echo " ralph-ultra run"
printf "\n${BOLD}Shell profile:${NC}\n"
echo " export RALPH_ULTRA_HOME=\"$INSTALL_DIR\""
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""