-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwavemill-status.sh
More file actions
executable file
Β·1251 lines (1095 loc) Β· 42 KB
/
wavemill-status.sh
File metadata and controls
executable file
Β·1251 lines (1095 loc) Β· 42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/opt/homebrew/bin/bash
# Wavemill Status Dashboard - Real-time task status for tmux control panel
#
# Usage: wavemill-status.sh [--pane=jobs|--pane=queued-pending] <session> <worktree_root> [state_file]
#
# Displays a compact per-task summary refreshing every 2 seconds by default
# (override with WAVEMILL_DASHBOARD_REFRESH_SECONDS=1..10):
# ISSUE TASK TIME PHASE AGENT PR
# WAV-42 hero-cta 12m π planning β running β
# WAV-55 nav-a11y 8m π¨ executing β running #147 β
set -euo pipefail
if ! declare -f wavemill_pick_usage_tip >/dev/null 2>&1; then
_wss_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null)" || true
if [[ -f "${_wss_dir}/wavemill-common.sh" ]]; then
# shellcheck source=wavemill-common.sh
source "${_wss_dir}/wavemill-common.sh"
fi
unset _wss_dir
fi
PANE_MODE=""
if [[ "${1:-}" == --pane=* ]]; then
PANE_MODE="${1#--pane=}"
shift
fi
if [[ "$#" -lt 2 ]]; then
echo "Usage: wavemill-status.sh [--pane=jobs|--pane=queued-pending] <session> <worktree_root> [state_file]" >&2
exit 1
fi
SESSION="$1"
WORKTREE_ROOT="$2"
STATE_FILE="${3:-}"
if [[ -n "$PANE_MODE" ]]; then
case "$PANE_MODE" in
jobs|queued-pending) ;;
*)
echo "wavemill-status.sh: unsupported pane mode '$PANE_MODE'" >&2
exit 1
;;
esac
fi
# Signal-driven refresh uses USR1 for fast updates and polling as fallback.
WAVEMILL_REDRAW=0
trap 'WAVEMILL_REDRAW=1' USR1
DEFAULT_REFRESH=2
MAX_REFRESH=10
DEFAULT_TIP_REFRESH=60
MAX_TIP_REFRESH=3600
PR_CACHE="/tmp/${SESSION}-pr-cache.json"
PR_TTL=15
WAVEMILL_STATUS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WAVEMILL_REPO_DIR="$(cd "$WAVEMILL_STATUS_DIR/../.." && pwd)"
declare -Ag WAVEMILL_ROUTING_DISPLAY_CACHE=()
# Colors
G='\033[32m'; Y='\033[33m'; R='\033[31m'; D='\033[90m'; B='\033[1m'; N='\033[0m'
# Erase from cursor to end-of-line after each rendered row so shorter redraws
# cannot leave stale terminal cells behind.
EL='\033[K'
resolve_dashboard_refresh_seconds() {
local raw_refresh="${WAVEMILL_DASHBOARD_REFRESH_SECONDS:-$DEFAULT_REFRESH}"
if [[ "$raw_refresh" =~ ^[0-9]+$ ]] && (( raw_refresh >= 1 && raw_refresh <= MAX_REFRESH )); then
printf '%s\n' "$raw_refresh"
return 0
fi
if [[ "${WAVEMILL_DASHBOARD_REFRESH_WARNED:-0}" -eq 0 ]]; then
printf 'wavemill: invalid WAVEMILL_DASHBOARD_REFRESH_SECONDS=%s, using default %s\n' \
"$raw_refresh" "$DEFAULT_REFRESH" >&2
WAVEMILL_DASHBOARD_REFRESH_WARNED=1
fi
printf '%s\n' "$DEFAULT_REFRESH"
}
resolve_tip_refresh_seconds() {
local raw="${WAVEMILL_TIP_REFRESH_SECONDS:-$DEFAULT_TIP_REFRESH}"
if [[ "$raw" =~ ^[0-9]+$ ]] && (( raw >= 1 && raw <= MAX_TIP_REFRESH )); then
printf '%s\n' "$raw"
return 0
fi
if [[ "${WAVEMILL_TIP_REFRESH_WARNED:-0}" -eq 0 ]]; then
printf 'wavemill: invalid WAVEMILL_TIP_REFRESH_SECONDS=%s, using default %s\n' \
"$raw" "$DEFAULT_TIP_REFRESH" >&2
WAVEMILL_TIP_REFRESH_WARNED=1
fi
printf '%s\n' "$DEFAULT_TIP_REFRESH"
}
REFRESH="$(resolve_dashboard_refresh_seconds)"
TIP_REFRESH="$(resolve_tip_refresh_seconds)"
_CURRENT_TIP=""
_LAST_TIP_REFRESH_AT=0
# Hide cursor during rendering
tput civis 2>/dev/null || true
trap 'tput cnorm 2>/dev/null || true' EXIT
# ββ PR cache (refreshed every PR_TTL seconds) ββββββββββββββββββββββββββββ
refresh_pr_cache() {
local now
now=$(date +%s)
local mtime=0
[[ -f "$PR_CACHE" ]] && mtime=$(stat -f %m "$PR_CACHE" 2>/dev/null || echo 0)
if (( now - mtime >= PR_TTL )); then
local tmp_file
# Per-writer tmp file so this dashboard refresh does not race the monitor's
# wavemill_pr_cache_refresh on a shared "${PR_CACHE}.tmp" path.
tmp_file=$(mktemp "${PR_CACHE}.tmp.XXXXXX" 2>/dev/null) || return 0
if gh pr list --json number,headRefName,state,statusCheckRollup --limit 50 \
< /dev/null 2>/dev/null > "$tmp_file"; then
if [[ -s "$tmp_file" ]]; then
mv "$tmp_file" "$PR_CACHE" 2>/dev/null || rm -f "$tmp_file"
else
rm -f "$tmp_file"
fi
else
rm -f "$tmp_file"
fi
fi
}
pr_for_branch() {
local branch="$1"
[[ -f "$PR_CACHE" ]] || return 0
jq -r --arg b "$branch" \
'.[] | select(.headRefName == $b) | "\(.number)|\(.state)"' \
"$PR_CACHE" 2>/dev/null | head -1
}
pr_checks() {
local branch="$1"
[[ -f "$PR_CACHE" ]] || return 0
# Rollup entries are either CheckRun (uses .conclusion) or StatusContext
# (uses .state, e.g. Vercel/Netlify). Coalesce so both are treated uniformly.
jq -r --arg b "$branch" '
def outcome: .conclusion // .state;
.[] | select(.headRefName == $b) |
.statusCheckRollup // [] |
if length == 0 then "none"
elif all(.[]; outcome == "SUCCESS" or outcome == "NEUTRAL" or outcome == "SKIPPED") then "pass"
elif any(.[]; outcome == "FAILURE" or outcome == "ERROR" or outcome == "TIMED_OUT" or outcome == "CANCELLED") then "fail"
else "pending" end
' "$PR_CACHE" 2>/dev/null | head -1
}
# ββ Agent-reported status (from status file) ββββββββββββββββββββββββββββββ
agent_reported_status() {
local issue="$1"
local status_file="/tmp/${SESSION}-${issue}-status.txt"
if [[ -f "$status_file" ]]; then
local raw_status
raw_status=$(head -1 "$status_file" 2>/dev/null | tr -d '\r' | cut -c1-40)
case "$raw_status" in
working|waiting|done)
echo "$raw_status"
;;
*)
echo "$raw_status"
;;
esac
fi
}
# Read detail field from hook JSON (e.g., tool name, error message).
# Only returns detail if hook file is fresh (300s TTL).
agent_hook_detail() {
local issue="$1"
local hook_file="/tmp/wavemill-${SESSION}-${issue}.hook"
[[ -f "$hook_file" ]] || return 0
local ts now staleness
ts=$(jq -r '.timestamp // 0' "$hook_file" 2>/dev/null || echo 0)
now=$(date +%s)
staleness=$(( now - ts ))
(( staleness < 300 )) || return 0
jq -r '.detail // empty' "$hook_file" 2>/dev/null || true
}
# Read the planning stage display status from stage result files.
# Returns: awaiting_approval, approved, running, rejected, aborted, or empty string.
get_planning_display_status() {
local worktree="$1" slug="$2"
local feature_dir="$worktree/features/$slug"
local result_file="$feature_dir/.planning-result.json"
if [[ -f "$result_file" ]]; then
local status
status=$(jq -r '.status // empty' "$result_file" 2>/dev/null)
case "$status" in
awaiting_user) echo "awaiting_approval" ;;
completed) echo "approved" ;;
running) echo "running" ;;
failed) echo "rejected" ;;
aborted) echo "aborted" ;;
*) echo "" ;;
esac
return
fi
}
get_ready_display_status() {
local worktree="$1" slug="$2"
local feature_dir="$worktree/features/$slug"
local result_file="$feature_dir/.ready-result.json"
[[ -f "$result_file" ]] || return 0
jq -r '.status // empty' "$result_file" 2>/dev/null || true
}
get_ready_queue_state() {
local worktree="$1" slug="$2"
local feature_dir="$worktree/features/$slug"
local result_file="$feature_dir/.ready-result.json"
local status verdict queue_state
[[ -f "$result_file" ]] || return 0
queue_state=$(jq -r '.artifacts.queueState // empty' "$result_file" 2>/dev/null || true)
if [[ -n "$queue_state" ]]; then
printf '%s\n' "$queue_state"
return 0
fi
status=$(jq -r '.status // empty' "$result_file" 2>/dev/null || true)
verdict=$(jq -r '.artifacts.verdict // empty' "$result_file" 2>/dev/null || true)
if [[ "$status" == "completed" && ( "$verdict" == "pass" || "$verdict" == "warn" ) ]]; then
printf 'ready\n'
fi
}
is_ready_conflicted() {
local worktree="$1" slug="$2"
local feature_dir=""
local dir
for dir in features bugs; do
if [[ -d "$worktree/$dir/$slug" ]]; then
feature_dir="$worktree/$dir/$slug"
[[ -f "$feature_dir/.conflict-detected" ]] && return 0
return 1
fi
done
[[ -f "$worktree/features/$slug/.conflict-detected" ]]
}
ready_attention_detail() {
local worktree="$1" slug="$2"
local feature_dir="$worktree/features/$slug"
local attention_file="$feature_dir/.needs-attention"
[[ -f "$attention_file" ]] || return 0
head -1 "$attention_file" 2>/dev/null | tr -d '\r'
}
truncate_blocked_completion_summary() {
local summary="${1:-}"
local max_len=80
if (( ${#summary} > max_len )); then
printf '%s...\n' "${summary:0:77}"
else
printf '%s\n' "$summary"
fi
}
coding_blocked_completion_detail() {
local worktree="$1" slug="$2" issue="$3"
local feature_dir="$worktree/features/$slug"
local artifact_record summary reason artifact_mtime
local auto_detail
auto_detail="$(coding_auto_advance_detail "$worktree" "$slug" "$issue")"
[[ -z "$auto_detail" ]] || return 0
artifact_record="$(read_blocked_completion "$feature_dir" "$issue")"
[[ -n "$artifact_record" ]] || return 0
IFS=$'\001' read -r summary reason artifact_mtime <<< "$artifact_record"
summary="$(truncate_blocked_completion_summary "$summary")"
printf '%s needs attention: %s. Type "advance %s" to launch review.\n' "$issue" "$summary" "$issue"
}
coding_auto_advance_detail() {
local worktree="$1" slug="$2" issue="$3"
local feature_dir="$worktree/features/$slug"
local artifact="$feature_dir/.coding-auto-advance.json"
[[ -f "$artifact" ]] || return 0
printf '%s auto-advanced coding to review from blocked completion.\n' "$issue"
}
planning_rejection_detail() {
local worktree="$1" slug="$2"
local feature_dir="$worktree/features/$slug"
local artifact="$feature_dir/.planning-rejected.json"
local reason files
[[ -f "$artifact" ]] || return 0
reason=$(jq -r '.reason // empty' "$artifact" 2>/dev/null || true)
[[ "$reason" == "planning_modified_out_of_scope_files" ]] || return 0
files=$(jq -r '(.outOfScopeFiles // []) | join(", ")' "$artifact" 2>/dev/null || true)
[[ -n "$files" ]] || files="out-of-scope files"
printf 'Planning needs attention: edited %s; reverted. Review plan.md and re-approve.\n' "$files"
}
ready_watchdog_state_file() {
[[ -n "$STATE_FILE" ]] || return 0
printf '%s\n' "$(dirname "$STATE_FILE")/ready-watchdog-state.json"
}
ready_watchdog_field() {
local issue="$1" field="$2"
local watchdog_file
watchdog_file="$(ready_watchdog_state_file)"
[[ -n "$watchdog_file" && -f "$watchdog_file" ]] || return 0
jq -r --arg issue "$issue" --arg field "$field" '.tasks[$issue][$field] // empty' "$watchdog_file" 2>/dev/null || true
}
# Legacy compat wrapper β used in the render loop below.
plan_waiting_for_review() {
local task_phase="$1"
local agent_state="$2"
local worktree="$3"
local slug="$4"
[[ "$task_phase" == "planning" ]] || return 1
[[ -z "$worktree" || -z "$slug" ]] && return 1
# Prefer stage result
local display_status
display_status=$(get_planning_display_status "$worktree" "$slug")
[[ "$display_status" == "awaiting_approval" ]] && return 0
# If planning is no longer running and approval has not been recorded, treat
# an exited agent as waiting for review until the monitor persists the stage update.
[[ "$agent_state" == "exited" ]] || return 1
return 0
}
render_plan_model_routing() {
local worktree="$1" slug="$2"
local planning_result_file="" initial_route_file="" post_expansion_file="" routing_complete_file=""
local phase_config_file="" routing_jsonl_file="" candidate rendered cache_key artifact_key mtime
for candidate in \
"$worktree/features/$slug/.planning-result.json" \
"$worktree/bugs/$slug/.planning-result.json"
do
[[ -f "$candidate" ]] || continue
planning_result_file="$candidate"
break
done
for candidate in \
"$worktree/features/$slug/.initial-route.json" \
"$worktree/bugs/$slug/.initial-route.json"
do
[[ -f "$candidate" ]] || continue
initial_route_file="$candidate"
break
done
for candidate in \
"$worktree/features/$slug/.post-expansion-route.json" \
"$worktree/bugs/$slug/.post-expansion-route.json"
do
[[ -f "$candidate" ]] || continue
post_expansion_file="$candidate"
break
done
for candidate in \
"$worktree/features/$slug/.routing-complete" \
"$worktree/bugs/$slug/.routing-complete"
do
[[ -f "$candidate" ]] || continue
routing_complete_file="$candidate"
break
done
for candidate in \
"$worktree/features/$slug/.phase-config.json" \
"$worktree/bugs/$slug/.phase-config.json"
do
[[ -f "$candidate" ]] || continue
phase_config_file="$candidate"
break
done
for candidate in \
"$worktree/features/$slug/routing.jsonl" \
"$worktree/bugs/$slug/routing.jsonl"
do
[[ -f "$candidate" ]] || continue
routing_jsonl_file="$candidate"
break
done
artifact_key=""
for candidate in \
"$planning_result_file" \
"$initial_route_file" \
"$post_expansion_file" \
"$routing_complete_file" \
"$phase_config_file" \
"$routing_jsonl_file"
do
if [[ -n "$candidate" && -f "$candidate" ]]; then
mtime=$(stat -f %m "$candidate" 2>/dev/null || stat -c %Y "$candidate" 2>/dev/null || echo 0)
artifact_key+="${candidate}:${mtime}|"
fi
done
if [[ -z "$artifact_key" ]]; then
cache_key="missing:${worktree}:${slug}"
else
cache_key="$artifact_key"
fi
if [[ -v WAVEMILL_ROUTING_DISPLAY_CACHE["$cache_key"] ]]; then
printf '%s' "${WAVEMILL_ROUTING_DISPLAY_CACHE["$cache_key"]}"
return 0
fi
rendered="$(
MODEL_RESOLUTION_DISPLAY_PLANNING_RESULT_PATH="$planning_result_file" \
MODEL_RESOLUTION_DISPLAY_INITIAL_ROUTE_PATH="$initial_route_file" \
MODEL_RESOLUTION_DISPLAY_POST_EXPANSION_PATH="$post_expansion_file" \
MODEL_RESOLUTION_DISPLAY_ROUTING_COMPLETE_PATH="$routing_complete_file" \
MODEL_RESOLUTION_DISPLAY_PHASE_CONFIG_PATH="$phase_config_file" \
MODEL_RESOLUTION_DISPLAY_ROUTING_JSONL_PATH="$routing_jsonl_file" \
MODEL_RESOLUTION_DISPLAY_MODULE="$WAVEMILL_REPO_DIR/shared/lib/model-resolution-display.ts" \
npx tsx -e '
(async () => {
const modulePath = process.env.MODEL_RESOLUTION_DISPLAY_MODULE;
const { formatRouteLifecycleDisplayTextFromPaths } = await import(modulePath);
process.stdout.write(formatRouteLifecycleDisplayTextFromPaths({
planningResultPath: process.env.MODEL_RESOLUTION_DISPLAY_PLANNING_RESULT_PATH,
initialRoutePath: process.env.MODEL_RESOLUTION_DISPLAY_INITIAL_ROUTE_PATH,
postExpansionRoutePath: process.env.MODEL_RESOLUTION_DISPLAY_POST_EXPANSION_PATH,
routingCompletePath: process.env.MODEL_RESOLUTION_DISPLAY_ROUTING_COMPLETE_PATH,
phaseConfigPath: process.env.MODEL_RESOLUTION_DISPLAY_PHASE_CONFIG_PATH,
routingJsonlPath: process.env.MODEL_RESOLUTION_DISPLAY_ROUTING_JSONL_PATH,
}));
})().catch(() => process.exit(1));
' 2>/dev/null || true
)"
if [[ -z "$rendered" ]]; then
rendered="executed planning: model resolution unavailable"$'\n'"bootstrap route: unavailable"
fi
WAVEMILL_ROUTING_DISPLAY_CACHE["$cache_key"]="$rendered"
printf '%s' "$rendered"
}
# ββ Elapsed time from directory birth βββββββββββββββββββββββββββββββββββββ
elapsed() {
local dir="$1"
[[ -d "$dir" ]] || { echo "β"; return; }
local birth
birth=$(stat -f %B "$dir" 2>/dev/null || echo 0)
(( birth > 0 )) || { echo "β"; return; }
local mins=$(( ($(date +%s) - birth) / 60 ))
if (( mins < 60 )); then
printf "%dm" "$mins"
else
printf "%dh%dm" $((mins / 60)) $((mins % 60))
fi
}
# ββ Agent status via tmux pane liveness βββββββββββββββββββββββββββββββββββ
# Read agent status via hook protocol with TTL-based fallback to pane liveness.
# Hook files use a 300s TTL - stale status falls back to tmux pane state.
agent_status() {
local win="$1"
local issue="${win%%-*}"
local hook_file="/tmp/wavemill-${SESSION}-${issue}.hook"
# Prefer hook-reported state when fresh (300s TTL)
if [[ -f "$hook_file" ]]; then
local state ts now staleness
state=$(jq -r '.state // empty' "$hook_file" 2>/dev/null || true)
ts=$(jq -r '.timestamp // 0' "$hook_file" 2>/dev/null || echo 0)
now=$(date +%s)
staleness=$(( now - ts ))
if (( staleness < 300 )) && [[ -n "$state" ]]; then
# Map hook states to dashboard display states
case "$state" in
working) echo "running" ;;
idle) echo "exited" ;;
waiting) echo "waiting" ;;
error) echo "error" ;;
*) echo "$state" ;;
esac
return
fi
fi
# Fallback to pane liveness for agents without hook support or stale hooks
local dead
dead=$(tmux list-panes -t "$SESSION:$win" -F '#{pane_dead}' 2>/dev/null | head -1) || {
echo "done"; return
}
if [[ "$dead" == "1" ]]; then echo "exited"; else echo "running"; fi
}
# ββ Task discovery ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Prefer state file (from mill), fall back to worktree directories.
# Output: issue|slug|branch|worktree|status|phase|pr per line
gather_tasks() {
if [[ -n "$STATE_FILE" && -f "$STATE_FILE" ]]; then
jq -r '.tasks | to_entries[] | "\(.key)|\(.value.slug)|\(.value.branch)|\(.value.worktree)|\(.value.status // "")|\(.value.phase // "executing")|\(.value.pr // "")"' \
"$STATE_FILE" 2>/dev/null
else
for dir in "$WORKTREE_ROOT"/*/; do
[[ -d "$dir" ]] || continue
local slug
slug=$(basename "$dir")
local branch
branch=$(git -C "$dir" branch --show-current 2>/dev/null || echo "?")
echo "β|$slug|$branch|$dir||executing|"
done
fi
}
gather_jobs() {
[[ -r "$STATE_FILE" && -s "$STATE_FILE" ]] || return 0
jq -r --arg session "$SESSION" '
(.jobs // {}) |
if type == "array" then .[] else (to_entries[] | .value) end |
select((.kind == "eval" or .kind == "comparison") and .session? == $session) |
[
.id,
.kind,
(.status // ""),
(.issueId // "-"),
(.side // "-"),
(.pairId // "-"),
((.prNumbers // []) | map(tostring) | join("/")),
(.startedAt // "-"),
(.logPath // "-"),
((.excerpt // "") | gsub("[\r\n]+"; " "))
] | join("|")
' "$STATE_FILE" 2>/dev/null
}
# ββ Check if a task is still active ββββββββββββββββββββββββββββββββββββββ
# A task is active if its worktree exists OR its tmux window exists.
is_active() {
local worktree="$1"
local win="$2"
[[ -d "$worktree" ]] && return 0
tmux list-panes -t "$SESSION:$win" 2>/dev/null >/dev/null && return 0
return 1
}
# Truncate detail string to fit within available terminal width.
# Format "%-10s %4s ββ %s" uses ~20 chars of prefix. Leave enough room for
# per-subagent requested/resolved/fallback routing details while still
# truncating long freeform status messages.
truncate_detail() {
local detail="$1"
local max_len=68
if (( ${#detail} > max_len )); then
echo "${detail:0:$((max_len - 3))}..."
else
echo "$detail"
fi
}
render_task_detail_lines() {
local detail_block="${1:-}"
local line
[[ -n "$detail_block" ]] || return 0
while IFS= read -r line || [[ -n "$line" ]]; do
[[ -n "$line" ]] || continue
line=$(truncate_detail "$line")
printf "${D}%10s %4s ββ %s${N}${EL}\n" "" "" "$line" >> "$FRAME"
done <<< "$detail_block"
}
truncate_cell() {
local text="${1:-}" max_len="${2:-0}"
if (( max_len <= 0 )); then
printf ''
return 0
fi
if (( ${#text} <= max_len )); then
printf '%s' "$text"
return 0
fi
if (( max_len <= 3 )); then
printf '%.*s' "$max_len" "$text"
return 0
fi
printf '%.*s...' "$((max_len - 3))" "$text"
}
format_job_elapsed() {
local started_at="$1"
local start_epoch now elapsed ts
# Strip fractional seconds and timezone suffix (handles both 2006-01-02T15:04:05.999Z and no-fraction forms)
ts="${started_at%%.*}"
ts="${ts%Z}"
if date -j -f "%Y-%m-%dT%H:%M:%S" "$ts" "+%s" >/dev/null 2>&1; then
# BSD/macOS date
start_epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$ts" "+%s" 2>/dev/null || echo 0)
else
# GNU/Linux date
start_epoch=$(date -d "${ts/T/ }" "+%s" 2>/dev/null || echo 0)
fi
now=$(date +%s)
if (( start_epoch <= 0 || now < start_epoch )); then
echo "β"
return
fi
elapsed=$(( (now - start_epoch) / 60 ))
if (( elapsed < 60 )); then
printf "%dm" "$elapsed"
else
printf "%dh%dm" $((elapsed / 60)) $((elapsed % 60))
fi
}
parse_iso_timestamp_epoch() {
local timestamp="$1"
local ts
ts="${timestamp%%.*}"
ts="${ts%Z}"
ts="${ts%+*}"
[[ -n "$ts" ]] || { echo 0; return; }
if date -j -f "%Y-%m-%dT%H:%M:%S" "$ts" "+%s" >/dev/null 2>&1; then
date -j -f "%Y-%m-%dT%H:%M:%S" "$ts" "+%s" 2>/dev/null || echo 0
else
date -d "${ts/T/ }" "+%s" 2>/dev/null || echo 0
fi
}
format_running_elapsed() {
local started_at="$1"
local start_epoch now elapsed
start_epoch=$(parse_iso_timestamp_epoch "$started_at")
now=$(date +%s)
if (( start_epoch <= 0 )); then
echo ""
return
fi
if (( now < start_epoch )); then
echo "0s"
return
fi
elapsed=$((now - start_epoch))
if (( elapsed < 60 )); then
printf "%ss" "$elapsed"
elif (( elapsed < 3600 )); then
printf "%dm%02ds" $((elapsed / 60)) $((elapsed % 60))
else
printf "%dh%02dm" $((elapsed / 3600)) $(((elapsed % 3600) / 60))
fi
}
task_running_detail() {
local issue="$1"
[[ -r "$STATE_FILE" && -s "$STATE_FILE" ]] || return 0
local eval_side eval_pr eval_phase eval_started eval_elapsed
eval_side=$(jq -r --arg issue "$issue" '.tasks[$issue].evalRunning.side // empty' "$STATE_FILE" 2>/dev/null || true)
if [[ -n "$eval_side" ]]; then
eval_pr=$(jq -r --arg issue "$issue" '.tasks[$issue].evalRunning.pr // empty' "$STATE_FILE" 2>/dev/null || true)
eval_phase=$(jq -r --arg issue "$issue" '.tasks[$issue].evalRunning.phase // "eval"' "$STATE_FILE" 2>/dev/null || echo "eval")
eval_started=$(jq -r --arg issue "$issue" '.tasks[$issue].evalRunning.startedAt // empty' "$STATE_FILE" 2>/dev/null || true)
eval_elapsed=$(format_running_elapsed "$eval_started")
if [[ -n "$eval_elapsed" ]]; then
printf 'eval running (%s): side=%s pr=#%s phase=%s\n' "$eval_elapsed" "$eval_side" "$eval_pr" "$eval_phase"
else
printf 'eval running: side=%s pr=#%s phase=%s\n' "$eval_side" "$eval_pr" "$eval_phase"
fi
return 0
fi
local pair_id primary_pr challenger_pr comparison_started comparison_elapsed
pair_id=$(jq -r --arg issue "$issue" '.tasks[$issue].comparisonRunning.pairId // empty' "$STATE_FILE" 2>/dev/null || true)
if [[ -n "$pair_id" ]]; then
primary_pr=$(jq -r --arg issue "$issue" '.tasks[$issue].comparisonRunning.primaryPr // empty' "$STATE_FILE" 2>/dev/null || true)
challenger_pr=$(jq -r --arg issue "$issue" '.tasks[$issue].comparisonRunning.challengerPr // empty' "$STATE_FILE" 2>/dev/null || true)
comparison_started=$(jq -r --arg issue "$issue" '.tasks[$issue].comparisonRunning.startedAt // empty' "$STATE_FILE" 2>/dev/null || true)
comparison_elapsed=$(format_running_elapsed "$comparison_started")
if [[ -n "$comparison_elapsed" ]]; then
printf 'comparison running (%s): pair=%s prs=#%s/#%s\n' "$comparison_elapsed" "$pair_id" "$primary_pr" "$challenger_pr"
else
printf 'comparison running: pair=%s prs=#%s/#%s\n' "$pair_id" "$primary_pr" "$challenger_pr"
fi
fi
}
# Classify dashboard tasks into sections based on agent state.
is_actionable_state() {
local agent_state="$1"
local task_phase="${2:-}"
local worktree="${3:-}"
local slug="${4:-}"
local issue="${5:-}"
local ready_status attention_detail planning_detail watchdog_classification coding_detail
if [[ "$task_phase" == "coding" ]]; then
coding_detail=$(coding_blocked_completion_detail "$worktree" "$slug" "$issue")
if [[ -n "$coding_detail" ]]; then
echo "actionable"
return
fi
fi
planning_detail=$(planning_rejection_detail "$worktree" "$slug")
if [[ -n "$planning_detail" ]]; then
echo "actionable"
return
fi
attention_detail=$(ready_attention_detail "$worktree" "$slug")
if [[ -n "$attention_detail" ]]; then
echo "actionable"
return
fi
if [[ "$task_phase" == "ready" ]]; then
watchdog_classification=$(ready_watchdog_field "$issue" "classification")
case "$watchdog_classification" in
stuck|needs-user)
echo "actionable"
return
;;
waiting-on-ci|waiting-on-eval-comparison)
echo "active"
return
;;
esac
ready_status=$(get_ready_display_status "$worktree" "$slug")
case "$ready_status" in
completed|failed|aborted)
echo "actionable"
return
;;
esac
fi
case "$agent_state" in
exited|waiting|error) echo "actionable" ;;
*) echo "active" ;;
esac
}
window_index() {
local win="$1"
# `tmux display-message -t session:missing-window` silently falls back to the
# active window's info instead of erroring, which misreports missing task
# windows as whichever window is currently focused (typically the control
# window at index 0). Verify presence first.
if ! tmux list-windows -t "$SESSION" -F '#{window_name}' 2>/dev/null | grep -qxF "$win"; then
echo "β"
return
fi
tmux display-message -t "$SESSION:$win" -p '#{window_index}' 2>/dev/null || echo "β"
}
render_section_header() {
local title="$1"
local count="$2"
printf "${EL}\n${B}%s${N} ${D}(%s)${N}${EL}\n" "$title" "$count" >> "$FRAME"
printf "${D}%-10s %4s %-22s %6s %-12s %-11s %s${N}${EL}\n" \
"ISSUE" "PANE" "TASK" "TIME" "PHASE" "AGENT" "PR" >> "$FRAME"
printf "${D}%s${N}${EL}\n" \
"ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" >> "$FRAME"
}
# Render one task row and any optional follow-up detail line.
render_task_row() {
local issue="$1" slug="$2" branch="$3" worktree="$4" win="$5"
local task_status="$6" task_phase="$7" state_pr="$8" agent_state="$9"
local t st_str pr_str pr_info checks phase_str plan_status ready_status ready_queue_state attention_detail planning_detail reported ds pane watchdog_classification watchdog_detail running_detail coding_blocked_detail coding_auto_detail
t=$(elapsed "$worktree")
reported=""
watchdog_classification=""
watchdog_detail=""
coding_blocked_detail=""
coding_auto_detail=""
if [[ "$task_status" == "merged" ]]; then
st_str="${G}β merged${N}"
else
# Prefer rich hook detail (tool names, errors) over legacy text files.
reported=$(agent_hook_detail "$issue")
[[ -z "$reported" ]] && reported=$(agent_reported_status "$issue")
case "$agent_state:$reported" in
waiting:*) st_str="${Y}β³ waiting${N}" ;;
error:*) st_str="${R}! error${N}" ;;
exited:*) st_str="${D}β exited${N}" ;;
running:working) st_str="${G}β working${N}" ;;
running:waiting) st_str="${Y}β³ waiting${N}" ;;
running:done) st_str="${D}β idle${N}" ;;
running:*) st_str="${G}β running${N}" ;;
*) st_str="${D} done${N}" ;;
esac
fi
# Only resolve PR cache entries for tasks already tracked with a PR.
pr_str="${D}β${N}"
pr_info=""
if [[ -n "$state_pr" ]]; then
pr_info=$(pr_for_branch "$branch")
fi
if [[ -n "$pr_info" ]]; then
IFS='|' read -r pr_num pr_state <<<"$pr_info"
case "$pr_state" in
MERGED) pr_str="${G}#${pr_num} MERGED${N}" ;;
CLOSED) pr_str="${R}#${pr_num} CLOSED${N}" ;;
OPEN)
if is_ready_conflicted "$worktree" "$slug"; then
pr_str="${Y}#${pr_num} β ${N}"
else
checks=$(pr_checks "$branch")
case "$checks" in
pass) pr_str="${G}#${pr_num} β${N}" ;;
fail) pr_str="${R}#${pr_num} β${N}" ;;
pending) pr_str="${Y}#${pr_num} β¦${N}" ;;
*) pr_str="#${pr_num}" ;;
esac
fi
;;
esac
fi
if [[ "$task_status" == "merged" ]]; then
phase_str="${G}β done${N}"
else
case "$task_phase" in
planning)
plan_status=""
[[ -n "$worktree" && -n "$slug" ]] && plan_status=$(get_planning_display_status "$worktree" "$slug")
planning_detail=$(planning_rejection_detail "$worktree" "$slug")
case "$plan_status" in
awaiting_approval)
if [[ -n "$planning_detail" ]]; then
phase_str="${R}β planning${N}"
else
phase_str="${Y}β³ awaiting${N}"
fi
;;
approved) phase_str="${G}β
approved${N}" ;;
rejected) phase_str="${R}β rejected${N}" ;;
*) phase_str="${Y}π planning${N}" ;;
esac
;;
executing) phase_str="${G}π¨ executing${N}" ;;
coding)
coding_auto_detail=$(coding_auto_advance_detail "$worktree" "$slug" "$issue")
coding_blocked_detail=$(coding_blocked_completion_detail "$worktree" "$slug" "$issue")
if [[ -n "$coding_auto_detail" ]]; then
phase_str="${G}auto review${N}"
elif [[ -n "$coding_blocked_detail" ]]; then
phase_str="${R}β coding${N}"
else
phase_str="${G}π» coding${N}"
fi
;;
review) phase_str="${Y}π review${N}" ;;
ready)
watchdog_classification=$(ready_watchdog_field "$issue" "classification")
watchdog_detail=$(ready_watchdog_field "$issue" "detail")
ready_queue_state=$(get_ready_queue_state "$worktree" "$slug")
if is_ready_conflicted "$worktree" "$slug"; then
phase_str="${Y}β ready${N}"
else
case "$watchdog_classification" in
stuck|needs-user) phase_str="${R}π¦ ready${N}" ;;
waiting-on-ci|waiting-on-eval-comparison) phase_str="${Y}π¦ ready${N}" ;;
*)
ready_status=$(get_ready_display_status "$worktree" "$slug")
case "$ready_queue_state" in
ready-stale) phase_str="${Y}ready-stale${N}" ;;
merge-candidate) phase_str="${G}merge-candidate${N}" ;;
*)
case "$ready_status" in
failed|aborted) phase_str="${R}π¦ ready${N}" ;;
completed) phase_str="${Y}π¦ ready${N}" ;;
*) phase_str="${G}π¦ ready${N}" ;;
esac
;;
esac
;;
esac
fi
;;
*) phase_str="${D}$task_phase${N}" ;;
esac
fi
ds="$slug"
(( ${#ds} > 22 )) && ds="${ds:0:19}..."
pane=$(window_index "$win")
printf "%-10s %4s %-22s %6s %-12b %-11b %b${EL}\n" \
"$issue" "$pane" "$ds" "$t" "$phase_str" "$st_str" "$pr_str" >> "$FRAME"
if [[ -n "$coding_auto_detail" ]]; then
reported="$coding_auto_detail"
elif [[ -n "$coding_blocked_detail" ]]; then
reported="$coding_blocked_detail"
fi
planning_detail=$(planning_rejection_detail "$worktree" "$slug")
if [[ -z "$reported" && -n "$planning_detail" ]]; then
reported="$planning_detail"
elif [[ -z "$reported" ]] && plan_waiting_for_review "$task_phase" "$agent_state" "$worktree" "$slug"; then
reported="Plan ready β waiting for approval"
fi
attention_detail=$(ready_attention_detail "$worktree" "$slug")
if [[ -z "$reported" && -n "$attention_detail" ]]; then
reported="$attention_detail"
fi
if [[ -z "$reported" && -n "$watchdog_detail" ]]; then
reported="$watchdog_detail"
fi
if [[ -z "$reported" ]]; then
running_detail=$(task_running_detail "$issue")
[[ -n "$running_detail" ]] && reported="$running_detail"
fi
case "$reported" in
working|waiting|done) reported="" ;;
esac
if [[ -n "$reported" ]]; then
render_task_detail_lines "$reported"
fi
if [[ "$task_phase" == "planning" ]] && plan_waiting_for_review "$task_phase" "$agent_state" "$worktree" "$slug"; then
render_task_detail_lines "$(render_plan_model_routing "$worktree" "$slug")"
fi
}
render_inbox_section() {
local count="${#inbox_tasks[@]}"
local task_data issue slug branch worktree task_status task_phase state_pr agent_state
(( count == 0 )) && return
render_section_header "π₯ INBOX" "$count"
for task_data in "${inbox_tasks[@]}"; do
IFS='|' read -r issue slug branch worktree win task_status task_phase state_pr agent_state <<<"$task_data"
render_task_row "$issue" "$slug" "$branch" "$worktree" "$win" "$task_status" "$task_phase" "$state_pr" "$agent_state"
done
}
render_active_section() {
local count="${#active_tasks[@]}"
local task_data issue slug branch worktree task_status task_phase state_pr agent_state
render_section_header "β‘ ACTIVE" "$count"
if (( count == 0 )); then
printf "${D}No active tasks${N}${EL}\n" >> "$FRAME"
return
fi
for task_data in "${active_tasks[@]}"; do
IFS='|' read -r issue slug branch worktree win task_status task_phase state_pr agent_state <<<"$task_data"
render_task_row "$issue" "$slug" "$branch" "$worktree" "$win" "$task_status" "$task_phase" "$state_pr" "$agent_state"
done
}
render_queued_section() {
[[ -r "$STATE_FILE" && -s "$STATE_FILE" ]] || return 0
local count
count=$(jq '(.queued_tasks // []) | length' "$STATE_FILE" 2>/dev/null || echo 0)
(( count == 0 )) && return 0