Skip to content

Commit 1c3fedb

Browse files
kuitosJosXa
authored andcommitted
feat(agent): add order field for configurable agent cycling order
Add an optional `order` field to the agent config schema that controls agent sorting in the Tab cycle. Agents with lower order values appear first. Agents without an explicit order fall back to alphabetical sorting, preserving backward compatibility. This allows plugins and users to control the exact ordering of agents in the Tab cycle without relying on name-based alphabetical sorting. Closes anomalyco#7372
1 parent a4d2ae9 commit 1c3fedb

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/core/src/v1/config/agent.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const AgentSchema = Schema.StructWithRest(
2424
disable: Schema.optional(Schema.Boolean),
2525
description: Schema.optional(Schema.String).annotate({ description: "Description of when to use the agent" }),
2626
mode: Schema.optional(Schema.Literals(["subagent", "primary", "all"])),
27+
order: Schema.optional(Schema.Int).annotate({
28+
description:
29+
"Sorting order for agent cycling (Tab). Lower values appear first. Agents without order are sorted alphabetically after ordered agents.",
30+
}),
2731
hidden: Schema.optional(Schema.Boolean).annotate({
2832
description: "Hide this subagent from the @ autocomplete menu (default: false, only applies to mode: subagent)",
2933
}),
@@ -49,6 +53,7 @@ const KNOWN_KEYS = new Set([
4953
"temperature",
5054
"top_p",
5155
"mode",
56+
"order",
5257
"hidden",
5358
"color",
5459
"steps",

‎packages/opencode/src/agent/agent.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const Info = Schema.Struct({
4040
hidden: Schema.optional(Schema.Boolean),
4141
topP: Schema.optional(Schema.Finite),
4242
temperature: Schema.optional(Schema.Finite),
43+
order: Schema.optional(Schema.Int),
4344
color: Schema.optional(Schema.String),
4445
permission: PermissionV1.Ruleset,
4546
model: Schema.optional(
@@ -286,6 +287,7 @@ export const layer = Layer.effect(
286287
item.color = value.color ?? item.color
287288
item.hidden = value.hidden ?? item.hidden
288289
item.name = value.name ?? item.name
290+
item.order = value.order ?? item.order
289291
item.steps = value.steps ?? item.steps
290292
item.options = mergeDeep(item.options, value.options ?? {})
291293
item.permission = Permission.merge(item.permission, Permission.fromConfig(value.permission ?? {}))
@@ -318,6 +320,7 @@ export const layer = Layer.effect(
318320
values(),
319321
sortBy(
320322
[(x) => (cfg.default_agent ? x.name === cfg.default_agent : x.name === "build"), "desc"],
323+
[(x) => x.order ?? Infinity, "asc"],
321324
[(x) => x.name, "asc"],
322325
),
323326
)

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ import { TuiConfig } from "@/cli/cmd/tui/config/tui"
6161
import { createTuiApi, TuiPluginRuntime, type RouteMap } from "./plugin"
6262
import { FormatError, FormatUnknownError } from "@/cli/error"
6363
import { InputBuffer } from "@tui/util/input-buffer"
64-
import * as Log from "@/util/log"
6564

66-
const log = Log.create({ service: "tui-app" })
65+
const log = {
66+
info: (message: string, metadata?: unknown) => console.info("tui-app", message, metadata),
67+
}
6768

6869
import type { EventSource } from "./context/sdk"
6970
import { DialogVariant } from "./component/dialog-variant"

‎packages/opencode/src/config/reload.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Config } from "./config"
2-
import { Log } from "../util/log"
32
import { GlobalBus } from "../bus/global"
43
import { AppRuntime } from "../effect/app-runtime"
54
import { disposeAllInstancesAndEmitGlobalDisposed } from "../server/global-lifecycle"
65

76
export namespace ConfigReload {
8-
const log = Log.create({ service: "config.reload" })
7+
const log = {
8+
debug: (message: string, metadata?: unknown) => console.debug("config.reload", message, metadata),
9+
info: (message: string, metadata?: unknown) => console.info("config.reload", message, metadata),
10+
error: (message: string, metadata?: unknown) => console.error("config.reload", message, metadata),
11+
}
912

1013
export const Event = {
1114
Pending: { type: "config.reload.pending" },

‎packages/tui/src/ui/dialog.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useToast } from "./toast"
77
import { Flag } from "@opencode-ai/core/flag/flag"
88
import { useBindings, useOpencodeModeStack } from "../keymap"
99
import { useClipboard } from "../context/clipboard"
10-
import { useSync } from "@tui/context/sync"
10+
import { useSync } from "../context/sync"
1111

1212
export function Dialog(
1313
props: ParentProps<{

0 commit comments

Comments
 (0)