Skip to content

Commit 5d98975

Browse files
committed
feat(opencode): add order field to agent config for explicit list sorting
Adds an optional order field to Agent.Info and ConfigAgent.Info schemas so users and plugins can control agent display order. Sort precedence: order (asc), default_agent (desc), name (asc).
1 parent 8afb625 commit 5d98975

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

packages/opencode/src/agent/agent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const Info = z
4545
prompt: z.string().optional(),
4646
options: z.record(z.string(), z.any()),
4747
steps: z.number().int().positive().optional(),
48+
order: z.number().int().optional(),
4849
})
4950
.meta({
5051
ref: "Agent",
@@ -258,6 +259,7 @@ export const layer = Layer.effect(
258259
item.hidden = value.hidden ?? item.hidden
259260
item.name = value.name ?? item.name
260261
item.steps = value.steps ?? item.steps
262+
item.order = value.order ?? item.order
261263
item.options = mergeDeep(item.options, value.options ?? {})
262264
item.permission = Permission.merge(item.permission, Permission.fromConfig(value.permission ?? {}))
263265
}
@@ -288,6 +290,7 @@ export const layer = Layer.effect(
288290
agents,
289291
values(),
290292
sortBy(
293+
[(x) => x.order ?? Number.MAX_SAFE_INTEGER, "asc"],
291294
[(x) => (cfg.default_agent ? x.name === cfg.default_agent : x.name === "build"), "desc"],
292295
[(x) => x.name, "asc"],
293296
),

packages/opencode/src/config/agent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const Info = z
4747
.describe("Maximum number of agentic iterations before forcing text-only response"),
4848
maxSteps: z.number().int().positive().optional().describe("@deprecated Use 'steps' field instead."),
4949
permission: ConfigPermission.Info.optional(),
50+
order: z.number().int().optional().describe("Display order in the agent list. Lower values appear first."),
5051
})
5152
.catchall(z.any())
5253
.transform((agent, _ctx) => {
@@ -67,6 +68,7 @@ export const Info = z
6768
"permission",
6869
"disable",
6970
"tools",
71+
"order",
7072
])
7173

7274
const options: Record<string, unknown> = { ...agent.options }

0 commit comments

Comments
 (0)