No error is a dead end: crash, click, and your agent is already looking

Claude-Session: https://claude.ai/code/session_01Ms2FbjQy31TVf3CEvQhGM8
This commit is contained in:
Gabriel Brown
2026-08-25 12:50:09 -04:00
parent ada0faf1d1
commit cc7d91d09c
43 changed files with 4648 additions and 327 deletions
+81
View File
@@ -9,6 +9,7 @@
# sync Review, commit & push local changes to this repo
# edit Open the Panama repo in Neovim
# doctor Report what is actually running on this machine
# diagnose Hand this machine's health and recent errors to your agent
# test Run every contract under tests/ (--safe skips the hijacking ones)
# contracts Name the contracts that mention a given file
# upgrade Re-run the installer from anywhere, interview included
@@ -81,6 +82,9 @@ ${BOLD}Commands:${RESET}
${GREEN}edit${RESET} Open the Panama repo in Neovim.
${GREEN}doctor${RESET} Report what is actually running on this machine, rather
than what was installed. Takes --summary for one line per check.
${GREEN}diagnose${RESET} Hand the health summary, the recent journal errors and
whatever you say is wrong to your coding agent, in a terminal.
Needs an agent chosen on Settings System Agents.
${GREEN}test${RESET} Run every contract under tests/. Give it a pattern to run
a subset: 'panama test dock' runs the ones matching 'dock'.
--safe skips the ones that take over the live desktop; what
@@ -111,6 +115,8 @@ ${BOLD}Examples:${RESET}
$PROGRAM sync
$PROGRAM edit
$PROGRAM doctor --summary
$PROGRAM diagnose
$PROGRAM diagnose the bar disappears after unplugging the monitor
$PROGRAM test dock
$PROGRAM test --safe
$PROGRAM contracts config/dot/quickshell/services/Displays.qml
@@ -348,6 +354,80 @@ cmd_doctor() {
exec "$doctor" "$@"
}
# ----------------------------------------------------------------------------
# Command: diagnose
# ----------------------------------------------------------------------------
#
# The by-hand rung of the escalation ladder. Every other rung starts from an
# event -- a crash, a failed reload, a red check -- and this one starts from a
# person who can tell that something is wrong but not what.
#
# It gathers the two things anybody would be asked for first anyway (what the
# health check says, what the journal has been complaining about) and whatever
# words follow the command, then hands the lot to the configured agent. The free
# text is the valuable part: "the bar disappears after unplugging the monitor"
# is a symptom no collector reports, and it is the difference between an agent
# reading a health summary and an agent looking for something.
cmd_diagnose() {
local launcher="$PANAMA_DIR/bin/panama-agent"
if [[ ! -x "$launcher" ]]; then
err "The agent launcher is missing from $launcher"
exit 1
fi
local complaint="$*"
local health="(the health check did not run)"
local doctor="$PANAMA_DIR/config/dot/quickshell/scripts/panama-doctor"
if [[ -x "$doctor" ]]; then
health="$("$doctor" --summary 2>&1)" || true
fi
# Bounded twice, and not out of tidiness. journalctl counts entries, not
# lines, and thirty entries on this machine came to 2,430 lines and a quarter
# of a megabyte -- one multi-line traceback each. The prompt leaves as a
# single argv element, which the kernel caps at 128KB, so an unbounded excerpt
# turns this command into "Argument list too long" rather than a diagnosis.
local errors="(nothing at error level in this boot's user journal)"
if command -v journalctl >/dev/null 2>&1; then
local recent
recent="$(journalctl --user -b -p err -n 30 --no-pager --output=short 2>/dev/null \
| cut -c 1-300 | tail -80)" || true
[[ -n "${recent// }" ]] && errors="$recent"
fi
local complaint_section="Nothing in particular was reported; this was run to look around."
[[ -n "${complaint// }" ]] && complaint_section="$complaint"
local prompt
prompt="$(cat <<PROMPT
Something is wrong with this Panama machine and I would like to know what.
What I noticed:
$complaint_section
What panama doctor --summary says:
$health
The last error-level lines in this boot's user journal:
$errors
Panama is checked out at $PANAMA_DIR and every dotfile in ~/.config is a symlink
into it, so anything you find is a tracked file here rather than a copy. Start
by reading: work out what is actually broken and say so before changing
anything. If a check is red, 'panama doctor' with no arguments has the long form
of it. Root work goes through panama-sudo, which shows me your reason.
PROMPT
)"
# exec: from here on the agent's terminal is the process, and this shell has
# nothing left to do that the agent is not doing better.
exec "$launcher" --prompt "$prompt"
}
# ----------------------------------------------------------------------------
# The desktop-hijacking ledger
# ----------------------------------------------------------------------------
@@ -805,6 +885,7 @@ main() {
sync) shift; cmd_sync "$@" ;;
edit) shift; cmd_edit "$@" ;;
doctor) shift; cmd_doctor "$@" ;;
diagnose) shift; cmd_diagnose "$@" ;;
test) shift; cmd_test "$@" ;;
contracts) shift; cmd_contracts "$@" ;;
upgrade) shift; cmd_upgrade "$@" ;;