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
//! Deterministic project status-aggregation route (#2117, DOC-35 §4.1).
//!
//! Why: `tm projects status <name>` (#2115) and the multipane-TUI Projects-pane
//! aggregate glyph (#2118) need a single-call rollup of a project's session
//! landscape without every consumer re-implementing the count/max logic. DOC-35
//! §11 draws a hard boundary: this endpoint is L3-substrate (deterministic
//! control plane) — it polls and reports already-computed state and MUST NEVER
//! call an LLM, reason across projects, or infer anything. It is a pure function
//! of already-materialized state: re-running it with no state change between
//! calls yields byte-identical output. #2382 (Wave 2) extends the rollup with
//! Deliverable/Milestone status histograms (DOC-35 §4.1 extension) computed the
//! same way, over the same kind of already-persisted state.
//! What: defines the response shapes ([`SessionStateCounts`],
//! [`ProjectConfigFlags`], [`DeliverableStatusCounts`],
//! [`MilestoneStatusCounts`], [`ProjectStatusResponse`]), the pure aggregation
//! function [`aggregate_project_status`], its counting helpers
//! ([`count_deliverable_statuses`], [`count_milestone_statuses`]), and the axum
//! handler [`project_status_route`] for `GET /api/v1/projects/{name}/status`.
//! Split into this directory module (`mod.rs` + `tests.rs`) to stay under the
//! 500-SLOC production cap once #2382 added the histogram types/logic —
//! mirrors the `core/session_launch/` mod.rs+tests.rs split pattern.
//! Test: the `aggregate_project_status_*` and `count_*_statuses_*` unit tests in
//! `tests.rs` (pure-rollup contract) and
//! `status_route_returns_deterministic_rollup` /
//! `status_route_unknown_project_is_404` /
//! `status_route_includes_deliverable_and_milestone_histograms` HTTP handler
//! tests in `tests/project_status_route.rs`.
use HashSet;
use Arc;
use ;
use ;
use Serialize;
use warn;
use crateDaemonError;
use crateDaemonState;
use crate;
use crate;
use crate;
/// Histogram of a project's sessions by [`ManagedSessionState`].
///
/// Why: the aggregate view needs a per-state count so a consumer can render
/// "3 active, 1 errored" without walking the raw session list. A typed struct
/// (one field per variant) keeps the wire shape explicit and self-documenting
/// rather than a map keyed by stringly-typed states.
/// What: one `usize` per lifecycle variant plus `total` (the sum of all five —
/// the number of session records bound to the project, tombstones included).
/// Every field is a pure count over already-persisted `SessionRecord.state`.
/// Test: `aggregate_project_status_counts_by_state`.
/// Boolean config-completeness flags for a project (DOC-35 §4.1).
///
/// Why: the aggregate view surfaces at-a-glance whether a project is fully
/// configured for delegated `gh` operations without the consumer reading the
/// full [`Project`] record. Every flag is a pure `Option::is_some()` check over
/// already-persisted config — no validation, no network call, no `gh auth`
/// probe (that mutating/side-effecting check belongs to the PATCH route, §4).
/// What: one bool per config field that gates project automation. `jira_config`
/// is intentionally absent until #2082/#2122 land its persisted field; per §4.1
/// it will be added here additively as `jira_config_set` at that point.
/// Test: `aggregate_project_status_config_flags`.
/// Histogram of a project's Deliverables by [`DeliverableStatus`] (#2382, DOC-35
/// §4.1 extension).
///
/// Why: the rollup surfaces at-a-glance how many Deliverables sit in each
/// §10.3 lifecycle state, without every consumer walking
/// [`crate::deliverable::DeliverableManager::all_deliverables`] and
/// re-implementing the tally. A typed struct (one field per variant, like
/// [`SessionStateCounts`]) keeps the wire shape explicit and lets
/// [`count_deliverable_statuses`] use an exhaustive `match` — a future new
/// [`DeliverableStatus`] variant fails this file's build rather than being
/// silently dropped from the count.
/// What: one `usize` per [`DeliverableStatus`] variant plus `total` (the sum of
/// all six). Every field is a pure count over already-persisted
/// `Deliverable::status` values, scoped to one project (§11: single-project
/// scope, zero inference — no normalization, no derived business rules).
/// Test: `count_deliverable_statuses_empty_is_all_zero`,
/// `count_deliverable_statuses_mixed_tally`.
/// Histogram of a project's Milestones by [`MilestoneStatus`], plus a
/// referential-integrity SIGNAL — never a repair (#2382, DOC-35 §4.1
/// extension).
///
/// Why: mirrors [`DeliverableStatusCounts`] for Milestones.
/// `dangling_deliverable_refs` surfaces the #2378/#2395 write-path deferral
/// (referential integrity between a Milestone's `deliverables` member ids and
/// the Deliverable store is explicitly NOT validated at write time, per §13
/// Q6 and §11's no-cross-store-reasoning boundary) as a read-only count. This
/// endpoint counts dangling references; it does not validate, fix, or drop
/// them, and it performs no cross-store write.
/// What: one `usize` per [`MilestoneStatus`] variant, `total` (the sum of all
/// four), and `dangling_deliverable_refs` — the count of the project's
/// Milestones that reference at least one [`DeliverableId`] absent from the
/// project's own Deliverable set.
/// Test: `count_milestone_statuses_empty_is_all_zero`,
/// `count_milestone_statuses_mixed_tally`,
/// `count_milestone_statuses_flags_dangling_deliverable_refs`.
/// Deterministic rollup of one project's status (`GET .../{name}/status`).
///
/// Why: the single response body for #2117 — the pure-rollup contract of
/// DOC-35 §4.1. It was designed to extend additively, and #2382 (Wave 2) does
/// exactly that: `deliverables`/`milestones` histogram fields, computed the
/// same way over the same kind of already-persisted state now that the §10
/// data model (#2378) has landed. Adding serde-serialized fields is
/// non-breaking for existing consumers, so no version bump or shape change is
/// required.
/// What: the project identity (`project_name`/`repo_url`), the session-state
/// histogram, the most-recent `last_activity_at` across the project's sessions,
/// the config-completeness flags, and (as of #2382) the Deliverable/Milestone
/// status histograms. Every field is a pure function of the inputs — zero
/// inference, zero LLM, single-project scope.
/// Test: `aggregate_project_status_counts_by_state`,
/// `aggregate_project_status_max_activity`, `aggregate_project_status_config_flags`,
/// `aggregate_project_status_includes_deliverable_and_milestone_histograms`.
/// Compute the deterministic status rollup for a project.
///
/// Why: the pure core of #2117 (extended by #2382), extracted from the handler
/// so the rollup logic is unit-testable with hand-constructed inputs and so its
/// determinism is self-evident — it takes owned/borrowed state, performs only
/// counting and a `max`, and does zero I/O, no LLM call, and no cross-project
/// reasoning (DOC-35 §11 boundary contract). Given the same inputs it returns a
/// byte-identical [`ProjectStatusResponse`] every time.
/// What: filters `all_sessions` to those bound to `project` (reusing the shared
/// [`fleet_by_project`] URL-matching so binding stays consistent with the
/// `/fleet` route), tallies a per-state histogram, takes the maximum
/// `last_activity_at` across the bound sessions, and reads the two config flags
/// off the record. Sessions with no `repo_url` (or an unmatched one) are omitted,
/// exactly as `fleet_by_project` specifies. As of #2382, also filters
/// `all_deliverables`/`all_milestones` to those whose `project_name` matches
/// `project.name`, then delegates to [`count_deliverable_statuses`] /
/// [`count_milestone_statuses`] for the two new histograms.
/// Test: `aggregate_project_status_counts_by_state`,
/// `aggregate_project_status_max_activity`, `aggregate_project_status_config_flags`,
/// `aggregate_project_status_is_deterministic`,
/// `aggregate_project_status_includes_deliverable_and_milestone_histograms`.
/// Tally a project-scoped Deliverable slice into a [`DeliverableStatusCounts`].
///
/// Why: the pure counting core DOC-35 §11 requires — no normalization, no
/// derived business rules, just an exhaustive tally so a future
/// [`DeliverableStatus`] variant fails to compile here instead of silently
/// under-counting.
/// What: one pass over `deliverables`, incrementing exactly one bucket per
/// record via an exhaustive `match` over every [`DeliverableStatus`] variant
/// (no wildcard arm), plus `total`.
/// Test: `count_deliverable_statuses_empty_is_all_zero`,
/// `count_deliverable_statuses_mixed_tally`.
/// Tally a project-scoped Milestone slice into a [`MilestoneStatusCounts`],
/// including the dangling-deliverable-ref signal.
///
/// Why: same pure-counting contract as [`count_deliverable_statuses`], plus the
/// #2378-deferred referential-integrity signal — surfaced here as a count,
/// never repaired or (re-)validated (§11, §13 Q6).
/// What: one pass over `milestones`, incrementing exactly one status bucket per
/// record via an exhaustive `match` over every [`MilestoneStatus`] variant (no
/// wildcard arm), `total`, and `dangling_deliverable_refs` — incremented once
/// per Milestone that references at least one id absent from
/// `project_deliverable_ids`.
/// Test: `count_milestone_statuses_empty_is_all_zero`,
/// `count_milestone_statuses_mixed_tally`,
/// `count_milestone_statuses_flags_dangling_deliverable_refs`.
/// GET /api/v1/projects/{name}/status — deterministic project status rollup.
///
/// Why: exposes [`aggregate_project_status`] over HTTP so the deterministic CLI
/// (#2115) and TUI (#2118) — and any other consumer, including #2109 per the
/// §11 "expose data over MCP/HTTP for ANY consumer to read" row — can read the
/// rollup without an MCP client. The handler is a thin composition over
/// `ProjectRegistry::get` + `SessionManager::list` + (as of #2382)
/// `DeliverableManager::all_deliverables`/`all_milestones`; it adds no
/// persistence and no reasoning.
/// What: looks up the named project (404 if unregistered), lists all live
/// session records plus all Deliverable/Milestone records, and returns
/// `Json(aggregate_project_status(..))`. A project store read error (other than
/// not-found) or a Deliverable/Milestone store read error degrades to 500 with
/// a logged warning rather than a panic — the library never `unwrap`s a store
/// result.
/// Test: `status_route_returns_deterministic_rollup`,
/// `status_route_unknown_project_is_404`,
/// `status_route_includes_deliverable_and_milestone_histograms` in
/// `tests/project_status_route.rs`.
pub async
/// [`project_status_route`]'s body, with no transport in it (#6288 slice 5).
///
/// # Errors
///
/// [`DaemonError::NotFound`] when `name` is not registered;
/// [`DaemonError::Internal`] when the project, deliverable, or milestone store
/// read fails.
///
/// Test: `parity_project_status_agrees_across_transports`,
/// `rpc_project_status_unknown_project_is_not_found`.
pub async