tui: resolve default mini footer agent (#38315)

This commit is contained in:
Simon Klee 2026-07-22 15:42:12 +02:00 committed by GitHub
parent e12ec8681b
commit 5841b04fe7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 7 deletions

View file

@ -102,6 +102,11 @@ type RunFooterOptions = {
subscribeThemeSignal: (listener: () => void) => () => void
}
export function resolveRunAgent(agents: RunAgent[], current: string | undefined) {
const selectable = agents.filter((agent) => agent.mode !== "subagent" && !agent.hidden)
return selectable.find((agent) => agent.id === current) ?? selectable.at(0)
}
const PERMISSION_ROWS = 12
const FORM_ROWS = 14
const SUBAGENT_ROWS = RUN_SUBAGENT_PANEL_ROWS
@ -252,13 +257,15 @@ export class RunFooter implements FooterApi {
const [providers, setProviders] = createSignal<RunProvider[] | undefined>()
this.providers = providers
this.setProviders = setProviders
const [currentAgentID, setCurrentAgentID] = createSignal(options.agent)
this.currentAgentID = currentAgentID
const [selectedAgentID, setCurrentAgentID] = createSignal(options.agent)
const currentAgent = () => resolveRunAgent(this.agents(), selectedAgentID())
this.currentAgentID = () => currentAgent()?.id ?? selectedAgentID()
this.setCurrentAgentID = setCurrentAgentID
this.currentAgent = () => {
const agent = currentAgentID()
if (!agent) return "Default"
return this.agents().find((item) => item.id === agent)?.name ?? Locale.titlecase(agent)
const agent = currentAgent()
if (agent) return agent.name
const selected = selectedAgentID()
return selected ? Locale.titlecase(selected) : "Default"
}
const [currentModel, setCurrentModel] = createSignal<RunInput["model"]>(options.model)
this.currentModel = currentModel

View file

@ -1,6 +1,6 @@
import { expect, test } from "bun:test"
import { coalesceProgressCommit } from "../../src/mini/footer"
import type { StreamCommit } from "../../src/mini/types"
import { coalesceProgressCommit, resolveRunAgent } from "../../src/mini/footer"
import type { RunAgent, StreamCommit } from "../../src/mini/types"
function progress(input: Partial<StreamCommit> = {}): StreamCommit {
return {
@ -23,3 +23,16 @@ test("coalesces progress only within the same message and tool state", () => {
progress({ text: "onetwo", directory: "/latest" }),
)
})
test("resolves the first selectable agent when none is selected", () => {
const agents: RunAgent[] = [
{ id: "task", name: "Task", mode: "subagent", hidden: false },
{ id: "secret", name: "Secret", mode: "primary", hidden: true },
{ id: "build", name: "Build", mode: "primary", hidden: false },
{ id: "plan", name: "Plan", mode: "primary", hidden: false },
]
expect(resolveRunAgent(agents, undefined)?.id).toBe("build")
expect(resolveRunAgent(agents, "plan")?.id).toBe("plan")
expect(resolveRunAgent(agents, "missing")?.id).toBe("build")
})