mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:38:43 +01:00
* fix(hardcoded): give every duplicated constant one home A sweep of all 44 repos' default branches for literals that duplicate an existing source of truth. Loki's share, in four groups. WRONG, and live on the public footer. src/config/fleet-site-copy.ts still called the Zürich clinic "VitaReBa", a name retired on 2026-09-10 — its own title says "Vita · Metabolische Psychiatrie & Systemische Longevity". The generated fleet-sites.ts carried it onto loki.orangecat.ch, where it was serving until this commit. Fixed at the copy file, which is the one place that owns a site's own words, and the footer regenerated from it. WOULD HAVE WRITTEN STALE DATA. scripts/seed-fleet-site-urls.ts kept a hand-typed slug → URL map "read 2026-08-06". Two of its fifteen entries pointed at hosts retired since (aoz-wohnen.orangecat.ch, revampit.orangecat.ch), so running it would have filled empty live_url columns with addresses that only 308. It now derives the map from apps.conf — the same register the footer is generated from — which also fixes the six live sites the hand list never had. Verified: 19 sites, zero retired hosts. THE BOX ADDRESS, in seven places. scripts/hetzner/_box-env.sh has been the SSOT for it all along and sixteen scripts source it; four did not, and the shared deploy workflow — reused by ~20 repos — had the IP inline twice, so moving the box meant twenty edits. The workflow now reads the org-level Actions variable HETZNER_IP and fails loudly if it is unset, rather than ssh-ing to an empty string. loki's own deploy.yml had `vars.HETZNER_IP || '<literal>'`, a fallback that guaranteed the variable was never needed and so never noticed if wrong. ONE LAPTOP, baked into shipped code. site-cd-local.ts listed /home/g/.ssh and /home/ubuntu/.ssh as deploy-key candidates beside os.homedir() — which already IS those paths, since loki-app runs as `ubuntu` and a laptop runs as its owner; both spelled one homedir for one named person. install-push-deploy.sh wired hooks to /home/g/dev/loki, link-prod-runtime.ts to /home/g/dev/bitbaum, and scripts/fleet printed an install line only true on one machine: all now DEV_ROOT or the script's own resolved path. The two scripts in scripts/local are INSTALLED BY COPY into ~/.local/bin and run there by systemd timers, so they resolve _box-env.sh beside the real file first, then under DEV_ROOT, and exit loudly if neither exists — a security check that cannot find its target must not look like one that found nothing. Deliberately unchanged: the slug alias map (the mechanism that makes a rename safe), an executed migration's data row, the retired-handle detector's own handle list, and test fixtures reproducing past incidents. Verified: fleet-sites-derived in sync (14 sites), bash -n on every edited script, and the branch's only remaining literals are in scripts/test fixtures. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(push-deploy): the generated hook must not bake one laptop's path install-push-deploy.sh writes the hook body through an UNQUOTED heredoc, so $HERE expanded at generation time and the absolute path of one machine was committed into every repo's .husky/pre-push. kivvi and botsmann both carried it; anyone cloning those repos got a hook pointing into a stranger's home directory, and re-running the installer would have put it straight back after those repos were cleaned. The hook now resolves ${DEV_ROOT:-$HOME/dev}/loki/... at RUN time, so the generator stops re-introducing what the cleanup just removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
161 lines
5.3 KiB
Bash
Executable File
161 lines
5.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# fleet — Friendly local wrapper for Loki development and daily use.
|
|
# Valid both in a checkout's scripts/ directory and when extracted flat into
|
|
# ~/.local/share/loki/ by the hosted installer.
|
|
#
|
|
# Recommended: symlink as "fc" (or keep "cpit" during transition):
|
|
# ln -s /home/g/dev/loki/scripts/fleet ~/bin/fc
|
|
#
|
|
# Examples:
|
|
# fc daemon start
|
|
# fc install-agent grok
|
|
# fc status
|
|
# fc pause
|
|
# fc resume
|
|
|
|
set -euo pipefail
|
|
|
|
RUNTIME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
if [ ! -x "$RUNTIME_DIR/loki-daemon.sh" ]; then
|
|
echo "Loki helper is incomplete at $RUNTIME_DIR. Re-run the installer from Settings." >&2
|
|
exit 1
|
|
fi
|
|
DAEMON_SCRIPT="$RUNTIME_DIR/loki-daemon.sh"
|
|
INSTALL_SCRIPT="$RUNTIME_DIR/install-loki-daemon.sh"
|
|
|
|
# Load env if present (the one from the installer). Support both the new
|
|
# LOKI_ layout and legacy COCKPIT_ location during transition.
|
|
if [ -f "$HOME/.config/loki/daemon.env" ]; then
|
|
set -a
|
|
source "$HOME/.config/loki/daemon.env"
|
|
set +a
|
|
elif [ -f "$HOME/.config/loki/daemon.env" ]; then
|
|
set -a
|
|
source "$HOME/.config/loki/daemon.env"
|
|
set +a
|
|
fi
|
|
|
|
# Force remote for production Control when you also run a local dev server
|
|
export APP_DAEMON_FORCE_REMOTE=1
|
|
export LOKI_DAEMON_FORCE_REMOTE=1
|
|
export COCKPIT_DAEMON_FORCE_REMOTE=1
|
|
|
|
case "${1:-help}" in
|
|
daemon|d)
|
|
shift
|
|
case "${1:-start}" in
|
|
start)
|
|
if systemctl --user is-enabled loki-daemon >/dev/null 2>&1; then
|
|
echo "Starting via systemd (recommended)…"
|
|
bash "$INSTALL_SCRIPT" --restart 2>/dev/null || systemctl --user restart loki-daemon
|
|
else
|
|
echo "Starting daemon (no systemd service — run: fleet service enable)…"
|
|
pkill -f 'loki-daemon.sh' 2>/dev/null || true
|
|
sleep 0.5
|
|
nohup bash "$DAEMON_SCRIPT" >> "${HOME}/.local/state/loki/daemon.log" 2>&1 &
|
|
sleep 1
|
|
pgrep -f 'loki-daemon.sh' >/dev/null && echo "Daemon started." || echo "Daemon failed to start — check log."
|
|
fi
|
|
;;
|
|
stop)
|
|
if systemctl --user is-enabled loki-daemon >/dev/null 2>&1; then
|
|
systemctl --user stop loki-daemon
|
|
fi
|
|
pkill -f 'loki-daemon.sh' 2>/dev/null || true
|
|
echo "Daemon stopped."
|
|
;;
|
|
restart)
|
|
if systemctl --user is-enabled loki-daemon >/dev/null 2>&1; then
|
|
bash "$INSTALL_SCRIPT" --restart
|
|
else
|
|
$0 daemon stop
|
|
sleep 1
|
|
$0 daemon start
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Usage: fleet daemon {start|stop|restart}"
|
|
;;
|
|
esac
|
|
;;
|
|
install-agent|ia)
|
|
agent="${2:-}"
|
|
if [ -z "$agent" ]; then
|
|
echo "Usage: fleet install-agent <grok|claude|cursor|gemini>"
|
|
exit 1
|
|
fi
|
|
echo "Triggering one-click install for $agent (will open a tab if daemon running)..."
|
|
# This calls the production API — requires the daemon token (prefer new LOKI_, fall back)
|
|
TOKEN="${LOKI_DAEMON_TOKEN:-${COCKPIT_DAEMON_TOKEN:-}}"
|
|
if [ -z "$TOKEN" ]; then
|
|
echo "No LOKI_DAEMON_TOKEN (or legacy COCKPIT_DAEMON_TOKEN) found. Source your daemon.env first."
|
|
exit 1
|
|
fi
|
|
auth_header="$(mktemp)"
|
|
chmod 600 "$auth_header"
|
|
printf 'Authorization: Bearer %s\n' "$TOKEN" > "$auth_header"
|
|
trap 'rm -f "$auth_header"' EXIT
|
|
curl -s -X POST "https://loki.orangecat.ch/api/agent/install-cli" \
|
|
-H "@$auth_header" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"agent\":\"$agent\"}" | jq .
|
|
echo "The installer runs in a terminal Fleet Runner owns — watch it on Control → This computer."
|
|
;;
|
|
status|s)
|
|
echo "=== Running daemons ==="
|
|
pgrep -f 'loki-daemon.sh' -a || echo "None"
|
|
echo ""
|
|
echo "=== Systemd user service ==="
|
|
systemctl --user status loki-daemon 2>/dev/null || echo "Service not installed (run: ./scripts/install-loki-daemon.sh)"
|
|
echo ""
|
|
echo "=== Recent runtime state (if any) ==="
|
|
ls -lt /tmp/agent-current-prompt-* /tmp/agent-ready-* 2>/dev/null | head -5 || echo "No recent sentinels"
|
|
echo "=== Your projects ==="
|
|
grep -E '^(Loki|revamp|OrangeCat)' "$HOME/.config/agent-projects.conf" 2>/dev/null || echo "No conf"
|
|
;;
|
|
service)
|
|
shift
|
|
case "${1:-status}" in
|
|
enable|install)
|
|
echo "Installing/enabling background service..."
|
|
bash "$INSTALL_SCRIPT"
|
|
;;
|
|
disable)
|
|
echo "Disabling service..."
|
|
systemctl --user disable --now loki-daemon 2>/dev/null || true
|
|
;;
|
|
status)
|
|
systemctl --user status loki-daemon 2>/dev/null || echo "Not installed"
|
|
;;
|
|
*)
|
|
echo "Usage: fleet service {enable|disable|status}"
|
|
;;
|
|
esac
|
|
;;
|
|
pause)
|
|
touch "/tmp/loki-pause"
|
|
echo "Fleet paused (daemon will respect this on next cycle)."
|
|
;;
|
|
resume)
|
|
rm -f "/tmp/loki-pause"
|
|
echo "Fleet resumed."
|
|
;;
|
|
help|*)
|
|
echo "fleet — your friendly local Loki helper"
|
|
echo ""
|
|
echo "Recommended name: fc (or cpit during transition to avoid conflicts)"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " fc daemon start # Clean start against production"
|
|
echo " fc daemon stop"
|
|
echo " fc install-agent grok # Opens a tab and injects the installer"
|
|
echo " fc status"
|
|
echo " fc pause / resume # Low-power mode"
|
|
echo ""
|
|
echo "Setup (recommended):"
|
|
echo " ln -s $(readlink -f "$0") ~/bin/fc"
|
|
echo ""
|
|
echo "Then just use: fc daemon start"
|
|
;;
|
|
esac
|