d4ce03411c
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
133 lines
4.0 KiB
TypeScript
133 lines
4.0 KiB
TypeScript
import type { OhMyOpenCodeConfig } from "../config";
|
|
import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names";
|
|
import { isTaskSystemEnabled } from "../shared";
|
|
|
|
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[getAgentListDisplayName(key)] ?? agentResult[getAgentDisplayName(key)] ?? agentResult[key]) as
|
|
| AgentWithPermission
|
|
| undefined;
|
|
}
|
|
|
|
export function applyToolConfig(params: {
|
|
config: Record<string, unknown>;
|
|
pluginConfig: OhMyOpenCodeConfig;
|
|
agentResult: Record<string, unknown>;
|
|
}): void {
|
|
const taskSystemEnabled = isTaskSystemEnabled(params.pluginConfig)
|
|
const denyTodoTools = taskSystemEnabled
|
|
? { todowrite: "deny", todoread: "deny" }
|
|
: {}
|
|
|
|
const existingPermission = params.config.permission as Record<string, unknown> | undefined;
|
|
const skillDeniedByHost = existingPermission?.skill === "deny";
|
|
|
|
params.config.tools = {
|
|
...(params.config.tools as Record<string, unknown>),
|
|
"grep_app_*": false,
|
|
LspHover: false,
|
|
LspCodeActions: false,
|
|
LspCodeActionResolve: false,
|
|
"task_*": false,
|
|
teammate: false,
|
|
...(taskSystemEnabled
|
|
? { todowrite: false, todoread: false }
|
|
: {}),
|
|
...(skillDeniedByHost
|
|
? { skill: false, skill_mcp: 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 = {
|
|
webfetch: "allow",
|
|
external_directory: "allow",
|
|
...(params.config.permission as Record<string, unknown>),
|
|
task: "deny",
|
|
};
|
|
}
|