#!/bin/sh # VisionFlow (VF Agent) one-line installer. POSIX sh, macOS Apple Silicon. # # curl -fsSL https:///install.sh | sh # curl -fsSL https:///install.sh | sh -s -- --skip-models # # It downloads one release (wheel, hash-pinned dependency lock, plugin bundle, ExifTool), # verifies every file against the release's SHA256SUMS, installs the isolated runtime through # the plugin's own install.sh, registers the plugin with Claude Code and Codex when their CLIs # are present, and downloads the local models. No sudo, no Homebrew, no shell profile edits. # # The release layout this script expects is produced by packaging/build_release.py: # /LATEST one line, the newest version # //SHA256SUMS " " per artifact # // set -eu # Both values are filled in by packaging/build_release.py. An unreplaced placeholder means # "not embedded": the base must then come from --base or VF_RELEASE_BASE. EMBEDDED_BASE="https://vf-agent.oioi.bio/releases" EMBEDDED_VERSION="0.12.3" PLUGIN_NAME="vf-agent" MARKETPLACE_NAME="vf-agent" PLUGIN_MARKER=".vf-plugin-root" say() { printf '%s\n' "$*"; } step() { printf '\n==> %s\n' "$*"; } warn() { printf 'warning: %s\n' "$*" >&2; } die() { printf 'error: %s\n' "$*" >&2; exit 1; } usage() { cat <<'EOF' Usage: install.sh [OPTIONS] Install VisionFlow: the local runtime, the local models and the agent plugin. Options: --version Install this release instead of the newest one --base Release root (default: the site this script was published to, or $VF_RELEASE_BASE) --home VisionFlow home (default: ~/Library/Application Support/VisionFlow) --skip-models Do not download models now (run `vf models install` later) --model-source Model download source, e.g. hf-mirror --skip-plugin Do not register the plugin with Claude Code / Codex --hosts Hosts to register with, comma separated (default: claude,codex) --dry-run Download and verify into a temporary directory, print the plan, change nothing --uninstall Remove the runtime and the plugin (keeps projects and models) -h, --help Show this help EOF } is_placeholder() { case "$1" in "@@"*"@@"|"") return 0 ;; *) return 1 ;; esac } fetch() { # fetch case "$BASE" in http://*|https://*) curl -fL -sS --retry 3 --connect-timeout 20 -o "$2" "$BASE/$1" ;; file://*) cp -- "${BASE#file://}/$1" "$2" ;; *) cp -- "$BASE/$1" "$2" ;; esac } safe_name() { case "$1" in ""|.*|*/*|*[!0-9A-Za-z._+-]*) return 1 ;; *) return 0 ;; esac } file_url() { # curl decodes %XX in file:// URLs, so only the characters that break the URL are escaped. printf 'file://%s' "$1" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/#/%23/g' -e 's/?/%3F/g' } run_quiet() { # Child processes never read this script when it is piped into sh. "$@" /dev/null 2>&1 } register_claude() { if ! command -v claude >/dev/null 2>&1; then say " Claude Code: CLI not found, skipped." return 0 fi run_quiet claude plugin marketplace add "$PLUGIN_ROOT" \ || run_quiet claude plugin marketplace update "$MARKETPLACE_NAME" || true if run_quiet claude plugin install "$PLUGIN_NAME@$MARKETPLACE_NAME" \ || run_quiet claude plugin update "$PLUGIN_NAME@$MARKETPLACE_NAME"; then say " Claude Code: plugin $PLUGIN_NAME registered." else warn "Claude Code: could not register the plugin automatically. Run:" say " claude plugin marketplace add \"$PLUGIN_ROOT\"" say " claude plugin install $PLUGIN_NAME@$MARKETPLACE_NAME" fi } register_codex() { if ! command -v codex >/dev/null 2>&1; then say " Codex: CLI not found, skipped." return 0 fi # Codex records the resolved versioned directory, so an upgrade has to replace the old entry. run_quiet codex plugin remove "$PLUGIN_NAME@$MARKETPLACE_NAME" || true run_quiet codex plugin marketplace remove "$MARKETPLACE_NAME" || true run_quiet codex plugin marketplace add "$PLUGIN_ROOT" || true if run_quiet codex plugin add "$PLUGIN_NAME@$MARKETPLACE_NAME"; then say " Codex: plugin $PLUGIN_NAME registered." else warn "Codex: could not register the plugin automatically. Run:" say " codex plugin marketplace add \"$PLUGIN_ROOT\"" say " codex plugin add $PLUGIN_NAME@$MARKETPLACE_NAME" fi } unregister_hosts() { if command -v claude >/dev/null 2>&1; then run_quiet claude plugin uninstall "$PLUGIN_NAME@$MARKETPLACE_NAME" || true run_quiet claude plugin marketplace remove "$MARKETPLACE_NAME" || true say " Claude Code: plugin registration removed (if it was present)." fi if command -v codex >/dev/null 2>&1; then run_quiet codex plugin remove "$PLUGIN_NAME@$MARKETPLACE_NAME" || true run_quiet codex plugin marketplace remove "$MARKETPLACE_NAME" || true say " Codex: plugin registration removed (if it was present)." fi } main() { VERSION="" BASE="${VF_RELEASE_BASE:-}" VF_HOME_DIR="${VF_HOME:-$HOME/Library/Application Support/VisionFlow}" HOME_OVERRIDDEN=0 SKIP_MODELS=0 MODEL_SOURCE="" SKIP_PLUGIN=0 HOSTS="claude,codex" DRY_RUN=0 UNINSTALL=0 while [ $# -gt 0 ]; do case "$1" in --version) [ $# -ge 2 ] || die "--version requires a value"; VERSION=$2; shift 2 ;; --version=*) VERSION=${1#--version=}; shift ;; --base) [ $# -ge 2 ] || die "--base requires a value"; BASE=$2; shift 2 ;; --base=*) BASE=${1#--base=}; shift ;; --home) [ $# -ge 2 ] || die "--home requires a value"; VF_HOME_DIR=$2; HOME_OVERRIDDEN=1; shift 2 ;; --home=*) VF_HOME_DIR=${1#--home=}; HOME_OVERRIDDEN=1; shift ;; --skip-models) SKIP_MODELS=1; shift ;; --model-source) [ $# -ge 2 ] || die "--model-source requires a value"; MODEL_SOURCE=$2; shift 2 ;; --model-source=*) MODEL_SOURCE=${1#--model-source=}; shift ;; --skip-plugin) SKIP_PLUGIN=1; shift ;; --hosts) [ $# -ge 2 ] || die "--hosts requires a value"; HOSTS=$2; shift 2 ;; --hosts=*) HOSTS=${1#--hosts=}; shift ;; --dry-run) DRY_RUN=1; shift ;; --uninstall) UNINSTALL=1; shift ;; -h|--help) usage; exit 0 ;; *) usage >&2; die "unknown option: $1" ;; esac done [ -n "$VF_HOME_DIR" ] || die "--home must not be empty" if [ -n "${VF_HOME:-}" ]; then HOME_OVERRIDDEN=1; fi RUNTIME_HOME="${VF_RUNTIME_HOME:-$VF_HOME_DIR/runtime}" PLUGIN_HOME="$VF_HOME_DIR/plugin" PLUGIN_ROOT="$PLUGIN_HOME/current" # ---- Uninstall ---- if [ "$UNINSTALL" = "1" ]; then step "Removing VisionFlow from $VF_HOME_DIR" if [ "$DRY_RUN" = "1" ]; then say " Would unregister the plugin from Claude Code and Codex." say " Would remove the runtime at $RUNTIME_HOME." say " Would remove the plugin copies at $PLUGIN_HOME and downloads at $VF_HOME_DIR/downloads." say " Projects, catalogs and model caches are never touched." exit 0 fi unregister_hosts if [ -f "$PLUGIN_ROOT/plugin/install/install.sh" ]; then sh "$PLUGIN_ROOT/plugin/install/install.sh" --uninstall --runtime-home "$RUNTIME_HOME" /dev/null || printf unknown) ARCH_NAME=$(uname -m 2>/dev/null || printf unknown) if [ "$OS_NAME" != "Darwin" ] || [ "$ARCH_NAME" != "arm64" ]; then if [ "$DRY_RUN" = "1" ]; then warn "VisionFlow needs macOS on Apple Silicon; this machine is $OS_NAME $ARCH_NAME. Continuing because of --dry-run." else die "VisionFlow needs macOS on Apple Silicon (M-series). This machine is $OS_NAME $ARCH_NAME." fi fi for _tool in curl tar shasum; do command -v "$_tool" >/dev/null 2>&1 || die "$_tool is required but was not found." done if [ -z "$BASE" ]; then if is_placeholder "$EMBEDDED_BASE"; then die "no release location: pass --base or set VF_RELEASE_BASE." fi BASE=$EMBEDDED_BASE fi BASE=${BASE%/} WORK=$(mktemp -d "${TMPDIR:-/tmp}/vf-install.XXXXXX") trap 'rm -rf -- "$WORK"' EXIT INT TERM # ---- Resolve the version ---- if [ -z "$VERSION" ] && ! is_placeholder "$EMBEDDED_VERSION"; then VERSION=$EMBEDDED_VERSION fi if [ -z "$VERSION" ]; then fetch LATEST "$WORK/LATEST" || die "could not read $BASE/LATEST" VERSION=$(sed -n '1p' "$WORK/LATEST" | tr -d '[:space:]') fi VERSION=${VERSION#v} safe_name "$VERSION" || die "unexpected version string: $VERSION" step "VisionFlow $VERSION" say " release: $BASE/$VERSION" say " home: $VF_HOME_DIR" # ---- Download and verify ---- step "Downloading and verifying the release" STAGE="$WORK/stage" mkdir -p -- "$STAGE" _root=$BASE BASE="$_root/$VERSION" fetch SHA256SUMS "$STAGE/SHA256SUMS" || die "could not read $BASE/SHA256SUMS" WHEEL=""; LOCK=""; PLUGIN_TAR=""; EXIF_TAR="" : > "$STAGE/SHA256SUMS.checked" while read -r _sum _name; do [ -n "$_sum" ] || continue _name=${_name#\*} safe_name "$_name" || die "unexpected file name in SHA256SUMS: $_name" case "$_name" in *.whl) WHEEL=$_name ;; *.lock.txt) LOCK=$_name ;; vf-agent-plugin-*.tar.gz) PLUGIN_TAR=$_name ;; Image-ExifTool-*.tar.gz) EXIF_TAR=$_name ;; *) continue ;; esac fetch "$_name" "$STAGE/$_name" || die "could not download $BASE/$_name" printf '%s %s\n' "$_sum" "$_name" >> "$STAGE/SHA256SUMS.checked" say " fetched $_name" done < "$STAGE/SHA256SUMS" [ -n "$WHEEL" ] || die "the release has no wheel" [ -n "$LOCK" ] || die "the release has no dependency lock" [ -n "$PLUGIN_TAR" ] || die "the release has no plugin bundle" if ! (cd "$STAGE" && shasum -a 256 -c SHA256SUMS.checked >/dev/null 2>&1); then (cd "$STAGE" && shasum -a 256 -c SHA256SUMS.checked 2>&1 | sed 's/^/ /' >&2) || true die "checksum verification failed; nothing was installed." fi say " all checksums match" if tar -tzf "$STAGE/$PLUGIN_TAR" | grep -E '(^/|(^|/)\.\.(/|$))' >/dev/null 2>&1; then die "the plugin bundle contains unsafe paths; nothing was installed." fi # ---- Dry run: show the plan from the verified files, change nothing ---- if [ "$DRY_RUN" = "1" ]; then mkdir -p -- "$WORK/plugin" tar -xzf "$STAGE/$PLUGIN_TAR" -C "$WORK/plugin" step "Plan (dry run, nothing is changed)" say " 1. Unpack the plugin to $PLUGIN_HOME/$VERSION and point $PLUGIN_ROOT at it." say " 2. Install the runtime into $RUNTIME_HOME from $WHEEL," say " with every dependency pinned by $LOCK:" sh "$WORK/plugin/plugin/install/install.sh" --dry-run --version "$VERSION" \ --from "$STAGE/$WHEEL" --lock "$STAGE/$LOCK" --runtime-home "$RUNTIME_HOME" "$PLUGIN_HOME/$PLUGIN_MARKER" : > "$VF_HOME_DIR/downloads/$PLUGIN_MARKER" PLUGIN_NEW="$PLUGIN_HOME/.incoming-$VERSION-$$" rm -rf -- "$PLUGIN_NEW" mkdir -p -- "$PLUGIN_NEW" tar -xzf "$STAGE/$PLUGIN_TAR" -C "$PLUGIN_NEW" [ -f "$PLUGIN_NEW/plugin/install/install.sh" ] && [ -f "$PLUGIN_NEW/plugin/bin/vf" ] \ || { rm -rf -- "$PLUGIN_NEW"; die "the plugin bundle is incomplete; nothing was installed."; } rm -rf -- "$PLUGIN_HOME/$VERSION" mv -- "$PLUGIN_NEW" "$PLUGIN_HOME/$VERSION" ln -sfn "$VERSION" "$PLUGIN_ROOT" say " $PLUGIN_ROOT -> $VERSION" # Keep the verified artifacts next to the install for support and reinstalls. KEEP="$VF_HOME_DIR/downloads/$VERSION" rm -rf -- "$KEEP" mkdir -p -- "$KEEP" cp -- "$STAGE"/* "$KEEP"/ # ---- Runtime ---- step "Installing the local runtime (a few minutes on first install)" if [ -n "$EXIF_TAR" ]; then VF_EXIFTOOL_URL=$(file_url "$KEEP/$EXIF_TAR") export VF_EXIFTOOL_URL fi sh "$PLUGIN_ROOT/plugin/install/install.sh" --version "$VERSION" \ --from "$KEEP/$WHEEL" --lock "$KEEP/$LOCK" --runtime-home "$RUNTIME_HOME"