Skip to content

Commit 9fd3a17

Browse files
committed
fix(tui): use current model for context-limit display after switch
Fixes anomalyco#35072
1 parent e9f5d34 commit 9fd3a17

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎packages/tui/src/component/prompt/index.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ export function Prompt(props: PromptProps) {
269269
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
270270
if (tokens <= 0) return
271271

272-
const model = sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
272+
// Use the currently selected model for the context-limit denominator so it
273+
// updates immediately after a model switch, falling back to the last
274+
// assistant message's model when nothing is selected yet.
275+
const selected = local.model.current()
276+
const model =
277+
(selected && sync.data.provider.find((item) => item.id === selected.providerID)?.models[selected.modelID]) ??
278+
sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
273279
const pct = model?.limit.context ? `${Math.round((tokens / model.limit.context) * 100)}%` : undefined
274280
const cost = session?.cost ?? 0
275281
return {

‎packages/tui/src/feature-plugins/sidebar/context.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AssistantMessage } from "@opencode-ai/sdk/v2"
22
import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
33
import type { BuiltinTuiPlugin } from "../builtins"
44
import { createMemo } from "solid-js"
5+
import { useLocal } from "../../context/local"
56

67
const id = "internal:sidebar-context"
78

@@ -12,6 +13,7 @@ const money = new Intl.NumberFormat("en-US", {
1213

1314
function View(props: { api: TuiPluginApi; session_id: string }) {
1415
const theme = () => props.api.theme.current
16+
const local = useLocal()
1517
const msg = createMemo(() => props.api.state.session.messages(props.session_id))
1618
const session = createMemo(() => props.api.state.session.get(props.session_id))
1719
const cost = createMemo(() => session()?.cost ?? 0)
@@ -27,7 +29,16 @@ function View(props: { api: TuiPluginApi; session_id: string }) {
2729

2830
const tokens =
2931
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
30-
const model = props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
32+
// Use the currently selected model for the context-limit denominator so it
33+
// updates immediately after a model switch, falling back to the last
34+
// assistant message's model when nothing is selected yet. The global model
35+
// picker only applies to the top-level session, so for subagent sessions
36+
// (which run their own agent's model and can be viewed via the sidebar) use
37+
// the session's own last-message model instead.
38+
const selected = session()?.parentID ? undefined : local.model.current()
39+
const model =
40+
(selected && props.api.state.provider.find((item) => item.id === selected.providerID)?.models[selected.modelID]) ??
41+
props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
3142
return {
3243
tokens,
3344
percent: model?.limit.context ? Math.round((tokens / model.limit.context) * 100) : null,

0 commit comments

Comments
 (0)