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
//! Disk accounting for the Disk dashboard (DOC-73 §16).
//!
//! Why: DOC-73 §16.6 item 1 makes a cached byte figure the prerequisite for
//! every other Disk issue — the sunburst spans many projects and worktrees at
//! hundreds of GB to TiB, and neither existing primitive is an index
//! (`trusty-common`'s `dir_size_bytes` and this crate's `measure_bytes_until`
//! both re-stat every file on every call). This module is where that index
//! lives, and where the Disk survey MCP tool (#6927) and the console routes
//! (§16.5) read their bytes from.
//! What: [`size_index::DirSizeIndex`], a path → bytes-with-timestamp cache
//! whose refresh re-reads only the directories whose contents actually
//! changed.
//! Test: `size_index_tests`.
//!
//! # Why trusty-mpm and not trusty-common (#6926)
//!
//! The issue hedged "likely in `trusty-common` alongside `dir_size_bytes`".
//! It lives here instead because §16.1 names trusty-mpm as the Disk
//! dashboard's data source (project registry, worktree discovery) and §16.4
//! states console reaches trusty-mpm only through MCP tools — so the index has
//! exactly one caller, and it is in this crate. CLAUDE.md's common-entry-point
//! rule scopes itself to capabilities shared ACROSS crates; promoting this one
//! before a second crate calls it would buy a published-crate version bump and
//! a workspace-wide gate for sharing that does not exist yet. Moving the module
//! to `trusty-common` is a file move plus a re-export the day a second crate
//! needs it.
//!
//! [`size_index::DirSizeIndex`]: crate::disk::size_index::DirSizeIndex
// #6927: the Disk dashboard's worktree survey — the classification the
// `disk_survey` MCP tool returns, and the run that gathers its facts. Crate
// -internal: every type in it names a `pub(crate)` reclaim type, and the MCP
// tool is the only consumer.
pub
pub
/// Render a byte count the way an operator reads a disk figure.
///
/// Why: "1180591620717411303424" is not an early warning. The 1.1 TiB in the
/// 2026-07-21 post-mortem is only legible in binary units. It lives here, on
/// the module that owns disk accounting, rather than in
/// [`crate::daemon::doctor`]'s private `doctor_worktree_disk` submodule where
/// it started (#7313): `tm
/// session disk` renders the same figures from the `tm` binary, which is a
/// separate crate from the library and so cannot reach a private daemon
/// helper. One formatter, so the doctor row and the CLI never disagree about
/// what 1.1 TiB looks like.
/// What: binary units (1024-based), one decimal place above KiB.
/// Test: `human_bytes_renders_binary_units`.