Task page: what the task used, in all and per step
The task page's header says quietly what the task used from its
chat_usage rows ("Used 84k tokens (61k cached)"), and the specialist
panel on the right lists each step that used any ("Engineering, fix
round 1: 12k tokens (9k cached)") and the questions asked about it, in
their own live region (#task-spend). Tokens are all input, cached or
not, plus output: Claude's cached and cache-written input are counted
beside its input, Codex's inside it. A sum with a missing figure says
"at least"; a task without rows, or a sum that cannot be read, shows
nothing. Anyone on the team who can read the task sees it.
Seven new copy entries, each marked COPY REVIEW REQUIRED in copy.go and
listed in the Plan 3 copy inventory: work.spend, work.spend_uncached,
work.spend_at_least, work.spend_step, work.spend_step_uncached,
work.spend_questions, work.spend_steps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+263
−5
.rastrillo/budgets.txt+2 −2docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+7 −0internal/equipo/chat/connections.go+67 −0internal/equipo/copy.go+7 −0internal/equipo/static/equipo.css+1 −0internal/equipo/templates/work_task.html+2 −0internal/equipo/work_pages.go+10 −3internal/equipo/work_spend.go+74 −0internal/equipo/work_spend_test.go+36 −0internal/thintest/spend_pages_test.go+57 −0
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index b9666e2e..8bbfb3f6 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -49,7 +49,7 @@ perf GET /api/v1/notebook skip Thin v1 person API: bearer-only JSON for devices; |
| perf GET /api/v1/thinking skip Thin v1 person API: bearer-only JSON for devices; the browser reads thinking words on /settings/thinking. |
| perf GET /api/v1/tasks skip Thin v1 person API: bearer-only JSON for devices; the browser reads tasks through /tasks. |
| perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads a task through /tasks/{id}. |
| -size internal/equipo/chat 12000 - Claude's sign-in by a link adds the code route beside the token's in SendSecret, the sign-in prompt and the kind it becomes (about 40 lines); measured 11933. Mac runners slices A and B add per-runner mailboxes, placement, withdrawal, the offline rule, the runners view, transfers and publication (runners.go, transfers.go, about 1100 lines). Composer attachments add uploads, the message link, the mailbox relay with chunk frames hydrated from the stored file, and serving (attachments.go, attachments_http.go, about 330 lines); the link and relay run inside the send and dispatch transactions, so they live beside them; sniffing and stripping are pure, in internal/attach. Measured 10292. Merged with UX1 thinking words (f2602d3), measured 9801. Housekeeping slice 1 adds the loop's ledger and state machine, the housekeeping principal's checks inside the shared store functions, reservations, Pause, quiet hours, the digest, claim recovery and the API (housekeeping.go, housekeeping_control.go, housekeeping_http.go, about 1,350 lines); the checks must run inside the store's transactions, so they live beside them; the detectors themselves are pure, in internal/equipo/housekeeping. Measured 9637. Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Connections slice 1 review round 2: the mutation ledger matches record_task by subject only and refuses an ambiguous call with the earlier operations, the preference and forget (about 120 lines); measured 8236. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| +size internal/equipo/chat 12100 - Spend 1 adds a task's spend from its usage rows (TaskSpend, about 60 lines) and the usage rows' round; measured 12047. Claude's sign-in by a link adds the code route beside the token's in SendSecret, the sign-in prompt and the kind it becomes (about 40 lines); measured 11933. Mac runners slices A and B add per-runner mailboxes, placement, withdrawal, the offline rule, the runners view, transfers and publication (runners.go, transfers.go, about 1100 lines). Composer attachments add uploads, the message link, the mailbox relay with chunk frames hydrated from the stored file, and serving (attachments.go, attachments_http.go, about 330 lines); the link and relay run inside the send and dispatch transactions, so they live beside them; sniffing and stripping are pure, in internal/attach. Measured 10292. Merged with UX1 thinking words (f2602d3), measured 9801. Housekeeping slice 1 adds the loop's ledger and state machine, the housekeeping principal's checks inside the shared store functions, reservations, Pause, quiet hours, the digest, claim recovery and the API (housekeeping.go, housekeeping_control.go, housekeeping_http.go, about 1,350 lines); the checks must run inside the store's transactions, so they live beside them; the detectors themselves are pure, in internal/equipo/housekeeping. Measured 9637. Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Connections slice 1 review round 2: the mutation ledger matches record_task by subject only and refuses an ambiguous call with the earlier operations, the preference and forget (about 120 lines); measured 8236. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
| @@ -62,4 +62,4 @@ perf GET /conversation/attachments/{id}/preview skip Composer attachments: an im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s Mac runners slice B: TestReleaseRunnerHasNoFakeWorker builds the release runner exactly as make release-runner does and the thin package under the testbuild tag (measured 11.9s locally with a warm cache). |
| size internal/headless - 8300 Claude's sign-in by a link adds its end-to-end, contained-launch and real runner kill tests (signin_test.go, signin_contained_test.go, about 400 lines); measured 8090. |
| -size internal/thintest - 10000 Claude's sign-in by a link adds the code contract (signin_contract_test.go: the card, the code route's refusals, the wrong-code card, the kind it becomes and the canary sweep, about 220 lines); measured 9896. The Connections Add page and the Settings rail add their page contracts and the rail's browser drive (connections_add_pages_test.go, settings_rail_pages_test.go, about 230 lines); measured 9676. Claude setup tokens add the token and Check again contracts; measured 9444 with the composer and Mac lines merged. The instant thinking line adds its browser drive (instant_browser_test.go, about 230 lines); measured 9064 with the composer and Mac lines merged. Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness. |
| +size internal/thintest - 10100 Spend 1 adds the task page's spend contract (spend_pages_test.go, about 60 lines); measured 10025. Claude's sign-in by a link adds the code contract (signin_contract_test.go: the card, the code route's refusals, the wrong-code card, the kind it becomes and the canary sweep, about 220 lines); measured 9896. The Connections Add page and the Settings rail add their page contracts and the rail's browser drive (connections_add_pages_test.go, settings_rail_pages_test.go, about 230 lines); measured 9676. Claude setup tokens add the token and Check again contracts; measured 9444 with the composer and Mac lines merged. The instant thinking line adds its browser drive (instant_browser_test.go, about 230 lines); measured 9064 with the composer and Mac lines merged. Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness. |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 69c47ab8..e1093650 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -5881,6 +5881,13 @@ records remain unchanged. |
| | `runner.verdict.failed` | Failed | Mac runners (Darwin worker) | COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `runner.verdict.skipped` | Not run | Mac runners (Darwin worker) | COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `runner.verdict.unavailable` | Unavailable | Mac runners (Darwin worker) | COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.spend` | Used %s tokens (%s cached) | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_uncached` | Used %s tokens | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_at_least` | at least %s | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_step` | %s: %s tokens (%s cached) | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_step_uncached` | %s: %s tokens | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_questions` | Questions | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| +| `work.spend_steps` | Tokens each step used | Spend 1 (task page and specialist panel) | Runtime; COPY REVIEW REQUIRED | |
| ## Task 21 |
diff --git a/internal/equipo/chat/connections.go b/internal/equipo/chat/connections.go| index 03a73fba..246d22b6 100644 |
| --- a/internal/equipo/chat/connections.go |
| +++ b/internal/equipo/chat/connections.go |
| @@ -758,6 +758,73 @@ func (s *Store) NoConnection(ctx context.Context, person string) (out []NoConnec |
| return out, err |
| } |
| +// Spend is what usage rows add up to: every token read or written |
| +// (input, cached or not, and output) and, of them, the cached input. |
| +// Partial: a row lacked a figure, so the sum is a lower bound. |
| +type Spend struct { |
| + Tokens, Cached int64 |
| + Partial bool |
| +} |
| + |
| +func (s *Spend) add(o Spend) { |
| + s.Tokens, s.Cached, s.Partial = s.Tokens+o.Tokens, s.Cached+o.Cached, s.Partial || o.Partial |
| +} |
| + |
| +// TaskSpend is a task's recorded usage: in all, per step, and for the |
| +// questions asked about it. Rows is how many usage rows there were. |
| +type TaskSpend struct { |
| + Total Spend |
| + Steps map[string]Spend |
| + Questions Spend |
| + Rows int |
| +} |
| + |
| +// TaskSpend reads a task's usage rows for anyone on the team who can |
| +// read the task. Claude reports cached and cache-written input apart |
| +// from input; Codex counts cached input inside it. |
| +func (s *Store) TaskSpend(ctx context.Context, person, id string) (out TaskSpend, err error) { |
| + out.Steps = map[string]Spend{} |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx} |
| + if _, err := t.loadTask(id); err != nil { |
| + return err |
| + } |
| + var rows []usageRecord |
| + if err := tx.Where("task_id = ?", id).Find(&rows).Error; err != nil { |
| + return err |
| + } |
| + for _, r := range rows { |
| + one := Spend{Partial: r.InputTokens == nil || r.OutputTokens == nil} |
| + in, cached, written := figure(r.InputTokens), figure(r.CachedInputTokens), figure(r.CacheWriteTokens) |
| + if r.Provider == "claude" { |
| + in += cached + written |
| + } |
| + one.Tokens, one.Cached = in+figure(r.OutputTokens), cached |
| + out.Total.add(one) |
| + if r.Role == "ask" { |
| + out.Questions.add(one) |
| + } else { |
| + step := out.Steps[r.StepID] |
| + step.add(one) |
| + out.Steps[r.StepID] = step |
| + } |
| + } |
| + out.Rows = len(rows) |
| + return nil |
| + }) |
| + return out, err |
| +} |
| + |
| +func figure(p *int64) int64 { |
| + if p == nil { |
| + return 0 |
| + } |
| + return *p |
| +} |
| + |
| // UsageToday sums the person's recorded tokens (input and output) per |
| // connection since midnight UTC. |
| func (s *Store) UsageToday(ctx context.Context, person string) (map[string]int64, error) { |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 9c2508bb..434bf820 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -579,6 +579,13 @@ var pageCopy = map[string]string{ |
| "work.specialist.checks": "Checks", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.specialist.review": "Review", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.round": "fix round %d", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.spend": "Used %s tokens (%s cached)", // COPY REVIEW REQUIRED |
| + "work.spend_uncached": "Used %s tokens", // COPY REVIEW REQUIRED |
| + "work.spend_at_least": "at least %s", // COPY REVIEW REQUIRED |
| + "work.spend_step": "%s: %s tokens (%s cached)", // COPY REVIEW REQUIRED |
| + "work.spend_step_uncached": "%s: %s tokens", // COPY REVIEW REQUIRED |
| + "work.spend_questions": "Questions", // COPY REVIEW REQUIRED |
| + "work.spend_steps": "Tokens each step used", // COPY REVIEW REQUIRED |
| "work.checks.passed": "Checks passed (%s)", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.checks.failed": "Checks failed (%s, exit %d)", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.checks.none": "No checks found", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index 452ef2b6..624e55dc 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -546,6 +546,7 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| [equipo-tl] [equipo-decision] { margin: var(--rst-sp-2) 0 0; } |
| /* Questions and notes beside the timeline. */ |
| [equipo-t-thread] { position: sticky; inset-block-start: var(--rst-sp-4); display: flex; flex-direction: column; min-inline-size: 0; } |
| +[equipo-spend] { list-style: none; margin: 0 0 var(--rst-sp-3); padding: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-xs); font-variant-numeric: tabular-nums; } |
| [equipo-t-thread] [equipo-feed] { margin: 0 0 var(--rst-sp-3); font-size: var(--rst-fs-sm); gap: var(--rst-sp-3); } |
| [equipo-t-thread] [equipo-message] { max-inline-size: 92%; } |
| [equipo-t-thread] #chat-composer { padding: 0; } |
diff --git a/internal/equipo/templates/work_task.html b/internal/equipo/templates/work_task.html| index 4123a317..e7da7331 100644 |
| --- a/internal/equipo/templates/work_task.html |
| +++ b/internal/equipo/templates/work_task.html |
| @@ -10,6 +10,7 @@ |
| </div> |
| {{template "track-full" .}} |
| <p equipo-t-summary data-summary>{{if .Live}}{{template "mark" ""}}{{end}}<span data-stage-line>{{.Summary}}</span></p> |
| +{{with .Spend}}<p equipo-quiet data-spend>{{.}}</p>{{end}} |
| {{with .Dup}}{{if not $.Thin.Task.Decision}}<p equipo-dup>{{icon "alert-triangle"}}<span>{{copy "work.dup"}} <a href="/tasks/{{.ID}}">{{.Title}}</a>{{if not $.Thin.Task.Mine}} {{printf (copy "work.dup_decides") $.Thin.Task.Creator.Name}}{{end}}</span></p>{{end}}{{end}} |
| {{with .Folded}}<div equipo-combined data-folded>{{icon "check-circle"}}<span>{{copy "work.combined_line"}} <a href="/tasks/{{.Into.ID}}">{{.Into.Title}}</a>.</span>{{if $.Thin.Task.Mine}}<form method="post" action="/tasks/{{$.Thin.Task.ID}}/uncombine"><input type="hidden" name="from" value="task"><button equipo-link type="submit" data-uncombine>{{copy "chat.card.undo"}}</button></form>{{end}}</div>{{end}} |
| {{range .Combined}}<div equipo-combined data-combined="{{.ID}}">{{icon "check-circle"}}<span>{{printf (copy "work.combined_here") .Title}} <a href="/tasks/{{.ID}}">{{copy "work.combined_open"}}</a></span>{{if $.Thin.Task.Mine}}<form method="post" action="/tasks/{{.ID}}/uncombine"><input type="hidden" name="from" value="task"><input type="hidden" name="task" value="{{$.Thin.Task.ID}}"><button equipo-link type="submit" data-uncombine>{{copy "chat.card.undo"}}</button></form>{{end}}</div>{{end}} |
| @@ -39,6 +40,7 @@ |
| </section> |
| {{$thread := $.Thin.Thread}}<section equipo-thread equipo-t-thread data-chat-stream data-task="{{.ID}}" data-thinking-set="{{$.ThinkingSet}}" data-thinking-words="{{$.ThinkingWords}}" data-cursor="{{$thread.Cursor}}" data-elapsed="{{copy "chat.elapsed"}}" data-thinking="{{copy "chat.activity.thinking"}}" data-ask-format="{{copy "work.ask.target"}}" data-ask-placeholder="{{copy "work.ask.placeholder"}}" data-name-engineering="{{copy "work.specialist.engineering"}}" data-name-review="{{copy "work.specialist.review"}}"> |
| <h2>{{copy "work.thread"}}</h2> |
| +<div data-work-region id="task-spend">{{with .StepSpend}}<ul equipo-spend aria-label="{{copy "work.spend_steps"}}" data-spend-steps>{{range .}}<li data-spend-step="{{.Step}}">{{.Line}}</li>{{end}}</ul>{{end}}</div> |
| <template equipo-own-template><li equipo-message="own" data-message=""><div equipo-message-meta><strong equipo-visually-hidden>{{$.Address}}</strong><time></time></div><div equipo-bubble><p equipo-message-body></p></div></li></template> |
| <template equipo-thinking-template><li equipo-message="incoming" equipo-thinking data-turn="" data-started="" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}<span data-who></span></strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-activity-line><span equipo-activity>{{copy "chat.activity.thinking"}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li></template> |
| <template equipo-ended-template><li equipo-system-note data-ended=""><p></p></li></template> |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 0f812abf..76effcf9 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -52,9 +52,12 @@ type taskLine struct { |
| Running, Stopped *wire.Step |
| // WaitsOther: a teammate's task waiting on their decision. |
| WaitsOther bool |
| - // Summary and Timeline are the task page's. |
| - Summary string |
| - Timeline []timelineItem |
| + // Summary and Timeline are the task page's; Spend what the task used |
| + // and StepSpend each step's part, for the specialist panel. |
| + Summary string |
| + Timeline []timelineItem |
| + Spend string |
| + StepSpend []spendLine |
| } |
| // stepLine is one step on the task page. |
| @@ -472,6 +475,10 @@ func (a *application) workTask(w http.ResponseWriter, r *http.Request) bool { |
| } |
| v := lines[0] |
| v.Summary, v.Timeline = summaryOf(t, v), timelineOf(t, v) |
| + // What it used; an unreadable sum shows nothing, never zero. |
| + if sp, err := a.store.Chat().TaskSpend(ctx, address, id); err == nil { |
| + v.Spend, v.StepSpend = spendOf(t, sp) |
| + } |
| data.Thin.Task, data.Title, data.RequestID = v, "nav.tasks", rand.Text() |
| data.Thin.Thread, data.ChatStream = threadOf(t, address, cursor), true |
| data.ThinkingSet, data.ThinkingWords = a.thinkingFor(ctx, address) |
diff --git a/internal/equipo/work_spend.go b/internal/equipo/work_spend.go| new file mode 100644 |
| index 00000000..9e03b3da |
| --- /dev/null |
| +++ b/internal/equipo/work_spend.go |
| @@ -0,0 +1,74 @@ |
| +package equipo |
| + |
| +import ( |
| + "fmt" |
| + "math" |
| + "strconv" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// spendLine is one step's usage on the task page. |
| +type spendLine struct { |
| + Step, Line string |
| +} |
| + |
| +// spendOf is what a task used, in words: the task's quiet line and, in |
| +// step order, one line per step that recorded usage (then the questions |
| +// asked about it). Nothing when no usage was recorded. |
| +func spendOf(t wire.Task, sp chat.TaskSpend) (string, []spendLine) { |
| + if sp.Rows == 0 { |
| + return "", nil |
| + } |
| + var lines []spendLine |
| + for _, s := range t.Steps { |
| + one, ok := sp.Steps[s.ID] |
| + if !ok { |
| + continue |
| + } |
| + name := specialistName(s.Specialist) |
| + if s.Round > 0 && s.Specialist == wire.SpecialistEngineering && !s.Rebase { |
| + name += ", " + fmt.Sprintf(copyText("work.round"), s.Round) |
| + } |
| + lines = append(lines, spendLine{Step: s.ID, Line: spendWords(one, name)}) |
| + } |
| + if sp.Questions != (chat.Spend{}) { |
| + lines = append(lines, spendLine{Step: "questions", Line: spendWords(sp.Questions, copyText("work.spend_questions"))}) |
| + } |
| + return spendWords(sp.Total, ""), lines |
| +} |
| + |
| +// spendWords is one sum in words: the task's line when name is empty, |
| +// a step's otherwise; "at least" when a row lacked a figure. |
| +func spendWords(s chat.Spend, name string) string { |
| + n := tokenCount(s.Tokens) |
| + if s.Partial { |
| + n = fmt.Sprintf(copyText("work.spend_at_least"), n) |
| + } |
| + switch { |
| + case name == "" && s.Cached > 0: |
| + return fmt.Sprintf(copyText("work.spend"), n, tokenCount(s.Cached)) |
| + case name == "": |
| + return fmt.Sprintf(copyText("work.spend_uncached"), n) |
| + case s.Cached > 0: |
| + return fmt.Sprintf(copyText("work.spend_step"), name, n, tokenCount(s.Cached)) |
| + } |
| + return fmt.Sprintf(copyText("work.spend_step_uncached"), name, n) |
| +} |
| + |
| +// tokenCount is a token figure as people read it: 840, 1.5k, 84k, 1.2M. |
| +func tokenCount(n int64) string { |
| + trim := func(v float64, unit string) string { |
| + return strconv.FormatFloat(math.Round(v*10)/10, 'f', -1, 64) + unit |
| + } |
| + switch { |
| + case n < 1000: |
| + return strconv.FormatInt(n, 10) |
| + case n < 10_000: |
| + return trim(float64(n)/1000, "k") |
| + case n < 999_500: |
| + return strconv.FormatInt(int64(math.Round(float64(n)/1000)), 10) + "k" |
| + } |
| + return trim(float64(n)/1e6, "M") |
| +} |
diff --git a/internal/equipo/work_spend_test.go b/internal/equipo/work_spend_test.go| new file mode 100644 |
| index 00000000..cde63876 |
| --- /dev/null |
| +++ b/internal/equipo/work_spend_test.go |
| @@ -0,0 +1,36 @@ |
| +package equipo |
| + |
| +import ( |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Token figures read as people say them, and a sum with a missing |
| +// figure says it is a lower bound, never a precise number. |
| +func TestSpendWords(t *testing.T) { |
| + for n, want := range map[int64]string{0: "0", 840: "840", 1000: "1k", 1500: "1.5k", 9960: "10k", 84_300: "84k", 999_499: "999k", 999_500: "1M", 1_240_000: "1.2M"} { |
| + if got := tokenCount(n); got != want { |
| + t.Fatalf("%d: %q, want %q", n, got, want) |
| + } |
| + } |
| + task := wire.Task{Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering}, {ID: "s2", Specialist: wire.SpecialistChecks}, {ID: "s3", Specialist: wire.SpecialistEngineering, Round: 1}}} |
| + sp := chat.TaskSpend{Rows: 3, Total: chat.Spend{Tokens: 50_000, Partial: true}, Steps: map[string]chat.Spend{"s1": {Tokens: 40_000, Cached: 30_000}, "s3": {Tokens: 9_000, Partial: true}}, Questions: chat.Spend{Tokens: 1_000}} |
| + total, lines := spendOf(task, sp) |
| + if total != "Used at least 50k tokens" { |
| + t.Fatalf("total %q", total) |
| + } |
| + want := []spendLine{{"s1", "Engineering: 40k tokens (30k cached)"}, {"s3", "Engineering, fix round 1: at least 9k tokens"}, {"questions", "Questions: 1k tokens"}} |
| + if len(lines) != len(want) { |
| + t.Fatalf("lines %+v", lines) |
| + } |
| + for i := range want { |
| + if lines[i] != want[i] { |
| + t.Fatalf("line %d %+v, want %+v", i, lines[i], want[i]) |
| + } |
| + } |
| + if total, lines := spendOf(task, chat.TaskSpend{}); total != "" || lines != nil { |
| + t.Fatalf("no rows: %q %+v", total, lines) |
| + } |
| +} |
diff --git a/internal/thintest/spend_pages_test.go b/internal/thintest/spend_pages_test.go| new file mode 100644 |
| index 00000000..f4af20f0 |
| --- /dev/null |
| +++ b/internal/thintest/spend_pages_test.go |
| @@ -0,0 +1,57 @@ |
| +package thintest |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +func tokens(n int64) *int64 { return &n } |
| + |
| +// TestPagesTaskSpend: the task page says quietly what the task used, |
| +// from its usage rows (Claude's cached input counted beside its input, |
| +// Codex's inside it), and the specialist panel has one line per step |
| +// that used any. A task with no rows says nothing, and a teammate who |
| +// can read the task sees the same. |
| +func TestPagesTaskSpend(t *testing.T) { |
| + r := newToolRig(t) |
| + owner := r.inst.Cookie() |
| + base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| + id := taskID(t, r.call("s1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Fix the README typo", "brief": "teh panes"})) |
| + if page := r.get(owner, "/tasks/"+id, 200); strings.Contains(page, "data-spend") { |
| + t.Fatalf("a task with no usage shows spend: %s", page) |
| + } |
| + r.call("s2", wire.ToolStartTask, map[string]string{"task": id, "brief": "Fix it."}) |
| + _, body := r.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + r.step("s-run", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, Family: "claude", Account: "claude-a"}) |
| + eng := []wire.Usage{{Provider: "claude", Connection: "claude-a", Model: "claude-opus-5-5", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true, InputTokens: tokens(2000), CachedInputTokens: tokens(60000), CacheWriteTokens: tokens(1000), OutputTokens: tokens(1000), Turns: tokens(12)}} |
| + r.step("s-done", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Pushed: true, Termination: true, Family: "claude", Account: "claude-a", Usage: eng}) |
| + c := r.dispatched(wire.SpecialistChecks, base, cand, 0) |
| + r.checks("s-c", c, wire.ChecksPassed, exit(0), "", "ok\n") |
| + rv := r.dispatched(wire.SpecialistReview, base, cand, 0) |
| + review := []wire.Usage{{Provider: "codex", Connection: "codex-b", Model: "gpt-6-astra", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true, InputTokens: tokens(19000), CachedInputTokens: tokens(1000), OutputTokens: tokens(1000), Turns: tokens(3)}} |
| + r.step("s-r", wire.StepReport{TaskID: id, StepID: rv.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Termination: true, Family: "gpt", Account: "codex-b", Verdict: wire.VerdictChanges, ReviewLabel: wire.ReviewOtherFamily, Findings: []wire.Finding{}, Summary: "One more.", Usage: review}) |
| + r.wait("fix round", func(c *Conversation) bool { return c.Tasks[id].FixRounds == 1 }) |
| + for _, who := range []string{"owner", "member"} { |
| + cookie := owner |
| + if who == "member" { |
| + cookie = r.memberCookie() |
| + } |
| + page := r.get(cookie, "/tasks/"+id, 200) |
| + for _, want := range []string{ |
| + `<p equipo-quiet data-spend>Used 84k tokens (61k cached)</p>`, |
| + `<li data-spend-step="` + d.StepID + `">Engineering: 64k tokens (60k cached)</li>`, |
| + `<li data-spend-step="` + rv.StepID + `">Review: 20k tokens (1k cached)</li>`, |
| + } { |
| + if !strings.Contains(page, want) { |
| + t.Fatalf("%s's task page lacks %q:\n%s", who, want, page) |
| + } |
| + } |
| + // Checks used no model and the fix round has not reported: no line. |
| + if strings.Count(page, "data-spend-step=") != 2 { |
| + t.Fatalf("%s: step lines %d", who, strings.Count(page, "data-spend-step=")) |
| + } |
| + } |
| +} |