Files
oh-my-opencode/src/plugin-handlers/tool-config-handler.ts
T
MoerAI 1d20cac582 fix(config): respect user's external_directory permission setting
applyToolConfig() forcibly overrode the user's external_directory
permission to 'allow' by placing OMO defaults after the user config
spread. Reorder so defaults come first and user config spreads on
top, allowing users to set 'ask' or 'deny'. The task permission
remains forced to 'deny' after the spread for security.

Closes #1973
2026-02-24 16:31:44 +09:00

108 lines
3.0 KiB
TypeScript

import type { OhMyOpenCodeConfig } from "../config";
import { getAgentDisplayName } from "../shared/agent-display-names";
type AgentWithPermission = { permission?: Record<string, unknown> };
function agentByKey(agentResult: Record<string, unknown>, key: string): AgentWithPermission | undefined {
return (agentResult[key] ?? agentResult[getAgentDisplayName(key)]) as
| AgentWithPermission
| undefined;
}
export function applyToolConfig(params: {
config: Record<string, unknown>;
pluginConfig: OhMyOpenCodeConfig;
agentResult: Record<string, unknown>;
}): void {
const denyTodoTools = params.pluginConfig.experimental?.task_system
? { todowrite: "deny", todoread: "deny" }
: {}
params.config.tools = {
...(params.config.tools as Record<string, unknown>),
"grep_app_*": false,
LspHover: false,
LspCodeActions: false,
LspCodeActionResolve: false,
"task_*": false,
teammate: false,
...(params.pluginConfig.experimental?.task_system
? { todowrite: false, todoread: false }
: {}),
};
const isCliRunMode = process.env.OPENCODE_CLI_RUN_MODE === "true";
const questionPermission = isCliRunMode ? "deny" : "allow";
const librarian = agentByKey(params.agentResult, "librarian");
if (librarian) {
librarian.permission = { ...librarian.permission, "grep_app_*": "allow" };
}
const looker = agentByKey(params.agentResult, "multimodal-looker");
if (looker) {
looker.permission = { ...looker.permission, task: "deny", look_at: "deny" };
}
const atlas = agentByKey(params.agentResult, "atlas");
if (atlas) {
atlas.permission = {
...atlas.permission,
task: "allow",
call_omo_agent: "deny",
"task_*": "allow",
teammate: "allow",
...denyTodoTools,
};
}
const sisyphus = agentByKey(params.agentResult, "sisyphus");
if (sisyphus) {
sisyphus.permission = {
...sisyphus.permission,
call_omo_agent: "deny",
task: "allow",
question: questionPermission,
"task_*": "allow",
teammate: "allow",
...denyTodoTools,
};
}
const hephaestus = agentByKey(params.agentResult, "hephaestus");
if (hephaestus) {
hephaestus.permission = {
...hephaestus.permission,
call_omo_agent: "deny",
task: "allow",
question: questionPermission,
...denyTodoTools,
};
}
const prometheus = agentByKey(params.agentResult, "prometheus");
if (prometheus) {
prometheus.permission = {
...prometheus.permission,
call_omo_agent: "deny",
task: "allow",
question: questionPermission,
"task_*": "allow",
teammate: "allow",
...denyTodoTools,
};
}
const junior = agentByKey(params.agentResult, "sisyphus-junior");
if (junior) {
junior.permission = {
...junior.permission,
task: "allow",
"task_*": "allow",
teammate: "allow",
...denyTodoTools,
};
}
params.config.permission = {
webfetch: "allow",
external_directory: "allow",
...(params.config.permission as Record<string, unknown>),
task: "deny",
};
}