Skip to content

Commit a53e01a

Browse files
committed
docs: align TUI context tokens with session totals (anomalyco#3322)
1 parent 4086a9a commit a53e01a

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/routes/session/header.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ export function Header() {
5050
const context = createMemo(() => {
5151
const last = messages().findLast((x) => x.role === "assistant" && x.tokens.output > 0) as AssistantMessage
5252
if (!last) return
53-
const total =
54-
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
53+
const total = messages().reduce(
54+
(sum, x) =>
55+
x.role === "assistant"
56+
? sum + x.tokens.input + x.tokens.output + x.tokens.reasoning + x.tokens.cache.read + x.tokens.cache.write
57+
: sum,
58+
0,
59+
)
5560
const model = sync.data.provider.find((x) => x.id === last.providerID)?.models[last.modelID]
5661
let result = total.toLocaleString()
5762
if (model?.limit.context) {

‎packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
5151
const context = createMemo(() => {
5252
const last = messages().findLast((x) => x.role === "assistant" && x.tokens.output > 0) as AssistantMessage
5353
if (!last) return
54-
const total =
55-
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
54+
const total = messages().reduce(
55+
(sum, x) =>
56+
x.role === "assistant"
57+
? sum + x.tokens.input + x.tokens.output + x.tokens.reasoning + x.tokens.cache.read + x.tokens.cache.write
58+
: sum,
59+
0,
60+
)
5661
const model = sync.data.provider.find((x) => x.id === last.providerID)?.models[last.modelID]
5762
return {
5863
tokens: total.toLocaleString(),

0 commit comments

Comments
 (0)