OpenCode-style TUI, model probing, sandboxed auto approval
- TUI: centered home screen with logo, boxed input with mode line, sidebar (>=120 cols), Ctrl+P palette, Tab Build/Plan, Shift+Tab approval cycle, mouse (cards, cursor, pickers, wheel), /sidebar /mouse /approval - /models probing: key check on entry (401 re-asks), API models in /model - Shell sandbox in C: Linux Landlock (writes limited to workspace/tmp, ABI>=4 blocks TCP), macOS sandbox_init, rules fallback elsewhere - Approval modes ask/auto/yolo (default auto); read-only command whitelist; ask to rerun outside the sandbox when a command looks blocked - Upgradable bootstrap scripts (git pull --ff-only, rebuild, reinstall) and cst-agent-update; cst-agent --version - tests: test_sandbox, test_models
This commit is contained in:
+108
-38
@@ -1,46 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-shot: clone (optional) + build CST-Agent on Linux, WSL or macOS.
|
||||
# Install or upgrade CST-Agent on Linux, WSL or macOS. Safe to rerun: an
|
||||
# existing checkout is fast-forwarded, rebuilt and reinstalled.
|
||||
#
|
||||
# bootstrap_linux.sh [DIR] [--no-pull]
|
||||
# cst-agent-update (installed by this script; same as rerunning it)
|
||||
#
|
||||
# Env: CST_AGENT_PREFIX (install prefix, default ~/.local), CST_AGENT_DIR
|
||||
# (checkout, default: current checkout or ~/CST-agent), CST_AGENT_REPO.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}"
|
||||
DIR="${1:-}"
|
||||
|
||||
if [[ -z "$DIR" ]]; then
|
||||
if [[ -f Makefile && -d src ]]; then
|
||||
DIR="$(pwd)"
|
||||
else
|
||||
DIR="CST-agent"
|
||||
deps_hint() {
|
||||
echo "==> deps: gcc/clang make pkg-config libcurl ncursesw"
|
||||
if [[ "$(uname -s)" == Darwin ]]; then
|
||||
echo " macOS: xcode-select --install && brew install ncurses curl pkg-config"
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
echo " Arch: sudo pacman -S --needed base-devel curl ncurses"
|
||||
elif command -v apt-get >/dev/null 2>&1; then
|
||||
echo " Debian/Ubuntu/WSL: sudo apt install build-essential pkg-config libcurl4-openssl-dev libncurses-dev"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo " Fedora: sudo dnf install gcc make pkgconf libcurl-devel ncurses-devel"
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
echo " Alpine: sudo apk add build-base pkgconf curl-dev ncurses-dev"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ ! -f "$DIR/Makefile" ]]; then
|
||||
echo "==> git clone $REPO_URL -> $DIR"
|
||||
git clone "$REPO_URL" "$DIR"
|
||||
fi
|
||||
cd "$DIR"
|
||||
# On NixOS (outside a nix shell) build inside shell.nix.
|
||||
run_make() {
|
||||
if [[ -z "${IN_NIX_SHELL:-}" ]] && command -v nix-shell >/dev/null 2>&1 &&
|
||||
[[ -f shell.nix ]]; then
|
||||
nix-shell --run "make $*"
|
||||
else
|
||||
make "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "==> deps hint: gcc/clang make cmake libcurl ncursesw"
|
||||
if [[ "$(uname -s)" == Darwin ]]; then
|
||||
echo " macOS: xcode-select --install && brew install ncurses curl pkg-config"
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
echo " Arch: sudo pacman -S --needed base-devel cmake curl ncurses"
|
||||
elif command -v apt-get >/dev/null 2>&1; then
|
||||
echo " Debian/Ubuntu/WSL: sudo apt install build-essential cmake pkg-config libcurl4-openssl-dev libncurses-dev"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo " Fedora: sudo dnf install gcc make cmake pkgconf libcurl-devel ncurses-devel"
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
echo " Alpine: sudo apk add build-base pkgconf curl-dev ncurses-dev"
|
||||
elif command -v nix-shell >/dev/null 2>&1; then
|
||||
echo " Nix: nix-shell (uses shell.nix), then rerun this script"
|
||||
fi
|
||||
main() {
|
||||
local repo_url="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}"
|
||||
local prefix="${CST_AGENT_PREFIX:-$HOME/.local}"
|
||||
local dir="" pull=1 changed=0 arg
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--no-pull) pull=0 ;;
|
||||
--rebuilt) changed=1 ;; # internal: re-exec after a pull
|
||||
-h | --help)
|
||||
sed -n '2,9p' "$0"
|
||||
return 0
|
||||
;;
|
||||
*) dir="$arg" ;;
|
||||
esac
|
||||
done
|
||||
if [[ -z "$dir" ]]; then
|
||||
if [[ -n "${CST_AGENT_DIR:-}" ]]; then
|
||||
dir="$CST_AGENT_DIR"
|
||||
elif [[ -f Makefile && -f src/main.c && -d .git ]]; then
|
||||
dir="$(pwd)"
|
||||
else
|
||||
dir="$HOME/CST-agent"
|
||||
fi
|
||||
fi
|
||||
|
||||
JOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
|
||||
echo "==> make"
|
||||
make -j"$JOBS"
|
||||
make check || true
|
||||
local old="" new=""
|
||||
if [[ ! -f "$dir/Makefile" ]]; then
|
||||
echo "==> git clone $repo_url -> $dir"
|
||||
git clone "$repo_url" "$dir"
|
||||
changed=1
|
||||
elif ((pull)); then
|
||||
old="$(git -C "$dir" rev-parse HEAD)"
|
||||
if git -C "$dir" diff --quiet && git -C "$dir" diff --cached --quiet; then
|
||||
echo "==> git pull ($dir)"
|
||||
git -C "$dir" pull --ff-only
|
||||
else
|
||||
echo "warning: $dir has local changes; skipping git pull" >&2
|
||||
fi
|
||||
new="$(git -C "$dir" rev-parse HEAD)"
|
||||
if [[ "$old" != "$new" ]]; then
|
||||
echo " $(git -C "$dir" log --oneline "$old..$new" | wc -l) new commit(s)"
|
||||
# The script itself may have changed: continue with the new version.
|
||||
exec bash "$dir/scripts/bootstrap_linux.sh" "$dir" --no-pull --rebuilt
|
||||
fi
|
||||
fi
|
||||
cd "$dir"
|
||||
dir="$(pwd)"
|
||||
|
||||
echo
|
||||
echo "OK: ./cst-agent"
|
||||
echo "Install: make install PREFIX=\$HOME/.local"
|
||||
echo "Run it inside a project directory: cst-agent"
|
||||
echo " (the first start asks for the provider and its API key and saves them)"
|
||||
local jobs
|
||||
jobs="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
|
||||
echo "==> build"
|
||||
if ((changed)); then
|
||||
run_make clean >/dev/null 2>&1 || true
|
||||
fi
|
||||
if ! run_make -j"$jobs"; then
|
||||
deps_hint
|
||||
return 1
|
||||
fi
|
||||
run_make check >/dev/null 2>&1 || echo "warning: some tests failed (run 'make check')"
|
||||
|
||||
echo "==> install to $prefix/bin"
|
||||
mkdir -p "$prefix/bin"
|
||||
run_make install PREFIX="$prefix" >/dev/null
|
||||
cat >"$prefix/bin/cst-agent-update" <<EOF
|
||||
#!$(command -v bash)
|
||||
exec bash "$dir/scripts/bootstrap_linux.sh" "$dir" "\$@"
|
||||
EOF
|
||||
chmod 0755 "$prefix/bin/cst-agent-update"
|
||||
|
||||
echo
|
||||
echo "OK: $("$prefix/bin/cst-agent" --version)"
|
||||
case ":$PATH:" in
|
||||
*":$prefix/bin:"*) ;;
|
||||
*) echo "Add to PATH: export PATH=\"$prefix/bin:\$PATH\"" ;;
|
||||
esac
|
||||
echo "Run 'cst-agent' inside a project directory; upgrade later with 'cst-agent-update'."
|
||||
echo "The first start asks for the provider and its API key and saves them."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
+82
-18
@@ -1,26 +1,90 @@
|
||||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
# One-shot: clone, build and install CST-Agent on Android Termux.
|
||||
# Install or upgrade CST-Agent on Android Termux. Safe to rerun: an existing
|
||||
# checkout is fast-forwarded, rebuilt and reinstalled.
|
||||
#
|
||||
# bootstrap_termux.sh [DIR] [--no-pull]
|
||||
# cst-agent-update (installed by this script; same as rerunning it)
|
||||
set -euo pipefail
|
||||
|
||||
REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}"
|
||||
DIR="${1:-CST-agent}"
|
||||
main() {
|
||||
local repo_url="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}"
|
||||
local dir="" pull=1 changed=0 arg
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--no-pull) pull=0 ;;
|
||||
--rebuilt) changed=1 ;; # internal: re-exec after a pull
|
||||
-h | --help)
|
||||
sed -n '2,6p' "$0"
|
||||
return 0
|
||||
;;
|
||||
*) dir="$arg" ;;
|
||||
esac
|
||||
done
|
||||
if [[ -z "$dir" ]]; then
|
||||
if [[ -n "${CST_AGENT_DIR:-}" ]]; then
|
||||
dir="$CST_AGENT_DIR"
|
||||
elif [[ -f Makefile && -f src/main.c && -d .git ]]; then
|
||||
dir="$(pwd)"
|
||||
else
|
||||
dir="$HOME/CST-agent"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> Termux packages"
|
||||
pkg install -y git clang make pkg-config binutils libcurl ncurses
|
||||
echo "==> Termux packages"
|
||||
local need=() p
|
||||
for p in git clang make pkg-config binutils libcurl ncurses; do
|
||||
dpkg -s "$p" >/dev/null 2>&1 || need+=("$p")
|
||||
done
|
||||
if ((${#need[@]})); then
|
||||
pkg install -y "${need[@]}"
|
||||
else
|
||||
echo " all present"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$DIR/Makefile" ]]; then
|
||||
echo "==> git clone $REPO_URL -> $DIR"
|
||||
git clone "$REPO_URL" "$DIR"
|
||||
fi
|
||||
cd "$DIR"
|
||||
local old="" new=""
|
||||
if [[ ! -f "$dir/Makefile" ]]; then
|
||||
echo "==> git clone $repo_url -> $dir"
|
||||
git clone "$repo_url" "$dir"
|
||||
changed=1
|
||||
elif ((pull)); then
|
||||
old="$(git -C "$dir" rev-parse HEAD)"
|
||||
if git -C "$dir" diff --quiet && git -C "$dir" diff --cached --quiet; then
|
||||
echo "==> git pull ($dir)"
|
||||
git -C "$dir" pull --ff-only
|
||||
else
|
||||
echo "warning: $dir has local changes; skipping git pull" >&2
|
||||
fi
|
||||
new="$(git -C "$dir" rev-parse HEAD)"
|
||||
if [[ "$old" != "$new" ]]; then
|
||||
echo " $(git -C "$dir" log --oneline "$old..$new" | wc -l) new commit(s)"
|
||||
# The script itself may have changed: continue with the new version.
|
||||
exec bash "$dir/scripts/bootstrap_termux.sh" "$dir" --no-pull --rebuilt
|
||||
fi
|
||||
fi
|
||||
cd "$dir"
|
||||
dir="$(pwd)"
|
||||
|
||||
echo "==> build"
|
||||
make -j"$(nproc 2>/dev/null || echo 4)"
|
||||
make check || echo "warning: some tests failed (see above)"
|
||||
echo "==> build"
|
||||
local jobs
|
||||
jobs="$(nproc 2>/dev/null || echo 4)"
|
||||
if ((changed)); then
|
||||
make clean >/dev/null 2>&1 || true
|
||||
fi
|
||||
make -j"$jobs"
|
||||
make check >/dev/null 2>&1 || echo "warning: some tests failed (run 'make check')"
|
||||
|
||||
echo "==> install to $PREFIX/bin"
|
||||
make install
|
||||
echo "==> install to $PREFIX/bin"
|
||||
make install
|
||||
cat >"$PREFIX/bin/cst-agent-update" <<EOF
|
||||
#!$PREFIX/bin/bash
|
||||
exec bash "$dir/scripts/bootstrap_termux.sh" "$dir" "\$@"
|
||||
EOF
|
||||
chmod 0755 "$PREFIX/bin/cst-agent-update"
|
||||
|
||||
echo
|
||||
echo "OK: run 'cst-agent' inside a project directory."
|
||||
echo "The first start asks for the provider and its API key and saves them."
|
||||
echo
|
||||
echo "OK: $("$PREFIX/bin/cst-agent" --version)"
|
||||
echo "Run 'cst-agent' inside a project directory; upgrade later with 'cst-agent-update'."
|
||||
echo "The first start asks for the provider and its API key and saves them."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user