Skip to content

Commit d558873

Browse files
committed
core: simplify defaultAgent to single fallback path
Previously used 3-step fallback (primary -> visible -> build). Now uses single check: find primary+visible OR hardcoded 'build'. Same behavior, cleaner implementation. Signed-off-by: assagman <[email protected]>
1 parent 9dc3746 commit d558873

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

packages/opencode/src/agent/agent.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,8 @@ export namespace Agent {
256256

257257
export async function defaultAgent() {
258258
const agents = await list()
259-
const primary = agents.find((a) => a.mode !== "subagent" && a.hidden !== true)
260-
if (primary) return primary.name
261-
262-
const visible = agents.find((a) => a.hidden !== true)
263-
if (visible) return visible.name
264-
265-
return "build"
259+
const primaryVisible = agents.find((a) => a.mode !== "subagent" && a.hidden !== true)
260+
return primaryVisible?.name || "build"
266261
}
267262

268263
export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {

packages/opencode/test/agent/agent.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ test("explicit Truncate.DIR deny is respected", async () => {
513513
})
514514
})
515515

516-
// Tests for Agent.defaultAgent()
517-
518516
test("defaultAgent returns build when no default_agent config", async () => {
519517
await using tmp = await tmpdir()
520518
await Instance.provide({
@@ -627,3 +625,22 @@ test("defaultAgent returns plan when build is disabled and default_agent not set
627625
},
628626
})
629627
})
628+
629+
test("defaultAgent returns first primary-capable agent when all natives are disabled", async () => {
630+
await using tmp = await tmpdir({
631+
config: {
632+
agent: {
633+
build: { disable: true },
634+
plan: { disable: true },
635+
},
636+
},
637+
})
638+
await Instance.provide({
639+
directory: tmp.path,
640+
fn: async () => {
641+
const agent = await Agent.defaultAgent()
642+
// build and plan are disabled, so it should return general
643+
expect(agent).toBe("build")
644+
},
645+
})
646+
})

0 commit comments

Comments
 (0)