agent tracker updates

This commit is contained in:
David Chen 2026-01-17 14:01:39 -08:00
parent 689cc061cd
commit bb2a53206b
13 changed files with 375 additions and 106 deletions

View file

@ -57,6 +57,32 @@ if [[ -z "$sessions" ]]; then
exit 0
fi
# Refresh tracker cache (fast - skips if recent)
"$HOME/.config/tmux/tmux-status/tracker_cache.sh" 2>/dev/null || true
# Read from cache
CACHE_FILE="/tmp/tmux-tracker-cache.json"
tracker_state=""
if [[ -f "$CACHE_FILE" ]]; then
tracker_state=$(cat "$CACHE_FILE" 2>/dev/null || true)
fi
get_session_icon() {
local sid="$1"
[[ -z "$tracker_state" ]] && return
local result
result=$(echo "$tracker_state" | jq -r --arg sid "$sid" '
.tasks // [] | .[] | select(.session_id == $sid) |
if .status == "in_progress" then "in_progress"
elif .status == "completed" and .acknowledged != true then "waiting"
else empty end
' 2>/dev/null | head -1 || true)
case "$result" in
in_progress) printf '⏳' ;;
waiting) printf '🔔' ;;
esac
}
rendered=""
prev_bg=""
current_session_id_norm=$(normalize_session_id "$current_session_id")
@ -96,12 +122,14 @@ while IFS= read -r entry; do
label="${label:0:max_width-1}"
fi
task_icon=$(get_session_icon "$session_id")
if [[ -z "$prev_bg" ]]; then
rendered+="#[fg=${segment_bg},bg=${status_bg}]${left_cap}"
else
rendered+="#[fg=${prev_bg},bg=${segment_bg}]${separator}"
fi
rendered+="#[fg=${segment_fg},bg=${segment_bg}] ${label} "
rendered+="#[fg=${segment_fg},bg=${segment_bg}] ${label}${task_icon} "
prev_bg="$segment_bg"
done <<< "$sessions"

24
tmux/tmux-status/notes_count.sh Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
window_id=$(tmux display-message -p '#{window_id}' 2>/dev/null || true)
[[ -z "$window_id" ]] && exit 0
CACHE_FILE="/tmp/tmux-tracker-cache.json"
[[ ! -f "$CACHE_FILE" ]] && exit 0
state=$(cat "$CACHE_FILE" 2>/dev/null || true)
[[ -z "$state" ]] && exit 0
count=$(echo "$state" | jq -r --arg wid "$window_id" '
[.notes // [] | .[] | select(
.archived != true and
.completed != true and
.scope == "window" and
.window_id == $wid
)] | length
' 2>/dev/null || echo "0")
if [[ "$count" =~ ^[0-9]+$ ]] && (( count > 0 )); then
printf ' %s ' "$count"
fi

View file

@ -52,17 +52,38 @@ if [[ "$rainbarf_toggle" == "1" ]] && command -v rainbarf >/dev/null 2>&1; then
fi
fi
# Notes count for current window (red if > 0, hidden otherwise)
notes_segment=""
notes_count_script="$HOME/.config/tmux/tmux-status/notes_count.sh"
if [[ -x "$notes_count_script" ]]; then
notes_output=$("$notes_count_script" 2>/dev/null || true)
if [[ -n "$notes_output" ]]; then
notes_connector_bg="$status_bg"
if [[ -n "$rainbarf_segment" ]]; then
notes_connector_bg="$rainbarf_bg"
fi
notes_bg="#cc6666"
notes_fg="#1d1f21"
notes_segment=$(printf '#[fg=%s,bg=%s]%s#[fg=%s,bg=%s,bold]%s#[default]' \
"$notes_bg" "$notes_connector_bg" "$separator" \
"$notes_fg" "$notes_bg" "$notes_output")
fi
fi
# Build a connector into the hostname segment using host colors
host_connector_bg="$status_bg"
if [[ -n "$rainbarf_segment" ]]; then
if [[ -n "$notes_segment" ]]; then
host_connector_bg="#cc6666"
elif [[ -n "$rainbarf_segment" ]]; then
host_connector_bg="$rainbarf_bg"
fi
host_prefix=$(printf '#[fg=%s,bg=%s]%s#[fg=%s,bg=%s] ' \
"$host_bg" "$host_connector_bg" "$separator" \
"$host_fg" "$host_bg")
printf '%s%s%s #[fg=%s,bg=%s]%s' \
printf '%s%s%s%s #[fg=%s,bg=%s]%s' \
"$rainbarf_segment" \
"$notes_segment" \
"$host_prefix" \
"$hostname" \
"$host_bg" "$status_bg" "$right_cap"

View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
session_id="$1"
[[ -z "$session_id" ]] && exit 0
tracker_client="$HOME/.config/agent-tracker/bin/tracker-client"
[[ ! -x "$tracker_client" ]] && exit 0
state=$("$tracker_client" state 2>/dev/null || true)
[[ -z "$state" ]] && exit 0
# Check for in_progress or unacknowledged completed tasks in this session
result=$(echo "$state" | jq -r --arg sid "$session_id" '
.tasks // [] | .[] | select(.session_id == $sid) |
if .status == "in_progress" then "in_progress"
elif .status == "completed" and .acknowledged != true then "waiting"
else empty end
' 2>/dev/null | head -1 || true)
case "$result" in
in_progress) printf '⏳' ;;
waiting) printf '🔔' ;;
esac

View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
CACHE_FILE="/tmp/tmux-tracker-cache.json"
CACHE_MAX_AGE=1
tracker_client="$HOME/.config/agent-tracker/bin/tracker-client"
# Check if cache is fresh enough
if [[ -f "$CACHE_FILE" ]]; then
if [[ "$OSTYPE" == darwin* ]]; then
file_age=$(( $(date +%s) - $(stat -f %m "$CACHE_FILE") ))
else
file_age=$(( $(date +%s) - $(stat -c %Y "$CACHE_FILE") ))
fi
if (( file_age < CACHE_MAX_AGE )); then
exit 0
fi
fi
# Simple lock using mkdir (atomic on all systems)
LOCK_DIR="/tmp/tmux-tracker-cache.lock"
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
exit 0
fi
trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
if [[ -x "$tracker_client" ]]; then
"$tracker_client" state 2>/dev/null > "$CACHE_FILE.tmp" && mv "$CACHE_FILE.tmp" "$CACHE_FILE"
else
echo '{}' > "$CACHE_FILE"
fi

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
window_id="$1"
[[ -z "$window_id" ]] && exit 0
CACHE_FILE="/tmp/tmux-tracker-cache.json"
[[ ! -f "$CACHE_FILE" ]] && exit 0
state=$(cat "$CACHE_FILE" 2>/dev/null || true)
[[ -z "$state" ]] && exit 0
result=$(echo "$state" | jq -r --arg wid "$window_id" '
.tasks // [] | .[] | select(.window_id == $wid) |
if .status == "in_progress" then "in_progress"
elif .status == "completed" and .acknowledged != true then "waiting"
else empty end
' 2>/dev/null | head -1 || true)
case "$result" in
in_progress) printf '⏳' ;;
waiting) printf '🔔' ;;
esac