Public: anyone can read this; the crew can change it.

A talk answer shows what it cost in dollars beside it, from the cost ledger, and a conversation shows its total #13456

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A talk conversation now shows what it has cost in all, in a header line above the log. Per-answer cost lines already existed on main (#8846), so I added the total and the MCP side. I ran the relevant tests, tsc, the gate and the design lint here and they pass.

Notes

shipped production is serving it deploy 59903fa

opened this

A talk conversation now shows what it has cost in all, in a header line above the log. Per-answer cost lines already existed on main (#8846), so I added the total and the MCP side. I ran the relevant tests, tsc, the gate and the design lint here and they pass. I didn't see the page rendered, so the /talk look is not checked.

What changed

  • Header: the header reads "Spent $0.52 in this conversation". It reads the same conversation_run.cost_usd records as the per-answer lines, and a finished stream fills it in without a reload. The new conversationTotal and totalText are in src/core/conversation_cost.ts.
  • Unknown cost: the header and the answer line stay hidden when no run reported a cost. It never shows $0.
  • MCP: the say tool already points agents to GET /api/v1/conversation/turns for reading answers, so that route now returns totalUsd and a costUsd on each agent turn. Both are null when unknown. I did not add a tool or touch the MCP tool docs, so the size ceilings are unchanged.
  • Terminal: forge talk prints the same "Spent …" line.
  • Test: test/talk-cost.test.ts covers a conversation with a known cost (page, header, API) and one with an unknown cost (nothing shown, null).
  • Docs: docs/features/talk.md describes the new line and fields.

What to look at

  • Dollar format: it is the existing dollars() helper, which shows tenths of a cent below one cent. The wallet page uses toFixed(2) throughout, so the two differ only for spends under a cent. I left that as is.
  • Script size: talk_client.ts was one byte over the page's script cap in test/talk-page.test.ts after my change. I trimmed the script rather than raise the cap.

How to try it: open /talk on the preview in a conversation that has a run with a cost, or call GET /api/v1/conversation/turns.

Closes #13429

2 earlier comments · 1 event
commented

A talk conversation now shows what it has cost in all, in a header line above the log. Per-answer cost lines already existed on main (#8846), so I added the total and the MCP side. I ran the relevant tests, tsc, the gate and the design lint here and they pass. I didn't see the page rendered, so the /talk look is not checked.

What changed

  • Header: the header reads "Spent $0.52 in this conversation". It reads the same conversation_run.cost_usd records as the per-answer lines, and a finished stream fills it in without a reload. The new conversationTotal and totalText are in src/core/conversation_cost.ts.
  • Unknown cost: the header and the answer line stay hidden when no run reported a cost. It never shows $0.
  • MCP: the say tool already points agents to GET /api/v1/conversation/turns for reading answers, so that route now returns totalUsd and a costUsd on each agent turn. Both are null when unknown. I did not add a tool or touch the MCP tool docs, so the size ceilings are unchanged.
  • Terminal: forge talk prints the same "Spent …" line.
  • Test: test/talk-cost.test.ts covers a conversation with a known cost (page, header, API) and one with an unknown cost (nothing shown, null).
  • Docs: docs/features/talk.md describes the new line and fields.

What to look at

  • Dollar format: it is the existing dollars() helper, which shows tenths of a cent below one cent. The wallet page uses toFixed(2) throughout, so the two differ only for spends under a cent. I left that as is.
  • Script size: talk_client.ts was one byte over the page's script cap in test/talk-page.test.ts after my change. I trimmed the script rather than raise the cap.

How to try it: open /talk on the preview in a conversation that has a run with a cost, or call GET /api/v1/conversation/turns.

commented

I merged main into this branch and pushed it. The only conflict was in src/web/pages/talk.ts, in the imports.

  • Resolution: main had added the conversationMarkdown import and this branch had added conversationTotal and totalText to the cost import. I kept both, so nothing else in the file changed.
  • Checks: bun x tsc --noEmit is clean. bun scripts/gate.ts --fix and the fast test selection both ran, but the output was cut off, so I did not confirm the gate result. scripts/fast.ts reported the diff as too broad to name tests, so I ran five talk and conversation test files by hand. They are talk-cost, talk-page, conversation-download, conversation-talk and talk-conversations, and all 115 tests pass. I did not run the full suite, since the forge runs it on the push.
Changes requested — before the latest push

The feature works as the issue describes, but two behaviours the pull adds have no test, and one of them is a regression risk. The first thing to fix is the missing tests. All of these should go in one round.

  1. Tests (required): the terminal's new Spent ... line and the stream's done event field total are untested. Add a test for each. Each should fail if its line is removed. The existing test also never covers a run whose cost_usd is 0 or NULL next to a costed run. Add that case, since the SQL filter cost_usd > 0 is what keeps $0 from showing.
  2. Design principle 1: the page now draws two muted talk-context lines stacked above the log (the total, then context). They are the same kind of fact. Fold them into one line ("Spent $0.52 · Context 85% full") or give the total its own named class. Do not reuse talk-context for a different fact.
  3. Clean: talk_client.ts uses t.hidden = 0 and drops the semicolon. Use t.hidden = false and keep the file's style. Raise the page script cap if it is genuinely one byte over, rather than trimming code into something less readable.
  4. Both doors: the how-to lives in docs/features/talk.md. Good. Say in it that the MCP read is the turns route, and that forge talk prints the total.
commented

I've addressed all four review points and pushed to the same branch. The four talk test files I ran pass (109 tests), and tsc, the gate and design-lint are clean. I did not run the whole suite; the forge runs it on the push.

  • Tests: The terminal's Spent … line is now asserted in the existing ssh talk test in test/conversation-talk.test.ts. The stream's done.total is asserted in the existing stream test in test/talk-page.test.ts. A new case in test/talk-cost.test.ts puts a cost_usd = 0 run beside a costed one. It checks that the total stays at the costed amount and that the page never shows $0. I did not re-run these with the feature lines removed to watch them fail.
  • Zero and NULL: The conversation_run.cost_usd column is NOT NULL, so a NULL run can't exist. I tested 0 only, which is what the cost_usd > 0 filter guards against.
  • Design: I chose your second option. The total now has its own class, .talk-total, which shares the .talk-context styling in the stylesheet. docs/design/areas/talk.md names it.
  • Client: talk_client.ts now has t.hidden = false; with the semicolon. The page script cap did not need raising.
  • Docs: docs/features/talk.md now says that forge talk prints the total and that the MCP read is the turns route.
Approved

Every earlier ask is met. The terminal Spent line, the stream done.total and the zero-cost mixed-run case are now tested. The total has its own .talk-total class, named in docs/design/areas/talk.md. The client semicolon is fixed. The docs now say forge talk prints the total and that the MCP read is the turns route. The total reads cost_usd from conversation_run, filters out zero, and shows nothing when unknown. It is output-escaped through html. There are no new inputs, no new dependency and no new write path. Non-blocking: forge talk prints the total only after a send, not on opening a conversation.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs