diff options
| author | Eric Guo <[email protected]> | 2026-01-01 01:16:03 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-31 11:16:03 -0600 |
| commit | b97d20f2529889ef71316649ca2c042856a7e40d (patch) | |
| tree | 7a1cd1975d19abe614405f77eb46d1f98fd2630a | |
| parent | fcfcdd95e9fed58db6ca87abbb63c3b681a25d53 (diff) | |
| download | opencode-b97d20f2529889ef71316649ca2c042856a7e40d.tar.gz opencode-b97d20f2529889ef71316649ca2c042856a7e40d.zip | |
feat(cli): New debug agent <name> subcommand (#6529)
| -rw-r--r-- | packages/opencode/src/cli/cmd/debug/agent.ts | 51 | ||||
| -rw-r--r-- | packages/opencode/src/cli/cmd/debug/index.ts | 2 |
2 files changed, 53 insertions, 0 deletions
diff --git a/packages/opencode/src/cli/cmd/debug/agent.ts b/packages/opencode/src/cli/cmd/debug/agent.ts new file mode 100644 index 000000000..5a51a044d --- /dev/null +++ b/packages/opencode/src/cli/cmd/debug/agent.ts @@ -0,0 +1,51 @@ +import { EOL } from "os" +import { basename } from "path" +import { Agent } from "../../../agent/agent" +import { Provider } from "../../../provider/provider" +import { ToolRegistry } from "../../../tool/registry" +import { Wildcard } from "../../../util/wildcard" +import { bootstrap } from "../../bootstrap" +import { cmd } from "../cmd" + +export const AgentCommand = cmd({ + command: "agent <name>", + builder: (yargs) => + yargs.positional("name", { + type: "string", + demandOption: true, + description: "Agent name", + }), + async handler(args) { + await bootstrap(process.cwd(), async () => { + const agentName = args.name as string + const agent = await Agent.get(agentName) + if (!agent) { + process.stderr.write( + `Agent ${agentName} not found, run '${basename(process.execPath)} agent list' to get an agent list` + EOL, + ) + process.exit(1) + } + const resolvedTools = await resolveTools(agent) + const output = { + ...agent, + tools: resolvedTools, + toolOverrides: agent.tools, + } + process.stdout.write(JSON.stringify(output, null, 2) + EOL) + }) + }, +}) + +async function resolveTools(agent: Agent.Info) { + const providerID = agent.model?.providerID ?? (await Provider.defaultModel()).providerID + const toolOverrides = { + ...agent.tools, + ...(await ToolRegistry.enabled(agent)), + } + const availableTools = await ToolRegistry.tools(providerID, agent) + const resolved: Record<string, boolean> = {} + for (const tool of availableTools) { + resolved[tool.id] = Wildcard.all(tool.id, toolOverrides) !== false + } + return resolved +} diff --git a/packages/opencode/src/cli/cmd/debug/index.ts b/packages/opencode/src/cli/cmd/debug/index.ts index 3b0aefa28..789c726cc 100644 --- a/packages/opencode/src/cli/cmd/debug/index.ts +++ b/packages/opencode/src/cli/cmd/debug/index.ts @@ -8,6 +8,7 @@ import { RipgrepCommand } from "./ripgrep" import { ScrapCommand } from "./scrap" import { SkillCommand } from "./skill" import { SnapshotCommand } from "./snapshot" +import { AgentCommand } from "./agent" export const DebugCommand = cmd({ command: "debug", @@ -20,6 +21,7 @@ export const DebugCommand = cmd({ .command(ScrapCommand) .command(SkillCommand) .command(SnapshotCommand) + .command(AgentCommand) .command(PathsCommand) .command({ command: "wait", |
