testsAndMisc/linux_configuration/i3blocks/issue_dashboard.sh
Krzysztof kuhy Rudnicki 63465cffac
Some checks failed
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Python tests / test (push) Has been cancelled
i3blocks: issue_dashboard block
[issue_dashboard] shows what the local issue dashboard (~/src/issue-dashboard)
knows, from the status.json its server rewrites on every refresh:
"📋 <to do> · ⚙ <agents working> · ✓ <ready to merge>", green when something
is ready to merge, red with "· ✗ <n>" when an agent or a proof failed, grey
"📋 dashboard" when the file is missing or stale (server not running). Zero
forks on the hot path; a click opens issue-dashboard-desktop, which reuses or
starts the server and opens its window. Behaviour + fork-count test in
tests/test_i3blocks_issue_dashboard.sh. Prunes the oldest evidence artifact
to stay at the 60-file cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WXd5qap8DWqZCS9mjh3CzH
2026-10-02 17:03:47 +02:00

84 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# issue-dashboard status for i3blocks: issues to do, agents working, work
# ready to merge.
#
# Opened the same way as book_guard.sh: a click runs issue-dashboard-desktop,
# which reuses the dashboard server if it is answering (starting it detached
# if not) and opens an app window onto it.
#
# Reads the status.json the dashboard server rewrites on every refresh (every
# poll period, ~45 s, with or without a browser open) -- no network, no gh.
# Zero forks on the hot path: one builtin read, regex matches and a printf
# clock. Never blank: a missing or stale file means the server is not
# running, and is shown as a grey "dashboard" rather than old numbers.
# ============================================================================
set -euo pipefail
readonly STATUS="${ISSUE_DASHBOARD_STATUS:-$HOME/data/issue-dashboard/status.json}"
readonly LAUNCHER="${ISSUE_DASHBOARD_DESKTOP:-$HOME/.local/bin/issue-dashboard-desktop}"
# Four missed refreshes: past this the server is gone, not just slow.
readonly STALE_SECONDS=180
# Dracula-ish palette, matching the other blocks in this bar.
readonly RED='#FF5555'
readonly GREEN='#50FA7B'
readonly WHITE='#FFFFFF'
readonly GREY='#6272A4'
emit() {
# full_text, short_text, color — the three lines i3blocks reads.
printf '%s\n%s\n%s\n' "$1" "$2" "$3"
}
# The only fork, and only on a click: open (or reuse) the dashboard window.
if [[ ${BLOCK_BUTTON:-0} -ne 0 ]]; then
setsid -f "$LAUNCHER" >/dev/null 2>&1 || true
fi
# status.json is one line of flat JSON written atomically by the server.
line=''
if [[ -r $STATUS ]]; then
IFS= read -r line <"$STATUS" || true
fi
# field <name>: the integer value of a top-level key, or "" if absent.
field() {
if [[ $line =~ \"$1\":\ *([0-9]+) ]]; then
printf -v "$1" '%s' "${BASH_REMATCH[1]}"
else
printf -v "$1" '%s' ''
fi
}
field todo
field working
field ready
field failed
field updated_epoch
if [[ -z $todo || -z $working || -z $ready || -z $failed || -z $updated_epoch ]]; then
emit '📋 dashboard' '📋' "$GREY"
exit 0
fi
printf -v now '%(%s)T' -1
if ((now - updated_epoch > STALE_SECONDS)); then
emit '📋 dashboard' '📋' "$GREY"
exit 0
fi
text="📋 ${todo} · ⚙ ${working} · ✓ ${ready}"
short="📋 ${todo}"
color=$WHITE
if ((failed > 0)); then
text="$text · ✗ ${failed}"
color=$RED
elif ((ready > 0)); then
color=$GREEN
fi
emit "$text" "$short" "$color"