GeezerVison is showing github.com — Merge agent and mode into one (#1689) · meatcar/opencode@c34aec0
File treeExpand file treeCollapse file tree Open diff view settings web/src/content/docs/docs
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +description: You MUST use this agent when writing documentation | | 3 | +--- | | 4 | + | | 5 | +You are an expert technical documentation writer | | 6 | + | | 7 | +You are not verbose | | 8 | + | | 9 | +Every chunk of text should be followed by an example or something besides text | | 10 | +to look at. | | 11 | + | | 12 | +Chunks of text should not be more than 2 sentences long. |
Collapse file Copy file name to clipboardExpand all lines: .opencode/agent/example-driven-docs-writer.md -44Lines changed: 0 additions & 44 deletions Collapse file Copy file name to clipboardExpand all lines: bun.lock +348Lines changed: 348 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: packages/opencode/package.json +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 38 | 38 | "@openauthjs/openauth": "0.4.3", | 39 | 39 | "@opencode-ai/plugin": "workspace:*", | 40 | 40 | "@opencode-ai/sdk": "workspace:*", | | 41 | + "@opentelemetry/auto-instrumentations-node": "0.62.0", | | 42 | + "@opentelemetry/exporter-jaeger": "2.0.1", | | 43 | + "@opentelemetry/exporter-otlp-http": "0.26.0", | | 44 | + "@opentelemetry/exporter-trace-otlp-http": "0.203.0", | | 45 | + "@opentelemetry/instrumentation-fetch": "0.203.0", | | 46 | + "@opentelemetry/sdk-node": "0.203.0", | | 47 | + "@opentelemetry/sdk-trace-node": "2.0.1", | 41 | 48 | "@standard-schema/spec": "1.0.0", | 42 | 49 | "@zip.js/zip.js": "2.7.62", | 43 | 50 | "ai": "catalog:", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/agent/agent.ts +26-8Lines changed: 26 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,20 +10,24 @@ export namespace Agent { | 10 | 10 | export const Info = z | 11 | 11 | .object({ | 12 | 12 | name: z.string(), | | 13 | + description: z.string().optional(), | | 14 | + mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]), | | 15 | + topP: z.number().optional(), | | 16 | + temperature: z.number().optional(), | 13 | 17 | model: z | 14 | 18 | .object({ | 15 | 19 | modelID: z.string(), | 16 | 20 | providerID: z.string(), | 17 | 21 | }) | 18 | 22 | .optional(), | 19 | | - description: z.string(), | 20 | 23 | prompt: z.string().optional(), | 21 | 24 | tools: z.record(z.boolean()), | 22 | 25 | }) | 23 | 26 | .openapi({ | 24 | 27 | ref: "Agent", | 25 | 28 | }) | 26 | 29 | export type Info = z.infer<typeof Info> | | 30 | + | 27 | 31 | const state = App.state("agent", async () => { | 28 | 32 | const cfg = await Config.get() | 29 | 33 | const result: Record<string, Info> = { | @@ -35,6 +39,21 @@ export namespace Agent { | 35 | 39 | todoread: false, | 36 | 40 | todowrite: false, | 37 | 41 | }, | | 42 | + mode: "subagent", | | 43 | + }, | | 44 | + build: { | | 45 | + name: "build", | | 46 | + tools: {}, | | 47 | + mode: "primary", | | 48 | + }, | | 49 | + plan: { | | 50 | + name: "plan", | | 51 | + tools: { | | 52 | + write: false, | | 53 | + edit: false, | | 54 | + patch: false, | | 55 | + }, | | 56 | + mode: "primary", | 38 | 57 | }, | 39 | 58 | } | 40 | 59 | for (const [key, value] of Object.entries(cfg.agent ?? {})) { | @@ -46,21 +65,20 @@ export namespace Agent { | 46 | 65 | if (!item) | 47 | 66 | item = result[key] = { | 48 | 67 | name: key, | 49 | | - description: "", | 50 | | - tools: { | 51 | | - todowrite: false, | 52 | | - todoread: false, | 53 | | - }, | | 68 | + mode: "all", | | 69 | + tools: {}, | 54 | 70 | } | 55 | | - const model = value.model ?? cfg.model | 56 | | - if (model) item.model = Provider.parseModel(model) | | 71 | + if (value.model) item.model = Provider.parseModel(value.model) | 57 | 72 | if (value.prompt) item.prompt = value.prompt | 58 | 73 | if (value.tools) | 59 | 74 | item.tools = { | 60 | 75 | ...item.tools, | 61 | 76 | ...value.tools, | 62 | 77 | } | 63 | 78 | if (value.description) item.description = value.description | | 79 | + if (value.temperature != undefined) item.temperature = value.temperature | | 80 | + if (value.top_p != undefined) item.topP = value.top_p | | 81 | + if (value.mode) item.mode = value.mode | 64 | 82 | } | 65 | 83 | return result | 66 | 84 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/github.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -641,7 +641,7 @@ export const GithubRunCommand = cmd({ | 641 | 641 | messageID: Identifier.ascending("message"), | 642 | 642 | providerID, | 643 | 643 | modelID, | 644 | | - mode: "build", | | 644 | + agent: "build", | 645 | 645 | parts: [ | 646 | 646 | { | 647 | 647 | id: Identifier.ascending("part"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/run.ts +23-9Lines changed: 23 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,8 +8,8 @@ import { Flag } from "../../flag/flag" | 8 | 8 | import { Config } from "../../config/config" | 9 | 9 | import { bootstrap } from "../bootstrap" | 10 | 10 | import { MessageV2 } from "../../session/message-v2" | 11 | | -import { Mode } from "../../session/mode" | 12 | 11 | import { Identifier } from "../../id/id" | | 12 | +import { Agent } from "../../agent/agent" | 13 | 13 |
| 14 | 14 | const TOOL: Record<string, [string, string]> = { | 15 | 15 | todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD], | @@ -54,9 +54,9 @@ export const RunCommand = cmd({ | 54 | 54 | alias: ["m"], | 55 | 55 | describe: "model to use in the format of provider/model", | 56 | 56 | }) | 57 | | - .option("mode", { | | 57 | + .option("agent", { | 58 | 58 | type: "string", | 59 | | - describe: "mode to use", | | 59 | + describe: "agent to use", | 60 | 60 | }) | 61 | 61 | }, | 62 | 62 | handler: async (args) => { | @@ -103,8 +103,19 @@ export const RunCommand = cmd({ | 103 | 103 | } | 104 | 104 | UI.empty() | 105 | 105 |
| 106 | | - const mode = args.mode ? await Mode.get(args.mode) : await Mode.list().then((x) => x[0]) | 107 | | - const { providerID, modelID } = args.model ? Provider.parseModel(args.model) : mode.model ?? await Provider.defaultModel() | | 106 | + const agent = await (async () => { | | 107 | + if (args.agent) return Agent.get(args.agent) | | 108 | + const build = Agent.get("build") | | 109 | + if (build) return build | | 110 | + return Agent.list().then((x) => x[0]) | | 111 | + })() | | 112 | + | | 113 | + const { providerID, modelID } = await (() => { | | 114 | + if (args.model) return Provider.parseModel(args.model) | | 115 | + if (agent.model) return agent.model | | 116 | + return Provider.defaultModel() | | 117 | + })() | | 118 | + | 108 | 119 | UI.println(UI.Style.TEXT_NORMAL_BOLD + "@ ", UI.Style.TEXT_NORMAL + `${providerID}/${modelID}`) | 109 | 120 | UI.empty() | 110 | 121 |
| @@ -157,14 +168,17 @@ export const RunCommand = cmd({ | 157 | 168 | UI.error(err) | 158 | 169 | }) | 159 | 170 |
| 160 | | - | 161 | 171 | const messageID = Identifier.ascending("message") | 162 | 172 | const result = await Session.chat({ | 163 | 173 | sessionID: session.id, | 164 | 174 | messageID, | 165 | | - providerID, | 166 | | - modelID, | 167 | | - mode: mode.name, | | 175 | + ...(agent.model | | 176 | + ? agent.model | | 177 | + : { | | 178 | + providerID, | | 179 | + modelID, | | 180 | + }), | | 181 | + agent: agent.name, | 168 | 182 | parts: [ | 169 | 183 | { | 170 | 184 | id: Identifier.ascending("part"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,8 +11,8 @@ import { Config } from "../../config/config" | 11 | 11 | import { Bus } from "../../bus" | 12 | 12 | import { Log } from "../../util/log" | 13 | 13 | import { FileWatcher } from "../../file/watch" | 14 | | -import { Mode } from "../../session/mode" | 15 | 14 | import { Ide } from "../../ide" | | 15 | +import { Agent } from "../../agent/agent" | 16 | 16 |
| 17 | 17 | declare global { | 18 | 18 | const OPENCODE_TUI_PATH: string | @@ -115,7 +115,7 @@ export const TuiCommand = cmd({ | 115 | 115 | CGO_ENABLED: "0", | 116 | 116 | OPENCODE_SERVER: server.url.toString(), | 117 | 117 | OPENCODE_APP_INFO: JSON.stringify(app), | 118 | | - OPENCODE_MODES: JSON.stringify(await Mode.list()), | | 118 | + OPENCODE_AGENTS: JSON.stringify(await Agent.list()), | 119 | 119 | }, | 120 | 120 | onExit: () => { | 121 | 121 | server.stop() | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/config/config.ts +36-17Lines changed: 36 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,7 +83,7 @@ export namespace Config { | 83 | 83 | ...md.data, | 84 | 84 | prompt: md.content.trim(), | 85 | 85 | } | 86 | | - const parsed = Mode.safeParse(config) | | 86 | + const parsed = Agent.safeParse(config) | 87 | 87 | if (parsed.success) { | 88 | 88 | result.mode = mergeDeep(result.mode, { | 89 | 89 | [config.name]: parsed.data, | @@ -92,6 +92,15 @@ export namespace Config { | 92 | 92 | } | 93 | 93 | throw new InvalidError({ path: item }, { cause: parsed.error }) | 94 | 94 | } | | 95 | + // Migrate deprecated mode field to agent field | | 96 | + for (const [name, mode] of Object.entries(result.mode)) { | | 97 | + result.agent = mergeDeep(result.agent ?? {}, { | | 98 | + [name]: { | | 99 | + ...mode, | | 100 | + mode: "primary" as const, | | 101 | + }, | | 102 | + }) | | 103 | + } | 95 | 104 |
| 96 | 105 | result.plugin = result.plugin || [] | 97 | 106 | result.plugin.push( | @@ -108,6 +117,12 @@ export namespace Config { | 108 | 117 | if (result.keybinds?.messages_revert && !result.keybinds.messages_undo) { | 109 | 118 | result.keybinds.messages_undo = result.keybinds.messages_revert | 110 | 119 | } | | 120 | + if (result.keybinds?.switch_mode && !result.keybinds.switch_agent) { | | 121 | + result.keybinds.switch_agent = result.keybinds.switch_mode | | 122 | + } | | 123 | + if (result.keybinds?.switch_mode_reverse && !result.keybinds.switch_agent_reverse) { | | 124 | + result.keybinds.switch_agent_reverse = result.keybinds.switch_mode_reverse | | 125 | + } | 111 | 126 |
| 112 | 127 | if (!result.username) { | 113 | 128 | const os = await import("os") | @@ -149,32 +164,34 @@ export namespace Config { | 149 | 164 | export const Mcp = z.discriminatedUnion("type", [McpLocal, McpRemote]) | 150 | 165 | export type Mcp = z.infer<typeof Mcp> | 151 | 166 |
| 152 | | - export const Mode = z | | 167 | + export const Agent = z | 153 | 168 | .object({ | 154 | 169 | model: z.string().optional(), | 155 | 170 | temperature: z.number().optional(), | 156 | 171 | top_p: z.number().optional(), | 157 | 172 | prompt: z.string().optional(), | 158 | 173 | tools: z.record(z.string(), z.boolean()).optional(), | 159 | 174 | disable: z.boolean().optional(), | | 175 | + description: z.string().optional().describe("Description of when to use the agent"), | | 176 | + mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]).optional(), | 160 | 177 | }) | 161 | 178 | .openapi({ | 162 | | - ref: "ModeConfig", | | 179 | + ref: "AgentConfig", | 163 | 180 | }) | 164 | | - export type Mode = z.infer<typeof Mode> | 165 | | - | 166 | | - export const Agent = Mode.extend({ | 167 | | - description: z.string(), | 168 | | - }).openapi({ | 169 | | - ref: "AgentConfig", | 170 | | - }) | | 181 | + export type Agent = z.infer<typeof Agent> | 171 | 182 |
| 172 | 183 | export const Keybinds = z | 173 | 184 | .object({ | 174 | 185 | leader: z.string().optional().default("ctrl+x").describe("Leader key for keybind combinations"), | 175 | 186 | app_help: z.string().optional().default("<leader>h").describe("Show help dialog"), | 176 | | - switch_mode: z.string().optional().default("tab").describe("Next mode"), | 177 | | - switch_mode_reverse: z.string().optional().default("shift+tab").describe("Previous Mode"), | | 187 | + switch_mode: z.string().optional().default("none").describe("@deprecated use switch_agent. Next mode"), | | 188 | + switch_mode_reverse: z | | 189 | + .string() | | 190 | + .optional() | | 191 | + .default("none") | | 192 | + .describe("@deprecated use switch_agent_reverse. Previous mode"), | | 193 | + switch_agent: z.string().optional().default("tab").describe("Next agent"), | | 194 | + switch_agent_reverse: z.string().optional().default("shift+tab").describe("Previous agent"), | 178 | 195 | editor_open: z.string().optional().default("<leader>e").describe("Open external editor"), | 179 | 196 | session_export: z.string().optional().default("<leader>x").describe("Export session to editor"), | 180 | 197 | session_new: z.string().optional().default("<leader>n").describe("Create a new session"), | @@ -257,19 +274,21 @@ export namespace Config { | 257 | 274 | .describe("Custom username to display in conversations instead of system username"), | 258 | 275 | mode: z | 259 | 276 | .object({ | 260 | | - build: Mode.optional(), | 261 | | - plan: Mode.optional(), | | 277 | + build: Agent.optional(), | | 278 | + plan: Agent.optional(), | 262 | 279 | }) | 263 | | - .catchall(Mode) | | 280 | + .catchall(Agent) | 264 | 281 | .optional() | 265 | | - .describe("Modes configuration, see https://opencode.ai/docs/modes"), | | 282 | + .describe("@deprecated Use `agent` field instead."), | 266 | 283 | agent: z | 267 | 284 | .object({ | | 285 | + plan: Agent.optional(), | | 286 | + build: Agent.optional(), | 268 | 287 | general: Agent.optional(), | 269 | 288 | }) | 270 | 289 | .catchall(Agent) | 271 | 290 | .optional() | 272 | | - .describe("Modes configuration, see https://opencode.ai/docs/modes"), | | 291 | + .describe("Agent configuration, see https://opencode.ai/docs/agent"), | 273 | 292 | provider: z | 274 | 293 | .record( | 275 | 294 | ModelsDev.Provider.partial() | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/index.ts +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import "zod-openapi/extend" | | 2 | +import { Trace } from "./trace" | | 3 | +Trace.init() | 2 | 4 | import yargs from "yargs" | 3 | 5 | import { hideBin } from "yargs/helpers" | 4 | 6 | import { RunCommand } from "./cli/cmd/run" | @@ -18,9 +20,6 @@ import { DebugCommand } from "./cli/cmd/debug" | 18 | 20 | import { StatsCommand } from "./cli/cmd/stats" | 19 | 21 | import { McpCommand } from "./cli/cmd/mcp" | 20 | 22 | import { GithubCommand } from "./cli/cmd/github" | 21 | | -import { Trace } from "./trace" | 22 | | - | 23 | | -Trace.init() | 24 | 23 |
| 25 | 24 | const cancel = new AbortController() | 26 | 25 |
| |
|