Remap config.agent keys to display names at output boundary

Use display names as config.agent keys so opencode shows proper names in UI
(Tab/@ menu). Key remapping happens after all agents are assembled but before
reordering, via remapAgentKeysToDisplayNames().

- agent-config-handler: set default_agent to display name, add key remapping
- agent-key-remapper: new module to transform lowercase keys to display names
- agent-priority-order: CORE_AGENT_ORDER uses display names
- tool-config-handler: look up agents by config key via agentByKey() helper
This commit is contained in:
YeonGyu-Kim 2026-02-16 20:42:58 +09:00
parent c71a80a86c
commit d94a739203
4 changed files with 63 additions and 28 deletions

View File

@ -3,6 +3,7 @@ import { createSisyphusJuniorAgentWithOverrides } from "../agents/sisyphus-junio
import type { OhMyOpenCodeConfig } from "../config"; import type { OhMyOpenCodeConfig } from "../config";
import { log, migrateAgentConfig } from "../shared"; import { log, migrateAgentConfig } from "../shared";
import { AGENT_NAME_MAP } from "../shared/migration"; import { AGENT_NAME_MAP } from "../shared/migration";
import { getAgentDisplayName } from "../shared/agent-display-names";
import { import {
discoverConfigSourceSkills, discoverConfigSourceSkills,
discoverOpencodeGlobalSkills, discoverOpencodeGlobalSkills,
@ -13,6 +14,7 @@ import {
import { loadProjectAgents, loadUserAgents } from "../features/claude-code-agent-loader"; import { loadProjectAgents, loadUserAgents } from "../features/claude-code-agent-loader";
import type { PluginComponents } from "./plugin-components-loader"; import type { PluginComponents } from "./plugin-components-loader";
import { reorderAgentsByPriority } from "./agent-priority-order"; import { reorderAgentsByPriority } from "./agent-priority-order";
import { remapAgentKeysToDisplayNames } from "./agent-key-remapper";
import { buildPrometheusAgentConfig } from "./prometheus-agent-config-builder"; import { buildPrometheusAgentConfig } from "./prometheus-agent-config-builder";
import { buildPlanDemoteConfig } from "./plan-model-inheritance"; import { buildPlanDemoteConfig } from "./plan-model-inheritance";
@ -104,7 +106,7 @@ export async function applyAgentConfig(params: {
const configAgent = params.config.agent as AgentConfigRecord | undefined; const configAgent = params.config.agent as AgentConfigRecord | undefined;
if (isSisyphusEnabled && builtinAgents.sisyphus) { if (isSisyphusEnabled && builtinAgents.sisyphus) {
(params.config as { default_agent?: string }).default_agent = "sisyphus"; (params.config as { default_agent?: string }).default_agent = getAgentDisplayName("sisyphus");
const agentConfig: Record<string, unknown> = { const agentConfig: Record<string, unknown> = {
sisyphus: builtinAgents.sisyphus, sisyphus: builtinAgents.sisyphus,
@ -193,6 +195,9 @@ export async function applyAgentConfig(params: {
} }
if (params.config.agent) { if (params.config.agent) {
params.config.agent = remapAgentKeysToDisplayNames(
params.config.agent as Record<string, unknown>,
);
params.config.agent = reorderAgentsByPriority( params.config.agent = reorderAgentsByPriority(
params.config.agent as Record<string, unknown>, params.config.agent as Record<string, unknown>,
); );

View File

@ -0,0 +1,18 @@
import { AGENT_DISPLAY_NAMES } from "../shared/agent-display-names"
export function remapAgentKeysToDisplayNames(
agents: Record<string, unknown>,
): Record<string, unknown> {
const result: Record<string, unknown> = {}
for (const [key, value] of Object.entries(agents)) {
const displayName = AGENT_DISPLAY_NAMES[key]
if (displayName && displayName !== key) {
result[displayName] = value
} else {
result[key] = value
}
}
return result
}

View File

@ -1,4 +1,11 @@
const CORE_AGENT_ORDER = ["sisyphus", "hephaestus", "prometheus", "atlas"] as const; import { getAgentDisplayName } from "../shared/agent-display-names";
const CORE_AGENT_ORDER = [
getAgentDisplayName("sisyphus"),
getAgentDisplayName("hephaestus"),
getAgentDisplayName("prometheus"),
getAgentDisplayName("atlas"),
] as const;
export function reorderAgentsByPriority( export function reorderAgentsByPriority(
agents: Record<string, unknown>, agents: Record<string, unknown>,

View File

@ -1,7 +1,12 @@
import type { OhMyOpenCodeConfig } from "../config"; import type { OhMyOpenCodeConfig } from "../config";
import { getAgentDisplayName } from "../shared/agent-display-names";
type AgentWithPermission = { permission?: Record<string, unknown> }; type AgentWithPermission = { permission?: Record<string, unknown> };
function agentByKey(agentResult: Record<string, unknown>, key: string): AgentWithPermission | undefined {
return agentResult[getAgentDisplayName(key)] as AgentWithPermission | undefined;
}
export function applyToolConfig(params: { export function applyToolConfig(params: {
config: Record<string, unknown>; config: Record<string, unknown>;
pluginConfig: OhMyOpenCodeConfig; pluginConfig: OhMyOpenCodeConfig;
@ -27,18 +32,18 @@ export function applyToolConfig(params: {
const isCliRunMode = process.env.OPENCODE_CLI_RUN_MODE === "true"; const isCliRunMode = process.env.OPENCODE_CLI_RUN_MODE === "true";
const questionPermission = isCliRunMode ? "deny" : "allow"; const questionPermission = isCliRunMode ? "deny" : "allow";
if (params.agentResult.librarian) { const librarian = agentByKey(params.agentResult, "librarian");
const agent = params.agentResult.librarian as AgentWithPermission; if (librarian) {
agent.permission = { ...agent.permission, "grep_app_*": "allow" }; librarian.permission = { ...librarian.permission, "grep_app_*": "allow" };
} }
if (params.agentResult["multimodal-looker"]) { const looker = agentByKey(params.agentResult, "multimodal-looker");
const agent = params.agentResult["multimodal-looker"] as AgentWithPermission; if (looker) {
agent.permission = { ...agent.permission, task: "deny", look_at: "deny" }; looker.permission = { ...looker.permission, task: "deny", look_at: "deny" };
} }
if (params.agentResult["atlas"]) { const atlas = agentByKey(params.agentResult, "atlas");
const agent = params.agentResult["atlas"] as AgentWithPermission; if (atlas) {
agent.permission = { atlas.permission = {
...agent.permission, ...atlas.permission,
task: "allow", task: "allow",
call_omo_agent: "deny", call_omo_agent: "deny",
"task_*": "allow", "task_*": "allow",
@ -46,10 +51,10 @@ export function applyToolConfig(params: {
...denyTodoTools, ...denyTodoTools,
}; };
} }
if (params.agentResult.sisyphus) { const sisyphus = agentByKey(params.agentResult, "sisyphus");
const agent = params.agentResult.sisyphus as AgentWithPermission; if (sisyphus) {
agent.permission = { sisyphus.permission = {
...agent.permission, ...sisyphus.permission,
call_omo_agent: "deny", call_omo_agent: "deny",
task: "allow", task: "allow",
question: questionPermission, question: questionPermission,
@ -58,20 +63,20 @@ export function applyToolConfig(params: {
...denyTodoTools, ...denyTodoTools,
}; };
} }
if (params.agentResult.hephaestus) { const hephaestus = agentByKey(params.agentResult, "hephaestus");
const agent = params.agentResult.hephaestus as AgentWithPermission; if (hephaestus) {
agent.permission = { hephaestus.permission = {
...agent.permission, ...hephaestus.permission,
call_omo_agent: "deny", call_omo_agent: "deny",
task: "allow", task: "allow",
question: questionPermission, question: questionPermission,
...denyTodoTools, ...denyTodoTools,
}; };
} }
if (params.agentResult["prometheus"]) { const prometheus = agentByKey(params.agentResult, "prometheus");
const agent = params.agentResult["prometheus"] as AgentWithPermission; if (prometheus) {
agent.permission = { prometheus.permission = {
...agent.permission, ...prometheus.permission,
call_omo_agent: "deny", call_omo_agent: "deny",
task: "allow", task: "allow",
question: questionPermission, question: questionPermission,
@ -80,10 +85,10 @@ export function applyToolConfig(params: {
...denyTodoTools, ...denyTodoTools,
}; };
} }
if (params.agentResult["sisyphus-junior"]) { const junior = agentByKey(params.agentResult, "sisyphus-junior");
const agent = params.agentResult["sisyphus-junior"] as AgentWithPermission; if (junior) {
agent.permission = { junior.permission = {
...agent.permission, ...junior.permission,
task: "allow", task: "allow",
"task_*": "allow", "task_*": "allow",
teammate: "allow", teammate: "allow",