feat(tui): simplify mini footer model labels

This commit is contained in:
vimtor 2026-10-29 12:50:34 +00:00
parent 46c38271e2
commit 4d8e443bac
6 changed files with 68 additions and 23 deletions

View file

@ -51,6 +51,8 @@ export function runProviders(providers: CurrentProvider[], models: CurrentModel[
grouped.set(provider.id, {
id: provider.id,
name: provider.name,
canonical: provider.canonical,
integrationID: provider.integrationID,
models: {},
})
}

View file

@ -72,6 +72,8 @@ type RunProviderModel = {
export type RunProvider = {
id: string
name: string
canonical?: string
integrationID?: string
models: Record<string, RunProviderModel>
}

View file

@ -9,12 +9,26 @@
import { createSession, sessionVariant, type RunSession, type SessionMessages } from "./session.shared"
import type { RunInput, RunProvider } from "./types"
import { cycleModelVariant, normalizeModelVariant } from "../model-preference"
import { modelLabelKey, modelLabels, modelName, modelProviderName, type ModelLabel } from "../util/model-label"
export function modelInfo(providers: RunProvider[] | undefined, model: NonNullable<RunInput["model"]>) {
const provider = providers?.find((item) => item.id === model.providerID)
// The same short names as the prompt: no provider for native Console models, and `OpenCode / <Provider>` only for a
// managed provider that is also connected directly. Without a catalog, the raw IDs.
export function modelInfo(providers: RunProvider[] | undefined, model: NonNullable<RunInput["model"]>): ModelLabel {
if (!providers) return { provider: model.providerID, model: model.modelID }
const models = providers.flatMap((provider) =>
Object.entries(provider.models).map(([id, info]) => ({
providerID: provider.id,
id,
name: info.name ?? id,
status: info.status,
})),
)
const label = modelLabels(providers, models).get(modelLabelKey(model.providerID, model.modelID))
if (label) return label
const name = providers.find((item) => item.id === model.providerID)?.models[model.modelID]?.name
return {
provider: provider?.name ?? model.providerID,
model: provider?.models[model.modelID]?.name ?? model.modelID,
provider: modelProviderName(model.providerID, providers),
model: name ? modelName(name) : model.modelID,
}
}
@ -25,7 +39,8 @@ export function formatModelLabel(
): string {
const names = modelInfo(providers, model)
const label = variant ? ` · ${variant}` : ""
return `${names.model} · ${names.provider}${label}`
const name = names.provider ? `${names.model} · ${names.provider}` : names.model
return `${name}${label}`
}
export function cycleVariant(current: string | undefined, variants: string[]): string | undefined {

View file

@ -124,7 +124,7 @@ test.each([false, true])(
const model = width === 112 ? "GPT-5.6 Sol (50% Off) [max]" : mono ? "GPT-5.6... [max]" : "GPT-5.6\u2026 [max]"
expect(row).toBe(
(width === 112
? ["Build", model, "14.1K (1%)", "Anomaly / OpenCode", "$0.04", "ctrl+p menu"]
? ["Build", model, "14.1K (1%)", "$0.04", "ctrl+p menu"]
: width === 40
? ["Build", model, "1% ctx"]
: ["Build", model]

View file

@ -110,8 +110,8 @@ function model(input: {
function provider() {
return {
id: "opencode",
name: "opencode",
id: "deepseek",
name: "deepseek",
models: {
"gpt-5": model({ id: "gpt-5", name: "GPT-5", variants: { high: {}, minimal: {} } }),
"gpt-free": model({ id: "gpt-free", name: "GPT Free", cost: 0 }),
@ -567,13 +567,13 @@ test("direct footer leads with the active agent and default model", async () =>
test("direct footer describes commands and context and shows the model provider", async () => {
const app = await renderFooter({
providers: [provider()],
currentModel: { providerID: "opencode", modelID: "gpt-5" },
currentModel: { providerID: "deepseek", modelID: "gpt-5" },
state: { first: true },
})
try {
await app.renderOnce()
expect(app.captureCharFrame()).toContain("┃ Ask anything, / for commands, @ for context…")
expect(app.captureCharFrame()).toContain("Build · GPT-5 · opencode · ctrl+p menu")
expect(app.captureCharFrame()).toContain("Build · GPT-5 · deepseek · ctrl+p menu")
} finally {
app.cleanup()
}
@ -584,7 +584,7 @@ test.each([56, 160])("exit confirmation replaces routine footer details at %i co
width,
currentAgent: "Build",
providers: [provider()],
currentModel: { providerID: "opencode", modelID: "gpt-5" },
currentModel: { providerID: "deepseek", modelID: "gpt-5" },
currentVariant: "high",
state: { usage: { tokens: 12000, percent: 10 } },
queuedPrompts: [{ messageID: "queued", prompt: { text: "later", parts: [] }, delivery: "queue" }],
@ -598,7 +598,7 @@ test.each([56, 160])("exit confirmation replaces routine footer details at %i co
await app.renderOnce()
const frame = app.captureCharFrame()
expect(frame).toContain("Press ctrl+c again to exit")
for (const text of ["Build", "GPT-5", "opencode", "high", "12.0K", "queued", "menu"])
for (const text of ["Build", "GPT-5", "deepseek", "high", "12.0K", "queued", "menu"])
expect(frame).not.toContain(text)
app.setState((state) => ({ ...state, exit: 0 }))
await app.renderOnce()
@ -1742,7 +1742,7 @@ test("direct footer counts queued and steering work while running", async () =>
const app = await renderFooter({
width: 160,
state: { phase: "running" },
currentModel: { providerID: "opencode", modelID: "a-model-name-long-enough-to-force-responsive-truncation" },
currentModel: { providerID: "deepseek", modelID: "a-model-name-long-enough-to-force-responsive-truncation" },
subagents: {
tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
details: {},
@ -1761,7 +1761,7 @@ test("direct footer counts queued and steering work while running", async () =>
const transparent = RGBA.fromValues(0, 0, 0, 0).toInts()
const statusline = footerStatusline(app.renderer.root)
expect(frame).toContain("esc stop · ctrl+x q 2 pending · ↓ 1 subagent · ctrl+b background · Build")
expect(frame).toMatch(/opencode · ctrl\+p menu *$/m)
expect(frame).toMatch(/deepseek · ctrl\+p menu *$/m)
expect(frame).not.toContain("1 agent")
expect(statusline.backgroundColor.toInts()).toEqual(transparent)
} finally {
@ -1803,7 +1803,7 @@ test.each([16, 20, 24, 32])("status takeovers retain complete instructions at %i
mono,
currentVariant: "high",
providers: [provider()],
currentModel: { providerID: "opencode", modelID: "gpt-5" },
currentModel: { providerID: "deepseek", modelID: "gpt-5" },
state: { exit: 1, usage: { tokens: 12000, percent: 10 } },
queuedPrompts: [{ messageID: "queued", prompt: { text: "later", parts: [] }, delivery: "queue" }],
})
@ -1829,7 +1829,7 @@ test.each([16, 20, 24, 32])("status takeovers retain complete instructions at %i
expect(text).toMatch(state.action ? /exit/ : /stop|interrupt/)
expect(statusline.height).toBe(1)
}
for (const value of ["Build", "GPT-5", "opencode", "high", "12.0K", "queued", "menu", "..."])
for (const value of ["Build", "GPT-5", "deepseek", "high", "12.0K", "queued", "menu", "..."])
expect(text).not.toContain(value)
expect(!!statusline.findDescendantById("mini-work-spinner")).toBe(state.phase === "running")
}
@ -1843,7 +1843,7 @@ test.each([
{ field: "agent", text: "esc stop · GPT-5 [high]" },
{
field: "model",
text: "esc stop · Build · long-model-long-model-lo… [high] · opencode · ctrl+p menu",
text: "esc stop · Build · long-model-long-model-lo… [high] · deepseek · ctrl+p menu",
},
{ field: "provider", text: "esc stop · Build · GPT-5 [high]" },
])("running footer abbreviates only the model and stops at an oversized $field", async ({ field, text }) => {
@ -1852,11 +1852,11 @@ test.each([
width: 80,
currentAgent: field === "agent" ? long : "Build",
currentVariant: "high",
currentModel: { providerID: "opencode", modelID: "gpt-5" },
currentModel: { providerID: "deepseek", modelID: "gpt-5" },
providers: [
{
...provider(),
name: field === "provider" ? long : "opencode",
name: field === "provider" ? long : "deepseek",
models: { "gpt-5": model({ id: "gpt-5", name: field === "model" ? long : "GPT-5" }) },
},
],
@ -2021,7 +2021,7 @@ test("identity and context precede the provider and a non-fitting provider block
const app = await renderFooter({
width: 56,
providers: [{ ...provider(), name: "Long provider display name" }],
currentModel: { providerID: "opencode", modelID: "gpt-5" },
currentModel: { providerID: "deepseek", modelID: "gpt-5" },
currentVariant: "high",
state: { usage: { tokens: 12000, percent: 10 } },
})
@ -2376,7 +2376,7 @@ test("direct model panel keeps native V2 light search and options readable on a
provider(),
{ id: "openai", name: "OpenAI", models: { "gpt-5": model({ id: "gpt-5", name: "GPT-5" }) } },
])
const [current] = createSignal<RunInput["model"]>({ providerID: "opencode", modelID: "gpt-5" })
const [current] = createSignal<RunInput["model"]>({ providerID: "deepseek", modelID: "gpt-5" })
const app = await testRender(
() => (
@ -2403,7 +2403,7 @@ test("direct model panel keeps native V2 light search and options readable on a
expect(frame).toContain("Select model")
expect(frame).toContain("Search")
expect(frame).toContain("opencode")
expect(frame).toContain("deepseek")
expect(frame).toContain("GPT-5")
expect(frame).toContain("current")
expect(frame).toContain("GPT Free")
@ -2427,7 +2427,7 @@ test("direct model panel keeps native V2 light search and options readable on a
const search = app.captureCharFrame()
expect(search.match(/GPT-5/g)).toHaveLength(2)
expect(search).toContain("opencode")
expect(search).toContain("deepseek")
expect(search).toContain("OpenAI")
const spans = app.captureSpans().lines.flatMap((line) => line.spans)
const query = spans.find((span) => span.text.includes("gpt-5"))!

View file

@ -43,6 +43,32 @@ describe("run variant shared", () => {
expect(formatModelLabel(model, "high", providers)).toBe("GPT-5 · OpenAI · high")
})
test("formats model labels like the prompt", () => {
const sol = { providerID: "console-openai", modelID: "gpt-6.1-sol" }
const native: RunProvider = {
id: "opencode",
name: "Anomaly / OpenCode",
integrationID: "opencode",
models: { "gpt-6.1-sol": { name: "GPT-6.1 Sol (latest)" } },
}
const managed: RunProvider = {
id: "console-openai",
name: "Anomaly / OpenAI",
integrationID: "opencode",
canonical: "openai",
models: { "gpt-6.1-sol": { name: "GPT-6.1 Sol" } },
}
expect(formatModelLabel({ providerID: "opencode", modelID: "gpt-6.1-sol" }, "high", [native])).toBe(
"GPT-6.1 Sol · high",
)
expect(formatModelLabel(sol, undefined, [native, managed])).toBe("GPT-6.1 Sol · OpenAI")
expect(formatModelLabel(sol, undefined, [native, managed, ...providers])).toBe("GPT-6.1 Sol · OpenCode / OpenAI")
expect(formatModelLabel({ providerID: "openai", modelID: "missing" }, undefined, providers)).toBe(
"missing · OpenAI",
)
})
test("picks the latest matching variant from session history", () => {
const session: RunSession = {
first: false,