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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 59903fa
2 earlier comments · 1 event
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_usdrecords as the per-answer lines, and a finished stream fills it in without a reload. The newconversationTotalandtotalTextare insrc/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
saytool already points agents toGET /api/v1/conversation/turnsfor reading answers, so that route now returnstotalUsdand acostUsdon each agent turn. Both arenullwhen unknown. I did not add a tool or touch the MCP tool docs, so the size ceilings are unchanged. - Terminal:
forge talkprints the same "Spent …" line. - Test:
test/talk-cost.test.tscovers a conversation with a known cost (page, header, API) and one with an unknown cost (nothing shown,null). - Docs:
docs/features/talk.mddescribes 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 usestoFixed(2)throughout, so the two differ only for spends under a cent. I left that as is. - Script size:
talk_client.tswas one byte over the page's script cap intest/talk-page.test.tsafter 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.
I merged main into this branch and pushed it. The only conflict was in src/web/pages/talk.ts, in the imports.
- Resolution:
mainhad added theconversationMarkdownimport and this branch had addedconversationTotalandtotalTextto the cost import. I kept both, so nothing else in the file changed. - Checks:
bun x tsc --noEmitis clean.bun scripts/gate.ts --fixand the fast test selection both ran, but the output was cut off, so I did not confirm the gate result.scripts/fast.tsreported the diff as too broad to name tests, so I ran five talk and conversation test files by hand. They aretalk-cost,talk-page,conversation-download,conversation-talkandtalk-conversations, and all 115 tests pass. I did not run the full suite, since the forge runs it on the 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.
- Tests (required): the terminal's new
Spent ...line and the stream'sdoneevent fieldtotalare untested. Add a test for each. Each should fail if its line is removed. The existing test also never covers a run whosecost_usdis 0 or NULL next to a costed run. Add that case, since the SQL filtercost_usd > 0is what keeps$0from showing. - Design principle 1: the page now draws two muted
talk-contextlines 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 reusetalk-contextfor a different fact. - Clean:
talk_client.tsusest.hidden = 0and drops the semicolon. Uset.hidden = falseand 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. - 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 talkprints the total.
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 intest/conversation-talk.test.ts. The stream'sdone.totalis asserted in the existing stream test intest/talk-page.test.ts. A new case intest/talk-cost.test.tsputs acost_usd = 0run 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_usdcolumn is NOT NULL, so a NULL run can't exist. I tested0only, which is what thecost_usd > 0filter guards against. - Design: I chose your second option. The total now has its own class,
.talk-total, which shares the.talk-contextstyling in the stylesheet.docs/design/areas/talk.mdnames it. - Client:
talk_client.tsnow hast.hidden = false;with the semicolon. The page script cap did not need raising. - Docs:
docs/features/talk.mdnow says thatforge talkprints the total and that the MCP read is the turns route.
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.
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/talklook is not checked.What changed
conversation_run.cost_usdrecords as the per-answer lines, and a finished stream fills it in without a reload. The newconversationTotalandtotalTextare insrc/core/conversation_cost.ts.$0.saytool already points agents toGET /api/v1/conversation/turnsfor reading answers, so that route now returnstotalUsdand acostUsdon each agent turn. Both arenullwhen unknown. I did not add a tool or touch the MCP tool docs, so the size ceilings are unchanged.forge talkprints the same "Spent …" line.test/talk-cost.test.tscovers a conversation with a known cost (page, header, API) and one with an unknown cost (nothing shown,null).docs/features/talk.mddescribes the new line and fields.What to look at
dollars()helper, which shows tenths of a cent below one cent. The wallet page usestoFixed(2)throughout, so the two differ only for spends under a cent. I left that as is.talk_client.tswas one byte over the page's script cap intest/talk-page.test.tsafter my change. I trimmed the script rather than raise the cap.How to try it: open
/talkon the preview in a conversation that has a run with a cost, or callGET /api/v1/conversation/turns.Closes #13429