An always-on second brain you talk to. Voice notes in Telegram → typed, linked knowledge in your Obsidian vault. Runs 24/7 on the Claude subscription you already have.
Python ai-agentsai-automationclaudeclaude-codeebbinghausknowledge-graphllmmemory-systemobsidianpersonal-assistantpkmproductivitypythonsecond-braintelegram-botvoice-assistant
feat(setup)!: v3.0 installer — interview + upgrade.sh, drop Mac installer
smixsf7f9d199f023
diff --git a/install.sh b/install.shdeleted file mode 100755index 5713be8..0000000--- a/install.sh+++ /dev/null@@ -1,476 +0,0 @@-#!/bin/bash-# Agent Second Brain — One-command installer-# Works on Mac and Windows WSL-# https://github.com/smixs/agent-second-brain--set -e--# Colors-RED='\033[0;31m'-GREEN='\033[0;32m'-YELLOW='\033[1;33m'-BLUE='\033[0;34m'-NC='\033[0m' # No Color--# Config-REPO_URL="https://github.com/smixs/agent-second-brain.git"-INSTALL_DIR="$HOME/agent-second-brain"--#######################################-# Print colored message-#######################################-info() { echo -e "${BLUE}ℹ${NC} $1"; }-success() { echo -e "${GREEN}✓${NC} $1"; }-warn() { echo -e "${YELLOW}⚠${NC} $1"; }-error() { echo -e "${RED}✗${NC} $1"; exit 1; }--#######################################-# Detect OS-#######################################-detect_os() {- if [[ "$OSTYPE" == "darwin"* ]]; then- OS="mac"- info "Detected: macOS"- elif grep -q Microsoft /proc/version 2>/dev/null; then- OS="wsl"- info "Detected: Windows WSL"- elif [[ "$OSTYPE" == "linux-gnu"* ]]; then- OS="linux"- info "Detected: Linux"- else- error "Unsupported OS. This script works on Mac and Windows WSL only."- fi-}--#######################################-# Check if command exists-#######################################-has_command() {- command -v "$1" &> /dev/null-}--#######################################-# Install Homebrew (Mac only)-#######################################-install_homebrew() {- if [[ "$OS" != "mac" ]]; then return; fi-- if has_command brew; then- success "Homebrew already installed"- else- info "Installing Homebrew..."- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"-- # Add to PATH for current session- if [[ -f /opt/homebrew/bin/brew ]]; then- eval "$(/opt/homebrew/bin/brew shellenv)"- elif [[ -f /usr/local/bin/brew ]]; then- eval "$(/usr/local/bin/brew shellenv)"- fi-- success "Homebrew installed"- fi-}--#######################################-# Install dependencies-#######################################-install_dependencies() {- info "Installing dependencies..."-- if [[ "$OS" == "mac" ]]; then- # Node.js- if ! has_command node; then- info "Installing Node.js..."- brew install node- fi- success "Node.js $(node --version)"-- # Python 3.12- if ! has_command python3.12; then- info "Installing Python 3.12..."- brew install [email protected]- fi- success "Python $(python3.12 --version)"-- # Git- if ! has_command git; then- info "Installing Git..."- brew install git- fi- success "Git $(git --version | head -1)"-- elif [[ "$OS" == "wsl" ]] || [[ "$OS" == "linux" ]]; then- info "Updating apt packages..."- sudo apt update && sudo apt upgrade -y-- # Node.js 20- if ! has_command node; then- info "Installing Node.js..."- curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -- sudo apt install -y nodejs- fi- success "Node.js $(node --version)"-- # Python 3.12- if ! has_command python3.12; then- info "Installing Python 3.12..."- sudo apt install -y software-properties-common- sudo add-apt-repository -y ppa:deadsnakes/ppa- sudo apt update- sudo apt install -y python3.12 python3.12-venv python3.12-dev- fi- success "Python $(python3.12 --version)"-- # Git- if ! has_command git; then- info "Installing Git..."- sudo apt install -y git curl wget- fi- success "Git $(git --version | head -1)"- fi-}--#######################################-# Install uv (Python package manager)-#######################################-install_uv() {- if has_command uv; then- success "uv already installed: $(uv --version)"- else- info "Installing uv..."- curl -LsSf https://astral.sh/uv/install.sh | sh-- # Add to PATH for current session- export PATH="$HOME/.local/bin:$PATH"-- success "uv installed: $(uv --version)"- fi-}--#######################################-# Install Claude Code CLI-#######################################-install_claude() {- if has_command claude; then- success "Claude Code already installed: $(claude --version)"- else- info "Installing Claude Code CLI..."- npm install -g @anthropic-ai/claude-code- success "Claude Code installed"- fi-}--#######################################-# Clone repository-#######################################-clone_repo() {- if [[ -d "$INSTALL_DIR" ]]; then- warn "Directory $INSTALL_DIR already exists"- read -p "Overwrite? (y/n): " -n 1 -r < /dev/tty- echo- if [[ $REPLY =~ ^[Yy]$ ]]; then- rm -rf "$INSTALL_DIR"- else- error "Installation cancelled"- fi- fi-- info "Cloning repository..."- git clone "$REPO_URL" "$INSTALL_DIR"- success "Repository cloned to $INSTALL_DIR"-}--#######################################-# Prompt for token-#######################################-prompt_token() {- local name="$1"- local desc="$2"- local url="$3"- local var_name="$4"- local optional="${5:-false}"-- echo- echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"- echo -e "${YELLOW}$name${NC}"- echo "$desc"- echo -e "Get it here: ${GREEN}$url${NC}"- echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"-- if [[ "$optional" == "true" ]]; then- read -p "Enter token (or press Enter to skip): " token < /dev/tty- else- while true; do- read -p "Enter token: " token < /dev/tty- if [[ -n "$token" ]]; then- break- fi- warn "This token is required"- done- fi-- eval "$var_name=\"$token\""-}--#######################################-# Collect tokens interactively-#######################################-collect_tokens() {- echo- echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"- echo -e "${GREEN}║ TOKEN CONFIGURATION ║${NC}"- echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"- echo- echo "You'll need to provide 3 tokens. Instructions for each below."-- # Telegram Bot Token- prompt_token \- "1/3: Telegram Bot Token" \- "Create a bot via @BotFather in Telegram:-1. Open Telegram and search for @BotFather-2. Send /newbot-3. Follow instructions to create your bot-4. Copy the token (looks like: 7123456789:AAHd...)" \- "https://t.me/BotFather" \- "TELEGRAM_BOT_TOKEN"-- # Telegram User ID- prompt_token \- "2/3: Your Telegram User ID" \- "Get your ID via @userinfobot:-1. Search for @userinfobot in Telegram-2. Send any message-3. Copy your ID (just the number)" \- "https://t.me/userinfobot" \- "TELEGRAM_USER_ID"-- # Deepgram API Key- prompt_token \- "3/3: Deepgram API Key" \- "For voice transcription (free \$200 credit):-1. Sign up at console.deepgram.com-2. Go to Settings → API Keys-3. Create new key and copy it" \- "https://console.deepgram.com/" \- "DEEPGRAM_API_KEY"-}--#######################################-# Create .env file-#######################################-create_env() {- info "Creating .env file..."-- cat > "$INSTALL_DIR/.env" << EOF-# Telegram Bot Token (from @BotFather)-TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN--# Deepgram API Key (from console.deepgram.com)-DEEPGRAM_API_KEY=$DEEPGRAM_API_KEY--# Path to vault (don't change)-VAULT_PATH=./vault--# Your Telegram ID (bot responds only to you)-ALLOWED_USER_IDS=[$TELEGRAM_USER_ID]-EOF-- success ".env file created"-}--#######################################-# Install Python dependencies-#######################################-install_python_deps() {- info "Installing Python dependencies..."- cd "$INSTALL_DIR"- uv sync- success "Python dependencies installed"-}--#######################################-# Authenticate Claude-#######################################-auth_claude() {- echo- echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"- echo -e "${YELLOW}Claude Authentication${NC}"- echo "You need Claude Pro subscription (\$20/month) for this to work."- echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"- echo-- if claude auth status &>/dev/null; then- success "Claude already authenticated"- else- info "Starting Claude authentication..."- echo "A browser window will open. Log in with your Anthropic account."- echo- claude auth login- success "Claude authenticated"- fi-}--#######################################-# Setup autostart (optional)-#######################################-setup_autostart() {- echo- read -p "Configure autostart (bot runs when computer starts)? (y/n): " -n 1 -r < /dev/tty- echo-- if [[ ! $REPLY =~ ^[Yy]$ ]]; then- info "Skipping autostart configuration"- return- fi-- if [[ "$OS" == "mac" ]]; then- setup_launchd- else- setup_systemd- fi-}--#######################################-# Setup launchd (Mac)-#######################################-setup_launchd() {- info "Configuring launchd..."-- mkdir -p ~/Library/LaunchAgents-- cat > ~/Library/LaunchAgents/com.agent-second-brain.plist << EOF-<?xml version="1.0" encoding="UTF-8"?>-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">-<plist version="1.0">-<dict>- <key>Label</key>- <string>com.agent-second-brain</string>- <key>ProgramArguments</key>- <array>- <string>$HOME/.local/bin/uv</string>- <string>run</string>- <string>python</string>- <string>-m</string>- <string>d_brain</string>- </array>- <key>WorkingDirectory</key>- <string>$INSTALL_DIR</string>- <key>RunAtLoad</key>- <true/>- <key>KeepAlive</key>- <true/>- <key>StandardOutPath</key>- <string>$INSTALL_DIR/logs/bot.log</string>- <key>StandardErrorPath</key>- <string>$INSTALL_DIR/logs/bot-error.log</string>-</dict>-</plist>-EOF-- mkdir -p "$INSTALL_DIR/logs"- launchctl load ~/Library/LaunchAgents/com.agent-second-brain.plist-- success "Autostart configured (launchd)"- info "Bot will start automatically on login"-}--#######################################-# Setup systemd (Linux/WSL)-#######################################-setup_systemd() {- info "Configuring systemd..."-- mkdir -p ~/.config/systemd/user-- cat > ~/.config/systemd/user/agent-second-brain.service << EOF-[Unit]-Description=Agent Second Brain Telegram Bot-After=network.target--[Service]-Type=simple-WorkingDirectory=$INSTALL_DIR-ExecStart=$HOME/.local/bin/uv run python -m d_brain-Restart=always-RestartSec=10-Environment=PYTHONUNBUFFERED=1--[Install]-WantedBy=default.target-EOF-- systemctl --user daemon-reload- systemctl --user enable agent-second-brain- systemctl --user start agent-second-brain-- success "Autostart configured (systemd)"- info "Bot is running now and will start on boot"-}--#######################################-# Start bot manually-#######################################-start_bot() {- echo- echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"- echo -e "${GREEN}║ INSTALLATION COMPLETE! ║${NC}"- echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"- echo-- if [[ "$OS" == "mac" ]] && [[ -f ~/Library/LaunchAgents/com.agent-second-brain.plist ]]; then- echo "Bot is running in background."- echo- echo "Commands:"- echo " Stop: launchctl unload ~/Library/LaunchAgents/com.agent-second-brain.plist"- echo " Start: launchctl load ~/Library/LaunchAgents/com.agent-second-brain.plist"- echo " Logs: tail -f $INSTALL_DIR/logs/bot.log"- elif systemctl --user is-active --quiet agent-second-brain 2>/dev/null; then- echo "Bot is running in background."- echo- echo "Commands:"- echo " Stop: systemctl --user stop agent-second-brain"- echo " Start: systemctl --user start agent-second-brain"- echo " Logs: journalctl --user -u agent-second-brain -f"- else- echo "To start the bot manually:"- echo- echo -e " ${GREEN}cd $INSTALL_DIR && uv run python -m d_brain${NC}"- echo- read -p "Start bot now? (y/n): " -n 1 -r < /dev/tty- echo- if [[ $REPLY =~ ^[Yy]$ ]]; then- cd "$INSTALL_DIR"- info "Starting bot... (Ctrl+C to stop)"- uv run python -m d_brain- fi- fi-}--#######################################-# Main-#######################################-main() {- echo- echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"- echo -e "${GREEN}║ AGENT SECOND BRAIN INSTALLER ║${NC}"- echo -e "${GREEN}║ ║${NC}"- echo -e "${GREEN}║ Voice-first AI assistant with memory ║${NC}"- echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"- echo-- detect_os- install_homebrew- install_dependencies- install_uv- install_claude- clone_repo- collect_tokens- create_env- install_python_deps- auth_claude- setup_autostart- start_bot-}--main "$@"diff --git a/setup.sh b/setup.shindex 8381bd6..dbaf741 100755--- a/setup.sh+++ b/setup.sh@@ -1,10 +1,15 @@#!/bin/bash# =============================================================================-# Agent Second Brain - VPS Setup Script+# Agent Second Brain - VPS Setup Script (v3.0)# =============================================================================-# One-command setup for your personal AI assistant-# Usage: curl -fsSL https://raw.githubusercontent.com/YOUR_USER/agent-second-brain/main/setup.sh | bash+# Interactive first-time setup: installs dependencies, clones your fork,+# asks for tokens, then delegates the heavy lifting (systemd units, brain+# session, health check) to upgrade.sh — the same script that migrates+# existing installs. One source of truth, no drift.+#+# Usage:+# curl -fsSL https://raw.githubusercontent.com/smixs/agent-second-brain/main/bootstrap.sh | bash# Or: bash setup.sh# =============================================================================@@ -17,49 +22,34 @@ YELLOW='\033[1;33m'BLUE='\033[0;34m'PURPLE='\033[0;35m'CYAN='\033[0;36m'-NC='\033[0m' # No Color+NC='\033[0m'BOLD='\033[1m'-# Emojis (safe for most terminals)CHECK="[OK]"CROSS="[X]"WARN="[!]"ARROW="-->"GEAR="[*]"-# =============================================================================-# Helper functions-# =============================================================================-print_banner() {echo ""echo -e "${PURPLE}${BOLD}"echo " ╔═══════════════════════════════════════════════════════════╗"echo " ║ ║"- echo " ║ AGENT SECOND BRAIN - VPS SETUP ║"+ echo " ║ AGENT SECOND BRAIN - VPS SETUP (v3.0) ║"echo " ║ ║"- echo " ║ Personal AI Assistant with Long-term Memory ║"+ echo " ║ Always-on agent with long-term memory ║"echo " ║ ║"echo " ╚═══════════════════════════════════════════════════════════╝"echo -e "${NC}"echo ""}-info() {- echo -e "${BLUE}${GEAR}${NC} $1"-}--success() {- echo -e "${GREEN}${CHECK}${NC} $1"-}--warn() {- echo -e "${YELLOW}${WARN}${NC} $1"-}--error() {- echo -e "${RED}${CROSS}${NC} $1"-}+info() { echo -e "${BLUE}${GEAR}${NC} $1"; }+success() { echo -e "${GREEN}${CHECK}${NC} $1"; }+warn() { echo -e "${YELLOW}${WARN}${NC} $1"; }+error() { echo -e "${RED}${CROSS}${NC} $1"; }+ask() { echo -e "${YELLOW}?${NC} $1"; }step() {echo ""@@ -67,43 +57,24 @@ step() {echo -e "${CYAN}$(printf '%.0s─' {1..60})${NC}"}-ask() {- echo -e "${YELLOW}?${NC} $1"-}-# =============================================================================-# Validation functions+# Validation# =============================================================================validate_telegram_token() {- local token="$1"- # Telegram bot token format: 123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11- if [[ $token =~ ^[0-9]+:[A-Za-z0-9_-]+$ ]]; then- return 0- fi- return 1+ [[ $1 =~ ^[0-9]+:[A-Za-z0-9_-]+$ ]]}validate_telegram_id() {- local id="$1"- # Telegram ID is a positive integer- if [[ $id =~ ^[0-9]+$ ]] && [ "$id" -gt 0 ]; then- return 0- fi- return 1+ [[ $1 =~ ^[0-9]+$ ]] && [ "$1" -gt 0 ]}validate_deepgram_key() {- local key="$1"- # Deepgram key is alphanumeric, typically 40+ chars- if [[ $key =~ ^[A-Za-z0-9]+$ ]] && [ ${#key} -ge 20 ]; then- return 0- fi- return 1+ [[ $1 =~ ^[A-Za-z0-9]+$ ]] && [ ${#1} -ge 20 ]}# =============================================================================-# Check functions+# Checks# =============================================================================check_root() {@@ -133,64 +104,37 @@ check_command() {}# =============================================================================-# Installation functions+# Installation# =============================================================================install_system_deps() {step "Installing system dependencies"-info "Updating package list..."sudo apt-get update -qq-- info "Installing git, curl, wget, build-essential..."- sudo apt-get install -y -qq git curl wget build-essential software-properties-common-+ info "Installing git, curl, wget, tmux..."+ sudo apt-get install -y -qq git curl wget tmuxsuccess "System dependencies installed"}-install_python() {- step "Installing Python 3.12"-- if check_command python3.12; then- success "Python 3.12 already installed"- return- fi-- info "Adding deadsnakes PPA..."- sudo add-apt-repository -y ppa:deadsnakes/ppa- sudo apt-get update -qq-- info "Installing Python 3.12..."- sudo apt-get install -y -qq python3.12 python3.12-venv python3.12-dev-- success "Python 3.12 installed"-}-install_uv() {step "Installing uv (Python package manager)"-- if check_command uv; then+ if check_command uv || [ -x "$HOME/.local/bin/uv" ]; thensuccess "uv already installed"returnfi-info "Downloading and installing uv..."curl -LsSf https://astral.sh/uv/install.sh | sh-- # Add to current sessionexport PATH="$HOME/.local/bin:$PATH"-- # Add to .bashrc if not already thereif ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' ~/.bashrc 2>/dev/null; thenecho 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrcfi-+ # uv manages its own CPython (requires-python from pyproject) — no+ # system Python or PPA needed.success "uv installed"}install_nodejs() {- step "Installing Node.js 20"-+ step "Installing Node.js 20 (required by Claude Code)"if check_command node; thenNODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)if [ "$NODE_VERSION" -ge 18 ]; then@@ -198,32 +142,26 @@ install_nodejs() {returnfifi-info "Adding NodeSource repository..."curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash --info "Installing Node.js..."sudo apt-get install -y -qq nodejs-success "Node.js $(node --version) installed"}install_claude_cli() {- step "Installing Claude CLI"-+ step "Installing Claude Code"if check_command claude; then- success "Claude CLI already installed: $(claude --version 2>/dev/null || echo 'version unknown')"+ success "Claude Code already installed: $(claude --version 2>/dev/null || echo 'version unknown')"returnfi-info "Installing @anthropic-ai/claude-code globally..."sudo npm install -g @anthropic-ai/claude-code-- success "Claude CLI installed"+ success "Claude Code installed"}# =============================================================================-# Configuration functions+# Configuration# =============================================================================clone_repository() {@@ -231,7 +169,6 @@ clone_repository() {PROJECTS_DIR="$HOME/projects"PROJECT_DIR="$PROJECTS_DIR/agent-second-brain"-mkdir -p "$PROJECTS_DIR"if [ -d "$PROJECT_DIR" ]; then@@ -248,16 +185,13 @@ clone_repository() {ask "Enter your GitHub username (the one where you forked the repo):"read -r GITHUB_USER-if [ -z "$GITHUB_USER" ]; thenerror "GitHub username cannot be empty"exit 1fiREPO_URL="https://github.com/$GITHUB_USER/agent-second-brain.git"-info "Cloning from $REPO_URL..."-if ! git clone "$REPO_URL" "$PROJECT_DIR" 2>/dev/null; thenerror "Failed to clone repository!"echo " Make sure you've forked the repo and the username is correct"@@ -266,8 +200,6 @@ clone_repository() {cd "$PROJECT_DIR"success "Repository cloned to $PROJECT_DIR"-- # Save GitHub user for laterecho "$GITHUB_USER" > .github_user}@@ -280,48 +212,46 @@ collect_tokens() {echo " - Deepgram API Key (from console.deepgram.com)"echo ""- # Telegram Bot Tokenwhile true; doask "Telegram Bot Token (from @BotFather):"read -r TELEGRAM_BOT_TOKENif validate_telegram_token "$TELEGRAM_BOT_TOKEN"; thensuccess "Token format valid"break- else- error "Invalid token format. Should be like: 123456789:ABC-DEF1234ghIkl-zyx57W2v"fi+ error "Invalid token format. Should be like: 123456789:ABC-DEF1234ghIkl-zyx57W2v"done- # Telegram User IDwhile true; doask "Your Telegram User ID (from @userinfobot):"read -r TELEGRAM_USER_IDif validate_telegram_id "$TELEGRAM_USER_ID"; thensuccess "User ID valid"break- else- error "Invalid User ID. Should be a number like: 123456789"fi+ error "Invalid User ID. Should be a number like: 123456789"done- # Deepgram API Keywhile true; doask "Deepgram API Key (from console.deepgram.com):"read -r DEEPGRAM_API_KEYif validate_deepgram_key "$DEEPGRAM_API_KEY"; thensuccess "API Key format valid"break- else- error "Invalid API key format. Should be alphanumeric, 20+ characters"fi+ error "Invalid API key format. Should be alphanumeric, 20+ characters"done++ ask "Your timezone for reports and schedules (Enter for UTC, e.g. Asia/Tashkent):"+ read -r USER_TZ+ USER_TZ="${USER_TZ:-UTC}"+ success "Timezone: $USER_TZ"}create_env_file() {step "Creating .env file"ENV_FILE="$PROJECT_DIR/.env"-if [ -f "$ENV_FILE" ]; thenwarn ".env file already exists"read -p "Overwrite? (y/N): " -r REPLY@@ -341,78 +271,27 @@ DEEPGRAM_API_KEY=$DEEPGRAM_API_KEY# Path to Obsidian vault directoryVAULT_PATH=./vault-# JSON array of Telegram user IDs allowed to use the bot+# JSON array of Telegram user IDs allowed to use the bot.+# The FIRST id also receives health alerts / daily reports.ALLOWED_USER_IDS=[$TELEGRAM_USER_ID]++# Timezone for timers, reports and schedules+TZ=$USER_TZEOFchmod 600 "$ENV_FILE"success ".env file created (permissions: 600)"}-install_dependencies() {- step "Installing Python dependencies"-- cd "$PROJECT_DIR"-- info "Running uv sync..."- "$HOME/.local/bin/uv" sync-- success "Dependencies installed"-}--configure_systemd() {- step "Configuring systemd service"-- SERVICE_FILE="/etc/systemd/system/d-brain-bot.service"- SERVICE_NAME="d-brain-bot"-- # Generate service file content- SERVICE_CONTENT="[Unit]-Description=d-brain Telegram Bot-After=network.target--[Service]-Type=simple-User=$USER-WorkingDirectory=$PROJECT_DIR-ExecStart=$HOME/.local/bin/uv run python -m d_brain-Restart=always-RestartSec=10-Environment=PYTHONUNBUFFERED=1--[Install]-WantedBy=multi-user.target"-- info "Creating systemd service..."- echo "$SERVICE_CONTENT" | sudo tee "$SERVICE_FILE" > /dev/null-- info "Reloading systemd daemon..."- sudo systemctl daemon-reload-- info "Enabling service to start on boot..."- sudo systemctl enable "$SERVICE_NAME"-- info "Starting service..."- sudo systemctl start "$SERVICE_NAME"-- # Wait a moment for service to start- sleep 2-- success "Systemd service configured"-}-configure_git_remote() {step "Configuring Git for push access"cd "$PROJECT_DIR"-- # Set git configgit config user.name "Agent Second Brain Bot"git config user.email "bot@localhost"- ask "Do you want to configure GitHub push access? (for auto-sync)"+ ask "Do you want to configure GitHub push access? (for auto-sync of your vault)"read -p "(y/N): " -r REPLY-if [[ ! $REPLY =~ ^[Yy]$ ]]; thenwarn "Skipping GitHub push configuration"return@@ -428,146 +307,84 @@ configure_git_remote() {ask "Enter your GitHub Personal Access Token:"read -rs GITHUB_TOKENecho ""-if [ -z "$GITHUB_TOKEN" ]; thenwarn "No token provided, skipping"returnfiGITHUB_USER=$(cat .github_user 2>/dev/null || echo "")-if [ -z "$GITHUB_USER" ]; thenask "Enter your GitHub username:"read -r GITHUB_USERfigit remote set-url origin "https://[email protected]/$GITHUB_USER/agent-second-brain.git"-success "Git remote configured for push"}-# =============================================================================-# Status and verification-# =============================================================================--check_status() {- step "Final status check"-- ERRORS=()- WARNINGS=()-- echo ""-- # Check Python- if check_command python3.12; then- success "Python 3.12: $(python3.12 --version)"- else- ERRORS+=("Python 3.12 not found")- fi-- # Check uv- if check_command uv || [ -f "$HOME/.local/bin/uv" ]; then- success "uv: $($HOME/.local/bin/uv --version 2>/dev/null || uv --version)"- else- ERRORS+=("uv not found")- fi-- # Check Node.js- if check_command node; then- success "Node.js: $(node --version)"- else- ERRORS+=("Node.js not found")- fi-- # Check Claude CLI- if check_command claude; then- success "Claude CLI: installed"- else- WARNINGS+=("Claude CLI not found (needed for AI processing)")- fi-- # Check .env- if [ -f "$PROJECT_DIR/.env" ]; then- success ".env file: exists"- else- ERRORS+=(".env file not found")- fi+authorize_claude() {+ step "Claude Code authorization"- # Check systemd service- if systemctl is-active --quiet d-brain-bot; then- success "Bot service: running"- else- STATUS=$(systemctl is-active d-brain-bot 2>/dev/null || echo "unknown")- ERRORS+=("Bot service not running (status: $STATUS)")+ # The persistent brain session runs on your Claude subscription —+ # it cannot start without a logged-in Claude Code.+ if claude auth status --json 2>/dev/null | grep -q '"loggedIn": *true'; then+ success "Claude Code already authorized"+ returnfi+ warn "Claude Code is not logged in — the brain session needs it."echo ""-- # Summary- if [ ${#ERRORS[@]} -eq 0 ] && [ ${#WARNINGS[@]} -eq 0 ]; then- echo -e "${GREEN}${BOLD}"- echo " ╔═══════════════════════════════════════════════════════════╗"- echo " ║ ║"- echo " ║ SETUP COMPLETE! ║"- echo " ║ ║"- echo " ╚═══════════════════════════════════════════════════════════╝"- echo -e "${NC}"- echo ""- echo " Next steps:"- echo " 1. Open Telegram and find your bot"- echo " 2. Send /start to test"- echo " 3. Send a voice message!"- echo ""- echo " Useful commands:"- echo " - View logs: sudo journalctl -u d-brain-bot -f"- echo " - Restart bot: sudo systemctl restart d-brain-bot"- echo " - Stop bot: sudo systemctl stop d-brain-bot"- echo ""- else- if [ ${#ERRORS[@]} -gt 0 ]; then- echo -e "${RED}${BOLD}ERRORS:${NC}"- for err in "${ERRORS[@]}"; do- error "$err"- done- echo ""+ echo "Open a SECOND terminal on this server and run:"+ echo -e " ${CYAN}claude${NC}"+ echo "Complete the login it offers (subscription account), then exit claude."+ echo ""+ while true; do+ read -p "Press Enter when done (or type 'skip' to continue without login): " -r REPLY+ if [[ $REPLY == "skip" ]]; then+ warn "Continuing without login — the bot will alert until you log in."+ returnfi-- if [ ${#WARNINGS[@]} -gt 0 ]; then- echo -e "${YELLOW}${BOLD}WARNINGS:${NC}"- for wrn in "${WARNINGS[@]}"; do- warn "$wrn"- done- echo ""+ if claude auth status --json 2>/dev/null | grep -q '"loggedIn": *true'; then+ success "Claude Code authorized"+ returnfi-- echo "Troubleshooting:"- echo " - Check logs: sudo journalctl -u d-brain-bot -n 50"- echo " - Check .env: cat $PROJECT_DIR/.env"- echo " - Manual start: cd $PROJECT_DIR && uv run python -m d_brain"- echo ""- fi+ error "Still not logged in. Try again (or type 'skip')."+ done}-authorize_claude() {- step "Claude CLI Authorization"-- if claude auth status 2>/dev/null | grep -q "Logged in"; then- success "Claude CLI already authorized"- return- fi+run_upgrade() {+ step "Installing services and starting the agent (upgrade.sh)"+ # All the heavy lifting lives in upgrade.sh — the SAME script that+ # migrates older installs: uv sync, dbrain-* systemd --user units,+ # linger, dbrain CLI, claude-p guard, first health check.+ bash "$PROJECT_DIR/upgrade.sh"+}- warn "Claude CLI needs authorization"+print_outro() {+ echo ""+ echo -e "${GREEN}${BOLD}"+ echo " ╔═══════════════════════════════════════════════════════════╗"+ echo " ║ ║"+ echo " ║ SETUP COMPLETE! ║"+ echo " ║ ║"+ echo " ╚═══════════════════════════════════════════════════════════╝"+ echo -e "${NC}"echo ""- echo "Run this command manually:"- echo -e " ${CYAN}claude auth login${NC}"+ echo " Next steps:"+ echo " 1. Open Telegram and find your bot"+ echo " 2. Send /start to test"+ echo " 3. Send a voice message!"+ echo " 4. Try: \"remind me in 10 minutes to stretch\""echo ""- echo "This will open a browser for authentication."- echo "After authorizing, the bot will be able to use Claude for AI processing."+ echo " Useful commands:"+ echo " - Status: dbrain status"+ echo " - View logs: journalctl --user -u dbrain-bot -f"+ echo " - Restart bot: systemctl --user restart dbrain-bot"echo ""}# =============================================================================-# Main script+# Main# =============================================================================main() {@@ -577,11 +394,10 @@ main() {check_osecho "This script will:"- echo " 1. Install required software (Python, Node.js, uv, Claude CLI)"+ echo " 1. Install required software (uv, Node.js, tmux, Claude Code)"echo " 2. Clone your fork of the repository"echo " 3. Ask for your API tokens"- echo " 4. Create configuration files"- echo " 5. Set up auto-start service"+ echo " 4. Set up the always-on agent (systemd --user + tmux brain)"echo ""read -p "Ready to start? (Y/n): " -r REPLY@@ -590,27 +406,21 @@ main() {exit 0fi- # Installationinstall_system_deps- install_pythoninstall_uvinstall_nodejsinstall_claude_cli- # Configurationclone_repositorycollect_tokenscreate_env_file- install_dependencies- configure_systemdconfigure_git_remoteauthorize_claude- # Final check- check_status+ run_upgrade+ print_outro}-# Run main if script is executed (not sourced)if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; thenmain "$@"fidiff --git a/tests/test_setup_contract.py b/tests/test_setup_contract.pynew file mode 100644index 0000000..bc86c17--- /dev/null+++ b/tests/test_setup_contract.py@@ -0,0 +1,41 @@+"""Contract tests for the install/upgrade scripts.++setup.sh once generated the dead v2 layout (system-level d-brain-* units)+— a fresh install was broken. These pins keep the install path honest:+setup.sh = interactive questions only, upgrade.sh = the single source of+truth for services and health.+"""++from pathlib import Path++ROOT = Path(__file__).parent.parent+SETUP = (ROOT / "setup.sh").read_text()+UPGRADE = (ROOT / "upgrade.sh").read_text()+++def test_setup_delegates_services_to_upgrade():+ assert "upgrade.sh" in SETUP+++def test_setup_has_no_dead_v2_layout():+ assert "d-brain-" not in SETUP # legacy unit names+ assert "/etc/systemd/system" not in SETUP # v3 uses systemd --user+++def test_setup_login_check_uses_json_not_prose():+ # `claude auth status | grep "Logged in"` broke when the CLI changed+ # its prose; the JSON field is the stable contract.+ assert "loggedIn" in SETUP+++def test_setup_asks_timezone():+ assert "TZ=" in SETUP+++def test_upgrade_targets_v3():+ assert "v3.1" not in UPGRADE+ assert "dbrain-bot.service" in UPGRADE+++def test_legacy_mac_installer_is_gone():+ assert not (ROOT / "install.sh").exists()