Selaa lähdekoodia

fix(core): list default agent first (#42243)

Co-authored-by: Dax Raad <mail@thdxr.com>
opencode-agent[bot] 3 päivää sitten
vanhempi
sitoutus
8bcc245142
2 muutettua tiedostoa jossa 24 lisäystä ja 1 poistoa
  1. 4 1
      packages/core/src/agent.ts
  2. 20 0
      packages/core/test/agent.test.ts

+ 4 - 1
packages/core/src/agent.ts

@@ -122,7 +122,10 @@ const layer = Layer.effect(
         return { id: info?.id ?? defaultID, info }
       }),
       list: Effect.fn("Agent.list")(function* () {
-        return Array.fromIterable(state.get().agents.values())
+        const agents = Array.fromIterable(state.get().agents.values())
+        const selected = selectedDefault()
+        if (!selected) return agents
+        return [selected, ...agents.filter((agent) => agent.id !== selected.id)]
       }),
     })
   }),

+ 20 - 0
packages/core/test/agent.test.ts

@@ -68,6 +68,26 @@ describe("Agent", () => {
     }),
   )
 
+  it.effect("lists the selected default agent first", () =>
+    Effect.gen(function* () {
+      const agent = yield* Agent.Service
+      yield* agent.transform((editor) => {
+        editor.update(Agent.ID.make("build"), (info) => {
+          info.mode = "primary"
+        })
+        editor.update(Agent.ID.make("reviewer"), (info) => {
+          info.mode = "primary"
+        })
+        editor.update(Agent.ID.make("explore"), (info) => {
+          info.mode = "subagent"
+        })
+        editor.default(Agent.ID.make("reviewer"))
+      })
+
+      expect((yield* agent.list()).map((info) => String(info.id))).toEqual(["reviewer", "build", "explore"])
+    }),
+  )
+
   it.effect("rebuilds state when a transform is replaced", () =>
     Effect.gen(function* () {
       const agent = yield* Agent.Service