fix(agent): default agent selection in acp and headless mode (#8678)

Signed-off-by: assagman <ahmetsercansagman@gmail.com>
This commit is contained in:
Sercan Sagman
2026-01-16 02:09:19 +03:00
committed by GitHub
parent 7443b99295
commit 81983d4a2e
3 changed files with 141 additions and 1 deletions

View File

@@ -731,6 +731,9 @@ export namespace ACP {
const defaultAgentName = await AgentModule.defaultAgent()
const currentModeId = availableModes.find((m) => m.name === defaultAgentName)?.id ?? availableModes[0].id
// Persist the default mode so prompt() uses it immediately
this.sessionManager.setMode(sessionId, currentModeId)
const mcpServers: Record<string, Config.Mcp> = {}
for (const server of params.mcpServers) {
if ("type" in server) {

View File

@@ -255,7 +255,20 @@ export namespace Agent {
}
export async function defaultAgent() {
return state().then((x) => Object.keys(x)[0])
const cfg = await Config.get()
const agents = await state()
if (cfg.default_agent) {
const agent = agents[cfg.default_agent]
if (!agent) throw new Error(`default agent "${cfg.default_agent}" not found`)
if (agent.mode === "subagent") throw new Error(`default agent "${cfg.default_agent}" is a subagent`)
if (agent.hidden === true) throw new Error(`default agent "${cfg.default_agent}" is hidden`)
return agent.name
}
const primaryVisible = Object.values(agents).find((a) => a.mode !== "subagent" && a.hidden !== true)
if (!primaryVisible) throw new Error("no primary visible agent found")
return primaryVisible.name
}
export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {