support wildcard matching tool names in config
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://opencode.ai/config.json",
|
"$schema": "https://opencode.ai/config.json",
|
||||||
|
"agent": {
|
||||||
|
"build": {}
|
||||||
|
},
|
||||||
"mcp": {
|
"mcp": {
|
||||||
"context7": {
|
"context7": {
|
||||||
"type": "remote",
|
"type": "remote",
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import { ToolRegistry } from "../tool/registry"
|
|||||||
import { Plugin } from "../plugin"
|
import { Plugin } from "../plugin"
|
||||||
import { Agent } from "../agent/agent"
|
import { Agent } from "../agent/agent"
|
||||||
import { Permission } from "../permission"
|
import { Permission } from "../permission"
|
||||||
|
import { Wildcard } from "../util/wildcard"
|
||||||
|
|
||||||
export namespace Session {
|
export namespace Session {
|
||||||
const log = Log.create({ service: "session" })
|
const log = Log.create({ service: "session" })
|
||||||
@@ -768,7 +769,7 @@ export namespace Session {
|
|||||||
mergeDeep(input.tools ?? {}),
|
mergeDeep(input.tools ?? {}),
|
||||||
)
|
)
|
||||||
for (const item of await ToolRegistry.tools(input.providerID, input.modelID)) {
|
for (const item of await ToolRegistry.tools(input.providerID, input.modelID)) {
|
||||||
if (enabledTools[item.id] === false) continue
|
if (Wildcard.all(item.id, enabledTools) === false) continue
|
||||||
tools[item.id] = tool({
|
tools[item.id] = tool({
|
||||||
id: item.id as any,
|
id: item.id as any,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
@@ -829,7 +830,7 @@ export namespace Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, item] of Object.entries(await MCP.tools())) {
|
for (const [key, item] of Object.entries(await MCP.tools())) {
|
||||||
if (enabledTools[key] === false) continue
|
if (Wildcard.all(key, enabledTools) === false) continue
|
||||||
const execute = item.execute
|
const execute = item.execute
|
||||||
if (!execute) continue
|
if (!execute) continue
|
||||||
item.execute = async (args, opts) => {
|
item.execute = async (args, opts) => {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { sortBy, pipe } from "remeda"
|
||||||
|
|
||||||
export namespace Wildcard {
|
export namespace Wildcard {
|
||||||
export function match(str: string, pattern: string) {
|
export function match(str: string, pattern: string) {
|
||||||
const regex = new RegExp(
|
const regex = new RegExp(
|
||||||
@@ -11,4 +13,16 @@ export namespace Wildcard {
|
|||||||
)
|
)
|
||||||
return regex.test(str)
|
return regex.test(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function all(input: string, patterns: Record<string, any>) {
|
||||||
|
const sorted = pipe(patterns, Object.entries, sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]))
|
||||||
|
let result = undefined
|
||||||
|
for (const [pattern, value] of sorted) {
|
||||||
|
if (match(input, pattern)) {
|
||||||
|
result = value
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,6 +318,22 @@ Control which tools are available in this agent with the `tools` config. You can
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also use wildcards to control multiple tools at once. For example, to disable all tools from an MCP server:
|
||||||
|
|
||||||
|
```json title="opencode.json"
|
||||||
|
{
|
||||||
|
"agent": {
|
||||||
|
"readonly": {
|
||||||
|
"tools": {
|
||||||
|
"mymcp_*": false,
|
||||||
|
"write": false,
|
||||||
|
"edit": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If no tools are specified, all tools are enabled by default.
|
If no tools are specified, all tools are enabled by default.
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -371,7 +387,7 @@ For example, with OpenAI's reasoning models, you can control the reasoning effor
|
|||||||
"agent": {
|
"agent": {
|
||||||
"deep-thinker": {
|
"deep-thinker": {
|
||||||
"description": "Agent that uses high reasoning effort for complex problems",
|
"description": "Agent that uses high reasoning effort for complex problems",
|
||||||
"model": "openai/gpt-5-turbo",
|
"model": "openai/gpt-5-turbo",
|
||||||
"reasoningEffort": "high",
|
"reasoningEffort": "high",
|
||||||
"textVerbosity": "low"
|
"textVerbosity": "low"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user