#!/bin/sh # Agent Cortex installer. # Installs a read-only local watcher for the AI agents on this computer. # It downloads two files into ~/.agent-cortex and adds an `agent-cortex` command. set -eu BASE="${CORTEX_BASE:-https://agent-cortex.pages.dev}" DIR="${CORTEX_HOME:-$HOME/.agent-cortex}" say() { printf '%s\n' "$*"; } fail() { say "$*"; exit 1; } command -v curl >/dev/null 2>&1 || fail "curl is required but was not found." if ! command -v node >/dev/null 2>&1; then say "Agent Cortex needs Node.js 18 or newer, and Node was not found." say "Install it with: brew install node (or from https://nodejs.org)" exit 1 fi MAJOR=$(node -p 'process.versions.node.split(".")[0]') [ "$MAJOR" -ge 18 ] || fail "Agent Cortex needs Node.js 18 or newer; found $(node -v)." say "Installing Agent Cortex into $DIR" mkdir -p "$DIR" curl -fsSL "$BASE/app/cortex.mjs" -o "$DIR/cortex.mjs.tmp" curl -fsSL "$BASE/app/ui.html" -o "$DIR/ui.html.tmp" if ! grep -q "Agent Cortex" "$DIR/cortex.mjs.tmp" || ! grep -q "Agent Cortex" "$DIR/ui.html.tmp"; then rm -f "$DIR/cortex.mjs.tmp" "$DIR/ui.html.tmp" fail "The download did not look right, so nothing was installed." fi mv "$DIR/cortex.mjs.tmp" "$DIR/cortex.mjs" mv "$DIR/ui.html.tmp" "$DIR/ui.html" # Put the command somewhere already on PATH if we can write there. BIN="" for d in /opt/homebrew/bin /usr/local/bin "$HOME/.local/bin" "$HOME/bin"; do case ":$PATH:" in *":$d:"*) if [ -d "$d" ] && [ -w "$d" ]; then BIN="$d"; break; fi ;; esac done ONPATH=1 if [ -z "$BIN" ]; then BIN="$HOME/.local/bin"; mkdir -p "$BIN"; ONPATH=0; fi cat > "$BIN/agent-cortex" <