Files
Panama/bin/panama-agent-reload

68 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# "The shell would not reload" -> an agent already holding the error.
#
# Quickshell keeps the old shell running when a reload fails, which is what
# makes this rung possible at all: the desktop that just refused the new code is
# still there to notify you about it, and still there to click. shell.qml's
# onReloadFailed sends that notification; this builds the prompt behind it.
#
# panama-agent-reload "<what Quickshell said>"
#
# The failure string on its own is usually one line naming one file. The journal
# around it is where the rest is -- the QML warnings that preceded the fatal
# one, the property that was already undefined two saves ago -- so both go in.
#
# Environment seams, for the contract:
#
# PANAMA_PATH the repository
# PANAMA_RELOAD_UNIT the unit to read (default panama-quickshell.service)
set -euo pipefail
PANAMA_PATH="${PANAMA_PATH:-$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)}"
UNIT="${PANAMA_RELOAD_UNIT:-panama-quickshell.service}"
summary="${1:-}"
if [[ -z "${summary// }" ]]; then
printf 'Usage: panama-agent-reload "<the reload failure>"\n' >&2
exit 1
fi
# Read a generous window and filter it down, rather than asking journalctl for
# forty lines and hoping they were the relevant ones. A failed reload usually
# arrives after a burst of unrelated shell chatter.
#
# Each line is truncated because the prompt leaves as one argv element and the
# kernel caps that at 128KB; a single Quickshell backtrace can be most of it.
context=""
if command -v journalctl >/dev/null 2>&1; then
context="$(journalctl --user -u "$UNIT" -n 400 --no-pager --output=cat 2>/dev/null \
| grep -iE 'quickshell|\.qml|qml:|panama' \
| tail -40 \
| cut -c 1-300)" || true
fi
[[ -n "${context// }" ]] || context="(nothing in the journal for $UNIT)"
prompt="$(
cat <<PROMPT
The Panama shell refused to reload on this machine. The old shell is still
running, so the desktop is up, but the change that was just saved is not live.
What Quickshell reported:
$summary
The last relevant lines from $UNIT:
$context
The shell lives in config/dot/quickshell in this repository, symlinked into
~/.config/quickshell -- so the file that failed to parse is a tracked file here,
not a copy. Find what broke the reload and say what it is. Read before you
write: a bad guess saved into this tree is live in the desktop immediately.
PROMPT
)"
exec "$PANAMA_PATH/bin/panama-agent" --prompt "$prompt"