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
//! Spend attribution: the yog-side join (DESIGN §3.5; VISION spend attribution).
//!
//! Cost per ball is a **query**, and single-source-of-truth is what makes it
//! one. Every fact it needs already has an owner: brazen counts tokens and
//! never learns a price; litany commits that count into the step record; balls
//! tags every delivery `[bl-id]` and stays metric-free. Yog adds exactly two
//! things nobody below it may hold — **the price table** ([`prices`]) and
//! **the join** (this module) — and stores neither result (§3.5: a figure is
//! re-derived from disk, never written down).
//!
//! The join is `Σ(step usage over the agents tied to the ball) × prices`, and
//! *tied to* is the honest part. §3.2 enumerates two altitudes of ball
//! attribution and this module renders both rather than papering over the
//! gap:
//!
//! - a ball a conversation's `goal.md` **stamps** (`Ball <id>:`, §3.3) is
//! attributed at conversation granularity — the exact agents, their whole
//! descent included;
//! - a ball an agent claimed **mid-conversation** stamps only the *workspace*
//! name, and no fact anywhere records which conversation picked it up.
//! The ruling: accept **workspace-granularity**
//! attribution for such a ball and say so on the figure. No linkage fact is
//! invented — a yog-side conversation↔ball registry would be a second home
//! for someone else's fact, which is the thing §3.2 already refused.
//!
//! Unpriced tokens are reported, never rounded to free: a step whose model the
//! table does not price contributes to [`Cost::unpriced_tokens`], so a partial
//! table reads as "at least this much", which is true, instead of a number
//! that is quietly wrong.
//!
//! **The walk is the worker's, the join is anyone's** (bl-9dd4). Every function
//! here is pure over a workspace's already-walked [`StepBill`]s, which the
//! derivation worker folds once per pass onto `Snapshot::bills`. That is what
//! lets a whole *board* carry a spend column: a figure per row is a filter over
//! memory, not a `steps/` walk per row on the frame thread (§7.2 — the frame
//! renders snapshots and reads no disk).
use crate;
use PathBuf;
pub use Ceiling;
pub use ;
/// What a figure cost, in micro-USD, plus what it could not price.
/// The granularity a figure is honest at (§3.2's two altitudes, §3.5's
/// ruling). Not a quality grade — both arms are exact sums; they differ in
/// *what* they sum over.
/// The clause an attribution says out loud, with the explanation behind it.
/// One attributed spend figure: the tokens, what they cost when the table
/// prices them, and the granularity the sum is honest at.
/// The bills `roots` claims out of one workspace's walk: every bill under any
/// named root's tree, or — when `roots` is empty — the whole workspace, which
/// is §3.5's workspace-granularity arm. One bill is taken at most once however
/// many roots would want it, so a caller cannot double-bill by listing a root
/// twice.
/// The granularity a set of roots is honest at — empty is the workspace arm.
/// **The whole world's priced spend** — every workspace in `workspaces`, folded
/// into one number, which is the scope the §3.5
/// [`Ceiling`](crate::boundary::ceiling) gate compares against since bl-a80a.
/// `None` is the empty price table, the §3.5 severability gate.
///
/// A *cost* rather than a [`Figure`], because a bound is arithmetic and never a
/// rendering: an [`Attribution`] label answers "what is this figure honest
/// about" for a figure somebody reads, and nothing reads this one — the gate
/// compares it and the board asks the gate. Inventing a world label for a value
/// no surface shows would be a fact with no reader.
///
/// **The one fold that still walks disk itself** (bl-56d5 × bl-9dd4): every
/// other figure here reads the worker's `Snapshot::bills`, but a *gate* must
/// compare against the world as it is at the instant it refuses, not against a
/// snapshot that may be a debounce window old. It runs once per spawn, at a
/// chokepoint, so it costs one walk on a gesture rather than a walk per row per
/// frame — and the spawn rate is already bounded at one per full sweep (§4.3),
/// however many workspaces the roster holds.
/// **One branch's whole-tree figure** (§5.1 #16 priced): the agent named and
/// its hyphenated descent, attributed to itself. `bills` is its workspace's
/// walk.
///
/// A *branch*, not a root (bl-131d). [`Scope::Tree`] is a prefix predicate and
/// a child id is itself such a prefix, so the same one filter over the same
/// already-walked bills answers "what did this subagent cost" as cheaply as it
/// answers the whole conversation's — which is why the seat asks it about the
/// agent it is showing rather than about that agent's root. Selecting the root
/// still folds the whole tree, because the root's branch *is* the tree.
/// A ball's figure, attributed as honestly as the facts allow (§3.5's ruling).
/// `stamped_roots` is every root in the workspace whose goal stamps the ball;
/// empty falls back to the whole workspace and labels itself so.
/// Fold a bill set into a figure, pricing it only when a table exists. **Public
/// because a rollup crosses workspaces** (§3.5, bl-9dd4): the board selects one
/// slice per workspace, concatenates them, and folds the whole here — one fold,
/// whatever enumerated it.
/// The money half of [`figure`] alone: what `bills` cost, or `None` when the
/// table is empty. **The severability gate lives here and only here** — an
/// unpriced yog bounds nothing rather than inventing a token proxy for dollars
/// (§3.5) — so the ceiling's world fold and every rendered figure ask one
/// function and cannot disagree about what "unpriced" means.
/// Price every bill by its own step's model — the join proper. A bill whose
/// model the table does not carry lands in `unpriced_tokens`.