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
//! Pure data types and constants for the health screen.
//!
//! Why: keeping the wire shapes, the projected per-daemon payloads, the
//! connection-state enum, and the screen/struct definitions in one place lets
//! the transport (`probes`), the formatters (`format`), the line builders
//! (`screen`), and the renderer (`render`) all depend on a single, dependency-free
//! data layer.
//! What: the default URLs / poll cadence / buffer-cap constants, the [`Daemon`]
//! / [`HealthTab`] / [`PalaceActivity`] tags, the [`CollectionRow`] /
//! [`LogBuffer`] / [`PanelData`] / [`PanelState`] data structs (with their
//! self-contained impls), the [`HealthWire`] deserialization target, the
//! [`HealthUpdate`] message, and the [`HealthClient`] / [`HealthScreen`] struct
//! definitions (their impls live in `probes` and `screen` respectively).
//! Test: `cargo test -p trusty-mpm` exercises the projections and line builders
//! that consume these types.
use Duration;
use Deserialize;
/// Default trusty-search daemon address used when no override is supplied.
///
/// Why: the health screen must always have a target to probe; the search
/// daemon binds `127.0.0.1:7878` by convention.
/// What: the canonical local trusty-search HTTP base URL.
/// Test: `default_urls_are_local`.
pub const DEFAULT_SEARCH_URL: &str = "http://127.0.0.1:7878";
/// Default trusty-memory daemon address used when no override is supplied.
///
/// Why: mirrors [`DEFAULT_SEARCH_URL`]; the memory daemon's health endpoint is
/// reached at `127.0.0.1:7990` for the monitor surface.
/// What: the canonical local trusty-memory HTTP base URL.
/// Test: `default_urls_are_local`.
pub const DEFAULT_MEMORY_URL: &str = "http://127.0.0.1:7990";
/// Interval between health polls for each panel.
///
/// Why: the ticket mandates a 5-second refresh cadence for both the online and
/// the offline (retry) paths.
/// What: five seconds.
/// Test: exercised indirectly by the background poller.
pub const POLL_INTERVAL: Duration = from_secs;
/// Which daemon a panel (or a poll result) refers to.
///
/// Why: the background poller probes two daemons and the event loop must route
/// each [`HealthUpdate`] to the correct panel; a typed tag keeps that routing
/// exhaustive.
/// What: `Search` for trusty-search, `Memory` for trusty-memory.
/// Test: `toggle_focus_cycles_panels`.
/// Maximum number of buffered log lines kept per service.
///
/// Why: the Logs tab is a ring buffer of the most recent daemon log lines; a
/// fixed cap keeps memory bounded on long sessions.
/// What: 200 lines — wide enough to scroll through recent activity, small
/// enough to redraw quickly.
/// Test: `log_buffer_evicts_oldest`.
pub const LOG_BUFFER_CAP: usize = 200;
/// Which right-panel tab is currently active.
///
/// Why: the redesign in issue #36 puts the per-service detail behind three
/// tabs (`[1]HEALTH [2]LOGS [3]SEARCH`); a typed enum keeps tab-switch and
/// render dispatch exhaustive.
/// What: `Health` shows resource gauges + config, `Logs` shows a scrollable
/// log tail, `Search` shows a query input + results, `Index` shows
/// per-collection stats (graph + communities) for the selected row.
/// Test: `tab_default_is_health`, `tab_switch_keys_route`.
/// One row in the left-panel collections list.
///
/// Why: the redesigned screen surfaces the service's collections (search
/// indexes) or palaces (memory) so the operator can see each one's status at
/// a glance and drill into it.
/// What: a display id, an item count (chunks or vectors), and a one-line
/// status note (e.g. `indexed 2m ago`, `reindexing 42%…`, `error: …`).
/// Test: `collection_row_default_is_empty`.
/// Activity state of a memory palace, derived from `last_write_at`.
///
/// Why: operators want to see at a glance which palaces are doing something
/// (being indexed, recently touched) vs. idle. A typed enum keeps the
/// derivation logic, the spinner mapping, and the colour mapping exhaustive
/// and unit-testable.
/// What: `Idle` is the default (no recent activity), `Indexing` covers very
/// recent writes (within 10s) where the palace is likely still flushing
/// vectors, `Active` covers writes within the last minute, `Dreaming` is
/// returned when the row's `is_compacting` flag is set (the daemon flips it
/// for the duration of every `Dreamer::dream_cycle`), and `Error` is set
/// when a row's `ok` flag is false.
/// Test: `palace_activity_from_recent_write`.
/// Ring buffer of recently-observed log lines for one service.
///
/// Why: the Logs tab needs the last N lines and must drop the oldest when
/// full so memory cannot grow without bound; the tab also tracks a scroll
/// offset so the operator can hold position while new lines arrive.
/// What: a `VecDeque` capped at [`LOG_BUFFER_CAP`] plus an `auto_scroll` flag
/// and a `scroll_offset` (lines from the bottom).
/// Test: `log_buffer_evicts_oldest`, `log_buffer_scroll_clamps`.
/// Wire shape of `GET /health` shared by both daemons (issue #35).
///
/// Why: trusty-search and trusty-memory return a compatible health block —
/// `version`, `rss_mb`, `cpu_pct`, `uptime_secs`, `disk_bytes` — so one
/// deserialization target serves both. Every field is `#[serde(default)]` so a
/// daemon on an older build (missing the issue-#35 fields) still deserializes.
/// What: the resource block both `/health` endpoints emit.
/// Test: `health_wire_deserializes_partial_payload`.
pub
/// Projected health payload for one daemon panel.
///
/// Why: the panel renders a fixed set of fields; a small typed struct keeps the
/// renderer free of raw JSON and lets the line builder be unit-tested.
/// What: the version string, resource metrics, and the two key-count fields
/// (`count_a` / `count_b`) whose labels differ per daemon.
/// Test: `search_panel_lines_format_fields`, `memory_panel_lines_format_fields`.
/// The connection state of one daemon panel.
///
/// Why: each panel renders distinctly whether it is still connecting, has a
/// fresh payload, or is offline with a captured error; a typed enum keeps that
/// rendering exhaustive.
/// What: `Connecting` before the first poll, `Online` with a payload, or
/// `Offline` with the last error string.
/// Test: `panel_lines_render_each_state`.
/// A health poll result delivered from the background task to the event loop.
///
/// Why: polling runs off-thread so a slow daemon never freezes input handling;
/// the loop drains these messages and folds them into the [`HealthScreen`].
/// What: the [`Daemon`] the result is for, plus the new [`PanelState`].
/// Test: `apply_update_routes_to_panel`.
/// Typed HTTP client for one daemon's health + list endpoints.
///
/// Why: the background poller needs a small, testable transport that yields a
/// projected [`PanelData`] or a clean error string; keeping it here mirrors the
/// `trusty-common` monitor clients without depending on that crate's feature.
/// What: holds a base URL, the [`Daemon`] tag (which decides the list
/// endpoints), and a pooled `reqwest::Client` with a request timeout.
/// Test: `health_client_stores_base_url`.
/// The combined search + memory health screen (`[2]`).
///
/// Why: the event loop polls both daemons on a background task and folds the
/// results here; a clean data struct keeps the loop terse and the rendering
/// pure. Held alongside the chat `DashboardState` so switching screens never
/// resets either surface.
/// What: a [`PanelState`] and base URL per daemon, plus the focused [`Daemon`]
/// that the `[S]`/`[X]` keys act on.
/// Test: `toggle_focus_cycles_panels`, `apply_update_routes_to_panel`.