#!/usr/bin/env bash # install.sh โ€” set up the agent-watcher MCP Watcher (Layer 2) on this host. # # Usage: # ./install.sh # install: npm ci, build, link binary, print mcp.json snippet # ./install.sh --no-mcp-json # everything but the mcp.json snippet (you handle registration) # # What it does: # 1. Verifies Node 18+ is available. # 2. Installs dependencies (npm ci) and builds (tsc). # 3. Symlinks dist/server.js to ~/.local/bin/agent-watcher-mcp (chmod +x). # 4. Adds .stignore patterns for the local-only watcher-active sentinel. # 5. Prints the mcp.json snippet for paste into Claude Code's config. # # Per CLAUDE.md rule #2, this is intended to be run by a human. The MCP # Watcher itself, like agent-ping, never invokes this script. # # Layer 1 (Collector) has its own install path. See the repo root install.sh. set -euo pipefail NO_MCP_JSON=0 for arg in "$@"; do case "$arg" in --no-mcp-json) NO_MCP_JSON=1 ;; *) echo "unknown arg: $arg" >&2; exit 2 ;; esac done REPO_DIR="$(cd "$(dirname "$0")" && pwd)" BIN_DIR="$HOME/.local/bin" WORKSPACE="$HOME/Nyx/workspace" STIGNORE="$WORKSPACE/.stignore" echo "agent-watcher-mcp install" echo "repo: $REPO_DIR" echo # 1. Node check echo "[1/5] checking Node" if ! command -v node >/dev/null 2>&1; then echo " ERROR: 'node' not found. Install Node 18+ first." >&2 exit 1 fi NODE_MAJOR=$(node --version | sed 's/^v//' | cut -d. -f1) if [ "$NODE_MAJOR" -lt 18 ]; then echo " ERROR: Node 18+ required; found $(node --version)." >&2 exit 1 fi echo " $(node --version)" # 2. Install deps + build echo "[2/5] npm ci + build" ( cd "$REPO_DIR" && npm ci --silent && npx tsc ) echo " built: $REPO_DIR/dist/server.js" # 3. Binary symlink echo "[3/5] linking binary" mkdir -p "$BIN_DIR" ln -sf "$REPO_DIR/dist/server.js" "$BIN_DIR/agent-watcher-mcp" chmod +x "$REPO_DIR/dist/server.js" echo " linked: $BIN_DIR/agent-watcher-mcp -> $REPO_DIR/dist/server.js" # 4. .stignore โ€” sentinel + hwm files are local-only echo "[4/5] .stignore (sentinel + hwm are local-only per spec ยง4.3)" if [ -d "$WORKSPACE" ]; then touch "$STIGNORE" for pattern in "pings/.*.watcher-active" "pings/.*.hwm"; do if ! grep -qxF "$pattern" "$STIGNORE"; then echo "$pattern" >> "$STIGNORE" echo " added: $pattern" fi done else echo " $WORKSPACE not present โ€” skipping (Syncthing not set up here)" fi # 5. mcp.json snippet echo "[5/5] mcp.json registration" if [ "$NO_MCP_JSON" -eq 0 ]; then cat <