f9d354b63e
The spread order in applyToolConfig was incorrect - omo's external_directory: 'allow' was placed BEFORE the config.permission spread, allowing opencode's default 'ask' to overwrite it. This caused write/edit tools to hang on headless opencode serve sessions (no TUI to approve permission prompts). Move omo's permission overrides AFTER the base config spread so they always win. Fixes write/edit tool hangs when running opencode serve headlessly.
125 lines
3.6 KiB
TypeScript
125 lines
3.6 KiB
TypeScript
import type { OhMyOpenCodeConfig } from "../config";
|
|
import { getAgentDisplayName } from "../shared/agent-display-names";
|
|
|
|
type AgentWithPermission = { permission?: Record<string, unknown> };
|
|
|
|
function getConfigQuestionPermission(): string | null {
|
|
const configContent = process.env.OPENCODE_CONFIG_CONTENT;
|
|
if (!configContent) return null;
|
|
try {
|
|
const parsed = JSON.parse(configContent);
|
|
return parsed?.permission?.question ?? null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
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 configQuestionPermission = getConfigQuestionPermission();
|
|
const isQuestionDisabledByPlugin = params.pluginConfig.disabled_tools?.includes("question") ?? false;
|
|
const questionPermission =
|
|
isQuestionDisabledByPlugin ? "deny" :
|
|
configQuestionPermission === "deny" ? "deny" :
|
|
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 = {
|
|
...(params.config.permission as Record<string, unknown>),
|
|
webfetch: "allow",
|
|
external_directory: "allow",
|
|
task: "deny",
|
|
};
|
|
}
|