#!/usr/bin/env bash # DHARMA network — start all 19 soul Engrams as background processes. # # Each soul gets: # - Their own Engram binary instance # - ENGRAM_DATA_DIR / ENGRAM_DB_PATH = forge/imprints// # - ENGRAM_BIND = 0.0.0.0: # - ENGRAM_API_KEY = ntn--2026 per soul (or $DHARMA_API_KEY override) # # PIDs are written to forge/imprints//engram.pid # Logs go to forge/log/dharma-.log # # Usage: # ./launch_dharma.sh start all soul Engrams # ./launch_dharma.sh start one soul by slug # # Neuron stays untouched at localhost:8742. set -euo pipefail FORGE=/Users/will/Development/neuron-technologies/forge ENGRAM=/Users/will/Development/neuron-technologies/foundation/engram/dist/engram REGISTRY="$FORGE/registry.json" if [ ! -x "$ENGRAM" ]; then echo "[dharma] ERROR: engram binary not found at $ENGRAM" exit 1 fi if [ ! -f "$REGISTRY" ]; then echo "[dharma] ERROR: registry.json not found at $REGISTRY" exit 1 fi mkdir -p "$FORGE/log" FILTER="${1:-}" started=0 skipped=0 missing=0 while IFS='|' read -r slug port subject db_path; do [ -z "$slug" ] && continue if [ -n "$FILTER" ] && [ "$slug" != "$FILTER" ]; then continue fi full_db_path="$FORGE/$db_path" if [ ! -d "$full_db_path" ] || [ -z "$(ls -A "$full_db_path" 2>/dev/null)" ]; then echo "[dharma] WARN: $slug — imprint directory missing or empty" echo "[dharma] Run: python3 scripts/install_all.py" missing=$((missing + 1)) continue fi # Skip if already running on that port if lsof -ti tcp:"$port" >/dev/null 2>&1; then echo "[dharma] $slug already running on port $port — skipping" skipped=$((skipped + 1)) continue fi log_file="$FORGE/log/dharma-${slug}.log" pid_file="$full_db_path/engram.pid" # Per-soul key unless overridden by DHARMA_API_KEY env var soul_key="${DHARMA_API_KEY:-ntn-${slug}-2026}" echo "[dharma] starting $slug on :$port" ENGRAM_DATA_DIR="$full_db_path" \ ENGRAM_DB_PATH="$full_db_path" \ ENGRAM_BIND="0.0.0.0:$port" \ ENGRAM_API_KEY="$soul_key" \ "$ENGRAM" >> "$log_file" 2>&1 & pid=$! echo "$pid" > "$pid_file" started=$((started + 1)) done < <(python3 - "$REGISTRY" <<'PYEOF' import json, sys reg = json.load(open(sys.argv[1])) for imp in reg["imprints"]: print(f"{imp['slug']}|{imp['engram_port']}|{imp['subject']}|{imp.get('engram_db_path', 'imprints/' + imp['slug'])}") PYEOF ) echo "" echo "[dharma] started=$started skipped=$skipped missing=$missing" if [ "$missing" -gt 0 ]; then echo "[dharma] Run 'python3 scripts/install_all.py' to install missing souls first." fi echo "[dharma] logs: $FORGE/log/dharma-.log" echo "" if [ "$started" -gt 0 ]; then echo "[dharma] Verify:" echo " curl -s http://localhost:8801/stats # bobby-anderson" echo " curl -s http://localhost:8819/stats # helen-keller" echo "" echo "[dharma] Then wire peers:" echo " python3 scripts/wire_peers.py" fi