Repository navigation
Expand file tree
/
Copy pathinstall_dev.sh
More file actions
334 lines (295 loc) · 10.1 KB
/
Copy pathinstall_dev.sh
File metadata and controls
334 lines (295 loc) · 10.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
#!/usr/bin/env bash
set -euo pipefail
# cclite dev installer — builds from the dev branch, installs as cclite
# Usage: curl -fsSL https://raw.githubusercontent.com/Flybicy/CC-lite/main/install_dev.sh | bash
# Override these two before sourcing the shared install logic
BRANCH="dev"
BUILD_DIR="$HOME/.cache/cclite-dev"
# Everything below is the same as install.sh, only using $BRANCH / $BUILD_DIR.
# ---------------------------------------------------------------------------
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
ORANGE='\033[38;5;208m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
REPO="https://github.com/Flybicy/CC-lite.git"
INSTALL_DIR="$HOME/.local/bin"
# Runtime home for the JS bundle + the local semantic embedding stack.
LIB_DIR="$HOME/.local/lib/cclite"
BUN_MIN_VERSION="1.3.11"
# Pinned: must match the repo's package.json/bun.lock.
TRANSFORMERS_VERSION="3.8.1"
info() { printf "${CYAN}[*]${RESET} %s\n" "$*"; }
ok() { printf "${GREEN}[+]${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}[!]${RESET} %s\n" "$*"; }
fail() { printf "${RED}[x]${RESET} %s\n" "$*"; exit 1; }
header() {
echo ""
printf "${BOLD}${CYAN}CC-lite${RESET}${YELLOW} (dev)${RESET} installer"
echo ""
printf " ${DIM}Installs from the ${BOLD}dev${RESET}${DIM} branch.${RESET}"
echo ""
echo ""
}
# -------------------------------------------------------------------
# System checks
# -------------------------------------------------------------------
check_os() {
case "$(uname -s)" in
Darwin) OS="macos" ;;
Linux) OS="linux" ;;
*) fail "Unsupported OS: $(uname -s). macOS or Linux required." ;;
esac
ok "OS: $(uname -s) $(uname -m)"
}
check_git() {
if ! command -v git &>/dev/null; then
fail "git is not installed. Install it first:
macOS: xcode-select --install
Linux: sudo apt install git (or your distro's equivalent)"
fi
ok "git: $(git --version | head -1)"
}
check_rg() {
if ! command -v rg &>/dev/null; then
warn "ripgrep (rg) not found — install it for best results:
macOS: brew install ripgrep
Linux: sudo apt install ripgrep"
else
ok "rg: $(rg --version | head -1)"
fi
}
# Compare semver: returns 0 if $1 >= $2
version_gte() {
local newer
newer="$(printf '%s\n' "$1" "$2" | sort -V | tail -1)"
[ "$newer" = "$1" ]
}
check_bun() {
if command -v bun &>/dev/null; then
local ver
ver="$(bun --version 2>/dev/null || echo "0.0.0")"
if version_gte "$ver" "$BUN_MIN_VERSION"; then
ok "bun: v${ver}"
return
fi
warn "bun v${ver} found but v${BUN_MIN_VERSION}+ required. Upgrading..."
else
info "bun not found. Installing..."
fi
install_bun
}
install_bun() {
curl -fsSL https://bun.sh/install | bash
# Source the updated profile so bun is on PATH for this session
export BUN_INSTALL="${BUN_INSTALL:-$HOME/.bun}"
export PATH="$BUN_INSTALL/bin:$PATH"
if ! command -v bun &>/dev/null; then
fail "bun installation succeeded but binary not found on PATH.
Add this to your shell profile and restart:
export PATH=\"\$HOME/.bun/bin:\$PATH\""
fi
ok "bun: v$(bun --version) (just installed)"
}
# -------------------------------------------------------------------
# Clone & build
# -------------------------------------------------------------------
clone_repo() {
if [ -d "$BUILD_DIR" ]; then
warn "$BUILD_DIR already exists"
if [ -d "$BUILD_DIR/.git" ]; then
info "Pulling latest changes from $BRANCH..."
git -C "$BUILD_DIR" fetch origin "$BRANCH" 2>/dev/null
git -C "$BUILD_DIR" checkout "$BRANCH" 2>/dev/null || true
git -C "$BUILD_DIR" pull --ff-only origin "$BRANCH" 2>/dev/null || {
warn "Pull failed, continuing with existing copy"
}
fi
else
info "Cloning repository ($BRANCH branch) to cache..."
git clone --depth 1 --branch "$BRANCH" "$REPO" "$BUILD_DIR"
fi
ok "Source cache: $BUILD_DIR ($BRANCH branch)"
}
install_deps() {
info "Installing dependencies..."
cd "$BUILD_DIR" || fail "Cannot enter $BUILD_DIR"
bun install --frozen-lockfile 2>/dev/null || bun install
ok "Dependencies installed"
}
build_bundle() {
info "Building cclite (JS bundle)..."
cd "$BUILD_DIR" || fail "Cannot enter $BUILD_DIR"
bun run build:bundle:cclite
[ -f "$BUILD_DIR/cclite.js" ] || fail "Build did not produce cclite.js."
bun run build:bundle:verify || warn "Could not build the embeddings verifier (non-fatal)"
ok "Bundle built: $BUILD_DIR/cclite.js"
}
install_lib() {
info "Installing runtime to $LIB_DIR..."
mkdir -p "$LIB_DIR"
cp "$BUILD_DIR/cclite.js" "$LIB_DIR/cclite.js"
[ -f "$BUILD_DIR/verify-embeddings.js" ] &&
cp "$BUILD_DIR/verify-embeddings.js" "$LIB_DIR/verify-embeddings.js"
# Minimal manifest: only the embedding stack is resolved at runtime; every
# other dependency is already inlined in the bundle.
cat > "$LIB_DIR/package.json" <<EOF
{
"name": "cclite-runtime",
"private": true,
"type": "module",
"dependencies": {
"@huggingface/transformers": "${TRANSFORMERS_VERSION}"
}
}
trim_lib() {
local before after
before="$(du -sm "$LIB_DIR/node_modules" 2>/dev/null | cut -f1)"
find "$LIB_DIR/node_modules" -name "*.map" -delete 2>/dev/null || true
rm -rf "$LIB_DIR/node_modules/@types" 2>/dev/null || true
rm -rf "$LIB_DIR/node_modules/onnxruntime-web" 2>/dev/null || true
local napi="$LIB_DIR/node_modules/onnxruntime-node/bin/napi-v3"
if [ -d "$napi" ]; then
local keep=""
case "$OS" in
linux) keep="linux" ;;
macos) keep="darwin" ;;
windows) keep="win32" ;;
esac
local d
for d in "$napi"/*; do
[ -d "$d" ] || continue
[ "$(basename "$d")" = "$keep" ] || rm -rf "$d"
done
fi
after="$(du -sm "$LIB_DIR/node_modules" 2>/dev/null | cut -f1)"
if [ -n "$before" ] && [ -n "$after" ]; then
info "Trimmed runtime: ${before}MB -> ${after}MB"
fi
}
prefetch_model() {
[ -f "$LIB_DIR/verify-embeddings.js" ] || return 0
info "Downloading the semantic model (~23MB, one time) and verifying..."
cd "$LIB_DIR" || return 0
if bun ./verify-embeddings.js; then
ok "Semantic search ready"
else
warn "Model prefetch/verification failed - semantic search will fall back"
warn "to approximate matching. Re-run later: cclite-verify-embeddings"
fi
}
install_launchers() {
local main="$INSTALL_DIR/cclite"
# No `cd` here: cclite must run against the user's current directory.
# Bun resolves node_modules from the entry script's location, so the
# embedding stack in $LIB_DIR is found regardless of cwd.
cat > "$main" <<EOF
#!/usr/bin/env bash
set -euo pipefail
export BUN_INSTALL="\${BUN_INSTALL:-\$HOME/.bun}"
export PATH="\$BUN_INSTALL/bin:\$PATH"
exec bun "${LIB_DIR}/cclite.js" "\$@"
EOF
chmod +x "$main" 2>/dev/null || true
ok "Installed: $main"
local bypass="$INSTALL_DIR/cclite-bypass"
cat > "$bypass" <<EOF
#!/usr/bin/env bash
set -euo pipefail
export IS_SANDBOX=1
exec "${INSTALL_DIR}/cclite" --permission-mode bypassPermissions "\$@"
EOF
chmod +x "$bypass" 2>/dev/null || true
ok "Installed: $bypass"
if [ -f "$LIB_DIR/verify-embeddings.js" ]; then
local verify="$INSTALL_DIR/cclite-verify-embeddings"
cat > "$verify" <<EOF
#!/usr/bin/env bash
set -euo pipefail
export BUN_INSTALL="\${BUN_INSTALL:-\$HOME/.bun}"
export PATH="\$BUN_INSTALL/bin:\$PATH"
exec bun "${LIB_DIR}/verify-embeddings.js" "\$@"
EOF
chmod +x "$verify" 2>/dev/null || true
ok "Installed: $verify"
fi
}
# Ensure INSTALL_DIR is on PATH: persist it to the user's shell profiles
# (idempotently) and export it for the current session.
add_to_path() {
case ":$PATH:" in
*":$INSTALL_DIR:"*) return ;;
esac
local line='export PATH="$HOME/.local/bin:$PATH"'
local added="" present=""
local profile
for profile in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
[ -f "$profile" ] || continue
if grep -qF "$line" "$profile" 2>/dev/null; then
present="yes"
else
printf '\n# Added by cclite installer\n%s\n' "$line" >> "$profile"
added="$added $profile"
fi
done
# No profile existed at all: create ~/.profile so it applies on next login.
if [ -z "$added" ] && [ -z "$present" ]; then
printf '# Added by cclite installer\n%s\n' "$line" >> "$HOME/.profile"
added=" $HOME/.profile"
fi
# Make cclite usable in the current shell immediately.
export PATH="$INSTALL_DIR:$PATH"
if [ -n "$added" ]; then
ok "Added $INSTALL_DIR to PATH in:$added"
fi
warn "Open a new terminal (or run: source ~/.bashrc) to use 'cclite' in existing shells."
}
install_binary() {
mkdir -p "$INSTALL_DIR"
install_lib
install_launchers
prefetch_model
rm -rf "$BUILD_DIR"
ok "Build cache cleaned"
add_to_path
}
# -------------------------------------------------------------------
# Main
# -------------------------------------------------------------------
header
info "Starting dev installation..."
echo ""
check_os
check_git
check_bun
check_rg
echo ""
clone_repo
install_deps
build_bundle
install_binary
echo ""
printf "${GREEN}${BOLD} Installation complete!${RESET}\n"
echo ""
printf " ${BOLD}Run it:${RESET}\n"
printf " ${CYAN}cclite${RESET} # interactive REPL\n"
printf " ${CYAN}cclite-bypass${RESET} # interactive REPL with bypassPermissions\n"
printf " ${CYAN}cclite -p \"your prompt\"${RESET} # one-shot mode\n"
printf " ${CYAN}cclite-verify-embeddings${RESET} # re-check the local semantic model\n"
printf " ${CYAN}cclite config${RESET} # WebUI at 127.0.0.1:1511 - providers + model routing\n"
echo ""
printf " ${BOLD}Recommended: configure providers via the local WebUI:${RESET}\n"
printf " ${CYAN}cclite config${RESET} # multi-provider + main(planner)/subagent(worker)/advisor routing\n"
echo ""
printf " ${BOLD}Or set your API key via env vars:${RESET}\n"
printf " ${CYAN}export ANTHROPIC_API_KEY=\"sk-ant-...\"${RESET}\n"
echo ""
printf " ${BOLD}Also support OpenAI Chat Completions APIs (env, or use `cclite config`):${RESET}\n"
printf " ${CYAN}export CLAUDE_CODE_USE_OPENAI=1${RESET}\n"
printf " ${CYAN}export OPENAI_BASE_URL=http://.../v1${RESET}\n"
echo ""
printf " ${BOLD}See README.md for full configs.${RESET}\n"
echo ""