This repository was archived by the owner on Jun 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·629 lines (552 loc) · 19.8 KB
/
install
File metadata and controls
executable file
·629 lines (552 loc) · 19.8 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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
#!/usr/bin/env bash
set -euo pipefail
APP=codeplane
MUTED='\033[0;2m'
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
NC='\033[0m' # No Color
usage() {
cat <<EOF
Codeplane Installer
Usage: install.sh [options]
Options:
-h, --help Display this help message
-v, --version <version> Install a specific version (e.g., 1.0.180)
-b, --binary <path> Install from a local binary instead of downloading
--no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.)
Examples:
curl -fsSL https://codeplane.cc/install | bash
curl -fsSL https://codeplane.cc/install | bash -s -- --version 1.0.180
./install --binary /path/to/codeplane
EOF
}
requested_version=${VERSION:-}
no_modify_path=false
binary_path=""
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
requested_version="$2"
shift 2
else
echo -e "${RED}Error: --version requires a version argument${NC}"
exit 1
fi
;;
-b|--binary)
if [[ -n "${2:-}" ]]; then
binary_path="$2"
shift 2
else
echo -e "${RED}Error: --binary requires a path argument${NC}"
exit 1
fi
;;
--no-modify-path)
no_modify_path=true
shift
;;
*)
echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2
shift
;;
esac
done
INSTALL_DIR=$HOME/.codeplane/bin
mkdir -p "$INSTALL_DIR"
# If --binary is provided, skip all download/detection logic
if [ -n "$binary_path" ]; then
if [ ! -f "$binary_path" ]; then
echo -e "${RED}Error: Binary not found at ${binary_path}${NC}"
exit 1
fi
specific_version="local"
else
raw_os=$(uname -s)
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
case "$raw_os" in
Darwin*) os="darwin" ;;
Linux*) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
esac
arch=$(uname -m)
if [[ "$arch" == "aarch64" ]]; then
arch="arm64"
fi
if [[ "$arch" == "x86_64" ]]; then
arch="x64"
fi
if [ "$os" = "darwin" ] && [ "$arch" = "x64" ]; then
rosetta_flag=$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)
if [ "$rosetta_flag" = "1" ]; then
arch="arm64"
fi
fi
combo="$os-$arch"
case "$combo" in
linux-x64|linux-arm64|darwin-x64|darwin-arm64|windows-x64)
;;
*)
echo -e "${RED}Unsupported OS/Arch: $os/$arch${NC}"
exit 1
;;
esac
# npm tarballs are always .tgz regardless of host OS.
archive_ext=".tgz"
is_musl=false
if [ "$os" = "linux" ]; then
if [ -f /etc/alpine-release ]; then
is_musl=true
fi
if command -v ldd >/dev/null 2>&1; then
if ldd --version 2>&1 | grep -qi musl; then
is_musl=true
fi
fi
fi
needs_baseline=false
if [ "$arch" = "x64" ]; then
if [ "$os" = "linux" ]; then
if ! grep -qwi avx2 /proc/cpuinfo 2>/dev/null; then
needs_baseline=true
fi
fi
if [ "$os" = "darwin" ]; then
avx2=$(sysctl -n hw.optional.avx2_0 2>/dev/null || echo 0)
if [ "$avx2" != "1" ]; then
needs_baseline=true
fi
fi
if [ "$os" = "windows" ]; then
ps="(Add-Type -MemberDefinition \"[DllImport(\"\"kernel32.dll\"\")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);\" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)"
out=""
if command -v powershell.exe >/dev/null 2>&1; then
out=$(powershell.exe -NoProfile -NonInteractive -Command "$ps" 2>/dev/null || true)
elif command -v pwsh >/dev/null 2>&1; then
out=$(pwsh -NoProfile -NonInteractive -Command "$ps" 2>/dev/null || true)
fi
out=$(echo "$out" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
if [ "$out" != "true" ] && [ "$out" != "1" ]; then
needs_baseline=true
fi
fi
fi
target="$os-$arch"
if [ "$needs_baseline" = "true" ]; then
target="$target-baseline"
fi
if [ "$is_musl" = "true" ]; then
target="$target-musl"
fi
# tar is required on every platform — the npm registry tarballs are
# .tgz (gzipped tar). macOS / Linux / Windows 10+ all ship `tar` by
# default, so no platform-specific extractor is needed any more.
if ! command -v tar >/dev/null 2>&1; then
echo -e "${RED}Error: 'tar' is required but not installed.${NC}"
exit 1
fi
# The CLI binaries are distributed as platform-specific npm packages
# (codeplane-darwin-arm64, codeplane-linux-x64, …). The wrapper
# package `codeplane-ai` declares them as optionalDependencies; this
# script bypasses Node entirely by fetching the matching platform
# tarball directly from the npm registry. The previous GitHub-release
# download path was broken for two reasons: (a) the `v<x.y.z>` CLI
# release tags don't always get a matching GitHub Release record
# (only `-desktop` / `-mobile` tags do), and (b) when they do, the
# uploaded assets are .dmg / .AppImage / .exe — not the standalone
# CLI .zip the install script expected.
npm_pkg="codeplane-$target"
if [ -z "$requested_version" ]; then
specific_version=$(curl -fsSL "https://registry.npmjs.org/$npm_pkg/latest" 2>/dev/null \
| sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' \
| head -1)
if [[ -z "$specific_version" ]]; then
echo -e "${RED}Failed to fetch version from npm registry${NC}"
echo -e "${MUTED}Registry: https://registry.npmjs.org/$npm_pkg${NC}"
exit 1
fi
else
specific_version="${requested_version#v}"
# Verify the requested version exists on npm before downloading.
http_status=$(curl -sI -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/$npm_pkg/$specific_version")
if [ "$http_status" = "404" ]; then
echo -e "${RED}Error: $npm_pkg@$specific_version not published${NC}"
echo -e "${MUTED}Available versions: https://www.npmjs.com/package/$npm_pkg${NC}"
exit 1
fi
fi
filename="$npm_pkg-$specific_version.tgz"
url="https://registry.npmjs.org/$npm_pkg/-/$filename"
fi
print_message() {
local level=$1
local message=$2
local color=""
case $level in
info) color="${NC}" ;;
warning) color="${NC}" ;;
error) color="${RED}" ;;
esac
echo -e "${color}${message}${NC}"
}
native_tui_package() {
local native_os="$os"
if [ "$native_os" = "windows" ]; then
native_os="win32"
fi
printf "@opentui/core-%s-%s" "$native_os" "$arch"
}
has_tui_assets() {
if [ ! -f "${INSTALL_DIR}/runtime/tui/node-main.js" ]; then
return 1
fi
local native_pkg
native_pkg=$(native_tui_package)
local native_name="${native_pkg##*/}"
[ -d "${INSTALL_DIR}/node_modules/@opentui/${native_name}" ]
}
install_native_tui_dependency() {
local package_json="$1"
local scratch_dir="$2"
if [ ! -f "$package_json" ]; then
return 0
fi
local native_pkg
native_pkg=$(native_tui_package)
local native_name="${native_pkg##*/}"
local native_version
native_version=$(sed -n "s#.*\"${native_pkg}\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*#\1#p" "$package_json" | head -1)
if [ -z "$native_version" ]; then
print_message warning "${MUTED}No ${native_pkg} dependency declared; skipping native TUI dependency install.${NC}"
return 0
fi
local dep_filename="${native_name}-${native_version}.tgz"
local dep_url="https://registry.npmjs.org/@opentui/${native_name}/-/${dep_filename}"
local dep_dir="${INSTALL_DIR}/node_modules/@opentui/${native_name}"
print_message info "${MUTED}Installing${NC} ${native_pkg} ${MUTED}for the TUI renderer${NC}"
curl -fsSL -o "${scratch_dir}/${dep_filename}" "$dep_url"
rm -rf "$dep_dir"
mkdir -p "$dep_dir"
tar -xzf "${scratch_dir}/${dep_filename}" -C "$dep_dir" --strip-components=1
}
path_dir_can_host_shim() {
local dir="$1"
if [ -z "$dir" ]; then
return 1
fi
case "$dir" in
/*) ;;
*) return 1 ;;
esac
case "$dir" in
"$INSTALL_DIR"|"$INSTALL_DIR"/) return 1 ;;
"$HOME"/*|/opt/homebrew/bin|/usr/local/bin) ;;
*) return 1 ;;
esac
[ -d "$dir" ] && [ -w "$dir" ] && [ -x "$dir" ]
}
write_codeplane_shim() {
local dir="$1"
local shim="$dir/codeplane"
if [ -L "$shim" ]; then
ln -sf "${INSTALL_DIR}/codeplane" "$shim"
elif [ -e "$shim" ]; then
if ! grep -q "codeplane installer shim" "$shim" 2>/dev/null; then
return 1
fi
printf '#!/usr/bin/env sh\n# codeplane installer shim\nexec "%s" "$@"\n' "${INSTALL_DIR}/codeplane" > "$shim"
chmod 755 "$shim"
elif ! ln -s "${INSTALL_DIR}/codeplane" "$shim" 2>/dev/null; then
printf '#!/usr/bin/env sh\n# codeplane installer shim\nexec "%s" "$@"\n' "${INSTALL_DIR}/codeplane" > "$shim"
chmod 755 "$shim"
fi
print_message info "${MUTED}Linked${NC} codeplane ${MUTED}command → ${NC}$shim"
}
ensure_codeplane_command() {
if command -v codeplane >/dev/null 2>&1; then
return 0
fi
local old_ifs="$IFS"
IFS=:
for dir in $PATH; do
IFS="$old_ifs"
if path_dir_can_host_shim "$dir" && write_codeplane_shim "$dir"; then
return 0
fi
IFS=:
done
IFS="$old_ifs"
print_message warning ""
print_message warning "The codeplane binary was installed, but this shell does not have a writable user bin directory already on PATH."
print_message info " Run now: ${MUTED}${INSTALL_DIR}/codeplane${NC}"
print_message info " New shells: ${MUTED}codeplane${NC} after your shell config reloads"
print_message info " Or run: ${MUTED}export PATH=${INSTALL_DIR}:\$PATH${NC}"
print_message warning ""
}
check_version() {
if command -v codeplane >/dev/null 2>&1; then
codeplane_path=$(which codeplane)
## Check the installed version
installed_version=$(codeplane --version 2>/dev/null || echo "")
if [[ "$installed_version" != "$specific_version" ]]; then
print_message info "${MUTED}Installed version: ${NC}$installed_version."
elif has_tui_assets; then
print_message info "${MUTED}Version ${NC}$specific_version${MUTED} already installed"
exit 0
else
print_message info "${MUTED}Version ${NC}$specific_version${MUTED} already installed, but TUI assets are missing. Reinstalling assets.${NC}"
fi
fi
}
unbuffered_sed() {
if echo | sed -u -e "" >/dev/null 2>&1; then
sed -nu "$@"
elif echo | sed -l -e "" >/dev/null 2>&1; then
sed -nl "$@"
else
local pad="$(printf "\n%512s" "")"
sed -ne "s/$/\\${pad}/" "$@"
fi
}
print_progress() {
local bytes="$1"
local length="$2"
[ "$length" -gt 0 ] || return 0
local width=50
local percent=$(( bytes * 100 / length ))
[ "$percent" -gt 100 ] && percent=100
local on=$(( percent * width / 100 ))
local off=$(( width - on ))
local filled=$(printf "%*s" "$on" "")
filled=${filled// /■}
local empty=$(printf "%*s" "$off" "")
empty=${empty// /・}
printf "\r${ORANGE}%s%s %3d%%${NC}" "$filled" "$empty" "$percent" >&4
}
download_with_progress() {
local url="$1"
local output="$2"
if [ -t 2 ]; then
exec 4>&2
else
exec 4>/dev/null
fi
local tmp_dir=${TMPDIR:-/tmp}
local basename="${tmp_dir}/codeplane_install_$$"
local tracefile="${basename}.trace"
rm -f "$tracefile"
mkfifo "$tracefile"
# Hide cursor
printf "\033[?25l" >&4
trap "trap - RETURN; rm -f \"$tracefile\"; printf '\033[?25h' >&4; exec 4>&-" RETURN
(
curl --trace-ascii "$tracefile" -s -L -o "$output" "$url"
) &
local curl_pid=$!
unbuffered_sed \
-e 'y/ACDEGHLNORTV/acdeghlnortv/' \
-e '/^0000: content-length:/p' \
-e '/^<= recv data/p' \
"$tracefile" | \
{
local length=0
local bytes=0
while IFS=" " read -r -a line; do
[ "${#line[@]}" -lt 2 ] && continue
local tag="${line[0]} ${line[1]}"
if [ "$tag" = "0000: content-length:" ]; then
length="${line[2]}"
length=$(echo "$length" | tr -d '\r')
bytes=0
elif [ "$tag" = "<= recv" ]; then
local size="${line[3]}"
bytes=$(( bytes + size ))
if [ "$length" -gt 0 ]; then
print_progress "$bytes" "$length"
fi
fi
done
}
wait $curl_pid
local ret=$?
echo "" >&4
return $ret
}
download_and_install() {
print_message info "\n${MUTED}Installing ${NC}codeplane ${MUTED}version: ${NC}$specific_version"
local tmp_dir="${TMPDIR:-/tmp}/codeplane_install_$$"
mkdir -p "$tmp_dir"
if [[ "$os" == "windows" ]] || ! [ -t 2 ] || ! download_with_progress "$url" "$tmp_dir/$filename"; then
# Fallback to standard curl on Windows, non-TTY environments, or if custom progress fails
curl -# -L -o "$tmp_dir/$filename" "$url"
fi
# npm tarballs unpack to <tmp>/package/... — `--strip-components 1`
# peels the leading `package/` so the binary lands at <tmp>/bin/codeplane.
tar -xzf "$tmp_dir/$filename" -C "$tmp_dir" --strip-components=1
if [ ! -f "$tmp_dir/bin/codeplane" ]; then
# Some older platform tarballs put the binary at the package root
# (without the bin/ subdir). Fall back to that layout.
if [ -f "$tmp_dir/codeplane" ]; then
mv "$tmp_dir/codeplane" "${INSTALL_DIR}/codeplane"
else
echo -e "${RED}Error: codeplane binary not found in tarball at ${tmp_dir}${NC}"
ls -la "$tmp_dir" >&2 || true
exit 1
fi
else
rm -rf "${INSTALL_DIR}/runtime"
cp -R "$tmp_dir/bin/." "${INSTALL_DIR}/"
fi
install_native_tui_dependency "$tmp_dir/package.json" "$tmp_dir"
chmod 755 "${INSTALL_DIR}/codeplane"
rm -rf "$tmp_dir"
}
install_from_binary() {
print_message info "\n${MUTED}Installing ${NC}codeplane ${MUTED}from: ${NC}$binary_path"
cp "$binary_path" "${INSTALL_DIR}/codeplane"
chmod 755 "${INSTALL_DIR}/codeplane"
}
# Codeplane's `tui` (and the default `codeplane` invocation) spawns a
# child process that needs either Bun or Node.js 22+ available. The TUI
# launcher checks bin paths next to the codeplane executable first, so
# linking an already-installed bun into $INSTALL_DIR makes the TUI work
# regardless of how the user's shell PATH is configured (a common
# failure mode on fresh installs where no ~/.zshrc exists yet).
ensure_runtime() {
local link_path="${INSTALL_DIR}/bun"
if [ -L "$link_path" ] || [ -x "$link_path" ]; then
return 0
fi
local found=""
for candidate in "$HOME/.bun/bin/bun" "/opt/homebrew/bin/bun" "/usr/local/bin/bun" "/usr/bin/bun"; do
if [ -x "$candidate" ]; then
found="$candidate"
break
fi
done
if [ -z "$found" ]; then
found=$(command -v bun 2>/dev/null || true)
fi
if [ -n "$found" ]; then
ln -sf "$found" "$link_path"
print_message info "${MUTED}Linked${NC} bun ${MUTED}runtime → ${NC}$link_path"
return 0
fi
# Fall back to Node 22+ if available.
local node_found=""
node_found=$(command -v node 2>/dev/null || true)
if [ -n "$node_found" ]; then
local node_major
node_major=$("$node_found" --version 2>/dev/null | sed -n 's/^v\([0-9][0-9]*\).*/\1/p')
if [ -n "$node_major" ] && [ "$node_major" -ge 22 ]; then
ln -sf "$node_found" "${INSTALL_DIR}/node"
print_message info "${MUTED}Linked${NC} node ${MUTED}runtime → ${NC}${INSTALL_DIR}/node"
return 0
fi
fi
print_message warning ""
print_message warning "No bun runtime found. Codeplane's TUI needs bun (preferred) or Node.js 22+."
print_message info " Install bun: ${MUTED}curl -fsSL https://bun.sh/install | bash${NC}"
print_message info " Or set: ${MUTED}export CODEPLANE_TUI_RUNTIME=/path/to/node${NC}"
print_message warning ""
}
if [ -n "$binary_path" ]; then
install_from_binary
else
check_version
download_and_install
fi
ensure_runtime
ensure_codeplane_command
add_to_path() {
local config_file=$1
local command=$2
if grep -Fxq "$command" "$config_file"; then
print_message info "Command already exists in $config_file, skipping write."
elif [[ -w $config_file ]]; then
echo -e "\n# codeplane" >> "$config_file"
echo "$command" >> "$config_file"
print_message info "${MUTED}Successfully added ${NC}codeplane ${MUTED}to \$PATH in ${NC}$config_file"
else
print_message warning "Manually add the directory to $config_file (or similar):"
print_message info " $command"
fi
}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
current_shell=$(basename "$SHELL")
case $current_shell in
fish)
config_files="$HOME/.config/fish/config.fish"
;;
zsh)
config_files="${ZDOTDIR:-$HOME}/.zshrc ${ZDOTDIR:-$HOME}/.zshenv $XDG_CONFIG_HOME/zsh/.zshrc $XDG_CONFIG_HOME/zsh/.zshenv"
;;
bash)
config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
;;
ash)
config_files="$HOME/.ashrc $HOME/.profile /etc/profile"
;;
sh)
config_files="$HOME/.ashrc $HOME/.profile /etc/profile"
;;
*)
# Default case if none of the above matches
config_files="$HOME/.bashrc $HOME/.bash_profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
;;
esac
if [[ "$no_modify_path" != "true" ]]; then
config_file=""
for file in $config_files; do
if [[ -f $file ]]; then
config_file=$file
break
fi
done
if [[ -z $config_file ]]; then
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
print_message info " export PATH=$INSTALL_DIR:\$PATH"
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
case $current_shell in
fish)
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
;;
zsh)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
bash)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
ash)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
sh)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
*)
export PATH=$INSTALL_DIR:$PATH
print_message warning "Manually add the directory to $config_file (or similar):"
print_message info " export PATH=$INSTALL_DIR:\$PATH"
;;
esac
fi
fi
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
echo "$INSTALL_DIR" >> $GITHUB_PATH
print_message info "Added $INSTALL_DIR to \$GITHUB_PATH"
fi
echo -e ""
echo -e " ${ORANGE}▶${NC} codeplane ${specific_version} installed."
echo -e ""
echo -e " ${MUTED}Get started:${NC}"
echo -e " cd <project>"
echo -e " codeplane ${MUTED}# launch the TUI${NC}"
echo -e " codeplane web ${MUTED}# or open the web UI${NC}"
echo -e ""
echo -e " ${MUTED}Docs:${NC} https://codeplane.cc/docs"
echo -e ""