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
//! Transcript view-model (DESIGN §5.1 #12, §11 Altitude-2 Transcript tab).
//!
//! An agent's conversation is a directory of message files at
//! `<workspace>/agents/<agent-id>/messages/`. Each file is
//! `NNN-<origin>.<ext>` — **order lives in the filename** (the `NNN`
//! counter), and **origin lives in the filename token**:
//!
//! | ext | origin token | entry |
//! |------|--------------|----------------------------------------------|
//! | `md` | `<sender>` | delivered message, envelope stripped — bar its `epitaph:` |
//! | `json` | `tool` | `tool_result` (content / is_error / tool_use_id) |
//! | `json` | `<model-id>` | model output — canonical content blocks |
//!
//! Both `.json` origins carry the **same envelope**: a bare array of canonical
//! blocks as legacy litany committed it, or an API-shaped object wrapping them
//! in `content` — with the provider's token `usage` report as `content`'s
//! sibling when one was reported (lernie ≥0.0.4).
//! One function answers where the blocks live (`parse::block_array`)
//! — two answers left every real `NNN-tool.json` in the Raw bucket (bl-47ec).
//! | other / unparseable name / unparseable bytes | — | Raw bucket (never dropped) |
//!
//! **The directory is not append-only.** litany's compactor deletes message
//! files and squashes the span they lived in, so a hole in the `NNN` counter
//! is entries that were *removed* — [`compaction`] derives each one and seats
//! a virtual [`EntryKind::Compacted`] marker in it, carrying whatever
//! `summary/**` the compactor wrote in their place.
//!
//! Everything is a pure function of the on-disk bytes (§3.5 stateless
//! re-read): no field caches a fact the files already carry. "Tool in
//! progress" is a *query* over the entries (a committed `tool_use` with no
//! committed `tool_result`), never a stored flag (PRINCIPLES: single source
//! of truth).
//!
//! **[`build`] reads only what is committed.** The two *trailing* virtual
//! entries — the live streaming tail and the settled-failure notice — are
//! [`tail`]'s, folded on by the caller from what it already holds: the
//! rendered snapshot's [`Stream`](crate::git_tree::Stream), and the §7.3
//! [`Wound`](crate::steps_view::Wound) off a built steps view. Because the
//! halves have different clocks (§7.2): the committed read is memoized per
//! published snapshot, and the tail moves at frame cadence. Merging them into
//! one build made the tail as slow as the derivation, which is the defect
//! bl-54f7 closed.
pub use seq_of;
pub use key;
/// The committed record's disk read — its own file at §12's budget (bl-73e7).
/// The two virtual **trailing** entries and the folds that seat them.
pub
use ;
pub use build;
/// One message file classified — [`build`]'s own reading of a single entry,
/// for the §7.3 orphaned-tail predicate (`steps_view::orphan`, bl-abba), which
/// needs the **tail** entry alone and must not pay a whole record to get it.
pub use classify;
/// Directory under the workspace holding the per-agent worktrees (ARCH §2.3).
const AGENTS_DIR: &str = "agents";
/// The committed-transcript directory inside an agent's worktree.
const MESSAGES_DIR: &str = "messages";
/// The one reserved `.json` origin token: a `tool_result` payload.
const TOOL_ORIGIN: &str = "tool";
const MD_EXT: &str = "md";
const JSON_EXT: &str = "json";
/// A parsed agent transcript: the ordered `messages/` entries, plus whichever
/// [`tail`] entry the conversation's moment has — the live streaming tail
/// while a call is in flight, the settled-failure notice once it has stopped
/// on a §7.3 wound.
/// One transcript row. `raw` is the verbatim backing bytes surfaced by the
/// Raw toggle for *any* entry (§11 "every tab has a Raw toggle showing
/// verbatim bytes"); `kind` is the parsed projection.
/// The origin classification of a transcript entry (see the module table).
/// The committed `usage` record's token counters, verbatim from the bytes
/// (lernie ≥0.0.4 seals the provider's report beside `content`:
/// `{"content":[…],"usage":{"input_tokens":5,…}}`). Counter names are the
/// provider's own — no vocabulary is pinned here, so a counter brazen adds
/// rides through with no edit. Empty is the general path: a legacy bare-array
/// entry, or a provider that reported nothing (a `0` would be a lie).
pub type Usage = BTreeMap;
/// One content block of a model message (§4.4 canonical blocks).