feat(config): add custom_agents overrides and strict agent validation
This commit is contained in:
@@ -4,6 +4,7 @@ import type { OhMyOpenCodeConfig } from "../config";
|
||||
import { log, migrateAgentConfig } from "../shared";
|
||||
import { AGENT_NAME_MAP } from "../shared/migration";
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names";
|
||||
import { mergeCategories } from "../shared/merge-categories";
|
||||
import {
|
||||
discoverConfigSourceSkills,
|
||||
discoverOpencodeGlobalSkills,
|
||||
@@ -17,6 +18,13 @@ import { reorderAgentsByPriority } from "./agent-priority-order";
|
||||
import { remapAgentKeysToDisplayNames } from "./agent-key-remapper";
|
||||
import { buildPrometheusAgentConfig } from "./prometheus-agent-config-builder";
|
||||
import { buildPlanDemoteConfig } from "./plan-model-inheritance";
|
||||
import {
|
||||
applyCustomAgentOverrides,
|
||||
collectCustomAgentSummariesFromRecord,
|
||||
mergeCustomAgentSummaries,
|
||||
collectKnownCustomAgentNames,
|
||||
filterSummariesByKnownNames,
|
||||
} from "./custom-agent-utils";
|
||||
|
||||
type AgentConfigRecord = Record<string, Record<string, unknown> | undefined> & {
|
||||
build?: Record<string, unknown>;
|
||||
@@ -78,22 +86,6 @@ export async function applyAgentConfig(params: {
|
||||
const useTaskSystem = params.pluginConfig.experimental?.task_system ?? false;
|
||||
const disableOmoEnv = params.pluginConfig.experimental?.disable_omo_env ?? false;
|
||||
|
||||
const builtinAgents = await createBuiltinAgents(
|
||||
migratedDisabledAgents,
|
||||
params.pluginConfig.agents,
|
||||
params.ctx.directory,
|
||||
currentModel,
|
||||
params.pluginConfig.categories,
|
||||
params.pluginConfig.git_master,
|
||||
allDiscoveredSkills,
|
||||
params.ctx.client,
|
||||
browserProvider,
|
||||
currentModel,
|
||||
disabledSkills,
|
||||
useTaskSystem,
|
||||
disableOmoEnv,
|
||||
);
|
||||
|
||||
const includeClaudeAgents = params.pluginConfig.claude_code?.agents ?? true;
|
||||
const userAgents = includeClaudeAgents ? loadUserAgents() : {};
|
||||
const projectAgents = includeClaudeAgents ? loadProjectAgents(params.ctx.directory) : {};
|
||||
@@ -106,6 +98,44 @@ export async function applyAgentConfig(params: {
|
||||
]),
|
||||
);
|
||||
|
||||
const configAgent = params.config.agent as AgentConfigRecord | undefined;
|
||||
const mergedCategories = mergeCategories(params.pluginConfig.categories)
|
||||
const knownCustomAgentNames = collectKnownCustomAgentNames(
|
||||
userAgents as Record<string, unknown>,
|
||||
projectAgents as Record<string, unknown>,
|
||||
pluginAgents as Record<string, unknown>,
|
||||
configAgent as Record<string, unknown> | undefined,
|
||||
)
|
||||
|
||||
const customAgentSummaries = mergeCustomAgentSummaries(
|
||||
collectCustomAgentSummariesFromRecord(userAgents as Record<string, unknown>),
|
||||
collectCustomAgentSummariesFromRecord(projectAgents as Record<string, unknown>),
|
||||
collectCustomAgentSummariesFromRecord(pluginAgents as Record<string, unknown>),
|
||||
collectCustomAgentSummariesFromRecord(configAgent as Record<string, unknown> | undefined),
|
||||
filterSummariesByKnownNames(
|
||||
collectCustomAgentSummariesFromRecord(
|
||||
params.pluginConfig.custom_agents as Record<string, unknown> | undefined,
|
||||
),
|
||||
knownCustomAgentNames,
|
||||
),
|
||||
)
|
||||
|
||||
const builtinAgents = await createBuiltinAgents(
|
||||
migratedDisabledAgents,
|
||||
params.pluginConfig.agents,
|
||||
params.ctx.directory,
|
||||
currentModel,
|
||||
params.pluginConfig.categories,
|
||||
params.pluginConfig.git_master,
|
||||
allDiscoveredSkills,
|
||||
customAgentSummaries,
|
||||
browserProvider,
|
||||
currentModel,
|
||||
disabledSkills,
|
||||
useTaskSystem,
|
||||
disableOmoEnv,
|
||||
);
|
||||
|
||||
const isSisyphusEnabled = params.pluginConfig.sisyphus_agent?.disabled !== true;
|
||||
const builderEnabled =
|
||||
params.pluginConfig.sisyphus_agent?.default_builder_enabled ?? false;
|
||||
@@ -114,8 +144,6 @@ export async function applyAgentConfig(params: {
|
||||
const shouldDemotePlan = plannerEnabled && replacePlan;
|
||||
const configuredDefaultAgent = getConfiguredDefaultAgent(params.config);
|
||||
|
||||
const configAgent = params.config.agent as AgentConfigRecord | undefined;
|
||||
|
||||
if (isSisyphusEnabled && builtinAgents.sisyphus) {
|
||||
if (configuredDefaultAgent) {
|
||||
(params.config as { default_agent?: string }).default_agent =
|
||||
@@ -159,6 +187,7 @@ export async function applyAgentConfig(params: {
|
||||
pluginPrometheusOverride: prometheusOverride,
|
||||
userCategories: params.pluginConfig.categories,
|
||||
currentModel,
|
||||
customAgentSummaries,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -211,6 +240,24 @@ export async function applyAgentConfig(params: {
|
||||
};
|
||||
}
|
||||
|
||||
if (params.config.agent) {
|
||||
const builtinOverrideKeys = new Set([
|
||||
...Object.keys(builtinAgents).map((key) => key.toLowerCase()),
|
||||
"build",
|
||||
"plan",
|
||||
"sisyphus-junior",
|
||||
"opencode-builder",
|
||||
])
|
||||
|
||||
applyCustomAgentOverrides({
|
||||
mergedAgents: params.config.agent as Record<string, unknown>,
|
||||
userOverrides: params.pluginConfig.custom_agents,
|
||||
builtinOverrideKeys,
|
||||
mergedCategories,
|
||||
directory: params.ctx.directory,
|
||||
})
|
||||
}
|
||||
|
||||
if (params.config.agent) {
|
||||
params.config.agent = remapAgentKeysToDisplayNames(
|
||||
params.config.agent as Record<string, unknown>,
|
||||
|
||||
Reference in New Issue
Block a user