| 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. |
| 7 | ALTER TABLE runs ADD COLUMN agent TEXT; |
| 8 | ALTER TABLE runs ADD COLUMN asked_by TEXT; |
| 9 | ALTER TABLE ledger ADD COLUMN agent TEXT; |
| 10 | ALTER 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)… |
| 15 | UPDATE ledger SET agent = substr(repo, instr(repo, '/@') + 2) |
| 16 | WHERE kind = 'usage' AND agent IS NULL AND repo LIKE '%/@%'; |
| 17 | UPDATE 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. |
| 22 | UPDATE ledger SET agent = 'g1t' |
| 23 | WHERE kind = 'usage' AND agent IS NULL |
| 24 | AND (reference LIKE 'run%' OR (task = 'sandbox' AND compute = 'agent')); |
| 25 | UPDATE runs SET agent = 'g1t' WHERE agent IS NULL; |