Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
#!/usr/bin/env bash
#
# PortOS agent guard — pm2 shim
# ------------------------------
# Spawned AI agents (CoS "Fix with AI" tasks, the autofixer app, etc.) run their
# CLI with `--dangerously-skip-permissions`, i.e. fully unrestricted Bash. PortOS
# prepends THIS directory to those agents' PATH (see server/lib/agentGuard), so a
# bare `pm2 ...` resolves here first. We block the handful of subcommands that
# would take down the SHARED PM2 daemon — and therefore every other app on the
# machine, including PortOS itself — then exec the real pm2 for everything else.
#
# This is a confused-agent guard, not a sandbox: absolute binary paths bypass it.
# Share the option-aware policy with PortOS's command runner.
self_dir="$(cd "$(dirname "$0")" && pwd)"
node "$self_dir/../validatePm2.js" "$@" || exit $?
# Resolve the real pm2. PortOS sets PORTOS_REAL_PM2 to the Node-resolved binary;
# fall back to the first pm2 on PATH that is NOT this shim's own directory.
real="$PORTOS_REAL_PM2"
if [ -z "$real" ] || [ ! -x "$real" ]; then
real=""
OLD_IFS="$IFS"; IFS=':'
for d in $PATH; do
[ -z "$d" ] && continue
resolved="$(cd "$d" 2>/dev/null && pwd)" || continue
[ "$resolved" = "$self_dir" ] && continue
if [ -x "$d/pm2" ]; then real="$d/pm2"; break; fi
done
IFS="$OLD_IFS"
fi
if [ -z "$real" ]; then
printf '🛑 PortOS agent guard: real pm2 binary not found on PATH.\n' >&2
exit 127
fi
exec "$real" "$@"