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
//! Live daemon polling for the coordinator TUI (Child #2).
//!
//! Why: Child #1 rendered static placeholder rows; the coordinator list must
//! instead reflect the real fleet. This module owns the one async step the run
//! loop repeats on its `--interval-ms` cadence — probe daemon health, self-heal
//! the URL on failure, pull the coordinator context, and project each session
//! into a [`SessionEntry`] — plus the PURE mapping that does the projection so
//! it can be unit-tested without a terminal or a network (DOC-13 §6, §9). The
//! daemon-context feed carries no `last_summary` yet (that is Child #3 / #1275),
//! so the summary is derived client-side here (DOC-13 §6.2 option C).
//! What: [`coord_poll_daemon`] (health → rediscover-on-fail → context → map; on
//! daemon-down clears the rows and sets `daemon_reachable = false`) and
//! [`coord_session_to_entry`] (a pure `CoordinatorSession` → `SessionEntry`
//! projection deriving id/prefix/status/summary).
//! Test: `super::tests` covers `coord_session_to_entry` (summary from the last
//! non-empty `recent_output` line, status fallback, short-id derivation); the
//! async glue mirrors the dashboard's `poll_daemon`.
use crate;
// #9556: the one pin-aware re-discovery step every TUI poll shares (DOC-13 §6.3).
use craterediscover_daemon as rediscover;
use session_short_id;
use ;
/// Refresh [`CoordinatorState`] from one daemon poll.
///
/// Why: keeps the poll logic out of the key-driven run loop so the loop can
/// re-poll on its timer (and, later, on demand after a mutating action) without
/// duplicating the health/rediscover/map sequence. Mirrors the dashboard's
/// `tui::poll_daemon` so both surfaces self-heal the daemon URL identically.
/// What: probes health; if the daemon looks down, re-resolves the URL from the
/// lock file via [`rediscover`] (never an explicit, pinned URL — #9556) and
/// retries one health probe. When reachable it
/// pulls `GET /api/v1/sessions/context` and maps every session into a
/// [`SessionEntry`]; on a transport error or an unreachable daemon it clears the
/// rows and sets `daemon_reachable = false`. Always clamps the selection so a
/// shrunk list never leaves `selected` past the end.
/// Test: `poll_marks_unreachable_clears_sessions` drives the daemon-down branch
/// against a guaranteed-dead client and asserts the rows clear + `daemon_reachable`
/// flips false; `coord_poll_keeps_explicit_url` covers a pinned URL (#9556);
/// the pure projection is covered by the `coord_session_to_entry_*`
/// tests. The daemon-UP path requires a live daemon, so it is exercised manually /
/// by the daemon suites rather than unit-tested here.
pub async
/// Project one coordinator-context session into a list [`SessionEntry`].
///
/// Why: the daemon returns a rich [`CoordinatorSession`], but the list renders
/// the leaner `SessionEntry` shape (short id + prefix + status + a one-line
/// summary). Crucially the context feed has NO `last_summary` field yet (that
/// daemon-side enrichment is Child #3 / #1275), so the summary is derived
/// client-side here: the last non-empty line of `recent_output`, falling back to
/// the status word when the pane tail is empty (DOC-13 §6.2 option C). Keeping
/// this projection pure makes the summary/fallback/short-id rules unit-testable
/// without a terminal or a network.
/// What: returns a [`SessionEntry`] whose `short_id` is the 8-hex prefix of the
/// session id (via [`session_short_id`]), `prefix` and `status` are copied
/// through, and `summary` is the last non-empty `recent_output` line trimmed, or
/// the status word when none exists.
/// Test: `coord_session_to_entry_summarizes_last_output`,
/// `coord_session_to_entry_falls_back_to_status`,
/// `coord_session_to_entry_derives_short_id` in `super::tests`.
pub