Skip to content
25 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Spend adds up on one ledger. Charged this month has one definition, price less discount, included usage and credit, shared by the plan card, the spend limit, Spend and the top bar; the limit had counted usage not yet closed at full price before the discount, so a comped workspace read as charged a cent. Every agent line on the ledger names the agent and who asked, repository runs by g1t included, so Spent is the sum of its products, Agents is the agent product, and by agent adds up to it; the billing API returns by_agent and by_person. The usage and billing guide says how spend is counted.1-- Who an agent's usage is attributed to: the agent that did the work, by
2-- handle, and the person who asked, by username. Every reply and session
3-- step the agents service bills (a run under `<workspace>/@<handle>`), and
4-- every repository run by @g1t from the runner, carries both, so Spend's
5-- "by agent" and "by person" come from the one ledger that is charged,
6-- with no second ledger to disagree with it.
7ALTER TABLE runs ADD COLUMN agent TEXT;
8ALTER TABLE runs ADD COLUMN asked_by TEXT;
9ALTER TABLE ledger ADD COLUMN agent TEXT;
10ALTER TABLE ledger ADD COLUMN asked_by TEXT;
11
12-- What is already on the ledger, attributed once from what it says: a
13-- line billed under `<workspace>/@<handle>` is that agent's (no repository
14-- has an `@` in its name)…
15UPDATE ledger SET agent = substr(repo, instr(repo, '/@') + 2)
16 WHERE kind = 'usage' AND agent IS NULL AND repo LIKE '%/@%';
17UPDATE runs SET agent = substr(repo, instr(repo, '/@') + 2)
18 WHERE agent IS NULL AND repo LIKE '%/@%';
19-- …and every other run, and every agent's sandbox, is g1t's own agent at
20-- work on a repository: all g1t's work shows as @g1t. Who asked is not
21-- known for these; lines from here on carry it.
22UPDATE ledger SET agent = 'g1t'
23 WHERE kind = 'usage' AND agent IS NULL
24 AND (reference LIKE 'run%' OR (task = 'sandbox' AND compute = 'agent'));
25UPDATE runs SET agent = 'g1t' WHERE agent IS NULL;