Преглед изворни кода

Added `opencode agent list` command to show all available agents with details. (#4446)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
opencode-agent[bot] пре 3 месеци
родитељ
комит
37d5099728
1 измењених фајлова са 25 додато и 1 уклоњено
  1. 25 1
      packages/opencode/src/cli/cmd/agent.ts

+ 25 - 1
packages/opencode/src/cli/cmd/agent.ts

@@ -6,6 +6,7 @@ import { Agent } from "../../agent/agent"
 import path from "path"
 import path from "path"
 import matter from "gray-matter"
 import matter from "gray-matter"
 import { Instance } from "../../project/instance"
 import { Instance } from "../../project/instance"
+import { EOL } from "os"
 
 
 const AgentCreateCommand = cmd({
 const AgentCreateCommand = cmd({
   command: "create",
   command: "create",
@@ -133,9 +134,32 @@ const AgentCreateCommand = cmd({
   },
   },
 })
 })
 
 
+const AgentListCommand = cmd({
+  command: "list",
+  describe: "list all available agents",
+  async handler() {
+    await Instance.provide({
+      directory: process.cwd(),
+      async fn() {
+        const agents = await Agent.list()
+        const sortedAgents = agents.sort((a, b) => {
+          if (a.builtIn !== b.builtIn) {
+            return a.builtIn ? -1 : 1
+          }
+          return a.name.localeCompare(b.name)
+        })
+
+        for (const agent of sortedAgents) {
+          process.stdout.write(`${agent.name} (${agent.mode})${EOL}`)
+        }
+      },
+    })
+  },
+})
+
 export const AgentCommand = cmd({
 export const AgentCommand = cmd({
   command: "agent",
   command: "agent",
   describe: "manage agents",
   describe: "manage agents",
-  builder: (yargs) => yargs.command(AgentCreateCommand).demandCommand(),
+  builder: (yargs) => yargs.command(AgentCreateCommand).command(AgentListCommand).demandCommand(),
   async handler() {},
   async handler() {},
 })
 })