#!/usr/bin/env bash # Rebuild and run the personal data server in the foreground. # # One of a pair: this terminal shows registrations and lifecycle events, # `dev-mcp.sh` in another shows the scrobble feed. They are separate scripts # because they are separate things to watch, and because the two go stale for # different reasons — a lexicon change matters here, a tool schema change # matters there. # # Foreground on purpose. The log is the point, and a backgrounded process # writing to a file is a log nobody is looking at. set -euo pipefail cd "$(dirname "$0")/.." # This directory's profile, if it has one. See dev-profile.sh. . "$(dirname "$0")/dev-profile.sh" . "$(dirname "$0")/dev-watch.sh" . "$(dirname "$0")/dev-pidfile.sh" PORT="${DIDBOT_PDS_PORT:-3000}" ZONE="${DIDBOT_ZONE:-agents.localhost}" # Agents get names here, because the dev stack is where anyone finds out what # the feature does. `NAMES=hostname ./scripts/dev-pds.sh` turns it off; any # spec works, so `NAMES=cybernetic+chaos` changes what the swarm sounds like. NAMES="${NAMES:-mineral+creature}" # Empty by default: the stack is normally restarted many times a day and a # clean slate each time is what makes a run reproducible. Point it somewhere # to keep accounts, records and name holds across restarts. DATA="${DIDBOT_PDS_DATA:-}" say() { printf '\033[1m%s\033[0m\n' "$*"; } # Watching this one is not like watching the others. # # The index, the query service and the scrobble host hold nothing: restarting # them costs the build and nothing else. This holds every agent account, every # record and every name hold, and without `--data` all of it is in memory — so # a watch would factory-reset the deployment on every save, and the first # symptom would be sessions whose accounts have silently stopped existing. # # So it refuses, rather than being the same flag spelled the same way. Point # `--data` somewhere and the restart keeps everything; or say plainly that a # clean slate is what you wanted. if [ -z "$DATA" ] && [ "${DIDBOT_WATCH_EPHEMERAL:-0}" != "1" ]; then for arg in "$@"; do [ "$arg" = "--watch" ] || continue say "refusing to watch a server with nothing to keep" echo " Without --data this server is in memory, so every restart is a factory" echo " reset: every account, record and name hold goes, and live sessions find" echo " their accounts gone." echo echo " DIDBOT_PDS_DATA=./pds-data ./scripts/dev-pds.sh --watch" echo " DIDBOT_WATCH_EPHEMERAL=1 ./scripts/dev-pds.sh --watch # if a" echo " # clean slate each time is the point" exit 1 done fi # `--watch` reruns this script whenever the source moves. It never returns. watch_or_continue "$@" # A previous run holding the port makes the new one fail with "address already # in use", which reads as a port conflict with something else entirely. By # pidfile rather than by pattern: see dev-pidfile.sh for what a pattern matches # that it should not. claim_port pds "${PORT}" didbot-dev # The hook binary is built here rather than alongside the MCP host: it talks to # this server's provisioning API, so it goes stale when this side changes. say "building" cargo test --quiet -p didbot-pds -p didbot-serve -p didbot-hookd # The hook is the one binary that has to be on PATH, because the harness # invokes it by name from settings.json. It is installed in debug so it reuses # what the tests just built; a release build here would compile the workspace a # second time for no benefit in a development loop. say "installing the hook binary" cargo install --quiet --force --debug --path crates/didbot-hookd # The server itself is run straight out of the target directory. Nothing # invokes it by name, so installing it would only add a second full build and a # second copy to go stale. say "personal data server on port ${PORT}, zone ${ZONE}, names ${NAMES}" echo " stats curl -s http://localhost:${PORT}/xrpc/bot.did.stats" echo " events curl -N http://localhost:${PORT}/events" echo DATA_ARGS=() if [[ -n "$DATA" ]]; then DATA_ARGS=(--data "$DATA") echo " data ${DATA} (accounts and records survive a restart)" fi exec cargo run --quiet -p didbot-serve --bin didbot-dev -- \ --port "$PORT" --zone "$ZONE" --names "$NAMES" "${DATA_ARGS[@]}" "$@"