Skip to content

Commit c9235e5

Browse files
committed
feat(cli): add plugin disable/enable commands
Add new CLI commands to manage plugins: - opencode plugin list - list all plugins and their status - opencode plugin disable <name> - disable a plugin - opencode plugin enable <name> - enable a previously disabled plugin Also adds disabled_plugins config field to track disabled plugins without removing them from the config. Resolves anomalyco#7687
1 parent 3a3aa30 commit c9235e5

5 files changed

Lines changed: 187 additions & 1 deletion

File tree

‎packages/opencode/src/cli/cmd/mcp.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export const McpLogoutCommand = cmd({
379379
},
380380
})
381381

382-
async function resolveConfigPath(baseDir: string, global = false) {
382+
export async function resolveConfigPath(baseDir: string, global = false) {
383383
// Check for existing config files (prefer .jsonc over .json, check .opencode/ subdirectory too)
384384
const candidates = [path.join(baseDir, "opencode.json"), path.join(baseDir, "opencode.jsonc")]
385385

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import { cmd } from "./cmd"
2+
import * as prompts from "@clack/prompts"
3+
import { UI } from "../ui"
4+
import { Config } from "../../config/config"
5+
import { Instance } from "../../project/instance"
6+
import { Global } from "../../global"
7+
import { modify, applyEdits } from "jsonc-parser"
8+
import { resolveConfigPath } from "./mcp"
9+
10+
async function updateDisabledPlugins(plugins: string[], configPath: string) {
11+
const file = Bun.file(configPath)
12+
13+
let text = "{}"
14+
if (await file.exists()) {
15+
text = await file.text()
16+
}
17+
18+
const edits = modify(text, ["disabled_plugins"], plugins, {
19+
formattingOptions: { tabSize: 2, insertSpaces: true },
20+
})
21+
const result = applyEdits(text, edits)
22+
23+
await Bun.write(configPath, result)
24+
}
25+
26+
export const PluginCommand = cmd({
27+
command: "plugin",
28+
describe: "manage plugins",
29+
builder: (yargs) =>
30+
yargs.command(PluginListCommand).command(PluginDisableCommand).command(PluginEnableCommand).demandCommand(),
31+
async handler() {},
32+
})
33+
34+
export const PluginListCommand = cmd({
35+
command: "list",
36+
aliases: ["ls"],
37+
describe: "list all configured plugins and their status",
38+
async handler() {
39+
await Instance.provide({
40+
directory: process.cwd(),
41+
async fn() {
42+
UI.empty()
43+
prompts.intro("Plugins")
44+
45+
const config = await Config.get()
46+
const plugins = config.plugin ?? []
47+
const disabled = new Set(config.disabled_plugins ?? [])
48+
49+
if (plugins.length === 0) {
50+
prompts.log.warn("No plugins configured")
51+
prompts.outro("Add plugins in opencode.json or via npm install")
52+
return
53+
}
54+
55+
for (const plugin of plugins) {
56+
const name = Config.getPluginName(plugin)
57+
const isDisabled = disabled.has(name)
58+
const icon = isDisabled ? "○" : "✓"
59+
const status = isDisabled ? "disabled" : "enabled"
60+
prompts.log.info(`${icon} ${name} ${UI.Style.TEXT_DIM}${status}\n ${UI.Style.TEXT_DIM}${plugin}`)
61+
}
62+
63+
const enabledCount = plugins.filter((p) => !disabled.has(Config.getPluginName(p))).length
64+
prompts.outro(`${enabledCount}/${plugins.length} plugin(s) enabled`)
65+
},
66+
})
67+
},
68+
})
69+
70+
export const PluginDisableCommand = cmd({
71+
command: "disable <name>",
72+
describe: "disable a plugin",
73+
builder: (yargs) =>
74+
yargs.positional("name", {
75+
describe: "name of the plugin to disable",
76+
type: "string",
77+
demandOption: true,
78+
}),
79+
async handler(args) {
80+
await Instance.provide({
81+
directory: process.cwd(),
82+
async fn() {
83+
UI.empty()
84+
prompts.intro("Disable Plugin")
85+
86+
const config = await Config.get()
87+
const plugins = config.plugin ?? []
88+
const pluginName = args.name
89+
90+
if (plugins.length === 0) {
91+
prompts.log.warn("No plugins configured")
92+
prompts.outro("Done")
93+
return
94+
}
95+
96+
const pluginEntry = plugins.find((p) => Config.getPluginName(p) === pluginName)
97+
if (!pluginEntry) {
98+
prompts.log.error(`Plugin not found: ${pluginName}`)
99+
prompts.outro("Done")
100+
return
101+
}
102+
103+
const disabled = config.disabled_plugins ?? []
104+
if (disabled.includes(pluginName)) {
105+
prompts.log.warn(`Plugin "${pluginName}" is already disabled`)
106+
prompts.outro("Done")
107+
return
108+
}
109+
110+
const [projectConfigPath, globalConfigPath] = await Promise.all([
111+
resolveConfigPath(Instance.worktree),
112+
resolveConfigPath(Global.Path.config, true),
113+
])
114+
115+
const currentProject = Instance.project
116+
const configPath = currentProject.vcs === "git" ? projectConfigPath : globalConfigPath
117+
const nextDisabled = [...disabled, pluginName]
118+
await updateDisabledPlugins(nextDisabled, configPath)
119+
120+
prompts.log.success(`Plugin "${pluginName}" disabled`)
121+
prompts.outro("Done")
122+
},
123+
})
124+
},
125+
})
126+
127+
export const PluginEnableCommand = cmd({
128+
command: "enable <name>",
129+
describe: "enable a previously disabled plugin",
130+
builder: (yargs) =>
131+
yargs.positional("name", {
132+
describe: "name of the plugin to enable",
133+
type: "string",
134+
demandOption: true,
135+
}),
136+
async handler(args) {
137+
await Instance.provide({
138+
directory: process.cwd(),
139+
async fn() {
140+
UI.empty()
141+
prompts.intro("Enable Plugin")
142+
143+
const config = await Config.get()
144+
const disabled = config.disabled_plugins ?? []
145+
const pluginName = args.name
146+
147+
if (!disabled.includes(pluginName)) {
148+
prompts.log.warn(`Plugin "${pluginName}" is not disabled`)
149+
prompts.outro("Done")
150+
return
151+
}
152+
153+
const [projectConfigPath, globalConfigPath] = await Promise.all([
154+
resolveConfigPath(Instance.worktree),
155+
resolveConfigPath(Global.Path.config, true),
156+
])
157+
158+
const currentProject = Instance.project
159+
const configPath = currentProject.vcs === "git" ? projectConfigPath : globalConfigPath
160+
const nextDisabled = disabled.filter((p) => p !== pluginName)
161+
await updateDisabledPlugins(nextDisabled, configPath)
162+
163+
prompts.log.success(`Plugin "${pluginName}" enabled`)
164+
prompts.outro("Done")
165+
},
166+
})
167+
},
168+
})

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ export namespace Config {
10221022
})
10231023
.optional(),
10241024
plugin: z.string().array().optional(),
1025+
disabled_plugins: z
1026+
.array(z.string())
1027+
.optional()
1028+
.describe(
1029+
"Plugins to disable. Can be plugin names (e.g., 'my-plugin') or package specifiers (e.g., '@scope/[email protected]')",
1030+
),
10251031
snapshot: z.boolean().optional(),
10261032
share: z
10271033
.enum(["manual", "auto", "disabled"])

‎packages/opencode/src/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import path from "path"
3131
import { Global } from "./global"
3232
import { JsonMigration } from "./storage/json-migration"
3333
import { Database } from "./storage/db"
34+
import { PluginCommand } from "./cli/cmd/plugin"
3435

3536
process.on("unhandledRejection", (e) => {
3637
Log.Default.error("rejection", {
@@ -121,6 +122,7 @@ const cli = yargs(hideBin(process.argv))
121122
.completion("completion", "generate shell completion script")
122123
.command(AcpCommand)
123124
.command(McpCommand)
125+
.command(PluginCommand)
124126
.command(TuiThreadCommand)
125127
.command(AttachCommand)
126128
.command(RunCommand)

‎packages/opencode/src/plugin/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ export namespace Plugin {
5151
plugins = [...BUILTIN, ...plugins]
5252
}
5353

54+
const disabled = new Set(config.disabled_plugins ?? [])
55+
plugins = plugins.filter((plugin) => {
56+
const name = Config.getPluginName(plugin)
57+
if (disabled.has(name)) {
58+
log.info("skipping disabled plugin", { name, path: plugin })
59+
return false
60+
}
61+
return true
62+
})
63+
5464
for (let plugin of plugins) {
5565
// ignore old codex plugin since it is supported first party now
5666
if (plugin.includes("opencode-openai-codex-auth") || plugin.includes("opencode-copilot-auth")) continue

0 commit comments

Comments
 (0)